EECS 122 Introduction to Computer Networks Transport UDP and TCP Computer Science Division Department of Electrical Engineering and Computer Sciences University of California Berkeley Berkeley CA 94720 1776 Katz Stoica F04 Outline Motivation Transport layer TCP UDP Katz Stoica F04 2 Motivation IP provides a weak but efficient service model best effort Packets can be delayed dropped reordered duplicated Packets have limited size why IP packets are addressed to a host How to decide which application gets which packets How should hosts send into the network Too fast is bad too slow is not efficient Katz Stoica F04 3 Outline Motivation Transport layer TCP UDP Katz Stoica F04 4 Transport Layer Can provide more reliability in order delivery at most once delivery Supports messages of arbitrary length Provide a way to decide which packets go to which applications multiplexing demultiplexing Govern when hosts should send data can implement congestion and flow control Katz Stoica F04 5 Congestion Flow Control Flow Control avoid overflowing the receiver Congestion Control avoid congesting the network What is network congestion Katz Stoica F04 6 Transport Layer cont d ports HTTP RA DNS Application p1 p2 p1 p2 p3 p1 p2 Transport IP A B C A B p1 p2 UDP Not reliable TCP Ordered reliable well paced Katz Stoica F04 7 Ports Need to decide which application gets which packets Solution map each socket to a port Client must know server s port Separate 16 bit port address space for UDP and TCP src IP src port dst IP dst port uniquely identifies TCP connection Well known ports 0 1023 everyone agrees which services run on these ports e g ssh 22 http 80 on UNIX must be root to gain access to these ports why Ephemeral ports most 1024 65535 given to clients e g chat client gets one of these Katz Stoica F04 8 Headers IP IP header used for IP routing fragmentation error detection we study that when we explore IP UDP header used for multiplexing demultiplexing error detection TCP header used for multiplexing demultiplexing flow and congestion control Receiver data Sender Application Application TCP UDP data TCP UDP TCP UDP TCP UDP data IP IP data IP TCP UDP data TCP UDP data Katz Stoica F04 9 Outline Motivation Transport Layer UDP TCP Katz Stoica F04 10 UDP User Datagram Protocol Minimalist transport protocol Same best effort service model as IP Messages up to 64KB Provides multiplexing demultiplexing to IP Does not provide flow and congestion control Application examples video audio streaming Katz Stoica F04 11 UDP Service Header Service Send datagram from IPa Port 1 to IPb Port 2 Service is unreliable but error detection possible Header 0 16 Source port UDP length 31 Destination port UDP checksum Payload variable UDP length is UDP packet length including UDP header and payload but not IP header Optional UDP checksum is over UDP packet Why have UDP checksum in addition to IP checksum Why not have just the UDP checksum Why is the UDP checksum optional Katz Stoica F04 12 Outline Motivation Transport Layer UDP TCP Katz Stoica F04 13 TCP Transmission Control Protocol Reliable in order and at most once delivery Messages can be of arbitrary length Provides multiplexing demultiplexing to IP Provides congestion control and avoidance Application examples file transfer chat Katz Stoica F04 14 TCP Service 1 2 Open connection Reliable byte stream transfer from IPa TCP Port1 to IPb TCP Port2 3 Indication if connection fails Reset Close connection Katz Stoica F04 15 Timing Diagram Open connect SYN k 3 way handshake SYN n ACK k 1 DATA k 1 ACK n 1 ACK k n 1 data exchange Transfer FIN Close connect close FIN ACK FIN FIN ACK close Katz Stoica F04 16 Open Connection 3 Way Handshaking Goal agree on a set of parameters the start sequence number for each side Starting sequence numbers are random Server Client initiator Active connect Open SYN Seq Num x k x 1 c A d n a y qNum e S K C A SYN and ACK Ack y 1 listen accept Passive Open allocate buffer space Katz Stoica F04 17 3 Way Handshaking cont d Three way handshake adds 1 RTT delay Why Congestion control SYN 40 byte acts as cheap probe Protects against delayed packets from other connection would confuse receiver Katz Stoica F04 18 Close Connection Two Army Problem Goal both sides agree to close the connection Two army problem Two blue armies need to simultaneously attack the white army to win otherwise they will be defeated The blue army can communicate only across the area controlled by the white army which can intercept the messengers What is the solution Katz Stoica F04 19 Close Connection 4 ways tear down connection Host 1 Host 2 FIN close FIN ACK FIN FIN ACK timeout Avoid reincarnation Can retransmit FIN ACK if it is lost close closed Katz Stoica F04 20 Reliable Transfer Retransmit missing packets Numbering of packets and ACKs Do this efficiently Keep transmitting whenever possible Detect missing ACKs and retransmit quickly Two schemes Stop Wait Sliding Window Go back n and Selective Repeat Katz Stoica F04 21 Stop Wait Send wait for ack If timeout retransmit else repeat TRANS DATA Receiver Sender RTT ACK Inefficient if TRANS RTT Time Katz Stoica F04 22 Sliding Window window set of adjacent sequence numbers The size of the set is the window size Assume window size is n Let A be the last ack d packet of sender without gap then window of sender A 1 A 2 A n Sender can send packets in its window Let B be the last received packet without gap by receiver then window of receiver B 1 B n Receiver can accept out of sequence if in window Katz Stoica F04 23 Go Back n GBN Transmit up to n unacknowledged packets If timeout for ACK k retransmit k k 1 Katz Stoica F04 24 GBN Example n 9 packets in one RTT instead of 1 Fully efficient Time Katz Stoica F04 25 GBN Example with Errors Window size 3 packets 1 2 3 Timeout Packet 5 4 5 6 7 5 6 7 Sender Time Receiver Katz Stoica F04 26 Selective Repeat SR Sender transmit up to n unacknowledged packets Receiver indicate packet k is missing Sender retransmit packet k Katz Stoica F04 27 SR Example with Errors Window size 3 packets 1 2 3 4 5 6 7 5 8 Sender nack 5 Time Receiver Katz Stoica F04 28 Observations With sliding windows it is possible to fully utilize a link provided the window size is large enough Throughput is n RTT Stop Wait is like n 1 Sender has to buffer all unacknowledged packets because they may require retransmission Receiver may be able to accept out of order packets but only up to its buffer limits Katz Stoica F04 29 Setting Timers
View Full Document