Macro-programming Wireless Sensor Networks using Kairos

40
Embedded Networks Laborato Macro-programming Wireless Sensor Networks using Kairos Ramesh Govindan, Omprakash Gnawali USC Ramakrishna Gummadi

description

Macro-programming Wireless Sensor Networks using Kairos. Ramakrishna Gummadi. Ramesh Govindan, Omprakash Gnawali USC. What is Macro-programming?. Writing a single centralized program that describes the global behavior of a task on the entire sensor network - PowerPoint PPT Presentation

Transcript of Macro-programming Wireless Sensor Networks using Kairos

Embedded Networks Laboratory

Macro-programming Wireless Sensor Networks using Kairos

Ramesh Govindan, Omprakash Gnawali

USC

Ramakrishna Gummadi

Embedded Networks Laboratory

What is Macro-programming?

Writing a single centralized program that describes the global behavior of a task on the entire sensor network

Example: To build a shortest path tree rooted at N, the centralized program must capture the global behavior:

For each node n in the network, its parent is that

neighbor whose distance to N is shortest.

Embedded Networks Laboratory

What is Macroprogramming? (contd…)

The macroprogramming environment translates this centralized program into programs that execute on

individual nodes after adding some runtime support

CentralizedProgram

Localized BinaryCompiler

Link + distributewith runtime Link + distribute

with runtime

Link + distributewith runtime

In the shortest path tree example, the localized binary might poll the node’s neighbors about current

distances to N, and process and pick the correct parent

Embedded Networks Laboratory

Advantages

• Easier to describe the centralized version of a distributed computation– Top-down, linear

• Easier to reason about correctness– Can even construct formal proofs on a single program

using standard techniques (Hoare logic, etc.)

Embedded Networks Laboratory

Main Challenges

• Abstractions– Basic

• How should the network be exposed, how to do distributed control and data flow, etc.

• How to be language agnostic

– Advanced• Allow dynamic user-level control of heterogeneity, resource management,…

• Robustness– How to programmably discover, recover from, and tolerate faults

• Efficiency– How to minimize energy consumption by optimizing network traffic

Embedded Networks Laboratory

Main Challenges

• Abstractions– Basic

• How should the network be exposed, how to do distributed control and data flow, etc.

• How to be language agnostic

– Advanced• Allow dynamic user-level control of heterogeneity, resource management,…

• Robustness– How to programmably discover, recover from, and tolerate faults

• Efficiency– How to minimize energy consumption by optimizing network traffic

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Results• Conclusion

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Results• Conclusion

Embedded Networks Laboratory

Taxonomy of Sensor Network Programming Research

Macro-programming

Abstractions Support

Globalbehavior

LocalBehavior

Composition Distribution& Safe

Execution

AutomaticOptimization

Node-independent• TAG, Cougar• DFuseNode-dependent• Kairos• Regiment• Split-C

Data-Centric• EIP, State-spaceGeometric• Regions, Hood

SensorwareSNACK Mate

TofuTrickleDeluge

Impala

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Results• Conclusion

Embedded Networks Laboratory

Kairos Abstractions

• Goals (at least for now)– Small, yet expressive set of abstractions

– Abstractions for facilitating expressivity rather than performance tuning

• Three constructs– Addressing arbitrary nodes

– Iterating through one-hop neighbors of a node

– Reading remote variables at arbitrary nodes• Eventual consistency semantics

Embedded Networks Laboratory

Kairos Abstractions (contd..)

• Abstractions implemented as programming primitives– First-class extensions to host language, language-agnostic

• Nodes logically named using integer identifiers– node datatype with operators for equality, ordering, type

testing, etc.– node_list iterator data type for manipulating sets of

nodes

• One-hop neighbors using a get_neighbors()call at runtime– Can construct arbitrary topologies by iteration

Embedded Networks Laboratory

Kairos Abstractions (contd..)

• Remote data access ability– variable@node notation

– No restrictions on which remote variables may be read where and when, modulo language scoping, lifetime, and access rules

– Effectively, a shared-memory abstraction across nodes

– Can implicitly capture distributed data flow and control flow coordination

– Only remote reads, not remote writes• Eliminates a large class of subtle distributed programming bugs

due to locking, race conditions, etc.

Embedded Networks Laboratory

Kairos Programming Architecture

Runtimes loosely synchronize cached copies with one another. ~ 1 synchronization per 10,000 instructions for 10Mhz processor,

1000 samples/sec

Multi-hop wireless network

CentralizedProgram

Annotatedbinary

Kairos pre-processor+ language compiler

Program Kairos runtime

Threadof

control

syncread/write

Cached Objects

Managed Objects

Queue Manager

Requests Replies

Sensor Node

Link + distributeto runtime

Program Kairos runtime

Threadof

control

syncread/write

Cached Objects

Managed Objects

Queue Manager

Requests Replies

Sensor Node

Link + distributeto runtime

Link + distributeto runtime

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Results• Conclusion

Embedded Networks Laboratory

Kairos Example1: void buildtree(node root)2: node parent, self;3: unsigned short dist_from_root;4: node_list neighboring_nodes, full_node_set;5: unsigned int sleep_interval=1000; //Initialization6: full_node_set=get_available_nodes();7: for (node temp=get_first(full_node_set); temp!=NULL;

temp=get_next(full_node_set))8: self=get_local_node_id();9: if (temp==root) 10: dist_from_root=0; parent=self;11: else dist_from_root=INF;12: neighboring_nodes=create_node_list(get_neighbors(temp));13: full_node_set=get_available_nodes();14: for (node iter1=get_first(full_node_set); iter1!=NULL;

iter1=get_next(full_node_set))15: for(;;) //Event Loop16: sleep(sleep_interval);17: for (node iter2=get_first(neighboring_nodes); iter2!=NULL;

iter2=get_next(neighboring_nodes))18: if (dist_from_root@iter2+1<dist_from_root)19: dist_from_root=dist_from_root@iter2+1;20: parent=iter2;

Embedded Networks Laboratory

Kairos Example (contd..)

• Program as written is flexible– To start this tree construction at a pre-set time that is

programmed into a base station node with id 0, add a single line before line 7: • sleep(starting_time@0-get_current_time())

• Illustrates eventual consistency on dist_from_root• Sensitive to node failures at lines 17-19

– Can be re-written to be more robust

– Ideally, we desire automated and transparent recovery from such faults

– Current work

Embedded Networks Laboratory

Vehicle Tracking1: Start (at t = 0) with assuming that the master can be any node in the network, and

with an initial estimate for P(xt |Zt ) that represents the 2-dimensional grid probabilities of vehicle location xt given the past history of sensed input Zt

2: Calculate the new probability of vehicle location at (t +1) P(xt+1|Zt ) by using the belief propagation rule, the vehicle dynamics P(xt+1|xt ), and position estimates P(xt |Zt

) 3: Sense the environment Zt+1, and compute the grid probability P(Zt+1|xt+1) of receiving

such an input from the vehicle given our estimate of its location xt+1

4: Compute the Bayesian grid quantity P(xt+1|Zt+1) that represents the new probabilities of vehicle location on the grid after incorporating the latest sensor sample into the history Zt+1 from P(xt+1|Zt ) calculated in step 2, and P(Zt+1|xt+1) calculated in step 3

5: For each node k in the neighborhood of the master, compute the information utility Ik from the above quantities

6: Pick as next master that node kmaster that maximizes Ik and, therefore represents the node closest to the vehicle, and make that the new vehicle tracking master; goto step 2

Embedded Networks Laboratory

void track_vehicle() boolean master=true;

float grid[MAX_X][MAX_Y], p(xt|zt)[MAX_X][MAX_Y],p(xt+1|zt)[MAX_X][MAX_Y],

p(zt+1|xt+1)[MAX_X][MAX_Y], p(xt+1, zkt+1|zt )[MAX_X][MAX_Y],

p(zkt+1|zt ), p(xt+1|zt+1)[MAX_X][MAX_Y];

…self=get local node id();… node_list full_node_set=get_available_nodes(); for (node iter=get_first(full_node_set); iter!=NULL;iter=get_next(full_node_set)) for(;;)

sleep(); if (master) for (int x=0; x<MAX X; x++) for (int y=0; y<MAX Y; y++)

p(xt+1|zt)[x][y]=…

…zt+1=sense_z();… node_list neighboring_nodes=get_neighbors(iter); for (node temp=get first(neighboring nodes); temp!=NULL;

temp=get next(neighboring nodes))

…p(xt+1, zkt+1|zt )[x][y]=p(zt+1|xt+1)[x][y]@temp·p(xt+1|zt)[x][y];…

Pseudocode

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Results• Conclusion

Embedded Networks Laboratory

Implementation• Compiler generates code to call into runtime• Runtime manages reads/writes to managed objects,

and reads to cached objects• In a compiled version, need to implement the binary

interface between application and runtime (RBI) to copy these reads and writes

Program Kairos runtime

Threadof

control

syncread/write

Cached Objects

Managed Objects

Queue Manager

Requests Replies

Sensor Node

Request/Reply Object

Embedded Networks Laboratory

Implementation

• Python extended for Kairos• Stargate-based, with motes as radio interfaces• Python extensibility interfaces to redirect to runtime• Embeds python interpreter using embedding API’s• Intelligent push/pull in runtime

Python interpreter Comm API

Runtime

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Evaluation Results• Conclusion

Embedded Networks Laboratory

Testbed Setup

•16 Stargate nodes with Kairos using Emstar for E2E routing, topology management, and reliability

•Emstar uses a Mica2 mote on the Stargate as the NIC

•Single physical hop, multiple logical hops, S-MAC as the MAC layer

•8-node array of Mica2dots connected through a multiport serial card running 8 emstar processes

•/dev/node/<id> interface for send()/recv(); object accesses marshaled into messages by the runtime

•Ack-based E2E reliability, with multiple outstanding messages and duplicate sequence number detection

Embedded Networks Laboratory

Routing Tree Performance

• Compared against OPP (baseline)– Refined Directed Diffusion; traffic efficient and code

optimized– Flood interests (requests), unicast responses (data)

• Measure Convergence Time, Overhead, and Stretch– OPP doesn’t necessarily produce shortest paths, so quantify

stretch

2 3 4

5 6 7 8

9 10 11 12 13 14 15 16

17 18 19 20 21 22 23 24

Embedded Networks Laboratory

Routing Tree Performance (contd..)

0

5

10

15

20

25

0 5 10 15 20 25

Number of nodes

Co

nv

erg

en

ce

Tim

e (

S)

Time K (after)Time OPP (after)

Time OPP (before)

Time K (before)

Kairos < 1.3x OPP

Embedded Networks Laboratory

Routing Tree Performance (contd..)

0

5

10

15

20

25

30

35

40

0 5 10 15 20 25

Number of Nodes

Ov

erh

ea

d (

by

tes

)

Overhead K (after)

Overhead OPP (after)

Overhead OPP (before)

Overhead K (before)

Kairos < 2x OPP

Embedded Networks Laboratory

Routing Tree Performance (contd..)

OPP Stretch Higher as Network Traffic Increases

Embedded Networks Laboratory

Localization

• Hard-coded pair-wise distances from simultaions

• Perturbed distances with white Gaussian (=20mm)

• Two scenarios for 24 nodes– Localization error when all nodes are localizable

– Vary % of initial beacons

Embedded Networks Laboratory

Localization (contd..)

0

5

10

15

20

25

30

35

40

45

10 12 14 16 18 20 22 24 26

Number of Nodes

Av

era

ge

Err

or

(cm

)

Error decreases with increasing network size

Embedded Networks Laboratory

Localization (contd..)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80

% of Beacons

% o

f R

es

olv

ed

No

de

s

% of resolved nodes increases with increasing beacon %

Embedded Networks Laboratory

Vehicle Tracking

• Same vehicle tracking parameters as used in Reich et al. [1] for grid size, vehicle speed, sound RMS, acoustic sensor measurement simulations, sensor placement and connectivity, and DoA sensor measurements

• Measure location error and standard deviation

Line of vehicle movement

Embedded Networks Laboratory

K ||xMMSE −x|| ||x− xMMSE||2 Avg. Overhead (bytes)

12 42.39 1 875.47 135

14 37.24 1297.39 104

16 34.73 1026.43 89

18 31.52 876.54 76

20 28.96 721.68 67

22 26.29 564.32 60

24 24.81 497.58 54

Vehicle Tracking (contd..)

Embedded Networks Laboratory

% of DOA ||xMMSE −x|| ||x− xMMSE||2 Avg. Overhead (bytes)0.00% (0/24) 35.12 1376.57 142.38.33% (2/24) 31.37 902.64 113.416.66% (4/24) 28.45 779.28 108.625.00% (6/24) 25.73 629.43 102.933.33% (8/24) 23.91 512.76 99.141.66% (10/24) 22.85 478.39 97.250.00% (12/24) 21.96 443.72 94.558.33% (14/24) 20.98 421.27 92.766.66% (16/24) 20.07 387.23 89.475.00% (18/24) 19.67 342.54 85.683.33% (20/24) 19.24 312.09 82.291.67% (22/24) 18.97 292.76 79.7100% (24/24) 18.22 265.18 77.3

Vehicle Tracking (contd..)

Embedded Networks Laboratory

Talk Overview

• Discuss Related Work• Introduce Kairos• Give Examples in Kairos• Describe Implementation• Show Evaluation Results• Conclusion

Embedded Networks Laboratory

Conclusion

• Initial explorations into a particular model of macroprogramming

• Kairos is simple, expressive, flexible, and has decent real-world performance compared to hand-coded versions

• However– Doesn’t fully shield programmers from needing to understand

performance

– Compiler and runtime are primitive, and don’t optimize for specific communication patterns or topologies

– Lacks runtime resource control for predictability

– Mote implementation not yet available

Embedded Networks Laboratory

Backup Slides

Embedded Networks Laboratory

Localization Using Cooperative Multilateration

B

B B

BU

U

UB

BB

U U

LocalizableUnlocalizable

Example Localization

Embedded Networks Laboratory

Centralized Algorithm for Localization Using Cooperative Multilateration

1: At each node in the network, try to build a localization graph by starting with the node itself and adding all next_hop neighbors of all current nodes in the graph

2: Continue this process of building the localization graph at each unlocalized node, and test whether the graph it is currently considering is localizable

3: if NO then

4: The graph does not yet have enough number of beacon or localized nodes, so the node extends the localization graph with all the next_hop neighbors of the leaf nodes in the graph with the hope of acquiring more localized or beacon nodes in the next round

5: Go back to Step 2) if it has managed to extend the graph with more nodes; otherwise it means the localization graph is the entire network that is not localizable, so give up

6: else if YES then

7: Mark all the nodes in the localization graph as having been localized, and arrange to propagate this information eventually to all the newly localized nodes

8: end if

Embedded Networks Laboratory

Pseudocode1: void iterativeMultilateration()2: boolean localized=false, not_localizable=false, is_beacon=GPS_available();3: node self=get_local_node_id();4: graph subgraph_to_localize=NULL;5: node_list full_node_set=get_available_nodes();6: for (node iter=get_first(full_node_set); iter!=NULL;

iter=get_next(full_node_set))) //At each node, start building a localization graph7: participating_nodes=create_graph(iter);8: node_list neighboring_nodes=get_neighbors(iter);9: while ((!localized || !is_beacon) && !not_localizable)10: for (node temp=get_first(neighboring_nodes); temp!=NULL;

temp=get_next(neighboring_nodes))//Extend the subgraph with neighboring nodes

11: extend_graph(subgraph_to_localize, temp, localized@temp2||is_beacon@temp2?beacon:unknown);

//See if we can localize the currently available subgraph12: if (graph newly_localized_g=subgraph_check(subgraph_to_localize))13: node_list newly_localized_l=get_vertices(newly_localized_g);14: for (node temp=get_first(newly_localized_l); temp!=NULL;

temp=get_next(newly_localized_l))15: if (temp==iter) localized=true;16: continue; //If not, add nodes adjacent to the leaves of the accumulated subgraph and try again17 node_list unlocalized_leaves;18: unlocalized_leaves=get_leaves(subgraph_to_localize);19: boolean is_extended=false;20: for (node temp=get_first(unlocalized_leaves); temp!=NULL;

temp=get_next(unlocalized_leaves))21: node_list next_hop_l=get_neighbors(temp);22: for (node temp2=get_first(next_hop_l); temp2!=NULL;

temp2=get_next(next_hop_l))23: extend_graph(subgraph_to_localize, temp2,

localized@temp2||is_beacon@temp2?beacon:unknown);24: is_extended=true;25: if (!is_extended) not_localizable=true;