Politecnico di Milano Scuola di Ingegneria Industriale e dell Informazione Link Layer Fundamentals of Communication Networks
Data Link layer o It is the first logical layer in the protocol stack o Functions n Framing: Identification of the group of bits exchanged with the physical layer n Detect and correct errors (optional) n Multiplexing (optional) n Multiple access (optional)
Framing o The bits exchanged through the SAP with the physical layer are grouped and need to be identified bit Layer 2 1-SAP frame 1 frame 2 Layer 1 o The groups of bits define a data structure name frame (PDU-2)
Framing o It is necessary to identify boundaries between frames bit Layer 2 Layer 1 1-SAP frame 1 frame 2 o There are two possibilities n Frame delimiters (special sequences of bits) n Signaling information passed by the physical layer
Bit oriented protocols o These protocols use flags (special sequences of bits) for delimiting frames and aligning receiver o Example: HDLC n Flag sequence of start and end 0 1 1 1 1 1 1 0 n Problem: how to prevent that the sequence is present into the data part of the frame Solution: Bit stuffing: insert a 0 after five consecutive 1s
Bit Stuffing Data 1111000111111000010010101111101 Bit stuffing frame 01111110 111100011111010000100101011111001 01111110 flag flag reception 01111110 111100011111010000100101011111001 01111110 Start flag identification Deletion of bits added End flag identification
Politecnico di Milano Scuola di Ingegneria Industriale e dell Informazione Error detection and retransmission
Error control and recovery o Physical layer typically have error control mechanisms for ensuring reliability o These are based on FEC (Forward Error Correction) and allow to fully exploit channel capacity o Physical layer leave to data link layer a residual error (not corrected) that depends on the specific technology and may range from 10-2 to 10-9 o Since for most data applications this residual probability is not sufficient (think e.g. on your home banking application J ) o At data link layer a mechanism for error detection and retransmission of wrong frames is adopted (ARQ: Automatic Retransmission request)
Error detection No: error Yes: correct header payload FCS =? FCS Add error check sequence Check parity bits header payload FCS header payload FCS TX channel RX
Error recovery: ingredients o Correctly received frames are acknowledged to the transmitter with a message sent by the receiver (ACK) o In same case an incorrect frame can also be notified back with NACK (Not ACK) message o The lack of ACK or the reception of a NACK signals the need to retransmit a frame o Procedures repeats until the frame is correctly received o The transmission of service messages (ACK, NACK) requires a feedback communication channel o Note that also service messages can have errors when received
Error recovery o Error recovery procedures can be implemented in any layer o Historically they are considered part of the data link layer since most of the physical channel were unreliable o Now with some media (like e.g. fibers) they are not strictly necessary, while with others (like e.g. radio) they are still largely adopted o Due to the need of offering reliable services to applications, they are also implemented at transport layer (layer 4) as end-to-end procedures (like e.g. in TCP)
Number of retransmissions Let us consider a link with bit error rate equal to p Frames have a length of L bits ACK messages are error free o The correct reception probability is c = (1-p)L p << 1 c 1 Lp o The average number of retransmissions is i=1 r = i c(1 c) i = 1 c 1
Total number of retransmissions on multiple links Let us consider a path in the network with H links o The average number of retransmissions on the whole path is r (l) " = H 1 H $ # c 1 % ' &
Total number of retransmissions on multiple links o The probability of correct reception on the end-to-end connection is: C = c H = (1 p) LH o The average number of retransmissions is: r H (e) = H " $ # 1 C 1 % " ' = H 1 & c 1 % " $ ' = H r (l) H $ # H & # H +1 % ' & H H o o with H large with r H small r H (e) He r H (l ) H He r H (l ) r H (e) Hr H (l)
Example o Comparison between single link and multiple links with L= 10.000 bits and H = 20 1000 Average num. of retransmissions 100 10 1 0.1 0.01 end-to-end link 0.001 1.E-09 1.E-08 1.E-07 1.E-06 1.E-05 1.E-04 1.E-03 Bit Error rate
ARQ protocols o ARQ protocols define the rule for retransmissions between entities of the same layer o In addition to error recovery they provide in sequence delivery to upper layer without packet duplications o They use signaling messages: n ACK (acknowledgement) n NACK (not acknowledgement) o Three main classes: n Stop & Wait n Go-Back-N n Selective Repeat
Stop and Wait o It is based on ACK messages only o Retransmissions are regulated by a timer (time out) o Each correctly received message is acknowledged with an ACK
Stop and Wait o Transmitter sends one packet (frame) at a time and initializes the time-out counter o If first event occurring is: n n ACK reception, a new packet is transmitted Time-out expiration, packet is retransmitted 1 2τ+Τ ack time-out 2 2 3 tx ACK ACK rx Correct operation if time-out >= 2τ+Τ ack
Stop and Wait o If ACK is lost (due to error on the channel or any other reason), the packet is retransmitted and packet may be duplicated at receiver o For this reason frame are numbered with a sequence number (SN) so that duplicated frames can be discarded 1 2 2 3 tx ACK ACK ACK rx
Stop and Wait time-out 1 1 2 3 ACK ACK ACK 1 3 o Delays in ACK reception may lead to wrong interpretation of ACKs received o For this reason also ACK are numbered Receiver Number (RN) o In this case a binary numbering is sufficient (0,1)
Stop and Wait o Protocol efficiency: n Fraction of time channel is used for successful transmissions η = T + T τ T ack τ data T T ack + 2τ data T = transmission duration τ= propagation delay data tx ACK ACK ACK rx
Stop and Wait η = T T + T ack + = 2τ 1+ 1 Tack T + 2τ T o Low efficiency if T<<τ o Protocol not suitable for scenarios with high delay and/or high transmission rate o It can be used in half-duplex mode
Stop and Wait (with errors) o Assumptions n n n n n n Error process on bits purely random (no correlation) p: bit error probability T f : frame transmission time T a : ACK transmission time T o : retransmission time-out τ: propagation delay T f T o 1 1 ACK τ T a
Stop and Wait (with errors) o For each wrong packet, the time wasted is: T + f T o T f T o 1 1 ACK τ T a
Stop and Wait (with errors) o Success probability: o Average number of transmissions (including first one) : o Efficiency: P P P i P P P P P N i i s 1 ) (1... ) (1 3 ) (1 2 1 1 1 2 = = = + + + = = L f L a p P + = ) (1 τ η 2 ) 1)( ( + + + + = a f o f s f T T T T N T
Stop and Wait (with errors) o In the best case (T a =0, T o =2τ): η max = N s T ( T f f = + 2τ ) Tf P P = T τ f + 2τ 2 1+ T f η max P = 0.5 P = 0.7 P = 0.5 P =1 2τ T f
Stop and Wait: examples o IEEE 802.11 (WiFi) n Distance up to 250 m n Packet size 400-18000 bits n Rate 2-11-54-150 Mb/s o USB n distance + hub 30 m n rate max 480 Mb/s n Packet size 0-8216 bit o IEEE 1394 (Firewire) versions a and b n Distance 4.5 m n Rate max 400-1600 Mb/s n Packet size 0-16384 bit (at 400 Mb/s) 0-32768 bit (at 1600 Mb/s)
Go-back-N o Transmitter can send up to N packets before receiving ACK o Stop-and-wait is a special case with N=1 Window N 1 2 3 4 5 6 7 tx rx
Go-back-N o If an ACK arrives before the end of transmission of the N packets, the window of N packets is shifted by one position on the right Window (1,7) (1,7) (1,7) (1,7) (1,7) (2,8) (3,9) (4,10) 1 2 3 4 5 6 7 8 tx ACK 1 ACK 2 ACK 3 In this example with no error, transmission never stops and efficiency is 100% rx
Go-back-N o otherwise: transmitter starts retransmitting from the last non-acknowledged packet ( go back of N packets ) o Retransmission can be delayed by a time out (time out can be just equal to the transmission time of the window or larger) window (1,7) (1,7) (1,7) (1,7) (1,7) (1,7) 1 2 3 ----- 7 1 2 3 (1,7) tx rx
Go-back-N o Some packets that were correctly received may be retransmitted anyway o But the retransmission of the entire window allows receiver to keep only frames received in sequence Window (1,7) (1,7) (1,7) (1,7) (1,7) (1,7) 1 2 3 ----- 7 1 2 3 (1,7) tx 2 3 ----- rx Out of sequence packets can be discarded
Go-back-N: collective ACK o Since packets are delivered in sequence, ACK message can be collective (all packets up to k received correctly) Window (1,7) (1,7) (1,7) (1,7) (1,7) (1,7) (1,7) (4,10) 1 2 3 4 5 6 7 8 tx ACK 3 rx
Window size: continuous transmission o Retransmission can be triggered by a too short dimensioning of the window Finestra (1,3) (1,3) (1,3) (1,3) (1,3) (2,4) 1 2 3 1 2 3 (3,5) (4,6) 4 5 (4,6) 6 tx This reduces efficiency ACK 1 ACK 2 ACK 3 rx
Window size: with time-out o At the end of the window transmission is suspended until a time out expires (example: TCP) Window (1,3) (1,3) (1,3) (2,4) (3,5) (4,6) 1 2 3 4 5 6 tx ACK 1 ACK 2 ACK 3 rx Also in this case efficiency reduces
Window size T + Tack + 2τ N = T (1,5) (1,5) (1,5) (1,5) (1,5) (2,6) (3,7) (4,8) 1 2 3 4 5 6 7 T τ τ ACK 1 ACK 2 ACK 3 T ack 8 tx rx
Window size o Window can be dimensioned in time, bytes, packets, o Dimensioning gets complicated when propagation times are unknown: n example with go-back-n at Layer 4 (TCP), network crossing delay (τ) can vary with time
Window size o Window sufficiently big o With no error, efficiency is high o In case of error, error detection delay and number of retransmitted frames depend on the window size n It is also possible to use NACK messages
Use of NAK o The use of NAK can shorten retransmission delay in case of error, avoiding to wait until the end of the transmission window or timeout expiration o It is not possible to send NAK immediately after the reception of a wrong packet because receiver cannot decode the sequence number SN o Typically NAK is sent after the reception of an out-of-sequence packet/frame, assuming previous packet/frame is lost o It cannot be used in retransmission protocols at upper layer (like e.g. TCP) because outof-sequence may be due to other reasons
Window Use of NACK (1,9) (1,9) (1,9) (1,9) (2,10) (2,10) (2,10) (2,10) 1 2 3 4 5 6 2 3 tx ACK 1 NACK 2 rx
Go-back-N full-duplex Data packets/frames ACK Bidirectional channel receiver ACK receiver Data packets/frames - Analyzes received frames - Forwards correct frames to upper layer - generates ACKs
Go-back-N & piggy backing o ACKs can be included in the header of packets/frames sent in the opposite direction SN RN Information o SN: Sequence number of the packet/ frame sent o RN: Number of frame waited in the opposite direction (cumulative ACK indicating that all packets up to RN-1 have been correctly received)
Go-back-N rules o Transmitter: n N last : last ACK received n Nc: Current sequence number available for next transmission n Rules: o A frame is accepted for transmission only if Nc < N last + N, otherwise it is queued; if Nc < N last + N the frame is transmitted with SN = Nc and Nc is increased (Nc := Nc+1); o At each RN received, N last = RN; o Packets of the window are transmitted without timing constraints; o if time out expires (or window ends in case of continuous mode), retransmission starts from frame with SN=N last.
Go-back-N rules o Receiver: n Rules o If a frame with SN=RN is correctly received, it is forwarded to upper layer and RN:=RN +1; o When frames are transmitted in the opposite direction, the current values of RN is included n The interval N last and (N last + N-1) is the transmission window
Go-back-N full duplex w/o error Window (0,5) (1,6) (3,8) (4,9) 0 1 2 Received packets Transmitted packets SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=0 SN=4 RN=0 SN=5 RN=1 SN=6 RN=1 SN=7 RN=2 SN=8 RN=3 A B Transmitted packets SN=0 RN=1 SN=1 RN=3 SN=2 RN=4 Received packets Finestra 0 1 2 3 4 5 6 7 (0,5) (1,6) (2,7) 44
Go-back-N full duplex with error (0,4) (1,5) 0 1 2 3 4 5 (2,6) 6 7 8 9 A SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=1 SN=4 RN=2 SN=5 RN=3 SN=6 RN=4 SN=2 RN=5 SN=3 RN=6 SN=4 RN=7 SN=5 RN=8 SN=6 RN=9... Out of sequence B SN=0 RN=0 SN=1 RN=0 SN=2 RN=1 SN=3 RN=2 SN=4 RN=2 SN=5 RN=2 SN=6 RN=2 SN=7 RN=2 SN=8 RN=2 SN=9 RN=3 SN=10 RN=4... 0 1 2 3 4 (0,4) (1,5) (2,6) (3,7) (4,8) (5,9) (6,10) 5
Go-back-N full duplex with error (0,4) (3,7) (4,8) (5,9) 0 1 2 A SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=0 SN=4 RN=1 SN=0 RN=1 SN=1 RN=1 SN=3 RN=1 SN=4 RN=1 SN=5 RN=1 Out of sequence B SN=0 RN=0 SN=1 RN=1 SN=2 RN=2 SN=3 RN=3 SN=4 RN=4 SN=5 RN=5 SN=1 RN=5 SN=2 RN=5 0 1 2 3 4 (0,4) (1,5)
Go-back-N full duplex (short window) (0,3) (2,5) (4,7) 0 1 2 3 A SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=0 SN=0 RN=0 SN=1 RN=0 SN=2 RN=1 SN=3 RN=1 SN=4 RN=2 B SN=0 RN=2 SN=1 RN=4 SN=2 RN=4 SN=3 RN=4 0 1 2 3 4 (0,3) (1,4)
Go-back-N with ACKs (0,4) (1,5) (2,6) (3,7) (4,8) (5,9) (6,10) 0 1 2 3 A SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=0 SN=4 RN=0 SN=5 RN=0 SN=6 RN=1 SN=7 RN=1 SN=8 RN=2 B RN=1 RN=2 SN=0 RN=2 RN=3 SN=1 RN=4 SN=2 RN=5 SN=3 RN=6 RN=7 RN=8 0 1 2 3 4 5 6 7 8 (0,4) (1,5) (2,6) (3,7)
Go-back-N with NAK (0,6) (1,7) (2,8) 0 1 2 A SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=0 SN=4 RN=0 SN=0 RN=0 SN=1 RN=0 SN=2 RN=0 SN=3 RN=1 SN=4 RN=2 RN=3 B NAK RN=0 SN=0 RN=0 SN=1 RN=0 SN=2 RN=1 RN=2 RN=3 RN=4 0 1 2 3 (0,6)
Module of the SN-RN counter o The number of bits b of the sequence numbers SN and RN must be large enough so that the module of these counters M (0,1,,M-1), with M=2 b is always larger than the window o Otherwise in case of error an entire window may be lost due to the use of cumulative ACKs
Efficiency of Go-Back-N (w/o error) o If window is well dimensioned: WT f > T f +T a + 2τ η = 1 o Otherwise: WT f < T f +T a + 2τ η = WT f T f +T a + 2τ
Efficiency of Go-Back-N (with error) o Assumptions: n Independent errors n P: error probability on a frame n T f : frame transmission time n T a : ACK time n τ: propagation delay o Number of successfully transmitted frames: N s = 1 p o Number of consecutive errors: N e = 1 1 p
Efficiency of Go-Back-N (with error) o Efficiency is then: η = T f p T f p + T f +T a + 2τ 1 p = T f (1 p) T f + (T a + 2τ )p
Go back N examples o HDLC n Link Layer protocol of the ISO stack (I970) o TCP (Transport Control protocol) - Tahoe n Transport protocol of the Internet (used before TCP Reno)
Selective Repeat o Go Back N forces retransmission also of packets correctly received o This may be inefficient with many errors o As alternative, Selective Repeat (SR) retransmits wrong packets only using: n Packet reordering n ACK information per packet
Selective Repeat: Window o Also in this case, the protocol uses a window of N packets that can be transmitted o Window shifts when ACKs are received (like with GO- BACK-N) Window (1-5) 1 2 3 4 5 o o Window extends until the first packet without an ACK (like with GO-BACK-N) At the end of the window only packets without ACK are retransmitted Window (3-7) 3 5 6 7
Selective Repeat: Window o Note that window does not contain a fixed number of packets during retransmissions Window (3-7) 3 5 6 7 Window (3-7) 3 7 Window (3-7) 3 Window (8-12) 8 9 10 11 12
Selective Repeat: Reordering o For reordering packets in the window a buffer must be maintained n Buffer must contain a position for each packet of the window n Only packet sequences in order are delivered to upper layer n Buffer positions are realigned to window every this it shifts due to new ACKs received
Selective Repeat: Reordering buffer window To upper layer buffer pool New window
Selective Repeat: ACK o ACK can be transmitted with options: n Individual ACK messages n Cumulative ACKs (RN is first packet of the window to be received) and in addition a bitmap of packets to be received in the window RN=5 0 1 1 1 0 1 1 0 1 0 n Signaling information necessary is larger than with Go-back-N
Selective Repeat: Efficiency o Without error, efficiency is 1 like with Go- Back-N o With error, selective repeat retransmits only wrong packets, so efficiency can be calculated dividing the efficiency without error by the average number of retransmissions per packet η = 1 N s 1 N s = P
Selective Repeat examples o HDLC n ISO data link protocol (I970) in the SR mode o TCP (Transport Control protocol) Reno n Transport protocol of the Internet (version adopted after TCP Tahoe)
Error control: session set-up o For all error control protocols with retransmission it is necessary to setup a session n It is required to initialize SN and RN counters n Initialization guarantees no ambiguity in numbering packets/frames
Politecnico di Milano Scuola di Ingegneria Industriale e dell Informazione Link set-up protocols
Link set-up o They requires exchange of messages for activating channel and initializing counters SN and RN o Signaling messages must be protected to avoid state inconsistency (active, stand-by) of two end-points in case of error
Unbalanced setup and teardown o Only a primary station can initialize procedure o Messages can be retransmitted in case ACK is missing DOWN SET-UP UP TEAR-DOWN DOWN A INIT DISC B ACK-I ACK-D DOWN UP DOWN
Three way handshake o Like in previous case, but both end-points can initialize the connection o This requires ACK messages from both sides DOWN SET-UP UP TEAR-DOWN DOWN A INIT ACK-I DISC ACK-D B INIT ACK-I DISC ACK-D DOWN SET-UP UP TEAR-DOWN DOWN
Politecnico di Milano Scuola di Ingegneria Industriale e dell Informazione Flow control
Flow control o Objective: n Regulate transmission rate of packets so as it is adapted to the receiver processing rate o Usually implemented at n Data link layer (2) n Transport layer (4)
Flow control source destination o Buffer limited to W positions o Arbitrary user reception rate user Upper layer o Objective: avoiding packets are lost because buffer is full
Sliding window flow control o It s similar to the window mechanism of the go back n o Source cannot send more than W packets/frames without acknowledgment o ACKs are send by receiver only when packets are absorbed by user (forwarded to upper layer)
Sliding window
Sliding window ACK of bytes 1, 2 and 3
Sliding window flow control source SN=0 SN=1 SN=2 SN=3 SN=4 SN=5 SN=6 SN=7 destination RN=4 RN=2 RN=1 buffer 0 1 2 3 4 5 6 user 0 1 2,3
Retransmission and flow control o This mechanism is strictly linked with the error control since ACKs are delayed until packets are absorbed by users o If ACKs are too delayed, retransmissions can be triggered due to end of window or time out expiration o Increasing time-out is obviously not a solution since this will increase delay in case of error
Retransmission and flow control time-out source SN=0 SN=1 SN=2 SN=3 SN=4 SN=5 SN=2 SN=3 SN=4 SN=6 destination RN=6 RN=2 RN=1 buffer 0 1 2 3 4 5 user 0 1 2,3,4,5
Use of RNR o A possible solution n ACKs are transmitted when packets are correctly received n A special message RNR (Receiver Not Ready) is used to inform that buffer is full o Hybrid approach: n Delay ACKs up to a maximum time and then use RNR when necessary
Use of RNR source SN=0 SN=1 SN=2 SN=3 SN=4 SN=5 SN=6 SN=7 SN=8 SN=6 destination RN=6 RNR RN=5 RN=4 RN=3 RN=2 RN=1 buffer 0 1 2 3 4 5 6 user 0 1 2,3,4,5
Use of W field o The problem can be radically solved separating error control and flow control o This is done including explicitly the value of the available number of buffer positions in the header of the packets/frames transmitted in the opposite direction with a dedicated W field o The receiver then: n Sends ACKs when packets are received n Include in the window field W the available positions in the buffer o This is the approach used by TCP
Use of W field 0 1 2 3 4 5 6 source SN=0 SN=1 SN=2 SN=3 SN=4 SN=5 SN=6 destination buffer AN=1 W=3 AN=2 W=3 AN=3 W=3 AN=4 W=2 AN=5 W=1 AN=6 W=0 AN=6 W=4 0 1 2 3 4 5 6 user 0 1 2,3,4,5
Flow control- Rate Based approaches n o Flow control with leaky bucket P s Pacchetti W 1 P b Permessi o Flow control con token bucket n P s Packets ν P b 1 W Permessi ν
Flow control Rate Based P T T L o Example s ON = 1 Mbit / s P b = 4 Mbit = 0,8 s 1/ ν = 0,4 s OFF p = 1 s W = 10 = 25,000 byte / s C [Mbit/s] 1.2 1.0 0.8 0.6 0.4 0.2 0 0 C [Mbit/s] 0.5 1.0 1.5 2.0 2.5 3.0 t [s] o Leaky bucket 6 5 4 3 2 1 0 0 0.5 1.0 1.5 2.0 2.5 3.0 t [s] C [Mbit/s] o Token bucket 6 5 4 3 2 1 0 0 0.5 1.0 1.5 2.0 2.5 3.0 t [s]
Readings o Tanenbaum book: Chapter 3 o Study example Link protocols: HDLC and PPP