Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transmission Control Protocol (TCP)

Similar presentations


Presentation on theme: "Transmission Control Protocol (TCP)"— Presentation transcript:

1 Transmission Control Protocol (TCP)
Reference: TCP/IP Protocol Suite, Fourth Edition by Behrouz A. Forouzan

2 TCP Services Process-to-Process Communication Stream Delivery Service
using port numbers Stream Delivery Service Sending and Receiving Buffers necessary for flow- and error-control mechanisms

3 Full-Duplex Communication
Segments A number of bytes together into a packet called a segment Full-Duplex Communication Each TCP endpoint then has its own sending and receiving buffer, and segments move in both directions. Multiplexing and Demultiplexing Like UDP, TCP performs multiplexing at the sender and demultiplexing at the receiver Connection-Oriented Service TCP, unlike UDP, is a connection-oriented protocol a virtual connection, not a physical connection

4 Reliable Service Flow Control Error Control Congestion Control
It uses an acknowledgment mechanism to check the safe and sound arrival of data Flow Control Error Control Congestion Control

5 TCP Features Numbering System Byte Number Sequence Number
When TCP receives bytes of data from a process, it stores them in the sending buffer and numbers them. The numbering does not necessarily start from 0. TCP chooses an arbitrary number between 0 and 232 − 1 for the number of the first byte. Sequence Number The sequence number for each segment is the number of the first byte of data carried in that segment.

6 When a segment carries a combination of data and control information (piggybacking), it uses a sequence number. However, some segments, when carrying only control information, need a sequence number to allow an acknowledgment from the receiver. These segments are used for connection establishment, termination, or abortion

7 Example Suppose a TCP connection is transferring a file of 5,000 bytes. The first byte is numbered 10,001. What are the sequence numbers for each segment if data are sent in five segments, each carrying 1,000 bytes?

8 Solution

9 Acknowledgment Number
Acknowledgment number defines the number of the next byte that the party expects to receive The acknowledgment number is cumulative which means that the party takes the number of the last byte that it has received, safe and sound, adds 1 to it, and announces this sum as the acknowledgment number if receiver uses 5,643 as an acknowledgment number, it has received all bytes from the beginning up to 5,642. Note that this does not mean that the receiver has received 5,642 bytes, because the first byte number does not have to start from 0.

10 TCP Segment

11 Acknowledgment number
This 32-bit field defines the byte number that the receiver of the segment is expecting to receive from the other party Header length The length of the header can be between 20 and 60 bytes (value in this field is to be multiplied by 4 to get Hlen) Window size is determined by the receive

12 PSH In general, transport layer sends data when window becomes full,
When application have some data to be sent immediately, PSH is set and sent without waiting to get the window fills fully May be used in case on instant messaging application.

13 Urgent pointer TCP is a stream-oriented protocol
When application requires some data to be treated in special way, it is treated as urgent data The sending TCP creates a segment and inserts the urgent data at the beginning of the segment. The rest of the segment can contain normal data from the buffer The urgent pointer field in the header defines the end of the urgent data (the last byte of urgent data). When the receiving TCP receives a segment with the URG bit set, it informs the receiving application of the situation

14 Connect Reset (RST) TCP at one end may deny a connection request,
requested a connection to a nonexistent port may abort an existing connection, or want to abort an existing connection due to an abnormal situation may terminate an idle connection. the other side has been idle for a long time All of these are done with the RST (reset) flag.

15 Checksum

16 TCP Connection Connection Establishment Three-Way Handshaking
SYN segment (from client to server): only the SYN flag is set for synchronization of sequence numbers (called initial sequence number) does not contain an acknowledgment number. It does not define the window size either No data it consumes one sequence number

17 SYN + ACK (from server to client):
two flag bits set: SYN and ACK SYN segment for communication in the other direction (S-> R), to initialize a sequence number for numbering the bytes sent from the server to the client ACK to acknowledge received segment (SYN), displaying the next sequence number it expects to receive from the client As its ACK is set, need to defines the receive window size SYN + ACK segment cannot carry data, does consume one sequence number

18 ACK Segment (Client to Server):
Ack for SYN segment (received (SYN+ACK) Ack of ACK segment is not sent ACK segment does not consume any sequence numbers Some implementations allow this third segment in the connection phase to carry the first chunk of data from the client. In this case, the third segment must have a new sequence number showing the byte number of the first byte in the data. In general, the third segment usually does not carry data and consumes no sequence numbers.

19 3 way handshaking (connection establishment)

20 Data Transfer

21 Connection Termination
3-way handshaking

22 Half-Close

23 Flow Control We will be considering unidirectional communication (bidirectional communication can be considered, having two unidirectional)

24 Windows in TCP Send Window
The send window size is dictated by the receiver (flow control) and the congestion in the underlying network (congestion control).

25 SR vs TCP send windows The window in SR numbers pockets, but the window in the TCP numbers bytes. Although actual transmission in TCP occurs segment by segment, the variables that control the window are expressed in bytes. TCP can store data received from the process and send them later, but we assume that the sending TCP is capable of sending segments of data as soon as it receives them from its process. The theoretical Selective Repeat protocol may use several timers for each packet sent, but the TCP protocol uses only one timer

26 Receive Window

27 SR vs TCP receive windows
TCP allows the receiving process to pull data at its own pace. This means that part of the allocated buffer at the receiver may be occupied by bytes that have been received and acknowledged, but are waiting to be pulled by the receiving process. The receive window size is then always smaller or equal to the buffer size rwnd = buffer size − number of waiting bytes to be pulled ACK in TCP is a cumulative acknowledgment announcing the next expected byte to receive

28 Cont… Opening and Closing Windows
Size of buffer of both parties are fixed The receive window closes (moves its left wall to the right) when more bytes arrive from the sender; it opens (moves its right wall to the right) when more bytes are pulled by the process. We assume that it does not shrink (the right wall does not move to the left).

29 Cont… The opening, closing, and shrinking of the send window is controlled by the receiver The send window closes (moves its left wall to the right) when a new acknowledgement allows it to do so. The send window opens (its right wall moves to the right) when the receive window size (rwnd) advertised by the receiver allows it to do so. The send window shrinks on occasion.

30 A scenario

31 Shrinking of Windows Window Shutdown the receive window cannot shrink.
Send window can shrink Window Shutdown the receiver can temporarily shut down the window by sending a rwnd of 0. the sender does not actually shrink the size of the window, but stops sending data until a new advertisement has arrived. the sender can always send a segment with 1 byte of data. This is called probing and is used to prevent a deadlock

32 Silly Window Syndrome A serious problem can arise in the sliding window operation when either the sending application program creates data slowly or the receiving application program consumes data slowly, or both. results in the sending of data in very small segments, which reduces the efficiency of the operation This problem is called the silly window syndrome

33 Syndrome Created by the Sender
When an application program that creates data slowly, small segments are created and sent Solution Prevent the sending TCP from sending the data byte by byte It must wait and collect data to send in a larger block. How long should the sending TCP wait? If it waits too long, it may delay the process. If it does not wait long enough, it may end up sending small segments. Nagle found an elegant solution

34 Nagle’s Algorithm Immediately send 1st piece of data (even if it is only 1 byte) Then, wait until (keep on storing received data) either the receiving TCP sends an acknowledgment or until enough data has accumulated to fill a maximum-size segment. At this time, the sending TCP can send the segment. Step 2 is repeated for the rest of the transmission. Segment 3 is sent immediately if an acknowledgment is received for segment 2, or if enough data have accumulated to fill a maximum-size segment.

35 Syndrome Created by the Receiver
If receiving application consumes data slowly Receiving buffer will be full very soon Shutdowns sender window In worst case consumes 1 byte at a time Sender sends 1 byte segments Solution to it Clark’s Solution send an acknowledgment as soon as the data arrive, Close the window until either there is enough space to accommodate a segment of maximum size or at least half of the receive buffer is empty. Delayed Acknowledgment A segment is not acknowledged immediately The receiver waits until there is a decent amount of space in its incoming buffer before acknowledging the arrived segments.

36 prevents the sender (sending TCP) from sliding its window.
After the sender (sending TCP) has sent the data in the window, it stops. it reduces traffic (each segment is not acknowledged) The delayed acknowledgment may result in the sender unnecessarily retransmitting the unacknowledged segments. In TCP the acknowledgment should not be delayed by more than 500 ms.

37 Error Control TCP provides reliability using error control.
Error control includes mechanisms for detecting and resending corrupted segments, resending lost segments, storing out-of-order segments and detecting and discarding duplicated segments. Error control in TCP is achieved through the use of: checksum, acknowledgment, and time-out.

38 Acknowledgement ACK segments do not consume sequence numbers and are not acknowledged. Acknowledgment Type Cumulative Acknowledgment (ACK) The receiver advertises the next byte it expects, ignoring all segments received and stored out of order no feedback is provided for discarded, lost, or duplicate segments The 32-bit ACK field in the TCP header is used for cumulative acknowledgments and its value is valid only when the ACK flag bit is set to 1.

39 Selective Acknowledgment (SACK)
A SACK does not replace ACK, but reports additional information to the sender A SACK reports a block of data that is out of order, and also a block of segments that is duplicated SACK is implemented as an option at the end of the TCP header

40 Generating Acknowledgments
the most common rules Piggybacked ACKs, if possible If there is only one outstanding in-order segment, ACK is delayed When an expected segment arrives, and previous in-order is not ACKed, send ACK Out of order segment no. received (higher than expected), send ACK for expected. When a missing segment arrives, the receiver sends an ACK segment to announce the next sequence number expected. If a duplicate segment arrives, the receiver discards the segment, but immediately sends an acknowledgment indicating the next in-order segment expected

41 Retransmission Error control is handled using retransmission
When a segment is sent, it is stored in a queue until it is acknowledged. When the retransmission timer expires or when the sender receives three duplicate ACKs for the first segment in the queue, that segment is retransmitted.

42 Retransmission after RTO
The sending TCP maintains one retransmission time-out (RTO) RTO expires TCP sends the segment in the front of the queue (the segment with the smallest sequence number) and restarts the timer. Sf< Sn This version of TCP is sometimes referred to as Tahoe.

43 Retransmission after Three Duplicate ACK Segments
Usually RTO value is large To increase throughput , 3-dulicate ACKs (an original ACK plus three exactly identical copies) are used to retransmit the segment before RTO matures This feature is called fast retransmission This version of TCP is sometimes referred to as Reno

44 Out-of-Order Segments
TCP does not discard out-of-order segments. Those are stored temporarily and flag them as out-of-order segments until the missing segments arrive. however, that out-of-order segments are never delivered to the process.

45 Normal Operation of TCP

46 Some Segment Lost

47 Fast Retransmission

48 Automatically Corrected Lost ACK
Corrected by next ACK RTO does not expires

49 Corrected by RTO Duplicate segments will be received and discarded

50 Congestion Control The load on the network (the number of packets sent to the network) is greater than the capacity of the network (the number of packets a network can handle) Due to waiting in a system Buffers at routers and switches. Congestion Prevention Congestion Removal

51 TCP Congestion Control
TCP uses a congestion window and a congestion policy

52 3 Steps to control the congestion
First, how does a TCP sender limit the rate at which it sends traffic into its connection? Second, how does a TCP sender perceive that there is congestion on the path between itself and the destination? And third, What algorithm should the sender use to change its send rate as a function of perceived end-to-end congestion?

53 Limiting Sender rate: Congestion Window
Sender window size is determined by the available buffer space in the receiver (rwnd). What if network cannot deliver at the rate data is created at sender Now Sender decides window size according to Actual window size = minimum (rwnd, cwnd)

54 Congestion Detection Loss of segments Due to Timeout
Due to 3 Duplicate ACKs

55 Congestion Policy Based on three phases: slow start,
congestion avoidance, and congestion detection

56 Slow Start: Exponential Increase
cwnd starts with 1 MSS cwnd increases with 1 MSS when an ACK received We assume rwnd >> cwnd we ignore delayed-ACK policy and assume that each segment is acknowledged individually

57

58 When to stop slow-start?
When the size of window in bytes reaches a threshold, slow start stops and the next phase starts.

59 Congestion Avoidance: Additive Increase
Congestion avoidance, increases the cwnd additively instead of exponentially When the size of the cwnd reaches the slow start threshold in the case where cwnd = i, the slow start phase stops and the additive phase begins.

60 The increase in cwnd is based on RTT, not on the number of arrived ACKs.
In the congestion avoidance algorithm the size of the cwnd increases additively until congestion is detected.

61 Congestion Detection: Multiplicative Decrease
If congestion occurs, the congestion window size must be decreased TCP assumes that, when there is a need of retransmission it is due to congestion Retransmission can occur in one of two cases: when the RTO timer times out or when three duplicate ACKs are received. In both cases, the size of the threshold is dropped to half (multiplicative decrease).

62 Most TCP implementations have two reactions:
If a time-out occurs, there is a stronger possibility of congestion (a segment has probably been dropped in the network). In this case TCP reacts strongly: Threshold = ½(current window size). cwnd = one segment. It starts the slow start phase again. Also known as TCP Tahoe

63 If three duplicate ACKs are received, there is a weaker possibility of congestion. TCP has a weaker reaction as shown below: Threshold = ½(current window size). cwnd = threshold (some implementations add three segment sizes to the threshold). It starts the congestion avoidance phase. Also Known as TCP Reno

64 TCP Tahoe v/s TCP Reno TCP Tahoe is old method: Always enters to Slow-Start phase (Reacts in same manner for both: Tiome-out and 3 duplicate ACKs) TCP Reno: Reacts differently on both events of a segment loss.

65 Exercise In a network assume rwnd >>cwnd
Initially threshold value is 16. At time 40 sec. sender retransmits a segment due to RTO expiry. At time 70 sec. sender receives 2 duplicate ACKs. Draw a graph between cwnd and RTT Note: RTT = 5 sec.

66

67 TCP TIMERS Retransmission Timer Round-Trip Time (RTT)
retransmission time-out (RTO), the waiting time for an ack of a segment Round-Trip Time (RTT) To calculate the RTO, we first need to calculate the RTT

68 RTT Calculation MeasuredRTT (RTTm) SmoothedRTT (RTTS)
Time it takes to send a segment and receive an ack for it. Only 1 RTT can be measured at a time. TCP never computes Measured RTT for retransmitted segments. SmoothedRTT (RTTS) The RTTM, is likely to change for each round trip α =1/8

69 Retransmission Time-out (RTO)
RTT Deviation Retransmission Time-out (RTO) Whenever a timeout occurs, TCP sets timeout interval to twice the previous value. β =1/4 D

70

71 Doubling the Timeout interval
Whenever a timeout occurs, TCP sets timeout interval to twice the previous value. Fast Retransmission Timeout-triggered retransmission lead to slow retransmission. If sender receives 3 duplicate ACKs for the same data, retransmit segment before timeout occurs.

72

73 The window in SR numbers packets, but the window in the TCP numbers bytes.
The variables that control the window are expressed in bytes.


Download ppt "Transmission Control Protocol (TCP)"

Similar presentations


Ads by Google