Transcript ns2 2012

Ing. Henry Zárate Ceballos.
Redes Ad Hoc
AGENDA
1. INTRODUCCIÓN
2. ENTORNO DE SIMULACIÓN
3.Ejercicios.
4. BASICOS
5. REDES AD HOC
6. REDES MESH
7. CONCLUSIONES
8. PREGUNTAS
Page  2
INTRODUCCIÓN
Page  3
Ns–2 es un simulador de redes basado en
eventos discretos. NS es ampliamente utilizado
como herramienta educativa y de investigación.
Probablemente NS2 es el simulador de redes
de código abierto más extendido en
investigación como para propósitos docentes,
funciona en varios sistemas operativos como
Linux, OS X, Solaris, Windows y es el más útil
para simular un escenario para MANET's de
forma muy simple.
Page  4
¿Que se puede SIMULAR?
Page  5
Page  6
Simular estructuras y protocolos de redes de todo tipo
(satélite, wireless, cableadas, etc..)
Desarrollar nuevos protocolos y algoritmos y
comprobar su funcionamiento.
Comparar distintos protocolos en cuanto a
prestaciones
Page  7
CICLO DE
PROGRAMACIÓN
Archivo de
entrada
Page  8
Depuración
lenguaje Otcl
Archivo de
salida
Arquitectura Básica
Page  9
Page  10
Ns - Arquitectura
Page  11
ARQUITECTURA
Page  12
Topología simple de una Red
Page  13
Creando topologías
n1
5Mbps,
10ms
300Kbps,
100ms
n3
n5
500Kbps,
50ms
n4
n2
14Page  14
2Mbps,
20ms
300Kbps,
100ms
n6
Observación del comportamiento de la red
Src Dst IP
Address, Port
time
Page  15
A simple Example – Creating the topology
Bandwidth:1Mbps
Latency: 10ms
n1
Page  16
n2
Creating the topology
#create a new 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
$ns flush-trace
#close the trace file
close $nf
#execute nam on the trace file
exec nam out.nam &
exit 0
}
Page  17
Creating the topology (Contd)
#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
Page  18
DEMO
Page  19
Adding traffic
1Mbps,10ms
n1
n2
udp
null
cbr
node
agent
source
link
Packet Size: 500
bytes
rate: 800Kbps
cbr traffic
0.0
Page  20
20
0.5
4.5
Vacha Dave, University of Texas at Austin
5.0
time
Uniendo todo el código
#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
#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 to the sink
$ns connect $udp0 $null0
#Schedule events for CBR traffic
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#call the finish procedure after 5 secs of simulated time
$ns at 5.0 "finish"
#run the simulation
Page
 21
$ns
run
21
Vacha Dave, University of Texas at Austin
DEMO
Page  22
A second Scenario * (from NS by Example)
Taken from NS by
Example by Jae
Chung
and
Mark Claypool
Page  23
A second Example (From NS by Example)
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
Page  24
A Second Scenario (Contd.)
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
Page  25
A Second Scenario (Contd.)
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitor the queue for link (n2-n3). (for
NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
Page  26
A Second Scenario (Contd.)
#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
To create agents or traffic sources, we need
to know the class names these objects
(Agent/TCP, Agent/TCPSink, Application/FTP
and so on).
This information can be found in the NS
documentation.
But one shortcut is to look at the "ns2/tcl/libs/ns-default.tcl" file.
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
Page  27
A Second Scenario (Contd.)
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
Page  28
Page  29
Simulación
Page  30
Ns all in one
ns-allinone
Tcl8.0
TK8.0
OTcl
tclcl
...
tcl
ex
examples
Page  31
test
validation tests
mysrc
msg.tcl
ns-2
lib
nam-1
C++ code
mcast
OTcl code
...
INSTALACIÓN
Page  32
Pasos de instalación
 Desde el gestor de Descargas
Page  33
Pasos de instalación
 Desde el terminal
 $ sudo apt-get install «paquete» (para instalar)
 ns
 nam
 xgraph
$ sudo apt-get remove «paquete» (para desinstalar)
Page  34
ENTORNO DE
SIMULACIÓN
Page  35
Terminal
Page  36
Terminal
Page  37
Simulación y resultados
Page  38
Page  39
EJERCICIOS
Page  40
Estructura
Page  41
Ejercicio 1
 set ns [new Simulator]
 set nf [open out.nam w]
 $ns namtrace-all $nf
 proc finish {} {
 global ns nf
 $ns flush-trace
 close $nf
 exec nam out.nam &
 exit 0
}
Page  42
 set n0 [$ns node]
 set n1 [$ns node]
 $ns duplex-link $n0 $n1 1Mb 10ms DropTail
Page  43
 #Create a UDP agent and attach it to node n0
 set udp0 [new Agent/UDP]
 $ns attach-agent $n0 $udp0

Page  44
 # 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
 set null0 [new Agent/Null]
 $ns attach-agent $n1 $null0
 $ns connect $udp0 $null0
 $ns at 0.5 "$cbr0 start"
 $ns at 4.5 "$cbr0 stop"
Page  45
 $ns at 5.0 "finish"
 $ns run
Page  46
TRABAJO
POST
SIMULACIÓN
Page  47
Awk
 Awk es un lenguaje de programación que permite una fácil manipulación
delos datos estructurados y la generación de informes con
formato.
Awk
es
sinónimo
de
los
nombres
de
sus autores "Aho, Weinberger, y Kernighan"
 Software analizador de trazas, es un complemento usado post simulación
para analizar los resultados obtenidos en los diferentes simuladores
Page  48
Awk
 El Awk se utiliza sobre todo para el patrón de análisis y procesamiento.
Busca uno o más archivos para ver si contienen las líneas que
coincidan con los patrones especificados y a continuación realice las
acciones asociadas.
 awk <pattern> '{print <stuff>}' <file>
 Ejemplo
 awk '{print "Hit the",$1,"with your",$2}' words.data
Hit the nail with your hammer
Hit the pedal with your foot
Hit the clown with your pie
Page  49
Awk
Algunas de las características clave de Awk son:

1
2
3
Page  50
• Awk ve un archivo de texto como los registros y campos.
Como el lenguaje de programación
común, Awk tiene variables, condicionales y bucles
• Awk tiene la aritmética y de cadena.
• Awk puede generar informes en formato
• Awk lee de un archivo o desde su entrada estándar, y las
salidas a su salida estándar. Awk no se lleva bien con
archivos de texto no.
Ejemplo
Page  51
Ejemplo
Page  52
CONCLUSIONES
Page  53