Sunday, September 25, 2016

Program No 9:

Simulate a network which will create congestion in the network. With the trace file created, identify the points at which congestion occurs by writing sed/awk scripts. Also write a mechanism to correct/control the congestion.

TCL Script:

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

set tracefile [open 9a.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 $n3 2Mb 10ms DropTail
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link $n1 $n3 2Mb 10ms DropTail
$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns duplex-link-op $n2 $n3 orient right-up
$ns duplex-link $n3 $n4 2Mb 10ms DropTail
$ns duplex-link-op $n3 $n4 orient right
$ns duplex-link $n4 $n5 2Mb 10ms DropTail
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link $n4 $n6 2Mb 10ms DropTail
$ns duplex-link-op $n4 $n6 orient right
$ns duplex-link $n4 $n7 2Mb 10ms DropTail
$ns duplex-link-op $n4 $n7 orient right-down

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

set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1  
$ns connect $tcp1 $sink1

set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set null1 [new Agent/Null]
$ns attach-agent $n6 $null1  
$ns connect $udp1 $null1

set udp2 [new Agent/UDP]
$ns attach-agent $n2 $udp2
set null2 [new Agent/Null]
$ns attach-agent $n7 $null2  
$ns connect $udp2 $null2

set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1

set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1

set cbr2 [new Application/Traffic/CBR]
$cbr2 set packetSize_ 500
$cbr2 set interval_ 0.005
$cbr2 attach-agent $udp2

$tcp1 set class_ 1
$ns color 1 Blue

$udp1 set class_
2 $ns color 2 Red

$udp2 set class_ 3
$ns color 3 Green

set filesize [expr 4*1024*1024]
$ns at 0.0 "$ftp1 send $filesize"

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

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

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

proc finish {} {    
global ns namfile tracefile
$ns flush-trace close
$namfile close
$tracefile set awkCode
{
BEGIN{}
{
if($1 == "d" && $6 > 1000){
count_bytes = count_bytes + $6 - ($6 % 1000);
print $2,count_bytes >> "9a.data";
}
} END{}
} exec awk $awkCode 9a.tr
exec nam 9a.nam &
exec xgraph -bb -tk -x Time -x Bytes 9a.data -bg white &
exit 0 }

$ns at 100.0 "finish"
$ns run

Note:- Initially run the above program. That creats the congestion. Then, update the line as follows:
set tcp1 [new Agent/TCP/Newreno] and also for tcp2, tcp3. This provides the congestion control.

No comments:

Post a Comment