------------------------------------------------------------------------------ Mohamed G. Gouda CS 356 Spring 2014 Homework 1 ------------------------------------------------------------------------------ (A Flow Control Protocol) Consider the protocol that consists of the following two processes p and q, whose communication is assumed to be error-free. process p const w var ns, na, i: integer {init 0} begin ns < na+w --> send data(ns) to q; ns := ns+1 [] rcv ack(i) from q --> {na =< i} na := i end process q var nr, j: integer {init 0} begin rcv data(j) from p --> {nr=j} nr := j+1 [] true --> send ack(nr) to p end In this network, p sends data messages to q and q sends back ack messages (acknowledging the reception of data messages) to p. Each data message is of the form data(j), where j is the sequence number of the message. Each ack message is of the from ack(i) to acknowledge the reception of the data(i) message. The goal of this protocol is to ensure that the number of data messages in the channel from p to q never exceeds the constant w. (Such a protocol is referred to as a flow control protocol.) Note that process p has two integer variables ns and na. Variable ns stores the sequence number of the next data message to be sent by p. Variable na stores the sequence number of the next data message whose reception is expected to be acknowledged by q. Note also that process q has a variable nr that stores the sequence number of the next data message to be received by q. 1. (4 points) Modify processes p and q such that the protocol still achieves its goal under the assumption that sent messages can be reordered, but neither corrupted nor lost. (Hint: the variables in the modified processes are the same as those in the original processes.) 2. (4 points) Modify processes p and q such that the protocol still achieves its goal under the assumption that sent messages can be lost, but neither corrupted nor reordered. Moreover, no w consecutive data messages can be all lost (Hint: the variables in the modified processes are the same as those in the original processes.) 3. (2 points) Modify processes p and q such that the protocol still achieves its goal under the assumption that sent messages can be corrupted, but neither lost nor reordered. Moreover, no w consecutive data messages can be all corrupted (Hint: the variables in the modified processes are the same as those in the original processes.) Solutions: (1). process p const w var ns, na, i: integer {init 0} begin ns < na+w --> send data(ns) to q; ns := ns+1 [] rcv ack(i) from q --> if na =< i --> na := i [] na > i --> skip fi end process q var nr, j: integer {init 0} begin rcv data(j) from p --> if nr =< j --> nr := nr+1 [] nr > j --> skip fi [] true --> send ack(nr) to p end (2). Process p is the same as in (1). process q var nr, j: integer {init 0} begin rcv data(j) from p --> if nr =< j --> nr := j+1 [] nr > j --> skip fi [] true --> send ack(nr) to p end (3). Processes p and q remain as they are in (2), except that we need to add to p, the action: rcv error from q --> skip and add to q the action: rcv error from p --> skip