Data Link Layer Functionality - Computer Sciencebadri/352dir/Spring04/notes/week2-four.pdf · DLE...

16
1 Data Link Layer 2 Data Link Layer Functionality Services provided by the link layer Frame creation Error detection and/or correction Flow control Reliable delivery Creating the illusion of a reliable link 3 Framing The data unit at the data link layer is called a “frame” A frame is a group of bits, typically in sequence Issues: Frame creation Frame delineation 4 Frame Delineation How to tell when a new frame starts: Frame tags with character stuffing Frame tags with bit stuffing

Transcript of Data Link Layer Functionality - Computer Sciencebadri/352dir/Spring04/notes/week2-four.pdf · DLE...

1

1

Data Link Layer

2

Data Link Layer Functionality

Services provided by the link layerFrame creationError detection and/or correctionFlow controlReliable delivery

Creating the illusion of a reliable link

3

Framing

The data unit at the data link layer is called a “frame”A frame is a group of bits, typically in sequenceIssues:

Frame creationFrame delineation

4

Frame Delineation

How to tell when a new frame starts:Frame tags with character stuffingFrame tags with bit stuffing

2

5

Frame tagging with character stuffing

Use starting and ending characters (tags) to mark boundaries of frameProblem: What if tag characters occur in the data or control portions of the frame?

Frame tags (special characters)

6

Character stuffing

Insert extra escape characters when a tag appears in data field

STXDLE

ETXDLE

DLEDLE

Start Tag

End Tag

Character Stuffed DLE code

7

Character Stuffing Example

DLEI am a jerk trying to DLE crash your network! ETX

DLEI am a jerk trying to DLE crash your network! ETXSTXDLE DLE DLE ETXDLE

DLEI am a jerk trying to DLE crash your network! ETX

Tagging and Character Stuffing

Untagging and Character Unstuffing

8

Character StuffingPPP

PPP = Point-to-Point Protocol, used widely in the InternetPPP uses frame tags with character or byte stuffing

01111110 Control Fields Payload (up to 1500 bytes) Checksum 01111110

PPP Frame Format

Character Frame Tags

3

9

Frame tagging with bit stuffing

Bit strings may be used instead of character sequences to delineate framesMore efficient

10

Bit stuffing

Each frame begins with a start and end bit sequence, e.g., 01111110When sender’s data link layer sees five 1’s in a row, it stuffs a zero bitThe receiver “unstuffs” a zero after five consecutive 1’s.

11

Bit unstuffing

When a pattern of five 1s appears, examine sixth bitIf the sixth bit is 0, remove it (stuffed bit)If the sixth bit is 1, check seventh bit

If 0, accept as flag (BOF or EOF)If 1, error

12

Bit Stuffing Example

Tagging and Bit Stuffing

Untagging and Bit Unstuffing

00110010111111100010100

0111111000110010111110110001010001111110

00110010111111100010100

4

13

Bit StuffingHDLC

HDLC = High-level Data Link Control. Used in X.25 networksHDLC uses frame tags with bit stuffing

01111110 Control Fields Payload (arbitrarily long) Checksum 01111110

HDLC Frame Format

Character Frame Tags

14

Error Control

No physical link is perfectBits will be corruptedWe can either:

detect errors and request retransmissionor correct errors without retransmission

15

Error Detection

Parity bitsPolynomial codes or checksums

16

Parity bits

Append a single parity bit to a sequence of bitsIf 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

5

17

Parity bits: Example

00010101 even

01111 even

11111111 odd

10011 odd

TransmittedSequence Parity

ParityBit

18

Parity Bits

Only detects when there are an odd number of bit errorsDoes not detect an even number of bit errorsIt also has high overhead; it requires 1 extra bit for every several bits transmitted

19

Checksum

Consider data as 16 bit words.Add all the data values (1s complement of this sum is the checksum)Receiver adds all the words and the checksum. If no errors, then sum is all 1s

20

Polynomial Codes

Can detect errors on large chunks of dataHas low overheadMore robust than parity bitRequires the use of a “code polynomial”

Example: x2 + 1

6

21

Cyclic Redundancy Check

CRC: Example of a polynomial codeProcedure: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

22

Generating a CRCExample

Message: 1011 1 x x3 + 0 x x2 + 1 x x + 1 = x3 + x + 1

Code Polynomial: x2 + 1 (101)

Step 1: Compute S(x)

r = 2

S(x) = 101100

23

Generating a CRCExample (cont’d)

Step 2: Modulo 2 divide

101100101101

001000

010000

10010101

1001

Remainder

24

Generating a CRCExample (cont’d)

Step 3: Modulo 2 subtract the remainder from S(x)

101100- 01101101

Checksummed Message

7

25

Decoding a CRC

Procedure1. Let n be the length of the checksummed message

in bits2. Divide the checksummed message by the code

polynomial using modulo 2 division. If the remainer is zero, there is no error detected.

26

Decoding a CRCExample

101101 Checksummed message (n = 6)

1011 Original message (if there areno errors)

101101101101

001000

010000

10110100

1001

Remainder = 0(No error detected)

27

Decoding a CRCAnother 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.

101001101101

000000

000000

00100001

1000

Remainder = 1(Error detected) 28

Choosing a CRC polynomial

The longer the polynomial, the smaller the probability of undetected errorCommon 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

8

29

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

30

Controlling the Flow of Data

Slow JoeFast Frank

31

Some Flow Control Algorithms

Flow control for the ideal networkStop and Wait for noiseless channelsStop and Wait for noisy channelsSliding window protocolsSliding window with error control

– Go Back N– Selective Repeat

32

Flow control in the ideal network

Assumptions:Error free transmission link,Infinite buffer at the receiver

No acknowledgement of frames necessarySince the data link is error-free and the receiver can buffer as many frames as it likes, no frame will ever

be lost

9

33

Flow control in the ideal network (cont’d)

Slow JoeFast Frank

Infinite bucket

34

Stop and Wait with Noiseless Channels

Assumptions:Error free transmission link,Finite buffer at the receiver

Problem of Buffer overflow at the receiverBuffer overflow may happen at the receiver when the sending router sends frames at a rate faster than the receiving router

35

Stop and Wait with Noiseless Channels (cont’d)

Slow JoeFast Frank

Finite bucket (once full, ball is lost)

36

Stop and Wait with Noiseless Channels (cont’d)

Solution: Stop-and-WaitThe 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.

10

37

Stop and Wait with Noiseless Channels (cont’d)

Data

ACK

Data

38

Stop and Wait (cont’d)

Note that we assume an error-free transmission link and therefore ACK frames will not be lostIn 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.

39

Stop and Wait for Noisy Channels

Assumptions:Transmission link may cause errors in frames,

Finite buffer at the receiver

ACK frames may now be lost

40

Problems introduced by a noisy line

Problem 1: Loss of a data or ACK frameSince the transmission link is not error-free, a data or ACK frame may be lost, causing the sender to wait indefinitely for an ACK

11

41

Loss of an ACK frame

ACK

Data

error

?42

Problems introduced by a noisy line

Can we solve problem 1 by introducing a timeout period for the sender? Yes, but...

Problem 2: Duplicated framesIf 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

43

Duplicated data frames

Data

ACK

Data

TimedOut

Duplicate data

44

Stop and Wait for Noisy Channels (cont’d)

Solution:The sender uses a timer to retransmit data frames when an ACK has not arrivedThe 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.

12

45

Stop and Wait for Noisy Channels (cont’d)

Data

ACK

Data1

1

11

TimedOut

receiverknows to discard thisdata

1

46

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 time2. When waiting for an acknowledgement, the sender

cannot transmit any frames

Better solution? Sliding Window

47

Sliding Window ProtocolsDefinitions

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

48

Simple Sliding Window with Window Size of 1

A sliding window with a maximum window size of 1 frame

Window for a 3-bit sequence number

0

1

2

34

5

6

7

13

49

Sliding Window example0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

Sender window

Receiver window

(a) (b) (c) (d)

(a) Initial state, no frames transmitted, receiver expects frame 0(b) Sender transmits frame 0, receiver buffers frame 0(c) Receiver ACKS frame 0 (d) Sender receives ACK, removes frame 0

50

Simple Sliding Window withWindow size 1 (cont’d)

This protocol behaves identically to stop and wait for a noisy channel

51

Sliding Window ProtocolsGeneral Remarks

The sending and receiving windows do not necessarily have the same maximum sizeAny frame whose sequence number falls outside the receiver window is discarded at the receiverThe sender window’s size grows and shrinks as frames are transmitted and acknowledgedUnlike the sender window, the receiver window always remains at its maximum size

52

Sliding Window ProtocolsPiggybacking Acknowledgements

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

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.

14

53

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

54

Sender-Side Window with WS=2

0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

(a) (b) (c) (d)

(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

55

Pipelining

Sliding window with WS > 1 is also called “pipelined” communication

A B99

data stream51 50

4910

ACK stream

By allowing several frames onto the link before receiving an acknowledgement, pipelining keeps the link from

being idle

56

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

15

57

Receiver-Side Window with WR=2

0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7 0

1

2

34

5

6

7

(a) (b) (c) (d)

(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

58

What about Errors?

What if a data or acknowledgement frame is lost when using a sliding window

protocol?

Two Solutions:Go Back N

Selective Repeat

59

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 ACKThe sender will eventually time out and retransmit all the frames in its sending window

60

Go Back N

Discarded byreceiver

Frame witherror

Timeout interval

ACK

0

Time

Sender

Receiver

Maximumwindow size = 8

Maximumwindow size = 8

0

0 1

1

ACK

1

2

E

3

D

4

D

2 3

2

ACK

2

4 5 6

3 4 5

ACK

3

ACK

4

ACK

5

6

ACK

6

16

61

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

62

Sliding Window with Selective Repeat

The sender retransmits only the frame with errorsThe 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 numberWhen the sender times out waiting for an acknowledgement, it just retransmits the one unacknowledged frame, not all its successors.

63

Selective Repeat

Buffered byreceiver

Frame witherror

Timeout interval

ACK

0

Time

Sender

Receiver

Maximumwindow size = 8

Maximumwindow size = 8

0

0 1

1

ACK

1

2

E

3 4 2 5

2

ACK

4

6

5

ACK

5

6

ACK

6

3 4

ACK

1

ACK

1