CS 5520/ECE 5590NA: Network Architecture I Spring 2008 Lecture 13: UDP and TCP Most recent lectures discussed mechanisms to make better use of the IP address space, Internet control messages, and layering principles in more detail. This lecture provides an overview of the two main transport layer protocols, UDP and TCP. Chapter 11 - User Datagram Protocol (UDP) I. Transport Layer Protocols The purpose of this class is not to study transport layer protocols in detail. Left to CS 521, especially from an analysis standpoint. These protocols are used extensively, however, and basic knowledge of them will be important as other topics are discussed for the remainder of the semester. Two protocols are of interest. 1. User Datagram Protocol (UDP) 2. Transmission Control Protocol (TCP) II. User Datagram Protocol (UDP) IP only specifies the destination host for a datagram. But each machine contains multiple abstract destination points called protocol ports. Identified by positive integers. The local operating system provides an interface mechanism to those ports. In general, ports are buffered. Packets for a particular port are buffered. A process extracts packets when it is ready. The sender needs to know both the IP address and the port number. Lecture 13, Page 1 of 16
The User Datagram Protocol (UDP) provides a message format to also indicate port numbers. As a transport protocol sent in the IP datagram payload. Port numbers can be indicated for both source and destination. But only for the source port if it is a port to which replies are to be sent. UDP provides no additional reliability to IP. It is unreliable. Delivery is not assured. It is connectionless. Packets are sent individually. So, for what uses might UDP be a good choice? Note that much more overhead would need to be added to a transport protocol (as with TCP) to provide reliable delivery (acknowledgements, retransmissions, congestion control, handshaking to setup and tear down sessions, etc.). Control messages Audio/video where there is no time to wait for retransmissions. Instant messaging. UDP only provides two functions. 1. Port numbers 2. A checksum that checks for errors in the UDP header and UDP payload. The raw data from the application is transferred in the UDP payload. Checksum computation uses the same one's complement method as in the IP header. Lecture 13, Page 2 of 16
Checksum does not have to be used. - All 0 s in the checksum field says the checksum is not to be used. UDP provides an interface for a user (or application) to send a simple datagram. Port numbers Hence, the name User Datagram Protocol. Each application program must negotiate with the operating system to obtain a protocol port and port number. Two computers need to agree on and know each other s port numbers before they can interoperate. For example, when computer A wishes to obtain a file from computer B, it needs to know the port that the file transfer program on computer B uses. Some port numbers are used on a regular basis. Called well-known port assignments. Below are some of the UDP port numbers. TCP has its own set of well-known port assignments. UDP and TCP use the same numbers for services that are accessible from both UDP and TCP. Lecture 13, Page 3 of 16
Here are some of the TCP port numbers. Chapter 12 - Reliable Stream Transport Service (TCP) III. The Need for Reliable Stream Delivery Without a service for reliable delivery, each application would have to provide it. Error detection Recovery Lecture 13, Page 4 of 16
Five properties of the Reliable Delivery Service provided by TCP/IP 1. Stream Orientation Individual packets are usually part of a larger unit of data. Data is sent as a stream and is delivered in exactly the same order to the receiving application. - The receiving service must put packets back in order before giving them to the application. 2. Virtual Circuit Connection Before transfer starts, sending and receiving programs establish a connection, a virtual, logical connection with no resources reserved. So the endpoints can cooperate in providing reliability. 3. Buffered Transfer Applications send data to the service. The sending service packages the data into packets. - Waits until enough data has been received from the sending application. - Too little data in a packet is wasteful. - Because a high proportion of the packet would be the header. - Data is kept in buffers until it is sent. Sometimes applications will wish to force data to be sent immediately. - A push mechanism. - Does not wait to fill buffers. - This is necessary for real-time applications, to make sure data arrives within a required amount of time. 4. Unstructured stream Does not follow defined data structures. Data is just bytes. - For simplicity sake. 5. Full Duplex Communication Two independent streams can be flowing in opposite directions. Can add control information to the data sent in the reverse direction (piggybacking). Lecture 13, Page 5 of 16
Providing Reliability How can the protocol software provide reliable transfer if the underlying communication system offers only unreliable delivery? One approach for reliable protocols is to use positive acknowledgement with retransmission. Recipient sends acknowledgements (ACK's). Positive acknowledgements indicate which packets have been received. As compared to negative acknowledgements. - Sent when a packet is not received. Sender keeps a timer - Retransmits if a timer expires before an expected ACK is received. - Time proceeds downward as in the following diagram. Sequence numbers are used. - Duplicates can arise. - Such as when retransmissions occur and the original packets that are still in transit also arrive at the destination. - Sequence numbers allow receivers to discard duplicates, reassemble data streams, and let senders know what to send next. Lecture 13, Page 6 of 16
Sliding Windows A simple positive acknowledgement protocol wastes substantial time. Send a packet Then senders sit idle until an acknowledgement for that packet is received. Sometimes called a stop and wait protocol. Speed of light limitations cause a minimum delay that cannot be avoided. - Plus additional delays are incurred for service times of packets, packet processing times, and queueing delays. A sliding window mechanism allows multiple packets to be sent while awaiting ACK's. Here eight packets are sent before any acknowledgements are required. Once the acknowledgement for packet #1 is received, the window "slides". - Packet #9 can now be sent. - The lowest numbered packet in the window is the one which must be acknowledged. Lecture 13, Page 7 of 16
Example: 155 Mbps fiber optic link 1000 km long 1000 octet segments (8000 bits) Say the pulses travel along the link at 0.1c (3 x 10 7 m/s) 1000 km => 33.3 msec. With a window size of 8000 (one segment): Send a packet, wait for an acknowledgement. Time to clock packet onto the link = (8000 bits)/(622 Mbps) = 0.013 msec Propagation delay to the end = 33.333 msec Propagation delay back = 33.333 msec Total minimum delay = 66.679 msec Can send 8000 bits every 66.68 msec => 120.0 kbps on a 155 Mbps link! To get 155 Mbps, we want to send x bits every 66.67 msec (x/66.67e-3) = 155e6 => x = 10.3 Mbits Window size is 10.3 Mbits (1292 segments) So, we send 1292 segments before any acknowledgements are expected. Otherwise, we sit idle part of the time. Lecture 13, Page 8 of 16
IV. Transmission Control Protocol (TCP) A major piece of the TCP/IP protocol suite. Provides many important specifications. How TCP distinguishes among multiple destinations on a given machine (ports). Formats of data and acknowledgements. Procedures to follow for ensuring data arrives correctly. Recovery from lost or duplicated packets. Establishment and ending of connections. Response to congestion. TCP uses the concept of a "connection." A connection is defined by two endpoints and their ports. Like with UDP. Can have multiple connections to a destination port. From different sources. Since a connection is a source-destination pair, one can have the same destination from multiple sources. Well known ports can have many connections. How could a host have multiple connections to the same destination and destination port? Use different source ports. TCP divides data into segments. To be placed into IP. That are then placed into physical network. Lecture 13, Page 9 of 16
TCP uses sliding windows 1. For efficient transmission To avoid overrunning an endpoint. An endpoint advertises how much buffer space it has available to receive data. - Called the receiver advertisement. The sender establishes a sliding window to constrain itself to send only what the receiver can handle. 2. For flow control. To limit the amount of data that is sent to the amount that the intermediate routers can handle. - When congestion is present. Called the congestion window. Sizes of sliding windows adapt to changing conditions. The sender uses the smaller of the two values (receiver advertisement and congestion window) for its window size. Windows sizes can and will change with time. TCP Segment Format We will not study this in detail. The TCP Header includes a checksum as did UDP for the entire segment. Lecture 13, Page 10 of 16
The TCP Header includes the ACKNOWLEDGEMENT NUMBER. The receiver tells the. In terms of an octet number (not segment number). So this tells the source what group of data has been received. An ACK can be sent to cover multiple packets that have been received. - For example, from the sliding window figure above. - An ACK can be sent to indicate that the first octet of packet #5 is the next octet that is expected. - Covers packets #1 through #4. This scheme is cumulative because it reports how much of the stream has been accumulated successfully. Advantages Easy to generate Unambiguous Lost acknowledgements do not force retransmission next ACK will cover a missed ACK. Disadvantage Do not know about all successful transmissions, only those in a continuous block. There is no way for the receiver to tell the sender about other segments that have also been received. Lecture 13, Page 11 of 16
A sender can respond in two different ways after a timeout. Keeping in mind that it now needs to send the segment that includes the octet expected by the receiver. 1. Retransmit the single segment that was not received. - Must stop and wait for the acknowledgement for that segment. - It may only be able to slide the window by one packet when the ACK is received if others were also not received. - But if that was the only packet that was missing, then an ACK may be received for a large set of received packets. - If other segments also need to be resent, this approach adds lots of delay. 2. Retransmit the complete window. - May be very wasteful if only a few retransmitted segments are needed. Ideally, a selective repeat function would be used. It would tell the exact segments that need to be retransmitted. But this would require a negative acknowledgement approach. - That would tell what was not acknowledged. - And positive acknowledgements would still be needed, to be sure that data has been received successfully. The accepted standard is to follow the first approach. Only send the one segment that is needed at the time. Assumes fairly low incidence of data loss. - Might need to use a different environment in a lossy environment, like wireless. A Selective Acknowledgement (SACK) extension was developed. RFC 2018. Allows a receiver to add extra data to a TCP segment - Will list all blocks of data that have been received properly. - Still is a positive ACK approach. - Then the sender can retransmit those that are missing (after timeout). Lecture 13, Page 12 of 16
Explicit Congestion Notification (ECN) Here IP routers use the two unused bits not used by Diffserv in the TYPE OF SERVICE field in the IP header. - Routers set those bits if congestion occurs as they send packets to the destination. Then the destination sends a message back to the source using bits in the TCP header to indicate that congestion. TCP has 2 very important performance control parameters. Timeout. To know when to retransmit if no ACK is received. Congestion window size. To know how much data to send. Both should adapt to changing network conditions. Both are subjects of extensive research. Will be studied in detail in CS 521. Timeout Too large Hurts throughput, too much unnecessary waiting. Too small Injects unnecessary retransmissions into the network. Retransmission can aggravate congestion that has already delayed packets. Lecture 13, Page 13 of 16
Even more retransmissions could occur as previous retransmissions made congestion worse. Could result in congestion collapse. Window Sizes Reduction in window sizes will reduce congestion. By slowing down injection of traffic into the network. And will be very helpful if all TCP sources implement this behavior. The TCP standard recommends two techniques. Multiplicative decrease. - Cut the congestion window in half each time a segment is lost. - Causes quick reduction in traffic rates. - Transmission rates are effectively cut in half. - This happens every time a timeout occurs. Additive increase - Not multiplicative increase because that would cause wild oscillations. - Use additive increase - Each acknowledgement allows window size slowly to increase by one segment size. This was proposed by Jacobsen in 1988 to correct congestion collapse problems in the Internet and has become famous and known as AIMD (Additive Increase, Multiplicative Decrease). Slow-start Start the window size at one immediately after a timeout. Increase exponentially. Up until it reaches ½ of the previous window size for multiplicative decrease. Lecture 13, Page 14 of 16
Illustration of the behavior from a textbook from Tanenbaum: At the timeout, the threshold is reduced from 40 to 20 multiplicative decrease. - When the timeout occurs, slow start happens where the window size is reduced to 1. - Then it increases exponentially by a factor of 2 (1, 2, 4, 8, etc.) up to the threshold. - But to go above the threshold, it only increases by one for each ACK additive increase. - So, the above plot is not just AIMD, but also slow start. Why use slow start? To adapt if congestion is very bad TCP can vary its rates quite substantially. Many proposals have been made to stabilize this behavior. One idea: Not using slow start. Some of the most popular TCP variants have been named after cities in Nevada TCP Tahoe, TCP Reno, and TCP Vegas. - TCP Reno uses for retransmission if three ACK s Lecture 13, Page 15 of 16
arrive that still ask for the same segment, retransmit before waiting for a timeout. Multiplicative decrease and additive increase have improved TCP performance by factors from 2 to 10 times. By reducing problems with congestion collapse. Early browsers used to show this change in rates by the TCP sources. Note that UDP does not perform these congestion control adaptations. TCP Friendly Rate Control has been proposed for UDP, so that UDP uses packet loss indications to vary its sending rate. Tail Drop and RED Now, with fuller understanding, we can see more clearly the potential problem of global synchronization with TCP. And the value of AQM for TCP traffic. 100% Queue Utilization Time 3 Traffic Flows Start at Different Times Tail Drop Summary of TCP and UDP Port numbers. Another Traffic Flow Starts at this Point UDP does nothing else except for an overall checksum. TCP implements reliable communication. Positive acknowledgements, sequence numbers, sliding windows TCP uses adaptive timeouts and window sizes to adapt to congestion. Using slow start and AIMD. AQM can be used with TCP to avoid synchronized responses by many sources. Next lecture: Internet routing protocols (IS-IS, RIP, OSPF, BGP). Lecture 13, Page 16 of 16