📚 Introduction to TCP Protocol

The Transmission Control Protocol (TCP) is a fundamental transport layer protocol in the Internet protocol suite. It provides reliable, ordered, and error-checked delivery of data between applications running on hosts communicating over an IP network.

Key Characteristics of TCP:
• Connection-oriented communication (requires establishing connection before data transfer)
• Full-duplex service (data flows in both directions simultaneously)
• Reliable delivery through acknowledgments and retransmissions
• Flow control using sliding window mechanism
• Congestion control to prevent network overload

TCP Segment Structure

TCP Header Format (20-60 bytes)
Field Size (bits) Description
Source Port 16 Sender's port number
Destination Port 16 Receiver's port number
Sequence Number 32 Byte stream position
Acknowledgment Number 32 Next expected byte
Data Offset 4 Header length in 32-bit words
Flags (SYN, ACK, FIN, etc.) 6 Control bits
Window Size 16 Receive buffer space available
Checksum 16 Error detection
Urgent Pointer 16 Priority data indicator

Core Mechanisms

🔐 Reliability Mechanisms

  • Sequence Numbers: Track byte ordering
  • Acknowledgments: Confirm receipt of data
  • Retransmission: Timeout-based and fast retransmit
  • Checksum: Error detection in header and data

⚡ Performance Mechanisms

  • Sliding Window: Flow control optimization
  • Slow Start: Exponential window growth
  • Congestion Avoidance: Linear window growth
  • Fast Recovery: Rapid loss recovery

🎯 Learning Objectives

1

Understand Connection Management

Master the three-way handshake process for connection establishment and the four-way handshake for connection termination.

2

Analyze Sliding Window Protocol

Investigate how TCP uses sliding windows for flow control and efficient data transmission.

3

Study Congestion Control Algorithms

Examine slow start, congestion avoidance, fast retransmit, and fast recovery mechanisms.

4

Measure Performance Metrics

Calculate throughput, RTT, window sizes, and analyze the sawtooth pattern of congestion windows.

🤝 TCP Connection Establishment (3-Way Handshake)

Before data transmission begins, TCP establishes a connection using a three-way handshake to synchronize sequence numbers and acknowledge each other's readiness.

Interactive Handshake Visualization

📱
Client
Initiator
🖥️
Server
Listener
Ready to initiate connection...

Step-by-Step Process

STEP 1: SYN
Client
Server
Client sends SYN (synchronize) packet with initial sequence number (ISN)
SYN=1, SEQ=x
STEP 2: SYN-ACK
Client
Server
Server responds with SYN-ACK packet acknowledging client's SYN
SYN=1, ACK=1, SEQ=y, ACK=x+1
STEP 3: ACK
Client
Server
Client acknowledges server's SYN; connection ESTABLISHED
ACK=1, SEQ=x+1, ACK=y+1
State Transitions:
Client: CLOSED → SYN_SENT → ESTABLISHED
Server: LISTEN → SYN_RECEIVED → ESTABLISHED

👋 Connection Termination (4-Way Handshake)

TCP uses a four-way handshake to gracefully close connections, allowing both sides to finish transmitting data independently.

Client
Server
FIN=1, SEQ=u (Client wants to close)
Client
Server
ACK=1, SEQ=v, ACK=u+1 (Server acknowledges)
Client
Server
FIN=1, SEQ=v, ACK=u+1 (Server wants to close)
Client
Server
ACK=1, SEQ=u+1, ACK=v+1 (Client acknowledges)

🪟 Sliding Window Protocol

TCP uses a sliding window mechanism for flow control, allowing the sender to transmit multiple packets before requiring an acknowledgment, thus improving network utilization and throughput.

Interactive Sliding Window Simulator

4 packets
Sender Buffer Window: 4 | Sent: 0 | Acked: 0
> Ready to transmit...

Window Variables

Send Window

  • LastByteSent: Highest seq # sent
  • LastByteAcked: Highest seq # acked
  • LastByteWritten: Highest seq # from app
EffectiveWindow = AdvertisedWindow - (LastByteSent - LastByteAcked)

Receive Window

  • LastByteRead: Highest seq # read by app
  • NextByteExpected: Next seq # expected
  • LastByteRcvd: Highest seq # received
AdvertisedWindow = RcvBuffer - (LastByteRcvd - LastByteRead)
Cumulative Acknowledgments: TCP uses cumulative ACKs where ACK N confirms receipt of all bytes up to sequence number N-1. This allows for efficient acknowledgment of multiple packets with a single ACK segment.

🚦 TCP Congestion Control

Congestion control prevents network overload by dynamically adjusting the transmission rate based on perceived network conditions. TCP uses the AIMD (Additive Increase Multiplicative Decrease) algorithm combined with Slow Start.

Slow Start Threshold (ssthresh)

65535 bytes

Congestion Window (cwnd)

1 MSS

Current Phase

Slow Start

Round Trip Time

100 ms
Congestion Window (cwnd)
Slow Start Threshold
Packet Loss Event
16 MSS
5%

Congestion Control Phases

1. Slow Start

Exponential growth phase at connection start or after timeout.

cwnd = cwnd + MSS per ACK

Window doubles every RTT until ssthresh is reached or loss occurs.

2. Congestion Avoidance

Linear growth phase to probe for available bandwidth.

cwnd = cwnd + MSS×(MSS/cwnd) per ACK

Window increases by 1 MSS per RTT (linear growth).

3. Fast Retransmit

Triggered by 3 duplicate ACKs. Retransmit lost segment immediately without waiting for timeout.

4. Fast Recovery

After fast retransmit, inflate cwnd and continue with congestion avoidance (Reno) or slow start (Tahoe).

🎮 Comprehensive TCP Simulator

This integrated simulation demonstrates the complete TCP lifecycle including connection establishment, data transfer with sliding windows, and congestion control mechanisms.

📤 Sender (Client)

State: CLOSED
Seq: 0
CWND: 1 MSS
Flight Size: 0

📥 Receiver (Server)

State: LISTEN
Seq: 0
Window: 65535
Expected: 0
5x
5%
100 ms
Event Log:
[System] Ready to start simulation...

🧪 Laboratory Procedure

Experiment 1: TCP Connection Establishment

1

Setup

Open the 3-Way Handshake tab. Set the initial sequence numbers for both client and server (ISN). Observe the default values (typically random 32-bit values).

2

Execute Handshake

Click "Simulate Handshake" and observe the packet exchange. Record the SEQ and ACK numbers at each step in your observation table.

3

State Transition Analysis

Note the state changes: CLOSED → SYN_SENT → ESTABLISHED (client) and LISTEN → SYN_RCVD → ESTABLISHED (server).

4

Connection Teardown

Study the 4-way termination process. Understand the TIME_WAIT state and its purpose (2×MSL wait).

Experiment 2: Sliding Window Protocol

1

Window Size Variation

Set different window sizes (1, 4, 8 packets). Observe how the number of outstanding packets affects throughput.

2

Packet Loss and Recovery

Simulate packet loss by selecting a packet to drop. Observe Go-Back-N behavior vs Selective Repeat concepts.

3

Flow Control

Observe how the receive window advertisement limits the sender's transmission rate.

Experiment 3: Congestion Control

1

Slow Start Observation

Set ssthresh to 16 MSS. Start simulation and observe exponential growth of cwnd (1, 2, 4, 8, 16).

2

Congestion Avoidance

Continue simulation beyond ssthresh. Observe linear growth (16, 17, 18, 19...) until packet loss.

3

Loss Detection Comparison

Compare Tahoe (cwnd → 1 on loss) vs Reno (cwnd → ssthresh on 3 dup ACKs) behavior.

4

Sawtooth Pattern

Plot the congestion window over time. Identify the characteristic "sawtooth" pattern of TCP.

Safety Notes:
• This is a simulation environment - no actual network traffic is generated
• Record all observations immediately as simulations may run quickly
• Use the Step button for detailed analysis of protocol behavior
• Compare theoretical calculations with simulation results

📊 Observation Tables

Table 1: Three-Way Handshake

Step Direction Flags Sequence Number Ack Number Client State Server State
1 Client → Server SYN=1 x 0 SYN_SENT LISTEN
2 Server → Client SYN=1, ACK=1 y x+1 SYN_SENT SYN_RCVD
3 Client → Server ACK=1 x+1 y+1 ESTABLISHED ESTABLISHED

Table 2: Congestion Window Growth

RTT # Phase cwnd (MSS) ssthresh (MSS) Segments Sent Event
0 Slow Start 1 16 1 Connection start
1 Slow Start 2 16 2 -

📝 Laboratory Report Guidelines

1. Title Page

  • Experiment Title: TCP Protocol Analysis
  • Course Code and Name
  • Student Name and ID
  • Date of Experiment
  • Instructor Name

2. Objectives

  • Understand TCP connection establishment and termination
  • Analyze sliding window mechanism for flow control
  • Investigate congestion control algorithms (Slow Start, AIMD)
  • Measure and calculate throughput and RTT
  • Compare TCP variants (Tahoe, Reno, CUBIC)

3. Theory (Minimum 500 words)

  • Overview of TCP protocol and its position in TCP/IP stack
  • Detailed explanation of 3-way and 4-way handshake
  • Mathematical analysis of sliding window protocol
  • Congestion control algorithms with equations
  • Difference between Flow Control and Congestion Control

4. Experimental Procedure

  • Step-by-step methodology followed
  • Screenshot of simulation parameters
  • Description of test cases executed
  • Tools and configurations used

5. Results and Analysis

  • Completed observation tables with actual values
  • Graphs: CWND vs Time (sawtooth pattern)
  • Sequence number plots showing data transfer
  • State transition diagrams
  • Throughput calculations: Throughput = (Window Size × MSS × 8) / RTT
  • Comparison between theoretical and simulated results

6. Discussion Questions (Answer All)

  • Q1: Why does TCP use a 3-way handshake instead of 2-way?
  • Q2: Explain the role of sequence numbers in reliability.
  • Q3: What happens if the initial ssthresh is set too high or too low?
  • Q4: Compare the fairness of TCP when multiple flows share a bottleneck.
  • Q5: Why does TCP use AIMD and not AIAD or MIMD?

7. Conclusion

  • Summary of key findings
  • Validation of TCP behavior against RFC specifications
  • Practical implications in real networks
  • Limitations of the simulation

8. References

  • RFC 793 - Transmission Control Protocol
  • RFC 5681 - TCP Congestion Control
  • Course textbook (Chapter on Transport Layer)
  • Any additional academic papers cited
Grading Rubric:
• Theory & Background (20%)
• Experimental Setup (15%)
• Data Collection & Accuracy (25%)
• Analysis & Discussion (25%)
• Presentation & Formatting (15%)

Total: 100 points

📋 Pre-Submission Checklist

  • All tables filled with actual simulation data
  • Graphs properly labeled with axes and units
  • Calculations shown step-by-step
  • All discussion questions answered
  • No plagiarism - cite all sources
  • PDF format, max 15 pages
  • File named: TCP_Lab_StudentID.pdf