Networking rewards a layered mental model. Learn each unit as a layer with its own job, its own data unit (bit, frame, packet, segment, message), and its own set of named protocols. When a question asks "what happens when you open a web page", answer layer by layer. Marks in this subject are usually earned by precise vocabulary (framing, CIDR, three-way handshake) plus a small diagram.
Marks patterns to expect: definitions and comparisons (OSI vs TCP/IP, circuit vs packet switching), short numerical work (subnetting, CRC, window size), and diagram questions (TCP header, address formats).
Contents
- Unit 1: Introduction
- Unit 2: The Physical Layer
- Unit 3: The Data Link Layer
- Unit 4: The Network Layer
- Unit 5: The Transport Layer
- Unit 6: The Application Layer
- Unit 7: Network Security
Unit 1: Introduction
Teaching hours: 6
Topics in outline order
- Network as an infrastructure for data communication
- Applications of computer networks
- Network architecture
- Types of computer networks
- Protocols and standards
- The OSI reference model
- The TCP/IP protocol suite
- Comparison between OSI and TCP/IP reference models
- Critiques of the OSI and TCP/IP reference models
Explanation
1.1 Network as an infrastructure for data communication
A computer network is a set of autonomous devices connected by a transmission medium so they can exchange data. Its infrastructure role is to move bits reliably between endpoints and to hide the details of media, routing, and error recovery from applications. Think of it as a shared utility: applications buy "transport" the way a household buys electricity.
1.2 Applications of computer networks
File transfer, email, web access, remote login, video conferencing, e-commerce, cloud storage, distributed databases, and industrial control. In the exam, classify applications by traffic pattern — bulk transfer, interactive, real-time streaming — because that classification explains the transport protocol choice.
1.3 Network architecture
Architecture is the deliberate division of communication into layers with defined interfaces. The two canonical architectures are OSI (seven layers, a teaching and reference model) and TCP/IP (four to five layers, the deployed model). Architecture answers "who is responsible for what", not "which product to buy".
1.4 Types of computer networks
By scale: PAN (personal, a few metres, Bluetooth), LAN (a building, high speed, privately owned), MAN (a city, often provider-run), WAN (countries, leased lines and carriers), and the Internet as a network of networks. Also classify by topology — bus, star, ring, mesh, hybrid — and by ownership — intranet, extranet, internet.
1.5 Protocols and standards
A protocol is an agreed set of rules covering syntax (format), semantics (meaning), and timing (order and speed). Standards come from de jure bodies (ISO, IEEE, IETF RFCs, ITU-T) and de facto practice (Ethernet, TCP/IP, HTTP). Standards are what let equipment from different vendors interoperate.
1.6 The OSI reference model
Seven layers: physical (bits on media), data link (frames on a link), network (packets across networks), transport (end-to-end segments), session (dialogue control), presentation (syntax, encryption, compression), application (user services). Each layer serves the one above and uses the one below; encapsulation adds a header at each step.
1.7 The TCP/IP protocol suite
Four practical layers: network access (link + physical), internet (IP, ICMP, ARP), transport (TCP, UDP), application (HTTP, DNS, SMTP, FTP). TCP/IP grew from the ARPANET and is what the Internet actually runs.
1.8 Comparison between OSI and TCP/IP reference models
OSI has seven layers and separates session and presentation; TCP/IP merges them and has no formal session layer. OSI is protocol-independent and prescriptive; TCP/IP was written around its protocols. OSI's model is cleaner for teaching; TCP/IP's is the one implemented.
1.9 Critiques of the OSI and TCP/IP reference models
OSI is criticised for over-engineering, late and slow standardisation, and a session layer that real applications rarely use. TCP/IP is criticised because its network-access layer is not a true layer, its model does not separate service from protocol, and its original design had no security layer — security had to be retrofitted (IPSec, TLS).
Key terms
Encapsulation · peer-to-peer process · interface (SAP) · topology · protocol data unit (PDU) · de facto vs de jure standard · internetwork
Revision points
- Layer → PDU → device: physical/bit/hub-repeater, data link/frame/switch-bridge, network/packet/router, transport/segment/gateway-host.
- "Comparison" questions need at least three dimensions: layers, model vs implementation, and protocol coupling.
- A protocol needs all three of syntax, semantics, and timing; naming only two loses marks.
Practice questions
- Explain why layering is used in network architecture, and give one cost of layering.
- Compare the OSI and TCP/IP reference models on layers, origin, and practical use.
- Classify five real applications by traffic pattern and suggest TCP or UDP for each.
Answer notes: (1) Layering isolates change, allows vendor interoperability and independent development; the cost is header overhead and occasional duplication of function (e.g. error checking at several layers). (2) OSI: seven layers, ISO, reference/teaching model, protocol-independent. TCP/IP: four layers, ARPANET/DARPA, deployed implementation, built around its own protocols. (3) Bulk file transfer and email → TCP; live video/voice and DNS queries → UDP (with application-level recovery where needed).
Worked example: Classifying application traffic patterns
Problem: Classify the following applications by traffic pattern and suggest the appropriate transport protocol: (a) Web browsing, (b) Email, (c) Live video streaming, (d) DNS resolution, (e) File transfer.
Solution:
| Application | Traffic Pattern | Recommended Protocol | Rationale |
|---|---|---|---|
| Web browsing | Interactive, request-response | TCP | Reliable delivery of page content; occasional retransmission acceptable |
| Email (SMTP/POP3/IMAP) | Bulk transfer, store-and-forward | TCP | Reliability required; loss of a few bytes corrupts the message |
| Live video streaming | Real-time, continuous | UDP | Loss of a few packets is acceptable; latency must be minimised |
| DNS resolution | Query-response, tiny | UDP | Fast lookup; loss of one query is retryable; no connection overhead |
| File transfer (FTP) | Bulk transfer, reliability critical | TCP | All bytes must arrive intact; retransmission on loss |
Swipe to see all columns
Intermediate steps: (1) Identify the nature of each application's data. (2) Determine if the application can tolerate loss. (3) Match to TCP (reliable, connection-oriented) or UDP (unreliable, connectionless, low latency). (4) Note that some applications (e.g. streaming over TCP) buffer and retransmit, trading latency for completeness.
Use case: Lab setup — ping and traceroute
A student sets up two laptops on the same LAN. They ping the loopback address (127.0.0.1) and the other laptop's IP. They then run traceroute to observe the path packets take. This demonstrates the internet layer (IP) delivering packets hop-by-hop, and the ICMP protocol used by traceroute to measure round-trip times.
Comparison table: OSI vs TCP/IP reference models
| Dimension | OSI Reference Model | TCP/IP Protocol Suite |
|---|---|---|
| Number of layers | 7 (physical, data link, network, transport, session, presentation, application) | 4 (network access, internet, transport, application) — sometimes 5 (if session layer is added) |
| Layer responsibilities | Explicitly defines session (dialogue control) and presentation (syntax, encryption, compression) | Merges session and presentation into the application layer |
| Protocol coupling | Protocol-independent model; each layer has both services and protocols | Model was designed around the actual TCP/IP protocols; network-access layer combines OSI's physical + data link |
| Origin | ISO (1984), designed as a generic telecom standard | DARPA/ARPANET (1960s–1980s), implemented around TCP and IP |
| Practical use | Rarely used as-is in real networks; primarily a teaching tool | The Internet and virtually all commercial networks run TCP/IP |
| Session layer | Present, responsible for dialogue control, synchronization, and recovery | Absent; session management typically handled by application-layer protocols |
| Presentation layer | Present, responsible for encryption, compression, character encoding | Absent; these functions are handled by application-layer protocols (e.g. TLS/SSL) or the transport layer |
Common mistakes, limitations, and security concerns
- Mistake 1: Saying "OSI has 5 layers" or "TCP/IP has 7 layers". Always count correctly.
- Mistake 2: Confusing "connection-oriented" with "reliable". TCP is both, but not all connection-oriented protocols are reliable (e.g. some ATM services).
- Mistake 3: Thinking the OSI model is "more correct" than TCP/IP. Remember: TCP/IP is what the Internet runs on; OSI is a teaching aid.
- Security concern: The original TCP/IP design had no built-in security. IPSec and TLS/SSL were added later. Students should not assume any layer provides security by default.
Exam-ready answer points
Short answer (1–2 marks):
- Define "protocol" with syntax, semantics, and timing.
- List the seven OSI layers from bottom to top.
- List the four TCP/IP layers from bottom to top.
- What is the PDU at the data link layer? (frame)
- What is CIDR and how does it differ from classful addressing?
Long answer (5–10 marks):
- Compare OSI and TCP/IP on layers, origin, and practical deployment.
- Explain encapsulation: how a packet gets headers added at each layer, from application down to physical.
- Describe the relationship between a "service" and a "protocol" at a given layer.
- Explain how routing works: IP addresses, routers, and the network layer's role in internetworking.
Diagram question:
- Draw the OSI seven-layer model with a packet flowing down through the layers at the sender, each adding a header, and then up through the layers at the receiver, each stripping a header.
- Draw the TCP/IP four-layer model with equivalent flow.
Self-check questions (with answers)
-
Question: How many layers does the OSI reference model have, and what is the PDU at the network layer? Answer: Seven layers; the PDU at the network layer is the packet.
-
Question: Name the two main internetworking architectures and one key difference between them. Answer: OSI (7 layers, protocol-independent, teaching model) and TCP/IP (4 layers, protocol-coupled, deployed model). Key difference: OSI was designed as a generic standard; TCP/IP was designed around the protocols that became the Internet.
-
Question: Classify the following application by traffic pattern and protocol: interactive voice over IP. Answer: Real-time, continuous; UDP (with jitter buffer and possibly error correction at the application level).
-
Question: What does "de jure standard" mean? Give one example. Answer: A standard established by a recognised standards body (e.g. ISO/IEC, ITU-T). Example: V.35 (WAN physical layer standard defined by ITU-T).
-
Question: Why is the TCP/IP model's network-access layer considered less precise than OSI's physical and data link layers split? Answer: The TCP/IP network-access layer combines the functions of OSI's physical layer (bit transmission) and data link layer (framing, addressing) into one layer, making it less granular for analysis but more reflective of actual hardware implementation.
Unit 2: The Physical Layer
Teaching hours: 6
Topics in outline order
- Functions of the physical layer
- Data and signals: analog and digital signals, transmission impairment, data rate limits, performance
- Data transmission media: guided media, unguided media, satellites
- Bandwidth utilisation: multiplexing and spreading
- Switching: circuit, message, and packet switching
- Telephone, mobile, and cable networks for data communication
Explanation
2.1 Functions of the physical layer
The physical layer moves raw bits over a medium. It defines the mechanical and electrical interface (connectors, voltage levels), line configuration (point-to-point, multipoint), transmission mode (simplex, half-duplex, full-duplex), bit synchronisation, and bit rate. It does not know what the bits mean.
2.2 Data and signals: analog and digital signals, transmission impairment, data rate limits, performance
Data is the meaning; a signal is its physical representation. Analog signals vary continuously; digital signals take discrete levels. A periodic analog signal is described by amplitude, frequency, and phase; a digital signal by bit rate and bit interval. Impairment has three causes: attenuation (weakening with distance), distortion (different frequencies arriving with different delays, changing shape), and noise (thermal, induced, crosstalk, impulse). Data rate limits: Nyquist gives the maximum rate for a noiseless channel, bit rate = 2 × B × log2(L) for bandwidth B and L signal levels; Shannon gives capacity for a noisy channel, C = B × log2(1 + SNR). Performance is measured by bandwidth (Hz), throughput (bps), latency (propagation + transmission + queuing + processing delay), and bandwidth-delay product, which is the number of bits "in flight".
2.3 Data transmission media: guided media, unguided media, satellites
Guided: twisted pair (UTP/STP, Cat 5e/6), coaxial cable, and optical fibre (single-mode for long haul, multimode for premises) — fibre wins on bandwidth and immunity to interference. Unguided: radio waves (omnidirectional, penetrate walls), microwaves (line of sight, terrestrial or satellite), and infrared (short range, cannot pass walls). Satellites: GEO (35,786 km, fixed position, high latency ~250 ms), MEO (GPS), and LEO (low latency, large constellations, handover needed).
2.4 Bandwidth utilisation: multiplexing and spreading
Multiplexing shares one link: FDM (separate frequency bands), TDM (separate time slots, synchronous or statistical), and WDM (wavelengths in fibre). Spreading widens the signal to resist interference and to share spectrum: FHSS (frequency hopping) and DSSS (direct sequence), the basis of CDMA.
2.5 Switching: circuit, message, and packet switching
Circuit switching reserves a dedicated path for the whole call — constant delay, poor utilisation, ideal for voice. Message switching stores and forwards whole messages — no dedicated path but high delay and large buffer needs. Packet switching chops data into packets, each routed independently (datagram) or along a set-up path (virtual circuit); it is efficient and resilient, which is why data networks use it.
2.6 Telephone, mobile, and cable networks for data communication
The telephone network supplies the local loop, historically via modem over voice band, then DSL splitting voice and data frequencies. Cable networks share a coaxial/HFC plant and use DOCSIS. Mobile networks evolved 2G (GSM, voice + SMS) → 3G (UMTS, data) → 4G LTE (all-IP) → 5G NR (higher bands, low latency, dense cells).
Key terms
Baud vs bit rate · SNR · bandwidth-delay product · multiplexing · statistical TDM · baseband vs broadband · last mile
Revision points
- Nyquist = noiseless, Shannon = noisy; both give an upper bound in bps.
- Latency components are four; "delay" alone is an incomplete answer.
- Circuit switching reserves, packet switching shares — connect this to utilisation and to voice vs data.
Practice questions
- A channel has bandwidth 3 kHz and SNR of 30 dB. Find the Shannon capacity.
- Distinguish attenuation, distortion, and noise with one remedy for each.
- Why is packet switching preferred for bursty data traffic?
Answer notes: (1) 30 dB → SNR = 1000; C = 3000 × log2(1001) ≈ 3000 × 9.97 ≈ 29.9 kbps. (2) Attenuation = loss of strength → amplifiers/repeaters; distortion = shape change from unequal propagation delay → equalisers, shorter links; noise = unwanted energy → shielding, higher SNR, error control. (3) Bursty traffic leaves a reserved circuit idle; statistical multiplexing lets many users share capacity, trading guaranteed delay for efficiency.
Worked example: Shannon capacity calculation
Problem: A coaxial cable has a bandwidth of 3 kHz and a signal-to-noise ratio of 30 dB. What is the maximum data rate (Shannon capacity)?
Solution:
- Convert SNR from dB to linear: SNR_dB = 10 × log10(SNR_linear), so 30 = 10 × log10(SNR_linear), giving SNR_linear = 10^(30/10) = 10^3 = 1000.
- Apply Shannon's formula: C = B × log2(1 + SNR) = 3000 × log2(1 + 1000) = 3000 × log2(1001).
- Compute log2(1001): log2(1001) = ln(1001)/ln(2) ≈ 6.995/0.693 ≈ 9.97 (or note that 2^10 = 1024, so log2(1001) is slightly less than 10).
- C = 3000 × 9.97 ≈ 29,910 bps ≈ 29.9 kbps.
Intermediate result: The maximum data rate is approximately 29.9 kbps. Any system claiming a higher rate over this channel without additional bandwidth or error-correction coding would violate the Shannon limit.
Use case: Choosing media for a Nepali campus network
A university campus in Kathmandu needs to connect three buildings 500 m apart. Twisted pair (Cat 6) costs Rs. 200/m and supports 1 Gbps up to 100 m per segment, requiring repeaters every 100 m. Optical fibre (single-mode) costs Rs. 800/m but supports 10 Gbps up to 2 km per segment. For 500 m, one fibre span connects the buildings directly with no repeaters, future-proofing the network for higher speeds. The total cost difference is Rs. 300 per metre × 500 m = Rs. 150,000, but the fibre eliminates repeaters and provides headroom for growth.
Mermaid diagram: Signal impairments and data rate limits
graph TD
A[Physical Layer] --> B[Signal Type]
B --> C[Analog]
B --> D[Digital]
C --> E[Impairments]
D --> E
E --> F[Attenuation]
E --> G[Distortion]
E --> H[Noise]
F --> I[Amplifiers/Repeaters]
G --> J[Equalisers]
H --> K[Shielding, Error Control]
I --> L[Maximum Distance]
J --> L
K --> L
L --> M[Data Rate]
M --> N[Nyquist: 2B log2(L) bps]
M --> O[Shannon: B log2(1+SNR) bps]
N --> P[Upper Bound]
O --> P
P --> Q[Design Choice]
Q --> R[Trade-off: distance vs rate]
R --> S[Select modulation, FEC]
Explanation: The diagram shows how signal type (analog/digital) leads to three impairment categories (attenuation, distortion, noise), each with a mitigation strategy. The data rate is bounded by both Nyquist (noiseless) and Shannon (noisy), and the designer must trade off distance and rate through modulation and forward error correction.
Self-check questions (with answers)
-
Question: What are the three causes of signal impairment, and how does each affect the transmitted signal? Answer: Attenuation weakens the signal with distance; distortion changes the signal shape because different frequencies propagate at different speeds; noise adds unwanted energy from thermal, induced, crosstalk, or impulse sources.
-
Question: State the Nyquist formula for maximum bit rate in a noiseless channel and define each variable. Answer:
bit rate = 2 × B × log2(L)where B is bandwidth in Hz and L is the number of signal levels. -
Question: State the Shannon capacity formula and explain what SNR means. Answer:
C = B × log2(1 + SNR)where B is bandwidth in Hz and SNR is the signal-to-noise ratio (linear, not dB). SNR = average signal power / average noise power. -
Question: Compare guided and unguided transmission media: give one advantage and one disadvantage for each. Answer: Guided (twisted pair, coaxial, fibre): advantage = high bandwidth, immunity to interference (fibre); disadvantage = installation cost (fibre), distance limits (twisted pair). Unguided (radio, microwave, infrared): advantage = flexibility, no physical infrastructure; disadvantage = susceptible to interception, multipath fading, weather attenuation.
-
Question: What is the bandwidth-delay product, and why does it matter? Answer: The bandwidth-delay product is the number of bits that can be "in flight" on a link; it equals the link's capacity (bps) × propagation delay (seconds). It matters because it determines how much data must be buffered to fill the link; a large product requires large windows (TCP) or large frames to achieve full utilisation.
Unit 3: The Data Link Layer
Teaching hours: 8
Topics in outline order
- Functions of the data link layer
- Data link control: framing, flow and error control
- Error detection and correction
- HDLC and PPP
- Channel allocation problem
- Multiple access: random access, controlled access, channelisation
- Wired LAN: Ethernet standards and FDDI
- Wireless LAN: IEEE 802.11 and Bluetooth
- Token bus, token ring, and virtual LAN
Explanation
3.1 Functions of the data link layer
The data link layer turns a raw transmission facility into a reliable link. It handles framing, physical addressing, flow control, error control, and access control on shared media. Its PDU is the frame.
3.2 Data link control: framing, flow and error control
Framing delimits frames by character count, byte stuffing with flag bytes (01111110), or bit stuffing with the flag 01111110. Flow control prevents a fast sender from drowning a slow receiver — stop-and-wait or sliding window. Error control uses acknowledgements, timers, and retransmission (ARQ).
3.3 Error detection and correction
Parity (single-bit detection), two-dimensional parity, checksum (used by IP/TCP/UDP), and CRC, the strongest common scheme: treat bits as a polynomial, divide by a generator, append the remainder. Correction is done by Hamming codes (redundant parity bits at positions 1, 2, 4, 8…) or by retransmission. Detection plus ARQ is cheaper than forward correction on copper; correction suits latency-sensitive links.
3.4 HDLC and PPP
HDLC is a bit-oriented protocol with flag-delimited frames, a control field, and three frame types (information, supervisory, unnumbered); it supports normal and asynchronous balanced modes. PPP carries IP over point-to-point links: flag, address, control, protocol, payload, FCS; it adds LCP for link setup and NCP for network-layer configuration, and supports authentication (PAP, CHAP).
3.5 Channel allocation problem
When several stations share one channel, allocation may be static (FDM/TDM) — simple but wasteful for bursty traffic — or dynamic (multiple access), which needs a protocol to decide who transmits when.
3.6 Multiple access: random access, controlled access, channelisation
Random: ALOHA (transmit at will, ~18% efficiency for pure ALOHA, 37% slotted), CSMA (listen before transmit), CSMA/CD (Ethernet: detect collision, back off), CSMA/CA (wireless: avoid collision, use ACKs because collisions cannot be detected while transmitting). Controlled: reservation, polling, token passing — no collisions but added overhead and single-point dependence. Channelisation: FDMA, TDMA, CDMA divide frequency, time, or code space.
3.7 Wired LAN: Ethernet standards and FDDI
Ethernet (IEEE 802.3) evolved from 10BASE5 to switched gigabit and 10GbE; the frame has preamble, destination and source MAC, type/length, payload (46–1500 bytes), and FCS. Switches learn MAC addresses and forward per port, removing the collision domain. FDDI is a dual-ring fibre token-passing network with self-healing rings, now largely historical.
3.8 Wireless LAN: IEEE 802.11 and Bluetooth
IEEE 802.11 uses CSMA/CA with optional RTS/CTS, a basic service set coordinated by an access point, and frames with four address fields for distribution. Bluetooth (802.15.1) forms piconets of up to eight active devices with a master and uses FHSS in the 2.4 GHz band.
3.9 Token bus, token ring, and virtual LAN
Token bus and token ring pass a token to grant transmission, giving bounded delay. A VLAN logically segments a switched LAN independent of physical location (802.1Q tags), improving broadcast control and security.
Key terms
Bit stuffing · CRC generator polynomial · piggybacking · collision domain vs broadcast domain · CSMA/CD vs CSMA/CA · BSS/ESS · trunk port
Revision points
- CRC detects all single-bit errors and all burst errors shorter than the generator degree.
- Ethernet has no timers or ACKs at the link layer; reliability is left to higher layers.
- Wireless cannot do collision detection, so it does collision avoidance plus link-layer ACK.
Practice questions
- Given data
1101011011and generator10011, state the procedure to compute the CRC and explain what the receiver does. - Why does CSMA/CD fail in wireless LANs?
- Compare a hub, a switch, and a router by the layer they operate at and the domain they break.
Answer notes: (1) Append four zeros (degree of generator), divide modulo-2, take the 4-bit remainder, transmit data plus remainder; the receiver divides the received bits by the same generator and accepts only a zero remainder. (2) A wireless transmitter cannot hear collisions at its own antenna while sending (hidden terminal, near/far), so 802.11 uses CSMA/CA with ACKs and optional RTS/CTS. (3) Hub — physical layer, repeats bits, one collision and broadcast domain. Switch — data link layer, forwards by MAC, separates collision domains (VLANs separate broadcast domains). Router — network layer, forwards by IP, separates broadcast domains.
Worked example: CRC-4 computation
Problem: Given the data 1101011011 and a CRC generator 10011 (degree 4), compute the CRC checksum and show how the receiver verifies it.
Solution:
- The data is
1101011011(10 bits). Append 4 zeros (generator degree):11010110110000(14 bits). - Perform modulo-2 division (XOR-based long division) by
10011. - The 4-bit remainder is the CRC checksum:
1110. - Transmitted frame:
11010110111110(data + checksum). - At the receiver: divide the received 14 bits by
10011. If the remainder is0000, the frame is accepted; otherwise, an error is detected.
Verification: 11010110111110 ÷ 10011 leaves remainder 0000, so the transmitted frame divides cleanly.
The key point: the receiver always expects a zero remainder. Any non-zero remainder indicates corruption.
Use case: Designing a simple stop-and-wait protocol
A student project implements a stop-and-wait data link protocol over a wireless link with 10 ms propagation delay and 1 Mbps link rate (1000 bits/ms). Each frame is 1000 bits. The sender transmits one frame and waits for an ACK. The round-trip time (RTT) is 2 × 10 ms = 20 ms plus transmission time of 1 ms = 21 ms. The link utilisation is 1 / (1 + 2a) where a = propagation time / transmission time = 10 / 1 = 10, so utilisation = 1 / (1 + 20) ≈ 4.8%. This demonstrates why pipelining (Go-Back-N or Selective Repeat) is essential for efficient links.
Mermaid diagram: CRC polynomial division procedure
graph TD
A[Data + CRC Zeros] --> B[Modulo-2 Long Division]
B --> C{XOR with Generator?}
C -->|Yes| D[Subtract XOR Result]
C -->|No| E[Bring Down Next Bit]
D --> F[Continue Division]
E --> F
F --> G[Remainder is CRC Checksum]
G --> H[Append to Data]
H --> I[Transmitted Frame]
I --> J[Receiver Divides by Same Generator]
J --> K{Remainder?}
K -->|0000| L[Accept Frame]
K -->|Non-zero| M[Error Detected, Request Retransmission]
Explanation: The diagram shows the core CRC procedure: append zeros, perform modulo-2 division (XOR-based), the remainder becomes the checksum. At the receiver, the same division is performed; a zero remainder means no errors were detected.
Common mistakes, limitations, and security concerns
- Mistake 1: Forgetting to append the CRC zeros before division. The transmitted frame will be too short, and the receiver's division will produce a non-zero remainder even if no corruption occurred.
- Mistake 2: Confusing bit stuffing (used in HDLC/Ethernet framing) with bit roation (a different concept). Bit stuffing inserts a 0 after five consecutive 1s; bit rotation shifts all bits.
- Mistake 3: Thinking CRC can correct errors. CRC only detects errors; correction requires Hamming code or ARQ.
- Limitation: CRC effectiveness depends on the generator polynomial. Some error patterns (e.g., errors exactly equal to the generator length) may not be detected.
- Security concern: CRC is not a cryptographic checksum; an adversary can flip bits and recompute a valid CRC. Use HMAC or digital signatures for authenticated integrity.
Exam-ready answer points
Short answer (1–2 marks):
- What is the PDU at the data link layer? (frame)
- Define "framing" and name one method. (character count, byte stuffing, or bit stuffing)
- What is the difference between CSMA/CD and CSMA/CA?
- What does CRC stand for, and what does it detect?
Long answer (5–10 marks):
- Explain the three functions of the data link layer: framing, flow control, and error control.
- Describe the HDLC frame format: flag, address, control, information, FCS.
- Compare stop-and-wait and sliding-window flow control; give one advantage and one disadvantage of each.
- Explain how Ethernet switches learn MAC addresses and why this removes the collision domain.
Diagram question:
- Draw the CRC computation procedure: append zeros, modulo-2 long division, remainder is checksum.
- Draw an Ethernet frame format: preamble, SFD, destination MAC, source MAC, type/length, payload, FCS.
Self-check questions (with answers)
-
Question: What is the purpose of bit stuffing in HDLC, and after how many consecutive 1s is a 0 inserted? Answer: Bit stuffing prevents the flag pattern
01111110from appearing in the data. A 0 is inserted after five consecutive 1s. -
Question: How does CRC detect errors, and can it correct them? Answer: CRC detects errors by dividing the received frame by the generator polynomial; a non-zero remainder indicates corruption. CRC only detects errors; correction requires Hamming code or ARQ.
-
Question: What is the difference between a collision domain and a broadcast domain? Answer: A collision domain is the set of devices whose frames can collide when sent on a shared medium; a broadcast domain is the set of devices that receive broadcast frames. A switch separates collision domains; a router separates broadcast domains.
-
Question: In a CSMA/CA network, why can't stations detect collisions while transmitting, and what do they do instead? Answer: A wireless transmitter cannot hear its own transmission due to the near-far effect and signal strength. Instead, CSMA/CA uses carrier sensing, optional RTS/CTS handshake, and ACKs to avoid and recover from collisions.
-
Question: Given a CRC generator of degree 5, how many bits are appended to the data, and what is the minimum number of bit errors that can be detected? Answer: 5 bits are appended. The minimum detectable error pattern depends on the generator; a well-chosen generator can detect all single-bit errors, all double-bit errors, and all burst errors up to length 5.
Unit 4: The Network Layer
Teaching hours: 8
Topics in outline order
- Functions of the network layer
- Virtual circuits and datagram subnets
- IPv4 addresses: address space, notations, classful addressing, classless addressing, subnetting, NAT
- IPv4 datagram format and fragmentation
- IPv6 address structure and advantages over IPv4
- Routing algorithms: distance vector, link state
- Internet control protocols: ARP, RARP, ICMP
- Routing protocols: OSPF, BGP, unicast, multicast, broadcast
Explanation
4.1 Functions of the network layer
Logical addressing, routing (path selection across networks), packet forwarding, fragmentation and reassembly, congestion indication, and inter-network connection. The PDU is the packet; the key device is the router.
4.2 Virtual circuits and datagram subnets
A virtual circuit sets up a path first and sends all packets along it with a short label — order preserved, per-flow state in routers, used by ATM/MPLS. A datagram subnet routes each packet independently — no setup, resilient to failure, may reorder; this is IP's model.
4.3 IPv4 addresses: address space, notations, classful addressing, classless addressing, subnetting, NAT
32 bits, written dotted decimal. Classful: A (/8), B (/16), C (/24), D multicast, E reserved. Classless (CIDR): prefix length a.b.c.d/n; the network address is found by ANDing with the mask, and the block size is 2^(32-n). Subnetting borrows host bits to create subnets; supernetting/aggregation combines them. NAT translates private addresses (10/8, 172.16/12, 192.168/16) to one public address using port numbers, conserving IPv4 space at the cost of breaking end-to-end addressing.
4.4 IPv4 datagram format and fragmentation
Version, header length, type of service, total length, identification, flags, fragment offset, TTL, protocol, header checksum, source and destination, options. Fragmentation splits a datagram when it exceeds the MTU; offset is in 8-byte units and MF marks "more fragments". TTL prevents loops; the checksum covers the header only.
4.5 IPv6 address structure and advantages over IPv4
128-bit addresses in eight hexadecimal groups with :: compression; fixed 40-byte header, no header checksum, no router fragmentation, extension headers, built-in flow label, and mandatory support for IPSec. Its address space removes the need for NAT and simplifies router processing.
4.6 Routing algorithms: distance vector, link state
Distance vector (Bellman-Ford, RIP): each router keeps a table of distances to all destinations and exchanges it with neighbours; simple, but slow convergence and count-to-infinity. Fixes: split horizon, poison reverse, triggered updates. Link state (Dijkstra, OSPF): each router floods link-state advertisements, builds a topology map, and computes shortest paths — faster convergence, more memory and CPU.
4.7 Internet control protocols: ARP, RARP, ICMP
ARP resolves an IPv4 address to a MAC address by broadcast and caches the reply; RARP (obsolete) did the reverse for diskless hosts; ICMP reports errors and diagnostics (ping, traceroute) and is carried inside IP.
4.8 Routing protocols: OSPF, BGP, unicast, multicast, broadcast
OSPF is intra-domain link state with areas and cost metrics; BGP is the inter-domain path-vector protocol that exchanges reachability between autonomous systems and applies policy. Unicast is one-to-one, broadcast one-to-all on a subnet, multicast one-to-many group delivery (IGMP manages membership), and anycast one-to-nearest.
Key terms
Prefix, mask, block size · MTU · count-to-infinity · autonomous system · longest-prefix match · CIDR notation · IGMP
Revision points
- Subnetting arithmetic: block size = 256 − mask octet; usable hosts = 2^h − 2 (network and broadcast reserved).
- Distance vector learns "by rumour", link state learns "by map" — use that phrasing to structure comparison answers.
- ARP is link-layer-adjacent but sits between layers 2 and 3; state that clearly.
Practice questions
- Subnet
192.168.10.0/24into four equal subnets. Give each network address and usable range. - Explain count-to-infinity and two ways to limit it.
- Distinguish OSPF and BGP by scope, algorithm type, and metric.
Answer notes: (1) /26 blocks: 192.168.10.0-.63, .64-.127, .128-.191, .192-.255; usable hosts are the first and last minus one on each end (.1–.62, .65–.126, .129–.190, .193–.254). (2) A failed link is advertised as unreachable at cost "infinity"; neighbours increment the old route until it exceeds infinity because they keep learning each other's stale paths. Limit with a small infinity (16 in RIP), split horizon (do not advertise a route back to the interface it came from), and poison reverse. (3) OSPF: interior, link state/Dijkstra, cost from bandwidth. BGP: exterior, path vector with policy attributes, chooses paths by policy and AS-path rather than pure cost.
Worked example: Subnetting 192.168.10.0/24 into four subnets
Problem: Subnet the network 192.168.10.0/24 into four equal subnets. List each subnet's network address, first usable host, last usable host, and broadcast address.
Solution:
- The original network is
192.168.10.0/24with a /24 mask (255.255.255.0). We need 4 subnets, so we borrow 2 bits from the host portion (2^2 = 4). - New prefix length: /24 + 2 = /26. New subnet mask: 255.255.255.192.
- Block size (increment): 256 − 192 = 64. Subnets increment by 64 in the last octet.
- Subnet blocks:
- Subnet 0: 192.168.10.0 − 192.168.10.63, network = .0, first usable = .1, last usable = .62, broadcast = .63
- Subnet 1: 192.168.10.64 − 192.168.10.127, network = .64, first usable = .65, last usable = .126, broadcast = .127
- Subnet 2: 192.168.10.128 − 192.168.10.191, network = .128, first usable = .129, last usable = .190, broadcast = .191
- Subnet 3: 192.168.10.192 − 192.168.10.255, network = .192, first usable = .193, last usable = .254, broadcast = .255
Verification: Each subnet has 2^(32−26) = 2^6 = 64 addresses. Usable hosts per subnet = 64 − 2 = 62 (minus network and broadcast). 4 subnets × 62 hosts = 248 total usable hosts, which matches the original /24 (2^8 − 2 = 254... wait, 254 usable in /24, but we have 4 × 62 = 248. The difference is because each subnet reserves network and broadcast, and we've split the space.)
Actually: /24 has 2^8 = 256 total addresses, 254 usable. Each /26 has 2^6 = 64 total addresses, 62 usable. 4 × 62 = 248 usable. The 6 missing addresses are the 4 network addresses and 4 broadcast addresses that are "lost" in the subnetting process (256 total − 248 usable = 8 reserved = 4 network + 4 broadcast, but some overlap... let me just note that 4 × 64 = 256, so the space is fully consumed).
Intermediate result: The four subnets are .0/26, .64/26, .128/26, and .192/26, each with 62 usable host addresses.
Use case: Home network design with NAT
A family in Kathmandu has three devices (laptop, smartphone, smart TV) that need internet access. Their ISP provides one public IP address. The home router runs NAT, assigning private addresses from 192.168.1.0/24 to the devices. When the laptop (192.168.1.10) requests a web page, the NAT router changes the source IP to the router's public IP and records the translation in its NAT table (port 54321 → 192.168.1.10:80). The response comes back to the public IP; the router reverses the translation and delivers the page to the laptop. This allows all three devices to share one public IP, but breaks end-to-end reachability (inbound connections require port forwarding).
Mermaid diagram: IPv4 datagram format
graph TB
A[IPv4 Datagram Header (20-60 bytes)] --> B[Version (4 bits)]
A --> C[IHL (4 bits)]
A --> D[TOS (8 bits)]
A --> E[Total Length (16 bits)]
A --> F[Identification (16 bits)]
A --> G[Flags (3 bits)]
A --> H[Fragment Offset (13 bits)]
A --> I[TTL (8 bits)]
A --> J[Protocol (8 bits)]
A --> K[Header Checksum (16 bits)]
A --> L[Source IP (32 bits)]
A --> M[Destination IP (32 bits)]
A --> N[Options (0-40 bytes)]
subgraph Fragmentation Fields
G --> G1[MF (More Fragments)]
G --> G2[Fragment Offset]
end
Explanation: The IPv4 header is 20–60 bytes (with optional fields). The core fixed fields include version, IHL (Internet Header Length), type of service, total length (total datagram size), identification, flags (MF + reserved), fragment offset (in 8-byte units), TTL (time to live), protocol (TCP/UDP/ICMP), header checksum, and source/destination IP addresses. The fragmentation fields (flags and offset) allow a datagram to be split when it exceeds the MTU.
Common mistakes, limitations, and security concerns
- Mistake 1: Forgetting that subnet masks must be contiguous 1s followed by 0s (i.e., /26 is valid but /25.16 is not classless — you can't have a mask like 255.255.128.0 if the /24 started as a class C, although CIDR allows any mask position).
- Mistake 2: Miscomputing the block size. Remember: block size = 256 − last octet of mask. For /26, mask octet = 192, block size = 64.
- Mistake 3: Reporting the network address as a usable host. The network address (e.g., 192.168.1.0) and broadcast address (e.g., 192.168.1.255) are never assigned to hosts.
- Security concern: NAT provides IPv4 address conservation but also provides a basic layer of obscurity — internal addresses are not directly reachable from the internet. However, NAT is not a security mechanism; firewalls and proper network hardening are required. Port forwarding can open unintended pathways.
Exam-ready answer points
Short answer (1–2 marks):
- What is the field in the IPv4 header that limits a packet's lifetime? (TTL)
- What does NAT stand for, and what problem does it solve? (Network Address Translation; conserves IPv4 address space)
- What is the difference between a virtual circuit and a datagram subnet?
- What protocol is used to map an IP address to a MAC address? (ARP)
Long answer (5–10 marks):
- Describe the IPv4 datagram format and explain the role of each core field.
- Explain subnetting: given a network prefix, borrow bits, compute the new mask, list the resulting subnets.
- Compare distance vector and link-state routing algorithms on convergence speed, complexity, and susceptibility to count-to-infinity.
- Describe how ARP resolves an IP to a MAC; what happens when ARP fails?
Diagram question:
- Draw the IPv4 header with all core fields labeled.
- Draw a sample subnetting scenario: given
192.168.10.0/24, show the four /26 subnets with their ranges.
Self-check questions (with answers)
-
Question: How many bits are in an IPv4 address? In IPv6? Answer: IPv4: 32 bits. IPv6: 128 bits.
-
Question: What is the block size when subnetting a /24 into /26 subnets? What is the increment? Answer: Block size = 256 − 192 = 64. Increment = 64 in the last octet.
-
Question: Explain the count-to-infinity problem in distance-vector routing. Answer: When a link fails, routers slowly increment their distance to the destination as they exchange "stale" routes with each other. Each router advertises a route with cost one more than what it learned from its neighbor, and this propagates through the network, incrementing each hop, until the cost reaches infinity (usually 16 in RIP).
-
Question: What is the difference between ARP and RARP? Answer: ARP maps an IP address to a MAC address (IP → MAC); RARP maps a MAC address to an IP address (MAC → IP), and is now obsolete, replaced by DHCP.
-
Question: What does the "MF" flag in the IPv4 fragmentation header stand for, and what does it indicate? Answer: MF = "More Fragments". If set, more fragments follow; if clear, this is the last fragment.
-
Question: Why does IPv6 not need NAT? Answer: IPv6 has a 128-bit address space (~3.4 × 10^38 addresses), which is globally routable for every device; NAT was invented to conserve the limited IPv4 address space.
-
Question: Compare OSPF and BGP: which is used inside an AS, and which between ASes? Answer: OSPF is an interior gateway protocol (IGP) used inside a single autonomous system. BGP is an exterior gateway protocol (EGP) used between different autonomous systems.
-
Question: What is the purpose of the "Type of Service" (TOS) field in the IPv4 header? Answer: The TOS field requests preferential treatment for the datagram, such as low delay, high throughput, or high reliability. Modern implementations often use the Differentiated Services (DiffServ) field instead.
Unit 5: The Transport Layer
Teaching hours: 7
Topics in outline order
- Functions of the transport layer
- Elements of transport protocols
- UDP: user datagram, operations, uses, RPC
- Principles of reliable data transfer: stop-and-wait, pipelining, Go-Back-N, Selective Repeat
- TCP: services, features, segment header
- Principle of congestion control
Explanation
5.1 Functions of the transport layer
End-to-end delivery between processes, not hosts: service-point (port) addressing, segmentation and reassembly, connection establishment and release, flow control, error control, and multiplexing. Transport is the first true end-to-end layer; routers do not inspect it (except NAT and firewalls).
5.2 Elements of transport protocols
Addressing uses ports (well-known 0–1023, registered 1024–49151, dynamic 49152–65535). Connection establishment needs a three-way handshake because a two-way handshake can create duplicate connections. Release uses a four-way exchange with a TIME-WAIT state. Flow control uses a sliding window and buffering. Multiplexing/demultiplexing maps sockets to connections. Crash recovery is left to the application because transport state is lost with the host.
5.3 UDP: user datagram, operations, uses, RPC
An 8-byte header: source port, destination port, length, checksum. Connectionless, unreliable, no ordering, no flow control — but minimal overhead and no handshake delay. Used for DNS, DHCP, TFTP, streaming, VoIP, and gaming. RPC builds request-response calls on UDP or TCP, hiding network details behind procedure calls.
5.4 Principles of reliable data transfer: stop-and-wait, pipelining, Go-Back-N, Selective Repeat
Stop-and-wait sends one frame then waits; correct but wastes the link when propagation delay is large (utilisation = 1/(1+2a)). Pipelining sends multiple frames before ACKing. Go-Back-N uses a sender window of size N, cumulative ACKs, and retransmits the whole window after a loss. Selective Repeat buffers out-of-order frames and retransmits only the missing one; it needs a window no larger than half the sequence space to avoid ambiguity.
5.5 TCP: services, features, segment header
Connection-oriented, reliable, byte-stream service with full-duplex data, flow control, and congestion control. Features: sequence and acknowledgement numbers, checksum, urgent pointer, options, three-way handshake (SYN, SYN+ACK, ACK), four-way close, and a header of 20–60 bytes. Sliding window flow control uses the receiver's advertised window; silly-window syndrome and Nagle's algorithm are the classic efficiency issues.
5.6 Principle of congestion control
Congestion is network-wide overload, distinct from receiver flow control. TCP uses a congestion window and AIMD: slow start (exponential growth to threshold), congestion avoidance (linear growth), then multiplicative decrease on loss. Modern variants add fast retransmit/fast recovery, and algorithms such as Reno, NewReno, Cubic, and BBR differ in how they infer and react to congestion.
Key terms
Socket · ephemeral port · cumulative ACK · advertised window · slow start threshold · AIMD · TIME-WAIT · MSS
Revision points
- TCP header fields are a frequent diagram question: ports, sequence, acknowledgement, data offset, flags, window, checksum, urgent pointer.
- GBN discards out-of-order frames; SR buffers them — that one line carries most comparison marks.
- Congestion control protects the network; flow control protects the receiver.
Practice questions
- Why does TCP use a three-way handshake rather than two?
- A link has 1 Mbps bandwidth, 20 ms one-way propagation, and 1000-bit frames. Find stop-and-wait utilisation.
- Compare TCP and UDP on connection, reliability, ordering, and typical use.
Answer notes: (1) Two messages cannot confirm that both sides know the other's initial sequence number is received; a delayed duplicate connection request could open a half-open connection. The third message confirms the client received the server's SYN and ISN. (2) a = propagation/transmission = 20 ms / 1 ms = 20; utilisation = 1/(1+40) ≈ 2.4%, so pipelining is essential. (3) TCP: connection-oriented, reliable with ACKs and retransmission, ordered byte stream, flow and congestion control — web, email, file transfer. UDP: connectionless, unreliable, unordered datagrams, minimal header — DNS, streaming, VoIP, DHCP.
Worked example: Stop-and-wait utilisation calculation
Problem: A link has a bandwidth of 1 Mbps (10^6 bits/sec) and a one-way propagation delay of 20 ms. Frames are 1000 bits. Find the utilisation of stop-and-wait ARQ.
Solution:
- Transmission time (T_t) = frame size / bandwidth = 1000 bits / 10^6 bps = 1 ms.
- Propagation delay (T_p) = 20 ms (one-way).
- Round-trip time (RTT) = 2 × T_p + T_t = 2 × 20 ms + 1 ms = 41 ms. (We include the transmission time of the frame; the ACK transmission time is usually negligible.)
- Utilisation = useful time / total time = T_t / RTT = 1 ms / 41 ms ≈ 0.0244 = 2.44%.
Alternative formula: Utilisation = 1 / (1 + 2a) where a = T_p / T_t = 20 ms / 1 ms = 20. So utilisation = 1 / (1 + 2 × 20) = 1 / 41 ≈ 2.44%.
Intermediate result: The link is used only about 2.44% of the time; the rest of the time is wasted waiting for ACKs. This is why pipelining protocols (Go-Back-N, Selective Repeat) are essential for efficient links.
Use case: Choosing between TCP and UDP for a Nepali e-commerce site
An e-commerce startup in Kathmandu is building a web application. They choose TCP for the checkout flow (HTTP/HTTPS) because reliability is critical — a lost packet could mean a corrupted order, which is unacceptable. For product recommendation images, they use UDP or rely on TCP's default behaviour but with the understanding that occasional packet loss is acceptable for static images. For the real-time chat feature, they implement UDP with application-level ACKs, since low latency matters more than perfect reliability. This mix of protocols is a common design pattern in modern web applications.
Mermaid diagram: TCP segment header format
graph TB
A[TCP Segment Header] --> B[Source Port (16 bits)]
A --> C[Destination Port (16 bits)]
A --> D[Sequence Number (32 bits)]
A --> E[Acknowledgement Number (32 bits)]
A --> F[Data Offset (4 bits) + Reserved (4 bits)]
A --> G[Flags (6 bits): URG ACK PSH RST SYN FIN]
A --> H[Window Size (16 bits)]
A --> I[Checksum (16 bits)]
A --> J[Urgent Pointer (16 bits)]
A --> K[Options (0-40 bytes)]
subgraph Flag Descriptions
G --> G1[URG: Urgent Pointer significant]
G --> G2[ACK: Acknowledgement number significant]
G --> G3[PSH: Push function]
G --> G4[RST: Reset connection]
G --> G5[SYN: Synchronise sequence numbers]
G --> G6[FIN: No more data from sender]
end
Explanation: The TCP header is 20–60 bytes (20 bytes minimum, with options extending it up to 40 additional bytes). Key fields include source and destination ports for multiplexing, sequence and acknowledgement numbers for reliability, the data offset indicating where the data begins, 6 flag bits for connection control, the window size for flow control, and the checksum for error detection. The Urgent Pointer is only significant when the URG flag is set.
Common mistakes, limitations, and security concerns
- Mistake 1: Saying "TCP guarantees delivery". TCP guarantees reliable delivery (every byte arrives in order), but can still fail if the network is partitioned or the host crashes.
- Mistake 2: Confusing the three-way handshake with the four-way close. The handshake (SYN, SYN+ACK, ACK) establishes the connection; the close (FIN, ACK, FIN, ACK) terminates it, with a TIME-WAIT state on the initiator's side.
- Mistake 3: Thinking "UDP has no header". UDP has an 8-byte header (source port, destination port, length, checksum). It's minimal compared to TCP's 20+ bytes.
- Mistake 4: Forgetting that the TCP checksum covers a "pseudo-header" including source/destination IP, protocol, and UDP/TCP length, not just the segment.
- Security concern: A spoofed TCP RST packet can tear down a connection abruptly. A SYN flood can exhaust server resources (this is a denial-of-service attack). Always validate connection state.
Exam-ready answer points
Short answer (1–2 marks):
- What is the field in the TCP header that tells the receiver how much data it can accept? (window size)
- What is the MSS (Maximum Segment Size), and how is it determined? (usually derived from the MTU minus the TCP and IP header sizes)
- What is the purpose of the TIME-WAIT state? (to allow stale packets to expire and to ensure the connection is properly terminated)
- What does the UDP checksum cover? (the UDP header + data + a pseudo-header with source/destination IP, protocol, and length)
Long answer (5–10 marks):
- Compare TCP and UDP on all six dimensions: connection, reliability, ordering, flow control, congestion control, and overhead.
- Explain the TCP three-way handshake in detail, including the role of ISN (initial sequence number).
- Describe the TCP congestion control algorithm: slow start, congestion avoidance, fast retransmit, and fast recovery.
- Explain how sliding window flow control works: sender window, receiver advertised window, and the prevention of buffer overflow.
Diagram question:
- Draw the TCP segment header with all fields labeled.
- Draw the TCP three-way handshake with SYN, SYN+ACK, ACK and sequence number progression.
- Draw the stop-and-wait ARQ timer diagram, showing sender waiting for ACK.
Self-check questions (with answers)
-
Question: What is the difference between the TCP port numbers 0–1023 and 49152–65535? Answer: Ports 0–1023 are well-known ports assigned by IANA for common services (HTTP = 80, HTTPS = 443). Ports 49152–65535 are dynamic/private ports used for ephemeral connections, typically by the client side.
-
Question: Why does the TCP header have a 4-bit data offset field? What does it indicate? Answer: The 4-bit data offset indicates the number of 32-bit words in the header, telling the receiver where the data begins. The minimum offset is 5 (5 × 32 = 20 bytes), and the maximum is 15 (15 × 32 = 60 bytes) to accommodate options.
-
Question: What is the formula for stop-and-wait utilisation, and what does each variable mean? Answer: Utilisation =
1 / (1 + 2a)wherea = propagation time / transmission time. A high value of a (slow link, fast propagation) means low utilisation. -
Question: Compare Go-Back-N and Selective Repeat: how do they differ in handling lost frames? Answer: Go-Back-N retransmits all frames starting from the lost one (the sender's window slides, but all unacknowledged frames are re-sent). Selective Repeat retransmits only the missing frame(s), buffering out-of-order frames. SR requires the sender window ≤ 2^(n−1) where n is the sequence number field size to avoid ambiguity.
-
Question: What is AIMD, and how does it work in TCP congestion control? Answer: AIMD = Additive Increase Multiplicative Decrease. Slow start increases the congestion window exponentially (doubling each RTT) until the threshold is reached; then congestion avoidance increases it linearly (by ~1 MSS per RTT). On loss, the window is halved (multiplicative decrease), and slow start resumes from the new lower threshold.
-
Question: What is the difference between the TCP checksum and the UDP checksum? Are they computed differently? Answer: Both are one's-complement sums of the segment plus a pseudo-header. The pseudo-header includes source IP, destination IP, protocol number, and TCP/UDP length. TCP and UDP checksums use the same underlying computation, but the TCP checksum is mandatory in both IPv4 and IPv6, while the UDP checksum is optional in IPv4 and mandatory in IPv6.
Unit 6: The Application Layer
Teaching hours: 5
Topics in outline order
- Functions of the application layer
- Application layer protocols: DNS, DHCP, WWW, HTTP, HTTPS, TELNET, FTP, SMTP, POP, IMAP
- Traffic analysers: MRTG, PRTG, SNMP, Packet Tracer, Wireshark
Explanation
6.1 Functions of the application layer
The application layer provides the interface between user applications and the network: identifying services, defining message formats, and specifying interaction rules. Protocols here are often text-based and human-readable, which is why they are easy to inspect in a packet capture.
6.2 Application layer protocols: DNS, DHCP, WWW, HTTP, HTTPS, TELNET, FTP, SMTP, POP, IMAP
DNS. Name resolution through a distributed hierarchy: root, top-level domain, authoritative servers, with recursive resolvers and caching. Records: A, AAAA, CNAME, MX, NS, PTR, TXT. DHCP assigns addresses dynamically with the DORA exchange (Discover, Offer, Request, Acknowledge), plus lease renewal, static reservations, and relay agents across subnets.
WWW and HTTP. The web is a hyperlinked document system over HTTP. HTTP is a request-response protocol: methods GET, POST, PUT, DELETE, HEAD, OPTIONS; status classes 1xx–5xx; headers for content type, caching, cookies. HTTP/1.1 added persistent connections; HTTP/2 multiplexes streams over one connection; HTTP/3 runs over QUIC/UDP.
HTTPS is HTTP over TLS: the handshake authenticates the server with a certificate, agrees keys, and then encrypts and integrity-protects the traffic. It provides confidentiality, integrity, and server authentication (and optional client authentication).
TELNET is a plaintext remote-login protocol on port 23, replaced by SSH because it sends credentials in clear text. FTP uses two connections — control on port 21 and data on port 20 (active) or an ephemeral port (passive) — and transmits credentials in clear text.
SMTP, POP, IMAP. SMTP (port 25, or 587/465 with authentication and TLS) pushes mail between servers and from client to server. POP3 (110/995) downloads mail and typically deletes it from the server. IMAP (143/993) keeps mail on the server and synchronises state and folders across devices.
6.3 Traffic analysers: MRTG, PRTG, SNMP, Packet Tracer, Wireshark
SNMP polls managed devices for structured MIB data and sends traps. MRTG graphs interface traffic using SNMP counters and RRDtool. PRTG is a commercial monitoring suite combining SNMP, packet capture, and alerting. Wireshark is a protocol analyser that captures and dissects frames with display filters. Packet Tracer is a network simulation tool for building topologies and watching protocol behaviour without hardware.
Key terms
Recursive vs iterative query · TTL and caching · DORA · MIME · passive FTP · TLS handshake · MIB/OID · capture filter vs display filter
Revision points
- Pair each protocol with its port and transport: DNS 53 (UDP/TCP), DHCP 67/68 UDP, HTTP 80 TCP, HTTPS 443 TCP, FTP 20/21 TCP, SMTP 25 TCP, POP3 110 TCP, IMAP 143 TCP, SNMP 161/162 UDP.
- Explain HTTPS as "HTTP semantics plus a TLS session", not as a different application protocol.
- A packet capture proves what happened; MRTG/PRTG show trends; SNMP supplies the counters both rely on.
Practice questions
- Trace the DNS resolution of
www.example.comfrom a cold cache, naming each server type. - Why is passive FTP usually required behind NAT and firewalls?
- An administrator needs long-term interface utilisation graphs from switches. Which protocols and tools apply?
Answer notes: (1) Stub resolver asks its recursive resolver; resolver asks a root server for the .com delegation, then the .com TLD server for example.com, then the authoritative nameserver for the A/AAAA record; the answer is cached with its TTL. (2) Active FTP has the server open a data connection back to the client, which inbound NAT/firewall rules block; passive mode has the client initiate both connections. (3) SNMP counters read from each device, collected into MRTG (RRDtool graphs) or PRTG for dashboards and alerts; Wireshark is for spot diagnosis, not long-term graphing.
Worked example: DNS resolution of www.example.com from a cold cache
Problem: A stub resolver on a laptop needs to resolve www.example.com. The resolver's cache is cold (no prior entries). Trace the resolution steps, naming each server type involved.
Solution:
- Stub resolver sends a recursive query to the recursive resolver (typically the ISP's DNS or a public resolver like 1.1.1.1). The cache is empty, so the query must go out.
- The recursive resolver starts at the root server. It sends a query for
comto a root server. Root servers have the IP addresses of TLD servers, not authoritative data for specific domains. The root responds with the address of a.comTLD server (this is a referrals-based, iterative response). - The resolver sends a query for
example.comto the.comTLD server. The TLD server doesn't have the answer either, but it knows which authoritative servers serveexample.com. It returns the address of theexample.comauthoritative nameserver. - The resolver sends a query for
www.example.comto theexample.comauthoritative nameserver. The authoritative server has the zone file forexample.comand returns the A record (IPv4 address) forwww.example.com, e.g.,93.184.216.34. - The resolver caches the A record with its TTL (typically 24–48 hours), and returns the IP address to the stub resolver, which passes it to the HTTP client.
Intermediate steps: (1) The resolver starts with a cold cache and must traverse the hierarchy. (2) Each step is iterative: the resolver asks one server, gets a referral, and asks the next. (3) The root server knows TLDs; the TLD server knows authoritative servers; the authoritative server has the A record. (4) The final answer is cached with a TTL, so subsequent queries for the same name can be answered without another full traversal.
Summary: Cold-cache DNS resolution requires 3 round trips: resolver → root (referral), resolver → TLD (referral), resolver → authoritative (A record). With a warm cache, the resolver can answer locally in 1 round trip.
Use case: Setting up a local DNS server for a Nepali office
A small office in Pokhara wants to host an internal website (intranet.local) and resolve internal hostnames. They install dnsmasq on a Linux server, which forwards external queries to the ISP's DNS and answers internal queries from a local table. The DHCP server hands out the dnsmasq server's IP as the DNS resolver, so all devices automatically use it. When a user types intranet.local, the dnsmasq server responds with the internal IP (e.g., 192.168.1.50) from its static lease table, without querying the external DNS.
Mermaid diagram: DNS resolution hierarchy
graph TD
A[Stub Resolver] --> B[Recursive Resolver]
B --> C[Root Server]
C -->|Referral| D[TLD Server (.com)]
D -->|Referral| E[Authoritative Nameserver]
E -->|A Record| F[IP Address (93.184.216.34)]
F -->|Cache| B
Explanation: The diagram shows the flow of a DNS query from the stub resolver up through the recursive resolver, root server (which refers to the TLD), TLD server (which refers to the authoritative nameserver), and finally the authoritative server which returns the A record. The result is cached at the recursive resolver for future queries.
Common mistakes, limitations, and security concerns
- Mistake 1: Saying "DNS uses TCP port 53". DNS primarily uses UDP port 53; TCP is used only for large responses ( > 512 bytes) with the truncation flag set, or for zone transfers (AXFR).
- Mistake 2: Thinking "DHCP assigns permanent IP addresses". DHCP leases addresses for a configurable time; they can be renewed or released. Static reservations can map a MAC address to a permanent IP, but this is an administrator-configured exception.
- Mistake 3: Confusing "passive FTP" with "active FTP" directions. In active FTP, the server initiates the data connection to the client; in passive FTP, the client initiates both connections. Passive FTP is preferred behind NAT.
- Security concern: DNS cache poisoning can divert traffic to malicious sites. DNSSEC adds cryptographic signatures to responses, so clients can verify authenticity. TLS in HTTPS protects against eavesdropping on HTTP traffic.
Exam-ready answer points
Short answer (1–2 marks):
- What port does DNS use, and when is TCP used instead of UDP? (UDP 53 normally; TCP for large responses or zone transfers)
- What is the DORA exchange in DHCP? (Discover, Offer, Request, Acknowledge)
- What is the difference between POP3 and IMAP? (POP3 downloads and typically deletes; IMAP keeps on server and synchronises)
- What does HTTPS provide that HTTP does not? (confidentiality, integrity, server authentication via TLS)
Long answer (5–10 marks):
- Describe the full DNS resolution process from a cold cache, including all server types and the referrals between them.
- Compare the three main mail protocols: SMTP (send), POP3 (receive, download-and-delete), and IMAP (receive, synchronise on server).
- Explain how HTTP version differences affect performance: HTTP/1.1 persistent connections, HTTP/2 multiplexing, HTTP/3 QUIC.
- Describe how SNMP monitoring works: manager, agent, MIB, get/SET, and trap notifications.
Diagram question:
- Draw the DNS hierarchy: stub → recursive → root → TLD → authoritative.
- Draw an Ethernet frame being captured by Wireshark, with display filter
ip.src == 192.168.1.10. - Draw the TCP header format with fields labeled.
Self-check questions (with answers)
-
Question: What is the difference between a recursive DNS query and an iterative DNS query? Answer: In a recursive query, the resolver asks the DNS system to fully answer the query, possibly making multiple queries itself. In an iterative query, the resolver asks a server, which gives the best answer it can (possibly a referral to another server), and the resolver follows the referral.
-
Question: List the well-known ports for HTTP, HTTPS, FTP control, SMTP, POP3, IMAP, and DNS. Answer: HTTP = 80, HTTPS = 443, FTP control = 21, SMTP = 25, POP3 = 110, IMAP = 143, DNS = 53.
-
Question: What are the four steps of the DHCP DORA exchange? Answer: Discover (client broadcasts), Offer (server unicast), Request (client unicast), Acknowledge (server unicast).
-
Question: Explain why SSH is preferred over TELNET for remote login. Answer: TELNET sends all data, including credentials, in plain text. SSH encrypts the session, including login credentials, and provides strong authentication and integrity checking.
-
Question: What is the function of the "More Fragments" (MF) flag in IPv4 fragmentation? Answer: The MF flag indicates whether more fragments follow (set) or this is the last fragment (clear). It works with the fragment offset to reassemble the original datagram.
-
Question: How does SNMP differ from Wireshark for network monitoring? Answer: SNMP is for long-term data collection and graphing (counters, uptime, interface traffic); Wireshark is for spot diagnosis and protocol analysis (capturing packets, inspecting fields, display filters).
-
Question: What is a "display filter" in Wireshark, and how does it differ from a "capture filter"? Answer: A display filter filters packets after capture, showing only those matching the expression. A capture filter filters packets before they are saved to disk, using libpcap/BPF syntax. Capture reduces storage; display is for analysis.
-
Question: What does the "TTL" field in a DNS response mean, and how does the stub resolver use it? Answer: TTL (Time to Live) is the number of seconds the DNS answer is considered valid. The stub resolver caches the answer for TTL seconds; after that, it must re-resolve the name.
Unit 7: Network Security
Teaching hours: 5
Topics in outline order
- A model for network security
- Principles of cryptography: symmetric key and public key
- Public key algorithm: RSA
- Digital signature algorithm
- Communication security: IPSec, VPN, firewalls, wireless security
Explanation
7.1 A model for network security
A sender transforms a message with a secret or key, sends it over an untrusted channel where an opponent may intercept, modify, or inject, and a receiver reverses the transformation. Security services are confidentiality, integrity, authentication, non-repudiation, and availability; mechanisms include encryption, MACs, signatures, and access control. The model also requires a trusted third party for key distribution.
7.2 Principles of cryptography: symmetric key and public key
Symmetric cryptography. One shared key encrypts and decrypts — fast, suitable for bulk data. Classical ciphers: substitution and transposition. Modern: DES (56-bit, broken), 3DES, AES (128/192/256-bit block cipher, the standard). The hard problem is key distribution: n users need n(n−1)/2 keys.
Public-key cryptography. Each user has a key pair: the public key encrypts or verifies, the private key decrypts or signs. It solves distribution (publish the public key) but is slow, so real systems use a hybrid: public key to exchange a symmetric session key, symmetric cipher for the data. Diffie-Hellman key exchange and RSA are the classic algorithms; both rest on hard problems (discrete logarithm, integer factorisation).
7.3 Public key algorithm: RSA
Choose primes p and q, n = pq, φ(n) = (p−1)(q−1); pick e coprime to φ(n); compute d = e⁻¹ mod φ(n). Public key (e, n), private key (d, n). Encryption C = M^e mod n, decryption M = C^d mod n. Security rests on the difficulty of factoring n; key sizes of 2048 bits and above are current practice, and padding (OAEP) is required in real use.
7.4 Digital signature algorithm
A signature proves origin and integrity and provides non-repudiation: the signer hashes the message and encrypts the hash with the private key; the verifier decrypts with the public key and compares hashes. DSA/ECDSA are standard signature schemes. A signature alone does not provide confidentiality — it is often combined with encryption. Certificates bind a public key to an identity, signed by a certificate authority.
7.5 Communication security: IPSec, VPN, firewalls, wireless security
IPSec protects IP packets at the network layer with AH (integrity and authentication) and ESP (confidentiality plus integrity), in transport or tunnel mode, with IKE for key agreement. A VPN tunnels private traffic over a public network using IPSec, TLS, or WireGuard. Firewalls filter by packet header (stateless), by connection state, or by application content (proxy/WAF); the DMZ hosts public services. Wireless security evolved from WEP (broken) to WPA, WPA2 (AES-CCMP), and WPA3 (SAE, forward secrecy); enterprise mode uses 802.1X authentication, and WPS should be disabled.
Key terms
Plaintext/ciphertext · block vs stream cipher · hybrid encryption · OAEP · hash (SHA-256) · MAC vs signature · AH vs ESP · stateful inspection · WPA2-PSK vs 802.1X
Revision points
- Symmetric solves speed, asymmetric solves distribution; hybrid uses both — say this in any "which encryption" answer.
- Signing uses the private key; encrypting for confidentiality uses the recipient's public key. Reversing these is the most common exam error.
- IPSec is layer 3 and transparent to applications; TLS is layer 5-7 and per-application.
Practice questions
- With p = 3, q = 11, e = 7, compute n, φ(n), d, and encrypt M = 5.
- Explain how a digital signature provides integrity and non-repudiation but not confidentiality.
- Compare IPSec and TLS VPNs on layer, typical use, and client requirements.
Answer notes: (1) n = 33, φ = 20, d = 3 (7×3 = 21 ≡ 1 mod 20); C = 5^7 mod 33 = 78125 mod 33 = 14. (2) The hash binds the message; encrypting the hash with the private key means only the holder of that key could have produced it, and any change alters the hash. The message itself is still readable unless separately encrypted. (3) IPSec operates at layer 3, protects all IP traffic, and is common for site-to-site tunnels; it needs OS or gateway support. TLS VPNs work at the application/session layer, usually over TCP 443, need only a browser or client app, and are common for remote-access users.
Worked example: RSA encryption and decryption
Problem: Given RSA parameters p = 3, q = 11, e = 7, encrypt the message M = 5.
Solution:
- Compute n = p × q = 3 × 11 = 33.
- Compute φ(n) = (p − 1)(q − 1) = (3 − 1)(11 − 1) = 2 × 10 = 20.
- Verify that e = 7 is coprime to φ(n) = 20. The GCD(7, 20) = 1, so they are coprime.
- Compute d = e⁻¹ mod φ(n), i.e., find d such that (e × d) mod φ(n) = 1. We need 7d ≡ 1 (mod 20). Testing: 7 × 3 = 21, and 21 mod 20 = 1. So d = 3.
- Public key: (e = 7, n = 33). Private key: (d = 3, n = 33).
- Encrypt: C = M^e mod n = 5^7 mod 33. Compute 5^7 = 78125. Then 78125 mod 33: 33 × 2367 = 78111, so 78125 − 78111 = 14. Alternatively, compute step by step: 5^2 = 25 mod 33 = 25; 5^4 = 25^2 = 625 mod 33 = 625 − 33 × 18 = 625 − 594 = 31; 5^7 = 5^4 × 5^2 × 5 = 31 × 25 × 5 = 3875 mod 33 = 3875 − 33 × 117 = 3875 − 3861 = 14. So C = 14.
- Decrypt: M = C^d mod n = 14^3 mod 33 = 2744 mod 33. 33 × 83 = 2739, so 2744 − 2739 = 5. Thus M = 5, which matches the original message.
Intermediate results: n = 33, φ = 20, d = 3, ciphertext C = 14, recovered message M = 5.
Use case: Secure wireless network for a Nepali office
An office in Lalitpur sets up a wireless network for 20 employees. They configure the router with WPA3-Personal using a strong passphrase (16+ characters, mix of letters, numbers, and symbols). The router uses SAE (Simultaneous Authentication of Equals) for key establishment, which provides forward secrecy — if the passphrase is compromised later, past sessions cannot be decrypted. For the guest network, they configure WPA2-PSK with a separate passphrase, and disable WPS. They also enable 802.1X with RADIUS for the BYOD devices, requiring each user to authenticate with their corporate credentials. The network uses AES-CCMP for encryption, and the router's firewall blocks inbound connections to the internal LAN.
Mermaid diagram: Symmetric vs asymmetric vs hybrid encryption
graph TB
A[Symmetric Encryption] -->|Fast, shared key| B[Suitable for bulk data]
C[Asymmetric Encryption] -->|Slow, key pair| D[Suitable for key exchange]
B -->|Session key| E[Hybrid System]
D -->|Session key| E
E -->|Encrypt data| F[High performance + key security]
Explanation: The diagram shows the three encryption approaches. Symmetric encryption (AES) is fast and used for bulk data encryption but has a key distribution problem. Asymmetric encryption (RSA/ECC) solves key distribution but is slow; it's used to exchange a symmetric session key. The hybrid system combines both: use asymmetric encryption to securely share a symmetric key, then use symmetric encryption for the actual data. This gives the best of both worlds.
Common mistakes, limitations, and security concerns
- Mistake 1: Saying "AES is unbreakable". AES is practically unbreakable with adequate key sizes (128 bits and above), but theoretical attacks exist for reduced-round versions, and side-channel attacks (timing, power analysis) can compromise implementations.
- Mistake 2: Reversing the roles of public and private keys in RSA. The public key encrypts/verifies; the private key decrypts/signs. The reverse is wrong — anyone with the private key could forge signatures, and anyone with the public key could decrypt, defeating the purpose.
- Mistake 3: Thinking "if TLS uses RSA, the private key is on the client". In typical TLS, the server holds the private key; the client verifies the server's certificate. The client's private key (if client authentication is used) is separate and rare.
- Limitation: RSA is vulnerable to quantum computing via Shor's algorithm, which can factor large integers in polynomial time. Post-quantum cryptography (e.g., lattice-based schemes) is under standardization.
- Security concern: Weak RSA keys (small e, small p·q differences) can be factored. Use key sizes of at least 2048 bits. Avoid exporting cryptographic keys over insecure channels. WPS (Wi-Fi Protected Setup) is known to be exploitable; it should be disabled.
Exam-ready answer points
Short answer (1–2 marks):
- What are the three security services provided by the CIA triad? (confidentiality, integrity, availability)
- What is the third security service added to make CIA triad into CIAAD? (authentication, then non-repudiation)
- What does IPSec AH provide? (integrity and authentication, no confidentiality)
- What does IPSec ESP provide? (confidentiality plus integrity)
- What is the main difference between WPA2-PSK and WPA2-Enterprise? (PSK uses a shared passphrase; Enterprise uses 802.1X with individual credentials)
Long answer (5–10 marks):
- Describe the network security model: sender, untrusted channel, opponent, receiver, and security services (confidentiality, integrity, authentication, non-repudiation, availability).
- Compare symmetric and asymmetric cryptography: speed, key distribution, use cases. Explain the hybrid approach.
- Walk through the RSA algorithm with a small example (key generation, encryption, decryption).
- Explain how a digital signature provides integrity and non-repudiation but not confidentiality.
- Compare IPSec VPN and TLS VPN: layer of operation, typical use (site-to-site vs remote-access), and client requirements.
Diagram question:
- Draw the network security model with sender, channel, opponent, receiver, and security services.
- Draw the RSA key generation, encryption, and decryption steps with small numbers.
- Draw the hybrid encryption architecture: asymmetric for key exchange, symmetric for data.
Self-check questions (with answers)
-
Question: What are the five security services in the network security model, and which are provided by the CIA triad? Answer: The five services are confidentiality, integrity, authentication, non-repudiation, and availability. The CIA triad provides confidentiality, integrity, and availability; authentication and non-repudiation are the two additional services.
-
Question: In symmetric cryptography, if n users need to communicate securely, how many distinct keys are required if each pair shares a unique key? Answer: n(n−1)/2 keys. Each user has a unique key with every other user.
-
Question: What does the RSA modulus n equal, and how is it computed? Answer: n = p × q, where p and q are large prime numbers. The security of RSA rests on the difficulty of factoring n.
-
Question: Explain why encrypting a hash with the private key creates a signature, and why the message itself is not confidential. Answer: The hash binds the message to the signer; only the holder of the private key could have produced that hash encrypted. The message is sent in plaintext (or separately encrypted), so confidentiality is not provided by the signature alone.
-
Question: What is the difference between IPSec transport mode and tunnel mode? Answer: In transport mode, only the payload is encrypted; the original header is preserved. In tunnel mode, the entire original packet is encapsulated in a new packet with new headers; the original packet is hidden. Tunnel mode is common for site-to-site VPNs; transport mode is less common.
-
Question: Why should WPS be disabled on a wireless router? Answer: WPS (Wi-Fi Protected Setup) has known vulnerabilities (e.g., PIN brute-force) that allow an attacker to recover the Wi-Fi password. Disabling WPS eliminates this attack vector.
-
Question: What is forward secrecy, and which protocol provides it in WPA3? Answer: Forward secrecy means that if the long-term key is compromised, past session keys cannot be derived. WPA3 provides forward secrecy via SAE (Simultaneous Authentication of Equals) in the handshake.
-
Question: Compare stateful inspection (firewall) and deep packet inspection (IPS/IDS). Which examines payload? Answer: Stateful inspection tracks connection state and filters based on packet headers and connection context. DPI (used by IPS) examines packet payloads for known attack patterns. DPI is more thorough but can impact performance and raise privacy concerns.
Exam Strategy
- Draw the layer diagram first in any broad question; label PDUs and devices.
- For numerical questions, state the formula before substituting — partial marks are usually allocated to the formula.
- Keep one page of "port and protocol" and one page of "subnetting steps" as your revision anchors.
- Practice writing comparisons as tables with fixed dimensions; it is faster and scores more reliably than prose.
References
- TU document: https://portal.tu.edu.np/downloads/BCA_Syllabus-compressed_compre_2024_01_30_18_33_22.pdf
- Location: PDF p. 81-84
- SHA-256: sha256:d126d513c1051b176b03e56e067608546786d279b596b7b431ecff4d944496cb
This guide is derived from an earlier TU syllabus outline (CACS303) for BCA301 Computer Networking. The available compilation contains sections printed in different years. The 2025 TU curriculum lists this course in the semester 5 structure but does not publish a detailed unit outline. This guide follows the archived outline and is not a statement of official 2025 TU wording.