html5-img
1 / 63

ns-2

ns-2. Polly Huang USC/ISI huang@isi.edu. Modeling The Internet. Web. Web. TCP. TCP. www.cs.columbia.edu. Internet. Network. Network. Link/Physical. Link/Physical. ns-2. Network Simulator Version 2 (ns-2) Help to debug problems in a controlled environment

rianna
Download Presentation

ns-2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ns-2 Polly Huang USC/ISI huang@isi.edu

  2. Modeling The Internet Web Web TCP TCP www.cs.columbia.edu Internet Network Network Link/Physical Link/Physical

  3. ns-2 • Network Simulator Version 2 (ns-2) • Help to debug problems in a controlled environment • Performance Analysis of hypothetical changes

  4. C++ and otcl Separation • C++ for data • per packet action • otcl for control • periodic or triggered action • Compromize between composibility and speed • Learning & debugging

  5. Hello World - Interactive Mode swallow 71% ns % set ns [new Simulator] _o3 % $ns at 1 “puts \“Hello World!\”” 1 % $ns at 1.5 “exit” 2 % $ns run Hello World! swallow 72%

  6. Hello World - Passive Mode simple.tcl set ns [new Simulator] $ns at 1 “puts \“Hello World!\”” $ns at 1.5 “exit” $ns run swallow 74% ns simple.tcl Hello World! swallow 75%

  7. Basic tcl proc test {} { set a 43 set b 27 set c [expr $a + $b] set d [expr [expr $a - $b] * $c] for {set k 0} {$k < 10} {incr k} { if {$k < 5} { puts “k < 5, pow= [expr pow($d, $k)]” } else { puts “k >= 5, mod= [expr $d % $k]” } } } test

  8. Class mom mom instproc greet {} { $selfinstvar age_ puts “$age_ years old mom: How are you doing?” } Class kid -superclass mom kid instproc greet {} { $selfinstvar age_ puts “$age_ years old kid: What’s up, dude?” } set a [new mom] $a set age_ 45 set b [new kid] $b set age_ 15 $a greet $b greet Basic otcl

  9. Basic ns-2 • Creating network • Computing routes • Creating connection • Creating traffic • Inserting errors • Monitoring

  10. Creating Network • Nodes • set ns [new Simulator] • set n0 [$ns node] • set n1 [$ns node] • Links & Queuing • $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> • <queue_type>: DropTail, RED, CBQ, WFQ, SFQ, DRR

  11. Creating Network: LAN • 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

  12. Computing routes • Unicast • $ns rtproto <type> • <type>: Static, Session, DV, cost, multi-path • Multicast • Simulator set EnableMcast_ 1 • Simulator set NumberInterfaces_ 1 • $ns mrtproto <type> • <type>: CtrMcast, DM, dynamicDM, pimDM

  13. Creating Connection: UDP • 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

  14. Creating Connection: TCP • 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

  15. Creating Traffic • FTP • set ftp [new Application/FTP] • $ftp attach-agent $tcp • Telnet • set telnet [new Application/Telnet] • Web • set session [new httpSession $ns <numPages> <clientNode>]

  16. Creating Traffic: On Top of TCP • FTP • set ftp [new Application/FTP] • $ftp attach-agent $tcp • $ns at <time> “$ftp start” • Telnet • set telnet [new Application/Telnet] • $telnet attach-agent $tcp

  17. Creating Traffic: Trace Driven • Trace driven • set tfile [new Tracefile] • $tfile filename <file> • set src [new Application/Traffic/Trace] • $src attach-tracefile $tfile • <file>: • Binary format • inter-packet time (msec) and packet size (byte)

  18. 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

  19. n0 n1 Example Script set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.2 "$ftp start" $ns at 1.2 ”exit" $ns run $ns duplex-link $n0 $n1 1.5Mb 10ms DropTail set tcp [$ns create-connection TCP $n0 TCPSink $n1 0]

  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. Tracing • Trace packets on all links • $ns trace-all [open test.out w] <event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst> <seqno> <aseqno> + 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 • Trace packets on all links in nam-1 format • $ns namtrace-all [open test.nam w]

  22. Visualization Tools • nam-1 (Network AniMator Version 1) • xgraph

  23. Network Dynamics • Link failures • Hooks in routing module to reflect routing changes • Four models $ns rtmodel Trace <config_file> $n0 $n1 $ns rtmodel Exponential {<params>} $n0 $n1 $ns rtmodel Deterministic {<params>} $n0 $n1 $ns rtmodel-at <time> up|down $n0 $n1 • Parameter list [<start>] <up_interval> <down_interval> [<finish>]

  24. Other ns-2 Freatures • Mathematical Support • Multi-access Media (some link layer support) • Network Dynamics • Simulation Scale • 460 nodes, 100,000 TCP connections • Emulation Interface

  25. Discrete Event Scheduler time_, uid_, next_, handler_ head_ -> head_ -> handler_ -> handle() insert time_, uid_, next_, handler_

  26. n0 n1 Port Classifier Multicast Node dmux_ Addr Classifier classifier_ Node entry Node entry dmux_ entry_ entry_ Multicast Classifier classifier_ multiclassifier_ Network Topology - Node Unicast Node

  27. n0 n1 n1 entry_ head_ enqT_ queue_ deqT_ link_ ttl_ drophead_ drpT_ Network Topology - Link

  28. n0 n1 Port Classifier Addr Classifier n1 entry_ Node entry 0 head_ dmux_ enqT_ queue_ deqT_ link_ ttl_ 1 entry_ classifier_ drophead_ drpT_ Routing

  29. n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 1 dmux_ dmux_ 1 0 entry_ entry_ classifier_ classifier_ Link n1-n0 Routing (cont.) Link n0-n1

  30. dst_=0.0 dst_=1.0 Agent/TCPSink Agent/TCP agents_ 1 0 1 0 Transport n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 0 agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

  31. Application/FTP dst_=0.0 dst_=1.0 0 1 1 0 Application n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier Agent/TCPSink Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0

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

  33. ts_ cmn header ptype_ ip header uid_ tcp header size_ rtp header iface_ trace header ... Packet Format header data

  34. sim tcl8.0 tk8.0 otcl Tcl ns-2 nam-1 ... tcl ex test lib ... ns-2 Directory Structure tcl code C++ code example validation test tcl code core

  35. Topology Generation • http://www.isi.edu/nsnam/ns/ns-topogen.html

  36. Scenario Generation • http://www-mach.cs.berkeley.edu/ns/ns-scengeneration.html • agent-gen-script.tcl • Source generator files • source topo-gen.tcl • source agent-gen.tcl • source route-gen.tcl

  37. topo-gen.tcl • GT-ITM • topology • outfile <file> • type <graph_type> : random or transit_stub • nodes <num_nodes> • connection_prob <probability>

  38. route-gen.tcl • Routing • outfile <file> • unicast <ucast_type> • multicast <mcast_type>

  39. agent-gen.tcl • Agents • outfile <file> • transport <transport_type> • src <application_type> • sink <transport_sink_type> • num <num_connections or %> • start <start_time> • stop <stop_time>

  40. Wireless Support: Setup • set ns [new Simulator] • set chan [new Channel/WirelessChannel] • set prop [new Propagation/TwoRayGround] • set topo [new Topography] • $topo load_flatgrid <length> <width> • $prop topology $topo

  41. Wireless Support: MobileNode • Creating mobile nodes • set mnode [<routing>-create-mobile-node <node_id>] • <routing>: dsdv or dsr • Node coordinates • $mnode set X_ <x> • $mnode set Y_ <y> • $mnode set Z_ 0

  42. Mobility Support: Movement • Specified • $ns at 1.0 “$mnode setdest <x> <y> <speed>” • Random • $ns at 1.0 “$mnode start”

  43. time 1.2s G2 time 1.3s time 1.35s G2 G1 G2 Example: Multicast Routing • Dynamic group membership under Dense Mode n2 1.5Mb, 10ms 1.5Mb, 10ms time 1.25s n0 n1 G1 1.5Mb, 10ms G2 n3

  44. Multicast: Step 1 • Scheduler, tracing, and topology # Create scheduler set ns [new Simulator] # Turn on multicast $ns multicast # Turn on Tracing set fd [new “mcast.nam” w] $ns namtrace-all $fd

  45. Multicast: Step 2 • Topology # Create nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] # Create links $ns duplex-link $n0 $n1 1.5Mb 10ms DropTail $ns duplex-link $n0 $n2 1.5Mb 10ms DropTail $ns duplex-link $n0 $n3 1.5Mb 10ms DropTail

  46. Multicast: Step 3 • Routing and group setup # Routing protocol: let’s run distance vector $ns mrtproto DM # Allocate group addresses set group1 [Node allocaddr] set group2 [Node allocaddr]

  47. Multicast: Step 4 • Sender 0 # Transport agent for the traffic source set udp0 [new Agent/UDP] $ns attach-agent $n1 $udp0 $udp0 set dst_addr_ $group1 $udp0 set dst_port_ 0 # Constant Bit Rate source #0 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 # Start at time 1.0 second $ns at 1.0 "$cbr0 start"

  48. Multicast: Step 5 • Sender 1 # Transport agent for the traffic source set udp1 [new Agent/UDP] $ns attach-agent $n3 $udp1 $udp1 set dst_addr_ $group2 $udp1 set dst_port_ 0 # Constant Bit Rate source #0 set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 # Start at time 1.1 second $ns at 1.1 "$cbr1 start"

  49. Multicast: Step 6 • Receiver with dynamic membership # Can also be Agent/Null set rcvr [new Agent/LossMonitor] # Assign it to node $n2 $ns at 1.2 "$n2 join-group $rcvr $group2" $ns at 1.25 "$n2 leave-group $rcvr $group2" $ns at 1.3 "$n2 join-group $rcvr $group2" $ns at 1.35 "$n2 join-group $rcvr $group1"

  50. Multicast: Step 7 • End-of-simulation wrapper (as usual) $ns at 2.0 "finish" proc finish {} { global ns fd close $fd $ns flush-trace puts "running nam..." exec nam out.nam & exit 0 } $ns run

More Related