1 / 38

LAB 3 NS2 Preliminaries

LAB 3 NS2 Preliminaries. Contents. TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast Creating Wireless Nodes. Fundamentals of TCL. A string-based command language.

lilac
Download Presentation

LAB 3 NS2 Preliminaries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LAB 3NS2 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. Class mom mom instproc init {age} { $selfinstvar age_ set age_ $age } mom instproc greet {} { $selfinstvar age_ puts “$age_ years old mom: How are you doing?” } Class kid -superclass mom kid instproc greet {} { $selfinstvar age_ puts “$age_ years old kid: What’s up, dude?” } set a [new mom 40] set b [new kid 10] Basic otcl $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 <time> <event> • <event>: any legitimate ns/tcl commands • Start scheduler • $ns run

  8. Tracing • Trace packets on all links $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 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 <bandwidth> <delay> <queue_type> • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR $ns_ duplex-link-op <n1> <n2> <op> <args>

  10. Computing routes • Unicast • $ns rtproto <type> • <type>: 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 <time> “$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 <file> set src [new Application/Traffic/Trace] $src attach-tracefile $tfile • <file>: • 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 <time> <up|down> $n0 $n1 • $ns rtmodel Trace <config_file> $n0 $n1 • $ns rtmodel <model> <params> $n0 $n1 • <model>: Deterministic, Exponential • <params>: [<start>] <up_interval> <down_interval> [<finish>]

  19. $ns rtmodel Exponential 0.8 1.0 1.0 $n1 <[start time], up interval, down interval, [finish time]> $ns rtmodel Trace dynamics.trc $n2 $n3 • v <time> <link-operation> <node1> <node2> 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 <type> • <type>: 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 <time> “$n1 join-group $rcvr $group”

  25. Attaching a traffic source • set cbr [new Application/Traffic/CBR] • $cbr attach-agent $udp • $ns at <time> “$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 <length> <width>

  29. Node Configuration: Layer 3-2 • $ns node-config • adhocRouting <adhoc routing type> • llType LL • ifqType Queue/DropTail/PriQueue • ifqLen <queue length> • macType Mac/802_11 • <adhoc routing type>: DSDV, DSR, TORA, AODV

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

  31. Node Configuration: Tracing • $ns node-config • agentTrace <ON or OFF> • routerTrace <ON or OFF> • macTrace <ON or OFF>

  32. Node Configuration: Energy • $ns node-config • energyModel EnergyModel • initialEnergy <total energy> • txPower <energy to transmit> • rxPower <energy to receive>

  33. Creating Nodes • set mnode [$ns node]

  34. Node Coordinates • $mnode set X_ <x> • $mnode set Y_ <y> • $mnode set Z_ 0

  35. Node Movement • Disable random motion • $mnode random-motion 0 • Specified • $ns at 1.0 “$mnode setdest <x> <y> <speed>” • Random • $ns at 1.0 “$mnode start”

  36. Tracing • at the beginning • $ns namtrace-all-wireless [open test.nam w] <length> <width> • initialize nodes • $ns initial_node_position $mnode 20 • at the end • $ns at <end time> “$ns nam-end-wireless <end time>”

  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)

More Related