8 Program
8 Program
#Open trace and NAM trace file set ntrace [open prog5.tr w]
$ns trace-all $ntrace
set namfile [open prog5.nam w]
$ns namtrace-all $namfile
#Use some flat file to create congestion graph windows set winFile0 [open WinFile0 w]
set winFile1 [open WinFile1 w]
#Plot the Congestion Window graph using xgraph exec xgraph WinFile0 WinFile1 &
exit 0
}
#Create 6 nodes
for {set i 0} {$i<6} {incr i} { set n($i) [$ns node]
}
#Setup queue between n(2) and n(3) and monitor the queue
$ns queue-limit $n(2) $n(3) 20
$ns duplex-link-op $n(2) $n(3) queuePos 0.5
#Set error model on link n(2) to n(3) set loss_module [new ErrorModel]
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n(2) $n(3)
#Set up the TCP connection between n(0) and n(4) set tcp0 [new Agent/TCP/Newreno]
$tcp0 set fid_ 1
$tcp0 set window_ 8000
$tcp0 set packetSize_ 552
$ns attach-agent $n(0) $tcp0
set sink0 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(4) $sink0
$ns connect $tcp0 $sink0
#Set up another TCP connection between n(5) and n(1) set tcp1 [new Agent/TCP/Newreno]
$tcp1 set fid_ 2
$tcp1 set window_ 8000
$tcp1 set packetSize_ 552
$ns attach-agent $n(5) $tcp1
set sink1 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(1) $sink1
$ns connect $tcp1 $sink1
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.
$n5 l
abel "dest1"
$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL Queue/DropTail Mac/802_3
proc finish { } {
global ns nf tf
$ns flush-trace
close $tf
close $nf
exec nam lab3.nam &
exit 0
}
$ns at 0.1 "$ftp0 start"
$ns at 5 "$ftp0 stop"
$ns at 7 "$ftp0 start"
$ns at 0.2 "$ftp2 start"
$ns at 8 "$ftp2 stop"
$ns at 14 "$ftp0 stop"
$ns at 10 "$ftp2 start"
$ns at 15 "$ftp2 stop"
$ns at 16 "finish"
$ns run
AWK file (Open a new editor using “vi command” and write awk file and save with
“.awk” extension)
BEGIN {
}
{
END {
1) Open vi editor and type program. Program name should have the extension ― .tcl ‖
[root@localhost ~]# gedit lab3.tcl
2) Open vi editor and type awk program. Program name should have the extension ―.awk ‖
[root@localhost ~]# gedit lab3.awk
[root@localhost~]# ns lab3.tcl
5) Here we are using the congestion window trace files i.e. file1.tr and file2.tr and we are
redirecting the contents of those files to new files say a1 and a2 using output redirection
operator (>).