TCP Protocol: Exercises, Flow Control, Congestion & Error Management
TCP Protocol: Exercises and Mechanisms
TCP Exercise 1: Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is numbered 10001. What are the sequence numbers for each segment if data is sent in five segments, each carrying 1000 bytes?
The following shows the sequence number for each segment:
- Segment 1 ➡ Sequence Number: 10,001 (range: 10,001 to 11,000)
- Segment 2 ➡ Sequence Number: 11,001 (range: 11,001 to 12,000)
- Segment 3 ➡ Sequence Number: 12,001 (range: 12,001 to 13,000)
- Segment 4 ➡ Sequence Number: 13,001 (range: 13,001 to 14,000)
- Segment 5 ➡ Sequence Number: 14,001 (range: 14,001 to 15,000)
TCP Exercise 2: Imagine a TCP connection is transferring a file of 6000 bytes. The first byte is numbered 10010. What are the sequence numbers for each segment if data is sent in five segments with the first four segments carrying 1,000 bytes and the last segment carrying 2,000 bytes?
The following shows the sequence number for each segment:
- Segment 1 ➡ 10,010 (10,010 to 11,009)
- Segment 2 ➡ 11,010 (11,010 to 12,009)
- Segment 3 ➡ 12,010 (12,010 to 13,009)
- Segment 4 ➡ 13,010 (13,010 to 14,009)
- Segment 5 ➡ 14,010 (14,010 to 16,009)
TCP Exercise 3: Suppose that Receiver B has a buffer size of 5000 and receives 1000 bytes of unprocessed data. What is the value of the receiver window (rwnd) for sender A?
Solution: The value of rwnd = 5,000 – 1,000 = 4,000. Host B can receive only 4,000 bytes of data before overflowing its buffer. Host B advertises this value in its next segment to A.
TCP Exercise 4: How can the receiver avoid shrinking the window in example 8?
Solution:
- The receiver needs to keep track of the last acknowledgment number and the last rwnd.
- Right wall = acknowledgment number + rwnd
- To prevent shrinking, we must always have the following relationship: new ack + new rwnd ≥ last ack + last rwnd or new rwnd ≥ (last ack + last rwnd) – new ack.
TCP Exercise 5: Figure 12.38 shows part of a connection. The figure shows the connection establishment and part of the data transfer phases. When the SYN segment is sent, there is no value for RTTM, RTTS, or RTTD. The value of RTO is set to 6.00 seconds.
RTO = 6.
When the SYN+ACK segment arrives, RTTM is measured and is equal to 1.5 seconds.
RTTM = 1.5, RTTS = 1.5, RTTD = 1.5 / 2 = 0.75, RTO = 1.5 + 4 * 0.75 = 4.5.
Nueva medida: RTTM = 2.5
RTTS = 7/8 (1.5) + 1/8 (2.5) = 1.625, RTTD = 3/4 (7.5) + 1/4 |1.625 – 2.5| = 0.78, RTO = 1.625 + 4 (0.78) = 4.74
Measured RTT: RTTM
RTTS = (1-a) RTTS + a x RTTM: a is usually 1/8 percent
After first measurement: RTTD = RTTM/2. After any other measurement: RTTD=(1-B)RTTD+Bx |RTTS -RTTM|: B is usually 1/4
After any measurement: RTO = RTTS + 4 x RTTD
Flow Control in TCP
The receiver controls how much data are to be sent by the sender to prevent the receiver from being overwhelmed with data. The numbering system allows TCP to use a byte-oriented flow control. Flow control regulates the amount of data a source can send before receiving an acknowledgment from the destination. TCP defines a window that is imposed on the buffer of data delivered from the application program.
Regulate the amount of data a source can send before receiving an acknowledgment.
- Two extreme cases:
- Send 1 byte of data and wait for an acknowledge.
- Source would be idle.
- Send all of the data without worrying about acknowledge.
- May overwhelm the receiver buffer.
- Inefficient if some part of data is lost, duplicated, received out of order or corrupted.
- Send 1 byte of data and wait for an acknowledge.
- Solution: the sliding window protocol by TCP.
Both hosts use a window for each connection containing bytes that a host can send before worrying about an acknowledgment, called sliding windows. The window can slide over the buffer. TCP’s sliding windows are byte oriented. The size of the window at one end is determined by the minimum of two values:
- Receiver window (rwnd): Advertised by the opposite end in a segment containing acknowledgement.
- Congestion window (cwnd): Determined by the network to avoid congestion.
To avoid shrinking the sender window, the receiver must wait until more space is available in its buffer.
Congestion Control Mechanism
- Congestion control:
- Prevent congestion before it happens.
- Remove congestion after it happens.
- Two categories:
- Open-loop congestion control (prevention).
- Closed-loop congestion control (removal).
Open-Loop Congestion Control
Prevent congestion before it happens with possible policies:
- Retransmission policy: Retransmission policy and retransmission timer should be designed to optimize efficiency.
- Acknowledgment policy: Does not ACK every packet it receives.
- Discard policy: Router should adopt good discard policy.
Closed-Loop Congestion Control
Try to alleviate congestion after it happens with possible mechanisms:
- Back pressure: When a router is congested, it can inform the previous upstream router to reduce its outgoing rate. The action can be recursive all the way to the router just prior to the source.
- Choke Point: A router sends a packet to the source to inform congestion. This packet is called chock point, like ICMP’s source quench packet.
- Implicit signaling: Source can detect an implicit signal warning of congestion, for example, the delay in receiving an acknowledgment.
- Explicit signaling: Router can send an explicit signal to the sender or receiver of congestion, for example, set a bit in a packet.
TCP Format
TCP Connection Establishment
The client sends the first segment, a SYN segment. Set the SYN flag. The segment is used for synchronization of sequence number. Initialization sequence number (ISN). If client wants to define MSS, add MSS option. If client needs a larger window, define the window scale factor option. Does not contain any acknowledgment number. Does not define the window size either. A window size makes sense only when a segment includes an acknowledgment. Although a control segment and does not carry data, it consumes one sequence number.
The server sends a second segment, a SYN + ACK segment:
- Set the SYN and ACK flag.
- Acknowledge the receipt of the first segment using the ACK flag and acknowledgment number field.
- Acknowledgment number = client initialization sequence number + 1
- Must also define the receiver window size for flow control.
- SYN information for the server:
- Initialization sequence number from server to client.
- Window scale factor if used.
- MSS is defined.
The client sends the third segment, ACK segment:
- Acknowledge the receipt of second segment.
- ACK flag is set.
- Acknowledgement number = server initialization sequence number + 1
- Must also define the server window size.
- Set the window size field.
- The sequence number is the same as the one in the SYN segment.
- ACK segment does not consume any sequence number.
- However, in some implementation, data can be sent with the third packet.
- Must have a new sequence number showing the byte number of the first byte in the data.