Transport Layer Notes Performs a critical role in providing communication services directly to application processes running on different hosts. Critical function: Extending the network layer's delivery service between two end systems to a delivery service between two application layer processes running on end systems. Deals with the two most fundamental problems in computer networking: 1. How can two entities communicate reliability over a medium that is unreliable. 2. How can the transmission rate of the transport layer entities be controlled in order to avoid, or recover from, congestion within the network. A transport layer protocol provides for logical communication between application processes running on different hosts. Appears like a direct connection between them, so they can exchange messages, freeing them from the details of the physical infrastructure underneath. Transport layer protocols only exist in end systems, never in routers. Multiplexing and Demultiplexing Required for extending host-to-host delivery to process-to-process delivery by directing data from the network layer to a specific process. Uses a concept called a socket for delivery. So the delivery is not directly to an application process but to an intermediate socket. 1. Each transport layer segment has a set of header fields for this purpose. 2. At the receiving end, the transport layer examines these fields to identify the receiving socket and then directs the segment to that socket. (Demultiplexing) At the sending end, the transport layer gathers data chunks of the source host from different sockets, encapsulating each data chunk with header information to create segments and passes them to the network layer. (Multiplexing) Multiplexing requires: 1. that sockets have unique identifiers and 2. that each segment have special fields that indicate the socket to which the segment is to be delivered. The fields are a) source port number and b) destination port number Each port number is a 16 bit number ranging from 0 to 65,535. 0 1023 are reserved and called well-known port numbers. (RFC 1700) maintained on Unix systems at /etc/services Identify commonly used TCP and UDP default ports SMTP 25 RDP - 3389 HTTP 80 SSH - 22 HTTPS 443 DNS - 53 FTP - 20, 21 DHCP - 67, 68 TELNET - 23 IMAP - 143
User Datagram Protocol (UDP) (RFC 768) At the very least, the transport layer has to provide multiplexing/demultiplexing service in order to pass data between the network layer and the correct application layer process. UDP does this along with some minimal error checking. It basically adds nothing more to the network layer function. Activities: 1. accepts a message from an application process 2. attaches source and destination port numbers fields 3. adds checksum results 4. passes the resulting segment to the network layer 5. at the destination (if it arrives), UDP consults the destination port number for delivering the segment's data to the correct application process. Completely connectionless. Example: Domain Name Service (DNS) Why would a programmer choose UDP? (it is unreliable) Some applications are better suited for UDP for the following reasons: 1. No connection establishment does not introduce any delay to establish a connection. Application protocols that require speed may choose UDP, e.g., DNS 2. No connection state in contrast TCP maintains connection state which includes: a. receive and send buffers b. congestion control parameters c. sequence and acknowledgment number parameters UDP does not track any of this, thus a server using UDP can typically support many more active clients than a server using TCP. 3. Small packet header overhead. TCP has 20 bytes of header, UDP as 8 bytes. 4. Finer application level control over what data is sent and when. UDP will package data from the application process and immediately pass the segment to the network layer. TCP has a congestion control mechanism that throttles the transport layer TCP sender when one or more links between the source and destination hosts become excessively congested. Also will continue to send a segment of data until receipt of the segment has been acknowledged by the destination host. Real time applications require: minimum sending rate little delay in segment transmission can tolerate some data loss Applications can implement additional functionality needed beyond UDP's no-frills process-toprocess segment delivery service. UDP Segment Structure (RFC 768) Contains only four fields, each consisting of two bytes. Source port number Destination port number
Length length of the UDP segment including the header, in bytes Checksum used by receiving host to check whether errors have been introduced into the segment during transmission. Why does UDP offer a checksum function (since other layers also do this)? There is no guarantee that all the links between source and destination provide error checking. Note: UDP does nothing to recover from an error; it can discard or pass the data upwards with a warning. Transmission Control Protocol connection oriented because before one application process can begin to send data to another, the two processes must first, hand shake, i.e., they must send some preliminary segments to each other to establish the parameters of the ensuing data transfer. Both sides must initialize many TCP state variables associated with the TCP connection. This is not an end-to-end circuit, as in circuit switching, nor a virtual circuit. The connection state resides entirely in the two end system's memory buffers. No TCP state exists in the intermediate network elements since they do not contain a transport layer. TCP connections provide full duplex data transfer, i.e., application data can flow from A > B at the same time application data flows from B > A. TCP connections are also point-to-point, i.e., between a single sender and a single receiver. Multicasting (one-to-many) is not possible with TCP. How a TCP connection is established: 1. Client application process must inform the transport layer that it wants to establish a connection. Must provide both an IP address and a port number to identify the destination host and application process. 2. The Transport Layer establishes a TCP connection with the server/host: a) send a special TCP segment (no payload) b) server responds with a special TCP segment (no payload) c) client responds with a third special TCP segment (may contain a payload) Process is called three way handshake 3. Connection is established both hosts can now exchange data. a) Client > Server via socket Application data is sent to the connection's send buffer (created during the initial three way handshake). From time-to-time, TCP will grab chunks of data from this send buffer at its own convenience. The maximum amount of data that can be grabbed and placed in a segment is limited by the maximum segment size (MSS) which depends on the TCP implementation in a particular operating system; can often be configured by the administrator. Common values are 1500 bytes, 536 bytes, and 512 bytes. Note: MSS is the maximum amount of application layer data in the segment, NOT the maximum size of the TCP segment including headers. TCP pairs each chunk of data with a TCP header, thereby forming TCP segments. b) Server side Segments are placed in a receive buffer. The application process reads the stream
of data from this buffer. Conclusion: Each host allocates memory buffers, initializes variables and creates a socket. The TCP socket is identified by a four tuple (source IP and port, destination IP and port). Thus when a TCP segment arrives, the host uses all four values to direct (demultiplex) the segment to the appropriate socket. In contrast to UDP, two arriving TCP segments with different source IP addresses or port numbers will be directed to two different sockets. TCP server starts and listens to a welcoming socket TCP client generates a connection-establishment segment 1) a TCP segment with the destination port # the same as the welcoming socket 2) a special connection-establishment bit set in the TCP header (SYN) 3) a source port # generated by the client OS TCP server receives the incoming connection request and creates a connection socket TCP server notes four values 1) source port # 2) IP address of source host 3) destination port # 4) own IP address TCP client and server exchange data. TCP Segment Structure Composed of header fields and data (application layer message) limited by MSS size. Large files are broken down into multiple MSS sized chunks with the last chunk being less than MSS. Some application layer protocol never fill a MSS chunk, e.g., telnet. Since the TCP header must be at least 20 bytes, the smallest segment size is 21 bytes. Fields: 32 bit Sequence Number Since TCP views data as an unstructured, but ordered stream of bytes, this number represents the break points of each segment with the number beginning with the first byte in the segment. Use to arrange bytes back into order when all are collected on the end system. 32 bit Acknowledgment Number the receiving system removes the incoming segment sequence number and increments it by one to represent the sequence number of the next expected byte from the sender. 16 bit Receive Window used for flow control since it indicates the number of bytes that the receiver is willing to accept. 4 bit Header Length Field specifies the length of the TCP header in 32 bit words. The TCP header can be of variable length due to the TCP options field (which is typically empty so the length is usually 20 bytes.) Options Field used when the sender and receiver negotiate the MSS or as a window scaling factor for use in high speed networks. Time stamp option is also available. Flag Field contains six bits: 1. ACK bit used to indicate the value carried in the Acknowledgment field is valid 2. RST, SYN, FIN used for connection setup and tear down 3. PSH when set, an indication that the receiver should pass the data to the upper layer immediately 4. URG indicates that there is data in this segment that the sending side upper layer entity has marked as urgent. The location of the last byte of this urgent data by the 16 bit Urgent Data Pointer Field. TCP must inform the receiving side upper layer
exists and pass it a pointer to the end of the UDPF. (Typically never used!)