Download presentation
Presentation is loading. Please wait.
1
Data Link Layer
2
Outline Design Issues Error Detection and Correction
Elementary Data Link Protocols Sliding Window Protocols Protocol Verification Example – The Data Link Layer in the Internet
3
Data Link Layer Design Issues
Services Provided to the Network Layer Framing Error Control Flow Control
4
Functions of the Data Link Layer
Provide service interface to the network layer Dealing with transmission errors Regulating data flow Slow receivers not swamped by fast senders
5
How data is moved. The DLL is responsible for taking the packets of information that it receives from the Network Layer and putting them into frames for transmission. Each frame holds the payload plus a header and a trailer (overhead). It is the frames that are transmitted over the physical layer.
6
Functions of the Data Link Layer (2)
Relationship between packets and frames.
7
Services Provided to Network Layer
(a) Virtual communication. (b) Actual communication.
8
Types of services provided to the Network Layer
Unacknowledged Connectionless service Acknowledged Connectionless service Acknowledged Connection-Oriented service
9
Unacknowledged Connectionless service
Losses are taken care of at higher layers Used on reliable medium like coax cables or optical fiber, where the error rate is low. Appropriate for voice, where delay is worse than bad data.
10
Acknowledged Connectionless service
Useful on unreliable medium like wireless. Acknowledgements add delays. Adding ack in the DLL rather than in the NL is just an optimization and not a requirement. Leaving it for the NL is inefficient as a large message (packet) has to be resent in that case in contrast to small frames here. On reliable channels, like fiber, the overhead associated with the ack is not justified.
11
Acknowledged Connection-oriented service
Most reliable, Guaranteed service – Each frame sent is indeed received Each frame is received exactly once Frames are received in order Special care has to be taken to ensure this in connectionless services
12
Services Provided to Network Layer …
Placement of the data link protocol.
13
How are Frames sent? The Physical Layer is only able to put a raw bit stream on the transmission media. We have to be able to break up this bit stream into frames. Putting spaces between the frames won’t work as we can’t guarantee that the spaces will stay. We need to look at other methods of denoting the start and finish of a frame.
14
Framing Methods Character count. Flag bytes with byte stuffing
Starting and ending flags, with bit stuffing Physical layer coding violations
15
Character Count We use a field in the header to specify the number of characters in the frame. This method can cause problems if the count is garbled in transit. The receiver will be able to tell the frame is bad (due to a bad checksum) The receiver will not know where to pick up and the sender will not know how much to resend. This method is rarely used anymore.
16
Character Count Example
17
Flag Bytes (with byte stuffing!)
Frames begin and end with special bytes. Often used are the same start/end flag. If the receiver gets “lost”, it just looks for a pair of flag bytes to denote the end of one frame and the start of the next. What happens if the “flag” byte is accidentally transmitted in the message?
18
We use Byte Stuffing! “Byte stuffing” is the process of putting an “ESC”ape character in front of any accidentally occurring FLAG in a message. What happens if an ESC accidentally occurs in a message? We ESC that too! This is sometimes referred to as character stuffing.
19
Example of Byte Stuffing
20
Frames that need to be send in a bit stream:
Flag The sender sends the following bit stream: Flag Esc The receiver will ignore this flag. Frames that need to be send in a bit stream: Flag Esc The sender sends the following bit stream: Esc Esc Flag Esc Flag The receiver will ignore this Esc, and accept the flag. The receiver will ignore this flag.
21
What about Bit Stuffing?
We could have problems with two machines communicating where one uses 8-bit characters and one uses 16-bit characters. We stuff bits instead of bytes. Most DLL protocols use a combination of character count with another method for extra safety. This increases the chances of catching an error. 4343 X2
22
Framing (3) Bit stuffing (a) The original data.
The goal is to have as a unique bit pattern. Bit stuffing (a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in receiver’s memory after destuffing.
23
Error Control We use bit and byte stuffing as a method for detecting and determining errors in the data that we send. We also have to deal with making sure that the frames make it to their destination. The receiver sends back a control frame acknowledging the received frame and the condition of the frame.i.e. Positive and Negative feedback Timers : what happens when a frame completely vanishes : receiver neither sends a +ack nor –ack … then timer comes to help. It may result in a frame being sent more than once and received more than once : solution : assign sequence numbers to frames A timeout can occur if the acknowledgement doesn’t arrive, resulting in the frame being resent.
24
Error Control (cont’d)
Resending the frame can also cause problems – what happens when the same frame is received twice? We can also sequentially number the frames to prevent this problem. There are many different ways to do this type of error control (and it can be done at different levels as well).
25
Error Correction Error-correcting codes try to add enough redundant information so that the receiver can still figure out the data if the frame is damaged. This is sometimes referred to as forward error correction. The overhead is high but it reduces the need to resend frames. These redundant codes are best suited for networks with high error (wireless).
26
Error Detection and Correction
In some cases it is sufficient to detect an error and in some, it requires the errors to be corrected also. For eg. On a reliable medium : ED is sufficient where the error rate is low and asking for retransmission after ED would work efficiently In contrast, on an unreliable medium : Retransmission after ED may result in another error and still another and so on. Hence EC is desirable.
27
Error Detection and Correction
Error-Correcting Codes Error-Detecting Codes
28
Block Code Principles Hamming distance d(v1,v2), is the number of bits in which v1 and v2 differ. Hence, d(011011,110001) = 3. Consider the following mapping for k = 2 and n = 5 Data Block Codeword Now is a is received, what do we do ? Obviously this is not a codeword. So we have detected a error. Now let's see the hamming distance of the received word from all code words: d(00100,00000) = 1, d(00100,00111) = 2, d(00100,11001) = 4, d(00100,11110) = 3. So hamming distance to codeword for 00 is least. Hence it is most likely that the code transmitted codeword was and hence the data was 00. So now we have,with high probability, corrected the error.
29
Block Code Principles contd.
Hence of 2n words 2k are valid codewords. Of the remaining 2n - 2k words, at times some have minimun valid hamming distances to 2 codewords. For example from previous example. If received word was 01010, then this has min hamming distance d(01010,00000) = 2 and d(01010, 11110) = 2 from 2 valid code words. So in this case we can detect the error, but cannot correct it. Consider pairwise hamming distances between codewords: d(00000,00111) = 3; d(00000,11001) = 3; d(00000,11110) = 4; d(00111,11001) = 4; d(00111,11110) = 3; d(11001,11110) = 3; Minimum distance between valid codewords = 3; Single bit error will cause invalid codeword at distance 1 from a valid codeword and at least distance 2 from all other valid codewords. So we can always correct single bit errors. We can always detect two bit errors, but we might not aways be able to detect 3 bit errors.
30
Block Code Principles contd.
Each bit error increases the hamming distance by 1. In general, to correct error of up to t bits, the hamming distance between codewords should be at least 2t + 1. Design goals: (1) Given k and n we would like to design codewords that are farthest away from each other. (2) Codewords should be easy to encode and decode. (3) Extra bits (n-k), should be as small as possible. (4) Extra bits (n-k) should be large to reduce error rate.
31
The bits of the codeword are numbered consecutively, starting with bit 1 at the left end, and so on.
The bits that are powers of 2 (1, 2, 4, 8, 16, …) are check bits. The rest (3, 5, 6, 7, 9, …) are data bits. Each check bit forces the parity of some collection of bits, including itself, to be even. To see which check bits the data bit in position k contributes to, rewrite k as a sum of power of 2, e.g.,: 11 = and 29 = is encoded as Check bits are in blue. Which data position contributes to the first check bit: 3, 5, 7, 9, 11 Which data position contributes to the second bit: ? The example figure is in the next table.
32
When a codeword arrives, the receiver examines each check bit for the correct parity.
It the error counter is nonzero, it contains the number of incorrect bits. Hamming codes can correct single errors: If check bits 1, 2, and 8 are in error, the inverted bit is 11, because: 11 = The trick so that Hamming codes can correct burst errors: Arrange k consecutive codewords in a single matrix. Transmit the data one column at a time (normally the data would be transmitted one row at a time).
33
Error-Correcting Codes
Use of a Hamming code to correct burst errors.
34
Hamming Codes : for ED n EC
m data bits together with r error check bits form an n = (m + r) bit codeword The number of bits two codewords differ in is called the hamming distance between the two codewords Significance : If two codewords are at HD d then it requires d single bit errors to convert one into the other
35
HD of a coding scheme For m bit data .. All the 2^m possible combinations are legal But not all the 2^n codewords are used -- in a coding scheme (algorithm to compute the check bits) some of these codewords are legal and others are illegal For eq .. Consider parity : 1(r = 1) parity bit is appended with value so that the total number of 1’s in the codeword is even .. Then is a legal codeword in this scheme but is not
36
HD of a list of legal codewords
Minimum HD between any pair of legal codewords in the list Remember : Each algorithm to compute the check bits create a different list of legal codewords
37
Use of HD for error detection
To detect d single bit errors , we need (an algorithm that creates) a code list with HD at least d + 1 For eg . For the parity scheme .. HD is 2 ..hence it can be used to detect single bit errors (d=1)
38
Continued… If the recvd codeword is legal .. We accept it ,
And if it is illegal we report (detect) an error Q1 : Can it happen that we recv a legal codeword when d single bit errors have ocurred …this is eqwt to saying can we get a legal code from another legal code by d single bit errors? A1 : No, since the HD of the code is at least d + 1. So a legal CW can be genearted from another LCW by inerting at least d + 1 bits and not by inverting d or less bits.
39
Continued… Q2 : Can we get an illegal CW when no error has occurred ?
A2 : Obviously not ..since the legal CW was sent by the sender and if no error has occurred then the recver must recv a legal CW
40
Use of HD for error correction
To correct d single bit errors , we need (an algorithm that creates) a code list with HD at least 2d + 1. For eg. Consider the following legal CWs: , , , HD is 5 .. It can be used to correct 2 single bit errors
41
Continued.. Claim : Suppose we recv an illegal code C .. Then there is a unique legal code which is at a distance d or less from C Proof : Suppose there are 2 codes C1 and C2 at distance d (or less) from C .. Then C1 can be obtained from C2 by 2d (or less) inversions .. A contradiction to (code has HD at least 2d + 1)
42
Continue… Obtain C1 from C2
Lets rearrange the bits of C so that all the bits(B1) that are inverted to obtain C1 are in the beginning followed by bits(B2) inverted to obtain C2 ..followed by the remaining bits (B3) ..In the worst case there is no overlapping between B1 and B2 .. In that case C1 is obtained from C2 by inverting exactly these B1 and B2 bits which together are no more than 2d .. (if there is some overlapping then those bits are not inverted, hence < 2d)
43
Hamming Code to correct one bit errors
The bits of the CW are numbered left to right , starting from 1 … the bits that are powers of 2 are check bits (1,2,4,8 …) and the remaining are data bits. Expand the position of each data bit in powers of 2 ..for eg. 11 = So 11th bit contributes to the computation of value of these check bits I.e. 1,2, 8
44
Continued… We do this for each data bit ..
The value of a check bit is computed so that the parity of the all the data bits that contribute to it together with the check bit itself is even. For eg . data bits will be sent as the codeword
45
Hamming Code to correct burst errors
46
Error detecting code Polynomial code or CRC( Cyclic Redundancy Check )
47
Error detecting code Polynomial code or CRC( Cyclic Redundancy Check )
48
CRC A message m : a string of bits corresponds to a polynomial denote it by M(x). r check bits ….polynomial R(x). Transmitted bits m + r ….polynomial T(x) = M(x) + R(x) Generator polynomial G(x) r checkbits are computed so that when G(x) divides T(x), the remainder is zero.
49
Error-Detecting Codes
Calculation of the polynomial code checksum.
50
CRC contd.. At the receiving end, receiver again divides the polynomial corresponding to the received bits by G(x) and accepts it iff the remainder is zero. Now let E(x) denote the polynomial corresponding to the errored bits. Then receiver receives T’(x) = T(x) + E(x) G(x) divides T’(x) iff it divides E(x)
51
CRC Detecting single bit errors E(x) = x^i
Choose G(x) = any polynomial with at least two terms
52
Detecting 2 single bit errors
E(x) = x^i + x^j = x^i (x ^ (j-i) + 1) Choose G(x) s.t it neither divides x nor divides x^k + 1 for any k <= frame length
53
Detecting odd number of single bit errors
E(x) can’t be of the form (x + 1) Q(x) Choose G(x) of the type (x + 1) Q(x)
54
G(x) = a general polyn of degree r
Will detect single burst of length <= r Will accept (without detecting) bursts of length r+1 with probably only ½^(r-1) Will accept longer bursts (without detecting) with probability only ½^r Note : Certain Polynomials have become international standards
55
Detecting single burst of length k <=r with a gen polyn of degree r
E(x) = x^i ( x^(k-1) + …+ 1) Choose G(x) = Q(x) + 1 If k-1 < degree of G(x) then G(x) can never divide E(x) … I.e. if k-1 < r ..I.e. if k <= r
56
IEEE 802 LANs use For eg. X^32 + x^26 + x^23 + x^22 …..x^2 + x + 1
Detects single burst of length <= 32 Note : A simple shift register circuit can be constructed to compute and verify the checksums in hardware.
57
Error-Detecting Codes
Error-correcting codes are widely used on wireless links that are noisy. However, they generate too large transmission overhead for reliable links such as copper wire or fiber. Therefore, here error-detection codes are used. When error is detected, the data is retransmitted. The goal for error correcting codes it to add redundancy to the data so that the errors are not only detected but can be at the same time corrected (without retransmission). For error-detecting codes the goal is to only detect the errors with the minimal transmission overhead. They are based on polynomial code also known as CRC (Cyclic Redundancy Check) A k-bit frame is regarded as polynomial with coefficients 0 and 1 with terms from xk-1 to x0 For example: > x5 + x4 + x0
58
Polynomial arithmetic is done modulo 2 using the rules of algebraic field theory.
Both addition and subtraction are identical to exclusive OR. For exampe: The sender and receiver must agree on a generator polynomial G(x). G(x) must have the first and last bit equal to 1. For a given frame, we consider its polynomial M(x) (longer than G(x)). The checksum is the reminder from the division M(x)*xr / G(x), where r is the degree of G(x). Polynomial T(x) obtained as M(x)*xr - checksum represents the check-summed frame that is divisible by G(x). An example division is shown on the next page, where the frame is (corresponds to M(x)) and the generator polynomial G(x) = x4 + x + x0 -> M(x)*xr -> (we added 4 zeros at the end)
59
Calculation of the polynomial code checksum.
60
Upon receiving the check-summed frame, the receiver divides it by G(x):
[T(x) + E(x)] / G(x) Since T(x) / G(x) is always zero, the result is always E(x) / G(x). The errors containing G(x) as a factor will slip by, all other errors will be caught. Single bit errors will be detected: We have E(x)=xi for a single bit error, E(x) / G(x) will not be zero, since G(x) must have the first and last bit equal to 1. All errors consisting of an odd number of inverted bits will be detected if G(x) is divisible by (x + 1). E(x) consists of odd number of terms, e.g., x5 + x2 + x0 and therefore, cannot be divisible by (x+1). Since E(x) has an odd number of terms E(1)=1. If E(x) = (x + 1) Q(x), then E(1) = (1 + 1) Q(1) = 0, a contradiction. The polynomial G(x) used in IEEE 802 standard is x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x1 + 1
61
Flow Control We must deal with the issue where the sender is sending data at a higher rate than the receiver can receive the data. There are two approaches to this problem: feedback-based flow control feedback is used to tell the sender how the receiver is doing or to send another frame rate-based flow control the transfer rate is fixed by the sender this is not used often in the DLL 4343 X2
62
A Simple Frame Structure
typedef struct{ frame_kind kind; /*what kind of frame?*/ seq_nr seq; /*sequence number */ seq_nr ack; /*acknowledgement number */ packet info; /*the network layer packet*/ } frame; 4343 X2
63
Packet vs Frame A packet is data constructed at the network layer and passed to the data link layer. It knows nothing of the frame and the frame header used to send the data. A frame is a structure used to move the packet across the network. The frame header is hidden from the network layer. 4343 X2
64
A Frame 4343 X2
65
Elementary Data Link Protocols
An Unrestricted Simplex Protocol A Simplex Stop-and-Wait Protocol A Simplex Protocol for a Noisy Channel Each protocol is increasing in complexity and drops unrealistic assumptions.
66
Unrestriced simplex protocol
Assumption 1. Receiver can process data infinitely fast. Assumption 2. Channel never looses data Sender sends as fast as possible Receiver can always process fast enough
67
Simplex stop-and-wait protocol
Assumption 2. Channel never looses data Sender sends frame Rcvr sends ack after processing Sender waits for ack Sender sends frame
68
Simplex protocol for noisy channel
Assumption 2. Channel may loose data * Data frame can be lost * Ack can be lost Lost data frames: This means that sender will never get an ack. Sender can implement timer for each frame sent. If timer expires retransmit. But what if the data frame arrived but the ack was lost? Using above method, sender will retransmit frame that receiver has already received. Result: Duplicate frame at sender. So receiver needs some way of distinguishing duplicates. Answer: Use sequence numbers. What should be the field size of these sequence numbers ?
69
Simplex protocol for noisy channel
Since we are still using a stop-and-wait type protocol, sender will never transmit frame m+1 unless it gets an ack for m. So receiver need only distinguish between successive frames. A 1 bit sequence number (0,1) is enough. Sender includes consecutive seq numbers in frame, receiver sends ack with seq number. Sender: Send frame with seq number N. Wait (with timer) for ack with seq number N. If timer expires: retransmit frame with seq number N If ack arrives : N = mod(N+1,2) Receiver: Expect frame N If N arrives: deliver to network layer, send ack for N, N = mod(N+1,2) The main difference between this protocol for simple stop-and-wait is that the receiver knows which seq num to expect and sender known which seq num to send. This technique is called Automatic Repeat Request (ARQ)
70
Sliding Window Protocols
A One-Bit Sliding Window Protocol A Protocol Using Go Back N A Protocol Using Selective Repeat
71
Sliding Window Protocols (2)
A sliding window of size 1, with a 3-bit sequence number. (a) Initially. (b) After the first frame has been sent. (c) After the first frame has been received. (d) After the first acknowledgement has been received.
72
Pipelining Consider a 50 kbps channel to a satellite with round-trip propagation delay 500 msec. Using window size 1: At t = 0 sender starts sending first bit of 1000 bit frame At t = 20 msec frame completely sent At t = 270 frame completely received At t = 520 ack received by sender Sender busy for 20/520 = 4% of time ... very inefficient. Why ? Sender has to wait till a frame is acked before sending the next frame. Solution: Allow sender to send up to w (>1) frames without waiting for ack. So from t = 0 to t = 520, sender could have sent 26 frames, so let w should be atleast 26. Need for large window occurs when the bw x delay is big .... think about this !! bw x delay determines how many frames can “fit in the pipe”. We will revisit this later.
73
Pipelining and error control
Pipelining is fine ... but what if frames in the pipeline are lost. Sender will detect loss of frames only after many successive frames have already been transmitted. So, does the sender retransmit all frames (lost and successive) or just lost ? The buffer at the receiver decides.
74
Go-back-N Vs. Selective-repeat
Pipelining and error recovery. Effect on an error when (a) Receiver’s window size is 1. (b) Receiver’s window size is large.
75
A Simplex Stop-and-Wait ARQ
Normal operation The frame is lost The ACK is lost The ACK is delayed
76
Stop-and-Wait ARQ -Normal operation-
The sender will not send the next piece of data until it is sure that the current one is correctly received sequence number necessary to check for duplicated packets No NACK – when packet is corrupted – duplicate ACKs instead
77
Stop-and-Wait ARQ -Lost or damaged frame-
roundtrip delay processing in the receiver
78
Stop-and-Wait ARQ -Lost ACK-
Importance of numbering
79
Stop-and-Wait ARQ -Delayed ACK-
Importance of ACK numbering
80
Duplex Stop-and-Wait ARQ
Piggybacking combine data with ACK (less overhead saves bandwidth)
81
Drawbacks of Stop-and-Wait ARQ
After each frame sent the host must wait for an ACK inefficient use of bandwidth To improve efficiency ACK should be sent after multiple frames Alternatives: Sliding Window protocols Go-back-N ARQ Selective Repeat ARQ
82
Pipelining One task begins before the other one ends
increases efficiency in transmission There is no pipelining in Stop-and-Wait ARQ
83
Sliding Window Protocols
Sequence numbers sent frames are numbered sequentially number of frames stored in the header if the number of bits in the header is m than sequence number goes from 0 to 2^m-1 Sliding window to hold the unacknowledged outstanding frames the receiver window size always 1 sequence number frame acknowledged frames
84
Question What is the consequence of the window size in the receiver on the order of the received packets? Answer: Window size 1 means that the packets are received in order Note: this is not the case for the larger receiver window size
85
Go-back-N -Control variables-
S- holds the sequence number of the recently sent frame SF – holds sequence number of the first frame in the window SL – holds the sequence number of the last frame R – sequence number of the frame expected to be received
86
The name of Go-back-N: why?
Re-sending frame when the frame is damaged the sender goes back and sends a set of frames starting from the last one ACKn’d the number of retransmitted frames is N Example: The window size is 4. A sender has sent frame 6 and the timer expires for frame 3 (frame 3 not ACKn’d). The sender goes back and re-sends the frames 3, 4, 5 and 6.
87
Go-back-N -normal operation-
How many frames can be transmitted without acknowledgment? ACK1 – not necessary if ACK2 is sent Cumulative ACK expected sequence number
88
Go-back-N -damaged or lost frame-
damaged frames are discarded! Why are correctly received packets not buffered? What is the disadvantage of this?
89
Go-back-N -sender window size-
sequence number
90
Go-back-N Inefficient This is a problem in a noisy link Solution
all out of order received packets are discarded This is a problem in a noisy link many frames must be retransmitted -> bandwidth consuming Solution re-send only the damaged frames Selective Repeat ARQ avoid unnecessary retransmissions
91
Stop-and-Wait ARQ is a special case of Go-Back-N ARQ in which the size of the send window is 1.
92
Selective Repeat ARQ Processing at the receiver more complex
The window size is reduced to one half of 2m Both the transmitter and the receiver have the same window size Receiver expects frames within the range of the sequence numbers
93
Selective Repeat ARQ -lost frame-
Note: retransmission triggered with NACK and not with expired timer
94
Selective Repeat ARQ -sender window size-
95
Readings Chapter 11 (B.A Forouzan) Section 11.2,11.3, 11.5
(Cover only those contents which are related to topics covered in class)
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.