Chapter3 Data Link Layer

Embed Size (px)

Citation preview

  • 7/27/2019 Chapter3 Data Link Layer

    1/51

    1

    The Data Link Layer

    Chapter 3

  • 7/27/2019 Chapter3 Data Link Layer

    2/51

    2

    Data Link Layer Design Issues

    Main topics: the algorithms for achieving reliable, efficient

    communication between two adjacentmachines at the datalink 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. Communication circuits make errors occasionally,

    2. they have a finite data rate,

    3. there is a nonzero propagation delay, and

    4. the adjacent machines have finite and maybe different processing speeds.

  • 7/27/2019 Chapter3 Data Link Layer

    3/51

    3

    Functions of the Data Link Layer

    Provide service interface to the network layer

    Dealing with transmission errors

    Regulating data flow: slow receivers notswamped by fast senders

  • 7/27/2019 Chapter3 Data Link Layer

    4/51

    4

    Relationship between packets and frames

  • 7/27/2019 Chapter3 Data Link Layer

    5/51

    5

    Services Provided to Network Layer

    Virtual communication. Actual communication.

    The principal service: transferring data from the network layer on the source

    machine to the network layer on the destination machine.

    Three possible services:

    1. Unacknowledged connectionless service.

    2. Acknowledged connectionless service.

    3. Connection-oriented service.

  • 7/27/2019 Chapter3 Data Link Layer

    6/51

    6

    Placement of the data link protocol

    An example: a subnet consisting of routers connected by point-to-point lines.1. When a frame arrives at a router, the hardware verifies the checksum and passes the frame to

    the data link layer software.

    2. The data link layer software, which may be embedded in a chip on the network adaptorboard, 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.3. The routing software chooses the appropriate outgoing line and passes the packet back down

    to the data link layer software.

    4. The data link layer software transmits it over the selected outgoing line.

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    7/51

    7

    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/27/2019 Chapter3 Data Link Layer

    8/51

    8

    A character stream

    (a) Without errors. (b) With one error.

    What happens if the count is garbled by an error ?

  • 7/27/2019 Chapter3 Data Link Layer

    9/51

    9

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    10/51

    10

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    11/51

    11

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    12/51

    12

    Error control and flow controlError 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. Acknowledgements from the receiver to the sender.

    2. Timers for preventing senders from hanging forever.

    3. Sequence numbers for dealing with duplicated frames.

    Flow control: What to do with a sender that systematically wantsto transmit frames faster than the receiver can accept them ?

    Some kind of feedback mechanism is needed so that the sender canbe made aware of whether or not the receiver is able to keepup.

    This is frequently integrated with error handling for convenience.

  • 7/27/2019 Chapter3 Data Link Layer

    13/51

  • 7/27/2019 Chapter3 Data Link Layer

    14/51

    14

    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 rbits of redundancy, or check bits, is

    referred to as an m + rbits codeword.

    The number of bit positions in which two codewords differ is called the

    Hamming distance. Two d apart codewords require dsingle-bit errors toconvert 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 derrors, a distance of d + 1 is needed because with such a code there

    is no way that dsingle-bit errors can change a valid codeword into another

    valid codeword.

    To correct derrors, a distance of 2d + 1 is needed because that way the legal

    codewords are so far apart that even with dchanges, the original codeword is

    still closer than any other codeword, so it can be uniquely determined.

  • 7/27/2019 Chapter3 Data Link Layer

    15/51

    15

    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 of2**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.

  • 7/27/2019 Chapter3 Data Link Layer

    16/51

    16

    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, kis added into the counter.

    4. If the counter is zero at the end, the codeword is accepted asvalid. 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 thatdata bit 7 was inverted since bit 7 is the only one checked by

    bits 1, 2, and 4.

  • 7/27/2019 Chapter3 Data Link Layer

    17/51

    17

    Use of a Hamming code to correct burst errorsThe 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.

    http://www.cit.gu.edu.au/teaching/3142CIT/slides/ch3/node3.html
  • 7/27/2019 Chapter3 Data Link Layer

    18/51

    18

    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 overheadof only 2001 (= 1000 + 1001) bits.

    Under what conditions is error-correction more efficient ?

  • 7/27/2019 Chapter3 Data Link Layer

    19/51

    19

    Cyclic Redundancy Code (CRC) method

    A k-bit frame is regarded as the coefficient list for a

    polynomial with kterms, ranging fromx**(k-1) tox**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 agenerator 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 ?

    http://www.cit.gu.edu.au/teaching/3142CIT/slides/ch3/node3.htmlhttp://www.cit.gu.edu.au/teaching/3142CIT/slides/ch3/node3.html
  • 7/27/2019 Chapter3 Data Link Layer

    20/51

    20

    Calculation of the CRC checksumIn 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 ifG(x) contains

    two or more terms.

    2. All double errors are detectable ifG(x) does not

    dividex**k + 1 for any kup to the maximum

    frame length.3. All odd number of errors ifG(x) contains a factor

    ofx + 1 .

    4. All burst errors of length r(the degree ofG(x) )

    or the number of check bits.

    5. The probability of a burst error of lengthr + 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.

  • 7/27/2019 Chapter3 Data Link Layer

    21/51

    21

    Elementary Data Link Protocols

    Assumptions:

    1. The physical layer, data link layer, and network layer are independentprocesses.

    2. The network layer contacts the data link layer by generating properevents.

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

    3. The data link layer provides a reliable, connection-oriented service to the

    network layer.

    4. The physical layer computes/checks checksums in outgoing/incomingframes, and contacts the data link layer by generating properevents.

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

  • 7/27/2019 Chapter3 Data Link Layer

    22/51

    22

    Protocol Definitions

    Continued

    Some definitions needed in the protocols to follow.

    These are located in the file protocol.h.

  • 7/27/2019 Chapter3 Data Link Layer

    23/51

    23

    Protocol

    Definitions

    (ctd.)

    Some definitions

    needed in the

    protocols to follow.

    These are located in

    the file protocol.h.

  • 7/27/2019 Chapter3 Data Link Layer

    24/51

    24

    Unrestricted

    SimplexProtocol

  • 7/27/2019 Chapter3 Data Link Layer

    25/51

    25

    Simplex

    Stop-and-

    WaitProtocol

  • 7/27/2019 Chapter3 Data Link Layer

    26/51

    26

    A Simplex Protocol for a Noisy Channel

    Continued

    A scheme using timer and

    acknowledgement:1. The sender starts a timer after

    sending a frame.

    2. The receiver sends back an

    acknowledgement only when

    the incoming frame were

    correctly received.

    3. The sender will retransmit the

    frame if the timer expired

    before receiving an

    acknowledgement.

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    27/51

    27

    A Simplex Protocol for a Noisy Channel (ctd.)

    A positive acknowledgement with retransmission protocol.

  • 7/27/2019 Chapter3 Data Link Layer

    28/51

    28

    Sliding Window Protocols

    How to achieve full-duplex data transmission ?

    1. Two separate simplex data channels -- waste of bandwidth.

    2. 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).

  • 7/27/2019 Chapter3 Data Link Layer

    29/51

    29

    Basics ofsliding 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 awindow 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 highestsequence 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.

    A lidi i d f i 1 ith 3 bit

  • 7/27/2019 Chapter3 Data Link Layer

    30/51

    30

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    31/51

    31

    A One-Bit Sliding Window Protocol

    Continued

    1. The maximum window size is 1.

    2. Stop-and-wait.

  • 7/27/2019 Chapter3 Data Link Layer

    32/51

    32

    A One-Bit Sliding Window Protocol (ctd.)

  • 7/27/2019 Chapter3 Data Link Layer

    33/51

    33

    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.

    A P l U i G B k N

  • 7/27/2019 Chapter3 Data Link Layer

    34/51

    34

    A Protocol Using Go Back N

    A tacit assumption in previous protocols: the time in the following period isnegligible:

    1. The transmission time for a frame to arrive at the receiver.2. The processing time for the receiver to handle the incoming frame.

    3. The transmission time for an acknowledgement to come back at the sender.

    Consequently, the sender is blocked during the above period, which can be verylarge 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 ofoutstanding frames) so large that the sender is allowed to transmit multipleframes 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 ?

    Pi li i d

  • 7/27/2019 Chapter3 Data Link Layer

    35/51

    35

    Pipelining and error recovery

    (a) The go back n strategy:1. The receiver discards all

    subsequent frames, sending noacknowledgements. The

    receiver's window size is 1.

    2. After time out, the sender

    retransmits all unacknowledged

    frames in order, starting with the

    damaged or lost one.

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

    http://www.cit.gu.edu.au/teaching/3142CIT/slides/ch3/node5.html
  • 7/27/2019 Chapter3 Data Link Layer

    36/51

    36

    Sliding

    WindowProtocol

    Using Go

    Back N

    Continued

  • 7/27/2019 Chapter3 Data Link Layer

    37/51

    37

    Sliding Window Protocol Using Go Back N

    Continued

  • 7/27/2019 Chapter3 Data Link Layer

    38/51

    38

    Sliding Window Protocol Using Go Back N

    Continued

  • 7/27/2019 Chapter3 Data Link Layer

    39/51

    39

    Sliding Window Protocol Using Go Back N

    A Slidi Wi d P t l U i S l ti R t

  • 7/27/2019 Chapter3 Data Link Layer

    40/51

    41

    A Sliding Window Protocol Using Selective Repeat

    Continued

    A Slidi Wi d P t l U i S l ti R t (2)

  • 7/27/2019 Chapter3 Data Link Layer

    41/51

    42Continued

    A Sliding Window Protocol Using Selective Repeat (2)

  • 7/27/2019 Chapter3 Data Link Layer

    42/51

    43

    A Sliding Window Protocol Using Selective Repeat (3)

    Continued

    A Slidi Wi d P t l U i S l ti R t (4)

  • 7/27/2019 Chapter3 Data Link Layer

    43/51

    44

    A Sliding Window Protocol Using Selective Repeat (4)

  • 7/27/2019 Chapter3 Data Link Layer

    44/51

    45

    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.

  • 7/27/2019 Chapter3 Data Link Layer

    45/51

    50

    Example Data Link Protocols

    HDLCHigh-Level Data Link Control

    The Data Link Layer in the Internet

    Hi h L l D t Li k C t l

  • 7/27/2019 Chapter3 Data Link Layer

    46/51

    51

    High-Level Data Link Control

    The frame is delimited with flag sequence 01111110.

    Address can be used to identify a terminal on multidrop lines or to distinguishcommands from responses for point-to-point lines.

    Controlis used for sequence numbers, acknowledgements, and others.

    Data can be arbitrarily long.

    Checksum uses CRC-CCITT.

    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), ISOHDLC (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:

  • 7/27/2019 Chapter3 Data Link Layer

    47/51

    52

    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.

    The Data Link Layer in the Internet

  • 7/27/2019 Chapter3 Data Link Layer

    48/51

    53

    The Data Link Layer in the Internet

    A home personal computer acting as an internet host.

    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 Internetservice providers' routers, as shown in the following Figure.

    PPP Point to Point Protocol

  • 7/27/2019 Chapter3 Data Link Layer

    49/51

    54

    PPPPoint to Point Protocol

    PPP provides three features:

    1. A framing method that unambiguously delineates the end ofone 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 (NetworkControl Protocol) for each network layer supported.

    A typical scenario of PPP

  • 7/27/2019 Chapter3 Data Link Layer

    50/51

    55

    A typical scenario of PPPA 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.

    2. Data link layer options negotiation phase: 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.3. Network layer options negotiation phase:

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

    4. Data communication phase: The PC sends and receives IP packets over the established connection.

    5. Connection release phase: 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.

  • 7/27/2019 Chapter3 Data Link Layer

    51/51