77
Department of Computer Science DCS COMSATS Institute of Information Technology Advanced Computer Networks Rab Nawaz Jadoon Assistant Professor COMSATS University, Lahore Pakistan Advanced Computer Networks

Advanced Computer Networks Rab Nawaz Jadoon · Department of Computer Science 28 DATA Link Layer For block coding we use modulo-2 arithmetic's. In this arithmetic, the modulus N is

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • Department of Computer Science

    DCS

    COMSATS Institute of Information Technology

    Advanced Computer Networks

    Rab Nawaz JadoonAssistant Professor

    COMSATS University, Lahore

    Pakistan

    Advanced Computer Networks

  • Department of Computer Science 22

    Course Plan

    Lectures

    Seminars

    Reading of various Research Papers

    Presentations by the students on selected topics

    Quizzes and Reports

    Recommended Books

    Data Communication & Networks by Behrouz A. Forouzan

    Computer Networks by Andrew Tannenbaum

  • Department of Computer Science 3

    Grading

    Percentage Grade GP

    90% and above A 4

    80% to 89% B 3.5

    70% to 79% C 3

    60% to 69% D 2.5

    Below 60% F 0

  • Department of Computer Science 4

    Marks Distribution

    Description Weight age

    Quiz/Assignment 25%

    Midterm 25%

    Final 50%

  • Department of Computer Science 5

    Layer Task

    The Letter is written, put in

    envelop and dropped in

    mailbox.

    The Letter is carried from

    mailbox to a post office.

    The Letter is delivered to a

    carrier by the post office.

    The Letter is picked up,

    removed from the envelop

    and read.

    The Letter is carried from

    the post office to the

    mailbox.

    The Letter is delivered from

    the carrier to the post office

  • Department of Computer Science 6

    OSI layers

  • Department of Computer Science 7

    Internet Model

    H5 D5 (Application Layer)

    H4 D4 ( Transport Layer)

    H3 D3 ( Network Layer)

    H2 D2 ( Data Link Layer)

    Physical Layer

    Layered Architecture

  • Department of Computer Science 8

    Organization of layers

    TCP/IP protocol suite can be divided into threesubgroups

    Network support layers

    Deals with the physical aspect of the moving data from onedevice to other device

    Electrical specification, physical connections, addressingtiming and reliability

    User support layer

    Transport layer links the two subgroups

  • Department of Computer Science 9

    Functionality of layers

    Physical Layer

    Responsible for transmitting individual bits from onenode to another.

    It defines the physical characteristics of the interfacebetween the device and transmission media.

    Representation of bits into signals.

    Data rate such as duration of bits.

    Clock Synchronization of bits.

    Multiplexing

  • Department of Computer Science 10

    Functionality of layers

    Data link Layer

    Responsible for transmitting frames from one nodeto another.

    Framing: it divides stream of bits received fromnetwork layer into manageable data units calledframes.

    Physical addressing

    Flow Control

    Error Control: it adds reliability to the physical layerby adding mechanism to detect and retransmitdamaged or lost frames. Trailer

    Access control

  • Department of Computer Science 11

    Functionality of layers

    Network Layer

    Responsible for original source to final destinationdelivery of packet across multiple networks.

    It oversees the delivery of the packets between twosystems on the same networks.

    Logical addressing.

    Routing

  • Department of Computer Science 12

    Functionality of layers

    Transport Layer

    Responsible for delivery of a message from processto process delivery.

    Also maintaining the logical connections betweensender and receiver

    Port Addressing.

    Segmentation and reassembly.

    Connection control

    Flow control

    Error Control

  • Department of Computer Science 13

    Functionality of layers

    Application Layer

    Responsible for providing services to user.

    Mail services

    File Transfer and access.

    Remote login

    Accessing www

  • Department of Computer Science 14

    OSI Model

    Presentation Layer

    It is concerned with the syntax and semantics of theinformation exchange between two systems.

    Translation: sender dependent format to commonformat.

    Encryption

    Compression

  • Department of Computer Science 15

    Summary

    Node-to-Node Delivery

    (At MAC Layer)

    Host-to-Host Delivery

    (At Network Layer)

    Process-to-Process Delivery

    (At Transport Layer)

  • Department of Computer Science 16

    TCP/IP Suit

  • Department of Computer Science 17

    Comparison of Network models

  • Department of Computer Science 18

    Functioning of Layers

  • Department of Computer Science 19

    Data Link Layer

    Common responsibilities and functionalities provided by DATA Link Layer,

    Hop to Hop Delivery

    Also include framing, addressing, flow control, error control, and media access control.

    The data link layer divides the stream of bits received from the network layer into manageable data units called frames.

    The data link layer adds a header to the frame to define the addresses of the sender and receiver of the frame.

  • Department of Computer Science 20

    Data Link Layer

    Flow Control

    If the rate at which the data are absorbed by the receiver is less than the rate at which data are produced in the sender, the data link layer imposes a flow control mechanism to avoid overwhelming the receiver.

    Error Control

    It also adds reliability to the physical layer by adding mechanisms to detect and retransmit damaged, duplicate, or lost frames.

  • Department of Computer Science 21

    DATA Link Layer

    Access Control

    When two or more devices are connected to the same link, data link layer protocols are necessary to determine which device has control over the link at any given time.

    Due to this functionality it is also called MAC layer.

  • Department of Computer Science 22

    Error Detection and Correction

    A system must guarantee that the data received should be identical to the data transmitted.

    Data can be corrupted during transmission. Some applications require that errors be detected and corrected.

    Many factors can alter one or more bits of a message.

  • Department of Computer Science 23

    Error Detection and Correction

    Error vs. Fault Fault leads to error and error leads to failure.

    Types of errors Single bit error

    Single-bit errors are the least likely type of error in serial data transmission.

    Burst error The term burst error means that 2 or more bits in the data

    unit have changed from 1 to 0 or from 0 to 1.

  • Department of Computer Science 24

    DATA Link Layer

    Burst Error

    In figure below, 0100010001000011 was sent, but 0101110101100011 was received.

    Burst error does not occur in consecutive bits.

    The length of the burst is measured from the first corrupted bit to the last corrupted bit.

    Burst error of length 8

  • Department of Computer Science 25

    Data link layer

    Redundancy

    The central concept in detecting or correcting errors is redundancy.

    This is done through by sending extra bits with the data to be sent.

    These redundant bits are added by the sender and removed by the receiver.

    It helps the receiver to detect and then correct the corrupted bits.

  • Department of Computer Science 26

    Data link layer

    Coding

    Redundancy is achieved through various coding schemes.

    The sender adds redundant bits through a process that creates a relationship between the redundant bits and the actual data bits.

    The receiver checks the relationships between the two sets of bits to detect or correct the errors.

    Block coding is used to do the stuff.

  • Department of Computer Science 27

    Data Link Layer

    Message

    Generator

    Message +

    redundancy

    Message

    Checker

    Received DATA

    Sender Receiver

    Unreliable transmission

    Accepted or discarded

    Encoder Decoder

  • Department of Computer Science 28

    DATA Link Layer

    For block coding we use modulo-2 arithmetic's.

    In this arithmetic, the modulus N is 2.

    Mean that use only 0 and 1.

    Operations in this arithmetic are very simple.

    The following shows how we can add or subtract 2 bits.

    In this arithmetic we use the XOR (exclusive OR) operation for both addition and subtraction.

    Adding: 0+0=0 0+1=1 1+0=1 1+1=0 Subtracting: 0 -0=0 0- 1=1 1 - 0 =1 1-1 =0

  • Department of Computer Science 29

    BLOCK Coding

    In this coding the actual message is divided into blocks each of k-bits, called data words.

    Then add r redundant bits to each block to make the length n = k + r.

    The resulting n-bit blocks are called codewords. E.g. The 4B/5B block coding

  • Department of Computer Science 30

    Block Coding

    How can errors be detected by using block coding?

    Two ways,

    1. The receiver has (or can find) a list of valid codeword.

    2. The original codeword has changed to an invalid one.

  • Department of Computer Science 31

    Example

    Let us assume that k = 2 and n = 3. Table below shows the list of datawords and codewords.

    A code for error detection

  • Department of Computer Science 32

    Solution

    Assume the sender encodes the dataword 01 as 011 and sends it to the receiver.

    Consider the following cases, The receiver receives 011. It is a valid codeword.

    The codeword is corrupted during transmission, and 111 is received. This is not valid codeword so it is discarded.

    The codeword is corrupted during transmission, and 000 is received. This is a valid codeword. The receiver incorrectly extracts the dataword 00. Two

    corrupted bits have made the error undetectable.

  • Department of Computer Science 33

    Error Correction Mechanism

    Structure of encoder and decoder in error correction,

  • Department of Computer Science 34

    Hamming Distance

    It is a central concept in coding for error control.

    The Hamming distance between two words (of the same size) is the number of differences between the corresponding bits.

    It is depicted as d(x, y).

    It can easily done by applying the XOR operation on the two words and count the number of 1’s in the result.

    The Hamming distance d(10101, 11110) is 3 because 10101 xor 11110 is 01011 (three 1’s).

  • Department of Computer Science 35

    Minimum Hamming Distance

    The minimum Hamming distance is the smallest Hamming distance between all possible pairs in a set of words.

    For example, d(00000, 01011) = 3

    d(01011, 10101) = 4

    d(00000, 10101) = 3

    d(01011, 11110) = 3

    d(00000, 11110) = 4

    d(10101, 11110) = 3

    The dmin in this case is 3.

  • Department of Computer Science 36

    LINEAR BLOCK CODES

    Almost all block codes used today belong to a subset called linear block codes.

    Non linear block codes are not used widely b/c their structure makes the theoretical analysis and implementation difficult.

    A linear block code is a code in which the exclusive OR (addition modulo-2) of two valid codewords creates another valid codeword.

  • Department of Computer Science 37

    Some Linear Block Codes

    Following are some linear block codes are,

    Simple Parity-Check Code

    Most familiar error-detecting code is the simple parity-check code.

    A k-bit dataword is changed to an n-bit codeword where

    n = k + 1.

    The extra bit, called the parity bit, is selected to make the total number of 1’s in the codeword even.

    The minimum Hamming distance for this category is

    dmin = 2

    The code is a single-bit error-detecting code; it cannot correct any error.

  • Department of Computer Science 38

    Simple parity-check code

    Simple parity-check code C(5, 4)

  • Department of Computer Science 39

    Simple parity-check code

    Encoder and decoder for simple parity-check code.

  • Department of Computer Science 40

    Calculating parity mechanism

    This is normally done by adding the 4 bits of the dataword (modulo-2); the result is the parity bit. In other words,

    r0 = a3 + a2 + a1 + a0 (modulo-2)

    If the number of 1’s is even, the result is 0; if the number of 1’s is odd, the result is 1.

    At the reciever end, the addition is done over all 5 bits.

    The result which is called the syndrome, is just 1 bit.

    so = b3 + b2 +b1 + b0 + q0 (modulo-2)

    If so is equal to 0 then no error, if 1 then the dataword is not extracted and hence the dataword is not created.

  • Department of Computer Science 41

    Hamming Codes

    It is a category of error-correcting codes.

    These codes were originally designed with

    dmin = 3, which means that they can detect up to two errors or correct one single error.

    First let us find the relationship between n and k in a Hamming code.

    We need to choose an integer m >= 3.

    The values of n and k are then calculated from m as n = 2m - 1 and k = n - m.

    The number of check bits r = m.

  • Department of Computer Science 42

    Hamming Code Mechanism

  • Department of Computer Science 43

    Hamming Code Mechanism

    A copy of a 4-bit dataword is fed into the generator that creates three parity checks r0, r1, and r2, r0 = a2 + a1 + a0 modulo-2

    r1 = a3 + a2 + a1 modulo-2

    r2 = a1 + a0 + a3 modulo-2

    Each of the parity-check bits handles 3 out of the 4 bits of the dataword.

    The total number of 1’s in each 4-bit combination (3 dataword bits and 1 parity bit) must be even.

    Above three equations are not unique.

    A combination of two equation cannot create the third one.

  • Department of Computer Science 44

    Hamming code C(7, 4)

  • Department of Computer Science 45

    Hamming Code Mechanism

    The checker in the decoder creates a 3-bit syndrome (S2S1SO) in which each bit is the parity check for 4 out of the 7 bits in the received codeword.

    s0 = b2 + b1 + b0 +q0 modulo-2

    s1 = b3 + b2 + b1 +q1 modulo-2

    s2 = b1 + b0 + b3 +q2 modulo-2

    The equations used by the checker are the same as those used by the generator with the parity-check bits added to the right-hand side of the equation.

  • Department of Computer Science 46

    Hamming Code Mechanism

    The 3-bit syndrome creates eight different bit patterns (000 to 111) that can represent eight different conditions.

    Syndrome 000 001 010 011 100 101 110 111

    Error None q0 q1 b2 q2 b0 b3 b1

    Generator is not concerned with the four cases shaded b/c there is either no error or an error in the parity bit.

    In the other four cases, 1 of the bits must be flipped (changed from 0 to 1 or 1 to 0) to find the correct dataword.

  • Department of Computer Science 47

    Example

    Let us trace the path of three datawords from the sender to the destination: Dataword Codeword Received Syndrome

    0100 0100011 0100011 000

    Result: No error

    0111 0111001 0011001 011

    Result: b2 is in error, after flipping b2 we get 0111

    1101 1101000 0001000 101

    Result: b0 is in error, after flipping b0 we get 0000, the wrong dataword.

    Note: This code cannot correct two errors.

  • Department of Computer Science 48

    Burst Error detection and correction

    The key is to split a burst error between several codewords.

    Normally we send a packet or a frame of data.

    Make the hamming code of size N codeword out of our frame to be sent.

    Instead of sending one frame, arrange codeword in table and send the bits in the table a column at a time.

    Bits are sent column by column. (from the left).

  • Department of Computer Science 49

    Burst error correction using H. Code

  • Department of Computer Science 50

    Cyclic Codes

    Cyclic codes are special linear block.

    In a cyclic code, if a codeword is cyclically shifted (rotated), the result is another codeword.

    For example if 1011000 is a codeword, then 0110001 is also a codeword after left shifting the dataword.

  • Department of Computer Science 51

    Cyclic Redundancy Check

    A CRC is an error-detecting code.

    Its computation resembles a polynomial long division operation in which the quotient is discarded and the remainder becomes the result.

    The coefficients are calculated according to the carry-less arithmetic of a finite field.

    The length of the remainder is always less than the length of the divisor.

  • Department of Computer Science 52

    Computation of CRC

    To compute an n-bit binary CRC

    Line the bits representing the input in a row.

    Put the divisor underneath the left-hand end of the row.

    Here is the first calculation for computing a 3-bit CRC,

    11010011101100

  • Department of Computer Science 53

    CRC

    Direct method calculation,

    If the input bit above the leftmost divisor bit is 0, do nothing and move the divisor to the right by one bit.

    If the input bit above the leftmost divisor bit is 1, the divisor is XORed into the input.

    The divisor is then shifted one bit to the right, and the process is repeated until the divisor reaches the right-hand end of the input row.

    Complete calculation is on the next slide.

  • Department of Computer Science 54

    CRC

  • Department of Computer Science 55

    2nd Method of Calculating CRC

    In the encoder, the dataword has k bits(4 here).

    The codeword has n bits(7 here).

    The size of the dataword is augmented by adding n–k (3 here).

    The n-bit result is fed into the generator.

    The generator uses a divisor of size n - k + 1(4 here), predefined and agreed upon i.e. 1011.

    The generator divides the augmented dataword by the divisor (modulo-2 division).

    The quotient of the division is discarded; the remainder (r2r1ro) is appended to the dataword to create the codeword.

  • Department of Computer Science 56

    2nd Method of Calculating CRC

    CRC encoder and decoder

  • Department of Computer Science 57

    CRC

    At decoder end,

    Receives the corrupted codeword.

    All n bits are fed into checker which is replica of the generator.

    Remainder produced by the checker is a syndrome of n-k bits, which is fed into decision logic analyzer.

    If all bits of the syndrome is zero then no error take the 4 leftmost bits of the codeword are accepted, else discarded.

  • Department of Computer Science 58

    At Encoder side

  • Department of Computer Science 59

    At Decoder Side

  • Department of Computer Science 60

    At decoder end

    If the code word changes during transmission, then,

  • Department of Computer Science 61

    Simulation of division in CRC encoder

  • Department of Computer Science 62

    Polynomial representation

    A pattern of Os and 1 s can be represented as a polynomial with coefficients of 0 and 1.

    The power of each term shows the position of the bit; the coefficient shows the value of the bit.

  • Department of Computer Science 63

    Polynomial representation

    X6 + x + 1

    1 0 0 0 0 1 1

    We have seven bit number, the degree of the polynomial is 6 one less then the number of bits in the pattern.

  • Department of Computer Science 64

    Polynomial operation

    Adding and subtracting Adding or subtracting is done by combining terms

    and deleting pairs of identical terms.

    For example adding x5 + x4 + x2 and x6 + x4 + x2

    gives just x6 + x5. The terms x4 and x2 are deleted.

    If we add three polynomial of the same degree then two of them deleted, one is kept left.

    Multiplying or Dividing Terms In multiplications, the powers are added.

    For division subtract the power of the second term from the power of first.

  • Department of Computer Science 65

    Polynomial operation

    Multiplying Two Polynomials Each term of the first polynomial must be multiplied

    by all terms of the second.

    The result, of course, is then simplified, and pairs of equal terms are deleted.

    Shifting Shifting number of bits to the right or left of the

    given pattern.

    Shifting left 3 bits: 10011 becomes 10011000

    x4 +x+ 1 becomes x7 +x4+x 3

    Shifting right 3 bits: 10011 becomes 10

    x 4 + x + 1 becomes x

  • Department of Computer Science 66

    CRC division using polynomials

  • Department of Computer Science 67

    CHECKSUM

    The checksum is used in the Internet by several protocols.

    The checksum is based on the concept of redundancy.

    Basic Idea Suppose our data is a list of five 4-bit numbers.

    send the sum of the numbers along with the data.

    If the set of numbers is (7, 11, 12, 0, 6),

    we send (7, 11, 12, 0, 6, 36).

    The receiver adds the five numbers and compares the result with the sum. If the result is same then no error else data is not accepted.

  • Department of Computer Science 68

    Checksum

    Another heuristic is the negative (complement) of the sum called the checksum.

    We send (7, 11, 12, 0, 6, -36).

    Receiver add all the numbers, if result is 0 then no error otherwise an error.

  • Department of Computer Science 69

    One's Complement

    The previous example has one major drawback.

    The data is of 4 bit word (0 to 15) except checksum.

    One solution is to use the 1’s complement.

    Using unsigned numbers between 0 and 2 n - 1 using only n bits.

    If the number has more than n bits, then wrapping the bits.

    For example, 21 in binary is 10101.

    We can wrap the leftmost bit and add it to the four rightmost bits.

    We have (0101 + 1) = 0110 or 6.

  • Department of Computer Science 70

    Checksum

    Problem

    How can we represent the number -6 in one's complement arithmetic using only four bits?

  • Department of Computer Science 71

    Checksum using 1’s complement

    Let the data to be sent is (7, 11, 12, 0, 6)

    Figure below show the process at the sender and receiver.

  • Department of Computer Science 72

    Checksum computation

    Sender site:

    The message is divided into 16-bit words.

    The value of the checksum word is set to 0.

    All words including the checksum are added using one's complement addition.

    The sum is complemented and becomes the checksum.

    The checksum is sent with the data.

  • Department of Computer Science 73

    Checksum computation

    Receiver Site:

    The message (including checksum) is divided into 16-bit words.

    All words are added using one's complement addition.

    The sum is complemented and becomes the new checksum.

    If the value of checksum is 0, the message is accepted; otherwise, it is rejected.

  • Department of Computer Science 74

    Checksum computation

    Let us calculate the checksum for a text of 8 characters ("Forouzan").

    The text needs to be divided into 2-byte (16-bit) words.

    We use ASCII to change each byte to a 2-digit hexadecimal number.

    F is represented as 0x46 and o is represented as 0x6F.

  • Department of Computer Science 75

    Solution

  • Department of Computer Science 76

    ASCII Chart

  • Department of Computer Science 7777