<<

DataData LinkLink LayerLayer

Networks: Layer 1 DataData LinkLink LayerLayer

• Provides a well-defined service interface to the . • Determines how the bits of the are grouped into frames (framing). • Deals with transmission errors (CRC and ARQ). • Regulates the flow of frames. • Performs general management.

Networks: 2 Packets Packets

(a) Data link Data link Layer Layer A Physical Frames Physical B Layer Layer

(b) 1 1 2 2 1 2 3 2 1 1 2 3 2 1 Medium 2 A B 1

1 Physical layer entity 3 Network layer entity 2 Data link layer entity

Copyright ©2000 The McGraw Hill Companies Figure 5.2 Leon-Garcia & Widjaja: Communication Networks Networks: Data Link Layer 3 End to End

ACK/NAK

1 2 3 4 5

Data Data Data Data

Hop by Hop

Data Data Data Data 1 2 3 4 5 ACK/ ACK/ ACK/ ACK/ NAK NAK NAK NAK

Figure 5.7 Leon-Garcia & Widjaja: Communication Networks Copyright ©2000 The McGraw Hill Companies Networks: Data Link Layer 4 Tanenbaum’sTanenbaum’s DataData LinkLink LayerLayer TreatmentTreatment • Concerned with communication between two adjacent nodes in the subnet ( 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 Layer 5 LayerLayer 4 4 Host Host A B

Layer 2 Node Node 1 2 frame

Data Link Layer Model Assume 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 help students understand the data link layer issues.

Networks: Data Link Layer 6 Basic Elements of ARQ

Error-free Packet Information frames packet sequence sequence Transmitter Receiver

Station A Control Station B frames

CRC CRC Header Information Header Control frame packet

Information Frame

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

Networks: Data Link Layer 7 Tanenbaum’sTanenbaum’s ProtocolProtocol DefinitionsDefinitions

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

Networks: Data Link Layer 8 ProtocolProtocol DefinitionsDefinitions (continued)(continued)

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

Networks: Data Link Layer 9 packet network layer buffer

frame data link layer info ack seq kind

physical layer

Networks: Data Link Layer 10 FigureFigure 33--1010

UnrestrictedUnrestricted SimplexSimplex ProtocolProtocol

Networks: Data Link Layer 11 FigureFigure 33--1111

SimplexSimplex StopStop--andand-- WaitWait ProtocolProtocol

Networks: Data Link Layer 12 Ambiguities with Stop-and-Wait [unnumbered frames]

(a) Frame 1 lost Time-out time A frame frame frame frame 0 1 1 2 ACK ACK B

(b) ACK lost Time-out time A frame frame frame frame 0 1 1 2 ACK ACK ACK B

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

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

Networks: Data Link Layer 13 State Machine for Stop-and-Wait

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

Rnext Slast Timer

Slast Transmitter Receiver

Station A Rnext Station B

(0,0) Error-free frame 0 (0,1) arrives at receiver Global State: ACK for (S , R ) last next ACK for frame 0 frame 1 arrives at arrives at transmitter transmitter Error-free frame 1 arrives at receiver (1,0) (1,1)

Copyright ©2000 The McGraw Hill Companies Leon-Garcia & Widjaja: Communication Networks Figure 5.11 Networks: Data Link Layer 14 #define MAX_SEQ 1 typedef 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; Protocol 3 next_frame_to_send = 0; Protocol 3 from_network_layer (&buffer); (PAR) Positive ACK while (true) with Retransmission { s.info = buffer; with Retransmission s.seq = next_frame_to_send; [Old Tanenbaum Version] 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); } } }

Networks: Data Link Layer 15 void receiver_par (void) { seq_nr next_frame_to_send; frame r, s; Protocol 3 event_type event; frame_expected = 0; (PAR) Positive ACK while (true) with Retransmission { wait_for_event (&event); [Old Tanenbaum Version] 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 */ } } }

Networks: Data Link Layer 16 PAR [OLD] problem Ambiguities when ACKs are not numbered

time-out time A frame 0 frame frame frame 0 ACK 1 2 ACK B Transmitting station A misinterprets duplicate ACKs

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

Networks: Data Link Layer 17 PARPAR

SimplexSimplex ProtocolProtocol forfor aa NoisyNoisy ChannelChannel

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

Networks: Data Link Layer Continued Æ 18 AA SimplexSimplex ProtocolProtocol forfor aa NoisyNoisy ChannelChannel

Code added

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

Networks: Data Link Layer 19 SlidingSliding WindowWindow ProtocolsProtocols [[TanenbaumTanenbaum]] • Must be able to transmit data in both directions. • Choices for utilization of the reverse channel: – mix DATA frames with ACK frames. –– PiggybackPiggyback thethe ACKACK • 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 Layer 20 SlidingSliding WindowWindow ProtocolsProtocols

• 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 Layer 21 SlidingSliding WindowWindow ProtocolsProtocols Each outbound frame must contain a sequence number. With n bits for the sequence number field, maxseq = 2n -1and 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 Layer 22 SlidingSliding WindowWindow ProtocolsProtocols The Host is oblivious to sliding windows and the message order at the 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 Layer 23 SlidingSliding WindowWindow ProtocolsProtocols • 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 Layer 24 SlidingSliding WindowWindow ProtocolsProtocols receiver’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 Layer 25 SlidingSliding WindowWindow ProtocolsProtocols Selective 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 Layer 26 ChoicesChoices inin ACKACK MechanismsMechanisms 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.

Networks: Data Link Layer 27 OneOne--BitBit SlidingSliding WindowWindow ProtocolProtocol

Networks: Data Link Layer 28 Go Back N

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

fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 3 4 5 6 3 4 5 6 7 8 9 A

B A A A Out-of-sequence frames A A A A A A C C C C C C C C C K K K K K K K K K 1 2 3 error 4 5 6 7 8 9

ACKing next frame expected

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

Networks: Data Link Layer 29 Go Back N with NAK error recovery

Transmitter goes back to frame 1

Go-Back-7:

fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 A 3 4 5 1 2 3 4 5 6 7 0

B A N Out-of-sequence A A A A A A C A frames C C C C C C K K K K K K K K 1 1 2 3 4 5 6 7

error

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

Networks: Data Link Layer 30 Networks: Data Link Layer 31 Networks: Data Link Layer 32 Selective Repeat with NAK error recovery

fr fr fr fr fr fr fr fr fr fr fr fr fr fr time 0 1 2 A 3 4 5 6 2 7 8 9 10 11 12

B A A N A A A A A A A A A C C A C C C C C C C C C K K K K K K K K K K K K 1 2 error 2 2 2 2 7 8 9 1 1 1 0 1 2

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

Networks: Data Link Layer 33 Networks: Data Link Layer 34 Networks: Data Link Layer 35