-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabp.pml
70 lines (64 loc) · 1.78 KB
/
abp.pml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define MAX 5
mtype { MESSAGE, ACK, NAK, ERROR }
proctype Sender(chan in, out) {
byte output = MAX - 1;
byte seq = 0;
byte res = 0;
do
::
output = (output + 1) % MAX;
again: if
:: out ! MESSAGE(output, seq) /* send */
:: skip -> progress_0: out ! ERROR(0, 0) /* distort */
:: skip -> progress_1: skip /* lose */
fi;
if
:: timeout -> goto again
:: in ? ERROR(0, 0) -> goto again
:: in ? NAK(res, 0) -> goto again
:: in ? ACK(res, 0) ->
if
:: (res == seq) -> goto progress
:: else -> goto again
fi
fi;
progress:
seq = 1 - seq /* toggle seq no */
od
}
proctype Receiver(chan in, out) {
byte input;
byte seq;
byte expected_seq;
byte expected_input;
do
:: in ? MESSAGE(input, seq) ->
if
:: (seq == expected_seq) ->
assert(input == expected_input);
progress: expected_seq = 1 - expected_seq;
expected_input = (expected_input + 1) % MAX;
if
:: out ! ACK(seq, 0) /* send */
:: out ! ERROR(0, 0) /* distort */
:: skip /* lose */
fi
:: else ->
if
:: out ! NAK(seq, 0) /* send */
:: out ! ERROR(0, 0) /* distort */
:: skip /* lose */
fi
fi
:: in ? ERROR(_, _) ->
out ! NAK(seq, 0)
od
}
init {
chan sender_to_receiver = [1] of { mtype, byte, byte };
chan receiver_to_sender = [1] of { mtype, byte, byte };
atomic {
run Sender(receiver_to_sender, sender_to_receiver);
run Receiver(sender_to_receiver, receiver_to_sender);
}
}