Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Communication and Networks Lecture 9 The Internet Transport Protocols: TCP, UDP November 10, 2005 Joseph Conron Computer Science Department New York.

Similar presentations

Presentation on theme: "Data Communication and Networks Lecture 9 The Internet Transport Protocols: TCP, UDP November 10, 2005 Joseph Conron Computer Science Department New York."— Presentation transcript:

1 Data Communication and Networks Lecture 9 The Internet Transport Protocols: TCP, UDP November 10, 2005 Joseph Conron Computer Science Department New York University

2 Internet Transport Protocols zTwo Transport Protocols Available yTransmission Control Protocol (TCP) xconnection oriented xmost applications use TCP xRFC 793 yUser Datagram Protocol (UDP) xConnectionless xRFC 768

3 Transport layer addressing zCommunications endpoint addressed by: yIP address (32 bit) in IP Header yPort number (16 bit) in TP Header 1 yTransport protocol (TCP or UDP) in IP Header 1 TP => Transport Protocol (UDP or TCP)

4 Standard services and port numbers

5 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 zfull duplex data: ybi-directional data flow in same connection yMSS: maximum segment size zconnection-oriented: yhandshaking (exchange of control msgs) init’s sender, receiver state before data exchange zflow controlled: ysender will not overwhelm receiver z point-to-point: yone sender, one receiver z reliable, in-order byte steam: yno “message boundaries” z pipelined: yTCP congestion and flow control set window size z send & receive buffers

6 TCP Header

7 TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number rcvr window size ptr urgent data checksum F SR PAU head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet checksum (as in UDP)

8 Reliability in an Unreliable World zIP offers best-effort (unreliable) delivery zTCP uses IP zTCP provides completely reliable transfer zHow is this possible? How can TCP realize: yReliable connection startup? yReliable data transmission? yGraceful connection shutdown?

9 Reliable Data Transmission zPositive acknowledgment yReceiver returns short message when data arrives yCalled acknowledgment zRetransmission ySender starts timer whenever message is transmitted yIf timer expires before acknowledgment arrives, sender retransmits message yTHIS IS NOT A TRIVIAL PROBLEM! – more on this later.

10 TCP Flow Control zReceiver yAdvertises available buffer space yCalled window yThis is a known as a CREDIT policy zSender yCan send up to entire window before ACK arrives zEach acknowledgment carries new window information yCalled window advertisement yCan be zero (called closed window) zInterpretation: I have received up through X, and can take Y more octets

11 Credit Scheme zDecouples flow control from ACK yMay ACK without granting credit and vice versa zEach octet has sequence number zEach transport segment has seq number, ack number and window size in header

12 Use of Header Fields zWhen sending, seq number is that of first octet in segment zACK includes AN=i, W=j zAll octets through SN=i-1 acknowledged yNext expected octet is i zPermission to send additional window of W=j octets yi.e. octets through i+j-1

13 Credit Allocation

14 TCP Flow Control receiver: explicitly informs sender of (dynamically changing) amount of free buffer space  RcvWindow field in TCP segment sender: keeps the amount of transmitted, unACKed data less than most recently received RcvWindow sender won’t overrun receiver’s buffers by transmitting too much, too fast flow control receiver buffering RcvBuffer = size of TCP Receive Buffer RcvWindow = amount of spare room in Buffer

15 TCP seq. #’s and ACKs Seq. #’s: ybyte stream “number” of first byte in segment’s data ACKs: yseq # of next byte expected from other side ycumulative ACK Q: how receiver handles out-of-order segments yA: TCP spec doesn’t say, - up to implementor Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario

16 TCP ACK generation [RFC 1122, RFC 2581] Event in-order segment arrival, no gaps, everything else already ACKed in-order segment arrival, no gaps, one delayed ACK pending out-of-order segment arrival higher-than-expect seq. # gap detected arrival of segment that partially or completely fills gap TCP Receiver action delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK immediately send single cumulative ACK send duplicate ACK, indicating seq. # of next expected byte immediate ACK if segment starts at lower end of gap

17 TCP: retransmission scenarios Host A Seq=92, 8 bytes data ACK=100 loss timeout time lost ACK scenario Host B X Seq=92, 8 bytes data ACK=100 Host A Seq=100, 20 bytes data ACK=100 Seq=92 timeout time premature timeout, cumulative ACKs Host B Seq=92, 8 bytes data ACK=120 Seq=92, 8 bytes data Seq=100 timeout ACK=120

18 Why Startup/ Shutdown Difficult? zSegments can be yLost yDuplicated yDelayed yDelivered out of order yEither side can crash yEither side can reboot zNeed to avoid duplicate ‘‘shutdown’’ message from affecting later connection

19 TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments zinitialize TCP variables: yseq. #s  buffers, flow control info (e.g. RcvWindow ) zclient: connection initiator Socket clientSocket = new Socket("hostname","port number"); zserver: contacted by client Socket connectionSocket = welcomeSocket.accept(); Three way handshake: Step 1: client end system sends TCP SYN control segment to server yspecifies initial seq # Step 2: server end system receives SYN, replies with SYNACK control segment yACKs received SYN yallocates buffers yspecifies server-> receiver initial seq. #

20 TCP Connection Management (OPEN) client SYN server SYNACK ACK opening closed established

21 TCP Connection Management (cont.) Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. client FIN server ACK FIN close closed timed wait

22 TCP Connection Management (cont.) Step 3: client receives FIN, replies with ACK. yEnters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. Note: with small modification, can handle simultaneous FINs. client FIN server ACK FIN closing closed timed wait closed

23 TCP Connection Management (cont) TCP client lifecycle TCP server lifecycle

24 Timing Problem! The delay required for data to reach a destination and an acknowledgment to return depends on traffic in the internet as well as the distance to the destination. Because it allows multiple application programs to communicate with multiple destinations concurrently, TCP must handle a variety of delays that can change rapidly. How does TCP handle this.....

25 Solving Timing Problem zKeep estimate of round trip time on each connection zUse current estimate to set retransmission timer zKnown as adaptive retransmission zKey to TCP’s success

26 TCP Round Trip Time and Timeout Q: how to set TCP timeout value? zlonger than RTT ynote: RTT will vary ztoo short: premature timeout yunnecessary retransmissions ztoo long: slow reaction to segment loss Q: how to estimate RTT?  SampleRTT : measured time from segment transmission until ACK receipt yignore retransmissions, cumulatively ACKed segments  SampleRTT will vary, want estimated RTT “smoother”  use several recent measurements, not just current SampleRTT

27 TCP Round Trip Time and Timeout EstimatedRTT = (1-x)*EstimatedRTT + x*SampleRTT zExponential weighted moving average zinfluence of given sample decreases exponentially fast ztypical value of x: 0.1 Setting the timeout  EstimtedRTT plus “safety margin”  large variation in EstimatedRTT -> larger safety margin Timeout = EstimatedRTT + 4*Deviation Deviation = (1-x)*Deviation + x*|SampleRTT-EstimatedRTT|

28 Implementation Policy Options zSend zDeliver zAccept zRetransmit zAcknowledge

29 Send zIf no push or close TCP entity transmits at its own convenience (IFF send window allows!) zData buffered at transmit buffer zMay construct segment per data batch zMay wait for certain amount of data

30 Deliver (to application) zIn absence of push, deliver data at own convenience zMay deliver as each in-order segment received zMay buffer data from more than one segment

31 Accept zSegments may arrive out of order zIn order yOnly accept segments in order yDiscard out of order segments zIn windows yAccept all segments within receive window

32 Retransmit zTCP maintains queue of segments transmitted but not acknowledged zTCP will retransmit if not ACKed in given time yFirst only yBatch yIndividual

33 Acknowledgement zImmediate yas soon as segment arrives. ywill introduce extra network traffic yKeeps sender’s pipe open zCumulative yWait a bit before sending ACK (called “delayed ACK”) yMust use timer to insure ACK is sent yLess network traffic yMay let sender’s pipe fill if not timely!

34 UDP: User Datagram Protocol [RFC 768] z“no frills,” “bare bones” Internet transport protocol z“best effort” service, UDP segments may be: ylost ydelivered out of order to app zconnectionless: yno handshaking between UDP sender, receiver yeach UDP segment handled independently of others Why is there a UDP? z no connection establishment (which can add delay) z simple: no connection state at sender, receiver z small segment header z no congestion control: UDP can blast away as fast as desired

35 UDP: more zoften used for streaming multimedia apps yloss tolerant yrate sensitive zother UDP uses yDNS ySNMP zreliable transfer over UDP: add reliability at application layer yapplication-specific error recover! source port #dest port # 32 bits Application data (message) UDP segment format length checksum Length, in bytes of UDP segment, including header

36 UDP Uses zInward data collection zOutward data dissemination zRequest-Response zReal time application

Download ppt "Data Communication and Networks Lecture 9 The Internet Transport Protocols: TCP, UDP November 10, 2005 Joseph Conron Computer Science Department New York."

Similar presentations

Ads by Google