230 likes | 439 Vues
Transport Layer TCP and UDP. IS250 Spring 2010 chuang@ischool.berkeley.edu. Transport Layer Functions. Addressing (ports) Data integrity (error detection) Reliable data transport Flow control Congestion control. TCP Transmission Rate.
E N D
Transport LayerTCP and UDP IS250 Spring 2010 chuang@ischool.berkeley.edu
Transport Layer Functions • Addressing (ports) • Data integrity (error detection) • Reliable data transport • Flow control • Congestion control John Chuang
TCP Transmission Rate • Q: Why limit ourselves to send only four packets at a time? • Q: how much data can be sent before ACK received? John Chuang
Flow Control Producer Consumer Queue Stream of messages Flow control (“Slow down please!”) Note: We don’t want packet to travel the entire network only to be dropped at the destination. John Chuang
Stop-and-go Sliding Window Flow Control: Two Approaches John Chuang
Recipient explicitly requests lower send rate by specifying window size (or MaxUnackedPackets) Source stops sending when number of unacknowledged data equal to window size Sliding Window window_size acknowledged sent can be sent outside window John Chuang
TCP Header: Flow Control 0 16 31 Source Port Number (16) Destination Port Number (16) Sequence Number (32) Acknowledgement Number (32) TCP Header Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) Padding Data … John Chuang
TCP Flow Control John Chuang
Throughput as Function of Window Size Sender Receiver Time Window Size Throughput = Roundtrip Time John Chuang
Transport Layer Functions • Addressing (ports) • Data integrity (error detection) • Reliable data transport • Flow control • Congestion control John Chuang
Network Congestion • If link is congested • Router queue fills up • Drops packets • Source does not receive ACK • Resends packets • Makes congestion worse John Chuang
Use packet drop as indicator of congestion Do not send all data to receiver at once Voluntary source-imposed policy (RFC 2581) slow start (SS) congestion avoidance (CA) fast retransmission fast recovery TCP Tahoe: SS + CA + fast retransmission TCP Reno: all four Other variants: TCP SACK, TCP Vegas, TCP Westwood, … TCP Congestion Control John Chuang
TCP Congestion + Flow Control window_size • Control transmission rate by setting window size • Window size set to be smaller of: • rwnd: receiver window (flow control) • cwnd: congestion window (congestion control) win = min(rwnd, cwnd) • rwnd set by receiver • Question: how does sender set cwnd? acknowledged sent can be sent outside window John Chuang
Congestion Window Size cwnd • TCP congestion control is an algorithm for sender to adaptively adjust window size • At steady state, cwnd oscillates around the optimal window size Congestion Avoidance Slow Start Time
Slow Start • Whenever starting traffic on a new connection, or whenever increasing traffic after congestion was experienced: • Set cwnd =1 (one segment) • Each time a segment is acknowledged increment cwnd by one (cwnd++). • DoesSlow Startincrement slowly? Not really. In fact, the increase of cwnd is exponential John Chuang
Slow Start Example • The congestion window size grows very rapidly • TCP slows down the increase of cwnd when cwnd >= ssthresh John Chuang
Congestion Avoidance • Slows down “Slow Start” • Ifcwnd > ssthreshtheneach time a segment is acknowledged increment cwnd by 1/cwnd (cwnd += 1/cwnd). • So cwnd is increased by one only if all segments have been acknowledged. • (We will learn later how to set ssthresh) John Chuang
Slow Start/Congestion Avoidance Example • Assume that ssthresh = 8 ssthresh Cwnd (in segments) Roundtrip times John Chuang
SEQ # unack next win TCP Congestion Control Pseudo-code win = min(cwnd, rwnd); while (next < unack + win) transmit next packet; Initially: cwnd = 1; ssthresh = infinite; New ack received: if (cwnd < ssthresh) /* Slow Start*/ cwnd = cwnd + 1; else /*Congestion Avoidance*/ cwnd = cwnd + 1/cwnd; Timeout: /* Multiplicative decrease */ ssthresh = 0.5 * win; cwnd = 1;
The big picture cwnd Timeout Congestion Avoidance Slow Start 1 Time
Cumulative and Duplicate ACKs • TCP uses cumulative ACK • ACK N means all bytes up to N-1 have been received • Duplicate ACKs may be due to • packets reordering • lost packet ACK 2 ACK 4 ACK 4 ACK 4 cwnd = 2 ACK 4 John Chuang
Fast Retransmit/Fast Recovery cwnd • Retransmit after 3 duplicated ACKs • Don’t want for timeout • No need to slow start again • halve cwnd • At steady state, cwnd oscillates around the optimal window size. Congestion Avoidance Slow Start 1 Time
TCP Congestion Control Shortcomings • “Fairness criterion” • Is “equal division” of resources always desirable? • Estimating congestion by retransmission is flawed for wireless links • Depends on accurate implementation -- cheating possible • Application can avoid congestion control by using UDP John Chuang