Week 7: Oct 10 UDP socket programming details TCP ========================================================================= TCP - P&D 5.2 more semantic issues: connected v connectionless connection is between two sockets: a socketpair one socket on host A can be part of multiple distinct socketpairs reliable v unreliable stream v packets what TCP does; header fields TCP Header Format 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TCP Header Format connection establishment Logical issue of what is a "connection" connection state on top of stateless lower layer basic strategy of 3-way handshake ISN issue outline versus one 2-way handshake TCP sliding windows mostly done earlier basic outline examples, window-size flow control fast sender, slow receiver fast receiver, slow sender slow router Keeping the pipe full: bandwidth*delay! p. 301 eoc: just got to TIMEWAIT and final ACK Introduction to TCP state diagram, as far as connection establishment Initial Sequence Numbers (ISNs) SYN, ACK, FIN, RST packets TIMEWAIT and final ACK again old late duplicates problem: TIMEWAIT again! what a connection is: machine state at each endpoint TCP should handle: lost packets damaged packets reordered packets duplicated packets widely varying delay OLD LATE DUPLICATES problem TCP example ISN negotiation, choice MSL TIMEWAIT TIMEWAIT and final ACK ISN rationale 1: old late duplicates ISN rationale 2: distinguishing new SYN from dup SYN From Dalal & Sunshine's original paper on the TCP 3-way handshake: 2-way handshake: can't confirm both ISNs 4-way handshake: 1 --SYN-> 2 <-ACK-- 3 <-SYN-- 4 --ACK-> FAILS if first SYN is very very old The ack at line 2 is ignored. LHS thinks the SYN on line 3 is a new request, and so it acks it. It would then send its own SYN (on what would be line 5), but it would be ignored. At this point A and B have different notions of ISN_A. 3-way handshake ================================================================================ An example exchange, showing SEQ and ACK fields for each packet. Each side chooses its ISN: A chooses 500 and B chooses 3000. A B SYN, ISN_A = 500 SYN+ACK, ISN_B=3000, ACK=501 ACK 3001 Data="ABC", SEQ=501,ACK=3001 ACK SEQ=3001, ACK=504 // 3001 *would* be next byte DATA="EF", SEQ=504, ACK=3001 DATA="G", SEQ=506 ACK=507 DATA="xyzw" SEQ=3001 ACK=3005 SEQ=507 DATA="HI" ACK=509, SEQ=3005 ACK=3005, SEQ=509, FIN ACK=510, SEQ=3005 // FIN is like 1 byte ACK=510, SEQ=3005, DATA="goodbye" ACK=510, SEQ=3012, FIN ACK=3013, SEQ=510