Data Link Layer Data link layer The communication

  • Slides: 25
Download presentation
Data Link Layer

Data Link Layer

Data link layer • The communication between two machines that can directly communicate with

Data link layer • The communication 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 constraints – Errors – Computers have different capabilities – Delay is not zero

Data Link Layer Framing

Data Link Layer Framing

Data link layer framing • What the data link layer does is to encapsulate

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.

Framing • How does the receiver know where is the start and where is

Framing • How does the receiver know where is the start and where is the end of a frame? • Counter. Tell the receiver how many bytes there are in this frame. Problems? • The counter part could be corrupted and you are done.

Flag Bytes • Add special bytes to the beginning and the end of the

Flag Bytes • Add special bytes to the beginning and the end of the frame. • What if the data contains the flag bytes? • Add ESC byte to each flag or ESC in the data. Stuffing. • Any time you see an ESC, the next byte is either ESC or FLAG naturally occurred in the data. Or, a FLAG is a real FLAG if not proceeded by ESC.

Using Bits • More flexibility gained by sending bits. Using 01111110 as the flag

Using Bits • More flexibility gained by sending bits. Using 01111110 as the flag bits. • If the data contains “ 011111”, add a 0 after the fifth 1. When the receiver sees in the data part “ 0111110, ” it removes the last 0. • What if the original data contains “ 0111111”? – It will be stuffed as “ 01111101”, and won’t be regarded as the flag. The receiver will destuff it back into “ 0111111. ” • What if the original data contains “ 0111110”? – It will be stuffed as “ 01111100”. The receiver will destuff it back into “ 0111110. ”

Data Link Layer Protocols

Data Link Layer Protocols

Data link layer protocols • Assume that the physical layer, the data link layer,

Data link layer protocols • Assume that the physical layer, the data link layer, and the network layer are three processes and communicate 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).

Protocol 1. • Your protocol really depends on the world you live in. •

Protocol 1. • Your protocol really depends on the world you live in. • If (1) the link never screws up your bits, and (2) the receiver’s network layer process reads the bits infinitely fast, what should be your protocol?

Protocol 1 • Sender. 1. Grab data from the network layer. 2. Send to

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

Protocol 2 • Now remove assumption (2). The receiver’s network layer process is not

Protocol 2 • Now remove assumption (2). The receiver’s network layer process is not infinitely fast. • How to design the protocol? – Note that the receiver may not be able to process a frame if it is still working on a frame received earlier.

Protocol 2 • The receiver must provide some kind of acknowledgements. If the receiver

Protocol 2 • The receiver must provide some kind of acknowledgements. If the receiver never tells the sender anything, the sender has no way of knowing whether this speed is too high or too low. • The simplest form of ack is the receiver sends back an ack every time he receives a frame. • The sender waits for this ack to start sending the next frame. • Called “stop and wait. ”

Protocol 2 • Sender. 1. Grab data from the network layer and send to

Protocol 2 • Sender. 1. Grab data from the network layer and send to physical layer. 2. Wait (blocked here) for ack. 3. After getting ACK, goto 1. • Receiver 1. Wait (blocked here) for data. 2. After getting the data, give it to the network layer and send ack. Goto 1.

Protocol 3 • Now, let’s remove assumption (1). There is now noise in the

Protocol 3 • Now, let’s remove assumption (1). There is now noise in the channel and frames could be corrupted. Both the data frame and the ack frame. • How to design your protocol? What are the considerations? • When a frame is lost, how can the sender know?

Protocol 3 • So we can add a timer. If the sender does not

Protocol 3 • So we can add a timer. If the sender does not receive the ack before the timer expires, he knows something is wrong and resend this frame. • How long should the timer be set? • Problems?

Protocol 3 • A sent B frame F. • B received the frame. Sent

Protocol 3 • A sent B frame F. • B received the frame. Sent ack to A. Ack got lost. • A time out. Resend F. • B received F. AGAIN!

Sequence Number • Every frame has a sequence number. • Sender says I am

Sequence Number • Every frame has a sequence number. • Sender says I am sending the frame with sequence number m. • Receiver acks saying that I have successfully received the frame with sequence number m, please send me frame with sequence number m+1. • This will solve the duplication problem.

Protocol 3 • Sender (maintains “m” as the sequence number up to which has

Protocol 3 • Sender (maintains “m” as the sequence number up to which has been ACKed) 1. 2. 3. • • Grab data from the network layer. Send to physical layer with the current sequence number , i. e. , m+1 and start timer. Wait for ACK. If got an ACKm+1, m: =m+1, repeat 1. Else, timeout, repeat 2. • Receiver (maintains “m” as the sequence number up to which has been received) 1. 2. 3. Wait for data. Get data from the physical layer. If it is with the expected sequence number, i. e. , m+1, give it to the network layer, m: =m+1. send ACKm. Goto 1.

Protocol 3 • Question 1. After sends frame m, will he receive ACK lower

Protocol 3 • Question 1. After sends frame m, will he receive ACK lower than m-1? Will it receive ACK higher than m?

Protocol 3 • Answer. No. Because when sender sent frame m, he must have

Protocol 3 • Answer. No. Because when sender sent frame m, he must have received ACK from the receiver of m-1. Receiver keeps the sequence number and won’t decrease it. And it will not receive ACK higher than m, because m+1 has not been sent yet.

Protocol 3 • Question 2. After sending out an ACKm, what are the possible

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

Protocol 3 • Answer. The only possible frames he could receive is m or

Protocol 3 • Answer. The only possible frames he could receive is m or m+1. • In what case he receives m? (ACKm gets lost) In what case he receives m+1 (when everything goes fine)? Why can’t he receive m -1 (Because when sender sends m, he knows that m-1 is received correctly. )? Why can’t he receive m+2 (because sender won’t send m+2 before the receiver sends ACKm+1)?

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

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

Protocol 3 • Answer. 1 bit. At any time, there are only two possible

Protocol 3 • Answer. 1 bit. At any time, there are only two possible frames both for the sender and the receiver.