Top Banner
Ing. Henry Zárate Ceballos. Redes Ad Hoc
53

Ing. Henry Zárate Ceballos. Redes Ad Hoc

Mar 15, 2016

Download

Documents

Samson Parks

SIMULADOR NS 2. Ing. Henry Zárate Ceballos. Redes Ad Hoc. A GENDA. INTRODUCCIÓN. NS 2. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Ing. Henry Zárate Ceballos.Redes Ad Hoc

Page 2: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 2

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 3: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 3

INTRODUCCIÓN

Page 4: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 4

NS 2

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 5: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 5

¿Que se puede SIMULAR?

Page 6: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 6

Page 7: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 7

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 8: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 8

CICLO DE PROGRAMACIÓN

Archivo de entrada

Depuración lenguaje Otcl

Archivo de salida

Page 9: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 9

Arquitectura Básica

Page 10: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 10

Page 11: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 11

Ns - Arquitectura

Page 12: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 12

ARQUITECTURA

Page 13: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 13

Topología simple de una Red

Page 14: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 14

Creando topologías

14

n1

n4

n2

n5

n6

n3

5Mbps,10ms

2Mbps,20ms

300Kbps,100ms

300Kbps,100ms

500Kbps,50ms

Page 15: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 15

Observación del comportamiento de la red

Src Dst IP Address, Port

time

Page 16: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 16

A simple Example – Creating the topology

n1 n2

Bandwidth:1MbpsLatency: 10ms

Page 17: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 17

#create a new simulator objectset ns [new Simulator]

#open the nam trace fileset nf [open out.nam w]$ns namtrace-all $nf

#define a 'finish' procedureproc 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}

Creating the topology

Page 18: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 18

Creating the topology (Contd)

#create two nodesset n0 [$ns node]set n1 [$ns node]

#create a duplex link between the nodes$ns duplex-link $n0 $n1 1Mb 10ms DropTail

Page 19: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 19

DEMO

Page 20: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 20 Vacha Dave, University of Texas at Austin20

Adding traffic

n1 n21Mbps,10ms

udp null

cbr

Packet Size: 500 bytesrate: 800Kbps

cbr traffic

0.00.5 5.04.5 time

node agent sourcelink

Page 21: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 21 Vacha Dave, University of Texas at Austin21

Uniendo todo el código

#create a udp agent and attach it to node n0set udp0 [new Agent/UDP]$ns attach-agent $n0 $udp0

#Create a CBR traffic source and attach it to udp0set 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 n1set 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$ns run

Page 22: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 22

DEMO

Page 23: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 23

A second Scenario * (from NS by Example)

Taken from NS by Example by Jae ChungandMark Claypool

Page 24: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 24

A second Example (From NS by Example)

#Create a simulator objectset ns [new Simulator]

#Define different colors for data flows (for NAM)$ns color 1 Blue$ns color 2 Red

#Open the NAM trace fileset nf [open out.nam w]$ns namtrace-all $nf

#Define a 'finish' procedureproc 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 25: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 25

A Second Scenario (Contd.)

#Create four nodesset 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 26: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 26

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 27: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 27

A Second Scenario (Contd.)

#Setup a TCP connectionset tcp [new Agent/TCP]$tcp set class_ 2$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n3 $sink$ns connect $tcp $sink$tcp set fid_ 1

#Setup a FTP over TCP connectionset ftp [new Application/FTP]$ftp attach-agent $tcp$ftp set type_ FTP

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 "ns-2/tcl/libs/ns-default.tcl" file.

Page 28: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 28

A Second Scenario (Contd.)

#Setup a UDP connectionset udp [new Agent/UDP]$ns attach-agent $n1 $udpset null [new Agent/Null]$ns attach-agent $n3 $null$ns connect $udp $null$udp set fid_ 2

#Setup a CBR over UDP connectionset 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 29: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 29

Page 30: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 30

Simulación

Page 31: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 31

Ns all in one

TK8.0 OTcl tclclTcl8.0 ns-2 nam-1

tcl

ex test lib

...

...

examples validation tests

C++ code

OTcl code

ns-allinone

mcastmysrc

msg.tcl

Page 32: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 32

INSTALACIÓN

Page 33: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 33

Pasos de instalación Desde el gestor de Descargas

Page 34: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 34

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 35: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 35

ENTORNO DE SIMULACIÓN

Page 36: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 36

Terminal

Page 37: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 37

Terminal

Page 38: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 38

Simulación y resultados

Page 39: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 39

Page 40: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 40

EJERCICIOS

Page 41: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 41

Estructura

Page 42: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 42

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 43: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 43

set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail

Page 44: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 44

#Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0  

Page 45: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 45

# 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 46: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 46

$ns at 5.0 "finish" $ns run

Page 47: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 47

TRABAJO POST SIMULACIÓN

Page 48: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 48

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 49: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 49

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 hammerHit the pedal with your footHit the clown with your pie

Page 50: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 50

Awk

Algunas de las características clave de Awk son:

1 •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

2 •Awk tiene la aritmética y de cadena.•Awk puede generar informes en formato

3 •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.

Page 51: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 51

Ejemplo

Page 52: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 52

Ejemplo

Page 53: Ing. Henry Zárate Ceballos. Redes Ad Hoc

Page 53

CONCLUSIONES