Skip to content

Instantly share code, notes, and snippets.

Created April 30, 2013 17:47
Show Gist options
  • Save anonymous/5490456 to your computer and use it in GitHub Desktop.
Save anonymous/5490456 to your computer and use it in GitHub Desktop.
set ns [new Simulator]
# Definimos que sea un protocolo de ruteo dinamico
set tr [open out.tr w]
set nf [open out.nam w]
$ns namtrace-all $nf
$ns trace-all $tr
# Definimos el metodo finish
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
#Se crean los nodos
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Creamos un nodo central
set centro [$ns node]
# Vinculamos los nodos en forma de anillo
$ns duplex-link $centro $n0 1.5Mb 10ms DropTail
$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail
$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail
$ns duplex-link $n4 $centro 1.5Mb 10ms DropTail
$ns duplex-link-op $centro $n0 orient down-right
$ns duplex-link-op $n0 $n1 orient down
$ns duplex-link-op $n1 $n2 orient down-left
$ns duplex-link-op $n2 $n3 orient up-left
$ns duplex-link-op $n3 $n4 orient up
$ns duplex-link-op $n4 $centro orient up-right
# Creamos un agente UDP y lo conectamos al nodo central
set udp0 [new Agent/UDP]
$ns attach-agent $centro $udp0
$udp0 set class_ 1
$ns color 1 Blue
# Generamos traficos con paquetes e intervalos definidos y lo conectamos al agent UDP
set tcp [new Agent/TCP]
$ns attach-agent $centro $tcp
$tcp set class_ 2
$ns color 2 Red
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set tcp2 [new Agent/TCP]
$ns attach-agent $n4 $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp2 $sink2
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.002
$cbr0 attach-agent $udp0
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp0 $null
$ns duplex-link-op $centro $n0 queuePos 0.05
$ns connect $tcp $sink
$ns connect $udp0 $null
$ns rtmodel-at 0.008 down $n4 $n3
$ns rtmodel-at 0.0092 down $n4 $centro
$ns rtmodel-at 0.7 up $n4 $n3
$ns rtmodel-at 1.0 up $n4 $centro
# Iniciamos el trafico y lo detenemos en el segundo 1.5
$ns at 0.01 "$cbr0 start"
$ns at 0.1 "$ftp start"
$ns at 0.03 "$ftp2 start"
$ns at 1.0 "$ftp stop"
$ns at 1.0 "$ftp2 stop"
$ns at 1.5 "$cbr0 stop"
# La simulacion termina al segundo 1.5
$ns at 1.7 "finish"
$ns run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment