Transport Layer: TCP vs UDP
⭐ CSJMU PYQs:
2024–25, 2023–24, 2021, 2018 (Asked almost every year for 5–10 marks — Core Comparison!)
🎯 Learning Objectives:
⚡ Essential Pass Content
- Understand process-to-process communication using Socket Addressing (IP + Port Number).
- Contrast Connection-Oriented byte streams (TCP) with Connectionless datagrams (UDP).
- Analyze reliability trade-offs (retransmissions vs real-time latency).
| Evaluation Parameter | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
|---|---|---|
| Connection Paradigm | Connection-Oriented; requires a formal 3-way handshake to establish a virtual session before sending payload. | Connectionless; sends independent datagrams directly without prior negotiation or session state. |
| Transmission Reliability | 100% Guaranteed Reliability; uses sequence numbers, positive ACKs, checksums, and automatic retransmission (ARQ). | Unreliable ("Best Effort"); packets may be dropped, duplicated, or arrive out of order with zero retransmission. |
| Header Overhead | Heavy: 20 to 60 bytes (includes sequence numbers, acknowledgment numbers, window sizes, flags). | Lightweight: 8 bytes fixed (Source Port, Destination Port, Length, Checksum). |
| Data Transfer Stream | Continuous Byte Stream; packets are segmented, numbered, and reassembled into the exact original order. | Discrete Message/Datagram Stream; packet boundaries are preserved as separate units. |
| Flow & Congestion Control | Comprehensive; uses Sliding Window (flow control) and Congestion Windows (Slow Start, Congestion Avoidance, AIMD). | None; transmits as fast as the application generates data regardless of network buffer status. |
| Speed & Latency | Slower; handshakes, acknowledgments, and retransmission delays introduce latency. | Extremely fast & real-time; zero connection overhead or wait states. |
| Practical Applications | Web browsing (HTTP/HTTPS), File transfers (FTP), Email (SMTP/IMAP), Secure shell (SSH). | Live video streaming (YouTube Live), VoIP calls (WhatsApp/Zoom), DNS lookups, DHCP, Online multiplayer gaming. |
TCP Segment Header Architecture
⭐ CSJMU PYQs:
2024–25, 2022, 2019 (Draw and explain the TCP header format and all 6 control flags — 10 Marks!)
A TCP header has a minimum length of 20 bytes (when options are absent) and a maximum of 60 bytes:
| Field Name | Bit Size | Functional Description |
|---|---|---|
| Source Port Address | 16 bits | Identifies the sending application process on the source host. |
| Destination Port Address | 16 bits | Identifies the receiving application process on the destination host. |
| Sequence Number | 32 bits | Identifies the position of the first data byte in this segment relative to the total byte stream. |
| Acknowledgment Number | 32 bits | Valid if ACK flag is set; indicates the next expected byte number the receiver anticipates receiving. |
| Header Length (HLEN) | 4 bits | Specifies header length in 32-bit (4-byte) words. Minimum value is $5$ ($5 \times 4 = 20$ bytes). |
| Reserved | 6 bits | Reserved for future definition (must be 0). |
| Control Flags | 6 bits | Six 1-bit flags controlling connection state: URG, ACK, PSH, RST, SYN, FIN. |
| Window Size | 16 bits | Advertises receiver's available buffer capacity for sliding-window flow control. |
| Checksum | 16 bits | Mandatory 16-bit 1's complement checksum covering TCP header, payload, and pseudo-IP header. |
| Urgent Pointer | 16 bits | Valid only if URG flag is set; points to the end of urgent out-of-band data. |
The 6 TCP Control Flags (Guaranteed 5-Mark Question):
- URG (Urgent): Indicates that the Urgent Pointer field is valid and data should be processed with top priority.
- ACK (Acknowledgment): Indicates that the Acknowledgment Number field contains valid confirmation data.
- PSH (Push): Instructs the receiver to push buffered data immediately to the application without waiting for buffers to fill.
- RST (Reset): Aborts and resets an invalid or broken connection immediately.
- SYN (Synchronize): Initiates a connection and synchronizes initial sequence numbers during the 3-way handshake.
- FIN (Finish): Indicates that the sender has finished transmitting data and requests graceful connection termination.
TCP Connection Management: 3-Way Handshake & 4-Way Teardown
⭐ CSJMU PYQs:
2025–26, 2023–24, 2021, 2017 (Complete sequence diagrams for establishment and termination)
1. Connection Establishment (3-Way Handshake):
🎬
Animated Video Explainer: TCP 3-Way Handshake Connection
🎙️ Sarvam AI Voice Sync
Connection Setup: Server is listening; Client initiates handshake.
Hindi Samjhaun: Server port 80 par wait kar raha hai; Client connection request bhejta hai.
2. Connection Termination (4-Way Handshake / Graceful Teardown):
The TCP 4-Way Handshake Connection Termination Flow
TCP Flow Control vs. Congestion Control
| Dimension | TCP Flow Control | TCP Congestion Control |
|---|---|---|
| Focus | Prevents a fast sender from overwhelming a slow receiver. | Prevents all senders from overwhelming the intermediate network links & routers. |
| Governing Window | Advertised Window ($rwnd$) advertised by the receiver in the TCP header. | Congestion Window ($cwnd$) maintained dynamically by the sender based on perceived network state. |
| Transmission Limit | Sender can transmit at most: $\mathbf{W = \min(rwnd, cwnd)}$ | |
The 4 TCP Congestion Control Algorithms (AIMD Sawtooth Cycle):
- Slow Start: The sender starts with $cwnd = 1 \text{ MSS}$ (Maximum Segment Size). For every incoming ACK, $cwnd$ increases by 1 MSS. Thus, $cwnd$ doubles every Round-Trip Time (RTT) ($1 \to 2 \to 4 \to 8 \dots$, exponential growth) until reaching the threshold $ssthresh$.
- Congestion Avoidance: When $cwnd \ge ssthresh$, growth switches from exponential to Additive Increase: $cwnd$ increases by strictly $+1 \text{ MSS}$ per RTT (linear ramp).
- Fast Retransmit: If the sender receives 3 duplicate ACKs for the same segment, it assumes that specific packet was lost in transit and retransmits it immediately, without waiting for the slow retransmission timer to expire!
- Fast Recovery: Instead of dropping all the way back to $cwnd = 1$, the sender performs Multiplicative Decrease: $$ssthresh = \frac{cwnd}{2}, \quad cwnd = ssthresh + 3 \text{ MSS}$$ The sender continues in congestion avoidance, preserving high throughput and creating the famous TCP Sawtooth Curve!
Application Layer Protocols: DNS, Email (SMTP/POP3/IMAP) & Web
⭐ CSJMU PYQs:
2024–25, 2022, 2017 (DNS hierarchy, SMTP vs POP3/IMAP, and port numbers)
| Protocol | Default Port | Transport Protocol | Core Function & Directionality |
|---|---|---|---|
| DNS (Domain Name System) | Port 53 | UDP (queries) / TCP (zone transfers) | Translates human-readable domain names (e.g. google.com) into 32-bit IPv4 or 128-bit IPv6 addresses via hierarchical trees (Root $\to$ TLD $\to$ Authoritative). |
| SMTP (Simple Mail Transfer) | Port 25 / 587 | TCP | Push Protocol: Uploads outgoing emails from sender's client to mail server, and transfers emails between intermediary mail servers. |
| POP3 (Post Office Protocol 3) | Port 110 | TCP | Pull Protocol: Downloads emails to a single local device and deletes them from the server by default (single-device model). |
| IMAP (Internet Message Access) | Port 143 | TCP | Pull Protocol: Synchronizes folders, read/unread states, and messages across multiple devices (phone, laptop) while preserving copies on the server. |
| HTTP / HTTPS | Port 80 / 443 | TCP | Transfers hypertext web documents; HTTPS encrypts traffic using TLS/SSL to prevent eavesdropping and MITM attacks. |
| FTP (File Transfer Protocol) | Port 21 (control) & Port 20 (data) | TCP | Uses two separate connections: Port 21 sends commands (user, pass, get), Port 20 streams actual file data bytes. |
Cryptography: Symmetric vs Asymmetric & The RSA Algorithm
⭐ CSJMU PYQs:
2025–26, 2023–24, 2020, 2016 (Symmetric vs Asymmetric, RSA algorithm, and Digital Signatures — 15 Marks!)
⚡ Essential Pass Content
| Evaluation Parameter | Symmetric Key Cryptography (Secret Key) | Asymmetric Key Cryptography (Public Key) |
|---|---|---|
| Number of Keys | One single secret key shared by both sender and receiver. | Two mathematically linked keys: Public Key (open) + Private Key (kept secret). |
| Encryption / Decryption | Same key encrypts and decrypts: $C = E_K(P), P = D_K(C)$. | Public key encrypts $\to$ Only matching Private key can decrypt. |
| Key Distribution Problem | Major problem: How to securely share the secret key over an untrusted network? | Solved: Public key can be broadcast freely to the entire world without secrecy. |
| Computational Speed | Extremely fast; ideal for encrypting multi-gigabyte databases and video streams. | Computationally slow; relies on heavy modular exponentiation of large prime numbers. |
| Standard Algorithms | DES (56-bit), 3DES (168-bit), AES (128, 192, 256-bit). | RSA (Rivest-Shamir-Adleman), Diffie-Hellman, ECC (Elliptic Curve). |
📝 Master Solved University RSA Numerical (Step-by-Step):
In an RSA cryptosystem, choose prime numbers $p = 3$ and $q = 11$. Given public encryption exponent $e = 7$, encrypt plaintext message $M = 2$ and decrypt the resulting ciphertext $C$.
In an RSA cryptosystem, choose prime numbers $p = 3$ and $q = 11$. Given public encryption exponent $e = 7$, encrypt plaintext message $M = 2$ and decrypt the resulting ciphertext $C$.
Step 1: Compute Modulus $n$:
$$n = p \times q = 3 \times 11 = \mathbf{33}$$
$$n = p \times q = 3 \times 11 = \mathbf{33}$$
Step 2: Compute Euler's Totient $\phi(n)$:
$$\phi(n) = (p - 1)(q - 1) = (3 - 1)(11 - 1) = 2 \times 10 = \mathbf{20}$$
$$\phi(n) = (p - 1)(q - 1) = (3 - 1)(11 - 1) = 2 \times 10 = \mathbf{20}$$
Step 3: Verify Public Exponent $e$:
Given $e = 7$. Check: $1 < e < \phi(n)$ and $\gcd(7, 20) = 1$ (coprime ✓).
Public Key: $\{e, n\} = \{\mathbf{7, 33}\}$.
Given $e = 7$. Check: $1 < e < \phi(n)$ and $\gcd(7, 20) = 1$ (coprime ✓).
Public Key: $\{e, n\} = \{\mathbf{7, 33}\}$.
Step 4: Compute Private Decryption Exponent $d$:
Condition: $d \cdot e \equiv 1 \pmod{\phi(n)} \implies 7d \equiv 1 \pmod{20}$
Find integer $k$ such that $7d = 20k + 1$:
• For $k = 1$: $7d = 21 \implies d = \frac{21}{7} = \mathbf{3}$
Private Key: $\{d, n\} = \{\mathbf{3, 33}\}$.
Condition: $d \cdot e \equiv 1 \pmod{\phi(n)} \implies 7d \equiv 1 \pmod{20}$
Find integer $k$ such that $7d = 20k + 1$:
• For $k = 1$: $7d = 21 \implies d = \frac{21}{7} = \mathbf{3}$
Private Key: $\{d, n\} = \{\mathbf{3, 33}\}$.
Step 5: Encryption of Plaintext $M = 2$:
$$C = M^e \pmod n = 2^7 \pmod{33} = 128 \pmod{33}$$ $128 = 3 \times 33 + 29 = 99 + 29 \implies \mathbf{C = 29}$. Ciphertext is 29!
$$C = M^e \pmod n = 2^7 \pmod{33} = 128 \pmod{33}$$ $128 = 3 \times 33 + 29 = 99 + 29 \implies \mathbf{C = 29}$. Ciphertext is 29!
Step 6: Decryption of Ciphertext $C = 29$:
$$M = C^d \pmod n = 29^3 \pmod{33}$$ Notice: $29 \equiv -4 \pmod{33}$
$$29^3 \equiv (-4)^3 = -64 \pmod{33}$$ $$-64 = -2 \times 33 + 2 \implies \mathbf{M = 2}$$ Verification: Original plaintext $M = 2$ recovered perfectly!
$$M = C^d \pmod n = 29^3 \pmod{33}$$ Notice: $29 \equiv -4 \pmod{33}$
$$29^3 \equiv (-4)^3 = -64 \pmod{33}$$ $$-64 = -2 \times 33 + 2 \implies \mathbf{M = 2}$$ Verification: Original plaintext $M = 2$ recovered perfectly!
Digital Signatures & Non-Repudiation:
A Digital Signature provides authenticity, integrity, and non-repudiation:
A Digital Signature provides authenticity, integrity, and non-repudiation:
- Signing: The sender generates a cryptographic hash of the document (e.g. SHA-256) and encrypts the hash using the Sender's Private Key.
- Verification: The receiver decrypts the signature using the Sender's Public Key and compares it with the freshly computed hash of the received document.
- If the hashes match, it guarantees that: (1) The document was not altered in transit, and (2) The sender cannot deny having sent it (Non-repudiation)!
Exam Answer Blueprint & Pitfalls to Avoid
How to Score Full 10 Marks on "TCP vs UDP & 3-Way Handshake":
- Comparison Table (4 Marks): Create a clean 6-row table comparing connection model, reliability, headers (20B vs 8B), flow control, and application examples.
- Handshake Timeline Diagram (3 Marks): Draw client and server vertical axes with arrows: SYN (Seq=x) $\to$ SYN+ACK (Seq=y, Ack=x+1) $\to$ ACK (Seq=x+1, Ack=y+1).
- Step Explanations (2 Marks): Explain what happens at each step (ISN negotiation, buffer allocation).
- Teardown Mention (1 Mark): State that termination requires a 4-way handshake using FIN and ACK flags.
⚠️ Common Exam Pitfalls:
• Confusing Public and Private Keys in Encryption vs Signing: For confidentiality, encrypt with the Receiver's Public Key. For digital signatures, encrypt with the Sender's Private Key! Mixing these up loses 5 marks!
• Calculating $\phi(n)$ incorrectly: Remember that $\phi(n) = (p-1)(q-1)$, NOT $p \times q$! Modulus $n = p \times q$, but totient uses $(p-1)(q-1)$!
• Confusing Public and Private Keys in Encryption vs Signing: For confidentiality, encrypt with the Receiver's Public Key. For digital signatures, encrypt with the Sender's Private Key! Mixing these up loses 5 marks!
• Calculating $\phi(n)$ incorrectly: Remember that $\phi(n) = (p-1)(q-1)$, NOT $p \times q$! Modulus $n = p \times q$, but totient uses $(p-1)(q-1)$!
Unit V Exam Mastery MCQ Quiz (10 Questions)
Answer all 10 questions covering TCP/UDP, 3-way handshake, email protocols, and cryptography.