------------------------------------------------------------------------------ Mohamed G. Gouda CS 356 Spring 2009 Homework 2 ------------------------------------------------------------------------------ 1. (4 points) The connection protocols in Chapter 6 are designed under the assumption that sent messages can be lost or reordered before they are received. Design a simplex connection protocol, where a process p can establish a connection and send up to m data messages to another process q, under the assumption that sent messages are not corrupted, lost, nor reordered. Specify your designed protocol using the AP notation. Solution: process p inp m : integer var conp : boolean {init. false} cansnd : 0..m readyp : boolean {init. true} begin ~conp ^ readyp -> send crqst to q; readyp:=false [] rcv crply from q -> conp,cansnd,readyp:=true,m,true [] conp ^ readyp -> if cansnd>0 -> send data to q; cansnd:=cansnd-1 [] true -> send drqst to q; readyp:=false fi [] rcv drply from q -> conp,readyp:=false,true end process q var conq : boolean {init. false} begin rcv crqst from p -> if true -> conq:=true; send crply to p [] true -> conq:=false;send drply to p fi [] conq -> conq:=false; send drply to q [] rcv data from p -> if conq -> {accept data} skip [] ~conq -> {discard data} skip fi [] rcv drqst from p -> if conq -> conq:=false; send drply to p [] ~conq -> skip fi end ------------------------------------------------------------------------------ 2. (3 points) Extend the simplex protocol that you designed in solving problem 1 to a multi- connection full-duplex protocol where each of two processes r and s can establish up to v connections, and send up to m data messages over each established connection, to the other process. Again the extended protocol is to be designed under the assumption that sent messages are not corrupted, lost, nor reordered. Specify the extended protocol using the AP notation. Solution: process r const v inp m : integer var conp,conq : array[0..v-1] of boolean {init. false} cansnd : array[0..v-1] of 0..m readyp : array[0..v-1] of boolean {init. false} par c : 0..v-1 begin ~conp[c] ^ readyp[c] -> send crqst(c) to s; readyp[c]:=false [] rcv crply(c) from s -> conp[c],cansnd[c],readyp[c]:=true,m,true [] conp[c] ^ readyp[c] -> if cansnd[c]>0 -> send data(c) to s; cansnd[c]:=cansnd[c]-1 [] true -> send drqst(c) to s; readyp[c]:=false fi [] rcv drply(c) from s -> conp[c],readyp[c]:=false,true [] rcv crqst(c) from s -> if true -> conq[c]:=true; send crply(c) to s [] true -> conq[c]:=false;send drply(c) to s fi [] conq[c] -> conq[c]:=false; send drply(c) to p; [] rcv data(c) from s -> if conq[c] -> {accept data} skip [] ~conq[c] -> {discard data} skip fi [] rcv drqst(c) from s -> if conq[c] -> conq[c]:=false; send drply(c) to p [] ~conq[c] -> skip fi end ------------------------------------------------------------------------------ 3. (3 points) Consider the corruption detection protocol that uses parity bits in Section 8.1. This protocol is to be used to transmit blocks of 6000 data bits each, after augmenting each block with n parity bits. Assume that only the first 1000 bits and the last 1000 bits in an augmented block can be corrupted while this block is being transmitted. What are the best values for the two constants m and n in this protocol in this case? Explain your answer. Solution: The smallest value of n that guarantees detecting every corruption is 2000. Thus m = 3 and n = 2000. ------------------------------------------------------------------------------