NS-2 Ing. Alessandro Leonardi Dipartimento di Ingegneria Informatica e delle Telecomunicazioni Università degli Studi di Catania
Outline Introduzione Oggetti ns Esempi Wireless World in NS-2 DIIT - A. Leonardi 2
NS-2 (Network Simulator ver.2) Simulatore di reti a pacchetto di tipo ad eventi discreti FREEWARE Sorgenti disponibili Meno user friendly di altri simulatori di tipo commerciale DIIT - A. Leonardi 3
NS-2 (Network Simulator ver.2) Sviluppato nella Berkeley University dipartimento di Computer Science In continua evoluzione, aggiornato da ricercatori, studenti e grandi aziende Bluetooth è stato inserito da IBM DiffServ da Nortel DIIT - A. Leonardi 4
NS-2 (Network Simulator ver.2) Applicazioni simulazioni reti wired simulazioni reti wireless e satellitari simulazioni protocolli routing generatori di traffico gestione code DIIT - A. Leonardi 5
NS-2 (Network Simulator ver.2) simulazione in ns descrivere lo scenario simulativo (nodi, link, sorgenti) eseguire la simulazione visualizzare i risultati DIIT - A. Leonardi 6
NS-2 (Network Simulator ver.2) lo scenario simulativo viene descritto tramite uno script il linguaggio utilizzato è OTcl (Tcl ad oggetti) il software che permette la simulazione è in linguaggio C++ esiste una interconnessione tra OTcl e C++ gli oggetti utilizzati nello script in Tcl sono interconnessi con gli oggetti C++ DIIT - A. Leonardi 7
NS-2 (Network Simulator ver.2) set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] $ns duplex-link $n0 $n2 5Mb 10ms DropTail $ns duplex-link $n1 $n2 5Mb 10ms DropTail $ns duplex-link $n2 $n3 1Mb 10ms DropTail DIIT - A. Leonardi 8
NS-2 (Network Simulator ver.2) esecuzione delle simulazione > ns nomefile.tcl NS viene fornito in codice sorgente da compilare già compilato (windows) www.isi.edu/nsnam DIIT - A. Leonardi 9
NS-2 (Network Simulator ver.2) visualizzazione dei risultati tramite dei file di trace, in cui si specifica al simulatore cosa monitorare file di trace standard, che rappresentano tutti gli eventi durante la simulazione off-line si possono elaborare statisticamente i risultati DIIT - A. Leonardi 10
NS-2 (Network Simulator ver.2) animazione può essere generato un file che permette di visualizzare una animazione della simulazione mediante il NAM (Network Animator Module) DIIT - A. Leonardi 11
NS-2 (Network Simulator ver.2) Analisi script Tcl Interprete Tcl Librerie NS in C++ Risultati della simulazione Animazione Nam DIIT - A. Leonardi 12
Oggetti ns Oggetto Simulator set ns [new Simulator] una volta creata la variabile, viene utilizzata facendo precedere al nome il simbolo $ $ns Nodi sono gestiti da Simulator e vengono creati con il seguente comando set n0 [$ns node] set n1 [$ns node] le due variabili n0 e n1 consentono di manipolare i due nodi nello script DIIT - A. Leonardi 13
Oggetti ns Link i nodi possono essere collegati da link esistono due tipi di link simplex-link (monodirezionale) duplex-link (bidirezionale) sintassi $ns duplex-link $n0 $n1 1Mb 10ms Droptail $ns duplex-link <nodo 1> <nodo 2> <bandwidth> <delay> <queue type> DIIT - A. Leonardi 14
Oggetti ns è possibile stabilire la lunghezza del buffer in pacchetti $ns queue-limit $n0 $n1 10 esiste un modulo di errore che permette di simulare una probabilità di perdita su link DIIT - A. Leonardi 15
Agenti/Applicazioni servono a creare la parte attiva della rete che gestisce il traffico Agent livello di trasporto (TCP, UDP) Application generatori di traffico (FTP, CBR, VBR) DIIT - A. Leonardi 16
Agent/UDP Agent/UDP set UDP0 [new Agent/UDP] l Agent deve essere collegato ad un nodo $ns attach-agent $n0 $UDP0 ad un altro Agent con cui scambiarsi i dati Agent/Null è un ricevitore passivo set Null0 [new Agent/Null] $ns attach-agent $n1 $Null0 collegamento tra i due Agent $ns connect $UDP0 $Null0 DIIT - A. Leonardi 17
Agent/UDP parametri dimensione massima del pacchetto (byte) $UDP0 set packetsize_ 100 identificativo del flusso di pacchetti $UDP0 set fid_ 1 DIIT - A. Leonardi 18
Agent/TCP Agenti TCP implementati TCP Tahoe Agent/TCP TCP Reno Agent/TCP/Reno TCP NewReno Agent/TCP/Newreno TCP Vegas Agent/TCP/Vegas TCP Sack Agent/TCP/Sack1 TCP Fack Agent/TCP/Fack DIIT - A. Leonardi 19
Agent/TCP Agent/TCP/Newreno set tcp0 [new Agent/TCP/Newreno] $ns attach-agent $n0 $tcp0 Receiver Agent/TCPSink set tcpsink0 [new Agent/TCPSink] $ns attach-agent $n1 $tcpsink0 Agent/TCPSink/Sack1 Agent/TCPSink/DelAck collegamento tra i due Agent $ns connect $tcp0 $tcpsink0 DIIT - A. Leonardi 20
Agent/TCP parametri receiver window $tcp0 set window_ 20 dimensione pacchetto $tcp0 set packetsize_ 20 identificatore flusso $tcp0 set fid_ 2 altri parametri nelle varie versioni TCP DIIT - A. Leonardi 21
Applicazione/CBR Application/Traffic/CBR genera pacchetti di lunghezza fissa ad intervalli costanti set CBR0 [new Application/Traffic/CBR] deve essere collegata ad un Agent $CBR0 attach-agent $UDP0 DIIT - A. Leonardi 22
Applicazione/CBR parametri rate di emissione dei pacchetti $CBR0 set rate_ 128 Kb $CBR0 set packetsize_ 100 DIIT - A. Leonardi 23
Applicazione/FTP Application/FTP simula il trasferimento di file di grosse dimensioni set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 DIIT - A. Leonardi 24
Eventi dinamica della simulazione la riga finale in ogni script che fa partire la simulazione è: $ns run tutte le sorgenti di traffico supportano i comandi start $ns at 0.5 $CBR0 start stop $ns at 1 $CBR0 stop per fermare la simulazione $ns at 10 exit 0 DIIT - A. Leonardi 25
Traccia è possibile ottenere un file di trace utile per l animazione in nam set nf [open nome_file.nam w] $ns namtrace-all $nf ed un file di trace che descrive tutti gli eventi del sistema set tf [open nome_file.out w] $ns trace-all $tf DIIT - A. Leonardi 26
Informazioni www.isi.edu/nsnam Tutorial di Marc Greis www.isi.edu/nsnam/ns/tutorial/ nella distribuzione ns-allinone Ns by examples http://nile.wpi.edu/ns DIIT - A. Leonardi 27
Esempio 1 rete con 3 nodi e 2 link CBR su protocollo UDP visualizzazione in nam UDP UDP 1 2 3 DIIT - A. Leonardi 28
Esempio 1 set ns [new Simulator] set nf [open esempio.nam w] $ns namtrace-all $nf proc finish{} { global ns nf $ns flush-trace close $nf exit 0 } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] continua DIIT - A. Leonardi 29
Esempio 1 $ns duplex-link $n0 $n1 1Mb 10ms Droptail $ns duplex-link $n1 $n2 1Mb 10ms Droptail set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set packetsize_ 500 $cbr0 set interval_ 0.05 set null0 [new Agent/Null] $ns attach-agent $n2 $null0 $ns connect $udp0 $null0 continua DIIT - A. Leonardi 30
Esempio 1 $ns at 0.5 $cbr0 start $ns at 4.5 $cbr0 stop $ns at 5.0 finish $ns run prova pratica! DIIT - A. Leonardi 31
Esempio 2 4 nodi e 3 link che li connettono, usando gli array n0 n2 n3 n1 DIIT - A. Leonardi 32
Esempio 2 for {set k 0} {$k < 4} {incr k} { set n($k) [$ns node] } $ns duplex-link $n(0) $n(2) 1Mb 10ms DropTail $ns duplex-link $n(1) $n(2) 1Mb 10ms DropTail $ns duplex-link $n(2) $n(3) 1Mb 10ms DropTail for {set i 0} {$i < 2} {incr i} { set udp($i) [new Agent/UDP] $ns attach-agent $n($i) $udp($i) } set cbr($i) [new Application/Traffic/CBR] $cbr($i) set packetsize_ 500 $cbr($i) set interval_ 0.05 $cbr($i) attach-agent $udp($i) continua DIIT - A. Leonardi 33
Esempio 2 set null0 [new Agent/Null] $ns attach-agent $n(3) $null0 $ns connect $udp(0) $null0 $ns connect $udp(1) $null0 $ns queue-limit $n(0) $n(1) 10 $ns at 0.5 $cbr(0) start $ns at 1.0 $cbr(1) start $ns at 4.0 $cbr(0) stop $ns at 4.5 $cbr(1) stop continua DIIT - A. Leonardi 34
Esempio 2 flussi colorati $ns color 1 blue $ns color 2 green $udp(0) set fid_ 1 $udp(1) set fid_ 2 $ns duplex-link-op $n(2) $n(3) queuepos 1.5 continua DIIT - A. Leonardi 35
Esempio 2 - LossMonitor set sink0 [new Agent/LossMonitor] $ns attach-agent $n(3) $sink0 $ns connect $udp(0) $sink0 proc record {} { global ns sink0 set tick_ 0.5 set bw0 [$sink0 set bytes_] set now [$ns now] } puts $now $bw0 $ns at [expr $now+$tick_] record continua DIIT - A. Leonardi 36
Esempio 2 $ns at 0.0 record $ns at 1.0 $source0 start $ns run DIIT - A. Leonardi 37
Approfondimenti queue monitor flow monitor scrittura su file e prelevamento dati utili awk excel matlab perl DIIT - A. Leonardi 38
Wireless World in NS-2 I moduli wireless sono stati implementati originariamente dal gruppo CMU Monarch è possibile simulare multi-hop ad-hoc networks wireless LAN sensor networks DIIT - A. Leonardi 39
Esempio 3 nodi mobili topologia 670m x 670m protocollo di routing Ad-Hoc DSDV modello di mobilità dei nodi RANDOM protocollo di trasporto TCP traffico tipo CBR DIIT - A. Leonardi 40
Esempio - wireless set ns [new Simulator] set topo [new Topography] $topo load_flatgrid 670 670 set tracefd [open esempio.tr w] $ns trace-all $tracefd set namtrace [open esempio.nam w] $ns namtrace-all-wireless $namtrace 670 670 set god [create-god 3] DIIT - A. Leonardi 41
Esempio - wireless $ns node-config \ -addresstype hierarchical \ -adhocrouting DSDV \ -lltype LL \ -mactype Mac/802_11 \ -ifqlen 50 \ -ifqtype Queue/DropTail/PriQueue \ -anttype Antenna/OmniAntenna \ -proptype Propagation/TwoRayGround \ -phytype Phy/WirelessPhy \ -channeltype Channel/WirelessChannel \ -topoinstance $topo -agenttrace ON \ -routertrace OFF \ -mactrace OFF DIIT - A. Leonardi 42
DIIT - A. Leonardi 43
DIIT - A. Leonardi 44
Esempio - wireless for {set i < 0} {$i < 3} {incr i} { set node($i) [$ns node] $node($i) random-motion 0 } $node(0) set x_ <100> $node(0) set y_ <200> $node(0) at 1.0 setdest <x1> <y1> <speed> #oppure $node(0) random-motion 1 $node(0) start #protocolli di trasporto e generatori di traffico come nel wired DIIT - A. Leonardi 45
Scenario generator > setdest n <num_nodes> -p <pause_time> -s <maxspeed> -t <sim_time> -x <max_x> -y <max_y> si trova in /indep-utils/cmu-scen-gen/setdest/ DIIT - A. Leonardi 46
Traffic generator CBR Traffic > ns cbrgen.tcl [-type cbr tcp] [-nn nodes] [-seed seed] [-mc connections] [-rate rate] TCP Traffic ns tcpgen.tcl [- nn nodes] [- seed seed] DIIT - A. Leonardi 47
Energy extension $ns node-config \ -energymodel EnergyModel -initialenergy 100 -txpower 0.8 -rxpower 0.2 DIIT - A. Leonardi 48
nam invece di $ns namtrace-all $fd usare $ns namtrace-all-wireless $fd alla fine $ns nam-end-wireless [$ns now] DIIT - A. Leonardi 49
Nodo mobile node entry classifier agent routing agent LL MAC PHY DIIT - A. Leonardi 50
DIIT - A. Leonardi 51
DIIT - A. Leonardi 52
Traccia wireless $ns use-newtrace DIIT - A. Leonardi 53
Traccia wireless DIIT - A. Leonardi 54
Traccia wireless DIIT - A. Leonardi 55
Traccia wireless DIIT - A. Leonardi 56
Estensione ns2 in C++ Modifiche sul codice make depend ricompilare Aggiunta di nuovi file cambiare il makefile make depend ricompilare DIIT - A. Leonardi 57