320 likes | 554 Views
TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP. Instructor: Dr. Li-Chuan Chen Date: 09/22/2003. Based in part upon slides of Prof. J. Kurose (U Mass), Prof. K. Fall (UC-Bekeley). Telnet. FTP. DNS. Application. TCP. UDP. IP. Transport. Packet radio.
E N D
TCOM 509 – Internet Protocols (TCP/IP)Lecture 04_bTransport Protocols - TCP Instructor: Dr. Li-Chuan ChenDate: 09/22/2003 Based in part upon slides of Prof. J. Kurose (U Mass), Prof. K. Fall (UC-Bekeley)
Telnet FTP DNS Application TCP UDP IP Transport Packet radio LAN Internet Net interface/ Physical Internet Layer Transport Layer: • UDP • TCP
TCP • Provides the following reliable services to applications such as FTP, SMTP, TELNET. • Logical connection Establishment • Maintenance termination • Reliable data transfer • In-order byte stream • point-to-point: • one sender, one receiver • connection-oriented: • Establish a connection before data exchange • flow control • sender will not overwhelm receiver
TCP - Reliability • Sequence numbers are used for re-ordering at the destination • Use sequence numbers and acknowledgements (ack) • sender sends a packet, starts a timer, and waits for ack before next send • Retransmit if data is lost (timer expires before receiving ack)
TCP – Flow Control • Use sliding window mechanism • TCP sliding window operates at octet (byte) level not segment or packet level. • Receiver sends a window that specifies receiver current buffer size • Multiple segments can be sent before an ACK is received by the sender
32 bits source port # dest port # sequence number acknowledgement number head len not used Receive window U A P R S F checksum Urg data pnter Options (variable length) application data (variable length) TCP segment structure URG: urgent data (generally not used) counting by bytes of data (not segments!) ACK: ACK # valid PSH: push data now (generally not used) # bytes Receiver willing to accept RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) TCP minimum header size = 20 bytes
Opening a connection Three way handshake: Step 1: client host sends TCP SYN segment to server specifies initial seq # no data Step 2: server host receives SYN, replies with SYNACK segment server allocates buffers specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data TCP Connection Management Host A Host B SYN, Seq=100 SYNACK, Seq=1000, Ack=101 ACK, Seq=101, Ack=1001 time TCP Connection scenario
Closing a connection: Step 1:client end system sends TCP FIN control segment to server Step 2:server receives FIN, replies with ACK. Closes connection, sends FIN. TCP Connection Management (cont.) client server close FIN ACK close FIN ACK timed wait closed
Step 3:client receives FIN, replies with ACK. Enters “timed wait” - will respond with ACK to received FINs Step 4:server, receives ACK. Connection closed. TCP Connection Management (cont.) client server closing FIN ACK closing FIN ACK timed wait closed closed
stop-and-wait operation sender receiver first packet bit transmitted, t = 0 last packet bit transmitted, t = L / R first packet bit arrives RTT last packet bit arrives, send ACK ACK arrives, send next packet, t = RTT + L / R
TCP: Transmission scenarios Host A Host B Seq, Seq=101, Ack=10018 bytes data ACK=109 timeout Seq=109, 16 bytes data ACK=125 time
Pipelining: sender allows multiple packets send before receiving acknowledged range of sequence numbers must be increased buffering at sender and/or receiver Two generic forms of pipelined protocols: go-Back-N, selective repeat Pipelined protocols
Pipelining: increased utilization sender receiver first packet bit transmitted, t = 0 last bit transmitted, t = L / R first packet bit arrives RTT last packet bit arrives, send ACK last bit of 2nd packet arrives, send ACK last bit of 3rd packet arrives, send ACK ACK arrives, send next packet, t = RTT + L / R Increase utilization by a factor of 3!
receiver individually acknowledges all correctly received packets buffers packets, as needed, for eventual in-order delivery to upper layer sender only resends packets for which ACK not received sender timer for each unACKed pkt sender window N consecutive seq #’s again limits seq #s of sent, unACKed pkts Selective Repeat
Example: seq #’s: 0, 1, 2, 3 window size=3 receiver sees no difference in two scenarios! incorrectly passes duplicate data as new in (a) Q: what relationship between seq # size and window size? Selective repeat:dilemma
Host A Host B Seq=101, 8 bytes data ACK=109 Seq=92 timeout timeout X loss Seq=101, 8 bytes data ACK=109 SendBase = 109 time time lost ACK scenario TCP: retransmission scenarios Host A Host B Seq=101, 8 bytes data Seq=109, 16 bytes data ACK=109 ACK=125 Seq=101, 8 bytes data Sendbase = 101 SendBase = 125 ACK=125 Seq=92 timeout SendBase = 125 premature timeout
Host A Host B Seq=101, 8 bytes data ACK=109 Seq=109, 16 bytes data timeout X loss ACK=125 time Cumulative ACK scenario TCP retransmission scenarios (more) Cumulative ACK: • Pros: • acks are unambiguous and easy to generate. • Lost acks may not need to retransmit • Cons: • Sender does not receive all acks for the successful transmission SendBase = 125
receive side of TCP connection has a receive buffer: speed-matching service: matching the send rate to the receiving app’s drain rate flow control sender won’t overflow receiver’s buffer by transmitting too much, too fast TCP Flow Control • app process may be slow at reading from buffer
Congestion: informally: “too many sources sending too much data too fast for network to handle” different from flow control! manifestations: lost packets (buffer overflow at routers) long delays (queueing in router buffers) Principles of Congestion Control
end-end control (no network assistance) sender limits transmission: LastByteSent-LastByteAcked CongWin Roughly, CongWin is dynamic, function of perceived network congestion How does sender perceive congestion? loss event = timeout or 3 duplicate acks TCP sender reduces rate (CongWin) after loss event three mechanisms: AIMD slow start conservative after timeout events CongWin rate = Bytes/sec RTT TCP Congestion Control
multiplicative decrease: cut CongWin in half after loss event additive increase: increase CongWin by 1 maximum segment size (MSS) every RTT in the absence of loss events: probing TCP AIMD
Slow-start: Let i = ith iteration of round trip c = congestion window size Init i = 0, c=1: TCP sends 1 segment i = 1, c = 2: TCP sends 2 segments i = 2, c = 4: TCP sends 4 segments i = 3, c = 8: TCP sends 8 segments … i = n, what is the number of segments that TCP can send? Response to TCP Congestion
When connection begins, increase rate exponentially until first loss event: double CongWin every RTT done by incrementing CongWin for every ACK received Summary: initial rate is slow but ramps up exponentially fast Host A Host B one segment RTT two segments four segments time TCP Slow Start (more)
Congestion collapse: retransmission can cause network unusable. To avoid congestion collapse, must reduce transmission rate Slow-start Multiplicative decrease Multiplicative decrease congestion avoidance (exponential backoff timer): upon loss of a segment, reduce the congestion window size by half (traffic is reduced exponentially overtime). Slow-start recovery: for a new connection or after a period of congestion, increase the congestion windows size by one segment each time when ACK arrives. Response to TCP Congestion
To avoid increasing the window size too quickly and causing more congestions, TCP uses congestion avoidance phase. Congestion avoidance phase Once the congestion windows reaches half of its original size, slows down the rate by increases the congestion window size by only 1 if all segments in the window have been acknowledged. Response to TCP Congestion
Read Section 13.1 – 13.15, 13.20, 13.23 – 13.25,13.33 Chapter 13