Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof....

71
Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. [email protected] http://www.cpe.ku.ac.th/~cpj Computer Engineering Department Kasetsart University, Bangkok, Thailand Adapted from lecture slides by Behrouz A. Forouzan © The McGraw-Hill Companies, Inc. All rights reserved

Transcript of Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof....

Page 1: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

Data Link Layer:Data Link Control

01204325: Data Communication and Computer Networks

Asst. Prof. Chaiporn Jaikaeo, [email protected]

http://www.cpe.ku.ac.th/~cpjComputer Engineering Department

Kasetsart University, Bangkok, ThailandAdapted from lecture slides by Behrouz A. Forouzan© The McGraw-Hill Companies, Inc. All rights reserved

Page 2: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

2

Outline Framing

Byte vs. bit oriented protocols Data Link Control

Flow control Error control

Protocols

Page 3: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

3

Framing Process of wrapping data with certain info

before sending out

A frame typically consists of Flag: indication for start and end of a frame Header: source/destination addresses, as well

as other control information Data from the upper layer Trailer: error detection/correction code

Page 4: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

4

Byte vs. Bit Oriented Framing in byte-oriented protocols

Framing in bit-oriented protocols

Page 5: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

5

Byte Stuffing Process of adding extra byte whenever

there is an escape or a flag character in the data

Page 6: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

6

Bit Stuffing Process of adding extra bit to ensure

flag sequence does not appear in the data

01111110

Page 7: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

7

Flow Control and Error Control Flow control

A set of procedures that tells the sender how much data can be sent before waiting for acknowledgment

Error control Includes both error detection and

correction Allows receiver to inform sender of lost

or duplicate frames Mostly based on Automatic Repeat

Request (ARQ)

Page 8: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

8

Data Link Protocols

Page 9: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

9

Protocols for Noiseless Channel Assuming channel is error free

Not realistic… No need for error control

Page 10: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

10

"Simplest" Mechanism Assuming

Noiseless channel Unlimited buffer and speed for the receiver

Page 11: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

11

"Simplest" : Pseudo Code Sender

Receiver

Page 12: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

12

"Simplest": Flow Diagram

Page 13: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

13

Stop-and-Wait Mechanism Still noiseless channel Receiver has limited buffer

Requires flow control Sender sends one frame at a time

and wait for an acknowledgment

Page 14: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

14

Stop-and-Wait: Overview

Page 15: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

15

Stop-and-Wait: Pseudo Code Sender side

Page 16: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

16

Stop-and-Wait: Pseudo Code Receiver side

Page 17: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

17

Stop-and-Wait: Flow Diagram

Page 18: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

18

Noisy Channel Realistic

Error can and will happen Require error control

Mechanisms: Stop-and-Wait ARQ Go-Back-N ARQ Selective Repeat ARQ

Page 19: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

19

Stop-and-Wait ARQ Sender keeps a copy of sent frame

until successful delivery is ensured Receiver responds with an ack when

it successfully receives a frame Both data and ack frames must be

numbered When sender does not receive an ack

within certain time, it assumes frame is lost, then retransmits the same frame.

Page 20: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

20

Stop-and-Wait ARQ

Page 21: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

21

Flow Diagram: Normal Operation

Time

Sender Receiver

Time

Frame 0

ACK 1

Frame 1

ACK 0

S = 0

S = 1

R = 0

R = 1

R = 0

Deliver

Deliver

Page 22: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

22

Thinking Corner Why data frames need to be

numbered?

Page 23: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

23

Flow Diagram: Lost Frame

Time

Sender Receiver

Time

Frame 0

ACK 1

Frame 1

ACK 0

S = 0 R = 0

R = 1

R = 0

S = 1

Timeout

Frame 1

Deliver

Deliver

Page 24: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

24

Flow Diagram: Lost ACK

Time

Sender Receiver

Time

Frame 0

ACK 1

Frame 1

ACK 0

S = 0 R = 0

R = 1

R = 0

Frame 1S = 1

Timeout

ACK 0

S = 1

S = 0

R = 0Frame 0

expected; discard

Deliver

Deliver

Page 25: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

25

Thinking Corner Why ACK frames need to be

numbered?

Page 26: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

26

Flow Diagram: Delayed ACK

Sender Receiver

Frame 0

ACK 1

ACK 0

S = 0 R = 0

R = 1

R = 0

Frame 0Timeout

S = 1

S = 0

R = 1

Frame 0 expected;

discard

Deliver

ACK 1Frame 1

Timeout Frame 1

Deliver

Page 27: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

27

Bidirectional Transmission Data are transferred both ways ACK are "piggybacked" with data

frames

Page 28: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

28

Example Assuming a communication system where:

Stop-and-Wait ARQ is used Bandwidth of the link is 1 Mbps Propagation delay is 10 ms One-way data flow

Questions What should be an appropriate time-out value? What is the bandwidth-roundtrip-delay

product? If the system data frames are 1000 bits in

length, what is the utilization percentage of the link?

Page 29: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

29

Improving Link Utilization Previous example demonstrates

major disadvantage of Stop-and-Wait ARQ

Prefer to send more frames before waiting for ACK

Example: Recalculate the link utilization if we

allow up to 15 frames to be sent before waiting for an ACK

Page 30: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

30

Go-Back-N ARQ Allows multiple frames to be sent

before waiting for ACK These frames must be numbered

differently Frame numbers are called Sequence

numbers Frames must be received in the

correct order If a frame is lost, the lost frame and

all of the following frames must be retransmitted

Page 31: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

31

Sequence Numbers Frame header contains m bits for

sequence number That allows up to 2m different frame

numbers How big should m be?

Page 32: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

32

Sending Window Sending more than one frame at once

requires sender to buffer multiple frames Known as "sending window" Any of these frames in the window can be lost

Page 33: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

33

"Sliding" Window Once the first frames in the window is

ACKed ACKed frames are removed from the buffer More frames are transmitted Result: The window slides to the right

Page 34: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

34

Receiving Window Receiver expects one frame at a time

Page 35: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

35

Send vs. Receive Windows

Page 36: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

36

Go-Back-N: Window Sizes For m-bit sequence numbers Send window size: at most 2m-1

Up to 2m-1 frames can be sent without ACK

Receive window size: 1 Frames must be received in order

Page 37: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

37

Go-Back-N: Normal Operation

Page 38: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

38

Go-Back-N: Lost Frame

ACKs are cumulative

Page 39: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

39

Lost ACK: Window Size < 2m

Page 40: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

40

Thinking Corner What is a problem if send window is

greater than 2m-1?

Page 41: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

41

Lost ACK: Window Size = 2m

Page 42: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

42

Thinking Corner Stop-and-Wait is a special case of Go-

Back-N. What is the send window size in Stop-

and-Wait?

Page 43: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

43

Selective Repeat ARQ Go-Back-N always discards out-of-

order frames Losing one frame may result in

retransmission of multiple frames Very inefficient in noisy link

Selective Repeat ARQ allows frames to be received out of order Therefore, receive window > 1

Page 44: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

44

Send and Receive Windows Sender and receiver share window

space equally For m-bit sequence numbers

Send window: up to 2m-1

Receive window: up to 2m-1

Page 45: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

45

Send Window

Page 46: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

46

Receive Window

Page 47: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

47

Negative ACK Used by receiver to indicate missing frame

Page 48: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

48

Selective Repeat: Window Size

Page 49: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

Data Link Control Protocols: HDLC and PPP

Page 50: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

50

HDLC High-level Data Link Control Bit-oriented protocol Support both

Point-to-point links Multipoint links

Page 51: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

51

Normal Response Mode "NRM" mode Used in both point-to-point and multi-point

link

Page 52: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

52

Asynchronous Balance Mode "ABM" Supports only point-to-point links Each station is both primary and

secondary

Page 53: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

53

HDLC Frames Information frame (I-frame)

Supervisory frame (S-frame)

Unnumbered frame (U-frame)

Frame Check Sequence (error detection code)

Page 54: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

54

Control Field Format

N(S) – Frame sequence number N(R) – Ack sequence number P/F

Poll (primary secondary) Final (secondary primary)

Page 55: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

55

U-Frame Codes

Page 56: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

56

Connection and Disconnection

Page 57: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

57

Data Transfer: No Error

Page 58: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

58

Data Transfer: With Error

Page 59: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

59

PPP Point-to-Point Protocol Byte-oriented protocol Most common protocol for point-to-

point access Dial-up access ADSL GPRS/EDGE/3G

Page 60: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

60

PPP Frame Format

Escape byte: 01111101 Control field uses HDLC's U-frame

format No flow or error control

Page 61: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

61

PPP Transition States

Page 62: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

62

Multiplexing in PPP

Page 63: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

63

PPP Stack Link Control Protocol (LCP) Authentication Protocol (AP) Network Control Protocol (NCP)

Page 64: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

64

LCP: Link Control Protocol Responsible for establishing,

maintaining, configuring, and terminating links

Page 65: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

65

PPP Authentication Two protocols are supported:

Password Authentication Protocol (PAP) Challenge Handshake Authentication

Protocol (CHAP)

Page 66: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

66

PAP

Page 67: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

67

CHAP

Page 68: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

68

NCP: Network Control Protocol A set of control protocols to allow data

from the network layer to be encapsulated into a PPP frame

One common protocol: IPCP(Internetwork Protocol Control Protocol) Allow negotiation at the network layer

Page 69: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

69

Data Encapsulation

Page 70: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

70

Example: PPP Session

Page 71: Data Link Layer: Data Link Control 01204325: Data Communication and Computer Networks Asst. Prof. Chaiporn Jaikaeo, Ph.D. chaiporn.j@ku.ac.th cpj.

71

Example: PPP Session (cont'd)