EECS 122: Introduction to Computer Networks Transport: UDP and TCPOutlineMotivationSlide 4Transport LayerCongestion & Flow ControlTransport Layer (cont’d)PortsHeadersSlide 10UDPUDP Service & HeaderSlide 13TCPTCP ServiceTiming DiagramOpen Connection: 3-Way Handshaking3-Way Handshaking (cont’d)Close Connection (Two-Army Problem)Close ConnectionReliable TransferStop & WaitSliding WindowGo-Back-n (GBN)GBN ExampleGBN Example with ErrorsSelective Repeat (SR)SR Example with ErrorsObservationsSetting TimersTiming IllustrationAdaptive TimersTimer AlgorithmTCP HeaderSummaryKatz, Stoica F04EECS 122: Introduction to Computer Networks Transport: UDP and TCPComputer Science DivisionDepartment of Electrical Engineering and Computer SciencesUniversity of California, BerkeleyBerkeley, CA 94720-17762Katz, Stoica F04OutlineMotivationTransport layerTCPUDP3Katz, 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 into the network?-Too fast is bad; too slow is not efficient4Katz, Stoica F04OutlineMotivationTransport layerTCPUDP5Katz, Stoica F04Transport LayerCan provide more reliability, in order delivery, at most once deliverySupports messages of arbitrary lengthProvide a way to decide which packets go to which applications (multiplexing/demultiplexing)Govern when hosts should send data can implement congestion and flow control6Katz, Stoica F04Congestion & Flow ControlFlow Control – avoid overflowing the receiverCongestion Control – avoid congesting the networkWhat is network congestion?7Katz, Stoica F04Transport Layer (cont’d)IPTransportA B C[A | B | p1 | p2 | …]p1 p2 p1 p2 p3 p1 p2portsApplicationHTTPDNSRAUDP: Not reliableTCP: Ordered, reliable, well-paced8Katz, 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 client gets one of these9Katz, Stoica F04HeadersIP header used for IP routing, fragmentation, error detection… (we study that when we explore IP)UDP header used for multiplexing/demultiplexing, error detectionTCP header used for multiplexing/demultiplexing, flow and congestion control IPTCP UDPdataTCP/UDPdataTCP/UDPIPApplicationSenderdataIPTCP UDPApplicationReceiverdataTCP/UDPdataTCP/UDPIPdata10Katz, Stoica F04OutlineMotivationTransport LayerUDPTCP11Katz, Stoica F04UDPUser Datagram 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 streaming12Katz, Stoica F04UDP Service & HeaderService:-Send datagram from (IPa, Port 1) to (IPb, Port 2)-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 packet Why have UDP checksum in addition to IP checksum? Why not have just the UDP checksum? Why is the UDP checksum optional?13Katz, Stoica F04OutlineMotivationTransport LayerUDPTCP14Katz, Stoica F04TCPTransmission Control ProtocolReliable, in-order, and at most once deliveryMessages can be of arbitrary lengthProvides multiplexing/demultiplexing to IPProvides congestion control and avoidanceApplication examples: file transfer, chat15Katz, Stoica F04TCP Service1) Open connection2) Reliable byte stream transfer from (IPa, TCP Port1) to (IPb, TCP Port2)•Indication if connection fails: Reset3) Close connection16Katz, Stoica F04SYN kSYN n; ACK k+1DATA k+1; ACK n+1ACK k+n+1data exchangeFINFIN ACK½ closeFINFIN ACK½ closeTiming Diagram3-way handshakeOpenconnect.TransferCloseconnect.17Katz, Stoica F04Open Connection: 3-Way HandshakingGoal: agree on a set of parameters: the start sequence number for each side-Starting sequence numbers are random.Client (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
View Full Document