Uni Innsbruck Informatik - Uni Innsbruck Informatik - 1 IASTED ASM 2004 Tutorial: IASTED ASM 2004 Tutorial: The The ns-2 ns-2 Network Simulator Network Simulator Michael Welzl Michael Welzl http://www.welzl.at Distributed and Parallel Systems Group Distributed and Parallel Systems Group Institute of Computer Science Institute of Computer Science University of Innsbruck, Austria University of Innsbruck, Austria
49
Embed
Uni Innsbruck Informatik - 1 IASTED ASM 2004 Tutorial: The ns-2 Network Simulator Michael Welzl Distributed and Parallel Systems Group.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 11
The The ns-2ns-2 Network Simulator Network Simulator
Michael Welzl Michael Welzl http://www.welzl.at
Distributed and Parallel Systems GroupDistributed and Parallel Systems GroupInstitute of Computer ScienceInstitute of Computer ScienceUniversity of Innsbruck, AustriaUniversity of Innsbruck, Austria
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 22
OutlineOutline
• ns-2 overview
• Writing simulation scripts
• Obtaining results
• General network simulation hints
• Teaching with ns-2
• Conclusionsimulated transit-stub network
(ns/nam dump)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 33
ns-2 overviewns-2 overview
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 44
Some thoughts about network Some thoughts about network simulationsimulation
• Real-world experiments sometimes impossible
• Mathematical modeling can be painful– Sometimes even painful and inaccurate!
• Mechanism implementation in C++, test with simple OTcl script
• Simulation scenario development in OTcl
• Test simulation with nam
• One way to obtain a useful result:perl script -> simulations with varyingparameter(s) -> several output files ->perl script -> result file ->xgraph (gnuplot, MS Excel, ..) -> ps file
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 1010
Simulation elementsSimulation elements
• Code: C++ network elements, OTcl simulator elements and simulation script, perl (or whatever) scripts for running simulation and interpreting results
• ns to run simulation, nam for immediate feedback• Visualization tool (xgraph, gnuplot, ..)
C++ network elem ents
Otcl script ns trace fileuser
perl script results
visualisation tool diagram
nam
generates
uses
nam trace file
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 1111
• $ns at 1.0 “$app1 send 100 \"$app2 app-recv 123\““
• Application/TcpApp instproc app-recv { number } { ... }
if you want to receive ...
size content
to send back
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2020
Writing your own protocolWriting your own protocol
• simple (for teaching): use TcpApp– inefficient, not very flexible
• more useful (for researchers): change ns code
• two basic approaches
1. truly understand architecture(class hierarchy, including “shadow objects“ in OTcl etc.)
2. “hack“ code– change existing code to suit your needs– generally use C++ (and not OTcl) if possible
works surprisingly well; I recommend this.
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2121
How to “hack“ ns codeHow to “hack“ ns code
• “ping“ example in the Marc Greis tutorial (easy - try it!)– simple end-to-end protocol
• how to integrate your code in ns:– write your code: e.g., ping.h and ping.cc– if it‘s an agent...
• “command“ method = method call from OTcl• recv method = called when a packet arrives
– if it‘s a new packet type: change packet.h and tcl/lib/ns-packet.tcl– change tcl/lib/ns-default.tcl
• define and initialize attributes that are visible from OTcl– do a “make depend“, then “make“
• Note: ns manual mixes “how to use it“ with “what happens inside“– this is where you look for details
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2222
Obtaining resultsObtaining results
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2323
Obtaining resultsObtaining results
proc record {} { global sink0 ns f0 #Set the time after which the procedure should be called again set time 0.5 #How many bytes have been received by the traffic sinks? set bw0 [$sink0 set bytes_] #Get the current time set now [$ns now] #Calculate the bandwidth (in MBit/s) and write it to the files puts $f0 "$now [expr $bw0/$time*8/1000000]" #Reset the bytes_ values on the traffic sinks $sink0 set bytes_ 0 #Re-schedule the procedure $ns at [expr $now+$time] "record"}
read byte counter
Use LossMonitor instead of Null agent
puts [$filehandle] “text“write text to a file
Important:$ns at 0.0 "record"
Note:puts “[expr 1+1]“ -> 2puts “1+1“ -> 1+1
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2424
Obtaining results /2Obtaining results /2
• LossMonitor: simple solution for CBR, but TCP <-> TCPSink !
• Very common solution: generate tracefileset f [open out.tr w]$ns trace-all $f
• Trace file format:event | time | from | to | type | size | flags | flow ID | src addr | dst addr | seqno | uid
Color your flow in nam:$ns color num color(e.g. $ns color 1 blue)
Monitoring queues in nam:$ns duplex-link-op $node1 $node2 queuePos 0.5
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2525
Obtaining results /3Obtaining results /3
• Problem: trace files can be very large
• Solution 1: use pipeset f [open | perl filter.pl parameters w]$ns trace-all $f
• Other solutions:– Use specific trace or monitor - more efficient!– direct output in C++ code - even more efficient, but less flexible!
• Note: TCP throughput != TCP “goodput“– Goodput: bandwidth seen by the receiving application– should not include retransmits!– requires modification of TCP C++ code
perl script to filter irrelevant information(could be any script file)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2626
Dynamic vs. long-term behaviorDynamic vs. long-term behavior
• Typically two types of simulation results:– dynamic behavior– long-term behavior: 1 result per simulation (behavior as function of parameter)
– actually slightly more difficult - e.g., “empty“ intervals should be included
• long-term behavior– script calls simulations with varying parameter– each simulation trace file parsed (simply summarize data or calculate statistics)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 2727
Long-term behaviorLong-term behavior
• Simulation script:– (..)set parameter [lindex $argv 0](..)set f [open "| perl stats.pl tcp w]$ns trace-all $f(..)($parameter used in simulation!)
• loop:– for {set i 1} {$i <= 10} {set i [expr $i+1]} {
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3232
General network simulation hintsGeneral network simulation hints
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3333
RecommendationsRecommendations
• Select parameters carefully– consider RTT: what is realistic? what is a reasonable simulation
duration?– ideally, duration should depend on statistics
• e.g., until variance < threshold• not supported by ns• thus, just simulate long (realistic duration for, e.g., ftp
download)
• Frequently ignored (but important) parameters:– TCP maximum send window size (should not limit TCP behavior)– TCP “flavor“ (should be a state-of-the-art variant like SACK)– buffer length (should be bandwidth*delay)– Active Queue Management parameters (RED = hard to tune!)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3434
Recommendations /2Recommendations /2
• Start simple, then gradually approach reality– 1 source, 1 destination– multiple homogeneous flows across single bottleneck– multiple homogeneous flows with heterogeneous RTTs– multiple heterogeneous flows with homogeneous and heterogeneous
RTTs– impact of routing changes, various types of traffic sources (web,
“greedy“, ..)
• eventually implement and test in controlled environment• ...and then perhaps even test in real life :)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3535
Common topologiesCommon topologies
• Dumbbell:
evaluate basicend2end behaviour,TCP-friendliness, ..– often: n vs. m flows
• Parking Lot:
evaluate behaviourwith different RTT's,fairness, ..– often: S0/D0 - n flows,
all other S/D pairs - m flows
S1 D1
DnSn
S0 D0
D1S1 S2 D2 Dn
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3636
• Krzysztof Pawlikowski, Hae-Duck Jeong, and Jong-Suk Ruth Lee, “On Credibility of Simulation Studies of Telecommunication Networks“, IEEE Communications Magazine, January 2002, pp. 132-139.
• Mark Allman, Aaron Falk, “On the Effective Evaluation of TCP“, ACM Computer Communication Review, 29(5), October 1999. http://www.icir.org/mallman/papers/tcp-evaluation.pdf
• Sally Floyd and Vern Paxson, “Difficulties in Simulating the Internet“, IEEE/ACM Transactions on Networking, Vol.9, No.4, pp. 392-403.
• Sally Floyd and Eddie Kohler, “Internet Research Needs Better Models“, ACM Hotnets-I, October 2002.
• and this website: http://www.icir.org/models/bettermodels.html
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3737
Teaching with ns-2Teaching with ns-2
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3838
Teaching experience: ns for lab Teaching experience: ns for lab exercisesexercises
• Reason to use ns– lack of other tools to “fool around“ with network dynamics
(mainly congestion control)– some sort of “hands-on experience“ without endangering real net
• Personal experience: (3 times; lab courses accompanyingnetworks lecture) - Students did not like it!– poor documentation (problem eliminated for 3rd try, didn‘t help)– OTcl learning effort large, but exercises small - too much overhead– some things do not work as expected; bugs etc.
• Recommendations– avoid long-term simulation (various languages and files for single exercise)– avoid C++ changes; exercises in OTcl only, with precompiled ns-2
• Currently working on a GUI ! (monitor my ns website)
Note: teaching repository at ns site
lecture + nam animations could be a nice alternative!
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 3939
Example exercise 1: congestion Example exercise 1: congestion collapsecollapse
• Congestion control necessary
• adding fast links does not help!
S1 D1
D2S2
100 kb/s
1000 kb/s
100 kb/s
10 kb/s
110 kb/s
Queue
S 1
S 2
SwitchingFabric
total throughput w/o cc.: 20kb/stotal throughput w/ cc.: 110kb/s
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4040
Example exercise 1: congestion Example exercise 1: congestion collapse /2collapse /2
“knee“
“cliff“
Goal: operation at the “knee“
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4141
Internet congestion control: HistoryInternet congestion control: History
• 1968/69: dawn of the Internet• 1986: first congestion collapse• 1988: "Congestion Avoidance and Control" (Jacobson)
Combined congestion/flow control for TCP
• Goal: stability - in equilibrum, no packet is sent into the network until an old packet leaves– ack clocking, “conservation of packets“ principle– made possible through window based stop+go - behaviour
• Superposition of stable systems = stable network based on TCP with congestion control = stable
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4242
TCP Congestion Control /1: Tahoe, TCP Congestion Control /1: Tahoe, 19881988
• Distinguish:– flow control: protect receiver against overload
(receiver "grants" a certain amount of data ("receiver window") )
– congestion control: protect network against overload("congestion window" (cwnd) limits the rate: min(cwnd,rwnd) used! )
• Flow/Congestion Control combined in TCP. Several algorithms:
• (window unit: SMSS = Sender Maximum Segment Size, usually adjusted to Path MTU; init cwnd<=2 (*SMSS), ssthresh = usually 64k)
– Slow Start: for each ack received, increase cwnd by 1(exponential growth) until cwnd >= ssthresh
– Congestion Avoidance: each RTT, increase cwnd by SMSS*SMSS/cwnd(linear growth - "additive increase")
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4343
TCP Congestion Control /2TCP Congestion Control /2
• If a packet or ack is lost (timeout, roughly 4*rtt), set cwnd = 1, ssthresh = current bandwidth / 2(“multiplicative decrease") - exponential backoff
• Several timers, based on RTT; good estimation is crucial!
• Later additions:(TCP Reno, 1990)Fast retransmit / fast recovery (notify sender of loss via duplicate acks)
0
1
2
3
4
5
6
7
8
9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
time
ba
nd
wid
th
Timeout
ssthresh
Slow Start
Congestion Avoidance
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4444
Example exercise 2: TCP vs. UDPExample exercise 2: TCP vs. UDP
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4545
Example exercise 2: TCP vs. UDP /2Example exercise 2: TCP vs. UDP /2
• Results by astudent inLinz, Austria
1 tcp - 1 cbr - drop tail
-50000
0
50000
100000
150000
200000
10 tcp - 1 cbr - drop tail
-200000
0
200000
400000
600000
800000
1000000
1200000
1400000
100 tcp - 1 cbr - drop tail
-200000
0
200000
400000
600000
800000
1000000
1200000
1400000
100 tcp - 1 cbr - RED
-200000
0
200000
400000
600000
800000
1000000
1200000
1400000
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4646
ConclusionConclusion
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4747
ConclusionConclusion
• Research+ freely available+ de facto standard for (Internet-) simulations+ open source spirit: compare your mechanism with the state-of-
the-art+ lots of features– rather complex architecture; new protocol = typically a hack– must use lots of tools (and typically languages) at once
• Teaching– OTcl learning effort for exercises+ nam animations may be good for lectures (repository available)
Uni Innsbruck Informatik - Uni Innsbruck Informatik - 4848
Key linksKey links
• Official website: http://www.isi.edu/nsnam/ns– docs: “ns manual“, “Marc Greis‘ tutorial“, “ns by example“
• note: HTML version of “ns manual“ not always up-to-date– large number of “Contributed Modules“
• Personal ns website: http://www.welzl.at/tools/ns– “throughput“ and “stats“ scripts– working versions of ns and nam Windows binaries– German ns documentation (student work)– these slides