57 2 108KB
Workshop On Network Simulation A Handout Tools to be Used: 1. Network Simulator 2 (ns-allinone-2.33.tar.gz) 2. Tracegraph (tracegraph202.tar.gz) Operating System Fedora Core 9 or 10 This handout enables the participants to install network simulator 2 and tracegraph successfully in Linux Operating systems. Also the users can run the basic programs given in this handout and see the network animator and trace the results.
Ex. 1 Installation Instructions for Network Simulator 2 (ns-allinone2.33) The ns2 version taken here is 2.33, if you downloaded any other version, please modify your version during installation 1)Uncompress the ns2 tar zxvf ns-allinone-2.33.tar.gz or gzip -d ns-allinone-2.33.tar.gz tar xvf ns-allinone-2.33.tar 2) cd /home/pradeep/ns-allinone-2.33 3) ./install (execute the command) 4) If the installation fails in the middle, then try to install the linux packages that are necessary to run NS2. (In any linux (ubuntu or fedora or redhat or suse), install the TCL/TK, Perl packages during the installation of linux… if you dont know how to select the above packages, then install all the options available in the Fedora DVD or CD) 5) Once the installation succeeded, then the path information will be given by the NS2 itself 6) Set the path in the /home/pradeep/.bash_profile (gedit /home/pradeep/.bash_profile) or If you are a super user or root user then /root/.bash_profile logout and login. 9) go to the terminal and give either of these commands ns (a % indicates successful installation of NS2) or nam (an animator window will be opened) 10) for running the examples comes along with the distribution of NS2 cd /home/pradeep/ns-allinone-2.33/ns-2.33/tcl/ex 11. This is how you will see once the ns2 installation is success, from this information, you can put the PATH and LD_LIBRARY_PATH variable.. ////////////////This is the successful installation of the NS2 package Ns-allinone package has been installed successfully.
Here are the installation places: tcl8.4.14: /home/pradeep/ns-allinone-2.33/{bin,include,lib} tk8.4.14: /home/pradeep/ns-allinone-2.33/{bin,include,lib} otcl: /home/pradeep/ns-allinone-2.33/otcl-1.13 tclcl: /home/pradeep/ns-allinone-2.33/tclcl-1.19 ns: /home/pradeep/ns-allinone-2.33/ns-2.33/ns nam: /home/pradeep/ns-allinone-2.33/nam-1.13/nam xgraph: /home/pradeep/ns-allinone-2.33/xgraph-12.1 gt-itm: /home/pradeep/ns-allinone-2.33/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns ———————————————————————————Please put /home/pradeep/ns-allinone-2.33/bin:/home/pradeep/nsallinone-2.33/tcl8.4.14/unix:/home/pradeep/ns-allinone-2.33/tk8.4.14/unix into your PATH environment; so that you’ll be able to run itm/tclsh/wish/xgraph. IMPORTANT NOTICES: (1) You MUST put /home/pradeep/ns-allinone-2.33/otcl-1.13, /home/pradeep/ns-allinone-2.33/lib, into your LD_LIBRARY_PATH environment variable. If it complains about X libraries, add path to your X libraries into LD_LIBRARY_PATH. If you are using csh, you can set it like: setenv LD_LIBRARY_PATH If you are using sh, you can set it like: export LD_LIBRARY_PATH= (2) You MUST put /home/pradeep/ns-allinone-2.33/tcl8.4.14/library into your TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during startup. After these steps, you can now run the ns validation suite with cd ns-2.33; ./validate For trouble shooting, please first read ns problems page http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive for related posts.
Ex.2 How to Run TCL File in Network Simulator 2 1. Install NS2 and set the path (using Ex.1) 2. After Installing NS2, go the shell prompt and run ns filename.tcl For example, ns tcp.tcl (if the file name is tcp.tcl) 3. .nam and .tr files will be created if the above tcl file contains those codes in the same folder (the tcl file should contain the provision of tracing the nam and trace file.. ) (nam means Network Animator and tr means Trace file) 4. to see the demo in GUI, run nam tcp.nam (a window will be opened and you can click the run button ) 5. .tr file is actual file helpful to see the performance factors like(throughput, packet drop, etc). You can parse the .tr file using softwares like tracegraph202 (need to download separately) or xgraph( which comes along with ns2)
Ex. 3 How to install Tracegraph in Linux (Fedora 9) To Install Tracegraph in Fedora Linux (I used Fedora Core 9) 1. Step download the Tracegraph software from http://www.tracegraph.com 2. Select Linux Version and download two files, mglinstaller.gz and tracegraph202.tar.gz 3. copy the files under /home/pradeep 4. Untar the tracegraph202.tar.gz using the command tar zxvf tracegraph202.tar.gz 5. A Folder tracegraph202/ will be created and go to the folder using the command cd tracegraph202 or cd /home/pradeep 6. copy the mglinstaller.gz file in the above said folder using the following command cp /home/pradeep 7. now execute the command to unzip the mglinstaller.gz using the following command gzip -d mglinstaller.gz 8. run the mglinstaller by executing the command ./mglinstaller 9. the above command will create a folder within the bin folder and set the following lines to the LD_LIBRARY_PATH variable 10.export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pradeep/tracegraph202/bin/glnx86 11.The above path will be set to the LD_LIBRARY_PATH Variable in the following file .bashrc which will be available at /home/pradeep (each username will have such a file in the corresponding folder, if you are using more number of users, each user should be set with the LD_LIBRARY_PATH, root will be having the .bash_profile at /root/.bashrc). 12.To open this file type either vi /home/pradeep/.bashrc 13.Save the file, close and logout and login and go to the tracegraph202 folder and run ./trgraph 14.You may get a message like libXp.so.6 not found, just connect your system to internet and execute the command as a super user yum install libXp.so.6 Ex.4 How to Start # create a simulator Object sset ns [new Simulator] # open a file for writing Nam Trace data set nf [open out.nam w] $$ns namtrace-all $nf set nt [open out.tr w] $$ns trace-all $nt # finish procedure that closes the trace file and starts nam proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } # two nodes with a connected link
set n0 [$ns node] sset n1 [$ns node] # connection between the two nodes with bandwidth of 1 Megabits, delay of 10ms and a DropTail queue $$ns duplex-link $n0 $n1 1Mb 10ms DropTail #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $$ns attach-agent $n0 $udp0 # 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 $udp0 set null0 [new Agent/Null] $$ns attach-agent $n1 $null0 $$ns connect $udp0 $null0 $ns at 0.5 "$cbr0 start" $$ns at 4.5 "$cbr0 stop" #after 5 simulation time execute the finish procedure $$ns at 5.0 "finish" #Starts the simulation $ns run The above example is a wired network example
Ex. 5 Wireless Example #Define Options set val(chan) Channel/WirelessChannel ;#Channel Type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type 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(nn) 3 ;# number of mobilenodes set val(rp) DSDV ;# routing protocol set val(x) 543 set val(y) 5 543
# Initialize Global Variables set ns_ [new Simulator] set tracefd [open second.tr w] $$ns_ trace-all $tracefd set namtrace [open second.nam w] $$ns_ namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object sset topo [new Topography] $$topo load_flatgrid $val(x) $val(y) # Create God ccreate-god $val(nn) # Create channel #1 and #2 set chan_1_ [new $val(chan)] sset chan_2_ [new $val(chan)] # Create node(0) "attached" to channel #1 # configure node, please note the change below. $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) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace ON \ -movementTrace ON \ --channel $chan_1_ sset node_(0) [$ns_ node] # node_(1) can also be created with the same configuration, or with a different # channel specified. # Uncomment below two lines will create node_(1) with a different channel. # $ns_ node-config \ # -channel $chan_2_ set node_(1) [$ns_ node] sset node_(2) [$ns_ node]
$node_(0) random-motion 0 $node_(1) random-motion 0 $$node_(2) random-motion 0 for {set i 0} {$i < $val(nn)} {incr i} { $ns_ initial_node_pos $node_($i) 100 } # # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes # $node_(0) set X_ 5.0 $node_(0) set Y_ 2.0 $$node_(0) set Z_ 0.0 $node_(1) set X_ 8.0 $node_(1) set Y_ 5.0 $$node_(1) set Z_ 0.0 $node_(2) set X_ 11.0 $node_(2) set Y_ 8.0 $$node_(2) set Z_ 0.0 # # Now produce some simple node movements # Node_(1) starts to move towards node_(0) # $ns_ at 3.0 "$node_(2) setdest 150.0 140.0 25.0" $ns_ at 3.0 "$node_(1) setdest 50.0 40.0 25.0" $$ns_ at 3.0 "$node_(0) setdest 48.0 38.0 5.0" # Node_(1) then starts to move away from node_(0) $ns_ at 10.0 "$node_(1) setdest 490.0 480.0 30.0" $ns_ at 20.0 "$node_(2) setdest 170.0 130.0 130.0" # Setup traffic flow between nodes # TCP connections between node_(0) and node_(1) set tcp [new Agent/TCP] $tcp set class_ 2 sset sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $$ns_ attach-agent $node_(2) $tcp $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns_ at 3.0 "$ftp start"
# # Tell nodes when the simulation ends # for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at 30.0 "$node_($i) reset"; } $ns_ at 30.0 "stop" $ns_ at 30.01 "puts \"NS EXITING...\" ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace exec nam second.nam & close $tracefd } puts "Starting Simulation..." $ns_ run
Ex. 6 How to interprete the NS2 tracefile for wireless simulation ACTION: [s|r|D]: s — sent, r — received, D — dropped WHEN: WHERE: LAYER:
flags: SEQNO: TYPE:
$
the the AGT RTR LL IFQ MAC PHY
time when the action happened node where the action happened -- application, -- routing, -- link layer (ARP is done here) -- outgoing packet queue (between link and mac layer) -- mac, -- physical
the sequence number of the packet the packet type cbr -- CBR data stream packet DSR -- DSR routing packet (control packet generated by routing) RTS -- RTS packet generated by MAC 802.11 ARP -- link layer ARP packet SIZE: the size of packet at current layer, when packet goes down, size increases, goes up size decreases [a b c d]: a -- the packet duration in mac layer header b -- the mac address of destination c -- the mac address of source d -- the mac type of the packet body flags: [......]: [ source node ip : port_number destination node ip (-1 means broadcast) : port_number ip header ttl ip of next hop (0 means node 0 or broadcast) ]
So we can interpret the below trace s 76.000000000 _98_ AGT
--- 1812 cbr 32 [0 0 0 0] ------- [98:0 0:0 32 0]
as Application 0 (port number) on node 98 sent a CBR packet whose ID is 1812 and size is 32 bytes, at time 76.0 second, to application 0 on node 0 with TTL is 32 hops. The next hop is not decided yet. And we can also interpret the below trace r 0.010176954 _9_ RTR -1:255 32 0]
--- 1 gpsr 29 [0 ffffffff 8 800] ------- [8:255
in the same way, as The routing agent on node 9 received a GPSR broadcast (mac address 0xff, and ip address is -1, either of them means broadcast) routing packet whose ID is 1 and size is 19 bytes, at time 0.010176954 second, from node 8 (both mac and ip addresses are 8), port 255 (routing agent).