Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 2008CPE 0907422 Computer Networks1 Reliable Byte-Stream (TCP) Outline Connection Establishment/Termination Sliding Window Revisited Flow Control.

Similar presentations


Presentation on theme: "Spring 2008CPE 0907422 Computer Networks1 Reliable Byte-Stream (TCP) Outline Connection Establishment/Termination Sliding Window Revisited Flow Control."— Presentation transcript:

1 Spring 2008CPE 0907422 Computer Networks1 Reliable Byte-Stream (TCP) Outline Connection Establishment/Termination Sliding Window Revisited Flow Control Adaptive Timeout Read: Sections 5.1 - 5.2

2 Spring 2008CPE 0907422 Computer Networks2 Transport Layer Our goals: understand principles behind transport layer services: –multiplexing/demulti plexing –reliable data transfer –flow control –congestion control learn about transport layer protocols in the Internet: –UDP: connectionless transport –TCP: connection-oriented transport –TCP congestion control

3 Spring 2008CPE 0907422 Computer Networks3 End-to-End Protocols Underlying best-effort network –drop messages –re-orders messages –delivers duplicate copies of a given message –limits messages to some finite size –delivers messages after an arbitrarily long delay Common end-to-end services –guarantee message delivery –deliver messages in the same order they are sent –deliver at most one copy of each message –support arbitrarily large messages –support synchronization –allow the receiver to flow control the sender –support multiple application processes on each host

4 Spring 2008CPE 0907422 Computer Networks4 Transport services and protocols provide logical communication between app processes running on different hosts transport protocols run in end systems –send side: breaks app messages into segments, passes to network layer –rcv side: reassembles segments into messages, passes to app layer more than one transport protocol available to apps –Internet: TCP and UDP application transport network data link physical application transport network data link physical logical end-end transport

5 Spring 2008CPE 0907422 Computer Networks5 Internet transport-layer protocols reliable, in-order delivery (TCP) –congestion control –flow control –connection setup unreliable, unordered delivery: UDP –no-frills extension of “best- effort” IP services not available: –delay guarantees –bandwidth guarantees application transport network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical application transport network data link physical logical end-end transport

6 Spring 2008CPE 0907422 Computer Networks6 User Datagram Protocol, UDP: Simple Demultiplexor Extends host-to-host delivery service of underlying network into a process-to-process communication service Adds Demultiplexing –allowing multiple application processes on each host to share network UDP adds no other functionality to the best-effort service provided by underlying network –Unreliable and unordered datagram service –No flow control

7 Spring 2008CPE 0907422 Computer Networks7 User Datagram Protocol, UDP: Simple Demultiplexor Endpoints identified by ports –servers have well-known ports e.g. mail server: port 25 Optional checksum –UDP header + data + pseudo header pseudoheader: from the IP header( Protocol number; source & destination IP addresses) + UDP length field  used to verify message delivered between the correct two endpoints »Example: Destination IP address modified »packet misdelivered; would be detected by UDP checksum Header Format

8 Spring 2008CPE 0907422 Computer Networks8 TCP Overview Connection-oriented Byte-stream –app writes bytes –TCP sends segments –app reads bytes Full duplex Flow control: keep sender from overrunning receiver Congestion control: keep sender from overrunning network Application process Write bytes TCP Send buffer Segment Transmit segments Application process Read bytes TCP Receive buffer ■ ■ ■

9 Spring 2008CPE 0907422 Computer Networks9 Sockets Socket: a door between application process and end-end- transport protocol (UCP or TCP) process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet

10 Spring 2008CPE 0907422 Computer Networks10 Multiplexing/demultiplexing application transport network link physical P1 application transport network link physical application transport network link physical P2 P3 P4 P1 host 1 host 2 host 3 = process= socket delivering received segments to correct socket Demultiplexing at rcv host: gathering data from multiple sockets, enveloping data with header (later used for demultiplexing) Multiplexing at send host:

11 Spring 2008CPE 0907422 Computer Networks11 Connectionless demux (cont) Client IP:B P2 client IP: A P1 P3 server IP: C SP: 6428 DP: 9157 SP: 9157 DP: 6428 SP: 6428 DP: 5775 SP: 5775 DP: 6428 SP provides “return address”

12 Spring 2008CPE 0907422 Computer Networks12 Using Sliding Window Algorithm: Transport Versus Data Link Layer Potentially connects many different hosts –need explicit connection establishment and termination Potentially different RTT –need adaptive timeout mechanism Potentially long delay in network –need to be prepared for arrival of very old segments Potentially different capacity at destination –need to accommodate different node capacity (flow- control) Potentially different network capacity –need to be prepared for network congestion

13 Spring 2008CPE 0907422 Computer Networks13 Segment Format

14 Spring 2008CPE 0907422 Computer Networks14 Segment Format (cont) Each connection identified with 4-tuple: –(SrcPort, SrcIPAddr, DsrPort, DstIPAddr) Sliding window (reliable transmission) + flow control –acknowledgment(Num), SequenceNum, AdvertisedWinow Flags –SYN, FIN, RESET, PUSH, URG, ACK Checksum –pseudo header + TCP header + data

15 Spring 2008CPE 0907422 Computer Networks15 Segment Format (cont I) Flags –SYN, FIN: used when establishing and terminating a TCP connection –RESET: receiver wants to abort the connection –PUSH : the sender invoked the push operation the receiving side of TCP should notify the receiving process of –URG : segment contains urgent data UrgPtr field indicates where the nonurgent data contained in this segment begins. –ACK: set any time Acknowledgment field is valid Checksum –pseudo header + TCP header + data

16 Spring 2008CPE 0907422 Computer Networks16 Client Server SYN ISN=X SYN ISN=X 1 SYN ISN=Y ACK=X+1 SYN ISN=Y ACK=X+1 2 ACK=Y+1 3 time Establishing A Connection

17 Spring 2008CPE 0907422 Computer Networks17 TCP 3-way handshake Client: “I want to talk, and I’m starting with byte number X+1”. Server: “OK, I’m here and I’ll talk. My first byte will be called number Y+1, and I know your first byte will be number X+1”. Client: “Got it - you start at byte number Y+1”. 1 2 3

18 Spring 2008CPE 0907422 Computer Networks18 Termination The TCP layer can send a RST segment that terminates a connection if something is wrong. Usually when one of the two application processes is finished using the connection it tells TCP to terminate the connection –TCP will send a FIN segment

19 Spring 2008CPE 0907422 Computer Networks19 FIN Either end of the connection can initiate termination. A FIN sent means the application is done sending data. The FIN is ACK’d. The other end must now send a FIN. That FIN must be ACK’d.

20 Spring 2008CPE 0907422 Computer Networks20 App1 App2 FIN SN=X FIN SN=X 1 ACK=X+1 2 ACK=Y+1 4 FIN SN=Y FIN SN=Y 3... Terminating A Connection

21 Spring 2008CPE 0907422 Computer Networks21 TCP Termination 1 2 3 4 App1: “I have no more data for you”. App2: “OK, I understand you are done sending.” ……. pause… App2: “OK - Now I’m also done sending data”. App1: “I understand, Goodbye”

22 Spring 2008CPE 0907422 Computer Networks22 State Transition Diagram A rectangle denotes a state that one end of a TCP connection can find itself in A connection end moves from state to state according to the arcs in the diagram An arc is labeled with a tag of event/action Connection ends start in the CLOSED state Two kinds of events trigger a state transition (1) A segment arrives from peer (2) The local application process invokes an operation on TCP

23 Spring 2008CPE 0907422 Computer Networks23 State Transition Diagram I CLOSED state to the ESTABLISHED 1.Server process invokes a passive open operation on TCP  TCP connection moves to LISTEN 2.Client process invokes an active open operation on TCP  Client end of connection sends a SYN to server and moves to SYN_SENT 3.SYN arrives at server end  Server end moves to SYN_RCVD /responds with a SYN+ACK 4.SYN+ACK arrives @ client  Client end moves to ESTABLISHED and sends ACK 5.ACK arrives at server end  Server end moves to ESTABLISHED

24 Spring 2008CPE 0907422 Computer Networks24 State Transition Diagram II CLOSED state to the ESTABLISHED : Notes 1.If the client’s ACK to the server is lost Client side is in ESTABLISHED Client process sends data segments with ACK flag set, and correct value in the Acknowledgment field Server moves to ESTABLISHED when first data segment arrives

25 Spring 2008CPE 0907422 Computer Networks25 State Transition Diagram III CLOSED state to the ESTABLISHED : Notes 2.There is a transition out of the LISTEN state whenever local process invokes a send operation on TCP This is a feature of TCP that no application process actually takes advantage of 3.There are arcs not shown States involving sending a segment also schedule a timeout that eventually could causes the segment to be resent These retransmissions are not depicted in the state transition diagram. After several retransmissions, TCP returns to the CLOSED state terminating a connection

26 Spring 2008CPE 0907422 Computer Networks26 State Transition Diagram IV ESTABLISHED state to the CLOSED 1.This side closes first: ESTABLISHED >> FIN_WAIT_1 >> FIN_WAIT_2 >> TIMEWAIT >> CLOSED 2.The other side closes first: ESTABLISHED >> CLOSE_WAIT >> LAST_ACK >> CLOSED 3.Both sides close at the same time: ESTABLISHED >> FIN_WAIT_1 >> CLOSINC >> TIME_WAIT >> CLOSED. 4.FIN_WAIT_1 to TIME_WAIT (Exercise 4.4)

27 Spring 2008CPE 0907422 Computer Networks27 State Transition Diagram V TIME _WAIT: A connection in the TIME_WAIT state waits for two times the maximum amount of time an IP datagram might live in the Internet (i.e., 120 seconds) Necessary because: Local side of the connection sent an ACK in response to the other side’s FIN If other side retransmits FIN and it is delayed in network If the connection were allowed to move directly to the CLOSED state, then another pair of application processes might open the same connection Then, delayed FIN would immediately initiate the termination of the second incarnation of connection

28 Spring 2008CPE 0907422 Computer Networks28 Reliability in TCP Checksum used to detect bit level errors Sequence numbers used to detect sequencing errors –Duplicates are ignored –Out of order segments are reordered (or dropped) –Lost segments are retransmitted Timeouts used to detect lost segments –Requires RTT calculation –Requires sender to maintain data until it is ACKed

29 Spring 2008CPE 0907422 Computer Networks29 Sliding Window in TCP Guarantees reliable delivery of data Ensures data is delivered in order Enforces flow control

30 Spring 2008CPE 0907422 Computer Networks30 Sliding Window: Reliable and Ordered Delivery Sending side –LastByteAcked < = LastByteSent –LastByteSent < = LastByteWritten –buffer bytes between LastByteAcked and LastByteWritten Receiving side –LastByteRead < NextByteExpected –NextByteExpected < = LastByteRcvd + 1 –buffer bytes between LastByteRead and LastByteRcvd

31 Spring 2008CPE 0907422 Computer Networks31 Sliding Window: Flow Control Receiver advertises a window size to the sender in the AdvertisedWindow field in the TCP header Sender is limited to having no more than a value of AdvertisedWindow bytes of unacknowledged data at any given time Receiver selects a suitable value for AdvertisedWindow based on the amount of memory allocated to the connection for the purpose of buffering data Keeps the sender from overrunning the receiver’s buffer

32 Spring 2008CPE 0907422 Computer Networks32 Sliding Window: Flow Control (cont. I) Send buffer size: MaxSendBuffer Receive buffer size: MaxRcvBuffer Receiving side –LastByteRcvd - LastByteRead < = MaxRcvBuffer –AdvertisedWindow = MaxRcvBuffer - ( NextByteExpected - LastByteRead )

33 Spring 2008CPE 0907422 Computer Networks33 Sliding Window: Flow Control (cont. II) Sending side –LastByteWritten - LastByteAcked < = MaxSendBuffer –LastByteSent - LastByteAcked < = AdvertisedWindow –EffectiveWindow = AdvertisedWindow - ( LastByteSent - LastByteAcked ) EffectiveWindow = 0 if AdvertisedWindow = 0 –EffectiveWindow limits amount of data that can be sent without waiting for acknowledgment –Receiver throttles sender by advertising a window that is no larger than the amount of data it can buffer

34 Spring 2008CPE 0907422 Computer Networks34 Sliding Window: Flow Control (cont. III) Sending side –block sender if tries to write y bytes but ( LastByteWritten - LastByteAcked ) + y > MaxSenderBuffer

35 Spring 2008CPE 0907422 Computer Networks35 Sliding Window: Flow Control (cont. IV) Always send ACK in response to arriving data segment Sending side – Persist when AdvertisedWindow = 0 send a segment with 1 byte of data every so often which triggers a response that contains the current advertised window (eventually nonzero)

36 Spring 2008CPE 0907422 Computer Networks36 Triggering Transmission: If flow control is ignored (i.e. assume the receiver window is wide open), then a segment is sent when any of the three following conditions occur: 1.MSS bytes are collected from sending process –MSS set to size of largest segment TCP can send without causing the local IP to fragment MSS = MTU of directly connected physical network – (TCP & IP header) 2.Sending process invokes a push operation to flush the buffer of unsent bytespush 3.A timer fires –segment contains as many bytes as are currently buffered for transmission

37 Spring 2008CPE 0907422 Computer Networks37 Silly Window Syndrome Sender is accumulating bytes –Receiver window is closed An ACK arrives –Opens window enough for sender to transmit MSS/2 bytes Should sender transmit a half-full segment or wait for window to open to a full MSS? Taking advantage of any available window leads to a situation now known as the silly window syndrome

38 Spring 2008CPE 0907422 Computer Networks38 Silly Window Syndrome (cont.) How aggressively does sender exploit open window? Think of TCP stream a conveyer belt with “full” containers (data segments) going in one direction and empty containers (ACKs) going in the reverse direction –MSS-sized segments correspond to large containers –1-byte segments correspond to very small containers

39 Spring 2008CPE 0907422 Computer Networks39 Silly Window Syndrome (cont.I) sender fills an empty container as soon as it arrives –small containers introduced into the system remain in the system indefinitely It is immediately filled and emptied at each end Never coalesced with adjacent containers to create larger containers Silly window syndrome is only a problem when –Sender transmits a small segment –Receiver opens the window a small amount It’s not possible to outlaw sending small segments –application might do a push after sending a single byte

40 Spring 2008CPE 0907422 Computer Networks40 Silly Window Syndrome Solutions Receiver-side solutions –after advertising zero window, wait for space equal to a maximum segment size (MSS) before it advertises an open window –delayed acknowledgements (mechanisms to coalesce small segments) receiver has no way of knowing how long to wait  for another segment to arrive  for the application to read more data (thus opening the window) Receiver Sender

41 Spring 2008CPE 0907422 Computer Networks41 Nagle’s Algorithm How long does the sender delay sending data? –Use a timer and transmit when timer expires. How long is the timer set?  too long: hurts interactive applications (e.g. telnet)  too short: poor network utilization

42 42 Nagle’s Algorithm (continued) Answer to: “how long does the sender delay sending data?” Self-clocking : When application generates additional data –if (both available data and window > MSS) send a full segment –else if (there is unack’ed data in transit) buffer it until ACK arrives else: send it

43 Spring 2008CPE 0907422 Computer Networks43 Nagle’s Algorithm (cont.I) Interactive application like Telnet will send data at a rate of one segment per RTT –Some segments will contain a single byte –Others will contain as many bytes as the user was able to type in one round-trip time

44 Spring 2008CPE 0907422 Computer Networks44 Nagle’s Algorithm (cont.II) Socket interface allows applications to turn off Nagle’s algorithm by setting the TCP NO_DELAY option –data is transmitted as soon as possible

45 Spring 2008CPE 0907422 Computer Networks45 Protection Against Wrap Around Segments sequence numbers take values from the set {0, 1, 2, …., (2 32 - 1)} During the life time of a TCP connection, if the sequence number wraps around [i.e. {0, 1, 2, …., (2 32 - 1), 0, 1, 2, ….} then –a byte with sequence number x could be sent at one time and at a later time a different byte with the same sequence number x will be sent.  The second byte will be discarded

46 Spring 2008CPE 0907422 Computer Networks46 Protection Against Wrap Around (cont.) Packets cannot survive for longer than MSL –Make sure sequence number does not wrap around within a 120-second i.e. separate the use of the same sequence # by at least 120-second

47 Spring 2008CPE 0907422 Computer Networks47 Protection Against Wrap Around (cont ) 32-bit SequenceNum BandwidthTime Until Wrap Around T1 (1.5 Mbps)6.4 hours Ethernet (10 Mbps)57 minutes T3 (45 Mbps)13 minutes FDDI (100 Mbps)6 minutes STS-3 (155 Mbps)4 minutes STS-12 (622 Mbps)55 seconds STS-24 (1.2 Gbps)28 seconds

48 Spring 2008CPE 0907422 Computer Networks48 Keeping the Pipe Full AdvertisedWindow must be big enough to allow the sender to keep the pipe full 16-bit AdvertisedWindow allows a window of only 64 KB BandwidthDelay x Bandwidth Product T1 (1.5 Mbps)18KB Ethernet (10 Mbps)122KB T3 (45 Mbps)549KB FDDI (100 Mbps)1.2MB STS-3 (155 Mbps)1.8MB STS-12 (622 Mbps)7.4MB STS-24 (1.2 Gbps)14.8MB assuming 100ms RTT

49 Spring 2008CPE 0907422 Computer Networks49 TCP Extensions Implemented as header options Because of the HdrLen field in TCP header the header can be of variable length Variable part of TCP header contains the options that have been added Hosts can still communicate using TCP even if they do not implement the options.

50 Spring 2008CPE 0907422 Computer Networks50 TCP Extensions: Protection Against Wrap Around 32-bit timestamp used to effectively extend the sequence number space TCP decides whether to accept or reject a segment based on a 64-bit identifier –the SequenceNum field in low-order 32 bits –timestamp in the high-order 32 bits Timestamp is always increasing –distinguishes between two different incarnations of the same sequence number

51 Spring 2008CPE 0907422 Computer Networks51 TCP Extensions: Advertise A Larger Window (to keep the pipe full) Shift (scale) advertised window An option defines a scaling factor for the advertised window Two sides of TCP to agree that AdvertisedWindow field counts chunks of bytes rather than bytes –e.g., 16-byte units of data Window scaling option specifies # of bits each side should left-shift the AdvertisedWindow field before using its contents to compute an effective window.

52 Spring 2008CPE 0907422 Computer Networks52 TCP Extensions: Improve TCP’s Timeout Mechanism Improve measurement of RTT: Store timestamp in outgoing segments –TCP put actual system clock “32-bit time- stamp” in the segment’s header. Receiver echoes this timestamp back to sender in acknowledgment Sender subtracts timestamp from the current time to measure RTT

53 Spring 2008CPE 0907422 Computer Networks53 Adaptive Retransmission(Original Algorithm) Keep a running average of RTT and compute timeout as a function of this RTT Measure SampleRTT for each segment / ACK pair Compute an updated EstimatedRTT as a weighted average between the previous estimate and new sample –EstRTT =  x EstRTT +  x SampleRTT –where  +  = 1  between 0.8 and 0.9  between 0.1 and 0.2 Set timeout based on EstRTT –TimeOut = 2 x EstRTT

54 Spring 2008CPE 0907422 Computer Networks54 Karn/Partridge Algorithm Do not sample RTT when retransmitting Also, because congestion is the most likely cause of lost segments –Double timeout after each retransmission (rather than basing it on the last EstimatedRTT ) (a) if you assume that the ACK is for the original transmission but it was really for the second, then the SampleRTT is too large (b) if you assume that the ACK is for the second transmission but it was actually for the first, then the SampIeRTT is too small

55 Spring 2008CPE 0907422 Computer Networks55 Jacobson/ Karels Algorithm New Calculations for average RTT Diff = SampleRTT - EstRTT EstRTT = EstRTT + (  x Diff) Dev = Dev +  ( |Diff| - Dev) –where  is a factor between 0 and 1 Consider variance when setting timeout value TimeOut =  x EstRTT +  x Dev –where  = 1 and  = 4 Notes –algorithm only as good as granularity of clock (500ms on Unix) –accurate timeout mechanism important to congestion control (later)


Download ppt "Spring 2008CPE 0907422 Computer Networks1 Reliable Byte-Stream (TCP) Outline Connection Establishment/Termination Sliding Window Revisited Flow Control."

Similar presentations


Ads by Google