Introduction to Networks CSEN 404 Introduction to Networks Amr El Mougy Ali Saudi ** Slides are attributed to J. F. Kurose
Chapter 3 outline Connection-oriented transport: TCP segment structure reliable data transfer flow control connection management Principles of congestion control Transport-layer services Multiplexing and demultiplexing Connectionless transport: UDP Principles of reliable data transfer Transport Layer
TCP: Overview point-to-point: full duplex data: one sender, one receiver reliable, in-order byte steam: no “message boundaries” pipelined: TCP congestion and flow control set window size send & receive buffers full duplex data: bi-directional data flow in same connection MSS: maximum segment size connection-oriented: handshaking (exchange of control msgs) init’s sender, receiver state before data exchange flow controlled: sender will not overwhelm receiver Transport Layer
Reliable Data Transfer Application Layer Sending Process Receiving Process rdt_send() deliver_data() Reliable data transfer protocols (sending side) Reliable data transfer protocols (receiving side) Transport Layer Reliable Channel udt_send() rdt_rcv() Network Layer Unreliable Channel Provided Service Service Implementation
TCP segment structure Transport Layer source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number Receive window Urg data pointer checksum F S R P A U head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet (as in UDP) Transport Layer
TCP seq. #’s and ACKs Seq. #’s: byte stream “number” of first byte in segment’s data ACKs: seq # of next byte expected from other side cumulative ACK Q: how receiver handles out- of-order segments A: TCP spec doesn’t say, - up to implementer Host A Host B User types ‘C’ Seq=42, ACK=79, data = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=79, ACK=43, data = ‘C’ host ACKs receipt of echoed ‘C’ Seq=43, ACK=80 time simple telnet scenario Transport Layer
TCP reliable data transfer (RDT) TCP creates RDT service on top of IP’s unreliable service pipelined segments cumulative ACKs TCP uses single retransmission timer retransmissions are triggered by: timeout events duplicate ACKs initially consider simplified TCP sender: ignore duplicate ACKs ignore flow control, congestion control Transport Layer
TCP sender events: data rcvd from app: create segment with seq # seq # is byte-stream number of first data byte in segment start timer if not already running (think of timer as for oldest unACKed segment) timeout: retransmit segment that caused timeout restart timer ACK rcvd: if acknowledges previously unACKed segments update what is known to be ACKed start timer if there are outstanding segments
TCP: retransmission scenarios Host A Seq=92, 8 bytes data ACK=100 loss timeout lost ACK scenario Host B X time Host A Host B Seq=92 timeout Seq=92, 8 bytes data Seq=100, 20 bytes data ACK=100 ACK=120 Seq=92, 8 bytes data Seq=92 timeout ACK=120 premature timeout time
TCP retransmission scenarios (more) Host A Seq=92, 8 bytes data ACK=100 loss timeout Cumulative ACK scenario Host B X Seq=100, 20 bytes data ACK=120 time
Fast Retransmit time-out period often relatively long: long delay before resending lost packet detect lost segments via duplicate ACKs. sender often sends many segments back-to-back if segment is lost, there will likely be many duplicate ACKs for that segment If sender receives 3 ACKs for same data, it assumes that segment after ACKed data was lost: fast retransmit: resend segment before timer expires Transport Layer
X time Host A Host B seq # x1 seq # x2 seq # x3 ACK x1 seq # x4 triple duplicate ACKs resend seq X2 timeout time
TCP Flow Control receiver side of TCP connection has a receive buffer: sender won’t overflow receiver’s buffer by transmitting too much, too fast flow control IP datagrams TCP data (in buffer) (currently) unused buffer space application process rwnd speed-matching service: matching send rate to receiving application’s drain rate guarantees receiver’s buffer doesn’t overflow RcvBuffer app process may be slow at reading from buffer receiver: advertises unused buffer space by including rwnd value in segment header sender: limits # of unACKed bytes to rwnd
TCP Congestion Control Sliding Window Protocol Sender maintains a congestion window (cwnd), in addition to the receiver’s window (rwnd) advertised in ACK Allowed-window = min(cwnd, rwnd) If no congestion: Allowed-window = rwnd Packet loss is interpreted as congestion occurrence: reduce congestion window size. Transport Layer
TCP Congestion Control Congestion control is performed at the sending host, using feedback from the destination host (acknowledgments) The sender keeps increasing the congestion window cwnd until something happens, then it starts to react The original version of TCP, called TCP Tahoe, had only two phases: slow start (exponential increase) and congestion avoidance (linear increase) New version of TCP, called TCP Reno, has three states: slow start, congestion avoidance, and fast recovery (to recover from errors faster) Transport Layer
Slow Start Initially cwnd = 1 MSS, ssthresh = 64KB. Thus, sending rate = 1 MSS/RTT The sender sends one segment and waits for ACK For every ACK received, increase cwnd by 1 MSS (exponential increase) For how long?
TCP Tahoe Exponential increase takes place until one of 3 things occur: cwnd ≥ ssthresh, OR timeout event occurs, OR 3 duplicate ACKs are detected If cwnd ≥ ssthresh go to congestion avoidance state directly If timeout or 3 duplicate ACKs ssthresh = cwnd/2, set cwnd = 1, Increase exponentially (go to slow start) until cwnd ≥ ssthresh, then go to congestion avoidance state In congestion avoidance: increase cwnd by MSS2/cwnd for every new ACK received (linear increase) How long do we stay in congestion avoidance until either a timeout or 3 duplicate ACKs are detected Reaction: ssthresh = cwnd/2, cwnd = 1, enter slow start
Example Assume 1 MSS = 1 KB RTT cwnd ssthresh Event 1 Initial: 1 MSS = 1 KB Initial: 64KB 2 64 3 4 8 5 16 Timeout or 3 dup ACKs 6 7 9 10 11 12 13 Transport Layer
TCP Reno Slow start still incorporates exponential increase If a timeout event occurs in any state the reaction is the same ssthresh = cwnd/2, cwnd = 1, increase exponentially until cwnd ≥ ssthresh, then enter congestion avoidance The main difference is in the reaction to 3 duplicate ACKs Recall: 3 duplicate ACKs means that one ACK is missing Here, TCP Reno will enter fast recovery state: go to congestion avoidance while waiting for missing ACK (increase linearly), ssthresh = cwnd/2, cwnd = cwnd/2 If the missing ACK did not arrive then a timeout will occur cwnd = 1, ssthresh = cwnd/2, go to slow start (increase exponentially) If the missing ACK arrives cwnd = ssthresh, stay in congestion avoidance (increase linearly)
Example