Data CommunicationUnit 815 min read
Layered Protocols & OSI Model: How Networks Talk
Unit 8 of Data Communication: Explores how networks break communication into layers (OSI model), how protocols like TCP/IP work, and how real-world apps (eSewa, WhatsApp) use these layers to send data reliably.
TAKEAWAYS:
- Networks use 7-layer OSI model to organize functions (e.g., physical cables, IP addresses, encryption) into logical layers.
- Layered design isolates changes (e.g., upgrading Wi-Fi without breaking apps) and reuses components (e.g., TCP’s flow control in WhatsApp).
- Protocols (like HTTP, TCP) define rules for each layer (e.g., TCP’s stop-and-wait ARQ for error recovery).
- Virtual circuits (e.g., VoIP calls) vs. datagrams (e.g., YouTube video chunks) trade reliability for speed.
- Real-world apps (eSewa payments, Daraz orders) rely on OSI layers to handle security, routing, and delivery.
- Exam focus: Compare OSI vs. TCP/IP, explain flow control (ARQ), and trace a packet’s journey through layers.
1. Why Layers? The OSI Model’s Purpose
Networks would be chaotic if every device reinvented communication rules. The Open Systems Interconnection (OSI) model solves this by splitting tasks into 7 layers, each with clear responsibilities. This lets devices from different makers (e.g., NTC router + Samsung phone) work together.
figure: OSI Model Layers
```mermaid
classDiagram
class Layer1 { Physical: bits, cables, signals }
class Layer2 { Data Link: frames, MAC, switching }
class Layer3 { Network: IP, routing, addressing }
class Layer4 { Transport: TCP/UDP, flow control }
class Layer5 { Session: connections, sync }
class Layer6 { Presentation: encryption, compression }
class Layer7 { Application: HTTP, FTP, apps }
Layer1 --> Layer2 : "Uses"
Layer2 --> Layer3 : "Uses"
Layer3 --> Layer4 : "Uses"
Layer4 --> Layer5 : "Uses"
Layer5 --> Layer6 : "Uses"
Layer6 --> Layer7 : "Uses"
Key Idea: Each layer hides complexity from the layer above. For example:
- Layer 1 (Physical): Your phone’s antenna sends raw radio waves (0s and 1s).
- Layer 2 (Data Link): Your phone’s Wi-Fi chip adds a frame header (e.g., MAC address) to group bits into packets.
- Layer 7 (Application): WhatsApp’s app layer adds metadata (e.g., "this is a text message") before sending.
2. The 7 OSI Layers: What Each Does
| Layer | Name | Key Functions | Example Protocol/Device |
|---|---|---|---|
| 7 | Application | User interfaces, app protocols (HTTP, SMTP, WhatsApp) | WhatsApp, eSewa API |
| 6 | Presentation | Data translation, encryption (SSL), compression | TLS (HTTPS), JPEG compression |
| 5 | Session | Manages connections (e.g., keeps a call alive) | NetBIOS, RPC |
| 4 | Transport | End-to-end delivery, flow control, error recovery (TCP), speed (UDP) | TCP (WhatsApp), UDP (YouTube video) |
| 3 | Network | Logical addressing (IP), routing (IPv4/IPv6) | Routers, BGP, ICMP |
| 2 | Data Link | Framing, MAC addresses, error detection (CRC), switching (Ethernet, Wi-Fi) | Switches, MAC addresses |
| 1 | Physical | Raw bit transmission (cables, signals, frequencies) | Ethernet cables, Wi-Fi antennas |
Visual: How a WhatsApp message travels through layers:
figure: WhatsApp Message Layers
```figure
{"type":"layers","layers":["Application (WhatsApp)","Presentation (TLS)","Session","Transport (TCP)","Network (IP)","Data Link (Ethernet)","Physical (Wi-Fi)"],"right":["Message","Encrypted Data","Connection","Segment","Packet","Frame","Bits"],"highlight":["Transport","Network","Data Link","Physical"],"caption":"Layer-by-layer breakdown of a WhatsApp message transmission"}
3. Why Layered Design Matters: Real-World Examples
In the Real World
eSewa Payments (Layer 7 + 6)
- When you pay via eSewa, Layer 7 (Application) handles the UI and business logic (e.g., "transfer NPR 100 to friend").
- Layer 6 (Presentation) encrypts the transaction (SSL/TLS) to protect your data.
- Layer 4 (Transport) ensures the payment request isn’t lost (TCP’s flow control).
WhatsApp Calls (Layer 4 + 3)
- WhatsApp uses UDP (Layer 4) for voice calls because it prioritizes speed over reliability (voice packets can be slightly delayed but not lost).
- Layer 3 (Network) routes the call through NTC’s servers globally.
Daraz Order Queue (Layer 2 + 3)
- When you order on Daraz, Layer 2 (Data Link) ensures your request reaches the server’s switch without errors (using MAC addresses).
- Layer 3 (Network) routes your request to the nearest Daraz data center (using IP addresses).
4. OSI vs. TCP/IP: The Two Most Used Models
Most modern networks (including the internet) use the TCP/IP model, which is simpler (4 layers) but functionally similar to OSI.
| Feature | OSI Model (7 Layers) | TCP/IP Model (4 Layers) |
|---|---|---|
| Layers | Physical, Data Link, Network, Transport, Session, Presentation, Application | Network Access (Physical + Data Link), Internet (Network), Transport, Application |
| Flexibility | More granular (e.g., separates Session/Presentation) | Combined layers (e.g., Internet layer handles IP + some Data Link) |
| Use Case | Academic/standardization | Practical (internet, most devices) |
| Example | Explains how a printer’s driver (Presentation) formats data | Explains how HTTP (Application) works over TCP (Transport) |
Visual: TCP/IP vs. OSI alignment:
figure: OSI vs TCP/IP
```figure
{"type":"tree","root":{"v":"OSI Model (7 Layers)","children":[{"v":"Application (L7)","children":[{"v":"HTTP, FTP, DNS"},{"v":"Session (L5)","children":[{"v":"NetBIOS, RPC"}]},{"v":"Presentation (L6)","children":[{"v":"SSL/TLS, JPEG"}]}]},{"v":"Transport (L4)","children":[{"v":"TCP, UDP"}]},{"v":"Network (L3)","children":[{"v":"IP, ICMP, Routing"}]},{"v":"Data Link (L2)","children":[{"v":"Ethernet, MAC, Switching"}]},{"v":"Physical (L1)","children":[{"v":"Cables, Signals, Wi-Fi"}]}]}}
5. Layered Protocols in Action: TCP’s Flow Control
Problem: If a slow device (e.g., a feature phone) tries to send data to a fast server, the server gets overwhelmed. Solution: Flow Control (Layer 4) ensures sender and receiver agree on a window size (how many packets to send before waiting for acknowledgments).
Stop-and-Wait ARQ (Automatic Repeat reQuest)
A simple flow control method where:
- Sender sends 1 frame and waits for an ACK (acknowledgment).
- If no ACK arrives in time, it retransmits.
- This guarantees delivery but wastes bandwidth.
Visual: Stop-and-Wait ARQ:
figure: Stop-and-Wait ARQ
```mermaid
sequenceDiagram
participant S as Sender
participant R as Receiver
S->>R: Frame 1 (Data)
alt ACK received
R-->>S: ACK 1
else Timeout
S->>R: Frame 1 (Retry)
end
Worked Example: Ncell Data Transfer
- When you upload a photo to Ncell’s cloud, TCP’s stop-and-wait ensures your phone doesn’t flood the server.
- If the server is busy, it sends a slow-down signal (smaller window), reducing retries.
6. Virtual Circuit vs. Datagram Networks
| Feature | Virtual Circuit (e.g., VoIP, ATM) | Datagram (e.g., Internet, UDP) |
|---|---|---|
| Connection | Sets up a path before sending data (like a phone call) | No setup; each packet is independent |
| Reliability | Guaranteed delivery (e.g., VoIP calls) | No guarantee (e.g., YouTube video chunks) |
| Overhead | High (initial handshake) | Low (no handshake) |
| Example | Skype call, NTC’s old circuit-switched network | WhatsApp messages, YouTube streaming |
| Layer | Works with Layer 3 (Network) for routing | Works with Layer 4 (Transport) for speed |
Visual: Virtual Circuit vs. Datagram:
figure: Virtual Circuit vs Datagram
```figure
{"type":"network","nodes":["Source","Router1","Router2","Destination"],"edges":[["Source","Router1",{"label":"Path Setup (VC)","color":"green"}],["Router1","Router2",{"label":"Reserved Path","color":"green"}],["Router2","Destination",{"label":"Data Flow","color":"green"}]],"caption":"Virtual Circuit: Dedicated path established before data transfer"}
7. Exam Tip: How to Score Full Marks
Define OSI Layers Clearly
- For each layer, mention 1 function and 1 example protocol.
- Example:
"Layer 4 (Transport) ensures end-to-end delivery using TCP’s flow control and error recovery, as seen in WhatsApp’s reliable messaging."
Compare Virtual Circuit vs. Datagram
- Use a table (like above) and highlight trade-offs (e.g., "Virtual circuits are reliable but slow to set up").
- Mention real-world apps:
"Virtual circuits are used in VoIP calls (e.g., Pathao’s ride requests), while datagrams power YouTube’s video streaming."
Explain Flow Control with a Diagram
- Draw a sequence diagram (like stop-and-wait ARQ above) and label:
- Sender, Receiver, ACK, Timeout, Retransmission.
- Tie it to a real scenario:
"In Ncell’s 4G network, TCP’s flow control adjusts the window size to prevent data loss during peak hours."
- Draw a sequence diagram (like stop-and-wait ARQ above) and label:
Trace a Packet’s Journey
- Show how a WhatsApp message moves through layers (use the sequence diagram earlier).
- Highlight layer interactions:
"Layer 3 (IP) adds the destination IP, while Layer 2 (Ethernet) adds the MAC address of the next hop router."
Avoid Common Mistakes
- Don’t confuse OSI layers with TCP/IP layers (they’re similar but not identical).
- Don’t forget to mention error control (e.g., CRC in Layer 2) when asked about reliability.
- For ARQ, always include both sender and receiver steps (e.g., "Sender waits for ACK; if timeout, retransmits").
8. Practice Questions (Exam-Style)
Question 1: Flow Control in ARQ
a) Define flow control as a layered protocol model. b) Explain the mechanism of a stop-and-wait ARQ model for a damaged frame.
Answer: a) Flow control is a Layer 4 (Transport) mechanism that regulates data transmission speed between sender and receiver to prevent overflow or underutilization of resources. It ensures the receiver can process data without losing packets.
b) In stop-and-wait ARQ:
- The sender transmits 1 frame and waits for an ACK from the receiver.
- If the receiver detects a damaged frame (e.g., due to noise), it discards it and sends a NACK (negative acknowledgment).
- The sender retransmits the frame upon receiving NACK or timeout.
- Upon correct reception, the receiver sends an ACK, and the cycle repeats.
Visual: ARQ with NACK:
figure: ARQ with NACK
Question 2: Virtual Circuit vs. Datagram
Compare and contrast Virtual Circuit Network and Datagram Network.
| Aspect | Virtual Circuit Network | Datagram Network |
|---|---|---|
| Setup | Requires a path establishment (e.g., call setup in VoIP) | No setup; packets are independent |
| Addressing | Uses virtual circuit IDs (e.g., connection number) | Each packet carries full destination address |
| Reliability | Guaranteed delivery (e.g., ATM networks) | Best-effort delivery (e.g., UDP) |
| Overhead | High (initial signaling) | Low (no signaling) |
| Example | VoIP calls, NTC’s old circuit-switched network | Internet (IP), WhatsApp messages, YouTube |
| Layer Focus | Primarily Layer 3 (Network) | Primarily Layer 4 (Transport) |
Real-World Tie:
- Virtual Circuit: Pathao’s ride requests use a virtual circuit to reserve a path for real-time location updates.
- Datagram: Daraz’s order processing uses datagrams to send individual product details quickly, even if some packets are lost.
Question 3: OSI Layers Trace
Explain the layers of the OSI model with a trace of how a bank transfer request (e.g., via eSewa) travels through them.
Answer: When you initiate a bank transfer via eSewa:
- Layer 7 (Application): eSewa’s app formats the request (e.g., "transfer NPR 500 to account XYZ").
- Layer 6 (Presentation): Encrypts the data (SSL/TLS) and compresses it for efficiency.
- Layer 5 (Session: Manages the connection with the bank’s server (e.g., keeps the session alive during transfer).
- Layer 4 (Transport): TCP breaks the request into segments, adds sequence numbers, and ensures reliable delivery.
- Layer 3 (Network): IP adds the source (your phone’s IP) and destination (bank’s server IP) addresses.
- Layer 2 (Data Link): Ethernet/Wi-Fi adds the MAC address of the next hop (e.g., your router).
- Layer 1 (Physical): Converts bits into electrical signals (Wi-Fi) or light pulses (fiber) for transmission.
Visual: Bank Transfer Layers:
figure: Bank Transfer Layers
```figure
{"type":"layers","layers":["eSewa App (L7)","TLS (L6)","TCP (L4)","IP (L3)","Ethernet (L2)","Wi-Fi (L1)"],"right":["Transaction Request","Encrypted Data","Segment","Packet","Frame","Bits"],"highlight":["TLS","TCP","IP"],"caption":"eSewa bank transfer: OSI layers in action"}
9. Key Formulas and Terms to Memorize
- Flow Control Window Size:
Window Size = Number of unacknowledged packets allowed before stopping.- Example: If window size = 4, sender can send 4 frames before waiting for ACKs.
ARQ Types:
- Stop-and-Wait: 1 frame at a time.
- Go-Back-N: Sender can send N frames without ACKs; retransmits all if error detected.
- Selective Repeat: Sender retransmits only corrupted frames.
OSI Layer Acronyms:
- PDNSPA: Please Do Not Send Pornography And Sexy (mnemonic for layers 1–7).
10. Common Pitfalls
- Confusing OSI with TCP/IP: Remember, TCP/IP merges some layers (e.g., Physical + Data Link = Network Access).
- Ignoring Layer 5 (Session): Often overlooked but critical for maintaining connections (e.g., keeping a WhatsApp call alive).
- Assuming Datagrams are Unreliable: While UDP is unreliable, IP (Layer 3) itself is also a datagram protocol but works with higher layers (e.g., TCP) for reliability.
- Forgetting Error Detection: Layers 1–2 use CRC to detect errors; Layer 4 uses checksums in TCP/UDP.
Based on the PU BE Computer (PU) syllabus for Data Communication, unit 8.
Discussion
Loading…