CS4470 Computer Networking Protocols 2/10/2018 CS4470 Computer Networking Protocols 3. Data Link Layer Huiping Guo Department of Computer Science California State University, Los Angeles
Outline Overview of data link layer Framing Error detection 2/10/2018 Outline Overview of data link layer Framing Error detection 3. Link CS470
Data link layer overview 2/10/2018 Data link layer overview Network layer Network layer Data Data Data H T frame Link layer Link layer Data H T 11001010… 11001010… Physical layer Physical layer 3. Link CS470
Data link layer overview (cont.) Achieve reliable, efficient communication between two physically connected machines Make use of services provided by the physical layer Get a series of bits Provide services to the network layer The kind of services depends on the link layer protocol How to make a link appear reliable A link may corrupt frame from time to time 3. Link CS470
Design issues Services interface to the network layer How to group bits into frames (framing) How to deal with errors (error control) Errors in the physical layer How to mediate access to a link if the link is shared by multiple hosts 3. Link CS470
Framing Break the bit stream into frames Why framing? Raw bit stream cannot provide any error detection capability. Bits may change (lightning strikes). Bits may get lost (clock drift). Challenge How to delimitate frames? 3. Link CS470
How to do framing Character count Flag bytes with byte stuffing Starting and ending flags with bit stuffing 3. Link CS470
Character count Uses a field in the header to specify the number of characters in the frame 5 1 2 3 4 5 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3 frame1 frame2 frame3 frame4 Problem: What if the count is corrupted error 5 1 2 3 4 7 6 7 8 9 8 0 1 2 3 4 5 6 8 7 8 9 0 1 2 3 frame1 frame2: wrong ! 3. Link CS470
Flag bytes with byte stuffing Each frame start and end with special bytes Soh block of data in frame eot Flag bytes Start of header: soh End of text: eot 3. Link CS470
What if the data contains the flag? Byte stuffing Uses another special flag. Translates the data to alternative form 3. Link CS470
Illustration of Frame with byte stuffing After byte stuffing, the characters soh and eot do not occur in the data Stuffed frame longer than original 3. Link CS470
Disadvantages of byte stuffing It is closely tied to the use of 8-bit characters Not all character codes use 8-bit characters UNICODE uses 16-bit characters How to support flags with arbitrary sized characters? 3. Link CS470
Bit stuffing Allows data frames to contain an arbitrary number of bits Allows character codes with an arbitrary number of bits per character Each frame begins and ends with a special bit pattern (01111110) It’s like flag byte 3. Link CS470
Bit stuffing (cont.) Receiver hunts for flag sequence to synchronize To avoid confusion with data containing 01111110 0 inserted after every sequence of five 1s If receiver detects five 1s it checks next bit If 0, it is deleted If 1 and seventh bit is 0, accept as flag If sixth and seventh bits 1, sender is indicating abort 3. Link CS470
Bit Stuffing 3. Link CS470
Exercise 2. Suppose the following sequence of bits arrive over a link Assuming a framing protocol that uses bit stuffing, show the bit sequence transmitted over the link when the frame contains the following bit sequence 1 1 0 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 2. Suppose the following sequence of bits arrive over a link 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 Show the resulting frame after any stuffed bits have been removed. 3. Link CS470
Error Detection Parity bits Checksum Cyclic Redundancy Code (CRC) 3. Link CS470
Parity Checking Single Bit Parity: Detect single bit errors 1 Count the number of 1s in the received d+1 bits. An odd number indicates at least one bit errors with an even parity scheme. 3. Link CS470
Parity Checking Two Dimensional Bit Parity: d bits are organized into ixj bit array Parity checking for each column and row Resulting i+j+1 parity bits Detect and correct single bit errors Forward error correction (FEC) Can also detect any combinations of two bit errors 3. Link CS470
Checksum Sender: Receiver: treat data as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents Attach the checksum to the end of data segments Receiver: Sum up data and checksum The results are all 1s? Yes, no errors No, errors. 3. Link CS470
2/10/2018 Checksum Example Note When adding numbers, a carryout from the most significant bit needs to be added to the result Example: add two 16-bit integers 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 wraparound Kurose and Ross forgot to say anything about wrapping the carry and adding it to low order bit sum checksum 3. Link CS470
Exercise Calculate the checksum for the following binary numbers. Give the result in binary. Use the 16-bit format. 11000111 11100001 10000111 10001001 11100101 10100011 11111111 11100111 3. Link CS470
Cyclic Redundancy Check A major goal in designing error detection algorithm is to maximize the probability of detecting errors using only a small number of redundant bits CRC uses some fairly powerful mathematics to achieve this goal The theoretical foundation of the CRC is finite field 3. Link CS470
Cyclic Redundancy Check An (n+1) bit message is represented by an n degree polynomial, a polynomial whose highest-order term is xn. The message is represented by a polynomial The value of each bit in the message is as the coefficient for each term in the polynomial The most significant bit represents the hightest-order term Eg. An 8-bit message 10011010 corresponds to the polynomial M(x) = 1 * x7 + 0 * x6 + 0 * x5 + 1 * x4 + 1 * x3 + 0 * x2 + 1 * x1 + 0 * x0 = x7 + x4 + x3 + x We can think of a sender and a receiver as exchanging polynomials with each other 3. Link CS470
Cyclic Redundancy Check view data bits, D, as a binary number choose r+1 bit pattern (generator), G goal: choose r CRC bits, R, such that <D,R> exactly divisible by G (modulo 2) receiver knows G, divides <D,R> by G. If non-zero remainder: error detected! can detect all burst errors less than r+1 bits widely used in practice (ATM, HDCL) 3. Link CS470
CRC Example D.2r R = remainder[ ] G Want: D.2r + R = nG equivalently: if we divide D.2r by G, want remainder R R = remainder[ ] D.2r G 3. Link CS470
Exercise D=11100110, G=11001, r=4 R=? The transmitted bits=? If no error occurs, how the receiver knows the received bits are correct? 3. Link CS470