You are on page 1of 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 shortest
path 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 queue of the link host3-host4 goes down to zero
at 2.5 sec and comes up to 50 again at 3.0 sec.
#At the same time the host named Robin is transmitting data to the
host named Juliet over a reliable, connection-oriented communication
at a rate of 0.1Mbps in 1000 bytes long packets. The shortest path
algorithm is followed for routing and a simple stop and wait protocol
is used for a reliable data transfer. It has been found that the
queue of the link host4-host3 goes down to zero at 4.5 sec and comes
up to 50 again at 5.0 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 nodes as Annie and
Robin and receiving nodes as Peter and Juliet 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
Robin to Juliet 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 Q55.nam w]
$ns namtrace-all $nf
set tf [open Q55.tr w]
$ns trace-all $tf
#finish procedure
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam Q55.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(7) shape box
$n(7) color blue
$ns at 0.0 "$n(7) label \"Peter\""
$n(5) shape hexagon
$n(5) color red
$ns at 0.0 "$n(5) label \"Robin\""

$n(2) shape box


$n(2) color blue
$ns at 0.0 "$n(2) label \"Juliet\""
$ns
$ns
$ns
$ns

at
at
at
at

0.0
0.0
0.0
0.0

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

#add links
$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

$n(0)
$n(1)
$n(2)
$n(3)
$n(4)
$n(4)
$n(4)

\"host1\""
\"host3\""
\"host4\""
\"host6\""

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

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

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(2)
$ns duplex-link-op $n(3)
$ns duplex-link-op $n(4)
$ns duplex-link-op $n(4)
$ns duplex-link-op $n(4)

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

orient
orient
orient
orient
orient
orient
orient

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

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

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

$n(0)
$n(1)
$n(2)
$n(3)
$n(4)
$n(4)
$n(4)

Queue set limit_ 50


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

tcp5 [new Agent/TCP]


attach-agent $n(5) $tcp5
tcpsink2 [new Agent/TCPSink]
attach-agent $n(2) $tcpsink2

#set agent parameters


$tcp0 set windowInit_ 8
$tcp0 set window_ 8
$tcp0 set maxcwnd_ 8
$tcp0 set fid_ 1
$tcp5 set window_ 1
$tcp5 set fid_ 2
#create connections
$ns connect $tcp0 $tcpsink7
$ns connect $tcp5 $tcpsink2
#set flow color of traffic
$ns color 1 red
$ns color 2 blue

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

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

#add traffics
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set ftp5 [new Application/FTP]
$ftp5 attach-agent $tcp5
#set traffic parameters
$ftp0 set rate_ 0.1Mb
$ftp0 set packetSize_ 1000
$ftp5 set rate_ 0.1Mb
$ftp5 set packetSize_ 1000
#insert network
$ns at 2.5 "$ns
$ns at 3.0 "$ns
$ns at 4.5 "$ns
$ns at 5.0 "$ns

dynamics
queue-limit
queue-limit
queue-limit
queue-limit

#set event scheduling


$ns at 0.1 "$ftp0 start"
$ns at 0.1 "$ftp5 start"
$ns at 10.1 "$ftp0 stop"
$ns at 10.1 "$ftp5 stop"
$ns at 10.2 "finish"
#run simulation
$ns run

$n(3)
$n(3)
$n(4)
$n(4)

$n(4)
$n(4)
$n(3)
$n(3)

0"
50"
0"
50"

You might also like