You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
8.1 KiB

  1. // CSMA/CD protocol - probabilistic version of kronos model (3 stations)
  2. // gxn/dxp 04/12/01
  3. mdp
  4. // note made changes since cannot have strict inequalities
  5. // in digital clocks approach and suppose a station only sends one message
  6. // simplified parameters scaled
  7. const int sigma=1; // time for messages to propagate along the bus
  8. const int lambda=30; // time to send a message
  9. // actual parameters
  10. const int N = 3; // number of processes
  11. const int K = 6; // exponential backoff limit
  12. const int slot = 2*sigma; // length of slot
  13. const int M = 63; // max number of slots to wait
  14. //const int lambda=782;
  15. //const int sigma=26;
  16. //----------------------------------------------------------------------------------------------------------------------------
  17. // the bus
  18. module bus
  19. b : [0..2];
  20. // b=0 - idle
  21. // b=1 - active
  22. // b=2 - collision
  23. // clocks of bus
  24. y1 : [0..sigma+1]; // time since first send (used find time until channel sensed busy)
  25. y2 : [0..sigma+1]; // time since second send (used to find time until collision detected)
  26. // a sender sends (ok - no other message being sent)
  27. [send1] (b=0) -> (b'=1);
  28. [send2] (b=0) -> (b'=1);
  29. [send3] (b=0) -> (b'=1);
  30. // a sender sends (bus busy - collision)
  31. [send1] (b=1|b=2) & (y1<sigma) -> (b'=2);
  32. [send2] (b=1|b=2) & (y1<sigma) -> (b'=2);
  33. [send3] (b=1|b=2) & (y1<sigma) -> (b'=2);
  34. // finish sending
  35. [end1] (b=1) -> (b'=0) & (y1'=0);
  36. [end2] (b=1) -> (b'=0) & (y1'=0);
  37. [end3] (b=1) -> (b'=0) & (y1'=0);
  38. // bus busy
  39. [busy1] (b=1|b=2) & (y1>=sigma) -> (b'=b);
  40. [busy2] (b=1|b=2) & (y1>=sigma) -> (b'=b);
  41. [busy3] (b=1|b=2) & (y1>=sigma) -> (b'=b);
  42. // collision detected
  43. [cd] (b=2) & (y2<=sigma) -> (b'=0) & (y1'=0) & (y2'=0);
  44. // time passage
  45. [time] (b=0) -> (y1'=0); // value of y1/y2 does not matter in state 0
  46. [time] (b=1) -> (y1'=min(y1+1,sigma+1)); // no invariant in state 1
  47. [time] (b=2) & (y2<sigma) -> (y1'=min(y1+1,sigma+1)) & (y2'=min(y2+1,sigma+1)); // invariant in state 2 (time until collision detected)
  48. endmodule
  49. //----------------------------------------------------------------------------------------------------------------------------
  50. // model of first sender
  51. module station1
  52. // LOCAL STATE
  53. s1 : [0..5];
  54. // s1=0 - initial state
  55. // s1=1 - transmit
  56. // s1=2 - collision (set backoff)
  57. // s1=3 - wait (bus busy)
  58. // s1=4 - successfully sent
  59. // LOCAL CLOCK
  60. x1 : [0..max(lambda,slot)];
  61. // BACKOFF COUNTER (number of slots to wait)
  62. bc1 : [0..M];
  63. // COLLISION COUNTER
  64. cd1 : [0..K];
  65. // start sending
  66. [send1] (s1=0) -> (s1'=1) & (x1'=0); // start sending
  67. [busy1] (s1=0) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // detects channel is busy so go into backoff
  68. // transmitting
  69. [time] (s1=1) & (x1<lambda) -> (x1'=min(x1+1,lambda)); // let time pass
  70. [end1] (s1=1) & (x1=lambda) -> (s1'=4) & (x1'=0); // finished
  71. [cd] (s1=1) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // collision detected (increment backoff counter)
  72. [cd] !(s1=1) -> (s1'=s1); // add loop for collision detection when not important
  73. // set backoff (no time can pass in this state)
  74. // probability depends on which transmission this is (cd1)
  75. [] s1=2 & cd1=1 -> 1/2 : (s1'=3) & (bc1'=0) + 1/2 : (s1'=3) & (bc1'=1) ;
  76. [] s1=2 & cd1=2 -> 1/4 : (s1'=3) & (bc1'=0) + 1/4 : (s1'=3) & (bc1'=1) + 1/4 : (s1'=3) & (bc1'=2) + 1/4 : (s1'=3) & (bc1'=3) ;
  77. [] s1=2 & cd1=3 -> 1/8 : (s1'=3) & (bc1'=0) + 1/8 : (s1'=3) & (bc1'=1) + 1/8 : (s1'=3) & (bc1'=2) + 1/8 : (s1'=3) & (bc1'=3) + 1/8 : (s1'=3) & (bc1'=4) + 1/8 : (s1'=3) & (bc1'=5) + 1/8 : (s1'=3) & (bc1'=6) + 1/8 : (s1'=3) & (bc1'=7) ;
  78. [] s1=2 & cd1=4 -> 1/16 : (s1'=3) & (bc1'=0) + 1/16 : (s1'=3) & (bc1'=1) + 1/16 : (s1'=3) & (bc1'=2) + 1/16 : (s1'=3) & (bc1'=3) + 1/16 : (s1'=3) & (bc1'=4) + 1/16 : (s1'=3) & (bc1'=5) + 1/16 : (s1'=3) & (bc1'=6) + 1/16 : (s1'=3) & (bc1'=7) + 1/16 : (s1'=3) & (bc1'=8) + 1/16 : (s1'=3) & (bc1'=9) + 1/16 : (s1'=3) & (bc1'=10) + 1/16 : (s1'=3) & (bc1'=11) + 1/16 : (s1'=3) & (bc1'=12) + 1/16 : (s1'=3) & (bc1'=13) + 1/16 : (s1'=3) & (bc1'=14) + 1/16 : (s1'=3) & (bc1'=15) ;
  79. [] s1=2 & cd1=5 -> 1/32 : (s1'=3) & (bc1'=0) + 1/32 : (s1'=3) & (bc1'=1) + 1/32 : (s1'=3) & (bc1'=2) + 1/32 : (s1'=3) & (bc1'=3) + 1/32 : (s1'=3) & (bc1'=4) + 1/32 : (s1'=3) & (bc1'=5) + 1/32 : (s1'=3) & (bc1'=6) + 1/32 : (s1'=3) & (bc1'=7) + 1/32 : (s1'=3) & (bc1'=8) + 1/32 : (s1'=3) & (bc1'=9) + 1/32 : (s1'=3) & (bc1'=10) + 1/32 : (s1'=3) & (bc1'=11) + 1/32 : (s1'=3) & (bc1'=12) + 1/32 : (s1'=3) & (bc1'=13) + 1/32 : (s1'=3) & (bc1'=14) + 1/32 : (s1'=3) & (bc1'=15) + 1/32 : (s1'=3) & (bc1'=16) + 1/32 : (s1'=3) & (bc1'=17) + 1/32 : (s1'=3) & (bc1'=18) + 1/32 : (s1'=3) & (bc1'=19) + 1/32 : (s1'=3) & (bc1'=20) + 1/32 : (s1'=3) & (bc1'=21) + 1/32 : (s1'=3) & (bc1'=22) + 1/32 : (s1'=3) & (bc1'=23) + 1/32 : (s1'=3) & (bc1'=24) + 1/32 : (s1'=3) & (bc1'=25) + 1/32 : (s1'=3) & (bc1'=26) + 1/32 : (s1'=3) & (bc1'=27) + 1/32 : (s1'=3) & (bc1'=28) + 1/32 : (s1'=3) & (bc1'=29) + 1/32 : (s1'=3) & (bc1'=30) + 1/32 : (s1'=3) & (bc1'=31) ;
  80. [] s1=2 & cd1=6 -> 1/64 : (s1'=3) & (bc1'=0) + 1/64 : (s1'=3) & (bc1'=1) + 1/64 : (s1'=3) & (bc1'=2) + 1/64 : (s1'=3) & (bc1'=3) + 1/64 : (s1'=3) & (bc1'=4) + 1/64 : (s1'=3) & (bc1'=5) + 1/64 : (s1'=3) & (bc1'=6) + 1/64 : (s1'=3) & (bc1'=7) + 1/64 : (s1'=3) & (bc1'=8) + 1/64 : (s1'=3) & (bc1'=9) + 1/64 : (s1'=3) & (bc1'=10) + 1/64 : (s1'=3) & (bc1'=11) + 1/64 : (s1'=3) & (bc1'=12) + 1/64 : (s1'=3) & (bc1'=13) + 1/64 : (s1'=3) & (bc1'=14) + 1/64 : (s1'=3) & (bc1'=15) + 1/64 : (s1'=3) & (bc1'=16) + 1/64 : (s1'=3) & (bc1'=17) + 1/64 : (s1'=3) & (bc1'=18) + 1/64 : (s1'=3) & (bc1'=19) + 1/64 : (s1'=3) & (bc1'=20) + 1/64 : (s1'=3) & (bc1'=21) + 1/64 : (s1'=3) & (bc1'=22) + 1/64 : (s1'=3) & (bc1'=23) + 1/64 : (s1'=3) & (bc1'=24) + 1/64 : (s1'=3) & (bc1'=25) + 1/64 : (s1'=3) & (bc1'=26) + 1/64 : (s1'=3) & (bc1'=27) + 1/64 : (s1'=3) & (bc1'=28) + 1/64 : (s1'=3) & (bc1'=29) + 1/64 : (s1'=3) & (bc1'=30) + 1/64 : (s1'=3) & (bc1'=31) + 1/64 : (s1'=3) & (bc1'=32) + 1/64 : (s1'=3) & (bc1'=33) + 1/64 : (s1'=3) & (bc1'=34) + 1/64 : (s1'=3) & (bc1'=35) + 1/64 : (s1'=3) & (bc1'=36) + 1/64 : (s1'=3) & (bc1'=37) + 1/64 : (s1'=3) & (bc1'=38) + 1/64 : (s1'=3) & (bc1'=39) + 1/64 : (s1'=3) & (bc1'=40) + 1/64 : (s1'=3) & (bc1'=41) + 1/64 : (s1'=3) & (bc1'=42) + 1/64 : (s1'=3) & (bc1'=43) + 1/64 : (s1'=3) & (bc1'=44) + 1/64 : (s1'=3) & (bc1'=45) + 1/64 : (s1'=3) & (bc1'=46) + 1/64 : (s1'=3) & (bc1'=47) + 1/64 : (s1'=3) & (bc1'=48) + 1/64 : (s1'=3) & (bc1'=49) + 1/64 : (s1'=3) & (bc1'=50) + 1/64 : (s1'=3) & (bc1'=51) + 1/64 : (s1'=3) & (bc1'=52) + 1/64 : (s1'=3) & (bc1'=53) + 1/64 : (s1'=3) & (bc1'=54) + 1/64 : (s1'=3) & (bc1'=55) + 1/64 : (s1'=3) & (bc1'=56) + 1/64 : (s1'=3) & (bc1'=57) + 1/64 : (s1'=3) & (bc1'=58) + 1/64 : (s1'=3) & (bc1'=59) + 1/64 : (s1'=3) & (bc1'=60) + 1/64 : (s1'=3) & (bc1'=61) + 1/64 : (s1'=3) & (bc1'=62) + 1/64 : (s1'=3) & (bc1'=63) ;
  81. // wait until backoff counter reaches 0 then send again
  82. [time] (s1=3) & (x1<slot) -> (x1'=x1+1); // let time pass (in slot)
  83. [time] (s1=3) & (x1=slot) & (bc1>0) -> (x1'=1) & (bc1'=bc1-1); // let time pass (move slots)
  84. [send1] (s1=3) & (x1=slot) & (bc1=0) -> (s1'=1) & (x1'=0); // finished backoff (bus appears free)
  85. [busy1] (s1=3) & (x1=slot) & (bc1=0) -> (s1'=2) & (x1'=0) & (cd1'=min(K,cd1+1)); // finished backoff (bus busy)
  86. // once finished nothing matters
  87. [time] (s1>=4) -> (x1'=0);
  88. endmodule
  89. //----------------------------------------------------------------------------------------------------------------------------
  90. // construct further stations through renaming
  91. module station2=station1[s1=s2,x1=x2,cd1=cd2,bc1=bc2,send1=send2,busy1=busy2,end1=end2] endmodule
  92. module station3=station1[s1=s3,x1=x3,cd1=cd3,bc1=bc3,send1=send3,busy1=busy3,end1=end3] endmodule
  93. //----------------------------------------------------------------------------------------------------------------------------
  94. // reward structure for expected time
  95. rewards "time"
  96. [time] true : 1;
  97. endrewards
  98. //----------------------------------------------------------------------------------------------------------------------------
  99. // labels/formulae
  100. label "all_delivered" = s1=4&s2=4&s3=4;
  101. label "one_delivered" = s1=4|s2=4|s3=4;
  102. label "collision_max_backoff" = (cd1=K & s1=1 & b=2)|(cd2=K & s2=1 & b=2)|(cd3=K & s3=1 & b=2);