-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CONSTANTS | ||
N = 7 | ||
M = 7 | ||
|
||
\* Relevant for statistics only! Exhaustive model | ||
\* checking will *not* work with AtStabilazation | ||
\* because it evaluates to false UniqueToken is | ||
\* true. | ||
CONSTRAINTS | ||
AtStabilization | ||
|
||
CHECK_DEADLOCK | ||
FALSE | ||
|
||
SPECIFICATION | ||
Spec | ||
|
||
INVARIANT | ||
TypeOK | ||
|
||
\* TLC will report a (bogus) violation of Stab in | ||
\* "generate" or "simulate" mode, due to the way these | ||
\* modes work. | ||
\* PROPERTIES | ||
\* Stab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-------------------------------- MODULE SimTokenRing ------------------------------- | ||
EXTENDS TokenRing, TLC, CSV, IOUtils | ||
|
||
(* Statistics collection *) | ||
|
||
CSVFile == | ||
"SimTokenRing.csv" | ||
|
||
ASSUME | ||
\* Initialize the CSV file with a header. | ||
/\ CSVRecords(CSVFile) = 0 => CSVWrite("steps", <<>>, CSVFile) | ||
|
||
AtStabilization == | ||
\* State constraint at cfg | ||
UniqueToken => | ||
/\ CSVWrite("%1$s", <<TLCGet("level")>>,CSVFile) | ||
/\ TLCGet("stats").traces % 250 = 0 => | ||
/\ IOExec(<<"/usr/bin/env", "Rscript", "SimTokenRing.R", CSVFile>>).exitValue = 0 | ||
/\ FALSE \* to make TLC simulate the next behavior one the system stabilizes. | ||
|
||
======================================================================================= | ||
$ rm -rf states/ ; rm *.csv ; tlc SimTokenRing -note -generate -depth -1 | ||
|
||
|
||
|
||
$ alias tlc | ||
tlc='java -cp /path/to/tla2tools.jar tlc2.TLC' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CONSTANTS | ||
N = 6 | ||
M = 6 | ||
|
||
CHECK_DEADLOCK | ||
FALSE | ||
|
||
SPECIFICATION | ||
Spec | ||
|
||
INVARIANT | ||
TypeOK | ||
|
||
PROPERTIES | ||
Stab | ||
|
||
ALIAS | ||
Alias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--------------------------------- MODULE TokenRing --------------------------------- | ||
(***********************************************************************************) | ||
(* Dijkstra's classical stabilizing token ring algorithm: EWD426 *) | ||
(* https://muratbuffalo.blogspot.com/2015/01/dijkstras-stabilizing-token-ring.html *) | ||
(***********************************************************************************) | ||
EXTENDS Naturals, FiniteSets | ||
|
||
CONSTANTS N, M | ||
ASSUME NAssumption == N \in Nat \ {0} \* At least one node | ||
ASSUME MAssumption == M \in Nat \ {0} \* Value domain of c | ||
|
||
ASSUME NMAssumption == N <= M + 1 | ||
|
||
Node == 0 .. N-1 | ||
|
||
VARIABLES | ||
c \* counter at each node, token is defined as function of c's in nbring nodes | ||
|
||
vars == << c >> | ||
|
||
TypeOK == | ||
/\ c \in [ Node -> 0 .. M-1 ] | ||
------------------------------------------------------------------------------------ | ||
|
||
Init == | ||
/\ c \in [ Node -> 0 .. M-1 ] | ||
|
||
CreateToken == | ||
(* Node 0 executes this action to inject new value into system *) | ||
/\ c [0] = c [N-1] | ||
/\ c' = [ c EXCEPT ![0] = (c[N-1]+ 1) % M ] | ||
|
||
PassToken(i) == | ||
(* Other nodes just copy value of the predecessor *) | ||
/\ i # 0 | ||
/\ c [i] # c [i-1] | ||
/\ c' = [ c EXCEPT ![i] = c[i-1]] | ||
|
||
--------------------------------------------------------------------------------------- | ||
Next == | ||
\/ CreateToken | ||
\/ \E i \in Node \ {0} : PassToken(i) | ||
|
||
Spec == Init /\ [][Next]_vars /\ WF_vars(Next) | ||
|
||
--------------------------------------------------------------------------------------- | ||
UniqueToken == | ||
\E i \in 0 .. N : \* unique token at i (or i=N => token is at 0) | ||
/\ \A j \in 0..i-1: c[j]= c[0] \* before i all c equals c[0] | ||
/\ \A j \in i..N-1: c[j]= (c[0]-1) % M \* after i all c following c[0] | ||
|
||
(* Stabilization property *) | ||
Stab == <>[]UniqueToken | ||
|
||
--------------------------------------------------------------------------------------- | ||
|
||
Alias == | ||
[ | ||
counter|-> c, | ||
unique |-> UniqueToken | ||
] | ||
|
||
======================================================================================= |