Hi I am having trouble creating a pseudocode for this question, but I did give it a shot. I hope someone can help. This is the question.
Consider the concurrent logical channels protocol. This protocol does not guarantee that messages are delivered in order. Modify the protocol to ensure that this is the case. I suggest you always send messages in channel order (first over channel 0, then over channel 1, then over channel 2, etc up to n-1 and then back over to channel 0). Modify the receiver to deliver messages to the application also in channel order (first channel 0, then 1, etc.). Modify also the receiver to have one buffer space for each channel (in case messages arrive out of order)
this is the original pseudocode:
process sender
variables
body : data from higher layer
sb: bit of last frame sent
ab: bit of last acknowledgment
begin
when sb = ab then
body := message from higher layer
sb := (sb+1) mod 2
19
send frame(sb, body) to receiver
when receive ack(ab) then
skip
when timeout for last message sent then
if sb ≠ ab then
send frame(sb, body) to receiver
end
process receiver
variables
body : data to be delivered to higher layer
nb: bit of next frame to deliver to app
b: bit in frame just received
begin
when receive frame(b, body) then
20
send ack(b) to sender
if b = nb then
deliver body to higher layer
nb := (nb + 1) mod 2
this is my psedocode:
process sender
const N : number of logical channels
variables
body : array[0 .. N-1] of whatever
sb: array[0 .. N-1] of 0 .. 1
ab: array[0 .. N-1] of 0 .. 1
b: 0 .. 1 {bit in ack}
n: 0 .. N-1 {channel number in ack}
begin
for any i, 0 ≤ i < N, //i is the channel number
when sb[n] = ab[n] then
body[n+1] := message from higher layer
sb[i] := (sb[i] + 1) mod 2
send frame(i, sb[n+1], body[n+1]) to receiver
when receive ack(n, b) then
ab[n] := b
for any i, 0 ≤ i < N,
when timeout for message sent in channel i then
if sb[i] ≠ ab[i] then
send frame(i, sb[i], body[i]) to receiver
end
process receiver
const N: number of channels
variables
nb: array [0 .. N-1] of 0..1 {next bit expected}
body: data to be delivered to higher layer
b: 0..1 {bit received in frame}
n: 0 .. N-1 {channel number of frame}
begin
when receive frame(n, b, body) then
if b = nb[n] then //if the received bit is the next bit expected then send ack
send ack(n, b) to sender
if b = nb[n] then
deliver body to higher layer
nb[n] := (nb[n] + 1) mod 2
Can someone help?
Thanks.