Systematically exploring control programs (Lecture I) Ratul Mahajan Microsoft Research Joint work with Jason Croft, Matt Caesar, and Madan Musuvathi.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Enabling smarter homes for everyone Ratul Mahajan.
Reliable Scripting Using Push Logic Push Logic David Greaves, Daniel Gordon University of Cambridge Computer Laboratory Reliable Scripting.
Openflow App Testing Chao SHI, Stephen Duraski. Motivation Network is still a complex stuff ! o Distributed mechanism o Complex protocol o Large state.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Systematically exploring control programs Ratul Mahajan Joint work with Jason Croft, Matt Caesar, and Madan Musuvathi.
UPPAAL Introduction Chien-Liang Chen.
Hybrid System Verification Synchronous Workshop 2003 A New Verification Algorithm for Planar Differential Inclusions Gordon Pace University of Malta December.
Hybrid Systems Presented by: Arnab De Anand S. An Intuitive Introduction to Hybrid Systems Discrete program with an analog environment. What does it mean?
Fuzzy Logic and its Application to Web Caching
Logic Synthesis – 3 Optimization Ahmed Hemani Sources: Synopsys Documentation.
Timed Automata.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
A SOFT Way for OpenFlow Interoperability Testing Marco Canini TU Berlin / T-Labs [CoNEXT’12]
FixtureFinder: Discovering the Existence of Electrical and Water Fixtures Vijay Srinivasan*, John Stankovic, Kamin Whitehouse University of Virginia *(Currently.
Verification of Hybrid Systems An Assessment of Current Techniques Holly Bowen.
Compatibility between shared variable valuations in timed automaton network model- checking Zhao Jianhua, Zhou Xiuyi, Li Xuandong, Zheng Guoliang Presented.
6/14/991 Symbolic verification of systems with state machines David L. Dill Jeffrey Su Jens Skakkebaek Computer System Laboratory Stanford University.
The Cache Location Problem. Overview TERCs Vs. Proxies Stability Cache location.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Synergy: A New Algorithm for Property Checking
Model Checking. Used in studying behaviors of reactive systems Typically involves three steps: Create a finite state model (FSM) of the system design.
ECE Synthesis & Verification1 ECE 667 Spring 2011 Synthesis and Verification of Digital Systems Verification Introduction.
DART Directed Automated Random Testing Patrice Godefroid, Nils Klarlund, and Koushik Sen Syed Nabeel.
Department of CIS University of Pennsylvania 1/31/2001 Specification-based Protocol Testing Hyoung Seok Hong Oleg Sokolsky CSE 642.
1 Lecture 11: Digital Design Today’s topics:  Evaluating a system  Intro to boolean functions.
SEC PI Meeting Annapolis, May 8-9, 2001 Component-Based Design of Embedded Control Systems Edward A. Lee & Jie Liu UC Berkeley with thanks to the entire.
5. Case Study Smart Home in a Life Care Community Apartment Complex.
THE OBJECT-ORIENTED DESIGN WORKFLOW Statechart Diagrams.
Testing an individual module
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Real-Time Software Design Yonsei University 2 nd Semester, 2014 Sanghyun Park.
CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
CS 162 Discussion Section Week 1 (9/9 – 9/13) 1. Who am I? Kevin Klues Office Hours:
1 System Models. 2 Outline Introduction Architectural models Fundamental models Guideline.
VeriFlow: Verifying Network-Wide Invariants in Real Time
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
Reference: Ian Sommerville, Chap 15  Systems which monitor and control their environment.  Sometimes associated with hardware devices ◦ Sensors: Collect.
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
CSC 107 – Programming For Science. Announcements.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
1 Model Checking of Robotic Control Systems Presenting: Sebastian Scherer Authors: Sebastian Scherer, Flavio Lerda, and Edmund M. Clarke.
Embedded and Real Time Systems Lecture #2 David Andrews
Processes and Virtual Memory
DEVS-based Modeling and Simulation References: 1.B. P. Zeigler, Hessam S. Sarjoughian, Introduction to DEVS Modeling and Simulation with JAVA: Developing.
ECE/CS 584: Verification of Embedded Computing Systems Model Checking Timed Automata Sayan Mitra Lecture 09.
CUTE: A Concolic Unit Testing Engine for C Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
Jennifer Rexford Princeton University MW 11:00am-12:20pm Data-Plane Verification COS 597E: Software Defined Networking.
Workshop on Integrating Software Testing into Programming Courses (WISTPC14:2) Friday July 18, 2014 Introduction to Software Testing.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Week 6 MondayTuesdayWednesdayThursdayFriday Testing III Reading due Group meetings Testing IVSection ZFR due ZFR demos Progress report due Readings out.
TESTCOM/FATES Test Plan Generation for Concurrent Real-Time Systems based on Zone Coverage Analysis Farn Wang Dept. of Electrical Eng. National Taiwan.
Kalman Filter and Data Streaming Presented By :- Ankur Jain Department of Computer Science 7/21/03.
CS5270 Lecture 41 Timed Automata I CS 5270 Lecture 4.
CS 162 Discussion Section Week 2. Who am I? Prashanth Mohan Office Hours: 11-12pm Tu W at.
SS 2017 Software Verification Timed Automata
Programming & Scratch.
The Joy of Breaking Code Testing Logic and Case Selection
CPE555A: Real-Time Embedded Systems
Input Space Partition Testing CS 4501 / 6501 Software Testing
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Instructor: Rajeev Alur
Administrivia Course Web:
CSEP590 – Model Checking and Automated Verification
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Discrete Controller Synthesis
CSC-682 Advanced Computer Security
CUTE: A Concolic Unit Testing Engine for C
Presentation transcript:

Systematically exploring control programs (Lecture I) Ratul Mahajan Microsoft Research Joint work with Jason Croft, Matt Caesar, and Madan Musuvathi

Control programs are everywhere From the smallest of networks to the largest

Control programs are everywhere From the smallest of networks to the largest

The nature of control programs Collection of rules with triggers and actions motionPorch.Detected: if (Now - tLastMotion < 1s && lightLevel < 20) porchLight.Set(On) tLastMotion = PM: AM: porchLight.Set(Off) packetIn: entry = new Entry(inPkt.src, inPkt.dst) if (!cache.Contains(entry) cache.Insert(entry, Now) CleanupTimer: foreach entry in cache if (Now – cache[entry] < 5s) cache.Remove(entry)

Buggy control programs wreak havoc One nice morning in the summer

Buggy control programs wreak havoc “I had a rule that would turn on the heat, disarm the alarm, turn on some lights, etc. at 8am ….. I came home from vacation to find a warm, inviting, insecure, well lit house that had been that way for a week…… That’s just one example, but the point is that it has taken me literally YEARS of these types of mistakes to iron out all the kinks.”

Control programs are hard to reason about motionPorch.Detected: if (Now - timeLastMotion < 1 secs && lightMeter.Level < 20) porchLight.Set(On); timeLastMotion = Now; porchLight.StateChange: if (porchLight.State == On) timerPorchLight.Reset(5 mins); timerPorchLight.Fired: if (Now.Hour > 6AM && Now.Hour < 6PM) porchLight.Set(Off); Dependence on time Rule interaction Large input space 9:00 PM Physical actuation 9:04 PMMotion 9:05 PMLights off

Desirable properties for bug finders Sound Complete Fast

Two bug finding methods TestingModel checking

Two threads in model checking Check modelsCheck code

Model checking code FSM is the most popular abstraction

Model checking code FSM is the most popular abstaction

Model checking code FSM is the most popular abstraction – Decide what are “states” and “transitions” S0 S1S2 T1 T2 S3 T1 T2T1 S4 T2

Example motionPorch: porchLight.Set(On) timer.Start(5 mins) porchLight.On: timer.Start(5 mins) timer.Fired: porchLight.Set(Off) [PorchLight, Timer] [Off, Off] [On, On] Motion LightOn Motion LightOn Timer [Off, On] LightOff LightOn Motion Timer

Exploring input space motionPorch: if (lightLevel < 20) porchLight.Set(On) timer.Start(10 mins) porchLight.On: timer.Start(5 mins) timer.Fired: porchLight.Set(Off) To explore comprehensively, must consider all possible values of input parameters [Off, Off] […] LtLvl=0 […] LtLvl=99 ● ● ● [PorchLight, Timer] [Off, Off] LtLvl=0 [On, On] LtLvl=19 LtLvl=99 LtLvl=20 ● ● ● [PorchLight, Timer]

Symbolic execution if (x < 2) if (y > 5) p = 1; else p = 2; else if (y > 10) p = 3; else p = 4;

Finding equivalent inputs using symbolic execution motionPorch: if (lightMeter.level < 20) porchLight.Set(On) timer.Start(5 mins) porchLight.On: timer.Start(5 mins) timer.Fired: porchLight.Set(Off) 1.Symbolically execute each trigger 2.Find input ranges that lead to same state

Finding equivalent inputs using symbolic execution motionPorch: x = lightMeter.Level porchLight.On: timer.Start(5 mins) timer.Fired: porchLight.Set(Off) 1.Symbolically execute each trigger 2.Find input ranges that lead to same state

Efficiently exploring the input space [Off, Off] Motion, LtLvl =10 [On, On] Motion, LtLvl = 20 motionPorch: if (lightMeter.level < 20) porchLight.Set(On) timer.Start(5 mins) porchLight.On: timer.Start(5 mins) timer.Fired: porchLight.Set(Off) Pick random values in equivalent classes

Use symbolic execution alone? Trigger0, Trigger1, Trigger2 [] Trigger0 [] Trigger1 Trigger2 Symbolic, path-based Concrete, state-based

Exploring temporal behavior: soundness motionPorch: porchLight.Set(On) timerDim.Start(5 mins) timerOff.Start(10 mins) porchLight.On: timerDim.Start(5 mins) timerOff.Start(10 mins) timerDim.Fired: porchLight.Set(Dim) timerOff.Fired: porchLight.Set(Off) if timerDim.On() Abort(); [PorchLight, TimerDim, TimerOff] [Off, Off, Off] [On, On, On] LightOff [Off, On, On][Off, On, Off][Dim, Off, On] Motion LightOn TimerOff LightOff Motion LightOn TimerDim

Exploring temporal behavior: completeness motionPorch: if (Now - tLastMotion < 60) porchLight.Set(On) timer.Start(600) tLastMotion = Now porchLight.On: timer.Start(600) timer.Fired: porchLight.Set(Off) To explore comprehensively, must fire all possible events at all possible times

Trigger0: tTrigger1 = Now tTrigger2 = Now trigger1Seen = false Trigger1: if (Now – tTrigger1 < 5) trigger1Seen = true tTrigger1 = Now Trigger2: if (trigger1Seen) if (Now – tTrigger2 < 2) DoSomething() else DoSomethingElse() [trigger1Seen, tTrigger1, tTrigger2] [false, T, T] [true, T+3, T] Trigger2 Trigger1 [Now=T+3] [false, T+6, T] Trigger1 [Now=T+6] DoSomething()DoSomethingElse()

[trigger1Seen, tTrigger1, tTrigger2] [false, T, T] [true, T+1, T] Trigger2 Trigger1 [Now=T+1] [false, T+6, T] Trigger1 [Now=T+6] DoSomething()DoSomethingElse() Trigger0: tTrigger1 = Now tTrigger2 = Now trigger1Seen = false Trigger1: if (Now – tTrigger1 < 5) trigger1Seen = true tTrigger1 = Now Trigger2: if (trigger1Seen) if (Now – tTrigger2 < 2) DoSomething() else DoSomethingElse()

The tyranny of “all possible times” Speed Completeness

Timed automata FSM (states, transitions) + the following: Finite number of real-values clocks (VCs) All VCs progress at the same rate, except that one or more VCs may reset on a transition VC constraints gate transitions

[trigger1Seen] [false] [true] Trigger0 () [x1,x2] Trigger1 (x1<5) [x1] Trigger1 (x1 >=5) [x1] Trigger2 (x2 < 2) [] {DoSomething} Trigger2 (x2 >= 2) [] {DoSomethingElse} Trigger0 () [x1,x2] Trigger1 (x1 >= 5) [x1] Trigger1 (x1 < 5 ) [x1] Trigger2 () [] Trigger0: tTrigger1 = Now tTrigger2 = Now trigger1Seen = false Trigger1: if (Now – tTrigger1 < 5) trigger1Seen = true tTrigger1 = Now Trigger2: if (trigger1Seen) if (Now – tTrigger2 < 2) DoSomething() else DoSomethingElse()

Properties of timed automata If VC constraints are such that: No arithmetic operation involving two VCs No multiplication operation involving a VC No irrational constants in constraints Time can be partitioned into equivalence regions x + y < z 2x < 3 x < y + 2 [s0][s1] t1 (x<2) [x] t2 (y<1) [y] X  Y  regions Corner points (6) Line segments (14) Spaces (8) x < 2

X1  X2  Trigger0: tTrigger1 = Now tTrigger2 = Now trigger1Seen = false Trigger1: if (Now – tTrigger1 < 5) trigger1Seen = true tTrigger1 = Now Trigger2: if (trigger1Seen) if (Now – tTrigger2 < 2) DoSomething() else DoSomethingElse()

Why regions are fine-grained [s0][s1] t1 (x<2) [x] t2 (y<1) [y] X  Y  X  Y  ● ● ● ● ● (0.5, 0.5)● (1.5, 0.5) ● (1.5, 1.5)● (2.5, 1.5) [s0][s1] t1 (x<2) [x] t2 (y<1) [y] [s2] t3 (x 1)

Region construction X1  X2  x2 < x1 + 2

Why this construction works X1  X2  ● ● ●● 1.X1 < 5 2.X2 < 2 3.X1 2

Why this construction works X1  X2  ● ● ● ● 1.X1 < 5 2.X2 < 2 3.X1 2

Exploring a TA [false] [true] Trigger0 () [x1,x2] Trigger1 (x1<5) [x1] Trigger1 (x1 >=5) [x1] Trigger2 (x2 < 2) [] {DoSomething} Trigger2 (x2 > 2) [] {DoSomethingElse} Trigger0 () [x1,x2] Trigger1 (x1 >= 5) [x1] Trigger1 (x1 < 5 ) [x1] Trigger2 () [] [false] x1=0, x2=0 Trigger0 Trigger2 [true] x1=0, x2=0 [false] x1=0.5, x2=0.5 Trigger1 δ Trigger0 Trigger1 Trigger2 {DoSomething} [true] x1=0.5, x2=0.5 δ Trigger0 [true] x1=0, x2=0.5 Trigger1 Trigger2 [false] x1=1, x2=1 δ

Exploring a TA [false] [true] Trigger0 () [x1,x2] Trigger1 (x1<5) [x1] Trigger1 (x1 >=5) [x1] Trigger2 (x2 < 2) [] {DoSomething} Trigger2 (x2 > 2) [] {DoSomethingElse} Trigger0 () [x1,x2] Trigger1 (x1 >= 5) [x1] Trigger1 (x1 < 5 ) [x1] Trigger2 () [] [false] x1=0, x2=0 Trigger0 Trigger2 [true] x1=0, x2=0 [false] x1=0.5, x2=0.5 Trigger1 δ Trigger0 Trigger1 Trigger2 {DoSomething} [true] x1=0.5, x2=0.5 δ Trigger0 [true] x1=0, x2=0.5 Trigger1 Trigger2 [false] x1=1, x2=1 δ

Systematically exploring control programs (Lecture II) Ratul Mahajan Microsoft Research Joint work with Jason Croft, Matt Caesar, and Madan Musuvathi

Recap: The nature of control programs Collection of rules with triggers and actions motionPorch.Detected: if (Now - tLastMotion < 1s && lightLevel < 20) porchLight.Set(On) tLastMotion = PM: AM: porchLight.Set(Off) packetIn: entry = new Entry(inPkt.src, inPkt.dst) if (!cache.Contains(entry) cache.Insert(entry, Now) CleanupTimer: foreach entry in cache if (Now – cache[entry] < 5s) cache.Remove(entry)

Recap: Timed automata FSM (states, transitions) + the following: Finite number of real-values clocks (VCs) All VCs progress at the same rate, except that one or more VCs may reset on a transition VC constraints gate transitions

Recap: Properties of timed automata If VC constraints are such that: No arithmetic operation involving two VCs No multiplication operation involving a VC No irrational constants in constraints Time can be partitioned into equivalence regions x + y < z 2x < 3 x < y + 2 [s0][s1] t1 (x<2) [x] t2 (y<1) [y] X  Y  regions Corner points (6) Line segments (14) Spaces (8) x < 2

Recap: Region construction X1  X2  x2 < x1 + 2

Recap: Exploring a TA [false] [true] Trigger0 () [x1,x2] Trigger1 (x1<5) [x1] Trigger1 (x1 >=5) [x1] Trigger2 (x2 < 2) [] {DoSomething} Trigger2 (x2 > 2) [] {DoSomethingElse} Trigger0 () [x1,x2] Trigger1 (x1 >= 5) [x1] Trigger1 (x1 < 5 ) [x1] Trigger2 () [] [false] x1=0, x2=0 Trigger0 Trigger2 [true] x1=0, x2=0 [false] x1=0.5, x2=0.5 Trigger1 δ Trigger0 Trigger1 Trigger2 {DoSomething} [true] x1=0.5, x2=0.5 δ Trigger0 [true] x1=0, x2=0.5 Trigger1 Trigger2 [false] x1=1, x2=1 δ

Exploring control programs with TAs 1.Mapping time-related activity to VCs 2.Model devices 3.Construct time regions 4.Compute equivalent classes for inputs 5.Explore states

Mapping to VCs (1/4): Delay measurers Trigger1:... tLast = Now... Trigger2:... if (Now - tLast < 60)... Trigger1:... VC_tLast = 0... Trigger2:... if (VC_tLast < 60)...

Mapping to VCs (2/4): Periodic timers timer1.Period = 600 timer1.Event += Timer1Fired... Timer1Fired:... VC_timer1 = 0... VC_timer1 == 600:... VC_timer1 = 0

Mapping to VCs (2/4): Delayed actions Trigger1:... timer1.Start(600)... timer1.Fired:... Trigger1:... VC_timer1 = 0... VC_timer1 == 600:...

Mapping to VCs (4/4): Sleep calls Trigger:... Sleep(10)... Trigger:... // pre-sleep actions VC_sleeper = 0 VC_sleeper == 10:... // post-sleep actions

Reducing the number of VCs: Combining periodic timers timer1.Period = 600 timer1.Event += Timer1Fired timer2.Period = 800 timer2.Event += Timer2Fired... Timer1Fired:... Timer2Fired:... VC_timer = 0... VC_timer == 600:... VC_timer == 800:... VC_timer = 0

Reducing the number of VCs: Combining sleep calls Trigger: Act1() Sleep(5) Act2() Sleep(10) Act3() Trigger: Act1() VC_sleeper = 0 sleep_counter = 1; VC_sleeper == 5: Act2() VC_sleeper == 15: Act3()

Modeling devices Model a device using one of more key value pairs – Motion sensor: Single key with binary value – Dimmer: Single key with values in range [0..99] – Thermostat: Multiple keys Keys can be notifying or non-notifying – Triggers are used for notifying keys Queries for values are treated as program inputs

Limitations of device modeling Values can change arbitrarily Key value pairs of a device are independent Different devices are independent

Constructing time regions 1.Extract VC constraints using symbolic execution 2.Construct time regions using the constraints Trigger0: tTrigger1 = Now tTrigger2 = Now trigger1Seen = false Trigger1: if (Now – tTrigger1 < 5) trigger1Seen = true tTrigger1 = Now Trigger2: if (trigger1Seen) if (Now – tTrigger2 < 2) DoSomething() else DoSomethingElse()

Exploration using TA

Optimization: Predicting successor states Observation: Multiple region states can have identical response to a trigger Trigger1: if (x1 < 5) trigger1Seen = true x1= 0 Trigger2: if (trigger1Seen) if (x2 < 2) DoSomething() else DoSomethingElse() tTrigger1 tTrigger ● ●

Optimization: Predicting successor states Observation: Multiple region states can have identical response to a trigger Clock personality: region’s evaluation of clock constraints Same variable values and ready timers Different regions but same personality ● ● Compute ● ● Predict

Optimization: Independent control loops Observation: Control programs tend to have multiple, independent control loops 1.Determine independent sets of variables 2.Explore independent sets independently

DeLorean Control program Safety invariants Front end Program with virtualized devices Program analyzer Clock constraints Input space classes Control loops Region states Paths Explorer

Demo

Evaluation on ten real home automation rograms

Example bugs P9-1: Lights turned on even in the absence of motion – Bug in conditional clause: used OR instead of AND P9-2: Lights turned off between sunset and 2AM – Interaction between rules that turned lights on and off P10-1: Dimmer wouldn’t turn on despite motion – No rule to cover a small time window P10-2: One device in a group behaved differently – Missing reference to the device in one of the rules

Performance of exploration Time to “fast forward” the home by one hour

Benefit of successor prediction Successor prediction yields significant advantage

Comparison with untimed model checking Untimed model checking reaches many invalid states

Comparison with randomized testing Random testing misses many valid states

Exploring OpenFlow programs #devsSLoC#VCsGCD MAC-Learning Switch (PySwitch) 2 hosts, 2 sw, 1 ctrl 128>= 61 Web Server Load Balancer 3 hosts, 1 sw, 1 ctrl 1307>= 41 Energy-Efficient Traffic Engineering 3 hosts, 3 sw, 1 ctrl 342>= 82

Additional challenges in OF programs Dynamically created VCs Variable number of VCs along different paths packetIn: timer = new Timer(5s) Insert(timer, inPkt.src, inPkt.dst)

Open problems Handling communicating control programs Exploring all possible topologies

Summary Control programs are tricky to debug – Interaction between rules – Large space of inputs – Intimate dependence on time These challenges cab be tacked using – Systematic exploration (model checking) – Symbolic execution to find equivalent input classes – Timed automata based exploration (equivalent times)