0% found this document useful (0 votes)
54 views

Computer Network Lab Program 1

The document implements a simulation of ping and trace route messages over a 6 node network topology using the Network Simulator (ns) tool. It creates the network nodes and links, attaches ping agents to send messages, and schedules message sends over time. It also includes an AWK script to analyze the trace file output from the simulation and calculate the number of packets dropped due to congestion.

Uploaded by

lucas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Computer Network Lab Program 1

The document implements a simulation of ping and trace route messages over a 6 node network topology using the Network Simulator (ns) tool. It creates the network nodes and links, attaches ping agents to send messages, and schedules message sends over time. It also includes an AWK script to analyze the trace file output from the simulation and calculate the number of packets dropped due to congestion.

Uploaded by

lucas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2.

Implement transmission of ping messages/trace route over a network topology


consisting of 6 nodes and find the number of packets dropped due to congestion.

set ns [ new Simulator ]

set nf [ open lab2.nam w ]


$ns namtrace-all $nf

set tf [ open lab2.tr w ]


$ns trace-all $tf

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$n4 shape box

$ns duplex-link $n0 $n4 1005Mb 1ms DropTail


$ns duplex-link $n1 $n4 50Mb 1ms DropTail
$ns duplex-link $n2 $n4 2000Mb 1ms DropTail
$ns duplex-link $n3 $n4 200Mb 1ms DropTail
$ns duplex-link $n4 $n5 1Mb 1ms DropTail

set p1 [new Agent/Ping]


$ns attach-agent $n0 $p1
$p1 set packetSize_ 50000
$p1 set interval_ 0.0001

set p2 [new Agent/Ping]


$ns attach-agent $n1 $p2

set p3 [new Agent/Ping]


$ns attach-agent $n2 $p3
$p3 set packetSize_ 30000
$p3 set interval_ 0.00001

set p4 [new Agent/Ping]


$ns attach-agent $n3 $p4

set p5 [new Agent/Ping]


$ns attach-agent $n5 $p5

$ns queue-limit $n0 $n4 5


$ns queue-limit $n2 $n4 3
$ns queue-limit $n4 $n5 2

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 */

$ns connect $p1 $p5


$ns connect $p3 $p4

proc finish { } {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam lab2.nam &
exit 0
}

$ns at 0.1 "$p1 send"


$ns at 0.2 "$p1 send"
$ns at 0.3 "$p1 send"
$ns at 0.4 "$p1 send"
$ns at 0.5 "$p1 send"
$ns at 0.6 "$p1 send"
$ns at 0.7 "$p1 send"
$ns at 0.8 "$p1 send"
$ns at 0.9 "$p1 send"
$ns at 1.0 "$p1 send"
$ns at 1.1 "$p1 send"
$ns at 1.2 "$p1 send"
$ns at 1.3 "$p1 send"
$ns at 1.4 "$p1 send"
$ns at 1.5 "$p1 send"
$ns at 1.6 "$p1 send"
$ns at 1.7 "$p1 send"
$ns at 1.8 "$p1 send"
$ns at 1.9 "$p1 send"
$ns at 2.0 "$p1 send"
$ns at 2.1 "$p1 send"
$ns at 2.2 "$p1 send"
$ns at 2.3 "$p1 send"
$ns at 2.4 "$p1 send"
$ns at 2.5 "$p1 send"
$ns at 2.6 "$p1 send"
$ns at 2.7 "$p1 send"
$ns at 2.8 "$p1 send"
$ns at 2.9 "$p1 send"

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 at 3.0 "finish"

$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

You might also like