dlc slides1

48
Chapter 3 Data Link Layer & Data Link Layer & Error Control Coding Error Control Coding

Upload: gumbo-tyagi

Post on 14-Nov-2015

78 views

Category:

Documents


1 download

DESCRIPTION

data link layer slides info

TRANSCRIPT

  • Chapter 3

    Data Link Layer & Data Link Layer & Error Control CodingError Control Coding

  • ECE/CSC 570, NC State University

    DATA LINK CONTROL (DLC)

    DLC

    FRAMEHEADERSEQUENCENUMBERS

    TRAILERCRC

    OBJECTIVE: PROVIDE ANERROR FREE BIT PIPEPACKET

    PACKET

  • ECE/CSC 570, NC State University

    DATA LINK CONTROL (2)

    DLC

    MAC

    PHYSICAL

    DLC

    MAC

    PHYSICAL

    UNRELIABLEBIT PIPE

    RELIABLEBIT PIPE

  • ECE/CSC 570, NC State University

    Functions of the Data Link Layer (DLL)

    n Provide service interface to the network layer

    n Dealing with transmission errors error-control coding & retransmission

    n Regulating data flowslow receivers not swamped by fast sendersdone by ARQ..

  • ECE/CSC 570, NC State University

    Data Link Layer Design Issues

    n Service provided to the Network Layern Framingn Error Controln Flow Control

  • ECE/CSC 570, NC State University

    Packets vs. Frames

    Relationship between packets and frames.

  • ECE/CSC 570, NC State University

    Services Provided to Network Layer

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

  • ECE/CSC 570, NC State University

    Service types

    n Unacknowledged connectionless servicen Acknowledged connectionless servicen Acknowledged connection-oriented service

  • ECE/CSC 570, NC State University

    Services

    n Unacknowledged connectionless service Source machine sends independent frames without having the

    destination machine acknowledge them No logical connection is established If a frame is lost due to noise on the link, no detection or

    recovery Appropriate for reliable links and leave the recovery to higher

    layers. (LANs)

    n Acknowledged connectionless service No logical connection is established Each frame sent is individually acknowledged Retransmit if time out Useful for unreliable channels (wireless systems!) Delay of a packet is long if many frames are retransmitted

    Regular bulk postal mail

    certified postal mail

  • ECE/CSC 570, NC State University

    Services (2)

    n Acknowledged connection-oriented service Connection is established before any data are transferred Each frame is numbered and guaranteed to be received Each frame is received only once and all frames are

    received in the right order. Provides the network layer processes with the equivalent of

    a reliable bit stream

    Reliable pipe !

  • ECE/CSC 570, NC State University

    Framing

    n How to decide the successive frames start and stop ?

    n Inserting time gaps between frames will not work. Why?

    n Three types of framing used in practiceCharacter-based countFlag bytes with byte stuffingStarting and ending flags, with bit stuffing

  • ECE/CSC 570, NC State University

    Framing: Character-based count

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

    A header to specify the no. of characters in the frame

    Even the destination knows that the frame is bad, it still has no way of telling where the next frame starts. Resending a frame back to the source

    asking for retransmission does not help either. Rarely use any more

  • ECE/CSC 570, NC State University

    Framing: Flag bytes with byte stuffing

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

    Use flag bytes to separate the frames

    What if the data has the same byte pattern as flag bytes? Insert ESC as byte stuffing, but limited to 8-bit characters.

  • ECE/CSC 570, NC State University

    Framing: Starting/ending flags with bit stuffing

    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 de-stuffing.

    a flag byte = 01111110

    Delete 0 at the receiver

    Many DLL protocols use combined method!

  • Error Control CodingError Control Coding

  • ECE/CSC 570, NC State University

    Error Detection and Correction

    n The primary function of the DLC (Data Link Control) is to convert the unreliable bit pipe into a reliable bit pipe.

    n This can be done by using FEC (Forward Error Correction) or ARQ (Automatic Repeat reQuest) for retransmission.

    n The FEC relies upon some form of Error Control Coding and the ARQ relies on Error Control Coding but also on the introduction of Sequence Number(SN) and Request Numbers (RN).

  • ECE/CSC 570, NC State University

    Error Detection and Correction

    n Error-Correcting CodesHamming Code

    n Error-Detecting CodesParity CheckCyclic Redundancy Check (CRC)

  • ECE/CSC 570, NC State University

    Properties n Errors on a link tend to be dependent and occur in

    burstsn For any reasonable code, the frequency of

    undetectable errors is very small and thus difficult to measure and difficult to model analytically.

    n The minimum distance of the coden The burst detecting capabilityn The probability that a completely random string will

    be accepted as error free

  • ECE/CSC 570, NC State University

    Definitions n Codeword : n-bit unit (n = m + r ) containing m data and

    r redundant, or check bits, is referred to as an n-bit codeword

    n The minimum distance of the code : the smallest number of errors that can convert one codeword into another

    n The length of a burst of errors : the number of bits from the first error to the last error (inclusive). The burst error detecting capability of a code is defined as the largest integer B such that a code can detect all bursts of length B or less.

  • ECE/CSC 570, NC State University

    Definitions (2)

    n Hamming Distance d: the number of bit positions in which two codewords differGiven any two codewords, exclusive OR (XOR)

    100010011011000100111000

    n It requires d single-bit errors to convert one codeword to another.

    0 for same values1 for different values

  • ECE/CSC 570, NC State University

    n The probability that all k bits in a message are received correctly is equal to ( )1- pe

    k

    0

    1

    0

    11- pe

    1- pe

    pepe

    Binary Symmetric Channel

  • ECE/CSC 570, NC State University

    Bit Error Raten A simple error correction coding method is to send every

    packet three times.n Three values are then received for each bit and the receiver

    uses a majority vote on each bit.n Evaluate the effectiveness of this method assuming that all

    the bits errors are independent. The probability that a given bit is incorrectly received two or three

    times is equal to e = 3 Pe2 (1-Pe) + Pe3

    Therefore, the probability that at least one of the N bits of the packet is received incorrectly two or three times is equal to

    PER (packet error rate) = 1 (1 e)N Ne 3N Pe2

  • ECE/CSC 570, NC State University

    Packet Error Rate (Contd)

    n Compare the PERFor N = 105 and BER =Pe= 10-7, the PER of one time

    transmission is 1- (1-BER)N N BER = 10-2.The PER of three times transmission is

    PER Ne 3N Pe2 = 3 10-9

    n Price? The useful transmission rate has been reduce by a factor

    of 3.

  • ECE/CSC 570, NC State University

    Single Parity Coder

    n Parity check append a single bit to the data. If the number of 1 bits in the codeword is even (or odd), a bit 0 (1) is appended. E.g., 1011010, a bit 0 will be added to the end and it makes

    10110100 It can be used to detect single errors. Minimum distance of the code ?

    1 2 ks s s 1 2 ks s s cCODER

    where c = s1 s2 L sk , the modulo-2 sum

  • ECE/CSC 570, NC State University

    njjjjj

    ikiiii

    ssssrssssc

    L

    L

    ==

    321

    321

    Horizontal and Vertical Parity Checksl A two-dimensional array with one parity check

    for each row and one for each column.

    s11 s12 s13 L s1k c1s21 s22 s23 L s2k c2s31 s31 s33 L s3k c3M M M M M M

    sn1 sn2 sn3 L snk cnr1 r2 r3 L rk cn +1

  • ECE/CSC 570, NC State University

    njjjjj

    ikiiii

    ssssr

    ssssc

    L

    L

    =

    =

    321

    321

    Detects all single, double and triple errors and most quadruple but not all!

    Horizontal and Vertical Parity Checks (2)

    1 0 0 1 0 1 0 10 1 1 1 0 1 0 0 1 1 1 0 0 0 1 01 0 0 0 1 1 1 00 0 1 1 0 0 1 11 0 1 1 1 1 1 0

    Horizontal checks

    Vertical checks

    1 0 0 1 0 1 0 10 1 1 1 0 1 0 0 1 1 1 0 0 0 1 01 0 0 0 1 1 1 00 0 1 1 0 0 1 11 0 1 1 1 1 1 0

    If the bit in each circle is changed, all parity checks are still satisfied

  • ECE/CSC 570, NC State University

    Observationsn To detect d errors, we need a distance d+1 code so

    that d single-bit errors cannot change a codeword to another.

    n To correct d errors, we need a distance 2d+1 code so that even d-bit errors, the original codeword is still closer than any other codewords. E.g., there are 4 valid codewords: 0000000000, 0000011111,

    1111100000, 1111111111. This code has distance of 5 (2d +1= 5). If a codeword 0000000111 arrives, the closest valid codeword is

    0000011111 (2-bit error, d = 2). Then the receiver can determine the original codeword. If there are 3-bit errors, this code is unable to correct.

  • ECE/CSC 570, NC State University

    Hamming Code (Error Correcting Code)n The bits of the codeword are numbered consecutively,

    starting from bit 1 at the left end. 1 2 3 4 5 6 7

    Original code 1 0 0 1 0 0 0n The bits that are powers of 2 (1,2,4,8) are check bits, so

    the codeword becomes1 2 3 4 5 6 7 8 9 10 11

    Codeword x x 1 x 0 0 1 x 0 0 0 n The rest (3,5,6,7) are filled up with the m (=7) data bitsn Any k that is not a power of 2 can be written as a sum of

    powers of 2. Data bit in k will contribute to some of the check bits. E.g., k = 11 = 1+2+8, which means it contributes to the check bits 1, 2, 8.

  • ECE/CSC 570, NC State University

    Hamming Code: Example

    n Consider a (7,4) code: 4 bits message+3 parity bits 7 bits codeword 3 = 1+2 : 5 = 1+4 : 6 = 2+4 : 7 = 1+2+4

    4(Even Parity)DDDP---

    2(Even Parity)DD--DP-

    1(Even Parity)D-D-D-P

    Check bit contributed7-bit codewordDDDPDPP

    7654321

  • ECE/CSC 570, NC State University

    Hamming Code: Example (contd)

    4(Even Parity)1100---

    2(Even Parity)11--11-

    1(Even Parity)1-0-1-0

    Check bit contributed7-bit codeword1100110

    7654321

    n Rule: Each circle must have EVEN parity.

    n Message 1011 would be sent as 0110011, since

  • ECE/CSC 570, NC State University

    Hamming Code: Example (contd)n Single bit error (bit) occurs: 0110011 0110111

    n The bad parity bits labeled 101 point directly to the bad bit (101 = 5 !)

    (NOT!) 1(Even Parity)1110---

    (OK!) 0(Even Parity)11--11-

    (NOT!) 1(Even Parity)1-1-1-0

    Parity computed7-bit codeword1110110

    7654321

  • ECE/CSC 570, NC State University

    Hamming Code: Example (contd)

    n Correction of single bit errorsn Detection of 2 bit errors (assuming no

    correction is attempted)n Cost of 3 bits added to a 4-bit message.n In general, Hamming distance = 3The minimum distance between any two valid

    codewords is 3 allows error correction of one bit and detection of 2 bits.

  • ECE/CSC 570, NC State University

    Hamming Code (contd)

    Use of a Hamming code to correct burst errors.

    When a codeword arrives, the receiver initializes a counter to zero. It then examines each check bit, k, to see if it has the correct parity. If k = 0 after the whole examination, the codeword is accepted. Otherwise, it contains the number of the incorrect bit, (1+2+8 = 11) Hamming codes can only correct single errors. To correct burst errors, transmit one column at a time.

  • ECE/CSC 570, NC State University

    Cyclic Redundancy Check (CRC)n The basic idea is to start with a bit string and to generate

    parity checks on various subsets of the bits.n The most common code is the polynomial code Bit string is represented by a polynomial with coefficients of 0 and 1

    only. A k-bit frame is regarded as a polynomial with k terms, ranging from

    xk-1 to x0 . It is called a polynomial of degree (k-1) If the data bits are denoted as mK-1, mK-2, , m1,m0, the polynomial

    M(x) representation of the string with coefficients is

    M(x) = mK-1xK-1 + mK-2xk-2 + , +m1x + m0

  • ECE/CSC 570, NC State University

    CRC (Contd)n Both the sender and receiver agree upon a generator

    polynomial, G(x) of degree r.

    n G(x) = xr+gr-1xr-1++g1x+1 G(x) has at least two nonzero terms (i.e., xr and 1)

    n Rule of the game: r(x) = Remainder[M(x)xr /G(x)] This is a ordinary long division of one polynomial by another, except

    that the coefficients are restricted to be binary, and the arithmetic on coefficients is performed modulo 2.

    n What is modulo 2 arithmetic?

    n The CRC polynomial T(x) = M(x)xr r(x) = M(x)xr+r(x) The remainder is of degree at most r-1.

    n If there is no error, T(x) must be divisible (modulo) by G(x)

  • ECE/CSC 570, NC State University

    Example of Polynomial

    Example: r=3 and k=32 3

    2

    G(x) 1 x xM(x) 1 x

    = + +

    = +( m2m1m0=101)

    x x3 2 1+ + x x5 3+x 2

    x x x5 4 2+ +x x x4 3 2+ +

    + x

    x x x4 3+ +x x2 + Remainder

    Code-polynomial T(x) = x5 + x3 +x2 + x

  • ECE/CSC 570, NC State University

    Error-Detecting Codes

    Calculation of the polynomial code checksum.

    1. Add (r=4) zero bits at the end of frame polynomial

    2. Divide by G(x)3. Subtract (or add) the remainder

    from the bit string corresponding to xrM(x)

    11010110110000- 1110

    11010110111110

  • ECE/CSC 570, NC State University

    Error Detection with CRCn T(x) is divisible by G(x), so the remainder should be zero for correct

    transmission.

    1101011011111010011

    1001110011

    00001000000001000000

    00101000000101100000

    10111100110100100000

    10011

    100111100001010

    Assume there is an error occurs, so the received bit string is T(x) + E(x) (in module 2!!)

    Each 1 bit in E(x) corresponds to a bit that has been inverted. If there are k 1 bits in E(x), k single-bit errors have occurred.

  • ECE/CSC 570, NC State University

    Error Detection with CRC (2)

    n If no errors occur, then E(x) = 0 remainder =0n E(x) 0 is undetectable if and only if

    E(x) = G(x) z(x), where z(x) is nonzero polynomial.

    ])()([Re

    ])()(

    )()([Re])(

    )([Re

    xGxEmainder

    xGxE

    xGxTmainderxG

    xYmaider

    =

    +=

    T(x) Y(x)=T(x)+E(x)Channel

  • ECE/CSC 570, NC State University

    n If there is a single error, then E(x)=xj for some j . Since G(x) has at least two non- zero terms xr and 1,it follows that G(x) z(x) must also have two non-zero terms for any non-zero z(x) . Consequently G(x)z(x)cannot equal E(x) .

    This means that all single errors can be detected.

    Single Error

  • ECE/CSC 570, NC State University

    Double Errors

    n We know that xj is not divisible by G(x). So only if xi-j +1 is divisible by G(x) will we fail to detect double errors. G(x) is carefully chosen such that it does not divide xk+1 for any kup to the maximum value of (i-j) (the max. frame length) a primitive polynomial

    Double errors can be detected.

    n E.g., x15+x14+1 will not divide xk+1 for any value of k below 32,768!

    jixxxxxE jijji >+=+= - where)1()(

  • ECE/CSC 570, NC State University

    CRC Propertiesn In most CRC implementations the G(x) used is of the form

    G(x)=(x+1) { primitive polynomial of degree r-1 }.n A polynomial E(x) is divisible by x+1 if and only if E(x)

    contains an even number of non-zero coefficients. If E(x) has an odd number of terms, substituting 1 for x everywhere will always yield 1 as the result. Thus, no polynomial with an odd number of terms is divisible by x+1.

    n This nice property ensures that all odd number of errors can be detected.

  • ECE/CSC 570, NC State University

    CRC Properties (Contd)

    n The degrees of the highest and lowest order terms of G(x) differ by r.

    n For G(x)z(x), it must be that the difference between the highest and lowest degree is at least r. Thus if E(x) is a error polynomial, then the burst length of errors must be at least r+1. This means that all bursts of length r can be detected because the burst stream has 1 at the first and last bits.

  • ECE/CSC 570, NC State University

    Standards

    n Standard CRC polynomials: G(x) = x16+x15+x2+1 CRC-16G(x) = x16+x12+x5+1 CRC-ITU-TG(x)

    =x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x1+1 IEEE 802

  • ECE/CSC 570, NC State University

    Block Codesn The previous discussion is about how to transform

    a message of k bits into a codeword of n (n=k+r) bits with n > k. Accordingly, there are 2k codewordsin a set of 2n binary words.

    n A good code is one where the codewords are as far from each other as possible.

    n Easy to use: coding and decoding. These codes are called block codes because they group the source bits into blocks of k bits that they encode and decode independently of one anotherone word at a time.

    n Probability of failing to detect errors in random string = 2-r

  • ECE/CSC 570, NC State University

    Practical Implementations of CRC

    Feedback Shift Register

    rM(x) xR(x) Rem{ }G(x)

    =

    g g g1 2 m -1In p u t

    ++ + + . . .

    How the long division (by modulo 2) is done?

  • ECE/CSC 570, NC State University

    Example: r = 3 and k = 32 3

    2

    G(x) 1 x xM(x) 1 x

    = + +

    = +

    Input 101000

    First bit into the circuit

    Initial values

    Remainder 110011111101010001000

    + +Input

    r(x) = x2+x

  • ECE/CSC 570, NC State University

    Other Error-Detecting Codes

    n Convolutional Codesn Decoding:Maximum likelihood detectionTrellis decoding

    n Usually involves number theory!