25
ns network simulator Edwin Hernandez January 19 th , 2001 Harris Lab Seminar

Ns network simulator

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Ns network simulator

ns network simulator

Edwin HernandezJanuary 19th, 2001

Harris Lab Seminar

                     

Page 2: Ns network simulator

Background on ns

• What’s ns– The VINT project : Virtual InterNet Testbed– UC Berkeley, Lawrence Berkeley National Lab,

USC/ISI, Xerox PARC, AT&T Research – http://www.isi.edu/nsnam/ns

• Download the full version, Linux, Solaris, current snapshots, there is a Win32 version.

• Languages used : C++, Otcl and TCL/TK• Current release : ns 2.1b7a, Harris Lab : ns2.1b6

Page 3: Ns network simulator

Characteristics of ns

• By using C++/Otcl, the network simulator is complete Object-oriented.

• C++ is used for data per packet events

• Otcl is used for periodic or triggered events

• The TCL interpreter: TclCL is the language used to provide a linkage between C++ and Otcl

Page 4: Ns network simulator

Installation process for ns

• Takes time to compile and configure!• Be careful with ./configure you must try to:

– ./configure --with-tclcl=../tclcl_dir –with-otcl=../

– Provide ../configure --help– make clean; make install (i.e. root in linux)

• Required ns-2, otcl, tclcl, tcl/tk8.0., nam (network animator)

Page 5: Ns network simulator

The starting point

• Lets create a two node simulation• First we proceed to create the scheduler

– set ns_ [new Simulator]

• The scheduler requires a set of events to process:– $ns_ at <time> <event>– Where event is anything in ns/tcl commands.– For example: puts “Hello World\n”;

• To start a simulation we can just execute– $ns_ run

Page 6: Ns network simulator

A test script for ns• Type in pico or vi.

• Test it with ns script.tcl– Will return “Hello World”

set ns_ [new Simulator]$ns_ at 1 “puts \”hello world\””$ns_ at 1.5 “exit”$ns_ run

Page 7: Ns network simulator

Creating the network nodes• Nodes

– set n0 [$ns_ node]– set n1 [$ns_ node]

• Links & Queuing– $ns duplex-link $n0 $n1 <bandwidth> <delay>

<queue_type>

– <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR

• Once we have the network configuration we can create some traffic.

Page 8: Ns network simulator

Creating TCP traffic

• Agent/TCP– set tcp [new Agent/TCP]

• We need a source of traffic

– set tcpsink [new Agent/TCPSink]• We need a sink for this traffic

– $ns attach-agent $n0 $tcp• We attach the TCP “agents” to the node source

– $ns attach-agent $n1 $tcpsink• We attach the TCPSink Agent to the node destination

– $ns connect $tcp $tcpsink• We connect both end points

Page 9: Ns network simulator

Creating TCP Traffic

• Application FTP– set ftp [new Application/FTP]– $ftp attach-agent $tcp– $ns at <time> “$ftp start”

• Application Telnet– set telnet [new Application/Telnet]– $telnet attach-agent $tcp

• Application HTTP– Client: set client [new HTTP/Client $ns_ $n0]– $client connect $server

– Server:set server [new HTTP/Server $ns_ $n1]– $server set-page-generator $pgp– For further details check chp. 34 of the ns manual

Page 10: Ns network simulator

Creating UDP traffic

• Agent/UDP is required– set udp [new Agent/UDP]– set null [new Agent/NULL] or– set lossMonitor [new Agent/LossMonitor]– $ns_ attach-agent $n0 $udp– $ns_ attach-agent $n1 $null– $ns_ connect $udp $null or– $ns_ connect $udp $lossMonitor

• The Agent/LossMonitor can monitor number of packets transferred, as well as packets lost.

• A procedure can be scheduled to poll the LossMonitor every T seconds and obtain throughput information.

Page 11: Ns network simulator

Polling the LossMonitor

proc record {sink} { global fthrput fpcklost #Get an instance of the simulator set ns [Simulator instance] #Set the time for polling set time 0.25 #How many bytes have been received by the traffic

set bw1 [$sink set bytes_] set lpkts [$sink set nlost_] set now [$ns now] puts $fthrput "$now [expr $bw1/$time*8]" puts $fpcklost "$now $lpkts" #Reset the bytes_ values on the traffic sinks $sink set bytes_ 0 $sink set nlost_ 0 #Re-schedule the record function $ns at [expr $now+$time] "record sink" }

Page 12: Ns network simulator

Creating UDP traffic

• CBR : Constant Bit Rate, back-to-back transfers.– set cbr [new Application/Traffic/CBR]– $cbr_ set packetSize_ 512– $cbr_ set interval_ 0.1 – $cbr_ set random_ 1– $cbr_ set maxpkts_ 1000000– $cbr_ attach-agent $udp– $ns_ connect $udp $lossMonitor

• Exponential or Pareto on-off– set src [new Application/Traffic/Exponential]– set src [new Application/Traffic/Pareto]

Page 13: Ns network simulator

Creating UDP traffic

• Trace driven– set tfile [new Tracefile]– $tfile filename <file>– set traceSrc [new Application/Traffic/Trace]– $traceSrc attach-tracefile $tfile

• <file>:– Binary format– inter-packet time (msec) and packet size (byte)

• We need also to schedule the traffic with, ns_ at “cbr start”

Page 14: Ns network simulator

Wireless extensions

• IEEE 802.11 can be simulated, Mobile-IP, and adhoc protocols such as DSR, TORA, DSDV and AODV.

• CMU provides tools to create traffic patterns and scenario files.

• Special trace-file format for wireless packets, very detailed. Drawback: Files are extremely big. (100’s of Mbytes for 1000 sec of simulation)

Page 15: Ns network simulator

Simulation of two wireless nodes

• A simple simulation for two nodes and no infrastructure we need to configure the nodes first (in ns2.1b7).– $ns_ node-config -adhocRouting $opt(rp) \– -llType $opt(ll) \– -macType $opt(mac) \– -ifqType $opt(ifq) \– -ifqLen $opt(ifqlen) \– -antType $opt(ant) \– -propType $$opt(prop) \– -phyType $val(netif) \– -channelType $chan \– -topoInstance $topo \– -agentTrace ON \– -routerTrace OFF \– -macTrace OFF

Page 16: Ns network simulator

Simple wireless simulation

• Array opt( )– set opt(chan) Channel/WirelessChannel ;# channel type– set opt(prop) Propagation/TwoRayGround ;# radio-propagation – set opt(netif) Phy/WirelessPhy ;# network interface – set opt(mac) Mac/802_11 ;# MAC type– set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type– set opt(ll) LL ;# link layer type– set opt(ant) Antenna/OmniAntenna ;# antenna model– set opt(ifqlen) 50 ;# max packet in ifq– set opt(rp) DSDV ;# routing protocol

Page 17: Ns network simulator

Configuring the wireless/phy

• Phy/WirelessPhy set CPThresh_ 10.0• Phy/WirelessPhy set CSThresh_ 1.559e-11• Phy/WirelessPhy set RXThresh_ 3.652e-10• Phy/WirelessPhy set Rb_ 2*1e6• Phy/WirelessPhy set Pt_ 0.2818• Phy/WirelessPhy set freq_ 914e+6

Page 18: Ns network simulator

Important initialization variables

• set topo [new Topography]

• $topo load_flatgrid $opt(x) $opt(y) ;– opt(x) and opt(y) are the dimensions of the

simulation area• set chan [new $opt(chan)]• Create-god Number_of_entities

Page 19: Ns network simulator

Creating the mobile nodes

• Set mobile node– set Mnode [dsdv-create-mobile-node <node_id>]– Or set Mnode [$ns_ node <node_id>]

• Attach it to the topography– $node topography $topo

• Determine the motion pattern and initial position• $node random-motion 0 #; no random• $node set Z_ 0.000000• $node set Y_ 100.0000• $node set X_ 2.000000

Page 20: Ns network simulator

Adding movement to the nodes

• Random set to 0 – $ns at <time> “$node setdest <x> <y> <speed>”

• Random set to 1– $ns at <time> “$node start”

Page 21: Ns network simulator

Tracing the node movement and traffic information

• Trace packets on all links (Old Trace format)– $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 0r 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]

• Due the size of trace files, $ns_ trace-all [ open “|gzip –c > out.tr.gz” w]|

• Or $ns_ trace-all [open “awk –f awkScript > output.tr” w]

Page 22: Ns network simulator

New trace format

• Activating trace/nam files– $ns_ trace-all $tracefd– $ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)– $ns_ use-newtrace

• New trace file sample– r 1499.998807 5 4 cbr 532 ------- 0 1.0.1.2 0.0.0.2 163975 235152– d -t 1500.000000000 -Hs 5 -Hd 16777216 -Ni 5 -Nx 2.00 -Ny 1500.00 -Nz

0.00 -Ne -1.000000 -Nl IFQ -Nw END -Ma a2 -Md 5 -Ms 5 -Mt 800 -Is 16777216.0 -Id 4194305.0 -It udp -Il 92 -If 0 -Ii 198410 -Iv 32

• S: send, r: received, d: dropped, -t <time>, -Is: node source, -Id: destination, -Ii: packet ID, -Nl: cause of dropped –Nw: cause of dropped –Nx: position in x, - Ny: positon in y. etc. More details in Chp. 16 of the NS manual.

Page 23: Ns network simulator

We can visualize the trace/nam files

Network animator screenshots of an ad-hoc network simulation(courtesy of S. Shah)

Page 24: Ns network simulator

ns-2 can be modified• Any modification to the source code of NS can be

followed by a make distclean: make all command to make effective all the changes.

• We can modify the propagation model by making changes to tworayground.cc and tworayground.hclass TwoRayGround : public Propagation {public: TwoRayGround(); virtual double Pr(PacketStamp *tx, PacketStamp *rx,

WirelessPhy *ifp);

protected: double TwoRay(double Pt, double Gt, double Gr, double ht,

double hr, double L$ double last_hr, last_ht; double crossover_dist;};

Page 25: Ns network simulator

For more internals and how to modify ns

• Check the NS manual: http://www.isi.edu/nsnam/ns/doc/ns_doc.pdf

• Tutorial by Marc Greis: http://www.isi.edu/nsnam/ns/tutorial/index.html

• This tutorial is very good for ns internalshttp://www.isi.edu/nsnam/dist/ns-workshop00/