Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Data Link Layer.

Similar presentations


Presentation on theme: "The Data Link Layer."— Presentation transcript:

1 The Data Link Layer

2 Data Link Layer Design Issues
Services Provided to the Network Layer Framing Error Control Flow Control

3 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

4 Functions of the Data Link Layer (2)
Relationship between packets and frames.

5 Services Provided to Network Layer
(a) Virtual communication. (b) Actual communication.

6 Services Provided to Network Layer (2)
Placement of the data link protocol.

7 A character stream. (a) Without errors. (b) With one error.
Framing A character stream. (a) Without errors. (b) With one error.

8 Framing (2) (a) A frame delimited by flag bytes.
(b) Four examples of byte sequences before and after stuffing.

9 Framing (3) 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.

10 Error Control No physical link is perfect Bits will be corrupted
We can either: detect errors and request retransmission or correct errors without retransmission

11 Error types Single bit :only one Muti bit : isolated & low numbers Burst Errors : lots of bits in a row are lost BBBB-BBB--BBB-B--BBBB-BBB

12

13 If minimum hamming distance is dm
Min distance If minimum hamming distance is dm 2t +s+1 <dm s is detectable t is correctable

14 Error Detection and Correction
Error-Correcting Codes Error-Detecting Codes

15 Error Detection Parity bits Polynomial codes or checksums

16 Parity bits Append a single parity bit to a sequence of bits
If using “odd” parity, the parity bit is chosen to make the total number of 1’s in the bit sequence odd. If “even” parity, the parity bit makes the total number of 1’s in the bit sequence even

17 Parity bits: Example Transmitted Sequence Parity Parity Bit 00010101
even 1 01111 even odd 1 10011 odd

18 Parity Bits Only detects when there are an odd number of bit errors ?(exercise) Does not detect an even number of bit errors It also has high overhead; it requires 1 extra bit for every several bits transmitted

19 Parity Error-detecting codes Parity bit for 1 bit error detection
Parity bit can detect 1 error. Parity bit for n bit burst error detection Each block is considered as matrix, width n, height k. Parity bit calculated for each column. Last row of parity bits appended: (parity bit for col 1, col 2, ..., col n) Transmit n(k+1) block row by row. Any burst of length up to n will leave at most 1 error in each col. Can be detected.

20 Example Usage of hamming codes For burst errors!!!

21 Polynomial Codes Benefits : Can detect errors on large chunks of data
Has low overhead stronger than parity bit Requires the use of a “code polynomial” Example: x2 + 1

22 Poly codes Data is viewed a single long “number”,S(x)
Divide S(X) by an agreed upon divisor, G(X) S(x)/G(x) = C(x) + remainder, R(x) Transmit T(x) = S(x) – R(x) Check: if ( (T(x)/G(x) ) != 0) then error!

23 Cyclic Redundancy Check
CRC: Example of a polynomial code Procedure: 1. Let r be the degree of the code polynomial. Append r zero bits to the end of the transmitted bit string. Call the entire bit string S(x) 2. Divide S(x) by the code polynomial using modulo 2 division. 3. Subtract the remainder from S(x) using modulo 2 subtraction. The result is the checksummed message Easy to build in hardware

24 Why polynomial? Treat numbers as polynomials, not as integers, Why?
Polynomial arithmetic has no carries Arithmetic same a “XOR” gate 0-0 = 0 1-0 =1 0-1 =1 (wraparound) 1-1 =0

25 Generating a CRC Example
Message: x x x x2 + 1 x x + 1 = x3 + x + 1 Code Polynomial: x (101) Step 1: Compute S(x) r = 2 S(x) =

26 Generating a CRC Example (cont’d)
Step 2: Modulo 2 divide 101100 101 001 000 010 100 01 1001 Remainder

27 Generating a CRC Example (cont’d)
Step 3: Modulo 2 subtract the remainder from S(x) 101100 - 01 101101 Checksummed Message

28 Decoding a CRC(Receiver Side)
Procedure 1. Let n be the length of the checksummed message in bits 2. Divide the checksummed message by the code polynomial using modulo 2 division. If the remainer is zero, there is no error detected.

29 Decoding a CRC Example 101101 Checksummed message (n = 6) 1011 Original message (if there are no errors) 101101 101 001 000 010 00 1001 Remainder = 0 (No error detected)

30 Decoding a CRC Another Example
When a bit error occurs, there is a large probability that it will produce a polynomial that is not an even multiple of the code polynomial, and thus errors can usually be detected. 101001 101 000 001 01 1000 Remainder = 1 (Error detected)

31 Choosing a CRC polynomial
The longer the polynomial, the smaller the probability of undetected error Common standard polynomials: (1) CRC-12: x12 + x11 + x3 + x2 + x1 + 1 (2) CRC-16: x16 + x15 + x2 + 1 (3) CRC-CCITT: x16 + x12 + x5 + 1

32 Putting it all together
101 1001 101001 Network Layer message Data-Link Layer message: Data CRC First bit Last bit Code Polynomial

33 Error Correction Parity bits and polynomial codes catch errors, but can we correct them without retransmitting information? Yes, using Hamming Codes

34 Hamming Codes( similarity& dissimilarities)
Hamming codes, like polynomial codes, are appended to the transmitted message Hamming codes, unlike polynomial codes, contain the information necessary to locate a single bit error

35 Example Of Using Parity code in 2D for single bit error Correction
(In 2D it uses more Parity! to correct 1 bit ????)

36 How use Parity for correcting 1 bit in linear codes ( Hamming)

37 Calculating a Hamming Code
Procedure: Place message bits in their non-power-of-two Hamming positions Build a table listing the binary representation of each of the message bit positions Calculate the check bits

38 Hamming Code Example Index positions from 1 Message to be sent:
Index positions from 1 Position 2n: check bits

39 Hamming Code Example Message to be sent: 1 0 1 1 1 0 1 1 1 2 3 4 5 6 7
Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = =

40 Hamming Code Example Message to be sent: 1 0 1 1 1 0 1 1 1 2 3 4 5 6 7
Even parity use xor Odd parity use xnor Message to be sent: 1 Starting with the 20 position: Look at positions with 1’s in them Count the number of 1’s in the corresponding message bits If even, place a 1 in the 20 check bit, i.e., use odd parity Otherwise, place a 0 Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = =

41 Hamming Code Example Message to be sent: 1 0 1 1 1 0 1 1 1 2 3 4 5 6 7
1 Repeat with the 21 position: Look at positions those positions with 1’s in them Count the number of 1’s in the corresponding message bits If even, place a 1 in the 21 check bit Otherwise, place a 0 Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = =

42 Hamming Code Example Message to be sent: 1 0 1 1 1 0 1 1 1 2 3 4 5 6 7
1 1 Repeat with the 22 position: Look at positions those positions with 1’s in them Count the number of 1’s in the corresponding message bits If even, place a 1 in the 22 check bit Otherwise, place a 0 Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = =

43 Hamming Code Example Original message = 1011 Sent message = 1011011
Now, how do we check for a single-bit error in the sent message using the Hamming code?

44 Using Hamming Codes to Correct Single-Bit Errors
Received message: Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = =

45 Using Hamming Codes on Longer Messages
Received message: Position 2n: check bits Does this work? 3 = = 5 = = 6 = = 7 = =

46 Using Hamming Codes to Correct Single-Bit Errors
Sent message: Received message: Starting with the 20 position: Look at positions with 1’s in them Count the number of 1’s in both the corresponding message bits and the 20 check bit and compute the parity. If even parity, there is an error in one of the four bits that were checked. Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = = Odd parity: No error in bits 1, 3, 5, 7

47 Using Hamming Codes to Correct Single-Bit Errors
Sent message: Received message: Repeat with the 21 position: Look at positions with 1’s in them Count the number of 1’s in both the corresponding message bits and the 21 check bit and compute the parity. If even parity, there is an error in one of the four bits that were checked. Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = = Even parity: ERROR in bit 2, 3, 6 or 7!

48 Using Hamming Codes to Correct Single-Bit Errors
Sent message: Received message: Repeat with the 22 position: Look at positions with 1’s in them Count the number of 1’s in both the corresponding message bits and the 22 check bit and compute the parity. If even parity, there is an error in one of the four bits that were checked. Position 2n: check bits Calculate check bits: 3 = = 5 = = 6 = = 7 = = Even parity: ERROR in bit 4, 5, 6 or 7!

49 Finding the error’s location
Position

50 Finding the error’s location
Position No error in bits 1, 3, 5, 7

51 Finding the error’s location
erroneous bit, change to 1 Position Error must be in bit 6 because bits 3, 5, 7 are correct, and all the remaining information agrees on bit 6 ERROR in bit 2, 3, 6 or 7 ERROR in bit 4, 5, 6 or 7

52 Finding the error’s location An Easier Alternative to the Last Slide
Check bits 3 = = 5 = = 6 = = 7 = = E E NE = 6 1 1 E = error in column NE = no error in column Other Way is to use xnor for (odd check & even generate) and xor for(odd generate and even check) ( exercise)?

53 Hamming Codes Hamming codes can be used to locate and correct a single-bit error If more than one bit is in error, then a Hamming code cannot correct it Hamming codes, like parity bits, are only useful on short messages

54 Flow Control What happens if the sender tries to transmit faster than the receiver can accept? Data will be lost unless flow control is implemented

55 Controlling the Flow of Data
Busy Client Slow Server

56 Some Flow Control Algorithms
Flow control for the ideal network Stop and Wait for noiseless channels Stop and Wait for noisy channels Sliding window protocols Sliding window with error control Go Back N Selective Repeat

57 Flow control in the ideal network
No acknowledgement of frames necessary Since the data link is error-free and the receiver can buffer as many frames as it likes, no frame will ever be lost Assumptions: Error free transmission link, Infinite buffer at the receiver

58 Flow control in the ideal network (cont’d)
Busy Client Slow Server Infinite Box

59 5.2 Stop and Wait with Noiseless Channels
Problem of Buffer overflow at the receiver Buffer overflow may happen at the receiver when the sender sends frames at a rate faster than the receiver Assumptions: Error free transmission link, Finite buffer at the receiver!

60 Stop and Wait with Noiseless Channels (cont’d)
Busy Client Slow Server Finite Box (once full, Letter is lost) Bit Bucket

61 Stop and Wait with Noiseless Channels (cont’d)
Solution: Stop-and-Wait The receiver sends an acknowledgement frame telling the sender to transmit the next data frame. The sender waits for the ACK, and if the ACK comes, it transmits the next data frame.

62 Stop and Wait with Noiseless Channels (cont’d)
Data ACK (I got your message) Data

63 Stop and Wait (cont’d) Note that we assume an error-free transmission link and therefore ACK frames will not be lost In this flow control protocol, there are two types of frames: data frames and ACK frames. The ACK frames don’t contain any particular information, since only the arrival of the ACK frame at the sender is important.

64 5.3 Stop and Wait for Noisy Channels
ACK frames may now be lost Assumptions: Transmission link may cause errors in frames, Finite buffer at the receiver

65 Problems introduced by a noisy line
Problem 1: Loss of a data or ACK frame Since the transmission link is not error-free, a data or ACK frame may be lost, causing the sender to wait indefinitely for an ACK

66 Loss of an ACK frame Data Time ACK ?

67 Problems introduced by a noisy line
Can we solve problem 1 by introducing a timeout period for the sender? Yes, but... Problem 2: Duplicated frames If the ACK frame for a certain data frame is lost, the sender will retransmit the same frame after a time-out period, and the receiver will then have two copies of the same frame

68 Duplicated Data Frames
Buy 10 Tckets! Time Timed Out ACK Where’s the ACK? Buy 10 Tickets! Order 20?

69 Stop and Wait for Noisy Channels (cont’d)
Solution: The sender uses a timer to retransmit data frames when an ACK has not arrived The sender includes a sequence number in each frame to distinguish one frame from another. This way, the receiver knows when it has received duplicate frames.

70 Stop-and-Wait with Noisy channels
Data 1 Timed Out ACK Where’s the ACK? Data Duplicate 1 1

71 Is Stop and Wait the best we can do?
Stop and Wait is an effective form of flow control, but… It’s not very efficient. 1. Only one data frame can be in transit on the link at a time 2. When waiting for an acknowledgement, the sender cannot transmit any frames Better solution? Sliding Window

72 Sliding Window Protocols Definitions
Sequence Number: Each frame is assigned a sequence number that is incremented as each frame is transmitted Sender Window: Keeps track of sequence numbers for frames that have been sent but not yet acknowledged Receiver Window: Keeps track of sequence numbers for frames the receiver is allowed to accept Maximum Sender Window size: The maximum number of frames the sender may transmit without receiving any acknowledgements Maximum Receiver Window size: The maximum number of frames the receiver may receive before returning an acknowledgement to the sender

73 Simple Sliding Window with Window Size of 1
1 2 3 4 5 6 7 A sliding window with a maximum window size of 1 frame for sending 7 farme( 3 bit seq num)

74 Sliding Window example
Sender window 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Receiver window 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 (a) (b) (c) (d) (a) Initial state, no frames transmitted (b) Sender transmits frame 0 (c) Receiver receives frame 0 and ACKs (d) Sender receives ACK

75 Simple Sliding Window with Window size 1 (cont’d)
This protocol behaves identically to stop and wait for a noisy channel

76 Sliding Window Protocols General Remarks
The sending and receiving windows do not necessarily have the same maximum size Any frame whose sequence number falls outside the receiver window is discarded at the receiver The sender window’s size grows and shrinks as frames are transmitted and acknowledged Unlike the sender window, the receiver window always remains at its maximum size

77 Sliding Window Protocols Piggybacking Acknowledgements
When a data frame arrives at a router, instead of immediately sending a separate ACK frame, the router waits until it is passed the next data frame to send. The acknowledgement is attached to the outgoing data frame. Since we have full duplex transmission, we can “piggyback” an ACK onto the header of an outgoing data frame to make better use of the channel

78 Sliding Window with Maximum Sender Window Size WS
With a maximum window size of 1, the sender waits for an ACK before sending another frame With a maximum window size of WS, the sender can transmit up to WS frames before “being blocked” This allows the sender to transmit several frames before waiting for an acknowledgement

79 Sender-Side Window with WS=2
1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 (a) (b) (c) (d) 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 (e) (f) (g) (h) (a) Initial window state (b) Send frame 0 (c) Send frame 1 (d) ACK for frame 0 arrives (e) Send frame 2 (f ) ACK for frame 1 arrives (g) ACK for frame 2 arrives, send frame 3 (h) ACK for frame 3 arrives

80 Pipelining packet 5 packet 6 packet 4 5 6 4 7 3 Ack 0 Ack 2 Ack 1 2 1

81 Pipelining data stream 99 51 50 A B 1 49 ACK stream By allowing several frames onto the link before receiving an acknowledgement, pipelining keeps the link from being idle Sliding window with WS > 1 is also called “pipelined” communication

82 5.4.3 Sliding Window with Maximum Receiver Window Size WR
With a maximum window size of 1, the receiver must receive and process every frame in sequence With a maximum window size of WR, the receiver can receive and process up to WR frames before acknowledging them This is useful when frames are lost!: the receiver can still accept and buffer frames after the missing frame

83 Receiver-Side Window with WR=2
1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 (a) (b) (c) (d) 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 (e) (f) (g) (h) (a) Initial window state (b) Nothing happens (c) Frame 0 arrives, ACK frame 0 (d) Nothing happens (e) Frame 1 arrives, ACK frame 1 (f) Frame 2 arrives, ACK frame 2 (g) Nothing happens (h) Frame 3 arrives, ACK frame 3

84 What about Errors? What if a data or acknowledgement frame is lost when using a sliding window protocol? Two Solutions: 1:Go Back N 2:Selective Repeat

85 5.5 Sliding Window with Go Back N
When the receiver notices a missing or erroneous frame, it simply discards all frames with greater sequence numbers and sends no ACK The sender will eventually time out and retransmit all the frames in its sending window

86 Go Back N Timeout interval Sender 1 2 3 4 2 3 4 5 6 Receiver 1 E D D 2
1 2 3 4 2 3 4 5 6 Maximum window size = 8 ACK 0 ACK 1 ACK 2 ACK 3 ACK 4 ACK 5 ACK 6 Receiver 1 E D D 2 3 4 5 6 Maximum window size = 8 Discarded by receiver Frame with error Time

87 Go Back N can recover from erroneous or missing frames
Go Back N (cont’d) Go Back N can recover from erroneous or missing frames But… It is wasteful. If there are errors, the sender will spend time retransmitting frames the receiver has already seen

88 Sliding Window with Selective Repeat
The sender retransmits only the frame with errors The receiver stores all the correct frames that arrive following the bad one. (Note that the receiver requires a frame buffer for each sequence number in its receiver window.) When the receiver notices a skipped sequence number, it keeps acknowledging the last good sequence number When the sender times out waiting for an acknowledgement, it just retransmits the one unacknowledged frame, not all its successors.

89 If nack is lost nothing Happen
Selective Repeat Benefits Of nack ? If nack is lost nothing Happen Timeout interval Sender 1 2 3 4 2 5 6 Maximum window size = 8 ACK 0 ACK 1 ACK 1 ACK 4 ACK 5 ACK 1 ACK 6 NACK 2 Receiver 1 E 3 4 2 5 6 Maximum window size = 8 Buffered by receiver Frame with error Time


Download ppt "The Data Link Layer."

Similar presentations


Ads by Google