Sei sulla pagina 1di 2

#Write TCL simulation scripts to simulate the following scenario:

#There are two LANs each comprising 4 hosts. These LANs are connected
via a router as shown in the figure. Each LAN is having a bandwidth
of 2Mbps and a delay of 100ms. These LANs use CSMA/CD (IEEE 802.3) as
LAN protocol.
#The host named Annie on LAN1 is transmitting data to the host named
Peter on LAN2 over a reliable, connection-oriented communication at a
rate of 0.1Mbps in 1000 bytes long packets. 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 router1-host4 goes down to 0 at
1.65 sec and comes up again to 100 at 1.80 sec and that of the link
router1-host3, down to 0 at 7.15 sec and up again to 100 at 7.19 sec.
#Set the queue size of all links to 100 packets. Orient the nodes as
shown in the figure. Set labels for transmitting and receiving nodes
as Annie and Peter 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. 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 Q77.nam w]
$ns namtrace-all $nf
#finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam Q77.nam &
exit 0
}
#add nodes
for {set i 0} {$i<9} {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\""
$ns
$ns
$ns
$ns
$ns
$ns
$ns

at
at
at
at
at
at
at

0.0
0.0
0.0
0.0
0.0
0.0
0.0

"$n(1)
"$n(2)
"$n(3)
"$n(4)
"$n(5)
"$n(6)
"$n(8)

label
label
label
label
label
label
label

\"host1\""
\"host2\""
\"host3\""
\"host4\""
\"host5\""
\"host6\""
\"router1\""

#add links
$ns duplex-link $n(3) $n(8) 1Mb 100ms DropTail
$ns duplex-link $n(8) $n(4) 1Mb 100ms DropTail

#set link parameters


$ns duplex-link-op $n(3) $n(8) orient right
$ns duplex-link-op $n(8) $n(4) orient right
$ns duplex-link-op $n(3) $n(8) label "\ 1Mb,100ms"
$ns duplex-link-op $n(8) $n(4) label "\ 1Mb,100ms"
Queue set limit_ 100
#create LAN
$ns make-lan "$n(0) $n(1) $n(2) $n(3)" 2Mb 100ms LL Queue/DropTail
Mac/802_3 Channel Phy/WiredPhy
$ns make-lan "$n(4) $n(5) $n(6) $n(7)" 2Mb 100ms LL Queue/DropTail
Mac/802_3 Channel Phy/WiredPhy
#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 agent parameters
$tcp0 set windowInit_ 8
$tcp0 set window_ 8
$tcp0 set maxcwnd_ 8
$tcp0 set fid_ 1
#create connections
$ns connect $tcp0 $tcpsink7
#set flow color of traffic
$ns color 1 red
#add traffics
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
#set traffic parameters
$ftp0 set rate_ 0.1Mb
$ftp0 set packetSize_ 1000
#insert network dynamics
$ns at 1.65 "$ns queue-limit
$ns at 1.80 "$ns queue-limit
$ns at 7.15 "$ns queue-limit
$ns at 7.19 "$ns queue-limit
#set event scheduling
$ns at 0.1 "$ftp0 start"
$ns at 10.1 "$ftp0 stop"
$ns at 10.2 "finish"
#run simulation
$ns run

$n(8)
$n(8)
$n(8)
$n(8)

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

0"
100"
0"
100"

Potrebbero piacerti anche