Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast.

Similar presentations


Presentation on theme: "LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast."— Presentation transcript:

1 LAB 3 NS2 Preliminaries

2 Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast Creating Wireless Nodes

3 Fundamentals of TCL A string-based command language. A few fundamental constructs and relatively little syntax, which makes it easy to learn. Designed to be a glue that assembles software building blocks into applications. Tcl is interpreted when the application runs. The interpreter makes it easy to build and refine your application in an interactive manner.

4 Example Script command arg1 arg2 arg3... puts stdout {Hello, World!}  Hello World! set a World puts stdout ”Hello $a! ” $a  Hello World! set b a  b = a set b $a  b = World set len [string length ns2work]  len = 7 set pi [expr 2*asin(1.0)]

5 Example Script proc name arglist body proc Diag {a b} { set c [expr sqrt($a * $a + $b * $b)] return $c } proc Factorial {x} { set i 1; set product 1 while {$i <= $x} { set product [expr $product * $i] incr i } return $product }

6 Basic otcl Class mom mom instproc init {age} { $self instvar age_ set age_ $age } mom instproc greet {} { $self instvar age_ puts “$age_ years old mom: How are you doing?” } Class kid -superclass mom kid instproc greet {} { $self instvar age_ puts “$age_ years old kid: What’s up, dude?” } set a [new mom 40] set b [new kid 10] $a greet  40 years old mom: How are you doing? $b greet  10 years old kid: What's up?

7 Creating Event Scheduler Create scheduler –set ns [new Simulator] Schedule event –$ns at – : any legitimate ns/tcl commands Start scheduler –$ns run

8 Tracing Trace packets on all links $ns trace-all [open test.out w] -- + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 r 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]

9 Creating Network Nodes set n0 [$ns node] set n1 [$ns node] Links & Queuing $ns duplex-link $n0 $n1 – : DropTail, RED, CBQ, FQ, SFQ, DRR $ns_ duplex-link-op

10 Computing routes Unicast –$ns rtproto – : Static, Session, DV, Manual $ns rtproto Static $ns rtproto Session $ns rtproto DV $n1 $n2 $n3 $ns rtproto LS $n1 $n2

11 Creating Connection: UDP UDP set udp [new Agent/UDP] set null [new Agent/NULL] $ns attach-agent $n0 $udp $ns attach-agent $n1 $null $ns connect $udp $null

12 Creating Connection: TCP TCP set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink

13 Creating Traffic: On Top of TCP FTP set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at “$ftp start” Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp

14 Creating Traffic: On Top of UDP CBR set src [new Application/Traffic/CBR] Exponential or Pareto on-off set src [new Application/Traffic/Exponential] set src [new Application/Traffic/Pareto] $src set packetSize_ 210 $src set burst_time_ 500ms $src set idle_time_ 500ms $src set rate_ 200k

15 Creating Traffic: Trace Driven Trace driven set tfile [new Tracefile] $tfile filename set src [new Application/Traffic/Trace] $src attach-tracefile $tfile : –Binary format –inter-packet time (msec) and packet size (byte)

16 Inserting Errors Creating Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] Inserting Error Module $ns lossmodel $loss_module $n0 $n1

17 Network Dynamics Link failures –route changes reflected automatically –can emulate node failure

18 Four Models $ns rtmodel-at $n0 $n1 $ns rtmodel Trace $n0 $n1 $ns rtmodel $n0 $n1 : Deterministic, Exponential : [ ] [ ]

19 $ns rtmodel Exponential 0.8 1.0 1.0 $n1 $ns rtmodel Trace dynamics.trc $n2 $n3 v v 0.8123 link-up 3 5 v 3.5124 link-down 3 5 $ns rtmodel Deterministic 20.0 20.0 $node(1) $node(5)

20 Multicast - 5 components enable multicast capability configure multicast routing create a multicast group/sender create a multicast receiver attach traffic source

21 Enabling multicast capability set ns [new Simulator -multicast on] or $ns multicast (right after [new Simulator])

22 Configuring multicast routing $ns mrtproto : CtrMcast, DM, ST

23 Creating a multicast group set udp [new Agent/UDP] $ns attach-agent $n0 $udp set group [Node allocaddr] $udp set dst_addr_ $group

24 Creating a multicast receiver set rcvr [new Agent/NULL] $ns attach-agent $n1 $rcvr $ns at “$n1 join-group $rcvr $group”

25 Attaching a traffic source set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $ns at “$cbr start”

26 Case Study mcast.tcl

27 Wireless - 5 components setup node configuration –layer 3-2, layer 1, tracing, energy node coordinates node movements nam tracing

28 Setup set ns [new Simulator] set topo [new Topography] $topo load_flatgrid

29 Node Configuration: Layer 3-2 $ns node-config –adhocRouting –llType LL –ifqType Queue/DropTail/PriQueue –ifqLen –macType Mac/802_11 : DSDV, DSR, TORA, AODV

30 Node Configuring: Layer 1 $ns node-config –phyType Phy/WirelessPhy –antType Antenna/OmniAntenna –propType –channelType Channel/WirelessChannel –topoInstance $topo : Propagation/TwoRayGround, Propagation/FrissSpaceAttenuation

31 Node Configuration: Tracing $ns node-config –agentTrace –routerTrace –macTrace

32 Node Configuration: Energy $ns node-config –energyModel EnergyModel –initialEnergy –txPower –rxPower

33 Creating Nodes set mnode [$ns node]

34 Node Coordinates $mnode set X_ $mnode set Y_ $mnode set Z_ 0

35 Node Movement Disable random motion –$mnode random-motion 0 Specified –$ns at 1.0 “$mnode setdest ” Random –$ns at 1.0 “$mnode start”

36 Tracing at the beginning –$ns namtrace-all-wireless [open test.nam w] initialize nodes –$ns initial_node_position $mnode 20 at the end –$ns at “$ns nam-end-wireless ”

37 New Trace format $ns use-newtrace Event type –s: send, r: receive, d: drop, f: forward Node property tags –-Ni: node id, -Nx: node’s x-coordinate, -Ny: node’s y-coordinate, -Nz: node’s z-coordinate –-Ne: node energy level –-Nl: trace level, such as AGT, RTR, MAC –-Nw: reason for the event.

38 Case Studies multicast (mcast.tcl) wireless (wireless-udp.tcl)


Download ppt "LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast."

Similar presentations


Ads by Google