330 likes | 456 Views
Computer Networks (CSE-4711) Lecture-Segment-4- Data link layer. Instructor: Sazid Zaman Khan Lecturer, Department of Computer Science and Engineering, IIUC. Data Link layer and it’s services.
E N D
Computer Networks (CSE-4711)Lecture-Segment-4- Data link layer Instructor: SazidZaman Khan Lecturer, Department of Computer Science and Engineering, IIUC
Data Link layer and it’s services • The data link layer has to achieve reliable, efficient communication between two adjacent machines at its level: two machines physically connected by a communication channel that acts conceptually like a wire: the bits are delivered in exactly the same order as they are sent. Limitations to deal with are errors in the communication circuit, the finite data rate (in wire and computers) and the nonzero propagation delay between the sending and receiving of a bit. • The data link layer has to provide a well-defined interface to the network layer, has to determine how the bits of the physical layer are grouped into frames to be sent as one block, has to deal with transmission errors and has to regulate the flow of frames, so that slow receivers are not swamped by fast senders.
Data Link layer and it’s services • Following services are commonly provided: • Framing and link access: Almost all link-layer protocols encapsulate each network-layer datagram within a link-layer frame before transmission onto the link. A frame consists of a data field, in which the network-layer datagram is inserted, and a number of header fields. (A frame may also include trailer fields; however, we will refer to both header and trailer fields as header fields.) A data link protocol specifies the structure of the frame, as well as a channel access protocol that specifies the rules by which a frame is transmitted onto the link. • Reliable delivery: If a link-layer protocol provides the reliable-delivery service, then it guarantees to move each network-layer datagram across the link without error. • Flow control: The nodes on each side of a link have a limited amount of packet buffering capacity. This is a potential problem, as a receiving node may receive frames at a rate faster than it can process the frames (over some time interval). Without flow control, the receiver's buffer can overflow and frames can get lost. • Error detection and Error correction.
Framing • Data from the transport layer is broken up into discrete frames which can be of fixed length, using extra padding bits if needed, or of variable length but with a maximum size.
Character count • Field in header gives no. of chars in frame. Shown in (a) below. Char count includes the counting character itself. • If there is an error the entire framing structure is disturbed.
Flag Bytes with Byte stuffing • Let’s begin with a simple idea and develop it into a full, robust scheme. • Flag bytes are special byte values that denote when a frame begins and ends. Suppose that we want to be able to send frames of arbitrary length. A special start flag byte will denote the beginning of the frame, and an end flag byte will denote its end. • A question arises, however. Suppose that the value of the end flag is 0×98. What if the value 0×98 appears somewhere in the data? The protocol will get confused and end the message.
Flag Bytes with Byte stuffing • There is a simple solution to this problem that will be familiar to all programmers who know about escaping quotes and special characters in strings. It is called byte stuffing, or octet stuffing, or simplyescaping. The scheme goes as follows: • Whenever a flag (start or end) byte appears in the data, we shall insert a special escape byte (ESC) before it. When the receiver sees an ESC, it knows to ignore it and not insert it into the actual data received (de-stuffing). • Whenever ESC itself has to appear in the data, another ESC is prepended to it. The receiver removes the first one but keeps the second one
Bit stuffing Input Stream 0110111111100111110111111111100000 Stuffed Stream 01101111101100111110011111011111000000 Stuffed bits Unstuffed Stream 0110111111100111110111111111100000
Cyclic redundancy check (CRC) • the polynomial code, also known as a CRC (Cyclic Redundancy Check). Polynomial codes are based upon treating bit strings as representations of polynomials with coefficients of 0 and 1 only. A k-bit frame is regarded as the coefficient list for a polynomial with k terms, ranging from xk- 1to x0. Such a polynomial is said to be of degree k - 1. The high-order (leftmost) bit is the coefficient of xk- 1; the next bit is the coefficient of xk- 2, and so on. For example, 110001 has 6 bits and thus represents a six-term polynomial with coefficients 1, 1, 0, 0, 0, and 1: x5 + x4 + x0.
Cyclic redundancy check • Polynomial arithmetic is done modulo 2, according to the rules of algebraic field theory. There are no carries for addition or borrows for subtraction. Both addition and subtraction are identical to exclusive OR. For example.
CRC • When the polynomial code method is employed, the sender and receiver must agree upon a generator polynomial, G(x), in advance. Both the high- and low-order bits of the generator must be 1. To compute the checksum for some frame with m bits, corresponding to the polynomial M(x), the frame must be longer than the generator polynomial. The idea is to append a checksum to the end of the frame in such a way that the polynomial represented by the checksummed frame is divisible by G(x). When the receiver gets the checksummed frame, it tries dividing it by G(x). If there is a remainder, there has been a transmission error. • The algorithm for computing the checksum is as follows:
CRC • Let r be the degree of G(x). Append r zero bits to the low-order end of the frame so it now contains m + r bits and corresponds to the polynomial xrM(x). • Divide the bit string corresponding to G(x) into the bit string corresponding to xrM(x), using modulo 2 division. • Subtract the remainder (which is always r or fewer bits) from the bit string corresponding to xrM(x) using modulo 2 subtraction. The result is the checksummed frame to be transmitted. Call its polynomial T(x). • Figure-3-8 illustrates the calculation for a frame 1101011011 using the generator G(x) = x4 + x + 1.
Parity bit checking • Suppose you are transmitting data over a telephone line, say, or even within the computer system itself. How do you know it arrived safely – that is, that nothing was lost or garbled? Sometimes data is lost in transit, owing to bit synchronization, hardware failure, and the like. • To signal the computer that the bits in a byte have stayed the way they are supposed to, another bit is added to the byte as a check. This bit is called a parity bit or check bit. Thus, in an eight-bit EBCDIC byte, the parity bit is a ninth bit. • As figure on the next slide shows, the parity bit stored with each byte alerts the computer system if any bits are flawed or missing because – since we are using an odd parity system – the number of 1 bits must add up to an odd number. (If even parity were used, the number of 1 bits would have to add up to an even number. Computers vary: some use odd parity, some use even.)
Parity bit checking • As you might suspect, a parity check is not infallible. For instance, for any of the letters in Figure, if two 1s were dropped, the number of 1 bits would still add up to an odd number – and the computer would not notice that the byte was erroneous. But two bit failures within one byte in one move are not likely to occur.
Error detection and Correction codes-Hamming Code • The number of corresponding bits that differ between two codewords is the Hamming distance of those two codewords. For example, the Hamming distance between the codewords 1001 and 0101 is 2. The Hamming distance of two codewords can be calculated as the number of 1 bits in the bitwise exclusive-or of the two codewords: 1001 xor 0101 = 1100. • A code is the set of all codewords of a given length that are constructed by adding a specified number of check digits in a specified way to a specified number of data bits. The minimum Hamming distance of a code is the minimum of the Hamming distance between all possible pairs of codewords of that code. The following table indicates the Hamming distance between all pairs of a simple 4-bit binary code:
Error detection and Correction codes-Hamming Code • Because the minimum Hamming distance between any two codewords is 2, the Hamming distance of the code is 2.
Error detection with Hamming code • If a code has a minimum Hamming distance of 2, then at least two bits of any codeword would have to be transmitted in error or changed in memory in order to yield another codeword. If only one bit changed, the result would not be a codeword, so the single-bit error could be detected. Similarly, if a code has a minimum Hamming distance of 3, any fewer than 3 single-bit errors could be detected, since at least 3 bits must be flipped to change any codeword into another codeword of the same code. • To detect d single-bit errors, a code must have a minimum Hamming distance of at least d + 1.
Error Correction with Hamming Code • In order to correct transmission or storage errors, the data block that results from erroneous changes to a codeword must be "closer" (in Hamming distance) to a particular codeword of the code than to any other codeword. For example, given the 4-bit code above, the data block 0100 could have resulted from a single-bit error in any of the codewords 0000, 0101, 0110, or 1100. According to the Hamming distance metric, 0100 is "halfway" between any pair of these codewords, so we can't tell which codeword it was originally. (Of course, if multi-bit errors occurred, it could originally have been any codeword.) • If a data block is closer to one particular codeword than to any of the other codewords of a code, and if we assume that only the minimum possible number of bit errors occurred, then we can correct these errors by using the closest codeword in place of the erroneous data block. Thus, error correction is possible only if the number of bit errors is less than half the minimum Hamming distance of the code. • To correct d single-bit errors, a code must have a minimum Hamming distance of at least 2d + 1.
Error Correction with Hamming Code- example • Consider a code with only four valid codewords: • 0000000000, 0000011111, 1111100000, 1111111111. • This code has a distance 5 (=2d+1) which means that it can correct double (d=2) errors. • If the codeword 0000000111 arrives, the receiver knows that the original must have been 0000011111, If, however, a triple error changes 0000000000 into 0000000111, the error will not be corrected properly.
Go back N protocol • With this protocol, if an error occurs during frame transmission, all subsequent frames are discarded and no acknowledgement is sent for discarded frames. Eventually, the sender will time out and retransmit all unacknowledged frames in order starting with the damaged or lost one. This approach wastes a lot of bandwidth if the error rate is high.
Go back N protocol • 2. Damaged ACK • Station B receives frame i and sends ACK(i+1), which is lost in transit. Since ACK’s are cumulative (e.g., ACK 6 means that all frames through 5 are acknowledged), it may be that Station A will receive a subsequent ACK to a subsequent frame that will do the job of the lost ACK before the associated time expires. • If Station A’s timer expires, station A retransmits frame i and all subsequent frames. • 3. Damaged NAK If a NAK is lost, station A will eventually time out on the associated frame and retransmit that frame and all subsequent frames.
Selective repeat protocol • When it is used, a bad frame that is received is discarded but good frames received after it are buffered. When the sender times out, only the oldest unacknowledged frame is retransmitted, If that frame arrives correctly, the receiver can deliver it to the network layer in sequence all the frames it has buffered.
HDLC protocol (High Level Data-link Control Protocol) • If you have a T1 leased line to the Internet or a private network between locations, you use one of these three WAN Protocols: HDLC, PPP, or Frame-relay. • HDLC stands for High-Level Data Link Control protocol. Like the two other WAN protocols mentioned in this article, HDLC is a Layer 2 protocol. HDLC is a simple protocol used to connect point to point serial devices. For example, you have point to point leased line connecting two locations, in two different cities. HDLC would be the protocol with the least amount of configuration required to connect these two locations. HDLC would be running over the WAN, between the two locations. Each router would be de-encapsulating HDLC and dropping it off on the LAN.
HDLC protocol • HDLC performs error correction, just like Ethernet. Cisco’s version of HDLC is actually proprietary because they added a protocol type field. Thus, Cisco HDLC can only work with other Cisco devices.
Point to point protocol • Point-to-Point Protocol (PPP) is a data link layer protocol commonly used in establishing a direct connection between two network nodes. It can provide connection authentication, transmission encryption (using), and compression. • PPP is used over many types of physical networks including, phone line, cellular telephone, specialized radio links, and fiber optic links. PPP is also used over Internet access connections (now marketed as "broadband"). (ISPs) have used PPP for customer dial up access to the Internet, since IP packets cannot be transmitted over a modem line on their own, without some data link protocol.