Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer...

59
Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia

Transcript of Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer...

Page 1: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Programming Abstractionsin

Wireless Sensor Networks

Professor Jack StankovicDepartment of Computer

ScienceUniversity of Virginia

Page 2: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ImportanceImportance

• Raise the level of abstraction• Move out of the domain of HW and

embedded systems programmer• Amplify the applications addressed –

programmed by domain experts• More reliable

• One of the most important areas of research to make WSN widely used

Page 3: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ContextContext

System DevelopmentEnvironment

Analysis/Tools

Use of SystemSQL/Queries

Actual Programming

Page 4: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Programming ModelsProgramming Models

• Environmental (domain specific, tracking, monitoring, …)– EnviroSuite

• Data/Database Centric - Queries– SQL, TinyBD, Cougar– Statistical and range queries

• Middleware APIs and Services– Group Management, Token machine language

(Regiment), Milan (QoS based), Agilla– Support for other models

• Components• Database• Event • Agent

Page 5: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Programming ModelsProgramming Models

• Components– nesC

• Virtual Machines– Mate

• Functional Macro-programming– Regiment (regions, streams)

• (Mobile) Scripts– SensorWare

• Extend TCL interpreter with support for commands such as query, send, wait, replicate, …

• Provides execution environment for Scripts

• Events– Publish/subscribe– DSWare, SNEDL, Impala

Page 6: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Programming ModelsProgramming Models

• Model Driven• Swarm computing• Java• Linux

Page 7: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Program What?Program What?

• Low level protocols (MAC, routing, …)

• Middleware services• Application• Use of system

– Queries

Blurs

Page 8: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Sensor/Actuator/CommunicationSensor/Actuator/Communication

HeterogeneousHomogeneous

Resource management, team formation, networking, aggregation, …

Severe constraints power, memory, bandwidth, cpu, cost, ...

Page 9: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ReliabilityReliability

• Make an unreliable platform reliable!!

• HW (motes) are/will be very reliable

• Environment/wireless communication will not be reliable

Page 10: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

AbstractionsAbstractions

• Program as a whole – not individual nodes

• Hide details (which ones, expose what)– Single node decisions– Asynchrony– Race conditions– False alarms– Retries– Physical details (e.g., location, sensor characteristics,

…)– Faults– Scale– Storage locations

Page 11: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Other QuestionsOther Questions

• How to disseminate programs– Flooding, viral programs, gossip

protocols

• Efficient on small, embedded, real-time devices

• Long-lived systems – Disseminate again– Disseminate pieces of executable

Page 12: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Environmental Paradigm

Environmental Paradigm

• Current Paradigms– Single node abstractions– Explicit interactions between nodes– Read sensor data; fuse data; move data– Set actuators

• Environmental Paradigm– Reflect the physical world directly– Virtual world of entities (fire, people, vehicles,

pesticide, velocity, location, areas, …)

Page 13: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

EnviroSuiteEnviroSuite

• Way to think– Events – measurable environmental activities– Events mapped to programming objects– Computation is attached to these objects

• Report location, compute velocity, …

• Library provides protocols for sensor data processing, object maintenance, inter-object coordination, aggregation mechanisms, etc.

Page 14: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

personevent

Base Station

vehicleevent

object type: VEHICLE object ID: vehicle01

method:report location to thebase station every 5seconds

attribute: location

object type: PERSON object ID: person01

method:turn on a nearby micro-phone if current locationis less than 1 mile awayfrom the base station

attribute: location

mapping

EnviroSuite

Page 15: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

EnviroSuiteEnviroSuite

event-object VEHICLE { object_creation_condition = ferrous object && background sound object_resolution = 6; // minimal distance between // two events object_function = report.Location; object_function = report.Speed;}

ferrous object && background sound

This statement is supported by drivers in a library:

Page 16: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Level of Knowledge Required

Level of Knowledge Required

• Ferrous object– Which signal processing module?– What parameter specifications need to

be made?

– We are programming in an application that interacts with the environment – how divorced from that fact can the programmer be?

Page 17: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Routing Protocol - SPEEDRouting Protocol - SPEED

E2E Di stance

j

FS

iD

Actual Speed

Speed todestination(Set Point )

E2E Delay is bound by E2E Distance/Speed SetPoint

USES VELOCITY

Expose Velocity

Page 18: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Radio Irregularity Radio Irregularity

DOI = Degree of Irregularity

DOI = 0.05 DOI = 0.2

Do NotExpose

Page 19: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Data/Database CentricData/Database Centric

• Query Processing Architectures (SQL-based)– Process the queries– Route the queries– Retrieve information efficiently (in time and

with low energy costs)

• Storage Architectures– How/where to store collected data from

sensors– In-network storage

• At local node• Data centric – name the data and hash to a location• Multi-resolution (hierarchies)

Page 20: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Example of QueryExample of Query

• Retrieve, every 30 seconds, the rainfall level if it is greater than 50 mm

SELECT R.Sensor.getRainfallLevel()FROM RFSensors RWHERE R.Sensor.getRainfallLevel() > 50AND $every(30);

Many other extensions to query capabilityincluding statistical and range based queries

Page 21: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Content Dissemination - Caching

Content Dissemination - Caching

Information source(Aperiodic updates)

Data replicas(Placement?)

Receivers(Refresh Rate,Accuracy)

Goal: Find the optimal communication path to send sensory data from a monitored source to multiple (mobile) sinks such that energy usage is minimized.

Page 22: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Middleware APIsMiddleware APIs

• Group Management– Create– Terminate– Merge– Join/Leave– Assign function

• Track target• Classify target• Map temperature region

– Consensus

Page 23: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Group ManagementGroup Management

IR Camera

Page 24: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Group ManagementGroup Management

IR Camera

Page 25: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Examples: Tracking and

Map Regions

Examples: Tracking and

Map Regions

Base Station

Page 26: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Group Management - APIGroup Management - API

– Create_Group(name,function,criterion,atleast,accuracy) - implicit and explicit

– Destroy_Group(name)– Join()– Leave()– Merge()– Move_COG()– Expand() -- to gain sensing confidence– Shrink() -- to save power– Commit(grp_ID) - to synchronize group re-

configurations

Page 27: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Other ServicesOther Services

• Naming• Directory• Location• Monitor• Configure• …

Page 28: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

QuestionQuestion

• How general/specific should a middleware service be?

Function of severity of resource constraints

Severe

Careful interoperabilityExactly what is needed and no more!

ExcessCapacity

More general servicesUseable by many

Page 29: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Functional Macro-Programming (Regiment)

Functional Macro-Programming (Regiment)

• Apply function to data from a stream• Aggregate samples from a stream• Filter stream• Define/Disseminate Events from a

area (region)

AreaBaseStationAbstract

Regions

Streams

Page 30: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Regiment (cont.)Regiment (cont.)

• Set frequency• Fidelity• Contour finding• Combine regions• Anchors (leaders for a region)

• Functional Language

Page 31: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

RegimentRegiment

• Abstractions– Streams, Spaces, Events, Anchors

(leader for a region), When (time)– Regions – group of nodes with some

relationship to each other• Like the function for a group in previous

middleware slides• Ex. – all nodes within k radio hops of node N• Ex. – all nodes whose proximity sensor

records a hit

Page 32: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Token Machine Language (TML)Token Machine Language (TML)

• Kind of middleware to support Regiment PL

• Regiment– Compiler transforms a macro-program

written in functional style into an efficient nodal program based on a token machine

– Token machine is an intermediate language (target) for Regiment

Page 33: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

TMLTML

NODE

Token Handlers –Atomic Tasks

Token from Network

Name of Token HandlerDataGenerate

Tokens

Page 34: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Components - nesCComponents - nesC

• Underlying execution model (TinyOS)– Tasks and Events– Split phase operation

• Modules– Component Specification – Interfaces– Component Implementation

• Configurations– Wiring Diagrams

Page 35: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Tasks and EventsTasks and Events

• Tasks– Deferred computation– Non-preemptable by other tasks– Scheduled FCFS from task queue

• Events– Execution of an interrupt handler– Runs to completion– Can preempt tasks and can be

preempted by other events

Page 36: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Application ExampleApplication Example

RFM

Radio byte

i2c

Tempphoto

Messaging Layer

clocksbit

byte

packet Radio Packet

Routing Layer

sensing applicationapplication

HW

SW

ADC

messaging

routing

UART Packet

UART byte

Page 37: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Components - nesCComponents - nesC

• The nesC model:– Interfaces:

• uses• provides

– Components:• modules• configurations

• Application:= graph of components

Component A

Component B

ComponentD

Component C

Application

configurationconfigurationComponent

E

ComponentF

EnviroTrack on top ofnesC

Page 38: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

InterfacesInterfaces

• Examples of interfaces:

interface StdControl { command result_t init (); command result_t start (); command result_t stop ();}

interface Timer { command result_t start (char type, uint32_t

interval); command result_t stop (); event result_t fired ();}

interface SendMsg { command result_t send (uint16_t

addr, uint8_t len, TOS_MsgPtr

p); event result_t sendDone ();}

interface ReceiveMsg { event TOS_MsgPtr receive (TOS_MsgPtr

m);}

StdControl.nc Timer.nc

ReceiveMsg.ncSendMsg.nc

Page 39: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ModulesModules

• Implements a component’s specification with C code:

module MyCompM { provides interface X; provides interface Y; uses interface Z;}implementation {…// C code}

MyCompM.nc

Page 40: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ModulesModules

• Posting Tasks:

module BlinkM {…}implementation {… task void processing () { if(state) call Leds.redOn(); else call Leds.redOff(); }

event result_t Timer.fired () { state = !state; post processing(); return SUCCESS; }…} BlinkM.nc

Page 41: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Configuration ExampleConfiguration Example

• Blink application• Wiring Example

configuration BlinkC { }

implementation { components Main, BlinkM, ClockC,

LedsC;

Main.StdControl->BlinkM.StdControl; BlinkM.Clock->ClockC; BlinkM.Leds->LedsC;}

ClockC LedsC

Main

BlinkC

BlinkM

BlinkC.nc

Page 42: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Future?Future?

• Different component models?

• nesC components are “low level” with a fair amount of syntax

• Envirosuite, Mate, etc. do build on top of nesC

Page 43: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Mate – Virtual Machine Mate – Virtual Machine

TinyOS

Mate VM(interprets)

24 Instruction ProgramsEach instructionexecutes as task(slow)

Code capsules

Page 44: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Code CapsulesCode Capsules

• One capsule = 24 instructions• Fits into single TOS packet

– Energy efficient

• Atomic reception• Code Capsule

– Type and version information– Types: send, receive, timer, subroutine

• Larger programs – use several capsules

Page 45: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

ValueValue

• Re-programmability– Re-task a network

• Parameter adjustment

• Self-replication– One of the special instructions on the

VM is forward (which supports a viral-like infection of the entire network)

• Incremental addition of new nodes

Page 46: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Propagation ExamplePropagation Example

Page 47: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Node Enters the NetworkNode Enters the Network

Page 48: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Instruction SetInstruction Set

One byte per instruction Three classes: basic, s-type, x-type

•basic: arithmatic, halting, LED operation•s-type: messaging system•x-type: pushc, blez

8 instructions reserved for users to define Instruction polymorphism

•Example: add(data, message, sensing)

Page 49: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

User Defined Instructions User Defined Instructions

TinyOS

Mate VM(interprets)

24 Instruction Programs

Code capsules InstructionsUnderstood byMate

User defined

1 2 3 4

1 3

3

1

- Sound alarm

- Write to flash

Page 50: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Mate ArchitectureMate Architecture

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receiv

e

Events

gets/sets

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receiv

e

Events

gets/sets

Co

de

OperandStack

ReturnStack

PC

Co

de

OperandStack

ReturnStack

PC

Stack based architecture Operand stack Return address stack

Three events/execution contexts:•Clock timer•Message reception•Message send

Page 51: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Code Example(1)Code Example(1)

• Display Counter to LEDgets # Push heap variable on stackpushc 1 # Push 1 on stackadd # Pop twice, add, push resultcopy # Copy top of stacksets # Pop, set heappushc 7 # Push 0x0007 onto stackand # Take bottom 3 bits of valueputled # Pop, set LEDs to bit patternhalt #

Page 52: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Code Example(2)Code Example(2)

• Sense and Sendpushc 1 # Light is sensor 1sense # Push light reading on stackpushm # Push message buffer on stackclear # Clear message bufferadd # Append reading to buffersend # Send message using built-inhalt # ad-hoc routing system

Page 53: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

TinyOS Sense and Send

TinyOS Sense and Sendevent result_t Timer.fired() {

if (state == IDLE && call Photo.sense()) {state = SENSE;}return SUCCESS;

}event result_t Photo.dataReady(uint16_t data) {

if (state == SENSE) {packet->reading = data;if (call SendMsg.send(packet, sizeof(DataBuf)) {

state = SENDING;} else {state = IDLE;}

}return SUCCESS;

}event result_t SendMsg.sendDone(TOS_MsgPtr msg) {

if (state == SENDING) {state = IDLE;}return SUCCESS;

}

Page 54: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Component BreakdownComponent Breakdown

• 7286 bytes code, 603 bytes RAM

Page 55: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

QuestionsQuestions

• What should a programmer see?– New language– New middleware– Services– Components– Abstracts models– All the above– None of the above

Page 56: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

QuestionsQuestions

• What would have made your life easier in doing the programming assignments?

• What makes it easier to get the system to work?– Debugging tools

• Initially (in programming environment)• On real platform

Page 57: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

IdeasIdeas

• Move code to node – executes on middleware, VM, interpreter

• Domain specific (good or bad?)• Regions/Streams• Expose/Hide?

– Performance– Physical systems

• Disseminate

Page 58: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

SummarySummary

• Very active area– It must be

• Solutions can have large impact– Applications programmers rather than

system experts

• Standard?– Analogy to real-time computing and

programming languages?• WSN-Java?

Page 59: Programming Abstractions in Wireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia.

Final QuestionFinal Question

• Will there be GP WSNs (and how might that affect the programming abstractions)?