74
1 The Data Link Layer Sending Data Over a Communications Link. Schemes for Doing This --- Protocol. Need For Data Link Control: Frame Synchronization Use of a variety of Line Configuration Flow Control Error Control • Addressing Control and Data on Same Link Link Management

The Data Link Layer

Embed Size (px)

DESCRIPTION

The Data Link Layer. Sending Data Over a Communications Link. Schemes for Doing This --- Protocol. Need For Data Link Control: Frame Synchronization Use of a variety of Line Configuration Flow Control Error Control Addressing Control and Data on Same Link Link Management. - PowerPoint PPT Presentation

Citation preview

Page 1: The Data Link Layer

1

The Data Link Layer

Sending Data Over a Communications Link. Schemes for Doing This --- Protocol.

Need For Data Link Control:• Frame Synchronization• Use of a variety of Line Configuration• Flow Control• Error Control • Addressing• Control and Data on Same Link• Link Management

Page 2: The Data Link Layer

2

The Data Link Layer (cont.)

Format of a Frame:

KIND SEQ ACK Information

Control Info.

Page 3: The Data Link Layer

3

Two different representations of the service primitives

The Data Link Layer (cont.)

Networklayer

Datalink

layer

Physicallayer

RequestConfirm

ResponseIndication

(a)

Request

Indication

ResponseConfirm

A B

Service user(network layer)

Serviceprovider

datalink

layer

Service user(network layer)

A B(b)

Page 4: The Data Link Layer

4

Data Link Layer (cont.)

Services Provided to Network Layer:

• Unacknowledged connectionless service.

• Acknowledged connectionless service.

• Connection-oriented service.

Page 5: The Data Link Layer

5

Page 6: The Data Link Layer

6

Data Link Layer (cont.)

•Note: Data are Transmitted One Char At a Time and Timing or Synchronization Must Be Maintained Within Each Char. Overhead 2-3 Bits/Char, Not Good.

Page 7: The Data Link Layer

7

Data Link Layer (cont.)

(b) Bit-oriented frame

SYN SYN

One or moreSYN character

Controlcharacter

Datacharacter

Controlcharacter

(a) Character-oriented frame

8-bitflag

F

Control fields Data field Control field

8-bitflag

Page 8: The Data Link Layer

8

Data Link Layer (cont.)

•Note: Blocks of Chars or Bits are Transmitted

Without Start and Stop Codes. Clocks Must be

Synchronized. Preamble Bit Patterns and

Postamble Used.

Page 9: The Data Link Layer

9

Framing

Beginning and End?

• Character count

• Starting and ending characters, with

character stuffing

• Starting and ending flags, with bit stuffing

• Physical layer coding violations.

Page 10: The Data Link Layer

10

Framing (cont.)

5 1 2 3 4 5 6 7 8 9 8 0 1 2 3 4 5 6 9 7 8 9 0 1 2 3 4

5 1 2 3 4 7 6 7 8 9 8 0 1 2 3 4 5 6 9 7 8 9 0 1 2 3 4

Character countOne

character

Frame 15 character

Frame 25 character

Frame 38 character

Frame 49 character

Error

Frame 1 Frame 2 (Wrong) Now a Character count

A character stream (a) Without error (b) With one error

(a)

(b)

Page 11: The Data Link Layer

11

Framing (cont.)

(a) Data sent by the network layer

(b) Data after being character stuffed by the data link layer(c) Data passed to the network layer on the receiving side

DLE A DLE B DLE ETXSTX

DLE STX A DLE DLE B

DLE A DLE B DLE ETXSTX

DLE ETX

(A)

(B)

(C)

Stuffed DLE

Page 12: The Data Link Layer

12

Framing (cont.)

(a) 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0

(b) 0 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 1 0

(c) 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0Stuffed bits

Bit stuffing.

(a) The original data.

(b) The data as they appear on the line.

(c) The data as they are stored in the receiver's memory after destuffing.

Page 13: The Data Link Layer

13

Error Detection/Correction

Include enough redundant information along with data to use:

•Error correcting codes

•Error Detecting Codes

Parity checks (error detecting)

Page 14: The Data Link Layer

14

Error Detection/Correction (cont.)

• Example: 7-bit ASCII character -- If 1110001 is transmitted using odd parity, then 1 is appended. 11100011 If an odd number of bits is erroneously inverted during transmission, then the receiver will detect an error. However, if an even number of bits is inverted, an undetected error occurs.

• Note: Even parity may also be used. Problem with parity: noise impulses maybe long enough to destroy more than 1 bit, particularly at high data rates. (eg 1200bps)

Page 15: The Data Link Layer

15

Parity Checks (cont.)

• Use 2 sets of parity bits for blocks of characters arranged in 2 dimensions. Parity bits are obtained by performing exclusive OR operation on row and column bits (even parity).

• Example:Char1 1 0 1 1 0 1 1 1Char2 1 1 0 1 0 1 1 1Char3 0 0 1 1 1 0 1 0Char4 1 1 1 1 0 0 0 0Char5 1 0 0 0 1 0 1 1Char6 0 1 0 1 1 1 1 1

0 1 1 1 1 1 1 0 LRC

VRC

VRC: Vertical Redundancy Checks

LRC: Longitudinal Redundancy Checks

Page 16: The Data Link Layer

16

Parity Checks (cont.)

Note: This scheme is 2-4 orders of magnitude better than simple VRC.

Also, some patterns of even number of errors remain undetected (e.g., bits 1 and 3 of Char1 and bits 1 and 3 of Char5)

Page 17: The Data Link Layer

17

Parity Checks (cont.)

Consider:Message with m message bits and r redundant bits,

then the total length n = m + r. Referred to as an n-bit codeword. Given 2 codewords say, 110100 and 110111, we can tell how many corresponding bits differ by performing an exclusive OR on the 2 codewords. In this case, 2 bits differ, so, the Hamming distance = 2.

Error-detection/error correction of a code depends on its Hamming distance of the complete code.

Page 18: The Data Link Layer

18

Parity Checks (cont.)

Note: from the complete list of the legal codewords, the 2 whose Hamming distance is minimum defines the Hamming distance of the complete code.

Example:1001 1000 1100 1011

This code has a distance = 1

Page 19: The Data Link Layer

19

Format of a Frame

• To detect d errors, you need a distance of d+1. • To correct d errors, you need a distance of 2d+1.

Example: 111100 010111 100011 000000• Can detect 2-single bit errors, since its Hamming

distance = 3.Suppose the code 000011 arrives, then an error occurs.

• Can correct 2d+1 = 3 or d = 1 error. Suppose the code 000011 arrives, then the code is corrected to 100011.Could this corrected code still be an error?

Page 20: The Data Link Layer

20

Format of a Frame

Picture code space as vertices of a hypercube.

Use majority rule: –1. If 0 or 1 one bit decide 000–2. If 2 or 3 one bits decide 111

So, we can overcome single errors, but not double errors.

000

001011 111

110100

010

101

Page 21: The Data Link Layer

21

Error Code Correcting

• Example: (4 codewords)

0000000000, 0000011111,1111100000, 1111111111

Hamming distance = 5 2d+ 1=5 or d = 2

Suppose 0000000111 arrives, the receiver knows that the original must have been 0000011111.

• Note: if triple error changes 0000000000 into 0000000111, the error will not be corrected properly.

Page 22: The Data Link Layer

22

Design a code with m message bits and r check bits that will allow all single bit errors to be corrected.

Each of the 2m legal messages has n (n = m + r) illegal codewords a distance 1 from it. So, each of the 2m messages requires n+1 bit patterns dedicated to it. Thus we have

2m(n+1) 2n

==> 2m(1+m+r) 2m+r , note n = m + r

==> 1+m+r 2r

Error Code Correcting (cont.)

Page 23: The Data Link Layer

23

Example: Given m = 4, find the smallest r satisfying the above ineq.

Solution: start with r=1, substitute the values for r+m.1 + 4 + 1 21 r = 1)

6 21 False1 + 4 + 2 22 r = 2)

7 22 False1 + 4 + 3 23 r = 3)

8 23 TRUESo, at least 3 check bits are needed to correct a single

bit error.

Error Code Correcting(cont.)

Page 24: The Data Link Layer

24

Error Code Correcting (cont.)

Char ASCII Check bits

Hamming

code

100100011000011101101110110111010011101110110011101000001100011110111111001001100101

001100100001011100100111101010101111010101010110101100101101010110111110011111001100000011111000011001010111111111100110000111000101

Orderof bittrans-mission

Use of a Hamming code to correct burst error

Page 25: The Data Link Layer

25

Cyclic Redundancy Checks (CRC)

Given a m-bit frame or message, the transmitter generates an r-bit sequence, knows as frame check sequence (FCS), so the resulting frame consists of m+r bits, exactly divisible by some predetermined number. The receiver then divides the incoming frame by the same number, and if there is no remainder, assume that no error occurred.

Ways of presenting this procedure:– Module arithmetic– Polynomials– Shift registers and exclusive OR

Page 26: The Data Link Layer

26

Cyclic Redundancy Checks (CRC) (cont.)

We will use polynomials.Consider the Following Message:

10011 x4 + x + 1, 01001 x3 + 1Note:

Addition and subtraction -- mod2

Example:1 0 0 1 1 x4 + x + 10 1 0 0 1 x3 + 11 1 0 1 0 x4 + x3 + x

Page 27: The Data Link Layer

27

Polynomial Method

Sender and receiver must agree on a generator polynomial, G(x). Both the high-order and low- order bits of the polynomial must be 1.

Let

M(x): polynomial of degree m-1, (m bit message)

G(x): polynomial of degree r, (r+1 bit), where m > r

Page 28: The Data Link Layer

28

Polynomial Method (cont.)

Step 1. Form xr M(x)Step 2. Compute

{xr M(x)}/{G(x)} = Q(x) + {R(x)}/{G(x)}, where R(x) is the remainder or xr M(x) = Q(x)G(x) + R(x).

Step 3. Create the r-bit string (ck-bits) corresponding to R(x), and append it to the message string. T(x) = xr M(x) + R(x). This is the message transmitted.

Note: degree R(x) < degree G(x)

Page 29: The Data Link Layer

29

Polynomial Method (cont.)

Example:Let

G(x) = x3 + x2 + 1; r = 3 1101M(x) = x5 + x2 + x + 1; m = 6 100111

Find check bits:1. x3M(x) = x8 + x5 + x4 + x3 1001110002. Find Q(x), R(x)

Page 30: The Data Link Layer

30

Polynomial Method (cont.)

x3 + x2+1 x8 + x5+ x4 + x3 1101 1001110001101 1001 1101 1001 1101 1000 1101 1010 1101 1110 1101 011

111111

x + 1 CK-Bit

Page 31: The Data Link Layer

31

Polynomial Method (cont.)

Example: (cont.)3. Transmitted message: 100111011 x8+x5+x4+x3+x+1

In general: T(x) = xr M(x) + R(x)However, xr M(x) = G(x) Q(x) + R(x), T(x) = G(x) Q(x) + R(x) + R(x) = G(x) Q(x)

Page 32: The Data Link Layer

32

Polynomial Method (cont.)

Example: 1. Given

message M = 110011 (6 bits)generator G = 11001 (5 bits)FCS R = To be calculated (4 bits)

2. The message is multiplied by 24, yielding 1100110000.

Page 33: The Data Link Layer

33

Polynomial Method (cont.)

3. The product is divide by G: 4. The remainder is added to 2n M to give

T = 1100111001, which is transmitted.

100001110011000011001 10000 11001 1001

11001

Q

2M

R

G

Page 34: The Data Link Layer

34

Polynomial Method (cont.)

Example(cont.): 5. If there are no errors, the receiver receives T

intact. The received frame is divided by G.

Note: Since the remainder = 0, it is assumed that there have been no errors.

100001110011100111001 11001 11001 0

11001

Page 35: The Data Link Layer

35

Polynomial Method (cont.)

T(x) = G(x)Q(x) T(x) is divisible by G(x).

Received Message: T(x) + E(x), where E(x) is error polynomial.

{T(x) + E(x)} / {G(x)} must test for divisibility.

If remainder = 0, decide no error was made, otherwise error.

Page 36: The Data Link Layer

36

Polynomial Method (cont.)

Suppose the error pattern is 100100000 (2 errors), the received message is 000011011 (x4 + x3 + x + 1).

So, an error was made (non-zero)

x4 + x3 + x + 1x4 + x3 + x

1

x3 + x2 + 1x

1 1 0 1 11 1 0 1

1

1 1 0 11

Page 37: The Data Link Layer

37

Error Analysis

How to choose G(x) to detect as many errors as possible? Must consider several cases.

Page 38: The Data Link Layer

38

Case 1: Single Errors

Suppose E(x) = xi (i.e. 1 bit flipped). How can G(x) be selected to detect a single bit error?

Ans: Choose G(x) with at least 2 terms We will get a remainder from {Xi} / {G(x)} Error will be detectedExample: n=6, error pattern = 001000 (E(x) = x3) If G(x) = x + 1, then {E(x)} / {G(x)}

has a remainder.

Page 39: The Data Link Layer

39

Case 2: Double Errors

Note: (xk+1) = (x+1)(x{k-1} + x{k-2} + + 1)

e.g.,: (x4+1) = (x+1)(x3 + x2 + x1 + 1)

Suppose G(x) = x3 + x2 + x + 1 and E(x) = x4 + 1,

then {E(x)} / {G(x)} = x + 1, (no remainder)

So, error is not detected unless G(x) does not divide xk + 1, 1 k n

Page 40: The Data Link Layer

40

Case 3: Odd Number of Errors

Suppose the error pattern has either 1 or 3 or 5, etc. Then E(x) is not divisible by (x+1).

Proof: contradiction

If E(x) has an odd number of terms, and is divisible by x+1, we can write

E(x) = (x+1) E1(x)

E(1) = (1+1) E1 (1) = 0

Page 41: The Data Link Layer

41

Case 3: Odd Number of Errors(cont.)

However, E(1)=0 E(x) has an even number of terms (contradiction). Therefore, if G(x) has the factor (x+1), all error patterns of odd weight will be detected.

Example: E(x) = x6 + x3 + 1, G(x) = (x+1)(x2+1)

= x3 + x2 + x + 1

So, the error pattern is detected.

Page 42: The Data Link Layer

42

Case 4: Burst Errors

Burst errors -- string of bits in an error pattern delimited by 1's.

Example: 000110100100

To analyze burst errors; let bit i be the degree of the lowest bit in the burst (2 above) and write E(x) = xi E1(x) , so E1 (x) has a 1 in the 0th position.

Example: x8 + x7 + x5 + x2 = x2 (x6 + x5 + x3 + 1)

E(x) = xi E1(x)Now, E(x) will not be detected iff E1(x) is divisible by

G(x).

burst of length 7

Page 43: The Data Link Layer

43

Case 4: Burst Errors (cont.)

We know that G(x) does not divide xi (from Case 1).

Also, the degree of G(x) is r and contains (r+1) bits.

If the burst contains r or fewer errors, E1(x) is of

degree (r-1) or less.

So, {E1(x)} / {G(x)} will have a remainder, E1(x), and

the burst errors will be detected.

Page 44: The Data Link Layer

44

Case 4: Burst Errors (cont.)

Example: suppose r=7 and

G(x) = (x5+1) (x2+1) = x7 + x5 + x2 + 1

Now, E(x) = x2 (x6+x5+x3+1) = x2 E1(x)

so, {E1 (x)} / {G(x)} has remainder E1 (x) 0.

Conclude: All burst of length r or less are detected

if:

1. G(x) is of degree r (r+1 bits)

Page 45: The Data Link Layer

45

Case 4: Burst Errors (cont.)

If the length of the burst is r+1, then the burst polynomial, E1(x) must have a 1 in positions r and

0; so does G(x).

The chance of not detecting this burst is the chance of a perfect match between E1 (x) and G(x) in the

remaining (r-1) positions or (1/2)r-1.

Page 46: The Data Link Layer

46

Three polynomial are international standards

• CRC-12 = x12 + x11 + x3 + x2 + x + 1 (C.H. 6 bits)

• CRC-16+ = x16 + x15 + x2 + 1 (C.H. 8 bits)

• CRC-CCITT+ = x16 +x12 + x5 + 1 (C.H. 8 bits)

+: catch all single and double errors, all errors with an odd number of bits, all burst errors of length 16 or less.

Page 47: The Data Link Layer

47

Protocols

Set of rules governing the exchange of data between 2 entities.

• Elements of a Protocol– Syntax -- Include such things as data format, coding,

and signal levels.

– Semantics -- Includes control information for coordination and error handling.

– Timing -- Includes speed matching and sequencing.

Page 48: The Data Link Layer

48

Protocols (cont.)

• 2 major classes of protocols – Character oriented (old)

Example: IBM's BISYNC

– Bit oriented (newer)Example: IBM's SDLC, HDLC developed by

ISO. Note: Transmission via Frames.

– We will emphasize.

Page 49: The Data Link Layer

49

Protocols (cont.)

• Example: Unrestricted Simplex Protocol

Sender:

Receiver:

Go get something to send (buffer)Copy it into info. field for transmissionSend information

Do until doomsday

Frame arrivalGet the inbound framePass data to host

Do until doomsday

Page 50: The Data Link Layer

50

Protocols (cont.)

Note: Simplest possible situation

• Send information in one direction only

• No control fields

• Channel assumed to be perfect

• Receiver can process information infinitely fast

Page 51: The Data Link Layer

51

Protocols (cont.)

• Example: A Simplex Stop-And-Wait ProtocolSender:

Receiver:

Fetch info. from hostCopy it into info. field for transmissionSend information

Do not proceed until given go ahead

Frame arrivalGet the inbound framePass data to host

Do until doomsday

Send dummy frame signal

Page 52: The Data Link Layer

52

Protocols (cont.)

Note:

Same as previous example except, the sender must wait until an acknowledgment frame arrives before fetching the next message.

Page 53: The Data Link Layer

53

Protocol 3-- Simplex Protocol For A Noisy Channel

State Diagram X Y ZSender: X = 0: Send frame 0

= 1: Send frame 1Receiver: Y = 0: Get frame 0

= 1: Get frame 1Channel: Z = 0: Frame 0 in transit

= 1: Frame 1 in transit = A: Frame Ack in transit = --: Empty

Page 54: The Data Link Layer

54

Protocol 3-- Simplex Protocol For A Noisy Channel (cont.)

(a) State diagram for protocol 3. (b) Transitions.

Page 55: The Data Link Layer

55

A Petri netmodel forProtocol 3

Page 56: The Data Link Layer

56

Sliding Window Protocol 4

• Bidirectional -- All IMPs run the same program.• Three functions

– Receive – Send– Pack

• Piggyback acknowledgment

Page 57: The Data Link Layer

57

Sliding Window Protocol 4 (cont.)

A sliding windowof size 1, with a 3-bit sequencenumber

(a) Initially(b) After first frame has been sent(c) After the first frame has been received(d) After the first acknowledgement has been received

Page 58: The Data Link Layer

58

One bit Sliding Window

Page 59: The Data Link Layer

59

3 42 5 6 7 8 9 101 20 3 4 5 6 7 8

10 2 3 4 5 6 7 8E D DD D D D

Timeout intervalA

ck 0

Ack

1

Ack

2A

ck 3

Ack

4A

ck 5

Ack

6A

ck 7

Error

Frames Discarded by data link layer

Time

Sliding Window Protocol 4 (cont.)

(a) Effect of an error when the receiver window size is 1

Page 60: The Data Link Layer

60

Sliding Window Protocol 4 (cont.)

9 102 11 12 13 14

9 10

1 20 3 4 5 6 7 8

10 23 4 5 6 7 8E

Timeout interval

Error Time

11 12

Buffered by data link layer Packets 2-8 Passedto network layer

Ack

0A

ck 1

Ack

1A

ck 1

Ack

1A

ck 1

Ack

1A

ck 1

Ack

8A

ck 9

Ack

10

(b) Effect of an error when the receiver window size is large

Page 61: The Data Link Layer

61

Data Link ControlHDLC frame structure

(a) Frame Format

(b) Control field format

Page 62: The Data Link Layer

62

Data Link ControlHDLC frame structure

(c) Extended address field (d) Extended control field

Page 63: The Data Link Layer

63

Error Control

Automatic Repeat Request (ARQ)

• Stop-and-Wait ARQ

• Go-Back-N ARQ*

• Selective Repeat ARQ*

* Sliding window protocols

Page 64: The Data Link Layer

64

Effect of Propagation Delay and Transmission Rate

d = max distanceV = propagation velocity

2 108 m/s or 3 108 m/s speed of light d/V = & max propagation delay in seconds

R = data rate (bits/second) 1/R = 1 bit time{d / V} / {1 / R} = {Rd / V} max number of bits in

transit = cable length in bits

Page 65: The Data Link Layer

65

Cable Length Example

(1) 500m baseband LAN (107 bits/second)

{500 1072 108bits in flight at a time

(2) 5000m broadband LAN (5 108 bits/second)

{(2 62 108bits

* Note: Signal passes thru headend and back, so 2. Not including headend delay (7-8 bits)

Page 66: The Data Link Layer

66

Cable Length Example

L = Length of frame (or packet)

Length of data path in bitsa =

Length of frame in bits

or Fraction of frame in transit

Max propagation delay or

Transmission time

Page 67: The Data Link Layer

67

Cable Length Example

d/V Rd (bits/sec) (meters)a = = = L/R VL (meters/sec) bits)

Data rate Distanceor

(Prob. Velocity) (Msg Length)

Note: Assuming medium admits one msg at a time

“a” Limits efficiency (Smaller Better)

Page 68: The Data Link Layer

68

Cable Length Example

a < 1 Bit length of link is less than that of the frame.

Example: Satellite Link

270 ms round trip propagation delay,Digital transmission service is 56 kbps,4k bit frame, soTransmission time = 4K/56K = 71ms

a = 270/71 = 3.8u = 1 /{1+2(3.8)} or 0.12 (poor)

Page 69: The Data Link Layer

69

0.1 0.5 0.9 1.0

0.1

0.5

0.9

1.0 a = 0

a = 0.1

a = 1

a = 10

G, offered load

Thruput

Effect of “a”on ideal zero overhead LAN

Page 70: The Data Link Layer

70

Total Time To Send Data

TD = TI + n TF, where

TI = Time to initiate Seq.

TF = Time to send one frameNote:

TI = tprop + tpoll + tproc (drop)

TF = tprop + tframe + tproc + tprop + tack + tproc (drop)

We ignore a few terms and write:

TD = n (2 tprop + tframe)

Of that time, only n tframe is actually spent

Page 71: The Data Link Layer

71

Total Time To Send Data

transmitting data and the rest is overhead

n tframe u =

n (2 tprop + tframe)

Now, let a = tprop / tframe

u = 1 / (1 + 2a)

Page 72: The Data Link Layer

72

The effect of a on utilization

Page 73: The Data Link Layer

73

Efficiency of the channel depends on both N, the window size, and a

Case 1: N > 2a + 1.Frame ACK reaches station A before it has exhausted its window. Thus A can transmit without pause u = 1

Case 2: N < 2a + 1Station A exhaust its window at t0 + N and

cannot send additional frames until t0 + 2a + 1. Thus, the utilization is N time units out of a period of (2a + 1) time units. u = N / (2a + 1)

Sliding Window

Page 74: The Data Link Layer

74

Line Utilization as a function of window size

0.1 1 10 100 1000

0.0

0.2

0.4

0.6

0.8

1.0

N=127

N=7

N=1

Utilization

a