Tutorial3a Answers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Tutorial 3 Answers

Exercise 1 – Answers
In the following, the symbol “→” is read “reduces to” or “transitions to”.
1. send(5).0 | recv(x).0 → 0

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


3. n[send(5).0 | recv(x).0] → n[0]
4. m[send(5).0 | recv(x).send(x).0] → m[send(5).0]
5. n[m :: send(5).0] | m[n :: recv(x).0] → n[0] | m[0]

6. n[:: send(5).0] | m[n :: recv(x).0] → n[0] | m[0]


7. n[m :: send(5).0] | m[:: recv(x).0] → n[0] | m[0]
8. n[:: send(5).0] | m[:: recv(x).0] → n[0] | m[0]
9. n[:: send(5).in m.0] | m[:: recv(x).del n.0] → n[in m.0] | m[del n.0] → m[n[0] | del n.0] → m[0]

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


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

Exercise 2 – Answers
1. P is: recv(x).send(ack ).0

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


3. Explain the behaviour of the following process

m[in n.out.0] | n[in m.out.0]

The ambients m and n move in and out of each other in a non-deterministic manner. Here are the possible
executions of this process.
(a) m[in n.out.0] | n[in m.out.0]
→ n[m[out.0] | in m.out.0]
→ m[0] | n[in m.out.0]
→ m[n[out.0]]
→ m[0] | n[0]

1
(b) m[in n.out.0] | n[in m.out.0]
→ m[n[out.0] | in n.out.0]
→ n[0] | m[in n.out.0]
→ n[m[out.0]]
→ n[0] | m[0]

Exercise 3
Description
• m and n are sibling ambients.
• u is child ambient to n.
• w is child ambient to m.
• u sends a message hi to w.
Answers
1. Specify n, m, u, and w for this communication to take place.

m[
n::recv(s,r,msg).r#send(s,r,msg).0 |
w[
@recv(s,r,msg).0
]
]
|
n[
u#recv(s,r,msg).m::send(s,r,msg).0 |
u[
@send(u,w,hi).0
]
]

2. Simulate your program and show the communication graph.


Execution Output

1. ---> {Child to parent: u ===(u,w,hi)===> n}


2. ---> {Sibling to sibling: n ===(u,w,hi)===> m}
3. ---> {Parent to child: m ===(u,w,hi)===> w}

Communication Graph

3. Modify the program to allow w to send an acknowledgement thanks to u upon receiving the message.

2
m[
n::recv(s,r,msg).r#send(s,r,msg).0 |
w#recv(s,r,msg).n::send(s,r,msg).0 |
w[
@recv(s,r,msg).@send(w,u,thanks).0
]
]
|
n[
u#recv(s,r,msg).m::send(s,r,msg).0 |
m::recv(s,r,msg).r#send(s,r,msg).0 |
u[
@send(u,w,hi).@recv(s,r,msg).0
]
]

4. Simulate your program and show the communication graph.


Execution Output

1. ---> {Child to parent: u ===(u,w,hi)===> n}


2. ---> {Sibling to sibling: n ===(u,w,hi)===> m}
3. ---> {Parent to child: m ===(u,w,hi)===> w}
4. ---> {Child to parent: w ===(w,u,thanks)===> m}
5. ---> {Sibling to sibling: m ===(w,u,thanks)===> n}
6. ---> {Parent to child: n ===(w,u,thanks)===> u}

Communication Graph

Exercise 4
Description
• n is the parent ambient of m.
• m is the parent ambient of u,.
• n sends a message hi to u and receives an acknowledgement from u.
Questions

3
1. Specify n, m, u, and w for this communication to take place.

n[ m#send(n,u,hi).m#recv(s,r,msg).0 |
m[ n@recv(s,r,msg).u#send(s,r,msg).0 |
u#recv(s,r,msg).n@send(s,r,msg).0 |
u[
m@recv(s,r,msg).m@send(u,s,thanks).0
]
]
]

2. Simulate your program and show the communication graph.


Execution Output

1. ---> {Parent to child: n ===(n,u,hi)===> m}


2. ---> {Parent to child: m ===(n,u,hi)===> u}
3. ---> {Child to parent: u ===(u,n,thanks)===> m}
4. ---> {Child to parent: m ===(u,n,thanks)===> n}

Communication Graph

Exercise 5
Description
• m, n, and u are sibling ambients.
• w is a child ambient of m.

• w can move from m to n and then to u.


Questions
1. Specify n, m, u, and w.

n[0]
|
m[
w[out.in n.out.in u.0]
]
|
u[0]

4
2. Simulate your program and show the behaviour graph.
Execution Output

1. ---> {Parent to child: n ===(n,u,hi)===> m}


2. ---> {Parent to child: m ===(n,u,hi)===> u}
3. ---> {Child to parent: u ===(u,n,thanks)===> m}
4. ---> {Child to parent: m ===(u,n,thanks)===> n}

Behaviour Graph

Exercise 6
Description
• m is parent to the ambient n.
• n is parent to u.

• u is parent to w.
• w can move into m.
Questions

1. Specify n, m, u, and w.

m[
n[
u[
w[out.out.0]
]
]
]

2. Simulate your program and show the behaviour graph.


Execution Output

5
1. ---> {ambient "w" moves out of ambient "u"}
2. ---> {ambient "w" moves out of ambient "n"}

Behaviour Graph

Exercise 7
Description
• m is sibling to the ambient n.

• u is child to n.
• w is child to u.
• w can move into m.

Questions
1. Specify n, m, u, and w.

m[ 0] |
n[
u[
w[out.out.in m.0]
]
]

2. Simulate your program and show the behaviour graph.


Execution Output

1. ---> {ambient "w" moves out of ambient "u"}


2. ---> {ambient "w" moves out of ambient "n"}
3. ---> {ambient "w" moves into ambient "m"}

Behaviour Graph

6
Exercise 8
• Specify in ccaPL a server that receives a service request, invokes the requested service, and sends the
output to the requester. Services can be modelled as process abstractions.

server[
!::recv(requester, service, args).service(requester,args).0
|
proc service1(requester, args) {
requester::send(results_service1).0
}
|
proc service2(requester, args) {
requester::send(results_service2).0
}
|
proc service3(requester, args) {
requester::send(results_service3).0
}
|
proc service4(requester, args) {
requester::send(results_service4).0
}
]
|
jack[server::send(jack, service1, 23).server::recv(result).0]
|
john[server::send(john, service2, 3).server::recv(result).0]
|
paul[server::send(paul, service4, 50).server::recv(result).0]

• Simulate your program and show the execution output.


Execution Output

1. ---> {Sibling to sibling: jack ===(jack,service1,23)===> server}


2. ---> {local call to the abstraction "service1" in the ambient "server"}
3. ---> {Sibling to sibling: john ===(john,service2,3)===> server}
4. ---> {local call to the abstraction "service2" in the ambient "server"}

7
5. ---> {Sibling to sibling: server ===(results_service1)===> jack}
6. ---> {Sibling to sibling: paul ===(paul,service4,50)===> server}
7. ---> {local call to the abstraction "service4" in the ambient "server"}
8. ---> {Sibling to sibling: server ===(results_service2)===> john}
9. ---> {Sibling to sibling: server ===(results_service4)===> paul}

Communication Graph

Exercise 9 – Answers
Network Hub

Hub[
!D1::recv(sender, msg, dest).{
D2::send(sender, msg, dest).0
| D3::send(sender, msg, dest).0
| D4::send(sender, msg, dest).0
}
| !D2::recv(sender, msg, dest).{
D1::send(sender, msg, dest).0
| D3::send(sender, msg, dest).0
| D4::send(sender, msg, dest).0
}
| !D3::recv(sender, msg, dest).{
D2::send(sender, msg, dest).0
| D1::send(sender, msg, dest).0
| D4::send(sender, msg, dest).0
}
| !D4::recv(sender, msg, dest).{
D2::send(sender, msg, dest).0
| D1::send(sender, msg, dest).0
| D3::send(sender, msg, dest).0
}
]
|
D1[ !Hub::recv(sender, msg, dest).0]
|
D2[ !Hub::recv(sender, msg, dest).0]

8
|
D3[ !Hub::recv(sender, msg, dest).0]
|
D4[ !Hub::recv(sender, msg, dest).0 | Hub::send(D4, hello, D1).0]

Execution Output
1. ---> {Sibling to sibling: D4 ===(D4,hello,D1)===> Hub}
2. ---> {Sibling to sibling: Hub ===(D4,hello,D1)===> D1}
3. ---> {Sibling to sibling: Hub ===(D4,hello,D1)===> D2}
4. ---> {Sibling to sibling: Hub ===(D4,hello,D1)===> D3}
Communication Graph

Exercise 10 – Answers
Network switch

switch[
!::recv(sender, msg, dest).dest::send(sender, msg).0
]
|
D1[ !switch::recv(sender, msg).0]
|
D2[ !switch::recv(sender, msg).0]
|
D3[ !switch::recv(sender, msg).0]
|
D4[ !switch::recv(sender, msg).0 | switch::send(D4, hello, D1).0]

Execution Output
1. ---> {Sibling to sibling: D4 ===(D4,hello,D1)===> switch}
2. ---> {Sibling to sibling: switch ===(D4,hello)===> D1}
Communication Graph

You might also like