1EE 122: Computer Networks Network Simulator ns2Department of Electrical Engineering and Computer SciencesUniversity of California, BerkeleyBerkeley, CA 94720-1776Adapted from F04 SlidesK. Fall, J. Heidemann, P. Huang, K. Lai, A. Parekh, I. Stoica, S. Shenker, J. Walrand2Outline§ Goals§ Discrete Event Simulation§ Basic ns-2 § Examples23What is ns-2?§ Discrete event simulator§ Models network protocols- Wired, wireless, satellite- TCP, UDP, multicast, unicast- Web, Telnet, FTP- Ad-hoc routing, sensor networks- Infrastructure: stats, tracing, error models, etc.§ Multiple levels of detail in one simulator4Why simulate?§ To examine protocol in controlled environment§ Repeatable experiments§ Alternatives:- Experimentation: operational details, but limited scale, limited flexibility- Analysis: can provide deeper understanding, but ignores implementation details35ns-2 components§ ns: the Network Simulation engine- executes tcl scripts containing simulation setup and events§ nam: the Network AniMator- visualize ns outputtcl script(specificationof experiment)ns-2trace file (output)nam6Discrete Event Simulation§ model world as events- maintain queue of events, ordered by time- maintain [virtual time]- repeat: • extract event at head, set [virtual time]=event’s time• process it• if processing generates another event, add it to queue§ each event takes predefined amount of virtual time, arbitrary amount of real time- having a slow CPU makes simulation run slower (in real time), but doesn’t change result47Discrete Event Simulation8oTcl overview§ programming language used for setting up simulation environment- object oriented- interpreted (slow)§ Used for- Setting up topology- Placing agents- Injecting events- Configuring tracingExamples:§ variables- set x 10- puts “x is $x”§ expressions- set y [pow x 2]- set y [expr x+x*3]§ control- if ($x>0) { return $x } else { return [expr -$x] }- while ($x >0) { puts $x• set x [eval x+1] }59Basic ns-21. Create the simulator objectset ns [new Simulator]2. Set up the network topology set <var> [$ns node]3. Define traffic patterns $ns <link-type> <node1> <node2> <bandwidth> <delay> <queuetype>4. Define agentsset <var> [new Agent/<agent type>]$ns attach-agent <node variable> <agent variable>$ns connect <agent variable> <agent variable>5. Define the trace files and monitors$ns namtrace-all ,namtracefile>6. Schedule simulation events$ns at <time> <event>7. Run the simulator$ns runn0 n1ftptcp tcp-sinkn210Basic ns-21. Create the Simulatorset ns [new Simulator]2. Set Up Network Topologyset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]3. Define Traffic Patterns$ns duplex-link $n0 $n1 4Mb 10ms DropTail$ns duplex-link $n2 $n1 1Mb 10ms DropTail$ns queue-limit $n1 $n2 10n0 n1 n2611Basic ns-24. Define Agents#Create a TCP agent and attach it to node n0set tcp0 [new Agent/TCP]$ns attach-agent $n0 $tcp0#Create a TCP sink agent and attach it to node n2set sink [new Agent/TCPSink]$ns attach-agent $n2 $sink#Connect both agents$ns connect $tcp0 $sink# create an FTP source set ftp [new Application/FTP]$ftp set maxpkts_ 1000$ftp attach-agent $tcp0n0 n1ftptcp tcp-sinkn212Basic ns-25. Define Trace Files and Monitors# open the nam trace fileset nam_trace_fd [open tcp_tahoe.nam w]$ns namtrace-all $nam_trace_fd# define a 'finish' procedureproc finish {} {global ns nam_trace_fd trace_fd# close the nam trace file$ns flush-traceclose $nam_trace_fd# execute nam on the trace fileexit 0}n0 n1ftptcp tcp-sinkn2713Basic ns-26. Schedule Simulation Events$ns at 0.0 "$ftp start"$ns at 10.0 "$ftp stop"$ns at 10.1 "finish“7. Run the simulation#Run the simulation$ns runn0 n1ftptcp tcp-sinkn214Examplen0 n1ftptcp#Create a simulator objectset ns [new Simulator]#Create three nodesset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]#Create link between the nodes$ns duplex-link $n0 $n1 4Mb 10ms DropTail$ns duplex-link $n2 $n1 1Mb 10ms DropTail$ns queue-limit $n1 $n2 10#Create a TCP agent and attach it to node n0set tcp0 [new Agent/TCP]$ns attach-agent $n0 $tcp0#Create a TCP sink agent and attach it to node n2set sink [new Agent/TCPSink]$ns attach-agent $n2 $sink#Connect both agents$ns connect $tcp0 $sink# create an FTP source set ftp [new Application/FTP]$ftp set maxpkts_ 1000$ftp attach-agent $tcp0#Inject starting events$ns at 0.0 "$ftp start"$ns at 10.0 "$ftp stop"$ns at 10.1 "finish"#Run the simulation$ns runtcp-sinkn2n0 n1ftptcp tcp-sinkn2815nam visualization demo§ Now I show an instance of nam running the example on the previous slide…tcl script(specificationof experiment)ns-2trace file (output)namWe just saw this… Now I will show you this…16Analysis- Other commands for configuring nam not discussed here917Questions?Project 2 - Introduction1019Overview§ Learning goals§ Project structure§ Submission details20Goals§ Investigating the behavior of TCP - Effects of different window sizes on TCP dataflow - Appreciate the different variants of TCP- TCP with non-TCP flows§ Queueing- Droptail vs. RED1121Project Structure§ Project is divided into two main tasks- Task 1: • 4 questions• 10 points- Task 2: • 8 questions• 30 points22Task 1§ Initial network configuration§ 2 TCP flows§ Observe what happens when the window sizes change1223Results§ Trace file: typically has the format (time, val)§ Nam file format:- [event type] -t [time] -s [src node] -d [dst node] -p [pkt type] -e [pkt size] -c [color] -i [pkt id] -a [flow id] -x {[src.port] [dst.port] [seqno] ------- null} § For example: event r –t 10 –s 1 –d 2 –p “tcp”§ How do we access events?- awk '$1== "r" && $7==3 {a += $11} END {print a}' task1_out.nam 24Task 1: modifications§ You will need to modify the script to create the following topology:§ A third TCP flow is added1325Task 2§ You are given several “black-box” (unknown) components: - tcp_A; sink_A - tcp_B; sink_B- tcp_C; sink_C- Queue_A- Queue_B§ You must figure out what these components implement (give reasons)26Task 2§ The black-box components DO NOT work with the normal NS2 simulator§ A new “bns” executable has been provided- Run the executable on solaris- Type: “> ./bns myscript.tcl”§ Scripts- Scripts that simulate each component are provided- Can also write your own scripts using the black-box components if result from scripts are not clear1427Task 2: Details§ TCP- We will look at the following variants • Tahoe: slow-start + fast-retransmit • Reno: fast recovery• SACK: selective acknowledgements-
View Full Document