```html Chapter 3: Transport Layer – Complete PDF Summary + Deep Dive

📡 TRANSPORT LAYER
Complete Chapter 3: Services · RDT · TCP · Congestion

Full PDF content + RDT deep comparison + Handshake & Checksum examples
📄 Chapter 3 (full summary v1) + extended sections — organized by original PDF order
📖 page 1⚙️ transport layer services & protocols
1. Transport Layer Services & Protocols

The transport layer provides logical communication between application processes on different hosts. It relies on network layer and enhances it for application use.

✂️ Segmentation

  • Breaks app messages into smaller units → segments
  • Passes them to network layer

🔄 Reassembly

  • On receiving side: reassembles segments into original messages
  • Delivers to correct application process

🌐 Key Internet Protocols

TCPUDP

🔄 Transport vs. Network Layer

  • Network layer: logical communication between hosts.
  • Transport layer: logical communication between processes (applications).
  • Transport enhances host-to-host delivery with process-level multiplexing.
طبقة النقل: توفر اتصالاً منطقياً بين العمليات (التطبيقات). التقسيم (segmentation) على المرسل وإعادة التجميع على المستقبل. البروتوكولات الرئيسية: TCP و UDP. طبقة الشبكة تواصل بين الأجهزة، طبقة النقل تواصل بين العمليات.
📖 page 2🔀 multiplexing/demultiplexing · UDP
3. Multiplexing & Demultiplexing

📤 Multiplexing (Sender)

  • Gathers data from multiple sockets
  • Adds transport header (source/dest ports)
  • Prepares segments for network layer

📥 Demultiplexing (Receiver)

  • Examines header (ports)
  • Delivers segment to correct socket → process
4. UDP: User Datagram Protocol
  • Connectionless & unreliable — no guarantee of delivery or ordering.
  • UDP Checksum: error detection (16-bit ones complement sum). Sender computes, receiver verifies; if mismatch → segment dropped.
  • Note: matching checksum does not guarantee no errors (only detection).

✅ UDP lightweight: no handshake, no connection state, minimal overhead. Used for streaming, DNS, SNMP.

Multiplexing: جمع البيانات من عدة sockets وإضافة رأس (ports). Demultiplexing: تسليم البيانات للعملية الصحيحة. UDP: غير موثوق وغير متصل، يقدم checksum لاكتشاف الأخطاء فقط.
📖 page 3📡 Reliable Data Transfer · Pipelining
5. Principles of Reliable Data Transfer (RDT)

Building reliable transfer on top of an unreliable channel. Complexity depends on underlying channel characteristics.

✅ Core RDT Principles

  • Error Detection
  • Acknowledgment (ACK)
  • Retransmission
  • Sequence Numbers
  • Flow Control

📈 RDT Evolution

  • rdt2.0/2.1/2.2: bit errors, ACK/NACK, sequence numbers (avoid duplicates).
  • rdt3.0: handles loss + errors → countdown timer; retransmit if ACK not received.

📊 Detailed Comparison: rdt2.0 / 2.1 / 2.2 vs rdt3.0

ProtocolHandles Bit Errors?Handles Packet Loss?ACK/NACK SchemeSequence NumbersTimer / RetransmissionKey Limitation / Improvement
rdt2.0✅ Yes (checksum)❌ NoACK + NACK (explicit negative ack)❌ No seq numbersNo timer (assumes no loss)Fails if packet lost; cannot handle duplicate packets due to no seq#
rdt2.1✅ Yes❌ No (still assumes loss-free channel)ACK and NAk✅ 0/1 seq bitsNo timer, but seq numbers prevent duplicate deliverySolves duplicate problem but still no loss recovery
rdt2.2✅ Yes❌ No (loss not handled)ACK‑only (no NACK, uses ACK for last received packet)✅ seq # 0/1No timer (loss not considered)NACK‑free version, but no loss recovery; prepares for timer extension
rdt3.0✅ Yes (checksum)✅ Yes (handles loss)ACK‑only, uses sequence numbers + countdown timer✅ 0/1 seq numbers✅ Timer per packet; timeout → retransmitHandles both corruption AND packet loss; stop‑and‑wait inefficient

📌 Key insight: rdt2.x family solves bit errors and duplicates using sequence numbers, but assumes no loss. rdt3.0 adds a timer to detect lost packets (data or ACK) and retransmits → complete reliable data transfer over an unreliable channel. However, rdt3.0 is stop‑and‑wait → leads to pipelined protocols (GBN, SR, TCP).

rdt2.0: يكتشف الأخطاء (checksum) لكن لا يعالج الفقد، يستخدم ACK و NACK. rdt2.1: يضيف أرقام تسلسلية لتجنب التكرار، لا يزال بدون مؤقت. rdt2.2: مشابه لـ2.1 لكن بدون NACK (يعتمد على ACK المتأخر). rdt3.0: يضيف مؤقت (timer) لإعادة الإرسال عند فقدان الحزمة أو الـACK، يتعامل مع الفقد والفساد.

🚀 6. Pipelined Protocols

rdt3.0 is stop‑and‑wait (inefficient). Pipelining allows multiple in‑flight packets → larger seq # range, buffering.

🔄 Go-Back-N (GBN)

  • Sender up to N unacked packets
  • Cumulative ACK
  • Single timer for oldest packet
  • Timeout → retransmit all outstanding packets

🎯 Selective Repeat (SR)

  • Individual ACK per packet
  • Timer per packet
  • Timeout → retransmit only lost packet
  • More efficient than GBN (avoids unnecessary retransmissions)
Go-Back-N: إعادة إرسال كل الحزم عند انتهاء المؤقت. Selective Repeat: أكثر كفاءة، يعيد فقط الحزمة المفقودة.
📖 page 4📦 TCP · Flow Control · Three‑Way Handshake (detailed)
7. TCP: Transmission Control Protocol
  • Point‑to‑point: single sender ↔ single receiver
  • Reliable, in-order byte stream (no message boundaries)
  • Pipelined: window‑based (similar to GBN/SR)
  • Full‑duplex: bidirectional data flow
  • Connection‑oriented: three‑way handshake before data
  • Flow control & congestion control

📊 8. TCP Flow Control

Prevents sender from overwhelming receiver’s buffer.

  • Receiver advertises rwnd (receive window) in every segment.
  • Sender limits unacked data to rwnd → buffer never overflows.

🤝 9. TCP Three‑Way Handshake – Detailed Explanation

🔹 Step 1: SYN (Client)

  • Client sends TCP segment with SYN=1, ACK=0.
  • Initial sequence number client_isn = x (random).
  • Client enters SYN_SENT state.
  • Purpose: request connection, advertise initial seq#.

🔸 Step 2: SYN+ACK (Server)

  • Server responds with SYN=1, ACK=1.
  • Server chooses its own seq# server_isn = y.
  • Acknowledgment number = x+1 (confirms receipt of client SYN).
  • Server enters SYN_RCVD.

🔹 Step 3: ACK (Client)

  • Client sends ACK segment: ACK=1, seq = x+1, ack = y+1.
  • Client → ESTABLISHED; upon receipt, server → ESTABLISHED.
  • Data can be piggybacked on this ACK.
📡 VISUAL HANDSHAKE
🖥️ Client                🧩 Server
|------ SYN (seq=x) ------------------->|
|<---- SYN+ACK (seq=y, ack=x+1) ------|
|------ ACK (seq=x+1, ack=y+1) ------->|
✅ ESTABLISHED        ✅ ESTABLISHED
  • Why three ways? Prevents old duplicate connection initiations (synchronizes seq numbers, allocates buffers, avoids half‑open connections).
  • SYN flood attack: attacker sends many SYN without final ACK → consumes server resources.
  • After handshake, both sides can send data: full‑duplex reliable stream.
Three‑way handshake: 1) العميل يرسل SYN (seq=x). 2) الخادم يرد بـ SYN+ACK (seq=y, ack=x+1). 3) العميل يرسل ACK (ack=y+1). بعدها يتم الاتصال (ESTABLISHED). تضمن مزامنة الأرقام التسلسلية ومنع الاتصالات القديمة.
📖 page 5⚠️ Congestion Control · Causes & Approaches
10. Principles of Congestion Control

Congestion occurs when “too many sources sending too much data too fast for the network to handle” (differs from flow control).

🚦 Manifestations

  • Packet loss (router buffer overflow)
  • Long delays (queueing in buffers)

💸 Costs & Causes

  • Retransmissions increase load (λ*_in > λ_in)
  • Premature timeouts → duplicate copies
  • Multihop congestion: throughput collapses when rates increase
11. Approaches to Congestion Control

📡 End‑to‑End Congestion Control

  • No explicit network feedback
  • End systems infer congestion from loss/delay
  • Used by TCP (loss‑based, delay‑based variants)

🏷️ Network‑Assisted Congestion Control

  • Routers provide explicit feedback (e.g., ECN bit)
  • Explicit rate notification possible
  • Example: ECN, ATM, some data center protocols

Key distinction: Flow control = receiver capacity; Congestion control = network capacity.

ECN (Explicit Congestion Notification): network‑assisted congestion control. Router sets a bit in IP header → receiver echoes to sender → sender reduces rate.

الازدحام: إرسال بيانات أكثر من طاقة الشبكة → خسارة حزم وتأخير. التكلفة: إعادة الإرسال تزيد الحمل. نهجان: end‑to‑end (TCP يستدل من الفقد) و network‑assisted (الموجهات ترسل إشارة مثل ECN).
🧮 UDP CHECKSUM ExampleConcrete numerical demonstration
UDP Checksum – Step-by-Step Example (Practical)

📌 Concept: Sender treats segment (header + data) as sequence of 16‑bit integers, computes ones' complement sum, places result in checksum field. Receiver recomputes and checks if result is all 1's (0xFFFF).


🔢 Example (simplified 16-bit words):
Suppose we have three 16-bit words: 1100 1010 0111 0001 (0xCA71)
                    1010 1010 0101 1111 (0xAA5F)
                    0111 0001 1100 1011 (0x71CB)

1. Summation (normal 16‑bit addition, wrap around carry):
Add first two: 0xCA71 + 0xAA5F = 0x174D0 → wrap carry (1) + 0x74D0 = 0x74D1
Add third: 0x74D1 + 0x71CB = 0xE69C   (no carry) → intermediate sum = 0xE69C
2. Ones' complement: ~0xE69C = 0x1963 (since 0xFFFF - 0xE69C = 0x1963).
✅ Checksum = 0x1963 (placed in UDP header).

3. Receiver verification: Receiver computes sum of all words including checksum field (0x1963). Total sum = 0xE69C + 0x1963 = 0xFFFF → all bits 1 → no error detected.

⚠️ Note: matching checksum indicates no error detected, but cannot guarantee zero errors (limited detection).

Why ones' complement? Endian‑independent, easy to compute, detects all errors affecting an odd number of bits, and simple to implement in hardware.
UDP checksum: تجمع الكلمات 16-bit باستخدام الجمع مع wrap-around، ثم تأخذ ones' complement. المرسل يضع الناتج في حقل المجموع. المستقبل يعيد الحساب، إذا كانت النتيجة 0xFFFF فلا خطأ مكتشف. المثال: كلمات CA71 + AA5F + 71CB → المجموع E69C → مكمل واحد = 1963. عند التحقق E69C+1963=FFFF.
📌 Summaryrwnd · cwnd · key takeaways
Flow Control vs Congestion Control Recap
  • Flow Control (receiver window rwnd): prevents sender from overwhelming receiver buffer. Advertised via TCP header.
  • Congestion Control (cwnd): prevents sender from overloading network. Dynamically adjusted based on loss/delay.
  • TCP sender effective window = min(rwnd, cwnd).
  • TCP uses pipelined sliding window, cumulative ACK, fast retransmit, and SACK option for efficiency.
📌 Key takeaway: rdt3.0 solves loss & corruption → pipelining (GBN/SR) → TCP integrates flow, congestion, and reliability.

📘 Chapter 3 Complete — Merged Edition (PDF order + extended content): full original summary (pages 1–5) + RDT comparison table (rdt2.0,2.1,2.2,3.0), deep three‑way handshake, UDP checksum numeric example, GBN vs SR, flow/congestion control. All sections placed according to original PDF sequence.

🔁 Use toggle buttons for Arabic translation of each major section.

```