Está en la página 1de 3

#Write TCL simulation scripts to simulate the following scenario:

#In the following network, the host named Annie is transmitting data
over a reliable, connection-oriented communication to the host named
Peter at a rate of 0.1Mbps in 1000 bytes long packets. The link state
algorithm is followed for routing and a sliding window protocol with
a window size of 8 is used for a reliable data transfer. It has been
found that the link between the host1 and Peter goes down at 1.0 sec
and that between the host3 and host4 goes down at 2.0 sec. The link
host3-host4 comes up again at 4.5 sec and the link host1-Peter, up
again at 6.5 sec. It is desired that, while the present path is
unavailable due to a link failure, the traffic should take the next
available shortest path in the network.
#At the same time the host Peter is transmitting data to the host
Annie over an unreliable, connectionless communication at a rate of
0.1Mbps in 500 bytes long packets. The link state algorithm is
followed for routing. It has been found that the queue of the link
host6-host5 goes down to zero at 3.3 sec and comes up to 50 again at
3.4 sec and that of the link host4-host3 goes down to 0 at 1.3 sec
and comes up to 50 again at 1.4 sec. The above-said transmissions
exist totally for 10.0 secs.
#Set the queue size of all links to 50 packets. Orient the nodes as
shown in the figure. Set labels for transmitting and receiving nodes
as Annie and Peter respectively as shown in the figure. Set label for
each link indicating its bandwidth, and delay as shown in the figure.
Set the shape of the transmitting and receiving nodes to hexagon and
box, and color, to red and blue, respectively. Set the color of the
traffic flow from Annie to Peter to red and that from Peter to Annie
to blue. Set nam and .tr tracings. Analyze the .tr trace file to get
details on dropped packets during this transmission scenario.
#create new simulator object
set ns [new Simulator]
#set nam and .tr tracings
set nf [open Q44.nam w]
$ns namtrace-all $nf
set tf [open Q44.tr w]
$ns trace-all $tf
#finish procedure
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam Q44.nam &
exit 0
}
#add nodes
for {set i 0} {$i<8} {incr i} {
set n($i) [$ns node]
}
#set node parameters
$n(0) shape hexagon
$n(0) color red
$ns at 0.0 "$n(0) label \"Annie\""
$n(2) shape box
$n(2) color blue
$ns at 0.0 "$n(2) label \"Peter\""

$ns
$ns
$ns
$ns
$ns
$ns

at
at
at
at
at
at

0.0
0.0
0.0
0.0
0.0
0.0

"$n(1)
"$n(3)
"$n(4)
"$n(5)
"$n(6)
"$n(7)

#add links
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link
$ns duplex-link

label
label
label
label
label
label

$n(0)
$n(1)
$n(0)
$n(3)
$n(4)
$n(0)
$n(5)
$n(6)
$n(7)

\"host1\""
\"host3\""
\"host4\""
\"host5\""
\"host6\""
\"host7\""

$n(1)
$n(2)
$n(3)
$n(4)
$n(2)
$n(5)
$n(6)
$n(7)
$n(2)

1Mb
1Mb
1Mb
1Mb
1Mb
1Mb
1Mb
1Mb
1Mb

100ms
100ms
100ms
100ms
100ms
100ms
100ms
100ms
100ms

#set link parameters


$ns duplex-link-op $n(0)
$ns duplex-link-op $n(1)
$ns duplex-link-op $n(0)
$ns duplex-link-op $n(3)
$ns duplex-link-op $n(4)
$ns duplex-link-op $n(0)
$ns duplex-link-op $n(5)
$ns duplex-link-op $n(6)
$ns duplex-link-op $n(7)

$n(1)
$n(2)
$n(3)
$n(4)
$n(2)
$n(5)
$n(6)
$n(7)
$n(2)

orient
orient
orient
orient
orient
orient
orient
orient
orient

$ns
$ns
$ns
$ns
$ns
$ns
$ns
$ns
$ns

$n(1)
$n(2)
$n(3)
$n(4)
$n(2)
$n(5)
$n(6)
$n(7)
$n(2)

label
label
label
label
label
label
label
label
label

duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op

$n(0)
$n(1)
$n(0)
$n(3)
$n(4)
$n(0)
$n(5)
$n(6)
$n(7)

Queue set limit_ 50


#add agents
set tcp0 [new Agent/TCP]
$ns attach-agent $n(0) $tcp0
set tcpsink2 [new Agent/TCPSink]
$ns attach-agent $n(2) $tcpsink2
set
$ns
set
$ns

udp2 [new Agent/UDP]


attach-agent $n(2) $udp2
null0 [new Agent/Null]
attach-agent $n(0) $null0

#set agent parameters


$tcp0 set windowInit_ 8
$tcp0 set window_ 8
$tcp0 set maxcwnd_ 8
$tcp0 set fid_ 1
$udp2 set fid_ 2
#create connections
$ns connect $tcp0 $tcpsink2
$ns connect $udp2 $null0
#set flow color of traffic

DropTail
DropTail
DropTail
DropTail
DropTail
DropTail
DropTail
DropTail
DropTail
right
right
right-up
right
right-down
right-down
right
right
right-up
"\
"\
"\
"\
"\
"\
"\
"\
"\

1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"
1Mb,100ms"

$ns color 1 red


$ns color 2 blue
#add traffics
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
#set traffic parameters
$ftp0 set rate_ 0.1Mb
$ftp0 set packetSize_ 1000
$cbr2 set rate_ 0.1Mb
$cbr2 set packetSize_ 500
#insert routing
$ns rtproto LS
#insert network dynamics
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 down $n(3) $n(4)
$ns at 3.3 "$ns queue-limit $n(6) $n(5)
$ns at 3.4 "$ns queue-limit $n(6) $n(5)
$ns rtmodel-at 4.5 up $n(3) $n(4)
$ns at 1.3 "$ns queue-limit $n(4) $n(3)
$ns at 1.4 "$ns queue-limit $n(4) $n(3)
$ns rtmodel-at 6.5 up $n(1) $n(2)
#set event scheduling
$ns at 0.1 "$ftp0 start"
$ns at 0.1 "$cbr2 start"
$ns at 10.1 "$ftp0 stop"
$ns at 10.1 "$cbr2 stop"
$ns at 10.2 "finish"
#run simulation
$ns run

0"
50"
0"
50"

También podría gustarte