Data Link Layer Sliding window Think the frames

  • Slides: 32
Download presentation
Data Link Layer

Data Link Layer

Sliding window • Think the frames the sender has to send as a continuous

Sliding window • Think the frames the sender has to send as a continuous stream. The window contains the current frame being sent and is not acked yet. Every ack (Expc) moves the window forward one frame.

Correctness Part is Done! • So our Protocol 3 will work without causing errors.

Correctness Part is Done! • So our Protocol 3 will work without causing errors. ARQ. (automatic repeat request) • So the next step is the optimization. • Any one sees the problem?

Optimization • Consider an example of – 500 ms delay. 50 kbps. Each frame

Optimization • Consider an example of – 500 ms delay. 50 kbps. Each frame is 1000 bits. 9/15/2020 3: 03: 52 PM

Large link delays • 500 ms delay. 50 kbps. Each frame is 1000 bits.

Large link delays • 500 ms delay. 50 kbps. Each frame is 1000 bits. • What is the link efficiency? • The time to send 1000 bits is 1000/50, 000=20 ms. • At time 520 ms, the receiver gets the entire frame, and send ACK back. Assume ACK is small. • At time 1020 ms, the sender gets the ACK, and sends the next frame.

Solution • So, increase the window size from 1 to n. • Would want

Solution • So, increase the window size from 1 to n. • Would want to have a large window size whenever the bandwidth delay product is large. – If bandwidth is large, sending is fast – If delay is large, even a moderate bandwidth will cause a poor efficiency 9/15/2020 3: 03: 53 PM

Question • Given link speed and link delay, how large should the window be

Question • Given link speed and link delay, how large should the window be to achieve 100% efficiency? 9/15/2020 3: 03: 54 PM

Question • Given link speed and link delay, how large should the window be

Question • 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. 9/15/2020 3: 03: 54 PM

Sender window • The sender has a window from m+1 to m+n means that

Sender window • The sender has a window from m+1 to m+n means that – the sender has received ack from the receiver for frame up to m, – the sender is allowed to send m+1, m+2, …, m+n. These packets can be outstanding without ack. • Sender has to maintain the sender window (buffering all outstanding frames), maintain timeout for all outstanding frames. • The size of the sender window is determined by the bandwidth and link delay 9/15/2020 3: 03: 54 PM

Go-Back-N • Let’s first consider the receiver’s window size is only 1. • This

Go-Back-N • Let’s first consider the receiver’s window size is only 1. • This is called Go-Back-N. 9/15/2020 3: 03: 54 PM

Go-Back-N (Protocol 4) Sender. while (1) { If network layer got data, if current

Go-Back-N (Protocol 4) Sender. while (1) { If network layer got data, if current window not full yet, read data, send to physical layer with the frame ID. Start timer. Increment frame ID by one. If got ACKm, if m is outside the window, don’t do anything. If m is inside the window, consider all frames in the window with frame ID no more than the m acked. Forward window to m+1. If timeout for frame m, start to resend all frames in the window with frame ID no less than m. } Receiver while (1){ Wait to get data from the physical layer (blocked here until data got). After getting data: (1) If the data is with the expected frame ID m, give the frame to the network layer, increment the frame ID by one; (2) Send the ACK with the current frame ID. } • Note: assuming the sequence number is the frame ID. 9/15/2020 3: 03: 54 PM

Go-Back-N • Two new things. – Cumulative ACK – Resend every frame after the

Go-Back-N • Two new things. – Cumulative ACK – Resend every frame after the timeout frame 9/15/2020 3: 03: 54 PM

Go-Back-N 9/15/2020 3: 03: 55 PM

Go-Back-N 9/15/2020 3: 03: 55 PM

Go-Back-N • What if ACK is lost? 9/15/2020 3: 03: 58 PM

Go-Back-N • What if ACK is lost? 9/15/2020 3: 03: 58 PM

Go-Back-N • Works fine is error is rare. Achieves full capacity. • Else wastes

Go-Back-N • Works fine is error is rare. Achieves full capacity. • Else wastes bandwidth. 9/15/2020 3: 03: 58 PM

Sequence Number • If the sequence number field is large enough, just use frame

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/15/2020 3: 03: 58 PM

Sequence number • Using the sequence number is to make sure that the receiver

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/15/2020 3: 03: 58 PM

Sequence Number • Say the sequence number field is 2 bits. • Will this

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 0, 1, 2, 3. Then the receiver sends ACK 0, 1, 2, 3. 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/15/2020 3: 03: 58 PM

Sequence number • Solution? • Use window size less than 4. Say, 3. •

Sequence number • Solution? • Use window size less than 4. Say, 3. • Now, if the receiver gets frame 0, 1, 2, it sends ACK 0, 1, 2. 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. It knows that if the sender sends seq#3, it must have got ack for frame 0. 9/15/2020 3: 03: 58 PM

Protocol 5 – Selective Repeat • Further optimization. – Receiver: has a window greater

Protocol 5 – Selective Repeat • 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/15/2020 3: 03: 58 PM

Protocol 5 – Selective Repeat Sender. while (1) { If network layer got data,

Protocol 5 – Selective Repeat Sender. while (1) { If network layer got data, if current window not full yet, read data, send to physical layer with the frame ID. Start timer. Increment frame ID by one. If got ACKm, if m is outside the window, don’t do anything. If m is inside the window, consider all frames in the window with frame ID no more than the m acked. Forward window to m+1. If timeout for frame m, resend frame m. } Receiver while (1) { Wait (blocked here) and get frame from the physical layer. If it is within the receiver window and hasn’t been received before, fill in the slot, and 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 (m+1= the beginning of the current receiver window). } • Note: assuming the sequence number is the frame ID. 9/15/2020 3: 03: 59 PM

The Timer • Each packet in the sender’s window should have a timer. •

The Timer • Each packet in the sender’s window should have a timer. • If the window contains F 0, F 1, F 2, F 3. Could it happen that the when the timer for F 0 expires, the timer for F 1 has not expired yet? Yes, e. g. , when you paused. • Could it happen that the timer for F 1 expires but the timer for F 0 has not? Yes, if F 0 has been retransmitted before. 9/15/2020 3: 04: 00 PM

Sequence Number • If the sequence number field is 3 bits, how large should

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 --- wrong, because the receiver will discard such packets. • Window size should be 4. 9/15/2020 3: 04: 00 PM

Sequence Number • Still, should make sure that the receiver is sure that when

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. • At the receiver: For seq# 0 to be in my window again, I must have forwarded to frame 5. When I forwarded to frame 5, I must have got frame 4. I got frame 4 because the sender sent frame 4. The sender sent frame 4 only if it got ACK for frame 0. 9/15/2020 3: 04: 01 PM

Sequence Number A proof. • Let the sequence number be log 2 N bits.

Sequence Number A proof. • Let the sequence number be log 2 N bits. Let the window size be W, where W<= N/2. • Suppose the receiver gets a frame with sequence number m. He thinks it is for frame x. Could he actually receive frame x-N (with the same seq#)? • No. Because when x is in the receiver’s window, his window has forwarded to x-W+1, at least. So he has got x-W. The sender has sent x-W. The sender will send x-W only if it has got ACK for x-2 W+1. If W<= N/2, the sender must have got ACK for x-N. 9/15/2020 3: 04 PM

Piggybacking • Considered only one direction. Bidirection. • Piggybacking – Combining ACK with data

Piggybacking • Considered only one direction. Bidirection. • Piggybacking – Combining ACK with data – When no data? • Wait some time and ACK anyway. • Internet. PPP. 9/15/2020 3: 04 PM

Problem 1 • The link delay is 270 ms. Each data frame is 1000

Problem 1 • The link delay is 270 ms. Each data frame is 1000 bits. Data rate is 1 Mbps. What is the link efficiency of the Stop&Wait protocol?

Problem 1 • The link delay is 270 ms. Each data frame is 1000

Problem 1 • The link delay is 270 ms. Each data frame is 1000 bits. Data rate is 1 Mbps. What is the link efficiency of the Stop&Wait protocol? • Answer. – Transmission delay: 1000/1000000 = 1 ms. – The last bit of the frame reaches the receiver at time 271 ms. ACK is received at the sender at 541 ms. In 541 ms, 1 ms is used to send data. Link efficiency is 1/541.

Problem 2 • Still the Stop&Wait protocol. The link length is 200 m. Signal

Problem 2 • Still the Stop&Wait protocol. The link length is 200 m. Signal travels at a speed of 20000 m/s. The file is 1000000 bytes. The server divides the file into frames of 500 bytes. Data rate is 10 Mbps. How long does it need for the server to send the entire file? (Assuming no frame loss. )

Problem 2 • Still the Stop&Wait protocol. The link length is 200 m. Signal

Problem 2 • Still the Stop&Wait protocol. The link length is 200 m. Signal travels at a speed of 20000 m/s. The file is 1000000 bytes. The server divides the file into frames of 500 bytes. Data rate is 10 Mbps. How long does it need for the server to send the entire file? (Assuming no frame loss. ) • Answer. – Transmission delay: 500*8/10000000 = 400 us. – The propagation delay is 200/20000 = 1 us. – The last bit of the frame reaches the receiver at time 401 us. ACK is received at the sender at 402 us. Every 402 us, a data frame can sent, hence the total time is 402*2000 = 804000 us.

Problem 3 • Consider a link with propagation delay of 1 ms and the

Problem 3 • Consider a link with propagation delay of 1 ms and the transmission delay of 1 ms. Assume Stop&Wait is used and assume that every one of four ACKs is lost. Assume the timeout the sender uses is 3 ms, defined as the time to wait AFTER the last bit is sent. What is the link efficiency?

Problem 3 • Consider a link with propagation delay of 1 ms and the

Problem 3 • Consider a link with propagation delay of 1 ms and the transmission delay of 1 ms. Assume Stop&Wait is used and assume that every one of four ACKs is lost. Assume the timeout the sender uses is 3 ms, defined as the time to wait AFTER the last bit is sent. What is the link efficiency? • Answer. The first three frames are transmitted correctly using 3*3=9 ms. At time 9 ms (time starts at 0), the sender started to send the fourth frame. Because the ACK was lost, the sender will timeout and retransmit at 13 ms. This time it will go through. So the efficiency is 3/13, that is, every 13 ms, three frames will go through.