data link layer - computer science | academics | wpi ·  · 2006-11-10data link layer • provides...

35
Data Link Layer Data Link Layer Networks: Data Link Layer Networks: Data Link Layer 1 1

Upload: ngomien

Post on 20-May-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Data Link LayerData Link Layer

Networks: Data Link LayerNetworks: Data Link Layer 11

Data Link LayerData Link Layer

• Provides a well-defined service interface to the network layer.

• Determines how the bits of the physical layer are grouped into frames (framing).

• Deals with transmission errors (CRC and ARQ).• Regulates the flow of frames.• Performs general link layer management.

Networks: Data Link LayerNetworks: Data Link Layer 22

Packets

Networks: Data Link LayerNetworks: Data Link Layer 33

3 2 11 22

1

3 2 11 22

1

21

Medium

1

2

Physical layer entity

Data link layer entity3 Network layer entity

PhysicalLayer

Data linkLayer

PhysicalLayer

Data linkLayer

Packets

(a)

A BFrames

(b)

A B

Copyright ©2000 The McGraw Hill Companies Figure 5.2Leon-Garcia & Widjaja: Communication Networks

End to End

1 2 3 4 5

Data Data Data

ACK/NAK

Data

Networks: Data Link LayerNetworks: Data Link Layer 44

1 2 3 4 5Data Data Data

Hop by Hop

Data

ACK/NAK

ACK/NAK

ACK/NAK

ACK/NAK

Leon-Garcia & Widjaja: Communication NetworksFigure 5.7 Copyright ©2000 The McGraw Hill Companies

Tanenbaum’sTanenbaum’s Data Link Layer Data Link Layer TreatmentTreatment

• Concerned with communication between two adjacent nodes in the subnet (node to node).

• Assumptions:– The bits are delivered in the order sent.– Rigid interface between the HOST and the node

the communications policy and the Host protocol (with OS effects) can evolve separately.

– He uses a simplified model.

Networks: Data Link LayerNetworks: Data Link Layer 55

HostA

HostB

Layer 4

Node2

Node1

Layer 4

Layer 2

frame

Networks: Data Link LayerNetworks: Data Link Layer 66

Data Link Layer ModelAssume the sending Host has infinite supply of messages.A node constructs a frame from a single packet message.The CRC is automatically appended in the hardware.The protocols are developed in increasing complexity to helpstudents understand the data link layer issues.

Basic Elements of ARQ

Packetsequence

Error-free packet

sequence

Informationframes

Control frames

Transmitter Receiver

CRC

Informationpacket

Header

Station A Station B

Information Frame

Control frame

CRC Header

Networks: Data Link LayerNetworks: Data Link Layer 77

Copyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.8

Tanenbaum’sTanenbaum’s Protocol DefinitionsProtocol Definitions

Continued

Networks: Data Link LayerNetworks: Data Link Layer 88

Figure 3-9. Some definitions needed in the protocols to follow. These are located in the file protocol.h.

Protocol Protocol DefinitionsDefinitions(continued)(continued)

Networks: Data Link LayerNetworks: Data Link Layer 99

Figure 3-9. Some definitions needed in the protocols to follow. These are located in the file protocol.h.

packet

ack seq kindinfo

buffernetwork layer

data link layer

frame

physical layer

Networks: Data Link LayerNetworks: Data Link Layer 1010

Figure 3Figure 3--1010

Unrestricted Unrestricted Simplex Simplex Protocol

Networks: Data Link LayerNetworks: Data Link Layer 1111

Protocol

Networks: Data Link LayerNetworks: Data Link Layer 1212

Figure 3Figure 3--1111

Simplex Simplex StopStop--andand--Wait Wait ProtocolProtocol

Ambiguities with Stop-and-Wait[unnumbered frames]

(a) Frame 1 lost

A

B

frame 0

frame1

ACK

frame1

ACK

timeTime-out

frame2

(b) ACK lost

A

B

frame 0

frame1

ACK

frame1

ACK

timeTime-out

frame2

ACK

Networks: Data Link LayerNetworks: Data Link Layer 1313

In parts (a) and (b) transmitting station A acts the same way, but part (b) receiving station B accepts frame 1 twice.

Figure 5.9Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

State Machine for Stop-and-Wait

SlastRnext

0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

Timer

Transmitter Receiver

(0,0) (0,1)

(1,0) (1,1)

Global State:(Slast, Rnext)

Error-free frame 0arrives at receiver

ACK forframe 0arrives attransmitter

ACK forframe 1arrives attransmitter Error-free frame 1

arrives at receiver

Station A Station BRnext

Slast

Networks: Data Link LayerNetworks: Data Link Layer 1414

Copyright ©2000 The McGraw Hill Companies Figure 5.11Leon-Garcia & Widjaja: Communication Networks

Networks: Data Link LayerNetworks: Data Link Layer 1515

#define MAX_SEQ 1typedef enum {frame_arrival, cksum_err, timeout} event_type;include “protocol.h”

void sender_par (void){seq_nr next_frame_to_send;frame s;packet buffer;event_type event;next_frame_to_send = 0;from_network_layer (&buffer);while (true){ s.info = buffer;

s.seq = next_frame_to_send;to_physical_layer (&s);start_timer (s.seq);wait_for_event(&event);if (event == frame_arrival) {

from_network_layer (&buffer);inc (next_frame_to_send);

}}}

Protocol 3Protocol 3(PAR) Positive ACK(PAR) Positive ACKwith Retransmissionwith Retransmission

[Old [Old TanenbaumTanenbaum Version]Version]

void receiver_par (void){

seq_nr next_frame_to_send;frame r, s;

event_type event;frame_expected = 0;while (true){ wait_for_event (&event);

if (event == frame_arrival) { from_physical_layer (&r);

if (r.seq == frame_expected) {to_network_layer(&r.info);inc (frame_expected);

}to_physical_layer (&s); /* Note – no sequence number on ACK */

}}}

Protocol 3(PAR) Positive ACKwith Retransmission

[Old Tanenbaum Version]

Networks: Data Link LayerNetworks: Data Link Layer 1616

PAR [OLD] problemAmbiguities when ACKs are not numbered

Networks: Data Link LayerNetworks: Data Link Layer 1717

frame 0 frame

0ACKframe

1ACK

timetime-out

frame2

A

BTransmitting station A misinterprets duplicate ACKs

Figure 5.10Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

PARPAR

Simplex Simplex Protocol Protocol

for a for a Noisy Noisy

ChannelChannel

Networks: Data Link LayerNetworks: Data Link Layer 1818

Figure 3-12.A Positive Acknowledgement with Retransmission protocol.

CodeCode addedadded

Continued

A Simplex Protocol for a Noisy ChannelA Simplex Protocol for a Noisy Channel

CodeCode addedadded

Figure 3-12.A positive acknowledgement with retransmission protocol.

Networks: Data Link LayerNetworks: Data Link Layer 1919

Sliding Window ProtocolsSliding Window Protocols[[TanenbaumTanenbaum]]

• Must be able to transmit data in both directions.• Choices for utilization of the reverse channel:

– mix DATA frames with ACK frames.–– PiggybackPiggyback the ACKthe ACK

• Receiver waits for DATA traffic in the opposite direction.• Use the ACK field in the frame header to send sequence

number of frame being ACKed.

– better use of the channel capacity.

Networks: Data Link LayerNetworks: Data Link Layer 2020

Sliding Window ProtocolsSliding Window Protocols

• ACKs introduce a new issue – how long does receiver wait before sending ONLY an ACK frame.

Now we need an ACKTimer !!The sender timeout period needs to be set longer.

• The protocol must deal with the premature timeout problem and be “robust” under pathological conditions.

Networks: Data Link LayerNetworks: Data Link Layer 2121

Sliding Window ProtocolsSliding Window ProtocolsEach outbound frame must contain a sequence number. With n

bits for the sequence number field, maxseq = 2n - 1 and the numbers range from 0 to maxseq.

Sliding window :: the sender has a window of frames and maintains a list of consecutive sequence numbers for frames that it is permitted to send without waiting for ACKs.

The receiver has a window of frames that has space for frames whose sequence numbers are in the range of frame sequence numbers it is permitted to accept.

Note – sending and receiving windows do NOT have to be the same size.

The windows can be fixed size or dynamically growing and shrinking.

Networks: Data Link LayerNetworks: Data Link Layer 2222

Sliding Window ProtocolsSliding Window ProtocolsThe Host is oblivious to sliding windows and the

message order at the transport layer is maintained.sender’s window :: holds frames sent but not yet

ACKed.– new packets from the Host cause the upper

edge inside the sender’s window to be incremented.

– acknowledged frames from the receiver cause the lower edge inside the sender’s window to be incremented.

Networks: Data Link LayerNetworks: Data Link Layer 2323

Sliding Window ProtocolsSliding Window Protocols• All frames in the sender’s window must be

saved for possible retransmission and we need one timer per frame in the window.

• If the maximum sender window size is B, the sender needs at least B buffers.

• If the sender’s window gets full (i.e., it reaches the maximum window size, the protocol must shut off the Host (the network layer) until buffers become available.

Networks: Data Link LayerNetworks: Data Link Layer 2424

Sliding Window ProtocolsSliding Window Protocolsreceiver’s window

– Frames received with sequence numbers outside the receiver’s window are not accepted.

– The receiver’s window size is normally static.The set of acceptable sequence numbers is rotated as “acceptable” frames arrive.

If a receiver’s window size = 1 , then the protocol only accepts frames in order.

This scheme is referred to as Go Back N. Networks: Data Link LayerNetworks: Data Link Layer 2525

Sliding Window ProtocolsSliding Window ProtocolsSelective Repeat :: receiver’s window

size > 1.• The receiver stores all correct frames

within the acceptable window range.• Either the sender times out and resends

the missing frame, or• Selective repeat receiver sends a NACK

frame back the sender.

Networks: Data Link LayerNetworks: Data Link Layer 2626

Networks: Data Link LayerNetworks: Data Link Layer 2727

1. The ACK sequence number indicates the last frame successfully received.

- OR -2. ACK sequence number indicates the next

frame the receiver expects to receive.Both of these can be strictly individual ACKs

or represent cumulative ACKs.Cumulative ACKs is the most common

technique.

Choices in ACK MechanismsChoices in ACK Mechanisms

Networks: Data Link LayerNetworks: Data Link Layer 2828

OneOne--BitBitSlidingSlidingWindowWindowProtocolProtocol

Go Back N

Networks: Data Link LayerNetworks: Data Link Layer 2929

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr6

fr3

ACK1 error

Out-of-sequence frames

Go-Back-4: 4 frames are outstanding; so go back 4

fr5

fr6

fr4

fr7

fr8

fr9

ACK2

ACK3

ACK4

ACK5

ACK6

ACK7

ACK8

ACK9

Figure 5.13Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

ACKing next frame expected

Networks: Data Link LayerNetworks: Data Link Layer 3030

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr1

fr2

ACK1

error

Out-of-sequenceframes

Go-Back-7:

fr4

fr5

fr3

fr6

fr7

fr0

NAK1

ACK3

ACK4

ACK5

ACK6

ACK7

ACK2

Transmitter goes back to frame 1

Figure 5.17

Go Back Nwith NAK error recovery

Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Networks: Data Link LayerNetworks: Data Link Layer 3131

Networks: Data Link LayerNetworks: Data Link Layer 3232

Selective Repeatwith NAK error recovery

Networks: Data Link LayerNetworks: Data Link Layer 3333

A

B

fr0

timefr1

fr2

fr3

fr4

fr5

fr6

fr2

ACK1 error

fr8

fr9

fr7

fr10

fr11

fr12

ACK2

NAK2

ACK7

ACK8

ACK9

ACK10

ACK11

ACK12

ACK2

ACK2

ACK2

Figure 5.21Leon-Garcia & Widjaja: Communication NetworksCopyright ©2000 The McGraw Hill Companies

Networks: Data Link LayerNetworks: Data Link Layer 3434

Networks: Data Link LayerNetworks: Data Link Layer 3535