Research Article Pymote: High Level Python Library...

13
Hindawi Publishing Corporation International Journal of Distributed Sensor Networks Volume 2013, Article ID 797354, 12 pages http://dx.doi.org/10.1155/2013/797354 Research Article Pymote: High Level Python Library for Event-Based Simulation and Evaluation of Distributed Algorithms Damir Arbula and Kristijan Lenac Department of Computer Engineering, Faculty of Engineering, University of Rijeka, 51000 Rijeka, Croatia Correspondence should be addressed to Damir Arbula; [email protected] Received 4 November 2012; Accepted 19 December 2012 Academic Editor: Long Cheng Copyright © 2013 D. Arbula and K. Lenac. is is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. In recent years we have witnessed strong development and widespread use of powerful wirelessly connected platforms, thus the set of the related problems that need to be solved by distributed algorithms is growing rapidly. Some of them present large obstacles in harnessing the full potential of this new technology, so there is an imminent need for a fast and easy evaluation of new ideas and approaches. Simulation is a fundamental part of distributed algorithm design and evaluation process. In this paper, we present a library for event-based simulation and evaluation of distributed algorithms. is library provides a set of simple but powerful tools with a goal to ease virtual setup of a complex system such as a distributed network of communicating entities and to define, simulate, and analyze its behavior. In order to reduce a huge problem space inherent in such systems, our library is using a high level of abstraction. is is made possible by a strict and complete definition of the distributed computing environment. e library is implemented in Python whose simple and expressive syntax provides a possibility of minimal implementations and a mild learning curve. In addition to executing automated simulations or larger experiments, the library fully supports interactive mode along with a step-by-step execution, which can be a very powerful combination. 1. Introduction e evaluation of distributed algorithms calls for adequate simulation and comparison with existing state-of-the-art solutions. Although it seems that this task is straightforward, in practice there are a few issues that need to be handled correctly. Existing simulation environments, like OMNeT++, usually require definition of large set of low level parameters (transmitter frequency, communication protocol, etc.) to simulate the behavior of a system as close to implemen- tation as possible. ere is certainly nothing wrong with that approach but when a problem is defined in a more generic way (i.e., anchor free localization of wireless sensor nodes with ranging capabilities) selection of some of those parameters is not problem related, thus they are highly arbitrary. is can lead to a simulation of a more specific case than needed. Here we present a high level Python library for event- based simulation of distributed algorithms in wireless ad hoc networks. e library allows the user to make imple- mentation of their ideas using Python—a popular, easy to learn, full featured, object oriented programming language. Functionalities provided by the library are implemented without additional layer of abstraction, thus harnessing full power of Python’s native highly expressive syntax. Using the library, users can quickly and accurately define and simulate their algorithms. e library particularly focuses on (1) fast and easy implementation of ideas and approaches at algorithm level without any specification overhead using formally defined distributed computing envi- ronment; (2) support for two different workflows and their seam- less combination: (1) interactive control and step by step execution of simulation with easy introspec- tion and modification of all objects in the runtime environment, and (2) fully automated creation and modification of simulation environment and running multiple experiments in a clean and minimal way using simple Python scripts;

Transcript of Research Article Pymote: High Level Python Library...

Hindawi Publishing CorporationInternational Journal of Distributed Sensor NetworksVolume 2013 Article ID 797354 12 pageshttpdxdoiorg1011552013797354

Research ArticlePymote High Level Python Library for Event-Based Simulationand Evaluation of Distributed Algorithms

Damir Arbula and Kristijan Lenac

Department of Computer Engineering Faculty of Engineering University of Rijeka 51000 Rijeka Croatia

Correspondence should be addressed to Damir Arbula damirarbularitehhr

Received 4 November 2012 Accepted 19 December 2012

Academic Editor Long Cheng

Copyright copy 2013 D Arbula and K Lenac This is an open access article distributed under the Creative Commons AttributionLicense which permits unrestricted use distribution and reproduction in any medium provided the original work is properlycited

In recent years we have witnessed strong development and widespread use of powerful wirelessly connected platforms thus the setof the related problems that need to be solved by distributed algorithms is growing rapidly Some of them present large obstaclesin harnessing the full potential of this new technology so there is an imminent need for a fast and easy evaluation of new ideasand approaches Simulation is a fundamental part of distributed algorithm design and evaluation process In this paper we presenta library for event-based simulation and evaluation of distributed algorithms This library provides a set of simple but powerfultools with a goal to ease virtual setup of a complex system such as a distributed network of communicating entities and to definesimulate and analyze its behavior In order to reduce a huge problem space inherent in such systems our library is using a high levelof abstraction This is made possible by a strict and complete definition of the distributed computing environment The library isimplemented in Python whose simple and expressive syntax provides a possibility of minimal implementations and amild learningcurve In addition to executing automated simulations or larger experiments the library fully supports interactive mode along witha step-by-step execution which can be a very powerful combination

1 Introduction

The evaluation of distributed algorithms calls for adequatesimulation and comparison with existing state-of-the-artsolutions Although it seems that this task is straightforwardin practice there are a few issues that need to be handledcorrectly Existing simulation environments like OMNeT++usually require definition of large set of low level parameters(transmitter frequency communication protocol etc) tosimulate the behavior of a system as close to implemen-tation as possible There is certainly nothing wrong withthat approach but when a problem is defined in a moregeneric way (ie anchor free localization of wireless sensornodes with ranging capabilities) selection of some of thoseparameters is not problem related thus they are highlyarbitraryThis can lead to a simulation of a more specific casethan needed

Here we present a high level Python library for event-based simulation of distributed algorithms in wireless adhoc networks The library allows the user to make imple-mentation of their ideas using Pythonmdasha popular easy to

learn full featured object oriented programming languageFunctionalities provided by the library are implementedwithout additional layer of abstraction thus harnessing fullpower of Pythonrsquos native highly expressive syntax Using thelibrary users can quickly and accurately define and simulatetheir algorithms

The library particularly focuses on

(1) fast and easy implementation of ideas and approachesat algorithm level without any specification overheadusing formally defined distributed computing envi-ronment

(2) support for two different workflows and their seam-less combination (1) interactive control and stepby step execution of simulation with easy introspec-tion and modification of all objects in the runtimeenvironment and (2) fully automated creation andmodification of simulation environment and runningmultiple experiments in a clean and minimal wayusing simple Python scripts

2 International Journal of Distributed Sensor Networks

(3) promoting open source reproducible research thusencouraging its reuse and reevaluation trough com-parisons with new ideas based on easily customizedcriteria

Since the library is built upon a formally defined distributedcomputing environment implementation of specific algo-rithm is a straightforward processThis process is additionallyalleviated by using interactive console and the native Pythondebugger in which all objects are directly accessible for intro-spection and modification

Python is a modular language so advanced usage orextension of basic functionalities is easily available by writingadditional modules and inheriting from the library coreclasses These extensions are encouraged through the opensource developing workflow

In the next section a brief analysis of currently availablesimulators and libraries is given In Section 3 we formallydefine distributed computing environment giving theoreticfoundation and basic principles onwhich this library is basedThis is followed by a short discussion on platform selectiondescription of some implementation details and possibleways of extending the library beyond its current functional-ities Finally in Section 5 there is an example of definitionsimulation and analysis of one of the popular localizationalgorithms using the library in interactive and automatedworkflow

2 Related Work

A large number of simulators have been proposed in literaturein which algorithms for wireless ad hoc networks can beimplemented and studied These simulators have differentdesign goals and largely vary in the level of complexity andincluded features They support different hardware and com-munication layers assumptions focus on different distributednetworks implementations and environments and comewitha different set of tools for modeling analysis and visualiza-tion Classical algorithms include NS-2 OMNeT++ J-SimTOSSIM and others

NS-2 [1] is a discrete event simulator for general networksimulation It is probably the most widely used networksimulator for research NS-2 provides substantial supportfor simulation of TCP routing and multicast protocols overwired and wireless networks It was originally targeted to IPnetworks but extensions [2 3] for wireless sensor networkshave been proposed in the past NS-2 allows for a detailedsimulation tracing and comes with the simulation tool calledNAM (network animator) for later playback Due to a verydetailed packet level simulation the NS-2 simulator is notsuitable for simulation of very large networks made ofthousands of nodes NS-2 has many different distributionsand extensions and a large number of network simulationshave been performed with them However NS-2 has a steeplearning curve and requires considerable effort to repeat thesimulations and compare with the obtained results The coreof the simulator and most of the network protocol modelsare written in C++ while OTcl is used for the definition and

configuration of the simulation environment It is availableunder an open source license

Wireless sensor network simulation can be performedusing Mannasim framework which extends NS-2 by intro-ducing new modules for design development and analysisof different WSN applications The Mannasim frameworkprovides standardized structures for common sensor clusterheads and access point nodes on top of NS-2 In a simulationthese three types of nodes run different algorithms which areimplemented directly in C++

Another simulation platform which is widely used inthe global scientific community is OMNeT++ [4 5] It isan extensible modular component-based C++ simulationlibrary and framework used primarily for building networksimulators OMNeT++ offers extensive simulation librarythat includes support for inputoutput statistics data col-lection graphical presentation of simulation data randomnumber generators and data structures Domain-specificfunctionality such as support for sensor networks wirelessad hoc networks Internet protocols performance model-ing and so forth are provided by model frameworks anddeveloped as independent projects Extensions for real-timesimulation network emulation alternative programminglanguages database integration and other functions existFor the simulation of wireless sensor networks one popularextension is Castalia [6] Its development was motivatedby the desire to provide a realistic channelradio modelingHowever for the development of high level algorithm andstudying of its behavior Castalia is time consuming becauseone has to account for all the details related to specific lowlevel modeling

J-Sim [7] is a general purpose simulator written in Javaaccording to the component-based software paradigm Com-ponents are loosely coupled as each component can bedesigned implemented and tested independently On thetop of the autonomous component architecture a generalizedpacket switched network model defines the generic structureof a node and the generic network components both ofwhichcan then be used as base classes to implement protocols acrossvarious layers J-Sim was initially designed for wired networksimulation but a wireless extension exists which proposes animplementation of the IEEE 80211MAC togetherwith a set ofnetwork and protocol components which facilitates the sim-ulation of wireless networks It supports real-time process-driven simulation

TOSSIM [8] is a platform-specific simulation librarywhich simulates TinyOS [9] motes at the bit level It allowsemulation of system components and modeling of differentnetwork topologies thus providing a realistic setting for mea-surement of the communication costs of algorithms TOSSIMis an open source discrete event simulator which directlycompiles code written for TinyOS to an executable file thatcan be run on standard PC equipment It can run simulationswith a few thousand virtual TinyOS nodes It ships withthe graphical user interface TinyViz that can visualize andinteract with running simulations

For a survey and comparison of these and other simula-tion platforms the reader can refer to [10ndash12]

International Journal of Distributed Sensor Networks 3

One classification [13] divides simulators into threemajorcategories based on the level of complexity

(1) algorithm level(2) packet level and(3) instruction level

Algorithm level simulators focus on the logic data structureand presentation of algorithmsThese simulators do not con-sider detailed communication models and most commonlythey rely on some form of a graph data structure to illustratethe communication between nodes Packet level simulatorsimplement the data link and physical layers in a typical OSInetwork stackHence it is common for this type of simulatorsto include implementations of 80211b or newer MAC proto-cols and radio models that account for propagation fadingcollision noise and wave diffraction Instruction level simu-lators model the CPU execution at the level of instructions oreven cycles They are often regarded as emulators

According to this classification Pymote is an algorithmlevel simulator In comparison to the abovementioned widelyused simulators Pymote does not provide packet level andinstruction level simulation Instead it uses abstract modelsof the communicating entities and the environment thusenabling researcher to focus on a general principles not influ-enced by large amount of implementation details This factmakes it considerably easier to learn and more straightfor-ward to use An additional benefit of such decision is scalingof the simulation environment in a way that can accom-modate large networks Pymote is focused on the designand evaluation of algorithms while also providing toolsfor quick definition of different network structures In theremaining part of this section we describe some of the algo-rithm level simulators that were proposed in the literature

AlgoSensim [14] is a framework used to simulate dis-tributed algorithms It focuses on network specific algorithmslike localization distributed routing flooding and so forthIt is written in Java and uses XML files for configurationTheframework was published as open source in 2006 but hasremained in alpha release since

Shawnrsquos [15] primary design goals are to simulate theeffect caused by a phenomenon not the phenomenon itselfto improve scalability and to support free choice of theimplementation model Instead of performing a completesimulation of the MAC layer including radio propagationproperties such as attenuation collision fading and multi-path propagation Shawn simulates the effects of aMAC layerfor the application like packet loss corruption and delay Inthis way while producing similar effects on the applicationlayer a performance gain is obtained with a more efficientimplementation This additionally enables Shawn to supportlarge-scale network simulation Shawn is written in C++

NetTopo [13] is an integrated framework for simulationand visualization of wireless sensor networks written in JavaIts design is also algorithm-oriented with the goal of rapidprototyping of algorithms however it derives its motivationby the need to study applications which can run partially ina simulation environment and partially in a physical wirelesssensor network testbed NetTopo supports the simulation of

large scale networks and provides a graphical user interfaceto drive the simulation

Sinalgo [16] is another simulation framework for wirelessnetworkswritten in Javawhich does not simulate the differentlayers of the ISO network stack and focuses instead on algo-rithm layer abstraction It offers amessage passing view of thenetwork and can simulate very large networks Sinalgo comeswith a set of available models for node mobility connectivityinitial distribution interference and transmission which auser can extend with his own if necessary The simulation isusually started from the available graphical user interface butfor long-lasting well-defined simulations it can also be startedin batch mode

One important difference of these algorithm level simu-lators with Pymote is the programming language and envi-ronment Pymote leverages Pythonrsquos strengths like ease oflearning and use and faster development than C++ and Javamaking the solutionwell suited for rapid prototyping Furtherdifference is that Pymote naturally supports both interactiveand programmed simulation modes enabling and actuallyfostering quick often intertwined definition and simulationphases By using Pythonrsquos introspection power that is itsability to inspect objects at runtime determine informationabout them and make that information available to the userPymote is able to interactively explore and manage all theentities involved in the simulation

3 Distributed Computing Environment

To design a proper distributed algorithm the environmentin which it performs must be strictly defined Distributedenvironment and restrictions to problem space used in spec-ifications for making Pymote library are taken from [17]Main principles governing algorithm operation in this envi-ronment are described below

Distributed computing environment is composed from aset of computational entities E (in our case wireless nodes)and messages they interchange A node 119909 isin E has the capa-bility to store data in finite local memory119872

119909consisting from

a number of defined registers One of them with specialfunction is the status register that can take values from afinite set of states S Other parts of the node 119909 are CPU andcommunication

Node behavior is reactive It acts only when it detectsone of two possible events (1) arrival of message and (2)spontaneous impulsemdashusually used in random or definednodes at algorithm initiation The action that node performsis a result of its state (in status register) and the event whichin our case is the arrival of message as follows

status times event 997888rarr action (1)Distributed algorithm is defined as a set of rules that associateall possible combinations of states and events with specificactions

The system has homogenous behavior if all nodes runthe same algorithm which simplifies its development andanalysis Since every nonhomogenous behavior can be madehomogeneous as described in [17] all nodes in our libraryare running the same algorithm

4 International Journal of Distributed Sensor Networks

Table 1 Message structure

Field name Data type DescriptionSource Node Sender node instance

Nexthop Node Neighboring node instance that is nexthop in path to destination

Destination Node Destination node instance

Header String Message header defining function andstructure of sent data

Data Dict Any data

There are three types of actions storing and processingdata message transmission and changing the value of statusregister All other actions such as measuring some phenom-ena or relation between nodes can be thought of as a combi-nation of message transmission storing and processing data

Message transmission between nodes is defined as atransfer of finite sequence of bits Simple but generic structureand description of fields in messages used in our library ispresented in Table 1

Every node 119909 can send a message to a set of other nodes119873out(119909) isin E and receive it from set 119873in(119909) isin E Inherentproperty of every node is local orientation which means thata node can distinguish between its neighbors by their uniqueID so for example it can send amessage to a specific neighborwithout sending it to the other neighbors This is utilizedthrough destination field in the message structure

In practice sending and receiving messages are complexoperations liable to failures and spanning through severalcommunication layers with unknown possibly infinite dura-tionWhendesigning distributed algorithms it is very impor-tant to make their performance invariant to communicationfailures and delays

Up to this point all network properties have been definedfor some general case Special properties are called restrictionsbecause algorithms designed under assumption of this prop-erties are restricted and cannot be applied to a more generalunrestricted cases

Current restrictions in our library are as followsBidirectional Links For every node 119909 a set of outgoing andincoming links are identical 119873out(119909) = 119873in(119909) for all 119909 isinE and the nodes that belong to this set are called neighborsof 119909Connectivity In cooperative distributed algorithms it is veryimportant that every node can communicate to all othernodes directly or through intermediate nodesTotal Reliability Every sent message eventually in unknownbut finite time will be received with its content uncorruptedand without any failure occurring

These restrictions are strong but sensible They try tolimit problem space to an application layer only and removeunwanted overspecification by focusing on a generic casesolutions

Nodersquos memory content and information held in it repre-sent its local knowledge If at least one node in a set119882 sube Ehas information 119901 it is defined as implicit knowledge If every

node in a set119882 has the same information then it is explicitknowledge Notion of knowledge is very important since thesole purpose of (distributed) algorithm is improving localknowledge of nodes and implicit and explicit knowledge ofthe network in general

4 Implementation

The Pymote library is based on goals described in Section 1and formalism of the distributed computing environmentstated in Section 3 We proceed with discussion on platformselection and brief description of the implementation of basiclibrary functionalities We conclude with a description ofsome of directions that can be taken to extend them

41 Why Python Python language with included librariesand tools was selected after research and analysis of anumber of existing platforms and frameworks The selectionof Python allows to fulfil the following requirements

(i) easy to learn and well documented(ii) full featured object oriented language Partial or

restricted solutions (ie MATLAB) are bound to havea limit regarding supported object oriented features

(iii) simple and highly expressive As such it keeps thecode clean andminimal making its usage straightfor-ward

(iv) support for interactive mode since this kind of work-flow is especially suitable for experimentation andanalysis IPython [18] is a Python interactive consolethat provides all major functionalities needed forinteractive scientific computing (Figure 1)

(v) introspection features namely easy programmaticinspection of all defined objectrsquos properties

(vi) rich scientific functions library and strong supportfor scientific computing and calculations AlthoughPython is a general purpose language in this field itis very competitive NumPy and SciPy [19] are thefundamental packages for scientific computing inPython They add significant power to the interac-tive Python session by exposing the user to high-level commands and classes needed for all kinds ofscientific data manipulation In addition to these forplotting and general graphical representation of datamatplotlib is a perfect choice

(vii) promote open source reproducible research Pythonis a platform that already promotes similar ideasand that grows with the community of its users anddevelopers

After long and exhaustive usage we have concluded thatPython completely fulfills the requirements

42 Core Classes The implementation philosophy followedDRY (Do not Repeat Yourself) and KISS (Keep It SimpleStupid) principles DRYprinciple states our intention tomakea library that will not rediscover and rewrite already existing

International Journal of Distributed Sensor Networks 5

Python 271 (r27186832 Nov 27 2010 183046) [MSC v1500 32 bit (Intel)] Type copyright credits or license for more information

IPython 0131 -- An enhanced Interactive Python -gt Introduction and overview of IPythons features quickref -gt Quick reference help -gt Pythons own help system object -gt Details about `object use lsquoobjectrsquo for extra details

Welcome to pylab a matplotlib-based Python environment [backend Qt4Agg]

For more information type `help(pylab)

In [1]

Figure 1 IPython interactive console

GraphNetworkXPymote

Network Simulation

0 lowast 0 lowast

0 lowast

1

1

Algorithm Environment Node

NodeAlgorithm NetworkAlgorithm Sensor CompositeSensor

All algorithms All sensors

Figure 2 Simplified class diagram

functionalities but one that will build on top of the existingcode KISS principle reflects the need to simplify libraryusage and library implementation To adhere with the DRYprinciple Pymote library is placed in such a position that itdoes not repeat work that has been already done Since thenetwork is identified as an instance of graph the only sensiblechoice was to find a package on top of which this libraryshould be built

NetworkX [20] is a package for the creation manipula-tion and study of the structure dynamics and functions ofcomplex networks Its graph definition is as general as possi-ble allowing for easy extension It has a huge base of graph-related functions andmethods already implemented Pymotelibrary extends from NetworkX and defines few core classesthat we describe in this section Simplified class diagramdescribing relations between core classes is presented inFigure 2

Network class is a subclass of the NetworkXrsquos Graph classand as such it implements all methods provided by this classIn addition all graph-related algorithms implemented in thispackage are available directly in Pymote Based on node posi-tions (stored inside network) environment communicationrange and channel type Network is managing creation andremoval of links namely edges of the underlying Graph Alist of algorithm instances that should be executed is placedinside Network instance Other responsibilities of Network

class include communication or passing messages betweenneighboring nodes and managing state of algorithms that areexecuted on a network

Node class represents a wireless node Every node has anid to satisfy local orientation property Additionally it hasa set of memory fields (outbox inbox status and generalpurpose memory) and communication range property thatis used as an argument to a Network class method that ismanaging communication links In order to simulate nodersquosknowledge in amore realistic way a node does not know any-thing that it would not know in real deployment for examplethe node does not know its position inside the network If thisinformation should be part of nodersquos knowledge (ie node isan anchor) the user could ensure this in experiment setup byequipping the nodewith an adequate sensor as demonstratedin Section 52

Instances of Simulation class are used to control step-by-step execution of algorithms defined in the networkSimulation is using methods defined in Algorithm class toexecute them either on a every node or on a network levelas presented in a sequence diagram in Figure 3 During exe-cution network and its nodesrsquo states are changing but thesimulation instance does not store any data in the processAll data before during and after simulation is held inside thenetwork instancewhich is important as all needed data can bestored simply by serializing and storing the network instance

Algorithm class represents an executable code that shouldrun inside a network Currently there are twomain subclassesof Algorithm class NetworkAlgorithm and NodeAlgorithm

NodeAlgorithm is a classic distributed algorithm that runsin every node Its start is triggered spontaneously either inrandomly chosen nodes or defined ones Every action afterthe algorithm initiation is a result of incoming message andstate in which the node is in

There is a notable difference between local terminationwhere the node knows it is donewith all actions in the currentalgorithm and a global termination in which the node knowsthat all other nodes are also done Only global terminationcan be a simple and clear signal to advance further to the nextalgorithm In our library the simulation instance (which isused to execute algorithms on a network) is responsible fordetecting when a certain algorithm has terminated It can bedetected by the absence of messages (local termination) or bya node returning a clear signal that every node has terminatedits execution (global termination)

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

2 International Journal of Distributed Sensor Networks

(3) promoting open source reproducible research thusencouraging its reuse and reevaluation trough com-parisons with new ideas based on easily customizedcriteria

Since the library is built upon a formally defined distributedcomputing environment implementation of specific algo-rithm is a straightforward processThis process is additionallyalleviated by using interactive console and the native Pythondebugger in which all objects are directly accessible for intro-spection and modification

Python is a modular language so advanced usage orextension of basic functionalities is easily available by writingadditional modules and inheriting from the library coreclasses These extensions are encouraged through the opensource developing workflow

In the next section a brief analysis of currently availablesimulators and libraries is given In Section 3 we formallydefine distributed computing environment giving theoreticfoundation and basic principles onwhich this library is basedThis is followed by a short discussion on platform selectiondescription of some implementation details and possibleways of extending the library beyond its current functional-ities Finally in Section 5 there is an example of definitionsimulation and analysis of one of the popular localizationalgorithms using the library in interactive and automatedworkflow

2 Related Work

A large number of simulators have been proposed in literaturein which algorithms for wireless ad hoc networks can beimplemented and studied These simulators have differentdesign goals and largely vary in the level of complexity andincluded features They support different hardware and com-munication layers assumptions focus on different distributednetworks implementations and environments and comewitha different set of tools for modeling analysis and visualiza-tion Classical algorithms include NS-2 OMNeT++ J-SimTOSSIM and others

NS-2 [1] is a discrete event simulator for general networksimulation It is probably the most widely used networksimulator for research NS-2 provides substantial supportfor simulation of TCP routing and multicast protocols overwired and wireless networks It was originally targeted to IPnetworks but extensions [2 3] for wireless sensor networkshave been proposed in the past NS-2 allows for a detailedsimulation tracing and comes with the simulation tool calledNAM (network animator) for later playback Due to a verydetailed packet level simulation the NS-2 simulator is notsuitable for simulation of very large networks made ofthousands of nodes NS-2 has many different distributionsand extensions and a large number of network simulationshave been performed with them However NS-2 has a steeplearning curve and requires considerable effort to repeat thesimulations and compare with the obtained results The coreof the simulator and most of the network protocol modelsare written in C++ while OTcl is used for the definition and

configuration of the simulation environment It is availableunder an open source license

Wireless sensor network simulation can be performedusing Mannasim framework which extends NS-2 by intro-ducing new modules for design development and analysisof different WSN applications The Mannasim frameworkprovides standardized structures for common sensor clusterheads and access point nodes on top of NS-2 In a simulationthese three types of nodes run different algorithms which areimplemented directly in C++

Another simulation platform which is widely used inthe global scientific community is OMNeT++ [4 5] It isan extensible modular component-based C++ simulationlibrary and framework used primarily for building networksimulators OMNeT++ offers extensive simulation librarythat includes support for inputoutput statistics data col-lection graphical presentation of simulation data randomnumber generators and data structures Domain-specificfunctionality such as support for sensor networks wirelessad hoc networks Internet protocols performance model-ing and so forth are provided by model frameworks anddeveloped as independent projects Extensions for real-timesimulation network emulation alternative programminglanguages database integration and other functions existFor the simulation of wireless sensor networks one popularextension is Castalia [6] Its development was motivatedby the desire to provide a realistic channelradio modelingHowever for the development of high level algorithm andstudying of its behavior Castalia is time consuming becauseone has to account for all the details related to specific lowlevel modeling

J-Sim [7] is a general purpose simulator written in Javaaccording to the component-based software paradigm Com-ponents are loosely coupled as each component can bedesigned implemented and tested independently On thetop of the autonomous component architecture a generalizedpacket switched network model defines the generic structureof a node and the generic network components both ofwhichcan then be used as base classes to implement protocols acrossvarious layers J-Sim was initially designed for wired networksimulation but a wireless extension exists which proposes animplementation of the IEEE 80211MAC togetherwith a set ofnetwork and protocol components which facilitates the sim-ulation of wireless networks It supports real-time process-driven simulation

TOSSIM [8] is a platform-specific simulation librarywhich simulates TinyOS [9] motes at the bit level It allowsemulation of system components and modeling of differentnetwork topologies thus providing a realistic setting for mea-surement of the communication costs of algorithms TOSSIMis an open source discrete event simulator which directlycompiles code written for TinyOS to an executable file thatcan be run on standard PC equipment It can run simulationswith a few thousand virtual TinyOS nodes It ships withthe graphical user interface TinyViz that can visualize andinteract with running simulations

For a survey and comparison of these and other simula-tion platforms the reader can refer to [10ndash12]

International Journal of Distributed Sensor Networks 3

One classification [13] divides simulators into threemajorcategories based on the level of complexity

(1) algorithm level(2) packet level and(3) instruction level

Algorithm level simulators focus on the logic data structureand presentation of algorithmsThese simulators do not con-sider detailed communication models and most commonlythey rely on some form of a graph data structure to illustratethe communication between nodes Packet level simulatorsimplement the data link and physical layers in a typical OSInetwork stackHence it is common for this type of simulatorsto include implementations of 80211b or newer MAC proto-cols and radio models that account for propagation fadingcollision noise and wave diffraction Instruction level simu-lators model the CPU execution at the level of instructions oreven cycles They are often regarded as emulators

According to this classification Pymote is an algorithmlevel simulator In comparison to the abovementioned widelyused simulators Pymote does not provide packet level andinstruction level simulation Instead it uses abstract modelsof the communicating entities and the environment thusenabling researcher to focus on a general principles not influ-enced by large amount of implementation details This factmakes it considerably easier to learn and more straightfor-ward to use An additional benefit of such decision is scalingof the simulation environment in a way that can accom-modate large networks Pymote is focused on the designand evaluation of algorithms while also providing toolsfor quick definition of different network structures In theremaining part of this section we describe some of the algo-rithm level simulators that were proposed in the literature

AlgoSensim [14] is a framework used to simulate dis-tributed algorithms It focuses on network specific algorithmslike localization distributed routing flooding and so forthIt is written in Java and uses XML files for configurationTheframework was published as open source in 2006 but hasremained in alpha release since

Shawnrsquos [15] primary design goals are to simulate theeffect caused by a phenomenon not the phenomenon itselfto improve scalability and to support free choice of theimplementation model Instead of performing a completesimulation of the MAC layer including radio propagationproperties such as attenuation collision fading and multi-path propagation Shawn simulates the effects of aMAC layerfor the application like packet loss corruption and delay Inthis way while producing similar effects on the applicationlayer a performance gain is obtained with a more efficientimplementation This additionally enables Shawn to supportlarge-scale network simulation Shawn is written in C++

NetTopo [13] is an integrated framework for simulationand visualization of wireless sensor networks written in JavaIts design is also algorithm-oriented with the goal of rapidprototyping of algorithms however it derives its motivationby the need to study applications which can run partially ina simulation environment and partially in a physical wirelesssensor network testbed NetTopo supports the simulation of

large scale networks and provides a graphical user interfaceto drive the simulation

Sinalgo [16] is another simulation framework for wirelessnetworkswritten in Javawhich does not simulate the differentlayers of the ISO network stack and focuses instead on algo-rithm layer abstraction It offers amessage passing view of thenetwork and can simulate very large networks Sinalgo comeswith a set of available models for node mobility connectivityinitial distribution interference and transmission which auser can extend with his own if necessary The simulation isusually started from the available graphical user interface butfor long-lasting well-defined simulations it can also be startedin batch mode

One important difference of these algorithm level simu-lators with Pymote is the programming language and envi-ronment Pymote leverages Pythonrsquos strengths like ease oflearning and use and faster development than C++ and Javamaking the solutionwell suited for rapid prototyping Furtherdifference is that Pymote naturally supports both interactiveand programmed simulation modes enabling and actuallyfostering quick often intertwined definition and simulationphases By using Pythonrsquos introspection power that is itsability to inspect objects at runtime determine informationabout them and make that information available to the userPymote is able to interactively explore and manage all theentities involved in the simulation

3 Distributed Computing Environment

To design a proper distributed algorithm the environmentin which it performs must be strictly defined Distributedenvironment and restrictions to problem space used in spec-ifications for making Pymote library are taken from [17]Main principles governing algorithm operation in this envi-ronment are described below

Distributed computing environment is composed from aset of computational entities E (in our case wireless nodes)and messages they interchange A node 119909 isin E has the capa-bility to store data in finite local memory119872

119909consisting from

a number of defined registers One of them with specialfunction is the status register that can take values from afinite set of states S Other parts of the node 119909 are CPU andcommunication

Node behavior is reactive It acts only when it detectsone of two possible events (1) arrival of message and (2)spontaneous impulsemdashusually used in random or definednodes at algorithm initiation The action that node performsis a result of its state (in status register) and the event whichin our case is the arrival of message as follows

status times event 997888rarr action (1)Distributed algorithm is defined as a set of rules that associateall possible combinations of states and events with specificactions

The system has homogenous behavior if all nodes runthe same algorithm which simplifies its development andanalysis Since every nonhomogenous behavior can be madehomogeneous as described in [17] all nodes in our libraryare running the same algorithm

4 International Journal of Distributed Sensor Networks

Table 1 Message structure

Field name Data type DescriptionSource Node Sender node instance

Nexthop Node Neighboring node instance that is nexthop in path to destination

Destination Node Destination node instance

Header String Message header defining function andstructure of sent data

Data Dict Any data

There are three types of actions storing and processingdata message transmission and changing the value of statusregister All other actions such as measuring some phenom-ena or relation between nodes can be thought of as a combi-nation of message transmission storing and processing data

Message transmission between nodes is defined as atransfer of finite sequence of bits Simple but generic structureand description of fields in messages used in our library ispresented in Table 1

Every node 119909 can send a message to a set of other nodes119873out(119909) isin E and receive it from set 119873in(119909) isin E Inherentproperty of every node is local orientation which means thata node can distinguish between its neighbors by their uniqueID so for example it can send amessage to a specific neighborwithout sending it to the other neighbors This is utilizedthrough destination field in the message structure

In practice sending and receiving messages are complexoperations liable to failures and spanning through severalcommunication layers with unknown possibly infinite dura-tionWhendesigning distributed algorithms it is very impor-tant to make their performance invariant to communicationfailures and delays

Up to this point all network properties have been definedfor some general case Special properties are called restrictionsbecause algorithms designed under assumption of this prop-erties are restricted and cannot be applied to a more generalunrestricted cases

Current restrictions in our library are as followsBidirectional Links For every node 119909 a set of outgoing andincoming links are identical 119873out(119909) = 119873in(119909) for all 119909 isinE and the nodes that belong to this set are called neighborsof 119909Connectivity In cooperative distributed algorithms it is veryimportant that every node can communicate to all othernodes directly or through intermediate nodesTotal Reliability Every sent message eventually in unknownbut finite time will be received with its content uncorruptedand without any failure occurring

These restrictions are strong but sensible They try tolimit problem space to an application layer only and removeunwanted overspecification by focusing on a generic casesolutions

Nodersquos memory content and information held in it repre-sent its local knowledge If at least one node in a set119882 sube Ehas information 119901 it is defined as implicit knowledge If every

node in a set119882 has the same information then it is explicitknowledge Notion of knowledge is very important since thesole purpose of (distributed) algorithm is improving localknowledge of nodes and implicit and explicit knowledge ofthe network in general

4 Implementation

The Pymote library is based on goals described in Section 1and formalism of the distributed computing environmentstated in Section 3 We proceed with discussion on platformselection and brief description of the implementation of basiclibrary functionalities We conclude with a description ofsome of directions that can be taken to extend them

41 Why Python Python language with included librariesand tools was selected after research and analysis of anumber of existing platforms and frameworks The selectionof Python allows to fulfil the following requirements

(i) easy to learn and well documented(ii) full featured object oriented language Partial or

restricted solutions (ie MATLAB) are bound to havea limit regarding supported object oriented features

(iii) simple and highly expressive As such it keeps thecode clean andminimal making its usage straightfor-ward

(iv) support for interactive mode since this kind of work-flow is especially suitable for experimentation andanalysis IPython [18] is a Python interactive consolethat provides all major functionalities needed forinteractive scientific computing (Figure 1)

(v) introspection features namely easy programmaticinspection of all defined objectrsquos properties

(vi) rich scientific functions library and strong supportfor scientific computing and calculations AlthoughPython is a general purpose language in this field itis very competitive NumPy and SciPy [19] are thefundamental packages for scientific computing inPython They add significant power to the interac-tive Python session by exposing the user to high-level commands and classes needed for all kinds ofscientific data manipulation In addition to these forplotting and general graphical representation of datamatplotlib is a perfect choice

(vii) promote open source reproducible research Pythonis a platform that already promotes similar ideasand that grows with the community of its users anddevelopers

After long and exhaustive usage we have concluded thatPython completely fulfills the requirements

42 Core Classes The implementation philosophy followedDRY (Do not Repeat Yourself) and KISS (Keep It SimpleStupid) principles DRYprinciple states our intention tomakea library that will not rediscover and rewrite already existing

International Journal of Distributed Sensor Networks 5

Python 271 (r27186832 Nov 27 2010 183046) [MSC v1500 32 bit (Intel)] Type copyright credits or license for more information

IPython 0131 -- An enhanced Interactive Python -gt Introduction and overview of IPythons features quickref -gt Quick reference help -gt Pythons own help system object -gt Details about `object use lsquoobjectrsquo for extra details

Welcome to pylab a matplotlib-based Python environment [backend Qt4Agg]

For more information type `help(pylab)

In [1]

Figure 1 IPython interactive console

GraphNetworkXPymote

Network Simulation

0 lowast 0 lowast

0 lowast

1

1

Algorithm Environment Node

NodeAlgorithm NetworkAlgorithm Sensor CompositeSensor

All algorithms All sensors

Figure 2 Simplified class diagram

functionalities but one that will build on top of the existingcode KISS principle reflects the need to simplify libraryusage and library implementation To adhere with the DRYprinciple Pymote library is placed in such a position that itdoes not repeat work that has been already done Since thenetwork is identified as an instance of graph the only sensiblechoice was to find a package on top of which this libraryshould be built

NetworkX [20] is a package for the creation manipula-tion and study of the structure dynamics and functions ofcomplex networks Its graph definition is as general as possi-ble allowing for easy extension It has a huge base of graph-related functions andmethods already implemented Pymotelibrary extends from NetworkX and defines few core classesthat we describe in this section Simplified class diagramdescribing relations between core classes is presented inFigure 2

Network class is a subclass of the NetworkXrsquos Graph classand as such it implements all methods provided by this classIn addition all graph-related algorithms implemented in thispackage are available directly in Pymote Based on node posi-tions (stored inside network) environment communicationrange and channel type Network is managing creation andremoval of links namely edges of the underlying Graph Alist of algorithm instances that should be executed is placedinside Network instance Other responsibilities of Network

class include communication or passing messages betweenneighboring nodes and managing state of algorithms that areexecuted on a network

Node class represents a wireless node Every node has anid to satisfy local orientation property Additionally it hasa set of memory fields (outbox inbox status and generalpurpose memory) and communication range property thatis used as an argument to a Network class method that ismanaging communication links In order to simulate nodersquosknowledge in amore realistic way a node does not know any-thing that it would not know in real deployment for examplethe node does not know its position inside the network If thisinformation should be part of nodersquos knowledge (ie node isan anchor) the user could ensure this in experiment setup byequipping the nodewith an adequate sensor as demonstratedin Section 52

Instances of Simulation class are used to control step-by-step execution of algorithms defined in the networkSimulation is using methods defined in Algorithm class toexecute them either on a every node or on a network levelas presented in a sequence diagram in Figure 3 During exe-cution network and its nodesrsquo states are changing but thesimulation instance does not store any data in the processAll data before during and after simulation is held inside thenetwork instancewhich is important as all needed data can bestored simply by serializing and storing the network instance

Algorithm class represents an executable code that shouldrun inside a network Currently there are twomain subclassesof Algorithm class NetworkAlgorithm and NodeAlgorithm

NodeAlgorithm is a classic distributed algorithm that runsin every node Its start is triggered spontaneously either inrandomly chosen nodes or defined ones Every action afterthe algorithm initiation is a result of incoming message andstate in which the node is in

There is a notable difference between local terminationwhere the node knows it is donewith all actions in the currentalgorithm and a global termination in which the node knowsthat all other nodes are also done Only global terminationcan be a simple and clear signal to advance further to the nextalgorithm In our library the simulation instance (which isused to execute algorithms on a network) is responsible fordetecting when a certain algorithm has terminated It can bedetected by the absence of messages (local termination) or bya node returning a clear signal that every node has terminatedits execution (global termination)

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of Distributed Sensor Networks 3

One classification [13] divides simulators into threemajorcategories based on the level of complexity

(1) algorithm level(2) packet level and(3) instruction level

Algorithm level simulators focus on the logic data structureand presentation of algorithmsThese simulators do not con-sider detailed communication models and most commonlythey rely on some form of a graph data structure to illustratethe communication between nodes Packet level simulatorsimplement the data link and physical layers in a typical OSInetwork stackHence it is common for this type of simulatorsto include implementations of 80211b or newer MAC proto-cols and radio models that account for propagation fadingcollision noise and wave diffraction Instruction level simu-lators model the CPU execution at the level of instructions oreven cycles They are often regarded as emulators

According to this classification Pymote is an algorithmlevel simulator In comparison to the abovementioned widelyused simulators Pymote does not provide packet level andinstruction level simulation Instead it uses abstract modelsof the communicating entities and the environment thusenabling researcher to focus on a general principles not influ-enced by large amount of implementation details This factmakes it considerably easier to learn and more straightfor-ward to use An additional benefit of such decision is scalingof the simulation environment in a way that can accom-modate large networks Pymote is focused on the designand evaluation of algorithms while also providing toolsfor quick definition of different network structures In theremaining part of this section we describe some of the algo-rithm level simulators that were proposed in the literature

AlgoSensim [14] is a framework used to simulate dis-tributed algorithms It focuses on network specific algorithmslike localization distributed routing flooding and so forthIt is written in Java and uses XML files for configurationTheframework was published as open source in 2006 but hasremained in alpha release since

Shawnrsquos [15] primary design goals are to simulate theeffect caused by a phenomenon not the phenomenon itselfto improve scalability and to support free choice of theimplementation model Instead of performing a completesimulation of the MAC layer including radio propagationproperties such as attenuation collision fading and multi-path propagation Shawn simulates the effects of aMAC layerfor the application like packet loss corruption and delay Inthis way while producing similar effects on the applicationlayer a performance gain is obtained with a more efficientimplementation This additionally enables Shawn to supportlarge-scale network simulation Shawn is written in C++

NetTopo [13] is an integrated framework for simulationand visualization of wireless sensor networks written in JavaIts design is also algorithm-oriented with the goal of rapidprototyping of algorithms however it derives its motivationby the need to study applications which can run partially ina simulation environment and partially in a physical wirelesssensor network testbed NetTopo supports the simulation of

large scale networks and provides a graphical user interfaceto drive the simulation

Sinalgo [16] is another simulation framework for wirelessnetworkswritten in Javawhich does not simulate the differentlayers of the ISO network stack and focuses instead on algo-rithm layer abstraction It offers amessage passing view of thenetwork and can simulate very large networks Sinalgo comeswith a set of available models for node mobility connectivityinitial distribution interference and transmission which auser can extend with his own if necessary The simulation isusually started from the available graphical user interface butfor long-lasting well-defined simulations it can also be startedin batch mode

One important difference of these algorithm level simu-lators with Pymote is the programming language and envi-ronment Pymote leverages Pythonrsquos strengths like ease oflearning and use and faster development than C++ and Javamaking the solutionwell suited for rapid prototyping Furtherdifference is that Pymote naturally supports both interactiveand programmed simulation modes enabling and actuallyfostering quick often intertwined definition and simulationphases By using Pythonrsquos introspection power that is itsability to inspect objects at runtime determine informationabout them and make that information available to the userPymote is able to interactively explore and manage all theentities involved in the simulation

3 Distributed Computing Environment

To design a proper distributed algorithm the environmentin which it performs must be strictly defined Distributedenvironment and restrictions to problem space used in spec-ifications for making Pymote library are taken from [17]Main principles governing algorithm operation in this envi-ronment are described below

Distributed computing environment is composed from aset of computational entities E (in our case wireless nodes)and messages they interchange A node 119909 isin E has the capa-bility to store data in finite local memory119872

119909consisting from

a number of defined registers One of them with specialfunction is the status register that can take values from afinite set of states S Other parts of the node 119909 are CPU andcommunication

Node behavior is reactive It acts only when it detectsone of two possible events (1) arrival of message and (2)spontaneous impulsemdashusually used in random or definednodes at algorithm initiation The action that node performsis a result of its state (in status register) and the event whichin our case is the arrival of message as follows

status times event 997888rarr action (1)Distributed algorithm is defined as a set of rules that associateall possible combinations of states and events with specificactions

The system has homogenous behavior if all nodes runthe same algorithm which simplifies its development andanalysis Since every nonhomogenous behavior can be madehomogeneous as described in [17] all nodes in our libraryare running the same algorithm

4 International Journal of Distributed Sensor Networks

Table 1 Message structure

Field name Data type DescriptionSource Node Sender node instance

Nexthop Node Neighboring node instance that is nexthop in path to destination

Destination Node Destination node instance

Header String Message header defining function andstructure of sent data

Data Dict Any data

There are three types of actions storing and processingdata message transmission and changing the value of statusregister All other actions such as measuring some phenom-ena or relation between nodes can be thought of as a combi-nation of message transmission storing and processing data

Message transmission between nodes is defined as atransfer of finite sequence of bits Simple but generic structureand description of fields in messages used in our library ispresented in Table 1

Every node 119909 can send a message to a set of other nodes119873out(119909) isin E and receive it from set 119873in(119909) isin E Inherentproperty of every node is local orientation which means thata node can distinguish between its neighbors by their uniqueID so for example it can send amessage to a specific neighborwithout sending it to the other neighbors This is utilizedthrough destination field in the message structure

In practice sending and receiving messages are complexoperations liable to failures and spanning through severalcommunication layers with unknown possibly infinite dura-tionWhendesigning distributed algorithms it is very impor-tant to make their performance invariant to communicationfailures and delays

Up to this point all network properties have been definedfor some general case Special properties are called restrictionsbecause algorithms designed under assumption of this prop-erties are restricted and cannot be applied to a more generalunrestricted cases

Current restrictions in our library are as followsBidirectional Links For every node 119909 a set of outgoing andincoming links are identical 119873out(119909) = 119873in(119909) for all 119909 isinE and the nodes that belong to this set are called neighborsof 119909Connectivity In cooperative distributed algorithms it is veryimportant that every node can communicate to all othernodes directly or through intermediate nodesTotal Reliability Every sent message eventually in unknownbut finite time will be received with its content uncorruptedand without any failure occurring

These restrictions are strong but sensible They try tolimit problem space to an application layer only and removeunwanted overspecification by focusing on a generic casesolutions

Nodersquos memory content and information held in it repre-sent its local knowledge If at least one node in a set119882 sube Ehas information 119901 it is defined as implicit knowledge If every

node in a set119882 has the same information then it is explicitknowledge Notion of knowledge is very important since thesole purpose of (distributed) algorithm is improving localknowledge of nodes and implicit and explicit knowledge ofthe network in general

4 Implementation

The Pymote library is based on goals described in Section 1and formalism of the distributed computing environmentstated in Section 3 We proceed with discussion on platformselection and brief description of the implementation of basiclibrary functionalities We conclude with a description ofsome of directions that can be taken to extend them

41 Why Python Python language with included librariesand tools was selected after research and analysis of anumber of existing platforms and frameworks The selectionof Python allows to fulfil the following requirements

(i) easy to learn and well documented(ii) full featured object oriented language Partial or

restricted solutions (ie MATLAB) are bound to havea limit regarding supported object oriented features

(iii) simple and highly expressive As such it keeps thecode clean andminimal making its usage straightfor-ward

(iv) support for interactive mode since this kind of work-flow is especially suitable for experimentation andanalysis IPython [18] is a Python interactive consolethat provides all major functionalities needed forinteractive scientific computing (Figure 1)

(v) introspection features namely easy programmaticinspection of all defined objectrsquos properties

(vi) rich scientific functions library and strong supportfor scientific computing and calculations AlthoughPython is a general purpose language in this field itis very competitive NumPy and SciPy [19] are thefundamental packages for scientific computing inPython They add significant power to the interac-tive Python session by exposing the user to high-level commands and classes needed for all kinds ofscientific data manipulation In addition to these forplotting and general graphical representation of datamatplotlib is a perfect choice

(vii) promote open source reproducible research Pythonis a platform that already promotes similar ideasand that grows with the community of its users anddevelopers

After long and exhaustive usage we have concluded thatPython completely fulfills the requirements

42 Core Classes The implementation philosophy followedDRY (Do not Repeat Yourself) and KISS (Keep It SimpleStupid) principles DRYprinciple states our intention tomakea library that will not rediscover and rewrite already existing

International Journal of Distributed Sensor Networks 5

Python 271 (r27186832 Nov 27 2010 183046) [MSC v1500 32 bit (Intel)] Type copyright credits or license for more information

IPython 0131 -- An enhanced Interactive Python -gt Introduction and overview of IPythons features quickref -gt Quick reference help -gt Pythons own help system object -gt Details about `object use lsquoobjectrsquo for extra details

Welcome to pylab a matplotlib-based Python environment [backend Qt4Agg]

For more information type `help(pylab)

In [1]

Figure 1 IPython interactive console

GraphNetworkXPymote

Network Simulation

0 lowast 0 lowast

0 lowast

1

1

Algorithm Environment Node

NodeAlgorithm NetworkAlgorithm Sensor CompositeSensor

All algorithms All sensors

Figure 2 Simplified class diagram

functionalities but one that will build on top of the existingcode KISS principle reflects the need to simplify libraryusage and library implementation To adhere with the DRYprinciple Pymote library is placed in such a position that itdoes not repeat work that has been already done Since thenetwork is identified as an instance of graph the only sensiblechoice was to find a package on top of which this libraryshould be built

NetworkX [20] is a package for the creation manipula-tion and study of the structure dynamics and functions ofcomplex networks Its graph definition is as general as possi-ble allowing for easy extension It has a huge base of graph-related functions andmethods already implemented Pymotelibrary extends from NetworkX and defines few core classesthat we describe in this section Simplified class diagramdescribing relations between core classes is presented inFigure 2

Network class is a subclass of the NetworkXrsquos Graph classand as such it implements all methods provided by this classIn addition all graph-related algorithms implemented in thispackage are available directly in Pymote Based on node posi-tions (stored inside network) environment communicationrange and channel type Network is managing creation andremoval of links namely edges of the underlying Graph Alist of algorithm instances that should be executed is placedinside Network instance Other responsibilities of Network

class include communication or passing messages betweenneighboring nodes and managing state of algorithms that areexecuted on a network

Node class represents a wireless node Every node has anid to satisfy local orientation property Additionally it hasa set of memory fields (outbox inbox status and generalpurpose memory) and communication range property thatis used as an argument to a Network class method that ismanaging communication links In order to simulate nodersquosknowledge in amore realistic way a node does not know any-thing that it would not know in real deployment for examplethe node does not know its position inside the network If thisinformation should be part of nodersquos knowledge (ie node isan anchor) the user could ensure this in experiment setup byequipping the nodewith an adequate sensor as demonstratedin Section 52

Instances of Simulation class are used to control step-by-step execution of algorithms defined in the networkSimulation is using methods defined in Algorithm class toexecute them either on a every node or on a network levelas presented in a sequence diagram in Figure 3 During exe-cution network and its nodesrsquo states are changing but thesimulation instance does not store any data in the processAll data before during and after simulation is held inside thenetwork instancewhich is important as all needed data can bestored simply by serializing and storing the network instance

Algorithm class represents an executable code that shouldrun inside a network Currently there are twomain subclassesof Algorithm class NetworkAlgorithm and NodeAlgorithm

NodeAlgorithm is a classic distributed algorithm that runsin every node Its start is triggered spontaneously either inrandomly chosen nodes or defined ones Every action afterthe algorithm initiation is a result of incoming message andstate in which the node is in

There is a notable difference between local terminationwhere the node knows it is donewith all actions in the currentalgorithm and a global termination in which the node knowsthat all other nodes are also done Only global terminationcan be a simple and clear signal to advance further to the nextalgorithm In our library the simulation instance (which isused to execute algorithms on a network) is responsible fordetecting when a certain algorithm has terminated It can bedetected by the absence of messages (local termination) or bya node returning a clear signal that every node has terminatedits execution (global termination)

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

4 International Journal of Distributed Sensor Networks

Table 1 Message structure

Field name Data type DescriptionSource Node Sender node instance

Nexthop Node Neighboring node instance that is nexthop in path to destination

Destination Node Destination node instance

Header String Message header defining function andstructure of sent data

Data Dict Any data

There are three types of actions storing and processingdata message transmission and changing the value of statusregister All other actions such as measuring some phenom-ena or relation between nodes can be thought of as a combi-nation of message transmission storing and processing data

Message transmission between nodes is defined as atransfer of finite sequence of bits Simple but generic structureand description of fields in messages used in our library ispresented in Table 1

Every node 119909 can send a message to a set of other nodes119873out(119909) isin E and receive it from set 119873in(119909) isin E Inherentproperty of every node is local orientation which means thata node can distinguish between its neighbors by their uniqueID so for example it can send amessage to a specific neighborwithout sending it to the other neighbors This is utilizedthrough destination field in the message structure

In practice sending and receiving messages are complexoperations liable to failures and spanning through severalcommunication layers with unknown possibly infinite dura-tionWhendesigning distributed algorithms it is very impor-tant to make their performance invariant to communicationfailures and delays

Up to this point all network properties have been definedfor some general case Special properties are called restrictionsbecause algorithms designed under assumption of this prop-erties are restricted and cannot be applied to a more generalunrestricted cases

Current restrictions in our library are as followsBidirectional Links For every node 119909 a set of outgoing andincoming links are identical 119873out(119909) = 119873in(119909) for all 119909 isinE and the nodes that belong to this set are called neighborsof 119909Connectivity In cooperative distributed algorithms it is veryimportant that every node can communicate to all othernodes directly or through intermediate nodesTotal Reliability Every sent message eventually in unknownbut finite time will be received with its content uncorruptedand without any failure occurring

These restrictions are strong but sensible They try tolimit problem space to an application layer only and removeunwanted overspecification by focusing on a generic casesolutions

Nodersquos memory content and information held in it repre-sent its local knowledge If at least one node in a set119882 sube Ehas information 119901 it is defined as implicit knowledge If every

node in a set119882 has the same information then it is explicitknowledge Notion of knowledge is very important since thesole purpose of (distributed) algorithm is improving localknowledge of nodes and implicit and explicit knowledge ofthe network in general

4 Implementation

The Pymote library is based on goals described in Section 1and formalism of the distributed computing environmentstated in Section 3 We proceed with discussion on platformselection and brief description of the implementation of basiclibrary functionalities We conclude with a description ofsome of directions that can be taken to extend them

41 Why Python Python language with included librariesand tools was selected after research and analysis of anumber of existing platforms and frameworks The selectionof Python allows to fulfil the following requirements

(i) easy to learn and well documented(ii) full featured object oriented language Partial or

restricted solutions (ie MATLAB) are bound to havea limit regarding supported object oriented features

(iii) simple and highly expressive As such it keeps thecode clean andminimal making its usage straightfor-ward

(iv) support for interactive mode since this kind of work-flow is especially suitable for experimentation andanalysis IPython [18] is a Python interactive consolethat provides all major functionalities needed forinteractive scientific computing (Figure 1)

(v) introspection features namely easy programmaticinspection of all defined objectrsquos properties

(vi) rich scientific functions library and strong supportfor scientific computing and calculations AlthoughPython is a general purpose language in this field itis very competitive NumPy and SciPy [19] are thefundamental packages for scientific computing inPython They add significant power to the interac-tive Python session by exposing the user to high-level commands and classes needed for all kinds ofscientific data manipulation In addition to these forplotting and general graphical representation of datamatplotlib is a perfect choice

(vii) promote open source reproducible research Pythonis a platform that already promotes similar ideasand that grows with the community of its users anddevelopers

After long and exhaustive usage we have concluded thatPython completely fulfills the requirements

42 Core Classes The implementation philosophy followedDRY (Do not Repeat Yourself) and KISS (Keep It SimpleStupid) principles DRYprinciple states our intention tomakea library that will not rediscover and rewrite already existing

International Journal of Distributed Sensor Networks 5

Python 271 (r27186832 Nov 27 2010 183046) [MSC v1500 32 bit (Intel)] Type copyright credits or license for more information

IPython 0131 -- An enhanced Interactive Python -gt Introduction and overview of IPythons features quickref -gt Quick reference help -gt Pythons own help system object -gt Details about `object use lsquoobjectrsquo for extra details

Welcome to pylab a matplotlib-based Python environment [backend Qt4Agg]

For more information type `help(pylab)

In [1]

Figure 1 IPython interactive console

GraphNetworkXPymote

Network Simulation

0 lowast 0 lowast

0 lowast

1

1

Algorithm Environment Node

NodeAlgorithm NetworkAlgorithm Sensor CompositeSensor

All algorithms All sensors

Figure 2 Simplified class diagram

functionalities but one that will build on top of the existingcode KISS principle reflects the need to simplify libraryusage and library implementation To adhere with the DRYprinciple Pymote library is placed in such a position that itdoes not repeat work that has been already done Since thenetwork is identified as an instance of graph the only sensiblechoice was to find a package on top of which this libraryshould be built

NetworkX [20] is a package for the creation manipula-tion and study of the structure dynamics and functions ofcomplex networks Its graph definition is as general as possi-ble allowing for easy extension It has a huge base of graph-related functions andmethods already implemented Pymotelibrary extends from NetworkX and defines few core classesthat we describe in this section Simplified class diagramdescribing relations between core classes is presented inFigure 2

Network class is a subclass of the NetworkXrsquos Graph classand as such it implements all methods provided by this classIn addition all graph-related algorithms implemented in thispackage are available directly in Pymote Based on node posi-tions (stored inside network) environment communicationrange and channel type Network is managing creation andremoval of links namely edges of the underlying Graph Alist of algorithm instances that should be executed is placedinside Network instance Other responsibilities of Network

class include communication or passing messages betweenneighboring nodes and managing state of algorithms that areexecuted on a network

Node class represents a wireless node Every node has anid to satisfy local orientation property Additionally it hasa set of memory fields (outbox inbox status and generalpurpose memory) and communication range property thatis used as an argument to a Network class method that ismanaging communication links In order to simulate nodersquosknowledge in amore realistic way a node does not know any-thing that it would not know in real deployment for examplethe node does not know its position inside the network If thisinformation should be part of nodersquos knowledge (ie node isan anchor) the user could ensure this in experiment setup byequipping the nodewith an adequate sensor as demonstratedin Section 52

Instances of Simulation class are used to control step-by-step execution of algorithms defined in the networkSimulation is using methods defined in Algorithm class toexecute them either on a every node or on a network levelas presented in a sequence diagram in Figure 3 During exe-cution network and its nodesrsquo states are changing but thesimulation instance does not store any data in the processAll data before during and after simulation is held inside thenetwork instancewhich is important as all needed data can bestored simply by serializing and storing the network instance

Algorithm class represents an executable code that shouldrun inside a network Currently there are twomain subclassesof Algorithm class NetworkAlgorithm and NodeAlgorithm

NodeAlgorithm is a classic distributed algorithm that runsin every node Its start is triggered spontaneously either inrandomly chosen nodes or defined ones Every action afterthe algorithm initiation is a result of incoming message andstate in which the node is in

There is a notable difference between local terminationwhere the node knows it is donewith all actions in the currentalgorithm and a global termination in which the node knowsthat all other nodes are also done Only global terminationcan be a simple and clear signal to advance further to the nextalgorithm In our library the simulation instance (which isused to execute algorithms on a network) is responsible fordetecting when a certain algorithm has terminated It can bedetected by the absence of messages (local termination) or bya node returning a clear signal that every node has terminatedits execution (global termination)

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of Distributed Sensor Networks 5

Python 271 (r27186832 Nov 27 2010 183046) [MSC v1500 32 bit (Intel)] Type copyright credits or license for more information

IPython 0131 -- An enhanced Interactive Python -gt Introduction and overview of IPythons features quickref -gt Quick reference help -gt Pythons own help system object -gt Details about `object use lsquoobjectrsquo for extra details

Welcome to pylab a matplotlib-based Python environment [backend Qt4Agg]

For more information type `help(pylab)

In [1]

Figure 1 IPython interactive console

GraphNetworkXPymote

Network Simulation

0 lowast 0 lowast

0 lowast

1

1

Algorithm Environment Node

NodeAlgorithm NetworkAlgorithm Sensor CompositeSensor

All algorithms All sensors

Figure 2 Simplified class diagram

functionalities but one that will build on top of the existingcode KISS principle reflects the need to simplify libraryusage and library implementation To adhere with the DRYprinciple Pymote library is placed in such a position that itdoes not repeat work that has been already done Since thenetwork is identified as an instance of graph the only sensiblechoice was to find a package on top of which this libraryshould be built

NetworkX [20] is a package for the creation manipula-tion and study of the structure dynamics and functions ofcomplex networks Its graph definition is as general as possi-ble allowing for easy extension It has a huge base of graph-related functions andmethods already implemented Pymotelibrary extends from NetworkX and defines few core classesthat we describe in this section Simplified class diagramdescribing relations between core classes is presented inFigure 2

Network class is a subclass of the NetworkXrsquos Graph classand as such it implements all methods provided by this classIn addition all graph-related algorithms implemented in thispackage are available directly in Pymote Based on node posi-tions (stored inside network) environment communicationrange and channel type Network is managing creation andremoval of links namely edges of the underlying Graph Alist of algorithm instances that should be executed is placedinside Network instance Other responsibilities of Network

class include communication or passing messages betweenneighboring nodes and managing state of algorithms that areexecuted on a network

Node class represents a wireless node Every node has anid to satisfy local orientation property Additionally it hasa set of memory fields (outbox inbox status and generalpurpose memory) and communication range property thatis used as an argument to a Network class method that ismanaging communication links In order to simulate nodersquosknowledge in amore realistic way a node does not know any-thing that it would not know in real deployment for examplethe node does not know its position inside the network If thisinformation should be part of nodersquos knowledge (ie node isan anchor) the user could ensure this in experiment setup byequipping the nodewith an adequate sensor as demonstratedin Section 52

Instances of Simulation class are used to control step-by-step execution of algorithms defined in the networkSimulation is using methods defined in Algorithm class toexecute them either on a every node or on a network levelas presented in a sequence diagram in Figure 3 During exe-cution network and its nodesrsquo states are changing but thesimulation instance does not store any data in the processAll data before during and after simulation is held inside thenetwork instancewhich is important as all needed data can bestored simply by serializing and storing the network instance

Algorithm class represents an executable code that shouldrun inside a network Currently there are twomain subclassesof Algorithm class NetworkAlgorithm and NodeAlgorithm

NodeAlgorithm is a classic distributed algorithm that runsin every node Its start is triggered spontaneously either inrandomly chosen nodes or defined ones Every action afterthe algorithm initiation is a result of incoming message andstate in which the node is in

There is a notable difference between local terminationwhere the node knows it is donewith all actions in the currentalgorithm and a global termination in which the node knowsthat all other nodes are also done Only global terminationcan be a simple and clear signal to advance further to the nextalgorithm In our library the simulation instance (which isused to execute algorithms on a network) is responsible fordetecting when a certain algorithm has terminated It can bedetected by the absence of messages (local termination) or bya node returning a clear signal that every node has terminatedits execution (global termination)

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

6 International Journal of Distributed Sensor Networks

Simulation Network NetworkAlgorithm

NodeAlgorithm

Loop[Networkalgorithms]

Alt[NetworkAlgorithm]

Alt[NodeAlgorithms]

Loop

Loop

[nodes]

run()

communicate()

initializer()

step()

[is halted]

Figure 3 Algorithm sequence diagram

To simplify the definition and running of distributedalgorithms with known behavior output and cost it isallowed for them to use their centralized network versionrepresented by NetworkAlgorithm class Algorithms that aresubclass of NetworkAlgorithm have the ability to improvenodes local knowledge by inserting data directly into theirmemory For example network version of distributed span-ning tree algorithm should have the ability to write parent-child relationship directly into every nodes memory Thesealgorithms are usually helper algorithms that could insertprerequisite knowledge data for algorithms under test Algo-rithms under test should always be defined as a properdistributed algorithm or namely NodeAlgorithm

43 Extending Base Functionalities As we have stated in theintroduction section Pymote is primarily focused on thesimulation of high level algorithms Communicating entitiesshould not affect the outcome of the high level algorithmand this is ensured by introducing restrictions such as totalreliability described in Section 3

Even though they should not affect the outcome entitiesand their lower level behavior can affect the algorithm perfor-mance that is battery usage reliability of the communicationlinks and so forth If the user wants to simulate and inspectlower level behavior or use specific communication protocolsit certainly can be done

For example low level simulation of battery usage or com-munication reliability currently can be handled by overridingthe communicate method of the Network class to simulateand track power consumption or other custom behaviors

Another example is radio channel simulation which canbe done by writing custom ChannelType class and then pass-ing it to network instance Library is currently implementingtwo simple ChannelType subclasses Udg-unit disc graphand SquareDisc in which probability of connection betweennodes is equal to 1 minus 11988921199032 where 119889 is the true distancebetween nodes and 119903 is the communication range

The simplest example is the routing protocol which canbe implemented as a native NodeAlgorithm with the taskof maintaining routing table in the node memory Data inrouting table can be used to appropriately fill nexthop fieldthat is already present in the message structure (Table 1)and used in communicatemethod when sending message tononneighbor node

All these types of extensions can quickly be incorporatedinto future versions of the main library Using collaborativeopen source workflow this kind of development is stronglyencouraged

5 Usage

Pymote library supports usage in two distinct workflowsOne of the most popular workflows in scientific community

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of Distributed Sensor Networks 7

class FloodingUpdate (NodeAlgorithm)required params = (lsquodataKeyrsquo)default params =

def initializer (self)for node in selfnetworknodes()

if selfinitiator condition(node)msg = Message(destination=nodeheader=lsquoinitializersquo)selfnetworkoutboxinsert(0msg)

nodestatus = lsquoFLOODINGrsquo

def flooding(self node message)if messageheader==lsquoinitializersquo

nodesend(Message(header=lsquoFloodrsquodata=selfinitiator data (node)))

if messageheader==lsquoFloodrsquoupdated data = selfhandle flood message (nodemessage)if updated data

nodesend (Message(header=lsquoFloodrsquodata=updated data))

STATUS = lsquoFLOODINGrsquo flooding

Listing 1 Generic flooding protocol Function initializer is special function that is issuing spontaneous impulses in the form of initializemessages at the beginning of the algorithm execution

class DVHop(FloodingUpdate)

def initiator condition(self node)nodememory[selftruePositionKey] = nodecompositeSensorread(node)get(lsquoTruePosrsquoNone)return nodememory[selftruePositionKey] is not None

def initiator data(self node)returnnode concatenate((nodememory[selftruePositionKey][2][1]))

def handle flood message(self node message)if not nodememoryhas key(selfdataKey)

nodememory[selfdataKey] = updated data = for landmark landmark data in messagedataitems()

if landmark==node continue update only if data is new or new hopcount is smallerif not nodememory[selfdataKey]has key(landmark) or

landmark data[2]ltnodememory[selfdataKey][landmark][2]nodememory[selfdataKey][landmark] = array(landmark data) increase hopcountlandmark data[2] += 1

updated data[landmark] = landmark data

landmarks should recalculate hopsizeif nodememory[selftruePositionKey] is not None

selfrecalculate hopsize(node)return updated data

Listing 2 APS DV-hop 1st phase DVHop Function recalculate hopsize is omitted Note that during initiator condition node reads TruePos-Sensor if it has one

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

8 International Journal of Distributed Sensor Networks

class Trilaterate(FloodingUpdate)

def initiator condition(self node)return nodememory[selftruePositionKey] is not None

def initiator data(self node)return nodememory[selfhopsizeKey]

def handle flood message(self node message)if nodememoryhas key(selfhopsizeKey)

return None

nodememory[selfhopsizeKey] = messagedataselfestimate position(node)return nodememory[selfhopsizeKey]

Listing 3 APS DV-hop 2nd phase trilaterate Function estimate position is omitted

create network with degree 9In [1] netgen = NetworkGenerator(n min=100n max=300degree=9)In [2] net = netgengenerate() select landmarks by placing TruePosSensor on themIn [3] for node in netnodes()[10]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo)) import algorithms and pass them to network with their parametersIn [4] from pymotealgorithmsniculescu2003dvhop import DVHopIn [5] from pymotealgorithmsniculescu2003trilaterate import

Trilaterate

In [6] netalgorithms = ((DVHop lsquodataKeyrsquo lsquodvDatarsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) (Trilaterate rsquodataKeyrsquo lsquodvDatarsquo lsquopositionKeyrsquolsquodvHoprsquo lsquotruePositionKeyrsquolsquolandmarkPosrsquo lsquohopsizeKeyrsquolsquohopsizersquo ) )

In [7] sim = Simulation(net)In [8] simrun()INFO [simulationpy] Simulation has finished save network with all relevant data on diskIn [9] write npickle(netrsquonetgzrsquo)

Listing 4 Interactive session for preliminary algorithm simulations First we set up a random network in a default environment Sincein the original article presenting the algorithm there is network with 200 randomly distributed nodes and average degree 9 we set upNetworkGenerator with similar settings to get the appropriate instance of Network After that algorithms implemented in the last subsectionare instantiated and placed in this new network Since algorithms require some nodes to know their position (landmarks) we fit first 10 nodeswith the appropriate sensor using simple for loop Network is now ready so after instantiation of new Simulation we can run it At the end byserializing and storing network object all relevant data is preserved to be analyzed later

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of Distributed Sensor Networks 9

In [10] simreset() first reset network algorithm state and nodes memoryIn [11] simrun(1) run 1 step of the first algorithmIn [12] landmark node = netnodes()[0]In [13] landmark nodeinbox landmark receiving initializer messageOut[13][

- - - - - - Message - - - - - -source = None

destination = ltNode id=1gtheader = lsquoinitializersquo

id(message) = 0x908e9f0gt]

In [14] simrun(1) run another stepIn [15] landmark nodeoutbox landmark prepared a broadcast messageOut[15][

- - - - - - Message - - - - - -source = ltNode id=1gt

destination = Broadcastedheader = lsquoFloodrsquo

id(message) = 0x90a3d30gt]

In [16] landmark nodeoutbox[0]dataOut[16] ltNode id=1gt array([2012419 1419482 1]) check if position being sent in message is one being read by TruePosSensorIn [17] landmark nodememory[lsquolandmarkPosrsquo]Out[17] array([2012419 1419482]) another check by directly inspecting networkIn [18] netpos[node]Out[18] array([2012419 1419482])

Listing 5 Example of step-by-step simulation and inspection of nodes and network data In the first step of the DVHop algorithmspontaneous impulses are issued to landmark nodes in the from of special initializemessages As a consequence in the second step landmarknode is broadcasting Flood message with its true position and hopcount set to 1 After that we check if this is the same data being read byTruePositionSensor and at the end if that really is the landmarkrsquos true position by inspecting network data

netgen = NetworkGenerator(degree=9 n min=100 n max=300)For lm pct in [5 10 20 33]

for net count in range(100)net = netgengenerate()for node in netnodes()[int(lm pctlowastlen(netnodes())100)]

nodecompositeSensor = CompositeSensor((lsquoTruePosSensorrsquo))netalgorithms = ALGORITHMSsim = Simulation(net)simrun()write npickle(net lsquod-dgzrsquo (net countlm pct))

Listing 6 Simple automated experiment For each of the defined landmarks percentages (5 10 20 33) 100 different networksconsisting of 100 to 300 nodes with average degree 9 are created Each of them is fitted with described algorithms which are then executedin a simulation At the end of each simulation network data is stored in appropriately named compressed file Definition of variableALGORITHMS is omitted for brevity

is using an interactive console This workflow enables freeform experimentation runtime introspection direct accessand modification of all objects Another popular workflow isperforming a batch of prepared and automated experiments

In this section examples of using the library in bothways are presented Specifically we shall try to implement

and simulate Ad hoc Positioning System (APS) with DV-hop propagationmdasha popular algorithm for node localizationproposed by Niculescu and Nath [21]

51 Algorithm Definition In Pymote library algorithms aredefined as direct Python implementations In our example

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

10 International Journal of Distributed Sensor Networks

inspect non landmark nodes and list their estimated positionsIn [19] for node in netnodes()[10]

print nodememoryget(lsquodvHoprsquo lsquoNotlocalizedrsquo)[46604 57944]

[24325 8075][38679 6909][25492 12266][21636 8027]Not localized[43108 10228][14036 11935]etcIn [20] estimated = In [21] for node in netnodes()

if nodememoryhas key(lsquodvHoprsquo)

estimated[node] = nodememory[lsquodvHoprsquo]In [22] get rms(netpos[estimated])Out[22] 3219781563265385In [23] show localized(net[estimated]show labels=False)

Listing 7 Analyzing nodes memory after simulation In dvHop key in memory of all successfully localized nodes there are estimatedcoordinates data we can inspect Using library provided utilities such as get rms function root mean square error of estimated positionscan be quickly estimated Finally errors in estimated positions are visualized graphically Result of the last command is presented on Figure 5

APS with DV-hop propagation algorithm is based on thefollowing simple idea Every node in a network shouldestimate its distance to asmany as possible landmark (anchorbeacon) nodes Landmark nodes are nodes that a priori knowtheir absolute position Using the estimated distance and alandmark coordinates the node should be able to estimate itsposition using trilateration

The algorithm has two distinct phases as follows

(1) All landmark nodes are flooding the network withinformation about their coordinates As these mes-sages are propagating hop by hop through the net-work every node is increasing hopcounter andmain-tainingminimum received hopcount from each of thelandmarks During this phase landmarks are calculat-ing average hopsize by dividing knowndistances fromother landmarks with respective hopcounts

(2) After the first phase is done every landmark makesanother (controlled) flooding with information ofnew estimated hopsize After the first reception ofhopsize from nearest landmark the node forwards itand drops all other incomingmessagesThen itmakesdistance estimation and finally estimates its position

These phases are implemented as two separate instances ofNodeAlgorithm subclass Since both phases are using thesame flooding protocol to share information we can definea generic algorithm class for flooding In Listing 1 there is theimplementation of base flooding protocol

In general NodeAlgorithm is structured as a set offunctions that are corresponding to all possible statuses Eachfunction should be able to handle all types of incomingmessages (defined by header) in a sequence of if conditionsSince this is a simple protocol with nodes remaining only in

one status ldquoFLOODINGrdquo and with only one type of messageldquoFloodrdquo the implementation is neat

Note that in this algorithm function calls (hooks) occurin three places These are initiator condition initiator dataand handle flood message By subclassing this protocol andimplementing missing hooks we can make algorithms forboth phases as presented in Listings 2 and 3

This behavior is in accordance with established DRYprinciple Even better every other algorithm using floodingprotocol can reuse this distributed algorithm solely by imple-menting its ownhooksThus object oriented paradigmnativeto Python can be exploited even in the distributed algorithmimplementation

52 Simulation The best way to initially test and if neededdebug newly defined algorithms is done by using interactiveconsole In Listing 4 one example of such interactive sessionis presented

Another advantage of running simulation in an interac-tive console is that on every exception the user is back atthe console There the user can issue a debug commandto enter a debug console and run commands inspect andmodify all data in every frameof the program stack that raisedthe exception

In addition to continuous execution algorithms can beexecuted step by step This is very useful when we want toanalyze algorithm in depth and inspect or modify objectsduring every step of the simulation Furthermore it can behandy in a situation when the algorithm does not executeas expected but the error is not explicit enough to raise anexceptionThere is an example of such execution in Listing 5

The second type of workflow is an automated experimentThe automated experiment is defined as a simple Python

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of Distributed Sensor Networks 11

script that is generating networks running simulations onthem and eventually storing network data on disk to beanalyzed later Example of one such script is given inListing 6

53 Analyze Data Objects can be inspected and data canbe analyzed at any moment For example during the net-work setup phase or after the network is loaded from diskit is convenient to visualize network topology It can bedone by calling show method defined on a network objectnetshow() Results are displayed in a new window like theone in Figure 4

Interactive console can be used to analyze experimentdata in more detail as presented in Listing 7 and Figure 5 orto return to investigate execution of different parts of specificexperiment

As a complement to console based workflows Pymoteincludes a graphical user interface for step-by-step algo-rithm simulation and visualization Interface screenshot ispresented in Figure 6 Through this interface users can

(i) save and load network files from disk(ii) run and control simulation step by step with imme-

diate visual feedback such as messages passing nodestatus and so forth

(iii) inspect different objects including network nodesand messages simply by clicking on them

(iv) customize display of network topology (edges labelsetc)

(v) visualize of custom in-node memory structures suchas trees

(vi) pan and zoom control and(vii) save visualized data in many different image formats

6 Conclusion

In this paper we have presented Pymote the library thatprovides support for simulation and analysis of distributedalgorithms built on top of comprehensive Python environ-ment Pymote is designed to allow rapid interactive testingof new algorithms their analysis and visualization whileminimizing developers time It supports both interactivealgorithm simulation and automation of experiments andprovides visualization tools for both It has been deliberatelykept simple easy to use and extensible

We plan to continue developing Pymote environment inseveral different directions as follows

(i) further development of graphical user interface func-tionalities for network setup and data analysis

(ii) implementation of some of the state of the art algo-rithms from the set of different fields and relatedproblems and

(iii) adding support for web based version of setup andsimulation execution

Figure 4 Network topology display

0 100 200 300 400 500 600

0

100

200

300

400

500

600

Figure 5 Localization error display

Figure 6 Graphical user interface

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

12 International Journal of Distributed Sensor Networks

The source code along with the documentation is availableas an open source project at httpsgithubcomdarbulapymote We hope to have enticed you to take a look at it useit or even participate in further development

References

[1] ns-2 httpwwwisiedunsnamns[2] I T Downard ldquoSimulating sensor networks in ns-2rdquo Tech Rep

Naval Research Laboratory 2004[3] Mannasim simulator httpwwwmannasimdccufmgbr[4] Omnet++ simulation system httpwwwomnetpporg[5] A Varga ldquoe omnet++ discrete event simulation systemrdquo in Pro-

ceedings of the European Simulation Multi-conference (ESM rsquo01)Prague Czech Republic June 2001

[6] A Boulis ldquoCastalia revealing pitfalls in designing distributedalgorithms in wsnrdquo in Proceedings of the 5th International Con-ference on Embedded Networked Sensor Systems (SenSys rsquo07)2007

[7] J-Sim httpssitesgooglecomsitejsimofficial[8] P Levis N Lee M Welsh and D Culler ldquoTOSSIM accu-

rate and scalable simulation of entire TinyOS applicationsrdquo inProceedings of the 1st International Conference on EmbeddedNetworked Sensor Systems (SenSys rsquo03) November 2003

[9] P Levis S Madden J Polastre et al ldquoTinyos an operatingsystem for sensor networksrdquo in Ambient Intelligence W WeberJ Rabaey and E Aarts Eds pp 115ndash148 Springer BerlinGermany 2005 httpdxdoiorg1010073-540-27139-2 7

[10] H Sundani H Li V K Devabhaktuni M Alam and PBhattacharya ldquoWireless sensor network simulators a surveyand comparisonsrdquo International Journal of Computer Networksvol 2 no 6 pp 249ndash265 2011

[11] E Egea-Lopez J Vales-Alonso A S Martinez-Sala P Pavon-Marino and J Garcia-Haro ldquoSimulation tools for wirelesssensor networksrdquo in Proceedings of the Summer SimulationMulticonference (SPECTS rsquo05) 2005

[12] S Mehta N Sulatan and K S Kwak ldquoNetwork and systemsimulation tools for next generation networks a case studyrdquoin Modelling Simulation and Identification A Mohamed EdInTech 2010

[13] L Shu M Hauswirth H C Chao M Chen and Y ZhangldquoNettopo a framework of simulation and visualization forwireless sensor networksrdquoAdHocNetworks vol 9 pp 799ndash8202011

[14] Algosensim httptcsunigechdokuphpcodealgosensimoverview

[15] A Kroeller D Pfisterer C Buschmann S Fekete and S Fis-cher ldquoShawn a new approach to simulating wireless sensornetworksrdquo in Proceedings of the Design Analysis and Simulationof Distributed Systems (DASD rsquo05) San Diego Calif USA 2005httpsgithubcomitmshawn

[16] Sinalgo httpdcgethzchprojectssinalgo[17] N Santoro Design and Analysis of Distributed Algorithms Par-

allel and Distributed Computing John Wiley amp Sons 2007[18] F Perez and B E Granger ldquoIpython a system for interactive

scientific computing computingrdquo Science and Engineering vol9 no 3 pp 21ndash29 2007

[19] E Jones T Oliphant P Peterson et al ldquoSciPy open source sci-entific tools for Pythonrdquo 2001 httpwwwscipyorg

[20] A A Hagberg D A Schult and P J Swart ldquoExploringnetwork structure dynamics and function using Net-workXrdquoinProceedings of the 7th Python inScience Conference (SciPy rsquo08)Pasadena Calif USA August 2008

[21] D Niculescu and B Nath ldquoDV based positioning in ad hocnetworksrdquo Telecommunication Systems vol 22 no 1ndash4 pp 267ndash280 2003

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of

International Journal of

AerospaceEngineeringHindawi Publishing Corporationhttpwwwhindawicom Volume 2014

RoboticsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Active and Passive Electronic Components

Control Scienceand Engineering

Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

International Journal of

RotatingMachinery

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporation httpwwwhindawicom

Journal ofEngineeringVolume 2014

Submit your manuscripts athttpwwwhindawicom

VLSI Design

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Shock and Vibration

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Civil EngineeringAdvances in

Acoustics and VibrationAdvances in

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Electrical and Computer Engineering

Journal of

Advances inOptoElectronics

Hindawi Publishing Corporation httpwwwhindawicom

Volume 2014

The Scientific World JournalHindawi Publishing Corporation httpwwwhindawicom Volume 2014

SensorsJournal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Modelling amp Simulation in EngineeringHindawi Publishing Corporation httpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Chemical EngineeringInternational Journal of Antennas and

Propagation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

Navigation and Observation

International Journal of

Hindawi Publishing Corporationhttpwwwhindawicom Volume 2014

DistributedSensor Networks

International Journal of