270 likes | 289 Vues
Network Simulator - NS. Introduction. Discrete Event Simulator Research on networks Wired, wireless TCP, UDP, multicast, unicast Web, telnet, ftp. Discrete Event Simulations. Real world is modeled by the occurance of events List of events List of events is visited sequentially
E N D
Introduction • Discrete Event Simulator • Research on networks • Wired, wireless • TCP, UDP, multicast, unicast • Web, telnet, ftp
Discrete Event Simulations • Real world is modeled by the occurance of events • List of events • List of events is visited sequentially • Virtual time • Single control thread
Ns Architecture • Object Oriented (C++, OTcl) • C++ for the objects: • Packet processing, NS kernel • Fast execution • OTcl for control: • Configuration of scenarios • Deals with objects in C++ • Fast to write and execute
Ns Architecture • OTcl (object Tcl) and C++share class hierarchy. • TclCL is the library which allows the sharing of functions and variables C++ C++/OTcl split objects otcl
variables: set x 10 puts “x é $x” Functions and expressions: set y [pow x 2] set y [expr x*x] control: if {$x > 0} { return $x } else { return [expr -$x] } while { $x > 0 } { puts $x incr x –1 } procedures: proc pow {x n} { if {$n == 1} { return $x } set part [pow x [expr $n-1]] return [expr $x*$part] } Lists, vectors, etc. Tcl
Class Person # constructor: Person instproc init {age} { $selfinstvar age_ set age_ $age } # method: Person instproc greet {} { $selfinstvar age_ puts “$age_ years old: How are you doing?” } # subclass: Class Kid -superclass Person Kid instproc greet {} { $selfinstvar age_ puts “$age_ years old kid: What’s up, dude?” } set a [new Person 45] set b [new Kid 15] $a greet $b greet OTCL
C++ and OTCL class ControleAdmissao{ public: ControleAdmissao(); private: int fluxos_admitidos; int fluxos_rejeitados; int tam_janela; int admitir_fluxo(Pacote *, int); int computar_estatisticas(); }
C++ and OTCL static class ControleAdmissaoClass: public TclClass{ public: ControleAD():TclClass(“CAdmissao”){ } TclObject * create(int argc, const char*cons*argv){ return(new ControleAdmissao()); } }class_controleadmissao;
C++ and OTCL C++ Admission_Control(){ ….. ….. bind(“tam_janela_”,&tam_janela); ….. } Script OTCL set cad [new CAdmissao] $cad set tam_janela_ 1s
Utilizando o ns Problem Output Analysis Modify Ns Simulation Model Run Simulation in Ns
Using Ns • Criate Event scheduler • Use trace • Design the network • Define Routing • Insert errors • Create transport connection • Create traffic
Event Scheduler • Create event scheduler set ns [new Simulator] • Schedule events $ns at <time> <event> • <event>: qualquer comando ns/tcl $ns at 5.0 “finish” • Initiate Scheduler $ns run
Trace and Monitoring • Trace of packets: • In every channel: $ns trace-all [open out.tr w] • In a specific channel: $ns trace-queue $n0 $n1 $tr <Event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr> + 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 + 0.94176 2 3 tcp 1000 ------- 0 0.0 3.0 26 41 d 0.94176 2 3 tcp 1000 ------- 0 0.0 3.0 26 41 + 0.95072 2 0 ack 40 ------- 0 3.0 0.0 14 29
Monitoring • Queue monitoring set qmon [$ns monitor-queue $n0 $n1 $q_f $sample_interval] • Collect statistical data $qmon set pdrops_ • Record a trace 29.000000000000142 0 1 0.0 0.0 4 4 0 1160 1160 0 • Flow monitoring set fmon [$ns_ makeflowmon Fid] $ns_ attach-fmon $slink $fmon $fmon set pdrops_
Trace and Monitoring • Visualize the trace in nam (network animator) $ns namtrace-all [open test.nam w] $ns namtrace-queue $n0 $n1
Creating the network • Nodes set n0 [$ns node] set n1 [$ns node] • Channels and queues $ns <link_type> $n0 $n1 <bandwidth> <delay> <queue_type> • <link_type>: duplex-link, simplex-link • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR, diffserv RED queues
Creating a LAN $ns make-lan <node_list> <bandwidth> <delay> <ll_type> <ifq_type> <mac_type> <channel_type> <ll_type>: LL <ifq_type>: Queue/DropTail, <mac_type>: MAC/802_3 <channel_type>: Channel
Routing • Unicast $ns rtproto <type> <type>: Static, Session, DV, cost, multi-path • Multicast $ns multicast (right after [new Simulator]) $ns mrtproto <type> <type>: CtrMcast, DM, ST, BST
Errors • Error Modulo 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] $ns lossmodel $loss_module $n0 $n1
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 CBR set src [new Application/Traffic/CBR] Exponential ou Pareto on-off set src [new Application/Traffic/Exponential] set src [new Application/Traffic/Pareto] Conection and Traffic
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 FTP set ftp [new Application/FTP] $ftp attach-agent $tcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp Traffic
Traffic • Trace driven set tfile [new Tracefile] $tfile filename <file> set src [new Application/Traffic/Trace] $src attach-tracefile $tfile <file>: • Binary format • Interarrival time (msec) and packet size (byte)
An Example #Create a simulator object set ns [new Simulator] #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 }
Na Example #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 0 1
An Example #Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run
Documents • http://www.isi.edu/nsnam/ns/ • ns Notes and Documentation • Tutorials (ns by Example) • Trace Graph – analysis of trces