Data Link Layer RAHUL DEVA
The Data Link Layer Framing Error Control Flow Control Error Correction Error Detection Flow Control Retransmission with Sliding Window Protocols Protocol Specification and Verification Example Data Link Protocols
Data Link Layer Services Unacknowledged connectionless service Voice Acknowledged connectionless service wireless Acknowledged connection-oriented service no out-of-order
Framing To break the bit stream up into discrete frames and compute the checksum for each frame. When a frame arrives at the destination, the checksum is recomputed and validated. One way to achieve this framing is to insert time gaps between frames. However, networks rarely make any guarantees about timing.
Error Control Three types of frames at a receiver’s end Damaged frame: Negative acknowledgment / retransmission Lost frame: Time-out mechanism Valid frame: Sequence numbering / discarding for valid but duplicate frames
Flow Control A technique for assuring that a transmitting station does not overwhelm a receiving station with data
Data Framing Character count Starting and ending characters with character stuffing Starting and ending flags with bit stuffing Physical layer coding violations
Character Count 5 1 2 3 4 5 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3 character count frame 1 5 characters frame 2 frame 3 8 characters frame 4 5 1 2 3 4 7 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3 frame 2 (wrong) frame 1 5 characters one-bit error Now a character count Even if the checksum is incorrect so the destination knows that the frame is bad, it still has no way of telling where the next frame starts.
Starting and Ending Characters with Character Stuffing DLE STX user data DLE ETX beginning of frame end of frame DLE(0x10): Data Link Escape STX(0x02): Start of TeXt ETX(0x03): End of TeXt DLE STX A DLE B DLE ETX user data 0x10 DLE stuffed at the sender DLE destuffed at the receiver DLE STX A DLE DLE B DLE ETX
Starting and Ending Flags with Bit Stuffing 01111110 user data 01111110 beginning of frame end of frame flag 011011111111111111110010 011011111011111011111010010 bits stuffed at the sender bits destuffed at the receiver original data
Introduction: Error Detection and Correction It is physically impossible for any data recording or transmission medium to be 100% perfect over its entire expected useful life. Noise is always present If a communications line experiences too much noise, the signal will be lost or corrupted Communication systems should check for transmission errors Once an error is detected, a system may perform some action Some systems perform no error control, but simply let the data in error be discarded
Noise Also known as thermal or Gaussian noise Relatively constant and can be reduced If noise gets too strong, it can completely disrupt the signal
Noise (continued)
The effect of impulse noise on a digital signal One of the most disruptive forms of noise Random spikes of power that can destroy one or more bits of information Difficult to remove from an analog signal because it may be hard to distinguish from the original signal Impulse noise can damage more bits if the bits are closer together (transmitted at a faster rate) The effect of impulse noise on a digital signal
Three Telephone Circuits experiencing crosstalk Unwanted coupling between two different signal paths For example, hearing another conversation while talking on the telephone Relatively constant and can be reduced with proper measures Three Telephone Circuits experiencing crosstalk
A signal bouncing back at the end of a cable and causing echo The reflective feedback of a transmitted signal as the signal moves through a medium Most often occurs on coaxial cable If echo bad enough, it could interfere with original signal Relatively constant, and can be significantly reduced A signal bouncing back at the end of a cable and causing echo
Original digital signal and digital signal with jitter The result of small timing irregularities during the transmission of digital signals Occurs when a digital signal is repeated over and over If serious enough, jitter forces systems to slow down their transmission Steps can be taken to reduce jitter Original digital signal and digital signal with jitter
Delay Distortion Occurs because the velocity of propagation of a signal through a medium varies with the frequency of the signal Can be reduced
Attenuation The continuous loss of a signal’s strength as it travels through a medium
Error Prevention (continued)
Error Detection Despite the best prevention techniques, errors may still happen To detect an error, something extra has to be added to the data/signal This extra is an error detection code Three basic techniques for detecting errors: parity checking, arithmetic checksum, and cyclic redundancy checksum
Parity Checks Simple parity If performing even parity, add a parity bit such that an even number of 1s are maintained If performing odd parity, add a parity bit such that an odd number of 1s are maintained For example, send 1001010 using even parity For example, send 1001011 using even parity
Parity Checks (continued) Simple parity (continued) What happens if the character 10010101 is sent and the first two 0s accidentally become two 1s? Thus, the following character is received: 11110101 Will there be a parity error? Problem: Simple parity only detects odd numbers of bits in error
Parity Checks (continued) Longitudinal parity Adds a parity bit to each character then adds a row of parity bits after a block of characters The row of parity bits is actually a parity bit for each “column” of characters The row of parity bits plus the column parity bits add a great amount of redundancy to a block of characters
Vertical Redundancy Check (VRC) Append a single bit at the end of data block such that the number of ones is even Even Parity (odd parity is similar) 0110011 01100110 0110001 01100011 VRC is also known as Parity Check Performance: Detects all odd-number errors in a data block
Longitudinal Redundancy Check (LRC) Organize data into a table and create a parity for each column 11100111 11011101 00111001 10101001 11100111 11011101 00111001 10101001 10101010 11100111 11011101 00111001 10101001 10101010 Original Data LRC
Longitudinal Redundancy Check and Vertical Redundancy Check 27 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 VRC LRC
Parity Checks (continued) Both simple parity and longitudinal parity do not catch all errors Simple parity only catches odd numbers of bit errors Longitudinal parity is better at catching errors but requires too many check bits added to a block of data We need a better error detection method What about arithmetic checksum?
Modulo 2 Modulo 2 arithmetic works like clock arithmetic. In clock arithmetic, if we add 2 hours to 11:00, we get 1:00. In modulo 2 arithmetic if we add 1 to 1, we get 0. The addition rules couldn’t be simpler: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0
Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic. As with traditional division, we note that the dividend is divisible once by the divisor. We place the divisor under the dividend and perform modulo 2 subtraction.
Error Detection and Correction Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic… Now we bring down the next bit of the dividend. We see that 00101 is not divisible by 1101. So we place a zero in the quotient.
Error Detection and Correction Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic… 1010 is divisible by 1101 in modulo 2. We perform the modulo 2 subtraction.
Error Detection and Correction Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic… We find the quotient is 1011, and the remainder is 0010. This procedure is very useful to us in calculating CRC syndromes. Note: The divisor in this example corresponds to a modulo 2 polynomial: X 3 + X 2 + 1.
Cyclic redundancy checking (CRC) Suppose we want to transmit the information string: 1111101. The receiver and sender decide to use the (arbitrary) polynomial pattern, 1101. The information string is shifted left by one position less than the number of positions in the divisor. The remainder is found through modulo 2 division (at right) and added to the information string: 1111101000 + 111 = 1111101111.
Cyclic redundancy checking (CRC) If no bits are lost or corrupted, dividing the received information string by the agreed upon pattern will give a remainder of zero. We see this is so in the calculation at the right. Real applications use longer polynomials to cover larger information strings. Some of the standard poly-nomials are listed in the text.
Hamming codes The minimum Hamming distance for a code, D(min), determines its error detecting and error correcting capability. For any code word, X, to be interpreted as a different valid code word, Y, at least D(min) single-bit errors must occur in X. Thus, to detect k (or fewer) single-bit errors, the code must have a Hamming distance of D(min) = k + 1.
Flow Control and Error Control A set of procedures that tells the sender how much data can be sent before waiting for acknowledgment Error control Includes both error detection and correction Allows receiver to inform sender of lost or duplicate frames Mostly based on Automatic Repeat Request (ARQ)
Data Link Protocols
Protocols for Noiseless Channel Assuming channel is error free Not realistic… No need for error control
"Simplest" Mechanism Assuming Noiseless channel Unlimited buffer and speed for the receiver
"Simplest" : Pseudo Code Sender Receiver
"Simplest": Flow Diagram
Stop-and-Wait Mechanism Still noiseless channel Receiver has limited buffer Requires flow control Sender sends one frame at a time and wait for an acknowledgment
Stop-and-Wait: Overview
Stop-and-Wait: Pseudo Code Sender side
Stop-and-Wait: Pseudo Code Receiver side
Stop-and-Wait: Flow Diagram
Noisy Channel Realistic Error can and will happen Require error control Mechanisms: Stop-and-Wait ARQ Go-Back-N ARQ Selective Repeat ARQ
Stop-and-Wait ARQ Sender keeps a copy of sent frame until successful delivery is ensured Receiver responds with an ack when it successfully receives a frame Both data and ack frames must be numbered. (For identification purpose, both data frames and ACK frames are numbered alternately 0 and 1.) When sender does not receive an ack within certain time, it assumes frame is lost, then retransmits the same frame.
Stop-and-Wait ARQ
Flow Diagram: Normal Operation Sender Receiver S = 0 R = 0 Frame 0 Deliver ACK 1 R = 1 S = 1 Frame 1 Deliver ACK 0 R = 0 Time Time
Thinking Corner Why data frames need to be numbered?
Flow Diagram: Lost Frame Sender Receiver S = 0 R = 0 Frame 0 Deliver ACK 1 R = 1 S = 1 Frame 1 Timeout Frame 1 Deliver ACK 0 R = 0 Time Time
Frame 0 expected; discard Flow Diagram: Lost ACK Sender Receiver S = 0 R = 0 Frame 0 Deliver ACK 1 R = 1 S = 1 Frame 1 Timeout Deliver ACK 0 R = 0 S = 1 Frame 1 Frame 0 expected; discard ACK 0 R = 0 S = 0 Time Time
Flow Diagram: Delayed ACK Sender Receiver S = 0 R = 0 Frame 0 Timeout Deliver ACK 1 R = 1 Frame 0 Frame 0 expected; discard S = 1 ACK 1 Frame 1 Timeout R = 1 Frame 1 Deliver ACK 0 R = 0 S = 0
Bidirectional Transmission Data are transferred both ways ACK are "piggybacked" with data frames
Improving Link Utilization Previous example demonstrates major disadvantage of Stop-and-Wait ARQ Prefer to send more frames before waiting for ACK Example: Recalculate the link utilization if we allow up to 15 frames to be sent before waiting for an ACK
Go-Back-N ARQ Allows multiple frames to be sent before waiting for ACK These frames must be numbered differently Frame numbers are called Sequence numbers Frames must be received in the correct order If a frame is lost, the lost frame and all of the following frames must be retransmitted
Sequence Numbers Frame header contains m bits for sequence number That allows up to 2m different frame numbers How big should m be?
Sending Window Sending more than one frame at once requires sender to buffer multiple frames Known as "sending window" Any of these frames in the window can be lost
"Sliding" Window Once the first frames in the window is ACKed ACKed frames are removed from the buffer More frames are transmitted Result: The window slides to the right
Receiving Window Receiver expects one frame at a time
Send vs. Receive Windows
Go-Back-N: Window Sizes For m-bit sequence numbers Send window size: at most 2m-1 Up to 2m-1 frames can be sent without ACK Receive window size: 1 Frames must be received in order
Go-Back-N: Normal Operation
Go-Back-N: Lost Frame ACKs are cumulative
Lost ACK: Window Size < 2m
Lost ACK: Window Size = 2m
Selective Repeat ARQ Go-Back-N always discards out-of-order frames Losing one frame may result in retransmission of multiple frames Very inefficient in noisy link Selective Repeat ARQ allows frames to be received out of order Therefore, receive window > 1
Send and Receive Windows Sender and receiver share window space equally For m-bit sequence numbers Send window: up to 2m-1 Receive window: up to 2m-1
Send Window
Receive Window
Negative ACK Used by receiver to indicate missing frame
Selective Repeat: Window Size