Introduction to Computer Networks 03 Data Link Layer Introduction
Link Layer 1 Introduction and services 2 Link Layer Services 2.1 Framing 2.2 Error detection and correction 2.3 Flow Control 2.4 Multiple access protocols 2.5 Switching 3 Ethernet
Link Layer: Introduction Some terminology: hosts and routers are nodes communication channels that connect adjacent nodes along communication path are links wired links wireless links LANs layer-2 packet is a frame, encapsulates datagram data-link layer has responsibility of transferring datagram from one node to adjacent node over a link
Link Layer Services framing, link access: encapsulate datagram into frame, adding header, trailer channel access if shared medium MAC addresses used in frame headers to identify source, dest different from IP address! reliable delivery between adjacent nodes We ll talk more about this when we discuss the Transport Layer seldom used on low bit-error link (fiber, some twisted pair)
Link Layer Services (more) flow control: pacing between adjacent sending and receiving nodes error detection: errors caused by signal attenuation, noise. receiver detects presence of errors: signals sender for retransmission or drops frame error correction: receiver identifies and corrects bit error(s) without resorting to retransmission
Where is the link layer implemented? in each and every host link layer implemented in adaptor (aka network interface card NIC) Ethernet card, PCMCI card, 802.11 card implements link, physical layer attaches into host s system buses combination of hardware, software, firmware application transport network link link physical cpu controller physical transmission host schematic memory host bus (e.g., PCI) network adapter card
Adaptors Communicating datagram datagram controller controller sending host frame datagram receiving host sending side: encapsulates datagram in frame adds error checking bits, flow control, etc. receiving side looks for errors,, flow control, etc extracts datagram, passes to upper layer at receiving side
From Signals to Packets Analog Signal Digital Signal Bit Stream 0 0 1 0 1 1 1 0 0 0 1 Packets 0100010101011100101010101011101110000001111010101110101010101101011010111001 Header/Body Header/Body Header/Body Packet Transmission Sender Receiver
Link Layer 1 Introduction and services 2 Link Layer Services 2.1 Framing 2.2 Error detection and correction 2.3 Flow Control 2.4 Multiple access protocols 2.5 Switching 3 Ethernet
Framing Byte Stuffing (also called sentinel) - Approach To view each frame as a collection of bytes (characters) rather than bits E.g. BISYNC (Binary Synchronous Communication) Protocol Developed by IBM (late 1960) Frame parts are denoted by sending special characters E.g. Syn 0x10 in BISYNC What happens when the special character is encountered in the data stream? Escape: DLE character in BISYNC
Framing BISYNC sentinel approach Frames transmitted beginning with leftmost field Beginning of a frame is denoted by sending a special SYN (synchronize) character Data portion of the frame is contained between special sentinel character STX (start of text) and ETX (end of text) SOH : Start of Header DLE : Data Link Escape CRC: Cyclic Redundancy Check BISYNC Frame Format
Framing Byte-counting approach DDCMP count : how many bytes are contained in the frame body If count is corrupted Framing error DDCMP Frame Format
Framing Bit-Stuffing Approach HDLC : High Level Data Link Control Beginning and Ending Sequences 0 1 1 1 1 1 1 0 HDLC Frame Format If the body contains five consecutive 1 s the sender inserts 0 before transmitting the next bit
Framing HDLC Protocol The receiving side: 5 consecutive 1 s Next bit is 0 : Stuffed, so discard it Next bit is 1: Either end of the frame or an error 6 consecutive 1 s Look at the next bit If 0 ( 01111110 ) End of the frame marker If 1 ( 01111111 ) Error, discard the frame, wait for 01111110
Ethernet Framing Preamble is 7 bytes of 10101010 followed by one byte of 10101011 With Manchester code, 10101 becomes 10 01 10 01 10, which looks like 1 00 11 00 11 0, which looks like a square wave Allows receivers to recognize start of transmission after idle channel 8 Bytes 6 Bytes 6 Bytes 2 Bytes 4 Bytes Each frame is followed by a minimum of 12 bytes of idle time called the Inter-frame Gap (IFG)
Clock-Based Framing Used by SONET and SDH Fixed size frames (810 bytes) Look for start of frame marker that appears every 810 bytes Will eventually sync up
Link Layer 1 Introduction and services 2 Link Layer Services 2.1 Framing 2.2 Error detection and correction 2.3 Flow Control 2.4 Multiple access protocols 2.5 Switching 3 Ethernet
Error Coding Transmission process may introduce errors into a message. Single bit errors versus burst errors Detection: Requires a convention that some messages are invalid Hence requires extra bits Correction Forward error correction: many related code words map to the same data word Detect errors and retry transmission
Error Detection D = Data protected by error checking, may include header fields EDC= Error Detection and Correction bits (redundancy) Error detection not 100% reliable! Protocol may miss some errors, but rarely Larger EDC field yields better detection and correction
Error Coding We ll discuss several error detection and correction codes: One dimension parity bit Error detection Internet checksum Error detection Two dimension parity Error detection and correction CRC Error detection
Parity Checking Single Bit Parity: Detect single bit errors
Internet Checksum Algorithm Not used at the datalink level Add up all the words that are transmitted and then transmit the result The result is called the checksum The receiver compares the result with the received checksum If any transmitted data, including the checksum itself, is corrupted, the receiver knows that an error occurred
Internet Checksum Algorithm Consider the data being checksummed as a sequence of 16-bit integers. Add them together using 16-bit ones complement arithmetic and then take the ones complement of the result. That 16-bit number is the checksum
Internet Checksum Algorithm In ones complement arithmetic, a negative integer x is represented as the complement of x; Each bit of x is inverted. When adding numbers in ones complement arithmetic, a carryout from the most significant bit needs to be added to the result.
Internet Checksum Algorithm To add two numbers represented in one s complement, one does a conventional binary addition, but it is then necessary to add any resulting carry back into the resulting sum Ones complement example: 1111111 11111110 (-1) + 00000010 ( 2) --------------- 100000000 +1 00000001
Internet Checksum Algorithm Easy to calculate From RFC 1071 (1988): /* Compute Internet Checksum for "count" bytes * beginning at location "addr". */ register long sum = 0; while( count > 1 ) { /* This is the inner loop */ sum += * (unsigned short) addr++; count -= 2; } /* Add left-over byte, if any */ if( count > 0 ) sum += * (unsigned char *) addr; /* Fold 32-bit sum to 16 bits */ while (sum>>16) sum = (sum & 0xffff) + (sum >> 16); checksum = ~sum; Easy to update if we have an existing checksum and we ve changed a few bits in a packet
Basic Concept: Hamming Distance Hamming distance of two bit strings = number of bit positions in which they differ. If the valid words of a code have minimum Hamming distance D, then D-1 bit errors can be detected. If the valid words of a code have minimum Hamming distance D, then [(D-1)/2] bit errors can be corrected. 1 0 1 1 0 1 1 0 1 0 HD=2 HD=3
Example: Parity What is the minimum Hamming distance between to valid code words using a single parity bit? How many bit errors can always be detected with parity? If there are more bit errors, how often will they be detected? What is [(D-1)/2] for parity? How many bit errors can be corrected with parity?
2D Parity 0 0
Cyclic Redundancy Check (CRC) Reduce the number of extra bits and maximize protection Based on polynomial arithmetic mod 2 Polynomial Arithmetic Modulo 2: Given a bit string 110001 we can associate a polynomial on a single variable x for it: 1.x 5 +1.x 4 +0.x 3 +0.x 2 +0.x 1 +1.x 0 = x 5 +x 4 +1 and the degree is 5.
Cyclic Redundancy Check (CRC) The coefficients are a single bit 0 or 1 Odd coefficients correspond to 1 (mod 2) Even coefficients correspond to 0 (mod 2) This way addition and multiplication can be performed: We can even do division:
Cyclic Redundancy Check (CRC) Let M(x) be a message polynomial and C(x) be a generator polynomial. Let M(x)/C(x) leave a remainder of 0. When M(x) is sent and M (x) is received we have M (x) = M(x)+E(x) The receiver computes M (x)/c(x) and if the remainder is nonzero, then an error has occurred. The only thing the sender and the receiver should know is C(x).
Cyclic Redundancy Check (CRC) How to create a frame with CRC: Let D(x) be an m bit message without CRC Let C(x) be an r bit generator (r<m) Append r-1 zero bits to the end of the message, so it contains m+r-1 bits and corresponds to x r D(x) Calculate the remainder R of the division x r D(x)/C(x) Subtract R from x r D(x) using modulo 2 subtraction (same as addition) The result is the frame M(x) to be transmitted.
Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check (CRC) Now we send The receiver calculates
Cyclic Redundancy Check (CRC) A Second example (from a different book)
Cyclic Redundancy Check (CRC) Properties of Generator Polynomial Let M(x) represent what the sender sent and M (x) = M(x) + E(x) is the received string. A 1 in E(x) represents that in the corresponding position in M(x) the message the bit is flipped. We know that M(x)/C(x) leaves a remainder of 0, but if E(x)/C(x) leaves a remainder of 0, then either E(x) = 0 or C(x) is factor of E(x). When C(x) is a factor of E(x) we have problem; errors go unnoticed. If there is a single bit error then E(x) = x i, where i determines the bit in error. If C(x) contains two or more terms it will never divide E(x), so all single bit errors will be detected.
Cyclic Redundancy Check (CRC) Six generator polynomials that have become international standards are: CRC-8 = x 8 +x 2 +x+1 CRC-10 = x 10 +x 9 +x 5 +x 4 +x+1 CRC-12 = x 12 +x 11 +x 3 +x 2 +x+1 CRC-16 = x 16 +x 15 +x 2 +1 CRC-CCITT = x 16 +x 12 +x 5 +1 CRC-32 = x 32 +x 26 +x 23 +x 22 +x 16 +x 12 +x 11 +x 10 +x 8 +x 7 +x 5 +x 4 +x 2 +x+1
Link Layer 1 Introduction and services 2 Link Layer Services 2.1 Framing 2.2 Error detection and correction 2.3 Flow Control 2.4 Multiple access protocols 2.5 Switching 3 Ethernet
A Naïve Protocol Sender simply sends to the receiver whenever it has packets. Potential problem: sender can outrun the receiver. Receiver too slow, buffer overflow,.. Not always a problem: receiver might be fast enough. Sender Receiver
Adding Flow Control Stop and wait flow control: sender waits to send the next packet until the previous packet has been acknowledged by the receiver. Receiver can pace the receiver Sender Receiver
Stop & Wait Sender RTT Receiver Time Max Throughput = 1 pkt Roundtrip Time
Window Flow Control Stop and wait flow control results in poor throughput for long-delay paths: packet size/ roundtrip-time. Solution: receiver provides sender with a window that it can fill with packets. The window is backed up by buffer space on receiver Receiver acknowledges the a packet every time a packet is consumed and a buffer is freed Sender Receiver
Go-Back-N Sender RTT Receiver Time Max Throughput = Window Size Roundtrip Time
Flow Control Stop & Wait as well as Go-Back-N (GBN) are called ARQ protocols (Automatic Repeat request) Used for flow control and reliability In reality both ARQ and flow control is often not implemented or used at L2 E.g. regular Ethernet, just uses CRC for error detection We ll discuss both flow control and ARQ in the transport layer.
These slides were based on: CMU s 15-441 course with permission from Roger Dannenberg and Srinivasan Seshan Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009. Computer Networks: A Systems Approach, 5e. Larry L. Peterson and Bruce S. Davie