Using Alloy to Design a Safe Traffic Light System

Slides:



Advertisements
Similar presentations
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 2.
Advertisements

– Seminar in Software Engineering Cynthia Disenfeld
2005conjunctive-ii1 Query languages II: equivalence & containment (Motivation: rewriting queries using views)  conjunctive queries – CQ’s  Extensions.
Alan Shaffer, Mikhail Auguston, Cynthia Irvine, Tim Levin The 7th OOPSLA Workshop on Domain-Specific Modeling October 21-22, 2007 Toward a Security Domain.
Alloy Vatche Ishakian Boston University- CS511 March/24/2008 Contributors: Andrei Lapets, Michalis Potamias, Mark Reynolds.
1 Model Checking, Abstraction- Refinement, and Their Implementation Based on slides by: Orna Grumberg Presented by: Yael Meller June 2008.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Assignment: Changing Data CMSC Introduction to Computer Programming November 1, 2002.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
High Integrity Ada in a UML and C world Peter Amey, Neil White Presented by Liping Cai.
Albert Gatt LIN3021 Formal Semantics Lecture 4. In this lecture Compositionality in Natural Langauge revisited: The role of types The typed lambda calculus.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
A stop sign is a traffic sign that stands for coming to a complete stop at an intersection or end of the road.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 4 Inverse, Exponential, and Logarithmic Functions Copyright © 2013, 2009, 2005 Pearson Education,
Alloy Analyzer 4 Tutorial Session 2: Language and Analysis Greg Dennis and Rob Seater Software Design Group, MIT.
Alloy Analyzer 4 Tutorial Session 3: Static Modeling Greg Dennis and Rob Seater Software Design Group, MIT.
Ch. 7 Intersections.
AS Computer Studies Finite State Machines 1.
1.3 Finite State Machines.
Statistical Data Analysis - Lecture /04/03
Session 4: Dynamic Modeling
Finite State Machines Dr K R Bond 2009
Using Alloy to model the self-selection of a leader in a decentralized set of communicating processes I’m the leader! time … Roger L. Costello December.
CPE555A: Real-Time Embedded Systems
SEAA 2014 Automatic Production of Transformation Chains Using Structural Constraints on Output Models Cuauhtémoc Castellanos Etienne Borde Thomas Vergnaud.
How to Design Supplier Classes
Flowcharting Guidelines
Roger L. Costello December 29, 2016
VCU, Department of Computer Science CMSC 302 Sequences and Summations Vojislav Kecman 9/19/2018.
Seven Segment Displays
The Red Signal Prohibits Any Traffic From Proceeding.
Situations that require a driver to yield right-of-way
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
PROGRAMMING IN HASKELL
March 2017 Project: IEEE P Working Group for Wireless Personal Area Networks (WPANs) Submission Title : Parking Assistance based on V2X and CamCom.
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Navigating through Alloy relations
Can the constraints be satisfied?
Using Alloy to Solve the Einstein Puzzle
Bell Ringer: Define to the best of your ability the definition of:
Name: _______________________________
IS 2935: Developing Secure Systems
Model the non-negative even integers
Over-Approximating Boolean Programs with Unbounded Thread Creation
Each hotel guest has a set of keys and no two guests have the same key
PROGRAMMING IN HASKELL
Semantics In Text: Chapter 3.
Model Land and Seafloor Surfaces using Alloy (Part 2)
Use Alloy to model and find a solution to the Farmer, Goat, Cabbage, and Wolf problem Roger L. Costello July 14, 2018.
Expressing set properties in Alloy
Red lights, yellow lights, and green lights
Language-based Security
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Sculpting Alloy Models
Seminar 2 Design of Informatics Systems
Encapsulation in Alloy
Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1
Eve knows Alice’s password
Lecture 24 Logistics Last lecture Today HW7 back today
Expressing set properties in Alloy
Model Land and Seafloor Surfaces using Alloy (Part 3)
Testing versus instance generation
Object model versus Event model
The root cause of all security failures
Transformations Dilations Translations Reflections Rotations.
Object model versus Event model
Body Mapping. Body Mapping Chemical Body Mapping Activity For this activity at your tables you will do a specific Chemical exposure Body Map Use the.
How to create easy-to-read Alloy models
Directions to play game
Abstract Types Defined as Classes of Variables
Presentation transcript:

Using Alloy to Design a Safe Traffic Light System Roger L. Costello December 1, 2016

Acknowledgement The traffic light model shown in these slides comes from this (fantastic) book, page 129.

Traffic lights control the flow of vehicles Traffic lights guard the vehicles passing through. For a safe system, the traffic lights must not allow vehicles from perpendicular directions to pass through the junction at the same time.

We will create a model of traffic lights

Light Light

Junction

“Light State” is the state of the lights “Light State” is the state of the lights. The Light State at this junction: this light is red, that light is green.

What “safety requirement” do we desire for the lights?

What “safety requirement” do we desire for the lights? Answer: at no time are the lights for perpendicular directions green.

3 things needed for a safe flow of traffic at a junction: Only one light changes at a time. Each light must follow the proper color change sequence, e.g., red to green to yellow to red. If a light changes from red to non-red, then all the other lights must be red.

Recap Model the traffic lights at each junction. The model must implement the safety requirement.

Step 1: Define the components The components of the traffic light system are: The lights The junctions and the lights at each junction The light colors (red, green, yellow) The light states (i.e., the color of each light at each junction)

Model the junctions sig Junction {} Junction 5th & Elm 6th & Elm … Alloy code: sig Junction {}

This is the 5th & Elm junction Light L1 Light L2

Simple identifiers, for illustrative purposes In these slides the traffic lights are identified by L1, L2, etc. In reality a more complicated identifier would be used to identify a light, perhaps its model number.

Model the lights sig Light {} Light L1 2 lights at 5th & Elm L2 L3 … Alloy code: sig Light {}

Model the lights at each junction 5th & Elm L1 5th & Elm L1 6th & Elm L2 5th & Elm L2 7th & Elm L3 6th & Elm L3 L4 6th & Elm L4 L5 7th & Elm L5 L6 7th & Elm L6 Lights at each junction Alloy code: sig Junction {lights: set Light}

Model the colors displayed by the traffic lights Green Red Yellow Alloy code: abstract sig Color {} one sig Red, Yellow, Green extends Color {}

Model the state of the lights LightState state1 state2 … Alloy code: sig LightState {}

For example, “state1” could denote the traffic lights having these colors At 5th & Elm light L1 is red, light L2 is green At 6th & Elm light L3 is green, light L4 is red At 7th & Elm light L5 is green, light L6 is yellow

Model the color displayed by each light, for all states LightState Light Color color state1 L1 red state1 L1 red state2 L2 yellow state1 L2 green L3 green state1 L3 green L4 state1 L4 red L5 state1 L5 green L6 state1 L6 yellow state2 L1 green state2 L2 yellow Alloy code: state2 L3 yellow sig LightState { color: Light -> one Color } state2 L4 green state2 L5 yellow state2 L6 red

Recap: here’s the traffic lights model abstract sig Color {} one sig Red, Yellow, Green extends Color {} sig Light {} sig Junction { lights: set Light } sig LightState { color: Light -> one Color

Step 1: Define the components The components of the traffic light system are: The lights The junctions and the lights at each junction The light colors (red, green, yellow) The light states (the color of each light at each junction) Accomplished

Step 2: Constrain the transitions of the lights For the lights at a junction: For the light change (transition): A light’s color changes must follow the proper sequence. At most one light can change at a time. If the light that changed is red, then the other lights must be red.

For the lights at a junction: For the light change: A light’s color changes must follow the proper sequence. At most one light can change. If the light that changed is red, then the other lights must be red. Let’s first implement this constraint.

Example of a valid and invalid light sequence A traffic light can change from red to green, but not from red to yellow.

The set of valid light sequences

No change in color, i. e. , identity mappings No change in color, i.e., identity mappings. The next few slides show a really neat way to generate these identity mappings.

Here’s our universe univ L1 L2 L3 Light L4 L5 L6 state1 LightState red yellow Color green 5th & Elm 6th & Elm Junction 7th & Elm

Identity mappings iden L1 L1 L2 L2 L3 L3 L4 L4 L5 L5 L6 L6 state1 red red yellow yellow green green 5th & Elm 5th & Elm 6th & Elm 6th & Elm 7th & Elm 7th & Elm

Color identity mappings “Restriction operator.” It says: give me all the color mappings in iden. iden L1 L1 Color L2 L2 Color <: iden red red red L3 L3 yellow yellow yellow L4 L4 green green green L5 L5 L6 L6 Color identity mappings state1 state1 state2 state2 red red yellow yellow green green 5th & Elm 5th & Elm 6th & Elm 6th & Elm 7th & Elm 7th & Elm

The set of valid traffic light color sequences Red -> green + Green -> yellow + Yellow -> red + Red -> red Green -> green Yellow -> yellow Color <: iden

Here’s an Alloy function that returns the valid color sequences fun colorSequence: Color -> Color { (Color <: iden) + (Red -> Green) + (Green -> Yellow) + (Yellow -> Red) } colorSequence returns this mapping: red red yellow yellow green green red green green yellow yellow red

For the lights at a junction: For the light change: A light’s color changes must follow the proper sequence. At most one light can change. If the light that changed is red, then the other lights must be red. Now let’s implement this constraint.

Here’s how to get the lights at junction j j: Junction lights x 5th & Elm 5th & Elm L1 x: j.lights L1 5th & Elm L2 L2 6th & Elm L3 x denotes the lights at 5th & Elm 6th & Elm L4 7th & Elm L5 7th & Elm L6

Here’s how to get the colors of the lights at 5th & Elm, in state1 x s: LightState color L1 state1 state1 L1 red x.(s.color) L2 state1 L2 green state1 L3 green state1 L4 red red state1 L5 green green state1 L6 yellow state2 L1 red state2 L2 yellow state2 L3 yellow state2 L4 red state2 L5 green state2 L6 red

Equivalent x.(s.color) s.color[x]

Here’s how to get the colors of the lights at 5th & Elm, in state2 red state1 L2 green state1 L3 green state1 L4 red state1 L5 green x s: LightState state1 L6 yellow L1 state2 state2 L1 red s.color[x] L2 state2 L2 yellow state2 L3 yellow state2 L4 red red state2 L5 green yellow state2 L6 red

Light changes at 5th & Elm between state1 and state2 red red green yellow state1 state2 Only one light changed from state1 to state 2.

Alloy code that expresses: At most one light changes color from state s to state s’ pred at_most_one_light_changes_color (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] }

Implemented For the lights at a junction: For the light change: A light’s color changes must follow the proper sequence. At most one light can change. If the light that changed is red, then the other lights must be red. Implemented

Consider the lights at a junction: Consider a light change: A light’s color changes must follow the proper sequence. At most one light can change. If the light that changed is red, then the other lights must be red. Now let’s implement this constraint.

Let s be the current state of the traffic lights Let s be the current state of the traffic lights. Then s’ is a valid next state for the traffic lights at junction j if: At most one light changes between s and s’. For each light x at junction j: The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red.

pred transition (s, s': LightState, j: Junction) { At most one light changes between s and s’. For each light x at junction j: The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red. }

pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] pred transition (s, s': LightState, j: Junction) { At most one light changes between s and s’. For each light x at junction j: The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red. }

pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] For each light x at junction j: The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red. } all x: j.lights

pred transition (s, s': LightState, j: Junction) { s.color[x] pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red. } colorSequence s'.color[x]

pred transition (s, s': LightState, j: Junction) { let step = s.color[x] -> s'.color[x] step in colorSequence pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | The mapping from the color of x in state s to the color of x in state s’ is part of the color sequence. If x changes color from red to non-red, then all the lights at junction j, in state s, must be red. }

pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] step in colorSequence If x changes color from red to non- red, then all the lights at junction j, in state s, must be red. } Red -> (Color - Red) j.lights

pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] step in colorSequence If x changes color from red to non- red, then all the lights at junction j, in state s, must be red. } step in Red -> (Color - Red) => j.lights in redLights[s]

pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] { step in colorSequence step in Red -> (Color - Red) => j.lights in redLights[s] }

This predicate only requires instances contain a junction j and a pair of states s and s’ that satisfy the constraints. But we want all junctions and all pairs of states to satisfy the constraints. pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] { step in colorSequence step in Red -> (Color - Red) => j.lights in redLights[s] }

Also notice that this predicate assumes nothing about the current state s. So all the lights at junction j in state s could be green! We need to constrain s to those states where all lights are red except at most one. pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] { step in colorSequence step in Red -> (Color - Red) => j.lights in redLights[s] }

assert SafeTrafficLights { all s, s': LightState, j: Junction | all_lights_red_except_at_most_one_light [s, j] and transition [s, s', j] => all_lights_red_except_at_most_one_light [s', j] } Assertion: every junction and every light transition is safe.

Yea!

Here’s the complete Alloy code: abstract sig Color {} one sig Red, Yellow, Green extends Color {} sig Light {} sig Junction { lights: set Light } sig LightState { color: Light -> one Color fun colorSequence: Color -> Color { (Color <: iden) + (Red -> Green) + (Green -> Yellow) + (Yellow -> Red) fun redLights (s: LightState): set Light { s.color.Red pred all_lights_red_except_at_most_one_light (s: LightState, j: Junction) { lone j.lights - redLights[s] pred transition (s, s': LightState, j: Junction) { lone x: j.lights | s.color[x] != s'.color[x] all x: j.lights | let step = s.color[x] -> s'.color[x] { step in colorSequence step in Red -> (Color - Red) => j.lights in redLights[s] assert SafeTrafficLights { all s, s': LightState, j: Junction | all_lights_red_except_at_most_one_light [s, j] and transition [s, s', j] => all_lights_red_except_at_most_one_light[s', j] check SafeTrafficLights Here’s the complete Alloy code:

Extend the traffic model to ensure against security flaws https://jhalderm.com/pub/papers/traffic-woot14.pdf