From Action System to Distributed Systems: the Refinement Approach
Total Page:16
File Type:pdf, Size:1020Kb
Luigia Petre and Emil Sekerinski From Action System to Distributed Systems: The Refinement Approach Contents List of Figures ix List of Tables xi I This is What a Part Would Look Like 1 1 A Contract-Based Approach to Ensuring Component Inter- operability in Event-B 3 Linas Laibinis and Elena Troubitsyna 1.1 Introduction . 3 1.2 Background: Event-B . 5 1.2.1 Modelling and Refinement in Event-B . 5 1.2.2 Modelling Modular Systems in Event-B . 7 1.3 From Event-B Modelling to Contracts . 11 1.3.1 Contracts . 11 1.3.2 From a Module Interface to a Component Contract . 12 1.4 Example: an Auction System . 13 1.4.1 Initial Model . 14 1.5 Conclusions . 19 Bibliography 21 vii List of Figures 1.1 Event-B machine and context components . 5 1.2 Before-after predicates . 6 1.3 Module interface . 8 1.4 Component contract . 11 1.5 Interface Component . 17 1.6 The Seller class contract . 18 ix List of Tables xi Part I This is What a Part Would Look Like 1 Chapter 1 A Contract-Based Approach to Ensuring Component Interoperability in Event-B Linas Laibinis Abo˚ Akademi University, Turku, Finland Elena Troubitsyna Abo˚ Akademi University, Turku, Finland 1.1 Introduction :::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 1.2 Background: Event-B :::::::::::::::::::::::::::::::::::::::::::: 5 1.2.1 Modelling and Refinement in Event-B :::::::::::::::::: 5 1.2.2 Modelling Modular Systems in Event-B :::::::::::::::: 7 1.3 From Event-B Modelling to Contracts ::::::::::::::::::::::::::: 11 1.3.1 Contracts :::::::::::::::::::::::::::::::::::::::::::::::: 11 1.3.2 From a Module Interface to a Component Contract :::: 12 1.4 Example: an Auction System :::::::::::::::::::::::::::::::::::: 13 1.4.1 Initial Model ::::::::::::::::::::::::::::::::::::::::::::: 14 1.5 Conclusions ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 1.1 Introduction Ensuring component interoperability constitutes one of the main chal- lenges in the component-based development approach [10]. The approach relies on a composition of reusable software components (or services) to implement a desired functionality [19]. While composing them, we should ensure that the components are compatible not only at the interface but also at the seman- tic level. Essentially, it requires for the components to share the knowledge about their globally observable behaviour and properties. The most popular approach to representing such knowledge is by defining component contracts. Usually a contract is expressed as an assumption-guarantee pair [11]. The assumption part postulates the properties that the component's environment should satisfy, while the guarantee part defines the properties that must be satisfied by the component itself. 3 4 From Action System to Distributed Systems: The Refinement Approach The design by contract approach proposed by Meyer [16] facilitates struc- turing of software into encapsulated modules with contracts regulating com- ponent interactions. While the benefits of the contract-based approach are evident, defining the contracts themselves is often a challenging task, espe- cially in the development of decentralised systems with complex component interdependencies. In this paper, we propose a refinement-based approach fa- cilitating definition of contracts and ensuring component interoperability. The formal basis of the proposed approach is within Event-B [1] and its modularisation extension [13]. Event-B is a formal approach for designing correct-by-construction distributed systems. The main development technique of Event-B { refinement { allows the designers to transform an abstract speci- fication into a detailed model through a chain of correctness-preserving model transformations. Each refinement step is verified by proofs guaranteeing that the refined model preserves the externally observable behaviour and does not introduce new deadlocks. Modelling and verification in Event-B is automated by a industrial-strength tool { the Rodin platform [21]. Refinement allows us to formally define relations between models repre- senting the system behaviour at different levels of abstraction. Hence it consti- tutes a suitable mechanism for establishing relationships between the system- level properties and the behaviour of system components. The main idea behind our approach is to derive component contracts from a formal Event-B specification of the overall system. We start from an ab- stract centralised specification of the system. The initial model relies on the shared global state and abstracts away the communication between the com- ponents. The interoperability properties are fairly transparent at this level and easy to define. In the refinement process, while elaborating on the system behaviour and properties, we introduce a representation of inter-component communication, distribute the global state space between the components and decouple them. Finally, we decompose the obtained system specification into independent modules. While deriving the module interfaces, we at the same time define their contracts. Since decomposition is a special kind of refine- ment step, we guarantee that the components remain interoperable under the derived contracts. We believe that the proposed approach facilitates the rigorous develop- ment of complex component-based systems and enhances confidence in the correctness of the overall system design. It allows us to propagate the system level properties into the component contracts and ensure component interop- erability. The paper is structured as follows: in Section 1.2, we present our main modelling framework { Event-B and its modularisation extension. In Section 1.3, we demonstrate how to derive contracts from Event-B models using the modularisation extension. In Section 1.4, we give a small illustrative example { an auction system. Finally, in Section 1.5, we overview the proposed approach and discuss the related work. A Contract-Based Approach to Ensuring Component Interoperability in Event-B 5 Machine M Variables v Invariants I Context C Events Carrier Sets s −! Init Constants c evt1 Axioms A ··· evtN FIGURE 1.1: Event-B machine and context components 1.2 Background: Event-B In this section, we overview our modelling framework { Event-B. The Event-B formalism [1] is a state-based formal approach that promotes the correct-by-construction development paradigm and formal verification by the- orem proving. Event-B is a specialisation of the B Method that facilitates modelling of event-based (reactive) systems by incorporating the ideas of the Action Systems formalism [3] into the B Method. 1.2.1 Modelling and Refinement in Event-B In Event-B, a system specification (model) is defined using the notion of an abstract state machine [1]. An abstract state machine encapsulates the model state, represented as a collection of model variables, and defines operations on this state. Therefore, it describes the dynamic part (behaviour) of the modelled system. Usually a machine also has the accompanying component, called context, which contains the static part of the model. In particular, a context can include user-defined carrier sets, constants and their properties, which are given as a list of model axioms. A general form of Event-B models is given in Figure 1.1. The machine is uniquely identified by its name M. The state variables, v, are declared in the Variables clause and initialised in the Init event. The variables are strongly typed by the constraining predicates I given in the Invariants clause. The invariant clause might also contain other predicates defining properties that should be preserved during system execution. The dynamic behaviour of the system is defined by the set of atomic events specified in the Events clause. Generally, an event can be defined as follows: any lv where g then S end; where lv is a list of new local variables (parameters), the guard g is a state 6 From Action System to Distributed Systems: The Refinement Approach 0 Statement (S) BAS(s; c; lv; x; y; x ) skip x0 = x ^ y0 = y x := E(s; c; lv; x; y) x0 = E(s; c; lv; x; y) ^ y0 = y x :2 Set x0 2 Set ^ y0 = y x :j P (s; c; lv; x; y; x0) P (s; c; lv; x; y; x0) ^ y0 = y S1 k S2 BAS1 ^ BAS2 FIGURE 1.2: Before-after predicates predicate, and the action S is a statement (assignment). In the case when lv is empty, the event syntax becomes when g then S end. If g is always true, the syntax can be further simplified to begin S end. The occurrence of events represents the observable behaviour of the sys- tem. The guard defines the conditions under which the action can be executed, i.e., when the event is enabled. If several events are enabled at the same time, any of them can be chosen for execution nondeterministically. If none of the events is enabled then the system deadlocks. In general, the action of an event is a parallel composition of state- ments (assignments). The statements can be either deterministic or non- deterministic. A deterministic assignment, x := E(x; y), has the standard syn- tax and meaning. A nondeterministic assignment is denoted either as x :2 Set, where Set is a set of values, or x :j P (x; y; x0), where P is a predicate relat- ing initial values of x and y to some final value of x0. As a result of such a assignment, x can get any value belonging to Set or according to P . Semantics of an Abstract Model. The semantics of Event-B actions is de- fined using before-after (BA) predicates [1]. A before-after predicate describes a relationship between the system states before and after an execution of an event action. The definitions of a BA for different action statements are shown in Figure 1.2. Here x and y are disjoint lists (partitions) of state variables, and x0; y0 represent their values in the state after the action execution. Moreover, lv refers to the local event variables, where s and c stand for respectively the sets and constants defined in the model context.