Skip to content

Commit 75a846d

Browse files
committed
Toy model
0 parents  commit 75a846d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

vchan.tla

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
------------------------------- MODULE vchan -------------------------------
2+
3+
EXTENDS Naturals, Sequences \* Library imports
4+
CONSTANT BufferSize
5+
Byte == 0..255
6+
MSG == Seq(Byte)
7+
8+
Take(m, i) == SubSeq(m, 1, i)
9+
Drop(m, i) == SubSeq(m, i + 1, Len(m))
10+
11+
VARIABLES Got, Buffer, Sent
12+
vars == << Got, Buffer, Sent >>
13+
14+
\* Desired properties
15+
16+
Integrity == Take(Sent, Len(Got)) = Got
17+
18+
AvailabilityNat == Nat
19+
Availability == \A x \in AvailabilityNat :
20+
Len(Sent) = x ~> Len(Got) >= x
21+
22+
\* Algorithm
23+
24+
Read == \E n \in 1..Len(Buffer) :
25+
/\ Got' = Got \o Take(Buffer, n)
26+
/\ Buffer' = Drop(Buffer, n)
27+
/\ UNCHANGED Sent
28+
29+
Write == \E m \in MSG :
30+
/\ Buffer' = Buffer \o m
31+
/\ Len(Buffer') <= BufferSize
32+
/\ Sent' = Sent \o m
33+
/\ UNCHANGED Got
34+
35+
Next == Read \/ Write
36+
37+
Init == /\ Sent = << >>
38+
/\ Buffer = << >>
39+
/\ Got = << >>
40+
41+
Spec == Init /\ [][Next]_vars /\ WF_vars(Read)
42+
43+
BufferOK == Len(Buffer) <= BufferSize
44+
45+
\* Model checking
46+
47+
MSG_SEQ(max) == { [ x \in 1..N |-> Len(Sent) + x ] : N \in 1..max }
48+
49+
=============================================================================
50+

0 commit comments

Comments
 (0)