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

Programming Abstractions in Wireless Sensor Networks

Embed Size (px)

DESCRIPTION

Programming Abstractions in Wireless Sensor Networks. Professor Jack Stankovic Department of Computer Science University of Virginia. Importance. Raise the level of abstraction Move out of the domain of HW and embedded systems programmer - PowerPoint PPT Presentation

Citation preview

Page 1: Programming Abstractions in Wireless Sensor Networks

Programming Abstractionsin

Wireless Sensor Networks

Professor Jack StankovicDepartment of Computer

ScienceUniversity of Virginia

Page 2: Programming Abstractions in Wireless Sensor Networks

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

ContextContext

System DevelopmentEnvironment

Analysis/Tools

Use of SystemSQL/Queries

Actual ProgrammingApplications prog.

Systems prog.

Page 4: Programming Abstractions in Wireless Sensor Networks

Programming Models (9)

Programming Models (9)• Environmental (domain specific ->

tracking, monitoring environment, medical…)– 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

Programming Models (9)

Programming Models (9)

• 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

Programming Models (9)

Programming Models (9)

• Networks of Networks– Across the Internet

Page 7: Programming Abstractions in Wireless Sensor Networks

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 8: Programming Abstractions in Wireless Sensor Networks

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 9: Programming Abstractions in Wireless Sensor Networks

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 10: Programming Abstractions in Wireless Sensor Networks

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 11: Programming Abstractions in Wireless Sensor Networks

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 12: Programming Abstractions in Wireless Sensor Networks

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 13: Programming Abstractions in Wireless Sensor Networks

Programming ModelProgramming Model

TrackingObjects

Context Type: CarContext Label

Aggregate State

Variables

TrackingObjects

Context Type: PersonContext Label

Aggregate State

Variables

Network Abstraction Layer

ExternalEntity

Page 14: Programming Abstractions in Wireless Sensor Networks

Contexts and ObjectsContexts and Objects

• Contexts: Encapsulate entity state and tracking objects

• Tracking objects: Perform entity-specific computation, communication and sensing

HistoryEntity

ID

State

ContextAttached Tracking Objects

Programmer’sView

Page 15: Programming Abstractions in Wireless Sensor Networks

CommunicationCommunication

State

Context

Programmer’sView

Context

Attached Tracking Objects

Attached Tracking Objects

Objects may export methods for remote invocation

Page 16: Programming Abstractions in Wireless Sensor Networks

Attaching ObjectsAttaching Objects

HistoryEntity

ID

Programmer’sView

Sensee( ) = TRUELeader

Members

Statee( ) = average position

begin context tracker sense: magnetic() + motion(); state: location = avg (position,3,2);end

begin object reporter send (state, home);end

Attach

begin object mic turn-on microphone send (sound, home);end

Page 17: Programming Abstractions in Wireless Sensor Networks

SummarySummary

• Program in C++ or Java – like language

• Library supports domain specific abstractions– E.g., Java Swing supports programming

GUIs

• Pre-compiler maps programming abstractions to underlying “system”– E.g., could map to nesC and TinyOS

Page 18: Programming Abstractions in Wireless Sensor Networks

MiddlewareMiddleware

Page 19: Programming Abstractions in Wireless Sensor Networks

Middleware APIsMiddleware APIs

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

• Track target• Classify target• Map temperature region

– Consensus

Page 20: Programming Abstractions in Wireless Sensor Networks

Group ManagementGroup Management

IR Camera

Page 21: Programming Abstractions in Wireless Sensor Networks

Group ManagementGroup Management

IR Camera

Page 22: Programming Abstractions in Wireless Sensor Networks

Examples: Tracking and

Map Regions

Examples: Tracking and

Map Regions

Base Station

Page 23: Programming Abstractions in Wireless Sensor Networks

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 24: Programming Abstractions in Wireless Sensor Networks

API for Other ServicesAPI for Other Services

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

Page 25: Programming Abstractions in Wireless Sensor Networks

Virtual Machine - Mate Virtual Machine - Mate

TinyOS

Mate VM(interprets)

24 Instruction ProgramsEach instructionexecutes as task(slow)

Code capsules

Page 26: Programming Abstractions in Wireless Sensor Networks

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 27: Programming Abstractions in Wireless Sensor Networks

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 28: Programming Abstractions in Wireless Sensor Networks

Propagation ExamplePropagation Example

Page 29: Programming Abstractions in Wireless Sensor Networks

Node Enters the NetworkNode Enters the Network

Page 30: Programming Abstractions in Wireless Sensor Networks

Instruction SetInstruction Set

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

•basic: arithmetic, 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 31: Programming Abstractions in Wireless Sensor Networks

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 32: Programming Abstractions in Wireless Sensor Networks

Mate ArchitectureMate Architecture

0 1 2 3

Subroutines

Clock

Send

Receive

Events

gets/sets

0 1 2 3

Subroutines

Clock

Send

Receive

Events

gets/sets

Code

OperandStack

ReturnStack

PC

Code

OperandStack

ReturnStack

PC

Stack based architecture Operand stack Return address stack

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

Page 33: Programming Abstractions in Wireless Sensor Networks

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 34: Programming Abstractions in Wireless Sensor Networks

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 35: Programming Abstractions in Wireless Sensor Networks

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 36: Programming Abstractions in Wireless Sensor Networks

Component BreakdownComponent Breakdown

• 7286 bytes code, 603 bytes RAM

Page 37: Programming Abstractions in Wireless Sensor Networks

SummarySummary

• Layer of software that can interpret programs

• Easy to download new programs• Power of VM will relate to ease of

programming– E.g., Java versus Mate

Page 38: Programming Abstractions in Wireless Sensor Networks

Networks of NetworksNetworks of Networks

BodyNetworks

Road and Street Networks

Battlefield Networks

VehicleNetworks

IndustrialNetworks

BuildingNetworks

Environmental Networks Heterogeneous

Networks withSensors and Actuators

(HNSAs)

Page 39: Programming Abstractions in Wireless Sensor Networks

Motivating ApplicationsMotivating Applications

Home

Home Application 1:Musical TrackingHome Application 2:

Alarm System

Page 40: Programming Abstractions in Wireless Sensor Networks

Motivating ApplicationsMotivating Applications

HomeForest

Forest Application 1:Temperature MonitoringForest Application 2:

Animal Tracking

Page 41: Programming Abstractions in Wireless Sensor Networks

Motivating ApplicationsMotivating Applications

Road

HomeForest

MESSAGE

Road Application 1:Traffic MonitoringRoad Application 2:

Traffic Law Enforcement

Page 42: Programming Abstractions in Wireless Sensor Networks

Motivating ApplicationsMotivating Applications

Road

HomeForest

Cross Network Application 1:Protection Against Wild Animals

Page 43: Programming Abstractions in Wireless Sensor Networks

Motivating ApplicationsMotivating Applications

Road

HomeForest

MESSAGECross Network Application 2:Wild Animal & Automobile Protection

Page 44: Programming Abstractions in Wireless Sensor Networks

System ArchitectureSystem Architecture

Internet

LocalTransportProtocol

LocalTransportProtocol

ProgrammingStation

Server Server

Nodes Nodes

Page 45: Programming Abstractions in Wireless Sensor Networks

System ArchitectureSystem Architecture

Internet

LocalTransportProtocol

LocalTransportProtocol

ProgrammingStation

Server Server

Nodes NodesInformation about

Services, InterfacesLocation

Page 46: Programming Abstractions in Wireless Sensor Networks

System ArchitectureSystem Architecture

Internet

ProgrammingStation

Server Server

Nodes Nodes

LocalTransportProtocol

LocalTransportProtocol

High levelProgramming

Language

EXE

High LevelVirtual Machine

High LevelVirtual Machine

Low LevelVirtual Machine

Low LevelVirtual Machine

Page 47: Programming Abstractions in Wireless Sensor Networks

System ArchitectureSystem Architecture

Internet

LocalTransportProtocol

LocalTransportProtocol

ProgrammingStation

Server Server

Nodes Nodes

Responsible forResource management

User access rights

Page 48: Programming Abstractions in Wireless Sensor Networks

System ArchitectureSystem Architecture

Internet

LocalTransportProtocol

LocalTransportProtocol

ProgrammingStation

Server Server

Nodes Nodes

Omnix PhysicalNetwork

Omnix PhysicalNetwork

The Physicalnet

Page 49: Programming Abstractions in Wireless Sensor Networks

SummarySummary

• Future Problem• Java-like language with different

levels of VMs

Page 50: Programming Abstractions in Wireless Sensor Networks

QuestionsQuestions

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

Page 51: Programming Abstractions in Wireless Sensor Networks

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 52: Programming Abstractions in Wireless Sensor Networks

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?