Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail...

28
Towards Context-oriented Self- adaptation in Resource- constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico di Milano (Italy), †SICS Swedish ICT

Transcript of Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail...

Page 1: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems

Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi**Politecnico di Milano (Italy), †SICS Swedish ICT

Page 2: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Problem

• CPSs are intimately tied to the real world– Multiple environment dimensions at hand– Continuously changing environment

• The software must adapt • Missing design and

programming support

Page 3: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Example: Wildlife Tracking

Page 4: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Problemmodule ReportLogs{ uses interface Collection; uses interface DataStore;} implementation {

int base_station_reachable = 0;

event msg_t Beacon.receive(msg_t msg) { if (!acceleromenter_detects_activity()) return; if (call Battery.energy() <= THRESHOLD) return; base_station_reachable = 1; call GPS.stop() call BaseStationReset.stop(); call BaseStationReset.startOneShot(TIMEOUT); }

event void BaseStationReset.fired() { base_station_reachable = 0; }

event void ReportPeriod.fired() { switch (base_station_reachable){ case 0: call DataStore.deposit(msg); case 1: call Collection.send(msg);} } }

Page 5: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Solution

• Context• Context-Oriented Programming (COP)• Language-independent design concepts • Programming support

Page 6: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Solution

context Unreachable { uses interface DataStore; } implementation { layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

context group BaseStationG { layered command void report(msg_t msg); } implementation { contexts Reachable, Unreachable is default, MyErrorC is error; components Routing, Logging; Reachable.Collection -> Routing;Unreachable.DataStore -> Logging;}

context Reachable { uses interface Collection; } implementation { layered command void report(msg_t msg){ call Collection.send(msg);}}

Functionality are decoupled;

implementations are individually simpler

Page 7: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Context-oriented Programming

• Layered functions change the behavior depending on the context

Page 8: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Context-oriented Programming

Java PythonErlang

Lisp

Objective-C

• Layered functions change the behavior depending on the context

8Kb RAM

Page 9: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Design Concepts• Context group as collection of environmental

situations sharing the same characteristics• Context represents a single environmental

situation in a group

Context group

Context Context

Page 10: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Wildlife Tracking Design

Page 11: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Programming: ConesC

• Context-Oriented extension of nesC• Enable layered functions (commands) in nesC• Redefine component and configuration

Page 12: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Execution Examplecall BaseStationG.report(msg);

Page 13: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

call BaseStationG.report(msg);

activate BaseStationG.Reachable;//...activate BaseStationG.Unreachable;

Execution Example

Page 14: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

call BaseStationG.report(msg);

activate BaseStationG.Reachable;//...activate BaseStationG.Unreachable;

context Reachable { uses interface Collection; } implementation { //... layered command void report(msg_t msg){ call Collection.send(msg);}}

context Unreachable { uses interface DataStore; } implementation { //... layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

Execution Example

Page 15: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

call BaseStationG.report(msg);

activate BaseStationG.Reachable;//...activate BaseStationG.Unreachable;

context Reachable { uses interface Collection; } implementation { //... layered command void report(msg_t msg){ call Collection.send(msg);}}

context Unreachable { uses interface DataStore; } implementation { //... layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

Execution Example

Page 16: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

call BaseStationG.report(msg);

activate BaseStationG.Reachable;//...activate BaseStationG.Unreachable;

context Reachable { uses interface Collection; } implementation { //... layered command void report(msg_t msg){ call Collection.send(msg);}}

context Unreachable { uses interface DataStore; } implementation { //... layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

Execution Example

Page 17: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

call BaseStationG.report(msg);

activate BaseStationG.Reachable;//...activate BaseStationG.Unreachable;

context Reachable { uses interface Collection; } implementation { //... layered command void report(msg_t msg){ call Collection.send(msg);}}

context Unreachable { uses interface DataStore; } implementation { //... layered command void report(msg_t msg){ call DataStore.deposit(msg);}}

context group BaseStationG { layered command void report(msg_t msg); } implementation { contexts Reachable, Unreachable is default, MyErrorC is error; components Routing, Logging; Reachable.Collection -> Routing; Unreachable.DataStore -> Logging;}

Execution Example

Page 18: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Transition Control• Design issues• Programming errors• Hardware faults

Page 19: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Transition Control

context NotMoving { transitions Resting;} implementation {//...}

• Design issues• Programming errors• Hardware faults

Page 20: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Transition Control

context Unreachable { transitions Reachable iff ActivityG.Running;} implementation {//...}

• Design issues• Programming errors• Hardware faults

Page 21: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Transition Control

context Reachable {//...} implementation {//... command bool check(){ return call BatteryG.getContext() == BatteryG.Normal;}}

• Design issues• Programming errors• Hardware faults

Page 22: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Translator and Benchmarks

• Wildlife tracking• Smart-home controller• Adaptive protocol stack

Page 23: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Evaluation: Coupling

W. Stevens et al. Classics in software engineering. Chapter Structured Design. 1979.

Easier to maintain

Strongest Weakest

Page 24: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Evaluation: Complexity

Easier to understand

Page 25: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Evaluation: Run-time OverheadMCU Overhead

Memory Overhead

Turning an LED on is 8 MCU cycles Max 2.5%!

Negligible Overhead

Page 26: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Conclusion

• Context as a CPS programming concept– Language independent design– Programming support: ConesC

• Key results:– Easier to maintain and to understand– Negligible performance overhead

Page 27: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Future Work

• Domain-specific model-checking• Source-code generator• Context-Oriented programming for other

CPS platforms

Page 28: Towards Context-oriented Self-adaptation in Resource-constrained Cyberphysical Systems Mikhail Afanasov*, Luca Mottola*† and Carlo Ghezzi* *Politecnico.

Questions?