Você está na página 1de 97

Datalink Layer

Prepared by Bhavesh Borisaniya

Introduction
Responsibilities of the data link layer include:
Framing
Addressing Flow control Error control, and Media access control

Datalink Layer

9/9/2011

Functions of the Data Link Layer

Relationship between packets and frames

Datalink Layer

9/9/2011

Services provided to the Network Layer


Three reasonable possibilities: 1. Unacknowledged connectionless service
appropriate when the error rate is very low appropriate for real-time traffic, such as voice

2. Acknowledged connectionless service


useful over unreliable channels, such as wireless systems

3. Acknowledged connection-oriented service


the source and destination machines establish a connection before

any data are transferred Each frame sent over the connection is numbered guarantees that each frame sent is indeed received
4 Datalink Layer

9/9/2011

Framing

Datalink Layer

9/9/2011

Framing
Framing in data link layer,
separates a message from one source to a destination, or from other

messages to other destinations


Why framing ?
Large frame will make flow and error control very inefficient

Single-bit error would require the retransmission of the whole

message
Types of framing
Fixed-Size Framing Variable-Size Framing
6 Datalink Layer 9/9/2011

Variable Size Framing


Breaking the bit stream up into frames is more difficult..
One way is to insert time gaps between frames Not work because network rarely make any guarantees about timing Another framing method

Datalink Layer

9/9/2011

Variable Size Framing


Character-oriented protocols
Data to be carried are 8-bit characters from a coding system such as ASCII

A frame in a character-oriented protocol

8-bit (1-byte) flag is added at beginning and the end of a frame

Datalink Layer

9/9/2011

Variable Size Framing


Character-Oriented Protocols Byte stuffing is the process of adding 1 extra byte whenever there is a flag or escape character in the text

Datalink Layer

Byte stuffing and unstuffing

9/9/2011

Variable Size Framing


Bit-Oriented Protocols
the data section of frame is a sequence of bits to be interpreted by

upper layer as text, graphic, audio, video and so on. Most protocols use a special 8-bit pattern flag 01111110 as the delimiter.

A frame in a bit-oriented protocol

10

Datalink Layer

9/9/2011

Variable Size Framing


Bit-Oriented Protocols

11

Datalink Layer

Bit stuffing and unstuffing

9/9/2011

Flow Control and Error Control

12

Datalink Layer

9/9/2011

Flow Control and Error Control


Flow Control
what to do with a sender that systematically transmits frames faster

than the receiver can accept them Flow control refers to a set of procedures used to restrict the amount of data that the sender can send before waiting for acknowledgement
Error Control

how to make sure all frames are eventually delivered to the network

layer at the destination and in the proper order. Error control in the data link layer is based on automatic repeat request, which is the retransmission of data
13 Datalink Layer

9/9/2011

Error Detection and Correction


Data can be corrupted during transmission.
Some applications require that errors be detected and corrected

Types of errors
Single-Bit Error Only 1 bit in the data unit has changed Burst Error A burst error means that 2 or more bits in the data unit have changed

14

Datalink Layer

9/9/2011

Types of errors
Single-bit error

In a single-bit error, only 1 bit in the data unit has changed

15

Datalink Layer

9/9/2011

Types of Errors
Burst Error

A burst error means that 2 or more bits in the data unit have changed
16 Datalink Layer 9/9/2011

Redundancy
The central concept in detecting or correcting errors is

redundancy used to detect or correct errors


need to send some extra bits with data

redundant bits are added by the sender and removed by the

receiver
Their presence allows the receiver to detect or correct corrupted

bits

17

Datalink Layer

9/9/2011

Detection versus Correction


The correction of errors is more difficult than the detection.
In error detection
looking only to see if any error has occurred

The answer is a simple yes or no


not even interested in the number of errors

single-bit error is the same for us as a burst error

In error correction
need to know the exact number of bits that are corrupted

their location in the message

18

Datalink Layer

9/9/2011

Forward Error Correction Versus Retransmission


There are two main methods of error correction. Forward error correction
is the process in which the receiver tries to guess the message by using

redundant bits works if the number of errors is small Uses error-detecting codes
Correction by retransmission

is a technique in which the receiver detects the occurrence of an error and

asks the sender to resend the message resending is repeated until a message arrives that the receiver believes is error-free Uses error-detecting codes
19 Datalink Layer

9/9/2011

Coding
Redundancy is achieved through various coding schemes.
The sender adds redundant bits through a process that creates

a relationship between the redundant bits and the actual data bits. The receiver checks the relationships between the two sets of bits to detect or correct the errors. The ratio of redundant bits to the data bits and the robustness of the process are important factors Coding schemes can be divided into two broad categories
Block Coding
Convolution Coding complex and beyond the scope
20 Datalink Layer 9/9/2011

Coding

The structure of encoder and decoder


21 Datalink Layer 9/9/2011

Block Coding
Message will be divided into blocks
each block will be of k bits, called datawords r redundant bits will be added to each block to make the length

n=k+r, called codewords (n>k)

22

Datalink Layer

9/9/2011

Example
In 4B/5B block coding scheme, k = 4 and n = 5 we have 2k =

16 datawords and 2n = 32 codewords. How many codewords will be used for message transfer.
16 out of 32 codewords are used for message transfer and the

rest are either used for other purposes or unused.

23

Datalink Layer

9/9/2011

Error Detection

Process of error detection in block coding


24 Datalink Layer 9/9/2011

Example
Let us assume that k = 2 and n = 3 and the sender encodes

the dataword 01 as 011 and sends it to the receiver. Table shows the list of datawords and codewords.

25

Datalink Layer

9/9/2011

Example
Consider the following cases: 1. The receiver receives 011.

It is a valid codeword.The receiver extracts the dataword 01 from it.

2.

The codeword is corrupted during transmission, and 111 is received.


This is not a valid codeword and is discarded.

3.

The codeword is corrupted during transmission, and 000 is received.


This is a valid codeword. The receiver incorrectly extracts the dataword 00. Two corrupted bits have made the error undetectable.

26

Datalink Layer

9/9/2011

Error Correction

Structure of encoder and decoder in error correction


27 Datalink Layer 9/9/2011

Example
k=2 and n=5. The sender assume dataword 01 and sends 01011.

The codeword is corrupted and 01001 is received.

A code for error correction


28 Datalink Layer 9/9/2011

Hamming Distance
The Hamming distance between two words is the number of

differences between corresponding bits.


Hamming distance of two words x and y is d(x,y)
Can be found by applying XOR operation on the two words and

count the number of 1s in the result.

30

Datalink Layer

9/9/2011

Hamming Distance
Hamming distance between two pairs of words.
1.

The Hamming distance d(000, 011) is 2 because

2.

The Hamming distance d(10101, 11110) is 3 because

31

Datalink Layer

9/9/2011

Minimum Hamming Distance


The minimum Hamming distance is the smallest Hamming

distance between all possible pairs in a set of words. Find the minimum Hamming distance of the coding scheme in Table:

32

Datalink Layer

The dmin in this case is 2.

9/9/2011

Minimum Hamming Distance


Find the minimum Hamming distance of the coding scheme in

Table:

The dmin in this case is 3.


33 Datalink Layer 9/9/2011

Minimum Hamming Distance


Three parameters for coding scheme C(n,k)
n codeword size k dataword size dmin minimum hamming distance

Example
C(3,2) with dmin = 2

34

Datalink Layer

9/9/2011

Minimum Hamming Distance


To guarantee the detection of up to s errors in all cases, the

minimum hamming distance in a block code must be dmin = s + 1

35

Datalink Layer

9/9/2011

Minimum Hamming Distance


To guarantee correction of up to t errors in all cases, the

minimum Hamming distance in a block code must be dmin = 2t + 1

36

Datalink Layer

9/9/2011

Example
A code scheme has a Hamming distance dmin = 4. What is the error

detection and correction capability of this scheme?

Solution This code guarantees the detection of up to three errors (s = 3), but it can correct up to one error. If this code is used for error correction, part of its capability is wasted.
Error correction codes need to have an odd minimum distance (3, 5, 7, . ).

37

Datalink Layer

9/9/2011

Linear Block Codes


A linear block code is a code in which the exclusive OR (addition

modulo-2) of two valid codewords creates another valid codeword.


XORing any codeword with any other codeword is a valid codeword

all four codewords can be retrieved by XORing two other codewords


38 Datalink Layer 9/9/2011

Parity Check
A simple parity-check code is a single-bit error-detecting

code in which n = k + 1 with dmin = 2.

Simple parity-check code C(5, 4)


39 Datalink Layer 9/9/2011

Parity Check

40

Datalink Layer

Encoder and decoder for simple parity-check code

9/9/2011

Two dimensional parity check

41

Datalink Layer

9/9/2011

Two dimensional parity check

42

Datalink Layer

9/9/2011

Two dimensional parity check

43

Datalink Layer

9/9/2011

Hamming Code
use of extra parity bits to allow the position identification of a single

error 1. Mark all bit positions that are powers of 2 as parity bits. (positions 1, 2, 4, 8, 16, etc.) 2. All other bit positions are for the data to be encoded. (positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, etc.) 3. Each parity bit calculates the parity for some of the bits in the code word. The position of the parity bit determines the sequence of bits that it checks.

Position 1: checks bits (1,3,5,7,9,11,...) Position 2: checks bits (2,3,6,7,10,11,14,15,...) Position 4: checks bits (4,5,6,7,12,13,14,15,20,21,22,23,...) Position 8: checks bits (8-15,24-31,40-47,...)

4.
44

Set the parity bit to create even parity.


Datalink Layer 9/9/2011

Hamming Code
Bit position Encoded data bits 1 p1 2 p2 3 d1 4 p4 5 d2 6 d3 7 d4 8 p8 9 d5 10 d6 11 d7 12 d8 13 d9 14 d10 15 d11 16 p16

p1
p2 Parity bit coverage p4 p8 p16

X
X

X
X X

X
X X X

X
X X X

X
X

X
X X

X
X X X X X

X
X X X X .

45

Datalink Layer

9/9/2011

Hamming Code Example


Encoder process
Data word : 1011

1 0 1 1 1 2 3 4 5 6 7 p1 p2 d1 p4 d2 d3 d4

- data word - bit position - encoded data bits

p1 = d1 + d2 + d4 = 1 + 0 + 1 = 0 p2 = d1 + d3 + d4 = 1 + 1 + 1 = 1 p4 = d2 + d3 + d4 = 0 + 1 + 1 = 0
Codeword : 1011010
46 Datalink Layer 9/9/2011

Hamming Code Example


Decoder process
Code word : 1010010

0 1 1 0 0 1 0 1 2 3 4 5 6 7 p1 p2 d1 p4 d2 d3 d4

- code word - bit position - encoded data bits

p1 = d1 + d2 + d4 = 1 + 0 + 0 = 1 p2 = d1 + d3 + d4 = 1 + 1 + 0 = 0 p4 = d2 + d3 + d4 = 0 + 1 + 0 = 1
Error is in p1, p2 and p4 bit, i.e., 1+ 2 + 4 = 7th bit (d4) is erroneous
47 Datalink Layer 9/9/2011

Cyclic Codes
Cyclic codes are special linear block codes with one extra

property
In a cyclic code, if a codeword is cyclically shifted (rotated), the

result is another codeword


Example

1011000 0110001
Cyclic codes are used to correct the errors in networks (LAN

and WAN) Cyclic Redundancy Check (CRC)

48

Datalink Layer

9/9/2011

Cyclic Redundancy Check

49

Datalink Layer

A CRC code with C(7, 4)

9/9/2011

Cyclic Redundancy Check

50

Datalink Layer

CRC encoder and decoder

9/9/2011

CRC Encoder

Division in CRC encoder

51

Datalink Layer

9/9/2011

CRC Decoder

52

Datalink Layer

9/9/2011

Polynomials
A better way to understand cyclic codes and how they can be

analyzed is to represent them as polynomials

A polynomial to represent a binary word


53 Datalink Layer 9/9/2011

Polynomials

54

Datalink Layer

CRC Division using Polynomials

9/9/2011

Cyclic Code Analysis


The divisor in a cyclic code is normally called the generator

polynomial or simply the generator. Dataword: d(x) Syndrome: s(x) Codeword: c(x) Error: e(x) Generator: g(x)
In a cyclic code, If s(x) 0, one or more bits is corrupted. If s(x) = 0, either a. No bit is corrupted. or b. Some bits are corrupted, but the decoder failed to detect them.

55

Datalink Layer

9/9/2011

Cyclic Code Analysis


Received codeword =c(x) + e(x)
Received codeword = c(x)/g(x) + e(x)/g(x)

56

Datalink Layer

9/9/2011

Checksum
The checksum is used in the Internet by several protocols
although not at the data link layer

It is based upon the concept of redundancy Example


We want to send list of 4-bit numbers (7, 11, 12, 0, 6)

We send (7, 11, 12, 0, 6, 36), where 36 is the sum of original no.
If we send (7, 11, 12, 0, 6, -36), called the checksum

57

Datalink Layer

9/9/2011

Using Ones Complement for Checksum

1 0 0 1

1 1 1 1 0 0 0 0

58

Datalink Layer

9/9/2011

Internet Checksum
Uses 16-bit checksum

Sender site:
1.

2.
3. 4. 5.

The message is divided into 16-bit words. The value of the checksum word is set to 0. All words including the checksum are added using ones complement addition. The sum is complemented and becomes the checksum. The checksum is sent with the data.

59

Datalink Layer

9/9/2011

Checksum
Receiver uses following steps for error detection

Receiver site:
The message (including checksum) is divided into 16-bit words. 2. All words are added using ones complement addition. 3. The sum is complemented and becomes the new checksum. 4. If the value of checksum is 0, the message is accepted; otherwise, it is rejected.
1.

60

Datalink Layer

9/9/2011

Protocols

61

Datalink Layer

9/9/2011

Protocols
Noiseless Channels

62

Datalink Layer

9/9/2011

Simplest Protocol

63

Datalink Layer

The design of the simplest protocol with no flow or error control

9/9/2011

Simplest Protocol

Flow diagram
64 Datalink Layer 9/9/2011

Stop-and-Wait Protocol

65

Datalink Layer

Design of Stop-and-Wait Protocol

9/9/2011

Stop-and-Wait Protocol

66

Datalink Layer

Flow diagram
9/9/2011

Protocols
Noisy Channels

67

Datalink Layer

9/9/2011

Stop-and-Wait ARQ
Error correction in Stop-and-Wait ARQ is done by keeping a

copy of the sent frame and retransmitting of the frame when the timer expires. In Stop-and-Wait ARQ, we use sequence numbers to number the frames.
The sequence numbers are based on modulo-2 arithmetic.

In Stop-and-Wait ARQ, the acknowledgment number always

announces in modulo-2 arithmetic the sequence number of the next frame expected.

68

Datalink Layer

9/9/2011

Stop-and-Wait ARQ

69

Datalink Layer

Design of the Stop-and-Wait ARQ Protocol

9/9/2011

Stop-and-Wait ARQ

70

Datalink Layer

Flow diagram

9/9/2011

Stop-and-Wait ARQ
Efficiency Protocol is inefficient if our channel is thick and long
Thick channel has a large bandwidth

Long the round-trip delay is long

The product of these two is called bandwidth-delay product The bandwidth-delay product
is a measure of the number of bits we can send out of our system

while waiting for news from the receiver.

71

Datalink Layer

9/9/2011

Example
Assume that, in a Stop-and-Wait ARQ system, the bandwidth of the

line is 1 Mbps, and 1 bit takes 20 ms to make a round trip. What is the bandwidth-delay product? If the system data frames are 1000 bits in length, what is the utilization percentage of the link?
Solution The bandwidth-delay product is
The link utilization is only 1000/20,000, or 5 percent

72

Datalink Layer

9/9/2011

Example
What is the utilization percentage of the link in Example if we have

a protocol that can send up to 15 frames before stopping and worrying about the acknowledgments?
Solution The bandwidth-delay product is
The link utilization is only 15,000/20,000, or 75 percent

73

Datalink Layer

9/9/2011

Go-Back-N ARQ
To improve the efficiency of transmission (filling the pipe),
multiple frames must be

in transition while waiting for

acknowledgement
In this protocol
we can send several frames before receiving acknowledgements

we keep a copy of these frames until the acknowledgments arrive

Sequence numbers are modulo-2m (i.e. 0 to 2m-1) Sliding window is an abstract concept that defines the range of

sequence numbers that is the concern of the sender and receiver.


Send sliding window and receive sliding window
74 Datalink Layer 9/9/2011

Go-Back-N ARQ

75

Datalink Layer

Send window for Go-Back-N ARQ

9/9/2011

Go-Back-N ARQ

Receive window for Go-Back-N ARQ


76 Datalink Layer 9/9/2011

Go-Back-N ARQ

77

Datalink Layer

Design of Go-Back-N ARQ

9/9/2011

Go-Back-N ARQ

78

Datalink Layer

Window size for Go-Back-N ARQ

9/9/2011

Go-Back-N ARQ

79

Datalink Layer

Flow Diagram for Go-Back-N ARQ Example Scenario 1

9/9/2011

Go-Back-N ARQ

80

Datalink Layer

Flow Diagram for Go-Back-N ARQ Example Scenario 2

9/9/2011

Selective Repeat ARQ


Go-Back-N ARQ is inefficient for noisy channel
In a noisy link a frame has a higher probability of damage, which

means the resending of multiple frames.


retransmission uses up the bandwidth and slows down the

transmission
Selective Repeat ARQ does not resend N frames when only one

frame is damaged; only the damaged frame is resent

81

Datalink Layer

9/9/2011

Selective Repeat ARQ

82

Datalink Layer

Design of Selective Repeat ARQ

9/9/2011

Selective Repeat ARQ

83

Datalink Layer

Selective Repeat ARQ, window size

9/9/2011

Selective Repeat ARQ

84

Datalink Layer

Flow diagram

9/9/2011

Piggybacking
The three protocols we discussed in this section
data frames flow in only one direction although control info-rmation such

as ACK and NAK frames can travel in the other direction

In real life, data frames are normally flowing in both directions.


Control information also needs to flow in both directions.

A technique called piggybacking is used to improve the efficiency

of the bidirectional protocols. When a frame is carrying data from A to B,


B;
When a frame is carrying data from B to A,

it can also carry control information about arrived (or lost) frames from

it can also carry control information about the arrived (or lost) frames

from A

85

Datalink Layer

9/9/2011

Piggybacking

86

Datalink Layer

Design of piggybacking in Go-Back-N ARQ

9/9/2011

HDLC (High-level Data Link Control)

87

Datalink Layer

9/9/2011

HDLC
It is a bit-oriented protocol for communication over point-

to-point and multipoint links. Configuration and Transfer modes: HDLC provides two common transfer modes that can be used in different configurations:
normal response mode (NRM)
asynchronous balanced mode (ABM)

88

Datalink Layer

9/9/2011

HDLC
Normal Response Mode (NRM)

89

Datalink Layer

9/9/2011

HDLC
Asynchronous Balanced Mode (ABM)

90

Datalink Layer

9/9/2011

HDLC
Frames Three types of frames
Information frames (I-frames) Used to transport user data and control information relating to user data Supervisory frames (S-frames) Used to transport only control information Unnumbered frames (U-frames) Reserved for system management

91

Datalink Layer

9/9/2011

HDLC

HDLC Frames
92 Datalink Layer 9/9/2011

HDLC

Control field format for the different frame types

93

Datalink Layer

9/9/2011

HDLC
Control field for S-Frames Receive Ready (RR)
Code: 00, N(R): acknowledgement number

Receive Not Ready (RNR)


Code: 10, N(R): acknowledgement number

Reject (REJ)
Code: 01, N(R): negative acknowledgement number

Selective Reject (SREJ)


Code: 11, N(R): negative acknowledgement number

94

Datalink Layer

9/9/2011

HDLC

95

Datalink Layer

U-frame control command and response

9/9/2011

HDLC

96

Datalink Layer

Example of connection and disconnection

9/9/2011

HDLC
Example of piggybacking without error

97

Datalink Layer

9/9/2011

HDLC
Example of piggybacking with error

98

Datalink Layer

9/9/2011

Você também pode gostar