37
Prepared By: Kind Kishor Tribhuvan University

Unit 4 data link layer

  • Upload
    mekind

  • View
    114

  • Download
    3

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Unit 4 data link layer

Prepared By: Kind Kishor

Tribhuvan University

Page 2: Unit 4 data link layer

Topics to be Included

1. Services provided to Network layer.

2. Framing.

3. Error detection methods: Parity, Checksum, CRC.

4. Data link protocols:

a. A simplex stop and wait protocol.

b. Sliding window protocols.

c. Go back and ARQ.

d. Selective repeat.

Page 3: Unit 4 data link layer

Data Link Layer:

Devices:- Switch, Bridge.

Services:- Framing, Flow control, Error control.

Functions of Data Link Layer:� Providing a well-defined service interface to the

network layer.

�Dealing with transmission error.

�Regulating the flow of data so that slow receivers are

not swamped by fast senders.

Page 4: Unit 4 data link layer

Services Provided to Network Layer

�The principle service is transferring data from the network layer

on the source machine to the network layer on the destination

machine.

(a) Virtual communication.(b) Actual communication.

Page 5: Unit 4 data link layer

Data Link Layer

Logical Link Control (LLC)

Layer

Media Access Control (MAC)

Layer

(The LLC is responsible for

flow control, error correction)

(The MAC layer is responsible for

providing a method for station to

gain access to medium)

Page 6: Unit 4 data link layer

Framing(1)� Framing is the process of breaking the bit stream up into

discrete frames.

� DDL prepares a frame for transport across the local media by

encapsulating it with a header and trailer.

� The data link layer frame includes:

�Data: The packet from the network layer.�Data: The packet from the network layer.

�Header: contains control information (addressing) and located at

the beginning of frame.

�Trailer: Contains control information added to the end of the

frame.

Page 7: Unit 4 data link layer

Framing(2)

Fixed-size Framing:

ӿ In fixed size framing, there is no need for defining the boundaries

of the frames.

ӿ The size of frame itself can be used as a delimiter.

Variable-size Framing:

ӿ In variable-size framing, we need a way to define the end of the

frame and the beginning of the frame.

ӿ There are two approaches used for this purpose:

a) A character-oriented approach.

b) A bit-oriented approach.

Page 8: Unit 4 data link layer

A character-oriented approach

Here, data are 8-bit characters from a coding system such

as ASCII.

The header and trailer are also multiples of 8-bits.

To separate one frame from next, an 8-bit flag is added at To separate one frame from next, an 8-bit flag is added at

the end and beginning of the frame.

The flag, is composed of protocol-dependent special

characters, which signals the start and end of a frame.

A byte-stuffing strategy is used in character-oriented

framing.

Page 9: Unit 4 data link layer

Byte-Stuffing(Character-Stuffing)(1)

In this method, Frame starts & end with a special character that

mark the beginning & end of frame.

Each character begins with the ASCII character sequence DLE STX

(data link escape start of text ) and end with ASCII character

sequence DLE ETX (data link escape end of text).

DLE ASTX B DC ETXDLE

Start Of Frame Data End Of Frame

A B DC Data From Network Layer

Starting & Ending Characters Added By Link Layer

Page 10: Unit 4 data link layer

Byte-Stuffing(Character-Stuffing)(2)

DLE ASTX B DC ETXDLE

A B DCDLE

DLE DLE

data on Sender

side

DLE ASTX B DC ETXDLE

Start Of Frame Data End Of Frame

DLE DLE

A B DCDLEdata on

Reciever side

Page 11: Unit 4 data link layer

A bit-oriented approach

In this method, each frame begins & ends with a special bit pattern 01111110 called flags.

There for each frame starts with 01111110 & also ends with 01111110.

The main problem arises in this method when the flag The main problem arises in this method when the flag byte 01111110 appear as data.

This problem is handled by technique called bit stuffing that is similar to character stuffing.

Page 12: Unit 4 data link layer

Bit-Stuffing

01 10 0 10 1 11 1 01 1001111110 01111110Stuffing

Performed

By Data

Link layer

01 10 0 10 11 1 01 11Data from network layer

Starting flag Bit

Ending Flag BITShifted Bit

Link layer

01 10 0 10 1 11 1 01 1 Data received by

Network layer On

receiver side After

Performing De-stuffing

By data link Layer

Page 13: Unit 4 data link layer

Flow Control● One of the most important functions of data link layer.

● A technique for assuring that a transmitting station does not overwhelm a receiving station with data.

● A set of procedures that tells the sender how much data it can transmit before it must wait for an acknowledgement from the receiver.

●● Receiver has a limited speed at which it can process incoming data and a limited amount of memory in which to store incoming data.

● Receiver must inform the sender before the limits are reached and request that the transmitter to send fewer frames or stop temporarily.

● Since the rate of processing is often slower than the rate of transmission, receiver has a block of memory (buffer) for storing incoming data until they are processed.

Page 14: Unit 4 data link layer

Stop and Wait Flow Control

� Source transmits frame and waits for ACK before sending

next frame.

� Destination receives frame and indicates its willingness to

accept another frame by sending back an acknowledgement accept another frame by sending back an acknowledgement

with the frame just received.

� Destination can stop flow by not sending ACK.

� It works well for a few large frames.

� It is inadequate for multiple frames for a single message

because only one frame at a time can be in transit.

Page 15: Unit 4 data link layer

Sliding-window Flow Control(1)

� Allow multiple frames to be in transit at a time.

� Receiver has allocates buffer space for n frames.

� Transmitter can sent up to n frames without ACK.

� Frames are numbered by assigning each frame a k-bit sequence

number and the range of sequence no is (0…….2^k-1).number and the range of sequence no is (0…….2^k-1).

� ACK includes number of next frame expected.

� This ACK announces that receiver is prepared to receive next n

frame.

� The sequence numbers lists can be thought of as window of

frames.

Page 16: Unit 4 data link layer

Sliding-window Flow Control(2)

Page 17: Unit 4 data link layer

How flow control is achieved?

●Receiver can control the size of the sending window.●Receiver can control the size of the sending window.

●By limiting the size of the sending window data flow

from sender to receiver can be limited.

Page 18: Unit 4 data link layer

Error ControlӿWhen data is transmitted over a channel, there is always a chance

that some of bits will be changed(corrupted) due to noise, signal

distortion, or attenuation.

ӿMechanisms to detect or correct errors that occur in the transmission

of frames.

ӿThere is possibility of two types of errors:ӿThere is possibility of two types of errors:

o Lost frame

o Damaged frame

ӿIt allows the receiver to inform the sender if a frame is lost or

damaged during transmission and coordinates the retransmission of

those frames by the sender.

ӿError control includes both error detection and error correction.

Page 19: Unit 4 data link layer

Error Detection

�It allows a receiver to check whether received

data has been corrupted during the

transmission or not.transmission or not.

�There three ways to detect errors:•Parity check

•CRC

•Checksum

Page 20: Unit 4 data link layer

Parity CheckSingle bit added to the end of the data.

Value of parity bit is such that data and parity have even

(even parity) or odd (odd parity) number of ones.

Typically, even parity is used for synchronous transmission

and odd parity is used for asynchronous transmission.

Even number of bit errors goes undetected.Even number of bit errors goes undetected.

It is example of even parity because

there are even number of 1s.

Page 21: Unit 4 data link layer

Cyclic Redundancy Check(CRC)

Consider the d-bit piece of data, D, that the sending node wants to send.

The sender and receiver must first agree on r+1 bit pattern, called generator,

which we will denote as G.

G must have the first and last bit equal to 1.

For D, the sender choose r additional bits, R, and append them to D.

The resulting d+r bit pattern is exactly divisible by G using modulo 2

arithmetic.arithmetic.

The receiver checks the error by dividing received d+r by G.

• If the remainder is non-zero, there is an error has occurred.

• Otherwise the data is correctly received.

Page 22: Unit 4 data link layer

Modulo 2 Arithmetic

Polynomial arithmetic is done modulo 2 using the rules of

algebraic field theory.

Both addition and subtraction are identical to exclusive OR.

For example:

10011011 11110000

+11001010 -10100110

-------------- -------------

01010001 01010110

Page 23: Unit 4 data link layer

Calculation of the

polynomial code

checksum.

Here generator

polynomial is

x^4+x+1.

Page 24: Unit 4 data link layer

Internet ChecksumThe Internet has been using a 16-bit checksum.

Sender Site:

The message is divided into 16-bit words.

The value of checksum is set to be 0.

All words including the checksum are added using 1’s complement addition.

The sum is complement and becomes the checksum.

The checksum is sent with the data.

Receiver Site:

The message, including checksum, is divided into 16-bit words.

All words are added using 1’s complement addition.

The sum is complemented and becomes the new checksum.

If the value of checksum is zero;

The message is accepted.

Otherwise, it is rejected.

Page 25: Unit 4 data link layer

Error Correction

ӿIt allows a receiver to reconstruct the original

information when it has been corrupted during

transmission.

ӿWe can control the found errors in two ways:ӿWe can control the found errors in two ways:

� Forward Error Correction(FEC):- FEC is accomplished by

adding redundancy to the transmitted information using a

predetermined algorithm.

�Automatic Repeat Request(ARQ):- In ARQ, the receiver

detects transmission errors in a message and automatically

requests a retransmission from the transmitter. When the

transmitter receives the ARQ, it retransmits the message.

Page 26: Unit 4 data link layer

Hamming Distance

The number of bit positions in which two codewords differ is

called the Hamming distance between these two codewords.

The Hamming distance between two words( of same size) is the

number of differences between the corresponding bits.

It can easily be found if we apply the XOR operation on the two

words and count the numbers of 1’s in the result.words and count the numbers of 1’s in the result.

It is value greater than 0(zero).

10001001

10110001

00111000Here Hamming distance = 3

Page 27: Unit 4 data link layer

Stop and Wait Protocol(1)

�Based on the stop-and-wait flow

control technique.

�The source station transmits a single

frame and then must wait for

ACK(acknowledgement).

�The frames and ACK are numbered

0 & 1.0 & 1.

� If frame 0 is received, ACK1 is sent,

and if frame 1 is received, ACK0 is

sent.

� If no ACK received then the same

frame is sent again.

�The receiver sends only positive ACK

for frame received safe and sound.

Page 28: Unit 4 data link layer

Stop and Wait Protocol(2)

Piggybacking:�It is a method to combine a

data frame with an

acknowledgement.

�It is used when both station A �It is used when both station A

and B have data to send.

�Here both station A and B send

data frame which also includes

an ACK.

�It can save bandwidth of

channel because the data

frame and ACK frame can be

combined into just one frame.

Page 29: Unit 4 data link layer

Sliding Window Protocols

�The basic idea of sliding window protocol is that

both sender and receiver keep a ``window'' of

acknowledgment.

�The sender keeps the value of expected �The sender keeps the value of expected

acknowledgment; while the receiver keeps the

value of expected receiving frame.

�When sender receives an acknowledgment from the

receiver, it advances the window.

�When receiver receives the expected frame, then it

advances the window.

Page 30: Unit 4 data link layer

One-bit sliding window

One bit sliding window protocol is also called

Stop-And-Wait protocol.

In this protocol, the sender sends out one In this protocol, the sender sends out one

frame, waits for acknowledgment before

sending next frame, thus the name Stop-And-

Wait.

Page 31: Unit 4 data link layer

Go-Back-N ARQ(1)Based on sliding-window flow control.

Transmitter may send a series of frames sequentially.

If no error, receiver sends ACK(RR= receive ready), as usual, with next frame expected.

Use window to control number of Use window to control number of outstanding frames.

If error, receiver sends a negative ACK(REJ= reject) for that frame.

Receiver will discard that frame and all future frames until the frame in error received correctly.

Transmitter, when it receives REJ, must go back and retransmit that frame and all subsequent frames.

Page 32: Unit 4 data link layer

Go-Back-N ARQ(2)

Damaged frame:Receiver detects error in frame i.

Receiver sends rejection-i.

Transmitter gets rejection-i.

Transmitter retransmits frame i and all subsequent.Transmitter retransmits frame i and all subsequent.

Lost frame(1):Frame i lost.

Transmitter sends i+1.

Receiver gets frame i+1 out of sequence.

Receiver send reject i.

Transmitter retransmits frame i and all subsequent frames.

Page 33: Unit 4 data link layer

Go-Back-N ARQ(3)

Lost frame(2):

Frame i lost and no additional frame sent.

Receiver gets nothing and returns neither acknowledgement nor rejection.acknowledgement nor rejection.

Transmitter times out and sends acknowledgement frame with P bit set to 1(this is actually a command for ACK request).

Receiver interprets this as command which it acknowledges with the number of the next frame it expects (frame i ).

Transmitter then retransmits frame i.

Page 34: Unit 4 data link layer

Go-Back-N ARQ(4)Damaged acknowledgement(RR):

�Receiver gets frame i and send acknowledgement (i+1)

which is lost.

�Acknowledgements are cumulative, so next

acknowledgement (i+n) may arrive before transmitter times

out on frame i.out on frame i.

� If transmitter times out, it sends acknowledgement with P bit

set as before.

�This can be repeated a number of times before a reset

procedure is initiated

Damaged rejection(REJ):�As for lost frame.

Page 35: Unit 4 data link layer

Selective Reject ARQ●Also called selective retransmission.

●Only rejected(negative ACK, or time-out) frames are retransmitted.

●Minimizes amount of retransmission.

●Subsequent frames are accepted by the receiver and buffered.

●Receiver must maintain large enough ●Receiver must maintain large enough buffer to save received frames until the frame in error is retransmitted.

●Receiver must contain logic for reinserting that frame is the proper sequence.

●More complex logic in transmitter because it is much less used than go-back-n ARQ.

Page 36: Unit 4 data link layer
Page 37: Unit 4 data link layer