Chapter 3 The Data Link Layer (60 % practical part)

98
Chapter 3 The Data Link Layer (60 % practical part)

Transcript of Chapter 3 The Data Link Layer (60 % practical part)

Page 1: Chapter 3 The Data Link Layer (60 % practical part)

Chapter 3The Data Link Layer

(60 % practical part)

Page 2: Chapter 3 The Data Link Layer (60 % practical part)

The Introduction

• The study of it deals with the algorithms for achieving reliable, efficient, communication between two adjacent machines

• The machines are physically connected by a communication channel that acts conceptually like a wire

Page 3: Chapter 3 The Data Link Layer (60 % practical part)

Data Link Layer Functions1. Provide a well defined service interface to

the network layer

2. Framing: Determine how the bits of the physical layer

are grouped into frames

3. Error Control: Dealing with transmission errors

4. Flow Control: Regulate the flow of frames so that slow

receivers are not swamped by fast senders

Page 4: Chapter 3 The Data Link Layer (60 % practical part)

Relationship between Packets and Frames

Relationship between packets and frames.

Page 5: Chapter 3 The Data Link Layer (60 % practical part)

Services Provided To NL

• Transferring data from the NL on the source to the NL on the destination

• On the source machine entity (process), in the NL, that hands some bits to DLL

• On the destination machine the data link layer hands it over to network layer

Page 6: Chapter 3 The Data Link Layer (60 % practical part)

Virtual and Actual Communication

The actual transmission follows thru physical layer but it can be neglected here

Page 7: Chapter 3 The Data Link Layer (60 % practical part)

Services Provided by DLL

1. Unacknowledged connectionless service

2. Acknowledged connectionless service

3. Acknowledged Connection-oriented service

Page 8: Chapter 3 The Data Link Layer (60 % practical part)

1… Unacknowledged CL Service• Least reliable but faster than all other

• The source machine sends independent frames to the destination machine without having the destination machine ack them

• No connection is established beforehand or released afterwards

• If a frame is lost due to noise burst in the channel, no attempt is made in the data link layer to recover the same

Page 9: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• This is very appropriate when the error rate is very low and recovery is left to higher layers

• It is also appropriate for real-time traffic where late data is worse then bad data

• Many LANs have unacknowledged connectionless service in their DLL

Page 10: Chapter 3 The Data Link Layer (60 % practical part)

2… Acknowledged CL Service

• Here each frame is individually acked

• If the ack frame is not arrived in some specific time interval, sender may resend

• Each frame sent over the connection is numbered

• This service is useful over unreliable medium such as wireless channel

Page 11: Chapter 3 The Data Link Layer (60 % practical part)

3… Connection Oriented Service

• It is the most sophisticated service provided by the data link layer

• With this service the sender and receiver establishes a connection before any data can be transmitted

• The choice of CO or CL service is to be determined by the reliability of media

Page 12: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• When C.O. services is used, three phases are involved in transfer

• In the first phase the connection is established by having both sides initialize variables and counters needed to keep track of which frames have been received

• In the second phase one or more frames are actually transmitted

Page 13: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• In the third and final phase, the connection is released, freeing up the buffers, variables and other resources used to maintain the connection.

• The communication between the network layer and the data link layer uses the standard OSI service primitives, request, indication, response and confirm.

Page 14: Chapter 3 The Data Link Layer (60 % practical part)

Placement of the DLL Protocol

Page 15: Chapter 3 The Data Link Layer (60 % practical part)

Framing

• The PL provides DLL continuous bit stream of raw data without any error checking

• DLL breaks raw stream of data into frames and compute the checksum for each frame

• When a frame arrives checksum is recomputed error report or ack be sent

Page 16: Chapter 3 The Data Link Layer (60 % practical part)

Ways of framing• To insert time gaps between frames

– As like spaces in words– it is possible these gaps might be squeezed out or

other gaps might be inserted during transmission.– So four other methods are used

1. Character count.

2. Flag bytes with byte stuffing.

3. Starting and ending flags, with bit stuffing.

4. Physical layer coding violations

Page 17: Chapter 3 The Data Link Layer (60 % practical part)

1… Character Count

• It uses a field in the header to specify the number of characters in the frame

• If count is garbled by the transmission, it can make the receiver go out of sync

Page 18: Chapter 3 The Data Link Layer (60 % practical part)

A Character Stream With and Without Errors

Page 19: Chapter 3 The Data Link Layer (60 % practical part)

2… Flag bytes with byte stuffing.• Here each frame starts and ends with flag

byte

• When binary or floating point data is being transmitted, flag byte may occur in data

• Sender's data link layer insert a special escape byte (ESC) just before each ''accidental'' flag byte in the data

• This is called byte stuffing or character stuff

Page 20: Chapter 3 The Data Link Layer (60 % practical part)
Page 21: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• It is closely tied to 8 bit characters in general and ASCII in particular

• Not all character code use 8 bit chars.– Ex: Unicode uses 16 bit chars.

• Embedding the character code having different length in the framing mechanism is not possible

• New technique for allowing arbitrary sized characters must be needed

Page 22: Chapter 3 The Data Link Layer (60 % practical part)

3… Starting and ending flags, with bit stuffing.

• It allows character codes with an arbitrary number of bits per character

• Each frame begins and ends with a special bit pattern, namely 01111110

• What will happen if data also contain 01111110 bit pattern– ???

Page 23: Chapter 3 The Data Link Layer (60 % practical part)

3… Starting and ending flags, with bit stuffing.

• It allows character codes with an arbitrary number of bits per character

• Each frame begins and ends with a special bit pattern, namely 01111110

• What will happen if data also contain 01111110 bit pattern– Whenever the sender’s data link layer

encounters five consecutive 1s it stuffs a 0

Page 24: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• This bit stuffing is analogous to character stuffing

• When the receiver sees five consecutive incoming 1 bits, followed by a 0 bit, it automatically destuffs the 0 bit

Page 25: Chapter 3 The Data Link Layer (60 % practical part)

Bit Stuffing Example

Page 26: Chapter 3 The Data Link Layer (60 % practical part)

4… Physical Layer Coding Violations

• It is applicable to NWs where the encoding on the physical medium contains some redundancy

• Some LAN encodes 1 bit data using 2 physical bits

• I.e. 1 and 0 are represented using HL and LH combination in Manchester encoding

• Here H and L can’t occur in data• So no need of stuffing if H or L is used as a flag

Page 27: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• Many data link protocols use combination of character count with other techniques

• It provides two ways to check for the length of frame and provides extra safety

Page 28: Chapter 3 The Data Link Layer (60 % practical part)

Error control

• To ensure reliable delivery is to provide the sender with feedback of other end

• Receiver sends back special control frames for +ve or –ve acks

• If a frame is lost, then receiver does not react and do not send any acks at all– Timers are introduced in the data link layer

to combat this problem

Page 29: Chapter 3 The Data Link Layer (60 % practical part)

Continue…

• When the sender transmits a frame, it generally also starts a timer

• If timer runs out, it warns the sender

• The destination may receive more then one copy of a single frame– A seq number is attached to solve the same

Page 30: Chapter 3 The Data Link Layer (60 % practical part)

Flow Control

• When sender sends data faster then receiver can accept them, flow control becomes imp

• The protocol contains well defined rules about when sender may send the next frame

• This rules generally prohibits the sender to send the frame until the receiver permits

Page 31: Chapter 3 The Data Link Layer (60 % practical part)

Two approaches are commonly used

• Feedback-based flow control– the receiver sends back information to the

sender giving it permission to send more data

• Rate-based flow control – the protocol has a built-in mechanism that

limits the rate at which senders may transmit data,

Page 32: Chapter 3 The Data Link Layer (60 % practical part)

Error Detection and Correction

• Transmission errors are fact of life so the only option available to us is to learn how to deal with them

• Transmission without error is not possible at all

Page 33: Chapter 3 The Data Link Layer (60 % practical part)

Error Types

• Singly Error– Just one bit interchanged

– Easy to catch and correct

• Burst Error– More than one bit interchanged

– Difficult to catch and correct

– If in 1000 bit long frame 35th no bit and 134th no bit has interchanged than it is the burst error of length 100.

Page 34: Chapter 3 The Data Link Layer (60 % practical part)

Strategies For Handling Errors1. Error Correcting Codes

include enough redundant information along with each block of data sent

So that the receiver can deduce what the transmitted data must have been.

Also known as forward error correction No need of retransmission

2. Error Detecting Codes include only enough redundancy to allow the

receiver to deduce that an error occurred Must be retransmitted

Page 35: Chapter 3 The Data Link Layer (60 % practical part)

Where to use What

• On channels that are highly reliable, such as fiber retransmission is better– Error detection should be used

• On channels such as wireless links that make many errors retransmission is costly– Error correction strategy should be used

Page 36: Chapter 3 The Data Link Layer (60 % practical part)

Error Correcting and Detecting

• Codeword– Data bits + Check bits– If Frame contains ‘m’ data bit and ‘r’ redundant

bits, – Length is m + r = n

Page 37: Chapter 3 The Data Link Layer (60 % practical part)

Error Correcting and Detecting

• Hamming distance – The number of bit positions in which two

codewords differ is the Hamming distance– Given any two code words, say 10001001 and

10110001 it is possible to determine how many bits differ, using EXOR

• Ans = ???

Page 38: Chapter 3 The Data Link Layer (60 % practical part)

Error Correcting and Detecting

• Hamming distance – The number of bit positions in which two

codewords differ is the Hamming distance– Given any two code words, say 10001001 and

10110001 it is possible to determine how many bits differ, using EXOR

• Ans = 3

Page 39: Chapter 3 The Data Link Layer (60 % practical part)

Hamming Distance of Whole code• For m bit frame 2m frames are possible

– So 2m legal codewords

• Because for n bit codewords – 2n codewords are possible

• In the list of all legal codewords two codewords having the minimum distance is hamming distance of whole code

Page 40: Chapter 3 The Data Link Layer (60 % practical part)

Significance of Hamming Distance

• Hamming distance (d) tells that one codeword need ‘d’ single bit errors to be converted to another codeword

• To detect d errors, you need a distance d + 1 code

• to correct d errors, you need a distance 2d + 1 code

Page 41: Chapter 3 The Data Link Layer (60 % practical part)

Error correcting code(Hamming code)

1. Count down the no of check bits satisfying formula (m+r+1)<=2r

2. Check bits = 1,2,4,8,16,32,64….

3. Data bits = 3,5,6,7,9,10,11,12,13,14,15….

4. 1 is responsible for the parity of 1,3,5,7…

5. 2 = 2,3,6,7,10,11,14,15…

6. 4 = 4,5,6,7,12,13,14,15…

7. 8 = 8,9,10,11,12,13,14,15….

Page 42: Chapter 3 The Data Link Layer (60 % practical part)

(Hamming code)

• Send the data• At the receiving side from the received

codeword calculate the parity of each check bit

• Add all the check bits which does not have right parity

• Answer is the bit where the error has occurred

Page 43: Chapter 3 The Data Link Layer (60 % practical part)

Example

• A byte of data: 10011010Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0Calculate the parity for each parity bit (a ? represents the bit position being set):

• Position 1 checks bits 1,3,5,7,9,11: ? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0

• Position 2 checks bits 2,3,6,7,10,11:0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0

Page 44: Chapter 3 The Data Link Layer (60 % practical part)

Example

• Position 4 checks bits 4,5,6,7,12:0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0

• Position 8 checks bits 8,9,10,11,12:0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0

• Code word: 011100101010.

Page 45: Chapter 3 The Data Link Layer (60 % practical part)

Example

• At the receiving side verify each check bit. Write down all the incorrect parity bits.

• suppose the codeword we received is 011100101011 instead of 011100101010.

• Parity bits 1,2 are correct

• Parity bits 4,8 are incorrect

• So at 4+8=12th bit error has occurred.

Page 46: Chapter 3 The Data Link Layer (60 % practical part)

Using Hamming Code for

Burst Errors

Page 47: Chapter 3 The Data Link Layer (60 % practical part)

Checking For Burst Errors

• k codewords are arranged as a matrix

• Instead of sending codeword send columns

• Receiver will reconstruct the matrix

• If burst error occurred of length k than at most one bit per codeword is incorrect and can be corrected

Page 48: Chapter 3 The Data Link Layer (60 % practical part)

Burst Error Correction using Hamming Code

Page 49: Chapter 3 The Data Link Layer (60 % practical part)

Error detecting codes

• To detect single bit error– Add parity bit to each bloke

• To detect burst error of length k– Divide the block in k words– Arrange k words in sequence to form matrix– Add parity bit for each column– Send the block Row-wise.

Page 50: Chapter 3 The Data Link Layer (60 % practical part)
Page 51: Chapter 3 The Data Link Layer (60 % practical part)

Polynomial Code or CRC Method(Second method to detect burst errors)

• Polynomial codes are based upon treating bit strings as representations of polynomials with coefficients of 0 and 1 only

• 110001 is x5 +x4 +x0

• In this method a generator polynomial is first agreed upon by receiver and the sender

• Both high and low order bits of the generator polynomial must be one

Page 52: Chapter 3 The Data Link Layer (60 % practical part)

The Standard Polynomials

• Certain polynomials have become international standards. The one used in IEEE 802 is

• a polynomial code with r check bits will detect all burst errors of length <= r.

Page 53: Chapter 3 The Data Link Layer (60 % practical part)

G(x) and Checksum• The frame must be bigger then the generator

polynomial G(x)• Append the frame by 0’s • No of 0’s = degree of generator polynomial

G(x)

• The frame is divided by G(x) • remainder is subtracted form frame yielding

T(x)• When the receiver gets the frame, it tries to

divide the frame by G(x)

Page 54: Chapter 3 The Data Link Layer (60 % practical part)

Is replaced by reminder

Page 55: Chapter 3 The Data Link Layer (60 % practical part)

CRC at Sender Side

Page 56: Chapter 3 The Data Link Layer (60 % practical part)

CRC at Receiver Side

Page 57: Chapter 3 The Data Link Layer (60 % practical part)

Protocols

• Unidirectional Protocols – An Unrestricted Simplex Protocol– A Simplex Stop-and-Wait Protocol – A Simplex Protocol for a Noisy Channel

• Bidirectional Protocols (sliding window)– A One-Bit Sliding Window Protocol – A Protocol Using Go Back N – A Protocol Using Selective Repeat

Page 58: Chapter 3 The Data Link Layer (60 % practical part)
Page 59: Chapter 3 The Data Link Layer (60 % practical part)
Page 60: Chapter 3 The Data Link Layer (60 % practical part)

Unidirectional Protocols • An Unrestricted Simplex Protocol

– No flow control– No error control

• A Simplex Stop-and-Wait Protocol – Flow control – No error control

• A Simplex Protocol for a Noisy Channel– Flow control– Error control

Page 61: Chapter 3 The Data Link Layer (60 % practical part)

1… An Unrestricted Simplex Protocol

• Data are transmitted in one direction only.

• Both the transmitting and receiving NLs are always ready

• the communication channel between the data link layers never damages or loses frames

• thoroughly unrealistic protocol

Page 62: Chapter 3 The Data Link Layer (60 % practical part)

Algorithm

Page 63: Chapter 3 The Data Link Layer (60 % practical part)

Sender Receiver

f2F3f4f1

f5

to_phisical_layer(&s)from_phisical_layer(&s)

No Flow Control

An Unrestricted Simplex Protocol

Page 64: Chapter 3 The Data Link Layer (60 % practical part)

2... A Simplex Stop-and-Wait Protocol

• Flow control– Receiver will send acknowledgement for each

received frame

• Error control– Not present

Page 65: Chapter 3 The Data Link Layer (60 % practical part)

Algorithm

Page 66: Chapter 3 The Data Link Layer (60 % practical part)

Sender Receiver

a0

f1a1

to_phisical_layer(&s)from_phisical_layer(&s)

With Flow Control

f0

f0

a0

A Simplex Stop-and-Wait Protocol

Time0

N

Page 67: Chapter 3 The Data Link Layer (60 % practical part)

3… A Simplex Protocol for a Noisy Channel

• Flow control– Acknowledgement from receiver

• Error control– Lost frames

• Timer timeout and retransmission

– Lost Acknowledgements• Same but problem of duplication

– Duplication• Sequence no added to each frame header

Page 68: Chapter 3 The Data Link Layer (60 % practical part)
Page 69: Chapter 3 The Data Link Layer (60 % practical part)
Page 70: Chapter 3 The Data Link Layer (60 % practical part)
Page 71: Chapter 3 The Data Link Layer (60 % practical part)

Sender Receiver

to_phisical_layer(&s)from_phisical_layer(&s)

With Flow Control + Error Control

A Simplex Protocol for a Noisy Channel

a0

f1a1f0

f0

a0

NormalTransmission

Time0

N

Page 72: Chapter 3 The Data Link Layer (60 % practical part)

Case 1:- Frame Lost

Sender Receiver

to_phisical_layer(&s)from_phisical_layer(&s)

a0

f1

a1

f0

f1

f1

Time0

N

Page 73: Chapter 3 The Data Link Layer (60 % practical part)

Case 1:- Ack Lost & Duplication

Sender Receiver

to_phisical_layer(&s)from_phisical_layer(&s)

a0

f1a1

f0

a1

f1

Time0

Na1

Page 74: Chapter 3 The Data Link Layer (60 % practical part)

Sliding Window Protocols(Bidirectional Transmission)

• It is for bi-directional transmission• Piggybacking

– Ack for received frame is sent in data frame to be sent.

– Frame = Data + Seq_no + Ack_no

Page 75: Chapter 3 The Data Link Layer (60 % practical part)

Window

• No of buffers to store sending or receiving frame

• Whenever frame is sent it is stored in sending window’s buffers

• Whenever frame received it is stored in receiving window’s buffers

Page 76: Chapter 3 The Data Link Layer (60 % practical part)

Window

• When expected ack comes from receiver, frame is discarded from sending window

• Whenever frame is passed to NL it is removed from receiving window

Page 77: Chapter 3 The Data Link Layer (60 % practical part)

a) initially b) after the first frame has been sent

c) after the first frame has been received

d) after the ack is received

A Sliding window of size 1 with three bit seq no.

Page 78: Chapter 3 The Data Link Layer (60 % practical part)

1… A One Bit Sliding Window Protocol

• Bidirectional transmission

• Only one frame can be sent

• Second can be sent only after the ack of first

• Window size = 1 buffer only– Because only 1 bit is allotted for seq no (0 to 1)

• Timer is started after transmission of each frame

Page 79: Chapter 3 The Data Link Layer (60 % practical part)

A B

0,0,b1

1,0,a21,1,b2

to_phisical_layer(&s)from_phisical_layer(&s)

0,1,a3

0,1,a1

0,0,b3

Time0

N

Page 80: Chapter 3 The Data Link Layer (60 % practical part)

A One Bit Sliding Window Protocol

Page 81: Chapter 3 The Data Link Layer (60 % practical part)
Page 82: Chapter 3 The Data Link Layer (60 % practical part)

Comparison

Page 83: Chapter 3 The Data Link Layer (60 % practical part)

Moving to more sophisticated protocols

• Time between frame sent & ack received is considerable in real situations

• Pipelining:-– If sender can send frame before getting

acknowledgement channel utilization increases

• To do this sender will need buffers to store the sent frames

Page 84: Chapter 3 The Data Link Layer (60 % practical part)

Effect of

Error

Page 85: Chapter 3 The Data Link Layer (60 % practical part)

Sliding Window Diagram

Page 86: Chapter 3 The Data Link Layer (60 % practical part)

Go Back N

Page 87: Chapter 3 The Data Link Layer (60 % practical part)
Page 88: Chapter 3 The Data Link Layer (60 % practical part)
Page 89: Chapter 3 The Data Link Layer (60 % practical part)
Page 90: Chapter 3 The Data Link Layer (60 % practical part)
Page 91: Chapter 3 The Data Link Layer (60 % practical part)
Page 92: Chapter 3 The Data Link Layer (60 % practical part)

A Protocol Using Selective Repeat

• Receiver is also provided by receiving window

• So if expected frame doesn’t come receiver can receive frame out of order instead of discarding it.

Page 93: Chapter 3 The Data Link Layer (60 % practical part)

Algorithm

Page 94: Chapter 3 The Data Link Layer (60 % practical part)
Page 95: Chapter 3 The Data Link Layer (60 % practical part)
Page 96: Chapter 3 The Data Link Layer (60 % practical part)
Page 97: Chapter 3 The Data Link Layer (60 % practical part)
Page 98: Chapter 3 The Data Link Layer (60 % practical part)

Window Management

a) Initial Situation with WS 7 b) After 7 frames sent but not acked c ) Initial situation with a window size of four d) After four frames sent and received but not acked