the calculus of context-aware ambients (cca)fsiewe/ccapl/ccapl_processes.pdf · thecalculus of...

68
Introduction Installing ccaPL My Hello program The concept of ambient Programming in ccaPL The Calculus of Context-aware Ambients (CCA) How to program: Capabilities and Processes Dr. François Siewe Software Technology Research Laboratory (STRL) De Montfort University Leicester, UK [email protected] / [email protected] http://www.cse.dmu.ac.uk/~fsiewe/ September 2017 Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Upload: others

Post on 01-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

The Calculus of Context-aware Ambients(CCA)

How to program: Capabilities and Processes

Dr. François Siewe

Software Technology Research Laboratory (STRL)De Montfort University

Leicester, [email protected] / [email protected]

http://www.cse.dmu.ac.uk/~fsiewe/

September 2017

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 2: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Overview

The Calculus of Context-aware Ambients (CCA) is a formalnotation for modelling and reasoning about the behavioursof context-aware and mobile concurrent systems.ccaPL is a programming environment for executing CCAmodels.This lesson presents the ccaPL programming languageand its use in the modelling of context-aware systems.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 3: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Outline

1 Introduction

2 Installing ccaPL

3 My Hello program

4 The concept of ambient

5 Programming in ccaPL

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 4: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Introduction

CCA stands for Calculus of Context-aware Ambients.It is a process calculus for modelling and reasoning aboutthe behaviours of context-aware and mobile concurrentsystems.A process calculus is a formalism for the high-leveldescription of interactions, communications, andsynchronisations between a collection of independentprocesses.The main features of CCA are: mobility,context-awareness, and concurrency. The syntax andsemantics of CCA can be found in [1,2,3].ccaPL is the programming environment of CCA.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 5: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Installing ccaPL

1 Create a work directory2 Download from Black Board the JAR file “ccaPL.jar” into

your work directory3 Make sure java virtual machine (JVM) is installed on your

computer4 This works with any operating system that supports JVM5 That is all you need to execute ccaPL programs.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 6: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

How to Execute a Program?

1 Create a program file “myprog.cca” using your favoritetext editor, e.g. emacs, gedit, or notepad++.

2 Save your program in your work directory containing theJAR file “ccaPL.jar”

3 Open a Terminal Window and use command line tochange to your work directory

4 You can now execute your ccaPL program using thecommand:

ccaPL version 4.01 or lower

java -jar ccaPL.jar myprog.cca

ccaPL version 4.02 or higher

java -jar ccaPL.jar -e myprog.cca

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 7: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Save the execution output in a file

The execution output is sent to the standard output, which isyour computer screen by default.

To save the execution output in a file “myoutput.txt”,

java -jar ccaPL.jar -e myprog.cca > myoutput.txt

To append sequence of execution outputs in a file “myoutput.txt”,

java -jar ccaPL.jar -e myprog.cca > > myoutput.txt

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 8: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello program (locally in the root ambient)

hello program

send(hello).0 | recv(x).0

execution output

send(hello).0| recv(x).0

---> {Local: root ===(hello)===> root}

0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 9: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello program (locally in ambient n)

hello program

n[ send(hello).0 | recv(x).0 ]

execution output

n[send(hello).0

| recv(x).0]

---> {Local: n ===(hello)===> n}

n[ 0 ]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 10: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello program (sibling to sibling)

hello program

n[ m::send(hello).0] | m[ n::recv(x).0 ]

execution output

n[ m::send(hello).0 ]|

m[ n::recv(x).0 ]

---> {Sibling to sibling: n ===(hello)===> m}

n[ 0 ]|

m[ 0 ]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 11: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello program (parent to child)

hello program

n[ #send(hello).0 | m[ @recv(x).0 ] ]

execution output

n[m[ @recv(x).0 ]

| #send(hello).0]

---> {Parent to child: n ===(hello)===> m}

n[m[ 0 ]

]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 12: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello program (child to parent)

hello program

n[ #recv(x).0 | m[ @send(hello).0 ] ]

execution output

n[m[ @send(hello).0 ]

| #recv(x).0]

---> {Child to parent: m ===(hello)===> n}

n[m[ 0 ]

]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 13: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

My hello+ack program

hello+ack programn[ ::send(hello).::recv(ack).0]| m[ ::recv(x).::send(hello).0 ]

execution outputn[ ::send(hello).::recv(ack).0 ]

|m[ ::recv(x).::send(hello).0 ]

---> {Sibling to sibling: n ===(hello)===> m}

n[ ::recv(ack).0 ]|

m[ ::send(thanks).0 ]---> {Sibling to sibling: m ===(hello)===> n}

n[ 0 ]|

m[ 0 ]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 14: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

What is an ambient?

An ambient is a conceptual representation of things,whether physical, virtual, mobile or immobile.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 15: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

What is an ambient (cont’d)?

An ambientis a bounded place in which computation takes placehas a name, a boundary and can be nested inside an otherambientcan be mobilecan exchange messages locally and with other ambientscan be aware of the presence of other ambients in itsenvironment

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 16: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Syntax of ambient

Textual:n[P]

where n is the ambient’s name and P is a computation(process) describing the behaviour of this ambient.Graphicaln

P

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 17: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Ambient hierarchy

In ccaPL, the top ambient is called the root ambient.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 18: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: smart devices and users

A smart mobile phone device can be modelled as anambient:

phone[P]

where P encompasses the functionality of the smart phone.Graphically it looks like this:

phone

P

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 19: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: smart devices and users

the user, bob, carrying the phone can also be modelled asan ambient:

bob[phone[P] | Q]

Q here characterises the behaviour of the user, bob.Graphically it looks like this:

bob

phone

PQ

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 20: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: smart devices and users

Bob might carry more than one device: a phone and a PDA

bob[phone[P] | pda[R] | Q]

Graphically it looks like this:

bob

phone

P

pda

RQ

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 21: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: user’s location

The location of the user can be modelled as an ambientE.g. Bob is carrying a phone at the conference room

conf [bob[phone[P] | Q] | R]

Graphically it looks like this:

confbob

phone

PQ R

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 22: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: user is with an other person

Bob is with Alice at the conference room, Bob carrying amobile phone while Alice holding a pda

conf [bob[phone[P] | Q] | alice[pda[R] | S]]

Graphically it looks like this:

confbob

phone

PQ

alicepda

RS

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 23: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Modelling with ambients: user/device environment

the conference room is next to the reception roomBob is at the conference room, carrying a mobile phoneand Alice is at the reception room, carrying a pda

conf [bob[phone[P] | Q]] | recept[alice[pda[R] | S]]

Graphically it looks like this:

confbob

phone

PQ

receptalice

pda

RS

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 24: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Syntax of ccaPL

There are 3 main syntactic categories:Processes: which denote a computation (i.e. behaviour)Capabilities: which are elementary actions a process canperformContext expression: which is a formula expressing someproperty of a process’ context.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 25: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Notations

In the syntax of processes, the following notations are used:P, Q: denote processesn, x: are namesy: denotes a comma seperated (possibly empty) list ofvariable symbols y1, y2, . . . , y`; for some integer ` ≥ 0.M: denotes a capabilityκ: denotes a context expression

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 26: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Syntax of Processes

P,Q ::= Processes0 inactivityM.P sequential compositionP|Q parallel composition!P replicationnew n P name restrictionn[P] ambient{P} brackets<κ>M.P context-guarded prefixproc x(y) {P} process abstraction xfind y : κ for P searchif <κ1>M1.P1 . . . <κ`>M`.P` fi selectionlet x1 = e1, . . . , x` = e` in P ‘let’ statement

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 27: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Syntax of Capabilities

M ::= in n move into the ambient nout move out of current locationdel n delete the ambient nα x(z) call the process x defined in location α,

with actual parameters zα recv(y) receive into y a list of messages

from location αα send(z) send a list of messages z to location α

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 28: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Syntax of Locations α

α ::= @ any parent ambientn@ parent n# any child ambientn# child n:: any sibling ambientn :: sibling nε locally (empty string)

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 29: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Context Property Language

Context expressions are described by the following language:

κ ::= Context Expressionstrue truen = m name matchthis holenot κ negationκ1 | κ2 parallel compositionκ1 and κ2 conjunctionκ1 or κ2 disjunctionn[κ] locationnext κ spatial next modalitysomewhere κ somewhere modality

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 30: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Inactive Process (0)

The inactivity process or null process 0does nothingterminates immediatelyis the unit element for the parallel composition ofprocesses, i.e.

0 | P ≡ P | 0 ≡ P

where the symbol ‘≡’ means ‘equivalent’.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 31: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Sequential Composition (M.P)

M.P

this process performs the capability M then continues likethe process P.

Exampleout.0 // performs the capability out and termiantes

send(5).0 // performs the capability send and termiantes

send(5).out.0 // performs the capability send then out and termiantes

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 32: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Parallel Composition (P | Q)

P | Qmeans that the process P and the process Q executeconcurrentlywe also say P and Q execute in parallel i.e. P and Qexecute at the same timeduring their execution, P and Q can communicate bymessage passing

Example

out.0 | send(5).0send(5).0 | recv(x).0send(5).out.0 | recv(x).0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 33: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Parallel Composition (P | Q) (cont’d)

Properties of parallel composition of processes0 is the unit element

0 | P ≡ P | 0 ≡ P

Commutative (i.e. the syntactic order does not matter)

P | Q ≡ Q | P

Associative (i.e. the execution order does not matter)

P | (Q | R) ≡ (P | Q) | R ≡ P | Q | R

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 34: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Replication (!P)

!P denotes a process which can always creates a newcopy of the process P

!P ≡ P | !PCan be used to model iteration and recursion

Example

This process always outputs/sends the value 2:

!send(2).0

This process always prompts to receive a message and then simplyforwards the received message:

!recv(x).send(x).0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 35: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Brackets ({P})

{P} behaves just like P.

Brackets are used to describe complex processes.

Used only as suffix process, i.e. in the form P.{Q}

Example

{P | Q}P.{Q | R}!{P | Q}

Example

Counter examples

{P | Q}.SP.{Q | R}.S

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 36: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Ambient process (n[P])

n[P]

represents an ambient named n with behaviour describedby the process P.P specifies the capabilities that the ambient n can perform.it is also said that the ambient n executes the process P.

Example

n[!send(2).0 | !recv(x).0]n[!recv(x).send(x).0]n[in m.out.0] | m[in n.out.0]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 37: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Restriction (new n P)

The restriction new n P

states that n is a new name visible only in the process P.So the name n cannot be referred to outside P.Similar to the declaration of local variables in programminglanguages like C or Java.Also use to hide the name n in P so that no other processcan ‘see’ it.

Example

new n {del n.0 | n[0]}new n del n.0 | n[0]Do these processes have the same behaviour?

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 38: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Mobility Primitives (in)

in mallows an ambient to move into a sibling ambient m

n

in m.P

m

Qreduces into

m

n

PQ

The corresponding reduction rule

n[in m.P] | m[Q] −→ m[n[P] | Q]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 39: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Mobility Primitives (out)

outallows an ambient to move out of its parent

m

n

out.PQ

reduces into

n

P

m

Q

The corresponding reduction rule

m[n[out.P] | Q] −→ n[P] | m[Q]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 40: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Mobility Primitives: Examples

A software agent ag moves into computer win.

ag[in win.out.0] | win[0] → win[ag[out.0]]

Agent ag exits computer win.

win[ag[out.0]] → ag[0] | win[0]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 41: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Mobility Primitives: Exercise

Specify a process Q′ that allows Alice to move from thereception room to the conference room

confbob

phone

PQ

receptalice

pda

RQ′

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 42: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Delete an ambient (del)

del ndeletes the ambient n if n has no capabilities; i.e.

del n.P | n[0] −→ P

del n.P | n[out.0] 6−→ P

Inside an ambient, it looks like this:

m

del n.P

n

0reduces into

m

P

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 43: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Message passing communication: one process (thesender) sends a message n and another process (thereceiver) receives it in a variable x.

Sender : send(n).PReceiver : recv(x).Q

The reduction rule for message passing is

send(n).P | recv(x).Q −→ P | Q{x← n}

where Q{x← n} denotes the substitution of n for each freeoccurrence of x in Q.Example

send(n).0 | recv(x).x[0] −→ n[0]send(5).0 | recv(x).send(x).0 −→ send(5).0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 44: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Can model both synchronous and asynchronous communicationsSynchronous communication: both the sender and the receiver wait foreach other

Sender : send(2).PReceiver : recv(x).Q

P and Q cannot be executed until the communication has taken placed.

Asynchronous communication: the sender does not waitfor the communication to take place.

Sender : send(2).0 | PReceiver : recv(x).Q

Q cannot be executed until the communication takes place;but P can be executed before the communication takesplace.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 45: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Examples: the receiver is in red.Synchronous communication

m

n

send(2).out.0 | recv(x).0reduces into

m

n

out.0

Asynchronous communication

m

n

send(2).0 | out.0| recv(x).0

reduces into

n

send(2).0 | recv(x).0

m

0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 46: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Capabilities to send a message:send(a): capability to send a message a to selfn@send(a): capability to send a message a to the parentambient n@send(a): capability to send a message a to any parentambientn#send(a): capability to send a message a to the childambient n#send(a): capability to send a message a to any childambientn :: send(a): capability to send a message a to the siblingambient n:: send(a): capability to send a message a to any siblingambient

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 47: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Capabilities to receive a message:recv(x): capability to receive a message a from selfn@recv(x): capability to receive in the variable x amessage from the parent ambient n@recv(x): capability to receive in the variable x a messagefrom any parent ambientn#recv(x): capability to receive in the variable x amessage from the child ambient n#recv(x): capability to receive in the variable x amessage from any child ambientn :: recv(x): capability to send receive in the variable x amessage from the sibling ambient n:: recv(x): capability to receive in the variable x amessage from any sibling ambient

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 48: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Local communication:

n

send(a).P | recv(x).Q reduces into

n

P | Q{x← a}

The corresponding reduction rule

n[send(a).P | recv(x).Q] −→ n[P | Q{x← a}]

Example

n[send(5).0 | recv(x).send(x).0] −→ n[send(5).0]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 49: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Child-parent communication: specific child and specificparent

m

n

m@send(a).Pn#recv(x).Q reduces into

m

n

PQ{x← a}

The corresponding reduction rule

m[n[m@send(a).P] | n#recv(x).Q] −→ m[n[P] |Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 50: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Child-parent communication: specific child and any parent

m

n

@send(a).Pn#recv(x).Q reduces into

m

n

PQ{x← a}

The corresponding reduction rule

m[n[@send(a).P] | n#recv(x).Q] −→ m[n[P] |Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 51: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Child-parent communication: any child and specific parent

m

n

m@send(a).P#recv(x).Q reduces into

m

n

PQ{x← a}

The corresponding reduction rule

m[n[m@send(a).P] |#recv(x).Q] −→ m[n[P] |Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 52: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Child-parent communication: any child and any parent

m

n

@send(a).P#recv(x).Q reduces into

m

n

PQ{x← a}

The corresponding reduction rule

m[n[@send(a).P] |#recv(x).Q] −→ m[n[P] |Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 53: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Sibling-sibling communication: specific siblings

n

m :: send(a).P

m

n :: recv(x).Q reduces into

n

P

m

Q{x← a}

The corresponding reduction rule

n[m :: send(a).P] |m[n :: recv(x).Q] −→ n[P] |m[Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 54: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Sibling-sibling communication: a specific sibling and anyother sibling

n

m :: send(a).P

m

:: recv(x).Q reduces into

n

P

m

Q{x← a}

The corresponding reduction rule

n[m :: send(a).P] |m[:: recv(x).Q] −→ n[P] |m[Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 55: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Communication Primitives (send/recv)

Sibling-sibling communication: any siblings

n

:: send(a).P

m

:: recv(x).Q reduces into

n

P

m

Q{x← a}

nThe corresponding reduction rule

n[:: send(a).P] |m[:: recv(x).Q] −→ n[P] |m[Q{x← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 56: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

‘let’ statement

let x0 = e0, x1 = e1, · · · , xn = en in P

Behaves like P{x0 ← v0, . . . , xn ← vn} where vi is the valueof the arithmetic expression ei.Arithmetic expressions e:

e ::= x a name: string or integer| − e unary minus| e1 + e2 addition of integers or concatenation of strings| e1 − e2 minus| e1 ∗ e2 multiplication| e1 ∗ ∗e2 power| e1%e2 modulo| e1/e2 division

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 57: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

‘let’ statement – Examples

Example

let x = 3 + 4 in send(x).0 behaves like send(7).0recv(x, y).let z = x + y in send(z).0receives two integers(resp. strings) and outputs their sum (res. concatenation).recv(x).let z = x%2 in send(z).0recv(x).let y = x + 1, z = x%2 in send(y, z).0recv(x).let z = x%2 in let y = x ∗ z + 1 in send(y, z).0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 58: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call

A process abstraction links a name x to a process Pusing the syntax:

proc x(y1, y2, . . . , yn) {P}where y1, y2, . . . , yn are formal parameters.A process call invokes a process abstraction x using thesyntax:

αx(z1, z2, . . . , zn).

where z1, z2, . . . , zn are actual parameters and α indicatesthe location of the process abstraction called and isdefined as follows:

α ::= @ | n@ | # | n# | :: | n :: | ε

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 59: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call: Semantics

Calling a local process

n

proc x(y) {P} |x(a)

reduces into

n

proc x(y) {P} |P{y← a}

The corresponding reduction rule

n[proc x(y) {P} | x(a)] −→ n[proc x(y) {P} | P{y← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 60: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call: Semantics

Calling a process abstraction defined in a child ambient

m

n

proc x(y) {P} n#x(a) reduces into

m

n

proc x(y) {P} P{y← a}

The corresponding reduction rule

m[n[proc x(y) {P}] | n#x(a)] −→ m[n[proc x(y) {P}] | P{y← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 61: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call: Semantics

Calling a process abstraction defined in a child ambient

m

n

m@x(a) proc x(y) {P} reduces into

m

n

P{y← a} proc x(y) {P}

The corresponding reduction rule

m[n[m@x(a)] | proc x(y) {P}] −→ m[n[P{y← a}] | proc x(y) {P}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 62: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call: Semantics

Calling a process abstraction defined in a sibling ambient

n

proc x(y) {P}

m

n :: x(a) reduces into

n

proc x(y) {P}

m

P{y← a}

The corresponding reduction rule

n[proc x(y) {P}] | m[n :: x(a)] −→ n[proc x(y) {P}] | m[P{y← a}]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 63: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Process Abstraction/Call: Example

Context Provision using Process AbstractionUser preferences, Available services, Device configurationMy favourite text editor on Windows is notepad

win[proc edit(file) {notepad(file).0}]

My favourite text editor on Linux is emacs

lin[proc edit(file) {emacs(file).0}]

A Context-aware file editing agent can be specified as

ag[@edit(foo).0]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 64: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Context Acquisition using Process Call

When the file editing agent runs

on my Windows machine, notepad is used

win[proc edit(file) {notepad(file).0} | ag[@edit(foo).0]]→

win[proc edit(file) {notepad(file).0} | ag[notepad(foo).0]]

on my Linux machine, emacs is used

lin[proc edit(file) {emacs(file).0} | ag[@edit(foo).0]]→

lin[proc edit(file) {emacs(file).0} | ag[emacs(foo).0]]

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 65: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Exercise 1

Give the reductions corresponding to the execution of the followingprocesses:

1 send(5).0 | recv(x).02 send(5).0 | recv(x).send(x).03 n[send(5).0 | recv(x).0]4 m[send(5).0 | recv(x).send(x).0]5 n[m :: send(5).0] | m[n :: recv(x).0]6 n[:: send(5).0] | m[n :: recv(x).0]7 n[m :: send(5).0] | m[:: recv(x).0]8 n[:: send(5).0] | m[:: recv(x).0]9 n[:: send(5).in m.0] | m[:: recv(x).del n.0]

10 n[@send(5).0 | in m.0] | m[#recv(x).del n.0] | del m.0

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 66: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Exercise 2

1 The following process send a hello message and receives anacknowledgement:

send(hello).recv(x).0 | PGive the specification of P.

2 An ambient m sends an hello message to another ambient n andreceives an acknowledgement from n. Give the specification of theambients m and n.

3 Explain the behaviour of the following process

m[in n.out.0] | n[in m.out.0]4 Specify a network hub that has 4 output ports.5 Specify a simple network switch with four output ports connected to

specific devices.6 Specify a server that receives a service request, invokes the requested

service, and sends the output to the requester. Services can bemodelled as process abstractions.

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 67: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

Summary

1 Introduction

2 Installing ccaPL

3 My Hello program

4 The concept of ambient

5 Programming in ccaPL

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)

Page 68: The Calculus of Context-aware Ambients (CCA)fsiewe/ccaPL/ccaPL_processes.pdf · TheCalculus of Context-aware Ambients(CCA) is a formal notation for modelling and reasoning about the

IntroductionInstalling ccaPL

My Hello programThe concept of ambientProgramming in ccaPL

References

F. Siewe (2016). Towards the Modelling of Secure Pervasive Computing Systems: A Paradigm of

Context-Aware Secure Action System. Journal of Parallel and Distributed Computing (Elsevier), 87.

F. Siewe and H. Yang (2016). Privacy Protection by Typing in Ubiquitous Computing Systems. Journal of

Systems and Software (Elsevier), 120, 133-153.

F. Siewe, et al. (2016). Analysing Use Case Diagrams in a Calculus of Context-aware Ambients.

International Journal of Intelligent Computing Research, Infonomics Society, 7(1), 655-662.

M. Al-Sammarraie, F. Siewe and H. Zedan (2011). Formal Specification of an Intelligent Message

Notification Service in Infostation-based mLearning System using CCA. In Proceedings of CCIT’11.

M. Al-Sammarraie, F. Siewe and H. Zedan (2010). Formalising Policies of a mLearning System using CCA.

In Proceedings of CASEMANS 2010, Copehagen, Danmark.

F. Siewe, H. Zedan and A. Cau (2010). The Calculus of Context-aware Ambients. Journal of Computer and

Systems Sciences (Elsevier), 77(4), 597-620.

F. Siewe, A. Cau and H. Zedan (2009). CCA: a Calculus of Context-aware Ambients. In the proceeding of

the IEEE 23rd International Conference on Advanced Information Networking and Applications (AINA-09).

Dr. François Siewe The Calculus of Context-aware Ambients (CCA)