Computer Network Lab Program 1
Computer Network Lab Program 1
4
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received answer from $from with round trip time $rtt msec"
}
/* please provide space between $node_ and id. No space between $ and from.
No space between and $ and rtt */
proc finish { } {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam lab2.nam &
exit 0
}
5
$ns at 0.1 "$p3 send"
$ns at 0.2 "$p3 send"
$ns at 0.3 "$p3 send"
$ns at 0.4 "$p3 send"
$ns at 0.5 "$p3 send"
$ns at 0.6 "$p3 send"
$ns at 0.7 "$p3 send"
$ns at 0.8 "$p3 send"
$ns at 0.9 "$p3 send"
$ns at 1.0 "$p3 send"
$ns at 1.1 "$p3 send"
$ns at 1.2 "$p3 send"
$ns at 1.3 "$p3 send"
$ns at 1.4 "$p3 send"
$ns at 1.5 "$p3 send"
$ns at 1.6 "$p3 send"
$ns at 1.7 "$p3 send"
$ns at 1.8 "$p3 send"
$ns at 1.9 "$p3 send"
$ns at 2.0 "$p3 send"
$ns at 2.1 "$p3 send"
$ns at 2.2 "$p3 send"
$ns at 2.3 "$p3 send"
$ns at 2.4 "$p3 send"
$ns at 2.5 "$p3 send"
$ns at 2.6 "$p3 send"
$ns at 2.7 "$p3 send"
$ns at 2.8 "$p3 send"
$ns at 2.9 "$p3 send"
$ns run
AWK file (Open a new editor using “vi command” and write awk file and save with
“.awk” extension)
BEGIN{
drop=0;
}
{
if($1=="d" )
{
drop++;
}
}
END{
printf("Total number of %s packets dropped due to congestion =%d\n",$5,drop);
}
6
Steps for execution
1) Open gedit and type the program. program name should have
extension “.tcl” [root@localhost ~]# gedit lab2.tcl
2) Save the program by pressing “CTRL + S”
3) Open gedit and type awk program. program name should have extension
“.awk” [root@localhost ~]# gedit lab2.awk
4) Save the program by pressing “CTRL + S”
5)Run the simulation program
[root@localhost~]# ns lab2.tcl
i) Here “ns” indicates network simulator. We get the topology shown in the snapshot.
ii) Now press the play button in the simulation window and the
simulation will begins.
6) After simulation is completed run awk file to see the
output , [root@localhost~]# awk –f lab2.awk lab2.tr
7) To see the trace file contents open the file as ,
[root@localhost~]# gedit lab2.tr
7
8