Computer Networks
1. Network Models
1.1 The OSI Reference Model
The Open Systems Interconnection (OSI) model defines seven layers of abstraction for network Communication:
| Layer | Name | Function | Examples |
|---|---|---|---|
| 7 | Application | User-facing protocols | HTTP, DNS, SMTP, FTP |
| 6 | Presentation | Data representation, encryption, compression | TLS, SSL, JPEG, ASCII |
| 5 | Session | Dialog control, synchronisation | NetBIOS, RPC, PPTP |
| 4 | Transport | End-to-end reliability, flow control | TCP, UDP, SCTP |
| 3 | Network | Logical addressing, routing | IP, ICMP, ARP, OSPF |
| 2 | Data Link | Framing, error detection, MAC | Ethernet, Wi-Fi, PPP |
| 1 | Physical | Bit transmission on the medium | Cables, hubs, radio waves |
Encapsulation. Each layer adds its own header (and possibly trailer) to the data from the layer Above, forming a protocol data unit (PDU):
1.2 The TCP/IP Model
The TCP/IP model is the practical standard used on the Internet, with four layers:
| Layer | OSI Equivalent | Protocols |
|---|---|---|
| Application | 5, 6, 7 | HTTP, DNS, SMTP, TLS |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP, ARP |
| Network Access | 1, 2 | Ethernet, Wi-Fi, MAC |
1.3 Comparison
The OSI model is a theoretical reference used for teaching and design. The TCP/IP model reflects Actual protocol implementations. The session and presentation layers in OSI are absorbed into the Application layer in TCP/IP.
Detailed OSI vs TCP/IP comparison:
| Aspect | OSI Model | TCP/IP Model |
|---|---|---|
| Layers | 7 | 4 |
| Nature | Theoretical reference model | Practical implementation model |
| Session/Presentation | Separate layers (5, 6) | Merged into Application layer |
| Network layer | Connection-oriented and connectionless | Primarily connectionless (IP) |
| Transport layer | TP4 (reliable) and TP0 (unreliable) | TCP (reliable) and UDP (unreliable) |
| Standardisation | ISO/IEC | IETF (RFCs) |
| Adopted by | Academic, government | The global Internet |
| Protocol independence | Layer-independent protocols | Protocols tightly coupled |
| Service interface | Precisely defined (SAPs) | Loosely defined |
| Release | 1984 | Developed 1970s, formalised 1980s |
1.4 Protocol Data Unit Encapsulation
Each layer encapsulates data from the layer above by prepending a header (and appending a trailer at Layer 2). The resulting data unit is named according to its layer:
| Layer | PDU Name | Header Added | Trailer | Size (typical) |
|---|---|---|---|---|
| Application | Data | Application-specific | None | Variable |
| Transport | Segment | TCP/UDP header | None | 20—60 bytes |
| Network | Packet | IP header | None | 20—60 bytes |
| Data Link | Frame | MAC header | FCS | 14—18 + 4 B |
| Physical | Bits | None (encoding) | None | N/A |
Encapsulation walkthrough. Consider sending an HTTP GET request of 500 bytes through TCP/IP over Ethernet:
- Application layer: HTTP creates a request message (500 bytes).
- Transport layer: TCP adds a 20-byte header. Segment = 520 bytes.
- Network layer: IP adds a 20-byte header. Packet = 540 bytes.
- Data Link layer: Ethernet adds 14-byte header + 4-byte FCS. Frame = 558 bytes.
- Physical layer: Frame is encoded into bits and transmitted on the medium.
Decapsulation. At the receiver, each layer strips its corresponding header before passing data To the layer above. This process is the reverse of encapsulation.
2. Physical Layer
2.1 Transmission Media
Guided media: Twisted pair (UTP, STP), coaxial cable, fibre optic.
- Twisted pair: Category 5e/6/6a for Ethernet. Bandwidth up to 10 Gbps (Cat 6a, 100 m).
- Fibre optic: Single-mode (long distance, laser) and multi-mode (shorter distance, LED). Bandwidth up to 100+ Gbps.
Unguided media: Radio waves, microwaves, infrared. Subject to attenuation, interference, and Line-of-sight constraints.
2.2 Signaling
Analog vs. Digital. Analog signals vary continuously; digital signals are discrete.
- Bandwidth: Range of frequencies a channel can carry, measured in Hz.
- Bit rate: Number of bits transmitted per second (bps).
- Nyquist theorem: For a noiseless channel of bandwidth Hz with discrete signal levels:
Theorem 2.1 (Nyquist—Shannon Sampling Theorem). A bandlimited signal of bandwidth Hz can Be perfectly reconstructed from samples taken at a rate of at least samples per second.
Proof. Let be a signal with Fourier transform such that for . Sampling at rate produces Where . In the frequency domain, . When The spectral copies do not overlap, and can be recovered by an ideal Lowpass filter with cutoff . When Aliasing occurs and perfect recovery is Impossible.
- Shannon capacity: For a noisy channel with signal-to-noise ratio :
Theorem 2.2 (Shannon—Hartley Theorem). The channel capacity is the maximum error-free data Rate achievable on a channel of bandwidth with signal-to-noise ratio .
Proof. For a bandlimited AWGN channel, the number of distinguishable signal levels is constrained By the noise power. Let where is signal power and is noise Power. The number of distinguishable amplitude levels is proportional to . With levels per signal element and signal elements per second (Nyquist), the maximum Error-free rate is .
Example. A telephone line has Hz and (35 dB). Shannon limit: bps.
Worked Example: Nyquist Bit Rate
A noiseless channel has a bandwidth of 4000 Hz. How many signal levels are needed to achieve a data Rate of 56000 bps?
Using Nyquist”s formula:
Answer: 128 signal levels are required.
Worked Example: Shannon Channel Capacity
A satellite channel has a bandwidth of 36 MHz and an SNR of 30 dB. Find the maximum data rate.
First convert SNR from dB to linear: \mathrm{SNR_}{\mathrm{linear} = 10^{30/10} = 1000}
Apply Shannon’s formula:
Answer: The maximum achievable data rate is approximately 358.8 Mbps. Any attempt to exceed This rate will result in an unacceptable error rate regardless of the modulation scheme used.
Worked Example: Comparing Nyquist and Shannon Limits
A channel has Hz and (30 dB).
Shannon limit:
Nyquist limit with :
The Nyquist limit (36 kbps) is below the Shannon limit (60 kbps), so 8 signal levels are Achievable. With :
This exceeds Shannon’s limit of 60 kbps, meaning 64 levels would produce errors. The maximum Number of levels consistent with Shannon:
Answer: At most 32 signal levels can be used reliably on this channel.
:::caution Common Pitfall Bandwidth (Hz) and bit rate (bps) are different quantities. Bandwidth is the range of frequencies The channel can carry; bit rate is the number of bits transmitted per second. Shannon’s theorem Relates the maximum bit rate to bandwidth and SNR, but they are not interchangeable. :::
2.3 Multiplexing
Frequency-Division Multiplexing (FDM). Divide bandwidth into non-overlapping frequency bands. Each user gets a dedicated band. Used in radio and cable TV.
Time-Division Multiplexing (TDM). Divide time into fixed slots; each user gets a slot per cycle. Synchronous TDM assigns slots statically; statistical TDM assigns dynamically based on demand.
Wavelength-Division Multiplexing (WDM). FDM for fibre optics. Multiple wavelengths share a Single fibre. Dense WDM (DWDM) supports 80+ channels.
Code-Division Multiple Access (CDMA). Each user is assigned a unique code. All users transmit Simultaneously on the same frequency; codes are mathematically orthogonal so receivers can isolate Their signal.
2.4 Modulation
Digital-to-analog modulation: ASK (Amplitude Shift Keying), FSK (Frequency Shift Keying), PSK (Phase Shift Keying). QAM combines ASK and PSK for higher data rates.
- 16-QAM encodes 4 bits per symbol (16 combinations of amplitude and phase).
- 256-QAM encodes 8 bits per symbol.
- 1024-QAM encodes 10 bits per symbol (used in Wi-Fi 6).
Theorem 2.3 (QAM spectral efficiency). An -ary QAM scheme where has a spectral Efficiency of bits/symbol, i.e., the bit rate equals where is the bandwidth In Hz.
Proof. QAM modulates both amplitude and phase of a carrier. With symbols, each symbol carries bits. The symbol rate equals the bandwidth (Nyquist: 2 symbols/Hz for Baseband, 1 symbol/Hz for passband). Therefore bit rate = .
Worked Example: QAM Data Rate Calculation
A 256-QAM modem operates over a 20 MHz channel. What is the maximum data rate?
If the channel has SNR = 24 dB, verify against Shannon:
\mathrm{SNR_}{\mathrm{linear} = 10^{24/10} = 251.2}
The Nyquist-based rate (160 Mbps) is very close to the Shannon limit (159.6 Mbps), meaning 256-QAM Is near-optimal for this channel but has almost no margin for noise or interference.
2.5 Line Coding
Line codes map binary data to signals suitable for the physical medium.
| Encoding | Description | Example |
|---|---|---|
| NRZ (L) | High = 1, Low = 0 | USB |
| NRZI | Transition = 1, no transition = 0 | USB |
| Manchester | Transition at mid-bit; low-to-high = 0 | 802.3 (10 Mbps) |
| Differential Manchester | Transition at start of 0 bit only | 802.5 (Token Ring) |
| 4B/5B | 4 data bits encoded as 5-bit codes | 100BASE-TX |
| 8B/10B | 8 data bits encoded as 10-bit codes | Gigabit Ethernet |
| 64B/66B | 64 data bits encoded as 66-bit codes | 10GBASE-R |
Spectral efficiency. Manchester encoding doubles the bandwidth requirement (two signal levels per Bit). 4B/5B adds 25% overhead. 8B/10B adds 25%. 64B/66B adds only 3% overhead.
Scrambling. High-density bipolar 3 (HDB3) and other scrambling techniques ensure sufficient Transitions for clock recovery, preventing long runs of identical bits.
3. Data Link Layer
3.1 Framing
The data link layer receives a bit stream and divides it into manageable frames.
Framing methods:
- Byte count: First field specifies frame length. Vulnerable to corrupted count.
- Flag bytes: Special flag byte (
0x7Efor HDLC) marks start/end. Byte stuffing with escape byte (0x7D) prevents ambiguity. - Bit-oriented flags: Flag pattern
01111110. Bit stuffing: insert0after five consecutive1S in the data. - Clock-based: Manchester encoding provides self-clocking and frame boundaries.
3.2 Error Detection and Correction
Error types: Single-bit errors (one bit flipped), burst errors (multiple consecutive bits).
Hamming distance. is the number of bit positions where codewords and differ. The minimum distance determines capability:
- Detect up to errors.
- Correct up to errors.
Hamming code. Adds parity bits to data bits where . Each parity bit Covers positions whose binary representation has a 1 in a specific bit position.
Example (Hamming(7,4)). 4 data bits, 3 parity bits. : detects 2 errors, corrects 1.
Worked Example: Hamming(7,4) Encoding and Error Correction
Encoding. Transmit data bits .
Codeword positions (1-indexed): . Place data bits: position 3 = 1, position 5 = 0, position 6 = 1, position 7 = 1.
Parity bits cover positions whose binary index has a 1 in the corresponding bit:
covers positions with bit 0 set: {1, 3, 5, 7}. covers positions with bit 1 set: {2, 3, 6, 7}. covers positions with bit 2 set: {4, 5, 6, 7}.
Calculate parity bits (even parity):
: positions 1, 3, 5, 7 data at 3, 5, 7 are 1, 0, 1. Sum = 0 (even) .
: positions 2, 3, 6, 7 data at 3, 6, 7 are 1, 1, 1. Sum = 1 (odd) .
: positions 4, 5, 6, 7 data at 5, 6, 7 are 0, 1, 1. Sum = 0 (even) .
Transmitted codeword:
Error correction. Suppose bit 6 is flipped during transmission. Received word:
Compute syndrome bits:
: check positions 1, 3, 5, 7 (even, OK).
: check positions 2, 3, 6, 7 (odd, error).
: check positions 4, 5, 6, 7 (odd, error).
Syndrome = . The error is at position 6. Flip bit 6: Corrected word = .
Answer: The Hamming code detects and corrects the single-bit error at position 6.
Cyclic Redundancy Check (CRC). A polynomial code widely used (Ethernet, Wi-Fi, USB).
- Append zero bits to the message ( = degree of generator polynomial ).
- Divide the augmented message polynomial by using modulo-2 arithmetic.
- Append the remainder (CRC) to the original message.
- Receiver divides by ; zero remainder means no error.
Theorem 3.1. CRC detects all single-bit errors, all double-bit errors (if has factor ), all odd-numbered errors, and all burst errors of length .
Worked Example: CRC Polynomial Division
Compute the CRC for message 110100 using generator (binary 1011Degree ).
Step 1: Append zero bits augmented message: 110100000.
Step 2: Perform modulo-2 (XOR) polynomial division.
Division steps:
. Multiply: . Subtract (XOR): .
. Multiply: . Subtract: .
. Multiply: . Subtract: .
. Multiply: . Subtract: .
Degree of (which is 2) is less than degree of (which is 3). Stop.
Remainder: = binary 100.
Step 3: Append remainder to original message. Transmitted codeword: 110100100.
Verification. The receiver divides 110100100 by 1011. Since was chosen as the remainder, So the division yields remainder 0, Confirming no error.
3.3 MAC Protocols
ALOHA. Transmit whenever ready; if collision, wait random time and retransmit.
- Pure ALOHA: Throughput Maximum at : .
- Slotted ALOHA: Time divided into slots; transmit at slot boundary. Maximum at : .
CSMA (Carrier Sense Multiple Access). Listen before transmitting.
- 1-persistent: If busy, wait; transmit immediately when idle. High collision probability.
- Non-persistent: If busy, wait random time before sensing again. Lower collision, higher delay.
- p-persistent: If busy, wait until idle, then transmit with probability .
CSMA/CD (Collision Detection). Used in wired Ethernet (802.3). Transmit and listen simultaneously; If collision detected, send jam signal and wait random backoff.
- Binary exponential backoff: After -th collision, choose random and wait bit times.
- Minimum frame size: Must be at least where is the round-trip propagation delay. For 10 Mbps Ethernet with : minimum frame = 64 bytes.
CSMA/CD collision analysis. The sender must still be transmitting when a collision signal returns From the farthest point on the network. The worst-case round-trip propagation time is Where ( is the maximum cable length, is the signal propagation speed, m/s in copper). The minimum frame size is therefore:
Where is the data rate.
Worked Example: CSMA/CD Minimum Frame Size
A 100 Mbps Ethernet network uses a maximum cable length of 2 km. Signal propagation speed is m/s. Calculate the minimum frame size.
One-way propagation delay:
Worst case: collision occurs at the far end, signal must travel back. Total time is .
The sender must still be transmitting after :
Answer: The minimum frame size is 250 bytes (2000 bits). Any frame shorter than this risks an Undetected collision.
CSMA/CA (Collision Avoidance). Used in wireless (802.11). Cannot detect collisions while Transmitting (half-duplex radio). Uses RTS/CTS handshake and inter-frame spacing (IFS).
Wi-Fi (IEEE 802.11). Wireless LAN standards operating in the 2.4 GHz, 5 GHz, and 6 GHz bands.
| Standard | Frequency | Max PHY Rate | Channel Width |
|---|---|---|---|
| 802.11a | 5 GHz | 54 Mbps | 20 MHz |
| 802.11b | 2.4 GHz | 11 Mbps | 22 MHz |
| 802.11g | 2.4 GHz | 54 Mbps | 20 MHz |
| 802.11n | 2.4/5 GHz | 600 Mbps | 20/40 MHz |
| 802.11ac | 5 GHz | 6.93 Gbps | 20-160 MHz |
| 802.11ax | 2.4/5/6 | 9.6 Gbps | 20-160 MHz |
Key 802.11 mechanisms:
- DCF (Distributed Coordination Function): CSMA/CA with random backoff. IFS priorities: SIFS (shortest, for ACKs/CTS), PIFS (PCF), DIFS (standard data), EIFS (after error).
- RTS/CTS: Sender sends Request To Send, receiver replies with Clear To Send. Reduces hidden terminal problem.
- RTS/CTS pseudocode:
void wifi_send(frame *f) { while (channel_busy()) wait(DIFS); send_RTS(); wait_for_CTS(timeout); if (received_CTS()) { wait(SIFS); send_data(f); wait(SIFS); wait_for_ACK(timeout); if (!received_ACK()) { backoff = choose_random(0, 2^min(n,10) - 1) * slot_time; wait(backoff); retry_count++; } } else { backoff = choose_random(0, 2^min(n,10) - 1) * slot_time; wait(backoff); }}- MIMO: Multiple-Input Multiple-Output. Uses multiple antennas for spatial multiplexing (simultaneous streams) and diversity (reliability). 802.11n supports up to 4x4 MIMO.
- OFDM/OFDMA: Orthogonal Frequency-Division Multiplexing divides the channel into subcarriers. OFDMA (802.11ax) allows scheduling different clients on different subcarriers simultaneously.
- BSS (Basic Service Set): An access point (AP) and its associated stations. ESS (Extended Service Set): multiple BSSs connected by a distribution system.
3.4 Ethernet (IEEE 802.3)
Frame format:
| Field | Size | Description |
|---|---|---|
| Preamble | 7 bytes | Alternating 1s and 0s for sync |
| SFD | 1 byte | Start of frame delimiter (10101011) |
| Dest MAC | 6 bytes | Destination MAC address |
| Src MAC | 6 bytes | Source MAC address |
| Type/Len | 2 bytes | EtherType or frame length |
| Payload | 46-1500 B | Data |
| FCS | 4 bytes | Frame check sequence (CRC-32) |
MAC address: 48-bit globally unique address. First 24 bits: OUI (organisation). Last 24 bits: Device-specific. Broadcast: FF:FF:FF:FF:FF:FF. Multicast: least significant bit of the first Octet is 1.
Ethernet evolution:
| Standard | Speed | Medium | Max Segment |
|---|---|---|---|
| 10BASE-T | 10 Mbps | Cat3+ UTP | 100 m |
| 100BASE-TX | 100 Mbps | Cat5+ UTP | 100 m |
| 1000BASE-T | 1 Gbps | Cat5e+ UTP | 100 m |
| 10GBASE-T | 10 Gbps | Cat6a+ UTP | 100 m |
| 10GBASE-SR | 10 Gbps | Multi-mode fibre | 26-300 m |
| 10GBASE-LR | 10 Gbps | Single-mode fibre | 10 km |
| 100GBASE-SR4 | 100 Gbps | Multi-mode fibre | 70-100 m |
| 400GBASE-DR4 | 400 Gbps | Single-mode fibre | 500 m |
Theorem 3.3 (CSMA/CD efficiency). The maximum efficiency of CSMA/CD is:
Where is the ratio of propagation delay to frame transmission time.
Proof. In the worst case, a collision wastes time and one frame transmission time . The useful time per cycle is . The total cycle time is in the worst case, but On average (with the binary exponential backoff), the effective overhead is approximately . Thus .
When (large frames or short distances), efficiency approaches 1. When approaches 1 (short frames or long distances), efficiency drops significantly. This is why minimum frame sizes Are imposed.
3.5 VLANs
A Virtual LAN (VLAN) logically segments a physical LAN into separate broadcast domains at layer 2, Without requiring separate physical infrastructure.
802.1Q frame tagging. A 4-byte tag is inserted after the source MAC address:
| Field | Size | Description |
|---|---|---|
| TPID | 16 bits | Tag Protocol Identifier (0x8100) |
| PCP | 3 bits | Priority Code Point (802.1p) |
| DEI | 1 bit | Drop Eligible Indicator |
| VLAN ID (VID) | 12 bits | VLAN identifier (1-4094) |
Trunking. Links between switches that carry traffic for multiple VLANs. Frames are tagged with Their VLAN ID on trunk links.
Benefits: Security (isolation between VLANs), broadcast containment, flexible network management, Reduced cost (no need for separate switches per segment).
3.6 Switching
Circuit switching. A dedicated path is established for the entire duration. Used in traditional Telephone networks. Constant bandwidth but inefficient for bursty data.
Packet switching. Data divided into packets, each routed independently.
- Datagram: Each packet routed independently (IP). No setup; may arrive out of order.
- Virtual circuit: Logical path established before data transfer (ATM, MPLS). Ordered delivery.
Theorem 3.2. Packet switching achieves higher utilisation than circuit switching for bursty Traffic.
Proof. Circuit switching reserves the peak rate per connection. Packet switching uses statistical Multiplexing: the sum of peak rates can exceed link capacity as long as the average aggregate rate Does not.
Switch forwarding methods. A layer-2 switch can forward frames using two strategies:
| Aspect | Store-and-Forward | Cut-Through |
|---|---|---|
| Operation | Receives entire frame first | Reads destination MAC only |
| Latency | per hop | per hop |
| Error detection | Can check FCS before forward | Cannot check FCS |
| Memory requirement | Must buffer full frame | Only needs header buffer |
| Use case | General-purpose switching | Low-latency environments |
Where is the full frame length, is the header length (14 bytes for Ethernet), is the Link rate, and is the propagation delay.
For a path through switches:
\mathrm{Store}\mathrm{-and\mathrm}{-forward\;latency} = n \cdot \frac{L}{R} + d_{\mathrm{total}}
\mathrm{Cut}\mathrm{-through}\;latency} = \frac{L}{R} + (n-1) \cdot \frac{L_h}{R} + d_{\mathrm{total}
Worked Example: Switching Latency Comparison
A 1500-byte frame traverses 3 store-and-forward switches on 1 Gbps links. Each link has 5 S Propagation delay.
Store-and-forward:
Cut-through:
Answer: Cut-through saves approximately 23.8 S (47% reduction) for this scenario, but it Cannot detect corrupted frames before forwarding them.
4. Network Layer
4.1 IPv4 Addressing
An IPv4 address is a 32-bit number in dotted-decimal: 192.168.1.1.
IPv4 header format (20 bytes minimum):
| Field | Size | Description |
|---|---|---|
| Version | 4 bits | Always 4 |
| IHL | 4 bits | Header length in 32-bit words (5 = 20 bytes) |
| DSCP/ECN | 8 bits | Differentiated services / Explicit congestion |
| Total Length | 16 bits | Entire packet size (header + data) |
| Identification | 16 bits | Unique ID for fragments of the same datagram |
| Flags | 3 bits | DF (Don’t Fragment), MF (More Fragments) |
| Fragment Off. | 13 bits | Offset in 8-byte units |
| TTL | 8 bits | Time to live; decremented by each router |
| Protocol | 8 bits | Upper-layer protocol (6=TCP, 17=UDP, 1=ICMP) |
| Checksum | 16 bits | Header checksum only |
| Src Address | 32 bits | Source IPv4 address |
| Dst Address | 32 bits | Destination IPv4 address |
Address classes:
| Class | Range | Default Mask | First Bits |
|---|---|---|---|
| A | 1.0.0.0 — 126.255.255.255 | 255.0.0.0 | 0 |
| B | 128.0.0.0 — 191.255.255.255 | 255.255.0.0 | 10 |
| C | 192.0.0.0 — 223.255.255.255 | 255.255.255.0 | 110 |
| D | 224.0.0.0 — 239.255.255.255 | Multicast | 1110 |
| E | 240.0.0.0 — 255.255.255.255 | Reserved | 1111 |
Special addresses: 127.0.0.0/8 (loopback), 0.0.0.0 (this network), 255.255.255.255 (broadcast).
4.2 Subnetting and CIDR
Subnetting. Borrow bits from the host portion to create subnets.
Example. Network 192.168.1.0/24 with /26 mask (borrow 2 bits):
| Subnet | Range | Broadcast |
|---|---|---|
| 192.168.1.0/26 | 192.168.1.1 — 192.168.1.62 | 192.168.1.63 |
| 192.168.1.64/26 | 192.168.1.65 — 192.168.1.126 | 192.168.1.127 |
| 192.168.1.128/26 | 192.168.1.129 — 192.168.1.190 | 192.168.1.191 |
| 192.168.1.192/26 | 192.168.1.193 — 192.168.1.254 | 192.168.1.255 |
Each subnet has usable hosts.
CIDR (Classless Inter-Domain Routing). Notation: a.b.c.d/n where is the prefix length. Allows route aggregation (supernetting).
Example. Aggregate 192.168.0.0/24 and 192.168.1.0/24 into 192.168.0.0/23.
Worked Example: VLSM Subnetting
Subnet 192.168.10.0/24 to accommodate:
- LAN A: 60 hosts
- LAN B: 28 hosts
- LAN C: 12 hosts
- LAN D: 6 hosts
- 3 point-to-point links: 2 hosts each
Strategy: Allocate largest subnets first. For each subnet, find the smallest power of 2 that Provides enough addresses (including network and broadcast).
| Subnet | Hosts needed | Prefix | Network | Range | Broadcast | |
|---|---|---|---|---|---|---|
| LAN A | 60 | 64 | /26 | 192.168.10.0/26 | .1 — .62 | 192.168.10.63 |
| LAN B | 28 | 32 | /27 | 192.168.10.64/27 | .65 — .94 | 192.168.10.95 |
| LAN C | 12 | 16 | /28 | 192.168.10.96/28 | .97 — .110 | 192.168.10.111 |
| LAN D | 6 | 8 | /29 | 192.168.10.112/29 | .113 — .118 | 192.168.10.119 |
| P2P Link 1 | 2 | 4 | /30 | 192.168.10.120/30 | .121 — .122 | 192.168.10.123 |
| P2P Link 2 | 2 | 4 | /30 | 192.168.10.124/30 | .125 — .126 | 192.168.10.127 |
| P2P Link 3 | 2 | 4 | /30 | 192.168.10.128/30 | .129 — .130 | 192.168.10.131 |
Remaining space: 192.168.10.132/24 — 192.168.10.255 (124 addresses for future use).
Key insight: VLSM avoids wasting addresses. Without VLSM, using /26 for all subnets would require addresses. With VLSM we use only 132 addresses.
4.3 IPv6
128-bit addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Abbreviation rules: leading zeros in a Group may be omitted; one consecutive group of all-zeros may be replaced with ::.
Key differences from IPv4:
- Address space: .
- No broadcast (uses multicast).
- Simplified header for faster processing.
- Mandatory IPsec support.
- No fragmentation at routers (only at source).
IPv6 header format (40 bytes fixed):
| Field | Size | Description |
|---|---|---|
| Version | 4 bits | Always 6 |
| Traffic Class | 8 bits | ECN and DSCP |
| Flow Label | 20 bits | QoS and flow identification |
| Payload Len | 16 bits | Length of the payload |
| Next Header | 8 bits | Type of extension header |
| Hop Limit | 8 bits | Replaces IPv4 TTL |
IPv6 header analysis. The fixed 40-byte header with no options field is a deliberate simplification Over IPv4 (whose header ranges from 20 to 60 bytes). Every field is either fixed-size or has a defined offset. This allows routers to process IPv6 packets faster because they never need to Parse variable-length options. Optional functionality is moved to extension headers, which are Chained via the Next Header field:
| Extension Header | Next Header Value | Purpose |
|---|---|---|
| Hop-by-Hop Options | 0 | Options processed by every router |
| Routing (Type 0) | 43 | Source routing (deprecated) |
| Fragment | 44 | Fragmentation and reassembly |
| Destination Options | 60 | Options for destination only |
| Authentication Header | 51 | Integrity and authentication |
| Encapsulating Security | 50 | Confidentiality and integrity |
Transition mechanisms: Dual stack, tunnelling (encapsulate IPv6 in IPv4), translation (NAT64).
4.4 ARP
Address Resolution Protocol resolves IP addresses to MAC addresses on a local network.
- Host needs to send a packet to IP address .
- Host checks its ARP cache for ‘s MAC address.
- If not cached, broadcast an ARP request: “Who has ? Tell .”
- Host replies with its MAC address (unicast).
- Host caches the mapping ( with a timeout of minutes).
Gratuitous ARP. A host broadcasts its own IP-to-MAC mapping, on startup or interface Change. Used for duplicate address detection, cache updates, and failover in high-availability setups.
ARP spoofing. An attacker sends forged ARP messages to associate their MAC address with the IP Address of a legitimate device, enabling man-in-the-middle attacks. Defences include static ARP Entries, ARP inspection, and dynamic ARP protection (DAI).
4.5 NAT
Network Address Translation maps private addresses (RFC 1918: 10.0.0.0/8 172.16.0.0/12``192.168.0.0/16) to public addresses.
- Static NAT: One-to-one mapping.
- Dynamic NAT: Pool of public addresses assigned on demand.
- PAT (NAT overload): Multiple private addresses share one public address via port numbers. Translation table maps (private IP, private port) to (public IP, public port).
PAT limitation: Approximately 65,000 concurrent connections per public IP.
4.6 Routing Algorithms
Distance Vector Routing. Each router maintains a vector of distances to all destinations. Routers exchange vectors with neighbours periodically.
- Bellman-Ford equation: where is the link cost to neighbour .
- RIP: Uses hop count (max 15 hops); updates every 30 seconds. Slow convergence; susceptible to count-to-infinity.
Count-to-infinity example. Routers A, B, C in a line with cost 1 each. If link A-B fails:
- B sets Advertises to C.
- C still has via B, advertises to B.
- B sets via C. C then sets . This continues.
Solution: Split horizon with poisoned reverse. B advertises to A (since B’s Route to A goes through A).
Link State Routing. Each router has complete topology. Uses Dijkstra’s algorithm.
- OSPF: Hierarchical design (areas), VLSM support, fast convergence. Link-state advertisements (LSAs) flooded throughout the area. Each router runs Dijkstra on the full topology graph. Uses cost = by default.
OSPF area design:
- Backbone area (Area 0): All other areas must connect to it. All inter-area traffic passes through Area 0.
- Non-backbone areas: Summarise routes before advertising to Area 0. Types: standard, stub (no external routes), totally stubby (no external or inter-area routes), NSSA.
- LSA types: Type 1 (router LSA, intra-area), Type 2 (network LSA, intra-area), Type 3 (summary LSA, inter-area), Type 5 (external LSA, redistributed routes).
OSPF adjacency states: Down, Init, 2-Way, ExStart, Exchange, Loading, Full.
OSPF packet fields:
| Field | Description |
|---|---|
| Header | Version, area ID, router ID, checksum |
| LSA type | Router-LSA, Network-LSA, Summary-LSA |
| Link ID | Identifies the described object |
| Advertising router | Router originating the LSA |
| Sequence number | Detects stale or duplicate LSAs |
| Age | Time since LSA originated (seconds) |
Path Vector Routing (BGP). Used for inter-domain routing. Carries the full AS path to each Destination, not just the distance.
- eBGP: Between different ASes. iBGP: Within the same AS.
- Attributes:
AS_PATH(loop prevention),NEXT_HOP``LOCAL_PREF(exit preference),MED(entry preference), origin type. - Decision process: Highest
LOCAL_PREFShortestAS_PATHLowest origin, lowestMEDeBGP over iBGP, lowest IGP cost toNEXT_HOPLowest router ID.
BGP route advertisement:
AS 65001 -> AS 65002: reach 203.0.113.0/24, AS_PATH = 65001AS 65002 -> AS 65003: reach 203.0.113.0/24, AS_PATH = 65001 65002AS 65003 rejects any route containing its own AS number (loop prevention).
BGP attributes in detail:
- Well-known mandatory:
AS_PATH``NEXT_HOP``ORIGIN(IGP EGP Incomplete). - Well-known discretionary:
LOCAL_PREF(not sent to eBGP peers; influences outbound traffic). - Optional transitive:
COMMUNITY(tag routes for policy),MP_REACH_NLRI(IPv6/VPNv4). - Optional non-transitive:
MED(suggestion to neighbour about preferred entry point; lower is better; compared only for routes from the same neighbouring AS).
iBGP full mesh requirement. Within an AS, all iBGP speakers must be fully meshed (or use route Reflectors/confederations) because iBGP does not re-advertise routes learned from other iBGP peers. This prevents routing loops within the AS.
Routing protocol comparison:
| Feature | RIP | OSPF | BGP |
|---|---|---|---|
| Type | Distance Vector | Link State | Path Vector |
| Algorithm | Bellman-Ford | Dijkstra | Policy-based |
| Metric | Hop count (max 15) | Cost (bandwidth-based) | AS_PATH + attributes |
| Scope | AS (interior) | AS (interior) | Inter-domain |
| Convergence | Slow | Fast | Configurable |
| Updates | Periodic (30 s) | Triggered (LSA flood) | Incremental |
| Scalability | Small networks | Large networks | Internet-scale |
| Hierarchy | Flat | Areas | AS-based |
| VLSM support | RIPv2 only | Yes | Yes |
Worked Example: Routing Table Construction with Dijkstra's Algorithm
Consider the following network topology with link costs:
A ---3--- B ---2--- C| | |4 1 5| | |D ---6--- E ---3--- FGoal: Construct the routing table at router A using Dijkstra’s algorithm.
Initialisation. Set , . Unvisited = .
Visit A (). Neighbours: B (cost 3), D (cost 4). Update: Prev. Prev.
Visit B (Smallest unvisited). Neighbours: A (skip), C (3 + 2 = 5), E (3 + 1 = 4). Update: Prev. Prev.
Visit D (). Neighbours: A (skip), E (4 + 6 = 10, worse than 4). No updates.
Visit E (). Neighbours: B (skip), D (skip), F (4 + 3 = 7). Update: Prev.
Visit C (). Neighbours: B (skip), F (5 + 5 = 10, worse than 7). No updates.
Visit F (). All neighbours visited. Done.
Routing table at A:
| Destination | Next Hop | Cost | Path |
|---|---|---|---|
| B | B | 3 | A — B |
| C | B | 5 | A — B — C |
| D | D | 4 | A — D |
| E | B | 4 | A — B — E |
| F | B | 7 | A — B — E — F |
4.7 ICMP
Internet Control Message Protocol provides error reporting and diagnostics. Encapsulated in IP (protocol number 1).
| Type | Code | Meaning |
|---|---|---|
| 0 | 0 | Echo reply |
| 3 | 0-15 | Destination unreachable |
| 8 | 0 | Echo request (ping) |
| 11 | 0-1 | Time exceeded (TTL expiry) |
Traceroute. Sends packets with incrementing TTL. When TTL expires, the router returns an ICMP Time Exceeded message, revealing intermediate hops.
4.8 IP Fragmentation
When a packet exceeds the MTU, it must be fragmented. The IP header includes Identification, Flags (DF, MF), and Fragment Offset fields.
Fragmentation process:
- The Identification field is the same for all fragments of the original datagram.
- The MF (More Fragments) flag is 1 for all fragments except the last.
- The Fragment Offset specifies the position of the fragment’s data in the original datagram (in 8-byte units).
- Each fragment becomes an independent IP packet with its own IP header.
- Only the receiver reassembles fragments; routers never reassemble.
Worked Example: IP Fragmentation
A 4000-byte datagram (20-byte header + 3980-byte data) must traverse a link with MTU = 1500 bytes.
Payload per fragment = MTU - IP header = 1500 - 20 = 1480 bytes.
The data size (3980 bytes) must be a multiple of 8 for fragmentation. The last fragment can be Shorter, but the offset is in 8-byte units. 1480 is divisible by 8 (), so this Works cleanly.
Number of fragments: .
| Fragment | Header | Data | MF | Offset | Total |
|---|---|---|---|---|---|
| 1 | 20 B | 1480 B | 1 | 0 | 1500 B |
| 2 | 20 B | 1480 B | 1 | 185 | 1500 B |
| 3 | 20 B | 1020 B | 0 | 370 | 1040 B |
Total transmitted: 4040 bytes (40 bytes of additional headers due to fragmentation).
Path MTU Discovery (PMTUD): The sender sets the DF flag. If a router cannot forward, it returns ICMP “Fragmentation Needed” and the sender reduces packet size. Preferred over fragmentation.
:::caution Common Pitfall When subnetting, remember that a /31 prefix (RFC 3021) has exactly 2 addresses and is valid for Point-to-point links with no network or broadcast address. A /32 is a single host route. The Formula usable hosts applies only for prefixes of /30 or shorter. :::
5. Transport Layer
5.1 UDP
Connectionless, unreliable, message-oriented. 8-byte header.
| Field | Size | Description |
|---|---|---|
| Src port | 16 bits | Source port |
| Dst port | 16 bits | Destination port |
| Length | 16 bits | Header + data length |
| Checksum | 16 bits | Optional (IPv4); mandatory (IPv6) |
Use cases: DNS, DHCP, VoIP, video streaming, gaming. Suitable when low latency matters more Than reliability, or when the application handles reliability itself.
5.2 TCP
Connection-oriented, reliable, byte-stream. Provides flow control, congestion control, ordered Delivery. Header: 20 bytes minimum.
| Field | Size | Description |
|---|---|---|
| Src port | 16 bits | Source port |
| Dst port | 16 bits | Destination port |
| Seq number | 32 bits | Byte position of first data byte |
| Ack number | 32 bits | Next expected byte from other side |
| Data offset | 4 bits | Header length in 32-bit words |
| Flags | 9 bits | URG, ACK, PSH, RST, SYN, FIN |
| Window | 16 bits | Receive window size (flow control) |
| Checksum | 16 bits | Mandatory |
| Urgent ptr | 16 bits | Pointer to urgent data |
5.3 TCP Options
The TCP header can include options (within the data offset space):
| Option | Size | Purpose |
|---|---|---|
| MSS | 4 bytes | Maximum Segment Size (announced in SYN) |
| Window Scale | 3 bytes | Scale the window field (RFC 7323) |
| SACK Permitted | 2 bytes | Allow Selective Acknowledgements |
| SACK | Variable | Specify blocks of received data |
| Timestamps | 10 bytes | RTT measurement, PAWS protection |
Selective Acknowledgement (SACK). Standard TCP only acknowledges contiguous data. If segments 3, 4, 5 are lost but 6-10 arrive, the receiver can only ACK up to segment 2. SACK allows the Receiver to inform the sender exactly which blocks have arrived, avoiding unnecessary Retransmissions.
Window scaling. The TCP window field is 16 bits (max 65,535 bytes), insufficient for high-BDP Paths. The window scale option shifts the window left by bits, allowing windows up to bytes (maximum Yielding a 1 GiB window).
5.4 TCP vs UDP Comparison
| Aspect | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Guaranteed delivery, ACKs | Best effort |
| Ordering | Ordered delivery | No ordering |
| Flow control | Sliding window | None |
| Congestion ctrl | cwnd, ssthresh | None |
| Header size | 20—60 bytes | 8 bytes |
| Overhead | Higher (handshake, ACKs) | Lower |
| Use cases | Web, email, file transfer | DNS, VoIP, streaming, gaming |
| Broadcast | No (point-to-point) | Yes (broadcast and multicast) |
| Retransmission | Automatic | Application-level |
Theorem 5.1. TCP achieves reliable ordered delivery over an unreliable network using cumulative Acknowledgements, sequence numbers, and retransmission timers.
Proof. TCP assigns each byte a sequence number. The receiver sends cumulative ACKs indicating the Next expected byte. If an ACK is not received within the RTO, the sender retransmits. Since the Receiver buffers out-of-order segments and only delivers in-order data to the application, and since Every byte is eventually acknowledged or retransmitted until acknowledged, all data is delivered Exactly once and in order.
5.5 TCP Connection Management
Three-way handshake:
Client Server |--- SYN (seq=x) ---------->| Client: SYN_SENT |<-- SYN+ACK (seq=y, | Server: SYN_RCVD | ack=x+1) ------------| |--- ACK (ack=y+1) -------->| ESTABLISHEDFour-way termination:
Client Server |--- FIN (seq=u) ---------->| Client: FIN_WAIT_1 |<-- ACK (ack=u+1) --------| Client: FIN_WAIT_2 | | Server: CLOSE_WAIT |<-- FIN (seq=v) ----------| Server: LAST_ACK |--- ACK (ack=v+1) -------->| Client: TIME_WAIT | (wait 2*MSL) | Server: CLOSEDTIME_WAIT. Client waits (Maximum Segment Lifetime, 60 s) Before closing. Ensures: (1) the last ACK reaches the server; (2) old segments have expired.
TCP state diagram (state transitions):
| From | Event | To |
|---|---|---|
| CLOSED | passive open | LISTEN |
| CLOSED | active open, send SYN | SYN_SENT |
| LISTEN | recv SYN, send SYN+ACK | SYN_RCVD |
| LISTEN | close | CLOSED |
| SYN_SENT | recv SYN+ACK, send ACK | ESTABLISHED |
| SYN_RCVD | recv ACK | ESTABLISHED |
| ESTABLISHED | close, send FIN | FIN_WAIT_1 |
| ESTABLISHED | recv FIN, send ACK | CLOSE_WAIT |
| FIN_WAIT_1 | recv ACK | FIN_WAIT_2 |
| FIN_WAIT_1 | recv FIN, send ACK | CLOSING |
| FIN_WAIT_2 | recv FIN, send ACK | TIME_WAIT |
| CLOSE_WAIT | close, send FIN | LAST_ACK |
| CLOSING | recv ACK | TIME_WAIT |
| LAST_ACK | recv ACK | CLOSED |
| TIME_WAIT | 2 MSL timeout | CLOSED |
5.6 Flow Control
TCP uses a sliding window. The receiver advertises rwnd (receive window). The sender never has More than rwnd bytes of unacknowledged data in flight.
Example. Buffer size 4096, 1024 unprocessed bytes: rwnd = 3072. The window slides as data is Acknowledged and the receiver processes data.
5.7 Congestion Control
TCP adapts its sending rate based on perceived network congestion.
Slow start. cwnd = 1 MSS. Double cwnd per ACK (exponential growth). Until cwnd reaches ssthresh or loss occurs.
Congestion avoidance. When Increase cwnd by per ACK (linear growth, approximately 1 MSS Per RTT).
Fast retransmit. Three duplicate ACKs trigger immediate retransmission of the missing segment.
Fast recovery. After fast retransmit: . Enter congestion avoidance (not slow start).
TCP Reno state transitions:
Slow Start: cwnd doubles each RTT | v (cwnd >= ssthresh)Congestion Avoidance: cwnd += 1 MSS/RTT | v (3 dup ACKs)Fast Retransmit + Recovery: ssthresh = cwnd/2, cwnd = ssthresh + 3 | v (new ACK)Congestion Avoidance | v (timeout)Slow Start: ssthresh = cwnd/2, cwnd = 1TCP Cubic. Default in Linux since 2.6.19. Uses a cubic function of time since last congestion Event. Better performance on high-bandwidth, high-latency networks.
Worked Example: TCP Congestion Window Evolution
Given: MSS = 1460 bytes, initial ssthresh = 16384 bytes. Trace cwnd through the following Events:
- Connection established, enter slow start.
- After 4 RTTs, cwnd reaches ssthresh.
- 3 more RTTs in congestion avoidance.
- Three duplicate ACKs received (fast retransmit).
- New ACK arrives after fast recovery.
Slow start (cwnd doubles each RTT):
| RTT | cwnd (MSS) | cwnd (bytes) | Phase |
|---|---|---|---|
| 1 | 2 | 2920 | Slow start |
| 2 | 4 | 5840 | Slow start |
| 3 | 8 | 11680 | Slow start |
| 4 | 16 | 23360 | cwnd ssthresh switch |
Congestion avoidance (cwnd increases by ~1 MSS per RTT):
| RTT | cwnd (bytes) | Increment | Phase |
|---|---|---|---|
| 5 | 24820 | +1460 | Congestion avoidance |
| 6 | 26280 | +1460 | Congestion avoidance |
| 7 | 27740 | +1460 | Congestion avoidance |
Fast retransmit and recovery (after 3 dup ACKs):
Ssthresh = 27740 / 2 = 13870 bytes Cwnd = 13870 + 3 1460 = 18250 bytes
New ACK arrives (exit fast recovery):
Cwnd = ssthresh = 13870 bytes, continue congestion avoidance.
5.8 Retransmission Timer
Where = measured RTT, , . Initial RTO = 1 s; minimum RTO = 200 ms.
:::caution Common Pitfall Karn’s algorithm: do not update RTT estimates for retransmitted segments. The ACK could correspond To either the original or the retransmission (retransmission ambiguity). :::
Worked Example: RTT Estimation
Given: , Initial , . Measured RTTs: 220 ms, 240 ms, 230 ms, 260 ms, 250 ms.
After measurement 1 (220 ms):
ms ms ms
After measurement 2 (240 ms):
ms ms ms
After measurement 3 (230 ms):
ms ms ms
After measurement 4 (260 ms):
ms ms ms
After measurement 5 (250 ms):
ms ms ms
The smoothed RTT converges toward the true average (~240 ms) and the RTO stabilises around 600 ms.
6. Application Layer
6.1 DNS
DNS translates domain names to IP addresses. Hierarchical, distributed database.
Domain hierarchy: Root (.) TLD (com``org``net) second-level (example.com) subdomain (www.example.com).
Record types:
| Type | Name | Purpose |
|---|---|---|
| A | IPv4 | IPv4 address |
| AAAA | IPv6 | IPv6 address |
| CNAME | Alias | Alias to another name |
| MX | Mail server for the domain | |
| NS | Name | Authoritative name server |
| SOA | Start | Zone administration info |
| TXT | Text | Arbitrary text (SPF, DKIM, verification) |
Resolution process:
- Client queries the recursive resolver (e.g.,
8.8.8.8). - Resolver queries a root server for the TLD server.
- Root refers to the TLD server (e.g., for
.com). - TLD server refers to the authoritative server for the domain.
- Authoritative server returns the answer.
- Resolver caches the result with a TTL.
Iterative vs recursive resolution. The client’s query to its configured resolver is recursive (the resolver does all the work). The resolver’s queries to root, TLD, and authoritative servers Are iterative (each server refers the resolver to the next, or answers directly). This Distinction is important: the root and TLD servers are not burdened with recursion.
DNS caching and TTL. Each DNS record has a Time-To-Live (TTL) value (in seconds). Resolvers cache The record for the TTL duration. Typical TTLs: 300 s (5 min) for dynamic records, 86400 s (24 h) For stable records. Negative caching (NXDOMAIN) also has a TTL (specified in the SOA record’s Minimum field).
DNS resolution sequence example: Resolving www.example.com with an empty cache:
- Client recursive resolver: “What is the A record for
www.example.com?” (UDP, 1 RTT). - Resolver root server: “Where is the
.comTLD?” (1 RTT). - Root resolver: “Ask the
.comTLD server at 192.5.6.30.” - Resolver
.comTLD: “Where isexample.com?” (1 RTT). - TLD resolver: “Ask the
example.comauthoritative server at 93.184.216.34.” - Resolver authoritative: “What is the A record for
www.example.com?” (1 RTT). - Authoritative resolver: “93.184.216.34, TTL = 300.”
- Resolver client: “93.184.216.34” (1 RTT).
Total: 5 RTTs for the resolver, 1 RTT for the client. With caching, subsequent lookups for www.example.com require only 1 RTT (client to resolver).
Theorem 6.1. DNS caching dramatically reduces latency. Without caching, every lookup requires Multiple round trips to root, TLD, and authoritative servers.
6.2 HTTP
HTTP/1.0. New TCP connection per request/response. No persistent connections.
HTTP/1.1. Default persistent connections (Connection: keep-alive). Pipelining allows multiple Requests without waiting for responses. Head-of-line blocking: one stalled request blocks subsequent Ones.
HTTP/2. Multiplexing over a single TCP connection. Binary framing, header compression (HPACK), Server push, stream prioritisation. Solved application-layer HOL blocking.
HTTP/3. Uses QUIC (UDP-based) instead of TCP. Solves TCP-level HOL blocking. Includes Connection migration, 0-RTT handshake resumption, integrated TLS 1.3.
HTTP methods:
| Method | Idempotent | Safe | Purpose |
|---|---|---|---|
| GET | Yes | Yes | Retrieve a resource |
| POST | No | No | Submit data |
| PUT | Yes | No | Replace a resource |
| DELETE | Yes | No | Delete a resource |
| PATCH | No | No | Partial modification |
| HEAD | Yes | Yes | Like GET but no body |
| OPTIONS | Yes | Yes | Describe communication options |
Status codes:
| Code Range | Category | Examples |
|---|---|---|
| 1xx | Informational | 100 Continue |
| 2xx | Success | 200 OK, 201 Created |
| 3xx | Redirection | 301 Moved, 304 Not Modified |
| 4xx | Client Error | 400 Bad Request, 404 Not Found |
| 5xx | Server Error | 500 Internal, 503 Unavailable |
6.3 TLS
Transport Layer Security provides encryption, authentication, and integrity for TCP connections.
TLS 1.3 handshake (simplified):
Client Server |--- ClientHello ------------>| | (supported ciphers, | | key_share) | |<-- ServerHello -------------| | (selected cipher, | | key_share, cert, | | Finished) | |--- Finished --------------->| | (Application data now | | encrypted) |TLS 1.3 reduces the handshake to 1-RTT (or 0-RTT with session resumption). Supports:
- AEAD ciphers: AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305.
- Key exchange: ECDHE (Elliptic Curve Diffie-Hellman Ephemeral). Forward secrecy guaranteed.
- Authentication: RSA or ECDSA signatures on the server certificate.
Certificate chain: Server certificate signed by intermediate CA, signed by root CA. Root CAs are Pre-installed in the browser/OS trust store.
6.4 Email Protocols
SMTP (Simple Mail Transfer Protocol). Push protocol for sending email (TCP port 25/587). Uses a Command-response dialogue: HELO/EHLO``MAIL FROM``RCPT TO``DATA``QUIT. Supports extensions For authentication (AUTH) and encryption (STARTTLS).
SMTP session example:
C: EHLO client.example.comS: 250-smtp.example.com HelloS: 250 AUTH PLAIN LOGINC: AUTH PLAIN <credentials>S: 235 Authentication successfulC: MAIL FROM:<alice@example.com>S: 250 OKC: RCPT TO:<bob@example.org>S: 250 OKC: DATAS: 354 Start mail inputC: From: alice@example.comC: To: bob@example.orgC: Subject: MeetingC:C: Hi Bob, let's meet at 3pm.C: .S: 250 OKC: QUITS: 221 ByeIMAP (Internet Message Access Protocol). Access email on the server without downloading. Supports Folders, search, partial fetch. TCP port 143 (993 for IMAPS). States: authenticated, selected, and Logout. Messages remain on the server unless explicitly deleted.
POP3 (Post Office Protocol v3). Download email to the client; deletes from server. TCP Port 110 (995 for POP3S). Simpler than IMAP but less flexible. Supports TOP (fetch headers) and RETR (fetch full message).
| Aspect | IMAP | POP3 |
|---|---|---|
| Mode | Remote access | Download and delete |
| Folders | Yes, server-side | No |
| Search | Server-side search | No |
| Sync | Multi-device sync | No |
| Resource | Higher server storage | Lower server storage |
6.5 Other Application Protocols
DHCP (Dynamic Host Configuration Protocol). Automatically assigns IP addresses, subnet masks, Default gateway, and DNS servers to clients. Uses UDP ports 67 (server) and 68 (client).
DHCP DORA process:
Client Server |--- DHCPDISCOVER (broadcast) -->| |<-- DHCPOFFER -----------------| |--- DHCPREQUEST (broadcast) --->| |<-- DHCPACK -------------------|Leases are time-limited; clients must renew before expiry (T1 at 50%, T2 at 87.5% of lease).
DHCP relay. In networks with multiple subnets, clients broadcast DHCPDISCOVER, which routers do Not forward. A DHCP relay agent (configured on the router) converts the broadcast to a unicast and Forwards it to the DHCP server, adding the giaddr (gateway IP address) field so the server knows Which subnet to allocate an address from.
DHCPv6. Uses multicast (ff02::1:2 for servers) and supports rapid commit (2-message exchange Instead of 4-message DORA). Stateless DHCPv6 provides only configuration (DNS, NTP) without address Assignment (SLAAC handles addressing).
FTP (File Transfer Protocol). Two connections: control (port 21) and data (port 20 for active Mode, random high port for passive mode). Supports ASCII and binary transfer modes.
SSH (Secure Shell). Encrypted remote access and file transfer (SCP, SFTP). TCP port 22. Uses Public-key authentication. Transport layer provides encryption, integrity, and compression.
WebSocket. Full-duplex communication channel over a single TCP connection (RFC 6455). Handshake Is HTTP-based with an Upgrade: websocket header. Used for real-time web applications (chat, Gaming, live data).
SNMP (Simple Network Management Protocol). Used for monitoring and managing network devices. UDP port 161/162. Three versions: v1 (community strings, no security), v2c, v3 (user-based security Model with authentication and encryption).
6.6 Network Performance Metrics
Key metrics:
Bandwidth-delay product (BDP): . The maximum amount of unacknowledged data that can be in flight. For a 10 Gbps link with 80 ms RTT: .
Throughput: Actual data rate achieved, less than bandwidth due to protocol overhead, congestion, and errors.
Latency components: Propagation delay (Where is distance), transmission delay (Where is frame length, is rate), queuing delay, processing delay.
Jitter: Variation in packet arrival times. Critical for real-time applications (VoIP, video). Measured as the standard deviation of delay.
Theorem 6.2. The maximum throughput of a TCP connection is bounded by the window size divided by The RTT: .
Proof. The sender cannot have more than the window size in unacknowledged data. Each byte sent Requires an ACK, which takes one RTT to arrive. Thus the sender can send at most window / RTT bytes Per second.
:::caution Common Pitfall DNS uses both TCP and UDP. Queries use UDP port 53 (for efficiency). TCP is used for zone Transfers, responses exceeding 512 bytes, and DNSSEC. The switch to TCP was formalised in RFC 7766. :::
7. Network Security
7.1 Symmetric Encryption
Symmetric encryption uses the same secret key for both encryption and decryption. Both parties Must share the key securely before communication.
| Algorithm | Key Size | Block Size | Status |
|---|---|---|---|
| DES | 56 bits | 64 bits | Insecure |
| 3DES | 168 bits | 64 bits | Deprecated |
| AES-128 | 128 bits | 128 bits | Secure |
| AES-256 | 256 bits | 128 bits | Secure |
| ChaCha20 | 256 bits | Stream | Secure |
Block cipher modes of operation:
| Mode | Description | Parallelisable |
|---|---|---|
| ECB | Each block encrypted independently | Yes |
| CBC | Each block XORed with previous ciphertext | Decryption only |
| CTR | Counter-based stream cipher from block cipher | Yes |
| GCM | Authenticated encryption (CTR + MAC) | Yes |
Theorem 7.1. ECB mode is insecure for messages longer than one block because identical plaintext Blocks produce identical ciphertext blocks, revealing patterns.
Proof. If the plaintext contains repeated blocks Then under ECB, . An attacker observing identical ciphertext blocks knows the corresponding Plaintext blocks are identical, regardless of the key.
Key distribution problem. Symmetric encryption requires a secure channel to exchange keys. For parties, keys are needed. This motivates asymmetric encryption and key exchange Protocols.
7.2 Asymmetric Encryption
Asymmetric encryption uses a key pair: a public key (for encryption/verification) and a private Key (for decryption/signing). The public key can be freely distributed.
RSA. Based on the difficulty of factoring large integers.
- Choose two large primes and . Compute and .
- Choose such that and .
- Compute such that .
- Public key: . Private key: .
- Encrypt: . Decrypt: .
Diffie-Hellman key exchange. Allows two parties to establish a shared secret over an insecure Channel without prior shared key.
- Public parameters: prime and generator .
- Alice picks secret Sends .
- Bob picks secret Sends .
- Shared secret: .
An eavesdropper who sees , , , cannot compute without solving the discrete Logarithm problem.
Digital signatures. The sender signs a message hash with their private key. Anyone can verify Using the sender’s public key. Provides authentication, integrity, and non-repudiation.
7.3 TLS in Depth
TLS 1.3 (RFC 8446) provides a clean, secure design:
- 1-RTT handshake: Client and server exchange key shares in the first round trip, enabling immediate encrypted communication.
- 0-RTT resumption: On subsequent connections, the client can send application data immediately using a pre-shared key from a previous session. Vulnerable to replay attacks.
- Forward secrecy: Every session uses ephemeral ECDHE keys, so compromise of the long-term private key does not allow decryption of past sessions.
- Cipher suites: Only AEAD ciphers are supported (AES-GCM, ChaCha20-Poly1305). No CBC or RC4.
Certificate chain validation:
- Server presents its certificate (signed by intermediate CA).
- Client verifies the signature chain up to a trusted root CA.
- Client checks: validity dates, hostname match (SAN), revocation (CRL/OCSP).
- Client verifies the server’s proof-of-possession for the private key.
7.4 Firewalls
A firewall controls network traffic based on security rules.
Types:
| Type | Layer | Mechanism |
|---|---|---|
| Packet filtering | 3 | Permit/deny based on src, dst, port, proto |
| Stateful inspection | 3—4 | Tracks connection state (TCP states) |
| Application gateway | 7 | Proxy for specific applications |
| Next-generation (NGFW) | 3—7 | Deep packet inspection, IDS/IPS, app ID |
Stateful inspection. Unlike simple packet filtering, a stateful firewall maintains a connection Table. It can distinguish between a new TCP SYN (allowed) and an unsolicited SYN+ACK (blocked), And it tracks UDP “connections” by observing request-response patterns.
DMZ (Demilitarised Zone). A separate network segment for publicly accessible services (web Servers, mail servers). The firewall allows external access to the DMZ but restricts DMZ-to-internal Access.
Worked Example: Firewall Rule Set Design
A company has a web server at 203.0.113.10A mail server at 203.0.113.20An internal network 10.0.0.0/24And a DNS server at 10.0.0.53.
| # | Dir | Src | Dst | Port | Proto | Action |
|---|---|---|---|---|---|---|
| 1 | In | Any | 203.0.113.10 | 80, 443 | TCP | Allow |
| 2 | In | Any | 203.0.113.20 | 25 | TCP | Allow |
| 3 | Out | 10.0.0.0/24 | Any | Any | Any | Allow |
| 4 | In | Any | 203.0.113.10 | Any | ICMP | Allow |
| 5 | In | Any | 10.0.0.53 | 53 | UDP | Allow |
| 6 | In | Any | Any | Any | Any | Deny |
Notes:
- Rule 1 allows HTTP/HTTPS to the web server.
- Rule 2 allows inbound SMTP for mail delivery.
- Rule 3 allows internal users outbound access to anything.
- Rule 4 allows ping to the web server for monitoring.
- Rule 5 allows external DNS queries.
- Rule 6 is the default deny (catches all unmatched traffic).
A stateful firewall automatically permits return traffic for outbound connections (rule 3) without Additional rules.
7.5 VPNs
A Virtual Private Network creates an encrypted tunnel over a public network.
| Technology | Layer | Protocol | Use Case |
|---|---|---|---|
| IPsec | 3 | AH, ESP | Site-to-site, remote access |
| SSL/TLS | 4—7 | TLS 1.3 | Client-to-site (OpenVPN) |
| WireGuard | 3 | UDP, ChaCha20 | Modern, lightweight VPN |
| SSH tunnel | 7 | SSH | Ad-hoc port forwarding |
IPsec architecture (RFC 4301):
- Security Association (SA): A one-way logical connection with parameters: SPI (Security Parameters Index), destination IP, protocol (AH or ESP), encryption algorithm, key, lifetime.
- IKE (Internet Key Exchange): Protocol for establishing SAs. IKEv2 is the current standard. Uses Diffie-Hellman for key exchange and digital signatures for authentication.
- AH (Authentication Header): Provides integrity and authentication but NOT confidentiality. Protects the entire IP packet (immutable fields). Protocol number 51.
- ESP (Encapsulating Security Payload): Provides confidentiality, integrity, and authentication. Protocol number 50.
WireGuard. A modern VPN protocol (Linux kernel 5.6+):
- Uses ChaCha20 for encryption, Poly1305 for authentication, Curve25519 for key exchange.
- No static keys: each peer has a public/private key pair.
- Under 4000 lines of code (vs ~100,000 for OpenVPN + OpenSSL).
- Roaming: peers can change IP without reconfiguration.
7.6 Packet Filtering
Rule syntax (generic):
| Field | Source IP | Src Port | Dest IP | Dst Port | Protocol | Action |
|---|---|---|---|---|---|---|
| Rule 1 | Any | Any | 10.0.0.0/8 | 22 | TCP | Allow |
| Rule 2 | 10.0.0.0/8 | Any | Any | 80, 443 | TCP | Allow |
| Rule 3 | Any | Any | Any | Any | Any | Deny |
Key principles:
- Rules are evaluated top-to-bottom; first match wins.
- Default deny policy: the last rule should deny everything not explicitly allowed.
- Specific rules must precede general rules.
- Stateful firewalls automatically allow return traffic for established connections.
:::caution Common Pitfall Encryption does not imply authentication. A message encrypted with a public key guarantees Confidentiality but does not prove who sent it. Digital signatures (signing with a private key) Provide authentication and non-repudiation. TLS combines both via the certificate chain.
7.7 Common Network Attacks
Denial of Service (DoS) and Distributed DoS (DDoS). Overwhelm a target with traffic, preventing Legitimate access. Amplification attacks (DNS, NTP) use small requests that generate large responses Directed at the victim.
Man-in-the-middle (MITM). An attacker intercepts communication between two parties. Defences: TLS with certificate pinning, mutual authentication, VPNs.
ARP spoofing. See Section 4.4. An attacker sends forged ARP messages to redirect traffic through Their machine.
DNS spoofing (cache poisoning). Injecting forged DNS records into a resolver’s cache, redirecting Users to malicious sites. Defences: DNSSEC (cryptographic signatures on DNS records), source port Randomisation, TSIG.
SQL injection. An attacker inserts malicious SQL into application input fields. Not strictly a Network attack, but often delivered over HTTP. Defences: parameterised queries, input validation.
TCP SYN flood. An attacker sends many SYN packets without completing the handshake, exhausting The server’s connection table. Defences: SYN cookies (encode state in the initial sequence number), Rate limiting, connection throttling.
8. Problem Set
Nyquist theorem. A noiseless channel has bandwidth 8000 Hz. What is the maximum data rate with 16 signal levels? With 256 signal levels?
Shannon capacity. A channel has bandwidth 4 MHz and SNR = 24 dB. Compute the maximum error-free data rate. If 64 signal levels are used with a Nyquist-based scheme, is the channel being used within its theoretical limit?
Nyquist vs Shannon. A channel has Hz and (about 15 dB). What is the maximum number of signal levels that can be used reliably?
Hamming code. Encode the data bits using Hamming(7,4). If bit 5 of the transmitted codeword is flipped, show how the receiver detects and corrects the error.
CRC computation. Compute the CRC for the message
10110010using the generator polynomial (binary1011). Write the transmitted codeword.CRC verification. The receiver gets the codeword
101101110and the generator is1011. Perform modulo-2 division to determine whether the frame was received correctly.ALOHA throughput. A slotted ALOHA system has 4 stations, each transmitting with probability in each slot. Compute the throughput and compare it to the theoretical maximum.
CSMA/CD minimum frame. A 1 Gbps Ethernet has a maximum segment length of 100 m and propagation speed m/s. What is the minimum frame size? How does it compare to the standard Ethernet minimum of 64 bytes?
Switching latency. A 1000-byte frame passes through 5 store-and-forward switches on 100 Mbps links (ignore propagation delay). Compute the total latency. Repeat for cut-through switching.
Subnetting. Given the network
172.16.0.0/16Create subnets to support 100 hosts, 50 hosts, 25 hosts, and 10 hosts using VLSM. List the network address, usable range, and broadcast for each.Route aggregation. Aggregate the following routes into the most specific supernet:
198.51.100.0/24``198.51.101.0/24``198.51.102.0/24``198.51.103.0/24.IPv6 addressing. Expand the IPv6 address
2001:db8::1to its full 128-bit form. How many /64 subnets does a /56 prefix provide? How many /128 addresses per /64?Dijkstra’s algorithm. Given the network topology below, find the shortest path tree from router S to all destinations:
S --2-- A --1-- B| | |5 3 2| | |C --4-- D --1-- EConstruct the routing table at S.
Distance vector convergence. Three routers X, Y, Z are connected: X—Y (cost 1), Y—Z (cost 1), X—Z (cost 5). Initially, X’s route to Z goes through Y. If link Y—Z fails, trace the count-to-infinity problem for 4 iterations. Explain how split horizon with poisoned reverse prevents it.
TCP congestion control. Given MSS = 1000 bytes, initial
ssthresh= 8000 bytes. Tracecwndthrough: slow start for 3 RTTs, then 2 RTTs of congestion avoidance, then a timeout. What is the value ofssthreshafter the timeout?RTT estimation. Using , And measured RTTs of 100 ms, 120 ms, 80 ms, compute , And RTO after each measurement (starting from ).
DNS resolution. A client at
192.168.1.100wants to resolvewww.example.com. Describe the complete resolution process, including: the recursive query to the local resolver, the iterative queries to root and TLD servers, and the role of caching. How many round trips are needed on a cold cache?HTTP performance. A web page contains 1 HTML document (10 KB), 5 CSS files (20 KB total), 10 images (500 KB total), and 2 JavaScript files (100 KB total). Compare the total time to load the page over HTTP/1.0 (6 parallel TCP connections), HTTP/1.1 (1 persistent connection, no pipelining), and HTTP/2 (1 connection with multiplexing). Assume RTT = 50 ms and bandwidth = 10 Mbps. Ignore processing time.
Hint: Total data = 630 KB = 5.04 Mb. Transmission time = 5.04 / 10 = 0.504 s.
- HTTP/1.0: 16 objects, 6 connections. Each connection requires 1 RTT for TCP handshake + 1 RTT for HTTP request/response. With 6 parallel connections: 3 round trips for the TCP + HTTP per batch = 150 ms per batch, with 3 batches (6 + 6 + 4 objects) = 3 150 + 504 = 954 ms.
- HTTP/1.1: 1 connection, sequential requests. 1 RTT for handshake + 16 RTTs for requests (serial) + 504 ms = 1 50 + 16 50 + 504 = 1354 ms.
- HTTP/2: 1 RTT for handshake, all requests multiplexed. 1 50 + 504 = 554 ms.
Firewall rules. A company has a web server at
203.0.113.10A mail server at203.0.113.20And an internal network10.0.0.0/24. Write a set of packet filtering rules that: (a) allows external HTTP/HTTPS to the web server, (b) allows external SMTP to the mail server, (c) allows internal users to access any external service, (d) blocks all other inbound traffic.RSA encryption. Given primes , And public exponent : (a) Compute , And the private key . (b) Encrypt the message . (c) Decrypt the ciphertext to verify.
TCP throughput bound. A TCP connection over a satellite link has RTT = 600 ms and bandwidth = 50 Mbps. The receiver advertises
rwnd= 1 MB. Ifcwndgrows to 2 MB during slow start, what is the maximum achievable throughput? What is the BDP, and is the window large enough to fill the pipe?CDMA orthogonality. Four stations share a channel using CDMA with chip codes: , , . Station 1 sends bit 1, station 2 sends bit 0, station 3 sends bit 1, station 4 is silent. Compute the combined signal and show that each receiver correctly recovers its station’s bit.
Common Pitfalls
Forgetting edge cases in algorithm design (e.g., empty input, single element, already sorted data).
Misunderstanding the difference between a stack (LIFO) and a queue (FIFO) in data structure applications.
Confusing authentication (who you are) with authorisation (what you can do) in security contexts.
Forgetting that average-case for quicksort becomes worst-case on already sorted input.
Worked Examples
Example 1: IP Addressing and Subnet Mask
Problem. Given IP 192.168.10.130 with subnet mask 255.255.255.192, find the network address, broadcast address, and usable host range.
Solution. Mask /26 means 64 addresses per subnet.
Network: 192.168.10.128 (IP AND mask = 130 AND 192 = 128).
Broadcast: 192.168.10.191 (network + 63).
Usable hosts: 192.168.10.129 to 192.168.10.190 (62 hosts).
Example 2: CRC Error Detection
Problem. Compute the CRC for data 11010011101100 using divisor 1011.
Solution. Append 3 zeros (divisor length − 1): 11010011101100000.
XOR division by 1011:
11010011101100000 ÷ 1011→ remainder = 100Transmitted frame: 11010011101100100. Receiver divides by 1011; remainder 0 → no error.
Summary
- OSI 7-layer model: Physical → Data Link → Network → Transport → Session → Presentation → Application.
- TCP/IP model maps to 4 layers; TCP provides reliable, ordered delivery; UDP provides fast, connectionless transport.
- IP addressing: IPv4 uses 32-bit addresses with CIDR notation; subnet masks determine network vs host portions.
- DNS translates domain names to IP addresses using hierarchical, distributed resolution with caching.
- HTTP/HTTPS: request-response protocol; TLS provides encryption, authentication, and integrity at the transport layer.
Cross-References
| Topic | Site | Link |
|---|---|---|
| Advanced Computer Networks | WyattsNotes | View |
| Operating Systems | WyattsNotes | View |
| Databases | WyattsNotes | View |
| Computer Networking — Stanford | Stanford CS144 | View |
:::