CPSC441: Data Link Layer
CPSC441: Data Link Layer
Jan 5, 1998
CMPN 369
Page 1
OSI
Application Presentation Session Transport Network Datalink Physical
Asynchronous
Synchronous
Presentation
Session Transport Network Data Link Physical
Framing
Error control
Flow control
Transmission/reception of frames
Framing
Group the physical layer bit stream into units called frames. Note that frames are nothing more than ``packets'' or ``messages''. By convention, we'll use the term ``frames'' when discussing DLL packets.
Flow Control Prevent a fast sender from overwhelming a slower receiver. For example, a supercomputer can easily generate data faster than a PC can consume it.
Error Control
Sender checksums the frame and sends checksum together with data. The checksum allows the receiver to determine when a frame has been damaged in transit.
Error Control Receiver recomputes the checksum and compares it with the received value. If they differ, an error has occurred and the frame is discarded.
Types of Services
Framing:
Translates the physical layer's raw bit stream into discrete units called frames
RECEIVER
Frame #2
SENDER
Frame #n
Frame #1
How can the receiver detect frame boundaries? That is, how can the receiver recognize the start and end of a frame?
Four methods:
1. Byte count (Decnet) 2. Byte stuffing (SDLC) 3. Bit stuffing (HDLC) 4. Generic Framing Procedure 5. Manchester Encoding(802.5)
Framing Length Count Make the first field in the frame's header be the length of the frame. That way the receiver knows how big the current frame is and can determine where the next frame ends.
Framing Length Count: Disadvantage Receiver loses synchronization when bits become garbled. If the bits in the count become corrupted during transmission, the receiver will think that the frame contains fewer (or more) bits than it actually does. Although checksum will detect the incorrect frames, the receiver will have difficulty resynchronizing to the start of a new frame. This technique is not used anymore, since better techniques are available.
Use reserved bit patterns to indicate the start and end of a frame.
For instance, use the 4-bit sequence of 0111 to delimit consecutive frames. A frame consists of everything between two delimiters. 0111 frame 0111
Problem: What happens if the reserved delimiter happens to appear in the frame itself? If we don't remove it from the data, the receiver will think that the incoming frame is actually two smaller frames!
Use reserved bit patterns to indicate the start and end of a frame.
Solution: Use bit stuffing. Within the frame, after every occurrence of two consecutive 1's insert 0. E.g., append a zero bit after each pair of 1's in the data. This prevents 3 consecutive 1's from ever appearing in the frame.
Likewise, the receiver converts two consecutive 1's followed by a 0 into two 1's, but recognizes the 0111 sequence as the end of the frame.
Bit stuffing (a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in receivers memory after destuffing.
cHEX and tHEX fields provide CRC based error checking for the preceding fields
In Manchester encoding, for instance, 1-bits are represented by a high-low sequence, and 0-bits by low-high sequences. The start/end of a frame could be represented by the signal low-low or high-high. The advantage of Manchester encoding is that no extra bandwidth is required as in bit-stuffing. The IEEE 802.4 standard uses this approach.
Manchester Encoding
1 is represented by negative going edge. 0 is represented by positive going edge Require twice the bandwidth
Error Control
SENDER
Frame #n Frame #2 Frame #1
RECEIVER
When data is sent as a sequence of frames, two types of error can occur:
Lost frame: the frame fails to arrive at the receiver. This may be due to a noise burst destroying the frame beyond recognition Damaged frame: A recognizable frame arrives at the receiver but some bits are in error
Error Control
Error control is concerned with insuring that all frames are eventually delivered (possibly in order) to a destination. How? Three items are required:
(1) Acknowledgements
Typically, reliable delivery is achieved using the ``acknowledgments with retransmission'' paradigm, whereby the receiver returns a special acknowledgment (ACK) frame to the sender indicating the correct receipt of a frame. In some systems, the receiver also returns a negative acknowledgment (NACK) for incorrectly-received frames. This is nothing more than a hint to the sender so that it can retransmit a frame right away without waiting for a timer to expire.
Error Control
Error control is concerned with insuring that all frames are eventually delivered (possibly in order) to a destination. How? Three items are required:
(2) Timers
One problem that simple ACK/NACK schemes fail to address is recovering from a frame that is lost, and as a result, fails to solicit an ACK or NACK. What happens if an ACK or NACK becomes lost? Retransmission timers are used to resend frames that don't produce an ACK. When sending a frame, schedule a timer to expire at some time after the ACK should have been returned. If the timer goes off, retransmit the frame.
Error Control
Error control is concerned with insuring that all frames are eventually delivered (possibly in order) to a destination. How? Three items are required:
Retransmissions introduce the possibility of duplicate frames. To suppress duplicates, add sequence numbers to each frame, so that a receiver can distinguish between new frames and old copies.
Data Errors
When data is transmitted over a cable or a channel, there is always a chance that some of the bits will be changed (corrupted) due to noise, signal distortion or attenuation. If errors do occur, then some of the transmitted bits will either change from 0 to 1 or from 1 to 0.
Random errors change bits unpredictably. Each bit transmitted has a probability of being changed. These errors are often caused by thermal noise.
Burst errors change a number of bits in succession. They are often caused by faults in
Parity Testing
Parity Testing
The receiving device can work out if a bit has been corrupted in a character by counting the number of 1s in the character and parity bit.
If even parity is being used but there are an odd number of 1s, then an error must have occurred. Similarly, if odd parity is being used but there are an even number of 1s, then an error must have occurred.
One drawback with parity testing is that if two errors occur in the same character they will not be detected.
This is because if there were an even number of 1s originally, if two bits are changed then there will still be an even number of 1s.
Now if an error occurs, we will know which character and which column it has occurred in.
Checksum Testing
Another way of checking for errors to to use a checksum. This is a number calculated from the data and sent along with the data. If any errors occur during transmission then checksum for the received data will differ from the transmitted checksum. A simple checksum can be calculated by adding all the data together.
For example, if the data is 121, 17, 29 and 47 then the checksum is 214. We would transmit 121, 17, 29, 47, 214. A checksum is usually restricted to a certain number of bits (typically 16). If the checksum is longer than this then only the lower 16 bits will be transmitted.
A Cyclic Redundancy Code (CRC) is a more sophisticated type of checksum. If a CRC is used, it is extremely unlikely that any errors will go undetected. Although the technique may sound a little complicated, in practice calculating a CRC is easy and can be implemented in hardware. Essentially the data is regarded as being one very long binary number. Place holder digits are added onto the end and it is divided by a generator polynomial using modulo 2 division. The remainder at the end of this division is the CRC.
Rather than just detecting an error, sometimes it is useful to be able to correct an error as well. CDs use error correcting codes to ensure high quality sound reproduction even if the CD is slightly damaged. Deep space probes use error correcting codes because it would take too long to retransmit data. We have already seen that we can correct a single error in a block parity check. There are other techniques that can correct more errors.
Error-Detecting Codes
Flow Control
SENDER
Frame #n Frame #2 Frame #1
RECEIVER
Buffer
A receiver reserves some buffer space for storing data from a sender, while the data is being processed If the sender sends data faster than the receiver can process it, then buffer over flow will occur Flow control is a technique for preventing the sender from overwhelming the receiver with data Flow control protocols enable the receiver to inform the sender when it is able to receive data
t prop
Propagation delay:
defined as the delay between transmission and receipt of packets between hosts can be used to estimate timeout period
t frame
Frame transmission time
TD 2t prop t frame
t frame TD
If we define a:
then
1 U 1 2a
Example #1
A channel has a bit rate of 4 Kbps and a propagation delay of 20 ms. For what range of frame sizes does the stopand wait protocol give an efficiency of 50 %?
propagation delay of 20 ms. For what range of frame sizes does the stopand wait protocol give an efficiency of 50 %?
R 4 Kbps t prop 20 ms L ?
U
t frame
frame
2t prop
0.5
t frame
frame
2t prop
t frame 2t prop 2 20 ms 40 ms
Example #2
There are 200 computers in a lab They are attached to a network with R = 10 Mbps of length d = 1500 m. The transmitted packets are L = 800 bits long The propagation speed is V = 2 108 m/sec
Example #2
Solution:
Sequence numbers usually occupy a field with a limited number of bits in the frame format.
We do not want to have sequence numbers that are too large because that would waste valuable bandwidth. Because sequence numbers occupy a whole number of bits, the range of sequence numbers is usually 0 to 2k-1 where k is the number of bits used. For example, we could have a 1-bit sequence number. This will be enough for a sliding window protocol with window size 1.
5 4 3
5 4 3
5 4 3
5 4 3
Sending Frame
7 6 0 1 6 7 0 1 6 7
Sending ACK
0 1 6 7 0 1
5
4 3
5
4 3
5 4 3
5 4 3
Getting Frame 0
Duplex Communication
The protocols we have seen so far just send data in one direction. Of course, data will usually flow in both directions.
Data Host B
Data
If
frames are travelling in both directions anyway, it makes sense to piggyback acknowledgements on these frames. This saves the overhead involved in sending a separate frame just to carry an acknowledgement. Of course, if no frames are due to be sent back, we will have no choice but to send back a separate acknowledgement frame.
The
data rate is 50-kbps. link na The round-trip delay is 500msec Down (thats half a second). Link If we used a 1-bit sliding Ground window protocol to send Station 1000-bit frames, the receiver will receive the whole frame 270msec later. The acknowledgement will take a further 250msec to get back. Out of 520msec, data is only being sent for 20msec. Only 20/520 = 4% of the links capacity is being utilised.
Pipelining
Rather than wasting so much channel capacity, a protocol can be designed to send enough frames to keep the link working at full capacity.
Rather
than just allowing one outstanding frame (like the one-bit sliding window protocol does) we can allow up to 26 outstanding frames (enough to fill the 520msec round-trip delay period). The sliding window of the sender need only be enlarged to 26. To accommodate this, a 5-bit (0-31) sequence number would be most suitable. With a sliding window size of 26, up to 26 frames and acknowledgements can be in transit at any time.
The
real question is: What happens when a frame is damaged during transit?
Go Back n
One approach is to discard the damage frame and all the frames that follow it.
Eventually
the sender will realise it has not received an acknowledgement for the damage frame within the timeout period. The sender will then retransmit the damage frame and all the frames that follow it.
Timeout interval
0 1 2 3 4 5 2 3 4 5 6 7
Ack 0
Ack 1
Ack 2
Ack 3
Ack 4
time
The
above time sequence diagram shows what happens when an erroneous frame (E) is received. All following frames are discarded (D) until the new copy of the erroneous frame is received.
Go Back n
The main advantage of go back n is that the receiver only needs to maintain enough buffer space for one frame at a time.
Packets
must be passed up to the Network Layer in the order in which they were sent by the Network Layer in the source host. Only one packet needs to be stored at a time since the frames will always arrive in the correct order.
To implement the go back n, the sliding window of the receiver is set to 1 (i.e. different from the sliding window of the sender).
With
a sliding window size of 1, the receiver will only accept the frame with the next expected frame sequence number. When a frame is damaged, the next expected frame sequence number remains the same.
Selective Repeat
Go back n can waste a lot of link capacity by re-sending frames that arrived perfectly the first time.
If
a link is particularly noisy, this waste can significantly reduce the links throughput.
With selective repeat, only those frames that are damaged are re-sent. Undamaged frames are stored until they can be passed (in the correct order) to the Network Layer.
The
receiver must have enough buffer space available to potentially store all the outstanding frames from the receiver. Much less of the links capacity is wasted since only the damaged frames are retransmitted and the rest of the time the link can carry useful data.
Selective Repeat
Frames
may arrive at the destination out of order. This means that the Data Link Layer is responsible for ordering them before sending the packets they contain to the Network Layer.
Timeout interval
0 1 2 3 4 5 2 6 7 8 9 10
Ack 0
Ack 1
Ack 1
Ack 1
Ack 1
time
The
selective repeat protocol can be implemented by setting the receiver sliding window size to more than 1 (usually it is set to the same size as the senders sliding window).