forked from cubicle-model-checker/cubicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distrib_channels.cub
169 lines (129 loc) · 3.14 KB
/
distrib_channels.cub
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
type state = Idle | Choose | Wait | Use
type msg = Empty
| Req1 | Ack1 | Ok1
| Req2 | Ack2 | Ok2
(* var Timer : real *)
array State[proc] : state
array Num[proc] : real
array Aux[proc] : real
array Channel_msg[proc,proc] : msg
array Channel_v[proc,proc] : real
const Tick : real
init (z z1) { State[z] = Idle &&
Num[z] = 0.0 &&
Aux[z] = 0.0 &&
(* Timer = 1.0 && *)
Channel_msg[z,z1] = Empty &&
Channel_v[z,z1] = 1.0 && Channel_v[z,z1] = 0.0 }
(* invariant () { Tick <= 0.0 } *)
unsafe (z1 z2) {
State[z1] = Use && State[z2] = Use &&
Channel_msg[z1,z2] = Ok2 && Channel_msg[z2,z1] = Ok2
}
transition t1 (z)
requires { State[z] = Idle && 0.0 < Tick }
{
(* Timer := Timer + Tick; *)
State[z] := Choose;
Aux[z] := Num[z];
Channel_msg[s,r] := case
| s = z && r <> z && Channel_msg[s,r] = Empty : Req1
| _ : Channel_msg[s,r];
Channel_v[s,r] := case
| s = z && r <> z && Channel_msg[s,r] = Empty : Num[z]
| _ : Channel_v[s,r];
}
transition t2 (z r)
requires { State[z] = Choose &&
Channel_msg[z,r] = Ack1 &&
Aux[z] < Channel_v[z,r] }
{
Channel_msg[z,r] := Ok1;
Aux[z] := Channel_v[z,r];
}
transition t3 (z r)
requires { State[z] = Choose &&
Channel_msg[z,r] = Ack1 &&
Channel_v[z,r] <= Aux[z] }
{
Channel_msg[z,r] := Ok1;
}
transition t4 (z)
requires { State[z] = Choose && 0.0 < Tick &&
forall_other r. Channel_msg[z,r] = Ok1 }
{
(* Timer := Timer + Tick; *)
State[z] := Wait;
Num[z] := Aux[z] + Tick;
}
transition t5 (z s)
requires { Channel_msg[s,z] = Req1 }
{
Channel_msg[s,z] := Ack1;
Channel_v[s,z] := Num[z];
}
transition t6 (z s)
requires { Channel_msg[s,z] = Req2 }
{
Channel_msg[s,z] := Ack2;
Channel_v[s,z] := Num[z];
}
transition t7 (z)
requires { State[z] = Wait }
{
Channel_msg[i,j] := case
| i = z && Channel_msg[z,j] = Ok1 : Req2
| _ : Channel_msg[i,j];
}
transition t8_1 (z r)
requires { State[z] = Wait &&
Channel_msg[z,r] = Ack2 &&
0.0 < Channel_v[z,r] &&
Channel_v[z,r] < Num[z] }
{
Channel_msg[z,r] := Req2;
}
transition t8_2 (z r)
requires { State[z] = Wait &&
Channel_msg[z,r] = Ack2 &&
0.0 < Channel_v[z,r] &&
Channel_v[z,r] = Num[z] && r < z }
{
Channel_msg[z,r] := Req2;
}
transition t9_1 (z r)
requires { State[z] = Wait &&
Channel_msg[z,r] = Ack2 &&
Channel_v[z,r] = 0.0 }
{
Channel_msg[z,r] := Ok2;
}
transition t9_2 (z r)
requires { State[z] = Wait &&
Channel_msg[z,r] = Ack2 &&
Num[z] < Channel_v[z,r] }
{
Channel_msg[z,r] := Ok2;
}
transition t9_3 (z r)
requires { State[z] = Wait &&
Channel_msg[z,r] = Ack2 &&
Num[z] = Channel_v[z,r] && z < r }
{
Channel_msg[z,r] := Ok2;
}
transition t10 (z)
requires { State[z] = Wait &&
forall_other r. Channel_msg[z,r] = Ok2 }
{
State[z] := Use;
}
transition t11 (z)
requires { State[z] = Use }
{
State[z] := Idle;
Num[z] := 0.0;
Channel_msg[i,j] := case
| i = z && j <> z && Channel_msg[i,j] = Ok2 : Empty
| _ : Channel_msg[i,j];
}