AMAZON

Showing posts with label ns2 coding. Show all posts
Showing posts with label ns2 coding. Show all posts

Wednesday, September 5, 2012

NS2 coding 3G -UMTS network simulation

  NS2 coding 3G -UMTS network simulation
> .............................................
banner > #Create a simulator object
> set ns [new Simulator]
> 
> #Open the nam trace file
> set nf [open out.nam w]
> $ns namtrace-all $nf
> 
> #Define a 'finish' procedure
> proc finish {} {
>         global ns nf
>         $ns flush-trace
>         #Close the trace file
>         close $nf
>         #Execute nam on the trace file
>         exec nam out.nam &
>         puts "Simulation ended!"
>         exit 0
> }
> 
> # Insert your own code for topology creation
> # and agent definitions, etc. here
> 
> # Node address is 0
> $ns node-config -UmtsNodeType rnc
> set rnc [$ns create-Umtsnode]
> 
> # Node address is 1
> $ns node-config -UmtsNodeType bs \
>                 -downlinkBW 32kbs \
>                 -downlinkTTI 10ms \
>                 -uplinkBW 32kbs \
>                 -uplinkTTI 10ms \
> 
> set bs [$ns create-Umtsnode]
> 
> #Iub configuration between RNC and BS
> $ns setup-Iub $bs $rnc 622Mbit 622Mbit 15ms 15ms DummyDropTail 2000
> 
> # Node address for ue1 is 2
> $ns node-config -UmtsNodeType ue \
>                 -baseStation $bs \
>                 -radioNetworkController $rnc
> 
> set ue1 [$ns create-Umtsnode]
> 
> # Node address for sgsn0 and ggsn0 is 3 and 4, respectively
> set sgsn0 [$ns node]
> set ggsn0 [$ns node]
> 
> # Node address for node1 is 5
> set node1 [$ns node]
> 
> $ns duplex-link $node1 $ggsn0 622Mbit 1ms DropTail 1000
> $ns duplex-link $ggsn0 $sgsn0 622Mbit 1ms DropTail 1000
> $ns duplex-link $sgsn0 $rnc 622Mbit 1ms DropTail 1000
> 
> $rnc add-gateway $sgsn0
> 
> set rtp_sender [new Agent/RTP]
> $ns attach-agent $node1 $rtp_sender
> 
> set rtp_receiver [new Agent/RTP]
> $ns attach-agent $ue1 $rtp_receiver
> 
> # Create a CBR traffic source and attach it to udp0
> set cbr0 [new Application/Traffic/CBR]
> $cbr0 set packetSize_ 500
> $cbr0 set interval_ 0.005
> $cbr0 attach-agent $rtp_sender
> 
> #creation of DCH channel
> $ns node-config -llType UMTS/RLC/AM \
>                 -downlinkBW 64kbs \
>                 -uplinkBW 64kbs \
>                 -downlinkTTI 10ms \
>                 -uplinkTTI 10ms
> 
> set dch0 [$ns create-dch $ue1 $rtp_receiver]
> 
> #Call the finish procedure after 5 seconds simulation time
> $ns at 5.0 "finish"
> 
> #Run the simulation
> $ns run
>

Performance Evaluation of DSDV, AODV, and DSR using ns2 simulator


-->
banner
Performance Evaluation of DSDV, AODV, and DSR
 
In this report, I just show the simulation scripts to compare the performance of DSDV, AODV, and DSR. More information about these adhoc routing protocols can be found on the Internet or books.
 
(TCL script --- adhoc.tcl)
if {$argc !=3} {
puts "Usage: ns adhoc.tcl Routing_Protocol Traffic_Pattern Scene_Pattern "
puts "Example:ns adhoc.tcl DSDV cbr-50-10-8 scene-50-0-20"
exit
}
 
set par1 [lindex $argv 0]
set par2 [lindex $argv 1]
set par3 [lindex $argv 2]
 
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagationmodel
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
 
if { $par1=="DSR"} {
set val(ifq) CMUPriQueue
} else {
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
}
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(rp) $par1 ;# routing protocol
set val(x) 500
set val(y) 500
set val(seed) 0.0
set val(tr) temp.tr
set val(nn) 50
set val(cp) $par2
set val(sc) $par3
set val(stop) 100.0
 
set ns_ [new Simulator]
 
set tracefd [open $val(tr) w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
 
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
 
set god_ [create-god $val(nn)]
 
set chan_1_ [new $val(chan)]
 
$ns_ node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF
 
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
 
puts "Loading connection pattern..."
source $val(cp)
 
puts "Loading scenario file..."
source $val(sc)
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
 
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).000000001 "$node_($i) reset";
}
 
$ns_ at $val(stop).000000001 "puts \"NS EXITING...\"; $ns_ halt"
puts "Start Simulation..."
$ns_ run
 
 
Performance metric: Packet Delivery fraction (The ratio of the data packets delivered to the destinations to those generated by the sources)
(AWK paring program --- getRatio.awk)
BEGIN {
sendLine = 0;
recvLine = 0;
fowardLine = 0;
}
 
$0 ~/^s.* AGT/ {
sendLine ++ ;
}
 
$0 ~/^r.* AGT/ {
recvLine ++ ;
}
 
$0 ~/^f.* RTR/ {
fowardLine ++ ;
}
 
END {
printf "cbr s:%d r:%d, r/s Ratio:%.4f, f:%d \n", sendLine, recvLine, (recvLine/sendLine),fowardLine;
}

 
Before running simulation, we have to use the tools to generate the traffic and scenario patterns.
 
1.      Traffic pattern (change the path to ~ns\indep-utils\cmu-scen-gen)
In this example, traffic models were generated for 50 nodes with CBR traffic sources, with maximum connections of 10 at a rate of 8kbps.
(-rate 2.0: in one second, 2 packets are generated. The packet size is 512 byte. Therefore the rate is 2*512*8=8kbps)
  
2. Scenario pattern (change the path to ~ns\indep-utils\cmu-scen-gen)


In this example, mobility models are created for the simulations using 50 nodes, with pause time of 0 seconds, maximum speed of 20m/s, topology boundary of 500x500 and simulation time of 100 secs.

 After creating the traffic and scenario pattern files, copy them to the place where you put the adhoc.tcl.
 
Start Running Simulation
1. DSDV


Parse the result
 



1.      AODV



2.      DSR







Monday, July 16, 2012

How to install Ns-2 doc linux/windows


-->

NS2 Installation Procedure (For Root User)

  • Check for the complete LINUX installation (with all the options enabled during installation) in the system.
  • During installation of NS2 its better to get into the ROOT login.
  • Copy the given ns-allinone-2.34.tar.gz file in the root directory.
  • Extract the files in the same folder using extract option or the command in the terminal as

root>tar -zxvf ns-allinone-2.34.tar.gz

  • The files will be extracted in the newly created folder as ns-allinone-2.34.
  • Now go to the terminal and get into the folder ns-allinone-2.34 and do the following
Root> cd ns-allinone-2.34
Root/ns-allinone-2.34 >./install

  • This command will run for 10-15 minutes. If it is a successful installation you will be getting IMPORTANT NOTICE notes (detailing about the paths to set)
  • Copy the ns-21 file given into the following folder

Computer/file system/etc/profile.d

  • Now close all the terminal and open a new terminal and get into the folder root/ns-allinone-2.34 and give ns command and you will be getting as below when you each time press ENTER key which indicates that the installation is complete .
      • Root/ns-allinone-2.34>./validate
Root/ns-allinone-2.34>ns
%
%
%exit
  • Now you can run the programs in a new terminal.

What ns-21 consists of??
It consist of path
PATH=$PATH:$HOME/bin:/root/ns-allinone-2.34/bin:/root/ns-allinone-2.34/tcl8.4.18/unix:/root/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=/root/ns-allinone-2.34/otcl-1.13:/root/ns-allinone-2.34/lib
export TCL_LIBRARY=/root/ns-allinone-2.34/tcl8.4.18/library



NS2 Installation Procedure (For other User)
Open terminal window

Type $ su & give root password & follow the above mention procedure
For copying ns21.sh file use following command
cp<space><source path><space> <destination path(/etc/profile.d)>
How to create(Enable) a Root User
  • Step1
$ su (give password)
Now it becomes Root
cd <space>/etc/pam.d
Vim gdm
Remove # symbol from 3rd line
Vim gdm- password
Remove! Symbol from 3rd line end

How to install Ns-2 in Windows