0% found this document useful (0 votes)
97 views8 pages

Wireless and Networking Lab EC7712 Ns2 Lab Module: Submitted by R.Nishanth 2016504562

The document describes simulating the distance vector routing protocol in NS2. It involves creating 12 nodes and links between them in a topology. UDP connections are set up between nodes 0 to 5 and 1 to 5. CBR traffic is applied over the connections. Distance vector routing protocol is used to route packets from senders to receiver. The simulation is run and throughput and end-to-end delay analyses are performed on the output trace file.

Uploaded by

dhiwahar cv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views8 pages

Wireless and Networking Lab EC7712 Ns2 Lab Module: Submitted by R.Nishanth 2016504562

The document describes simulating the distance vector routing protocol in NS2. It involves creating 12 nodes and links between them in a topology. UDP connections are set up between nodes 0 to 5 and 1 to 5. CBR traffic is applied over the connections. Distance vector routing protocol is used to route packets from senders to receiver. The simulation is run and throughput and end-to-end delay analyses are performed on the output trace file.

Uploaded by

dhiwahar cv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

WIRELESS AND NETWORKING LAB

EC7712
NS2 LAB MODULE

Submitted by
R.NISHANTH
2016504562
Distance Vector Routing Protocol
AIM:
To simulate and study the Distance Vector routing algorithm using simulation.

SOFTWARE REQUIRED:
NS-2 simulator

Network Animator

THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for computing
shortest path between source and destination. The Router is one main devices used in a wide area
network. The main task of the router is Routing. It forms the routing table and delivers the packets
depending upon the routes in the table either directly or via an intermediate devices.Each router
initially has information about its all neighbors. Then this information will be shared among nodes.

ALGORITHM:
1. Create a simulator object

2. Define different colors for different data flows

3. Open a nam trace file and define finish procedure then close the trace file, and execute nam on
trace

file.

4. Create n number of nodes using for loop

5. Create duplex links between the nodes

6. Setup UDP Connection between n(0) and n(5)

7. Setup another UDP connection between n(1) and n(5)


8. Apply CBR Traffic over both UDP connections9. Choose distance vector routing protocol to
transmit data from sender to receiver.

10. Schedule events and run the program.

PROGRAM:
set ns [new Simulator]

set nr [open thro.tr w]

$ns trace-all $nr

set nf [open thro.nam w]

$ns namtrace-all $nf

proc finish { } {

global ns nr nf

$ns flush-trace

close $nf

close $nr

exec nam thro.nam &

exit 0

for { set i 0 } { $i < 12} { incr i 1 } {

set n($i) [$ns node]}

for {set i 0} {$i < 8} {incr i} {

$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }

$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail

$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail

$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail

$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail

$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail

set udp0 [new Agent/UDP]


$ns attach-agent $n(0) $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n(5) $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n(1) $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

set null0 [new Agent/Null]

$ns attach-agent $n(5) $null0

$ns connect $udp1 $null0

$ns rtproto DV

$ns rtmodel-at 10.0 down $n(11) $n(5)

$ns rtmodel-at 15.0 down $n(7) $n(6)

$ns rtmodel-at 30.0 up $n(11) $n(5)

$ns rtmodel-at 20.0 up $n(7) $n(6)

$udp0 set fid_ 1

$udp1 set fid_ 2

$ns color 1 Red

$ns color 2 Green

$ns at 1.0 "$cbr0 start"


$ns at 2.0 "$cbr1 start"

$ns at 45 "finish"

$ns run

Throughput File:
BEGIN {
thput=0
sTime=0
}
{
event=$1
time=$2
intSrc=$3
intDest=$4
src=$9
dest=$10
size=$6
if (event=="r" && intDest==dest) {
thput+=size
sTime=time
}
}
END {
thput=(thput*8)/(1000*sTime)
printf("Throughput = %g Kbps \n",thput)
}

Endtoend delay file:


BEGIN {
for (i in pktSent) {
pktSent[i]=0
}
for (i in pktRecvd) {
pktRecvd[i]=0
}
totpktRecvd=0
delay=avgDelay=0
drop=0
}
{
event=$1
time=$2
intSrc=$3
intDest=$4
src=$9
dest=$10
pktSeq=$12
intSrc=(intSrc ".0")
intDest=(intDest ".0")
if (pktSent[pktSeq]==0 && event=="+" && intSrc==src) {
pktSent[pktSeq]=time
}
if (event=="r" && intDest==dest) {
totpktRecvd++
pktRecvd[pktSeq]=time
}
if (event=="d") {
drop++
}
}
END {
for (i in pktRecvd) {
if (pktSent[i]==0) {
printf("\nError %g\n",i)
}
delay+=pktRecvd[i]-pktSent[i]
num++
}
if (num!=0) {
avgDelay=delay/num
}
else {
avgDelay=0
}
printf("Total packets Received= %g\n",totpktRecvd)
printf("Total packets dropped= %g\n",drop)
printf("Average Delay=%g ms\n",avgDelay*100)
}

TOPOLOGY:
Trace File:

Throughput Analysis:
End to end delay Analysis:

RESULT:
Thus the Distance vector Routing Algorithm was Simulated and studied.

You might also like