29
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

Thesis

Embed Size (px)

Citation preview

Page 1: Thesis

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 Raja2001-03-0017

Lahore University of Management Sciences

May 30, 2001

Implementation and Evaluation of a Routing Algorithm for Sensor Networks i

Page 2: Thesis

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

Page 3: Thesis

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 eachother through a wireless medium. The amount of sensors in a typical network canvary from a few hundreds to a few thousands of sensors. The sensors can share andpropagate information from one part of the network to the other by using anappropriate routing protocol. The content of information may depend on theapplication and the routing/transport protocol which is deployed on the network. Theapplications of sensor networks are numerous ranging from deploying a network inones home to monitor different activities to deploying a network for surveillance orguarding a particular area. Although the nodes in a particular sensor networkcommunicate in the same way as a particular wireless computer network, there arecertain constraints on the sensors which require deployment of efficient routingprotocols in the sensor networks. Due to certain constraints of the sensor nodes it ismandatory to have specialized protocols for sensor networks. The focus of this workis to highlight the advantages of a routing protocol for sensor networks based uponMTE (minimum transmission energy) routing.

Implementation and Evaluation of a Routing Algorithm for Sensor Networks iii

Page 4: Thesis

Table of ContentsAcknowledgements........................................................................................................iiAbstract.........................................................................................................................iiiTable of Contents..........................................................................................................ivChapter 1........................................................................................................................1Introduction....................................................................................................................1

1.1 Microsensor Networks: An Overview............................................................21.2 Sensor Node...................................................................................................21.3 Applications of Sensor Networks...................................................................21.4 Driving Factors for Specialized Protocols.....................................................21.5 Protocol Design Goals....................................................................................31.6 Existing Routing Protocols............................................................................3

1.6.1 Flooding Based Approaches...................................................................31.6.2 Gradient Based Approaches...................................................................41.6.3 Clustering and Cellular Based Approaches............................................41.6.4 Geographic Routing...............................................................................41.6.5 Energy Aware Approaches.....................................................................4

Chapter 2........................................................................................................................5The Algorithm................................................................................................................5

2.1 Existing Routing Protocols............................................................................62.2 Objectives.......................................................................................................62.3 Description of the Algorithm.........................................................................6

2.3.1 Pre-requisites/Assumptions....................................................................62.3.2 The Algorithm........................................................................................72.3.3 Path Retransmissions.............................................................................72.3.4 Data Fusion and Compression...............................................................7

Chapter 3........................................................................................................................9The Simulator.................................................................................................................9

3.1 Description of the Algorithm.......................................................................103.2 Code Snippets...............................................................................................10

3.1.1 Send Join Message Procedure..............................................................113.1.2 Send Joining Message Procedure.........................................................113.1.3 Send Leaving Message Procedure........................................................113.1.4 Send Application Message Procedure..................................................113.1.5 Receive Join Message Procedure.........................................................123.1.6 Receive Joining Message Procedure....................................................143.1.7 Receive Leaving Message Procedure...................................................143.1.8 Receive Application Message Procedure.............................................143.1.9 Message Transmitter Procedure...........................................................153.1.10 Message Receiver Procedure...............................................................15

3.3 Simulator’s Link Layer Protocol..................................................................153.4 Network Topologies.....................................................................................15

3.4.1 Grid Topology......................................................................................163.4.2 Circular Topology.................................................................................163.4.3 Random Topology................................................................................17

3.5 First Order Radio Model..............................................................................18Chapter 4......................................................................................................................20Analysis and Results....................................................................................................20

4.1 Methodology................................................................................................21

Implementation and Evaluation of a Routing Algorithm for Sensor Networks iv

Page 5: Thesis

4.2 The Grid Topology.......................................................................................214.3 The Circular Topology.................................................................................214.4 The Random Topology.................................................................................21

References....................................................................................................................22

Implementation and Evaluation of a Routing Algorithm for Sensor Networks v

Page 6: Thesis

Chapter 1

Introduction

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 1

Page 7: Thesis

1.1 Micro-sensor Networks: An OverviewA 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 eachother, the sensor nodes have to be equipped with an appropriate routing protocol. A sensornetwork, like any wireless network, uses CSMA/CA at the data link layer for acquiring itsshare of the medium. So we do not have any differences between a sensor network and awireless computer network at the MAC layer. It is only at the upper layers wheredifferences between sensor networks and wireless computer networks arise. Thesedifferences arise due to the nature of the small-sized sensor nodes.

1.2 Sensor NodeAs 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. Asensor node is equipped with a MEMS2 sensor. The sensors can be of various types. Someof 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 termsof an electric signal. A sensor node further has a small power aware CPU. The CPU haslow 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 flashmemory to hold the program and 512 kilo bytes of flash memory to hold data. A sensornode has a small embedded operating system which is used to operate a sensor node. TinyOS is one example of operating systems in vogue for sensor nodes. Tiny OS is builtnormally on a UNIX like platform using Java. A sensor node also has a low powercommunication transceiver which can transmit approximately 40,000 bits per second. Ithas a range of a few hundred feet. In order to operate the whole sensor node, it is alsoequipped with a small battery power source. The limited battery power is a constraintwhich determines the effective life time of a sensor node. In order to increase the life of asensor node it is required to have a robust and power efficient routing algorithm at thenetwork layer. So by using a power efficient routing algorithm the life of a sensor nodecan be extended to almost 10 years.

1.3 Applications of Sensor NetworksBefore 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 sensornetworks are numerous ranging from deploying a network in ones home to monitordifferent 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 ProtocolsThe 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

Page 8: Thesis

resources of sensor nodes. Limited processing power of sensor nodes and storage isanother reason to have specialized protocols.

Unreliable communication channels due to battery depletion and harshenvironment is another driving factor to have specialized protocols. All these factorscombined together require to have energy efficient and yet robust protocols for sensornetworks.

1.5 Protocol Design GoalsIn 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 asensor node for both communication and computation. On average 3000 instructionsare 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 energyconsumption can thus be achieved by minimizing individual node responsibility.Traffic spreading and load balancing can also be used to decrease the energyconsumption. Similarly shutting down node when possible is also a way to reduceenergy consumption.

RobustnessWhile designing the protocol the robustness of the network should be taken intoconsideration. The protocol should be able to adapt to unpredictable environmentwithout intervention.

ScalableThe protocol should be scalable in the sense that it should rely on localized algorithmsinstead of centralized ones.

Low LatencyThe protocol must meet application latency and accuracy requirements.

Small FootprintThe protocol must be able to run on hardware with severe memory and computational power constraints.

1.6 Existing Routing ProtocolsPresently 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 tosend data to a particular destination, it broadcasts the data into the medium. All the nodesthat receive this data further broadcast it. In this way an effort is done so that the dataultimately reaches the destination. Although this technique works well, it has someserious consequences for the intermediate sensor nodes. The intermediate sensor nodeshave 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

Page 9: Thesis

may reach the same node again after getting transmitted through various nodes. Theseunnecessary retransmissions lead to earlier battery power depletion of the nodes. Soflooding based routing is simplest of all the approaches but it does not fulfill the designgoals discussed in the previous section.

1.6.2 Gradient Based ApproachesA node requests data by sending interests for named data in directed diffusion. Interestpropagation leaves traces (or direction state) so that data, which match the interest, can bedrawn toward that node. Intermediate nodes can process or process or direct data andinterests using application knowledge to conserve system resources [4].

1.6.3 Clustering and Cellular Based ApproachesThe 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 aprobability function. And localized coordination between sensor nodes is used for thecluster setup phase. Cluster heads are randomly rotated to increase network lifetime.Members of a cluster communicate with cluster heads using TDMA MAC. Apart fromsending data, data aggregation is done at cluster heads so as to reduce the overallcommunication. 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 andcluster 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 geographicrouting technique. It uses a cost function based on destination location and neighbor nodeenergies used to determine next hops.

1.6.5 Energy Aware Approaches

LEACH can once again be quoted as an example of energy aware routingapproaches 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

Page 10: Thesis

Chapter 2

The Algorithm

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 5

Page 11: Thesis

2.1 Existing Routing ProtocolsAt present a lot of work is being done in terms of developing energy-efficient routingprotocols for sensor networks. Some examples of these protocols are, LEACH andPEGASIS5. LEACH achieves low energy constraints by forming clusters among thesensor nodes and cluster heads are chosen to forward the data of the cluster nodes to thebase station. Additional energy saving in cluster heads is achieved by rotating clusterheads so that an individual cluster head’s battery does not dry out quickly. But anapparent drawback of this approach is that if cluster head’s are located far apart from thebase station then they have to transmit at longer distances, which comes at an expense ofenergy. Similarly, in a very large network it might become impractical to deploy thistechnique due to the larger distances between cluster heads and base station. PEGASIStries to resolve this issue by using a technique based upon multi-hop routing. In thistechnique sensor nodes transmit their data to their close neighbors and take turns beingleader for transmission to the Base Station. Further energy saving is achieved by datafusion, as is done in LEACH.

2.2 ObjectivesIt 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 basedon MTE6 routing in which a node transmits its data to its parent. A parent can be thoughtof to be a cluster head. The algorithm initially determines the loop-free shortest paths forall sensor nodes to the base station as a first priority. Load balancing among the peernodes comes as a second priority. To reduce the communication overhead data fusionshall be done in a way that nodes send their data fused with the data of their children totheir parents. In this per node communication over head shall be reduced.

2.3 Description of the Algorithm

2.3.1 Pre-requisites/AssumptionsAll 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 lieswithin the transmission range(s) of some sensor node(s). The transmission ranges of thesensor nodes are set up prior to setting up the network. Initially all the sensor nodes aresleeping. Every sensor node including the base station has a local routing data structurewhich 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 importantto 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

Page 12: Thesis

2.3.2 The Algorithm1. 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 thiscase).

4. The nodes which fulfill the criteria in step 3 send a joining message to the base stationand update their parent’s ID to be the MAC address of the base station, and becomechildren of the base station. They also update their distance to root field; to be equal toone 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 rootof 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 ofchildren field.

5. All the nodes which become the children in the previous step are now eligible forbecoming parents for the rest of the nodes in the network and broadcast joinmessages. The nodes which have become children of some node are also eligible tosend 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 messageto the former parent. Else, it does nothing and sticks to the former parentquietly.

v. A parent node which receives leaving message decrements its number ofchildren by one.

7. In this way, the routing information propagates to the whole network. By choosingparents 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 pathto root the algorithm tries to ensure that load is balanced among all the nodes equallyand that all that all the nodes in the network consume their available energy at thesame rate.

2.3.3 Path RetransmissionsApart 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 CompressionInstead 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

Page 13: Thesis

along with its own data and send it one step above (to its parent). In this way a sensornode can save on a lot of communication energy. A node has to receive C8 packets fromits children and transmits only one packet to its parent.

Certain algorithms such as [2] and [3] use certain compression techniques9 on thedata to reduce the communication overhead. One of the objectives of this work is to findout 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

Page 14: Thesis

Chapter 3

The Simulator

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 9

Page 15: Thesis

3.1 Description of the AlgorithmFigure 1 shows the software class diagram of the simulator.

Figure 1: - Class diagram of the Simulator

3.2 Code SnippetsThis 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 inthis simulator are set on the basis of relative x-y coordinates of the sensor nodes withrespect to the network.

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 10

Page 16: Thesis

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 theremaining battery power of the sensor node. Which ever of the above values is less is setto a variable named “temp”. This value is advertised as the min-Power of the path for thepotential children. Similarly if the battery power (energy) of the node falls below a certainthreshold10 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 achild. The joining message only contains the source and destination MAC addresses.

3.1.3 Send Leaving Message Procedurepublic 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 leavingmessage to its old parent. The leaving message comprises of the source and destinationMAC addresses. The destination in this case is the old parent of the node from which itwants to detach.

3.1.4 Send Application Message Procedurepublic 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

Page 17: Thesis

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 equalto amount of application messages from its children. An application message has anadditional field of data length. The reason is that application messages vary in size ascompared with other messages. This procedure initially sets the message length(MsgLength) to 2000. It then checks whether it has received any application messages ornot. If it has received any application messages it extracts the size of the message fromthe sixth field of the received message and adds it to the MsgLength field. TheMsgLength is set again as the sixth field of the application message and the applicationmessage is sent to the parent of the node along with the messages received messages fromthe children fused with this message.

3.1.5 Receive Join Message Procedurepublic 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

Page 18: Thesis

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 followingdecision.

a. It sets the parent MAC address as the MAC address of the sender of the joinmessage.

b. It adds one to the sixth field11 of the received join message and sets it as the hopcount of itself.

c. It sets the value of the power of the path to be equal to the seventh field of thereceived join message.

d. It sets the join status value to be true; as the node has now become a child of thenode 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 thanhop count of the node minus one. If so it sets the parent’s MAC address as the oldparent’s MAC address and updates the values of the rest of the attributes as a, b, cand e as described above.

ii. If the condition in ‘i’ above is not satisfied it checks whether the value in the sixthfield of the join message is equal to hop count of the node minus one and that thevalue in the seventh field13 of the join message is greater than the value of thepower 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

Page 19: Thesis

address as the old parent’s MAC address and updates the values of the rest of theattributes as a, b, c and e as described above.

iii. If both conditions ‘i’ and ‘ii’ are not satisfied then it checks that whether themessage has been sent by the actual parent itself. If so it updates the values of therest of the attributes as a, b, c and e as described above.

3.1.6 Receive Joining Message Procedurepublic string receiveJoiningMessage(string Msg){

this.NUM_CHILDREN++;return Msg;

}

Upon receiving a joining message from one of its children a node simplyincrements its number of children count by one.

3.1.7 Receive Leaving Message Procedurepublic 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 Procedurepublic 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

Page 20: Thesis

The receive application message procedure receives an application message andappends it to the already received messages. It then increments the received messagescount by one. It also updates the number of bits received in the sixth field of the firstreceived message.

3.1.9 Message Transmitter ProcedureThe message transmitter procedure sends messages to neighboring nodes

depending upon the node state value of the sensor node. Remember that apart from thebase station a sensor node is only eligible to send a message when it has become adescendant of some node. Initially the node state of all nodes is ‘0’. If the node state of anode is ‘1’, it broadcasts a join message to its neighbors and sets the node state to ‘4’. Ifthe node state of a node becomes ‘2’, it sends joining message to its parent and sets thenode state to ‘4’. And if the node was already a child of some other node before this, itneeds 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 leavingmessage 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 applicationmessages from its children or not. If so, it sends the fused together application messagesto its parent and sets the node state to 1. The message transmitter procedure also adjuststhe 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 fromthe base station receives a message it sets the node state to ‘4’. Like message transmitterprocedure, message receiver procedure also adjusts the remaining battery energy of thenode.

3.3 Simulator’s Link Layer ProtocolThe 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. Amessage 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 forit on the message list. If so, the node quietly accepts a message. The transmitter andreceiver nodes render themselves and their neighbors ineligible for transmitting messagesin that particular time slot. If there is no message for a node on the message list and thenode is also eligible for transmitting, it transmits its message depending upon its nodestate. In this way the sensor node implements parts of CSMA/CA and resolves the hiddennode problem too.

3.4 Network TopologiesThe 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 ofsize 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. Whiledrawing a particular network topology, the MAC addresses are calculated by multiplyingthe position of the node on the GUI with the ratio of transmission range14 to the inter nodedistance. 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

Page 21: Thesis

size of the network that appears on screen. The subsections below describe how varioustopologies are drawn on the network.

3.4.1 Grid TopologyIn 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 TopologyIn 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

Page 22: Thesis

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;

elsej=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 TopologyWhile 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.xmissionRange/(float)this.interNodeDistance));this.headNode.MAC_Y=((float)this.headNode.PIXEL_NUMBER_Y*(this.xmissionRange/(float)this.interNodeDistance));

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 17

Page 23: Thesis

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 closeif(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.xmissionRange/(float)this.interNodeDistance));this.temp.MAC_Y=((float)this.temp.PIXEL_NUMBER_Y*(this.xmissionRange/(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 FormatFollowing 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

Page 24: Thesis

3.6 First Order Radio ModelThe 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 receivercircuitry and έ amp = 100 pJ/bit/m2 for the transmit amplifier. These parameters are slightlybetter 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 dusing 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 costoperations. Thus, the protocols should try to minimize the inter node distance along withnumber of transmit and receive operations for each message.

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 19

Page 25: Thesis

Chapter 4

Analysis and Results

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 20

Page 26: Thesis

4.1 ComparisonAn 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 issomewhat similar to that used in [1].

One of the main considerations while designing a routing protocol for sensornetworks is to make the protocol energy efficient. Similarly, it is also desirable that all thesensor nodes consume maximum amount of their energies before the network becomesineffective. It is also desirable that all the nodes transmit maximum amount of bits beforethe network becomes ineffective.

It is worth mentioning here that every node initially has 0.5 Joules of energy bydefault. A network consisting of 100 nodes including base station is used in allsimulations. The performance metric used is the number of bits transmitted over thesystem lifetime as a function of transmission range.

Table 1: - Number of bits transmitted by all nodes as a function transmission range.

Transmissionrange

Number of bits transmitted

Grid Topology Circular Topology Random Topology1 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

Page 27: Thesis

The results show that random topology does better than rest of the two topologies on average.

4.2 Comparison with LEACHThe 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. InLEACH 2000 bits of data is sent to the user (base station) in every round. And in eachround every node sends one frame of data to the user. Using this information, the numberof bits sent to the base station can be calculated. Although it was expected that thealgorithm would do better than LEACH, the results found are not very appreciable. Butthe algorithm does perform well than direct transmission, static routing, and hop-by-hoprouting algorithms discussed in [1]. The following table shows the results of thiscomparison 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 TransmittedDirect Transmission 21800000Static Clustering 16000000Hop-by-hop Routing 1600000LEACH 186400000Grid Topology 94603112

Circular Topology 62611798

Random Topology 91002307

It can be seen that the algorithm does better than the above three algorithms butunfortunately does not do well as compared with LEACH.

4.3 Future WorkI 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 bedconsisting 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

Page 28: Thesis

References

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 23

Page 29: Thesis

[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-EfficientGAthering in Sensor Information Systems”. Computer Systems ResearchDepartment The Aerospace Corporation. Los Angeles, CA 90009-2957.

[4] Chalermek Intanagonwiwat Directed Diffusion: “An Application-specific andData-centric Communication Paradigm for Wireless Sensor Networks”.

Implementation and Evaluation of a Routing Algorithm for Sensor Networks 24