Presentation is loading. Please wait.

Presentation is loading. Please wait.

Alternating Bit Protocol Protocol for simplex data-transfer channel: data flows from sender to receiver control flows in both directions the transfer medium.

Similar presentations


Presentation on theme: "Alternating Bit Protocol Protocol for simplex data-transfer channel: data flows from sender to receiver control flows in both directions the transfer medium."— Presentation transcript:

1 Alternating Bit Protocol Protocol for simplex data-transfer channel: data flows from sender to receiver control flows in both directions the transfer medium may corrupt messages The protocol attaches a status bit, the alternation bit to messages. Assume send from A to B B receives message and accepts it only if bits differ B sends verification message (an ack) to A (receipt of message) A receives ack and deduces message sent was received correctly send next message with flipped bit message sent was corrupted resend message nothing - because ack was corrupted resend message We do not indicate the exact corrpution of a message, just turn any corrupted message into error message.

2 2 Alternating Bit Protocol messages mtype = {data, control, error} channels chan fromA =[N] of {byte, byte, bit} /* messagetype1, data, statusbit */ chan toB =[N] of {byte, byte, bit} /* messagetype1, data, statusbit */ chan fromB =[N] of {byte, bit} /* messagetype2, statusbit */ chan toA =[N] of {byte, bit} /* messagetype2, statusbit */ messagetype1 = {data, error} messagetype2 = {control, error} lower layer A B fromB toB fromA toA

3 3 Lower Layer transfer medium (perfect channel) proctype lower (chan fromA, toA, fromB, toB) { byte d; bit b; do :: fromA?data(d,b) -> toB!data(d,b) :: fromB?control(b) -> toA!control(b) od } transfer medium (imperfect channel) proctype lower (chan fromA, toA, fromB, toB) { byte d; bit b; do :: fromA?data(d,b) -> if :: toB!data(d,b) /* correct */ :: toB!error(d,b) /* error */ fi :: fromB?control(b) -> if :: toA!control(b) /* correct */ :: toA!error(b) /* error */ fi od }

4 4 Sender Sender - without initialisation proctype A (chan in, out) { byte mt;/* message type */ bit at;/* status bit */ bit vr;/* verification bit */ FETCH; /* get actual data */ out!data(mt,at);/* send the data */ do/* wait for correct response */ :: in?control(vr) -> /* got a control message */ if :: (vr == 1) ->/* correct ! */ FETCH; /* get next actual data */ at = at -1;/* alternate status bit */ :: (vr == 0) -> /* an error in send */ skip /* do nothing, resend */ fi; out!data(mt,at) /* send the data */ :: in?error(vr) ->/* got an error message */ out!data(mt,at)/ resend the data */ od }

5 5 Receiver Receiver - without initialisation proctype B (chan in, out) { byte mr;/* message type */ byte last_mr;/* mr of last error-free msg */ bit ar;/* status bit */ bit lar;/* ar of last error-free msg */ do :: in?error(mr,ar) ->/* receive corrupted msg */ out!control(0) :: in?data(mr,ar) -> /* receive correct msg */ out!control(1); if :: (ar == lar) -> /* retransmission, do not accept */ skip :: (ar != lar) ->/* new message, accept */ ACCEPT; lar = ar;/* set last variables */ last_mr = mr fi od }

6 6 Initialisation Send message from A to B (error-free, but not necessarily accepted) which forces setting of B’s alternation bit.

7 7 Sender Sender - with initialisation proctype A (chan in, out) { byte mt=0;/* message type */ bit at =0;/* status bit */ bit vr;/* verification bit */ out!data(0,1)/* initialise */ do :: in?error(vr) -> /* an error in ack*/ out!data(0,1)/* resend */ :: in?control(0) -> /*an error in send */ out!data(0,1)/* resend */ :: in?control(1) -> /* successful initialisation */ break od FETCH; /* get actual data */ out!data(mt,at);/* send the data */ do/* wait for correct response */ :: in?control(vr) -> /* got a control message */ if :: (vr == 1) ->/* correct ! */ FETCH; /* get next actual data */ at = at -1;/* alternate status bit */ :: (vr == 0) -> /* an error in send */ skip /* do nothing, resend */ fi; out!data(mt,at) /* send the data */ :: in?error(vr) ->/* got an error message */ out!data(mt,at)/ resend the data */ od }

8 8 Receiver Receiver - with initialisation proctype B (chan in, out) { byte mr;/* message type */ byte last_mr;/* mr of last error-free msg */ bit ar;/* status bit */ bit lar;/* ar of last error-free msg */ bit ini=0;/* initialised */ do :: in?error(mr,ar) ->/* receive corrupted msg */ out!control(0) :: in?data(mr,ar) -> /* receive correct msg */ out!control(1); if :: (!ini) ->/* not initialised */ ini = 1; lar =ar/* initialise */ :: (ini) ->/* initialised */ if :: (ar == lar) ->/* retransmission, do not accept */ skip :: (ar != lar) ->/* new message, accept */ ACCEPT; lar = ar;/* set last variables */ last_mr =mr fi od }

9 9 Assertions #define ACCEPT assert(mr == (last_mr+1)%MAX) Full program: #define N 2 #define MAX 8 #define FETCH mt = (mt+1)%MAX /* sequence of numbers */ #define ACCEPT assert (mr == (last_mr+1)%MAX) /* messages received in sequence */ init {chan fromA =[N] of {byte, byte, bit} chan toB =[N] of {byte, byte, bit} chan fromB =[N] of {byte, bit} chan toA =[N] of {byte, bit} atomic{run A(toA, fromA); run B(toB, fromB); run lower(fromA, toA, fromB, toB)}

10 10 Message Sequence Charts 1. Message and ack is successful, 2 times. 2. Message is corrupted first time, success 2nd time. 3. Message is received, but ack is corrupted first time; success 2nd time. Use global channel names; show states of variables.

11 11 Using Spin for Simulation Run spin on a linux machine by: /local/fda/tools/install/i386-unkown-linux/bin/xspin-linux Run from *your* own directory. Set Simulation Parameters Display Mode Simulation Style MSC Panel Random Seed:1 Timed Sequence Guided Steps skipped: 0 Interactive Data Values Full Queue Blocks New Messages Loses New Messages x x x


Download ppt "Alternating Bit Protocol Protocol for simplex data-transfer channel: data flows from sender to receiver control flows in both directions the transfer medium."

Similar presentations


Ads by Google