230 likes | 423 Views
Transport Layer - TCP. TCP: A Closer Look. Browser does not send HTTP-Request-PDUs directly to the webserver application The application layer programs are not physically connected Browser sends HTTP-Request-PDU to the user PC’s transport layer process for delivery. Browser. HTTP-Request-PDU.
E N D
TCP: A Closer Look • Browser does not send HTTP-Request-PDUs directly to the webserver application • The application layer programs are not physically connected • Browser sends HTTP-Request-PDU to the user PC’s transport layer process for delivery Browser HTTP-Request-PDU Transport Process
TCP: A Closer Look • Transport layer process stores the HTTP-Request-PDU Temporarily Browser Transport Process Transport Process
TCP: A Closer Look • User PC transport process opens a connection to the webserver transport layer process • This connection can be used to send several TCP-PDUs to handle a single HTTP request-response cycle in HTTP 1.0 Browser Transport Process Transport Process
TCP/IP: A Closer Look • The TCP header has a flags field with 1-bit SYN, ACK, and FIN fields. • SYN bit set to 1 to request connection • ACK bit set to 1 to acknowledge a received TCP-PDU • FIN bit set to 1 to inform of closure TCP-Header Flags Field
TCP: A Closer Look • Opening a connection takes 3 TCP-PDUs • Second message asks to open a connection and also acknowledges the first SYN message User PC Transport Process SYN Webserver Transport Process SYN, ACK ACK
TCP: A Closer Look • Sending the HTTP-Request-PDU requires 2 TCP-PDUs • Sends HTTP-Request-PDU in data field of a TCP-PDU • Receives an ACK TCP-PDU User PC Transport Process Webserver Transport Process TCP-PDU containing HTTP-Request-PDU ACK
Delivering the HTTP-Response-PDU • Transport layer process on the webserver receives the TCP-PDU delivering the HTTP-Request-PDU • The transport process on the webserver passes the HTTP-Request-PDU in the TCP-PDU data field to the webserver application program Webserver Application HTTP-Request-PDU Transport Process
Delivering the HTTP-Response-PDU • Webserver application creates the HTTP-Response-PDU • Webserver application passes the HTTP-Response-PDU to the webserver transport layer process for delivery to the user PC transport layer process Webserver Application HTTP-Response-PDU Transport Process
TCP: A Closer Look • Fragmentation of HTTP-Response-PDU • HTTP-Response-PDUs usually are large files • TCP-PDUs are limited to a certain maximum segment size (MSS) • Often only 512 bytes • Typical HTTP-Response-PDU must be fragmented into multiple TCP-PDUs containing parts of the HTTP-response-PDU HTTP-Response-PDU TCP-PDU-1 TCP-PDU-2 TCP-PDU-3
A Closer Look at TCP • Sample Fragmentation Calculation • 20 KB Size of HTTP-Response-PDU. Varies. 20KB is only an example • 20,480 octets 1,024 bytes per KB • 550 octets Maximum segment size (MSS). Varies. 550 is only an example. • 530 octets Maximum data per TCP-PDU (Header has 20 octets) • 38.6 Size of HTTP-Response PDU divided by maximum data/PDU • 39 Number of TCP-PDUs needed. (round up)
TCP: A Closer Look • Sending the HTTP-Response-PDU takes many TCP-PDUs • Each is acknowledged Response TCP-PDU 1 User PC Transport Process Webserver Transport Process ACK for 1 Response TCP-PDU 2 ACK for 2
TCP: A Closer Look • Closing the Connection takes 4 TCP-PDUs • Initiated by the webserver transport process when it finishes sending the last HTTP-Response-PDU fragment. FIN User PC Transport Process Webserver Transport Process ACK FIN ACK
TCP Connections: Recap • For EACH HTTP request-response cycle… • 3 TCP-PDUs to open the connection • 2 TCP-PDU to send the HTTP request and get an acknowledgement • N data TCP-PDUs to send the HTTP-Response-PDU and get acknowledgements • 4 TCP-PDUs to close the connection • For EACH HTTP request-response cycle at the application layer
TCP: Error Handling • TCP is reliable--it does error correction • Each TCP-PDU has a sequence number that increases with each TCP-PDU a transport process sends • ACKs acknowledge a specific TCP-PDU in the sequence • If a TCP-PDU is not acknowledged, the other side retransmits it after awhile • This adds TCP-PDUs beyond the ones we have seen
TCP: Why Connections? • Opens, closes, and ACKs create overhead, so undesirable • Why do it? • Allows sequence numbers, so that errors can be handled easily • Creates sequence numbers, so that fragmentation can be handled easily • Overall, TCP is a high-overhead, highly reliable transport layer protocol that catches any errors at lower layers, giving “clean” service to the application programs
TCP-Header • Fields in TCP Header • Shows 32 bits on each row (0 to 31) • Note: start with zero Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • Port number designates and application program • E.g, well-known port number for HTTP is 80 • Other applications also have well-known port numbers Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • Sequence and Acknowledgement Numbers • To be sure each TCP-PDU has arrived • To place arriving TCP-PDUs in order • To allow a specific TCP-PDU to be acknowledged Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • Flags • 1 bit each • SYN, FIN, ACK are three of the flags Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • Window Size • Number of bytes other side can send beyond the TCP-PDU being acknowledged • Initially set to allow one TCP-PDU (slow start) Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • TCP Checksum • To check for an error anywhere in the whole TCP-PDU, including the data field Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD
TCP-Header • Options • Rarely used • PAD set to bring options to 32-bit boundary New: Not in Book Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) Options (if any) PAD