The text of a manual · part 5 of 14
Feasibility of formal model checking in the Vitatron environment: Chapter 2Model checking, pages 19 to 26
Pages 19 to 26 of 91, from Feasibility of formal model checking in the Vitatron environment
The original document is the PDF (6.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the Vitatron EE244
Page 19
This section introduces the main concepts of mCRL2, heavily based on [9] and [10]. For more information see these papers. The mCRL2 language can be used to specify formal models, representing the behavior of distributed systems and protocols; using its accompanying toolset models can be analyzed and verified automatically. The ‘about’-section of [2] contains a good description of the mCRL2 philosophy: “mCRL2 is based on the Algebra of Communicating Processes (ACP) which is extended to include data and time. Like in every process algebra, a fundamental concept in mCRL2 is the process. Processes can perform actions and can be composed to form new processes using algebraic operators. A system usually consists of several processes (or components) in parallel. A process can carry data as its parameters. The state of a process is a specific combination of parameter values. This state may influence the possible actions that the process can perform. In turn, the execution of an action may result in a state change. Every process has a corresponding state space or Labeled Transition System (LTS) which contains all states that the process can reach, along with the possible transitions between those states. Using the algebraic operators, very complex processes can be constructed containing, for example, lots of parallelism. A central notion in mCRL2 is the linear process. This is a process from which all parallelism has been removed to produce a series of condition - action - effect rules. Complex systems, consisting of hundreds or even thousands of processes, can be translated to a single linear process. Even for systems with an infinite state space, the linear process (being an abstract representation of that state space) is finite and can often be obtained very easily. Therefore, most tools in the mCRL2 toolset operate on linear processes rather than on state spaces.” It should be noticed that the mentioned built-in concept of time is somewhat premature and therefore this concept is not used in this project. Instead, the passing of time is explicitly modeled in all time-dependent processes. The mCRL2 model description in section 5.2 comes back to this point.
2.1.1
The process specification language
This section describes the mCRL2 language followed by the mCRL2 specification of the coffee machine model, which might clarify how the contents of the language relate to each other. Processes and actions are the fundamental concepts in the mCRL2 language. A process in mCRL2 describes the behavior of a component in the modeled distributed system. Actions represent atomic events, which possibly can be synchronized with other actions. When two actions are declared synchronous, the actions can be performed by two different processes truly in parallel. By this synchronization mechanism communication and interaction between processes can be modeled. Processes are defined by process expressions, which are compositions of actions using a number of operators. The basic operators are as follows (let a and b be arbitrary actions and let p and q be arbitrary process expressions): • Deadlock or inaction δ, which does not display any behavior. 18
Page 20
• Alternative composition, written as p + q. This represents a non-deterministic choice between p and q. • Sequential composition, written as p · q. This expression first executes p and then q (assuming p terminates). • Recursion describes iterating behavior of a process. A simple example of recursion is the process expression X = a · X + b. This process describes a sequence of a actions of arbitrary length (as long as the first alternative is chosen) followed by a single b action. • Parallel composition or merge, written as p k q, which interleaves and synchronizes the actions of p with those of q. • Synchronization operator p|q, which synchronizes the first actions of p and q and combines the rest of p and q like the parallel composition. • Multiaction a| . . . |b, which is a special instance of the synchronization operator where the arguments are single actions (or multiactions). The meaning of a multiaction is that all actions occurring in it happen at the same moment (i.e. truly in parallel). Furthermore there are some operators to restrict the behavior of process expressions in order to model the interaction between processes. The restriction operator(∇) and blocking operator(∂) can be used to specify explicitly which multiactions are allowed to occur or are not allowed to occur, respectively. With the communication operator(Γ) a set of allowed communications can be defined, for example a communication a0 | . . . |an → c means that every group of actions a0 , . . . , an within a multiaction is replaced by c (this is expressed by Γ{a0 |...|an →c} (p) where p is the process expression on which the communication operator is applied). When we for instance want to model communication from process X to process Y , we declare three actions send , receive, and communicate and we define the process expressions of X and Y as follows: X = send and Y = receive. Then we use the communication operator to specify that the send action and the receive action synchronize to the communicate action (send |receive → communicate). Because we do not want X to send without Y receiving and vice versa, we use the restriction operator to specify that only the communicate action can occur. This combination of the synchronization and restriction operators is often used in modeling communicating processes. Before we move on to the data aspects of the language, the notion of abstraction has to be mentioned in the context of mCRL2. Usually the requirements of a system are defined in terms of external behavior (i.e. the interactions of the system with its environment), while one wishes to check these requirements on an implementation of the system which also contains internal behavior (i.e. the interaction between the components of the system). So it is desirable to be able to abstract from the internal behavior of the implementation. This is possible ‘hiding’ internal actions in a mCRL2 specification. This abstraction can be useful in reducing state space sizes. When internal actions are hidden and the state space is generated, reduction techniques based on bisimulation equivalence can be applied to the state space. More information can be found in [11].
19
Page 21
Data There are some standard data sorts and functions included in mCRL2. Unbounded positive (N+ ), natural (N), integer (Z) and real numbers (R) are included with all relational and arithmetic operators. Note that real numbers are only used in the time functionality, which will not be covered here. Booleans (B) are included with all elementary operators. Boolean expressions can be used in conditions, which are used together with the conditional operator, written as c → p q, where c is a boolean data expression. This process expression behaves as an if-then-else construct: take for example the process expression X = (n ≥ 10) → a b, which expresses that action a is performed for n at least 10, otherwise action b is performed. Note that the else-branch is optional; c → p is a valid expression which expresses that p is only performed if c holds. Besides these standard data sorts it is possible to declare custom sorts together with functions on these sorts. This can be done by declaring constructors, functions and their definitions manually or by using one of the type constructors. There is a type constructor for structured types, for list types, for sets, and finally one for bags. These type constructors automatically provide some standard functions to the type, for example comparing functions. Data can be used to parameterize actions and processes. As an example, actions can be declared as follows: act a; b, c, d : N; e : B × N+ ;
This declares parameterless action a, actions b, c and d with a data parameter of sort N, and action e with two parameters of sort B and N+ , respectively. For the above declaration, a, b(0) and e(false, 6) are valid actions. For all operators, except the communication operator, the data parameterization doesn’t change much; the data parameters are just retained when an operator is applied. The communication operator ΓC (p) has become stricter: for each communication a0 | . . . |an → c, n ≥ 1, multiactions a0 (. . .)| . . . |an (. . .) in p are only replaced by c(. . .) when the data parameters of all ai are equal (both the number of parameters and their values). The data parameters are retained in action c. For example Γ{b|c→d} (b(0)|c(0)) = d(0), but also Γ{b|c→d} (b(0)|c(1)) = b(0)|c(1). Furthermore Γ{b|c→d} (b(1)|b(0)|c(1)) = b(0)|d(1). Processes can be parameterized as follows: proc
P (d : B, e : N+ ) = a · P (d, e) +b(d) · P (¬d, e + 1) +c(d, e) · P (false, max (e − 1, 1));
This declares the process P with data parameters d and e of sort B and N+ , respectively. Note that the data parameters can be seen as local variables in the process, which are declared in the left-hand side of the equation. In the process references on the right-hand side it is specified how the values of the data parameters are changed when the corresponding action(s) in front of it are performed. There is also the ability to quantify over (possibly infinite) data types in process expressions. P This is provided through the summation operator d:D p where p is a process expression in 20
Page 22
which data variable d may occur. The corresponding behavior is p[d0 /d] + · · · + p[dn /d] + · · · , n ≥ 0, for all elements di ∈P D. Here, p[di /d] stands for p in which each free occurrence of d (i.e. not bound by another d:D ) is replaced by di . Summations over a data type are particularly useful to model the receipt of an arbitrary element of a data type. For example the following process is a description of a single-place buffer, repeatedly reading a natural number using action name r, and then delivering that value via action name s. act proc r, s : N; P Buffer = n:N r(n) · s(n) · Buffer ;
After this overview of the mCRL2 process specification language, we give an mCRL2 model of our coffee machine system. This model includes a process that represents the machine and a process that represents a user of the machine, which communicate with each other. As all mCRL2 models this model is structured as follows: first the custom sorts and all used actions are declared, next the process expressions that define the machine process (line 1332) and the user process (line 34-49) are given and finally the initial state of the model is defined. Note that alternative composition (+) is used in combination with conditions to specify all transitions of the state transition diagram in figure 2.2 in process Machine. The communication and restriction operator are used in the initial state definition to specify the possible communications between the processes. In the model we have given comments on some lines by stating them after the comment operator %. 1. % line 2-4 declare three structured data types 2. sort sort choice: struct tea | coffee | water; 3. machine state: struct start | wait | prepared | served; 4. user state: struct ready | chosen; 5. act r choose tea, s choose tea, c choose tea; 6. r choose coffee, s choose coffee, c choose coffee; 7. r choose water , s choose water , c choose water ; 8. r coin, s coin, c coin : N; 9. prepare : sort choice; 10. r serve, s serve, c serve : sort choice; 11. r return, s return, c return : N; 12. 13. proc Machine(state : machine state, choice : sort choice, paid : N) = 14. % line 15-19 define the behavior of Machine if state equals start 15. (state ≈ start) → 16. ( % line 17: receive of choose coffee changes state to (wait, coffee, paid ) 17. r choose coffee · Machine(wait, coffee, paid )+ 18. r choose tea · Machine(wait, tea, paid ) 19. )+ 20. (state ≈ wait) → 21. ( (paid < 30) → 22. % accept receive of coin with any natural valued parameter y 23. % Psuch a message changes state to (wait, choice, paid + y) 24. y:N r coin(y) · Machine(wait, choice, paid + y)+ 25.
26. % paid at least 30, so perform prepare action 27. prepare(choice) · Machine(prepared, choice, paid )
21
Page 23
28. )+ 29. (state ≈ prepared) → 30. s serve(choice) · Machine(served, choice, paid − 30); 31. (state ≈ served) → 32. s return(paid ) · Machine(start, choice, 0); 33. 34. proc User (state : user state) = 35. (state ≈ ready) → 36. ( s choose coffee · User (chosen coffee)+ 37. s choose tea · User (chosen tea)+ 38. s choose water · User (chosen water) 39. )+ 40. (state ≈ chosen coffee ∨ state ≈ chosen tea ∨ state ≈ chosen water) → 41. ( % drink is chosen, perform s coin action for a possible coin value 42. % or perform r serve action with any parameter of sort sort choice, 43. % followed by r return action with any natural valued parameter 44. s coin(5 ) · User (state)+ 45. s coin(10 ) · User (state)+ 46. sPcoin(20 ) · User (state)+ P 47. drink :sort choice r serve(drink ) · remainder :N r return(remainder )· 48. User (ready) 49. ); 50. 51. % line 52-65 define the initial state of the complete model 52. init % line 53 uses the restriction operator to allow only c actions and prepare 53. ∇{c choose tea,c choose coffee,c choose water ,c coin,prepare,c serve,c return} ( 54. % line 55-60 uses the communication operator to specify the communications 55. Γ{r choose tea|s choose tea→c choose tea, 56. r choose coffee|s choose coffee→c choose coffee, 57. r choose water |s choose water →c choose water , 58. r coin|s coin→c coin, 59. r serve|s serve→c serve, 60. r return|s return→c return} ( 61. % line 63 and 64 give the initial states of the individual processes 62. % parallel composition (k) is used to place the processes in parallel 63. Machine(start, tea, 0)k 64. User (ready) 65. ));
2.1.2
Modal µ-calculus
The mCRL2 model checking tools accept properties that are formulated in the modal µcalculus, which is an extension to the Hennessy-Milner logic as described in section 2.0.2. Although the Hennessy-Milner logic with regular expressions is already very expressive and most behavioral properties can be specified in this logic, the modal µ-calculus is even more expressive through the addition of minimal and maximal fixed point operators. However, this addition also makes it rather difficult to formulate correct properties in the modal µ-calculus. Note that all formulas in the Hennessy-Milner logic can also be used in mCRL2, because this logic is a true subset of the modal µ-calculus. We give a brief introduction of the modal µ-calculus for the interested reader.
22
Page 24
The syntax of the modal µ-calculus is as follows: φ ::= true | false | ¬φ | φ ∧ φ | φ ∨ φ | φ → φ | haiφ | [a]φ | µX .φ | νX .φ | X . The formula µX.φ is the minimal fixed point and νX.φ is the maximal fixed point. X is just a variables which is typically used in fixed points together with other capitals Y,Z,. . . A fixed point µX.φ or νX.φ only exists if X occurs positively in φ, meaning that X in φ must be preceded by an even number of negations. For counting negations φ1 → φ2 should be read as ¬φ1 ∨ φ2 . So, for instance νX.¬X and νX.¬([a]¬X ∨ X) are not allowed; in the first formula X occurs with one preceding negation, in the second formula only the former occurrence of X is fine because it is preceded by two negations. To understand fixed point modalities it is useful to consider X as a set of states. Formula µX.φ is valid for all states in the smallest set X that satisfies the equation X = φ, where X generally occurs in φ. Here we abuse notation, by thinking of φ as the set of states where φ is valid. Similarly, νX.φ is valid for the states in the largest set X that satisfies X = φ. As an example we can look at two simple fixed point formulas µX.X and νX.X. Because φ = X, we are interested in the smallest and largest set of states X that satisfies the equation X = X, respectively. Of course every set satisfies this equation. Hence, the smallest set to satisfy it, is the empty set. This means that µX.X is not valid in any state, which is equivalent to saying that µX.X = false. The largest set X that satisfies X = X is the set of all states, so νX.X is valid in all states which means that νX.X = true. As another example we look whether the formulas µX.haiX and νX.haiX are valid in the following transition system:
a s
The only sets of states to be considered are the empty set X = ∅ and the set of all states X = {s}. Both satisfy the ‘equation’ X = haiX. Namely, if X = ∅, then the equation reduces to false = haifalse, which is valid. If X = {s} it is also clear that this equation holds. So, µX.haiX is valid for all states in the empty set. Hence, this formula is not valid in s. However, νX.haiX is valid for all states in the largest set, being {s} in this case. So, νX.haiX is valid. This example concludes our small introduction to modal µ-calculus. For more details, see [11].
2.1.3 mCRL2 toolset
Now we have seen the basics of both the mCRL2 process specification language and the property language modal µ-calculus. Using these two languages as recipes one could specify a formal model of the considered system and a property of the system that must be verified by means of model checking. Model checking is one of the purposes of the mCRL2 toolset, but besides that the toolset can be also be used to analyze and explore the model by simulation and visualization of the model’s state space. Furthermore the toolset contains tools to optimize the model automatically. It should be noted that the toolset is subject to continuously development; here we give a description of the toolset version (SVN revision 3626) that we have used in this project. 23
Page 25
Figure 2.5 gives an overview of the use of the mCRL2 toolset. On the left the figure shows the inputs of the toolset, which are a model of a system expressed in the mCRL2 language and possibly a formula that must be verified. The first step in model analysis is always the generation of a Linearized Process Specification (LPS) for the model by using the linearizer tool mcrl22lps. This tool first performs a syntax check and then starts the linearization, which can be seen as compiling the model to a more strict format that is well suited for analysis and manipulation by the tools in the toolset. An LPS can be seen as a symbolic representation of the transition system of a model. For more information about linearizing mCRL2 process specifications, see [10].
Figure 2.5: Overview of the mCRL2 toolset (picture taken from [2]) An LPS is unreadable for humans, but sometimes it is needed to inspect the LPS. For this purpose the toolset contains a tool to pretty print the LPS and a tool which provides some basic information about the LPS (these tools are not present in figure 2.5). This basic information contains for example the number of summands in the LPS, which is often indicative for the size of the model’s state space. The LPS can be optimized by some manipulator tools; there is a tool for removing process parameters which are constant in the (reachable) state space, a tool for removing unused process parameters, and a rewriting tool. This rewriting tool evaluates conditions in the LPS by rewriting and then decides which alternatives are unused and can be removed. These optimization tools can have a substantial effect on the final size of the state space and/or the resources needed for the generation of the state space. Besides these manipulator tools there is a simulator tool available which can be used to get more insight in a model without generating its state space. The user explores the model with this tool by manually performing individual (multi)actions. After an action has been performed the simulator shows a representation of the new state (a state vector), and the actions that are possible from this state. The simulator also offers the ability to save action 24
Page 26
traces and load them again on a future moment. To generate the state space from an LPS the tool lps2lts can be used. This tool generates a Labeled Transition System (LTS) that represents the complete behavior of the model. On the LTS the manipulator tool ltsconvert can be used to convert between different formats of LTSs and to minimize the state space modulo (branching) bisimulation equivalence. This minimization is effective when several internal actions are hidden (abstraction) in the model. For example, if the state space contains a sequence of internal actions, this sequence can be collapsed in many cases. Then all intermediate states in the sequence are removed, which leads to a smaller state space. Furthermore there are several tools to visualize the state space, which again can help in finding specification errors or in getting more insight in the model. When analysis and simulation show that the formal model conforms to the modeled system well enough, one can start model checking. Model checking in mCRL2 is provided using Parameterized Boolean Equation Systems (PBES), which can be generated by the tool lps2pbes from an LPS and a modal µ-calculus formula. For PBESs there is again a tool to print it in human readable format and using pbes2bes one can try to remove data from the PBES in order to get a BES, which is often easier to solve. The actual model checking can be done by the tool pbes2bool, which internally uses pbes2bes and then solves the BES by rewriting the boolean equations in the BES. If requested, the tool returns a trace that indicates how pbes2bool came to the validity or invalidity of the PBES. Such a trace can again be useful to improve the model or the modeled system itself. This description of the mCRL2 toolset concludes the introduction to mCRL2. In later chapters we will see how mCRL2 can be useful in formal modeling the pacemaker firmware design and in verification of the resulting models.
2.2
Uppaal
Uppaal is an integrated tool environment for modeling, validation and verification of realtime systems. The tool has been developed in collaboration between the Department of Information Technology at Uppsala University, Sweden and the Department of Computer Science at Aalborg University in Denmark; the tool is available at [3]. In this project, we have used version 4.0.6 of Uppaal. Based on [4], this section gives an introduction to Uppaal. In Uppaal it is possible to model the behavior of real-time systems as concurrent processes via a (Java-based) graphical interface. The tool contains a graphical simulator which constantly shows the actual state of the model and enables the user to explore the possible executions of the model by manually performing actions. During the design or modeling of the system this can provide useful information to improve the model or the modeled system itself. Then there is the model checker which covers the complete behavior of the system by exploring all possible executions. The model checker can check invariant properties (properties that must hold in every reachable state of the model) and reachability properties (properties that must hold in at least one reachable state of the model) that are formulated in (temporal) logic.
2.2.1
Timed automata
Uppaal is designed to verify systems that can be modeled as a composition of timed automata. Timed automata are especially useful to model components of real-time systems. A timed automaton is a finite state machine extended with clock variables which evaluate to a 25