the data link layer

52
The Data Link Layer Chapter 3

Upload: carla-schultz

Post on 30-Dec-2015

28 views

Category:

Documents


3 download

DESCRIPTION

The Data Link Layer. Chapter 3. Data Link Layer Design Issues. Services Provided to the Network Layer Framing Error Control Flow Control. Functions of the Data Link Layer. Provide service interface to the network layer Dealing with transmission errors Regulating data flow - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Data Link Layer

The Data Link Layer

Chapter 3

Page 2: The Data Link Layer

Data Link Layer Design Issues

• Services Provided to the Network Layer• Framing• Error Control• Flow Control

Page 3: The Data Link Layer

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

• Services provided:• Unacknowledged connectionless service

(e.g. if error rate low, for voice transmission, or for LANs)• Acknowledged connectionless service (e.g. for wireless systems: retransmissions are possible)• Acknowledged connection-oriented service

frames guaranteed to be received in right order and exactly once 3 phases: initialization, transmission, release

Page 4: The Data Link Layer

Functions of the Data Link Layer (2)

Relationship between packets and frames.

Page 5: The Data Link Layer

Services Provided to Network Layer

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

Page 6: The Data Link Layer

Services Provided to Network Layer (2)

Placement of the data link protocol.

Page 7: The Data Link Layer

Framing

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

Page 8: The Data Link Layer

Framing (2)

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

Page 9: The Data Link Layer

Framing (3)

Bit stuffing (e.g. 01111110 is delimiter)

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

Page 10: The Data Link Layer

Error Detection and Correction

• Types of Errors

• Error-Correcting Codes

• Error-Detecting Codes

Page 11: The Data Link Layer

Types of ErrorsSingle-Bit Error:

Burst Error:

(a)

(b)

Page 12: The Data Link Layer

Redundancy All error detection/correction methods are based on redundancy

Page 13: The Data Link Layer

Error Detection• Four basic detection methods:

• Vertical Redundancy Check (VRC)• Longitudinal Redundancy Check (LRC)• Cyclic Redundancy Check (CRC)• Checksum

• VRC (Parity Bit Method):

Single-Bit errors are always detected.Burst errors detected, if number of errors is odd.

Page 14: The Data Link Layer

11100111 11011101 00111001 10101001

1110011111011101001110011010100110101010

11100111 11011101 00111001 10101001 10101010

Original data plus LRC

Original data

LRC

LRC

LRC detects burst errors better than VRC: Bursts less than number of columns are detected with a high probabilitySome error patterns remain undetected: e.g. 2 bits in the same position but in different rows change their values

Page 15: The Data Link Layer

CRC

r bits

r bits

r+1 bits

Page 16: The Data Link Layer

• CRC Algorithm:• Let M be the frame to be sent. M is interpreted as a binary number.

• Let G (divisor) be a binary number agreed on between sender and receiver. G should have r + 1 bits (G is the so-called generator polynomial of degree r).

• Append r zero bits to right-end of the frame M and get f:

f = M.2r

• Divide the “bit string” f by G (using modulo 2 division):

f = p.G + R (R has r or fewer bits and is the CRC)

• Get T = f + R (= f – R = p.G, which is divisible by G)

• T is now the checksummed frame to be transmitted.

CRC

Page 17: The Data Link Layer

CRC

G

M

Message transmitted: T = 100100001

Example:

Page 18: The Data Link Layer

CRCWhy polynomials?

Standard polynomials:

(IEEE 802)

Page 19: The Data Link Layer

CRC

• CRC Performance:• Assume an error is described as a bit string E:

e.g. E = 001010 means 2 error in second and fourth bit (from the right)

• Receiver gets: T + E

• Since T is divisible by G, E/G will determine whether or not an error can be detected.

• Cases:• Single-Bit Error: E = 2i for some i.

Choose G with 2 or more terms (e.g. G = 2p +1). G does not divide 2i

• Two-Bit Error: E = 2i + 2j = (2i-j +1)2i (with i > j).

G should include 2p + 1(to avoid the 2i term, see above)

Also, G should not divide 2i-j +1 for any (i-j=) k <= frame length

For example: G = 215 +214 +1 works for frames with length <= 32768

• E has an odd number of 1s:

Choose a G - as a number - that is divisible by 3

Page 20: The Data Link Layer

CRC

• CRC Performance (contd):• Burst Error: E = (2k-1 + … + 1).2i (E of length k).

G should be odd (i.e. it ends with 1) to avoid the factor 2i

Cases:

• k-1 < r: burst length less than length of G:

Error always detected, since A mod B != 0 for any A < B and A != 0

• k-1 = r: burst length equal length of G:

Error is not detected iff E = G. However, because G begins/ends with 1, only the middle k-2 (= r-1) bits are decisive in this case. This constellation happens then with probability 1/2r-1

• k-1 > r: burst is arbitrarily long:

The length of the remainder (of E/G) is r. Hence, the probability of the error not being detected is 1/2r (remainder has r zeros)

Page 21: The Data Link Layer

CRC• Hardware Implementation:

• Shift register of length r initialized to zero.

• XOR gates added between cells where there is 1 in G (except for leftmost 1)

• In each step, a bit is read from the message, the XOR operations activated, and then the shift operations.

• Our example:

0 0 0 100100000Adder

1 1 110

Register Data

1. 000 100100000

2. 001 00100000

3. 010 0100000

4. 100 100000

5. 100 00000

6. 101 0000

7. 111 000

8. 011 00

9. 110 0

10. 001

remainder

Page 22: The Data Link Layer

Checksum

Page 23: The Data Link Layer

Error Correction

• Two methods:• Sender-based: First error detection, then ask sender to retransmit data in case

of an error.• Automatic or Receiver-based: Here, receiver tries to find out after an error

what the correct data might have been. Error-correcting codes

• In theory, it is possible to correct any detected error automatically, however, this is not done in practice, because it requires lots of redundancy (which is overhead).

• How many redundant bits are needed to allow for correction?• Example for single-bit errors:

• ASCII character = 7 Bits• Situations: No error, Error in 1st bit, Error in 2nd bit, …, Error in 7th bit.• At first glance, we would need 3 redundant bits to perform correction.• However, errors can affect the redundant bits, too.

Page 24: The Data Link Layer

Error Correction

• How many redundant bits are needed? (Contd)

• Number of redundant bits r should be chosen in such a way that all

single-bit errors, and these are m+r+1 ones, can be corrected.• Since r bits can have 2r different states, a sufficient condition is:

2r >= m+r+1• For example, for ASCII code (m=7) the smallest value of r is 4:

16 = 24 >= 7+4+1 = 12

Page 25: The Data Link Layer

Error Correction

• We now know how many redundant bits to use. The remaining question is how to use them to identify the bit in error.

Hamming code

• Idea:• Place the redundant bits (r-bits) in different positions.

• Each r-bit is the parity bit (or VRC bit) for a subset of the entire data.

• Receiver checks the parity bits again, and can identify the bit in error (if any).

• Placement of the r-bits for ASCII characters:

r-bits are placed in positions which are power of 2.

Page 26: The Data Link Layer

Error Correction• Details of the r-bit placement:

Let bi the binary representation of (position i). Pj the set of bits, which rj is responsible for.

Pj = {i, bi has a 1 at position j and i !=j}• Our example again:

Page 27: The Data Link Layer

Error Correction• Our example: (contd)

Page 28: The Data Link Layer

Error Correction• Calculating the values of the r-bits (sender side):

Page 29: The Data Link Layer

Error Correction• Correcting a single-bit error (receiver side):

Assume bit 7 changed it value: received message = 10010100101

Page 30: The Data Link Layer

Error Correction• Burst errors:

• Hamming code can correct single-bit errors. In principle, same method can be applied for burst errors, too. However, the number of the r-bits may grow prohibitively for practical use.

• However, there is a trick that makes Hamming code practical enough also for burst errors:

Idea: 1. Use Hamming method for k data units. 2. Send those k codes column by column. 3. If |burst| <= k occurs, it would

affect different codes by changing at most one bit. 4. Thus, correct data can be reconstructed, since Hamming code can correct single-bit errors

Page 31: The Data Link Layer

Data Link Layer Protocols• Main task of these protocols:

• Flow control: Curb (fast) sender so that it does not overwhelm receiver. • Error control: Handle errors

• Types of flow control:• Stop-and-wait: Wait for acknowledgement of sent frame prior to sending a

new one. individual acknowledgement for each frame

• Sliding Window: Multiple frames can be sent without acknowledgement acknowledgement is not individual for each frame

• Error control:• Adds error handling to protocols for flow control.• Types of errors:

• Frame is damaged (and no correction is used or possible)• Frame is lost• Acknowledgement is lost• Negative acknowledgement is lost (if used)

Page 32: The Data Link Layer

Data Link Layer Protocols

Page 33: The Data Link Layer

Flow Control• Stop-and-Wait:

• Sender waits after each sent frame until corresponding acknowledgement arrives

• In this way, receiver will not be overwhelmed with frames

+ Simple- Inefficient: transmission time doubled Bandwidth wasted

Page 34: The Data Link Layer

Flow Control• Sliding Window:

• Multiple frames may be in transit at a time• Window prevents sender from overwhelming the receiver• More precisely:

• Both sender and receiver have a window with same size n.• Frames are numbered modulo n+1• Acknowledgements also carry a number (mod n+1), which identifies the

next frame expected by the receiver• The window can hold n frames at either ends, hence at most n frames can

be sent without a need for acknowledgement.• Example: n = 7

• Frames are numbered mod 8 e.g.0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 …

• If receiver sends ACK 5, the sender would understand that all frames up to number 4 have been successfully received.

Page 35: The Data Link Layer

Flow Control• Sender Sliding Window:

• Assume data are fed (by network layer) from the right, then:• Sender window shrinks from the left when frames are sent• Sender window expands to the right when acknowledgements are

received• Example: If frame 0, 1, 2, 3, 4 have been sent W = {5, 6} If ACK 4 arrives later W = {5, 6, 7, 0, 1, 2}

from networklayer

to physicallayer

Page 36: The Data Link Layer

Flow Control• Receiver Sliding Window:

• Assume data are fed (by physical layer) from the left, then:• Receiver window shrinks from the left when frames are received• Receiver window expands to the right when acknowledgements are sent

• Example: If frame 0, 1, 2, 3, 4, 5 have been received W = {6} If ACK 2 has been sent W = {6, 7, 0}

If ACK 5 has been sent W = {6, 7, 0, 1, 2, 3} (new win size = old win size + (current ACK# - previous

ACK#) mod 8)

to networklayer

from physicallayer

Page 37: The Data Link Layer

Flow Control: Example

Page 38: The Data Link Layer

Error Control• Idea:

• Integrate error handling with flow control.• Error control refers mainly to methods of error detection and retransmission.• Error control is based on ARQ (Automatic Repeat Request).• ARQ policy: On error detection, send NAK and let sender retransmit a frame. • Sender uses in general a timer to detect errors (lost ACK/NAK).• Again, errors are: corrupted frame, lost frame, or lost ACK/NAK

• Classification:

Page 39: The Data Link Layer

Error Control• Stop-and-Wait ARQ:

• Simple Stop-and-Wait flow control + retransmission in case of errors• Rules for retransmission:

• Sender keeps copy of last transmitted frame until an ACK arrives• Both data frames and ACK are numbered alternatively 0 and 1. For

example, ACK1 means that receiver accepted data frame 0 and is expecting data frame 1.

• If an error is detected in a frame, a NAK is send by receiver. NAKs are not numbered and tell sender to retransmit last frame.

• Sender uses a timer, after a timeout (without ACK) sender retransmits last frame.

• Error handling:• Damaged frame• Lost frame• Lost ACK/NAK

Page 40: The Data Link Layer

Stop-and-Wait ARQ : Damaged Frame

Example for a

damagedframe

0

1

0Error in frame 0

0

Retransmission

Page 41: The Data Link Layer

Stop-and-Wait ARQ: Lost Frame

ACK 0

Page 42: The Data Link Layer

Stop-and-Wait ARQ: Lost ACK/NAK

ACK 0

0

Second copy discardedACK 0

Page 43: The Data Link Layer

Sliding Window ARQ• New Features (added to basic sliding window flow control):

• Sender keeps copies of frames which are not acknowledged yet.• In addition to ACK receivers uses also NAKs.• Both are numbered:

• ACK carries the number of next frame expected.• NAK carries the number of the damaged frame itself (which is the

expected one).• Examples:

• If last ACK was numbered 4, an ACK 7 means that frames 4, 5, and 6 have been received correctly.

• If frame 8 and 9 were damaged, both NAK 8 and NAK 9 are returned, but NAK 8 tells sender that previous frames were intact.

• Sender has a timer. Since n (window size) frames can be sent without acknowledgement, sender starts the timer after sending n frames if their ACK is still missing.

• On timeout, sender resends one/multiple frames (depending on protocol). Receiver must be able to recognize duplicates.

• Two protocols: Go-Back-n ARQ and Selective Reject ARQ

Page 44: The Data Link Layer

Go-Back-n ARQ• Idea: If frame is lost/damaged all frames since the last ACK are resent.

• Damaged frame:

Resent

Resent

Resent

Page 45: The Data Link Layer

Go-Back-n ARQ• Lost frame:

Receiver detects 2 is skipped

Resent

Resent

Resent

Page 46: The Data Link Layer

Go-Back-n ARQ• Lost ACK:

Resent

Resent

Resent

Sender has to send 3 frames only(otherwise window size is decisive)

discard

discard

discard

ACK 3 Resent

Page 47: The Data Link Layer

Selective Reject ARQ• Idea:

• Resend only the specific lost/damaged frame.• If NAK is returned, sender retransmits only specified frame (out of

sequence).• This means that receiver must be able to sort frames and insert a retransmitted

frame in its proper place in the sequence.

• Requirements:• Receiver should have a sorting logic to enable to reorder frames received out

of sequence.• Receiver must be able to store frames after a NAK has been sent until the

damaged frame has been replaced.• A buffer in the receiver must keep all frames until all retransmissions have

been sorted and any duplicate frames have been identified and discarded.• To aid selectivity, ACK numbers, like NAK numbers should refer to the

frame received (or lost) instead of the next frame expected.• Sender must have a searching logic that allow to find and select the frame to

be retransmitted.• For efficiency, window size is recommended to be less than or equal 1+n/2

where n is the Go-Back-n window size.

Page 48: The Data Link Layer

Selective Reject ARQ• Damaged frame:

Receiver accepts further frames but must notreturn an ACK until frame 2 is retransmitted

ACK 5

Page 49: The Data Link Layer

Selective Reject ARQ• Lost frame:

Receiver detects 2 is skipped

Resent

3Data

NAK 2

4Data2Data

If frame 2 was last frame, sender treats this case as a lost ACK

5Data

2Data5Data

Page 50: The Data Link Layer

Selective Reject ARQ• Lost ACK/NAK:

• Like in Go-Back-n.• When sender reaches capacity of window or the end of its transmission, it

sets a timer.• If after timeout no ACK arrives, sender retransmits all frames that are not

acknowledged yet.• Receiver should recognize duplicates and discard them.

• Go-Back-n vs. Selective Reject:• Communication overhead:

Go-Back-n > Selective Reject• Logic complexity:

Selective Reject > Go-Back-n• However, in practice Go-Back-n is used more often (due to its simplicity).

• Remark:Note that stop-and-wait is a special case of the sliding window protocol with a window size of 1.

Page 51: The Data Link Layer

High-Level Data Link Control• HDLC:

• Origin: IBM mainframe protocol SDLC (Synchronous Data Link Control)• Various variants:

• ANSI: ADCCP• ISO: HDLC• CCITT: LAPB

• Bit-oriented protocol (not character-oriented)• Bit stuffing for transparency and sliding window (n=7) for flow control.• Point-to-point links and multi-point links (e.g. computer with different

terminals)• Structure of a frame:

Frame delimiter

Only for multipointlinks (e.g. terminal id)

Sequencenumber,

ACKs, …

Actualdata

CRC

Page 52: The Data Link Layer

HDLC: Control Field• 3 Types: information (a), supervisory (b), and unnumbered frame (c)• Information frame:

• Seq: sequence number• Next: piggybacked ACK (next expected frame) if there is reverse traffic.• P/F: Poll/Final bit; used if computer asks terminal to send data (P-frame).

Terminal replies with P-frames except the last one is an F-frame.• Supervisory frame:

• Type 0: ACK, Next= expected frame, used piggybacking not possible.• Type 1: NAK, Next=frame in error, sender resends all outstanding frames.• Type 2: ACK + asking sender to temporarily stop sending.• Type 3: Receiver asks sender to resend specified frame (in Next).

• Unnumbered frame:• No common use of it, but it may include information like:

- Disconnect/connect machine- Fame has impossible semantics- ACK for control frames