Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS Tutorial (For CMPE 252 A) By Duy Nguyen 10/25/2012.

Similar presentations


Presentation on theme: "NS Tutorial (For CMPE 252 A) By Duy Nguyen 10/25/2012."— Presentation transcript:

1 NS Tutorial (For CMPE 252 A) By Duy Nguyen 10/25/2012

2 What is NS-2? A discrete event simulator targeted at networking research Written in C++ and OTcl(OO of Tcl) OTcl usage: –Configuration and setup –Manipulating existing C++ objects C++ usage: –Anything that requires processing each packet of a flow –Change behavior of existing C++ class

3 Getting NS-2 Go to Download an ns-allinone package $ tar –zxf ns-allinone-2.34.tar.gz $ cd ns-allinone-2.34 &&./install Follow the instructions for setting up the environments: setenv LD_LIBRARY_PATH /cse/grads/duy/ns-allinone- 2.34/otcl-1.13:/cse/grads/duy/ns-allinone-2.34/lib setenv TCL_LIBRARY /cse/grads/duy/ns-allinone- 2.34/tcl8.4.18/library $ cd ns-2.34;./validate

4 NS-2 initialization # create simulator set ns [new Simulator] # Open trace file set tracefile [open out.tr w] $ns trace-all $tracefile # Open trace file $set namefile [open out.nam w] $ns nametrace-all $namefile

5 # define a finish procedure proc finish {} { global ns tracefile namefile $ns flush-trace close $tracefile close $namfile exec nam out.nam & exit 0 } # calling finish procedure at 125 $ns at “finish” # Run simulation $ns run

6 # Create nodes set n0 [$ns node] set n1 [$ns node] #available queues: RED, FQ, DRR, SFO,CBQ. $ns duplex-link $n0 $n1 10Mb 10ms DropTail #a unidirectional link $ns simplex-link $n0 $n1 10Mb 10m # Set queue size limit on the link to 50 $ns queue-limit $n0 $n2 50 NS-2 Create Nodes and Links

7 # Set up a TCP connection for node 0 setup tcp [new Agent/TCP] $ns attach-agent $n0 $tcp # Create a sink agent for node 1 set sink [new Agent/TCPSink] $ns attach-agent $ns1 $sink #Now connect them $ns connect $tcp $sink # Set packet size $ns set packetSize_ 512 NS-2 Agents and Applications

8 # Set FTP over TCP connection # FTP uses TCP/IP set ftp [new Application/FTP] $ftp attach-agent $tcp # Setting up UDP connection set udp [new Agent/UDP] $ns attach-agent $n0 $udp set null [new Agent/Null] $ns attach-agent $n1 $null $ns connect $udp $null # Set up CBR over UDP connection Set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set rate_.01Mb

9 # introduce noise $cbr set random_ true # interval between transmission of packets $cbr interval_.005 # set packet Size $cbr set packetSize_ 512

10 # Format $ns at # Examples $ns at 1.0 “$cbr start” $ns at 3.0 “$ftp start” $ns at 95.0 “$cbr stop” $ns at “$ftp stop” #a unidirectional link $ns simplex-link $n0 $n1 10Mb 10m Scheduling Events

11 # Format #Please see Trace File

12 cbr cbr r cbr cbr cbr cbr cbr tcp tcp r cbr r cbr cbr r tcp tcp cbr cbr r cbr cbr cbr cbr r cbr cbr cbr cbr

13 Comments on the tracefile There are current old and new trace format, select one which is most suitable. Need to write your own script for processing data from the trace file i.e. throughput, delay etc Awk, perl, grep are some of the tools Need to specify how the throughput and delay are obtained. For example: –Throughput is the number of successful packets received multiply by the packet length and divided by the total simulation time –Delay is difference between the time a packet arrives at the queue and the time a packet gets transmitted successfully

14 Plotting graphs Matlab, Xgraph, and many other tools I personally use an awk script to extract throughput, delay, etc information and use Microsoft Excel to graph them.

15 set opt(chan) Channel/WirelessChannel; set opt(prop) Propagation/TwoRayGround; set opt(netif) Phy/WirelessPhy; set opt(mac) Mac/802_11; set opt(ifq) Queue/DropTail/PriQueue; set opt(ll) LL ;#link layer set opt(ant) Antenna/OmniAntenna; set opt(ifqlen) 50 ;# queue length set opt(nn) 36 ;# number of nodes set opt(flow) 3 set opt(row) 6 ;#for grid set opt(column) 6 #set opt(adhocRouting) DSDV ;# routing protocol set opt(adhocRouting) DumbAgent ;# disable routing set opt(cp) "" ;# connection pattern set opt(sc) "" ;# node movement set opt(x) 400 ;# x coordinate of topology set opt(y) 400 ;# y coordinate of topology set opt(seed) 0 ;# seed for random number gen set opt(stop) 50 ;# time to stop simulation Wireless Simulation

16 # Create topography object set topo [new Topography] # define topology $topo load_flatgrid $opt(x) $opt(y) # configure for base-station node $ns_ node-config -adhocRouting $opt(adhocRouting) -llType $opt(ll) -macType $opt(mac) -ifqType $opt(ifq) -ifqLen $opt(ifqlen) -antType $opt(ant) -propType $opt(prop) -phyType $opt(netif) -channelType $opt(chan) -topoInstance $topo -agentTrace ON -routerTrace OFF -macTrace ON -movementTrace OFF

17 # create God for monitoring all nodes create-god [expr $opt(nn)] # Creating mobile nodes for {set j 0} {$j < $opt(nn)} {incr j} { set node_($j) [$ns_ node] } # define node’s fixed position for {set j 0} {$j < $opt(row)} {incr j} { for {set i 0} {$i < $opt(column)} {incr i} { $node_([expr $j * $opt(column) + $i]) set X_ [expr $i * 10] $node_([expr $j * $opt(column) + $i]) set Y_ [expr $j * 10] $node_([expr $j * $opt(column) + $i]) set Z_ 0 }

18 # setting up connection for {set k 1} {$k <= $opt(flow)} {incr k} { set udp_($k) [new Agent/UDP] $ns_ attach-agent $node_([expr $l + 0]) $udp_($k) set null_($k) [new Agent/Null] $ns_ attach-agent $node_([expr $l + 1]) $null_($k) set cbr_($k) [new Application/Traffic/CBR] $cbr_($k) set packetSize_ $pktsize $cbr_($k) set interval_ $inter $cbr_($k) set random_ 1 $cbr_($k) attach-agent $udp_($k) $ns_ connect $udp_($k) $null_($k) $ns_ at 9.8 "$cbr_($k) start" $ns_ at 30.0 "$cbr_($k) stop" set l [expr $l + 2] }

19 # Tell all nodes when the simulation ends for {set i 0} {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop).0 "$node_($i) reset"; } $ns_ at $opt(stop).0004 "stop" $ns_ at $opt(stop).0005 "puts \"NS EXITING...\" ; $ns_ halt"

20 # Available in ~ns/indep-utils/cmu-scen-gen # Format ns cbrgen.tcl [-type cbr|tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] # CBR 20 nodes, max 8 connections, seed value 1.0 and a rate of 4.0, output to cbr-20-test ns cbrgen.tcl -type cbr -nn 20 -seed 1.0 -mc 8 -rate 4.0 > cbr-20-test Generating traffic-connection

21 # Available in ~ns/indep-utils/cmu-scen-gen/setdest and consists of setdest{.cc,.h} and Makefile # Format./setdest [-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] [-x maxx] [-y maxy] > [outdir/movement- file] # 20 nodes, maximum speed of 10.0m/s, an average pause between movement being 2s../setdest -n 20 -p 2.0 -s t 200 -x 500 -y 500 > scen-20-test #Specify traffic-connection and node-movement in script set opt(cp) "tcl/mobility/scene/cbr-20-test" set opt(sc) "tcl/mobility/scene/scen-20-test" Generating node-movement file

22 New protocols See Chapter of NS Manual for better understanding of C++ and Otcl Linkage between the C++ code and Tcl code(if you modify an already existing protocol, no need) Add new protocols Make changes to makefile(.cc) or ~ns/tcl/lib/ns- lib.tcl(.tcl) $make clean &&./configure --enable-debug && make

23 Other features Emulation (nice complement with your simulation) NS-Click (Modular router) Sensor-nets Satellite …

24 More Help Use Nam visual tool to aid in visualizing the networks (not really essential) Check out other tutorials in reference section Sign up for NS user mailing list –http://www.isi.edu/nsnam/ns/ns-lists.htmlhttp://www.isi.edu/nsnam/ns/ns-lists.html Documentation(most comprehensive source): – Very detailed tutorial: k/ k/

25 References NS-2 page-- Detailed NS-2 tutorial--http://www- sop.inria.fr/members/Eitan.Altman/COURS -NS/n3.pdfhttp://www- sop.inria.fr/members/Eitan.Altman/COURS -NS/n3.pdf Marc Greis’ tutorial html NS-2 by examples--

26 NS-3 An open source project building a new network simulator to replace ns-2

27 ns-3 is a new simulator, without backward compatibility Similarities to ns-2: C++ software core GNU GPLv2 licensing ported ns-2 models: random variables, error models, OLSR, Calendar Queue scheduler, (more planned) Differences: Python scripting (or C++ programs) replaces OTcl most of the core rewritten also based on the yans and GTNetS simulators new animators, configuration tools, etc. are in work

28 ns-3 follows a Linux architecture class NetDevice class Ipv4Protocol Linux corollaries –each NetDevice is modelled like struct net_device –each layer-3 protocol has a struct in_device component for each NetDevice –this interface (transmit side) is aligned with Linux dev_queue_xmit() –on receive side, demux is modelled after Linux protocol handlers

29 Software Integration Do not reimplement models and tools for which open-source implementations abound ns-3 conforms to standard input/output formats so that other tools can be reused. –e.g., pcap trace output, ns-2 mobility scripts ns-3 is adding support for running implementation code –Network Simulation Cradle integration has met with success: Linux TCP code –ns-3 “process” API

30 Instructions Go to and download current ns-3http://www.nsnam.org/ $ wget https://www.nsnam.org/release/ns- allinone-3.15.tar.bz2https://www.nsnam.org/release/ns- allinone-3.15.tar.bz2./build.py --enable-examples --enable-tests –This script will build everything Also:./waf clean;./waf -d optimized --enable- examples --enable-tests configure;./waf –Replace ‘optimized’ with ‘debug’ for enabling debug messages

31 Sample Browse examples for sample scenarios. Try simple- global-routing // n0 // \ 5 Mb/s, 2ms // \ 1.5Mb/s, 10ms // n n3 // / // / 5 Mb/s, 2ms // n1 CBR/UDP flows from n0 to n3, and from n3 to n1 FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. UDP packet size of 210 bytes, with per-packet interval sec.

32 Sample To run:./waf --run simple-global-routing Output: pcap files and trace.tr files To view pcap files: –tcpdump -nn -tt -r filename.pcap

33 Sample tcpdump -nn -tt -r simple- global-routing-1-1.pcap reading from file simple-global-routing-1-1.pcap, link-type PPP (PPP) IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length IP > : UDP, length 512

34 Final comments Since ns-3 is a new network simulator, it does not have as many network models as ns-2. For wireless simulations: use ns-3 –Wireless Routing, Rate Adaptation For wired simulations: use ns-2 –Distance Vector (RIP): routing/rtProtoDV.cc –Link State: linkstate/

35 References NS-3 page-- Detailed NS-2 tutorial--http://www- sop.inria.fr/members/Eitan.Altman/COURS- NS/n3.pdfhttp://www- sop.inria.fr/members/Eitan.Altman/COURS- NS/n3.pdf Slides from Tom Henderson’s talk UW-EE Documentationhttp://www.nsnam.org/documenta tion/http://www.nsnam.org/documenta tion/ Tutorial: singlehtml/index.html singlehtml/index.html Contact: Duy Nguyen duy att soe.ucsc.edu

36 Qualnet RIP Tutorials links


Download ppt "NS Tutorial (For CMPE 252 A) By Duy Nguyen 10/25/2012."

Similar presentations


Ads by Google