Lazy loaded image
Wordsย 0Read Timeโ‰ˆย 1ย min
Invalid Date
ID
2
ย 

Chapter 2: Application Layer


๐Ÿ”น 1. Key Concepts: Application Layer Overview

โœ… What Is the Application Layer?

  • Main Role: Enables network applications (e.g., web browsers, email, video streaming).
  • Not part of network core: Runs only on end systems (hosts), not on routers/switches.
  • Design Goal: Understand how apps use transport protocols to communicate.

โœ… Two Architectures

Client-Server
Peer-to-Peer (P2P)
- Always-on server with permanent IP
- No always-on server
- Clients request service
- Peers request and provide services
- Centralized control
- Decentralized, self-scaling
- Examples: HTTP, SMTP, FTP
- Examples: BitTorrent, Skype (older), sharing apps
- Clients may have dynamic IPs
- Peers intermittently connected, IPs change
- Scalability limited by server capacity
- Scalability improves as peers join
๐Ÿ’ก Key Insight: P2P = "Everyone is both client AND server." ๐Ÿ’ก Tradeoff: P2P scales well, but hard to manage; client-server is simpler but bottlenecked at server.

๐Ÿ”น 2. Processes & Sockets

โœ… Process Communication

  • Same host: Use inter-process communication (IPC).
  • Different hosts: Communicate via messages over network.
  • Client process: Initiates communication.
  • Server process: Waits to be contacted.

โœ… Sockets: The โ€œDoorโ€ to the Network

  • Socket = interface between app and transport layer (TCP/UDP).
  • Analogy: Like a mailbox or door โ€” app pushes data out, transport delivers it.
  • Two sockets per connection: One on client, one on server.

โœ… Process Addressing: IP + Port

  • IP address: Identifies host.
  • Port number: Identifies process on that host.
  • Example: gaia.cs.umass.edu:80 โ†’ Web server at IP 128.119.245.12, port 80.
  • Well-known ports:
    • HTTP โ†’ 80
    • HTTPS โ†’ 443
    • SMTP โ†’ 25
    • DNS โ†’ 53
    • FTP โ†’ 21
    • POP3 โ†’ 110
    • IMAP โ†’ 143
โ— Exam Tip: IP address alone is NOT enough โ€” you need IP + port to identify a process.

๐Ÿ”น 3. Application-Layer Protocols: Requirements

โœ… What Defines a Protocol?

An application-layer protocol specifies:
  1. Message types: Request, response, etc.
  1. Syntax: Field structure, delimiters (e.g., CRLF).
  1. Semantics: Meaning of fields (e.g., GET = request object).
  1. Rules: When and how to send/respond.

โœ… Transport Service Requirements by App

Application
Data Loss Tolerance
Throughput
Timing
Security
File Transfer / Email / Web
No loss
Elastic
No
Yes
Real-time Audio/Video
Loss-tolerant
5Kโ€“5Mbps
Yes (10sโ€“100s ms)
Yes
Interactive Games
Loss-tolerant
Kbps+
Yes (10s ms)
Yes
Text Messaging
No loss
Elastic
Sometimes
Yes

โœ… Transport Protocols: TCP vs UDP

Feature
TCP
UDP
Reliability
โœ… Yes (retransmissions)
โŒ No
Ordering
โœ… In-order delivery
โŒ May arrive out of order
Flow Control
โœ… Yes
โŒ No
Congestion Control
โœ… Yes
โŒ No
Connection Setup
โœ… 3-way handshake
โŒ None
Overhead
Higher
Lower
Use Cases
Web, email, FTP
Video, VoIP, DNS, streaming
โš ๏ธ Why UDP?
  • Low latency (e.g., live video)
  • No connection setup (e.g., DNS queries)
  • App handles reliability (e.g., RTSP, QUIC)

๐Ÿ”น 4. Web & HTTP (CORE TOPIC)

โœ… HTTP Basics

  • HyperText Transfer Protocol
  • Client-Server: Browser (client) โ†” Web server (server)
  • Uses TCP: Port 80 (HTTP), 443 (HTTPS)
  • Stateless: Server remembers nothing between requests.

โœ… HTTP Connection Types

Non-Persistent HTTP (HTTP 1.0)
Persistent HTTP (HTTP 1.1)
- One TCP conn per object
- Single TCP conn for multiple objects
- 2 RTTs per object
- 1 RTT total for all objects
- High overhead: open/close TCP
- Connection kept open: Connection: keep-alive
- Inefficient for pages with many resources
- Supports pipelining (optional)
๐Ÿ“Œ Example: A webpage with 10 images =
  • Non-persistent: 22 RTTs (2 RTT ร— 11 objects)
  • Persistent: 2 RTTs (1 to open + 1 for all)

โœ… HTTP Messages: Request & Response

โžค HTTP Request Format (GET example):

  • Request Line: Method URI Version
  • Headers: Key-value pairs
  • Blank line ends headers
  • Body: Optional (for POST/PUT)

โžค HTTP Response Format:

  • Status Line: Version Code Phrase
  • Headers
  • Body: HTML, image, etc.

๐Ÿ“Œ HTTP Status Codes (Must Know!)

Code
Meaning
200 OK
Success
301 Moved Permanently
Page moved โ†’ new URL in Location: header
400 Bad Request
Syntax error
404 Not Found
File doesnโ€™t exist
505 HTTP Version Not Supported
Server doesnโ€™t support requested version

โœ… HTTP Methods (Commands)

Method
Purpose
GET
Retrieve object
POST
Submit form data (body used)
HEAD
Get headers only (no body)
PUT
Upload file (replace existing)
DELETE
Delete file
๐Ÿ’ก GET can send data via URL (?key=value) โ€” but only for small data.

๐Ÿ”น 5. Keeping State: Cookies

โœ… Why Need Cookies?

  • HTTP is stateless โ†’ server canโ€™t remember who you are.
  • Solution: Cookies โ†’ track user state across requests.

โœ… Cookie Process (4 Components)

  1. Server sends Set-Cookie: session_id=12345 in response.
  1. Browser saves cookie in cookie file.
  1. Browser includes Cookie: session_id=12345 in next request.
  1. Server uses cookie to identify user โ†’ accesses backend DB.

โœ… Cookie Uses

  • Authentication (login sessions)
  • Shopping carts
  • Personalization (recommendations)
  • User tracking

โœ… Privacy & Third-Party Cookies

  • First-party cookie: From site you visited (e.g., amazon.com)
  • Third-party cookie: From tracker site (e.g., adX.com embedded in nytimes.com)
    • Tracks you across multiple sites
    • Used for targeted ads
    • Disabled by default in Safari, Firefox; being phased out in Chrome
  • GDPR (EU): Requires user consent โ†’ cookies = personal data if can identify you.

๐Ÿ”น 6. Web Caching (Proxy Servers)

โœ… Purpose

  • Reduce latency + reduce bandwidth on access link.
  • Store copies of objects closer to user.

โœ… How It Works

  • Client โ†’ requests โ†’ web cache
  • Cache โ†’ if object exists โ†’ deliver it (cache hit)
  • Cache โ†’ if not โ†’ fetch from origin server, cache, deliver (cache miss)

โœ… Cache Hit Rate = % requests served from cache

  • Example: Hit rate = 0.4 โ†’ 40% hits, 60% misses

โœ… Performance Improvement Example:

Configuration
Access Link Utilization
Avg. Delay
No cache
0.97 (high)
~3โ€“5 minutes
With cache (40% hit)
0.58
~1.2 seconds
๐Ÿ’ก Caching is cheaper & more effective than upgrading bandwidth!

โœ… Conditional GET (Efficiency!)

  • Client sends: If-Modified-Since: Tue, 01 Mar 2016 18:57:50 GMT
  • Server responds with:
    • 304 Not Modified โ†’ client uses cached copy (no data transfer)
    • 200 OK + data โ†’ object updated

๐Ÿ”น 7. HTTP/2 & HTTP/3 / QUIC

โœ… HTTP/1.1 Issue: HOL Blocking

  • One large object blocks smaller ones (First-Come-First-Served).
  • 1 TCP connection โ†’ packet loss stalls all.

โœ… HTTP/2 (2015) Fixes:

  • Multiplexing: Objects split into frames, interleaved โ†’ no HOL blocking.
  • Server Push: Server sends resources it thinks client will need (e.g., CSS, JS).
  • Header Compression: Reduces overhead.
  • Still uses TCP.

โœ… HTTP/3 (2022) โ†’ QUIC

  • Over UDP, not TCP.
  • Built-in encryption + authentication (TLS 1.3).
  • 0-RTT or 1-RTT connection setup.
  • Per-flow congestion control โ†’ no HOL blocking between streams.
  • Better for mobile & unstable networks.
  • Used by Google, YouTube, Chrome.
๐Ÿ” QUIC = UDP + TLS + Reliable Transport (TCP-like) in App Layer
Real World: HTTP/2 โ†’ TCP โ†’ QUIC

๐Ÿ”น 8. Email: SMTP, POP3, IMAP

โœ… 3 Components of Email System

  1. User Agent (UA): Mail client (Outlook, iPhone Mail)
  1. Mail Server: Stores inbox/outbox
  1. SMTP: Protocol to send mail

โœ… SMTP (Simple Mail Transfer Protocol)

  • Reliable transfer via TCP (port 25)
  • Three Phases:
      1. Handshake (HELO)
      1. Transfer (MAIL FROM, RCPT TO, DATA)
      1. Closure (QUIT)
  • ASCII only โ†’ binary data must be base64 encoded.
  • Push protocol: Client pushes mail to server.

โœ… SMTP Interaction Example:

โœ… Email Message Format (RFC 2822)

  • Headers (To, From, Subject)
  • Blank line
  • Body (ASCII text)
โœ… SMTP vs HTTP:
  • SMTP: Push โ†’ client sends to server
  • HTTP: Pull โ†’ client requests from server

โœ… Retrieving Mail: IMAP vs POP3

Protocol
Stores Mail
Syncs State
Webmail Ready?
POP3
Downloads โ†’ deletes from server
โŒ No
โŒ No
IMAP
Keeps on server
โœ… Yes
โœ… Yes
โœ… Modern Use: IMAP (Gmail, Outlook) โ€” emails synced across phones/computers.

๐Ÿ”น 9. DNS: Domain Name System

โœ… Why DNS?

  • Humans: www.amazon.com
  • Machines: 54.240.10.10
  • DNS = Translator (name โ†” IP)

โœ… Why Distributed & Hierarchical?

  • โŒ Centralized โ†’ Single point of failure, traffic overload
  • โœ… Decentralized = scalable, reliable

โœ… DNS Hierarchy (Top to Bottom)

โœ… DNS Servers Types

Server
Role
Root
Point to TLD servers
TLD
.com, .edu โ†’ points to authoritative servers
Authoritative
Owns DNS records for domain (e.g., amazon.com)
Local (Recursive)
ISPโ€™s DNS server โ€” handles query for host

โœ… DNS Query Types

Type
Description
Iterative
Server responds: โ€œI donโ€™t know, ask THIS serverโ€ โ†’ client follows chain
Recursive
Server must resolve it โ†’ high load on root/TLD โ†’ rare
โœ… Most DNS queries use recursion at local server โ†’ it does iterative on your behalf.

โœ… DNS Record Types (RR) โ€” MUST KNOW!

Type
Meaning
Example
A
Hostname โ†’ IP
www.example.com โ†’ 192.0.2.1
CNAME
Alias โ†’ canonical name
www.amazon.com โ†’ amazon.com.edgesuite.net
MX
Mail server
example.com โ†’ mail.example.com
NS
Nameserver for domain
example.com โ†’ ns1.example.com

โœ… DNS Caching & TTL

  • DNS servers cache entries for TTL (Time To Live) seconds.
  • Problems:
    • Changes (e.g., IP change) take time to propagate.
    • Outdated records โ†’ misrouting.
โœ… DNS is best-effort โ†’ can be inaccurate.

โœ… DNS Security (DNSSEC)

  • Adds digital signatures โ†’ prevents spoofing & cache poisoning.
  • Authenticates DNS responses.

โœ… DNS Attack: DDoS

  • Flooding root/TLD servers โ†’ disrupt Internet.
  • Defenses:
    • Local caching of TLD IPs
    • Filtering
    • Replication

๐Ÿ”น 10. Video Streaming & CDNs

โœ… Challenges

  • Scalability: 1B+ viewers
  • Heterogeneity: Different bandwidths (mobile, wired)
  • Jitter: Variable delays โ†’_irq=planning playout
  • Loss: Video packets may drop

โœ… Video Coding

  • Spatial coding: Compress within frame (e.g., repeated colors)
  • Temporal coding: Compress between frames (e.g., only send changes)
  • CBR: Constant Bitrate โ†’ Film
  • VBR: Variable Bitrate โ†’ Internet โ†’ adaptive streaming

โœ… Streaming Architecture

  1. Video recorded โ†’ encoded โ†’ divided into chunks
  1. Each chunk encoded at multiple bitrates
  1. Client requests chunks via HTTP
  1. Client chooses bitrate based on current bandwidth

โœ… DASH: Dynamic Adaptive Streaming over HTTP

  • Client:
    • Estimates bandwidth
    • Requests highest sustainable bitrate chunk
    • Can change per chunk (e.g., from 1080p โ†’ 720p)
๐Ÿ’ก DASH = Adaptation + HTTP + Chunking = Standard today (Netflix, YouTube)

โœ… Content Distribution Networks (CDNs)

  • Problem: Single server canโ€™t handle 1M users โ†’ overload, latency.
  • Solution: Replicate content across thousands of geographically distributed servers.

โœ… CDN Example: Netflix

  1. Netflix uploads movie to CDN nodes globally.
  1. User requests video โ†’ DNS returns CDN URL (CNAME)
  1. Client gets manifest file โ†’ picks closest/server with good bandwidth
  1. Downloads chunk-by-chunk via HTTP (DASH)
๐Ÿ”ฅ Akamai: 240,000 servers โ†’ 1/4 of Internet traffic
๐Ÿ’ก CDNs = Edge Computing โ†’ move content as close as possible to users.

๐Ÿ”น 11. Socket Programming (Python)

โœ… Two Types of Sockets

Socket
Protocol
Use
UDP Socket
UDP
Fast, unreliable (e.g., DNS, video)
TCP Socket
TCP
Reliable, connection-oriented (e.g., web, email)

โœ… UDP Client-Server (Unreliable)

Client:
Server:
โš ๏ธ No connection โ†’ address must be included in sendto().

โœ… TCP Client-Server (Reliable)

Client:
Server:
โš ๏ธ Key difference:
  • TCP: Use connect() + accept() โ†’ connection established
  • UDP: Send/receive without connection

โœ… Handling Timeouts (Critical for Labs!)

  • Used in RDT programming assignments (Chapter 3) โ€” essential for timeouts!

๐Ÿšจ Chapter 2: Exam Checklist (Must Know!)

Topic
Must Know?
Client-server vs P2P
โœ”๏ธ
Process = IP + Port
โœ”๏ธ
Socket = handoff point to transport layer
โœ”๏ธ
TCP vs UDP features & use cases
โœ”๏ธโœ”๏ธโœ”๏ธ
HTTP: Stateless, Non-persistent vs Persistent
โœ”๏ธโœ”๏ธโœ”๏ธ
HTTP request/response syntax, status codes
โœ”๏ธโœ”๏ธโœ”๏ธ
Cookies โ†’ 4 components, use, privacy (GDPR)
โœ”๏ธโœ”๏ธ
Web caching: hit rate, advantage over bandwidth upgrade
โœ”๏ธโœ”๏ธ
DNS hierarchy, record types (A, CNAME, MX, NS)
โœ”๏ธโœ”๏ธโœ”๏ธ
UDP vs Recursive queries
โœ”๏ธ
DNS caching & TTL
โœ”๏ธ
DASH โ†’ adaptive bitrate, chunked streaming
โœ”๏ธโœ”๏ธ
CDNs -> Why? (scalability, latency, replication)
โœ”๏ธโœ”๏ธ
HTTP/2 โ†’ multiplexing, server push
โœ”๏ธ
HTTP/3 โ†’ QUIC over UDP, 0-RTT, security
โœ”๏ธ
SMTP: 3 phases, ASCII, STORED on server
โœ”๏ธ
IMAP vs POP3
โœ”๏ธ
TCP/UDP socket programming in Python
โœ”๏ธโœ”๏ธโœ”๏ธ
Socket timeout in Python
โœ”๏ธโœ”๏ธ (Very Important!)

๐Ÿ”š Final Thoughts: Key Themes of Chapter 2

  • Client-Server: Simple, centralized, brittle
  • P2P: Scalable, decentralized, complex
  • Stateless vs Stateful: HTTP vs Cookies
  • Reliability: TCP vs UDP tradeoffs
  • Scalability: CDNs, Caching, DASH
  • Complexity at Edge: Everything real happens in apps (DNS, codecs, security)
  • Use the Interface: Sockets abstract away network complexity
๐Ÿ’ฌ โ€œThe Internet is designed to run on end systemsโ€”itโ€™s not about infrastructure, itโ€™s about applications.โ€

๐Ÿ“˜ Practice & Labs

  • Use Wireshark โ†’ capture HTTP, DNS, SMTP traffic.
  • Run the Python socket code examples.
  • Try telnet gaia.cs.umass.edu 80 โ†’ send GET / HTTP/1.1\\r\\nHost: gaia.cs.umass.edu\\r\\n\\r\\n
  • Practice traceroute + dig/nslookup for DNS.

โœ… You now have a complete, exam-ready understanding of the Application Layer. Dig deeper into protocols โ€” youโ€™re ready for Chapter 3 (Transport Layer).
Good luck in your exams! ๐ŸŒ๐Ÿ’ป๐Ÿ“Š
ไธŠไธ€็ฏ‡
COMP1323 Networks and Security Notes
ไธ‹ไธ€็ฏ‡
About This Blog

Comments
Loading...