Presentation is loading. Please wait.

Presentation is loading. Please wait.

3: Transport Layer3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum.

Similar presentations


Presentation on theme: "3: Transport Layer3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum."— Presentation transcript:

1 3: Transport Layer3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum segment size r connection-oriented: m handshaking (exchange of control msgs) init’s sender, receiver state before data exchange r flow controlled: m sender will not overwhelm receiver r point-to-point: m one sender, one receiver r reliable, in-order byte steam: m no “message boundaries” r pipelined: m TCP congestion and flow control set window size r send & receive buffers

2 3: Transport Layer3b-2 Roadmap r TCP header and segment format r Connection establishment and termination r Normal Data flow r Retransmission

3 3: Transport Layer3b-3 TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number rcvr window size ptr urgent data checksum F SR PAU head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet checksum (as in UDP)

4 3: Transport Layer3b-4 TCP Headers: like UDP? r Source and destination port numbers r Checksum r Data length? Rely of length in IP header?

5 3: Transport Layer3b-5 TCP Headers: Familiar? r Sequence Number field ( 32 bit) m Sequence Number field indicates number of first byte in the packet r Receiver Window Size (16 bit) m Window like for GBN or selective repeat, but window size not fixed – variable based on receiver feedback r Acknowledgment Field (32 bit) m The acknowledgement field contains the next sequence number it is expecting thus implicitly acknowledging all previous segments. m Cumulative acks not selective acks or negative acks

6 3: Transport Layer3b-6 TCP seq. #’s and ACKs Seq. #’s: m byte stream “number” of first byte in segment’s data ACKs: m seq # of next byte expected from other side m cumulative ACK Q: how receiver handles out-of-order segments m A: TCP spec doesn’t say, - up to implementor Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario

7 3: Transport Layer3b-7 Implications of Field Length r 32 bits for sequence number (and acknowledgement) ; 16 bits for advertised window size m Implication for maximum window size? Window size <= ½ SequenceNumberSpace m Requirement easily satisfied because receiver advertised window field is 16 bits 2 32 >> 2* 2 16 m no wrap-around in maximum segment lifetime (MSL) = 120 seconds (?)

8 3: Transport Layer3b-8 Implications of Field Length (cont) r Advertised Window is 16 bit field => maximum window is 64 KB m Is this enough to fill the pipeline? m Pipeline = delay*BW product m 100 ms roundtrip and 100 Mbps => 1.19 MB r Sequence Number is 32 bit field => 4 GB m With a MSL of 120 seconds will this ever wrap too soon? m 4 GB/120 sec = 273 Mbps m Gigabit Ethernet? STS-12 at 622 Mbps?

9 3: Transport Layer3b-9 TCP Header: Flags (6 bits) r Connection establishment/termination m SYN – establish; sequence number field contains valid initial sequence number m FIN - terminate r RESET - abort connection because one side received something unexpected r PUSH - sender invoked push to send r URG – indicated urgent pointer field is valid; special data - record boundary r ACK - indicates Acknowledgement field is valid

10 3: Transport Layer3b-10 TCP Header: ACK flag r ACK flag – if on then acknowledgement field valid r Once connection established no reason to turn off m Acknowledgment field is always in header so acknowledgements are free to send along with data

11 3: Transport Layer3b-11 TCP Header: URG r If URG flag on, then URG pointer contains a positive offset to be added to the sequence number field to indicate the last byte of urgent data r No way to tell where urgent data starts – left to application r TCP layer informs receiving process that there is urgent data

12 3: Transport Layer3b-12 Out-of-band data r URG is not really out-of-band data; Receiver must continue to read byte stream till reach end of urgent data r If multiple urgent segments received, first urgent mark is lost; just one urgent pointer r How to get out-of-band data if need it? m Seperate TCP connection

13 3: Transport Layer3b-13 URG r How helpful is this? r Telnet and Rlogin use URG when user types the interrupt key; FTP uses when user aborts a file transfer r Is this worth a whole header field and a flag? r Doesn’t help that implementations vary in how they interpret the urgent pointer (point to last byte in urgent data or byte just past the last byte of urgent data)

14 3: Transport Layer3b-14 TCP Header: PSH r Intention: use to indicate not to leave the data in a TCP buffer waiting for more data before it is sent m In practice, programming interface rarely allows application to specify m Instead TCP will set if this segment used all the data in its send buffer r Receiver is supposed to interpret as deliver to application immediately; most TCP/IP implementations don’t delay deliver in the first place

15 3: Transport Layer3b-15 TCP Header: Data boundaries? r In general with UDP, application write of X bytes data results in a UDP datagram with X bytes of data – not so with TCP r In TCP, the stream of bytes coming from an application is broken at arbitrary points into the “best” size chunks to send r Sender may write 10 bytes then 15 then 30 but this is not in general visible to the receiver

16 3: Transport Layer3b-16 Record Boundaries r Could try to use URG and PSH to indicate record boundaries m socket interface does not notify app that push bit or urgent bit is on though! r In need record boundaries, applications must always insert their own by indicating it in the data (ie. Data is record len + record format)

17 3: Transport Layer3b-17 TCP Header: Header Length r Header Length (4 bits) m needed because options field make header variable length m Expressed in number of 32 bit words m 4 bits field => 4*16 = 60 bytes; 20 bytes of normal gives 40 bytes possible of options

18 3: Transport Layer3b-18 TCP Header: Common Options r Maximum Segment Size Option can be set in SYN packets r Options used to extend and test TCP r Each option is: m 1 byte of option kind m 1 byte of option length (except for kind = 0 for end of options and kind =1 for no operation) r Other options m window scale factor: if don’t want to be limited to 2 16 bytes in receiver advertised window) m timestamp option: if 32 bit sequence number space will wrap in MSL; add 32 bit timestamp to distinguish between two segments with the same sequence number

19 3: Transport Layer3b-19 TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments r initialize TCP variables: m seq. #s  buffers, flow control info (e.g. RcvWindow ) r client: connection initiator Socket clientSocket = new Socket("hostname","port number"); r server: contacted by client Socket connectionSocket = welcomeSocket.accept(); Three way handshake: Step 1: client end system sends TCP SYN control segment to server m specifies initial seq # Step 2: server end system receives SYN, replies with SYNACK control segment m ACKs received SYN m allocates buffers m specifies server-> receiver initial seq. # Step 3: client acknowledges servers initial seq. #

20 3: Transport Layer3b-20 Three-Way Handshake Active participant (client) Passive participant (server) SYN, SequenceNum = x SYN + ACK, SequenceNum = y, ACK, Acknowledgment = y + 1 Acknowledgment = x + 1 Note: SYNs take up a sequence number even though no data bytes

21 3: Transport Layer3b-21 Connection Establishment r Both data channels opened at once r Three-way handshake used to agree on a set of parameters for this communication channel m Initial sequence number for both sides m Receiver advertised window size for both sides m Optionally, Maximum Segment Size (MSS) for each side; if not specified MSS of 536 bytes is assumed to fit into 576 byte datagram

22 3: Transport Layer3b-22 Initial Sequence Numbers r Chosen at random in the sequence number space? r Well not really randomly; intention of RFC is for initial sequence numbers to change over time m 32 bit counter incrementing every 4 microseconds r Vary initial sequence number to avoid packets that are delayed in network from being delivered later and interpreted as a part of a newly established connection

23 3: Transport Layer3b-23 Special Case: Timeout of SYN r Client will send three SYN messages m Increasing amount of time between them (ex. 5.8 seconds after first, 24 seconds after second) r If now responding SYNACK will terminate

24 3: Transport Layer3b-24 Special Case: Simultaneous active SYNs r Possible but improbable for two ends to generate SYNs for the same connection at the same time r SYNs cross in the network r Both reply with SYNACK and connection is established

25 3: Transport Layer3b-25 Connection Termination r Each side of the bi-directional connection may be closed independently m 4 messages: FIN message and ACK of that FIN in each direction r Each side closes the data channel it can send on r One side can be closed and data can continue to flow in the other direction, but not usually r FINs consume sequence numbers like SYNs

26 3: Transport Layer3b-26 TCP Connection Management (cont.) Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. client FIN server ACK FIN close closed timed wait

27 3: Transport Layer3b-27 TCP Connection Management (cont.) Step 3: client receives FIN, replies with ACK. m Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. Note: with small modification, can handly simultaneous FINs. client FIN server ACK FIN closing closed timed wait closed

28 3: Transport Layer3b-28 TCP Connection Management (cont) TCP client lifecycle TCP server lifecycle

29 3: Transport Layer3b-29 CLOSED LISTEN SYN_RCVDSYN_SENT ESTABLISHED: data transfer! CLOSE_WAIT LAST_ACKCLOSING TIME_WAIT FIN_WAIT_2 FIN_WAIT_1 Passive openClose Send/SYN SYN/SYN + ACK /ACK /SYN + ACK ACK Close/FIN FIN/ACKClose/FIN FIN/ACK ACK + FIN/ACK Timeout after two segment lifetimes FIN/ACK ACK Close/FIN Close CLOSED Active open /SYN SYN/ SYN+ACK/ Typical Client Transitions Typical Server Transitions

30 3: Transport Layer3b-30 Netstat r netstat –a –n m Shows open connections in various states m Example: Active Connections ProtoLocalAddrForeignAddr State TCP : :0 LISTENING TCP : :80CLOSE_WAIT TCP : :22ESTABLISHED UDP :1070*:*

31 3: Transport Layer3b-31 Time Wait State r Wait 2 times Maximum Segment Lifetime (2 MSL) m Provides protection against delayed segments from an earlier incarnation of a connection being interpreted as for a new connection r Maximum time segment can exist in the network before being discarded m Time-To-Live field in IP is expressed in terms of hops not time m TCP estimates it as 2 minutes r During this time, combination of client IP and port, server IP and port cannot be reused m Some implementations say local port cannot be reused while it is involved in time wait state

32 3: Transport Layer3b-32 RST r RST flag r Abortive release of a connection rather than the orderly release with FINs r We saw client browser ended its connections that way - not good form

33 3: Transport Layer3b-33 Data Transfer (Simplified One- Way) Sender Data(SequenceNum) Acknowledgment + AdvertisedWindow Receiver

34 3: Transport Layer3b-34 TCP Sender: Simplified State Machine simplified sender, assuming wait for event wait for event event: data received from application above event: timer timeout for segment with seq # y event: ACK received, with ACK # y create, send segment retransmit segment ACK processing one way data transfer no flow, congestion control

35 3: Transport Layer3b-35 TCP Sender: Simplified Pseudo- code 00 sendbase = initial_sequence number 01 nextseqnum = initial_sequence number loop (forever) { 04 switch(event) 05 event: data received from application above 06 create TCP segment with sequence number nextseqnum 07 start timer for segment nextseqnum 08 pass segment to IP 09 nextseqnum = nextseqnum + length(data) 10 event: timer timeout for segment with sequence number y 11 retransmit segment with sequence number y 12 compue new timeout interval for segment y 13 restart timer for sequence number y 14 event: ACK received, with ACK field value of y 15 if (y > sendbase) { /* cumulative ACK of all data up to y */ 16 cancel all timers for segments with sequence numbers < y 17 sendbase = y 18 } 19 else { /* a duplicate ACK for already ACKed segment */ 20 increment number of duplicate ACKs received for y 21 if (number of duplicate ACKS received for y == 3) { 22 /* TCP fast retransmit */ 23 resend segment with sequence number y 24 restart timer for segment y 25 } 26 } /* end of loop forever */ Simplified TCP sender

36 3: Transport Layer3b-36 TCP Receiver: ACK generation [RFC 1122, RFC 2581] Event in-order segment arrival, no gaps, everything else already ACKed in-order segment arrival, no gaps, one delayed ACK pending out-of-order segment arrival higher-than-expect seq. # gap detected arrival of segment that partially or completely fills gap TCP Receiver action delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK immediately send single cumulative ACK send duplicate ACK, indicating seq. # of next expected byte (sender can use as hint of selective repeat) immediate ACK if segment starts at lower end of gap


Download ppt "3: Transport Layer3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum."

Similar presentations


Ads by Google