# TCP Variant Tahoe
# ========================
#
# (0)tcp0,ftp0 (5)tcpSink0
# \ /
# \2Mb /2Mb
# 2Mb \ 3Mbps / 2Mb
# (1)---------(3)---------------(4)------------(6)tcpSink1
# tcp1,ftp1 / \
# /2Mb \2Mb
# / \
# (2)tcp2,ftp2 (7)tcpSink2
#
#
# [.001s]
# tcp0 [1000b]----------> tcpsink0
# [.001s]
# tcp1 [1000b]----------> tcpsink1
# [.001s]
# tcp2 [1000b]----------> tcpsink2
#
# All 10ms DropTail
#
set ns [new Simulator]
set f0 [open tahoe0.tr w]
set f1 [open tahoe1.tr w]
set f2 [open tahoe2.tr w]
set nr [open taho.tr w]
$ns trace-all $nr
set nf [open taho.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nr nf f0 f1 f2
$ns flush-trace
#Close the NAM trace file
close $nf
close $nr
close $f0
close $f1
close $f2
exec nam taho.nam &
exec xgraph tahoe0.tr tahoe1.tr tahoe2.tr -bg white -t ConjestionWindowAnalysis_Tahoe -x Seconds -y ConjestionWindowSize
exit 0
}
#for{set i 0} {$i<12} {incr i}{
#set n($i) [$ns node]
#}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
#creating links
#for {set i 0} {$i<9}{incr i}{
#$ns duplex-link $n($i) $n([expr$i+1]) 1Mb 10ms DropTail
#}
$ns duplex-link $n0 $n3 2Mb 10ms DropTail
$ns duplex-link $n1 $n3 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns duplex-link $n3 $n4 3Mb 10ms DropTail
$ns duplex-link $n4 $n5 2Mb 10ms DropTail
$ns duplex-link $n4 $n6 2Mb 10ms DropTail
$ns duplex-link $n4 $n7 2Mb 10ms DropTail
$ns duplex-link-op $n0 $n3 orient right-up
$ns duplex-link-op $n1 $n3 orient middle
$ns duplex-link-op $n2 $n3 orient right-down
$ns duplex-link-op $n3 $n4 orient middle
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n6 orient middle
$ns duplex-link-op $n4 $n7 orient right-down
#create a tcp agent and attach it to nodes
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set packetSize_ 1000
$ftp0 set interval_ 0.001
set tcpsink0 [new Agent/TCPSink]
$ns attach-agent $n5 $tcpsink0
$ns connect $tcp0 $tcpsink0
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set packetSize_ 1000
$ftp1 set interval_ 0.001
set tcpsink1 [new Agent/TCPSink]
$ns attach-agent $n6 $tcpsink1
$ns connect $tcp1 $tcpsink1
set tcp2 [new Agent/TCP]
$ns attach-agent $n2 $tcp2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ftp2 set packetSize_ 1000
$ftp2 set interval_ 0.001
set tcpsink2 [new Agent/TCPSink]
$ns attach-agent $n7 $tcpsink2
$ns connect $tcp2 $tcpsink2
#setting colour
$tcp0 set fid_ 1 #to set flow ID
$tcp1 set fid_ 2
$tcp2 set fid_ 3
#flow ID 1 --->RED
$ns color 1 Red
$ns color 2 Green
$ns color 3 Blue
proc record {} {
global ns tcp0 tcp1 tcp2 f0 f1 f2
set time 0.01
set wnd0 [$tcp0 set cwnd_]
set wnd1 [$tcp1 set cwnd_]
set wnd2 [$tcp2 set cwnd_]
set timenow [$ns now]
puts $f0 "$timenow $wnd0"
puts $f1 "$timenow $wnd1"
puts $f2 "$timenow $wnd2"
$ns at [expr $timenow + $time] "record"
}
$ns at 0.1 "record"
$ns at 0.5 "$ftp0 start"
$ns at 1.0 "$ftp1 start"
$ns at 1.5 "$ftp2 start"
$ns at 25.0 "$ftp0 stop"
$ns at 25.5 "$ftp1 stop"
$ns at 26.0 "$ftp2 stop"
$ns at 27.0 "finish"
$ns run
No comments:
Post a Comment