[[TCP (Transmission Control Protocol)]] [[TCP Options]] ## Flow
Control - Balances the rate of data being created from the sender to the
rate of data that can be used - Send Window: - A buffer
of data to be sent is made and the data essentially queues up to be
sent. The data that is sent must have an acknowledgement before it can
be discarded from buffer. - Receive Window: - Works the
same way as Send Window. Bytes queue up in line to be moved into the
buffer, any that cannot be received will not be acknowledge and re-sent.
Once data is in the buffer it waits to be processed and once complete,
acknowledgement is sent to sender and data is pushed to next layer. -
Flow Control is based on feedback i.e acknowledgements to ensure that
the data has been received, processed and discarded correctly.
Error Control
- Ensures that data arrives to destination without any issues
- Error Control is based on the use of three tools
- Checksums
- Acknowledgements
- Time-Outs
Rules for Generating ACK
- When an end sends a data segment to the other end. It must have an
ACK as the ACK is the next sequence number that the end is
expecting.
- The receiver needs to delay sending an ACK segment if there is only
one outstanding in-order segment. This is to prevent extra ACK
traffic
- There should not be more than 2 in-order unacknowledged segments at
any time. It prevents unnecessary re-transmission.
- When a segment arrives with an out-of-order sequence number that is
higher than expected, the receiver immediately send an ACK segment
announcing the next expected segment.
- 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 immediately sends an
ACK.
- Note: Lost acknowledgements may create deadlock if
they are not handled properly.
Congestion Control
- TCP uses a congestion window and a congestion policy to avoid
congestion and to detect and alleviate congestion after it has
occurred.
- rwnd = receive window
- cwnd = congestion window
- Three Phases:
- 1 Slow Start, Exponential Increase
- cwnd starts at the MSS (max segment size). Doubles until cwnd =
ssthresh
- MSS = (MTU - IP hdr len - TCP hdr len)
- 2 Congestion Avoidance, Additive Increase
- When cwnd = slow start threshold, stop exponential increase
- cwnd increases by 1 for every “window” it sends
- Continues to increase until congestion is detected
- 3 Congestion Detection, Multiplicative Decrease
- Congestion detection occurs when a sender has to re-transmit a
segment.
- A re-transmission can occur due to:
- Re transmission time-out (RTO) expires
- Receive 3 ACKs for the same segment (fast re-transmit
condition)
- When congestion is detected, the threshold is cut in half
- When congestion is due to RTO: set cwnd = 1, start at Phase 1 (worst
case scenario)
- When congestion is due to fast re-transmit: set cwnd = threshold,
start Phase 2
TCP Timers
- To perform smooth operation, most TCP implementations use at least
four timers
- Retransmission Timer (RTO)
- Waits for ACK, sends first segment not ACK’d if it expires
- Based on round trip time (RTT)
- Persistence Timer - Starts when a zero-window size packed is
received; probe segment sent to get and ACK
- Keepalive Timer - used when a connection is open, but no dat is
flowing; probe segment sent to get an ACK
- TIME-WAIT Timer - Has to do with closing connections
Selective Acknowledgement
(SACK)
- Allows the sender to have a better idea of which segments are
actually lost and which have arrives out of order.
- Two parts:
- SACK permitted: As an option during three way handshake
- SACK option: As an option during ACKs
- SACK options includes a list for blocks arriving out of order
- 32-bit blocks that define the beginning and the end of the blocks
received. -> 8 bytes per block, plus the SACK option of 2 bytes
- Up to 4 blocks may be specified (40 byte options limit)