1 / 25

Introduction to NS

Introduction to NS. Information. Main website http://www.isi.edu/nsnam/ Documentation, mailing list archive, tutorial Location of Source codes C++ files $NS-HOME/ns-allinone-2.28/ns-2.28 Tcl files $NS-HOME/ns-allinone-2.28/ns-2.28/tcl/lib. NS2 – Network Simulator .

jody
Download Presentation

Introduction to NS

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. Introduction to NS

  2. Information • Main website http://www.isi.edu/nsnam/ • Documentation, mailing list archive, tutorial • Location of Source codes • C++ files • $NS-HOME/ns-allinone-2.28/ns-2.28 • Tcl files • $NS-HOME/ns-allinone-2.28/ns-2.28/tcl/lib

  3. NS2 – Network Simulator • Event-Driven simulator • Maintain a sorted event queue • Dequeue head event • Packet arrival • Assign event to its handler • At TCP agent • Handler processes event • Update Window • Enqueue more events in the event queue • Schedule delivery of ACK

  4. Basic Model • Back-end C++ • Protocols & Framework • Front-end Otcl (Object-Oriented Tcl) • Scenarios • Split Object • Object created in otcl has a corresponding object in C++ • This tutorial only deals with otcl

  5. Tcl/OTcl Basics • Variables • set v1 10 • set v2 $v1 • Array (String indexed) • a($i) ≠ a( $i ) • Printing • puts $filename “string” (default filename is stdout) • Arithmetic Expressions • set value [expr $v1+($v2 * 5.2)] • Control Structures • if {condition} then {…….} • for {set i 0} {$i < 10} {incr i 2} {……} • Procedures • proc proc_name {arg1 arg2…} { ……}

  6. OTcl Basics (contd.) • Creating a class • Class class_name • Class class_name –superclass Base_class • Defining instance procedures • class_name instproc proc_name {args} {…..} • Defining instance variables • $self instvar variable_name (inside a class method) • Creating an instance • set new_inst [new class_name] • Using value of an instance variable • $new_inst set v1 10 or set v2 [$new_inst set v1]

  7. NS Communication Model • Nodes • Hosts, Routers • Links • Queue Management • Queue Monitoring • Agents • Protocol 2 1 3 TCP 5 4 TCP Sink

  8. Node Slide taken from Hung-Yun Hsieh’s tutorial n0 Port Classifier Addr Classifier Node entry dmux_ entry_ classifier_ Link 1 Link 2 Unicast Node

  9. n0 n1 duplex link n1 entry_ head_ enqT_ queue_ deqT_ link_ ttl_ drophead_ drpT_ tracing simplex link Link Slide taken from Hung-Yun Hsieh’s tutorial

  10. n0 n1 Port Classifier Addr Classifier 0 Node entry n1 entry_ dmux_ head_ 1 entry_ enqT_ queue_ deqT_ link_ ttl_ classifier_ drophead_ drpT_ Routing Slide taken from Hung-Yun Hsieh’s tutorial

  11. n0 n1 Port Classifier Addr Classifier 1 0 dmux_ 0 1 entry_ classifier_ Link n1-n0 Routing Slide taken from Hung-Yun Hsieh’s tutorial Port Classifier Addr Classifier dmux_ entry_ Link n0-n1 classifier_

  12. Agent/TCP Agent/TCPSink 0 0 agents_ agents_ 0 1 1 0 Transport Slide taken from Hung-Yun Hsieh’s tutorial n0 n1 Port Classifier Port Classifier dst_= 0.0 dst_= 1.0 Addr Classifier Addr Classifier dmux_ dmux_ entry_ Link n0-n1 entry_ classifier_ classifier_ Link n1-n0

  13. Application/FTP dst_=0.0 dst_=1.0 0 1 1 0 Application Slide taken from Hung-Yun Hsieh’s tutorial n0 n1 Port Classifier Port Classifier Agent/TCPSink Addr Classifier Addr Classifier Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ entry_ Link n0-n1 entry_ classifier_ classifier_ Link n1-n0

  14. dst_=0.0 dst_=1.0 0 1 1 0 Packet Flow Slide taken from Hung-Yun Hsieh’s tutorial n0 n1 Application/FTP Port Classifier Port Classifier Addr Classifier Addr Classifier Agent/TCP 0 0 Agent/TCPSink entry_ Link n0-n1 entry_ Link n1-n0

  15. Starting off… • Things common to all simulation scripts: • Create a new simulator object set ns [new Simulator] • Finish procedure proc finish { } { …….. exit 0 } • Last line $ns run

  16. set ns [new Simulator] proc finish { } { exit 0 } Topology set n1 [$ns node] set n2 [$ns node] $ns duplex-link $n1 $n2 1Mb 10ms DropTail Agents set a1 [new Agent/TCP] set a2 [new Agent/TCPSink] Attach and Connect Agents $ns attach-agent $n1 $a1 $ns attach-agent $n2 $a2 $ns connect $a1 $a2 Start and Finish Time $ns at 0.5 “$a1 advance 10” $ns at 1.5 “finish” $ns run Basic Script

  17. set ns [new Simulator] set nam_file [open out.nam w] $ns namtrace-all $nam_file proc finish {} { global ns nam_file $ns flush-trace close $nam_file exec nam out.nam & exit 0 } set n1 [$ns node] set n2 [$ns node] $ns duplex-link $n1 $n2 1Mb 10ms DropTail set a1 [new Agent/TCP] set a2 [new Agent/TCPSink] $ns attach-agent $n1 $a1 $ns attach-agent $n2 $a2 $ns connect $a1 $a2 $ns at 0.5 “$a1 advance 10” $ns at 1.5 “finish” $ns run A more useful script

  18. Add a new procedure proc record-data { duration } { global datafile a1 ns # data format -- time bytes-received puts $datafile “[$ns now] [$a1 set ndatabytes_]” $ns after $duration “record-data $duration” } set datafile [open “datafile.dat” w] $ns at 0.5 “record-data 0.1” Recording Data

  19. More Complex Case • Bottleneck Link

  20. Topology for {set i 0}{$i < 4} {incr i} { set border($i) [$ns node] } for {set i 0}{$i < 2} {incr i} { set core($i) [$ns node] } $ns duplex-link $border(0) $core(0) 10Mb 5ms DropTail $ns duplex-link $border(1) $core(0) 10Mb 5ms DropTail $ns duplex-link $border(2) $core(1) 10Mb 5ms DropTail $ns duplex-link $border(3) $core(1) 10Mb 5ms DropTail $ns duplex-link $core(0) $core(1) 1Mb 5ms DropTail $ns queue-limit $core(0) $core(1) 20 set qmon [$ns monitor-queue $core(0) $core(1) “”]

  21. Agents set tcp [new Agent/TCP] $ns attach-agent $border(0) $tcp set tcpsink [new Agent/TCPSink] $ns attach-agent $border(3) $tcpsink set udp [new Agent/UDP] $ns attach-agent $border(1) $udp set lm [new Agent/LossMonitor] $ns attach-agent $border(2) $lm $tcp set fid_ 0 $udp set fid_ 1 $ns color 0 Red $ns color 1 Blue

  22. Sources • Attach traffic source to agents and connect set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set rate_ 2Mb set ftp [$tcp attach-app FTP] $tcp set packetSize_ 100 $ns connect $tcp $tcpsink $ns connect $udp $lm

  23. Data Collection proc record-data { duration } { global ns tcp tcp_file lm udp_file queue_file qmon puts $tcp_file “[$ns now] [expr [$tcp set ndatabytes_]/$duration]” $tcp set ndatabytes_ 0 puts $udp_file “[$ns now] [expr [$lm set bytes_]/$duration]” $lm set bytes_ 0 puts $queue_file “[$ns now] [$qmon set pkts_]” $ns after $duration “record-data $duration” }

  24. Other details set ns [new Simulator] # Nam, TCP-data, UDP-data, Queue-data files # Finish method # Topology # Agents # Sources # Data Collection $ns at 0.1 “$ftp start” $ns at 4.0 “$ftp stop” $ns at 1.0 “$cbr start” $ns at 2.0 “$cbr stop” $ns at 0.1 “record-data 0.1” $ns at 4.1 “finish” $ns run

  25. Things to Remember • Topology, agents, sources, start • Connect the agents • Slot not found error • Start/Stop the sources • In procedures, declare global variables before use • “$ns run”– last line

More Related