Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files.

Similar presentations


Presentation on theme: "Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files."— Presentation transcript:

1 Introduction to NS

2 Information Main website 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 TCP TCP Sink

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

9 Link n0n1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_ tracing simplex link duplex link Slide taken from Hung-Yun Hsieh’s tutorial

10 Routing n0n1 Addr Classifier Port Classifier classifier_ dmux_ entry_ Node entry 0 1 enqT_queue_deqT_ drophead_ drpT_ link_ttl_ n1 entry_ head_ Slide taken from Hung-Yun Hsieh’s tutorial

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

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

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

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

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 Basic Script 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

17 A more useful script 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

18 Recording Data 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”

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


Download ppt "Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files."

Similar presentations


Ads by Google