Program To Implement Bandwidth Vs Time of Topology in NS2

0
502

Let us create the following topology and plot the Bandwidth Vs Time graph for the topology. We can simulate the topology in NS2.

  • We need to find the packet delivery ratio at node 8,9,10.

ns2-program-awk-file

PROGRAM

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

set nr [open out.tr w]

$ns trace-all $nr

set f0 [open x1.tr w]

 

proc finish {} {

global ns nr nf

global f0

$ns flush-trace

close $nf

close $nr

close $f0

exec nam out.nam &

exec xgraph x1.tr -geometry 800*400 -x bandwidth -y time &

exit 0

}

proc record {} {

global f0 sink3

set ns [Simulator instance]

set time 0.01

set bw0 [$sink3 set bytes_]

set now [$ns now]

puts $f0 “$now $bw0”

$sink3 set bytes_ 0

$ns at [expr $now+$time] “record”

}

 

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]

set n12 [$ns node]

set n13 [$ns node]

 

$ns duplex-link $n0 $n2 2Mb 10ms RED

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

$ns duplex-link $n2 $n3 2Mb 10ms RED

$ns duplex-link $n2 $n4 1Mb 10ms FQ

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

$ns duplex-link $n3 $n5 2Mb 10ms RED

$ns duplex-link $n3 $n6 2Mb 10ms RED

$ns duplex-link $n4 $n11 1Mb 10ms FQ

$ns duplex-link $n4 $n5 2Mb 10ms RED

$ns duplex-link $n6 $n5 2Mb 10ms RED

$ns duplex-link $n6 $n7 2Mb 10ms RED

$ns duplex-link $n7 $n8 2Mb 10ms RED

$ns duplex-link $n7 $n9 2Mb 10ms RED

$ns duplex-link $n7 $n10 2Mb 10ms RED

$ns duplex-link $n11 $n12 2Mb 10ms RED

$ns duplex-link $n11 $n13 2Mb 10ms RED

 

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n1 $n2 orient down

$ns duplex-link-op $n2 $n3 orient down

$ns duplex-link-op $n2 $n4 orient right-down

$ns duplex-link-op $n3 $n4 orient right-up

$ns duplex-link-op $n3 $n5 orient right-down

$ns duplex-link-op $n3 $n6 orient down

$ns duplex-link-op $n4 $n11 orient right-up

$ns duplex-link-op $n4 $n5 orient down

$ns duplex-link-op $n6 $n5 orient right-up

$ns duplex-link-op $n6 $n7 orient down

$ns duplex-link-op $n7 $n8 orient left-down

$ns duplex-link-op $n7 $n9 orient right-down

$ns duplex-link-op $n7 $n10 orient down

$ns duplex-link-op $n11 $n12 orient right-up

$ns duplex-link-op $n11 $n13 orient right-down

 

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

set sink0 [new Agent/TCPSink]

$ns attach-agent $n8 $sink0

$ns connect $tcp0 $sink0

 

set tcp1 [new Agent/TCP]

$ns attach-agent $n0 $tcp1

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

set sink1 [new Agent/TCPSink]

$ns attach-agent $n9 $sink1

$ns connect $tcp1 $sink1

 

set tcp2 [new Agent/TCP]

$ns attach-agent $n0 $tcp2

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

set sink2 [new Agent/TCPSink]

$ns attach-agent $n10 $sink2

$ns connect $tcp2 $sink2

 

 

set tcp3 [new Agent/TCP]

$ns attach-agent $n0 $tcp3

set ftp3 [new Application/FTP]

$ftp3 attach-agent $tcp0

set sink3 [new Agent/TCPSink]

$ns attach-agent $n13 $sink3

$ns connect $tcp3 $sink3

 

set tcp4 [new Agent/TCP]

$ns attach-agent $n1 $tcp4

set ftp4 [new Application/FTP]

$ftp4 attach-agent $tcp4

set sink4 [new Agent/TCPSink]

$ns attach-agent $n8 $sink4

$ns connect $tcp4 $sink4

 

set tcp5 [new Agent/TCP]

$ns attach-agent $n1 $tcp5

set ftp5 [new Application/FTP]

$ftp5 attach-agent $tcp5

set sink5 [new Agent/TCPSink]

$ns attach-agent $n9 $sink5

$ns connect $tcp5 $sink5

 

set tcp6 [new Agent/TCP]

$ns attach-agent $n1 $tcp6

set ftp6 [new Application/FTP]

$ftp6 attach-agent $tcp6

set sink6 [new Agent/TCPSink]

$ns attach-agent $n10 $sink6

$ns connect $tcp6 $sink6

 

set tcp7 [new Agent/TCP]

$ns attach-agent $n1 $tcp7

set ftp7 [new Application/FTP]

$ftp5 attach-agent $tcp7

set sink7 [new Agent/TCPSink]

$ns attach-agent $n13 $sink7

$ns connect $tcp7 $sink7

 

$ns at 0.1 “$ftp0 start”

$ns at 3.0 “$ftp0 stop”

$ns at 0.3 “$ftp1 start”

$ns at 3.0 “$ftp1 stop”

$ns at 0.5 “$ftp2 start”

$ns at 3.0 “$ftp2 stop”

$ns at 0.8 “$ftp3 start”

$ns at 3.0 “$ftp3 stop”

 

$ns rtproto DV

$ns rtmodel-at 0.1 down $n2 $n3

$ns rtmodel-at 0.15 down $n6 $n7

$ns rtmodel-at 0.20 up $n2 $n3

$ns rtmodel-at 0.30 up $n6 $n7

 

$ns at 0.01 “record”

$ns at 1.2 “$ftp4 start”

$ns at 4.0 “$ftp4 stop”

$ns at 1.5 “$ftp5 start”

$ns at 4.0 “$ftp5 stop”

$ns at 1.7 “$ftp6 start”

$ns at 4.0 “$ftp6 stop”

$ns at 5.0 “finish”

$ns run

**************AWK File*******************

BEGIN {

rec=0;

rec1=0;

rec2=0;

send=0;

pr=0;

pr1=0;

pr2=0;

}

{

if($1==”+” && $5==”tcp” && $3==0 || $1==”+” && $5==”tcp” && $3==1)

send++;

if($1==”r” && $5==”tcp” && $4==8)

rec1++;

if($1==”r” && $5==”tcp” && $4==9)

rec++;

if($1==”r” && $5==”tcp” && $4==10)

rec2++;

}

END {

pr=rec/send;

pr1=rec1/send;

pr2=rec2/send;

printf(“packet delivery ratio at node 8 is %f\n”,pr);

printf(“packet delivery ratio at node 9 is %f\n”,pr1);

printf(“packet delivery ratio at node 10 is %f\n”,pr2);

}

Output:

throughput-ns2-program

packet-delivery-ratio-ns2-program

 

LEAVE A REPLY