0% found this document useful (0 votes)
15 views26 pages

WSN File Saksham

The document introduces Wireless Sensor Networks (WSN), explaining their structure, components, and applications, as well as the challenges and advantages associated with them. It also covers the architecture of sensor nodes, detailing their components and functions, and provides an overview of NS2, a network simulator used for simulating WSNs. Additionally, it discusses the features of NS2, including its use of C++ and OTcl, and outlines the steps for creating a simulation scenario.

Uploaded by

saksham002312
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)
15 views26 pages

WSN File Saksham

The document introduces Wireless Sensor Networks (WSN), explaining their structure, components, and applications, as well as the challenges and advantages associated with them. It also covers the architecture of sensor nodes, detailing their components and functions, and provides an overview of NS2, a network simulator used for simulating WSNs. Additionally, it discusses the features of NS2, including its use of C++ and OTcl, and outlines the steps for creating a simulation scenario.

Uploaded by

saksham002312
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/ 26

Experiment:01

Aim: Introduction of Wireless Sensor Networks(WSN).


Theory:
A. Wireless Sensor Network.
Wireless Sensor Network (WSN) is an infrastructure-less wireless network that is deployed
in a large number of wireless sensors in an ad-hoc manner that is used to monitor the system,
physical or environmental conditions.

Sensor nodes are used in WSN with the onboard processor that manages and monitors the
environment in a particular area. They are connected to the Base Station which acts as a
processing unit in the WSN System. Base Station in a WSN System is connected through the
Internet to share data. WSN can be used for processing, analysis, storage, and mining of the
data.
A WSN consists of spatially distributed sensors, and one or more sink nodes (also called base
stations). Sensors monitor, in real-time, physical conditions, such as temperature, vibration, or
motion, and produce sensory data. A sensor node could behave both as data originator and data
router. A sink, on the other hand, collects data from sensors. For example, in an event
monitoring application, sensors are required to send data to the sink(s) when they detect the
occurrence of events of interest. The sink may communicate with the end-user via direct
connections, the Internet, satellite, or any type of wireless links.

(fig.1.Basic architechture of Wireless Sensor Networks)

Components of WSN:
1. Sensors: Sensors in WSN are used to capture the environmental variables and which is
used for data acquisition. Sensor signals are converted into electrical signals.

SAKSHAM CHOUDHARY|Batch1|05420802821
2. Radio Nodes: It is used to receive the data produced by the Sensors and sends it to the
WLAN access point. It consists of a microcontroller, transceiver, external memory, and
power source.
3. WLAN Access Point: It receives the data which is sent by the Radio nodes wirelessly,
generally through the internet.
4. Evaluation Software: The data received by the WLAN Access Point is processed by a
software called as Evaluation Software for presenting the report to the users for further
processing of the data which can be used for processing, analysis, storage, and mining of
the data.

Challenges of Modern Wireless Network:


1. Limited power and energy: WSNs are typically composed of battery-powered
sensors that have limited energy resources. This makes it challenging to ensure that
the network can function for
long periods of time without the need for frequent battery replacements.
2. Limited processing and storage capabilities: Sensor nodes in a WSN are typically
small and have limited processing and storage capabilities. This makes it difficult to
perform complex tasks or store large amounts of data.
3. Heterogeneity: WSNs often consist of a variety of different sensor types and nodes
with different capabilities. This makes it challenging to ensure that the network can
function effectively and
efficiently.
4. Security: WSNs are vulnerable to various types of attacks, such as eavesdropping,
jamming, and spoofing. Ensuring the security of the network and the data it collects
is a major challenge.
5. Scalability: WSNs often need to be able to support a large number of sensor nodes
and handle large amounts of data. Ensuring that the network can scale to meet these
demands is a significant
challenge.
6. Interference: WSNs are often deployed in environments where there is a lot of
interference from other wireless devices. This can make it difficult to ensure reliable
communication between sensor nodes.
7. Reliability: WSNs are often used in critical applications, such as monitoring the
environment or controlling industrial processes. Ensuring that the network is
reliable and able to function correctly
in all conditions is a major challenge.

Advantages of Wireless Sensor Networks (WSN):


1. Low cost: WSNs consist of small, low-cost sensors that are easy to deploy,
making them a cost-effective solution for many applications.
2. Wireless communication: WSNs eliminate the need for wired connections,
which can be costly and difficult to install. Wireless communication also enables
flexible deployment and reconfiguration of the network.
3. Energy efficiency: WSNs use low-power devices and protocols to conserve
energy, enabling long-term operation without the need for frequent battery
replacements.
4. Scalability: WSNs can be scaled up or down easily by adding or removing
sensors, making them suitable for a range of applications and environments.

SAKSHAM CHOUDHARY|Batch1|05420802821
5. Real-time monitoring: WSNs enable real-time monitoring of physical
phenomena in the environment, providing timely information for decision making
and control.
6. Disadvantages of Wireless Sensor Networks (WSN):
7. Limited range: The range of wireless communication in WSNs is limited, which
can be a challenge for large-scale deployments or in environments with obstacles
that obstruct radio signals.
8. Limited processing power: WSNs use low-power devices, which may have
limited processing power and memory, making it difficult to perform complex
computations or support advanced applications.
9. Data security: WSNs are vulnerable to security threats, such as eavesdropping,
tampering, and denial of service attacks, which can compromise the
confidentiality, integrity, and availability of data.
10. Interference: Wireless communication in WSNs can be susceptible to
interference from other wireless devices or radio signals, which can degrade the
quality of data transmission.
11. Deployment challenges: Deploying WSNs can be challenging due to the need
for proper sensor placement, power management, and network configuration,
which can require significant time and resources.
12. while WSNs offer many benefits, they also have limitations and challenges that
must be considered when deploying and using them in real-world applications.

B. Node Architecture
A basic sensor node comprises five main components such as
I. Controller
II. Memory
III. Sensors and Actuators
IV. Communication Devices
V. Power Supply Unit

(fig.2.Hardware Components of Sensor Node)

SAKSHAM CHOUDHARY|Batch1|05420802821
A controller to process all the relevant data, capable of executing arbitrary code. The controller
is the core of a wireless sensor node. It collects data from the sensors, processes this data,
decides when and where to send it, receives data from other sensor nodes, and decides on the
actuator’s behavior. It is the Central Processing Unit of the node. For general purpose
processors applications microcontrollers are used. These are highly overpowered and their
energy consumption is excessive. These are used in embedded systems. Some of the key
characteristics of microcontrollers are particularly suited to embedded systems are their
flexibility in connecting with other devices like sensors and they are also convenient in that
they often have memory built in. A specialized case of programmable processor is Digital
Signal Processors. They are specifically geared, with respect to their architecture and their
instruction set, for processing large amount of vectorial data, as is typically the case in signal
processing applications.
Memory:
In WSN there is a need for Random Access Memory(RAM) to store intermediate sensor
readings, packets from other nodes and so on. While RAM is fast, its main disadvantage is that
it loses its content if power supply is interrupted. Program code can be stored in ROM or more
typically in Electrically Erasable Programmable Read –Only Memory(EEPROM) OR flash
memory. Flash memory can also serve as intermediate storage of data in case RAM is
insufficient or when the power supply of RAM should be shut down for some time.
Sensors and Actuators:
1. Sensors
Sensors can be categorized into three
I. Passive, Omnidirectional sensors: These sensors can measure a physical quantity at the
point of the sensor node without actually manipulating the environment by active
probing that is passive.
II. Passive, narrow- beam sensors: These sensors are passive as well, but have well defined
notion of direction of measurement.
III. Active sensors: This sensor actively probes the environment Eg: A sonar or radar sensor
or some types of seismic sensors, which generates shock waves by small explosions.

2. Actuators: Actuators are just about as diverse as sensors, yet for the purposes of
designing a WSN that converts electrical signals into physical phenomenon.
Communication Device:
Choice of transmission medium: The communication device is used to exchange data between
individual nodes. In some cases, wired communication can actually be the method of choice
and is frequently applied in many sensor networklike settings (using field buses like Profibus,
LON, CAN, or others). The communication devices for these networks are custom off-the-
shelf components. The case of wireless communication is considerably more interesting. The
first choice to make is that of the transmission medium – the usual choices include radio
frequencies, optical communication, and ultrasound; other media like magnetic inductance are
only used in very specific cases. Of these choices, Radio Frequency (RF)-based communication
is by far the most relevant one as it best fits the requirements of most WSN applications: It
provides relatively long range and high data rates, acceptable error rates at reasonable energy
expenditure, and does not require line of sight between sender and receiver

SAKSHAM CHOUDHARY|Batch1|05420802821
Transceivers :For actual communication, both a transmitter and a receiver are required in a
sensor node. The essential task is to convert a bit stream coming from a microcontroller (or a
sequence of bytes or frames) and convert them to and from radio waves.

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment:02
Aim: Introduction to NS2 (Network Simulator Version 2) and simulate a Wireless Sensor Network.
Software Used: NS-2 Simulator.
Theory:
A wireless sensor network (WSN) consists of a large number of small sensor nodes that are deployed in the
area in which a factor is to be monitored. In wireless sensor network, energy model is one of the optional
attributes of a node. The energy model denotes the level of energy in a mobile node. The components
required for designing energy model includes initialEnergy, txPower, rxPower, and idlePower. The
“initialEnergy” represents the level of energy the node has at the initial stage of simulation. “txPower” and
“rxPower” denotes the energy consumed for transmitting and receiving the packets. If the node is a sensor,
the energy model should include a special component called “sensePower”. It denotes the energy consumed
during the sensing operation. Apart from these components, it is important to specify the communication
range (RXThresh_) and sensing range of a node (CSThresh_). The sample 18.tcl designs a WSN in which
sensor nodes are configured with different communication and sensing range. Base Station is configured
with highest communication range. Data Transmission is established between nodes using UDP agent and
CBR traffic.
NS2 (Network Simulator version 2) is a discrete event network simulator that is widely used to simulate and
analyze the behavior of computer networks. It is open-source software and is written in C++ and OTcl
(Object-oriented Tool Command Language). The OTcl (Object-oriented Tool Command Language) is an
extension of Tcl (Tool Command Language) and is used to create and control network entities and configure
network scenarios in NS2.

NS2 is classified as :

C++ Part OTcl Part (User Interface)


The C++ part,provides the underlying The Otcl part, provides the user interface and
simulation engine interaction between the user and the C++ part
Compiled Hierearchy Interpreted Hierearchy
Used when dealing with a packet agent or a Faster to interpret,slow to run.
protocol.
The C++ part is responsible for scheduling The Otcl part is responsible for creating and
and executing events, maintaining the state configuring network entities, such as nodes
of the network, and handling low-level and links, and for specifying the network
details such as packet processing and bit- scenario.
level manipulation.

Slow to compile,faster to execute. Preferable for beginners

• To use NS2, you need to have a basic understanding of both C++ and Otcl. To write a simulation
script, you need to use both languages in conjunction. You write the network topology and scenario
in Otcl and write the code for the actual protocol implementation in C++.
• ‘.ns’ is the extension which is used to open NS file.

SAKSHAM CHOUDHARY|Batch1|05420802821
XGraph:

Xgraph in NS2 is used to plot the network parameter characteristics like throughout, delay , latency etc.

Xgraph includes the wide ranging functions through the x-y data plotter along with the interactive buttons
that are used for various processes such as selecting, printing, zooming and panning display options. It is
capable to plot the data from several numbers of files in that same graph and it is used to regulate the size
of unlimited data set sizes with the number of data files.

Xgraph is an Windows application includes:

i. Interactive plotting and graphing.


ii. Animation and directives.
iii. Portability and bug fixes.

NAM file:
The NAM is one of the Tcl/TK based animation tool. The tool used to viewing network simulation traces
and real world packet traces. By using this nam tool we can perform the process like topology layout,
packet level animation, and various data inspection tools. The nam trace files is stored with the file
extension with .nam. And also, we execute the nam trace file , with using the keyword, exec nam.
Basic Architechture of NS2:

Figure shown below shows the basic architecture of NS2. 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.

NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl). While the
C++ 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 C++ and
the OTcl are linked together 'using TclCL. Mapped to a C++ 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 C++ 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 (instproes)
and instance variables (instvars), respectively. Before proceeding further.

SAKSHAM CHOUDHARY|Batch1|05420802821
(fig.1.Basic architechture of NS2)

Features of NS2:

i. It is a discrete event simulator for networking research.


ii. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https and DSR.
iii. It simulates wired and wireless network.
iv. It Uses TCL as its scripting language.
v. Otcl: Object oriented support
Algorithum:
1. Create a simulator object
2. Define a setting options for wireless channel
3. Create trace file and name file
4. Setup topography object and nodes
5. Provide initial location of mobile nodes
6. Setup a UDP connection between nodes
7. Printing the window size
Program:
# Define setting options
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

SAKSHAM CHOUDHARY|Batch1|05420802821
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 10 ;# number of mobile nodes
set val(rp) DSDV ;# routing protocol
set val(x) 500 ;# X dimension of topography set val(y) 400 ;# Y dimension of topography
set val(stop) 150 ;# time of simulation end
set ns [new Simulator] #Creating trace file and nam file
set tracefd [open dsdv.tr w] set windowVsTime2 [open win.tr w]
set namtrace [open dsdv.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
# configure the nodes
$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) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
for {set i 0} {$i < $val(nn) } { incr i }
{ set node_($i) [$ns node]

SAKSHAM CHOUDHARY|Batch1|05420802821
}
# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 800.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 8.0
$node_(1) set Y_ 650.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 60.0
$node_(2) set Y_ 450.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 10.0
$node_(3) set Y_ 480.0
$node_(3) set Z_ 0.0
#another four
$node_(4) set X_ 350.0
$node_(4) set Y_ 500.0
$node_(4) set Z_ 0.0
$node_(5) set X_ 150.0
$node_(5) set Y_ 850.0
$node_(5) set Z_ 0.0
$node_(6) set X_ 200.0
$node_(6) set Y_ 500.0
$node_(6) set Z_ 0.0
#$node_(7) set X_ 320.0
$node_(7) set X_ 320.0
$node_(7) set Y_ 650.0
$node_(7) set Z_ 0.0
#another four
$node_(8) set X_ 250.0
$node_(8) set Y_ 700.0

SAKSHAM CHOUDHARY|Batch1|05420802821
$node_(8) set Z_ 0.0
$node_(9) set X_ 400.0
$node_(9) set Y_ 800.0
$node_(9) set Z_ 0.0
##################################
#copy of the data
##################################
#####Attack Node
$node_(5) color Green
$ns at 10.0 "
$node_(5) color Green"
$ns at 10.0 "
$node_(5) label EndUser"
# Set a udp connection between node_(5) and node_(8)
set udp [new Agent/UDP]
set sink [new Agent/LossMonitor] #$ns
attach-agent $node_(5) $udp #$ns attach-
agent $node_(8) $sink
$ns attach-agent $node_(8) $udp
$ns attach-agent $node_(5) $sink
$ns connect $udp $sink
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$node_(8) color Green
$ns at 10.0 "$node_(8) color yellow"
$ns at 10.0 "$node_(5) label node5 "
$ns at 10.0 "$node_(8) label node8 "
$ns at 10.0 "$cbr start"
$ns at 10.45 "$cbr stop"
# Set a udp connection between node_(8) and node_(6)
setudp1 [new Agent/UDP]
set sink1 [new Agent/LossMonitor]
$ns attach-agent $node_(8) $udp1
$ns attach-agent $node_(6) $sink1
$ns connect $udp1 $sink1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$node_(6) color yellow
$ns at 10.0 "$node_(6) color yellow"
$ns at 10.0 "$node_(6) label node6 "
$ns at 10.0 "$cbr1 start"
$ns at 10.45 "$cbr1 stop"
# Set a udp connection between node_(8) and node_(6) set
udp2 [new Agent/UDP]
set sink2 [new Agent/LossMonitor]

SAKSHAM CHOUDHARY|Batch1|05420802821
$ns attach-agent $node_(5) $udp2
$ns attach-agent $node_(8) $sink2
$ns connect $udp2 $sink2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$node_(6) color yellow
$ns at 12.0 "$cbr2 start"
$ns at 13.45 "$cbr2 stop"
# Set a udp connection between node_(8) and node_(6)
set udp3 [new Agent/UDP]
set sink3 [new Agent/LossMonitor]
$ns attach-agent $node_(8) $udp3
$ns attach-agent $node_(6) $sink3
$ns connect $udp3 $sink3
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $udp1
$node_(6) color yellow
$ns at 14.0 "$cbr3 start"
$ns at 16.45 "$cbr3 stop" #
Printing the window size
proc plotWindow {tcpSource file} {
globalnss
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts$file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
#$ns at 10.1 "plotWindow $tcp $windowVsTime2"
# Define node initial position in nam for {set i 0} {$i < $val(nn)}
{ incr i }{
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}
# Telling nodes when the simulation ends for {set
i 0} {$i < $val(nn) } { incr i } {
#$ns at $val(stop) "$node_($i) reset";
#$ns at 200.25 "$node_($i) reset";
$ns at 21.25 "$node_($i) reset";
}
$ns at 0.00 "$ns trace-annotate \"Wireless Mac Ptotocol \""
$ns at 10.0 "$ns trace-annotate \" Data send in node5 to node8 \""
$ns at 10.0 "$ns trace-annotate \" Data send in node6 to node8 \""
$ns at 10.45 "$ns trace-annotate \" Data Collision \""
$ns at 12.00 "$ns trace-annotate \"Data send in node5 to node8\""
$ns at 14.00 "$ns trace-annotate \"Data send in node6 to node8\""
$ns at 21.25 "$ns trace-annotate \"End simulation\""
$ns at 21.25 "$ns nam-end-wireless 21.01"
$ns at 21.25 "stop"
$ns at 22.01 "puts \"end simulation\" ; $ns halt" proc
stop {} {
global ns tracefd namtrace
$ns flush-trace close
$tracefd close $namtrace
exec nam dsdv.nam &

SAKSHAM CHOUDHARY|Batch1|05420802821
exit 0
}
$ns run

OUTPUT:

Basic Commands of NS2:


Some basic commands that in an OTcl script to create and configure network entities in NS2 are as follows:

1. set ns [new Simulator] − This command creates a new Simulator object, which is used to control the
simulation.
2. set n[i] [$ns node] − This command creates a new node, where i is an integer that uniquely identifies
the node. The node is created as an object of the Node class, and it can be used to configure various
properties of the node, such as its position in the network, its mobility, and its routing protocol.
3. nsduplex−linkn0 $n1 bw delay queue-type − This command creates a duplex link between two
nodes, n0andn1, with a given bandwidth (bw), delay (delay), and queue management algorithum.
.For example, nsduplex−linkn0 $n1 1Mb 10ms DropTail creates a duplex link with 1 Mbps
bandwidth and 10 ms delay, and uses the DropTail queue management algorithm.
4. nssimplex−linkn0 $n1 bw delay queue-type − This command creates a unidirectional link between
two nodes, n0andn1, with a given bandwidth (bw), delay (delay), and queue management algorithm
(queue-type).
5. $ns drop-tail − This command sets the queue management algorithm to DropTail.
6. nsqueue−limit queue_var limit − This command sets the maximum queue size for the queue with
variable name queuevar
For example:ns queue-limit $tcp_queue 1000000 sets the maximum queue size to 1,000,000 bytes.

SAKSHAM CHOUDHARY|Batch1|05420802821
7. Nsattime:"tcl_command" − This command schedules a Tcl command to be executed at a given
simulation time. For example, nsat5.0"n0 start" starts a node at 5.0 seconds in the simulation.
8. $ns run − This command starts the simulation and runs it for a specified time or until a specific event
occurs.
9. $ns stop − This command stops the simulation at a specific time or event.

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 03
Aim: Write a TCL Script to create fixed wireless nodes.
Theory/Description:
Three wireless nodes are created and they are configured with specific parameters of a mobile
wireless node. After creating the nam file and trace file, we set up topography object. set node_
($i) [$ns node] is used to create the nodes. Location of the nodes is fixed by specifying X, Y
coordinates. Z coordinate is always zero. Here we set the initial size for the every node by using
initial_node_pos. AODV routing protocol is used here. $val(stop) specifies the end time of the
simulation.
Source Code:
# Define options
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) 3 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end
#-------Event scheduler object creation--------#
set ns [new Simulator]
# Creating trace file and nam file

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(Fig.3.1. nam file to create three wireless node)

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 04
Aim:Write a TCL script to create dynamic number of nodes.
Theory/Description:
Number of nodes is not fixed in the program. We can give the number of nodes to be created
during runtime. Number of nodes should be given as command line arguments when we run
the coding. Dynamically created nodes are configured with specific parameters of a mobile
wireless node. After creating the nam file and trace file, we set up topography object. set node_
($i) [$ns node] is used to create the nodes. Location of the nodes is fixed by specifying X, Y
coordinates. Z coordinate is always zero Here we set the initial size for the every node by using
initial_node_pos. AODV routing protocol is used here. $val(stop) specifies the end time of the
simulation. In this program nodes are given with yellow color.
Source Code:
if {$argc != 1} {
error "\nCommand: ns wireless1.tcl <no.of.mobile-nodes>\n\n "
}
# Define options
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) [lindex $argv o] ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 600 ;# X dimension of topography
set val(y) 600 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#-------Event scheduler object creation--------#

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(fig.4.1 NAM file to create a dynamic number of nodes)

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 05
Aim: Write a TCL script to create the dynamic number of nodes and its initial location.
Theory/Description:
Number of nodes is not fixed in the program. We can give the number of nodes to be created
during runtime. Number of nodes should be given as command line arguments when we run
the coding. Dynamically created nodes are configured with specific parameters of a mobile
wireless node. After creating the nam file and trace file, we set up topography object. set node_
($i) [$ns node] is used to create the nodes. Initial location of the nodes is not fixed. X, Y
coordinates are randomly selected and assigned to every node. Here we set the initial size for
the every node by using initial_node_pos. AODV routing protocol is used here. $val(stop)
specifies the end time of the simulation. In this program nodes are given with yellow color.
Source Code:
if {$argc != 1} {
error "\nCommand: ns wireless3.tcl <no.of.mobile-nodes>\n\n "
}

# Define options

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) [lindex $argv o] ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 600 ;# X dimension of topography
set val(y) 600 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#-------Event scheduler object creation--------#

set ns [new Simulator]

#creating the trace file and nam file

set tracefd [open wireless3.tr w]


set namtrace [open wireless3.nam w]

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(fig.5.1.NAM file to create a dynamic number of nodes and its initial location.)

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 06
Aim:Write a TCL script to give mobility to nodes.
Theory/Description:
Number of nodes is fixed in the program. Nodes are configured with specific parameters of a
mobile wireless node. After creating the nam file and trace file, we set up topography object.
set node_ ($i) [$ns node] is used to create the nodes. Initial location of the nodes is fixed.
Specific X, Y coordinates are assigned to every node. Nodes are given mobility with fixed
speed and specific destination location which is generated randomly. Nodes mobility will
change time to time. Here we set the initial size for the every node by using initial_node_pos.
AODV routing protocol is used here. $val(stop) specifies the end time of the simulation.
Source Code:
if {$argc != 1} {
error "\nCommand: ns wireless3.tcl <no.of.mobile-nodes>\n\n "
}

# Define options

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) [lindex $argv 0] ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 750 ;# X dimension of topography
set val(y) 550 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end

#-------Event scheduler object creation--------#

set ns [new Simulator]

## Create a trace file and nam file..


set tracefd [open wireless2.tr w]
set namtrace [open wireless2.nam w]

## Trace the nam and trace details from the main simulation..
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(fig.6.1 nam file to give mobility to nodes)

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 07
Aim: Write a TCL Script to make TCP Communication between nodes using DSR routing
Protocol.
Theory/Description:
Number of nodes (3) is fixed in the program. Nodes are configured with specific parameters of
a mobile wireless node. After creating the nam file and trace file, we set up topography object.
set node_ ($i) [$ns node] is used to create the nodes. Initial location of the nodes is fixed.
Specific X, Y coordinates are assigned to every node. Nodes are given mobility with fixed
speed and fixed destination location. Here we set the initial size for the every node by using
initial_node_pos. DSR routing protocol is used here. $val(stop) specifies the end time of the
simulation. TCP agent is attached to node_ (0). TCPSink agent is attached to node_(1). Both
the agents are connected and FTP application is attached to TCP agent. Now communication
set up for node_(0) and node_(1) is established
Source Code:
# Define options

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) 3 ;# number of mobilenodes
set val(rp) DSR ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 400 ;# Y dimension of topography
set val(stop) 150.0 ;# time of simulation end

#-------Event scheduler object creation--------#

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(fig.7.1 file to setup communication using DSR)

(fig7.2. nam file to show transfer of packet using DSR)

SAKSHAM CHOUDHARY|Batch1|05420802821
Experiment - 08
Aim:Write a TCL Script to make communication between nodes using AODV routing protocol
and CBR traffic.
Theory/Description:
Number of nodes (22) is fixed in the program. Nodes are configured with specific parameters
of a mobile wireless node. After creating the nam file and trace file, we set up topography
object. set node_ ($i) [$ns node] is used to create the nodes. Initial location of the nodes is
fixed. Specific X, Y coordinates are assigned to every node. Nodes are given mobility with
fixed speed and fixed destination location. Here we set the initial size for the every node by
using initial_node_pos. AODV routing protocol is used here. $val(stop) specifies the end time
of the simulation. UDP agent is attached to sender node. LossMonitor agent is attached to
receiver node. Both the agents are connected and CBR traffic is attached to UDP agent. Now
communication set up for nodes are established.
Source Code:
# Define options
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) 22 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1800 ;# X dimension of topography
set val(y) 480 ;# Y dimension of topography
# set val(stop) 10.0 ;# time of simulation end
### Setting The Simulator Objects
set ns_ [new Simulator]
#create the nam and trace file:

SAKSHAM CHOUDHARY|Batch1|05420802821
Output:

(fig.8.1 nam file to show communication using AODV)

SAKSHAM CHOUDHARY|Batch1|05420802821

You might also like