EE 122: Transport Protocols: UDP and TCPToday’s LectureOutlineMotivationSlide 5Transport LayerCongestion vs. Flow ControlTransport Layer (cont’d)PortsHeadersSlide 11UDP: User (Unreliable) Data ProtocolUDP Service & HeaderSlide 14TCP: Transport Control ProtocolTCP ServiceOpen Connection: 3-Way Handshaking3-Way Handshaking (cont’d)Close Connection (Two-Army Problem)Close ConnectionReliable TransferStop & WaitSliding WindowGo-Back-n (GBN)GBN Example w/o ErrorsGBN Example with ErrorsSelective Repeat (SR)SR Example with ErrorsObservationsTCP Flow ControlSlide 31Retransmission TimeoutTiming IllustrationRetransmission Timeout (cont’d)RTT EstimationExponential Averaging ExampleProblemKarn/Partridge AlgorithmJacobson/Karels AlgorithmTCP HeaderSummaryKatz, Stoica F04EE 122: Transport Protocols: UDP and TCPComputer Science DivisionDepartment of Electrical Engineering and Computer ScienceUniversity of California, Berkeley,Berkeley, CA 94720-1776October 5, 20042Katz, Stoica F04Today’s LectureNetwork(IP)ApplicationTransportLinkPhysical3Katz, Stoica F04OutlineMotivationTransport layerTCPUDP4Katz, Stoica F04MotivationIP 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 packets into the network?-Too fast may overwhelm the network-Too slow is not efficient5Katz, Stoica F04OutlineMotivationTransport layerTCPUDP6Katz, Stoica F04Transport LayerProvide a way to decide which packets go to which applications (multiplexing/demultiplexing)Can -Provide reliability, in order delivery, at most once delivery-Support messages of arbitrary length-Govern when hosts should send data can implement congestion and flow control7Katz, Stoica F04Congestion vs. Flow ControlFlow Control – avoid overflowing the receiverCongestion Control – avoid congesting the networkWhat is network congestion?8Katz, Stoica F04Transport Layer (cont’d)IPTransportA B C[A | B | p1 | p2 | …]p1 p2 p1 p2 p3 p1 p2portsApplicationHTTPDNSRAUDP: Not reliableTCP: Ordered, reliable, well-paced9Katz, Stoica F04PortsNeed to decide which application gets which packetsSolution: map each socket to a portClient must know server’s portSeparate 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 clients, p2p networks10Katz, Stoica F04HeadersIP header used for IP routing, fragmentation, error detectionUDP header used for multiplexing/demultiplexing, error detectionTCP header used for multiplexing/demultiplexing, flow and congestion control IPTCP UDPdataTCP/UDPdataTCP/UDPIPApplicationSenderdataIPTCP UDPApplicationReceiverdataTCP/UDPdataTCP/UDPIPdata11Katz, Stoica F04OutlineMotivationTransport LayerUDPTCP12Katz, Stoica F04UDP: User (Unreliable) Data ProtocolMinimalist transport protocolSame best-effort service model as IPMessages up to 64KBProvides multiplexing/demultiplexing to IPDoes not provide flow and congestion controlApplication examples: video/audio streaming13Katz, Stoica F04UDP Service & HeaderService:-Send datagram from (IPa, Port1) to (IPb, Port2)-Service is unreliable, but error detection possibleHeader:Source portDestination port0 16 31UDP length UDP checksumPayload (variable)•UDP length is UDP packet length (including UDP header and payload, but not IP header)•Optional UDP checksum is over UDP packet14Katz, Stoica F04OutlineMotivationTransport LayerUDPTCP15Katz, Stoica F04TCP: Transport Control ProtocolReliable, in-order, and at most once deliveryStream oriented: messages can be of arbitrary lengthProvides multiplexing/demultiplexing to IPProvides congestion control and avoidanceApplication examples: file transfer, chat16Katz, Stoica F04TCP Service1) Open connection: 3-way handshaking2) Reliable byte stream transfer from (IPa, TCP_Port1) to (IPb, TCP_Port2)•Indication if connection fails: Reset3) Close (tear-down) connection17Katz, Stoica F04Open Connection: 3-Way HandshakingGoal: agree on a set of parameters: the start sequence number for each side-Starting sequence numbers are randomClient (initiator)ServerSYN, SeqNum = xSYN and ACK, SeqNum = y and Ack = x + 1ACK, Ack = y + 1ActiveOpenPassiveOpenconnect() listen()accept()allocatebuffer space18Katz, Stoica F043-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)19Katz, Stoica F04Close Connection (Two-Army Problem) Goal: both sides agree to close the connectionTwo-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?20Katz, Stoica F04Close Connection4-ways tear down connectionFINFIN ACKFINFIN ACKHost 1 Host 2timeout Avoid reincarnation Can retransmit FIN ACK if it is lostclosedcloseclose21Katz, Stoica F04Reliable TransferRetransmit missing packets-Numbering of packets and ACKsDo this efficiently-Keep transmitting whenever possible-Detect missing ACKs and retransmit quicklyTwo schemes-Stop & Wait-Sliding Window (Go-back-n and Selective Repeat)22Katz, Stoica F04Stop & Wait ACKDATATimeSenderReceiverRTTSend; wait for ackIf timeout, retransmit; else repeatInefficient ifTRANS << RTTInefficient ifTRANS << RTTTRANS23Katz, Stoica F04Sliding Windowwindow = set of adjacent sequence numbersThe size of the set is the window sizeAssume window size is nLet 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 windowLet 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 window24Katz, Stoica F04Go-Back-n (GBN)Transmit up to n unacknowledged packetsIf timeout for ACK(k),
View Full Document