0% found this document useful (0 votes)
26 views112 pages

CN Record

Uploaded by

Bhavana 2nd year
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views112 pages

CN Record

Uploaded by

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

network simulator 2(ns2)

INTRODUCTION:
Network Simulator (Version 2), widely known as NS2, is simply an event-driven simulation
tool that has proved useful in studying the dynamic nature of communication networks. Simulation
of wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP)
can be done using NS2. In general, NS2 provides users with a way of specifying such network
protocols and simulating their corresponding behaviors.
NS2 provides users with an executable command “ns” which takes one input argument, the
name of a Tcl simulation scripting file. In most cases, a simulation trace file is created and is used
to plot graph and/or to create animation.

BASIC ARCHITECTURE:
NS2 consists of two key languages: CCC and Object-oriented Tool Command Language
(OTcl). While the CCC defines the internal mechanism (i.e., a backend) of the simulation, the OTcl
sets up simulation by assembling and configuring the objects as well as scheduling discrete events
(i.e., a frontend). The CCC and the OTcl are linked together using TclCL. Mapped to a CCC object,
variables in the OTcl domains are sometimes referred to as handles. Conceptually, a handle is just a
string (e.g., “_o10”) in the OTcl domain and does not contain any functionality. Instead, the
functionality (e.g., receiving a packet) is defined in the mapped CCC object (e.g., of class
Connector). In the OTcl domain, a handle acts as a frontend which interacts with users and other
OTcl objects. It may define its own procedures and variables to facilitate the interaction. Note that
the member procedures and variables in the OTcl domain are called instance procedures (instprocs)
and instance variables (instvars), respectively

Basic Architecture of NS

NS2 provides a large number of built-in CCC classes. It is advisable to use these CCC classes to set
up a simulation via a Tcl simulation script. However, advance users may find these objects
insufficient. They need to develop their own CCC classes and use a OTcl configuration interface to
put together objects instantiated from these class. After simulation, NS2 outputs either text-based
simulation results. To interpret these results graphically and interactively, tools such as NAM
(Network AniMator) and XGraph are used. To analyze a particular behavior of the network, users
can extract a relevant subset of text-based data and transform it to a more conceivable presentation.

1
SIMULATION NETWORK:
• Wired Network
• Routing: Distance Vector, Link State
• Transportation: TCP and UDP
• Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR, RR
• QoS: IntServ and DiffServ
• Wireless
• Ad-hoc routing and mobile IP: AODV
• Sensor-MAC, WiMAX (new)
• Power control in wireless networks
• Tracing, Visualization, Analysis, Other utilities

INSTALLATION:
• Select the Operating System
• NS2 is available for both Windows and Linux
• Linux is desirable as C++ compiler is free and easy to debug
• Check your Hardware
• Processor speed, RAM, home directory space
• Minimum 400 MB space is required
• Install NS2 in your home directory
• Follow the instructions given in the course home page
• For trouble shooting refer to the links provided in the course home page
• http://nsnam.isi.edu/nsnam/index.php/Troubleshooting
• Else, do a google search
• Solutions to most of the problems are available in the NS2 mailing list
• http://www.isi.edu/nsnam/ns/ns-lists.html

WORKING:
• Download the software
• Install NS2 in your home directory
• Compile the latest version of NS2
• Validate NS2
• Create your topology
• Need to understand the real topology and the directory structure in NS2
• Modify the existing codes
• C++ and/or .tcl files
• Create your own .tcl script for this
• Execute the script
• Analyze your result

2
FUNCTIONALITIES:
• Traffic models and applications
• Web, FTP, Telnet, CBR, real time traffic
• Transport protocols
• Unicast: TCP (Reno, New-Reno, Vegas, etc.), UDP
• Multicast: SRM
• Routing and queuing
• Wired and ad-hoc routing and directed diffusion
• Queuing protocols: RED, drop-tail, etc
• Physical media
• Wired (point-to-point, LANs), wireless (multiple propagation models), error models,
satellite.

PROTOCOLS SUPPORTED BY NS2:


• Wired Networking
• – Routing: Unicast, Multicast, and Hierarchical Routing, etc.
• – Transportation: TCP, UDP, others;
• – Traffic sources: web, ftp, telnet, cbr, etc.
• – Queuing disciplines: drop-tail, RED, etc.
• – QoS: IntServ and Diffserv Wireless Networking
• Ad hoc routing and mobile IP
• – Routing Protocol: AODV, DSDV, DSR, etc.
• – MAC layer Protocol: TDMA, CDMA(?), IEEE Mac 802.x, etc.
• – Physical layers: different channels, directional antenna
• Sensor Networks

NS2 DIRECTORY STRUCTURE:

3
AWK Programs
WIRED NETWORKS:
PROGRAM TO CALCULATE END TO END DELAY :
BEGIN {
src="0.0"; dst="4.0";
num_samples = 0;
total_delay = 0;
}
/^\+/&&$9==src&&$10==dst {
t_arr[$12] = $2;
}
/^r/&&$9==src&&$10==dst{
if (t_arr[$12] > 0) {
num_samples++;
delay = $2 - t_arr[$12];
total_delay += delay;
}
}
END{
avg_delay = total_delay/num_samples;
print "total delay" total_delay;
print "no of samples" num_samples;
print "Average end-to-end transmission delay is " avg_delay " seconds";
print "Measurement details:";
print " - Since packets are created from the address " src;
print " - Until the packets are destroyed at the address " dst;
}

PROGRAM TO CALCULATE THROUGHPUT:


BEGIN {
lineCount = 0;totalBits = 0;
}
{
if($1=="r" && $3=="0" && $4=="4") {
# converting in to bits
totalBits += 8*$6;
if(lineCount==0 ) {
timeBegin = $2; lineCount++;
} else {
timeEnd = $2;
}
}
}
END {
duration = timeEnd-timeBegin;
# print "Number of records is " NR;
# print "Output: ";
# print "Transmission: 0 to 1";
print " - Total transmitted bits = " totalBits " bits";
print " - duration = " duration " s";
print " - Throughput = " totalBits/duration/1e3 " kbps.";
}

4
WIRELESS NETWORKS:
PROGRAM TO CALCULATE END TO END DELAY:
BEGIN {
seqno=-1;dp=0;rp=0;cnt=0;
}
{
if($4=="AGT"&&$1=="s"&&seqno<$6)
{
seqno=$6;
}
else if(($4=="AGT")&&($1=="r"))
{
rp++;
}
else if($1=="D"&&$7=="tcp")
{
dp++;
}
if($4=="AGT"&&$1=="s")
{
start_time[$6]=$2;
}
else if(($4=="AGT")&&($1=="r"))
{
end_time[$6]=$2;
}
else if($1=="D"&&$7="tcp")
{
end_time[$6]=-1;
}
}
END{
for(i=0;i<=seqno;i++)
{
if(end_time[i]>0)
{
delay[i]=end_time[i]-start_time[i];cnt++;
}
else
{
delay[i]=-1;
}
}
for(i=0;i<=seqno;i++)
{
if(delay[i]>0)
{
ssdelay=ssdelay+delay[i];
}
}
ssdelay=ssdelay/(cnt+1);
printf( "average ssdelay= %.2f" ,ssdelay*1000);print "\n";
}

5
PROGRAM TO CALCULATE THROUGHPUT:
BEGIN {
recvdSize = 0
txsize=0
drpSize=0
startTime = 400
stopTime = 0
thru=0
}
{
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
# Store start time
if (level == "MAC" && event == "s")
{
if (time < startTime)
{
startTime = time
}
hdr_size = pkt_size % 400
pkt_size = hdr_size
# Store transmitted packet’s size
txsize++;
}
# Update total received packets’ size and store packets arrival time
if (level == "RTR" && event == "r")
{
if (time > stopTime)
{
stopTime = time
}
# Rip off the header
hdr_size = pkt_size % 400
pkt_size = hdr_size
# Store received packet’s size
recvdSize++
thru=(recvdSize/txsize)
printf(" %.2f %.2f \n" ,time,thru)>"sst.tr"
}
if (level == "AGT" && event == "d" )
{
hdr_size = pkt_size % 400
pkt_size = hdr_size
# Store received packet’s size
drpSize++
}
}
END {
printf("Average Throughput[kbps] = %.2f\t",(recvdSize/(stopTime-startTime)))
}

6
PROGRAM FOR CALCULATING PACKET DELIVERY RATIO:
BEGIN {
sent=0;
received=0;
}
{
if($1=="s" && $4=="MAC")
{
sent++;
}
else if($1=="r" && $4=="RTR")
{
received++;
}
}
END{
printf (" Packet Sent:%d",sent);
printf ("\n Packet Received:%d",received);
printf ("\n Packet Delivery Ratio:%.2f\n",(received/sent)*100);
}

PROGRAM FOR CALCULATING ENERGY:


BEGIN {
initialenergy = 90
maxenergy=0
n=50
nodeid=999
}
{
17
# Trace line format: energy
event = $1
time = $2
if (event == "r" || event == "d" || event =="s"|| event=="f") {
node_id = $9
energy=$17
}
if (event=="N"){
node_id = $5
energy=$7
}
# Store remaining energy
finalenergy[node_id]=energy
}
END {
# Compute consumed energy for each node
for (i in finalenergy) {
consumenergy[i]=initialenergy-finalenergy[i]
totalenergy +=consumenergy[i]
if(maxenergy<consumenergy[i]){
maxenergy=consumenergy[i]
nodeid=i

7
}
}
###compute average energy
averagenergy=totalenergy/n
####output
for (i=0; i<n; i++) {
print("node",i, consumenergy[i])
}
print("====================")
print("average",averagenergy)
print("====================")
print("total energy",totalenergy)
print("====================")
}

8
Experiment-1: Writing a TCL Script to create
two nodes and link between nodes

AIM:
To write a TCL Script to create two nodes with duplex, simplex links between the nodes

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
Transmission mode means transferring of data between two devices. It is also known as
communication mode. Buses and networks are designed to allow communication to occur between
individual devices that are interconnected. There are three types of transmission mode. In Simplex
mode, the communication is unidirectional, as on a one-way street. Only one of the two devices on
a link can transmit, the other can only receive. In half-duplex mode, each station can both transmit
and receive, but not at the same time. When one device is sending, the other can only receive, and
vice versa. In full-duplex mode, both stations can transmit and receive simultaneously. In full-
duplex mode, signals going in one direction share the capacity of the link with signals going in
other direction.

PROCEDURE:
 Open the text editor and type the TCL script and save the file with .tcl extension.
 Contents on the directory can be viewed by using command "ls".
 Execute the TCL File by giving command "ns <filename> .tcl".
 The Network Animator (NAM) window is opened and nodes and links are seen.
 Corresponding trace file and nam file are generated.
 Trace file has no information as we are not transferring any data here.

9
TCL SCRIPT

Duplex Link:
set val(stop) 10.0 ;# time of simulation end
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open E1d.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open E1d.nam w]
$ns namtrace-all $namfile

#Create 2 nodes
set n0 [$ns node]
set n1 [$ns node]

#Createlinks between nodes


$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam E1d.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

10
Simplex Link:
set val(stop) 10.0 ;# time of simulation end
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open E1s.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open E1s.nam w]
$ns namtrace-all $namfile

#Create 2 nodes
set n0 [$ns node]
set n1 [$ns node]

#Createlinks between nodes


$ns simplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50

#Give node position (for NAM)


$ns simplex-link-op $n0 $n1 orient right

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam E1s.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

11
APPLICATIONS:
1 )Node to Node transmission is used for short distance communications.
2 )They are also used in telephone networks.
3 )They are also used in internet at various levels of hierarchy.
4 )They are used in every physical topology like LAN, WAN.

RESULT:
Hence the TCL Script has been written for creation of 2 nodes and link between the nodes.

12
Experiment-2: Writing a TCL Script
to transmit data between nodes

AIM:
To write a TCL Script to transmit data between two nodes through wireless and wired
medium.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
Transmission mode means transferring of data between two devices. It is also known as
communication mode. Buses and networks are designed to allow communication to occur between
individual devices that are interconnected. There are three types of transmission mode. In Simplex
mode, the communication is unidirectional, as on a one-way street. Only one of the two devices on
a link can transmit, the other can only receive. In half-duplex mode, each station can both transmit
and receive, but not at the same time. When one device is sending, the other can only receive, and
vice versa. In full-duplex mode, both stations can transmit and receive simultaneously. In full-
duplex mode, signals going in one direction share the capacity of the link with signals going in
other direction.

PROCEDURE:
 Open the text editor and type the TCL script and save the file with .tcl extension.
 Contents on the directory can be viewed by using command "ls".
 Execute the TCL File by giving command "ns <filename> .tcl".
 The Network Animator (NAM) window is opened and nodes and links are seen.
 Corresponding trace file and nam file are generated.
 Trace file has no information as we are not transferring any data here.

13
WIRELESS SCENARIO:
TCL SCRIPT:
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 2 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 902 ;# X dimension of topography
set val(y) 701 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open E2wl.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open E2wl.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

$ns node-config -adhocRouting $val(rp) \


-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \

14
-movementTrace ON

#Create 2 nodes
set n0 [$ns node]
$n0 set X_ 598
$n0 set Y_ 599
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 802
$n1 set Y_ 601
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20

#Setup a UDP connection


set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n1 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#Setup a CBR Application over UDP connection


set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam E2wl.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

15
TRACE FILE:
s 0.000821201 _0_ RTR --- 0 message 32 [0 0 0 0] ------- [0:255 -1:255 32 0]
s 0.001216201 _0_ MAC --- 0 message 90 [0 ffffffff 0 800] ------- [0:255 -1:255 32 0]
r 0.001936881 _1_ MAC --- 0 message 32 [0 ffffffff 0 800] ------- [0:255 -1:255 32 0]
r 0.001961881 _1_ RTR --- 0 message 32 [0 ffffffff 0 800] ------- [0:255 -1:255 32 0]
s 1.000000000 _0_ AGT --- 1 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [0] 0 0
r 1.000000000 _0_ RTR --- 1 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [0] 0 0
s 1.008000000 _0_ AGT --- 2 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [1] 0 0
r 1.008000000 _0_ RTR --- 2 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [1] 0 0
s 1.016000000 _0_ AGT --- 3 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [2] 0 0
r 1.016000000 _0_ RTR --- 3 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [2] 0 0
s 1.024000000 _0_ AGT --- 4 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [3] 0 0
r 1.024000000 _0_ RTR --- 4 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [3] 0 0
s 1.032000000 _0_ AGT --- 5 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [4] 0 0
r 1.032000000 _0_ RTR --- 5 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [4] 0 0
s 1.040000000 _0_ AGT --- 6 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [5] 0 0
r 1.040000000 _0_ RTR --- 6 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [5] 0 0
D 1.040000000 _0_ RTR IFQ 1 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [0] 0 0
s 1.048000000 _0_ AGT --- 7 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [6] 0 0
r 1.048000000 _0_ RTR --- 7 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [6] 0 0
D 1.048000000 _0_ RTR IFQ 2 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [1] 0 0
s 1.056000000 _0_ AGT --- 8 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [7] 0 0
r 1.056000000 _0_ RTR --- 8 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [7] 0 0
D 1.056000000 _0_ RTR IFQ 3 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [2] 0 0
s 1.064000000 _0_ AGT --- 9 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [8] 0 0
r 1.064000000 _0_ RTR --- 9 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [8] 0 0
D 1.064000000 _0_ RTR IFQ 4 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [3] 0 0
s 1.072000000 _0_ AGT --- 10 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [9] 0 0
r 1.072000000 _0_ RTR --- 10 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [9] 0 0
D 1.072000000 _0_ RTR IFQ 5 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [4] 0 0
s 1.080000000 _0_ AGT --- 11 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [10] 0 0
r 1.080000000 _0_ RTR --- 11 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [10] 0 0
D 1.080000000 _0_ RTR IFQ 6 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [5] 0 0
s 1.088000000 _0_ AGT --- 12 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [11] 0 0
r 1.088000000 _0_ RTR --- 12 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [11] 0 0
D 1.088000000 _0_ RTR IFQ 7 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [6] 0 0
s 1.096000000 _0_ AGT --- 13 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [12] 0 0
r 1.096000000 _0_ RTR --- 13 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [12] 0 0
D 1.096000000 _0_ RTR IFQ 8 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [7] 0 0
s 1.104000000 _0_ AGT --- 14 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [13] 0 0
r 1.104000000 _0_ RTR --- 14 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [13] 0 0
D 1.104000000 _0_ RTR IFQ 9 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [8] 0 0
s 1.112000000 _0_ AGT --- 16 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [14] 0 0
r 1.112000000 _0_ RTR --- 16 cbr 1000 [0 0 0 0] ------- [0:0 1:0 32 0] [14] 0 0
D 1.112000000 _0_ RTR IFQ 10 cbr 1020 [0 0 0 0] ------- [0:0 1:0 32 0] [9] 0 0

16
WIRED SCENARIO:
TCL SCRIPT:
set val(stop) 10.0 ;# time of simulation end

#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open E2w.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open E2w.nam w]
$ns namtrace-all $namfile

#Create 2 nodes
set n0 [$ns node]
set n1 [$ns node]

#Createlinks between nodes


$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
#Give node position (for NAM)
$ns duplex-link-op $n0 $n1 orient right

#Setup a TCP connection


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#Setup a FTP Application over TCP connection


set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam E2w.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"

17
$ns run

TRACE FILE:
+ 1 0 1 tcp 40 ------- 0 0.0 1.0 0 0
- 1 0 1 tcp 40 ------- 0 0.0 1.0 0 0
r 1.010003 0 1 tcp 40 ------- 0 0.0 1.0 0 0
+ 1.010003 1 0 ack 40 ------- 0 1.0 0.0 0 1
- 1.010003 1 0 ack 40 ------- 0 1.0 0.0 0 1
r 1.020006 1 0 ack 40 ------- 0 1.0 0.0 0 1
+ 1.020006 0 1 tcp 1540 ------- 0 0.0 1.0 1 2
- 1.020006 0 1 tcp 1540 ------- 0 0.0 1.0 1 2
+ 1.020006 0 1 tcp 1540 ------- 0 0.0 1.0 2 3
- 1.02013 0 1 tcp 1540 ------- 0 0.0 1.0 2 3
r 1.03013 0 1 tcp 1540 ------- 0 0.0 1.0 1 2
+ 1.03013 1 0 ack 40 ------- 0 1.0 0.0 1 4
- 1.03013 1 0 ack 40 ------- 0 1.0 0.0 1 4
r 1.030253 0 1 tcp 1540 ------- 0 0.0 1.0 2 3
+ 1.030253 1 0 ack 40 ------- 0 1.0 0.0 2 5
- 1.030253 1 0 ack 40 ------- 0 1.0 0.0 2 5
r 1.040133 1 0 ack 40 ------- 0 1.0 0.0 1 4
+ 1.040133 0 1 tcp 1540 ------- 0 0.0 1.0 3 6
- 1.040133 0 1 tcp 1540 ------- 0 0.0 1.0 3 6
+ 1.040133 0 1 tcp 1540 ------- 0 0.0 1.0 4 7
r 1.040256 1 0 ack 40 ------- 0 1.0 0.0 2 5
+ 1.040256 0 1 tcp 1540 ------- 0 0.0 1.0 5 8
+ 1.040256 0 1 tcp 1540 ------- 0 0.0 1.0 6 9
- 1.040256 0 1 tcp 1540 ------- 0 0.0 1.0 4 7
- 1.040379 0 1 tcp 1540 ------- 0 0.0 1.0 5 8
- 1.040502 0 1 tcp 1540 ------- 0 0.0 1.0 6 9
r 1.050256 0 1 tcp 1540 ------- 0 0.0 1.0 3 6
+ 1.050256 1 0 ack 40 ------- 0 1.0 0.0 3 10
- 1.050256 1 0 ack 40 ------- 0 1.0 0.0 3 10
r 1.050379 0 1 tcp 1540 ------- 0 0.0 1.0 4 7
+ 1.050379 1 0 ack 40 ------- 0 1.0 0.0 4 11
- 1.050379 1 0 ack 40 ------- 0 1.0 0.0 4 11
r 1.050502 0 1 tcp 1540 ------- 0 0.0 1.0 5 8
+ 1.050502 1 0 ack 40 ------- 0 1.0 0.0 5 12
- 1.050502 1 0 ack 40 ------- 0 1.0 0.0 5 12
r 1.050626 0 1 tcp 1540 ------- 0 0.0 1.0 6 9
+ 1.050626 1 0 ack 40 ------- 0 1.0 0.0 6 13
- 1.050626 1 0 ack 40 ------- 0 1.0 0.0 6 13
r 1.060259 1 0 ack 40 ------- 0 1.0 0.0 3 10
+ 1.060259 0 1 tcp 1540 ------- 0 0.0 1.0 7 14

18
NS2 CONFIGURATION:

APPLICATIONS:
1 )Node to Node transmission is used for short distance communications.
2 )They are also used in telephone networks.
3 )They are also used in internet at various levels of hierarchy.
4 )They are used in every physical topology like LAN, WAN.

RESULT:
TCL Script is written for transmission of data between two nodes in both wired and
wireless scenario and packets transfer is observed.

19
Experiment-3 :Evaluate the performance
of various LAN Topologies

AIM:
To evaluate the performance of Mesh, Star, Ring LAN topologies in both wired and wireless
medium.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
Network topology is the arrangement of the elements (links, nodes, etc.) of a communication
network. Network topology is the topological structure of a network and may be depicted physically or
logically. It is an application of graph theory where in communicating devices are modeled as nodes and
the connections between the devices are modeled as links or lines between the nodes. Physical topology
is the placement of the various components of a network (e.g., device location and cable installation),
while logical topology illustrates how data flows within a network. Distances between nodes, physical
interconnections, transmission rates, or signal types may differ between two different networks, yet their
logical topologies may be identical. A network’s physical topology is a particular concern of the
physical layer of the OSI model. A wide variety of physical topologies have been used in LANs,
including ring, bus, mesh and star. Conversely, mapping the data flow between the components
determines the logical topology of the network. There are different types of LAN Topologies like Mesh,
Star, Ring, Bus etc ;

PROCEDURE:
 Open the Terminal and change the directory to where NSG2.1 is present by using cd <Directory
Name>.
 Contents in the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to the requirement.
 Place desired number of nodes and connect the nodes with links in star, mesh and ring
topology.
 Select a source node and a destination node and give their agents as TCP, TCP Sink for wired
network and UDP, Null for wireless network respectively.
 Give application as FTP for TCP and CBR for UDP.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to TCL script and save it with .tcl extension.
 Execute the TCL file by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.

20
 The end to end delay , packet delivery ratio , throughput, energy can be calculated in wireless
scenario and end to end delay, throughput can be calculated in wired scenario by using
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and evaluate the performance of Mesh, Star, Ring Topologies.

WIRED SCENARIO:
MESH:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>
set val(stop) 10.0 ;# time of simulation end

#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open e33w.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open e33w.nam w]
$ns namtrace-all $namfile
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#Createlinks between nodes


$ns duplex-link $n0 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n4 50
$ns duplex-link $n4 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n3 50
$ns duplex-link $n3 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n2 50
$ns duplex-link $n2 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n1 50
$ns duplex-link $n1 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n0 50
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n3 50
$ns duplex-link $n4 $n1 100.0Mb 10ms DropTail

21
$ns queue-limit $n4 $n1 50
$ns duplex-link $n4 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n2 50
$ns duplex-link $n3 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n1 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n4 orient right-down
$ns duplex-link-op $n4 $n3 orient left-down
$ns duplex-link-op $n3 $n2 orient left

$ns duplex-link-op $n2 $n1 orient left-up


$ns duplex-link-op $n1 $n0 orient right-up
$ns duplex-link-op $n0 $n2 orient left-down
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n4 $n1 orient left-down
$ns duplex-link-op $n4 $n2 orient left-down
$ns duplex-link-op $n3 $n1 orient left-up

#Setup a TCP connection


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#Setup a FTP Application over TCP connection


set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam e33w.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

22
STAR:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open e32w.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open e32w.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n1 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n0 50
$ns duplex-link $n0 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n4 50
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n3 50
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail

23
$ns queue-limit $n0 $n2 50

#Give node position (for NAM)


$ns duplex-link-op $n1 $n0 orient right-down
$ns duplex-link-op $n0 $n4 orient right-up
$ns duplex-link-op $n0 $n3 orient left-down
$ns duplex-link-op $n0 $n2 orient left-up

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam e32w.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

24
RING:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n4 50
$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 50
$ns duplex-link $n3 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail

25
$ns queue-limit $n1 $n2 50
$ns duplex-link $n1 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n0 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n4 orient right-down
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n2 orient left-down
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n1 $n0 orient right-up

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

26
WIRELESS SCENARIO:
MESH:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 5 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 957 ;# X dimension of topography
set val(y) 659 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open e33wl.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open e33wl.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================

27
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
$n0 set X_ 780
$n0 set Y_ 559
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 479
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 857
$n2 set Y_ 476
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 772
$n3 set Y_ 406
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 855
$n4 set Y_ 536
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20

28
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam e33wl.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

29
STAR:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 5 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1196 ;# X dimension of topography
set val(y) 824 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open e32wl.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open e32wl.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================

30
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
$n0 set X_ 848
$n0 set Y_ 483
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 837
$n1 set Y_ 724
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 602
$n2 set Y_ 488
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 852
$n3 set Y_ 248
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 1096
$n4 set Y_ 499
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20

31
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam e32wl.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

32
RING:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 5 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1618 ;# X dimension of topography
set val(y) 100 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open e31wl.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open e31wl.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup

33
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
$n0 set X_ 837
$n0 set Y_ 696
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 1002
$n1 set Y_ 579
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 936
$n2 set Y_ 407
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 754
$n3 set Y_ 406
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 678
$n4 set Y_ 567
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20

34
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam e31wl.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

35
NSG2.1 SIMULATION:

36
APPLICATIONS:
1 )LAN Topologies are used in schools, offices and hospitals.
2 ) They are also used in home access internet.
3 )They are also used in manufacturing industries .
4 ) They are also used to connect slower devices together.

CALCULATIONS:
WIRED SCENARIO:
Queue Management
Number of nodes End to End Delay Throughput(kbps)
Schemes
Mesh 5 9.44 11590.8
Star 5 9.44 11590.8
Ring 5 9.44 11590.8

WIRELESS SCENARIO:
Queue Packet
Number of End to End
Management Throughput Delivery Energy
nodes Delay
Schemes Ratio
Mesh 5 131.87 73.12 28.43 10.72
Star 5 132.02 67.07 26.08 10.72
Ring 5 131.98 68.08 26.47 10.72

RESULT:
The performance of Mesh, Star, Ring Topologies are calculated and compared.

37
Experiment-4: Evaluate the performance
of Drop-Tail and RED queue management schemes

AIM:
To evaluate the performance of Drop Tail and RED Queue Management Schemes in wired
scenario.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
Drop tail is a simple queue mechanism that is used by the routers that when packets should to
be drop. In this mechanism each packet is treated identically and when queue filled to its maximum
capacity the newly incoming packets are dropped until queue have sufficient space to accept incoming
traffic. But in drop tail when a queue is filled the router start to discard all extra packets thus dropping
the tail of mechanism. The loss of packets (datagram’s) causes the sender to enter slow start which
decreases the throughput and thus increases its congestion window.
Random Early Detection (RED) is a congestion avoidance queuing mechanism (as opposed to a
congestion administration mechanism) that is potentially useful, particularly in high-speed transit
networks. It is active queue management mechanism. It operates on the average queue size and drop
packets on the basis of statistics information. If the buffer is empty all incoming packets are
acknowledged. As the queue size increase the probability for discarding a packet also increase. When
buffer is full probability becomes equal to 1 and all incoming packets are dropped. RED is capable to
evade global synchronization of TCP flows, preserve high throughput as well as a low delay and attains
fairness over multiple TCP connections, etc. It is the most common mechanism to stop congestive
collapses.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail or RED and connect the
nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink.
 Give application as FTP for TCP.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to TCL script and save it with .tcl extension.
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.

38
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of Drop-Tail and RED Queue
Management Schemes.

DROP TAIL:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open ring.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open ring.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail

39
$ns queue-limit $n3 $n4 50
$ns duplex-link $n4 $n5 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n5 50
$ns duplex-link $n5 $n0 100.0Mb 10ms DropTail
$ns queue-limit $n5 $n0 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient left-down
$ns duplex-link-op $n3 $n4 orient left

$ns duplex-link-op $n4 $n5 orient left-up


$ns duplex-link-op $n5 $n0 orient right-up
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam ring.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

40
RED:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfil
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms RED
$ns queue-limit $n0 $n1 50
$ns duplex-link $n1 $n2 100.0Mb 10ms RED
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms RED
$ns queue-limit $n2 $n3 50
$ns duplex-link $n3 $n4 100.0Mb 10ms RED
$ns queue-limit $n3 $n4 50
$ns duplex-link $n4 $n5 100.0Mb 10ms RED
$ns queue-limit $n4 $n5 50

41
$ns duplex-link $n0 $n5 100.0Mb 10ms RED
$ns queue-limit $n0 $n5 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient left-down
$ns duplex-link-op $n3 $n4 orient left

$ns duplex-link-op $n4 $n5 orient left-up


$ns duplex-link-op $n0 $n5 orient left-down
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

42
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) Queue management schemes are used to control internet traffic.
2 ) They are used to reduce end to end delay.
3 ) They are used in http protocols.
4 ) They are used in congestion control mechanisms.

CALCULATION:
Queue Management
Number of Nodes End To End Delay Throughput
Schemes
Drop Tail 6 9.44 11590.8
RED 6 9.44 11590.8

RESULT:
The performance of Drop-Tail and Red queue Management schemes are evaluated. The
throughput and end to end delay are also calculated

43
Experiment-5: Evaluate the performance
of SFQ and FQ Scheduling Mechanisms

AIM:
To evaluate the performance of FQ and SFQ scheduling Mechanisms in wired scenario.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
Fair queuing (FQ) is a queuing mechanism that is used to allow multiple packets flow to
comparatively share the link capacity. Routers have multiple queues for each output line for every
user. When a line as available as idle routers scans the queues through round robin and takes first
packet to next queue. FQ also ensure about the maximum throughput of the network. For more
efficiency weighted queue mechanism is also used.
Stochastic fair queuing (SFQ) is a queuing mechanism is based on fair queuing algorithm
and proposed by John Nagle in 1987. Because it is impractical to have one queue for each
conversation SFQ uses a hashing algorithm which divides the traffic over a limited number of
queues. It is not so efficient than other queues mechanisms but it also requires less calculation while
being almost perfectly fair. It is called "Stochastic" due to the reason that it does not actually assign
a queue for every session; it has an algorithm which divides traffic over a restricted number of
queues using a hashing algorithm. SFQ assigns a pretty large number of FIFO queues.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as FQ or SFQ and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink.
 Give application as FTP for TCP.
 Go to parameters and change the name of trace file, nam file accordindly and click on done.
 Go to TCL script and save it with .tcl extension.
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of FQ and SFQ scheduling mechanisms.

44
SFQ:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open sfq.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open sfq.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms SFQ
$ns queue-limit $n0 $n1 50
$ns duplex-link $n2 $n1 100.0Mb 10ms SFQ
$ns queue-limit $n2 $n1 50
$ns duplex-link $n2 $n3 100.0Mb 10ms SFQ
$ns queue-limit $n2 $n3 50
$ns duplex-link $n3 $n4 100.0Mb 10ms SFQ
$ns queue-limit $n3 $n4 50
$ns duplex-link $n4 $n5 100.0Mb 10ms SFQ
$ns queue-limit $n4 $n5 50

45
$ns duplex-link $n5 $n0 100.0Mb 10ms SFQ
$ns queue-limit $n5 $n0 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n2 $n1 orient left-up
$ns duplex-link-op $n2 $n3 orient left-down
$ns duplex-link-op $n3 $n4 orient left

$ns duplex-link-op $n4 $n5 orient left-up


$ns duplex-link-op $n5 $n0 orient right-up
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam sfq.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

46
FQ:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation en
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n1 $n2 100.0Mb 10ms FQ
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms FQ
$ns queue-limit $n2 $n3 50
$ns duplex-link $n4 $n3 100.0Mb 10ms FQ
$ns queue-limit $n4 $n3 50
$ns duplex-link $n4 $n5 100.0Mb 10ms FQ
$ns queue-limit $n4 $n5 50
$ns duplex-link $n0 $n5 100.0Mb 10ms FQ
$ns queue-limit $n0 $n5 50

47
$ns duplex-link $n0 $n1 100.0Mb 10ms FQ
$ns queue-limit $n0 $n1 50

#Give node position (for NAM)


$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient left-down
$ns duplex-link-op $n4 $n3 orient right
$ns duplex-link-op $n4 $n5 orient left-up
$ns duplex-link-op $n0 $n5 orient left-down
$ns duplex-link-op $n0 $n1 orient right
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

48
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) Queue management schemes are used to control internet traffic.
2 ) They are used to reduce end to end delay.
3 ) They are used in http protocols.
4 ) They are used in congestion control mechanisms.

CALCULATIONS:
Scheduling
Number of Nodes End To End Delay Throughput
Mechanisms
FQ 6 9.44 11590.8
SFQ 6 9.44 11590.8

RESULT:
The performance of SFQ and FQ Scheduling Mechanisms are evaluated. The throughput
and end to end delay are also calculated.

49
Experiment-6: Evaluate the performance
of TCP and UDP Protocols

AIM:
To evaluate the performance of TCP and UDP protocols in wireless scenario .

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
TCP is a connection-oriented protocol. Connection-orientation means that the
communicating devices should establish a connection before transmitting data and should close the
connection after transmitting the data.
UDP is the Datagram oriented protocol. This is because there is no overhead for opening a
connection, maintaining a connection, and terminating a connection. UDP is efficient for broadcast
and multicast type of network transmission. TCP is reliable as it guarantees delivery of data to the
destination router. The delivery of data to the destination cannot be guaranteed in UDP. TCP
provides extensive error checking mechanisms. It is because it provides flow control and
acknowledgment of data.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink in wired
scenario and UDP, Null in wireless scenario.
 Give application as FTP for TCP, CBR for UDP.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to TCL script and save it with .tcl extension.
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of TCP and UDP protocols.

50
TCP:
TCL SCRIPT:

# This script is created by NSG2 beta1


# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 900 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open tcp.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open tcp.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

51
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 501
$n0 set Y_ 699
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 701
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 800
$n2 set Y_ 597
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 700
$n3 set Y_ 438
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 500
$n4 set Y_ 432
$n4 set Z_ 0.0

52
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 400
$n5 set Y_ 544
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam tcp.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

53
UDP:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 899 ;# X dimension of topography
set val(y) 799 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open udp.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open udp.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

54
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 699
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 701
$n1 set Y_ 699
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 799
$n2 set Y_ 598
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 700
$n3 set Y_ 402
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 498
$n4 set Y_ 398
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401

55
$n5 set Y_ 559
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp1 [new Agent/UDP]
$ns attach-agent $n0 $udp1
set null0 [new Agent/Null]
$ns attach-agent $n5 $null0
$ns connect $udp1 $null0
$udp1 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp1
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam udp.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

56
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) It helps you to establish/set up a connection between different types of computers.
2 ) Operates independently of the operating system
3 ) Supports many routing-protocols.
4 ) UDP method is largely used by time-sensitive applications as well as by servers that
answer small queries from a larger client base.
5 )UDP is compatible with packet broadcasts for sending all over the network and for
multicasting sending.

CALCULATIONS:
Packet
Number of End to End
Protocols Throughput Delivery Energy
nodes Delay
Ratio
TCP 6 120.45 68.58 26.29 18
UDP 6 66.16 68.92 60.35 10.7

RESULT:
The performance of TCP and UDP protocols are evaluated. The throughput , end to end
delay , packet delivery ratio and energy are also calculated.

57
Experiment-7: Evaluate the performance
of TCP, New Reno and Vegas

AIM:
To evaluate the performance of TCP, TCP New Reno, TCP Vegas in wireless scenario.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
TCP is a reliable connection oriented end-to-end protocol. It contains within itself, mechanisms for
ensuring reliability by requiring the receiver the acknowledge the segments that it receives. The network is
not perfect and a small percentage of packets are lost en route, either due to network error or due to the fact
that there is congestion in the network and the routers are dropping packets. We shall assume that packet
losses due to network loss are minimal and most of the packet losses are due to buffer overflows at the router
This Reno retains the basic principle of Tahoe, such as slow starts and the coarse grain re-transmit
timer. However it adds some intelligence over it so that lost packets are detected earlier and the pipeline is
not emptied every time a packet is lost.
New RENO is a slight modification over TCP-RENO. It is able to detect multiple packet losses and
thus is much more efficient that RENO in the event of multiple packet losses. Like Reno, New-Reno also
enters into fast-retransmit when it receives multiple duplicate packets, however it differs from RENO in that
it doesn’t exit fast-recovery until all the data which was out standing at the time it entered fast recovery is
acknowledged. Thus it overcomes the problem faced by Reno of reducing the CWD multiples times.
Vegas is a TCP implementation which is a modification of Reno. It builds on the fact that proactive
measure to encounter congestion are much more efficient than reactive ones. It tried to get around the
problem of coarse grain timeouts by suggesting an algorithm which checks for timeouts at a very efficient
schedule. Also it overcomes the problem of requiring enough duplicate acknowledgements to detect a packet
loss, and it also suggest a modified slow start algorithm which prevent it from congesting the network. It
does not depend solely on packet loss as a sign of congestion. It detects congestion before the packet losses
occur.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select the source node with TCP , TCP New Reno, TCP Vegas as agent and destination
node with TCP Sink agent. Then give FTP as agent to source node only.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to TCL script and save it with .tcl extension.

58
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of TCP, New Reno, Vegas.

TCP:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 900 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open tcp.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open tcp.nam w]
$ns namtrace-all $namfile

59
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 501
$n0 set Y_ 699
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 701
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 800
$n2 set Y_ 597
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 700
$n3 set Y_ 438
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 500
$n4 set Y_ 432

60
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 400
$n5 set Y_ 544
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam tcp.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

61
NEW RENO:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 899 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open newreno.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open newreno.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

62
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 496
$n0 set Y_ 701
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 799
$n2 set Y_ 598
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 707
$n3 set Y_ 402
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 499
$n4 set Y_ 397
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 399

63
$n5 set Y_ 552
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP/Newreno connection
set tcp0 [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP/Newreno connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam newreno.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

64
VEGAS:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 900 ;# X dimension of topography
set val(y) 799 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open vegas.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open vegas.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

65
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 699
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 699
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 800
$n2 set Y_ 600
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 702
$n3 set Y_ 400
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 500
$n4 set Y_ 401
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 400

66
$n5 set Y_ 557
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP/Vegas connection
set tcp0 [new Agent/TCP/Vegas]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP/Vegas connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam vegas.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

67
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) It helps you to establish/set up a connection between different types of computers.
2 ) Operates independently of the operating system
3 ) Supports many routing-protocols.
4 )It enables the internetworking between the organizations.
5 ) TCP can be used to establish a connection between two computers.

CALCULATIONS:
Packet
TCP Number of End to End
Throughput Delivery Energy
Extensions nodes Delay
Ratio
TCP 6 120.45 68.58 26.29 18
New Reno 6 120.45 68.58 26.29 18
Vegas 6 29.42 30.07 29.56 18

RESULT:
The performance of TCP , TCP New Reno and TCP Vegas protocols are evaluated. The
throughput , end to end delay , packet delivery ratio and energy are also calculated.

68
Experiment-8: Evaluate the performance
of AODV and DSR routing protocols

AIM:
To evaluate the performance of AODV and DSR Routing protocols in wireless scenario
using both TCP and UDP.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
AODV (Ad-hoc On-demand Distance Vector)[7] is a loop-free routing protocol for ad-hoc
networks. It is designed to be self-starting in an environment of mobile nodes, withstanding a
variety of network behaviours such as node mobility, link failures and packet losses. At each node,
AODV maintains a routing table. The routing table entry for a destination contains three essential
fields: a next hop node, a sequence number and a hop count. All packets destined to the destination
are sent to the next hop node. The sequence number acts as a form of time-stamping, and is a
measure of the freshness of a route. The hop count represents the current distance to the destination
node.
Dynamic Source Routing (DSR) is a self-maintaining routing protocol for wireless
networks. The protocol can also function with cellular telephone systems and mobile networks with
up to about 200 nodes. A Dynamic Source Routing network can configure and organize itself
independently of oversight by human administrators. In Dynamic Source Routing, each source
determines the route to be used in transmitting its packets to selected destinations. There are two
main components, called Route Discovery and Route Maintenance. Route Discovery determines the
optimum path for a transmission between a given source and destination.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink for 1st time
and UDP, Null next in wireless scenario.
 Give application as FTP for TCP, CBR for UDP.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to parameters and select routing protocol as AODV or DSR and click on done. Go to tcl
script and save it with .tcl extension.
 Execute the TCL File by giving command "ns <filename> .tcl".

69
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of TCP and UDP protocols.

AODV(TCP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open aodv.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open aodv.nam w]
$ns namtrace-all $namfile

70
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 501
$n0 set Y_ 700
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 702
$n1 set Y_ 698
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 596
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 703
$n3 set Y_ 400
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501

71
$n4 set Y_ 398
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401
$n5 set Y_ 550
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam aodv.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

72
DSR(TCP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 902 ;# X dimension of topography
set val(y) 798 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open dsr1.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open dsr1.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

73
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 502
$n0 set Y_ 698
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 702
$n1 set Y_ 698
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 802
$n2 set Y_ 599
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 701
$n3 set Y_ 397
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501
$n4 set Y_ 396
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 399

74
$n5 set Y_ 563
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam dsr1.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

75
AODV(UDP):
TCL FILE:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open aodv2.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open aodv2.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

76
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 700
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 700
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 598
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 701
$n3 set Y_ 397
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 499
$n4 set Y_ 399
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 403

77
$n5 set Y_ 564
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n5 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam aodv2.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

78
DSR(UDP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 798 ;# X dimension of topography
set val(y) 804 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open dsr2.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open dsr2.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

79
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 398
$n0 set Y_ 703
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 601
$n1 set Y_ 704
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 698
$n2 set Y_ 600
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 600
$n3 set Y_ 400
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 403
$n4 set Y_ 399
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 298

80
$n5 set Y_ 565
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n5 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam dsr2.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

81
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) AODV are used in military applications
2 ) AODV minimises the number of broadcasts
3 ) AODV sends hello messages to know it's neighbours
4 )The DSR supports the following DSR Applications that use and enhance the
functions of the Diameter protocol for message processing:
FABR, RABR, CPA, PCA, GLA etc;

CALCULATIONS:
TCP:
Packet
Routing Number of End to End
Throughput Delivary Energy
Protocols nodes Delay
Ratio
AODV 6 123.97 133.99 25.74 18
DSR 6 127.73 246.30 48.89 27

UDP:
Packet
Routing Number of End to End
Throughput Delivary Energy
Protocols nodes Delay
Ratio
AODV 6 137.85 137.17 26.46 14.3
DSR 6 148.02 201.62 49.61 19.7

RESIULT:
The performance of AODV and DSR Routing protocols are evaluated using TCP and
UDP. The throughput , end to end delay , packet delivery ratio and energy are also calculated.

82
Experiment-9: Evaluate the performance
of AODV and DSDV routing protocols

AIM:
To evaluate the performance of AODV and DSDV Routing protocols in wireless scenario
using both TCP and UDP.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
AODV (Ad-hoc On-demand Distance Vector)[7] is a loop-free routing protocol for ad-hoc
networks. It is designed to be self-starting in an environment of mobile nodes, withstanding a
variety of network behaviours such as node mobility, link failures and packet losses. At each node,
AODV maintains a routing table. The routing table entry for a destination contains three essential
fields: a next hop node, a sequence number and a hop count. All packets destined to the destination
are sent to the next hop node. The sequence number acts as a form of time-stamping, and is a
measure of the freshness of a route. The hop count represents the current distance to the destination
node.
Destination Sequenced Distance Vector (DSDV) is a hop-by-hop vector routing protocol
requiring each node to periodically broadcast routing updates. This is a table driven algorithm based
on modifications made to the Bellman-Ford routing mechanism. Each node in the network
maintains a routing table that has entries for each of the destinations in the network and the number
of hops required to reach each of them. Each entry has a sequence number associated with it that
helps in identifying stale entries. This mechanism allows the protocol to avoid the formation of
routing loops. Each node periodically sends updates tagged throughout the network with a
monotonically increasing even sequence number to advertise its location.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink for 1st time
and UDP, Null next in wireless scenario.
 Give application as FTP for TCP, CBR for UDP.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 Go to parameters and select routing protocol as AODV or DSDV and click on done. Go to
tcl script and save it with .tcl extension.

83
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of TCP and UDP protocols.

AODV(TCP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open aodv.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open aodv.nam w]

84
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 501
$n0 set Y_ 700
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 702
$n1 set Y_ 698
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 596
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 703
$n3 set Y_ 400
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501

85
$n4 set Y_ 398
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401
$n5 set Y_ 550
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam aodv.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

86
DSDV(TCP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 801 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open dsdv1.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open dsdv1.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

87
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 499
$n0 set Y_ 701
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 701
$n1 set Y_ 699
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 602
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 702
$n3 set Y_ 401
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501
$n4 set Y_ 398
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401

88
$n5 set Y_ 560
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam dsdv1.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

89
AODV(UDP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open aodv2.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open aodv2.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

90
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 700
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 700
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 598
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 701
$n3 set Y_ 397
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 499
$n4 set Y_ 399
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 403

91
$n5 set Y_ 564
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n5 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam aodv2.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

92
DSDV(UDP):
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 900 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open dsdv2.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open dsdv2.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

93
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 501
$n0 set Y_ 699
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 699
$n1 set Y_ 700
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 800
$n2 set Y_ 599
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 702
$n3 set Y_ 401
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 502
$n4 set Y_ 401
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 402

94
$n5 set Y_ 557
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n5 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam dsdv2.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

95
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 ) AODV are used in military applications
2 ) AODV minimises the number of broadcasts
3 ) AODV sends hello messages to know it's neighbours
4 )DSDV is used in mobile networks.
5 )DSDV is used in less dynamic networks.

CALCULATIONS:
TCP:
Packet
Routing Number of End to End
Throughput Delivery Energy
Protocols nodes Delay
Ratio
AODV 6 123.97 133.99 25.74 18
DSDV 6 120.45 68.58 26.29 18

UDP:
Packet
Routing Number of End to End
Throughput Delivery Energy
Protocols nodes Delay
Ratio
AODV 6 137.85 137.17 26.46 14.3
DSDV 6 66.16 68.92 60.35 10.7

RESULT:
The performance of AODV and DSDV Routing protocols are evaluated using TCP and
UDP. The throughput , end to end delay , packet delivery ratio and energy are also calculated.

96
Experiment-10: Evaluate the performance
of IEEE 802.11 and IEEE 802.15.4

AIM:
To evaluate the performance of wireless networks IEEE 802.11, IEEE 802.15.4 .

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM

THEORY:
IEEE 802.11 is commonly known as WLAN and commonly called as WiFi. The 802.11 family
consists of a series of half-duplex over-the-air modulation techniques that use the same basic protocol.
The 802.11 protocol family employs carrier-sense multiple access with collision avoidance whereby
equipment listens to a channel for other users (including non 802.11 users) before transmitting each
packet.
IEEE 802.15.4 LR-WPAN is also known as ZigBee. ZigBee technology is simpler (and less
expensive) than Bluetooth. The main objectives of an LR-WPAN like ZigBee are ease of installation,
reliable data transfer, short-range operation, extremely low cost, and a reasonable battery life, while
maintaining a simple and flexible protocol. The raw data rate will be high enough (maximum of 250
kbit/s) to satisfy a set of simple needs such as interactive toys, but is also scalable down to the needs of
sensor and automation needs (20 kbit/s or below) using wireless communications.

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink and give
application as FTP to the source node only.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 In the TCL file generated change 802_11 with 802_15_4 and then save the file with .tcl
extension.
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of IEEE 802.11 and IEEE 802.15.4 .

97
IEEE 802.11:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open 801-11.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open 802-11.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

98
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 697
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 700
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 600
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 701
$n3 set Y_ 402
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501
$n4 set Y_ 397
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401

99
$n5 set Y_ 552
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam 802-11.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

100
IEEE 802.15.4:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy/802_15_4 ;# network interface type
set val(mac) Mac/802_15_4 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 828 ;# X dimension of topography
set val(y) 1648 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open smac.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open smac.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

101
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 703
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 701
$n1 set Y_ 698
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 595
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 697
$n3 set Y_ 397
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 498
$n4 set Y_ 401
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 402

102
$n5 set Y_ 554
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam smac.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

103
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 )IEEE 802.1 used in Projecting HD images and video from mobile devices
2 ) Large enterprises that rollout HD video conferencing use IEEE 802.11
3 )IEEE 802.15.4 is used in Virtual Monitoring
4 ) IEEE 802.15.4 is used in Consumer Electronics
5 ) IEEE 802.15.4 is used in Alarm Systems

CALCULATIONS:

Packet
Wireless Number of End to End
Throughput Delivery Energy
networks nodes Delay
Ratio
IEEE 802.11 6 123.97 133.99 25.74 18
IEEE 802.15.4 6 58.55 326.91 43.54 1.8

RESULT:
The performance of IEEE 802.11 and 802.15.4 Wireless Networks are evaluated . The
throughput , end to end delay , packet delivery ratio and energy are also calculated.

104
Experiment-11: Evaluate the performance
of IEEE 802.11 and SMAC

AIM:
To evaluate the performance of wireless networks IEEE 802.11, SMAC.

SOFTWARE REQUIRED:
 Ubuntu OS.
 NSG2.1 Simulator.
 NS2
 NAM.

THEORY:
IEEE 802.11 is commonly known as WLAN and commonly called as WiFi.The 802.11 family
consists of a series of half-duplex over-the-air modulation techniques that use the same basic protocol.
The 802.11 protocol family employs carrier-sense multiple access with collision avoidance whereby
equipment listens to a channel for other users (including non 802.11 users) before transmitting each
packet.
S-MAC is a medium-access control (MAC) protocol designed for wireless sensor networks.
Wireless sensor networks use battery-operated computing and sensing devices. A network of these
devices will collaborate for a common application such as environmental monitoring. We expect
sensor networks to be deployed in an ad hoc fashion, with individual nodes remaining largely
inactive for long periods of time, but then becoming suddenly active when something is detected.
These characteristics of sensor networks and applications motivate a MAC that is different from
traditional wireless MACs such as IEEE 802.11 in almost every way: energy conservation and self-
configuration are primary goals, while per-node fairness and latency are less important

PROCEDURE:
 Open the Terminal and change the directory to the location where NSG2.1 is present by using cd
<Directory Name>.
 Contents on the directory can be viewed by using command "ls".
 Open NSG2.1 by using the command "java –jar NSG2.1.jar".
 Click on the scenario and select wireless or wired scenario according to your requirement.
 Place the desired number of nodes and select the link as Drop-Tail and connect the nodes.
 Select a source node and a destination node and give their agents as TCP, TCP Sink and give
application as FTP to the source node only.
 Go to parameters and change the name of trace file, nam file accordingly and click on done.
 In the TCL file generated change 802_11 with SMAC and then save the file with .tcl
extension.
 Execute the TCL File by giving command "ns <filename> .tcl".
 The NAM window is opened and movement of packets can be seen by clicking on play button.
 Corresponding trace file and nam file are generated.
 The performance parameters can be calculated by command

105
"awk –f <awk file name>.awk <Trace file name>.tr"
 Compare the parameters and estimate the performance of IEEE 802.11 and SMAC .

IEEE 802.11:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 901 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open 801-11.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open 802-11.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

106
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 503
$n0 set Y_ 697
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 700
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 801
$n2 set Y_ 600
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 701
$n3 set Y_ 402
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 501
$n4 set Y_ 397

107
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 401
$n5 set Y_ 552
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam 802-11.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

108
SMAC:
TCL SCRIPT:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/SMAC ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 6 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 800 ;# X dimension of topography
set val(y) 802 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


set tracefile [open smac.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open smac.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

109
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 398
$n0 set Y_ 697
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 602
$n1 set Y_ 702
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 700
$n2 set Y_ 598
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 600
$n3 set Y_ 402
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 400
$n4 set Y_ 397
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 302

110
$n5 set Y_ 555
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam smac.nam &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

111
NETWORK ANIMATOR(NAM) CONSOLE OUTPUT:

APPLICATIONS:
1 )IEEE 802.1 used in Projecting HD images and video from mobile devices
2 ) Large enterprises that rollout HD video conferencing use IEEE 802.11
3 ) SMAC is used in virtual monitoring.

CALCULATIONS:

Packet
Wireless Number of End to End
Throughput Delivery Energy
Networks nodes Delay
Ratio
IEEE 802.11 6 123.97 133.99 25.74 18
SMAC 6 327.84 12.12 38.89 7.2

RESULT:
The performance of IEEE 802.11 and SMAC Wireless Networks are evaluated . The
throughput , end to end delay , packet delivery ratio and energy are also calculated.

112

You might also like