The Data Link layer can be further subdivided into: Computer Networks application 1. (LLC): provides flow and error control transport • different link protocols may provide different services, e.g., Ethernet doesn’t provide reliable network delivery (error recovery) Lecture 26: 2. Media Access Control (MAC): framing and LLC MAC and ARQ media access physical

Link Layer Services Flow Control Flow Control: What is flow control? • pacing between adjacent sending and receiving nodes • receiver telling sender to slow down Error Control: Why do you need flow control? • errors caused by signal attenuation, noise • ARQ: receiver detects presence of errors and asks sender for retransmission Flow control protocols at data link layer (single hop): • FEC: receiver identifies and corrects bit error(s), • XON/XOFF without resorting to retransmission • Stop & Wait Protocol • Reliable delivery between adjacent nodes • seldom used on low bit error links (fiber, some twisted pair) Similar issues and mechanisms apply at the • plays an important role in wireless links with high error rates (end-to-end) • Q: why do we need both link-level and end-end reliability? XON/XOFF Stop and Wait (S&W) Protocol ! : propagation After sending a packet, sender must wait for delay SR acknowledgment (ACK) before sending the next packet sender receiver Sender Receiver S R round-trip Algorithm: time (rtt) t • S sends stream of data Time ! : propagation • R sends XOFF, S stops transmission pkt delay • 2! R sends XON, S resumes transmission t+ !

ACK Works OK if τ is small, otherwise sender t+ can overrun receiver (Why?) 2!

Stop & Wait Performance Stop & Wait Performance sender receiver Disadvantages: first packet bit transmitted, t = 0 • slow last packet bit transmitted, t = L/µ • must wait for ACK even if no overrun first packet bit arrives • max transmission bandwidth 1 packet/round-trip time (rtt) RTT (2τ ) last packet bit arrives, send ACK

Performance is ok if τ is small, otherwise inefficient ACK arrives, send next packet, t = RTT + L/µ Example 1: Example 2: • link bandwith (µ) = 1 Mbps, with packet size (L) = 1 Kbits, • link bandwidth (µ ) = 1 Gbps, propagation delay (τ ) = 15 ms, transmission time is L/µ = 1 ms packet size (L) = 8 Kbits, transmission time is L/µ = 8 µs

• if rtt (2τ ) = 9 ms, we can send 100 pkts/sec • sender utilization (Us), fraction of time sender is sending: 3 9 • the throughput (Tg) is 100 Kbps (10% of capacity) L / µ 8·10 /10 U = = = 0.00027 s 2τ + L / µ 30 + 8·10−6 Sliding Window: Sliding Window Pipelined Flow Control Send w number of packets before waiting for an ACK (can have w outstanding, unACKed, packets) Pipelining: sender allows multiple “in-flight,” yet-to-be-acknowledged, packets

[Stevens]

For every received ACK, slide window (over data) by 1 packet (S&W is sliding window with w = 1)

Throughput of the sliding window protocol (Tw):

Tw = Tg*w

send window size w limited by buffer size at receiver (wR):

Tw = Tg*MIN(w,wR)

Pipelining: Increased Utilization sender receiver Sliding Window: Max Window Size first packet bit transmitted, t = 0 last bit transmitted, t = L/µ What is the optimal window size? first packet bit arrives i.e., what’s the maximum number of packets on can RTT (2τ ) last bit of 1st pkt arrives, send ACK last bit of 2nd pkt arrives, send ACK have outstanding (to “fill the pipe”)? last bit of 3rd pkt arrives, send ACK ACK arrives, send next μ = μ = 2 μ packet, t = RTT + L/µ Let be the link bandwidth, pipe size RTT* τ * (commonly called the bandwidth-delay product) Example 3: Normally you don’t want to, and can’t, fill the pipe • link bandwidth (μ) = 1 Gbps, propagation delay (τ ) = 15 ms, packet size (L) = 8 Kbits, transmission time is L/µ = 8 completely (more when we discuss reliable transport µs, window size (w) = 3 protocol) increased • sender utilization (Us), fraction of time sender is sending: utilization w * L / µ 3* 8·103 /109 by a factor U = = = 0.0008 of 3! s 2τ + L / µ 30 + 8·10−6 Error Control (ARQ)

Sender Receiver S R round-trip How does sender know when time (rtt) Errors are unavoidable, caused by noise on channel: t Time τ : propagation pkt • electrical interference, thermal noise, cosmic rays, etc. and which pkts to retransmit? X delay 2τ pkt lost • by the use of ACKs and timeout t+ τ

Three kinds of transmission errors: t+ 2τ General algorithm: pkt 1. sent signal destroyed (data not received) rexmitted 2. sent signal changed (received wrong data) • receiver acknowledges (ACKs) receipt of pkts 3. spurious signal created (received random data) • sender retransmits packets not ACKed by timeout • a.k.a. PAR: Positive Acknowledgement with Retransmission Automatic Repeat reQuest (ARQ): sender retransmits lost or corrupted packets Reliability protocols: • Alternating Bit Protocol (ABP) • Go-Back-N (GBN, with or without NAK) • Selective Repeat Protocol (SRP)

Alternating Bit Protocol (ABP) ABP in Action S&W with un-numbered packets and ACKs causes confusion on retransmission: • how to differentiate a retransmitted frame from the next frame? Sender Receiver S R round-trip time (rtt) t Time τ : propagation pkt delay 2τ t+ τ ACK X ACK lost t+ 2τ

how to detect duplicate? ABP: uses 1 bit to number packets and ACKs ABP in Action Performance of ABP ABP works, but performance is bad Example: • link bandwidth (µ ) = 1 Gbps • propagation delay (τ ) = 15 ms • packet size (L) = 8 Kbits, transmission time is L/µ = 8 µs

• sender utilization (Us) is the same as S&W: L / µ 8·103 /109 U = = = 0.00027 s 2τ + L / µ 30 + 8·10−6 • about 1 packet every 30 ms • 33 KBps or 264 Kbps throughput over a 1 Gbps link!

Go-Back-N (Link-layer) Go-Back-N (Link-layer)

Sender: Sender: • puts k-bit sequence number (seq#) in packet header • associates a timer with each in-flight packet • sends a “window” of up to N packets • timeout(n): retransmits packet with seq# n • consecutive unACKed (una) packets allowed and all higher seq# in window • resets snd_next to snd_una (n) snd_una snd_next • resets timer for all retransmitted packets

snd_una snd_next

• notation: ACK(n) means ACKs packet with seq# n Go-Back-N (Link-layer) Go-Back-N [K&R] Receiver: Sender: • only needs to remember next expected seq# (next_seqn) • ACK(n) is cumulative: ACKs all packets up to and including seq# n • ACKs and delivers to app packets that arrived in order • maintains only one active timer, for snd_una • discards out-of-order packets no buffering! • timeout(snd_una): retransmits snd_una and all higher seq#s in • ACKs out-of-order packets if seq# is smaller than next_seqn window Sender Receiver Sender Receiver (why?) S R S R • snd_next snd_una round-trip resets to time (rtt) 1 1 2 2 • resets timer for snd_una 3 3 4 4 X Pkts Pkts next_seqn 2τ 1 = 2 2 1 3 3 discard snd_una snd_next 4 4 these ACK(1) X next_seqn ACK(1) = 5 5 5 ACK(3) ACK(4) 2 2 3 3 rexmission 4 4 5 5 next_seqn 5 5 discard timeout (rto) = 6 next_seqn 2 2 = 2 ACK(5) 3 discard 3 4 all these 4 5 5 ACK(2) ACK(2) ACK(3) ACK(3) ACK(4) ACK(4) ACK(5) ACK(5)

Go-Back-N [K&R] Go-Back-N with Negative ACK (NAK) Receiver: Receiver: • only needs to remember next expected seq# (next_seqn) • ACKs and delivers in-order packets • cumulative ACK acknowledges all packets received in-order • sends NAK for first out of order packet and discards packet • out-of-order packets repeat the last ACK Sender Receiver Sender Receiver • ACKs and discards subsequent out of order packets S R S R round-trip time (rtt) 1 1 2 2 3 3 4 4 Sender: retransmits on receiving NAK or if RTO expires X Pkts Pkts next_seqn 2τ 1 1 2 = 2 3 3 discard 4 4 these ACK(1) X next_seqn ACK(1) 5 ACK(3) = 5 5 ACK(4) ACK(1) 6 7 2 8 3 sender rexmission 4 timeout (rto) 5 5 5 discard 6 next_seqn 7 2 = 2 ACK(5) 8 3 ACK(1) 4 next_seqn 5 ACK(6) = 9 ACK(2) receiver ACK(7) ACK(8) ACK(3) ACK(4) Walrand ACK(5) Selective Repeat Protocol (SRP) Selective Repeat Protocol (SRP) Receiver: Receiver: • buffers out-of-order packets (up to wR), for in-order delivery • buffers out-of-order packets (up to w ), for in-order delivery R • ACKs all correctly received packets individually • ACKs all correctly (no error, but may be out-of-order) received packets individually, not cumulatively 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Sender: cannot send ok to send snd_una snd_next • pkt 5 (why?) pkt 6 (why?) Sender: keeps track of wR and ensures that wR > (snd_next − snd_una), • keeps track of wR in the example, wR = 4 and ensures that w R • wR > (snd_next − snd_una) keeps a retransmit timer • keeps a retransmit timer for each packet

for each packet • retransmits only unACKed Walrand • retransmits only packets unACKed packets wR next_seqn Selective Acknowledgement: Piggy-back NAK with ACK., e.g. [ACK2,NAK1], [ACK4,NAK3]

Selective Repeat in Action Selective Repeat Summary sender receiver • data from upper layer: • packet n in [next_seqn, • if next available seq# in next_seqn+wR1] window, send packet • send ACK(n) • timeout(n): • out-of-order: buffer • non-cumulative ACK • resend packet n, restart timer in-order: deliver (also deliver buffered, in-order packets), • received ACK(n) in [snd_una, advance window to next not-yet- snd_next]: received packet • mark pkt n as received • next_seqn • if n is smallest unACKed packet n < • n packet, advance snd_una to send ACK( ) next unACKed seq# • otherwise: • ignore ARQ Protocols Summary Simplifying Assumption Infinite sequence# space Go-Back-N [K&R]: Selective Repeat • sender: allows up to N • sender: allows up to N Suppose you have only a 2-bit sequence space: Sender Receiver unACKed packets in pipeline unACKed packets in pipeline S R rexmission • • timeout (rto) receiver: sends cumulative receiver: ACKs individual 1 2 3 ACKs packets 4 • repeat last ACK if there’s a gap Pkts 1 • sender: maintains timer for 2 3 • sender: keeps timer only for 4 each unACKed pkt ACKs X oldest unACKed pkt • if timer expires: retransmits only • if timer expires: retransmits all unACKed packet 1 unACKed packets

1st or 5th pkt? Q: what’s the relationship between seq# space and window size?

Ethernet: Connectionless Service Other Issues at Transport Layer No handshaking between sending and receiving adaptor Connectionless network layer means each packet can: • take a different path Receiving adaptor doesn’t send ACKs or NACKs to • experience different congestion sending adaptor • stream of datagrams passed up to network layer can have gaps Implications: • gaps will be filled if application uses reliable transport layer • non-deterministic round-trip time • otherwise, application will see the gaps • out-of-order packets must be buffered for Go-Back-N (so as not to mistake late packets as lost packets) Other data link protocols may provide error correction • complicates computation of receiver’s window (w) and flow control