Data Link Layer Protocols Flow Control in Data Link Layer.

50
Data Link Layer Protocols Flow Control in Data Link Layer

Transcript of Data Link Layer Protocols Flow Control in Data Link Layer.

Page 1: Data Link Layer Protocols Flow Control in Data Link Layer.

Data Link Layer Protocols

Flow Control in Data Link Layer

Page 2: Data Link Layer Protocols Flow Control in Data Link Layer.

Flow Control: Initial Assumptions

• Simplex Channel

• Infinite buffer capacity with the receiver

• Error free transmission

• Network layer at the senders end is always ready with data

• No need for flow control

Page 3: Data Link Layer Protocols Flow Control in Data Link Layer.

Protocol Definitions

Continued

Some definitions needed in the protocols to follow. These are located in the file protocol.h.

Page 4: Data Link Layer Protocols Flow Control in Data Link Layer.

Protocol Definitions(ctd.)

Some definitions needed in the

protocols to follow. These are located in the file protocol.h.

Page 5: Data Link Layer Protocols Flow Control in Data Link Layer.

Unrestricted Simplex Protocol

Page 6: Data Link Layer Protocols Flow Control in Data Link Layer.

Some assumptions dropped

• Infinite capacity in the buffer of the receiver.• Need for “flow control”• Stop-n-Wait protocol

– Sender sends a frame

– And waits for a signal in the form of a dummy frame

– No seq no. is required since the line is still error free

Page 7: Data Link Layer Protocols Flow Control in Data Link Layer.

Simplex Stop-and-

Wait Protocol

Page 8: Data Link Layer Protocols Flow Control in Data Link Layer.

Further assumptions dropped

• The channel is noisy, frames may be damaged or lost

• Good scene : data frame reaches intact, ack sent back and received, next frame sent

• Bad scene : – Data frame damaged or lost ..hence no ack – sender times

out and resends .. No problems

– Data frame reaches intact but Ack lost .. Times out ..resends.. Receiver receives duplicate frames..Problem

Page 9: Data Link Layer Protocols Flow Control in Data Link Layer.

Problem of Duplicate frames• Solution :

– Keep a sequence number for each frame to distinguish between the new frame and a duplicate frame.

• How large should be the sequence number? Or• What should be minimum number of bits required for

the sequence number?– The only ambiguity at the receiver is between two

successive frames.. Say m and m+1 and never between m-1 and m +1 .. Its only after the ack for m-1 reaches back intact mth frame is sent.. And once mth frame reaches intact at the receiver’s end .. Story of m-1th frame is over .. However depending upon whether ack of mth frame reaches back intact or not either mth or m+1 th frame is sent .. hence only 1 bit is sufficient

Page 10: Data Link Layer Protocols Flow Control in Data Link Layer.

A Simplex Protocol for a Noisy Channel

A positive acknowledgement

with retransmission protocol.

Continued

Page 11: Data Link Layer Protocols Flow Control in Data Link Layer.

A Simplex Protocol for a Noisy Channel (ctd.)

A positive acknowledgement with retransmission protocol.

Page 12: Data Link Layer Protocols Flow Control in Data Link Layer.

Further assumption dropped

• Channel is simplex ..

• So, Now communication is two way .. I.e. Duplex channel– Interleave data and ack .. So ..a kind field is

required to specify whether the frame contains data or ack.

– Piggyback ack on data frame

Page 13: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol(Duplex)

• At any instant of time, the sender maintains a set of sequence numbers corresponding to frames it is permitted to send – this includes– frames not yet sent– Frames sent but not yet acknowledged .. May have to

be sent againThis corresponds to the sender’s window. When a packet

comes from the NL ..it is appended in the window and when an ack arrives for a frame..it is deleted from the buffer(and from the window)

Page 14: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol(Duplex)

• Similarly, the receiver also maintains a set of sequence numbers corresponding to frames it is permitted to accept. – When a frame arrives, its seq number is checked..if it

falls in the window it is accepted else discarded .. Once an ack is sent for a frame it is deleted from the window so that duplicate frames are not accepted.

• Sliding window gives the DLL the flexibility to accept the frames in any order but they must be handed over to the NL in order.

Page 15: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocols (2)

A sliding window of size 1, with a 3-bit sequence number.(a) Initially.(b) After the first frame has been sent.(c) After the first frame has been received.(d) After the first acknowledgement has been received.

Page 16: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocols

• A One-Bit Sliding Window Protocol

• A Protocol Using Go Back N

• A Protocol Using Selective Repeat

Page 17: Data Link Layer Protocols Flow Control in Data Link Layer.

A One-Bit Sliding Window Protocol

Continued

Page 18: Data Link Layer Protocols Flow Control in Data Link Layer.

A One-Bit Sliding Window Protocol (ctd.)

Page 19: Data Link Layer Protocols Flow Control in Data Link Layer.

How does it handle duplicate frames…

Say when an Ack is lost …A times out and resends..

Both A and B are wanting to send a packet numbered 0, or one can imagine they have both sent out packets with seq no. 1 and are waiting for its ack.

Page 20: Data Link Layer Protocols Flow Control in Data Link Layer.

• A sends A0, seq = 0, ack = 1, B sends B0, seq=0, ack = 1, but B0 is lost.

• B gets the packet A0 but ack is not the one required .. It resends B0 with the ack of A0… I.e. A0, seq = 0 and ack =0, (This is a duplicate of the ack that was lost) also it increments the FE .I.e FE becomes 1.

• Duplicates of A0,0,1 are rejected since their seq number (0) don’t match the FE(1). However B sends the duplicate of the above again.

• If this is also lost.. A duplicates and then B duplicates and so on.

Page 21: Data Link Layer Protocols Flow Control in Data Link Layer.

• Eventually one of the duplicates of B reaches A ..I.e. the ack required by A (remember both are waiting for ack of packet 0 in the beginning) and A sends another packet .. A1 with seq =1 and ack =0 that for B0 it just received.

• This was a good scene : problem was only due to noisy channel .. Ack were being lost

Page 22: Data Link Layer Protocols Flow Control in Data Link Layer.

Bad scene : duplicates without transmission error

• When B sends before receiving a frame from A.

Page 23: Data Link Layer Protocols Flow Control in Data Link Layer.

A One-Bit Sliding Window Protocol (2)

Two scenarios for protocol 4. (a) Normal case. (b) Abnormal case. The notation is (seq, ack, packet number). An asterisk indicates where a network layer accepts a packet.

Page 24: Data Link Layer Protocols Flow Control in Data Link Layer.

Further assumption dropped

• So far, implicitly, we have assumed that the time of transmission is negligible. I.e. the time frame takes to reach the receiver and the ack to travel back is negligible.

Page 25: Data Link Layer Protocols Flow Control in Data Link Layer.

Long propagation delays• Consider a 50 kbps satellite channel with a round trip

delay of 500 msec (10^-3 sec).• To send a frame of size 1000 bits ..it takes =

1000/50kbps = 20msec.• At t=0, the sender sends the first bit and at t = 20 msec (1000/50,000 sec= 1/50 sec= 1000/50

msec = 20msec), it sends the last bit.• At t= 270 msec, the frame completely reaches the

receiver.• Not before t= 520 msec , the ack arrives back at the

receiver ( it will be later than this). This means that the sender was blocked for 500 msec out of 520 msec.

Page 26: Data Link Layer Protocols Flow Control in Data Link Layer.

Contd..

• That means– Long propagation delays

– High bandwidth

– And, short frame length

Is bad in terms of channel efficiency.

A large window size is needed at the sender’s end whenever the bandwidth * round trip delay is large.

Page 27: Data Link Layer Protocols Flow Control in Data Link Layer.

Pipelining

• Imagine in the above example, if the sender could send more frames without waiting for the ack for the first one, the channel could have been utilized more efficiently. This technique is called pipelining.

Page 28: Data Link Layer Protocols Flow Control in Data Link Layer.

Pipelining

• Imagine the scenario, when the sender always has something to send until the ack for the first frame arrives .. Best scenario, right?

• Clearly this is not Stop-n Wait.

Page 29: Data Link Layer Protocols Flow Control in Data Link Layer.

Pipelining contd…

Let• Channel capacity is b bits/sec• Frame size l bits,• Round trip propagation time is R• The time required to transmit a single frame is l/b.• So, in stop n wait, the line is busy for l/b time and

idle for R time, thus the line utilization is= l/b divided by l/b + R = l/(l + bR).If l < bR, the efficiency will be less than 50%.

Page 30: Data Link Layer Protocols Flow Control in Data Link Layer.

Pipelining over noisy channels

• What if one or more frames is errored.• Two options :

– Throw away all the subsequent frames and go back and start resending from the damaged frame. This corresponds to size 1 window in the receiver. - Go back N Protocol

– Buffer the subsequent frames and wait for the damaged frame to be resent, once that comes handover the frames in proper order to the NL-Selective Repeat Protocol

Page 31: Data Link Layer Protocols Flow Control in Data Link Layer.

Comparison

• Trade off between the bandwidth utilization and the buffer space in the receiver.

Page 32: Data Link Layer Protocols Flow Control in Data Link Layer.

A Protocol Using Go Back N

Pipelining and error recovery. Effect on an error when

(a) Receiver’s window size is 1.

(b) Receiver’s window size is large.

Page 33: Data Link Layer Protocols Flow Control in Data Link Layer.

Issues• For a maxseq = 7, Number of outstanding frames

can only be 7 and not 8. To see why, let us consider what happens when 8 frames are allowed to be outstanding .. That is the scene is

• Sender has sent out 8 frames• The piggybacked ack for frame 7 finally comes to

the sender.• Now suppose the sender has 8 outstanding frames,

0…7• Now sender sends next frame 0, if it is lost, if B

has a frame to send, B will send the piggybacked ack for 7.

Page 34: Data Link Layer Protocols Flow Control in Data Link Layer.

• Next, the sender sends the next frame 1 without waiting for the ack for 0, now suppose this is also lost, again B has a frame to send,then B will again send ack for 7.

• And so on .. Sender sends all the outstanding frames, 0…7

• Suppose all of them are lost, the receiver will still send the ack of the last frame received I.e. 7.

• Now sender has no way of knowing, whether all the frames were lost or since it has received ack for 7..all the frames reached intact.

Page 35: Data Link Layer Protocols Flow Control in Data Link Layer.

Solution

• The problem is solved by keeping at most 7 instead of 8 outstanding frames, say– 0-6 in the first batch, and– 7,0-5 in the second

• If all the frames in the second batch are lost, sender may keep on receiving ack for frame 6 which is not in sender’s window and hence it will know that frames were lost.

Page 36: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol Using Go Back N

Continued

Page 37: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol Using Go Back N

Continued

Page 38: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol Using Go Back N

Continued

Page 39: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol Using Go Back N

Page 40: Data Link Layer Protocols Flow Control in Data Link Layer.

Sliding Window Protocol Using Go Back N (2)

Simulation of multiple timers in software.

Page 41: Data Link Layer Protocols Flow Control in Data Link Layer.

A Sliding Window Protocol Using Selective Repeat

Continued

Page 42: Data Link Layer Protocols Flow Control in Data Link Layer.

Continued

A Sliding Window Protocol Using Selective Repeat (2)

Page 43: Data Link Layer Protocols Flow Control in Data Link Layer.

A Sliding Window Protocol Using Selective Repeat (3)

Continued

Page 44: Data Link Layer Protocols Flow Control in Data Link Layer.

A Sliding Window Protocol Using Selective Repeat (4)

Page 45: Data Link Layer Protocols Flow Control in Data Link Layer.

Issues in “Selective Repeat”

• 7 frames 0-6 are sent,• Received, ack-ed, and window of the receiver

advanced to 7,0-5• All ack lost• Sender times out and resends frame 0-6• At receiver, 0-5 accepted, buffered(since next frame it

is expecting is 7) as new frames and ack-ed (Ack 6) and 6 discarded and acked as a duplicate

• Sender advances its window to 7,0-5• Sends packets 7,0-5

Page 46: Data Link Layer Protocols Flow Control in Data Link Layer.

• 7 is accepted and passed onto the NL• 0 and others are rejected as duplicate and the

previous buffered frames are passed on to the NL - wrong packets!!!!

• Order in which packets are sent:• P0…p6, p0…p6, p7, p0(new)…p5(new)• Order in which packets are handed over to NL of

the receiver:• P0…p6,p7,p0…p5(duplicate) and rest are

discarded including the new frames

Page 47: Data Link Layer Protocols Flow Control in Data Link Layer.

Solution

• Keep the window size 4

• That is half the range of permitted sequence numbers.

Page 48: Data Link Layer Protocols Flow Control in Data Link Layer.

A Sliding Window Protocol Using Selective Repeat (5)

(a) Initial situation with a window size seven.(b) After seven frames sent and received, but not acknowledged.(c) Initial situation with a window size of four.(d) After four frames sent and received, but not acknowledged.

Page 49: Data Link Layer Protocols Flow Control in Data Link Layer.

Programming Assignments

• Make Groups of two and,• Implement

– Sliding window protocol with CRC on a duplex channel– Go Back N protocol with Hamming Code on a duplex channel

• Implementation of the channel must be clearly defined.• There must be two copies of the same program running

simultaneously, ( For example, on time sharing basis on the same machine, say in two different windows.) if required some synchronization may be added between the two processes. Alternatively, threads could be used.

• Will tell you more about the points on which your programs will be evaluated. Few are:– Acks incorporated or not, piggybacked or not, channel is truly duplex or

not etc

Page 50: Data Link Layer Protocols Flow Control in Data Link Layer.

I Acknowledge

Help from the following site

http://www.cs.vu.nl/~ast/

In preparing this lecture.