Complex Systems Design &DistributedCalculusandCoordination

Similar documents
Orchestrating Tuple-based Languages

Coordination Languages

The Klaim Project: Theory and Practice

Course on Probabilistic Methods in Concurrency. (Concurrent Languages for Probabilistic Asynchronous Communication) Lecture 1

The Klaim Project: Theory and Practice

Types for access control

O Klaim: a coordination language with mobile mixins

Operational Semantics. One-Slide Summary. Lecture Outline

Simulation and Analysis of Distributed Systems in Klaim

A Formal Definition of RESTful Semantic Web Services. Antonio Garrote Hernández María N. Moreno García

Functional Programming. Big Picture. Design of Programming Languages

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

CSCI-GA Scripting Languages

Meta-programming with Names and Necessity p.1

Compilers. Cool Semantics II. Alex Aiken

Simulation and Analysis of Distributed Systems in Klaim

Foundational Calculi for Network Aware Programming

Lambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky.

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Mobile Distributed Programming in X-Klaim

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Mobile Distributed Programming in X-Klaim

Reliable Self-Deployment of Cloud Applications

Resource Access and Mobility Control with Dynamic Privileges Acquisition

Programming language design and analysis

Lambda Calculus. Gunnar Gotshalks LC-1

Network-aware Evaluations of Reputation Systems

Substitution in Structural Operational Semantics and value-passing process calculi

Variables and Bindings

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

JOURNAL OF OBJECT TECHNOLOGY

Modal Logic: Implications for Design of a Language for Distributed Computation p.1/53

A Formal Model for Web-Service Composition

IG-JADE-PKSlib. An Agent Based Framework for Advanced Web Service Composition and Provisioning. Erick Martínez & Yves Lespérance

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Lambda Calculus LC-1

CS 242. Fundamentals. Reading: See last slide

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Architectural Styles - Finale

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

1 Lexical Considerations

Motivation: Model-driven. driven Engineering. Semantics of Model Transformation. Reiko Heckel University of Leicester, UK

Typed Lambda Calculus. Chapter 9 Benjamin Pierce Types and Programming Languages

A Small Permutation Group Engine by: Gregory Kip. COMS W4115 Programming Languages and Translators Prof. Stephen Edwards

CS558 Programming Languages

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Programming with Types

Towards Semantic Interoperability between C2 Systems Following the Principles of Distributed Simulation

Programming Languages Third Edition

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Object Oriented Issues in VDM++

Specification, Verification, and Interactive Proof

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

Organization of Programming Languages CS3200/5200N. Lecture 11

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Mobile Applications in X-KLAIM

Verifying control systems using CSP, FDR, and Handel-C.

CMSC 330: Organization of Programming Languages

UNIT 3

Variables. Substitution

Lexical Considerations

Cover Page. The handle holds various files of this Leiden University dissertation

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

G Programming Languages - Fall 2012

Functional Programming. Pure Functional Programming

Operational Semantics of Cool

Formally Linking Security Protocol Models and Implementations

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

CS 314 Principles of Programming Languages

Rule Formats for Nominal Modal Transition Systems

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Lexical Considerations

Model driven Engineering & Model driven Architecture

Programming Safe Agents in Blueprint. Alex Muscar University of Craiova

Informatica 3 Syntax and Semantics

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011

Distributed Information System as a System of Asynchronous Concurrent Processes

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

LECTURE 16. Functional Programming

Behavioural Equivalences and Abstraction Techniques. Natalia Sidorova

IMT School for Advanced Studies, Lucca. Lucca, Italy. Programming Abstractions for Data Sharing in Distributed Spaces

Multi-Agent Dialogue Protocols

40 Behaviour Compatibility

Recap: Functions as first-class values

Model Checking of Location and Mobility Related Security Policy Specifications in Ambient Calculus

Architecture as coordination: the Orc perspective

Motivation was to facilitate development of systems software, especially OS development.

Distributed Systems Programming (F21DS1) Formal Verification

Multi-paradigm Declarative Languages

Programmiersprachen (Programming Languages)

Lecture08: Scope and Lexical Address

a data type is Types

The Abstract Behavioral Specification Language

CLAN: A Tool for Contract Analysis and Conflict Discovery

Specifying Web Workflow Services for Finding Partners in the Context of Loose Inter-Organizational Workflow

Chapter 2 The Language PCF

A Type System for Object Initialization In the Java TM Bytecode Language

Transcription:

Complex Systems Design &DistributedCalculusandCoordination Concurrency and Process Algebras: Theory and Practice - Klaim Francesco Tiezzi University of Camerino francesco.tiezzi@unicam.it A.A. 2014/2015 F. Tiezzi (Unicam) CoSyDesign & DCC 1/ 45

Outline 1 Motivations 2 Klaim syntax 3 Klaim semantics 4 An example 5 Klaim implementation F. Tiezzi (Unicam) CoSyDesign & DCC 2/ 45

Original goal Motivations Programming Global Computers: distributed software architecture models Large number of heterogeneous and autonomous components Wide area distribution, manifest to application programmers Different authorities with different administrative and security policies Components with highly dynamic behavior that must adapt to unpredictable changes over time oftheenvironment,duee.g.to lack of services node failures network reconfiguration... Mobile components must support heterogeneity and interoperability, as they may detach from a node and re-attach later on a different one Openended, loosely coupled, possibly collaborative settings F. Tiezzi (Unicam) CoSyDesign & DCC 3/ 45

Motivations Programming Global Computers Programming Languages would definitely benefit from explicit primitives for Concurrency considering parallel and non-deterministic computations Distribution computing over different (explicit) localities Mobility moving code and processes over localities and from formal semantics and associated tools for Reasoning on programs behaviour F. Tiezzi (Unicam) CoSyDesign & DCC 4/ 45

The spatial dimension Motivations Many foundational languages have been designed that features mechanisms for coordinating and monitoring the use of resources for code and process mobility for managing security All these foundational languages encompass a notion of location to reflect the idea of administrative domains to model the fact that computations at a certain location are under the control of a specific authority They focus on the spatial dimension of GC programming (which is often referred to as network awareness) F. Tiezzi (Unicam) CoSyDesign & DCC 5/ 45

Motivations Card game F. Tiezzi (Unicam) CoSyDesign & DCC 6 / 45

Motivations Klaim design goal Developing a simple programming language and associated tools for network aware and mobile applications with a tractable semantic theory that permits programs verification Our Starting Points (1980... ) Process Algebras CCS, CSP,... Calculi and languages for Mobility Pi-calculus, Obliq, Ambients,... Tuple-based Interaction Models Linda Modal and Temporal Logics HML, CTL, ACTL, µ-calculus,... F. Tiezzi (Unicam) CoSyDesign & DCC 7/ 45

Klaim: mainingredients Motivations Kernel Language for Agent Interaction and Mobility a formalism for concurrent, distributed and mobile systems Linda communication model Asynchronous communication Shared tuple spaces Pattern Matching Explicit use of localities Multiple distributed tuple spaces Code and process mobility Process Calculus flavored Small set of basic operators Clean operational semantics F. Tiezzi (Unicam) CoSyDesign & DCC 8/ 45

Klaim: mainingredients Motivations Kernel Language for Agent Interaction and Mobility a formalism for concurrent, distributed and mobile systems Linda communication model Asynchronous communication Shared tuple spaces Pattern Matching Explicit use of localities Multiple distributed tuple spaces Code and process mobility Process Calculus flavored Small set of basic operators Clean operational semantics F. Tiezzi (Unicam) CoSyDesign & DCC 8/ 45

Klaim: mainingredients Motivations Kernel Language for Agent Interaction and Mobility a formalism for concurrent, distributed and mobile systems Linda communication model Asynchronous communication Shared tuple spaces Pattern Matching Explicit use of localities Multiple distributed tuple spaces Code and process mobility Process Calculus flavored Small set of basic operators Clean operational semantics F. Tiezzi (Unicam) CoSyDesign & DCC 8/ 45

Klaim: mainingredients Motivations Kernel Language for Agent Interaction and Mobility a formalism for concurrent, distributed and mobile systems Linda communication model Asynchronous communication Shared tuple spaces Pattern Matching Explicit use of localities Multiple distributed tuple spaces Code and process mobility Process Calculus flavored Small set of basic operators Clean operational semantics F. Tiezzi (Unicam) CoSyDesign & DCC 8/ 45

Motivations Tuples and Pattern Matching Tuples: ( foo, 10 + 5, true) Actual Fields (i.e. expressions) Templates: (!s, 15,!b) Actual Fields Formal Fields (i.e. variables) Pattern Matching: Formal fields match any field of the same type Actual fields match if identical F. Tiezzi (Unicam) CoSyDesign & DCC 9/ 45

Motivations Tuples and Pattern Matching Tuples: ( foo, 10 + 5, true) Actual Fields (i.e. expressions) Templates: (!s, 15,!b) Actual Fields Formal Fields (i.e. variables) Pattern Matching: Formal fields match any field of the same type Actual fields match if identical F. Tiezzi (Unicam) CoSyDesign & DCC 9/ 45

Motivations Tuples and Pattern Matching Tuples: ( foo, 10 + 5, true) Actual Fields (i.e. expressions) Templates: (!s, 15,!b) Actual Fields Formal Fields (i.e. variables) Pattern Matching: Formal fields match any field of the same type Actual fields match if identical (!s, 15,!b) matches ( foo, 15, true) (!s, 15,!b) doesnot match ( foo, 10, true) F. Tiezzi (Unicam) CoSyDesign & DCC 9/ 45

Motivations Linda communication model Tuple Space F. Tiezzi (Unicam) CoSyDesign & DCC 10 / 45

Motivations Linda communication model out(t) Tuple Space F. Tiezzi (Unicam) CoSyDesign & DCC 10 / 45

Motivations Linda communication model out(t) Tuple Space eval(t) F. Tiezzi (Unicam) CoSyDesign & DCC 10 / 45

Motivations Linda communication model out(t) in(t ) Tuple Space eval(t) F. Tiezzi (Unicam) CoSyDesign & DCC 10 / 45

Motivations Linda communication model out(t) in(t ) Tuple Space eval(t) read(t ) F. Tiezzi (Unicam) CoSyDesign & DCC 10 / 45

From Linda to Klaim Motivations Localities to model distribution Physical localities (network addresses), i.e. names Logical localities (aliases for addresses), i.e. variables Adistinctvariableself indicates the node a process is on Local and remote operations to read/withdraw/write tuples, spawn processes, create nodes Allocation environments to associate physical to logical localities Logical localities are local aliases for network addresses Programmers may not know the exact network topology Process Calculi operators to specify behaviours Action prefix Parallel composition Name creation / scope delimitation F. Tiezzi (Unicam) CoSyDesign & DCC 11 / 45

From Linda to Klaim Motivations Localities to model distribution Physical localities (network addresses), i.e. names Logical localities (aliases for addresses), i.e. variables Adistinctvariableself indicates the node a process is on Local and remote operations to read/withdraw/write tuples, spawn processes, create nodes Allocation environments to associate physical to logical localities Logical localities are local aliases for network addresses Programmers may not know the exact network topology Process Calculi operators to specify behaviours Action prefix Parallel composition Name creation / scope delimitation F. Tiezzi (Unicam) CoSyDesign & DCC 11 / 45

From Linda to Klaim Motivations Localities to model distribution Physical localities (network addresses), i.e. names Logical localities (aliases for addresses), i.e. variables Adistinctvariableself indicates the node a process is on Local and remote operations to read/withdraw/write tuples, spawn processes, create nodes Allocation environments to associate physical to logical localities Logical localities are local aliases for network addresses Programmers may not know the exact network topology Process Calculi operators to specify behaviours Action prefix Parallel composition Name creation / scope delimitation F. Tiezzi (Unicam) CoSyDesign & DCC 11 / 45

From Linda to Klaim Motivations Localities to model distribution Physical localities (network addresses), i.e. names Logical localities (aliases for addresses), i.e. variables Adistinctvariableself indicates the node a process is on Local and remote operations to read/withdraw/write tuples, spawn processes, create nodes Allocation environments to associate physical to logical localities Logical localities are local aliases for network addresses Programmers may not know the exact network topology Process Calculi operators to specify behaviours Action prefix Parallel composition Name creation / scope delimitation F. Tiezzi (Unicam) CoSyDesign & DCC 11 / 45

Klaim Motivations Klaim consists of three layers: nets, processes, and actions Nets specify the overall structure of a system, including where processes and tuple spaces are located how nodes are interconnected Processes are the actors in this system and execute by performing actions F. Tiezzi (Unicam) CoSyDesign & DCC 12 / 45

Klaim Motivations Klaim consists of three layers: nets, processes, and actions Nets specify the overall structure of a system, including where processes and tuple spaces are located how nodes are interconnected Processes are the actors in this system and execute by performing actions F. Tiezzi (Unicam) CoSyDesign & DCC 12 / 45

Klaim Motivations Klaim consists of three layers: nets, processes, and actions Nets specify the overall structure of a system, including where processes and tuple spaces are located how nodes are interconnected Processes are the actors in this system and execute by performing actions F. Tiezzi (Unicam) CoSyDesign & DCC 12 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ Q F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ Q eval(p)@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ P Q eval(p)@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ P Q t 1 eval(p)@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ P Q t 1 eval(p)@s out(t)@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Motivations Klaim Nodes Locality name (address) Allocation environment Processes Tuple Space s P ρ Q t 1 t 2 eval(p)@s out(t)@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Motivations Klaim Nodes Locality name (address) Allocation environment Processes Tuple Space s P ρ Q t 1 t 2 eval(p)@s out(t)@s in(t )@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ P Q t 2 read(t )@s eval(p)@s out(t)@s in(t )@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nodes Motivations Locality name (address) Allocation environment Processes Tuple Space s ρ newloc(s ) P Q t 2 read(t )@s eval(p)@s out(t)@s in(t )@s F. Tiezzi (Unicam) CoSyDesign & DCC 13 / 45

Klaim Nets Motivations s 2 l s 1, l s 3 out(t)@l t3 s 3 s 1 self s 3 t 1 t 2 in(t )@self F. Tiezzi (Unicam) CoSyDesign & DCC 14 / 45

Klaim: Syntax(1) Klaim syntax Locality names: s, s,... Locality variables: self, l, l,... l will stand for a locality name or a locality variable F. Tiezzi (Unicam) CoSyDesign & DCC 15 / 45

Klaim: Syntax(1) Klaim syntax Locality names: s, s,... Locality variables: self, l, l,... l will stand for a locality name or a locality variable Tuples: Templates: t ::= e l P t1, t 2 T ::= e l P! x! l! X T1, T 2 F. Tiezzi (Unicam) CoSyDesign & DCC 15 / 45

Klaim: Syntax(1) Klaim syntax Locality names: s, s,... Locality variables: self, l, l,... l will stand for a locality name or a locality variable Tuples: Templates: t ::= e l P t1, t 2 T ::= e l P! x! l! X T1, T 2 Actions: a ::= in(t )@l read(t )@l out(t)@l eval(p)@l newloc(s) exchanging data, spawning new processes, creating new nodes F. Tiezzi (Unicam) CoSyDesign & DCC 15 / 45

Klaim: Syntax(2) Klaim syntax Nets are plain collections of interconnected nodes Nodes have a unique address, an allocation environment and host components N ::= 0 s :: ρ C N 1 N 2 (νs)n F. Tiezzi (Unicam) CoSyDesign & DCC 16 / 45

Klaim: Syntax(2) Klaim syntax Nets are plain collections of interconnected nodes Nodes have a unique address, an allocation environment and host components N ::= 0 s :: ρ C N 1 N 2 (νs)n Components are evaluated tuples or running processes C ::= t P C 1 C 2 F. Tiezzi (Unicam) CoSyDesign & DCC 16 / 45

Klaim: Syntax(2) Klaim syntax Nets are plain collections of interconnected nodes Nodes have a unique address, an allocation environment and host components N ::= 0 s :: ρ C N 1 N 2 (νs)n Components are evaluated tuples or running processes C ::= t P C 1 C 2 Processes are built up from the inert process via action prefixing, parallel composition and process invocation (and definition) P ::= a.p P 1 P 2 A( p) (A( f ) P) F. Tiezzi (Unicam) CoSyDesign & DCC 16 / 45

Klaim: Syntax Klaim syntax Nets: Components: Processes: Actions: N ::= 0 s :: ρ C N 1 N 2 (νs)n P ::= C ::= t P C 1 C 2 a.p P 1 P 2 A( p) (A( f ) P) a ::= in(t )@l read(t )@l out(t)@l eval(p)@l newloc(s) Tuples: t ::= e l P t1, t 2 Templates: T ::= e l P! x! l! X T1, T 2 F. Tiezzi (Unicam) CoSyDesign & DCC 17 / 45

Binders Klaim semantics Prefix in(...,!x,!l,!x,...)@l.p binds x, l, X in P (read acts similarly) Prefix newloc(s).p binds s in P Restriction (νs)n binds s in N F. Tiezzi (Unicam) CoSyDesign & DCC 18 / 45

Klaim semantics Klaim: StructuralCongruence Monoid laws for, i.e. N 0 N, N 1 N 2 N 2 N 1, (N 1 N 2 ) N 3 N 1 (N 2 N 3 ) (Alpha) N N if N = α N (RCom) (νs 1 )(νs 2 )N (νs 2 )(νs 1 )N (Ext) N 1 (νs)n 2 (νs)(n 1 N 2 ) if s fl(n 1 ) (Abs) s :: ρ C s :: ρ (C ) (Clone) s :: ρ C 1 C 2 s :: ρ C 1 s :: ρ C 2 (PDef) s :: ρ A( p) s :: ρ P[ p/ f ] if A( f ) P F. Tiezzi (Unicam) CoSyDesign & DCC 19 / 45

Klaim semantics Klaim: Operational Semantics (1) Producing data: ρ(l) =s E[[ t ]] ρ = t s :: ρ out(t)@l.p s :: ρ s :: ρ P s :: ρ t where the local environment ρ is used to determine the location s that is the target of the action function E[[ t ]]ρ replaces the free locality variables occurring in t according to the local environment ρ yielding t static binding discipline Remark: Free variables act as aliases that have to be replaced by network addresses F. Tiezzi (Unicam) CoSyDesign & DCC 20 / 45

Klaim semantics Klaim: Operational Semantics (2) Consuming data: ρ(l) =s match(e[[ T ]] ρ, t) =σ s :: ρ in(t )@l.p s :: ρ t s :: ρ Pσ s :: ρ where: function match(t, t) checkscompliance of E[[ T ]] ρ and t and associates values (i.e. basic values, names and processes) to variables bound by the template atuplematchesagainstatemplateiftheyhavethesamenumberof fields, and corresponding fields match σ is a substitution of names and processes for the free variables in T F. Tiezzi (Unicam) CoSyDesign & DCC 21 / 45

Matching Function Klaim semantics match(!x, v) =[v/x] match(v, v) =ϵ match(!l, s) =[s/l] match(s, s) =ϵ match(!x, P) =[P/X ] match(t 1, t 1 )=σ 1 match(t 2, t 2 )=σ 2 match((t 1, T 2 ), (t 1, t 2 )) = σ 1 σ 2 F. Tiezzi (Unicam) CoSyDesign & DCC 22 / 45

Klaim semantics Klaim: Operational Semantics (3) Accessing data: ρ(l) =s match(e[[ T ]] ρ, t) =σ s :: ρ read(t )@l.p s :: ρ t s :: ρ Pσ s :: ρ t read is similar to in, buttheaccessedtupleisleftinthetuplespace F. Tiezzi (Unicam) CoSyDesign & DCC 23 / 45

Klaim semantics Klaim: Operational Semantics (4) Spawning new processes: ρ(l) =s s :: ρ eval(q)@l.p s :: ρ s :: ρ P s :: ρ Q No interpretation of eval s argument is performed: free variables in Q will be translated according to the remote allocation environment dynamic binding discipline F. Tiezzi (Unicam) CoSyDesign & DCC 24 / 45

Dynamic Scoping Klaim semantics s 2 l s 1, l s 3 eval(out(t)@self)@l s 3 self s 3 F. Tiezzi (Unicam) CoSyDesign & DCC 25 / 45

Dynamic Scoping Klaim semantics s 2 l s 1, l s 3 eval(out(t)@self)@l s 3 self s 3 out(t)@self F. Tiezzi (Unicam) CoSyDesign & DCC 25 / 45

Dynamic Scoping Klaim semantics s 2 l s 1, l s 3 eval(out(t)@self)@l s 3 self s 3 out(t)@self t F. Tiezzi (Unicam) CoSyDesign & DCC 25 / 45

Static Scoping Klaim semantics s 2 l s 1, l s 3 out(out(t)@self)@l s 3 self s 3 F. Tiezzi (Unicam) CoSyDesign & DCC 26 / 45

Static Scoping Klaim semantics s 2 l s 1, l s 3 out(out(t)@self)@l s 3 self s 3 out(t)@s 2 F. Tiezzi (Unicam) CoSyDesign & DCC 26 / 45

Static Scoping Klaim semantics s 2 l s 1, l s 3 out(out(t)@self)@l t s 3 self s 3 out(t)@s 2 F. Tiezzi (Unicam) CoSyDesign & DCC 26 / 45

Klaim semantics Klaim: Operational Semantics (5) Creating new nodes: s :: ρ newloc(s ).P (νs )(s :: ρ P s :: ρ[s /self] ) with s codom(ρ) where the environment of the creator is used to build up the environment for the new node F. Tiezzi (Unicam) CoSyDesign & DCC 27 / 45

Klaim semantics Klaim: Operational Semantics (7) Rules summary: ρ(l) =s E[[ t ]] ρ = t s :: ρ out(t)@l.p s :: ρ s :: ρ P s :: ρ t ρ(l) =s s :: ρ eval(q)@l.p s :: ρ s :: ρ P s :: ρ Q ρ(l) =s match(e[[ T ]] ρ, t) =σ s :: ρ in(t )@l.p s :: ρ t s :: ρ Pσ s :: ρ ρ(l) =s match(e[[ T ]] ρ, t) =σ s :: ρ read(t )@l.p s :: ρ t s :: ρ Pσ s :: ρ t s :: ρ newloc(s ).P (νs )(s :: ρ P s :: ρ[s /self] ) with s codom(ρ) F. Tiezzi (Unicam) CoSyDesign & DCC 28 / 45

Klaim semantics Klaim: Operational Semantics (6) Remaining rules: N 1 N 1 N 1 N 2 N 1 N 2 N N (νs)n (νs)n N M M N N N F. Tiezzi (Unicam) CoSyDesign & DCC 29 / 45

An example Leader Election (assumptions) n participants distributed on the nodes of a network must elect a leader Each participant is univocally identified by an id The leader will be the participant with the smaller id The topology of the network is a ring: every node is directly connected to two other nodes (prev and next) n nodes with addresses s 0,...,s n 1 The allocation environment ρ i of node s i,inadditiontothestandard mapping self s i,mapsthelogicallocalitynext to s i+1 mod n At the outset, each process retrieves an id from the node rg that acts as a random generator The ids arealldifferent F. Tiezzi (Unicam) CoSyDesign & DCC 30 / 45

An example Leader Election: algorithm Once a participant has assigned an id, it spawns the mobile process checker to the next node This process travels along the ring to determine if the source node has to be the leader checker carries the id of the source node, retrieves the id of the node where it is running (stored in x) and compares the two ids If id < x, thecurrentlyhostingnodeisnottheleader: the process moves to the next node and restarts If id > x, thesourcenodeisnottheleader:theprocesscrossesthe rest of the ring to come back to the source node and insert this information in the local tuple space Otherwise, i.e. id = x, theprocessisbackonthesourcenode(thusno node with a smaller id has been found in the ring) and inserts the information that this is the leader in the local tuple space F. Tiezzi (Unicam) CoSyDesign & DCC 31 / 45

An example Leader Election: specification P in( ID,! id)@rg. out( ID, id)@self. eval(checker(id))@next. checker(myid) read( ID,! x)@self. if myid < x then eval(checker(myid))@next. else if myid > x then eval(notifier(myid))@next. else out( LEADER )@self. notifier(myid) read( ID,! x)@self. if x = myid then out( FOLLOWER )@self. else eval(notifier(myid))@next. F. Tiezzi (Unicam) CoSyDesign & DCC 32 / 45

(Mild) Extensions An example By exploiting pattern matching and parallel composition, the conditional construct can be rendered as if bcond then P else Q out( EVALUATE, bcond)@self. (in( EVALUATE, true)@self.p in( EVALUATE, false)@self.q) since only one of the two parallel processes can proceed F. Tiezzi (Unicam) CoSyDesign & DCC 33 / 45

An example Leader Election: specification s 0 :: [self s0,next s 1 ] P s 1 :: [self s1,next s 2 ] P s 2 :: [self s2,next s 0 ] P rg :: [self rg] ID, 7 ID, 4 ID, 5 F. Tiezzi (Unicam) CoSyDesign & DCC 34 / 45

The overall system s 0 next s 1 P An example rg ρ ID, 5 ID, 7 ID, 4 s 1 next s 2 s 2 next s 0 P P F. Tiezzi (Unicam) CoSyDesign & DCC 35 / 45

A computation s 0 next s 1 in( ID,!id)@rg.... An example rg ρ ID, 5 ID, 7 ID, 4 s 1 next s 2 s 2 next s 0 in( ID,!id)@rg.... in( ID,!id)@rg.... F. Tiezzi (Unicam) CoSyDesign & DCC 36 / 45

A computation s 0 next s 1 in( ID,!id)@rg.... An example rg ρ ID, 5 ID, 7 s 1 next s 2 s 2 next s 0 out( ID, 4)@self.... in( ID,!id)@rg.... F. Tiezzi (Unicam) CoSyDesign & DCC 36 / 45

A computation s 0 next s 1 in( ID,!id)@rg.... An example rg ρ ID, 5 ID, 7 s 1 next s 2 s 2 next s 0 eval(checker(4)) @next. ID, 4 in( ID,!id)@rg.... F. Tiezzi (Unicam) CoSyDesign & DCC 36 / 45

An example A computation s 0 next s 1 rg ρ ID, 7 in( ID,!id)@rg.... ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 in( ID,!id)@rg.... checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 36 / 45

An example A computation s 0 next s 1 rg ρ ID, 7 in( ID,!id)@rg.... ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 in( ID,!id)@rg.... checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 37 / 45

A computation s 0 next s 1 An example rg ρ in( ID,!id)@rg.... ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 out( ID, 7)@self.... checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 37 / 45

A computation s 0 next s 1 An example rg ρ in( ID,!id)@rg.... ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 eval(checker(7)) ID, 7 @next. checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 37 / 45

A computation s 0 next s 1 An example rg ρ in( ID,!id)@rg.... checker(7) ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 37 / 45

A computation s 0 next s 1 An example rg ρ in( ID,!id)@rg.... checker(7) ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 38 / 45

A computation s 0 next s 1 An example rg ρ out( ID, 5)@self.... checker(7) s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 38 / 45

A computation s 0 next s 1 An example rg ρ eval(checker(5)) @next. ID, 5 checker(7) s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 38 / 45

A computation s 0 next s 1 An example rg ρ ID, 5 checker(7) s 1 s 2 next s 2 next s 0 checker(5) ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 38 / 45

A computation s 0 next s 1 An example rg ρ ID, 5 checker(7) s 1 s 2 next s 2 next s 0 checker(5) ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

A computation s 0 next s 1 An example rg ρ ID, 5 checker(7) s 1 next s 2 s 2 next s 0 checker(5) ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

A computation s 0 next s 1 An example rg ρ ID, 5 checker(7) s 1 next s 2 s 2 next s 0 notifier(5) ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

A computation s 0 next s 1 An example rg ρ ID, 5 checker(7) s 1 next s 2 s 2 next s 0 notifier(5) ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

A computation s 0 next s 1 An example rg ρ notifier(5) checker(7) ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

A computation s 0 next s 1 An example rg ρ notifier(5) checker(7) ID, 5 s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

An example A computation s 0 next s 1 checker(7) FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 39 / 45

An example A computation s 0 next s 1 checker(7) FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

An example A computation s 0 next s 1 checker(7) FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 checker(4) F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

An example A computation s 0 next s 1 checker(4) checker(7) FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

An example A computation s 0 next s 1 checker(4) checker(7) FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

An example s 1 next s 2 s 2 next s 0 A computation s 0 next s 1 checker(7) FOLLOWER ID, 5 rg ρ checker(4) ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

An example s 1 next s 2 s 2 next s 0 A computation s 0 next s 1 checker(7) FOLLOWER ID, 5 rg ρ checker(4) ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ checker(7) s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 40 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ checker(7) s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ checker(7) s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ notifier(7) s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ notifier(7) s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 notifier(7) F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 LEADER ID, 4 ID, 7 notifier(7) F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 LEADER FOLLOWER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 41 / 45

A computation s 0 next s 1 An example FOLLOWER ID, 5 rg ρ s 1 next s 2 s 2 next s 0 LEADER FOLLOWER ID, 4 ID, 7 F. Tiezzi (Unicam) CoSyDesign & DCC 42 / 45

Klaim implementation Implementation X-Klaim (extended Klaim) A fully-fledged programming language including the Klaim operations and a high-level syntax: Variable declarations Assignments Conditionals, iteration,... Time-outs Klava (Klaim in Java) AJavapackageimplementing Klaim operations and concepts Communications among processes and nodes Code mobility F. Tiezzi (Unicam) CoSyDesign & DCC 43 / 45

Klaim implementation Klaim Programming Framework X-Klaim program xklaim compiler klava package Java program Java compiler Java virtual machine F. Tiezzi (Unicam) CoSyDesign & DCC 44 / 45

Klaim implementation KLAIM website: http://music.dsi.unifi.it/klaim.html F. Tiezzi (Unicam) CoSyDesign & DCC 45 / 45