770 likes | 783 Views
Understand the differences between UDP and TCP, the two major transport protocols in the internet, and their functionality for reliable message delivery and flow control.
E N D
End-to-End Protocols User Datagram Protocol (UDP) Transmission Control Protocol(TCP)
Underlying Best-Effort Network • Drops messages • Re-orders messages • Delivers duplicate copies of a given message • Limits messages to some finite size • Delivers messages after an arbitrarily long delay
Common End-to-End Services • Guarantee message delivery • Deliver messages in the same order they are sent • Deliver at most one copy of each message • Support arbitrarily large messages • Support synchronization • Allow the receiver to flow control the sender • Support multiple application processes on each host
Transport Protocol • All end-to-end services provided by transport protocol • Separate layer of protocol stack • Conceptually between • Applications layer • IP layer
Terminology • IP • Provides computer-to-computer (or node to node) communication in two different networks • Source and destination addresses are computers • Called machine-to-machine • Transport protocols • Provide application-to-application communication • Need extended addressing mechanism to identify applications (port numbers) • Called end-to-end
Transport Protocol Functionality • Identify sending and receiving applications (by using port numbers) • Optionally provide • Reliability • Flow control • Congestion control • Note: not all transport protocols provide above facilities
Two Transport Protocols Available • Transmission Control Protocol (TCP) • User Datagram Protocol (UDP) • Major differences • Interface to applications • Functionality
User Datagram Protocol (UDP) • Provides unreliable transfer • Requires minimal • Overhead • Computation • Communication • Best for LAN applications (because LAN is a very reliable environment) • Used to support audio/video streaming applications or similar applications that does not require absolute reliability
UDP Details • Connectionless service paradigm • Message-oriented interface • Each message encapsulated in IP datagram • UDP header identifies • Sending application • Receiving application
UDP Detail (cont’d) • Included in TCP/IP suite • Supports many protocol ports • Transports a message from one machine to another • Does not use acknowledgements • Does not order incoming messages • Does not do flow control • Application program is responsible to handle all problems such as loss, duplication, delay, out of order delivery, etc.
Simple Demultiplexor (UDP) 0 16 31 SrcPort DstPort • Adds multiplexing • No flow control • Endpoints identified by ports • servers have well-known ports • see /etc/services on Unix • Header format • Optional checksum • pseudo header + UDP header + data • Source port is optional (zero, if not used) • Length includes all fields (Minimum value is 8) Length Checksum Data
UDP Checksum • Optional: checksum can be used to verify delivery of datagram to a correction destination • Pseudoheader • Consists of three fields from IP header: protocol number, source IP address, and destination IP addressplus the UDP length field • UDP uses the same checksum algorithm as IP • Note: UDP length is included twice in the calculation
UDP Pseudo-Header • Used to verify that UDP has reached its destination • Used during UDP checksum computation
UDP Protocol Layering • Operates in the same layer as TCP Application Transport Internet Network Interface Physical
UDP Encapsulation • Entire UDP message is encapsulated in an IP datagram UDP-Hdr Data Area IP-Hdr IP Data Area Frame-Hdr Frame Data Area
Note: The IP layer is responsible only for transferring data between a pair of hosts on an internet, while UDP layer is responsible only for differentiating among multiple sources or destinations within one host.
UDP Message Queue Application Application Application process process process Ports Queues Packets demultiplexed UDP Packets arrive
Identifying An Application • Cannot extend IP address: No unused bits • Cannot use OS-dependent quantity: Process ID, task number or Job name • Must work on all computer systems • Invent new abstraction • Used only with TCP/IP • Identifies sender and receiver unambiguously • Technique • Each application assigned unique integer • Called protocol port number
Protocol Ports • Server • Follows standard • Always uses same port number • Uses lower port numbers • Client • Obtains unused port from protocol software • Uses higher port numbers
Protocol Port Example • Domain name server application is assigned port 53 • Application using DNS obtains port 28900 • UDP datagram sent from application to DNS server has • Source port number 28900 • Destination port number 53 • When DNS server replies, UDP datagram has • Source port number 53 • Destination port number 28900
Transmission Control Protocol (TCP) • Major transport protocol used in Internet • Heavily used • Completely reliable transfer
TCP Features • Connection-oriented service • Point-to-point • Full-duplex communication • Stream interface • Stream divided into segments for transmission • Each segment encapsulated in IP datagram • Uses protocol ports to identify applications
Application process Application process W rite Read bytes bytes … … TCP TCP Send buffer Receive buffer … Segment Segment Segment T ransmit segments TCP Overview • Full duplex • Flow control: keep sender from overrunning receiver • Congestion control: keep sender from overrunning network • Connection-oriented • Byte-stream • app writes bytes • TCP sends segments • app reads bytes
TCP Feature Summary TCP provides a completely reliable (no data duplication or loss), connection-oriented, full-duplex stream transport service that allows two application programs to form a connection, send data in either direction, and then terminate the connection.
Data Link Versus Transport • Potentially connects many different hosts • need explicit connection establishment and termination • Potentially different RTT • need adaptive timeout mechanism • Potentially long delay in network • need to be prepared for arrival of very old packets • Potentially different capacity at destination • need to accommodate different node capacity • Potentially different network capacity • need to be prepared for network congestion
Apparent Contradiction • IP offers best-effort (unreliable) delivery • TCP uses IP • TCP provides completely reliable transfer • How is this possible?
Achieving Reliability • Reliable connection startup • Reliable data transmission • Graceful connection shutdown
Reliable Data Transmission • Positive acknowledgement • Receiver returns short message when data arrives • Called acknowledgement • Retransmission • Sender starts timer whenever message is transmitted • If timer expires before acknowledgement arrives, sender retransmits message
How Long Should TCP Wait Before Retransmitting? • Time for acknowledgement to arrive depends on • Distance to destination • Current traffic conditions • Multiple connections can be open simultaneously • Traffic conditions change rapidly
Important Point The delay is required for data to reach a destination and an acknowledgement to return depends on traffic in the internet as well as the distance to the destination. Because it allows multiple application programs to communicate with multiple destinations concurrently, TCP must handle a variety of delays that can change rapidly.
Solving Retransmission Problem • Keep estimate of roundtrip time on each connection • Use current estimate to set retransmission timer • Known as adaptive retransmission • Key to TCP's success
TCP Flow Control • Receiver • Advertises available buffer space • Called window • Sender • Can send up to entire window before ack arrives
Window Advertisement • Each acknowledgement carries new window information • Called window advertisement • Can be zero (called closed window) • Interpretation: I have received up through X, and can take Y more octets
Startup And Shutdown • Connection startup • Must be reliable • Connection shutdown • Must be graceful • Difficult
Why Startup/Shutdown Difficult • Segments can be • Lost • Duplicated • Delayed • Delivered out of order • Either side can crash • Either side can reboot • Need to avoid duplicate "shutdown" message from affecting later connection
TCP's Startup/Shutdown Solution • Uses three-message exchange • Known as 3-way handshake • Necessary and sufficient for • Unambiguous, reliable startup • Unambiguous, graceful shutdown • SYN used for startup • FIN used for shutdown
Connection Establishment and Termination Active participant Passive participant (client) (server) SYN, SequenceNum = x , y 1 + SYN + ACK, SequenceNum = x Acknowledgment = ACK, Acknowledgment = y + 1
Illustration: Closing a connection Host 1 . . Host 2 Send FIN + ACK Receive FIN+ACK Send FIN +ACK Receive FIN+ACK Send ACK Receive ACK
All TCP segments have same format Data Acknowledgement SYN (startup) FIN (shutdown) Segment divided into two parts Header Payload area (zero or more bytes of data) Header contains protocol port numbers to identify sending and receiving applications Bits to specify items such as SYN FIN ACK Fields for window advertisement, acknowledgement, etc. TCP Segment Format
Sequence number specifies where in stream data belongs Acknowledgement fieldspecifies the sequence number of first byte in stream data to be received next (implying all previous bytes received correctly) Few segments contain options TCP Segment Format
Data (SequenceNum) Sender Receiver Acknowledgment + AdvertisedWindow Segment Format (cont) • Each connection identified with 4-tuple: • (SrcPort, SrcIPAddr, DsrPort, DstIPAddr) • Sliding window + flow control • acknowledgment, SequenceNum, AdvertisedWinow • Flags (6 bits) • SYN, FIN, RESET, PUSH, URG, ACK • Checksum • pseudo header + TCP header + data • HdrLen - Header length in 32-bit words
Flag/Code Bits in TCP Segment • 6-bit field • Tells how to interpret other fields in the header • RST bit set to abort the connection during unexpected situation (ex. Arrival of an unexpected segment )
Out of Band Data • Data to be sent immediately • Example: interrupting or aborting the program in a remote login session. • TCP option: specify data as urgent • Set URG code bit • Set the urgent pointer (UrgPtr) specifying where urgent data ends in the segment (Urgent data is contained at the front the segment body) • TCP tells the application to return to normal mode after consumption of urgent data • PUSH flag to tell receiving TCP to notify the receiving process about the PUSH operation
TCP Checksum Computation • TCP prepends a pseudo header to the segment • Appends enough zero bits to make the segment a multiple of 16 bits • Computes 16-bit checksum over the entire result • Uses 16-bit arithmetic • Takes one's complement of the one's complement sum • Notes: • TCP does not count the pseudo header or padding in the segment length • TCP does not transmit the pseudo header or padding • TCP assumes the checksum field itself is zero before computation
Format of Pseudoheader used in TCP computation • PROTOCOL field - for IP datagrams, it is 6 • TCP LENGTH field - total length of TCP segment including TCP header
Purpose of Pseudo Header • To verify the segment has reached its correct destination (Port number & destination IP address) • IP passes the source and destination IP addresses to the receiving TCP from the datagram • Receiving TCP performs the same computation
Timeout and Retransmission • Note:TCP software must accommodate both the vast differences in time required to reach various destinations and the changes in time required to reach a given destination as traffic load varies. • Uses an adaptive retransmission algorithm • Records the time at which each segment is sent • Records the time at which an acknowledgement arrives for the segment • From the two times, it computes a sample round trip time (RTT).
Adaptive Formulas • From the sample RTT and old RTT, it estimates the round-trip time for next segment • Example: RTT = (a * Old_RTT) + ((1 - a)* New_Round_Trip_Sample where, 0 <a< 1 • Calculates a timeout value as a function of the current round trip estimate • Example Timeout = b * RTT where b > 1 (Recommended value for b is 2)
Accurate Measurement Of Round Trip Samples • TCP uses a cumulative acknowledgement • ACK refers to data received but not to the instance of a specific segment • In case of retransmission, both the original and the retransmitted segments carry exactly same data • TCP cannot relate an ACK with the original or the retransmitted segment • The problem is called acknowledgement ambiguity