Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Link Layer.

Similar presentations


Presentation on theme: "Data Link Layer."— Presentation transcript:

1 Data Link Layer

2 Data link layer Between two machines that can directly communicate with each other. Basic property: if bit A is sent before bit B, bit A will be received earlier than bit B Fundamental issues to be addressed Errors Devices may have different capabilities such as speed Delay is not zero Data link layer functionality Framing and synchronization Error detection, correction Error control (error detection and recovery) Flow control (dealing with speed mismatch between communicating parties)

3 Data link layer framing
What the data link layer does is to encapsulate the packets from the network layer into frames and send out these frames. So we will discuss how to deliver these frames.

4 Framing: breaking bit stream into frames
Why framing? Give the data transmitted a meaning (e.g. find where the destination address is) Blocks of data (versus a stream of bits) allow for error detection and correction How does the receiver know where is the start and where is the end of a frame? At the beginning of a frame there is always a preamble which contains special signal to alert the physical layer about the beginning of a frame. The length of the frame can be indicated in a special field in the header. This is typically implemented by a network adaptor (hardware). The adaptor fetches/deposits frames out of/into the host/switch memory.

5 Framing Schemes Character/Byte-oriented
Character/Byte count: size data size data size data …… Problem: what if the size field is corrupted? Starting and ending characters STX (start of text) and ETX (end of text) Problem: what if data contains these characters? Character stuffing Escape them by preceding them with DLE character What if data contains DLE character?

6 Framing Schemes (cont’d)
Bit-oriented Each frame begins and ends with a special bit-sequence Flag or preamble Bit-stuffing Sender: any time 5 consecutive 1’s in the body Insert a 0 Receiver: should 5 consecutive 1’s arrive If next bit is 0: remove If next bits are 10: end-of-frame marker If next bits are 11: error

7 Data link layer protocols
Assume that the physical layer, the data link layer, and the network layer are three processes communicating with each other. Assume that the sender always has enough data to send. Assume that the machines don’t crash. Assume that the data flows only one direction (simplex). Trying to build a reliable connection oriented service. Support flow control and error control

8 Protocol 1. The protocol really depends on the world we live in.
Suppose the link never corrupts bits and receiver is sufficiently fast to receive everything – Protocol 1 (do nothing protocol).

9 Protocol 1 Sender. Receiver Grab data from the network layer.
Send to physical layer. Goto 1. Receiver Get data from the physical layer Give it to the network layer. Goto 1.

10 Protocol 2 What if the receiver may or may not be fast enough? Protocol 1 will lose data. Sender needs to slow down? Add delay? What else you can do to make sure that sender never over-run the buffer at the receiving end?

11 Protocol 2 The receiver can provide some kind of acknowledgements to tell the sender how much buffer it still has left and sender only send the amount that the receiver can handle. Similarly, in order for the sender to know if the receiver has received a packet, it must get some indication from the receiver. If the receiver never tells the sender anything, the sender has no way of knowing whether a frame is received correctly or not. The simplest form of ack is the receiver sends back an ack every time it receives a frame (when the buffer is processed and empty). The sender waits for this ack to start sending the next frame. Called “stop and wait.”

12 Protocol 2 (Stop and Wait): support flow control.
Sender. Grab data from the network layer and send to physical layer. Wait (blocked here) for ack. After getting ACK, goto 1. Receiver Wait (blocked here) for data from the physical layer. After getting the data, give data to the network layer and send ack. Goto 1.

13 Data Lost What if a data or ack frame can be lost?
If the data frame is lost, the sender will be blocked forever, because the receiver will never get the frame and send the ACK. Protocol 2 will stuck – “stop and wait” handles flow control, but not error control. The sender needs a way to get out of the blocking receive operation for the ACK packet, and resend the packet if no ack. – add a timer.

14 Timer So we can add a timer. If the sender does not receive the ACK before the timer expires, it knows something is wrong and resends this frame. Timer: generates an interrupt when timer expires – any real example of timer that any used? alarm(), select().

15 Timeout How long should the timer be set?
Slightly longer than the RTT (round trip time).

16 Protocol 3 (Stop and Wait with timer)
Sender. Grab data from the network layer and send to physical layer. Start timer and wait for ACK If receiving ACK, goto 1. Else if timer expires, resend the packet and go to 2 Receiver Wait (blocked here) for data from the physical layer. After getting the data, give data to the network layer and send ack. Goto 1. Does it provide a reliable connection oriented service?

17 ACK Lost A sends B frame F.
B receives the frame, sends ACK to A. ACK is lost. A times out. Resends F. B receives F. AGAIN and B does not know it is a duplicate. Not reliable connection oriented service!! How to deal with this? Add an identifier to each packet so that the receiver knows whether it receives a duplicate!

18 Sequence Number Every frame has a sequence number that identifies a frame This is a field in the frame header: header contains any necessary information for the protocol to operate. Sender says I am sending the frame with sequence number m. Receiver acks with sequence number m means: I have successfully received the frame with sequence number m-1, please send me frame with sequence number m. This will solve the duplication problem.

19 Stop-n-Wait + timeout + sequence number
Sender: maintain sequence number m (frames before frame m acked, the receiver is expecting frame m) while (1) { Send to physical layer frame m (sequence number =m), start a timer and wait If got ACKm+1, m=m+1. goto 1 else if got ACK of another frame restart a timer and wait If timeout, goto 1. } Receiver. Assume the expected sequence number is m. while (1){ Wait to get data from the physical layer (blocked here until data received). If the data has frame sequence m, give it to the network layer, m=m+1 Send ACKm. 9/19/2018 3:03:16 AM

20 Positive Acknowledgement with Retransmission (PAR) protocol
Stop-n-wait+timer+sequence number What if when the receiver gets Fm, but takes a while to send the ACK.

21 PAR Protocol – Exercise
What if when the receiver gets Fm, but takes a while to send the ACK. The sender timeouts, and resends Fm. The receiver will get Fm twice, but will send ACKm+1 both times. The receiver will drop the second Fm since it is expecting F m+1 The sender will react to the first ACKm+1 by sending F m+1, and the sender will react to the second ACKm+1 by restarting a new timer.

22 PAR Protocol Question 1. After sender sends frame m, will it receive ACK m-1 or lower? Will it receive ACK m+2 or higher?

23 PAR Protocol Question 1. After sender sends frame m, will it receive ACKm-1? ACKm+2? Answer. Both No. Not ACKm-1: When sender sends Fm, it must have received ACKm. If the receiver has sent ACKm, it will never will never send ACKm-1, because it never decrease the sequence number. Not ACKm+2: because Fm+1 has not been sent yet.

24 PAR Protocol So, only two cases:
Sender may receive ACKm+1 if everything is fine. Sender may receive ACKm, for example, if Fm is lost.

25 PAR Protocol Question 2. After sending out an ACKm, what are the possible frames the receiver can receive?

26 PAR Protocol Answer. The only possible frames it could receive is F m-1 or F m. Why can’t it receive Fm-2? (Because when sender sends Fm-1, it knows that Fm-2 is received correctly.) Why can’t it receive Fm+1? (because sender won’t send Fm+1 before the receiver sends ACKm+1)

27 PAR Protocol In what case it receives Fm-1? (ACKm gets lost)
In what case it receives Fm? (when everything goes fine)

28 PAR Protocol Question 3. How many bits should the sequence number have?

29 PAR Protocol Answer. 1 bit. At any time, there are only two possible frames both for the sender and the receiver – one expected, one not expected.

30 Go-Back-N

31 Got a working protocol with PAR
PAR will work without causing errors. So the next step is the optimization. The problem? F1 ACK1 F2

32 Optimization Consider an example of
500ms delay. 50kbps. Each frame is 1000 bits. 9/19/2018 3:03:16 AM

33 Large link delays 500ms delay. 50kbps. Each frame is 1000 bits.
What is the link efficiency? Defined as the percentage of time the link is utilized for sending data. Solution: Transmission time: The time to send 1000 bits is 1000/50,000=20ms. At time 520 ms, the receiver gets the entire frame, and send ACK back. Assume ACK is small. At time 1020ms, the sender gets the ACK, and sends the next frame. And this repeats. The efficiency is 20/1020.

34 Solution So the idea is to keep on sending before the first ACK comes back. In the figure, send 6 frames before the ACK is back. After the first ACK comes back, will receive one ACK in every frame transmission time (assuming frame size is fixed and no error). F1 F2 F3 ACK1 F4 ACK2 F5 ACK3 F6 F7 9/19/2018 3:03:16 AM

35 Sender window For reliability, the sender must keep the frames in its buffer that it sent, but not acked for potential retransmission. Once the sender receives the ACK for a frame, it can remove the frame from its buffer. Sender window: all frames that has been sent, but not ACKed. The sender has a window from m to m+n-1 means that the sender has received ACK from the receiver for frames up to m-1 the sender is allowed to send m, m+1, …, m+n-1. These packets can be outstanding without ACK. Sender has to maintain the sender window (buffering all outstanding frames), maintain timeout for all outstanding frames. For link efficiency purpose, the size of the sender window must be determined by the bandwidth and link delay 9/19/2018 3:03:16 AM

36 Receiver Window Assuming the receiver wants to deliver frames to the upper layer in order. If receiver receives a frame ahead of time, the frame cannot be delivered to the upper layer. If the receiver can store multiple frames, it can temporary put the out of order frame in the buffer (or drop it if no space). Receiver has a window from m to m+n-1 means that the receiver has received every frame up to frame m-1, and is missing frame m. Receiver can buffer frames from m+1 to m+n-1 in its buffer.

37 100% Efficiency Let’s first consider the receiver’s window size is only 1. Given link speed and link delay, how large should the window be to achieve 100% efficiency? Basically, we want to be able to keep on sending till the last frame in the window right before the first ACK is back. In the earlier example: 500ms one way prop latency, 50kbps, 1000-bit frame. What should be the sender window size? 9/19/2018 3:03:16 AM

38 Go-Back-N Sender. Assume the current window is m to m+n-1. Assume the current sending sequence number is S. while (1) { If S is within the window: send to physical layer a frame sequence number S, start timer for this frame, increment S. If got ACKw: if w-1 is outside the window, don’t do anything if w-1 is inside the window, consider all frames in the window with sequence number no more than w-1 acked, move the winder lower bound to w. If timeout for frame m: S=m. (frame m will always be the first to timeout) } 9/19/2018 3:03:16 AM

39 Go-Back-N Receiver. Assume the expected sequence number is m.
while (1){ Wait to get data from the physical layer (blocked here until data received). If the data has frame sequence m, give it to the network layer, m=m+1 Send ACKm. } 9/19/2018 3:03:16 AM

40 Go-Back-N Two new things. Cumulative ACK
Will try to resend every frame after the timeout frame (therefore called Go- Back-N). 9/19/2018 3:03:16 AM

41 Go-Back-N Works fine is error is rare. Achieves full capacity.
Else wastes bandwidth. 9/19/2018 3:03:16 AM

42 Sequence Number If the sequence number field is large enough, just use frame ID as sequence number. Else, how many bits do we need? 9/19/2018 3:03:16 AM

43 Sequence number Using the sequence number is to make sure that the receiver can be sure that a received frame is not a duplicate of some other frames. Using finite number of bits means that some frames will have the same sequence number. So, should make sure that the receiver is sure that when a frame with seq#m is received, the sender has got ACK for all previous frames with the same seq#, so the sender cannot be sending an old frame. 9/19/2018 3:03:16 AM

44 Sequence Number Say the sequence number field is 2 bits.
Will this be true if the window size is 4? 9/19/2018 3:03:16 AM

45 Sequence Number Say the sequence number field is 2 bits.
Will this be true if the window size is 4? No, because the sender may send frame 0,1,2,3. Then the receiver sends ACK1,2,3,0. If one of the ACK got through, the sender will send frame 4 with seq#0. If none of the ACK got through, the sender will send frame 0 with seq#0. 9/19/2018 3:03:16 AM

46 Sequence number Solution? Use window size less than 4. Say, 3.
Now, if the receiver gets frame 0,1,2, it sends ACK1,2,3. Then, if it receives a frame with seq#0 again, will it be able to tell whether it is a new frame or a retransmission? 9/19/2018 3:03:16 AM

47 Sequence number Solution? Use window size less than 4. Say, 3.
Now, if the receiver gets frame 0,1,2, it sends ACK1,2,3. Then, if it receives a frame with seq#0 again, will it be able to tell whether it is a new frame or a retransmission? Yes, because The receiver will accept frame with seq#3 first The receiver knows that if the sender sends seq#3, the sender must have got ack for frame 0. The receiver knows that the sender cannot be sending frame 0, so it must be frame 4. 9/19/2018 3:03:16 AM

48 Extending Receiver Window
Further optimization. Receiver: has a window greater than 1. Don’t discard frames simply because some earlier frames was damaged. Sender: if a frame times out, only retransmit that frame. 9/19/2018 3:03:16 AM

49 Extending Receiver Window
Sender. Assume the current window is m to m+n-1. while (1) { If current window not full yet: read data for a frame in the window with smallest sequence number that has not been sent yet, send it, start timer for this frame. If got ACKw: if w-1 is outside the window, don’t do anything if w-1 is inside the window, consider all frames in the window with sequence number no more than w-1 acked, and let m=w. If timeout for frame w in the window: resend frame w. } 9/19/2018 3:03:16 AM

50 Extending Receiver Window
Receiver. Assume the current window is m to m+n-1. while (1) { Wait (blocked here) and get frame from the physical layer. If the frame is within the receiver window and hasn’t been received before, fill in the slot, forward the beginning of the receiver window if necessary, and deliver to the network layer all frames between the beginning of the old receiver window and the new receiver window – 1, inclusive. Send ACKm } 9/19/2018 3:03:16 AM

51 The Timer Each packet in the sender’s window should have a timer.
If the window contains F0,F1,F2,F3. Could it happen that the when the timer for F0 expires, the timer for F1 has not expired yet? Yes, there might be a pause between F0 and F1 Could it happen that the timer for F1 expires but the timer for F0 has not? Yes, if F0 has been retransmitted before. 9/19/2018 3:03:16 AM

52 Sequence Number If the sequence number field is 3 bits, how large should the sender/receiver window be? Should the receiver have a different window size than the sender? No. larger --- makes no sense, the sender is not going to send that many outstanding frames smaller --- not efficient, because the receiver will discard such packets. But both will work correctly. Window size should be 23/2=4. 9/19/2018 3:03:16 AM

53 Sequence Number Still, should make sure that the receiver is sure that when a frame with seq#m is received, the sender has got ACK for all previous frames with the same seq#, so the sender cannot be sending an old frame. 9/19/2018 3:03:16 AM

54 Sequence Number -- A proof
Let the sequence number be log2N bits. Let the window size be W, where W<= N/2. Suppose the receiver gets a frame with sequence number m. The receiver thinks it is for frame x. Could the receiver actually received frame x-N (with the same seq#)? No. Because assuming everything is all right so far, When x is in the receiver’s window, the starting of the window is no less than x- W+1. So the receiver has got frame x-W. So the sender has sent x-W. The sender will send x-W only if the sender has got ACK for frames up to x-2W. If W<= N/2, the sender must have got ACK for x-N. 9/19/2018 3:03:16 AM

55 Piggybacking Considered only one direction. Bidirection. Piggybacking
Combining ACK with data When no data? Wait some time and ACK anyway. 9/19/2018 3:03:16 AM

56 An Exam Problem Consider a link running the Go-Back-N protocol. Suppose the transmission time and propagation delay are both 1ms, the window size is 3, and the timeout is 3ms (start to count after the last bit of a frame is sent). Suppose the sender starts to send at time 0 and no data frame is ever lost, and all ACKs are received except the ACKs the receiver sends at time 6ms and 7 ms. Depict the activities in the timeline for both the sender and receiver side till 14ms.


Download ppt "Data Link Layer."

Similar presentations


Ads by Google