The programming model

In our programming model, nodes run services. A service is a quadruple consisting of state, functions, generated events and event handlers. All interaction between services is realised by message exchange. A message takes the general form:

HandlerID arg_0 ... arg_n

Upon reception of a message, the handler specified by HandlerID is dispatched passing arg_0 up to arg_n as parameter.

Services generate events through event generators. Event generators are periodically triggered event-condition-action rules. The triggering period is specified by subscribers (and can differ per subscriber). To link the event generator of one service to the event-handler of another a subscription has to be made. Through these subscriptions services are externally composed to realize a network-wide behaviour. Here, external composition refers to the fact that the decision to bind event generators and event handlers is made by some third-party entity, not part of the services.

The following figure shows the various contexts present on each node:

Initially, each node runs a small lightweight virtual machine for configuration purposes and a single service, the system service.

Ncontext (Node context) consists of a collection of system calls (built-in functionality, typically written in C or nesC, e.g. a function to read sensor values) and system handlers. These system handlers are a small set of required handlers installed on each node. The most noteworthy is the configuration handler which is used to install new services.

Each service can define a global state which is shared between all its event generators and event handlers. We refer to this state as Gcontext. Besides a global state, each subscriber can define its own state. This state is stored in Scontext. Besides the subscribers state, Scontext also contains the triggering period of the event generator and the address of the subscriber.

Finally, Mcontext contains the body of received messages, it takes the form of a HandlerID followed by some parameters as described above.

All event generators have access to Ncontext, Gcontext and Scontext. All event handlers have access to Ncontext, Gcontext and Mcontext.