You are on page 1of 11

LABORATORIO N 4

SIMULACION DE UNA RED

I. OBJETIVO
Realizar la simulacin de la red con trfico CBR/UDP y analice el desempeo
de ancho de banda.
Analizar la red con trfico CBR y FTP y el comportamiento de ancho de banda
y la perdida de paquetes.

II. SESION DE PRUEBAS SIMULACION 1


Para la realizacin del laboratorio se utiliz el siguiente cdigo proporcionado por
el docente de la materia.
#Create a simulator object
set ns [new Simulator]

set tf [open out.tr w]


$ns trace-all $tf

#Open the output files


set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]

#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#Connect the nodes


$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail

#Define a 'finish' procedure


proc finish {} {
global f0 f1 f2 tf ns
$ns flush-trace
#Close the output files
close $f0
close $f1
close $f2
close $tf
#Call xgraph to display the results
#exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}

#Define a procedure that attaches a UDP agent to a previously created node


#'node' and attaches an Expoo traffic generator to the agent with the
#characteristic values 'size' for packet size 'burst' for burst time,
#'idle' for idle time and 'rate' for burst peak rate. The procedure connects
#the source with the previously defined traffic sink 'sink' and returns the
#source object.
proc attach-expoo-traffic { node sink size burst idle rate } {
#Get an instance of the simulator
set ns [Simulator instance]

#Create a UDP agent and attach it to the node


set source [new Agent/UDP]
$ns attach-agent $node $source

#Create an Expoo traffic agent and set its configuration parameters


set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate

# Attach traffic source to the traffic generator


$traffic attach-agent $source
#Connect the source and the sink
$ns connect $source $sink
return $traffic
}

#Define a procedure which periodically records the bandwidth received by the


#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.1
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set bytes_]
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
$sink0 set bytes_ 0
$sink1 set bytes_ 0
$sink2 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}

#Create three traffic sinks and attach them to the node n4


set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n4 $sink1
$ns attach-agent $n4 $sink2

#Create three traffic sources


set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 300k]
set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 700k]
set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 400k]

#Start logging the received bandwidth


$ns at 0.0 "record"
#Start the traffic sources
$ns at 1.0 "$source0 start"
$ns at 1.0 "$source1 start"
$ns at 1.0 "$source2 start"
#Stop the traffic sources
$ns at 20.0 "$source0 stop"
$ns at 20.0 "$source1 stop"
$ns at 20.0 "$source2 stop"
#Call the finish procedure after 60 seconds simulation time
$ns at 25.0 "finish"

#Run the simulation


$ns run

Donde se modific el cdigo (subrayado), en un principio no se sobrepas la


velocidad con la que se trabaja ptimamente, y posteriormente se cambi la
velocidad donde se excedi la velocidad recomendada
III. RESULTADOS SIMULACION 1
- Sin exceder 1Mbps de velocidad
Se generaron 3 archivos en los cuales se pudo observar lo siguiente a travs de
sus grficas.

Out 0
0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25 30
-0.1

Out 1
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05 0 5 10 15 20 25 30

Out 2
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05 0 5 10 15 20 25 30
- Excediendo 1Mbps de velocidad
Se generaron 3 archivos en los cuales se pudo observar lo siguiente a travs de
sus grficas.

Out 0
0.5
0.4
0.3
0.2
0.1
0
-0.1 0 5 10 15 20 25 30

Out 1
0.8

0.6

0.4

0.2

0
0 5 10 15 20 25 30
-0.2

Out 2
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-0.1 0 5 10 15 20 25 30
IV. CONCLUSIONES SIMULACION 1
Tras la realizacin de la simulacin 1 se pudo llegar a las siguientes conclusiones:
- Los grficos muestran que si la velocidad no es sobrepasada, y la suma de
todas las fuentes sumadas no excede 1Mbps, todos tendrn prioridad y la
comunicacin ser pareja.
- Si las velocidades de las fuentes sumadas excede 1Mbps, se puede
observar que existe demasiado trfico y la comunicacin no es pareja.
V. SESION DE PRUEBAS SIMULACION 2
Para la realizacin de la simulacin 2 se utiliz el siguiente cdigo proporcionado
por el docente de la materia:
#Flujos TCP y UDP

#Create a simulator object


set ns [new Simulator]

#Open the nam trace file


set nf [open task1.nam w]
$ns namtrace-all $nf

#open the measurement output files


set f0 [open task1_gpout0.tr w]
set f1 [open task1_gpout1.tr w]

#necessary to remember the old bandwidth


set oldbw0 0
set oldbw00 0

#Define different colors for nam data flows


$ns color 1 Blue
$ns color 2 Red

#Define a 'finish' procedure


proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Close the measurement files
global f0 f1
close $f0
close $f1
#Execute nam on the trace file
exec nam task1.nam &
# exec gnuplot hw3_task1.dem &
exit 0
}

proc record1 {} {
global null0 f0 fmon oldbw0 flowmon
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.2
#Get the current time
set now [$ns now]
#How many bytes have been received by the traffic sinks?
set bw0 [$null0 set bytes_]
set bwf1 [$fmon set bdepartures_]
set fcl [$flowmon classifier]
set fids { 2 }
foreach i $fids {
set flow($i) [$fcl lookup auto 0 0 $i]
if { $flow($i) != "" } {
set bytes2 [$flow($i) set bdepartures_]
#Calculate the throughput and write it to the files
puts $f0 "$now \t [expr ($bytes2 - $oldbw0)*8/$time/1000000]\t [expr [$flow($i) set
pdrops_]]"
#remember the old value
#set oldbw0 $bytes2
$flow($i) set barrivals_ 0
$flow($i) set bdepartures_ 0
$flow($i) set bdrops_ 0
$flowmon set bdrops_ 0
}
}
#Reset the bytes_ values on the traffic sinks
#$null1 set bytes_ 0
$fmon set bdepartures_ 0
$flowmon set barrivals_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record1"
}

#0.04sec interval
#Define a procedure which periodically records the bandwidth received by the
#three traffic sinks sink0/1/2 and writes it to the file f1.
proc record2 {} {
global null0 f1 qqmon oldbw00
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.2
#How many bytes have been received by the traffic sinks?
set bw00 [$null0 set bytes_]
set bw1 [$qqmon set bdepartures_]
set pk1 [$qqmon set pdepartures_]
set packetdrops [$qqmon set pdrops_]
#Get the current time
set now [$ns now]
#Calculate the throughput and write it to the files
puts $f1 "$now \t [expr ($bw00 - $oldbw00)*8/$time/1000000]"
#Reset the bytes_ values on the traffic sinks
$qqmon set bdepartures_ 0
$qqmon set pdrops_ 0
$qqmon set pdepartures_ 0
#remember the old value
set oldbw00 $bw00
#$null0 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record2"
}

#Create four nodes


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#Create links between the nodes


$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 2Mb 10ms DropTail

$ns queue-limit $n1 $n2 20

#Flow Monitor
set linkn1n2 [$ns link $n1 $n2]
set flowmon [$ns makeflowmon Fid]
$ns attach-fmon $linkn1n2 $flowmon

#Monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $n1 $n2 queuePos 0.5
set qqmon [$ns monitor-queue $n1 $n2 ""]
set fmon [$ns monitor-queue $n0 $n1 ""]
set qmon [$ns monitor-queue $n1 $n2 ""]

#Setting for nam


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right

#Create a UDP agent and attach it to node n1


set udp0 [new Agent/UDP]
$udp0 set fid_ 1
$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0


set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 100
$cbr0 set rate_ 650kb
#$cbr1 set interval_ 0.005
#$cbr0 set maxpkts_ 20
$cbr0 attach-agent $udp0

set null0 [new Agent/LossMonitor]


$ns attach-agent $n4 $null0
$ns connect $udp0 $null0

#TCP traffic source


#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
$tcp0 set fid_ 2
$tcp0 set rate_ 800kb
$tcp0 set packetSize_ 500
#$tcp0 set overhead_ 0.001

set Sink [new Agent/TCPSink]


$ns attach-agent $n4 $Sink
$ns connect $tcp0 $Sink

# create an FTP source "application";


set ftp [new Application/FTP]
$ftp set maxpkts_ 1000
$ftp attach-agent $tcp0

#Create a Null agent (a traffic sink) and attach it to node n3


#set null0 [new Agent/LossMonitor]
#$ns attach-agent $n4 $null0

#Schedule events for all the flows


$ns at 0.0 "record1"
$ns at 0.0 "record2"
$ns at 0.0 "$ftp start"
$ns at 0.0 "$cbr0 start"
$ns at 15.0 "$cbr0 stop"
$ns at 15.0 "$ftp stop"
#Call the finish procedure after 6 seconds of simulation time
$ns at 20.1 "finish"

#Run the simulation


$ns run

Como en el caso anterior se modific el cdigo (subrayado), en un principio no se


sobrepas la velocidad con la que se trabaja ptimamente, y posteriormente se
cambi la velocidad donde se excedi la velocidad recomendada
VI. RESULTADOS SIMULACION 2

- Sin exceder 1Mbps


Estos fueron los resultados:
- Excediendo 1Mbps
Estos fueron los resultados:
VII. CONCLUSIONES SIMULACION 2
Tras la realizacin de la simulacin 2 se pudo llegar a las siguientes conclusiones:
- Al principio no se excedi 1Mbps y se gener un archivo nam en el que se
puede observar claramente que no existe trfico en la comunicacin,
adems que se gener 2 tablas en las que se puede observar que no existe
perdida de paquetes.
- Posteriormente se modific el cdigo de manera que la velocidad sea
sobrepasada y se puede observar tanto en la grfica como en la tabla que
existe una amplia perdida de paquete.

You might also like