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.

213 lines
5.5 KiB

  1. // Modest PTA model of the bounded retransmission protocol (BRP)
  2. // [HH09], http://www.modestchecker.net/CaseStudies/BRP/
  3. action put, get, put_k, get_k, put_l, get_l;
  4. action new_file;
  5. action s_ok, s_dk, s_nok, s_restart;
  6. action r_ok, r_inc, r_fst, r_nok, r_timeout;
  7. exception error;
  8. const int N = 16; // number of frames per file
  9. const int MAX = 2; // maximum number of retransmissions per frame
  10. const int TD = 1; // transmission delay
  11. const int TS = 2 * TD + 1; // sender timeout
  12. const int TR = 2 * MAX * TS + 3 * TD; // receiver timeout
  13. const int SYNC = TR;
  14. bool ff, lf, ab; // channel data: first/last frame, alternating bit
  15. int(0..N) i; // sender chunk counter
  16. bool inTransitK = false;
  17. bool inTransitL = false;
  18. bool first_file_done = false;
  19. bool get_k_seen, s_ok_seen, s_nok_seen, s_dk_seen, s_restart_seen, r_ok_seen, r_timeout_seen;
  20. // Invariant (timed) properties (from [BrpOnTime], the TA model)
  21. bool premature_timeout, channel_k_overflow, channel_l_overflow;
  22. // "there is at most one message in transit for each channel"
  23. property T_1 = A[] (!(channel_k_overflow || channel_l_overflow));
  24. // "there is at most one message in transit in total"
  25. property T_2 = A[] (!(inTransitK && inTransitL));
  26. // Assumption (A1): "no premature timeouts"
  27. property T_A1 = A[] (!premature_timeout);
  28. // Assumption (A2): "sender starts new file only after receiver reacted to failure"
  29. // Note that receiver can only notice failure if it received at least one chunk, i.e. get_k_seen
  30. property T_A2 = A[] (!s_restart_seen || !get_k_seen || r_timeout_seen);
  31. // Probabilistic reachability properties (from [D'AJJL01], the RAPTURE/PRISM model)
  32. // property A of [D'AJJL01]: "the maximum probability that eventually the sender reports
  33. // a certain unsuccessful transmission but the receiver got the complete file"
  34. property P_A = Pmax(<>(s_nok_seen && r_ok_seen));
  35. // property B of [D'AJJL01]: "the maximum probability that eventually the sender reports
  36. // a certain successful transmission but the receiver did not get the complete file"
  37. property P_B = Pmax(<>(s_ok_seen && !r_ok_seen));
  38. // property 1 of [D'AJJL01]: "the maximum probability that eventually the sender
  39. // does not report a successful transmission"
  40. property P_1 = Pmax(<>(s_nok_seen || s_dk_seen));
  41. // property 2 of [D'AJJL01]: "the maximum probability that eventually the sender
  42. // reports an uncertainty on the success of the transmission"
  43. property P_2 = Pmax(<>(s_dk_seen));
  44. // property 3 of [D'AJJL01]: "the maximum probability that eventually the sender
  45. // reports an unsuccessful transmission after more than 8 chunks have been sent successfully"
  46. property P_3 = Pmax(<>(s_nok_seen && i > 8));
  47. // property 4 of [D'AJJL01]: "the maximum probability that eventually the receiver
  48. // does not receive any chunk and the sender tried to send a chunk"
  49. property P_4 = Pmax(<>((s_ok_seen || s_nok_seen || s_dk_seen) && !get_k_seen));
  50. process Sender()
  51. {
  52. bool bit;
  53. int(0..MAX) rc;
  54. clock c;
  55. try
  56. {
  57. do {
  58. :: when urgent(i < N) {= i++ =};
  59. do
  60. {
  61. // send frame
  62. invariant(c <= 0) put_k {= ff = (i == 1), lf = (i == N), ab = bit, c = 0 =};
  63. invariant(c <= TS) alt {
  64. :: // receive ack
  65. get_l {= bit = !bit, rc = 0, c = 0 =};
  66. urgent break
  67. :: // timeout
  68. when(c >= TS)
  69. if(rc < MAX)
  70. {
  71. // retry
  72. {= rc++, c = 0 =}
  73. }
  74. else if(i < N)
  75. {
  76. // no retries left
  77. s_nok {= rc = 0, c = 0 =};
  78. urgent throw(error)
  79. }
  80. else
  81. {
  82. // no retries left
  83. s_dk {= rc = 0, c = 0 =};
  84. urgent throw(error)
  85. }
  86. }
  87. }
  88. :: when(i == N)
  89. // file transmission successfully completed
  90. invariant(c <= 0) s_ok {= first_file_done = true =};
  91. urgent break
  92. }
  93. }
  94. catch error
  95. {
  96. // File transfer did not succeed: wait, then restart with next file
  97. invariant(c <= SYNC) when(c >= SYNC)
  98. s_restart {= bit = false, first_file_done = true =}
  99. }
  100. }
  101. process Receiver()
  102. {
  103. bool r_ff, r_lf, r_ab;
  104. bool bit;
  105. clock c;
  106. // receive first frame
  107. if(ff) { get_k {= c = 0, bit = ab, r_ff = ff, r_lf = lf, r_ab = ab =} }
  108. else { get_k {= c = 0, premature_timeout = true =}; stop };
  109. do
  110. {
  111. invariant(c <= 0)
  112. {
  113. if(r_ab != bit)
  114. {
  115. // repetition, re-ack
  116. put_l
  117. }
  118. else
  119. {
  120. // report frame
  121. if(r_lf) { r_ok }
  122. else if(r_ff) { r_fst }
  123. else { r_inc };
  124. put_l {= bit = !bit =}
  125. }
  126. };
  127. invariant(c <= TR)
  128. {
  129. alt {
  130. :: // receive next frame
  131. get_k {= c = 0, r_ff = ff, r_lf = lf, r_ab = ab =}
  132. :: // timeout
  133. when(c == TR)
  134. if(r_lf)
  135. {
  136. // we just got the last frame, though
  137. r_timeout; break
  138. }
  139. else
  140. {
  141. r_nok;
  142. // abort transfer
  143. r_timeout; break
  144. }
  145. }
  146. }
  147. };
  148. Receiver()
  149. }
  150. process ChannelK()
  151. {
  152. clock c;
  153. put_k palt
  154. {
  155. :98: {= c = 0, inTransitK = true =};
  156. invariant(c <= TD) alt {
  157. :: get_k {= inTransitK = false =}
  158. :: put_k {= channel_k_overflow = true =}; stop
  159. }
  160. : 2: {==}
  161. };
  162. ChannelK()
  163. }
  164. process ChannelL()
  165. {
  166. clock c;
  167. put_l palt
  168. {
  169. :99: {= c = 0, inTransitL = true =};
  170. invariant(c <= TD) alt {
  171. :: get_l {= inTransitL = false =}
  172. :: put_l {= channel_l_overflow = true =}; stop
  173. }
  174. : 1: {==}
  175. };
  176. ChannelL()
  177. }
  178. process Observer()
  179. {
  180. alt {
  181. :: get_k {= get_k_seen = true =}
  182. :: s_ok {= s_ok_seen = true =}
  183. :: s_nok {= s_nok_seen = true =}
  184. :: s_dk {= s_dk_seen = true =}
  185. :: s_restart {= s_restart_seen = true =}
  186. :: r_ok {= r_ok_seen = true =}
  187. :: r_timeout {= r_timeout_seen = true =}
  188. };
  189. Observer()
  190. }
  191. par {
  192. :: Sender()
  193. :: Receiver()
  194. :: ChannelK()
  195. :: ChannelL()
  196. :: Observer()
  197. }