Professional Documents
Culture Documents
Tutorial3a Answers
Tutorial3a Answers
Tutorial3a Answers
Exercise 1 – Answers
In the following, the symbol “→” is read “reduces to” or “transitions to”.
1. send(5).0 | recv(x).0 → 0
Exercise 2 – Answers
1. P is: recv(x).send(ack ).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
]
]
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
]
]
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
]
]
]
Communication Graph
Exercise 5
Description
• m, n, and u are sibling ambients.
• w is a child ambient of m.
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
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]
]
]
]
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]
]
]
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]
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