the data link layer

57
09/27/2007 EETS 7304 1 The Data Link Layer Chapter 3

Upload: jolie-vargas

Post on 30-Dec-2015

19 views

Category:

Documents


2 download

DESCRIPTION

The Data Link Layer. Chapter 3. Functions of the Data Link Layer. Framing Error Control: dealing with transmission errors Flow Control: regulating data flow (through acknowledgments) so that slow receivers are not swamped by fast senders. Relationship between packets and frames. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Data Link Layer

09/27/2007 EETS 7304 1

The Data Link Layer

Chapter 3

Page 2: The Data Link Layer

09/27/2007 EETS 7304 2

Functions of the Data Link Layer

• Framing• Error Control: dealing with transmission

errors• Flow Control: regulating data flow (through

acknowledgments) so that slow receivers are not swamped by fast senders.

Page 3: The Data Link Layer

09/27/2007 EETS 7304 3

Relationship between packets and frames

Page 4: The Data Link Layer

09/27/2007 EETS 7304 4

Services Provided to Network Layer

(a) Virtual communication.(b) Actual communication.

Page 5: The Data Link Layer

09/27/2007 EETS 7304 5

DLL within a router

Page 6: The Data Link Layer

09/27/2007 EETS 7304 6

Framing with character count

A character stream:

(a) Without errors: first byte contains the message length (in bytes).

(b) With one error: receiver looses synchronization and cannot recover.

Page 7: The Data Link Layer

09/27/2007 EETS 7304 7

Framing with ‘esc’ character: byte stuffing

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

Page 8: The Data Link Layer

09/27/2007 EETS 7304 8

PPP

7E 7D 5E 7D 5D 7E

7E 7D

ESC

IP datagram

Flag 7E

Contr 03

protocol

0021

1 1 1 2 up to 1500 2 1

CRCdataaddr FF

Flag 7E

Link control dataC021

network control data8021

Byte stuffing

Frame format

Page 9: The Data Link Layer

09/27/2007 EETS 7304 9

Framing with zero insertion (HDLC)

(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.

Flag bit pattern: 0 1 1 1 1 1 1 0Zero insertion eliminates flag bit pattern to appear in the output

text

Page 10: The Data Link Layer

09/27/2007 EETS 7304 10

Error Detection and Correction(using additional bits)

• Error-Correcting Codes (used in voice communication)

• Error-Detecting Codes (used in data communication)Sender receives a positive acknowledgment if data received correctly and negative ack to ask for retransmission.

• What to do if sent frame is completely lost?Solution is to use a timer slightly larger than round-trip delay. If sender doesn’t receive ack it retransmits.

There is a possibility that receiver receives the same frame twice. To avoid that the frames are numbered in increasing order and each frame carries this (sequence) number.

Page 11: The Data Link Layer

09/27/2007 EETS 7304 11

Hamming DistanceHamming distance d: the number of bits in which two words differ. To mistaken one word with the other at least d bits must be in error.

Hamming distance of the code: the minimum Hamming distancebetween any two code words.

For error detection with d bit error the code must have distance d+1.

S1 S2

d

d + 1

d

For error correction with d bit error the code must have distance 2d+1.

R S1 S2 are two valid code words. R isthe word received. Since not within theset of valid words it is an error. We have no way to say whether R is S1 or S2.Hence error detection.

Page 12: The Data Link Layer

09/27/2007 EETS 7304 12

Error Correction

S1 S2

d

2d + 1

d

Code with hamming distance 2d + 1 is capable of error correction within d or less erroneous bits.If R is received we say that the sending code word is S2.

R

Page 13: The Data Link Layer

09/27/2007 EETS 7304 13

Hamming code corrects single bit errors

000

101

011

110

100

010

001

111 m - word bitsr - check bitsn = m + r code bits

Example:m = 1n = 3r = 2

For single bit error correction: each valid word has n bit pattern dedicated to it (obtained by one bit change in a valid word).Therefore

(n+1)*2m <= 2n.

(m + r + 1)*2m <= 2m+r.

m+r+1 <= 2r

m r1 2 complete2 33 34 3 complete7 4

1000 10

Page 14: The Data Link Layer

09/27/2007 EETS 7304 14

Hamming (11,7) Code

p1 p2 d1 p3 d2 d3 d4 p4 d5 d6 d7

Data word (without parity) 1 0 0 1 0 0 0

p1 0 1 0 1 0 0

p2 0 1 0 1 0 0

p3 1 0 0 1

p4 0 0 0 0

Data word (with even parity) 0 0 1 1 0 0 1 0 0 0 0

p1 p2 d1 p3 d2 d3 d4 p4 d5 d6 d7Parity check Parity

bit

Received word 0 0 1 1 0 0 1 0 0 0 1

p10 1 0 1 0 1 fail 1

p20 1 0 1 0 1 fail 1

p31 0 0 1 pass 0

p40 0 0 1 fail 1

Coding

Decoding: the position of error bit = 8*p4 + 4*p3 + 2*p2 + p1 -> 8 + 2 + 1 = 11.

Page 15: The Data Link Layer

09/27/2007 EETS 7304 15

Use of a Hamming code to correct burst errors

Words are sent leftmost column first then the next column etc. If the burst error (burst <= 12) occurs it can be recovered by Hamming correction code.

Page 16: The Data Link Layer

09/27/2007 EETS 7304 16

Cyclic Redundancy Check Error Detecting Codes

Only words (represented as a single number) that are divisible by given

divisor are valid. In modulo arithmetic there is finite number of these

words. They are evenly spaced (equidistant from each other). Say all

number up to 100 divisible by 7 are legal.

Coding: transform message M word into code word T using generator

polynomial G.

Assume we want to send M = 50.

1. Multiply M*10 -> 500 (10 is the order of G)

2. Divide M*10 : G -> 500 : 7 = 71 + 3/7 -> 500 = 71*7 + 3 (remainder)

3. Subtract remainder from M*10 -> T = 500 – 3 = 497 (certainly divisible by 7).

Decoding: T/G -> 497/7 = 71 (good word divisible by 7)

Page 17: The Data Link Layer

09/27/2007 EETS 7304 17

CRC codes

G(x) is generating polynomial of degree r.

M(x) is a message word of degree m > r.

Coding

1. Append r 0’s to the M(x) -> xr M(x).

2. Divide modulo 2: xr M(x) : G(x) = Q(x) + R(x)/G(x)

3. T(x) = xr M(x) - R(x). (Certainly divisible by G(x))

On the next slide G(x) = x4 + x + 1 = 10011 -> r = 4.

M(x) = x9 + x8 + x6 + x4 + x3 + x + 1 = 1101011011 -> m = 9.

1. x4M(x) = 11010110110000

2. R(x) = x4M(x) : G(x) = 1110 = x3 + x2 + x < G(x)

3. T(x) = x4M(x) + R(x) = 11010110111110 (certainly divisible by G(x)).

Page 18: The Data Link Layer

09/27/2007 EETS 7304 18

Calculation of the polynomial code checksum.

Page 19: The Data Link Layer

09/27/2007 EETS 7304 19

Analysis of CRC coding: choice of G(x)

Decoding:Receiver calculates the remainder: (T(x) + E(x))/G(x) = E(x)/G(x).1. Single bit error: E(x) = xi . If G(x) contains 2 or more terms xi will never be divisible by

G(x) => single error is always detected.2. Double error: E(x) = xi + xj = xj(xi-j + 1) -> xk + 1 (0 < k < frame length)3. G(x) = x15 + x14 + 1 detects double errors up to 32768 frame length.….4. Polynomial coding with r check bits will detect all burst errors with the burst error length

<= r.

CRC calculations are performed on a fly by shift registers with feedback that is determined by G(x).

Page 20: The Data Link Layer

09/27/2007 EETS 7304 20

Elementary Data Link Protocols

• An Unrestricted Simplex Protocol

• A Simplex Stop-and-Wait Protocol

• A Simplex Protocol for a Noisy Channel

Page 21: The Data Link Layer

09/27/2007 EETS 7304 21

protocol.h (type declarations)

Continued

Page 22: The Data Link Layer

09/27/2007 EETS 7304 22

protocol.h (function declarations)

Page 23: The Data Link Layer

09/27/2007 EETS 7304 23

Unrestricted Simplex Protocol

sender1 receiver1

data-frame

data-frame

Message Sequence Chart

Page 24: The Data Link Layer

09/27/2007 EETS 7304 24

Simplex Stop-and-Wait Protocol

Sender waits for ack before sendingnext frame.

sender2 receiver2

data-frame

data-frame

ack-frame

ack-frame

Message Sequence Chart

Page 25: The Data Link Layer

09/27/2007 EETS 7304 25

A Simplex Protocol for a Noisy ChannelA Positive Ack with Retransmission PAR

or Automatic Repeat

reQuest ARQ

Continued

Introduction of sendingsequence number.

sender3 receiver3

I(0)

I(1)

A(0)

A(1)

Message Sequence Chart

time-out

Page 26: The Data Link Layer

09/27/2007 EETS 7304 26

A Simplex Protocol for a Noisy Channel (cont.)

sender3 receiver3

I(0)

I(1)

A(0)

A(1)

Message Sequence Chart

time-out

Page 27: The Data Link Layer

09/27/2007 EETS 7304 27

Sliding Window Protocols

So far protocol is correct, however, with poor performance (= channel utilization).

• A One-Bit Sliding Window Protocol• A Protocol Using Go Back N• A Protocol Using Selective Repeat

Page 28: The Data Link Layer

09/27/2007 EETS 7304 28

Sliding Window Protocols (2)

A sliding window of size 1, with a 3-bit sequence number.(Shadowy segment means pending.)(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.

Page 29: The Data Link Layer

09/27/2007 EETS 7304 29

A One-Bit Sliding Window Protocol

Continued

Page 30: The Data Link Layer

09/27/2007 EETS 7304 30

A One-Bit Sliding Window Protocol (cont.)

Page 31: The Data Link Layer

09/27/2007 EETS 7304 31

A One-Bit Sliding Window Protocol (2)

Two scenarios for protocol 4. The notation is (seq, ack, packet number).

An asterisk indicates where a network layer accepts a packet.

(a) Normal case.

(b) Abnormal case (messages sent twice: not error but waste of bandwidth).

Page 32: The Data Link Layer

09/27/2007 EETS 7304 32

Pipelining for long round-trip delays

20 ms Frame length = 1000 bitsSpeed = 50 bpsRound-trip delay = 500 ms Trans time = 20 ms Channel efficiency = 20/520 = 4%

25 additional frames can be sent

In general:Frame length = l bitsSpeed = b bpsRound-trip delay = R ms

Channel efficiency = l/(l + bR) Window size = (R + l/b)/(l/b) = Rb/l + 1

= number of outstanding (unacklnowledged frames).

520

ms

fr1

ack1

fr3

fr26

t

Page 33: The Data Link Layer

09/27/2007 EETS 7304 33

Pipelining and error recovery

(a) Go back n

delivers in sequence

without buffering.

(b) Selective repeat

Receiver must have

buffer of window size.

Page 34: The Data Link Layer

09/27/2007 EETS 7304 34

Sliding Window Protocol Using Go Back N

Continued

b

ac

Page 35: The Data Link Layer

09/27/2007 EETS 7304 35

Sliding Window Protocol Using Go Back N

Continued

Page 36: The Data Link Layer

09/27/2007 EETS 7304 36

Sliding Window Protocol Using Go Back N

Continued

Page 37: The Data Link Layer

09/27/2007 EETS 7304 37

Sliding Window Protocol Using Go Back N

Page 38: The Data Link Layer

09/27/2007 EETS 7304 38

Sliding Window Protocol Using Go Back N (2)

Simulation of multiple timers in software.

Page 39: The Data Link Layer

09/27/2007 EETS 7304 39

A Sliding Window Protocol Using Selective Repeat

Continued

Page 40: The Data Link Layer

09/27/2007 EETS 7304 40Continued

A Sliding Window Protocol Using Selective Repeat (2)

Page 41: The Data Link Layer

09/27/2007 EETS 7304 41

A Sliding Window Protocol Using Selective Repeat (3)

Continued

Page 42: The Data Link Layer

09/27/2007 EETS 7304 42

A Sliding Window Protocol Using Selective Repeat (4)

Page 43: The Data Link Layer

09/27/2007 EETS 7304 43

A Sliding Window Protocol Using Selective Repeat (5)

(a) Initial situation with a window size seven.

(b) After seven frames sent and received, but not acknowledged.

(c) Initial situation with a window size of four.

(d) After four frames sent and received, but not acknowledged.

Page 44: The Data Link Layer

09/27/2007 EETS 7304 44

Protocol Verification

• Finite State Machined Models• Petri Net Models

Page 45: The Data Link Layer

09/27/2007 EETS 7304 45

Finite State Machined Models

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

Page 46: The Data Link Layer

09/27/2007 EETS 7304 46

A Petri net with two places and two transitions

Page 47: The Data Link Layer

09/27/2007 EETS 7304 47

A Petri net model for protocol 3

Page 48: The Data Link Layer

09/27/2007 EETS 7304 48

Example Data Link Protocols

• HDLC – High-Level Data Link Control• The Data Link Layer in the Internet

Page 49: The Data Link Layer

09/27/2007 EETS 7304 49

High-Level Data Link Control

Frame format for bit-oriented protocols.

Page 50: The Data Link Layer

09/27/2007 EETS 7304 50

High-Level Data Link Control (2)

Control field of

(a) An information frame.

(b) A supervisory frame (ack, nack).

(c) An unnumbered frame.

Page 51: The Data Link Layer

09/27/2007 EETS 7304 51

The Data Link Layer in the Internet

A home personal computer acting as an internet host.

Page 52: The Data Link Layer

09/27/2007 EETS 7304 52

LAPD frames (Byte Oriented with padding)

8 7 6 5 4 3 2 1

opening flag0 1 1 1 1 1 1 0

address low

address high

Cyclic Redun- dancy Check

SAPI C/R

TEI

EA

EA

PN_R

N_S 0 control high

control low

Information

CRC high

CRC low

closing flag

bits

octets

1 2 3 4 5 N-2 N-1 N

opening flag

address low

address high

Cyclic Redun- dancy Check

C/RSAPI

TEI

EA

EA

1 1 control

CRC high

CRC low

closing flag

bits

octets

1 2 3 4 5 6 7

M M M P/F M M

opening flag

address low

address high

Cyclic Redun- dancy Check

C/RSAPI

TEI

EA

EA

P/FN_R

0 1 control high

control low

CRC high

CRC low

closing flag

bits

octets

1 2 3 4 5 6 7 8

x x x x S S

I - frame: SAPI - Service Access Point Identifier C/R - Comand/Response bit EA - Extension bit N_S - Send frame seq number N_R - Receved frame seq number

U - frame: M - Modifier function bit P/F - Poll/Final bit

S - frame:

0 1 1 1 1 1 1 0

0 1 1 1 1 1 1 0

0 1 1 1 1 1 1 0

0 1 1 1 1 1 1 0

0 1 1 1 1 1 1 0

8 7 6 5 4 3 2 1

8 7 6 5 4 3 2 1

Page 53: The Data Link Layer

09/27/2007 EETS 7304 53

LAPD Counters and Algorithm

Transmit: if ((V(A) -1 - V(S)) mod window_size) > 0:N(S) <- V(S); V(S) <- (V(S)+1) mod (window size); N(R) <- V(R); send message

Receive:receive messageV(A) <- N(R); stop if RRV(R) <- N(S);V(R) <- (V(R)+1) mod (window size);

1

2

34

5

6

70

1

2

34

5

6

70

V_S

V_R

1

2

34

5

6

70

V _A

1

2

34

5

6

70

1

2

34

5

6

70

V_S

V _R

1

2

34

5

6

70

V _A

N_S := 2

N_R := 4

N_S := 4

N_R := 3

Term inal A Term inal B

Page 54: The Data Link Layer

09/27/2007 EETS 7304 54

PPP – Point to Point Protocol

The PPP full frame format for unnumbered mode operation.

Page 55: The Data Link Layer

09/27/2007 EETS 7304 55

PPP – Activation State Diagram

Page 56: The Data Link Layer

09/27/2007 EETS 7304 56

PPP – Point to Point Protocol (3)

Page 57: The Data Link Layer

09/27/2007 EETS 7304 57

Ethernet 802.3

• Preamble (PRE). The PRE is an alternating pattern of ones and zeros.• Start-of-frame delimiter (SFD). The SOF is an alternating pattern of ones

and zeros, ending with two consecutive 1-bits. • Destination address (DA). Source addresses (SA). • Length/Type indicates either the number of MAC-client data bytes that

are contained in the data field of the frame, or the frame type ID if the frame is assembled using an optional format.

• Data n bytes (46=< n =<1500) of any value. (The total frame minimum is 64bytes.)

• Frame check sequence (FCS) 32-bit cyclic redundancy check (CRC) value, which is created by the sending MAC and is recalculated by the receiving MAC to check for damaged frames.

7 1 6 6 2 46-1500 4

Pre SFD DA SA Length/type Data FC