FRP IoT Modules as a Scala DSL BenCalus, BobReynders , - - PowerPoint PPT Presentation

frp iot modules as a scala dsl
SMART_READER_LITE
LIVE PREVIEW

FRP IoT Modules as a Scala DSL BenCalus, BobReynders , - - PowerPoint PPT Presentation

FRP IoT Modules as a Scala DSL BenCalus, BobReynders , DominiqueDevriese, Job Noorman, FrankPiessens imec - DistriNet - KU Leuven FRP IoT Modules Maintainable sensor network applications High-level FRP-based API FRP-modules compile


slide-1
SLIDE 1

FRP IoT Modules as a Scala DSL

BenCalus, BobReynders, DominiqueDevriese, Job Noorman, FrankPiessens

imec - DistriNet - KU Leuven

slide-2
SLIDE 2

FRP IoT Modules

  • Maintainable sensor network applications
  • High-level FRP-based API
  • FRP-modules compile to Protected Module Architecture (Sancus)
  • As a library in Scala using LMS

1

slide-3
SLIDE 3

FRP IoT Modules

  • Maintainable sensor network applications
  • High-level FRP-based API
  • FRP-modules compile to Protected Module Architecture (Sancus)
  • As a library in Scala using LMS

1

slide-4
SLIDE 4

FRP IoT Modules

  • Maintainable sensor network applications
  • High-level FRP-based API
  • FRP-modules compile to Protected Module Architecture (Sancus)
  • As a library in Scala using LMS

1

slide-5
SLIDE 5

FRP IoT Modules

  • Maintainable sensor network applications
  • High-level FRP-based API
  • FRP-modules compile to Protected Module Architecture (Sancus)
  • As a library in Scala using LMS

1

slide-6
SLIDE 6

FRP: Summary

Event sequences of time-stamped values (button presses) Behavior time-varying values (temperature readings)

2

slide-7
SLIDE 7

FRP: Summary

Event sequences of time-stamped values (button presses) Behavior time-varying values (temperature readings)

2

slide-8
SLIDE 8

FRP: Summary

3

slide-9
SLIDE 9

FRP-Modules

  • Unit of compilation/deployment
  • First-class values

def createModule[A](f: ModuleName > OutputEvent[A]): Module[A] trait Module[A] { val name: ModuleName val output: OutputEvent[A] }

4

slide-10
SLIDE 10

FRP-Modules

  • Unit of compilation/deployment
  • First-class values

def createModule[A](f: ModuleName > OutputEvent[A]): Module[A] trait Module[A] { val name: ModuleName val output: OutputEvent[A] }

4

slide-11
SLIDE 11

FRP-Modules: Interface

  • val input: Event[T] = InputEvent[T]
  • Timer

val timer: Event[Unit] = SystemTimerEvent()

  • Button

val button: Event[Unit] = ButtonEvent(Buttons.button1)

  • Modules!

val m1 = createModule[Int] { ... } val m2 = createModule[Unit] { val out: Event[Int] = ExternalEvent(m1.output) }

5

slide-12
SLIDE 12

FRP-Modules: Interface

  • val input: Event[T] = InputEvent[T]
  • Timer

val timer: Event[Unit] = SystemTimerEvent()

  • Button

val button: Event[Unit] = ButtonEvent(Buttons.button1)

  • Modules!

val m1 = createModule[Int] { ... } val m2 = createModule[Unit] { val out: Event[Int] = ExternalEvent(m1.output) }

5

slide-13
SLIDE 13

FRP-Modules: Interface

  • val input: Event[T] = InputEvent[T]
  • Timer

val timer: Event[Unit] = SystemTimerEvent()

  • Button

val button: Event[Unit] = ButtonEvent(Buttons.button1)

  • Modules!

val m1 = createModule[Int] { ... } val m2 = createModule[Unit] { val out: Event[Int] = ExternalEvent(m1.output) }

5

slide-14
SLIDE 14

FRP-Modules: Interface

  • val input: Event[T] = InputEvent[T]
  • Timer

val timer: Event[Unit] = SystemTimerEvent()

  • Button

val button: Event[Unit] = ButtonEvent(Buttons.button1)

  • Modules!

val m1 = createModule[Int] { ... } val m2 = createModule[Unit] { val out: Event[Int] = ExternalEvent(m1.output) }

5

slide-15
SLIDE 15

Example

slide-16
SLIDE 16

Example: Parking lot

Alarm Node Alarm Module Parking Module

Sensor Module Timer Module

Sensor Node Parking Module

Sensor Module Timer Module

Sensor Node

Figure 1: Parking Alarm

6

slide-17
SLIDE 17

Example: Parking module

val parkingMod = createModule[Boolean] { implicit n: ModuleName > val t = 1000 val sensorE = ExternalEvent(sensorMod.output) val timer = ExternalEvent(timerMod.output) val isParked: Behavior[Boolean] = sensorE.startWith(false) val isParkedOnTick: Event[Boolean] = isParked.snapshot(timer) val ticksParked: Behavior[Int] = isParkedOnTick.foldp((taken, s) > if (taken) s + 1 else 0, 0) val violations = ticksParked.changes().map(_ >= t)

  • ut("violations", violations)

}

7

slide-18
SLIDE 18

Example: Parking module as First-class values

  • val parkingMod = createModule[Boolean] { ... }
  • Code generation
  • def parkingMod(timeout: Long) = createModule[Boolean] { ... }

8

slide-19
SLIDE 19

Example: Parking module as First-class values

  • val parkingMod = createModule[Boolean] { ... }
  • Code generation
  • def parkingMod(timeout: Long) = createModule[Boolean] { ... }

8

slide-20
SLIDE 20

Example: Parking module as First-class values

  • val parkingMod = createModule[Boolean] { ... }
  • Code generation
  • def parkingMod(timeout: Long) = createModule[Boolean] { ... }

8

slide-21
SLIDE 21

Example: Parking lot

Alarm Node Alarm Module Parking Module

Sensor Module Timer Module

Sensor Node Parking Module

Sensor Module Timer Module

Sensor Node

Figure 2: Parking Alarm

9

slide-22
SLIDE 22

Example: Safely reusing the network

Space Node Space Module Parking Module

Sensor Module Timer Module

Sensor Node Parking Module

Sensor Module Timer Module

Sensor Node

Figure 3: Parking Counter

10

slide-23
SLIDE 23

Example: Safely reusing the network with Sancus

  • Spoofed events
  • Tampered execution
  • “If the program were to produce an output event, it produces the

same event regardless of an attacker.”

  • Authentic Execution of Distributed Event-Driven Applications with a

Small TCB (Noorman, Mühlberg, and Piessens 2017)

11

slide-24
SLIDE 24

Example: Safely reusing the network with Sancus

  • Spoofed events
  • Tampered execution
  • “If the program were to produce an output event, it produces the

same event regardless of an attacker.”

  • Authentic Execution of Distributed Event-Driven Applications with a

Small TCB (Noorman, Mühlberg, and Piessens 2017)

11

slide-25
SLIDE 25

Example: Safely reusing the network with Sancus

  • Spoofed events
  • Tampered execution
  • “If the program were to produce an output event, it produces the

same event regardless of an attacker.”

  • Authentic Execution of Distributed Event-Driven Applications with a

Small TCB (Noorman, Mühlberg, and Piessens 2017)

11

slide-26
SLIDE 26

Example: Safely reusing the network with Sancus

  • Spoofed events
  • Tampered execution
  • “If the program were to produce an output event, it produces the

same event regardless of an attacker.”

  • Authentic Execution of Distributed Event-Driven Applications with a

Small TCB (Noorman, Mühlberg, and Piessens 2017)

11

slide-27
SLIDE 27

Compilation

slide-28
SLIDE 28

Compilation Pipeline: Scala (EDSL)

Scala (EDSL) LMS Program (annotated) C Sancus Compiler Node Deployment

Figure 4: Compilation Pipeline

12

slide-29
SLIDE 29

Building the graph

1 val input1 = InputEvent[Int] 2 val input2 = InputEvent[Int] 3 val negate2 = input2.map( (i) => 0-i ) 4 val merged =

input1.merge(negate2, (x,y) => x + y)

5 val filtered =

merged.filter( (x) => abs(x) < 10)

6 val counter =

filtered.foldp((x,state)=>state + x, 0)

13

slide-30
SLIDE 30

Building the graph

1 val input1 = InputEvent[Int] 2 val input2 = InputEvent[Int] 3 val negate2 = input2.map( (i) => 0-i ) 4 val merged =

input1.merge(negate2, (x,y) => x + y)

5 val filtered =

merged.filter( (x) => abs(x) < 10)

6 val counter =

filtered.foldp((x,state)=>state + x, 0)

13

slide-31
SLIDE 31

Building the graph

1 val input1 = InputEvent[Int] 2 val input2 = InputEvent[Int] 3 val negate2 = input2.map( (i) => 0-i ) 4 val merged =

input1.merge(negate2, (x,y) => x + y)

5 val filtered =

merged.filter( (x) => abs(x) < 10)

6 val counter =

filtered.foldp((x,state)=>state + x, 0)

13

slide-32
SLIDE 32

Building the graph

1 val input1 = InputEvent[Int] 2 val input2 = InputEvent[Int] 3 val negate2 = input2.map( (i) => 0-i ) 4 val merged =

input1.merge(negate2, (x,y) => x + y)

5 val filtered =

merged.filter( (x) => abs(x) < 10)

6 val counter =

filtered.foldp((x,state)=>state + x, 0)

13

slide-33
SLIDE 33

Building the graph

1 val input1 = InputEvent[Int] 2 val input2 = InputEvent[Int] 3 val negate2 = input2.map( (i) => 0-i ) 4 val merged =

input1.merge(negate2, (x,y) => x + y)

5 val filtered =

merged.filter( (x) => abs(x) < 10)

6 val counter =

filtered.foldp((x,state)=>state + x, 0)

13

slide-34
SLIDE 34

Building the graph

13

slide-35
SLIDE 35

Compilation Pipeline: LMS Program

Scala (EDSL) LMS Program (annotated) C Sancus Compiler Node Deployment

Figure 5: Compilation Pipeline

14

slide-36
SLIDE 36

Compiling to (Sancus) C

15

slide-37
SLIDE 37

Compiling to (Sancus) C

15

slide-38
SLIDE 38

Compiling to (Sancus) C

void toplevel1( ) { input1( ); mergefun( ); filterfun( ); foldpfun( ); } void foldpfun( ) { … }

15

slide-39
SLIDE 39

Compiling to (Sancus) C

int foldp_w; void toplevel1( ) { bool input1_p; int input1_w; input1(&input1_p, &input1_w); mergefun( ... ); filterfun( … ); bool foldp_p; foldpfun(&foldp_p, … ); } 15

slide-40
SLIDE 40

Compiling to (Sancus) C

Scala (EDSL) LMS Program (annotated) C Sancus Compiler Node Deployment

Figure 6: Compilation Pipeline

16

slide-41
SLIDE 41

Compiling to (Sancus) C

SM_DATA(mod1) int foldp_w; SM_DATA(mod1) void toplevel1( ) { bool input1_p; int input1_w; input1(&input1_p, &input1_w); mergefun( ... ); filterfun( … ); bool foldp_p; foldpfun(&foldp_p, … ); } 17

slide-42
SLIDE 42

Compiling to (Sancus) C

val m1 = createModule[Int] { implicit m > val data: Event[Int] = ...

  • ut(data)

} val m2 = createModule[Unit] { implicit m > ExternalEvent(m1.output) }

Figure 7: Module Communication (EDSL)

18

slide-43
SLIDE 43

Compiling to (Sancus) C

SM_DATA(m1) ... SM_OUTPUT(m1, out); SM_INPUT(m1) { ... } SM_FUNC(m1) { ...

  • ut(&data, sizeof(data))

} SM_DATA(m2) ... SM_INPUT(m2) { ... }

Figure 8: Module Communication (Sancus)

19

slide-44
SLIDE 44

Deployment

Scala (EDSL) LMS Program (annotated) C Sancus Compiler Node Deployment

Figure 9: Compilation Pipeline

20

slide-45
SLIDE 45

Deployment

  • Sancus configuration file
  • Future Work
  • Configuration DSL
  • Well-typed deployments

21

slide-46
SLIDE 46

Deployment

  • Sancus configuration file
  • Future Work
  • Configuration DSL
  • Well-typed deployments

21

slide-47
SLIDE 47

Deployment

  • Sancus configuration file
  • Future Work
  • Configuration DSL
  • Well-typed deployments

21

slide-48
SLIDE 48

Deployment

  • Sancus configuration file
  • Future Work
  • Configuration DSL
  • Well-typed deployments

21

slide-49
SLIDE 49

Deployment: Future Work

val parkDevice = Pressure + Timer val alarmDevice = Alarm val parkingMod = ... val alarmMod = ... val deploymentScheme = parkDevice.deploy(parkingMod, Sancus) .and(alarmDevice.deploy(alarmMod, SGX))

22

slide-50
SLIDE 50

Summary

slide-51
SLIDE 51

Summary

  • (step towards) maintainable sensor network applications
  • High-level FRP library with (free) low-level guarantees
  • Scala EDSL with prototype at:

github.com/tzbob/scala-iot-modules-for-frp

23

slide-52
SLIDE 52

Summary

  • (step towards) maintainable sensor network applications
  • High-level FRP library with (free) low-level guarantees
  • Scala EDSL with prototype at:

github.com/tzbob/scala-iot-modules-for-frp

23

slide-53
SLIDE 53

Summary

  • (step towards) maintainable sensor network applications
  • High-level FRP library with (free) low-level guarantees
  • Scala EDSL with prototype at:

github.com/tzbob/scala-iot-modules-for-frp

23