analysis contracts for cps - ls.cs.cmu.edu

20
Analysis Contracts for CPS Presenter: Dionisio de Niz 1 [email protected] CPS V&V Workshop Team: Ivan Ruchkin 2 , Sagar Chaki 1 , David Garlan 2 1 Software Engineering Institute & 2 School of Computer Science

Upload: others

Post on 20-Jun-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Analysis Contracts for CPS - ls.cs.cmu.edu

Analysis Contracts for CPS

Presenter: Dionisio de Niz1

[email protected]

CPS V&V Workshop

Team: Ivan Ruchkin2, Sagar Chaki1,

David Garlan2

1Software Engineering Institute & 2School of Computer Science

Page 2: Analysis Contracts for CPS - ls.cs.cmu.edu

2

Copyright 2014 Carnegie Mellon University This material is based upon work funded and supported by the Department of Defense under Contract No. FA8721-05-C-0003 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the United States Department of Defense. NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN โ€œAS-ISโ€ BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. This material has been approved for public release and unlimited distribution except as restricted below. This material may be reproduced in its entirety, without modification, and freely distributed in written or electronic form without requesting formal permission. Permission is required for any other use. Requests for permission should be directed to the Software Engineering Institute at [email protected]. Carnegie Mellonยฎ is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. DM-0001998

Page 3: Analysis Contracts for CPS - ls.cs.cmu.edu

3

Motivation

The development of Cyber-Physical Systems (aircrafts, cars, trains, robots, etc.) increasingly relies on many types of analyses from different disciplines for assurance purposes

โ€ข Control stability, scheduling, logic, thermal, power, aerodynamics, etc.

Large CPS are integrated out of components developed by suppliers that use their own analysis methods and make their own assumptions

Analysis assumption mismatches are discovered late in the system integration phase

โ€ข Difficult and costly to solve

Page 4: Analysis Contracts for CPS - ls.cs.cmu.edu

4

Boeing 787 Suppliers

Kawasaki

Spirit

Saab

Goodrich

Rolls Royce

Boeing Australia

Mitsubishi

Boeing US Alenia

Alenia

KAL-ASD

Latecoere

Source: Boeing / Reuters

Page 5: Analysis Contracts for CPS - ls.cs.cmu.edu

5

Inter-Domain Analyses Interactions

Cha

rge

Dis

ch

arg

e

Source: National Renewable Energy Laboratory

main(){

for(i=0;;)

โ€ฆ

}

main(){

for(i=0;;)

โ€ฆ

}

main(){

for(i=0;;)

โ€ฆ

}

Scheduling +

Frequency

Scaling

Battery Recharge Scheduling

Selected

Voltage Cell Interconnects

Thermal Runaway Analysis

Page 6: Analysis Contracts for CPS - ls.cs.cmu.edu

6

Analysis Contracts

Sensor

Sampling

PID

Controller

Actuator

Controller

Sensor

Board CPU

Actuator

Board

Comm Protocol (reliable/unreliable)

Control Stability Schedulability

Pow

er

Exec T

ime

Frequency Scaling

Discharge Charge

Battery Sched

Tem

p

Thermal runaway

Assumption

Guarantee

Read/write Read/write

Read/w

rite

R

ead/w

rite

deadlock

Model checking

Read/write

AADL

Page 7: Analysis Contracts for CPS - ls.cs.cmu.edu

7

Analysis Contracts Structure

AADL Model

Domain (e.g. in SPIN)

Analysis

Plugin Analysis

Plugin

Domain (e.g. in SMT)

Analysis

Plugin Analysis

Plugin

Contract

(Annex) Contract

(Annex)

Contract

(Annex)

Contract

(Annex)

Page 8: Analysis Contracts for CPS - ls.cs.cmu.edu

8

Contract Semantic Basis

Domain (๐’œ, ๐’ฎ, โ„›, ๐’ฏ, โ‹… ๐œŽ)

โ€ข Sorts ๐’œ = ๐ด1, ๐ด2, โ€ฆ , e.g. Booleans, Integers, Threads, Priorities

โ€ข Static Properties : ๐’ฎ = ๐‘†๐‘– , ๐‘†๐‘–: ๐ด1 ร— โ‹ฏ ร— ๐ด๐‘— โ†ฆ ๐ด๐‘˜

โ€” Design-time invariants, Regular operators: (โˆง, โ„ฌ ร— โ„ฌ โ†ฆ โ„ฌ)

โ€ข Runtime Properties : โ„› = ๐‘…๐‘– , ๐‘…๐‘–: ๐ด1 ร— โ‹ฏ ร— ๐ด๐‘— โ†ฆ ๐ด๐‘˜

โ€” Evolving valuation at different states q: q(๐‘…๐‘–)

โ€ข Domain execution semantics: ๐’ฏ

โ€” Infinite sequence of assignments to runtime properties (executions)

โ€ข Domain interpretation of sorts/static properties: โ‹… ๐œŽ

โ€” E.g. allowed schedulers, some left uninterpreted

Architectural Model Interpretation: โ‹… ๐‘€ on ๐’œ, ๐’ฎ, ๐’ฏ

โ€ข E.g. threads and periods: ๐‘‡ ๐‘€ = ๐‘ก1, ๐‘ก2 ; ๐‘ƒ๐‘’๐‘Ÿ ๐‘€ = {๐‘ก1 โ†ฆ 10, ๐‘ก2 โ†ฆ 20}

Executions of system defined by M: ๐’ฏ ๐‘€

โ€ข Combining โ‹… ๐œŽ , โ‹… ๐‘€ into โ‹…

โ€ข Each state q in possible states Q maps ๐‘…๐‘– to function ๐‘ž ๐‘…๐‘– : ๐ด1 ร— โ‹ฏ ร— ๐ด๐‘— โ†ฆ ๐ด๐‘˜

โ€ข With all infinite sequence of states ๐‘„๐œ”

โ€ข ๐’ฏ ๐‘€ โŠ† ๐‘„๐œ”

Page 9: Analysis Contracts for CPS - ls.cs.cmu.edu

9

Contract Language

Contract formulas

โ€ข Given domain ๐œŽ = (๐’œ, ๐’ฎ, โ„›, ๐’ฏ, โ‹… ๐œŽ),

โ€ข โ„ฑ๐œŽ โˆท= โˆ€ ๐‘ฃ1, โ€ฆ , ๐‘ฃ๐‘— โ‹… ๐œ™ โˆƒ ๐‘ฃ1, โ€ฆ , ๐‘ฃ๐‘— โ‹… ๐œ™ โˆ€ ๐‘ฃ1, โ€ฆ , ๐‘ฃ๐‘— โ‹… ๐œ™: ๐œ“|โˆƒ๐‘ฃ1, โ€ฆ , ๐‘ฃ๐‘— โ‹… ๐œ™: ๐œ“

โ€” ๐‘ฃ๐‘–: ๐ด๐‘–, ๐œ™: static (first order) formula

โ€” ๐œ“ : LTL formula

Contract ๐ถ = (๐ผ, ๐‘‚, ๐ด, ๐บ)

โ€ข ๐ผ โŠ† (๐’œ โˆช ๐’ฎ): Sorts and properties read by the analysis

โ€ข ๐‘‚ โŠ† (๐’œ โˆช ๐’ฎ): Sorts and properties written by the analysis

โ€ข ๐ด โŠ† โ„ฑ๐œŽ: assumptions: must be true in input

โ€ข ๐บ โŠ† โ„ฑ๐œŽ: guarantees: must be true in output

Page 10: Analysis Contracts for CPS - ls.cs.cmu.edu

10

Contract Verification

Given model M and set of analyses ๐’œ๐’ฉ = {๐ด๐‘›๐‘–}:

โ€ข For ๐ด๐‘›๐‘– . ๐ถ = ๐ผ, ๐‘‚, ๐ด, ๐บ : M application to ๐ด๐‘›๐‘– iff

โ€” โˆ€ ๐‘Ž โˆˆ ๐ด โ‹… ๐‘€ โŠจ ๐‘Ž, โˆ€ ๐‘” โˆˆ ๐บ โ‹… Ani M โŠจ ๐‘”

Valid analysis ordering: no dependencies from later analysis

โ€ข Contract (& analysis) dependency: d Ci, Cj : Ci. I โˆฉ ๐ถ๐‘— . ๐‘‚ โ‰  โˆ…

Contract Formulas

โ€ข First order: in SMT (Z3)

โ€ข LTL : Model checker

โ€ข FOL + LTL: Generate all solutions for FOL, check LTL in each

Page 11: Analysis Contracts for CPS - ls.cs.cmu.edu

11

Example: Surveillance Aircraft

Analysis

Security: tasks of different level

to different processor

Scheduling: meet all deadlines

Freq. Scaling: minimize power

Logic: no deadlocks or race

conditions

Battery scheduling: meet

battery lifetime

Battery thermal: no runaways

main(){

for(i=0;;)

โ€ฆ

}

main(){

for(i=0;;)

โ€ฆ

}

main(){

for(i=0;;)

โ€ฆ

}

Security: Top Secret Security: Secret

Battery

Software

Processors

Page 12: Analysis Contracts for CPS - ls.cs.cmu.edu

12

Surveillance Aircraft Contracts

Security Analysis

โ€ข ๐ด๐‘›๐‘ ๐‘’๐‘ . ๐ถ: ๐ผ = ๐‘‡, ๐‘‡โ„Ž๐‘†๐‘’๐‘๐ถ๐‘™ , ๐‘‚ = ๐‘๐‘œ๐‘ก๐ถ๐‘œ๐‘™๐‘œ๐‘ , ๐ด = โˆ…, ๐บ = {๐‘”}

โ€” ๐‘”: โˆ€ ๐‘ก1, ๐‘ก2 โ‹… ๐‘‡โ„Ž๐‘†๐‘’๐‘๐ถ๐‘™ ๐‘ก1 โ‰  ๐‘‡โ„Ž๐‘†๐‘’๐‘๐ถ๐‘™ ๐‘ก2 โ‡’ ๐‘ก1 โˆˆ ๐‘๐‘œ๐‘ก๐ถ๐‘œ๐‘™๐‘œ๐‘(๐‘ก2)

Multiprocessor scheduling: (Binpacking + scheduling)

โ€ข ๐ด๐‘›๐‘ ๐‘โ„Ž๐‘’๐‘‘ . ๐ถ: ๐ผ = ๐‘‡, ๐ถ, ๐‘๐‘œ๐‘ก๐ถ๐‘œ๐‘™๐‘œ๐‘, ๐‘ƒ๐‘’๐‘Ÿ, ๐‘Š๐ถ๐ธ๐‘‡, ๐ท๐‘™๐‘–๐‘›๐‘’ , ๐‘‚ = ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ , ๐ด = โˆ…, ๐บ = {๐‘”}

โ€” ๐‘”: โˆ€ ๐‘ก1, ๐‘ก2 โ‹… ๐‘ก1 โˆˆ ๐‘๐‘œ๐‘ก๐ถ๐‘œ๐‘™๐‘œ๐‘ ๐‘ก2 โ‡’ ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ ๐‘ก1 โ‰  ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘(๐‘ก2)

Frequency Scaling

โ€ข ๐ด๐‘›๐‘“๐‘Ÿ๐‘’๐‘ž๐‘ ๐‘ . ๐ถ: ๐ผ = ๐‘‡, ๐ถ, ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘, ๐ท๐‘™๐‘–๐‘›๐‘’ , ๐‘‚ = ๐ถ๐‘ƒ๐‘ˆ๐น๐‘Ÿ๐‘’๐‘ž , ๐บ = โˆ…, ๐ด = {๐‘Ž}

โ€” ๐‘Ž: โˆ€๐‘ก1, ๐‘ก2 โ‹… ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ ๐‘ก1 = ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ ๐‘ก2 : ๐บ(๐ถ๐‘Ž๐‘›๐‘ƒ๐‘Ÿ๐‘š๐‘๐‘ก ๐‘ก1, ๐‘ก2 โ‡’ ๐ท๐‘™๐‘–๐‘›๐‘’ ๐‘ก1 < ๐ท๐‘™๐‘–๐‘›๐‘’(๐‘ก2)

Model checking periodic program (REK):

โ€ข ๐ด๐‘›๐‘Ÿ๐‘’๐‘˜. ๐ถ: ๐ผ = ๐‘‡, ๐ถ, ๐‘ƒ๐‘’๐‘Ÿ, ๐ท๐‘™๐‘–๐‘›๐‘’, ๐‘Š๐ถ๐ธ๐‘‡, ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ , ๐‘‚ = ๐‘‡โ„Ž๐‘†๐‘Ž๐‘“๐‘’ , ๐บ = โˆ…, ๐ด = {๐‘Ž1, ๐‘Ž2}

โ€ข ๐‘Ž1: โˆ€๐‘ก โ‹… ๐‘ƒ๐‘’๐‘Ÿ ๐‘ก = ๐ท๐‘™๐‘–๐‘›๐‘’ ๐‘ก , ๐‘Ž2: โˆ€๐‘ก1, ๐‘ก2 โ‹… ๐บ(๐ถ๐‘Ž๐‘›๐‘๐‘Ÿ๐‘š๐‘๐‘ก ๐‘ก1, ๐‘ก2 โ‡’ ๐บ ยฌ๐ถ๐‘Ž๐‘›๐‘ƒ๐‘Ÿ๐‘š๐‘๐‘ก ๐‘ก2, ๐‘ก1 )

Thermal runaway:

โ€ข ๐ด๐‘›๐‘กโ„Ž๐‘’๐‘Ÿ๐‘š . ๐ถ: ๐ผ = ๐ต, ๐ต๐‘Ž๐‘ก๐‘…๐‘œ๐‘ค๐‘ , ๐ต๐‘Ž๐‘ก๐ถ๐‘œ๐‘™๐‘ , ๐‘‰๐‘œ๐‘™๐‘ก๐‘Ž๐‘”๐‘’ , ๐‘‚ = ๐พ , ๐ด = โˆ…, ๐บ = โˆ…

Battery Scheduling

โ€ข ๐ด๐‘›๐‘๐‘ ๐‘โ„Ž๐‘’๐‘‘ . ๐ถ: ๐ผ = ๐ต, ๐ต๐‘Ž๐‘ก๐‘…๐‘œ๐‘ค๐‘ , ๐ต๐‘Ž๐‘ก๐ถ๐‘œ๐‘™๐‘  , ๐‘‚ = ๐ต๐‘Ž๐‘ก๐ถ๐‘œ๐‘›๐‘›๐‘†๐‘โ„Ž๐‘’๐‘‘๐‘ƒ๐‘œ๐‘™, ๐ป๐‘Ž๐‘ ๐‘…๐‘’๐‘ž๐ฟ๐‘–๐‘“๐‘’๐‘ก๐‘–๐‘š๐‘’, ๐‘†๐‘’๐‘Ÿ๐‘–๐‘ž๐‘™๐‘…๐‘’๐‘ž, ๐‘ƒ๐‘Ž๐‘Ÿ๐‘Ž๐‘™๐‘…๐‘’๐‘Ž , ๐ด = โˆ…, ๐บ ={๐‘”}

โ€ข ๐‘”: ๐บ(๐พ 0 ร— ๐‘‡๐‘ 0 + ๐พ 1 ร— ๐‘‡๐‘ 1 + ๐พ 2 ร— ๐‘‡๐‘ 2 + ๐พ 3 ร— ๐‘‡๐‘ 3 โ‰ฅ 0)

Page 13: Analysis Contracts for CPS - ls.cs.cmu.edu

13

Satisfying Assumptions in Specific System: Frequency Scaling

๐‘Ž: โˆ€๐‘ก1, ๐‘ก2 โ‹… ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ ๐‘ก1 = ๐ถ๐‘ƒ๐‘ˆ๐ต๐‘–๐‘›๐‘‘ ๐‘ก2 : ๐บ(๐ถ๐‘Ž๐‘›๐‘ƒ๐‘Ÿ๐‘š๐‘๐‘ก ๐‘ก1, ๐‘ก2 โ‡’ ๐ท๐‘™๐‘–๐‘›๐‘’ ๐‘ก1 < ๐ท๐‘™๐‘–๐‘›๐‘’(๐‘ก2)

P D

P=D

P=D

P=D

DMSโ‰ RMS

DMS=RMS

EDFโ‰ RMS

EDF=RMS

P=D, Harmonic, Sync

Page 14: Analysis Contracts for CPS - ls.cs.cmu.edu

14

Satisfying Assumptions in Specific System: Battery Scheduling Assumption

๐‘”: ๐บ(๐พ 0 ร— ๐‘‡๐‘ 0 + ๐พ 1 ร— ๐‘‡๐‘ 1 + ๐พ 2 ร— ๐‘‡๐‘ 2 + ๐พ 3 ร— ๐‘‡๐‘ 3 โ‰ฅ 0)

Cells w 1 neighbors TN(1)

Cells w 2 neighbors TN(2)

Cells

w 3

neig

hbors

TN

(3)

Ratio of cells with 0,1,2,3 neighbors: 1 โ‹… ๐‘‡๐‘ 1 โˆ’ 1 โ‹… ๐‘‡๐‘ 2 + 10 โ‹… ๐‘‡๐‘ 3 โ‰ฅ0

1 โ‹… 4 โˆ’ 1 โ‹… 10 + 10 โ‹… 2 = 14 โ‰ฅ 0 1 โ‹… 2 โˆ’ 1 โ‹… 14 + 10 โ‹… 0 = โˆ’12 < 0

Page 15: Analysis Contracts for CPS - ls.cs.cmu.edu

15

ACTIVE Tool

Plugins for OSATE that consist of

Contract Annex Sublanguage (Parser)

โ€ข Captures analysis contracts within AADL models

ACTIVE Executer

โ€ข Interprets contracts and identifies valid execution schedules

ACTIVE Verifier

โ€ข Identifies and run contract verification engines

Page 16: Analysis Contracts for CPS - ls.cs.cmu.edu

16

Analysis Contract Annex

package Contracts

public

with Contract_Properties, SEI, Deployment_Properties;

annex contract {**

name SecureAllocationAnalysis

input thread, thread.SecurityLevel

output thread.Not_Colocated

guarantees

forall x1: thread, x2:thread :

x1 != x2 -> (x1.SecurityLevel = x2.SecurityLevel) || x1 in x2.Not_Colocated

โ€ฆ

**};

end Contracts;

package AircraftPackage

public

with Contract;

system implementation AircraftSystem.i

โ€ฆ

annex contract {**

use contracts::SecureAllocationAnalysis,

contracts::BinPackingAnalysis,

โ€ฆ

**};

end AircraftSystem.i;

end AircraftPackage;

Page 17: Analysis Contracts for CPS - ls.cs.cmu.edu

17

Analysis Contract Annex Examples

name LlrekAnalysis

input thread, thread.Period, thread.Deadline,

thread.Source_Text, thread.Priority,

thread.Compute_Execution_Time,

thread.Priority,

thread.Actual_Processor_Binding

output system.Is_Thread_Safe

assumes

forall t: thread : t.Period = t.Deadline

assumes

forall t1:thread, t2: thread | t1 != t2 :

G (CanPreempt(t1, t2) =>

(G!CanPreempt(t2, t1)))

name BatterySchedulingAnalysis

input device, device.Cell_Rows,

device.Cell_Cols, device.K0, device.K1,

device.K2, device.K3,

processor.Current_Frequency

output device.Serial_Req, device.Paral_Req,

device.Bat_Scheduler

guarantees

forall b: device :

G (b.K0 * b.TN(0) + b.K1*b.TN(1) +

b.K2*b.TN(2) + b.K3*b.TN(3) >= 0 )

Page 18: Analysis Contracts for CPS - ls.cs.cmu.edu

18

ACTIVE Executer

Responsibilities

โ€ข Parse โ€œuseโ€ subclauses in scope

โ€ข Retrieve referred contracts from

libraries

โ€ข Create dependency graph

* no cycle support

โ€ข Correct sequence of execution

of analysis and verifiers

โ€ข Plugin wrappers to prevent

compiling dependencies

+ Monitors plugin completion

Page 19: Analysis Contracts for CPS - ls.cs.cmu.edu

19

ACTIVE Verifier

Decompose contract formulas into segments verifiable by single verifier

1. <Quan><Var><Predicate Expression>

โ€” e.g.: forall t:thread | t.Period = t.Deadline

โ€” sent to SMT solver. Each solution is later blocked to get all solutions

โ€” Identifies part of model that should be verified

2. <LTLExpression>

โ€” Identify domain atoms and functions: e.g. thread, CanPreempt()

โ€” Select verifier that can interpret all atoms, functions, and operators

โ€” Translate AADL model into verifier data (e.g. threads, periods,

scheduler, etc.)

โ€” Run verifier

โ€” Interpret and put results back into AADL model

Page 20: Analysis Contracts for CPS - ls.cs.cmu.edu

20

Conclusions

Analyses from multiple domains are key for development of CPS

โ€ข But inconsistent assumptions may compromise results

Analysis contracts to automatically verify assumptions

โ€ข Analysis contract language & verification framework

โ€ข Implementation in AADL sub-annex

ACTIVE (Analysis ContracT Integration VErifier) Tool

โ€ข Extensible

โ€ข ACTIVE Executer + ACTIVE Verifier

Tested on two domains and five analyses