This document is a thesis submitted by Muhammad Adil Raja to the Department of Computer Science at Lahore University of Management Sciences in partial fulfillment of the requirements for a Masters of Science degree in Computer Science. The thesis focuses on implementing and evaluating a routing algorithm for sensor networks based on minimum transmission energy routing. It includes chapters on sensor networks and routing protocols, describing the proposed algorithm and simulator for evaluating it, and analyzing the results of testing the algorithm on different network topologies.
Modeling the Effect of packet Loss on Speech Quality: GP Based Symbolic Regre...
Thesis
1. A report submitted to the
Department of Computer Science
in partial fulfillment of the requirements for the
degree
Masters of Science
in
Computer Science
by
Muhammad Adil Raja
2001-03-0017
Lahore University of Management Sciences
May 30, 2001
Implementation and Evaluation of a Routing Algorithm for Sensor Networks i
2. Acknowledgements
I truly acknowledge the cooperation and help make by Dr. Muhammad Ashraf Iqbal,
Head Department of Computer Science, Lahore University of Management Science.
He has been a constant source of guidance throughout the course of this project.
(Signed)
Muhammad Adil Raja 2001-03-0017
Date
June 25, 2004
Implementation and Evaluation of a Routing Algorithm for Sensor Networks ii
3. Abstract
“Wireless micro-sensor networks” is a novel field in the area of computer networks.
The basic philosophy is to deploy a network of sensors which communicate with each
other through a wireless medium. The amount of sensors in a typical network can
vary from a few hundreds to a few thousands of sensors. The sensors can share and
propagate information from one part of the network to the other by using an
appropriate routing protocol. The content of information may depend on the
application and the routing/transport protocol which is deployed on the network. The
applications of sensor networks are numerous ranging from deploying a network in
ones home to monitor different activities to deploying a network for surveillance or
guarding a particular area. Although the nodes in a particular sensor network
communicate in the same way as a particular wireless computer network, there are
certain constraints on the sensors which require deployment of efficient routing
protocols in the sensor networks. Due to certain constraints of the sensor nodes it is
mandatory to have specialized protocols for sensor networks. The focus of this work
is to highlight the advantages of a routing protocol for sensor networks based upon
MTE (minimum transmission energy) routing.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks iii
4. Table of Contents
Acknowledgements........................................................................................................ii
Abstract.........................................................................................................................iii
Table of Contents..........................................................................................................iv
Chapter 1........................................................................................................................1
Introduction....................................................................................................................1
1.1 Microsensor Networks: An Overview............................................................2
1.2 Sensor Node...................................................................................................2
1.3 Applications of Sensor Networks...................................................................2
1.4 Driving Factors for Specialized Protocols.....................................................2
1.5 Protocol Design Goals....................................................................................3
1.6 Existing Routing Protocols............................................................................3
1.6.1 Flooding Based Approaches...................................................................3
1.6.2 Gradient Based Approaches...................................................................4
1.6.3 Clustering and Cellular Based Approaches............................................4
1.6.4 Geographic Routing...............................................................................4
1.6.5 Energy Aware Approaches.....................................................................4
Chapter 2........................................................................................................................5
The Algorithm................................................................................................................5
2.1 Existing Routing Protocols............................................................................6
2.2 Objectives.......................................................................................................6
2.3 Description of the Algorithm.........................................................................6
2.3.1 Pre-requisites/Assumptions....................................................................6
2.3.2 The Algorithm........................................................................................7
2.3.3 Path Retransmissions.............................................................................7
2.3.4 Data Fusion and Compression...............................................................7
Chapter 3........................................................................................................................9
The Simulator.................................................................................................................9
3.1 Description of the Algorithm.......................................................................10
3.2 Code Snippets...............................................................................................10
3.1.1 Send Join Message Procedure..............................................................11
3.1.2 Send Joining Message Procedure.........................................................11
3.1.3 Send Leaving Message Procedure........................................................11
3.1.4 Send Application Message Procedure..................................................11
3.1.5 Receive Join Message Procedure.........................................................12
3.1.6 Receive Joining Message Procedure....................................................14
3.1.7 Receive Leaving Message Procedure...................................................14
3.1.8 Receive Application Message Procedure.............................................14
3.1.9 Message Transmitter Procedure...........................................................15
3.1.10 Message Receiver Procedure...............................................................15
3.3 Simulator’s Link Layer Protocol..................................................................15
3.4 Network Topologies.....................................................................................15
3.4.1 Grid Topology......................................................................................16
3.4.2 Circular Topology.................................................................................16
3.4.3 Random Topology................................................................................17
3.5 First Order Radio Model..............................................................................18
Chapter 4......................................................................................................................20
Analysis and Results....................................................................................................20
4.1 Methodology................................................................................................21
Implementation and Evaluation of a Routing Algorithm for Sensor Networks iv
5. 4.2 The Grid Topology.......................................................................................21
4.3 The Circular Topology.................................................................................21
4.4 The Random Topology.................................................................................21
References....................................................................................................................22
Implementation and Evaluation of a Routing Algorithm for Sensor Networks v
7. 1.1 Micro-sensor Networks: An Overview
A typical sensor network is a wireless network of low cost. It consists of densely
deployed, untethered sensor nodes. The sensor nodes are deployed in an ad hoc manner;
close to the phenomena to be sensed. Sensor networks generally have a limited lifetime.
In order for sensor nodes of the sensor networks to be able to communicate with each
other, the sensor nodes have to be equipped with an appropriate routing protocol. A sensor
network, like any wireless network, uses CSMA/CA at the data link layer for acquiring its
share of the medium. So we do not have any differences between a sensor network and a
wireless computer network at the MAC layer. It is only at the upper layers where
differences between sensor networks and wireless computer networks arise. These
differences arise due to the nature of the small-sized sensor nodes.
1.2 Sensor Node
As discussed earlier, a sensor network comprises of sensor nodes1
. The size of a
sensor node generally varies between the sizes of a typical match box to that of a dime. A
sensor node is equipped with a MEMS2
sensor. The sensors can be of various types. Some
of the more well known types of MEMS sensors are seismic, light, temperature, acoustic,
stress etc. A temperature sensor, for instance, measures the ambient temperature in terms
of an electric signal. A sensor node further has a small power aware CPU. The CPU has
low computation power. The computation power of a particular CPU is of a few MHz.
And it is a 8-bit processor. Similarly a sensor node has 128 kilobytes of on-board flash
memory to hold the program and 512 kilo bytes of flash memory to hold data. A sensor
node has a small embedded operating system which is used to operate a sensor node. Tiny
OS is one example of operating systems in vogue for sensor nodes. Tiny OS is built
normally on a UNIX like platform using Java. A sensor node also has a low power
communication transceiver which can transmit approximately 40,000 bits per second. It
has a range of a few hundred feet. In order to operate the whole sensor node, it is also
equipped with a small battery power source. The limited battery power is a constraint
which determines the effective life time of a sensor node. In order to increase the life of a
sensor node it is required to have a robust and power efficient routing algorithm at the
network layer. So by using a power efficient routing algorithm the life of a sensor node
can be extended to almost 10 years.
1.3 Applications of Sensor Networks
Before going in to any further details about sensor networks it will be worthwhile
to discuss some of the applications of sensor networks. The applications of sensor
networks are numerous ranging from deploying a network in ones home to monitor
different activities to deploying a network for surveillance or guarding a particular area.
Some of the other more peculiar applications of sensor networks are as follows.
1.4 Driving Factors for Specialized Protocols
The main driving factors for specialized protocols for sensor networks arise due to
the inherent features of sensor nodes. The foremost of these is the limited energy
1
Sensor nodes have been named differently by different vendors. For instance, they are called as motes by
some and beans by others.
2
Micro-electromechanical systems.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 2
8. resources of sensor nodes. Limited processing power of sensor nodes and storage is
another reason to have specialized protocols.
Unreliable communication channels due to battery depletion and harsh
environment is another driving factor to have specialized protocols. All these factors
combined together require to have energy efficient and yet robust protocols for sensor
networks.
1.5 Protocol Design Goals
In light of the factors discussed in the previous section the following protocol
design goals apply to sensor networks.
Low Energy Consumption
Protocol should be designed so as to reduce the overall energy consumption of a
sensor node for both communication and computation. On average 3000 instructions
are executed for cost of sending 100 bit through a distance of 100m by a sensor node.
This implies to have a low communication between sensor nodes. Low energy
consumption can thus be achieved by minimizing individual node responsibility.
Traffic spreading and load balancing can also be used to decrease the energy
consumption. Similarly shutting down node when possible is also a way to reduce
energy consumption.
Robustness
While designing the protocol the robustness of the network should be taken into
consideration. The protocol should be able to adapt to unpredictable environment
without intervention.
Scalable
The protocol should be scalable in the sense that it should rely on localized algorithms
instead of centralized ones.
Low Latency
The protocol must meet application latency and accuracy requirements.
Small Footprint
The protocol must be able to run on hardware with severe memory and computational
power constraints.
1.6 Existing Routing Protocols
Presently there are various approaches for developing routing protocols for sensor
networks. These approaches are listed below followed by brief description of these
approaches.
i. Flooding based approaches.
ii. Gradient based approaches.
iii. Clustering and cellular.
iv. Geographic routing.
v. Energy aware routing.
1.6.1 Flooding Based Approaches
The basic idea behind flooding based approaches is that if a sensor node has to
send data to a particular destination, it broadcasts the data into the medium. All the nodes
that receive this data further broadcast it. In this way an effort is done so that the data
ultimately reaches the destination. Although this technique works well, it has some
serious consequences for the intermediate sensor nodes. The intermediate sensor nodes
have to do a lot of redundant retransmissions. And the data transmitted by a node once
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 3
9. may reach the same node again after getting transmitted through various nodes. These
unnecessary retransmissions lead to earlier battery power depletion of the nodes. So
flooding based routing is simplest of all the approaches but it does not fulfill the design
goals discussed in the previous section.
1.6.2 Gradient Based Approaches
A node requests data by sending interests for named data in directed diffusion. Interest
propagation leaves traces (or direction state) so that data, which match the interest, can be
drawn toward that node. Intermediate nodes can process or process or direct data and
interests using application knowledge to conserve system resources [4].
1.6.3 Clustering and Cellular Based Approaches
The LEACH3
algorithm is an example of cluster based approaches. In LEACH
nodes elect themselves to be cluster heads at the beginning of each round based on a
probability function. And localized coordination between sensor nodes is used for the
cluster setup phase. Cluster heads are randomly rotated to increase network lifetime.
Members of a cluster communicate with cluster heads using TDMA MAC. Apart from
sending data, data aggregation is done at cluster heads so as to reduce the overall
communication. Cluster heads communicate directly with the base station.
Advantages of LEACH
Load Balancing: -
It balances energy among nodes and allows nodes to shut down radios.
Low Latency: -
The data reaches the user in only two hops.
Straightforward: -
Data aggregation is done at cluster head and then it is sent to user.
Scalability: -
The algorithm takes a distributed hierarchical approach by forming clusters and
cluster heads.
Disadvantages of LEACH
Cluster head formation is a problem.
Cluster head selection is questionable in the sense as to which nodes should be
chosen as cluster heads.
Since the cluster heads send the aggregated data to the user directly, the algorithm
assumes that all nodes are capable of doing long range transmissions.
1.6.4 Geographic Routing
GEAR4
is an example of geographic routing. It is based on a greedy geographic
routing technique. It uses a cost function based on destination location and neighbor node
energies used to determine next hops.
1.6.5 Energy Aware Approaches
LEACH can once again be quoted as an example of energy aware routing
approaches it has been discussed in section 1.6.3 in considerable detail.
3
Low energy adaptive clustering hierarchy.
4
Geographic and energy aware routing.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 4
11. 2.1 Existing Routing Protocols
At present a lot of work is being done in terms of developing energy-efficient routing
protocols for sensor networks. Some examples of these protocols are, LEACH and
PEGASIS5
. LEACH achieves low energy constraints by forming clusters among the
sensor nodes and cluster heads are chosen to forward the data of the cluster nodes to the
base station. Additional energy saving in cluster heads is achieved by rotating cluster
heads so that an individual cluster head’s battery does not dry out quickly. But an
apparent drawback of this approach is that if cluster head’s are located far apart from the
base station then they have to transmit at longer distances, which comes at an expense of
energy. Similarly, in a very large network it might become impractical to deploy this
technique due to the larger distances between cluster heads and base station. PEGASIS
tries to resolve this issue by using a technique based upon multi-hop routing. In this
technique sensor nodes transmit their data to their close neighbors and take turns being
leader for transmission to the Base Station. Further energy saving is achieved by data
fusion, as is done in LEACH.
2.2 Objectives
It is thought that further energy saving for sensor nodes can be done by designing
a good routing algorithm. The goal of this project is to develop a routing algorithm based
on MTE6
routing in which a node transmits its data to its parent. A parent can be thought
of to be a cluster head. The algorithm initially determines the loop-free shortest paths for
all sensor nodes to the base station as a first priority. Load balancing among the peer
nodes comes as a second priority. To reduce the communication overhead data fusion
shall be done in a way that nodes send their data fused with the data of their children to
their parents. In this per node communication over head shall be reduced.
2.3 Description of the Algorithm
2.3.1 Pre-requisites/Assumptions
All the sensor nodes have same transmission ranges. The base station has the same
transmission range as that of the sensor nodes. It is assumed that every sensor node lies
within the transmission range(s) of some sensor node(s). The transmission ranges of the
sensor nodes are set up prior to setting up the network. Initially all the sensor nodes are
sleeping. Every sensor node including the base station has a local routing data structure
which includes the following entries.
Distance to root.
Min-power of the path to root.
Parent’s ID.
Number of children.
Relative distances of the sensor nodes from the base station are used as MAC7
addresses of the sensor nodes. The reason for it is that in certain scenarios it is important
to know the geographical position of a sensor node in a network.
5
Power Efficient Gathering in Sensor Information Systems.
6
Minimum transmission energy.
7
Medium access control.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 6
12. 2.3.2 The Algorithm
1. The base station broad casts a join message with the distance to root equal to zero,
and the min-Power of the path to root (equal to remaining power of the base station).
2. All the nodes that listen to this message calculate their respective distances from the
base station.
3. Only the nodes whose distances from the base station are less than the transmission
range of the nodes are eligible for becoming children of the node (base station in this
case).
4. The nodes which fulfill the criteria in step 3 send a joining message to the base station
and update their parent’s ID to be the MAC address of the base station, and become
children of the base station. They also update their distance to root field; to be equal to
one in this case. The min-Power of the path to root field is also updated; the min-
power of the path to root is equal to the minimum of the min-Power of the path to root
of the parent (received in the join message) and the remaining power of the node.
The base station, upon receiving the individual messages, updates its number of
children field.
5. All the nodes which become the children in the previous step are now eligible for
becoming parents for the rest of the nodes in the network and broadcast join
messages. The nodes which have become children of some node are also eligible to
send the application messages to the base station.
6. The nodes which receive this join message do one of the following.
a) The undecided nodes repeat steps 4 and 5 for choosing a parent.
b) Every decided node (which is already a child of some node) does the following.
i. It checks to fulfill the criteria in step 3.
ii. If it fulfills the criteria in step 3 it compares its “cost to root” to the “cost to
root + 1” of the join message.
iii. If the latter is less than or equal to the former value, it compares its min-Power
of the path to root to the min-Power of the path to root of the join message.
iv. If the latter turns out to be strictly less than the former, then it sends a joining
message to the node which sent the join message and sends a leaving message
to the former parent. Else, it does nothing and sticks to the former parent
quietly.
v. A parent node which receives leaving message decrements its number of
children by one.
7. In this way, the routing information propagates to the whole network. By choosing
parents with least distance to root, the algorithm ensures that every node has a loop-
free shortest path to the root. By choosing a parent maximum min-Power of the path
to root the algorithm tries to ensure that load is balanced among all the nodes equally
and that all that all the nodes in the network consume their available energy at the
same rate.
2.3.3 Path Retransmissions
Apart from regular retransmissions of the join messages, a join message shall be
sent whenever:
i. The distance to root value of a node changes.
ii. The min-Power of the path to root changes.
2.3.4 Data Fusion and Compression
Instead of sending individual data packets of children to the root a sensor node can
wait for data to arrive from all of its children. The parent can then fuse that data together
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 7
13. along with its own data and send it one step above (to its parent). In this way a sensor
node can save on a lot of communication energy. A node has to receive C8
packets from
its children and transmits only one packet to its parent.
Certain algorithms such as [2] and [3] use certain compression techniques9
on the
data to reduce the communication overhead. One of the objectives of this work is to find
out the impact of data compression on the over all system life time.
8
Where C is the number of children of a particular node.
9
Compression technique is not used in this work.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 8
15. 3.1 Description of the Algorithm
Figure 1 shows the software class diagram of the simulator.
Figure 1: - Class diagram of the Simulator
3.2 Code Snippets
This section shows code snippets of various functions of the simulator software
followed by a brief description of them. It is worth repeating here that MAC addresses in
this simulator are set on the basis of relative x-y coordinates of the sensor nodes with
respect to the network.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 10
16. 3.1.1 Send Join Message Procedure
public String sendJoinMessage()
{
double temp;
int hps;
if(this.PATH_POWER<this.battery.BATTERYPOWER)
temp=this.PATH_POWER;
else
temp=this.battery.BATTERYPOWER;
if(this.battery.BATTERYPOWER<0.05)
hps=1000;
else
hps=this.HOP_COUNT;
return this.MAC_X.ToString()+";" +this.MAC_Y.ToString()+
";"+"10000"+";"+"10000"+";"+"1"+";"+hps.ToString()
+";"+temp.ToString()+";"+this.PIXEL_NUMBER_X.ToString()
+";"+this.PIXEL_NUMBER_Y.ToString();
}
3.1.2 Send Joining Message Procedure
The send message first calculates the min-Path power of the path with the
remaining battery power of the sensor node. Which ever of the above values is less is set
to a variable named “temp”. This value is advertised as the min-Power of the path for the
potential children. Similarly if the battery power (energy) of the node falls below a certain
threshold10
then the hop count to be advertised is incremented by one.
public String sendJoiningMessage()
{
return this.MAC_X.ToString()+";"+this.MAC_Y.ToString()+";"+
this.PARENT_MAC_X.ToString()+";"+this.PARENT_MAC_Y.ToString()
+";"+"2";
}
Joining message is sent when a node wants to associate itself to another node as a
child. The joining message only contains the source and destination MAC addresses.
3.1.3 Send Leaving Message Procedure
public String sendLeavingMessage()
{
return this.MAC_X.ToString()+";"+this.MAC_Y.ToString()+";"+
this.OLD_PARENT_MAC_X.ToString()
+";"+this.OLD_PARENT_MAC_Y.ToString()+";"+"3";
}
When ever a node wants to detach itself from another node, it sends a leaving
message to its old parent. The leaving message comprises of the source and destination
MAC addresses. The destination in this case is the old parent of the node from which it
wants to detach.
3.1.4 Send Application Message Procedure
public String sendApplicationMessage()
{
String str;
int MsgLength=2000;
if(this.receivedApplicationMessages!=null)
{
10
Threshold value is set as 0.05 Joules in this case.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 11
17. String [] toks=this.receivedApplicationMessages.Split(';');
MsgLength+=int.Parse(toks[5]);
}
str=this.MAC_X.ToString()+";"+this.MAC_Y.ToString()
+";"+this.PARENT_MAC_X.ToString()+";"+this.PARENT_MAC_Y.ToString()
+";"+"4"+";"+MsgLength.ToString()
+";"+this.receivedApplicationMessages;
return str;
}
An application message is only sent once a node has received greater that or equal
to amount of application messages from its children. An application message has an
additional field of data length. The reason is that application messages vary in size as
compared with other messages. This procedure initially sets the message length
(MsgLength) to 2000. It then checks whether it has received any application messages or
not. If it has received any application messages it extracts the size of the message from
the sixth field of the received message and adds it to the MsgLength field. The
MsgLength is set again as the sixth field of the application message and the application
message is sent to the parent of the node along with the messages received messages from
the children fused with this message.
3.1.5 Receive Join Message Procedure
public string receiveJoinMessage(string Msg)//returns nothing
{
String []tokens =Msg.Split(';');
switch(this.joinStatus)
{
case false:
{
this.PARENT_MAC_X=float.Parse(tokens[0]);
this.PARENT_MAC_Y=float.Parse(tokens[1]);
this.PARENT_PIXEL_NUMBER_X=int.Parse(tokens[7]);
this.PARENT_PIXEL_NUMBER_Y=int.Parse(tokens[8]);
this.HOP_COUNT=int.Parse(tokens[5])+1;
this.PATH_POWER=double.Parse(tokens[6]);
this.JOINSTATUS=true;
this.nodeState=2;
break;
}
case true:
{
if(int.Parse(tokens[5])<this.HOP_COUNT-1)
{
this.OLD_PARENT_MAC_X=this.PARENT_MAC_X;
this.OLD_PARENT_MAC_Y=this.PARENT_MAC_Y;
this.PARENT_MAC_X=float.Parse(tokens[0]);
this.PARENT_MAC_Y=float.Parse(tokens[1]);
this.PARENT_PIXEL_NUMBER_X=int.Parse(tokens[7]);
this.PARENT_PIXEL_NUMBER_Y=int.Parse(tokens[8]);
this.HOP_COUNT=int.Parse(tokens[5])+1;
this.PATH_POWER=double.Parse(tokens[6]);
this.nodeState=2;
}
else if(int.Parse(tokens[5])==this.HOP_COUNT-1 &&
double.Parse(tokens[6])>this.PATH_POWER)
{
this.OLD_PARENT_MAC_X=this.PARENT_MAC_X;
this.OLD_PARENT_MAC_Y=this.PARENT_MAC_Y;
this.PARENT_MAC_X=float.Parse(tokens[0]);
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 12
18. this.PARENT_MAC_Y=float.Parse(tokens[1]);
this.PARENT_PIXEL_NUMBER_X=int.Parse(tokens[7]);
this.PARENT_PIXEL_NUMBER_Y=int.Parse(tokens[8]);
this.HOP_COUNT=int.Parse(tokens[5])+1;
this.PATH_POWER=double.Parse(tokens[6]);
this.nodeState=2;
}
else if(float.Parse(tokens[0])==this.p_mac_x &&
float.Parse(tokens[1])==this.p_mac_y)//if the node gets a
message from its own parent then it updates the following
fields
{
this.OLD_PARENT_MAC_X=this.PARENT_MAC_X;
this.OLD_PARENT_MAC_Y=this.PARENT_MAC_Y;
this.PARENT_MAC_X=float.Parse(tokens[0]);
this.PARENT_MAC_Y=float.Parse(tokens[1]);
this.PARENT_PIXEL_NUMBER_X=int.Parse(tokens[7]);
this.PARENT_PIXEL_NUMBER_Y=int.Parse(tokens[8]);
this.HOP_COUNT=int.Parse(tokens[5])+1;
this.PATH_POWER=double.Parse(tokens[6]);
this.nodeState=4;
}
break;
}
}
return Msg;
}
Upon receiving a join message the node checks for the join status of the node i.e.
whether a node has already joined any node as a child or not. If the join status is false (i.e.
the node has not joined any other node as a child), then the node takes the following
decision.
a. It sets the parent MAC address as the MAC address of the sender of the join
message.
b. It adds one to the sixth field11
of the received join message and sets it as the hop
count of itself.
c. It sets the value of the power of the path to be equal to the seventh field of the
received join message.
d. It sets the join status value to be true; as the node has now become a child of the
node from whom it received the join message.
e. And it sets the value of the node state attribute to 212
.
If the join status of the node is already true (i.e. the node is already a child of some node)
then it first checks for the following conditions and takes corresponding actions.
i. It checks that the value in the sixth field of the join message is strictly less than
hop count of the node minus one. If so it sets the parent’s MAC address as the old
parent’s MAC address and updates the values of the rest of the attributes as a, b, c
and e as described above.
ii. If the condition in ‘i’ above is not satisfied it checks whether the value in the sixth
field of the join message is equal to hop count of the node minus one and that the
value in the seventh field13
of the join message is greater than the value of the
power of the path attribute. If the condition is satisfied it sets the parent’s MAC
11
The sixth field of the join message contains the hop count value of the node which sent the join message.
12
Node state attribute is discussed in a greater detail in a later section.
13
The seventh field of the join message contains the power of the path value advertised by the node which
sent the join message.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 13
19. address as the old parent’s MAC address and updates the values of the rest of the
attributes as a, b, c and e as described above.
iii. If both conditions ‘i’ and ‘ii’ are not satisfied then it checks that whether the
message has been sent by the actual parent itself. If so it updates the values of the
rest of the attributes as a, b, c and e as described above.
3.1.6 Receive Joining Message Procedure
public string receiveJoiningMessage(string Msg)
{
this.NUM_CHILDREN++;
return Msg;
}
Upon receiving a joining message from one of its children a node simply
increments its number of children count by one.
3.1.7 Receive Leaving Message Procedure
public string receiveLeavingMessage(string Msg)
{
this.NUM_CHILDREN--;
return Msg;
}
Similarly upon receiving a leaving message from one of its previous (detached)
children a node simply decrements its number of children count by one.
3.1.8 Receive Application Message Procedure
public string receiveApplicationMessage(string Msg)
{
String []str1=Msg.Split(';');
if(this.receivedApplicationMessages!=null)
{
String []str2=this.receivedApplicationMessages.Split(';');
String str3=this.receivedApplicationMessages;
int bits1, bits2;
bits1=int.Parse(str1[5]);
bits2=int.Parse(str2[5]);
bits1+=bits2;
this.receivedApplicationMessagesCount++;
int i=0;
this.receivedApplicationMessages=null;
foreach(string tok in str1)
{
if(i!=5)
{
this.receivedApplicationMessages+=tok;
this.receivedApplicationMessages+=";";
}
else
{
this.receivedApplicationMessages+=bits1.ToString();
this.receivedApplicationMessages+=";";
}
i++;
}
}
this.receivedApplicationMessages+=Msg;
return Msg;
}
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 14
20. The receive application message procedure receives an application message and
appends it to the already received messages. It then increments the received messages
count by one. It also updates the number of bits received in the sixth field of the first
received message.
3.1.9 Message Transmitter Procedure
The message transmitter procedure sends messages to neighboring nodes
depending upon the node state value of the sensor node. Remember that apart from the
base station a sensor node is only eligible to send a message when it has become a
descendant of some node. Initially the node state of all nodes is ‘0’. If the node state of a
node is ‘1’, it broadcasts a join message to its neighbors and sets the node state to ‘4’. If
the node state of a node becomes ‘2’, it sends joining message to its parent and sets the
node state to ‘4’. And if the node was already a child of some other node before this, it
needs to send a leaving message to its old parent. So it sets the node state to ‘3’.
Otherwise it sets the node state to ‘4’. If the node state of a node is ‘3’, it sends a leaving
message to its parent and sets the node state to ‘4’. If the node state of the message is ‘4’,
it checks whether the node has received greater than or equal to amount of application
messages from its children or not. If so, it sends the fused together application messages
to its parent and sets the node state to 1. The message transmitter procedure also adjusts
the remaining battery energy upon transmitting a message.
3.1.10 Message Receiver Procedure
A sensor node can receive any type of message at any time. If the base station
receives any message it sets the node state to ‘1’. Similarly if any other node apart from
the base station receives a message it sets the node state to ‘4’. Like message transmitter
procedure, message receiver procedure also adjusts the remaining battery energy of the
node.
3.3 Simulator’s Link Layer Protocol
The link layer protocol of the simulator has been made by following the IEEE
802.11 standard to some extent. Every node writes its messages on a message list. A
message remains on the message board for one time slot. Before sending a message (i.e.
writing a message on the message list) a node checks whether a message has been sent for
it on the message list. If so, the node quietly accepts a message. The transmitter and
receiver nodes render themselves and their neighbors ineligible for transmitting messages
in that particular time slot. If there is no message for a node on the message list and the
node is also eligible for transmitting, it transmits its message depending upon its node
state. In this way the sensor node implements parts of CSMA/CA and resolves the hidden
node problem too.
3.4 Network Topologies
The simulator has a graphical user interface having a panel of size 790 x 600
pixels. All the sensor nodes in the network are represented by round shaped bitmaps of
size 7 x 7 pixels each. The transmission range as shown on the GUI is fixed to 50 pixels.
Similarly, the inter node distance as shown on the GUI varies from 35 to 45 pixels. While
drawing a particular network topology, the MAC addresses are calculated by multiplying
the position of the node on the GUI with the ratio of transmission range14
to the inter node
distance. By doing so, a mapping is created between the actual size of the network and the
14
Transmission range is given as input by the user initially while setting the network parameters.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 15
21. size of the network that appears on screen. The subsections below describe how various
topologies are drawn on the network.
3.4.1 Grid Topology
In this topology all the nodes are equidistant from each other and form a square
grid of sensor nodes. The source code for drawing the grid topology is shown below.
SensorNode tmp;
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
oGraphics.Clear(Color.AliceBlue);
tmp=this.headNode;
this.tmpRMsg=this.headRMsg;
this.headNode.resetNodeAttributes(true);
int X=(int)((float)this.interNodeDistance*0.7), Y=(int)
((float)this.interNodeDistance*0.7);
int j=1;
for(int i=0;i<this.numNodes;i++)
{
if(X>=(this.panel1.Width-2*this.interNodeDistance))
{
j=1;
Y=Y+(int)((float)this.interNodeDistance*0.9);
}
oGraphics.DrawImage(tmp.IMG,X=j*(int)
((float)this.interNodeDistance*0.9),Y,7,7);
tmp.PIXEL_NUMBER_X=X;
tmp.PIXEL_NUMBER_Y=Y;
tmp.MAC_X=((float)tmp.PIXEL_NUMBER_X*(this.xmissionRange/
(float)this.interNodeDistance));
tmp.MAC_Y=((float)tmp.PIXEL_NUMBER_Y*(this.xmissionRange/
(float)this.interNodeDistance));
this.tmpRMsg.MAC_X=tmp.MAC_X;
this.tmpRMsg.MAC_Y=tmp.MAC_Y;
this.tmpRMsg.NODERECEIVEDMESSAGE=false;
tmp=tmp.Next;
this.tmpRMsg=this.tmpRMsg.Next;
tmp.resetNodeAttributes(false);
j++;
}
oGraphics.Dispose();
this.panel1.Invalidate();
3.4.2 Circular Topology
In this topology the sensor nodes are drawn in a hexagonal fashion on the
network. It is called circular because every hexagon has a node in the centre of its face
and has six other nodes surrounding it. These six nodes are equidistant from each other
and the central node as well. The source code for drawing the grid topology is shown
below.
SensorNode tmp;
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
oGraphics.Clear(Color.AliceBlue);
tmp=this.headNode;
this.headNode.resetNodeAttributes(true);
int Xi=(int)(this.interNodeDistance*0.9), Y=(int)
(this.interNodeDistance*0.9)/2;
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 16
22. int Xj=(int)Math.Sqrt(3*Xi*Xi/4)*2;
int X=Xi;
double j=1.5;
for(int i=0;i<this.numNodes;i++)
{
if(X>=(this.panel1.Width-2*(int)this.interNodeDistance))
{
if(j%1==0)
j=1.5;
else
j=1;
Y=Y+(int)(this.interNodeDistance*0.9)/2;
}
oGraphics.DrawImage(tmp.IMG,X=(int)(j*(double)Xj),Y,7,7);
tmp.PIXEL_NUMBER_X=X;
tmp.PIXEL_NUMBER_Y=Y;
tmp.MAC_X=((float)tmp.PIXEL_NUMBER_X*(this.xmissionRange/
(float)this.interNodeDistance));
tmp.MAC_Y=((float)tmp.PIXEL_NUMBER_Y*(this.xmissionRange/
(float)this.interNodeDistance));
tmp=tmp.Next;
tmp.resetNodeAttributes(false);
j=j+1;
}
oGraphics.Dispose();
this.panel1.Invalidate();
3.4.3 Random Topology
While drawing the random topology the simulator software ensures that every
node remains within 70 to 90 percent of the transmission range of some sensor node. The
positions of the nodes on the GUI are generated randomly and similarly MAC addresses
are calculated based upon these positions. The source code for drawing the grid topology
is shown below.
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
myPen.Color=Color.Red;
myLine.Color=Color.Gray;
this.temp=this.headNode;
oGraphics.Clear(Color.AliceBlue);
for(int i=0;i<this.numNodes;i++)
{
this.temp.PIXEL_NUMBER_X=0;
this.temp.PIXEL_NUMBER_Y=0;
this.temp.PARENT_PIXEL_NUMBER_X=0;
this.temp.PARENT_PIXEL_NUMBER_Y=0;
this.temp=this.temp.Next;
}
this.headNode.resetNodeAttributes(true);
this.temp=this.headNode.Next;
Random rnd=new Random();
this.headNode.PIXEL_NUMBER_X=rnd.Next(this.interNodeDistance,
this.panel1.Width-2*this.interNodeDistance);
this.headNode.PIXEL_NUMBER_Y=rnd.Next(this.interNodeDistance,
this.panel1.Height-2*this.interNodeDistance);
this.headNode.MAC_X=((float)this.headNode.PIXEL_NUMBER_X*(this.xmissionR
ange/(float)this.interNodeDistance));
this.headNode.MAC_Y=((float)this.headNode.PIXEL_NUMBER_Y*(this.xmissionR
ange/(float)this.interNodeDistance));
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 17
23. oGraphics.DrawImage(this.headNode.IMG,this.headNode.PIXEL_NUMBER_X,
this.headNode.PIXEL_NUMBER_Y,7,7);
for(int i=0;i<this.numNodes-1;i++)
{
int X1, Y1, X2, Y2, dist;
bool flag1=true, flag2=false;//
SensorNode tmp=this.headNode;
X2=rnd.Next(this.interNodeDistance,this.panel1.Width-
2*this.interNodeDistance);
Y2=rnd.Next(this.interNodeDistance,this.panel1.Height-
2*this.interNodeDistance);
for(int j=0;j<this.numNodes;j++)
{
if(tmp.PIXEL_NUMBER_X!=0 && tmp.PIXEL_NUMBER_Y!=0)
{
X1=tmp.PIXEL_NUMBER_X;
Y1=tmp.PIXEL_NUMBER_Y;
dist=(int)Math.Sqrt((double)(((X1-X2)*(X1-X2))+((Y1-
Y2)*(Y1-Y2))));
if(dist<this.interNodeDistance*0.7)
flag1=false;//means that the node is too close
if(dist<this.interNodeDistance*0.9)
flag2=true;//means that the node is within the range
of atleast one other node
}
tmp=tmp.Next;
}
if(flag1==true && flag2==true)
{
oGraphics.DrawImage(this.temp.IMG,X2, Y2,7,7);
this.temp.resetNodeAttributes(false);
this.temp.PIXEL_NUMBER_X=X2;
this.temp.PIXEL_NUMBER_Y=Y2;
this.temp.MAC_X=((float)this.temp.PIXEL_NUMBER_X*(this.xmiss
ionRange/(float)this.interNodeDistance));
this.temp.MAC_Y=((float)this.temp.PIXEL_NUMBER_Y*(this.xmiss
ionRange/(float)this.interNodeDistance));
this.temp=this.temp.Next;
}
else
i--;//random number not appropriate so revert back
}
oGraphics.Dispose();
this.panel1.Invalidate();
3.5 Message Header Format
Following table illustrates the message header format used in this simulator.
Source MAC
address (2 Bytes)
Destination MAC
address (2 bytes)
Message Type
(3 bits)
Data
(Variable Size)
Join message has a size of 41 bits. It uses an additional 2 bytes of data which include
the hop count to the base station and battery energy respectively.
Joining message has a size of 35 bits. It does not use any additional data.
Leaving message has a size of 35 bits. It does not use any additional data either.
The application message’s size varies from 2000 bits to a higher number depending
upon the number of messages received by a node n fused together before sending.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 18
24. 3.6 First Order Radio Model
The Simulator uses first order radio model as used in [1]. The characteristics of
this radio model are that it dissipates Eelec = 50 nJ/bit to run the transmitter or receiver
circuitry and έ amp = 100 pJ/bit/m2
for the transmit amplifier. These parameters are slightly
better than the current state-of-the-art in radio design [1]. The radio also assumes an r2
energy loss due to channel transmission. Thus, to transmit a k-bit message a distance d
using this radio model, the radio expends:
ETx (k, d)= ETx – elec(k) + ETx – amp(k, d)
ETx (k, d)= Eelec * k + έ amp * k * d2
(1)
And to receive this message, the radio expends:
ERx(k) = ERx – elec (k)
ERx(k) =Eelec * k (2)
For these parameter values, transmitting and receiving messages are not low cost
operations. Thus, the protocols should try to minimize the inter node distance along with
number of transmit and receive operations for each message.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 19
25. Chapter 4
Analysis and Results
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 20
26. 4.1 Comparison
An analysis of results produced by the simulator is done in this chapter. Results of
various network topologies are compared with each other. The methodology used is
somewhat similar to that used in [1].
One of the main considerations while designing a routing protocol for sensor
networks is to make the protocol energy efficient. Similarly, it is also desirable that all the
sensor nodes consume maximum amount of their energies before the network becomes
ineffective. It is also desirable that all the nodes transmit maximum amount of bits before
the network becomes ineffective.
It is worth mentioning here that every node initially has 0.5 Joules of energy by
default. A network consisting of 100 nodes including base station is used in all
simulations. The performance metric used is the number of bits transmitted over the
system lifetime as a function of transmission range.
Table 1: - Number of bits transmitted by all nodes as a function transmission range.
Transmission
range
Number of bits transmitted
Grid Topology Circular Topology Random Topology
1 115046008 110553061 136736427
2 139449092 75369556 101457706
4 61656822 64286909 79694353
8 94603112 62611798 91002307
16 67881802 86067459 90733277
32 42288533 59118813 50211036
64 18882247 10686965 21746429
Figure 2: - Number of bits transmitted in the system as a function of transmission range. The results
show that random topology does better than rest of the two topologies on average.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 21
27. The results show that random topology does better than rest of the two topologies on
average.
4.2 Comparison with LEACH
The results can be compared to LEACH [1]. One of the metrics used in LEACH is
to calculate the number of rounds15
completed before the first node in the system dies16
. In
LEACH 2000 bits of data is sent to the user (base station) in every round. And in each
round every node sends one frame of data to the user. Using this information, the number
of bits sent to the base station can be calculated. Although it was expected that the
algorithm would do better than LEACH, the results found are not very appreciable. But
the algorithm does perform well than direct transmission, static routing, and hop-by-hop
routing algorithms discussed in [1]. The following table shows the results of this
comparison for networks of 100 meters of diameter.
Table 2: - Number of bits transmitted before the first node dies for a network of 100 meters of
diameter
Routing Algorithm Number of Bits Transmitted
Direct Transmission 21800000
Static Clustering 16000000
Hop-by-hop Routing 1600000
LEACH 186400000
Grid Topology 94603112
Circular Topology 62611798
Random Topology 91002307
It can be seen that the algorithm does better than the above three algorithms but
unfortunately does not do well as compared with LEACH.
4.3 Future Work
I further intend to implement this algorithm on a real simulator such as OpNET or
NS2. Apart from this I also look forward to implementing this algorithm on a real test bed
consisting of sensor nodes.
15
Complete detail of how LEACH calculates the rounds can be read in [1].
16
i.e. when the first node’s battery energy finishes.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 22
29. [1] W. Heinzelman, A. Chandrakasan, and H. Balakrishnan. “Energy-Efficient
communication Protocol for Wireless Microsensor Networks”. In Proceedings of
the Hawaii Conference on System Sciences, Jan. 2000.
[2] J. Kulik, W. Rabiner, and H. Balakrishnan. “Adaptive Protocols for Information
dissemination in Wireless Sensor Networks”. In Proceedings of Mobicom’99,
1999.
[3] Stephanie Lindsey and Cauligi S. Raghavendra. “PEGASIS: Power-Efficient
GAthering in Sensor Information Systems”. Computer Systems Research
Department The Aerospace Corporation. Los Angeles, CA 90009-2957.
[4] Chalermek Intanagonwiwat Directed Diffusion: “An Application-specific and
Data-centric Communication Paradigm for Wireless Sensor Networks”.
Implementation and Evaluation of a Routing Algorithm for Sensor Networks 24