Integration of a modelling language and a distributed programming - - PowerPoint PPT Presentation

integration of a modelling language and a distributed
SMART_READER_LITE
LIVE PREVIEW

Integration of a modelling language and a distributed programming - - PowerPoint PPT Presentation

Integration of a modelling language and a distributed programming language Alexis Grall 11/06/2019 advisors : Dominique Mery and Horatiu Cirstea Alexis Grall Integration of a modelling language and a distributed programming language


slide-1
SLIDE 1

Integration of a modelling language and a distributed programming language

Alexis Grall 11/06/2019 advisors : Dominique Mery and Horatiu Cirstea

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 1 / 39

slide-2
SLIDE 2

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 2 / 39

slide-3
SLIDE 3

Introduction

Main objective : automatically translate models of distributed algorithms into executable programs. The models are obtained by refinement with the Event-B method. The chosen programming language is DistAlgo.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 3 / 39

slide-4
SLIDE 4

Introduction

Service First machine Second machine Third machine Machine to transform Program Event-B models DistAlgo program Induction refines Communi- cation refines Localization refines Intermediate Language refines Transformation

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 4 / 39

slide-5
SLIDE 5

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 5 / 39

slide-6
SLIDE 6

Event-B

Method for modelling systems Based on set theory Refinement of models Proof assistant and model checker. Framework Rodin is used. A model consists of contexts and machines

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 6 / 39

slide-7
SLIDE 7

Context

A context specifies Types (which are sets) Constants Axioms and theorems

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 7 / 39

slide-8
SLIDE 8

Machine

A machine specifies Variables Invariants on the variables Events which define the state transition of the system.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 8 / 39

slide-9
SLIDE 9

Events

An INITIALISATION event initialises the variables of the machine. Other events are made of : Parameters Guards on the variables and parameters Actions which modify the variables When there exists values for the parameters for which the guards are true, the event is then enabled. When an event is enabled, the actions of the event can be observed.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 9 / 39

slide-10
SLIDE 10

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 10 / 39

slide-11
SLIDE 11

DistAlgo

Programming language for distributed algorithms High level Based on Python

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 11 / 39

slide-12
SLIDE 12

Structure of a DistAlgo program

A DistAlgo program defines some class of processes and a main method. The main method instantiates the processes of each class of process and runs them. A class of processes consists of A setup method to initialise the local variables of the process. A run method with the program of the process. Message handlers that are executed when messages are received. User methods

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 12 / 39

slide-13
SLIDE 13

Program structure

class A(process): def setup(args): setup_body def receive(msg=mexp, from_=pexp): receive_body def run(): run_body class B(process): . . . def main (* args): a = new(A) setup(a, (args)) start(a)

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 13 / 39

slide-14
SLIDE 14

Communication

Sending a message : send(mexp, to=pexp) Messages are received at yield points : await statements. The statement await(bexp) triggers the reception of all the messages that arrived before but were not yet received. The process then waits for the condition bexp to be true while new messages are received. When a message is received, corresponding message handlers are executed.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 14 / 39

slide-15
SLIDE 15

Communication

sent channel transport layer msgQueue received skip message handler body Sender Receiver send copy yield point copy if message handler exists else

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 15 / 39

slide-16
SLIDE 16

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 16 / 39

slide-17
SLIDE 17

Stop-and-wait ARQ

A process p has an array IN of length n he wants to send to a process q and q wants to copy IN in an array OUT. Loss of messages can happen.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 17 / 39

slide-18
SLIDE 18

Stop-and-wait ARQ

P IN, ns, n Q OUT, nr, n OUT[0] ← IN[0] nr ← nr + 1 nr ← 0 ns ← 0 ns ← ns + 1 . . . OUT[i] ← IN[i] nr ← nr + 1 ns ← ns + 1

  • ,

I N [ ]

  • ,

I N [ ]

  • i, IN[i]

i

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 18 / 39

slide-19
SLIDE 19

Automata for p

Here is the automata for the program of process p. P_sending INITIALISATION P_waiting done P_send P_stop_sending P_has_received P_has_not_received P_receive

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 19 / 39

slide-20
SLIDE 20

Automata for q

Here is the automata for the program of process q. Q_waiting INITIALISATION done Q_receive_nr Q_receive_i Q_done

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 20 / 39

slide-21
SLIDE 21

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 21 / 39

slide-22
SLIDE 22

Context

CONTEXT C SETS

NODES MESSAGES MESSAGE_TYPES STATES

CONSTANTS

P Q p q class of processes and processes P_sending P_waiting Q_waiting done reception_states states send receive lose functions for communication between processes IN n dest @P array to send, length of IN and dest = q source @Q source = p

AXIOMS . . . END

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 22 / 39

slide-23
SLIDE 23

Transformation of the context

With the context, we can already get the main structure of the program. class P(process): . . . class Q(process): . . . def main (): p = new(P) q = new(Q) IN = . . . n = . . . setup(p, (IN , n, q)) setup(q, (n, p)) start ({p,q})

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 23 / 39

slide-24
SLIDE 24

Machine variables

OUT, ns and nr are variables only for this algorithm. channel is the variable modelling the communication channels. pc is a function of NODES → STATES which gives the state of each process.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 24 / 39

slide-25
SLIDE 25

Initialisation

The initialisation of the different variables is the following. MACHINE EVENTS Initialisation then

act1: OUT := ∅ function with the empty set as domain act2: ns := 0 act3: nr := 0 act4: channel := emptyChannel act5: pc := {p → P_sending, q → Q_waiting}

END

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 25 / 39

slide-26
SLIDE 26

Setup of P

The setup method for class P is obtained from the Initialisation event. class P(process): def setup(IN , n, dest): self.ns = 0 self.pc = "P_sending" def run(): . . . def receive(. . .): . . .

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 26 / 39

slide-27
SLIDE 27

Events of p

The different events of p are the transitions of its automata. P_sending INITIALISATION P_waiting done P_send P_stop_sending P_has_received P_has_not_received P_receive

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 27 / 39

slide-28
SLIDE 28

Events of p

P_stop_sending is a local event of computation. P_send is a sending event. P_has_received is an await event. P_has_not_received is an await event. P_receive is a reception event. Here, P_waiting is the only reception state. Events P_has_not_received and P_has_received are enabled in this reception state and thus are await events.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 28 / 39

slide-29
SLIDE 29

P_stop_sending

The event is enabled when ns is greater than the length of IN. It means that p has received all the needed acknowledgements from q and can stop sending data. P_stop_sending = when

grd1: ns ≥ n grd2: pc(p) = P_sending

then

act1: pc(p) := done

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 29 / 39

slide-30
SLIDE 30

P_send

The sending event is enabled when ns is less than the length of IN. In this case, p wants to send IN[ns] to q. P_send = when

grd1: pc(p) = P_sending grd2: ns < n

then

act1: channel := send(channel → (p → dest) → (data → data2msg(ns → IN(ns)))) act2: pc(p) := P_waiting

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 30 / 39

slide-31
SLIDE 31

Await events

Event P_has_received is an await event which is enabled when p has received an acknowledgement for the current value of ns. P_has_received = when

grd1: pc(p) = P_waiting grd2: received(channel → (dest → p) → (ack → nat2msg(ns)))

then

act1: ns := ns + 1 act2: pc(p) := P_sending

Event P_has_not_received is similar but is enabled when p has not received an acknowledgement for the current value of ns and thus does not increment ns.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 31 / 39

slide-32
SLIDE 32

Reception event

The reception event is enabled when pc(p) is in a reception state (P_waiting for this example) and a message is ready to be received by p. P_receive = any

s m

where

grd1: pc(p) ∈ reception_states grd2: s ∈ NODES grd3: m ∈ MESSAGE_FUNCTIONS × MESSAGES grd4: readyToBeReceived(channel → (s → p) → (m))

then

act1: channel := receive(channel → (s → p) → m)

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 32 / 39

slide-33
SLIDE 33

Transformation of the machine

The different value of pc(p) will corresponds to different methods of the class of p. The value of pc(p) will determine which methods to execute. class P(process): def setup(IN , n, dest): . . . def PSending (): . . . def PWaiting (): . . . def run(): state = {"P_sending":PSending , "P_waiting" :PWaiting} while(self.pc != "done"): states[self.pc]() def receive(. . .): . . .

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 33 / 39

slide-34
SLIDE 34

PSending

The two events that are enabled in the state P_sending are P_send and P_stop_sending. They are translated in the method PSending. def PSending (): # P_stop_sending if(self.ns >self.n): self.pc = "done" # P_send elif(self.ns <= self.n): send ((’data ’, (self.ns , self.IN[self. ns])), to=self.dest) self.pc = "P_waiting"

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 34 / 39

slide-35
SLIDE 35

PWaiting

The two events P_has_received and P_has_not_received are enabled in the state P_waiting which is a reception state. The events are therefore await events and translated in the PWaiting method. def PWaiting (): # P_has_received if await(received ((’ack’, self.ns), from_= self.dest): self.ns = self.ns+1 self.pc = "P_sending" # P_has_not_received elif(not(received ((’ack’, self.ns), from_= self.dest)): self.pc = "P_sending"

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 35 / 39

slide-36
SLIDE 36

Receive method

A reception event is enabled in a reception state and does not change the value of pc. It is translated by a receive method. # P_receive def receive(msg=(m), from_=s): pass It does not do anything special apart from receiving the message in our case.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 36 / 39

slide-37
SLIDE 37

1

Introduction

2

Event-B

3

DistAlgo

4

Stop-and-wait ARQ

5

Model for the stop-andwait ARQ and its transformation

6

Conclusion

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 37 / 39

slide-38
SLIDE 38

Conclusion

I showed with the example of the stop-and-wait algorithm how to transform a specific Event-B model of a distributed algorithm into a program. The rules of this transformation are currently being defined on a sublanguage of Event-B. The next goal will be to prove that this transformation is correct and to implement an automatic translation based on this transformation from Event-B to DistAlgo.

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 38 / 39

slide-39
SLIDE 39

End slide

Questions ?

Alexis Grall Integration of a modelling language and a distributed programming language 11/06/2019 39 / 39