# TCP 3-Way Handshake, AIMD Congestion Control & Routing (Distance Vector vs OSPF)
Exam: GATE Computer Science & Information Technology (GATE CS)
Subject: Computer Networks
Canonical URL: https://gateandnet.com/exams/gate-cs/computer-networks/tcp-congestion-control-and-routing-protocols

> TCP SYN/FIN sequence number consumption, Slow Start exponential growth vs Congestion Avoidance additive increase, 3-Dup-ACK vs Timeout cwnd transitions, and Count-to-Infinity.

## 1. TCP Connection Management & Sequence Numbers

- **SYN flag** consumes **1 sequence number** even if it carries 0 payload bytes!
  1. Client $\to$ Server: `SYN=1, Seq = x`
  2. Server $\to$ Client: `SYN=1, ACK=1, Seq = y, Ack = x + 1`
  3. Client $\to$ Server: `ACK=1, Seq = x + 1, Ack = y + 1` (can carry data!)
- **FIN flag** also consumes **1 sequence number**; pure **ACK** segments (with 0 data bytes) consume **0 sequence numbers**.
- After sending the final `ACK` in 4-way teardown, the active closer waits **$2 \times \text{MSL}$** in `TIME_WAIT` to absorb delayed duplicate segments and prevent port reuse collisions.

## 2. TCP Slow Start & AIMD Congestion Control

1. **Slow Start ($\text{cwnd} < \text{ssthresh}$):** Every ACK received increases $\text{cwnd}$ by $+1\text{ MSS}$ $\implies$ **$\text{cwnd}$ DOUBLES every 1 RTT** ($1 \to 2 \to 4 \to 8 \dots$).
2. **Congestion Avoidance ($\text{cwnd} \ge \text{ssthresh}$):** $\text{cwnd}$ increases by $+1\text{ MSS}$ **per entire RTT** (linear / additive increase).
3. **Loss Detection:**
   - **RTO Timeout (Severe congestion):** $\text{ssthresh} \leftarrow \lfloor \text{cwnd} / 2 \rfloor$, $\text{cwnd} \leftarrow 1\text{ MSS}$ (re-enters Slow Start).
   - **3 Duplicate ACKs (Mild loss in TCP Reno):** $\text{ssthresh} \leftarrow \lfloor \text{cwnd} / 2 \rfloor$, $\text{cwnd} \leftarrow \text{ssthresh}$ (Fast Retransmit + Fast Recovery — skips reset to 1 MSS!).

## 3. Routing Protocols Comparison

| Protocol | Algorithm | Metric | Key Exam Fact |
| :--- | :--- | :--- | :--- |
| **RIP (Intra-AS)** | Distance Vector (Bellman-Ford) | Hop Count ($infty = 16$) | Suffers **Count-to-Infinity**; partially mitigated by Split Horizon with Poison Reverse |
| **OSPF (Intra-AS)** | Link State (Dijkstra) | Bandwidth / Admin Cost | Floods Link-State Advertisements (LSAs) to all routers in area; loop-free convergence |
| **BGP (Inter-AS)** | Path Vector | Policy + AS-PATH | Runs over **TCP Port 179**; prevents inter-domain routing loops via full AS-PATH list |

## Solved Practice Questions & PYQs

### [GATE CS Networks | MCQ]
A TCP Reno connection currently has congestion window $\text{cwnd} = 32\text{ MSS}$ and $\text{ssthresh} = 24\text{ MSS}$. If a **Retransmission Timeout (RTO)** occurs, what become the new values of $\text{ssthresh}$ and $\text{cwnd}$?
**Correct Answer:** B
**Solution:** On an **RTO Timeout** (both TCP Tahoe and TCP Reno), $\text{ssthresh}$ is set to $\text{cwnd} / 2 = 32 / 2 = 16\text{ MSS}$, and $\text{cwnd}$ resets all the way to **$1\text{ MSS}$** (re-entering Slow Start). Only 3 Duplicate ACKs in Reno set $\text{cwnd} = 16\text{ MSS}$.

### [UGC NET / GATE CN | MCQ]
Which routing protocol suffers from the **Count-to-Infinity** problem when link failures occur?
**Correct Answer:** B
**Solution:** **Distance Vector (RIP)** exchanges only summary distance vectors with immediate neighbors using distributed Bellman-Ford, causing “bad news travels slowly” (**Count-to-Infinity**). OSPF/IS-IS flood complete topology LSAs, and BGP carries the full `AS-PATH`.
