Two Transport Protocols Available Transmission Control Protocol (TCP) User Datagram Protocol (UDP) Provides unreliable transfer Requires minimal – Overhead – Computation – Communication Each message encapsulated in IP datagram
UDP User Datagram Protocol
Connectionless Receiver socket bind on X recvfrom Sender socket sendto Dst/X Sender socket sendto Dst/X Dst internet
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
Data Encapsulation
Protocol Port Example Domain name server application is assigned port 53 Application using DNS obtains port UDP datagram sent from application to DNS server has – Source port number – Destination port number 53 When DNS server replies, UDP datagram has – Source port number 53 – Destination port number 28900
UDP checksum checksum data(if any) source portdestination port UDP length source IP address destination IP address zeroprotocolUDP length pad (0) UDP pseudo header UDP header
Example DHCP server DHCP client A: reboot DHCP client B: winipcfg
TCP Transmission Control Protocol
TCP Transmission Control Protocol RFC-793 Connection-oriented Reliable Byte stream Dispatch data to socket
Connection-Oriented Receiver socket bind on X listen accept recv Sender socket bind connect Dst/X send Dst internet
Reliable Packet Checksum Sequence number Ack number Timeout Re-transmission
Relationship Between TCP And Other Protocols TCP on one computer uses IP to communicate with TCP on another computer IP offers best-effort (unreliable) delivery TCP uses IP TCP provides completely reliable transfer
Packet Format source portdestination port sequence number acknowledgement number window size checksumurgent pointer header len reser URGURG ACKACK PSHPSH RSTRST SYNSYN FINFIN
Packet format SYN : synchronize sequence numbers to initiate a connection URG : urgent pointer is valid ACK : ack number is valid PSH : receiver should pass this data to application ASAP RST : reset the connection FIN : finish sending data
Reliable Data Transmission Positive acknowledgment – Receiver returns short message when data arrives – Called acknowledgment Retransmission – Sender starts timer whenever message is transmitted – If timer expires before acknowledgment arrives, sender retransmits message
Illustration Of Retransmission
How Long Should TCP Wait Before Retransmitting? Time for acknowledgment to arrive depends on – Distance to destination – Current traffic conditions Multiple connections can be open simultaneously Traffic conditions change rapidly Solving The Retransmission Problem Keep estimate of round trip time on each connection Use current estimate to set retransmission timer Known as adaptive retransmission Key to TCP’s success
Illustration Of Adaptive Retransmission Timeout depends on current round-trip estimate
Illustration Of Window Advertisement
For protecting the misdelivery by IP, except to the entire segment, the checksum calculation need to plus the pseudoheader it calculates the 16-bit one’s complement addition of all 16-bit words in the pseudoheaer, TCP header, and TCP segment body Two options for the TCP –Window scale factor: windows field is multiplied by a 2 F, F <=14 –Timestamp: for deriving the round-trip time Checksum
Uses 3-way handshake to establish connection SYN used for startup Connection Establish SYN , win 4096 SYN , win 4096 ack ack , win 4096 MSS: max segment size SYN_SENT SYN_RCVD ESTABLISH CLOSED
Uses modified 3-way handshake to establish connection FIN used for shutdown Connection Termination FIN ack FIN ack ack ack FIN_WAIT_1 CLOSE_WAIT FIN_WAIT_2 TIME_WAIT LAST_ACK CLOSED ESTABLISH CLOSED
TCP State Machine CLOSED LISTEN ESTABLISHED CLOSING TIME_WAIT SYN_RCVDSYN_SENT CLOSE_WAIT LAST_ACK FIN_WAIT_1 FIN_WAIT_2 active OPEN snd SYN recv SYN, ACK snd ACK recv FIN snd ACK recv ACK AP Close snd FIN passive OPEN AP Close snd FIN recv SYN snd ACK, SYN recv ACK recv FIN snd ACK recv ACK Timeout=2MSL recv ACK recv FIN snd ACK AP Close snd FIN recv FIN,ACK snd ACK AP Close or timeout