Monday, September 26, 2016

Program No 6

Bandwidth sharing between TCP and UDP Consider the dumbbell topology from our previous exercise: Node # 0 is a TCP source, and the corresponding sink is at node # 6. Node # 1 is a UDP source (CBR traffic) with a null agent attached to node # 7. These two traffic flows through the common link 2­3. The aim of this exercise is to examine how TCP and UDP share the bandwidth between themselves when the rate of CBR traffic is changed. Set the TCP packet size to 1460 B. The UDP and CBR packet sizes are 1500 B. All the links in the network have same bandwidths (say, 4 Mb), delay and queue types.  Part 1:    Set the initial rate of CBR traffic to 0.5ms. Run the simulation, and plot the "Bytes Received" by node #s 6 and 7 (sinks for TCP and UDP traffic)     Now, increment the rate up to 4ms, the rate of CBR, in steps of 0.5ms. Run the simulation and plot the graphs again.    How does the graphs change after each run? In particular, what's the nature of the graphs when the rate of CBR traffic is 50% of the bit rate?

TCL Script:

set ns [new Simulator]
set namfile [open ex_06.nam w]
$ns namtrace-all $namfile

set tracefile [open ex_06.tr w]
$ns trace-all $tracefile    
Agent/TCP set packetSize_ 1460

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]

$n1 color blue
$n1 shape box
$n0 color red

$ns duplex-link $n0 $n2 4Mb 10ms DropTail

$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link $n1 $n2 4Mb 10ms DropTail
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link $n2 $n3 4Mb 10ms DropTail
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link $n3 $n4 4Mb 10ms DropTail
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link $n3 $n5 4Mb 10ms DropTail
$ns duplex-link-op $n3 $n5 orient right-down
$ns duplex-link $n4 $n6 4Mb 10ms DropTail
$ns duplex-link-op $n4 $n6 orient right
$ns duplex-link $n5 $n7 4Mb 10ms DropTail
$ns duplex-link-op $n5 $n7 orient right

set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp

set sink [new Agent/TCPSink]
$ns attach-agent $n6 $sink  

$ns connect $tcp $sink

set ftp [new Application/FTP]
$ftp attach-agent $tcp

set udp [new Agent/UDP]
$ns attach-agent $n1 $udp

set null [new Agent/Null]
$ns attach-agent $n7 $null

$ns connect $udp $null

$udp set class_ 1
$ns color 1 Blue

$tcp set class_ 2
$ns color 2 Red

set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 1500
$cbr set interval_ 0.005
$cbr attach-agent $udp

$ns at 0.0 "$cbr start"
$ns at 9.0 "$cbr stop"

$ns at 0.0 "$ftp start"
$ns at 9.0 "$ftp stop"

proc finish {}
{    
global ns namfile tracefile
$ns flush-trace
close $namfile
close $tracefile

set awkCode {
BEGIN{}
{
if($1 == "r" && $4 == 6 && $6 >= 1460)
{
count_bytes = count_bytes + $6 - ($6 % 1460);
print $2,count_bytes >> "prgm6_tcp0.005.data";
}
else
if($1 == "r" && $4 == 7 && $6 >= 500)
{
count_bytes = count_bytes + $6 - ($6 % 500);
print $2,count_bytes >> "prgm6_udp0.005.data";
}
}
END{}
}
exec awk $awkCode ex_06.tr

exec nam ex_06.nam &
exec xgraph -bb -tk -x Time -y Bytes_Received_at_0.5 prgm6_tcp0.005.data -bg white &
exec xgraph -bb -tk -x Time -y Bytes_Received_at_0.5 prgm6_udp0.005.data -bg white &
exit 0
}
$ns at 100.0 "finish"
$ns run

No comments:

Post a Comment