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.

219 lines
7.1 KiB

2 months ago
  1. // WLAN PROTOCOL (two stations)
  2. // discrete time model
  3. // gxn/jzs 20/02/02
  4. mdp
  5. // COLLISIONS
  6. const int COL = 2; // maximum number of collisions
  7. // TIMING CONSTRAINTS
  8. // we have used the FHSS parameters
  9. // then scaled by the value of ASLOTTIME
  10. const int ASLOTTIME = 1;
  11. const int DIFS = 3; // due to scaling can be either 2 or 3 which is modelled by a non-deterministic choice
  12. const int VULN = 1; // due to scaling can be either 0 or 1 which is modelled by a non-deterministic choice
  13. const int TRANS_TIME_MAX = 2; // scaling up
  14. const int TRANS_TIME_MIN = 4; // scaling down
  15. const int ACK_TO = 6;
  16. const int ACK = 4; // due to scaling can be either 3 or 4 which is modelled by a non-deterministic choice
  17. const int SIFS = 1; // due to scaling can be either 0 or 1 which is modelled by a non-deterministic choice
  18. // maximum constant used in timing constraints + 1
  19. const int TIME_MAX = max(ACK_TO,TRANS_TIME_MAX)+1;
  20. // CONTENTION WINDOW
  21. // CWMIN =15 & CWMAX =16
  22. // this means that MAX_BACKOFF IS 2
  23. const int MAX_BACKOFF = 0;
  24. //-----------------------------------------------------------------//
  25. // THE MEDIUM/CHANNEL
  26. // FORMULAE FOR THE CHANNEL
  27. // channel is busy
  28. formula busy = c1>0 | c2>0;
  29. // channel is free
  30. formula free = c1=0 & c2=0;
  31. module medium
  32. // number of collisions
  33. col : [0..COL];
  34. // medium status
  35. c1 : [0..2];
  36. c2 : [0..2];
  37. // ci corresponds to messages associated with station i
  38. // 0 nothing being sent
  39. // 1 being sent correctly
  40. // 2 being sent garbled
  41. // begin sending message and nothing else currently being sent
  42. [send1] c1=0 & c2=0 -> (c1'=1);
  43. [send2] c2=0 & c1=0 -> (c2'=1);
  44. // begin sending message and something is already being sent
  45. // in this case both messages become garbled
  46. [send1] c1=0 & c2>0 -> (c1'=2) & (c2'=2) & (col'=min(col+1,COL));
  47. [send2] c2=0 & c1>0 -> (c1'=2) & (c2'=2) & (col'=min(col+1,COL));
  48. // finish sending message
  49. [finish1] c1>0 -> (c1'=0);
  50. [finish2] c2>0 -> (c2'=0);
  51. endmodule
  52. //-----------------------------------------------------------------//
  53. // STATION 1
  54. module station1
  55. // clock for station 1
  56. x1 : [0..TIME_MAX];
  57. // local state
  58. s1 : [1..12];
  59. // 1 sense
  60. // 2 wait until free before setting backoff
  61. // 3 wait for DIFS then set slot
  62. // 4 set backoff
  63. // 5 backoff
  64. // 6 wait until free in backoff
  65. // 7 wait for DIFS then resume backoff
  66. // 8 vulnerable
  67. // 9 transmit
  68. // 11 wait for SIFS and then ACK
  69. // 10 wait for ACT_TO
  70. // 12 done
  71. // BACKOFF
  72. // separate into slots
  73. slot1 : [0..1];
  74. backoff1 : [0..15];
  75. // BACKOFF COUNTER
  76. bc1 : [0..1];
  77. // SENSE
  78. // let time pass
  79. [time] s1=1 & x1<DIFS & free -> (x1'=min(x1+1,TIME_MAX));
  80. // ready to transmit
  81. [] s1=1 & (x1=DIFS | x1=DIFS-1) -> (s1'=8) & (x1'=0);
  82. // found channel busy so wait until free
  83. [] s1=1 & busy -> (s1'=2) & (x1'=0);
  84. // WAIT UNTIL FREE BEFORE SETTING BACKOFF
  85. // let time pass (no need for the clock x1 to change)
  86. [time] s1=2 & busy -> (s1'=2);
  87. // find that channel is free so check its free for DIFS before setting backoff
  88. [] s1=2 & free -> (s1'=3);
  89. // WAIT FOR DIFS THEN SET BACKOFF
  90. // let time pass
  91. [time] s1=3 & x1<DIFS & free -> (x1'=min(x1+1,TIME_MAX));
  92. // found channel busy so wait until free
  93. [] s1=3 & busy -> (s1'=2) & (x1'=0);
  94. // start backoff first uniformly choose slot
  95. // backoff counter 0
  96. [] s1=3 & (x1=DIFS | x1=DIFS-1) & bc1=0 -> (s1'=4) & (x1'=0) & (slot1'=0) & (bc1'=min(bc1+1,MAX_BACKOFF));
  97. // SET BACKOFF (no time can pass)
  98. // chosen slot now set backoff
  99. [] s1=4 -> 1/16 : (s1'=5) & (backoff1'=0 )
  100. + 1/16 : (s1'=5) & (backoff1'=1 )
  101. + 1/16 : (s1'=5) & (backoff1'=2 )
  102. + 1/16 : (s1'=5) & (backoff1'=3 )
  103. + 1/16 : (s1'=5) & (backoff1'=4 )
  104. + 1/16 : (s1'=5) & (backoff1'=5 )
  105. + 1/16 : (s1'=5) & (backoff1'=6 )
  106. + 1/16 : (s1'=5) & (backoff1'=7 )
  107. + 1/16 : (s1'=5) & (backoff1'=8 )
  108. + 1/16 : (s1'=5) & (backoff1'=9 )
  109. + 1/16 : (s1'=5) & (backoff1'=10)
  110. + 1/16 : (s1'=5) & (backoff1'=11)
  111. + 1/16 : (s1'=5) & (backoff1'=12)
  112. + 1/16 : (s1'=5) & (backoff1'=13)
  113. + 1/16 : (s1'=5) & (backoff1'=14)
  114. + 1/16 : (s1'=5) & (backoff1'=15);
  115. // BACKOFF
  116. // let time pass
  117. [time] s1=5 & x1<ASLOTTIME & free -> (x1'=min(x1+1,TIME_MAX));
  118. // decrement backoff
  119. [] s1=5 & x1=ASLOTTIME & backoff1>0 -> (s1'=5) & (x1'=0) & (backoff1'=backoff1-1);
  120. [] s1=5 & x1=ASLOTTIME & backoff1=0 & slot1>0 -> (s1'=5) & (x1'=0) & (backoff1'=15) & (slot1'=slot1-1);
  121. // finish backoff
  122. [] s1=5 & x1=ASLOTTIME & backoff1=0 & slot1=0 -> (s1'=8) & (x1'=0);
  123. // found channel busy
  124. [] s1=5 & busy -> (s1'=6) & (x1'=0);
  125. // WAIT UNTIL FREE IN BACKOFF
  126. // let time pass (no need for the clock x1 to change)
  127. [time] s1=6 & busy -> (s1'=6);
  128. // find that channel is free
  129. [] s1=6 & free -> (s1'=7);
  130. // WAIT FOR DIFS THEN RESUME BACKOFF
  131. // let time pass
  132. [time] s1=7 & x1<DIFS & free -> (x1'=min(x1+1,TIME_MAX));
  133. // resume backoff (start again from previous backoff)
  134. [] s1=7 & (x1=DIFS | x1=DIFS-1) -> (s1'=5) & (x1'=0);
  135. // found channel busy
  136. [] s1=7 & busy -> (s1'=6) & (x1'=0);
  137. // VULNERABLE
  138. // let time pass
  139. [time] s1=8 & x1<VULN -> (x1'=min(x1+1,TIME_MAX));
  140. // move to transmit
  141. [send1] s1=8 & (x1=VULN | x1=VULN-1) -> (s1'=9) & (x1'=0);
  142. // TRANSMIT
  143. // let time pass
  144. [time] s1=9 & x1<TRANS_TIME_MAX -> (x1'=min(x1+1,TIME_MAX));
  145. // finish transmission successful
  146. [finish1] s1=9 & x1>=TRANS_TIME_MIN & c1=1 -> (s1'=10) & (x1'=0);
  147. // finish transmission garbled
  148. [finish1] s1=9 & x1>=TRANS_TIME_MIN & c1=2 -> (s1'=11) & (x1'=0);
  149. // WAIT FOR SIFS THEN WAIT FOR ACK
  150. // WAIT FOR SIFS i.e. c1=0
  151. // check channel and busy: go into backoff
  152. [] s1=10 & c1=0 & x1=0 & busy -> (s1'=2);
  153. // check channel and free: let time pass
  154. [time] s1=10 & c1=0 & x1=0 & free -> (x1'=min(x1+1,TIME_MAX));
  155. // let time pass
  156. // following guard is always false as SIFS=1
  157. // [time] s1=10 & c1=0 & x1>0 & x1<SIFS -> (x1'=min(x1+1,TIME_MAX));
  158. // ack is sent after SIFS (since SIFS-1=0 add condition that channel is free)
  159. [send1] s1=10 & c1=0 & (x1=SIFS | (x1=SIFS-1 & free)) -> (s1'=10) & (x1'=0);
  160. // WAIT FOR ACK i.e. c1=1
  161. // let time pass
  162. [time] s1=10 & c1=1 & x1<ACK -> (x1'=min(x1+1,TIME_MAX));
  163. // get acknowledgement so packet sent correctly and move to done
  164. [finish1] s1=10 & c1=1 & (x1=ACK | x1=ACK-1) -> (s1'=12) & (x1'=0) & (bc1'=0);
  165. // WAIT FOR ACK_TO
  166. // check channel and busy: go into backoff
  167. [] s1=11 & x1=0 & busy -> (s1'=2);
  168. // check channel and free: let time pass
  169. [time] s1=11 & x1=0 & free -> (x1'=min(x1+1,TIME_MAX));
  170. // let time pass
  171. [time] s1=11 & x1>0 & x1<ACK_TO -> (x1'=min(x1+1,TIME_MAX));
  172. // no acknowledgement (go to backoff waiting DIFS first)
  173. [] s1=11 & x1=ACK_TO -> (s1'=3) & (x1'=0);
  174. // DONE
  175. [time] s1=12 -> (s1'=12);
  176. endmodule
  177. // ---------------------------------------------------------------------------- //
  178. // STATION 2 (rename STATION 1)
  179. module
  180. station2=station1[x1=x2,
  181. s1=s2,
  182. s2=s1,
  183. c1=c2,
  184. c2=c1,
  185. slot1=slot2,
  186. backoff1=backoff2,
  187. bc1=bc2,
  188. send1=send2,
  189. finish1=finish2]
  190. endmodule
  191. // ---------------------------------------------------------------------------- //
  192. label "twoCollisions" = col=2;
  193. label "fourCollisions" = col=4;
  194. label "sixCollisions" = col=6;