Click Here to download
Program 1:
#
# (0) tcp0, ftp0
# \
# \ 2Mbps
# \ 3Mbps
# (2)----------------(3) tcpSink0,tcpSink1
# /
# / 1Mbps
# /
# (1) tcp1, ftp1
#
# tcp0 --> tcpsink0
# tcp1 --> tcpsink1
# All 10ms DropTail
#
set ns [new Simulator]
set nf [open trace.tr w]
$ns trace-all $nf
set nm [open out.nam w]
$ns namtrace-all $nm
#Define a 'finish' procedure
proc finish {} {
global ns nf nm
$ns flush-trace
close $nf
close $nm
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#creating links
#$ns <link_type> $n0 $n1 <bandwidth> <delay> <queuetype>
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 3Mb 10ms DropTail
#set up a tcp, connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set tcpsink0 [new Agent/TCPSink]
$ns attach-agent $n3 $tcpsink0
set tcpsink1 [new Agent/TCPSink]
$ns attach-agent $n3 $tcpsink1
$ns connect $tcp0 $tcpsink0
$ns connect $tcp1 $tcpsink1
#Schedule an event: $ns at <time> <event>
$ns at 1.0 "$ftp0 start"
$ns at 1.1 "$ftp1 start"
$ns at 5.0 "$ftp0 stop"
$ns at 5.1 "$ftp1 stop"
$ns at 5.2 "finish"
$ns run
No comments:
Post a Comment