Title: CPET 355
1CPET 355
- 3. The Data Link Layer
- Framing, Error Detection
- and
- Correction
- Paul I-Hai Lin, Professor
- Electrical and Computer Engineering Technology
- Purdue University, Fort Wayne Campus
2Topics of Discussion
- Framing
- Error Detection
- Error Correction
3Framing
- Framing Marking Methods
- Character count
- Flag byte with byte stuffing
- Starting and ending flags, with bit stuffing
- Physical layer coding violations
4Framing Character Count
- Use a field in the header to specify the number
of characters in the frame - Disadvantage the count can be garbled by a
transmission error the problem of
resynchronization - An example
Character Count
5 a A b b 4 6 w w 1 2 y y 8 a b c d e f 1 2
5Framing Flag Bytes with Byte Stuffing
- Resolve the resynchronization problem
- Use a flag byte as the starting ending
delimiter - Potential problems
- When sending objects that containing
floating-point numbers It can be resolved by
inserting an ESC byte - Strong tie to 8-bit character cannot handle
Unicode (16-bit character coding International
languages) - An example Point-to-Point Protocol used by
Internet Service Provider with modem
6Framing Flag Bytes with Byte Stuffing
Flag Header Payload field Trailer Flag
Original Characters
After Stuffing
A ESCFLAG B
A FLAG B
A ESCESCB
A ESC B
A ESCFLAG B
A ESCESCESCFLAG B
A ESCESCB
A ESCESCESCESC B
7Framing Bit Stuffing
- Allow data frames to contain an arbitrary number
of bits, and character coding - Starting ending delimiter a special bit
pattern (flag byte) 01111110 - Sender stuffing a 0 when encounter five
consecutive 1s in the data - Receiver destuffing a 0 when it sees five
consecutive 1s
8Framing Bit Stuffing
The Original Data
01101111101111110
0110111110011111010
Stuffed 0 bits
9Checksums
- Checksum Calculation
- ASCII value of a Character x 128
- Divide the number by 255
- The remainder is the checksum
- An Example
- ASCII A 0100 00012 6510
- 65 x 128 8320
- 8320/255 32 remainder 160
- Transmitted checksum character is 160 (010 00002)
10Hamming Distance
- Error detection and correction
- The number of bit position in which two codeword
is differ called the hamming distance (1950) - To detect d errors, we need a distance of d 1
code - To correct d errors, we need 2d 1 code
11Hamming Distance
- Example two code words, 3 bits differ or a
hamming distance of 3 - Code Word 1 1000 1001
- EXOR --------------
- Code Word 2 1011 0001
- --------------
- 0011 1000
- Count the number of 1-bit 3
12Parity Bit
- Even parity or odd parity for detect 1-bit error
with a distance of 2 - Example
- Set 8-bit code
- x101 1010 as even parity code
- 0101 1010
- Set 8-bit code
- x101 1010 as odd parity code
- 1101 1010
13Hamming Code for Error Correction
- Correct a single error or burst errors
- 7-bit ASCII code, 11-bit code word
- Data are found in bit positions 3, 5, 6, 7, 9,
10, and 11 - Check bits are found in bit positions 1, 2, 4,
and 8 - Bit 11 1 2 8 10 2 8 9 1 8 7 1
2 4 6 2 4 5 1 5 3 12
14Hamming Code for Error Correction
- An Example
- Bit positions (1 2 3 4 5 6 7 8 9 10 11)
- H 1001000 ? 0011001000
15Checksums
- Checksum Calculation
- ASCII value of a Character x 128
- Divide the number by 255
- The remainder is the checksum
- An Example
- ASCII A 0100 00012 6510
- 65 x 128 8320
- 8320/255 32 remainder 160
- Transmitted checksum character is 160 (010 00002)
16Internet Checksums
- RFC 1071 Computing Internet Checksum,
http//www.faqs.org/rfcs/rfc1071.html - unsigned short checksum(unsigned short addr, int
count) - / Compute Internet checksum for count bytes
beginning at location addr/ - register long sum 0
- while( count gt 1 )
- / This is the inner loop /
- sum addr
- count - 2
17Internet Checksums
- / Add left-over byte, if any /
- if( count gt 0 )
- sum addr
- / Fold 32-bit sum to 16 bits /
- while (sumgtgt16)
- sum (sum 0xffff) (sum gtgt 16)
- checksum sum
- / end of checksum() function /
18Internet Checksums C Program
- Comments
- / / --- C style
- // --- C and Java style
- Function (name, input parameters types, a
return value type) - unsigned short checksum(unsigned short addr, int
count) - Return value sum
19Internet Checksums C Program
- Grouping of statements, functions, etc
-
- ( )
- Data types
- register long sum 0
- unsigned short addr --- Pointer type
- int count
20Internet Checksums C Program
- Decision making program loop control
- while, for, do while
- if
- Operators
- Add assign
- - Sub assign
- Increment
- -- Decrement
21Internet Checksums C Program
- Operators (continue)
- Remainder
- / Integer Quotient (or float division)
- Bit-wise AND
- Bit-wise OR
- Exclusive OR
- Bit-wise NOT (1s complement)
- gtgt Shift to the Right
- ltlt Shift to the Left
22Cyclic Redundancy Checks (CRCs) Frame Check
Sequence
- Generator Polynomial Codes G(x) - for generating
frame check sequence - CRC-12 (for 6-bit characters)
- x12 x11 x3 x2 x1 1
- CRC-16 (for 8-bit characters)
- x16 x15 x2 1
- CRC-CCITT x16 x12 x5 1
- CRC-32 (used in IEEE 802)
- x32 x26 x23 x22 x16 x12 x11 x10
x8 x7 x5 x4 x2 x1 1
23Cyclic Redundancy Checks (CRCs) Frame Check
Sequence
- An Example
- G(x) x4 x1 1
- M(x) message frame 1101011011
- R(x) remainder is computed from MOD2 operation
1110 - T(x) transmitted sequence plus append R(x) at the
end M(x) R(x)
11010110111110
24Number Systems in C
- Decimal Octal Hex
- 0 00 0x0
- 1 01 0x1
- 2 02 0x2
- 3 03 0x3
- 4 04 0x4
- 5 05 0x5
- 6 06 0x6
- 7 07 0x7
25Number Systems in C
- Decimal Octal Hex
- 8 010 0x8
- 9 011 0x9
- 10 012 0xa or 0xA
- 11 013 0xb or 0xB
- 12 014 0xc or 0xC
- 13 015 0xd or 0xD
- 14 016 0xe or 0xE
- 15 017 0xf or 0xF
26Cyclic Redundancy Checks (CRCs) Frame Check
Sequence
- An Implementation Using C Language
- unsigned short Gx 0x0013 /x4 x1 1/
- unsigned short Mx 0x035D /1101011011/
- unsigned short Rx Qx Tx 0x0000
- Rx GxMx / reaminder, 1-bit less than Gx /
- Qx Gx/Mx / quotient /
- Tx Tx Mx / Tx Mx /
- Tx ltlt 5 / Shift Tx to the left for
5-bit / - Tx Qx / Append quotient bits /