Search This Blog

Thursday, July 21, 2022

NS2 - Program 3

 #    pgm3DV.tcl 

#    (6)-------(5)null0,null1

#    /     /  \

#   /        /    \ 

# (7) (11) (4)

#     / / \   \

#    / / \    \

#   (8) (9) (10) (3)

#     \ /      \

#      \  /         \ (2)

#       \/        \ /

#     cbr0(0)------------(1)cbr1


# |Time| State | Nodes |

# |====| ===== | ===== |

# | 10 | Down  | 11-05 |

# | 13 | Down  | 07-06 |

# | 20 |  Up   | 07-06 |

# | 30 |  Up   | 11-05 |

# _______________________

# All 1Mb 10ms DropTail

#


set ns [new Simulator]

$ns rtproto DV

set nf [open trace1.tr w]

$ns trace-all $nf


set nm [open out1.nam w]

$ns namtrace-all $nm


#Define a 'finish' procedure

proc finish {} {

global ns nf nm

$ns flush-trace

#Close the NAM trace file

close $nf

close $nm

exec nam out1.nam 

exit 0

}

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

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

#}

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]

set n7 [$ns node]

set n8 [$ns node]

set n9 [$ns node]

set n10 [$ns node]

set n11 [$ns node]


#creating links

#for {set i 0} {$i<9}{incr i}{

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

#} 

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

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

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

$ns duplex-link $n3 $n4 1Mb 10ms DropTail

$ns duplex-link $n4 $n5 1Mb 10ms DropTail

$ns duplex-link $n5 $n6 1Mb 10ms DropTail

$ns duplex-link $n6 $n7 1Mb 10ms DropTail

$ns duplex-link $n7 $n8 1Mb 10ms DropTail

$ns duplex-link $n0 $n9 1Mb 10ms DropTail

$ns duplex-link $n10 $n11 1Mb 10ms DropTail

$ns duplex-link $n9 $n11 1Mb 10ms DropTail

$ns duplex-link $n1 $n10 1Mb 10ms DropTail

$ns duplex-link $n11 $n5 1Mb 10ms DropTail

$ns duplex-link $n8 $n0 1Mb 10ms DropTail


#create a udp agent and attach it to node n0

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1


#Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set interval_ 0.005

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 1000

$cbr1 set interval_ 0.005


#create a Null agent(a traffic sink) and attach it to node n1

set null0 [new Agent/Null]

$ns attach-agent $n5 $null0

set null1 [new Agent/Null]

$ns attach-agent $n5 $null1

#link statistics

$ns rtmodel-at 10.0 down $n11 $n5

$ns rtmodel-at 30.0 up $n11 $n5

$ns rtmodel-at 13.0 down $n7 $n6

$ns rtmodel-at 20.0 up $n7 $n6

#Connect the traffic source to the sink

$ns connect $udp0 $null0

$ns connect $udp1 $null1

$ns at 5.0 "$cbr0 start"

$ns at 5.0 "$cbr1 start"

$ns at 45.0 "$cbr0 stop"

$ns at 45.0 "$cbr1 stop"

$ns at 45.1 "finish"


$ns run


======countDV.awk

#!/usr/bin/awk -f

BEGIN{

send = 0

recv = 0

drop = 0

route = 0

#print" Count calculation in Distance Vector Algorithm"

}

{

if( $1=="+" && ($3=="1"||$3=="0") && $5=="cbr")

{

send+=1

}

if( $1=="r" && $4=="5" && $5=="cbr")

{

recv+=1

}

if( $1=="d" )

{

drop+=1

}

if( $1=="r" &&  $5=="rtProtoDV")

{

route+=1

}

}

END{

print "count of send packets"

print send

print "count of received packets"

print recv

print "count of dropped packets"

print drop

print "count of routed packets"

print route

print "Normalized Overhead"

print route/recv

print "Packet Delivery"

print recv/send

}

======

ns pgm3DV.tcl 
ns pgm3LS.tcl 
awk -f countDV.awk trace1.tr > DV.dat
awk -f countLS.awk trace2.tr > LS.dat

No comments: