3.
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.
/* gedit lab3.tcl */
set ns [new Simulator]
set tf [open lab3.tr w]
$ns trace-all $tf
set nf [open lab3.nam w]
$ns namtrace-all $nf
proc finish { } {
global nf tf ns
$ns flush-trace
exec nam lab3.nam &
close $nf
close $tf
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp0 $sink2
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp1 $sink3
######To trace the congestion window##########
set file0 [open file0.tr w]
$tcp0 attach $file0
$tcp0 trace cwnd_
$tcp0 set maxcwnd_ 10
set file1 [open file1.tr w]
$tcp1 attach $file1
$tcp1 trace cwnd_
$ns at 0.1 "$ftp0 start"
$ns at 1.5 "$ftp0 stop"
$ns at 2 "$ftp0 start"
$ns at 3 "$ftp0 stop"
$ns at 0.2 "$ftp1 start"
$ns at 2 "$ftp1 stop"
$ns at 2.5 "$ftp1 start"
$ns at 4 "$ftp1 stop"
$ns at 5.0 "finish"
$ns run
/* gedit lab3.awk */
AWK Script:
BEGIN{
#include<stdio.h>
}
{
if($6=="cwnd_")
printf("%f \t %f \n", $1,$7);
}
END{
puts "DONE"
}
To run:
ns lab3.tcl
awk –f lab3.awk file0.tr>tcp0
awk –f lab3.awk file1.tr>tcp1
xgraph –x “time” –y “congestion value ” tcp0 tcp1