330 likes | 409 Views
Introduction to NS-2. Tutorial overview of NS Create basic NS simulation Walk-through a simple example Model specification Execution and trace analysis. http://www-net.cs.umass.edu/~honggang/ns-cs653/. NS-2, the network simulator. Academic project over 10 years old
E N D
Introduction to NS-2 • Tutorial overview of NS • Create basic NS simulation • Walk-through a simple example • Model specification • Execution and trace analysis http://www-net.cs.umass.edu/~honggang/ns-cs653/
NS-2, the network simulator • Academic project over 10 years old • freely distributed, open source • Currently maintained by ISI (Information Sciences Institute) • DARPA + NSF projects • ~ 200K LoC, 403 page manual • Large user base • mostly academics • “de facto” standard in networking research • Main website: http://www.isi.edu/nsnam/ns
NS Functionality • Discrete event simulator • Modeling Network Components • Traffic models and applications • Web, FTP, telnet, audio, sensor nets • Transport protocols • TCP (Reno, SACK, etc), UDP, multicast • Routing and queueing • static routing, DV routing, multicast, ad-hoc routing • queueing disciplines: drop-tail, RED, FQ • Link layer • wired, wireless, satellite • Providing Infrastructure • tracing, visualization, error models, etc • modify or create your own modules
NS components • NS, the simulator itself (this is all we’ll have time for) • NAM, the Network AniMator • visualize NS (or other) output • GUI input simple Ns scenarios • pre-processing: • traffic and topology generators • post-processing: • simple trace analysis, often in Awk, Perl, or Tcl • Tutorial: http://www.isi.edu/nsnam/ns/tutorial • NS by example: http://nile.wpi.edu/NS/
NS Software Structure: C++ and OTCL • Uses two languages • C++ for the core of NS simulator • per packet processing • fast to run, detailed, complete control • OTCL for control [our focus] • simulation setup, configuration • fast to write and change
Steps when using NS • Create OTCL script for your network model • nodes, links, traffic sources, sinks, etc. • Parameterize simulation objects • Links: queue sizes, link speeds, … • Transport Protocols: TCP flavor and parameters (more than 30), … • Collect statistics • dump everything to trace, post process it • gather stats during simulation within OTCL script • modify Ns source code • Run NS multiple times • confidence intervals
Create a Basic NS Simulation • Create event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Create a Basic NS Simulation • Create the event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Step 1: Creating Event Scheduler • Create scheduler • set ns [new Simulator] • Schedule event • $ns at <time> <event> • <event>: any legitimate Ns/TCL commands • Start scheduler • $ns run
Create a Basic NS Simulation • Create the event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Step 2: Creating Network (Nodes + Links) • Nodes • set n0 [$ns node] • set n1 [$ns node] • Links: connect together two nodes • $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> • <delay> determines propagation delay • <queue_type> determines queueing policy • DropTail, RED, CBQ, FQ, SFQ, DRR
Create a Basic NS Simulation • Create the event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Step 3: Create Connections • Transports: • TCP, UDP, multicast, etc. • transport protocol instances attach to nodes
Creating Transport Channels: UDP • source and sink • set u_src [new Agent/UDP] • set u_dst [new Agent/NULL] • attach them to nodes, then connect to each other • $ns attach-agent $n0 $u_src • $ns attach-agent $n1 $u_dst • $ns connect $u_src $u_dst
Creating Transport Channels: TCP • source and sink • set t_src [new Agent/TCP/Newreno] • set t_dst [new Agent/TCPSink] • “Newreno” flavor of TCP • attach to nodes and each other • $ns attach-agent $n0 $t_src • $ns attach-agent $n1 $t_dst • $ns connect $t_src $t_dst
Create a Basic NS Simulation • Create the event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Step 4: Create Traffic Models • Traffic (applications): • Web, ftp, telnet, audio, etc. • application objects attach to transport protocol objects • generates traffic into transport protocol
Creating Traffic over TCP Channels How to create a FTP session over TCP? • create traffic model • set ftp [new Application/FTP] • default is “infinite” file size • attach to TCP channel • $ftp attach-agent $t_src • schedule start time • $ns at <time> “$ftp start”
Creating Traffic over UDP Channels How to create a CBR (Constant Bit Rate) model over UDP? • set cbr [new Application/Traffic/CBR] • $cbr set packetSize_ 512 • $cbr set interval_ 0.250 • $cbr attach-agent $u_src • $ns at <time> “$cbr start”
Create a Basic NS Simulation • Create the event scheduler • Create nodes and links • Create connections • Create traffic sources/sinks • Enable tracing
Tracing: dump everything into a file • Trace packets on individual link • Tracefile format: <event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst> <seqno> <aseqno> + 1 0 2 tcp 900 ------- 1 0.0 3.1 7 15 - 1 0 2 tcp 900 ------- 1 0.0 3.1 7 15 r 1.00234 0 2 tcp 900 ------- 1 0.0 3.1 7 15 enqueue Node 1 Node 0 time • + enqueue • dequeue • r receive • d drop nodes involved in this event receive dequeue drop
Tracing: dump everything into a file • Trace packets on individual links • Tracefile format: <event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst> <seqno> <aseqno> + 1 0 2 tcp 900 ------- 1 0.0 3.1 7 15 - 1 0 2 tcp 900 ------- 1 0.0 3.1 7 15 r 1.00234 0 2 tcp 900 ------- 1 0.0 3.1 7 15 packet type packet flags seq number time packet ID • + enqueue • dequeue • r receive • d drop packet length flow ID source dest addresses nodes involved in this event
Tracing via Monitors • Queue monitor: the queue to access a link • Flow monitor: particular flow within queue • to specify a link, we need: set link [$ns link $n0 $n1] • to create a flow monitor: set fmon [$ns makeflowmon Fid] $ns attach-fmon $link $fmon $ns at <time> “puts $fmon set pdrops_”
Introduction to NS-2: • Tutorial overview of NS • Create basic NS simulation • Walk-through simple example • Model specification • Execution and trace analysis
Walk-through example Node 2 Node 0 Node 1 acks acks full duplex full duplex
Walk-through example 12 FTP dest One CBR source 10 FTP sources 2 FTP sources performance 2 TCP SACK W_max = 32 MSS = 1400 10 TCP NewReno W_max = 32 MSS = 1400 One UDP 12 TCP dest tracing Node 2 Node 0 Node 1 acks acks One UDP Two UDP dest 1 Mbps full duplex 10 msec prop delay 700 packet buffer Drop-tail policy 2 Mbps full duplex 5 msec prop delay 100 packet buffer Drop-tail policy One On-Off dest One CBR dest One On-Off Source (voice) thin link fat link
Introduction to NS-2: • Tutorial overview of NS • Create basic NS simulation • Walk-through simple example • Model specification • Execution and trace analysis See handout for source code
NS Trace file (link n1->n2): NS-trace.txt ... + 11.533441 1 2 tcp 1440 ------- 12 1.2 2.4 96 2092 r 11.535694 1 2 tcp 1440 ------- 12 1.2 2.4 65 1527 - 11.537214 1 2 exp 180 ------- 100 0.2 2.13 284 1528 - 11.538654 1 2 cbr 1440 ------- 101 1.11 2.14 155 1530 r 11.547214 1 2 tcp 1440 ------- 12 1.2 2.4 66 1529 + 11.54728 1 2 tcp 1440 ------- 12 1.2 2.4 97 2095 r 11.548654 1 2 exp 180 ------- 100 0.2 2.13 284 1528 + 11.55 1 2 cbr 1440 ------- 101 1.11 2.14 211 2096 - 11.550174 1 2 tcp 1440 ------- 12 1.2 2.4 67 1534 r 11.560174 1 2 cbr 1440 ------- 101 1.11 2.14 155 1530 - 11.561694 1 2 exp 180 ------- 100 0.2 2.13 285 1532 + 11.56222 1 2 tcp 1440 ------- 12 1.2 2.4 98 2097 - 11.563134 1 2 tcp 1440 ------- 12 1.2 2.4 68 1537 r 11.571694 1 2 tcp 1440 ------- 12 1.2 2.4 67 1534 r 11.573134 1 2 exp 180 ------- 100 0.2 2.13 285 1532 - 11.574654 1 2 exp 180 ------- 100 0.2 2.13 286 1536 ... 0.0114sec=180*8/(10^6)+0.01
Flow Monitor (link n1->n2) Trace : packet-trace.txt ... 10 356 1394.6939635123624 1262 906 0 4 7 3 0 10.5 367 1575.3875777393503 1325 958 0 8 15 7 0 1 1 0 0 11 366 1759.8340061666161 1384 1018 0 8 15 7 0 1 1 0 0 11.5 370 1944.0583990191849 1448 1078 0 8 15 7 0 1 1 0 0 12 380 2131.710863713804 1512 1132 0 8 15 7 0 1 1 0 0 12.5 382 2325.178644727122 1558 1176 0 8 15 7 0 1 1 0 0 13 382 2516.7615454470124 1613 1231 0 8 15 7 0 1 1 0 0 13.5 395 2710.8647514290892 1676 1281 0 8 15 7 0 2 3 1 0 14 421 2912.3462186990751 1747 1326 0 16 31 15 0 2 3 1 0 14.5 432 3130.3858423193769 1805 1373 0 16 31 15 0 2 3 1 0 15 436 3344.5896974377333 1862 1426 016 31 15 02 3 1 0 15.5 462 3571.3811182311597 1937 1475 0 16 31 15 0 2 3 1 0 16 477 3804.653159658757 1995 1518 0 16 31 15 0 2 3 1 0 16.5 495 4049.5929326563519 2057 1562 0 16 31 15 0 2 3 1 0 17 531 4303.9211771379323 2136 1605 0 16 31 15 0 2 3 1 0 ...
Results - Queue Statistics • Red - instantaneous • Green - running average • Blue - average w/o transient • Purple - packet drops
Results - Flow Statistics • Red - TCP flow 1 • Green - TCP flow 2 • Number of packets in queue mimics TCP Window behavior
Results - Flow Statistics • Congestion Windows of Flow 1 and Flow 2 • Cumulative dropped packets of Flow 1 and Flow 2
Performance Queue Statistics • Multiple runs to obtain confidence intervals