280 likes | 406 Views
Two Transport Protocols Available. Transmission Control Protocol (TCP). User Datagram Protocol (UDP). Provides unreliable transfer. Each message encapsulated in IP datagram. Requires minimal – Overhead – Computation – Communication. UDP. U ser D atagram P rotocol. internet.
E N D
Two Transport Protocols Available • Transmission Control Protocol (TCP) • User Datagram Protocol (UDP) • Provides unreliable transfer • Each message encapsulated in IP datagram • Requires minimal • – Overhead • – Computation • – Communication
UDP • User Datagram Protocol
internet Connectionless Sender socket sendto Dst/X Receiver socket bind on X recvfrom Dst Sender socket sendto Dst/X
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
UDP checksum 0 15 16 31 source IP address UDP pseudo header destination IP address zero protocol UDP length source port destination port UDP header checksum UDP length data(if any) pad (0)
Example DHCP server DHCP client B: winipcfg DHCP client A: reboot
TCP • Transmission Control Protocol
TCP • Transmission Control Protocol • RFC-793 • Connection-oriented • Reliable • Byte stream • Dispatch data to socket
internet Connection-Oriented • Receiver • socket • bind on X • listen • accept • recv • Sender • socket • bind • connect Dst/X • send Dst
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
PacketFormat 0 15 16 31 source port destination port sequence number acknowledgement number header len reser U R G A C K P S H R S T S Y N F I N window size checksum urgent pointer
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
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
Checksum • 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 2F, F <=14 • Timestamp: for deriving the round-trip time
Connection Establish • Uses 3-way handshake to establish connection • SYN used for startup CLOSED SYN 141223, win 4096 <mss 1024> SYN_SENT SYN_RCVD SYN 254242, win 4096 ack 141224 <mss 1024> ESTABLISH ESTABLISH ack 254243, win 4096 MSS: max segment size
Connection Termination • Uses modified 3-way handshake to establish connection • FIN used for shutdown ESTABLISH FIN 341248 ack 668451 FIN_WAIT_1 CLOSE_WAIT ack 341249 LAST_ACK FIN_WAIT_2 FIN 668451 ack 341249 TIME_WAIT ack 668452 CLOSED CLOSED
TCP State Machine CLOSED passive OPEN active OPEN snd SYN recv SYN snd ACK, SYN LISTEN AP Close or timeout SYN_RCVD SYN_SENT recv SYN, ACK snd ACK recv ACK AP Close snd FIN ESTABLISHED CLOSE_WAIT AP Close snd FIN recv FIN snd ACK AP Close snd FIN LAST_ACK recv FIN snd ACK FIN_WAIT_1 CLOSING recv ACK recv FIN,ACK snd ACK recv ACK recv ACK recv FIN snd ACK Timeout=2MSL FIN_WAIT_2 TIME_WAIT