Sunteți pe pagina 1din 3

#Write TCL simulation scripts to simulate the following scenario:

#In the following network, the host named Annie is transmitting data
over an unreliable, connectionless 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. 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 an unreliable, connectionless communication at
a rate of 0.01Mbps in 500 bytes long packets. The shortest path
algorithm is followed for routing. 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.
#At 1.0 sec start increasing the traffic rate by 0.01Mbps and packet
size by 10 bytes at every second till 10.0. The above-said
transmissions exist totally for 10.0 secs.
#Set the queue size of all links to 100 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 Q66.nam w]
$ns namtrace-all $nf
set tf [open Q66.tr w]
$ns trace-all $tf
#finish procedure
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam Q66.nam &
exit 0
}
proc chrp {} {
global ns cbr5
set step 1.0
set now [$ns now]
set rate [$cbr5 set rate_]
set pktsize [$cbr5 set packetSize_]
set ratestep 10000
set pktsizestep 10
$cbr5 set rate_ [expr $rate+$ratestep]
$cbr5 set packetSize_ [expr $pktsize+$pktsizestep]
set qlimit [Queue set limit_]
#
Queue set limit_ [expr $qlimit+1]
#
$ns at $now "$ns trace-annotate \"Now traffic rate from Robin
to Juliet is [$cbr5 set rate_]\""
#
$ns at $now "$ns trace-annotate \"Now size of traffic packet

from Robin to Juliet is [$cbr5 set packetSize_]\""


#
$ns at $now "$ns trace-annotate \"Now queue size is [Queue set
limit_]\""
$ns at [expr $now+$step] "chrp"
}
#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_ 100


#add agents
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set null7 [new Agent/Null]
$ns attach-agent $n(7) $null7

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"

set
$ns
set
$ns

udp5 [new Agent/UDP]


attach-agent $n(5) $udp5
null2 [new Agent/Null]
attach-agent $n(2) $null2

#set agent parameters


$udp0 set fid_ 1
$udp5 set fid_ 2
#create connections
$ns connect $udp0 $null7
$ns connect $udp5 $null2
#set flow color of traffic
$ns color 1 red
$ns color 2 blue
#add traffics
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
set cbr5 [new Application/Traffic/CBR]
$cbr5 attach-agent $udp5
#set traffic parameters
$cbr0 set rate_ 0.1Mb
$cbr0 set packetSize_ 1000
$cbr5 set rate_ 0.01Mb
$cbr5 set packetSize_ 500
#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 "$cbr0 start"
$ns at 0.1 "$cbr5 start"
$ns at 1.0 "chrp"
$ns at 10.1 "$cbr0 stop"
$ns at 10.1 "$cbr5 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"
100"
0"
100"

S-ar putea să vă placă și