Ns network simulator

5,746 views
5,556 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,746
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
327
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ns network simulator

  1. 1. ns network simulator Edwin Hernandez January 19 th , 2001 Harris Lab Seminar                       
  2. 2. Background on ns <ul><li>What’s ns </li></ul><ul><ul><li>The VINT project : Virtual InterNet Testbed </li></ul></ul><ul><ul><li>UC Berkeley, Lawrence Berkeley National Lab, USC/ISI, Xerox PARC, AT&T Research </li></ul></ul><ul><ul><li>http://www.isi.edu/nsnam/ns </li></ul></ul><ul><ul><ul><li>Download the full version, Linux, Solaris, current snapshots, there is a Win32 version. </li></ul></ul></ul><ul><ul><ul><li>Languages used : C++, Otcl and TCL/TK </li></ul></ul></ul><ul><ul><ul><li>Current release : ns 2.1b7a, Harris Lab : ns2.1b6 </li></ul></ul></ul>
  3. 3. Characteristics of ns <ul><li>By using C++/Otcl, the network simulator is complete Object-oriented. </li></ul><ul><li>C++ is used for data per packet events </li></ul><ul><li>Otcl is used for periodic or triggered events </li></ul><ul><li>The TCL interpreter: TclCL is the language used to provide a linkage between C++ and Otcl </li></ul>
  4. 4. Installation process for ns <ul><li>Takes time to compile and configure! </li></ul><ul><li>Be careful with ./configure you must try to: </li></ul><ul><ul><li>./configure --with-tclcl=../tclcl_dir –with-otcl=../ </li></ul></ul><ul><ul><li>Provide ../configure --help </li></ul></ul><ul><ul><li>make clean; make install (i.e. root in linux) </li></ul></ul><ul><li>Required ns-2, otcl, tclcl, tcl/tk8.0., nam (network animator) </li></ul>
  5. 5. The starting point <ul><li>Lets create a two node simulation </li></ul><ul><li>First we proceed to create the scheduler </li></ul><ul><ul><li>set ns_ [new Simulator] </li></ul></ul><ul><li>The scheduler requires a set of events to process: </li></ul><ul><ul><li>$ns_ at <time> <event> </li></ul></ul><ul><ul><li>Where event is anything in ns/tcl commands. </li></ul></ul><ul><ul><li>For example: puts “Hello World ”; </li></ul></ul><ul><li>To start a simulation we can just execute </li></ul><ul><ul><li>$ns_ run </li></ul></ul>
  6. 6. A test script for ns <ul><li>Type in pico or vi. </li></ul><ul><li>Test it with ns script.tcl </li></ul><ul><ul><li>Will return “ Hello World ” </li></ul></ul>set ns_ [new Simulator] $ns_ at 1 “puts ”hello world”” $ns_ at 1.5 “exit” $ns_ run
  7. 7. Creating the network nodes <ul><li>Nodes </li></ul><ul><ul><li>set n0 [$ns_ node] </li></ul></ul><ul><ul><li>set n1 [$ns_ node] </li></ul></ul><ul><li>Links & Queuing </li></ul><ul><ul><li>$ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> </li></ul></ul><ul><ul><li><queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR </li></ul></ul><ul><li>Once we have the network configuration we can create some traffic. </li></ul>
  8. 8. Creating TCP traffic <ul><li>Agent/TCP </li></ul><ul><ul><li>set tcp [new Agent/TCP] </li></ul></ul><ul><ul><ul><li>We need a source of traffic </li></ul></ul></ul><ul><ul><li>set tcpsink [new Agent/TCPSink] </li></ul></ul><ul><ul><ul><li>We need a sink for this traffic </li></ul></ul></ul><ul><ul><li>$ns attach-agent $n0 $tcp </li></ul></ul><ul><ul><ul><li>We attach the TCP “agents” to the node source </li></ul></ul></ul><ul><ul><li>$ns attach-agent $n1 $tcpsink </li></ul></ul><ul><ul><ul><li>We attach the TCPSink Agent to the node destination </li></ul></ul></ul><ul><ul><li>$ns connect $tcp $tcpsink </li></ul></ul><ul><ul><ul><li>We connect both end points </li></ul></ul></ul>
  9. 9. Creating TCP Traffic <ul><li>Application FTP </li></ul><ul><ul><li>set ftp [new Application/FTP] </li></ul></ul><ul><ul><li>$ftp attach-agent $tcp </li></ul></ul><ul><ul><li>$ns at <time> “$ftp start” </li></ul></ul><ul><li>Application Telnet </li></ul><ul><ul><li>set telnet [new Application/Telnet] </li></ul></ul><ul><ul><li>$telnet attach-agent $tcp </li></ul></ul><ul><li>Application HTTP </li></ul><ul><ul><li>Client: set client [new HTTP/Client $ns_ $n0] </li></ul></ul><ul><ul><li>$client connect $server </li></ul></ul><ul><ul><li>Server :set server [new HTTP/Server $ns_ $n1] </li></ul></ul><ul><ul><li>$server set-page-generator $pgp </li></ul></ul><ul><ul><li>For further details check chp. 34 of the ns manual </li></ul></ul>
  10. 10. Creating UDP traffic <ul><li>Agent/UDP is required </li></ul><ul><ul><li>set udp [new Agent/UDP] </li></ul></ul><ul><ul><li>set null [new Agent/NULL] or </li></ul></ul><ul><ul><li>set lossMonitor [new Agent/LossMonitor] </li></ul></ul><ul><ul><li>$ns_ attach-agent $n0 $udp </li></ul></ul><ul><ul><li>$ns_ attach-agent $n1 $null </li></ul></ul><ul><ul><li>$ns_ connect $udp $null or </li></ul></ul><ul><ul><li>$ns_ connect $udp $lossMonitor </li></ul></ul><ul><li>The Agent/LossMonitor can monitor number of packets transferred, as well as packets lost. </li></ul><ul><li>A procedure can be scheduled to poll the LossMonitor every T seconds and obtain throughput information. </li></ul>
  11. 11. Polling the LossMonitor proc record {sink} { global fthrput fpcklost #Get an instance of the simulator set ns [Simulator instance] #Set the time for polling set time 0.25 #How many bytes have been received by the traffic set bw1 [$sink set bytes_] set lpkts [$sink set nlost_] set now [$ns now] puts $fthrput &quot;$now [expr $bw1/$time*8]&quot; puts $fpcklost &quot;$now $lpkts&quot; #Reset the bytes_ values on the traffic sinks $sink set bytes_ 0 $sink set nlost_ 0 #Re-schedule the record function $ns at [expr $now+$time] &quot;record sink&quot; }
  12. 12. Creating UDP traffic <ul><li>CBR : Constant Bit Rate, back-to-back transfers. </li></ul><ul><ul><li>set cbr [new Application/Traffic/CBR] </li></ul></ul><ul><ul><li>$cbr_ set packetSize_ 512 </li></ul></ul><ul><ul><li>$cbr_ set interval_ 0.1 </li></ul></ul><ul><ul><li>$cbr_ set random_ 1 </li></ul></ul><ul><ul><li>$cbr_ set maxpkts_ 1000000 </li></ul></ul><ul><ul><li>$cbr_ attach-agent $udp </li></ul></ul><ul><ul><li>$ns_ connect $udp $lossMonitor </li></ul></ul><ul><li>Exponential or Pareto on-off </li></ul><ul><ul><li>set src [new Application/Traffic/Exponential] </li></ul></ul><ul><ul><li>set src [new Application/Traffic/Pareto] </li></ul></ul>
  13. 13. Creating UDP traffic <ul><li>Trace driven </li></ul><ul><ul><li>set tfile [new Tracefile] </li></ul></ul><ul><ul><li>$tfile filename <file> </li></ul></ul><ul><ul><li>set traceSrc [new Application/Traffic/Trace] </li></ul></ul><ul><ul><li>$traceSrc attach-tracefile $tfile </li></ul></ul><ul><li><file>: </li></ul><ul><ul><li>Binary format </li></ul></ul><ul><ul><li>inter-packet time (msec) and packet size (byte) </li></ul></ul><ul><li>We need also to schedule the traffic with, ns_ at “cbr start” </li></ul>
  14. 14. Wireless extensions <ul><li>IEEE 802.11 can be simulated, Mobile-IP, and adhoc protocols such as DSR, TORA, DSDV and AODV. </li></ul><ul><li>CMU provides tools to create traffic patterns and scenario files. </li></ul><ul><li>Special trace-file format for wireless packets, very detailed. Drawback: Files are extremely big. (100’s of Mbytes for 1000 sec of simulation) </li></ul>
  15. 15. Simulation of two wireless nodes <ul><li>A simple simulation for two nodes and no infrastructure we need to configure the nodes first (in ns2.1b7). </li></ul><ul><ul><li>$ns_ node-config -adhocRouting $opt(rp) </li></ul></ul><ul><ul><li>-llType $opt(ll) </li></ul></ul><ul><ul><li>-macType $opt(mac) </li></ul></ul><ul><ul><li>-ifqType $opt(ifq) </li></ul></ul><ul><ul><li>-ifqLen $opt(ifqlen) </li></ul></ul><ul><ul><li>-antType $opt(ant) </li></ul></ul><ul><ul><li>-propType $$opt(prop) </li></ul></ul><ul><ul><li>-phyType $val(netif) </li></ul></ul><ul><ul><li>-channelType $chan </li></ul></ul><ul><ul><li>-topoInstance $topo </li></ul></ul><ul><ul><li>-agentTrace ON </li></ul></ul><ul><ul><li>-routerTrace OFF </li></ul></ul><ul><ul><li>-macTrace OFF </li></ul></ul>
  16. 16. Simple wireless simulation <ul><li>Array opt( ) </li></ul><ul><ul><li>set opt(chan) Channel/WirelessChannel ;# channel type </li></ul></ul><ul><ul><li>set opt(prop) Propagation/TwoRayGround ;# radio-propagation </li></ul></ul><ul><ul><li>set opt(netif) Phy/WirelessPhy ;# network interface </li></ul></ul><ul><ul><li>set opt(mac) Mac/802_11 ;# MAC type </li></ul></ul><ul><ul><li>set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type </li></ul></ul><ul><ul><li>set opt(ll) LL ;# link layer type </li></ul></ul><ul><ul><li>set opt(ant) Antenna/OmniAntenna ;# antenna model </li></ul></ul><ul><ul><li>set opt(ifqlen) 50 ;# max packet in ifq </li></ul></ul><ul><ul><li>set opt(rp) DSDV ;# routing protocol </li></ul></ul>
  17. 17. Configuring the wireless/phy <ul><li>Phy/WirelessPhy set CPThresh_ 10.0 </li></ul><ul><li>Phy/WirelessPhy set CSThresh_ 1.559e-11 </li></ul><ul><li>Phy/WirelessPhy set RXThresh_ 3.652e-10 </li></ul><ul><li>Phy/WirelessPhy set Rb_ 2*1e6 </li></ul><ul><li>Phy/WirelessPhy set Pt_ 0.2818 </li></ul><ul><li>Phy/WirelessPhy set freq_ 914e+6 </li></ul>
  18. 18. Important initialization variables <ul><li>set topo [new Topography] </li></ul><ul><li>$topo load_flatgrid $opt(x) $opt(y) ; </li></ul><ul><ul><li>opt(x) and opt(y) are the dimensions of the simulation area </li></ul></ul><ul><li>set chan [new $opt(chan)] </li></ul><ul><li>Create-god Number_of_entities </li></ul>
  19. 19. Creating the mobile nodes <ul><li>Set mobile node </li></ul><ul><ul><li>set Mnode [dsdv-create-mobile-node <node_id>] </li></ul></ul><ul><ul><li>Or set Mnode [$ns_ node <node_id>] </li></ul></ul><ul><li>Attach it to the topography </li></ul><ul><ul><li>$node topography $topo </li></ul></ul><ul><li>Determine the motion pattern and initial position </li></ul><ul><li>$node random-motion 0 #; no random </li></ul><ul><li>$node set Z_ 0.000000 </li></ul><ul><li>$node set Y_ 100.0000 </li></ul><ul><li>$node set X_ 2.000000 </li></ul>
  20. 20. Adding movement to the nodes <ul><li>Random set to 0 </li></ul><ul><ul><li>$ns at <time> “$node setdest <x> <y> <speed>” </li></ul></ul><ul><li>Random set to 1 </li></ul><ul><ul><li>$ns at <time> “$node start” </li></ul></ul>
  21. 21. Tracing the node movement and traffic information <ul><li>Trace packets on all links (Old Trace format) </li></ul><ul><ul><li>$ns_ trace-all [open test.out w] </li></ul></ul><ul><li><event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst> <seqno> <aseqno> </li></ul><ul><ul><li>+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 </li></ul></ul><ul><ul><li>- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 </li></ul></ul><ul><ul><li>r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0 </li></ul></ul><ul><li>Trace packets on all links in nam-1 format </li></ul><ul><ul><li>$ns_ namtrace-all [open test.nam w] </li></ul></ul><ul><li>Due the size of trace files, $ns_ trace-all [ open “|gzip –c > out.tr.gz” w]| </li></ul><ul><li>Or $ns_ trace-all [open “awk –f awkScript > output.tr” w] </li></ul>
  22. 22. New trace format <ul><li>Activating trace/nam files </li></ul><ul><ul><li>$ns_ trace-all $tracefd </li></ul></ul><ul><ul><li>$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y) </li></ul></ul><ul><ul><li>$ns_ use-newtrace </li></ul></ul><ul><li>New trace file sample </li></ul><ul><ul><li>r 1499.998807 5 4 cbr 532 ------- 0 1.0.1.2 0.0.0.2 163975 235152 </li></ul></ul><ul><ul><li>d -t 1500.000000000 -Hs 5 -Hd 16777216 -Ni 5 -Nx 2.00 -Ny 1500.00 -Nz 0.00 -Ne -1.000000 -Nl IFQ -Nw END -Ma a2 -Md 5 -Ms 5 -Mt 800 -Is 16777216.0 -Id 4194305.0 -It udp -Il 92 -If 0 -Ii 198410 -Iv 32 </li></ul></ul><ul><li>S: send, r: received, d: dropped, -t <time>, -Is: node source, -Id: destination, -Ii: packet ID, -Nl: cause of dropped –Nw: cause of dropped –Nx: position in x, - Ny: positon in y. etc. More details in Chp. 16 of the NS manual. </li></ul>
  23. 23. We can visualize the trace/nam files Network animator screenshots of an ad-hoc network simulation (courtesy of S. Shah)
  24. 24. ns-2 can be modified <ul><li>Any modification to the source code of NS can be followed by a make distclean: make all command to make effective all the changes. </li></ul><ul><li>We can modify the propagation model by making changes to tworayground.cc and tworayground.h </li></ul>class TwoRayGround : public Propagation { public: TwoRayGround(); virtual double Pr(PacketStamp *tx, PacketStamp *rx, WirelessPhy *ifp); protected: double TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L$ double last_hr, last_ht; double crossover_dist; };
  25. 25. For more internals and how to modify ns <ul><li>Check the NS manual: http://www.isi.edu/nsnam/ns/doc/ns_doc.pdf </li></ul><ul><li>Tutorial by Marc Greis : http://www.isi.edu/nsnam/ns/tutorial/index.html </li></ul><ul><li>This tutorial is very good for ns internals </li></ul><ul><ul><li>http://www.isi.edu/nsnam/dist/ns-workshop00/ </li></ul></ul>

×