Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT-II The Data Link Layer.

Similar presentations


Presentation on theme: "UNIT-II The Data Link Layer."— Presentation transcript:

1 UNIT-II The Data Link Layer

2 The Data Link Layer Data-Link Layer has responsibility of transferring frames from one node to adjacent node over a link The data link layer takes the packets it gets from the network layer and encapsulates them into frames for transmission . Each frame contains frame header ,a payload field for holding the packet ,and a frame trailer 5/21/2019 Sam_CN_UNIT-II

3 3.1 Data Link Layer design issues
Services Provided to the Network Layer Framing Error Control Flow Control 5/21/2019 Sam_CN_UNIT-II

4 3.1 Data Link Layer Design Issues Functions of Data Link Layer
Providing a well-defined service interface to the network layer Determining how the bits of the physical layer are grouped into frames Dealing with transmission errors Regulating the flow of frames so that slow receivers are not swamped by fast senders 5/21/2019 Sam_CN_UNIT-II

5 3.1 Data Link Layer Design Issues
Relationship between packets and frames 5/21/2019 Sam_CN_UNIT-II

6 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Model used 5/21/2019 Sam_CN_UNIT-II

7 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Three reasonable possibilities for data link services: 1. Unacknowledged connectionless service 2. Acknowledged connectionless service 3. Acknowledged connection-oriented service 5/21/2019 Sam_CN_UNIT-II

8 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Unacknowledged connectionless service 1. The source sends independent frames to the destination without the destination acknowledging them. 2. No connection is established beforehand or released afterward 3. If a frame is lost due to noise on the line, no attempt is made to recover it in the data link layer 4. Appropriate when the error rate is very low 5. Appropriate for real-time traffic, such as speech, in which late data are worse than bad data 6. Most LANs use unacknowledged connectionless service 5/21/2019 Sam_CN_UNIT-II

9 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Acknowledged connectionless service Each frame sent is individually acknowledged. In this way, the sender knows whether or not a frame has arrived safely. If it has not arrived within a specified time interval, it can be sent again It is perhaps worth emphasizing that providing acknowledgements in the data link layer is just an optimization, never a requirement. The transport layer can always send a message and wait for it to be acknowledged 5/21/2019 Sam_CN_UNIT-II

10 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Acknowledged connectionless service The trouble with this strategy is that if the average message is broken up into, say, 10 frames, and 20 percent of all frames are lost, it may take a very long time for the message to get through. If individual frames are acknowledged and retransmitted, entire messages get through much faster On reliable channels, such as fiber, the overhead of a heavyweight data link protocol may be unnecessary, but on wireless channels it is well worth the cost due to their inherent unreliability 5/21/2019 Sam_CN_UNIT-II

11 3.1 Data Link Layer Design Issues
3.1.1 Services Provided to the Network layer Acknowledged connection-oriented service 1. The source and the destination establish a connection before and data are transferred 2. Each frame sent over the connection is numbered 3. The data link layer guarantees that each frame sent is indeed received 4. Furthermore, it guarantees that each frame is received exactly once and that all frames are received in the right order 5. Connection-oriented service provides the network layer with the equivalent of a reliable bit stream 5/21/2019 Sam_CN_UNIT-II

12 3.1 Data Link Layer Design Issues
3.1.2 Framing The data link uses the services provided by the physical layer. The physical layer will not be perfect. It is up to the data link layer to detect, and if necessary, correct errors The usual approach is for the data link layer to break the bit stream up into discrete frames and compute the checksum for each frame. When a frame arrives at the destination, the checksum is recomputed. If the newly computed checksum is different from the one contained in the frame, the data link layer knows that an error has occurred and takes steps to deal with it 5/21/2019 Sam_CN_UNIT-II

13 3.1 Data Link Layer Design Issues
3.1.2 Framing: The usual approach is for the data link layer to break the bit stream up into discrete frames and compute the checksum for each frame Breaking the bit stream up into frames is more difficult than it at first appears, One way to achieve this framing is to insert time gaps between frames, much like the spaces between words in ordinary text Four framing methods are used : 1. Character count 2. Starting and ending characters, with character stuffing 3. Starting and ending flags, with bit stuffing 4. Physical layer coding violations 5/21/2019 Sam_CN_UNIT-II

14 3.1 Data Link Layer Design Issues
3.1.2 Framing: Character count Without error Without error Without error With one error With one error 5/21/2019 Sam_CN_UNIT-II

15 3.1 Data Link Layer Design Issues
3.1.2 Framing: Character count The first framing method uses a field in the header to specify the number of characters in the frame When the data link layer in the destination sees the character count ,it knows how many characters follow and hence where the end of the frame is Even if the checksum is incorrect so the destination knows that the frame is bad, it still has no way of telling where the next frame starts The trouble with this algorithm is that the count can be garbled by a transmission error 5/21/2019 Sam_CN_UNIT-II

16 3.1 Data Link Layer Design Issues
3.1.2 Framing: Starting and ending characters, with Character stuffing a) A frame delimited by flag bytes b) Four examples of byte sequences before and after byte stuffing 5/21/2019 Sam_CN_UNIT-II

17 3.1 Data Link Layer Design Issues
3.1.2 Framing: Starting and ending characters, with Character stuffing Most protocols used the same byte ,called flag byte, as both the starting and ending delimiter as FLAG. Two consecutive flag bytes indicate the end of one frame and start of the next one A major disadvantage of using this framing method is that it is closely tied to 8-bit characters in general and the ASCII character code in particular We need a technique to allow arbitrary sized characters 5/21/2019 Sam_CN_UNIT-II

18 3.1 Data Link Layer Design Issues
3.1.2 Framing: Starting and ending flags, with Bit Stuffing This new technique allows data frames to contain an arbitrary number of bits and allow character codes with an arbitrary number of bits per character Each frame begins and ends with a special bit pattern, called a flag byte. whenever the senders data link layer encounters five consecutive ones in the data , it automatically stuffs a 0 bit into the outgoing bit stream. whenever the receiver sees five consecutive incoming 1 bits, followed by a 0 bit ,it automatically destuffs (i.e deletes) the 0 bit. 5/21/2019 Sam_CN_UNIT-II

19 3.1 Data Link Layer Design Issues
3.1.2 Framing: Starting and ending flags, with Bit Stuffing Flags ( ) at the beginning and end Bit-oriented framing with bit stuffing 5/21/2019 Sam_CN_UNIT-II

20 3.1 Data Link Layer Design Issues
3.1.2 Framing: Physical layer coding violations This method of framing is only applicable to networks in which the encoding on the physical medium contains some redundancy For example, some LANs encode 1 bit of data by using 2 physical bits. Normally, a 1 bit is a high-low pair and a 0 bit is a low-high pair. The combinations high-high and low-low are not used for data and they can be used as frame boundaries 5/21/2019 Sam_CN_UNIT-II

21 3.1 Data Link Layer Design Issues
3.1.3 Error Control The usual way to ensure reliable delivery is to provide the sender with some feedback about what is happening at the other end of the line Data Frame Sender Receiver Acknowledgement (ACK) Or negative Acknowledgement (NAK) 5/21/2019 Sam_CN_UNIT-II

22 3.1 Data Link Layer Design Issues
3.1.3 Error Control An additional complication comes from the possibility that hardware troubles may cause a frame to vanish completely. In this case, the receiver will not react at all This possibility is dealt with by introducing timers into the data link layer When a sender transmits a frame, it generally also starts a timer The timer is set to expire after an interval long enough for the frame to reach the destination, be processed there ,and have the acknowledgement to propagate back to the sender 5/21/2019 Sam_CN_UNIT-II

23 3.1 Data Link Layer Design Issues
3.1.3 Error Control However, when frames may be transmitted multiple times there is a danger that the receiver will accept the same frame two or more times, and pass it to the network layer more than once To prevent this from happening, it is generally necessary to assign sequence numbers to outgoing frames, so that the receiver can distinguish retransmissions from originals 5/21/2019 Sam_CN_UNIT-II

24 3.1 Data Link Layer Design Issues
3.1.4 Flow Control When the sender is running on a fast (or lightly loaded) computer and the receiver is running on a slow (or heavily loaded machine) and what to do with a sender that systematically wants to transmit frames faster than the receiver can accept them? Even if the transmission is error free ,at a certain point the receiver will simply be unable to handle the frames as they arrive and will start to loose someone To prevent this situation, Feedback- based flow control mechanism is used 5/21/2019 Sam_CN_UNIT-II

25 3.1 Data Link Layer Design Issues
3.1.4 Flow Control Feedback- based flow control ,the receiver sends back information to the sender giving it permission to send more data Various flow control schemes are known, but most of them use the same basic principle. The protocol contains well-defined rules about when a sender may transmit the next frame These rules often prohibit frames from being sent until the receiver has granted permission, either implicitly or explicitly 5/21/2019 Sam_CN_UNIT-II

26 3.2 Error Detection and Correction
In some cases it is sufficient to detect an error and in some, it requires the errors to be corrected also For e.g. On a reliable medium : Error Detection is sufficient where the error rate is low and asking for retransmission after Error Detection would work efficiently In contrast, on an unreliable medium : Retransmission after Error Detection may result in another error and still another and so on. Hence Error Correction is desirable 5/21/2019 Sam_CN_UNIT-II

27 3.2.1 Error Correcting codes
A frame consists of m data (i.e., message ) bits and r redundant, or check bits Let the total length be n (i.e., n=m+r). an n-bit unit containing data and check bits is often referred to as an n-bit codeword Given any two code words ,say, and ,it is possible to define how many bits differ .In this case 3 bits differ. To determine how many bits differ ,just EXCLUSIVE OR the two code words ,and count the number of 1 bits in the result. The number of bit positions in which two code words differ is called the Hamming distance Its significance is that if two code words are a hamming distance d apart, it will require d single-bit errors to convert one into another 5/21/2019 Sam_CN_UNIT-II

28 3.2.1 Error Correcting codes
To detect d errors, you need a distance d+1 code To correct d errors, you need a distance 2d+1 code Consider a code with only 4 valid codewords: , , , This code has a distance of 5, which means that it can detect double errors 5/21/2019 Sam_CN_UNIT-II

29 3.2.1 Error Correcting codes
A simple example an error-detecting code, consider a code in which a single parity bit is appended to the data The parity bit is chosen so that the number of 1 bits in the codeword is even (or odd) For example, when is sent in even parity by adding a bit at the end ,it becomes ,where as becomes with even parity A code word with a single parity bit has a distance 2,since any single bit error produces a codeword with the wrong parity 5/21/2019 Sam_CN_UNIT-II

30 3.2.2 Error-detecting Codes: CRC (Cyclic Redundancy Code)
When the polynomial code method is employed ,the sender and receiver must agree upon a generator polynomial G(x) . In advance both higher and lower order bits of generator must be 1. To compute the check sum 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 check summed frame is divisible by G(x). When the receiver gets the check summed frame, it tries dividing it by G(x). If there is a remainder ,there has been a transmission error 5/21/2019 Sam_CN_UNIT-II

31 3.2.2 CRC : Algorithm for computing checksum
1. 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) 2. Divide the bit string corresponding to G(x) in to the bit string corresponding to XrM(x) using modulo 2 division 3. subtract the remainder (which is always r or fewer bits ) from the bit string correspond to XrM(x) using modulo 2 subtraction. The result is the check summed frame to be transmitted .call its polynomial T(x) 5/21/2019 Sam_CN_UNIT-II

32 Calculation of the polynomial code checksum
Frame: Generator : 1011 5/21/2019 Sam_CN_UNIT-II

33 Division in the CRC decoder for two cases
5/21/2019 Sam_CN_UNIT-II

34 5/21/2019 Sam_CN_UNIT-II


Download ppt "UNIT-II The Data Link Layer."

Similar presentations


Ads by Google