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

Program

Ns2 program

Uploaded by

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

Program

Ns2 program

Uploaded by

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

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 tf [open lab2.tr w]


$ns trace-all $tf

set nf [open lab2.nam w]


$ns namtrace-all $nf

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

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]

$ns duplex-link $n0 $n2 100Mb 300ms DropTail

$ns duplex-link $n1 $n2 1Mb 300ms DropTail

$ns duplex-link $n3 $n2 1Mb 300ms DropTail

$ns duplex-link $n4 $n2 1Mb 300ms DropTail

$ns duplex-link $n5 $n2 100Mb 300ms DropTail

$ns duplex-link $n6 $n2 1Mb 300ms DropTail

$ns queue-limit $n0 $n2 5


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

set ping0 [new Agent/Ping]


$ns attach-agent $n0 $ping0

set ping4 [new Agent/Ping]


$ns attach-agent $n4 $ping4

$ns connect $ping0 $ping4

set ping5 [new Agent/Ping]


$ns attach-agent $n5 $ping5

set ping6 [new Agent/Ping]


$ns attach-agent $n6 $ping6

$ns connect $ping5 $ping6

$ping0 set packetSize_ 50000MB


$ping0 set interval_ 0.0001

$ping5 set packetSize_ 60000MB


$ping5 set interval_ 0.00001
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts " The node [$node_ id] received a reply from $from with round trip time of $rtt"
}

$ns rtmodel-at 0.9 down $n2 $n6


$ns rtmodel-at 1.5 up $n2 $n6

$ns at 0.1 "$ping0 send"


$ns at 0.2 "$ping0 send"
$ns at 0.3 "$ping0 send"
$ns at 0.4 "$ping0 send"
$ns at 0.5 "$ping0 send"
$ns at 0.6 "$ping0 send"
$ns at 0.7 "$ping0 send"
$ns at 0.8 "$ping0 send"
$ns at 0.9 "$ping0 send"
$ns at 1.0 "$ping0 send"
$ns at 1.1 "$ping0 send"
$ns at 1.2 "$ping0 send"
$ns at 1.3 "$ping0 send"
$ns at 1.4 "$ping0 send"
$ns at 1.5 "$ping0 send"
$ns at 1.6 "$ping0 send"
$ns at 1.7 "$ping0 send"
$ns at 1.8 "$ping0 send"

$ns at 0.1 "$ping5 send"


$ns at 0.2 "$ping5 send"
$ns at 0.3 "$ping5 send"
$ns at 0.4 "$ping5 send"
$ns at 0.5 "$ping5 send"
$ns at 0.6 "$ping5 send"
$ns at 0.7 "$ping5 send"
$ns at 0.8 "$ping5 send"
$ns at 0.9 "$ping5 send"
$ns at 1.0 "$ping5 send"
$ns at 1.1 "$ping5 send"
$ns at 1.2 "$ping5 send"
$ns at 1.3 "$ping5 send"
$ns at 1.4 "$ping5 send"
$ns at 1.5 "$ping5 send"
$ns at 1.6 "$ping5 send"
$ns at 1.7 "$ping5 send"
$ns at 1.8 "$ping5 send"
$ns at 5.0 "finish"
$ns run

Awk Script:

BEGIN {
#include<stdio.h>
count=0;
}
{
If ($1=="d")
count++
}
END {
printf("The Total no of Packets Dropped due to Congestion is :%d ", count)
}

You might also like