0% found this document useful (0 votes)
77 views56 pages

Adhoc File - Sakeb

The document provides instructions for installing Network Simulator 2 (NS2) on Ubuntu. It involves downloading the NS2 package, extracting the files, installing dependencies like GCC 4.4, and making minor configuration changes to files. Once the dependencies are installed and configurations are complete, the installation script can be run to install NS2. Upon successful installation, confirmation messages detailing the installation locations are displayed.

Uploaded by

Abed aktar
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)
77 views56 pages

Adhoc File - Sakeb

The document provides instructions for installing Network Simulator 2 (NS2) on Ubuntu. It involves downloading the NS2 package, extracting the files, installing dependencies like GCC 4.4, and making minor configuration changes to files. Once the dependencies are installed and configurations are complete, the installation script can be run to install NS2. Upon successful installation, confirmation messages detailing the installation locations are displayed.

Uploaded by

Abed aktar
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/ 56

(THE ENGINEERING & MANAGEMENT COLLEGE)

AD HOC AND WIRELESS NETWORKS LAB


PRACTICAL FILE
(CODE: PCST-702)

Submitted To: Submitted By:


Ms. Ritu Pal Name: Sakeb Ahmad
Assistant Professor Student ID: 201804027
CSE Department Branch/Year: CSE IV

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


INDEX

Teacher’s
Sl no. Practical Name Date
Signature

1. Study of Network Simulator 2 (NS2)

Installation of Network Simulator (NS2) on


2.
Ubuntu

3. Simulate a Mobile Ad hoc Network

4. Implementing a wireless sensor network

Configure Wireless Access Point and build


5.
different networks

6. Implementing a wireless sensor network

Implementing Transport Control Protocol in


7.
Sensor Network

Develop sample wireless network in which,


a. Implement AODV and AOMDV protocol.
b. Calculate the time to receive reply from
8.
the receiver using NS2.
c. Generate graphs which show the
transmission time for packet

9. Implement mobile devices as wireless access point

10. Study of Security in Ad hoc Wireless Networks


Practical – 1
Objective: Study of Network Simulator 2 (NS2).

Introduction:
Simulation is a very important modern technology. It can be applied to different
science, engineering, or other application fields for different purposes. Computer
assisted simulation can model hypothetical and real-life objects or activities on a
computer so that it can be studied to see how the system function. Different variables
can be used to predict the behavior of the system. Computer simulation can be used to
assist the modeling and analysis in many natural systems. Typical application areas
include physics, chemistry, biology, and human-involved systems in economics,
finance or even social science. Other important applications are in the engineering such
as civil engineering, structural engineering, mechanical engineering, and computer
engineering. Application of simulation technology into networking area such as
network traffic simulation.

Basic concepts in network simulation:


In the area of computer and communications networks, simulation is a useful technique
since the behavior of a network can be modeled by calculating the interaction between
the different network components (they can be end-host or network entities such as
routers, physical links or packets) using mathematical formulas. They can also be
modeled by actually or virtually capturing and playing back experimental observations
from a real production networks. After we get the observation data from simulation
experiments, the behavior of the network and protocols supported can then be observed
and analyzed in a series of offline test experiments. All kinds of environmental
attributes can also be modified in a controlled manner to assess how the network can
behave under different parameters combinations or different configuration conditions.
Another characteristic of network simulation that worth noticing is that the simulation
program can be used together with different applications and services in order to
observe end-to-end or other point-to-point performance in the networks

Type of network simulators:


For network protocol designers, it is often difficult to decide which simulator to choose
for a particular task. Therefore, we conduct a survey to find a network simulator that
provides a good balance between availability of ready to use models, scripting and
language support, extendibility, graphical support, easiness of use, etc. The survey is
based on a collection of a number of criteria including published results, interesting
characteristics and features. From our survey results, we broadly categories network
simulators as: “Widely Used” simulators and “Other” simulators. The network
simulators taken into consideration as “Widely Used” are Ns-2, Ns-3, GloMoSim, J-
Sim, OMNet++, OPNet, and QualNet.

Network Simulator 2 (NS2)


NS2 is one of the most popular open source network simulators. The original
NS is a discrete event simulator targeted at networking research. NS2 is the second
version of NS (Network Simulator). NS is originally based on REAL network
simulator. The first version of NS was developed in 1989 and evolved a lot over the
past few years. The current NS project is supported through DARPA. The current
second version NS2 is widely used in academic research and it has a lot of packages
contributed by different non-benefit groups. An example of the graphical GUI of NS2
can be seen in Figure 1.

Figure1. NS2 GUI

Main features:
First and foremost, NS2 is an object-oriented, discrete event driven network
simulator which was originally developed at University of California-Berkely. The
programming it uses is C++ and OTcl (Tcl script language with Object-oriented
extensions developed at MIT). The usage of these two programming language has its
reason. The biggest reason is due to the internal characteristics of these two
languages.
C++ is efficient to implement a design but it is not very easy to be visual and
graphically shown. It's not easy to modify and assembly different components and to
change different parameters without a very visual and easy-to- use descriptive
language. Moreover, f or efficiency reason, NS2 separates control path
implementations from the data path implementation. The event scheduler and the
basic network component objects in the data path are written and compiled using C++
to reduce packet and event processing time.
OTcl happens to have the feature that C++ lacks. So the combination of these
two languages proves to be very effective. C++ is used to implement the detailed
protocol and OTcl is used for users to control the simulation scenario and schedule
the events. A simplified user's view of NS2 is shown in Figure 2.
The OTcl script is used to initiate the event scheduler, set up the network
topology, and tell traffic source when to start and stop sending packets through event
scheduler. The scenes can be changed easily by programming in the OTcl script.
When a user wants to make a new network object, he can either write the new object
or assemble a compound object from the existing object library, and plumb the data
path through the object. This plumbing makes NS2 very powerful.

Figure2. Simplified user's view of NS2


Practical – 2
Objective: Installation of Network Simulator (NS2) on Ubuntu.

Steps for Installing Network Simulator 2 (NS2) on Ubuntu:


Step 1: Download and Extract ns2

Download the all in one package for ns2 from internet. The package downloaded will
be named "ns-allinone-2.35.tar.gz". Copy it to the home folder. Then in a terminal use
the following two commands to extract the contents of the package:

tar -xvzf ns-allinone-2.35.tar.gz

All the files will be extracted into a folder called "ns-allinone-2.35".

Step 2: Building the dependencies

1. Ns2 requires a few packages to be pre installed. It also requires the GCC- version
4.3 to work correctly. So install all of them by using the following command:

sudo apt-get install build-essential autoconf automake libxmu-dev

2. One of the dependencies mentioned is the compiler GCC-4.3, which is no longer


available, and thus we have to install GCC-4.4 version. The version 4.4 is the oldest
we can get. To do that, use the follwoing command:

sudo apt-get install gcc-4.4

3. Once the installation is over, we have to make a change in the "ls.h" file. Use the
following steps to make the changes: Navigate to the folder "linkstate", use the
following command. Here it is assumed that the ns folder extracted is in the home
folder of your system.

cd ~/ns-allinone-2.35/ns-2.35/linkstate

4. Now open the file named "ls.h" and scroll to the 137th line. In that change the word
"error" to "this->error". The image below shows the line 137 (highlighted in the
image below) after making the changes to the ls.h file. To open the file use the
following command:

gedit ls.h

5. Save that file and close it.

6. Now there is one more step that has to be done. We have to tell the ns which version
of GCC will be used. To do so, go to your ns folder and type the following command:

sudo gedit ns-allinone-2.34/otcl-1.13/Makefile.in

Further following steps have to be followed for successful installation:

1. In the file, change Change CC= @CC@ to CC=gcc-4.4, as shown in the image
below:
Step 2: Save that file and close it

Step 3: Installation

1. Now we are ready to install ns2. To do so we first require root privileges and then
we can run the install script. Use the following two commands:

cd ns-allinone-2.35
/install

2. After successful installation following message will be shown on the screen. Ns-
allinone package has been installed successfully.

Ns-allinone package has been installed


successfully. Here are the installation places:

tcl8.5.10: /home/sitams/ns-allinone-2.35/{bin,include,lib}
tk8.5.10: /home/sitams/ns-allinone-
2.35/{bin,include,lib} otcl: /home/sitams/ns-allinone-
2.35/otcl-1.14

tclcl: /home/sitams/ns-allinone-
2.35/tclcl-1.20 ns: /home/sitams/ns-allinone-
2.35/ns-2.35/ns

nam: /home/sitams/ns-allinone-2.35/nam-
1.15/nam xgraph: /home/sitams/ns-allinone-
2.35/xgraph-12.2

gt-itm: /home/sitams/ns-allinone-2.35/itm, edriver, sgb2alt,


sgb2ns, sgb2comns, sgb2hierns

----------------------------------------------------------------------------------

Please put /home/sitams/ns-allinone-2.35/bin:/home/sitams/ns-


allinone- 2.35/tcl8.5.10/unix:/home/sitams/ns-allinone-2.35/tk8.5.10/unix

into your PATH environment; so that you'll be able


to run itm/tclsh/wish/xgraph.
Step 4: Setting the Environment Path

1. The final step is to tell the system, where the files for ns2 are installed or present.
To do that, we have to set the environment path using the ".bashrc" file. In that
file, we need to add a few lines at the bottom. The things to be added are given
below:
sudo gedit ~/.bashrc

2. Lines to be added:
# LD_LIBRARY_PATH
OTCL_LIB=/home/sitams/ns-allinone-2.35/otcl-1.14

NS2_LIB=/home/sitams/ns-allinone-
2.35/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib

export

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X
11_ LIB:$USR_LOCAL_LIB

# TCL_LIBRARY

TCL_LIB=/home/sitams/ns-allinone-
2.35/tcl8.5.10/libraryUSR_LIB=/usr/lib

export
TCL_LIBRARY=$TCL_LIB:$USR_LIB #
PATH

XGRAPH=/home/sitams/ns-allinone-2.35/bin:/home/sitams/ns-
allinone- 2.35/tcl8.5.10/unix:/home/sitams/ns-allinone-
2.35/tk8.5.10/unix

#the above two lines beginning from xgraph and ending with unix should
come on the same line

NS=/home/sitams/ns-allinone-2.35/ns-2.35/
NAM=/home/sitams/ns-allinone-2.35/nam-
1.15/
PATH=$PATH:$XGRAPH:$NS:$NAM

3. Once the changes have been made, save the file and restart the system.
Step 5: Running ns2

1. Once the system has restarted, open a terminal and start ns2 by using the
following command:

ns

2. System returns

Step 6: Testing ns2

Test the addition of two integer numbers.


%
set a
10
10
%
set b
20
20
% expr
$a+$b
30
%

Result :

NS2 software has been successfully installed and it’s tested with simple
example on Ubuntu Operating System.
Practical – 3
Objective: Simulate a Mobile Ad hoc Network.

Ad Hoc Network
Ad-hoc networks are temporary network. They do not need any external infrastructure like
base stations and physical wires.

Mobile Ad-hoc NETwork (MANET)


MANET automatically configure a network among mobile devices. Each devices moves
independently in any direction. Each node acts as a router.

A typical MANET is shown in the figure below:

Simulating a MANET using Network Simulator 2:


The Network Simulator simulate following steps for MANET:

1. The command required to configure a mobile node :

01 $ns_ node-config -adhocRouting $val(rp) \

02 -llType $val(ll) \ # LinkLayer

03 -macType $val(mac) \ #MAC type


04 -ifqType $val(ifq) \ #interface queue type

05 -ifqLen $val(ifqlen) \ #interface queue length

06 -antType $val(ant) \ #antenna type

07 -propType $val(prop) \ #propagation model

08 -phyType $val(netif) \ #network interface type

09 -topoInstance $topo \ #topography instance

10 -agentTrace ON \ #tracing at agent level

11 -routerTrace ON \ #tracing at router level

12 -macTrace ON \ #tracing at mac level

13 -movementTrace ON \ #mobile node movement

14 -channel $chan_1_

The four last option in node configuration can either be ON or OFF based on the condition of
the mobile nodes. The agent trace will give the trace of TCP, routerTrace provides tracing of
packets used in routing, macTrace is used to trace MAC protocol packets and
movementTrace is used to allow tracing the motion of nodes for nam.

2. Create some mobile nodes and assign them to the channels:

for {set i 0} {$i < $val(nn)} {incr i}

set node_($i) [$ns_ node]

$node_($i) random-motion 0;

3. Assigning mobility to the node.

4. Specifying routing protocols.

set val(rp) AODV; #for AODV

set val(rp) DSR; #for DSR


Practical – 4
Objective: Implementing a wireless sensor network.

Receiver
 Raspberry Pi—Model B with power supply, case, and SD card—Ensure the GPIO pins
are accessible with the case you choose
 Pi compatible Wi-Fi adapter
 Arduino
 Breadboard jumper wires
 Male to female jumper Wires
 Logic level converter
 434 MHz RF receiver
 Half breadboard

Transmitters (two units)


 2 x Arduino
 2 x Temperature / humidity sensors
 2 x 434 MHz RF transmitter
 2 x Half breadboard
 2 x Breadboard-friendly 2.1mm DC barrel jack
 2 x 9V power adapter with 2.1mm x 5
 Breadboard jumper wires

Tools
 PC/Mac with Arduino programming IDE installed
 USB cable for programming Arduino boards
 USB Keyboard and Mouse. Either combined or with a hub so both can be used with a
single USB port.
 The source package associated with this tutorial on your programming workstation

Assemble Transmitters

The transmitters themselves are relatively simple circuits. Only one pin is used to retrieve the
information from the temperature and humidity sensor and one pin is used to send that data to the
RF transmitter. The breadboard diagram is shown below.

The 9V power supply will attach to the barrel connector making the bottom rails 9V. The power
regulator in the Arduino will produce 5V that is safe to use for the radio and sensors, the top
power rail of the diagram.

The sensor comes with a 10k ohm resistor that connects the data pin to power as a pull up resistor
while another wire connects it to GPIO D3.
Transmitter diagram

The antenna is an important part of the board because the RF module does not have a built in
antenna. I used a 6-inch female to male jumper wire plugged into the breadboard and it worked
well enough to allow reception from all parts of my home and a little bit outside. As noted in the
diagram, 6.5-inch is optimal for this antenna if you need additional range.

Download Libraries for Components

The transmitter uses two libraries that are not bundled with the Arduino IDE. Download the
libraries as described below and uncompressed them into your sketch directory in a subdirectory
named Libraries.

 Download the VirtualWire source package for this tutorial and unzip
the wirelesstransmitter sketch folder into your Arduino sketch folder
 In the wirelesstransmitter folder create a folder named Libraries
 Download the latest version of the VirtualWire code, 1.23 as of this writing, from
the project page
 Extract the VirtualWire folder into the wirelesstransmitter/Libraries/ folder so you
have another subfolder named VirtualWire
 Download the DHT sensor library from its project github page
 Extract the DHT folder into the Libraries folder as well. You should now have the two
required library folders DHT and VirtualWire in
your wirelesstransmitter/Libraries folder.
Program the Arduino Board

This tutorial assumes you have some experience with Arduino and how to program them using
the Arduino IDE. If you do not, there are very good instructions at the official Arduino site.

 Open the wirelesstransmitter sketch from the source archive in the Arduino IDE and
save a copy locally
 Ensure the Arduino is NOT connect to power via the barrel connector
 Connect the board to your programming workstaiton station with an appropriate USB
cable
 Set the board type to your selected Arduino board under the Tools > Board menu
 Set the serial port to the port detected when you connected the Arduino board under
the Tools > Port menu
 Ensure that the MYID define is set to 1 and the TRANSPIN and DHTPIN are properly
set to the pins connected to the RF transmitter module and DHT sensor respectively. If
you built your board per the diagram above this should all be set already. See the code
example below.
 Ensure that the UNIT is set properly for your preference Fahrenheit or Celsius.

#define MYID 1 //the ID number of this board. Change this for each board you flash.
#define TRANSPIN 3 //what pin to transmit on
#define DHTPIN 4 // what pin the DHT is connected to
#define UNIT 0 // 0 for Fahrenheit and 1 for Celsius

The MYID define is a numeric ID that the transmitter uses to uniquely identify itself. Because
you will have multiple transmitters in different locations it is important to have a unique ID for
each one. This number will be used again when you setup the receiver script.

 Verify the code by pressing Control-R to ensure the libraries are included and compiled
properly.
 Push the code to the board by clicking the Upload button on the tool bar.
 Open the Serial Monitor windows by pressing Control-Shift-M

The Serial Monitor window resets the Arduino so you should see a line of code on the screen
that looks something like:

Even if there is doubling and the signal from both transmitters is lost, the random interval will
ensure that their next broadcasts will not overlap. The random seed for this interval is set from
an analogRead on an unused analog port which will return random values to ensure no two
transmitters are on the same pattern.

The transmitters are set to wait 2 to 5 minutes between broadcasts by default. If you wish to
speed this up for debugging purposes then modify the delay() value at the end of the sketch to be
more like 5000 (ms). It is highly recommended that you change this back and re-upload the code
to your transmitters when you are ready for full time use.

 Build the second transmitter board


 Modify the transmitter sketch so that the MYID define is set to 2
 Upload the code to the second board
 Open the Serial Monitor windows by pressing Control-Shift-M and verify that the
output looks like the first transmitter board with the exception that the transmitted
message starts with ID:2

Build the Receiver Board

The receiver board will be responsible for receiving the broadcast message on its RF Receiver
component and sending that message over serial wires to the Raspberry Pi. The Arduino board is
used to receive the signal for a couple very important reasons. The VirtualWire code uses the
real time nature of the Arduino to manage modulating and demodulating the signal.

This means that the receiving unit needs to be operating at the same frequency. In addition, there
is little room for jitter on the receiving processor, to which the Raspberry Pi is prone, due to its
preemptive, non real-time operating system. Comparing the costs of an Arduino Pro Mini plus the
RF receiver module to that of a Zigbee module that could talk directly to the Raspberry Pi
revealed that using an external Arduino was still quite economical.

Build the receiver board per the Fritzing diagram below.

Receiver Diagram
This component is required in order to convert the 5V Arduino serial signal to a 3.3V Raspberry
Pi serial signal and not damage the Pi. See the image below for additional help.

Actual Logic Level Converter Wiring

Note that the RX and TX wires cross through the logic level converter so that the TX from the
Arduino goes into the RX of the Pi. The next steps involve setting up the Pi, you'll return to
program the Arduino later.

Setup the Raspberry Pi

There are several guides to purchasing and installing an OS on your Raspberry Pi. Install the
latest Raspbian operating system. The following steps describe connecting the peripherals to the
Pi and configuring.

 Insert the USB Wi-Fi adapter into the top USB port on the Pi
 Connect the USB hub to the bottom USB port on the Pi
 Connect the mouse and keyboard to the USB hub
 Connect the HDMI Monitor
 Insert the SD Card
 Connect the power supply
 Perform first time setup configuration leaving the default option to boot to a graphical
desktop
 After the Pi reboots to a desktop follow these instructions on how to use the GUI tool
to configure your wifi network.
 Open a terminal window by double-clicking on the LXTerminal icon.
 Execute the command sudo raspi-config
 Select the Enable Boot to Desktop/Scratch > Console Text console, requiring
login option
 Select the Advanced Options > SSH to enable network command line access
 Select Finish and allow the Pi to reboot to the text console
 Make note of the IP address the Pi reports when it boots. This will be used to SSH to the
Pi in later steps. The steps below for configuring the Pi are easier done from an SSH
session to the Pi.
Configure Raspberry Pi

The Raspberry Pi uses its serial port by default as a serial console. The device is
named ttyAMA0. When it boots it dumps boot messages to this device and sets up a login
session on it. In order to use it for receiving data from the Arduino you will need to disable the
serial console and session.

 Edit the inittab file that controls text login session with the command below. It's always
recommended to make a backup of the original file before editing just in case something
goes wrong.

sudo pico /etc/inittab

 Locate the lines at the bottom of the file that refer to the device ttyAMA0 and add a # to
the start of the line that includes this device name. It should look like the lines below
when you are done

#Spawn a getty on Raspberry Pi serial line


#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

 Edit the /boot/cmdline.txt with the command below. Don't forget to make a backup copy
just in case.

sudo pico /boot/cmdline.txt

 Remove the arguments that reference ttyAMA0. They part you want to remove looks
something like this: console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
 Save the file and reboot the Pi

Install Python Script and Prerequisites

The python script that will complete the receiver will perform several functions.

1. Read from the serial port


2. Parse the input and ensure it is sane
3. Interpret the serial data
4. Post the data to Xively into the appropriate feed

In order to perform these functions you will need to install the prerequisite modules to install the
serial libraries and Xively communications.

 Login to the Pi and execute the commands below to install them.

sudo apt-get install python-serial python-setuptools


sudo easy_install pip
sudo pip install --pre xively-python
mkdir ~/scripts
 Copy the script wirelessnetwork.py from the source package for this tutorial into the
scripts directory you just created. You can do that by copying and pasting the contents or
by scping the script to the Pi.
 Ensure the script is executable with the command

chmod u+x wirelessnetwork.py


The next several steps will take you through setting up Internet of Things accounts that allow you
to record and react to the data your device is recording.

Setup Your Xively Account for the Pi

Xively is a service that collects data from things. You can setup and register your thing or
Raspberry Pi with Xively and data can be pushed from your Pi to the cloud for tracking and
triggering.

 Go to xively.com and register for a free account


 Click on the Get Started button
 Scroll to the bottom of the page and choose Sign Up for a free Developer Account
 Fill out the appropriate account information and validate your account
 Authenticate as your new account as needed
 Select Web Tools > Develop to go to your new developer page
 Click on the big + Add Device box to add your Raspberry Pi
 Fill out the Device Name: WirelessNetwork, Device Description: Environmental
Monitor, choose Private Device unless you wish to share your salt level with the world.
 Click Add Device. After the device is created you will be presented with the device
screen with keys and information about the device.
 Record the Feed ID and API Key from the device page. The Feed ID is in small font
near the top of the page and the API Key is in large font on the right side of the page.
You will need these to finalize the wirelessnetwork.py script you downloaded in the
previous section.

Configure the Python Script

In order to post data to Xively the wirelessnetwork.py script needs to have the Feed ID and API
Keys that you recorded above. Edit the script using pico or your favorite editing tool.

#some defines for Xively


FEED_ID = "FEED ID HERE" #enter your feed ID number here
API_KEY = "API KEY HERE" #set your API key here
# initialize api client
api = xively.XivelyAPIClient(API_KEY)

#Create mapping from transmitter ID number to names. This could be a DB some day
DEV={'1':'Bedroom', '2':'Basement'}

DEBUG = True
While you are editing the script make sure to edit the DEV variable. This variable is a name
mapping for the IDs that the sensor modules will be sending. In this example when the sensor
module with ID 1 sends a message, the script will post to a Xively channel with the friendly
name Bedroom instead of ID1. In the same way, the sensor module with ID 2 will be reported
into the channel Basement.

Program the Receiver Arduino

The Raspberry Pi is now ready to receive data using the wirelessnetwork.py script. The Arduino
needs to be programmed with the wirelessreceiver sketch.

 Open the wirelessreceiver sketch from the source package and save a copy locally
 Copy the VirtualWire library from the wirelesstransmitter/Library directory to
the Library directory under the new wirelessreceiver directory
 Attach the receiver Arduino receiver to your programming workstation and ensure the
port and board type are set correctly.
 Ensure that the RXPIN define is set to the pin number that is connected to the RF
receiver module. If it is built per the diagram the sketch should be fine without changes.
 Verify and upload the the sketch to the Arduino
 Open the Serial Monitor windows by pressing Control-Shift-M. If the transmitters are
not running you will not see out put.
 Plug one of the transmitter modules into power using the 9V wall adapter and the barrel
connector on the breadboard. You should now see the messages that are being received
on the Arduino. Unplug the USB cable from the Arduino

 Attach the ground and power jumpers from the Raspberry Pi

Test the Receiver Script

Now that you have the Arduino receiving data from a sensor module you can test the script on the
Pi to ensure it is properly reading the data and posting it to Xively. Open an SSH or terminal
session to the Pi for the following steps.

 Activate the second wireless transmitter by plugging it in with the second 9V adapter
 Execute the wirelessnetwork.py script from the /home/pi/scripts directory with the
following commands

cd /home/pi/scripts/
./wirelessnetwork.py

 Review the output in the console and on the Xively website.

Received input: ID:1:TS:154075:TF:73.39:RH:39.00


Processing data for: Bedroom
Posting temp fahrenheit for Bedroom
Creating datastream
Updating Xively feed with value: 73.39
Posting relative humidity for Bedroom
Found existing datastream
Updating Xively feed with value: 39.00

The script will create feeds for humidity and temperature the first time it runs. The example
above shows the script receiving the messages, parsing them and posting them to Xively
successfully. Use Control-C to exit the script before proceeding to the next step.

Switch to the browser windows where you created your Xively account and device. The new
datastreams and some information about them should be available and look something like the
image below.

Xively Channel Updated

Set the Script to Launch on Boot

Because the Raspberry Pi is going to be run headless the script should be set to start automatically
when the unit is powered.

 Add the following line to the /etc/rc.local file. Use your favorite editor, but make sure to
sudo the edit command as /etc/rc.local is a root owned file. The script itself can run as
the user pi rather than as root.

sudo -u pi /home/pi/scripts/wirelessnetwork.py &

 Reboot the Pi
 Login to the Pi after it has rebooted and verify that the script is running with the
following command.

ps ax |grep wirelessnetwork

The output should look something like the excerpt below.

22000 pts/1 S+ 0:02 /usr/bin/python /home/pi/scripts/wirelessnetwork.py


Practical – 5
Objective: Configure Wireless Access Point and build different networks.

A Wireless Access Point (WAP) is a networking device that allows wireless-capable devices
to connect to a wired network. Adding a WAP to your existing wired network is useful to
accommodate those devices that are only capable of wireless connection. It is like creating
another network only for wireless devices but still be a part of your existing wired network
such as shown in the diagram below.

In the network diagram above, the left portion shows an existing wired network. It
consists of four wired computers connected to a switch, which is connected to a router.
In the right portion, a wireless network shows two wireless computers connected to a
WAP.

Set up the Wireless Network


Step 1. Connect the WAP to your router or switch using the supplied Ethernet cable.
Note: If your WAP does not have Power over Ethernet (PoE) capability, connect the AC
power adapter to the WAP and plug it to the power outlet.
Step 2. Connect your wireless computer to the wireless network that the WAP is
broadcasting.
Note: The default Service Set Identifier (SSID) or wireless network name of the Cisco
Access Point is ciscosb.
Step 3. On the wireless computer, access the web-based utility of the WAP by launching
a web browser and entering the IP address of the WAP in the address bar.
Note: In the event that you do not know the IP address of your WAP, you can use the
Cisco FindIT Discovery Tool or the Cisco FindIT Network Management tool if these
applications are installed in your network. These applications will help you check the IP
addresses and other information of the access point and other Cisco devices within your
network.

Note: In the image above, 192.168.1.245 is used as an example of the IP address. This is
the default IP address of Cisco Access Points.

Step 4. In the authentication window, enter the username and password of the WAP in
the Username and Password fields, respectively.
Note: You can set up to five users to each access point that you are going to add to the
network. These users are the ones authorized to access the web-based utility through
their authentication keys but only one of these users can have the Read/Write privilege
level. Also, you can create a different username and password to each user.

Note: The default username and password of the default user for Cisco Access Points is
cisco/cisco.

Step 5. Click Log In.


Step 6. In the navigation area, choose LAN > IPv4 Setting.

Note: If you are using the WAP121, WAP321, WAP371, WAP551, or the WAP561,
choose LAN > VLAN and IPv4 Address.

Note: If you want to use IPv6 Addressing instead, click here for instructions.

Step 7. Click a radio button to choose the Connection Type.


 DHCP — The access point acquires its IP address from a Dynamic Host
Configuration Protocol (DHCP) server on the network.
 Static IP— You will be the one to manually assign the IPv4 address to the WAP.

Note: In this example, DHCP is chosen. This is the default setting. If you performed this
step, skip to Step 12.

Step 8. (Optional) If you chose Static IP in the previous step, enter the static IP address
you want to assign to the WAP in the Static IP Address field. Make sure that the IP
address you assign is in the same range as your network.
Note: In this example, the IP address used is 192.168.1.112.
Step 9. (Optional) Enter the subnet mask in the Subnet Mask field.

Note: In this example, 255.255.255.0 is used.


Step 10. Enter the router IP address in the Default Gateway field.

Note: In this example, 192.168.1.1 is used as the default gateway.


Step 11. In the Domain Name Servers (DNS) area, the radio button for Manual will be
automatically selected once the Connection Type is set to Static IP. You can enter up to
two DNS addresses in the fields provided.

Note: In this example, 192.168.1.1 is used.


Step 12. Click Save.
Configure Wireless Settings

Step 1. Choose Wireless > Networks.

Step 2. (Optional) If you are using a dual-band access point, click a radio button to choose
the Radio Interface that you want to configure.
 Radio 1 (2.4 GHz) — For wireless clients that operate in the 2.4 GHz frequency.
 Radio 2 (5 GHz) — For wireless clients that operate in the 5 GHz frequency.

Note: In this example, Radio 1 (2.4 GHz) is chosen.


Step 3. Under the Virtual Access Points (SSIDs) area, check the box beside the default
Virtual Access Point (VAP) and click the Edit button below it.

Note: You can add or create multiple VAPs on your WAP depending on the exact model
of your device by clicking on the Add button. For the WAP361, seven additional VAPs
can be created.
Step 4. Under SSID Name, create a new name for your wireless network in the field
provided.
Note: In this example, WireNet is used.
Step 5. (Optional) Under SSID Broadcast, check or uncheck the box depending on your
preference. Checking the box would allow your wireless network to broadcast its SSID
or to be visible to all wireless devices within its range. Unchecking the box would hide it
from all wireless devices.

Note: In this example, SSID broadcast is checked.


Step 6. Under Security, click on the drop-down menu to choose the type of security you
want to set up on the wireless network. The options are:
 None – This option would set the security to open and allow all wireless devices to
connect to your wireless network without being asked for a password or
authentication.
 WPA Personal — Wi-Fi Protected Access (WPA) is a security protocol designed to
improve upon the security features of Wired Equivalent Privacy (WEP). WPA uses
higher, 256-bit keys and improves data encryption and user authentication. This
security mode allows you to use either the Temporal Key Integrity Protocol (TKIP)
algorithm, or the latest, higher-level Advanced Encryption Security (AES)
algorithm if the device is newer and supports it with WPA. Both options, however,
implement stronger security standards.
 WPA Enterprise — In Enterprise mode, Wi-Fi Protected Access (WPA) is used with
Remote Authentication Dial-In User Service (RADIUS) server authentication.

Note: In this example, WPA Personal is chosen. The Security details window would
then be visible.
Step 7. Choose the types of client stations that you want to support by checking the
check boxes in the WPA Versions area.
 WPA-TKIP — This option would allow wireless clients that only support the original
WPA and TKIP security protocol to be able to connect to the network.
 WPA2-AES — This WPA version provides the best security per IEEE 802.11i
standard. As per the latest Wi-Fi Alliance requirement, the WAP has to support this
mode all the time.
Note: If the network has a mix of clients, check both of the check boxes. This setting lets
both WPA and WPA2 client stations associate and authenticate, but it uses the more
robust WPA2 for clients who support it. This WPA configuration allows more
interoperability in place of some security.

Step 8. In the Key field, enter a password consisting of 8 to 63 characters. Each wireless
device that would try to connect to this wireless network will be asked for this
authentication key.

Step 9. (Optional) Check the Show Key as Clear Text box to show the password you
created.

Note: The Key Strength Meter area shows colored bars based on the strength of the key
that you have created. In this example, Str0ngPassw0rd! is used as the authentication
key.
Step 10. In the Broadcast Key Refresh Rate field, enter a value from 0 to 86400 seconds.
This is the interval at which the broadcast (group) key is refreshed for clients associated
with this VAP.

Note: In this example, 300 seconds is used. This is the default value.
Step 11. (Optional) Under MAC Filter, click on the drop-down list either to disable
MAC Filter or to specify whether the stations that can access this VAP are restricted to a
configured global list of MAC addresses. The options are:
 Disabled — Does not use MAC filtering.
 Local — Uses the MAC authentication list that you configure on the MAC
Filtering page.
 RADIUS — Uses the MAC authentication list on an external RADIUS server.
Note: To learn how to configure MAC Filtering, click here.

Step 12. (Optional) Check or uncheck the check box under Channel Isolation to enable
or disable it depending on your preference. When enabled, the WAP blocks
communication between the wireless clients on the same VAP. The WAP still allows
data traffic between its wireless clients and the wired devices on the network, across a
Wireless Distribution System (WDS) link, and with other wireless clients associated
with a different VAP, but not among the wireless clients. When disabled, the wireless
clients can communicate with one another normally by sending traffic through the WAP.

Step 13. (Optional) Check or uncheck the check box under Band Steer to enable or
disable it depending on your preference. This feature is for dual-band WAPs only.
Enabling band steer effectively utilizes the 5 GHz band by steering dual-band supported
clients from the 2.4 GHz band to the 5 GHz band when both radios are up.

Note: In this example, Band Steer is enabled.

Step 14. Click Save.

You should now have successfully added a wireless network to your existing wired
network using a wireless access point.
Practical – 6
Objective: Implementing a wireless sensor network.

Receiver
 Raspberry Pi—Model B with power supply, case, and SD card—Ensure the GPIO pins
are accessible with the case you choose
 Pi compatible Wi-Fi adapter
 Arduino
 Breadboard jumper wires
 Male to female jumper Wires
 Logic level converter
 434 MHz RF receiver
 Half breadboard

Transmitters (two units)


 2 x Arduino
 2 x Temperature / humidity sensors
 2 x 434 MHz RF transmitter
 2 x Half breadboard
 2 x Breadboard-friendly 2.1mm DC barrel jack
 2 x 9V power adapter with 2.1mm x 5
 Breadboard jumper wires

Tools
 PC/Mac with Arduino programming IDE installed
 USB cable for programming Arduino boards
 USB Keyboard and Mouse. Either combined or with a hub so both can be used with a
single USB port.
 The source package associated with this tutorial on your programming workstation

Assemble Transmitters

The transmitters themselves are relatively simple circuits. Only one pin is used to retrieve the
information from the temperature and humidity sensor and one pin is used to send that data to the
RF transmitter. The breadboard diagram is shown below.

The 9V power supply will attach to the barrel connector making the bottom rails 9V. The power
regulator in the Arduino will produce 5V that is safe to use for the radio and sensors, the top
power rail of the diagram.

The sensor comes with a 10k ohm resistor that connects the data pin to power as a pull up resistor
while another wire connects it to GPIO D3.
Transmitter diagram

The antenna is an important part of the board because the RF module does not have a built in
antenna. I used a 6-inch female to male jumper wire plugged into the breadboard and it worked
well enough to allow reception from all parts of my home and a little bit outside. As noted in the
diagram, 6.5-inch is optimal for this antenna if you need additional range.

Download Libraries for Components

The transmitter uses two libraries that are not bundled with the Arduino IDE. Download the
libraries as described below and uncompressed them into your sketch directory in a subdirectory
named Libraries.

 Download the VirtualWire source package for this tutorial and unzip
the wirelesstransmitter sketch folder into your Arduino sketch folder
 In the wirelesstransmitter folder create a folder named Libraries
 Download the latest version of the VirtualWire code, 1.23 as of this writing, from
the project page
 Extract the VirtualWire folder into the wirelesstransmitter/Libraries/ folder so you
have another subfolder named VirtualWire
 Download the DHT sensor library from its project github page
 Extract the DHT folder into the Libraries folder as well. You should now have the two
required library folders DHT and VirtualWire in
your wirelesstransmitter/Libraries folder.
Program the Arduino Board

This tutorial assumes you have some experience with Arduino and how to program them using
the Arduino IDE. If you do not, there are very good instructions at the official Arduino site.

 Open the wirelesstransmitter sketch from the source archive in the Arduino IDE and
save a copy locally
 Ensure the Arduino is NOT connect to power via the barrel connector
 Connect the board to your programming workstaiton station with an appropriate USB
cable
 Set the board type to your selected Arduino board under the Tools > Board menu
 Set the serial port to the port detected when you connected the Arduino board under
the Tools > Port menu
 Ensure that the MYID define is set to 1 and the TRANSPIN and DHTPIN are properly
set to the pins connected to the RF transmitter module and DHT sensor respectively. If
you built your board per the diagram above this should all be set already. See the code
example below.
 Ensure that the UNIT is set properly for your preference Fahrenheit or Celsius.

#define MYID 1 //the ID number of this board. Change this for each board you flash.
#define TRANSPIN 3 //what pin to transmit on
#define DHTPIN 4 // what pin the DHT is connected to
#define UNIT 0 // 0 for Fahrenheit and 1 for Celsius

The MYID define is a numeric ID that the transmitter uses to uniquely identify itself. Because
you will have multiple transmitters in different locations it is important to have a unique ID for
each one. This number will be used again when you setup the receiver script.

 Verify the code by pressing Control-R to ensure the libraries are included and compiled
properly.
 Push the code to the board by clicking the Upload button on the tool bar.
 Open the Serial Monitor windows by pressing Control-Shift-M

The Serial Monitor window resets the Arduino so you should see a line of code on the screen
that looks something like:

Even if there is doubling and the signal from both transmitters is lost, the random interval will
ensure that their next broadcasts will not overlap. The random seed for this interval is set from
an analogRead on an unused analog port which will return random values to ensure no two
transmitters are on the same pattern.

The transmitters are set to wait 2 to 5 minutes between broadcasts by default. If you wish to
speed this up for debugging purposes then modify the delay() value at the end of the sketch to be
more like 5000 (ms). It is highly recommended that you change this back and re-upload the code
to your transmitters when you are ready for full time use.

 Build the second transmitter board


 Modify the transmitter sketch so that the MYID define is set to 2
 Upload the code to the second board
 Open the Serial Monitor windows by pressing Control-Shift-M and verify that the
output looks like the first transmitter board with the exception that the transmitted
message starts with ID:2

Build the Receiver Board

The receiver board will be responsible for receiving the broadcast message on its RF Receiver
component and sending that message over serial wires to the Raspberry Pi. The Arduino board is
used to receive the signal for a couple very important reasons. The VirtualWire code uses the
real time nature of the Arduino to manage modulating and demodulating the signal.

This means that the receiving unit needs to be operating at the same frequency. In addition, there
is little room for jitter on the receiving processor, to which the Raspberry Pi is prone, due to its
preemptive, non real-time operating system. Comparing the costs of an Arduino Pro Mini plus the
RF receiver module to that of a Zigbee module that could talk directly to the Raspberry Pi
revealed that using an external Arduino was still quite economical.

Build the receiver board per the Fritzing diagram below.

Receiver Diagram
This component is required in order to convert the 5V Arduino serial signal to a 3.3V Raspberry
Pi serial signal and not damage the Pi. See the image below for additional help.

Actual Logic Level Converter Wiring

Note that the RX and TX wires cross through the logic level converter so that the TX from the
Arduino goes into the RX of the Pi. The next steps involve setting up the Pi, you'll return to
program the Arduino later.

Setup the Raspberry Pi

There are several guides to purchasing and installing an OS on your Raspberry Pi. Install the
latest Raspbian operating system. The following steps describe connecting the peripherals to the
Pi and configuring.

 Insert the USB Wi-Fi adapter into the top USB port on the Pi
 Connect the USB hub to the bottom USB port on the Pi
 Connect the mouse and keyboard to the USB hub
 Connect the HDMI Monitor
 Insert the SD Card
 Connect the power supply
 Perform first time setup configuration leaving the default option to boot to a graphical
desktop
 After the Pi reboots to a desktop follow these instructions on how to use the GUI tool
to configure your wifi network.
 Open a terminal window by double-clicking on the LXTerminal icon.
 Execute the command sudo raspi-config
 Select the Enable Boot to Desktop/Scratch > Console Text console, requiring
login option
 Select the Advanced Options > SSH to enable network command line access
 Select Finish and allow the Pi to reboot to the text console
 Make note of the IP address the Pi reports when it boots. This will be used to SSH to the
Pi in later steps. The steps below for configuring the Pi are easier done from an SSH
session to the Pi.
Configure Raspberry Pi

The Raspberry Pi uses its serial port by default as a serial console. The device is
named ttyAMA0. When it boots it dumps boot messages to this device and sets up a login
session on it. In order to use it for receiving data from the Arduino you will need to disable the
serial console and session.

 Edit the inittab file that controls text login session with the command below. It's always
recommended to make a backup of the original file before editing just in case something
goes wrong.

sudo pico /etc/inittab

 Locate the lines at the bottom of the file that refer to the device ttyAMA0 and add a # to
the start of the line that includes this device name. It should look like the lines below
when you are done

#Spawn a getty on Raspberry Pi serial line


#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

 Edit the /boot/cmdline.txt with the command below. Don't forget to make a backup copy
just in case.

sudo pico /boot/cmdline.txt

 Remove the arguments that reference ttyAMA0. They part you want to remove looks
something like this: console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
 Save the file and reboot the Pi

Install Python Script and Prerequisites

The python script that will complete the receiver will perform several functions.

1. Read from the serial port


2. Parse the input and ensure it is sane
3. Interpret the serial data
4. Post the data to Xively into the appropriate feed

In order to perform these functions you will need to install the prerequisite modules to install the
serial libraries and Xively communications.

 Login to the Pi and execute the commands below to install them.

sudo apt-get install python-serial python-setuptools


sudo easy_install pip
sudo pip install --pre xively-python
mkdir ~/scripts
 Copy the script wirelessnetwork.py from the source package for this tutorial into the
scripts directory you just created. You can do that by copying and pasting the contents or
by scping the script to the Pi.
 Ensure the script is executable with the command

chmod u+x wirelessnetwork.py


The next several steps will take you through setting up Internet of Things accounts that allow you
to record and react to the data your device is recording.

Setup Your Xively Account for the Pi

Xively is a service that collects data from things. You can setup and register your thing or
Raspberry Pi with Xively and data can be pushed from your Pi to the cloud for tracking and
triggering.

 Go to xively.com and register for a free account


 Click on the Get Started button
 Scroll to the bottom of the page and choose Sign Up for a free Developer Account
 Fill out the appropriate account information and validate your account
 Authenticate as your new account as needed
 Select Web Tools > Develop to go to your new developer page
 Click on the big + Add Device box to add your Raspberry Pi
 Fill out the Device Name: WirelessNetwork, Device Description: Environmental
Monitor, choose Private Device unless you wish to share your salt level with the world.
 Click Add Device. After the device is created you will be presented with the device
screen with keys and information about the device.
 Record the Feed ID and API Key from the device page. The Feed ID is in small font
near the top of the page and the API Key is in large font on the right side of the page.
You will need these to finalize the wirelessnetwork.py script you downloaded in the
previous section.

Configure the Python Script

In order to post data to Xively the wirelessnetwork.py script needs to have the Feed ID and API
Keys that you recorded above. Edit the script using pico or your favorite editing tool.

#some defines for Xively


FEED_ID = "FEED ID HERE" #enter your feed ID number here
API_KEY = "API KEY HERE" #set your API key here
# initialize api client
api = xively.XivelyAPIClient(API_KEY)

#Create mapping from transmitter ID number to names. This could be a DB some day
DEV={'1':'Bedroom', '2':'Basement'}

DEBUG = True
While you are editing the script make sure to edit the DEV variable. This variable is a name
mapping for the IDs that the sensor modules will be sending. In this example when the sensor
module with ID 1 sends a message, the script will post to a Xively channel with the friendly
name Bedroom instead of ID1. In the same way, the sensor module with ID 2 will be reported
into the channel Basement.

Program the Receiver Arduino

The Raspberry Pi is now ready to receive data using the wirelessnetwork.py script. The Arduino
needs to be programmed with the wirelessreceiver sketch.

 Open the wirelessreceiver sketch from the source package and save a copy locally
 Copy the VirtualWire library from the wirelesstransmitter/Library directory to
the Library directory under the new wirelessreceiver directory
 Attach the receiver Arduino receiver to your programming workstation and ensure the
port and board type are set correctly.
 Ensure that the RXPIN define is set to the pin number that is connected to the RF
receiver module. If it is built per the diagram the sketch should be fine without changes.
 Verify and upload the the sketch to the Arduino
 Open the Serial Monitor windows by pressing Control-Shift-M. If the transmitters are
not running you will not see out put.
 Plug one of the transmitter modules into power using the 9V wall adapter and the barrel
connector on the breadboard. You should now see the messages that are being received
on the Arduino. Unplug the USB cable from the Arduino

 Attach the ground and power jumpers from the Raspberry Pi

Test the Receiver Script

Now that you have the Arduino receiving data from a sensor module you can test the script on the
Pi to ensure it is properly reading the data and posting it to Xively. Open an SSH or terminal
session to the Pi for the following steps.

 Activate the second wireless transmitter by plugging it in with the second 9V adapter
 Execute the wirelessnetwork.py script from the /home/pi/scripts directory with the
following commands

cd /home/pi/scripts/
./wirelessnetwork.py

 Review the output in the console and on the Xively website.

Received input: ID:1:TS:154075:TF:73.39:RH:39.00


Processing data for: Bedroom
Posting temp fahrenheit for Bedroom
Creating datastream
Updating Xively feed with value: 73.39
Posting relative humidity for Bedroom
Found existing datastream
Updating Xively feed with value: 39.00

The script will create feeds for humidity and temperature the first time it runs. The example
above shows the script receiving the messages, parsing them and posting them to Xively
successfully. Use Control-C to exit the script before proceeding to the next step.

Switch to the browser windows where you created your Xively account and device. The new
datastreams and some information about them should be available and look something like the
image below.

Xively Channel Updated

Set the Script to Launch on Boot

Because the Raspberry Pi is going to be run headless the script should be set to start automatically
when the unit is powered.

 Add the following line to the /etc/rc.local file. Use your favorite editor, but make sure to
sudo the edit command as /etc/rc.local is a root owned file. The script itself can run as
the user pi rather than as root.

sudo -u pi /home/pi/scripts/wirelessnetwork.py &

 Reboot the Pi
 Login to the Pi after it has rebooted and verify that the script is running with the
following command.

ps ax |grep wirelessnetwork

The output should look something like the excerpt below.

22000 pts/1 S+ 0:02 /usr/bin/python /home/pi/scripts/wirelessnetwork.py


Practical – 7
Objective: Implementing Transport Control Protocol in Sensor Network.

Transport Protocols for Sensor Networks:

In addition to energy-efficient transport layer protocols in resource constrained WSNs, the


protocol should also support

 reliable message delivery,


 congestion control, and
 energy efficiency.

7.1 TCP/IP

TCP/IP has been used successfully in wired 802.3 and wireless 802.11 networks and has been
discussed as a possible transport layer for WSN [14]. Certain attributes, such as IP addressing
for individual nodes, unnecessary header overhead for data segments, no support for data
centric routing, a heavyweight protocol stack, and an end-to-end reliability scheme that
attributes segment losses network congestion, of TCP/IP; however, they make it unsuitable
for use in WSNs without modification. Even if TCP/IP is not entirely suitable for WSNs, it is
informative to compare TCP/IP to transport protocols designed specifically for WSNs. Such a
comparison helps to illustrate that WSNs operate in a different paradigm, and thus need
specially designed transport layers to meet their unique needs.

TCP/IP may not be suitable for standard sensor nodes in a WSN, but may still be used at the
sink to communicate with other remote endpoints. Sensor nodes with high robustness, such as
Crossbow [18], may use TCP/IP as a virtual sink or proxy between the WSN and the remote
host to reduce the number of retransmissions of a data segment by less powerful sensor
nodes.

7.2 Reliable Multi-Segment Transport (RMST)

RMST, first proposed in [8], is a reliable transport layer for WSNs. RMST is meant to
operate on top of the gradient mechanism used in directed diffusion [5]. RMST adds two
important features to directed diffusion [8],
1. fragmentation and reassembly of segments, and
2. reliable message delivery.

One of the most intriguing features of RMST is that it is an extension of directed diffusion
that can be applied to a sensor node and configured without having to recompile. Essentially
RMST is a plugin transport layer mechanism for an already widely accepted and studied
WSN network layer.

RMST can be configured to allow hop-by-hop recovery (using local broadcast NACK) or
end-to-end recovery (end-to-end NACK) at run time, and can be combined with a MAC-level
Automatic Repeat Query (ARQ). The configuration between hop-by-hop (cached) recovery
and end-to-end (noncached) recovery can be configured at the sensor nodes at runtime.

The main contribution of the paper by Stann et al. [8] was to compare the combination of
transport layer reliability and lower layer recovery mechanisms. Reliable delivery was
compared to using end-to-end recovery at the transport layer, hop-by-hop recovery at the
transport layer, and hop-by-hop recovery at the MAC layer using an Automatic Repeat
Request (ARQ).

RMST considers reliable transport in the point-to-multipoint direction and multipoint-to-


point direction with special emphasis given to sensor re-programming or transfer of binary
objects, when the loss of a single segment would irreparably damage the entire message.

Loss Detection/Recovery Mechanisms

RMST employs a Negative Acknowledgement (NACK) gap detection to detect and recover
lost messages similar to the scheme used by PSFQ. However, RMST makes no guarantee of
in-order message delivery, rendering loss detection is particularly difficult since it is difficult
for sensor nodes to determine whether gaps are caused by out-of-order delivery or lost
messages. To help assuage this problem RMST creates a “hole map” for detected gaps and
assigns a “watchdog” timer to generate an automatic NACK for any segment that has not
been received in the timer interval [8].

Multiple fragment numbers can be combined into a single NACK, as in PSFQ, to cut down
on the network traffic generated during message recovery, as shown in Fig. 4. Since RMST
uses the same gap acknowledgement scheme as PSFQ, it inherits the same shortcomings
when detecting loss of truncated messages. As seen with PSFQ's recovery scheme, at least
one data segment must be received downstream for RMST to detect message loss.

Figure 4 An example of the RMST protocol.

(a) Interest is disseminated through the network, using directed diffusion.


(b) A reinforced gradient path is established between the source and the sink.
(c) RMST snoops on the reinforced path at each hop and uses it to establish a backchannel for NACK that
need to be sent in the source direction.
(d) RMST allows nodes to NACK multiple fragments of a message at once. Here the node is sending
NACK 2, 3, 8 asking for retransmission of packet fragments 2, 3, and 8.

7.3 Congestion Control Mechanisms

RMST does not specify any congestion control or detection mechanism. It is concerned
solely with reliable data transfer between the sensor nodes and the sink. Any congestion
control mechanisms are a byproduct of the use of directed diffusion which offers minimal
congestion control. For example, sensor nodes having gradients that show interest in the same
information, but have different reporting intervals, may “downconvert” to the lower of the
two reporting intervals [5].
7.4 ESRT (Event to Sink Reliable Transport)

ESRT introduces the idea of reliable event detection from the sensor nodes to the sink. ESRT
leverages the loss tolerant characteristic of WSNs, the goal being to pass a course description
of the event rather than providing fine details. Since ESRT will only reliably pass a course
description of the event, it is unacceptable for applications that require delivery of all
message segments. Unlike PSFQ and RMST, ESRT would be a good choice for tasks such as
sensor retasking or transporting binary objects in general.

ESRT uses a different paradigm to measure reliability in wireless sensor networks. The
assumption is not made that only messages in the point-to-multipoint direction, i.e. from the
sink to the sensor nodes, is the only type of message that needs to be reliably delivered.
Instead a measure of goodness is created using a defined event detection threshold and that
threshold is used to define reliability in the multipoint-to-point direction.

Loss Detection/Recovery Mechanisms

ESRT's loss detection and recovery mechanism does not prevent all losses, nor does it
guarantee delivery of all message segments from all source nodes. Instead ESRT tries to find
the correct frequency, f, to send messages.

Sankarasubramaniam et al. [9] introduce definitions for observed event reliability, ri, and
desired event reliability, R. Observed event reliability, ri, is defined as the number of data
segments received over some interval i at the sink, and desired event reliability, R, is defined
as the number of packets required for reliable event detection, i.e. R is the threshold for
reliable event detection. Data segments are given event IDs, and thus ri can be computed in
real time by incrementing a counter at the sink for all correlated segments.

Control reliable event detection and network congestion by relating ri and R to f. The problem
of reliable event detection then becomes adjusting f to maintain ri in an optimal interval
around R.

To further explore the idea of maximizing energy efficiency on WSNs by minimizing the
transmission of highly correlated data flows. Eliminating the need to send data from all
sensor nodes allows for some redundancy for the sensor nodes in WSNs and can prolong the
lifetime of the network.
Practical – 8
Objective: Develop sample wireless network in which,

a. Implement AODV and AOMDV protocol.


b. Calculate the time to receive reply from the receiver using NS2.
c. Generate graphs which show the transmission time for packet.

Implement AODV and AOMDV Protocol


Ad-hoc On-demand Distance Vector Routing Protocol is used for mobile or wireless ad-
hoc networks (MANETs or WANETs). An ad-hoc network is a temporary distributed
network that is built by two or more nodes, to transfer packets without requiring typical
infrastructures such as routers and access points. Nodes in the ad-hoc network follow a peer-
to-peer network (P2P). The AODV protocol was developed by joint efforts of the Nokia
Research Center, University of California, and the University of Cincinnati.

There are various simulators that can be used to simulate network protocols such
as NS2, NS3, OMNeT++, NetSim. Here I am using NS2, an open-source event-driven
simulator. NS2 is written in C++ and Otcl, and the simulation has to be written in TCL
Script. NS2 is a really old simulator, began as a revision of NS-1 in 1995. Though I am using
version 2.35 which was released in 2011 on Ubuntu 20.04.1, and it works really fine, So no
worries there :)

NS2 executes the TCL script and generates a trace file and a network animator file. The
trace file is used for the analysis of the simulation like throughput, energy consumption.
The network animator file is executed by Nam (version 1.15) which produces the simulation
as an animation.

Nodes discover routes using defined messages by AODV, which are Route Requests -
RREQ, Route Reply - RREP, Route Error - RERR. Originating node
broadcasts RREQ messages to all its neighbors, nodes that have a route to the destination
node broadcasts RREP message along the reverse route to the originating node. In case, the
neighboring node to originating node does not have a route to the destination, it, in turn,
broadcasts RREQ messages keeping a reverse route to the originating node. If a node loses
connection to its next-hop node destination, it broadcasts RERR messages to all nodes which
received RREP messages.

Routing Table Entries maintained by AODV


 Destination IP Address

 Destination Sequence Number

 Valid Destination Sequence number flag

 Other state and routing flags

 Network Interface

 Hop Count

 Next Hop

 List of Precursors

 Lifetime

First of all set up some variables, which will be used later on for node configuration. val here
is an array with non-number indices. val(stop) is the end time of the
simulation. val(x), val(y) will be used to define topography. val(nn) denotes no. of nodes
used. val(rp) contains the type of routing protocol, which is AODV in this case.
set val(chan) Channel/WirelessChannel;

set val(prop) Propagation/TwoRayGround;

set val(netif) Phy/WirelessPhy;

set val(mac) Mac/802_11;

set val(ifq) Queue/DropTail/PriQueue;

set val(ll) LL;

set val(ant) Antenna/OmniAntenna;

set val(ifqlen) 50;

set val(rp) AODV;

set val(nn) 11;

set val(x) 500;

set val(y) 400;

set val(stop) 3;

set val(energymodel) EnergyModel;

set val(initialenergy) 1000;

val(ifq) is the interface queue that gives priority to routing protocol packets and val(ifqlen) is
the max length of the queue. val(ant) defines antenna type as Omni-direction which means it
can receive and transmit in all directions. var(prop) is set as TwoRayGround which is the
attenuation model during radio propagation (1/r⁴). val(netif) contains value for network
interface. The Network Interface layer serves as a hardware interface that is used by the
mobile node to access the channel and it is set as Phy/WirelessPhy.

set ns [new Simulator]

set tf [open ns_aodv.tr w]

$ns trace-all $tf

set nf [open ns_aodv.nam w]

$ns namtrace-all-wireless $nf $val(x) $val(y)


set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

set chan_1_ [new $val(chan)]

Line 1 generates the NS simulator object instance and assigns it to variable ns. Line 2 creates
an empty trace file ns_aodv.tr and assigns it to variable tf. trace-all command traces all the
events in a specific format. Line 6 creates the NAM visualization file ns_aodv.nam and
assigns it to nf. Line 7 tells the simulator to record traces in NAM format. Line 10 sets the
topography to flatgrid. god object stores the table of shortest no. of hops required from one
node to another.

$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_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON \
-energyModel $val(energymodel) \
-initialEnergy $val(initialenergy) \
-rxPower 0.4 \
-txPower 1.0 \
-idlePower 0.6 \
-sleepPower 0.1 \
-transitionPower 0.4 \
-transitionTime 0.1

The above configures the node with the variable that we defined in the beginning. Some other
parameters such as agentTrace trace UDP in our case, routerTrace traces packets involved in
routing, macTrace traces MAC protocol packets, movementTrace traces the motion of
nodes.

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

$node_($i) set X_ [ expr 10+round(rand()*480) ]

$node_($i) set Y_ [ expr 10+round(rand()*380) ]

$node_($i) set Z_ 0.0

Here the first loop is assigning the initial location of nodes and the second loop is providing
the random movement of nodes within the topography.

set udp [new Agent/UDP]

$ns attach-agent $node_(5) $udp

set null [new Agent/Null]

$ns attach-agent $node_(2) $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set interval_ 0.1

$cbr set rate_ 1mb

$cbr set maxpkts_ 10000

$ns connect $udp $null

$ns at 0.4 "$cbr start"

We are creating an object of UDP and attaching it to our node no. 5, which will be the
originating node. Also, creating a Sink and attaching it to the destination node, node no. 2.
CBR (Constant Bit Rate) is our traffic source that will generate packets to send over UDP.
for {set i 0} {$i < $val(nn)} {incr i} {

$ns initial_node_pos $node_($i) 30

for {set i 0} {$i < $val(nn)} {incr i} {

$ns at $val(stop) "$node_($i) reset";

The first ‘for loop’ initialize all nodes with initial positions for nam and the second ‘for loop’
resets all nodes at the end of the simulation.

$ns at $val(stop) "finish"

$ns at 3.1 "puts \"end simulation\"; $ns halt"

proc finish {} {

global ns tf nf

$ns flush-trace

close $tf

close $nf

exec nam ns_aodv.nam &

exit 0

puts "CBR packet size = [$cbr set packetSize_]"

puts "CBR interval = [$cbr set interval_]"

$ns run

The keyword global is used because we are using variables that were declared outside the
scope of proc finish (procedure). flush-trace command saves all traces to respective files.
The simulation begins at $ns run.
Output:
Practical – 9
Objective: Implement mobile devices as wireless access point.

Setting up Android like a wireless access point is straightforward.

 On Android, open Settings > Network & internet > Hotspot & tethering.
 Next, select Portable hotspot.
 Tap On then confirm the message regarding interruptions to existing connections.
 Click Configure hotspot.
 Set a Network name (SSID) --- this can be anything.
 Choose the Security level --- WPA2 PSK is the strongest.
 Set a new Password.
 When you're done, tap Save.

With the hotspot enabled, you'll be able to use your phone like a home wireless network.

Set Up Wireless Internet on iPhone or iPad

iPhone users can use their phone like a Wi-Fi router by using the hotspot feature.

 Open Settings.
 Tap Personal Hotspot.
 Enable Allow Others to Join.
 You'll see a message labeled Bluetooth is Off.
 Select Turn on Bluetooth or Wi-Fi and USB Only, as per your preference.
 Tap Wi-Fi Password to set a new passkey.
With all options set, your iPhone will be running as a wireless hotspot --- essentially, a
mobile router for your home!

Use Windows 10 Mobile as a Wireless Router

If you have an old phone you plan to use as a wireless router, it might be a Windows 10
Mobile.

 Swipe down from the top and long-tap Mobile hotspot.


 Tap the Share my mobile data switch to On.
 Ensure Share my mobile data connection is set to Wi-Fi.
 Tap Edit to set a Network name and new password.
 When you're done, tap the Back

Windows 10 Mobile features an option to remotely enable the mobile hotspot feature over
Bluetooth. To do this, enable Turn on remotely. If your second device (perhaps a remote
control or headset) is connected to your device over Bluetooth, this will work.

Connect Devices to Your Home Mobile Wi-Fi Network

With your smartphone set up as a Wi-Fi router, you'll be ready to start connecting devices.
For the best results, keep this to as few devices as possible. A couple of tablets or laptops is a
smart idea; a games console, less so.

To do so, simply connect them as you would to any other wireless router. The broadcast
name (SSID) you specified will be displayed. Simply enable Wi-Fi on your device, find the
SSID, and enter the password you specified.
Practical – 10
Objective: Study of Security in Ad hoc Wireless Networks.

In these years, progresses of wireless technology and increasing popularity of wireless


devices, made wireless networks so popular. Mobile Ad Hoc Network (MANET) is an
infrastructure independent network with wireless mobile nodes. MANET is a kind of Ad Hoc
networks with special characteristics like open network boundary, dynamic topology,
distributed network, fast and quick implementation and hop-by-hop communications. These
characteristics of MANET made it popular, especially in military and disaster management
applications. Due to special features, wide-spread of MANET faced lots of challenges. Peer
to peer applications , integration with internet, security maintaining network topology and
energy are some of the most important challenges in MANET.

10.1 Important Parameters In MANET Security


Because of MANET’s special characteristics, there are some important metrics in MANET
security that are important in all security approaches; we call them “Security Parameters”.
Being unaware of these parameters may cause a security approach useless in MANET.

Each security approach must be aware of security parameters as shown in Figure 1. All
mechanisms proposed for security aspects, must be aware of these parameters and don’t
disregard them, otherwise they may be useless in MANET. Security parameters in MANET
are as follows:

Network Overhead: This parameter refers to number of control packets generated by


security approaches. Due to shared wireless media, additional control packets may easily lead
to congestion or collision in MANET. Packet lost is one the results of congestion and
collision. Therefore, high packet overhead increases packet lost and the number of
retransmitted packets. This will easily wastes nodes energy and networks resources.

Processing Time: Each security approach needs time to detect misbehaviours and eliminate
malicious nodes. Due to MANET’s dynamic topology it’s strongly possible that routes
between two different nodes break because of mobility. Therefore, security approaches must
have as low as possible processing time in order to increase MANET flexibility and avoid
rerouting process.

Energy Consumption: In MANET nodes have limited energy supply. Therefore, optimizing
energy consumption is highly challengeable in MANET. High energy consumption reduces
nodes and network’s lifetime. Each security protocol must be aware of these three important
parameters. In some situations a trade-off between these parameters is provided in order to
perform a satisfaction level in all of them. Security protocols that disregard these parameters
aren’t efficient as they waste network resources.
10.2 MANET Security Challenges
One of the earliest researches in security in MANET was presented in 2002 [9]. Some
security challenges in MANET were inherited from ad hoc networks that were research
interests since International Journal of Computer Science & Engineering Survey (IJCSES)
Vol.6, No.1, February 2015 17 1999 [10, 11]. Generally there are two important aspects in
security: Security services and Attacks. Services refer to some protecting policies in order to
make a secure network, while attacks use network vulnerabilities to defeat a security service.
In the next two parts, a brief discussion on these security aspects is presented.

10.3 Security Services


The aim of a security service is to secure network before any attack happened and made it
harder for a malicious node to breaks the security of the network. Due to special features of
MANET, providing these services faced lots of challenges. For securing MANET a trade-off
between these services must be provided, which means if one service guarantees without
noticing other services, security system will fail. Providing a trade-off between these security
services is depended on network application, but the problem is to provide services one by
one in MANET and presenting a way to guarantee each service. We discuss five important
security services and their challenges as follows:

Availability: According to this service, each authorized node must have access to all data
and services in the network. Availability challenge arises due to MANET’s dynamic topology
and open boundary. Accessing time, which is the time needed for a node to access the
network services or data is important, because time is one of the security parameters. By
using lots of security and authentication levels, this service is disregarded as passing security
levels needs time. Authors in [12] provided a new way to solve this problem by using a new
trust based clustering approach. In the proposed approach which is called ABTMC
(Availability Based Trust Model of Clusters), by using availability based trust model, hostile
nodes are identified quickly and should be isolated from the network in a period of time,
therefore availability of MANET will be guaranteed.

Authentication: The goal of this service is to provide trustable communications between two
different nodes. When a node receives packets from a source, it must be sure about identity of
the source node. One way to provide this service is using certifications, whoever in absence
of central control unit, key distribution and key management are challengeable. In [13] the
authors presented a new way based on trust model and clustering to public the certificate
keys. In this case, the network is divided into some clusters and in this clusters public key
distribution will be safe by mechanisms provided in the paper. Their simulation results show
that, the presented approach is better than PGP. But it has some limitations like clustering.
MANET dynamic topology and unpredictable nodes position, made clustering challengeable.

Data confidentially: According to this service, each node or application must have access to
specified services that it has the permission to access. Most of services that are provided by
data confidentially use encryption methods but in MANET as there is no central
management, key distribution faced lots of challenges and in some cases impossible. Authors
in [14] proposed a new scheme for reliable data delivery to enhance the data confidentially.
The basic idea is to transform a secret message into multiple shares by secret sharing schemes
and then deliver the shares via multiple independent paths to the destination. Therefore, even
if a small number of nodes that are used to relay the message shares, been compromised, the
secret message as a whole is not compromised. Using multipath delivering causes the
variation of delay in packet delivery for different packets. It also leads to out-of-order packet
delivery.

Integrity: According to integrity security service, just authorized nodes can create, edit or
delete packets. As an example, Man-In-The-Middle attack is against this service. In this
attack, the attacker captures all packets and then removes or modifies them. Authors in [15]
presented a International Journal of Computer Science & Engineering Survey (IJCSES)
Vol.6, No.1, February 2015 18 mechanism to modify the DSR routing protocol and gain to
data integrity by securing the discovering phase of routing protocol.

Non-Repudiation: By using this service, neither source nor destination can repudiate their
behaviour or data. In other words, if a node receives a packet from node 2, and sends a reply,
node 2 cannot repudiate the packet that it has been sent. Authors in [16] presented a new
approach that is based on grouping and limiting hops in broadcast packets. All group
members have a private key to ensure that another node couldn’t create packets with its
properties. But creating groups in MANET is challengeable.

10.4 Attacks
Due to special features like hop-by-hop communications, wireless media, open border and
easy to setup, MANET became popular for malicious nodes. Some of the most important
attacks in MANET are as follows:

Black Hole Attack: In this attack, malicious node injects fault routing information to the
network and leads packets toward itself, then discards all of them [17-19]. In [20] we present
a survey on black hole detection and elimination approaches. Also we presented a
classification of defeating approach for this attack. Authors in [21] presented a new approach
based on confirming the best path using second path. In this approach, whenever a source
node receives RREP packets, it send a confirmation packet through the second best path to
the destination and ask the destination whether it has a route to the RREP generator or to the
Next_Hop_Node of RREP generator or not. If the destination has no route to this nodes, both
RREP generator and it’s Next_Hop_Node will mark as malicious nodes. Using this approach
source node can detect cooperative malicious nodes. Whoever in the case of more than two
cooperative malicious node, this approach can’t detect all malicious nodes.
Worm Hole Attack: In worm hole attack, malicious node records packets at one location of
the network and tunnels them to another location [22]. Fault routing information could
disrupt routes in network [23]. Authors in [24] presented a way to secure MANET against
this attack by using encryption and node location information. But as mentioned before, key
distribution is a challenge in MANET.

Byzantine attack: In this attack, malicious node injects fault routing information to the
network, in order to locate packets into a loop [25, 26]. One way to protect network against
this attack is using authentication. Authors in [27] presented a mechanism to defeat against
this attack using RSA authentication.

Snooping attack: The goal of this attack is accessing to other nodes packets without
permission [28]. As in MANET packets transmitted hop by hop, any malicious node can
capture others packets.

Routing attack: In this attack, malicious node tries to modify or delete node’s routing tables
[17, 18, 29]. Using this attack, malicious node destroys routing information table in ordinal
nodes. Therefore, packet overhead and processing time will increase.

Resource consumption attack: In this attack, malicious node uses some ways to waste
nodes or network resources [30, 31]. For instance, malicious node leads packets to a loop that
consists of International Journal of Computer Science & Engineering Survey (IJCSES) Vol.6,
No.1, February 2015 19 ordinal nodes. As a result, node’s energy consumed for transmitting
fault packets. In addition, congestion and packet lost probability will increase.

Session hijacking: Session hijacking is a critical error and gives an opportunity to the
malicious node to behave as a legitimate system [32, 33]. Using this attack, malicious node
reacts instead of true node in communications. Cryptography is one of the most efficient
ways to defeat this attack.

Denial of service: In this attack, malicious node prevents other authorized nodes to access
network data or services [34-38]. Using this attack, a specific node or service will be
inaccessible and network resources like bandwidth will be wasted. In addition, packet delay
and congestion increases.

Jamming attack: Jamming attack is a kind of DOS attack [39]. The objective of a jammer is
to interfere with legitimate wireless communications. A jammer can achieve this goal by
either preventing a real traffic source from sending out a packet, or by preventing the
reception of legitimate packets [40].

Impersonation Attack: Using this attack, attacker can pretend itself as another node and
injects fault information to the network [41-43]. As MANET has open border and hop-by-hop
communications, it’s hardly vulnerable against this attack. In some cases even using
authentication is useless.
Modification Attack: In this attack, malicious nodes sniff the network for a period of time.
Then, explore wireless frequency and use it to modify packets [44, 45]. Man-in-the-middle is
a kind of Modification attack.

Fabrication Attack: In fabrication attack, malicious node destroys routing table of nodes by
injecting fault information [46-48]. Malicious node creates fault routing paths. As a result,
nodes send their packets in fault routes. Therefore, network resources wasted, packet delivery
rate decreased and packet lost will growth.

Man-in-the-middle attack: In this attack, malicious node puts itself between source and
destination. Then, captures all packets and drops or modifies them [49-51]. Hop by hop
communications are made MANET vulnerable against this attack. Authentication and
cryptography are the most effective ways to defeat this attack.

Gray Hole Attack: This attack is similar to black hole. In black hole, malicious node drops
all packets, while in this attack, malicious node drops packets with different probabilities. As
it relays some packets, detecting this attack is more complicated than black hole and some
detection approaches like sniffing or watchdog will be useless in it.

Traffic Analyse Attack: The goal of this attack is sniffing network traffic to use them in
another attack or in a specific time. Malicious node captures all packets to use them later.

You might also like