Download
network simulator 2 ns2 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Network Simulator 2(NS2) PowerPoint Presentation
Download Presentation
Network Simulator 2(NS2)

Network Simulator 2(NS2)

427 Vues Download Presentation
Télécharger la présentation

Network Simulator 2(NS2)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Network Simulator 2(NS2) Yingyue Xu 8/10/2014

  2. Overview: The Network simulator (NS): • discrete event simulator for networks. • supports wired, wireless, and satellite networks. • various routing and multicast protocols. • written in C++ and object-oriented tool command language (OTcl). • NS output is a file(s) which contains all packet information. It can be viewed using network animator (NAM), xgraph, or processed with custom scripts (Perl, Tcl or Awk ).

  3. User view of NS:

  4. C++ Fast in running. Slow and hard to modify (need to recompile the whole NS ). Used to implement detailed protocols and algorithms, to manipulate bytes since it can run over large number of data OTcl Slow in running Can be quickly changed (no need to recompile). Used to implement the simulation configuration like # of nodes, simulation topology and the dimensions of test area. Why two languages: That’s why NS object called split object! NSvia Tclcl (Tcl with classes) provides glue to make objects and variables appear on both languages.

  5. Ns functionalities • Wired world • Routing DV, LS, PIM-SM • Transportation: TCP and UDP • Traffic sources:web, ftp, telnet, cbr, stochastic • Queuing disciplines:drop-tail, RED, FQ, SFQ, DRR • QoS: IntServ and Diffserv • Emulation • Wireless • Ad hoc routing and mobile IP • Directed diffusion, sensor-MAC • Tracing, visualization, various utilities

  6. Ns Models • Traffic models and applications: • Web, FTP, telnet, constant-bit rate, real audio • Transport protocols: • unicast: TCP (Reno, Vegas, etc.), UDP • Multicast: SRM • Routing and queueing: • Wired routing, ad hoc rtg and directed diffusion • queueing protocols: RED, drop-tail, etc • Physical media: • Wired (point-to-point, LANs), wireless (multiple propagation models), satellite

  7. NS installation: • NS can work on most UNIX platforms, and also on windows platform. Detailed info for downloading and building NS: http://www.isi.edu/nsnam/ns/ns-build.html • Easier way to download all in one package and build NS (this will not work on Windows), this package contains Tcl, Tclcl, OTcl, Tk, and NS source codes. • You need to run install from UNIX shell (Bash or C shell).

  8. variables: set x 10 puts “x is $x” functions and expressions: set y [pow x 2] set y [expr x*x] control flow: if {$x > 0} { return $x } else { return [expr -$x] } while { $x > 0 } { puts $x incr x –1 } procedures: proc pow {x n} { if {$n == 1} { return $x } set part [pow x [expr $n-1]] return [expr $x*$part] } Also lists, associative arrays, etc. => can use a real programming language to build network topologies, traffic models, etc. Basic Tcl

  9. Class Person # constructor: Person instproc init {age} { $selfinstvar age_ set age_ $age } # method: Person instproc greet {} { $selfinstvar age_ puts “$age_ years old: How are you doing?” } # subclass: Class Kid -superclass Person Kid instproc greet {} { $selfinstvar age_ puts “$age_ years old kid: What’s up, dude?” } set a [new Person 45] set b [new Kid 15] $a greet $b greet Basic otcl => can easily make variations of existing things (TCP, TCP/Reno)

  10. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic • Transmit application-level data

  11. Creating Event Scheduler • Create event scheduler set ns [new Simulator] • Schedule events $ns at <time> <event> • <event>: any legitimate ns/tcl commands $ns at 5.0 “finish” • Start scheduler $ns run

  12. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic • Transmit application-level data

  13. Tracing and Monitoring • Packet tracing: • On all links: $ns trace-all [open out.tr w] • On one specific link: $ns trace-queue $n0 $n1$tr <Event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr> + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0

  14. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic • Transmit application-level data

  15. Creating Network • Nodes set n0 [$ns node] set n1 [$ns node] • Links and queuing $ns <link_type> $n0 $n1 <bandwidth> <delay> <queue_type> • <link_type>: duplex-link, simplex-link • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR, diffserv RED queues

  16. Creating Network: LAN $ns make-lan <node_list> <bandwidth> <delay> <ll_type> <ifq_type> <mac_type> <channel_type> <ll_type>: LL <ifq_type>: Queue/DropTail, <mac_type>: MAC/802_3 <channel_type>: Channel

  17. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic • Transmit application-level data

  18. Setup Routing • Unicast $ns rtproto <type> <type>: Static, Session, DV, cost, multi-path • Multicast $ns multicast (right after [new Simulator]) $ns mrtproto <type> <type>: CtrMcast, DM, ST, BST • Other types of routing supported: source routing, hierarchical routing

  19. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic • Transmit application-level data

  20. Inserting Errors • Creating Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] • Inserting Error Module $ns lossmodel $loss_module $n0 $n1

  21. Ns programming • Create the event scheduler • Turn on tracing • Create network • Setup routing • Insert errors • Create transport connection • Create traffic

  22. UDP set udp [new Agent/UDP] set null [new Agent/Null] $ns attach-agent $n0 $udp $ns attach-agent $n1 $null $ns connect $udp $null CBR set src [new Application/Traffic/CBR] Creating Connection and Traffic

  23. TCP set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink FTP set ftp [new Application/FTP] $ftp attach-agent $tcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp Creating Connection and Traffic II

  24. Summary: Generic Script Structure set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - multicast groups # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation

  25. dst_=0.0 dst_=1.0 0 1 1 0 Plumbing: Packet Flow n0 n1 Application/FTP Port Classifier Port Classifier Agent/TCPSink Addr Classifier Addr Classifier Agent/TCP 0 0 Link n0-n1 entry_ entry_ Link n1-n0

  26. Getting started with nam • Turn on nam tracing in your Tcl script • As easy as turning on normal tracing $ns namtrace $file • Specify link orientation (or node position for wireless) $ns duplex-link-op $node1 $node2 orient left • Execute nam exec nam $filename

  27. Advanced nam capabilities • Node options — color, shape, label $node color red $node shape hexagon $node label “my text” $node label-color blue $node label-at up • Link options $ns duplex-link-op $n1 $n2 color green $ns duplex-link-op queuePos right $ns duplex-link-op $n1 $n2 label “my text” $ns duplex-link-op $n1 $n2 label-color blue $ns duplex-link-op $n1 $n2 label-at down

  28. Advanced nam capabilities • Packet colors $ns color $n blue $agent set fid_ $n • Annotation $ns at $time “$ns trace-annotate $text” • Control playback $ns set-animation-rate 3ms

  29. The nam user interface

  30. The nam editor • Create simple scenarios graphically • Good for those who don’t want to learn Tcl, but only a limited subset of ns is available

  31. The nam editor

  32. Wireless model • Mobilenode at core of mobility model • Mobilenodes can move in a given topology, receive/transmit signals from/to wireless channels • Wireless network stack consists of LL, ARP, MAC, IFQ etc • Allows simulations of multi-hop ad hoc networks, wireless LANs, sensor networks etc

  33. An Example – Step 1 # Define Global Variables # create simulator set ns [new Simulator] # create a flat topology in a 670m x 670m area set topo [new Topography] $topo load_flatgrid 670 670

  34. An Example – Step 2 # Define standard ns/nam trace # ns trace set tracefd [open demo.tr w] $ns trace-all $tracefd # nam trace set namtrace [open demo.nam w] $ns namtrace-all-wireless $namtrace 670 670

  35. GOD (General Operations Director) • Stores smallest number of hops from one node to another • Optimal case to compare routing protocol performance • Automatically generated by scenario file • set god [create-god <no of mnodes>] • $god set-dist <from> <to> <#hops>

  36. Example –Step 3 • Create God set god [create-god 3] $ns at 900.00 “$god setdist 2 3 1”

  37. An Example – Step 4 # Define how a mobile node is configured $ns node-config \ -adhocRoutingDSDV \ -llType LL \ -macType Mac/802_11 \ -ifqLen 50 \ -ifqType Queue/DropTail/PriQueue \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \ -topoInstance $topo -agentTrace ON \ -routerTrace OFF \ -macTrace OFF

  38. An Example – Step 5 # Next create a mobile node, attach it to the channel set node(0) [$ns node] # disable random motion $node(0) random-motion 0 # Use “for” loop to create 3 nodes: for {set i < 0} {$i < 3} {incr i} { set node($i) [$ns node] $node($i) random-motion 0 }

  39. Mobilenode Movement • Node position defined in a 3-D model • However z axis not used $node set X_ <x1> $node set Y_ <y1> $node set Z_ <z1> $node at $time setdest <x2> <y2> <speed> • Node movement may be logged

  40. Scenario Generator: Movement • Mobile Movement Generator setdest -n <num_of_nodes> -p pausetime -s <maxspeed> -t <simtime> -x <maxx> -y <maxy> Source: ns-2/indep-utils/cmu-scen-gen/setdest/ • Random movement • $node random-motion 1 • $node start

  41. A Movement File $node_(2) set Z_ 0.000000000000 $node_(2) set Y_ 199.373306816804 $node_(2) set X_ 591.256560093833 $node_(1) set Z_ 0.000000000000 $node_(1) set Y_ 345.357731779204 $node_(1) set X_ 257.046298323157 $node_(0) set Z_ 0.000000000000 $node_(0) set Y_ 239.438009831261 $node_(0) set X_ 83.364418416244 $ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 170.519203111152 3.371785899154" $ns_ at 51.000000000000 "$node_(1) setdest 221.826585497093 80.855495003839 14.909259208114" $ns_ at 33.000000000000 "$node_(0) setdest 89.663708107313 283.494644426442 19.153832288917"

  42. Scenario Generator: Traffic • Generating traffic pattern files • CBR traffic ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] • TCP traffic ns tcpgen.tcl [-nn nodes] [-seed seed] • Source: ns-2/indep-utils/cmu-scen-gen/

  43. A Traffic Scenario set udp_(0) [new Agent/UDP] $ns_ attach-agent $node_(0) $udp_(0) set null_(0) [new Agent/Null] $ns_ attach-agent $node_(2) $null_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ 512 $cbr_(0) set interval_ 4.0 $cbr_(0) set random_ 1 $cbr_(0) set maxpkts_ 10000 $cbr_(0) attach-agent $udp_(0) $ns_ connect $udp_(0) $null_(0) $ns_ at 127.93667922166023 "$cbr_(0) start" …….

  44. An Example – Step 6 # Define node movement model source <movement-scenario-files> # Define traffic model source <traffic-scenario-files>

  45. An Example – Step 7 # Tell ns/nam the simulation stop time $ns at 200.0 “$ns nam-end-wireless 200.0” $ns at 200.0 “$ns halt” # Start your simulation $ns run

  46. nam Visualization • Replace $ns namtrace-all $fd with $ns namtrace-all-wireless $fd At the end of simulation, do $ns nam-end-wireless [$ns now]

  47. Wireless Trace Support • Original cmu trace format • A separate wireless trace format developed later at ISI • Current ongoing effort to have ONE format to combine all wired and wireless formats

  48. Useful links: • Tutorials:http://www.isi.edu/nsnam/ns/tutorial/index.htmlhttp://nile.wpi.edu/NS/ • NS2-Manual http://www.isi.edu/nsnam/ns/ns-man.html • Network Animator (NAM ): http://www.isi.edu/nsnam/nam/ • OTcl Tutorial: http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl

  49. Help and Resources • Ns and nam build questions • http://www.isi.edu/nsnam/ns/ns-build.html • Ns mailing list: ns-users@isi.edu • TCL: http://dev.scriptics.com/scripting • Otcl tutorial (in distribution): ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html