CN Final Part A

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

1.

Implement three nodes point – to – point network with duplex links


between them. Set the queue size, vary the bandwidth and find the
number of packets dropped.

set ns [new Simulator]


set nf [open PA1.nam w]
$ns namtrace-all $nf
set tf [open PA1.tr w]
$ns trace-all $tf

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

set n0 [$ns node]


set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 200Mb 10ms DropTail


$ns duplex-link $n2 $n3 1Mb 1000ms DropTail
$ns queue-limit $n0 $n2 10

set udp0 [new Agent/UDP]


$ns attach-agent $n0 $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 $n3 $null0
$ns connect $udp0 $null0

$ns at 0.1 "$cbr0 start"


$ns at 1.0 "finish"
$ns run

AWK FILE

BEGIN{
c=0;}
{
if($1=="d")
{ c++;
printf("%s\t%s\n",$5,$11);
}
}

END{
printf("The number of packets dropped =%d\n",c);
}

For open the editor to write the program

 Cnlab@sksjti:~$ gedit lab1.tcl


 Cnlab@sksjti:~$ gedit lab1.awk
Run the simulation program
 Cnlab@sksjti:~$ ns lab1.tcl
 Cnlab@sksjti:~$awk –f lab1.awk lab1.tr
 Cnlab@sksjti:~$ gedit lab1.tr

OUTPUT
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]

$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

Agent/Ping instproc recv {from rtt} {

$self instvar node_

puts "node [$node_ id]received answer from $from with round trip
time $rtt msec"

$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"

$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"


AWK file (Open a new editor using “gedit 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);

For open the editor to write the program

 Cnlab@sksjti:~$ gedit lab2.tcl


 Cnlab@sksjti:~$ gedit lab2.awk
Run the simulation program

 Cnlab@sksjti:~$ ns lab2.tcl

 Cnlab@sksjti:~$awk –f lab2.awk lab2.tr

 Cnlab@sksjti:~$ gedit lab2.tr


OUTPUT
3.Implement an Ethernet LAN using n nodes and set multiple traffic nodes
and plot congestion window for different source / destination.

set ns [new Simulator]


set tf [open lab7.tr w]
$ns trace-all $tf
set nf [open lab7.nam w]
$ns namtrace-all $nf
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns make-lan "$n0 $n1 $n2 $n3" 10mb 10ms LL Queue/DropTail Mac/802_3
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp0 $sink3
set tcp2 [new Agent/TCP]
$ns attach-agent $n2 $tcp2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp2 $sink1

######To trace the congestion window##########


set file1 [open file1.tr w]
$tcp0 attach $file1
$tcp0 trace cwnd_
$tcp0 set maxcwnd_ 10
set file2 [open file2.tr w]
$tcp2 attach $file2
$tcp2 trace cwnd_
proc finish { } {
global nf tf ns
$ns flush-trace
exec nam lab7.nam &
close $nf
close $tf
exit 0
}
$ns at 0.1 "$ftp0 start"
$ns at 1.5 "$ftp0 stop"
$ns at 2 "$ftp0 start"
$ns at 3 "$ftp0 stop"
$ns at 0.2 "$ftp2 start"
$ns at 2 "$ftp2 stop"
$ns at 2.5 "$ftp2 start"
$ns at 4 "$ftp2 stop"
$ns at 5.0 "finish"
$ns run

AWK FILE

BEGIN {}
{
if($6=="cwnd_")
printf("%f\t%f\t\n",$1,$7);
}
END {
}

For open the editor to write the program

 Cnlab@sksjti:~$ gedit lab3.tcl


 Cnlab@sksjti:~$ gedit lab3.awk

Run the simulation program

Cnlab@sksjti:~ awk -f lab3.awk file1.tr > a1


Cnlab@sksjti:~awk -f lab3.awk file2.tr > a2
Cnlab@sksjti:~ xgraph a1 a2

OUTPUT
4. Implement simple ESS and with transmitting nodes in wire-less LAN by
simulation and determine the performance with respect to transmission
of packets.

#create Simulator class


set ns [new Simulator]
#open trace file
set nt [open lab42.tr w]
$ns trace-all $nt
#create Topography object
set topo [new Topography]
#define grid size
$topo load_flatgrid 1000 1000
#open namtrace file
set nf [open lab42.nam w]
$ns namtrace-all-wireless $nf 1000 1000
#specify node configuration
$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 20 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON
#create General Operation Director(god) object that stores total number of mobile nodes.
create-god 4
#create nodes and label them
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$n0 label "tcp0"
$n1 label "sink0"
$n2 label "bs1"
$n3 label "bs2"
#give initial x, y, z coordinates to nodes
$n0 set X_ 110
$n0 set Y_ 500
$n0 set Z_ 0
$n1 set X_ 600

$n1 set Y_ 500


$n1 set Z_ 0
$n2 set X_ 300
$n2 set Y_ 500
$n2 set Z_ 0
$n3 set X_ 450
$n3 set Y_ 500
$n3 set Z_ 0
#attach agent and application to nodes and connect them
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1
#schedule the event
$ns at 0.5 "$ftp0 start"
#set up destination for mobile nodes. They move to <x><y> coordinates at <s>m/s.
$ns at 0.3 "$n0 setdest 110 500 10"
$ns at 0.3 "$n1 setdest 600 500 20"
$ns at 0.3 "$n2 setdest 300 500 30"
$ns at 0.3 "$n3 setdest 450 500 30"
$ns at 10.0 "$n0 setdest 100 550 5"
$ns at 10.0 "$n1 setdest 630 450 5"
$ns at 70.0 "$n0 setdest 170 680 5"
$ns at 70.0 "$n1 setdest 580 380 5"
$ns at 120.0 "$n0 setdest 140 720 5"
$ns at 135.0 "$n0 setdest 110 600 5"
$ns at 140.0 "$n1 setdest 600 550 5"
$ns at 155.0 "$n0 setdest 89 500 5"
$ns at 190.0 "$n0 setdest 100 440 5"
$ns at 210.0 "$n1 setdest 700 600 5"
$ns at 240.0 "$n1 setdest 650 500 5"
proc finish { } {
global ns nt nf
$ns flush-trace
exec nam lab42.nam &
close $nt
close $nf
exit 0
}
$ns at 400 "finish"
$ns run

AWK FILE

BEGIN{
PktsSent=0;
PktsRcvd=0;
PktsAtRTR=0;
}
{
if(($1=="s")&&($4=="RTR")&&($7=="tcp"))
{
PktsAtRTR++;
}
if(($1=="s")&&($4=="AGT")&&($7=="tcp"))
{
PktsSent++;
}
if(($1=="r")&&($4=="AGT")&&($7=="tcp"))
{
PktsRcvd++;
}
}
END{

print " Number of Packets Sent :" PktsSent

print " Number of Packets Received :" PktsRcvd

print " Pacjet Delivery Ratio :" PktsRcvd/PktsSent*100

print " Routing Load :" PktsAtRTR/PktsRcvd


}

For open the editor to write the program


 Cnlab@sksjti:~$ gedit lab3.tcl
 Cnlab@sksjti:~$ gedit lab3.awk

Run the simulation program

 Cnlab@sksjti:~ ns lab4.tcl
 Cnlab@sksjti:~ awk -f count.awk lab42.tr
 Cnlab@sksjti:~ cat lab42.tr

OUTPUT

$awk -f count.awk lab42.tr


Number of Packets Sent :6819
Number of Packets Received :6685
Pacjet Delivery Ratio :98.0349
Routing Load :1.02004
simulator

trace file

5. Implement and study the performance of GSM on NS2/NS3 (Using MAC layer)
or equivalent environment.

#General parameters
set stop 100
set type gsm
#AQM parameters
set minth 30
set maxth 0
set adaptive 1
#traffic generation
set flows 0
set window 30
#plotting statistics
set opt(wrap) 100
set opt(srcTrace) is
set opt(dstTrace) bs2
#default downlink bandwidth in bps
set bwDL(gsm) 9600
#default propogation delay in sec
set propDL(gsm) .500
set ns [new Simulator]
set tf [open Mlab5.tr w]
$ns trace-all $tf
set nodes(is) [$ns node]
set nodes(ms) [$ns node]
set nodes(bs1) [$ns node]
set nodes(bs2) [$ns node]
set nodes(lp) [$ns node]

proc cell_topo {} {
global ns nodes
$ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10ms DropTail
$ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
$ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
$ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50ms DropTail
puts "GSM Cell Topology"
}
proc set_link_params {t} {
global ns nodes bwDL propDL
$ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) duplex
$ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) duplex
$ns delay $nodes(bs1) $nodes(ms) $propDL($t) duplex
$ns delay $nodes(bs2) $nodes(ms) $propDL($t) duplex
$ns queue-limit $nodes(bs1) $nodes(ms) 10
$ns queue-limit $nodes(bs2) $nodes(ms) 10
}
#RED and TCP parameters
Queue/RED set adaptive_ $adaptive
Queue/RED set thresh_ $minth
Queue/RED set maxthresh_ $maxth
Agent/TCP set window_ $window
#create topology
switch $type {
gsm -
umts {cell_topo}
}
set_link_params $type
$ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
$ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
# set up TCP connection
if {$flows == 0} {
set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
set ftp1 [[set tcp1] attach-app FTP]
$ns at 0.8 "[set ftp1] start"
}
proc stop {} {
global nodes opt tf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
set a "Mlab5.tr"
set GETRC "../../../bin/getrc"
set RAW2XG "../../../bin/raw2xg"
exec $GETRC -s $sid -d $did -f 0 Mlab5.tr | \
$RAW2XG -s 0.01 -m $wrap -r > plot.xgr
exec $GETRC -s $did -d $sid -f 0 Mlab5.tr | \
$RAW2XG -a -s 0.01 -m $wrap >> plot.xgr
exec xgraph -x time -y packets plot.xgr &
exit 0
}
$ns at $stop "stop"
$ns run

For execution you need to change the directory

5th and 6th create .tcl file in this location : ~/ns-allinone-2.35/ns-2.35/tcl/ex/wireless-


scripts/

OUTPUT
To see the trace file use command: cat Mlab5.tr

Trace File-
6. Implement and study the performance of CDMA on NS2/NS3 (Using stack
called Call net) or equivalent environment.

#General parameters
set stop 100
set type umts
#AQM parameters
set minth 30
set maxth 0
set adaptive 1
#traffic generation
set flows 0
set window 30
#plotting statistics
set opt(wrap) 100
set opt(srcTrace) is
set opt(dstTrace) bs2
#default downlink bandwidth in bps
set bwDL(umts) 38400
#default propogation delay in sec
set propDL(umts) .150
set ns [new Simulator]
set tf [open Mlab6.tr w]
$ns trace-all $tf
set nodes(is) [$ns node]
set nodes(ms) [$ns node]
set nodes(bs1) [$ns node]
set nodes(bs2) [$ns node]
set nodes(lp) [$ns node]

proc cell_topo {} {
global ns nodes
$ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10ms DropTail
$ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
$ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
$ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50ms DropTail
puts "umts Cell Topology"
}
proc set_link_param {t} {
global ns nodes bwDL propDL
$ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) duplex
$ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) duplex
$ns delay $nodes(bs1) $nodes(ms) $propDL($t) duplex
$ns delay $nodes(bs2) $nodes(ms) $propDL($t) duplex
$ns queue-limit $nodes(bs1) $nodes(ms) 20
$ns queue-limit $nodes(bs2) $nodes(ms) 20
}
#set RED and TCP parameters
Queue/RED set adaptive_ $adaptive
Queue/RED set thresh_ $minth
Queue/RED set maxthresh_ $maxth
Agent/TCP set window_ $window
#create topology
switch $type {
umts {cell_topo}
}
set_link_param $type
$ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
$ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
#set up TCP connection
if {$flows == 0 } {
set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
set ftp1 [[set tcp1] attach-app FTP]
$ns at 0.8 "[set ftp1] start"
}
proc stop {} {
global nodes opt tf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
set a "Mlab6.tr"

set GETRC "../bin/getrc"


set RAW2XG "../bin/raw2xg"
exec $GETRC -s $sid -d $did -f 0 Mlab6.tr | \
$RAW2XG -s 0.01 -m $wrap -r > plot6.xgr
exec $GETRC -s $did -d $sid -f 0 Mlab6.tr | \
$RAW2XG -a -s 0.01 -m $wrap >> plot6.xgr
exec xgraph -x time -y packets plot6.xgr &
exit 0
}
$ns at $stop "stop"
$ns run
For execution you need to change the directory

5th and 6th create .tcl file in this location : ~/ns-allinone-2.35/ns-2.35/tcl/ex/wireless-


scripts/

OUTPUT

To see the trace file use command: cat Mlab6.tr

Trace File-

..............................THE END................................

You might also like