Rizwan Rehman Centre for Computer Studies Dibrugarh University

56
Rizwan Rehman Centre for Computer Studies Dibrugarh University The Data Link Layer

description

Rizwan Rehman Centre for Computer Studies Dibrugarh University. The Data Link Layer. Physical Layer. Source node. Destination node. Application. Application. Presentation. Presentation. Session. Session. Intermediate node. transport. transport. Packets. Network. Network. Network. - PowerPoint PPT Presentation

Transcript of Rizwan Rehman Centre for Computer Studies Dibrugarh University

Page 1: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Rizwan RehmanCentre for Computer StudiesDibrugarh University

The Data Link Layer

Page 2: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Physical Layer

Application

Presentation

Session

transport

Network

Data link

Physical

Application

Presentation

Session

transport

Network

Data link

Physical

Network

Data link

Physical

Source node Destination node

Intermediate node

Signals

Packets

Bits

Frames

Page 3: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Data Link Layer Design Issues• Services Provided to the Network Layer• Framing• Error Control• Flow Control

Page 4: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Data Link Layer Issues• Functions of the Data Link Layer

– Provide service interface to the network layer– Dealing with transmission errors– Regulating data flow: Slow receivers not swamped

by fast senders

• To accomplish these goals, the data link layer encapsulates the packets into frames.

Page 5: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Data Link Layera) Provides for reliable transfer of information across physical link

b) Includes:– transmission of blocks of data (“frames”)– synchronization– error control– flow control

Page 6: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Functions of the Data Link Layer

Relationship between packets and frames.

Page 7: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Services Provided to Network Layer

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

Page 8: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Services to the Network Layer

• Three possible services offered by the data link layer:– Unacknowledged connectionless service:

appropriate for channel with low error rate, real-time traffic, LAN

– Acknowledged connectionless service: useful over unreliable channel such as wireless systems

– Acknowledged connection-oriented service: used in routing

Page 9: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Services Provided to Network Layer

Placement of the data link protocol.

Page 10: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Data Link Layer Functionsa) Frame Synchronization - Create abstraction of “frame-

at-a-time” channel for higher layer (start & end of each frame must be recognizable)

b) Addressing - Needed when many nodes share transmission link

c) Flow Control - Control rate of transmission to prevent overflow of receiver's buffers

d) Error Control - Correct transmission errors (by retransmission) or by error correction schemes

e) Sequence Control - Receiver must be able to distinguish control information from data

f) Link Management - Initiation, maintenance, & termination of connections

Page 11: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Framing• To detect or correct errors in the raw bit stream

from the physical layer, the data link layer breaks the bit stream up into discrete frames and computes the checksum for each frame.

• Four methods can be used to mark the start and end of each frame:– Character count– Flag bytes with byte stuffing– Starting and ending flags, with bit stuffing– Physical layer coding violations

Page 12: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Framing

A character stream. (a) Without errors. (b) With one error

• Disadvantage: The count may be garbled. Rarely used.

Page 13: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Framing• Flag bytes with byte/character stuffing

– Each frame start and end with special bytes – flag byte– If the flag byte occurs in the frame, stuff an extra escape byte

(ESC).– Used in PPP (Point to Point Protocol)

• Starting and ending flags, with bit stuffing– Each frame begins and ends with a special bit pattern

01111110 whenever the sender sees 5 consecutive 1s, it stuffs a 0.

• Physical layer coding violations– Only applicable to networks in which the encoding on the

physical medium contains some redundancy. – For example, a 1 bit is a high-low pair and a 0 bit is a low-

high pair. High-high and low-low are used for delimiter.

Page 14: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Framing

(a) A frame delimited by flag bytes.(b) Four examples of byte sequences before and after stuffing.

Page 15: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Framing

Bit stuffing

(a) The original data.

(b) The data as they appear on the line.

(c) The data as they are stored in receiver’s memory after destuffing.

Page 16: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error and Flow Control• Error Control

– Detect and/or correct errors– Ensure that all frame are eventually delivered in

order use acknowledgement, timer, and sequence number

• Flow Control– Slow down the sender when the data is coming too

fast for the receiver– Two approaches:

• Feedback-based flow control – the receiver sends back permission to the sender.

• Rate-based flow control – built-in mechanism that limits senders’ rate. Rarely used in the data link layer.

Page 17: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Detection and Correction

• Error-correcting codes/forward error correction – include enough redundant information to enable the

receiver to deduce the correct transmitted data.– Used in unreliable channel such as wireless links

• Error-detecting codes – include only enough redundancy to allow the

receiver to request a retransmission.– Used in reliable channel such as fiber

Page 18: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Correction Codes

• N-bit codeword = m-bit data + r-bit check• The number of bit positions in which two codewords

differ is called the Hamming distance.• Example: Hamming distance is 3.

10001001

xor 10110001

00111000 3 bit difference• If two codewords are a Hamming distance d apart, it

will require d single-bit errors to convert one into the other.

Page 19: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Correction Codes• To detect d errors, we need a distance d+1 code

(because there is no way to convert a valid codeword into another valid codeword with d changes. The detail needs mathematical analysis).

• Example: A simple error - detection code: (check bit) a parity bit is chosen so that the number of 1 bits in the

codeword is even or odd. 000(0) - check bit 001 1 010 1

That is Hamming distance of parity bit code is 2 = d + 1 can detect d = 1 error

Page 20: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Correction Codes

• To correct d errors, we need a distance 2d+1 code. (because d changes is not enough to recover the original valid codeword but only to convert to other valid codeword The detail needs mathematical analysis).

• Examples: Consider a code with four valid codewords:0000000000, 0000011111, 1111100000, 1111111111

Hamming distance is 5. It can correct double errors.

If 0000000111 is received, the receiver knows the original

is 00000011111. But if a triple errors change 0000000000

to 0000000111, the error will not be corrected properly.

Page 21: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Correction Codes

• Correct round off to the nearest codeword.

m data bits 2m legal messages = codewords• Examples: Consider a code with four valid codewords:

000000, 000111, 111000, 111111 differ by 3

011000, 101000, 110000, 111001, 111010, and 111100 are six invalid code words a distance 1 from 111000.

each valid codeword has n invalid codewords within hamming distance 1. To correct these n invalid codewords with 1 bit error, n + 1 bit patterns are required.

Page 22: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error Correction Codes

• Since there are a total of 2n bit patterns (n + 1) x 2m ≤ 2n

(m + r + 1) x 2m ≤ 2m+r

m + r + 1 ≤ 2r

• Given m, this puts a lower limit on the number of check bits needed to correct 1 error.

m = 7 7 + r + 1 ≤ 2r

8 ≤ 2r - r r = 4

Page 23: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Hamming Codes• Bits are numbered from the left . Checkbits are bits

numbered powers of 2. {1,2,4,8,...}. Each checkbit forces the parity of some collection of bits, including itself, to be even or odd.

• To see which check bits the data in position k contributes to, write k as a sum of powers of 2.

Data bits 3 5 6 7 9 10 11

Check bits 1 + 2 1 + 4 2 + 4 1 + 2 + 4 1 + 8 2 + 8 1 + 2 + 8

Check bits

1 2 4 8

Data bits 3 + 5 + 7 + 9 + 11 3 + 6 + 7 + 10 + 11 5 + 6 + 7 9 + 10 + 11

Page 24: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Constructing Hamming Codes

• Consider an ASCII code H (1001000). Use even parity:

H 1001000 _ _ 1 _ 001 _ 000

Bit Calculation Result

1 (1 + 0 + 1 + 0 + 0) mod 2 = 0 0

2 (1 + 0 + 1 + 0 + 0) mod 2 = 0 0

4 (0 + 0 + 1) mod 2 = 1 1

8 (0 + 0 + 0 mod 2 = 0 0

The codeword is 00110010000.

Page 25: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Hamming Codes• When a codeword arrives, counter = 0.

If a checkbit k does not have the correct parity, it adds k to the counter.

• Supposed there is only one bit error.

If counter = 0 no error

If counter = 11 bit 11 in error.

ASCII codeword

H 1001000 0 0 1 1 001 0 000

G 1100001 1 0 1 1 100 1 001

If G is received as (0) 0 1 1 100 1 001, 1st bit is incorrect.

If G is received as (1)(0){0} 1 100 1 001

1st and 2nd has errors. 3rd bit is incorrect.

Page 26: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error-Correcting Codes

Use of a Hamming code to correct burst errors.

Page 27: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Cyclic Redundancy Check• A major goal in designing error detection algorithms is

to maximize the probability of detecting errors using only a small number of redundant bits.

• In general, correcting is more expensive than detecting and re-transmitting.

• Add k bits of redundant data to an n-bit message– want to use k << n to detect errors– e.g., k = 32 and n = 12,000 (1500 bytes)

• Represent n-bit message as n-1 degree polynomial– e.g., MSG=10011010 as M(x) = x7 + x4 + x3 + x1

• Let k be the degree of some divisor polynomial– e.g., G(x) = x3 + x2 + 1

Page 28: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Cyclic Redundancy Check

• CRC is a polynomial code. Frame 110001 represents x5 + x4 + x0

Polynomial arithmetic is performed modulo 2.

10011011 11001010 01010001 EX-OR result.

• Sender & receiver agree upon a 'generator polynomial' G(x).

Page 29: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Cyclic Redundancy Check

• Algorithm for computing the checksum1. shift left r bits (append r zero bits to low order end

of the frame), i.e., M(x)xr

2. divide the bit string corresponding to G(x) into (xr)M(x).

3. subtract (or add) remainder of M(x)xr / G(x) from M(x)xr using XOR, call the result T(x). Transmit T(x).

Page 30: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Cyclic Redundancy Check

• Suppose that a transmission error E(x) has occured and T(x)+E(x) arrives instead of T(x). Received polynomial T(x) + E(x) = (T(x)+E(x))/G(x) = T(x)/G(x) + E(x)/G(x) = E(x)/G(x)– E(x) = 0 implies no errors

• Divide (T(x) + E(x)) by G(x); remainder zero if:– E(x) was zero (no error), or– E(x) is exactly divisible by C(x)

Page 31: Rizwan Rehman Centre for Computer Studies Dibrugarh University

CRC Examplea) M(x)=10011010

b) C(x)=1101

c) k=3

d) P(x) = 10011010 101

11111001 ----------- 1101 /10011010000 <- Message 1101 ----- 1001 1101 ----- 1000 1101 ----- 1011 1101 ---- 1100 1101 ----- 1000 1101 ---- 101 <- Remainder

Page 32: Rizwan Rehman Centre for Computer Studies Dibrugarh University

CRC Examplea) M(x)=1101011011

b) C(x)=10011

c) k=4

d) P(x) = 1101011011 1110

1100001010 -------------- 10011 /11010110110000 10011 ----- 10011 10011 ----- 10110 10011 ----- 10100 10011 ----- 1110

Page 33: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Error-Detecting Codes

Calculation of the polynomial code checksum.

Page 34: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Elementary Data Link Protocols

• An Unrestricted Simplex Protocol– connectionless– the sender continues sending frames with no

acknowledge– the receiver has an infinite buffer.

• A Simplex Stop-and-Wait Protocol– assume error free channel.– the sender sends frames only after getting an

acknowledge– the receiver has finite buffer.

Page 35: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Elementary Data Link Protocols

• A Simplex Protocol for a Noisy Channel connectionless– Positive Acknowledge and Retransmission (PAR)– if frames may be lost or acknowledged, then a time-

out is required.– time-out must be long enough to account for the

max. possible delay – need time-outs and sequence #'s.

• Since only adjacent frames may conflict, we can use 2 sequence #'s 0 & 1. sequence # only requires 1 bit.

Page 36: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Sliding Window Protocols

• In stop-and-wait protocols, latency at the sender is high

channel utilization (efficiency) is low.• Piggybacking is a technique of attaching a

acknowledgement to a data frame.• In window-based Protocols, the sender's (receiver's)

window is the range of sequence numbers which the sender (receiver) is allowed to send (receive) before blocking.

• Pipelining means to increase the sender’s window size and transmit more than one frame before waiting for an acknowledge.

Page 37: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Sliding Window Protocols

• Sliding Window Protocols– A One-Bit Sliding Window Protocol– A Protocol Using Go Back N– A Protocol Using Selective Repeat

• Two approaches to deal with errors in pipelining:1. Go Back N – Recovery by timeout-receiver discards all

subsequent frames and sends no acknowledge.

2. Selective repeat – Special frame - receiver acknowledges with a special frame to start retransmit from missed frame.

Page 38: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Sliding Window Protocols

A sliding window of size 1, with a 3-bit sequence number.

(a) Initially.

(b) After the first frame has been sent.

(c) After the first frame has been received.

(d) After the first acknowledgement has been received.

Page 39: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A One-Bit Sliding Window Protocol

Two scenarios for protocol 4. (a) Normal case. (b) Abnormal case. The notation is (seq, ack, packet number). An asterisk indicates where a network layer accepts a packet.

Page 40: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A Protocol Using Go Back N

• Receiver will only accept the next frame in the sequence.

• Advantage: simple. • Disadvantage: Waste bandwidth if high error

rate exists.

Page 41: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A Protocol Using Go Back N

Pipelining and error recovery. Effect on an error when

(a) Receiver’s window size is 1.

(b) Receiver’s window size is large.

Page 42: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A Sliding Window Protocol Using Selective Repeat

• Receiver accepts any frame in its window, but only acknowledges the last frame in the successful sequence. The receiver can notify the sender to transmit a missing frame using the same two approaches:1. timeout

2. receiving a special frame from receiver.

• Advantage: don't waste bandwidth• Disadvantage: Receiver must buffer frames, thus

imposing a higher memory requirement on the receiver.

Page 43: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A Sliding Window Protocol Using Selective Repeat

(a) Initial situation with a window size seven.

(b) After seven frames sent and received, but not acknowledged.

(c) Initial situation with a window size of four.

(d) After four frames sent and received, but not acknowledged.

Page 44: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Protocol Verification

• Much research has been done by trying to find formal, mathematical techniques for specifying and verifying protocols.

• Finite State Machined Models• Petri Net Models

Page 45: Rizwan Rehman Centre for Computer Studies Dibrugarh University

The Data Link Layer in the Internet• Point-to-point communication:

– Router-router leased line connection– Dial-up host-router connection

• PPP provides three features:1. A framing method to delineate the frame and

handle error detection2. LCP (Link Control Protocol) for brining lines up,

testing them, negotiating options, and brining down them down.

3. A way to negotiate network-layer options or have a different NCP (Network Control Protocol).

Page 46: Rizwan Rehman Centre for Computer Studies Dibrugarh University

The Data Link Layer in the Internet

A home personal computer acting as an internet host.

Page 47: Rizwan Rehman Centre for Computer Studies Dibrugarh University

PPP – Point to Point Protocol

• The PPP full frame format for unnumbered mode operation.– Flag byte: 01111110– Address: 11111111 indicates all stations to accept the frame– Control: default value, 00000011 for an unnumbered frame

(unreliable transmission)– Protocol: indicate what kind of packet is in the payload– Payload: data (default length: 1500 bytes)– checksum

Page 48: Rizwan Rehman Centre for Computer Studies Dibrugarh University

PPP Protocol• PPP is a multi-protocol framing mechanism

suitable for use over modems, HDLC bit-serial lines, SONET, and other physical layers.

• PPP supports error detection, option negotiation, header compression, and reliable transmission.

• LCP is used to negotiate data link protocol options.

Page 49: Rizwan Rehman Centre for Computer Studies Dibrugarh University

PPP – Point to Point Protocol

A simplified phase diagram for bring a line up and down.

Page 50: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Sliding Window Protocols

a) For full duplex two transmission lines are required

b) One to send data and the other to receive data and/or ACKs

c) Sending ACKs in a packet of its own is waste of resources

d) May use piggybacking

e) The acknowledgement is attached to an outgoing data frame(ack field in the frame header)

f) Data link layer must wait until it has some thing to send before it can ack.

g) This may cause time out and the frame may be re-sent.

Page 51: Rizwan Rehman Centre for Computer Studies Dibrugarh University

a) The essence of sliding window protocols is that at any instant of time, the sender maintains a set of sequence numbers corresponding to frames it is permitted to send. These frames are said to fall within the sending window. Similarly, the receiver also maintains a receiving window corresponding to the set of frames it is permitted to accept. It is NOT necessary for the sender and receiver to have same number limits.

b) Sequence numbers of frames sent but not acknowledged are kept in the senders window.

c) The receivers window corresponds to the frames it may accept.

Page 52: Rizwan Rehman Centre for Computer Studies Dibrugarh University

One bit sliding window protocola) uses stop and wait scheme, since the sender transmits a frame and

waits for its acknowledgement before sending the next one.

b) The acknowledgement field of the frame contains the number of the last frame received without error. If this number agrees with the sequence number of the frame the sender is trying to send, the sender knows that it is done and can proceed with the next frame.

Page 53: Rizwan Rehman Centre for Computer Studies Dibrugarh University

A protocol using Go-Back-N

a) Takes into account of round trip transmission time.

b) Enough frames should be send to stuff the band with to avoid channel idling

c) Consider a 50-kbps satellite channel with 500 m-sec round-trip propagation delay

– Let us send 1000 bit frames– At t=0 starts sending the first frame, at t=20 msec the frames has been send– Receiver fully receives only at t=270msc, and ack will be received at t=520

msec.– Sender would be blocked 96% of time- only 4% of available band width was

used.

Page 54: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Go-Back-N continued.a) Instead of sending 4 frames, the sender should have sent 26 frames.

This will take t=520 msec.

b) at t=520 the acknowledgement for the first frame will be received. The senders maximum window size is 26.

c) This technique is called pipelining.

d) If a frame in the middle of a stream gets damaged, what should the receiver do? Should all frames starting at that point be re-sent?

e) Go-Back-N simply discards all frames including the damaged one, not sending acks. The time out at the sender will resend all subsequent frames.

f) Can waste a lot of bandwidth in an unreliable channel.

Page 55: Rizwan Rehman Centre for Computer Studies Dibrugarh University

Selective Repeat

a) Receiver stores all good frames after the damaged frame.

b) Notifies the sender of the bad frame, and sender re-sends that one.

c) This technique requires the data link layer to have large amount of memory for the cache.

Page 56: Rizwan Rehman Centre for Computer Studies Dibrugarh University

THANK YOU