You are on page 1of 51

Chapter 3

The Data Link Layer

Data Link Layer Design Issues


Main topics: the algorithms for achieving reliable, efficient communication between two adjacent machines at the data link layer. By adjacent, we mean the two machines are physically connected by a communication channel (e.g., a coaxial cable or a phone line) that acts conceptually like a wire. The essential property of a channel that makes it ``wire-like'' is that the bits are delivered in exactly the same order in which they are sent. Why need data link layer software ?
1. 2. 3. 4. Communication circuits make errors occasionally, they have a finite data rate, there is a nonzero propagation delay, and the adjacent machines have finite and maybe different processing speeds.
2

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

Relationship between packets and frames

Services Provided to Network Layer


The principal service: transferring data from the network layer on the source machine to the network layer on the destination machine.

Virtual communication.

Actual communication.

Three possible services: 1. Unacknowledged connectionless service. 2. Acknowledged connectionless service. 3. Connection-oriented service.

Placement of the data link protocol

An example: a subnet consisting of routers connected by point-to-point lines.


1. 2. When a frame arrives at a router, the hardware verifies the checksum and passes the frame to the data link layer software. The data link layer software, which may be embedded in a chip on the network adaptor board, checks to see if this is the frame expected. and if so, gives the packet in the payload field to the (network layer) routing software. The routing software chooses the appropriate outgoing line and passes the packet back down to the data link layer software. The data link layer software transmits it over the selected outgoing line.

3. 4.

Many of the principles at the data link layer, such as error control and flow control, are also found in transport and other layers and protocols as well.
6

Framing
What is framing ? The process of breaking the bit stream offered by the physical layer into discrete segments (frames). Why framing ? a) For computing the checksum for each frame. b) For acknowledging the lost frames. How to do framing ?
7

A character stream

(a) Without errors.

(b) With one error.

What happens if the count is garbled by an error ?


8

Flag bytes

(a)

A frame delimited by flag bytes.

(b) Four examples of byte sequences before and after stuffing.

Disadvantages: closely tied to 8-bit characters and the ASCII character code.
9

Bit stuffing

(a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in receivers memory after destuffing.
10

Physical layer coding violations


The IEEE 802 standard LAN uses the following (Differential Manchester) encoding scheme: a 1 bit is encoded as HL, and a 0 bit as LH. The invalid encodings - HH and LL - can be used for framing. Character count can be combined with others for extra safety.

11

Error control and flow control


Error control: the goal (of a reliable connection-oriented service): to ensure each frame is ultimately passed to the network layer at the destination exactly once, no more and no less. The measures:
1. 2. 3. Acknowledgements from the receiver to the sender. Timers for preventing senders from hanging forever. Sequence numbers for dealing with duplicated frames.

Flow control: What to do with a sender that systematically wants to transmit frames faster than the receiver can accept them ? Some kind of feedback mechanism is needed so that the sender can be made aware of whether or not the receiver is able to keep up. This is frequently integrated with error handling for convenience.
12

Error Detection and Correction


Transmission errors are a fact of life. Sources of errors (local loop and wireless links):
1. Thermal noise and electromagnetic interference broad-spectrum background noise level. 2. The frequency dependency of the amplitude, propagation speed, and phase of signals distortion. 3. Echoes, off-course birds, etc.

Errors tend to come in burst rather than singly.


13

Error-Correcting Codes
Basic idea: Including redundant information along with each block of data sent to enable the receiver to deduce what the transmitted character must have been. An unit containing m bits of data and r bits of redundancy, or check bits, is referred to as an m + r bits codeword. The number of bit positions in which two codewords differ is called the Hamming distance. Two d apart codewords require d single-bit errors to convert one into the other. The minimum Hamming distance between any two codewords from a list of codewords is the distance of the complete list. To detect d errors, a distance of d + 1 is needed because with such a code there is no way that d single-bit errors can change a valid codeword into another valid codeword. To correct d errors, a distance of 2d + 1 is needed because that way the legal codewords are so far apart that even with d changes, the original codeword is still closer than any other codeword, so it can be uniquely determined.
14

Hamming code
At the sending side: 1. The bits of the codeword are numbered consecutively, starting with bit 1 at the left end. 2. The bits that are powers of 2 (1, 2, 4, 8, 16, etc.) are check bits. The rest (3, 5, 6, 7, etc.) are filled up with the data bits. 3. Check bit forces the parity of the following bits to be even (or odd): the check bit itself, and all data bits whose position number has an element of 2**i when it is expended into a sum of powers of 2. E.g., for check bit 1, the following data bits are checked: 3 = 1 + 2, 5 = 1 + 4, 7 = 1 + 2 + 4, ... One data bit is checked by all and just those check bits occurring in its expansion.
15

Hamming code
At the receiver side:
1. A counter is initialized into zero. 2. Each check bit k (= 1, 2, 4, ...) and its checked data bits are examined to see if the parity is correct. 3. If not, k is added into the counter. 4. If the counter is zero at the end, the codeword is accepted as valid. Otherwise, it contains the number of the incorrect bit.

E.g., if the parities were wrong when examining check bits 1, 2, 4, then the counter-value = 7 = 1 + 2 + 4 , we can conclude that data bit 7 was inverted since bit 7 is the only one checked by bits 1, 2, and 4.
16

Use of a Hamming code to correct burst errors


The following figure shows some 7-bit ASCII characters encoded as 11-bit codewords using a Hamming code. The data bits are found in bit positions 3, 5, 6, 7, 9, 10, and 11.

To correct burst errors by means of Hamming codes :


1. A sequence of codewords are arranged as a matrix, one codeword per row. 2. The data is transmitted one column ( bits) at a time, starting with the leftmost column. 3. The matrix is reconstructed at the receiving side.

If a burst error of length occurs, at most 1 bit in each codeword will be effected, which can be corrected by the Hamming code. 17

Error-detecting codes
Error-correcting codes are suitable for simplex channels where no retransmission can be requested. Error-detection plus retransmission is often preferred because it is more efficient. For comparison, consider a channel with error rate of 10**(-6) per bit. Let block size be 1000 bits.
To correct a single error (by Hamming code), 10 check bits per block are needed. To transmit 1000 blocks, 10,000 check bits (overhead) are required. To detect a single error, a single parity bit per block will suffice. To transmit 1000 blocks, only one extra block (due to the error rate of 10**(-6) per bit) will have to be retransmitted, giving the overhead of only 2001 (= 1000 + 1001) bits.

Under what conditions is error-correction more efficient ?


18

Cyclic Redundancy Code (CRC) method


A k-bit frame is regarded as the coefficient list for a polynomial with k terms, ranging from x**(k-1) to x**0. Polynomial arithmetic is done modulo 2. Both addition and subtraction are identical to EXCLUSIVE OR: 10011011 01010101 + 11001010 - 10101111 ----------------------------01010001 11111010 The basic idea of the CRC method:
1. The sender appends a checksum to the end of the frame in such a way that the polynomial represented by the checksummed frame is divisible by a generator polynomial G(x). 2. When the receiver gets the frame, it tries dividing it by the same G(x). If there is a remainder, there must have been an error and a retransmission will be requested.

How to compute the chechsum for a given frame ?


19

Calculation of the CRC checksum


In any division problem, if you diminish the dividend by the remainder, what is left over is divisible by the divisor. Detectable errors by CRC:
1. All single errors are detectable if G(x) contains two or more terms. 2. All double errors are detectable if G(x) does not divide x**k + 1 for any k up to the maximum frame length. 3. All odd number of errors if G(x) contains a factor of x + 1 . 4. All burst errors of length r (the degree of G(x) ) or the number of check bits. 5. The probability of a burst error of length r + 1 being accepted as valid is (0.5)** (r 1). 6. The probability of a bad frame, garbled by a long burst or multiple shorter bursts, getting through unnoticed is (0.5)**r.

Simple hardware has been built to compute and verify the CRC checksum.

20

Elementary Data Link Protocols


Assumptions:
1. The physical layer, data link layer, and network layer are independent processes. The network layer contacts the data link layer by generating proper events. There exist suitable library procedures for the data link layer to delivery a packet (To_network_layer), and to fetch a packet (from_network_layer). The data link layer provides a reliable, connection-oriented service to the network layer. The physical layer computes/checks checksums in outgoing/incoming frames, and contacts the data link layer by generating proper events. There exist suitable library procedures for the data link layer to send a frame (to_physical_layer), and to fetch a frame (from_physical_layer).
21

2.

3.

4.

Protocol Definitions

Continued

Some definitions needed in the protocols to follow. These are located in the file protocol.h.

22

Protocol Definitions (ctd.)

Some definitions needed in the protocols to follow. These are located in the file protocol.h.
23

Unrestricted Simplex Protocol

24

Simplex Stop-andWait Protocol

25

A Simplex Protocol for a Noisy Channel


A scheme using timer and acknowledgement:
1. 2. The sender starts a timer after sending a frame. The receiver sends back an acknowledgement only when the incoming frame were correctly received. The sender will retransmit the frame if the timer expired before receiving an acknowledgement.

3.

What is the fatal flaw in the above scheme ? Loss of an acknowledgement duplicated frame. How to distinguish a frame being seen for the first time from a retransmission ? Use a sequence number in the header of each frame.

Continued
26

A Simplex Protocol for a Noisy Channel (ctd.)

A positive acknowledgement with retransmission protocol.27

Sliding Window Protocols


How to achieve full-duplex data transmission ?
1. 2. Two separate simplex data channels -- waste of bandwidth. One circuit for data in both directions and using the field in the frame header to distinguish a data from an acknowledgement.

Piggybacking: temporarily delay outgoing acknow-ledgements so that they can get a free ride on the next outgoing data frame. Save bandwidth, number of interrupts and buffers. How long should the receiver wait for an outgoing frame onto which to piggyback the acknowledgement ? An ad hoc scheme: waiting a fixed number of msec (timer).

28

Basics of sliding window protocols

A sequence number is assciated with each transmitted frame. Sequence numbers range from 0 up to some maximum (2**n - 1) circularly. A window is a list of consecutive sequence numbers. The size of a window is determined by two pointers: the lower edge and the higher edge. The size can be fixed or dynamically extended and shrunk. The sender maintains a sending window with consecutive sequence numbers corresponding to frames sent but has yet not acknowledged.
Whenever a new packet arrives from the network layer, it is given the next highest sequence number, and the upper edge of the window is advanced by one. When an acknowledgement comes in, the lower edge is advanced by one. The size of the sender's window is a dynamical one.

The receiver maintains a receiving window with consecutive sequence numbers corresponding to frames it is permitted to accept.
When a frame whose sequence number is equal to the lower edge of the window is received, it is passed to the network layer, an acknowledgement is generated, and the window is rotated by one. The receiver's window always remains at its initial size.
29

A sliding window of size 1, with a 3-bit sequence number

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

A One-Bit Sliding Window Protocol


1. The maximum window size is 1. 2. Stop-and-wait.

Continued

31

A One-Bit Sliding Window Protocol (ctd.)

32

A One-Bit Sliding Window Protocol (2)

Two scenarios for protocol 4. (a) Normal case. (b) Abnormal case. The notation is (seq, ack, packet number). An asterisk indicates where a network layer accepts a packet.
33

A Protocol Using Go Back N


A tacit assumption in previous protocols: the time in the following period is negligible:
1. 2. 3. The transmission time for a frame to arrive at the receiver. The processing time for the receiver to handle the incoming frame. The transmission time for an acknowledgement to come back at the sender.

Consequently, the sender is blocked during the above period, which can be very large in channels with long round-trip propagation delay. How to solve this problem ? The pipelining solution: Set the maximum sender's window size (the number of outstanding frames) so large that the sender is allowed to transmit multiple frames until the acknowledgement for the first frame comes back. Thereafter, acknowledgements will arrive one after another, so the sender always gets permission to transmit. What to do if a frame in the middle of a long stream is damaged or lost ?

34

Pipelining and error recovery


(a) The go back n strategy:
1. The receiver discards all subsequent frames, sending no acknowledgements. The receiver's window size is 1. After time out, the sender retransmits all unacknowledged frames in order, starting with the damaged or lost one.

2.

(b) The selective repeat strategy: 1. The receiver buffers correct subsequent frames, but sending no acknowledgements (or Nak). The receiver's window size is larger than 1. 2. After time out (or receiving Nak), the sender retransmits the damaged or lost frame.

35

Sliding Window Protocol Using Go Back N

Continued

36

Sliding Window Protocol Using Go Back N

Continued

37

Sliding Window Protocol Using Go Back N

Continued

38

Sliding Window Protocol Using Go Back N

39

A Sliding Window Protocol Using Selective Repeat

Continued

41

A Sliding Window Protocol Using Selective Repeat (2)

Continued

42

A Sliding Window Protocol Using Selective Repeat (3)

Continued

43

A Sliding Window Protocol Using Selective Repeat (4)

44

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

Example Data Link Protocols


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

50

High-Level Data Link Control


The nice thing about standards is that you have so many to choose from. At the data link layer, we have IBM SDLC (Synchronous Data Link Control), ANSI ADCCP (Advanced Data Communication Control Procedure), ISO HDLC (High-level Data Link Control), CCITT LAP (Link Access Procedure), etc. If you do not like any of them, you can just wait for next year's model. All are bit-oriented and using bit stuffing. All use the same frame structure:

The frame is delimited with flag sequence 01111110. Address can be used to identify a terminal on multidrop lines or to distinguish commands from responses for point-to-point lines. Control is used for sequence numbers, acknowledgements, and others. Data can be arbitrarily long. Checksum uses CRC-CCITT. 51

High-Level Data Link Control (2)

Three kinds of frames distinguished by the control field: (a) An information frame. (b) A supervisory frame. (c) An unnumbered frame.
52

The Data Link Layer in the Internet


There are two situations in which point-to-point communication occurs in Internet: Router-router leased line connection between Internet routers. Host-router dial-up line connection between home computers and the Internet service providers' routers, as shown in the following Figure.

A home personal computer acting as an internet host.


53

PPP Point to Point Protocol


PPP provides three features:
1. A framing method that unambiguously delineates the end of one frame and the start of the next one. The frame format also handles error detection. 2. A link control protocol for bringing lines up, testing them, negotiating options, and bringing them down again gracefully when they are no longer needed. This protocol is called LCP (Link Control Protocol). 3. A way to negotiate network-layer options in a way that is independent of the network layer protocol to be used. The method chosen is to have a different NCP (Network Control Protocol) for each network layer supported.

54

A typical scenario of PPP


A typical scenario of a home user calling up an Internet service provider to make a home PC a temporary Internet host: 1. Physical connection setup phase:
The PC calls the provider's router via a modem. The router's modem answers the phone and establishes a physical connection. The PC sends the router a series of LCP packets in the payload field of one or more PPP frames. These packets and their responses select the PPP parameters to be used. A series of NCP packets are sent to configure the network layer and to assign an IP address for the PC (if the PC wants to run a TCP/IP protocol stack). The PC sends and receives IP packets over the established connection. When the PC is finished, NCP is used to tear down the network layer connection and free up the IP address. The LCP is used to shut down the data line layer connection. The computer tells the modem to hang up the phone, releasing the physical connection. 55

2. Data link layer options negotiation phase:

3. Network layer options negotiation phase:

4. Data communication phase:


5. Connection release phase:


The PPP full frame format for unnumbered mode operation


The PPP frame was chosen to closely resemble the HDLC frame, as shown below:

In summary, PPP is a multi-protocol framing mechanism suitable for use over modems, HDLC bit-serial lines, SONET, and other physical layers. It supports error detection, option negotiation, header compression, and optionally, reliable transmission using HDLC framing.
56

You might also like