Skip to content

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:

LayerNameFunctionExamples
7ApplicationUser-facing protocolsHTTP, DNS, SMTP, FTP
6PresentationData representation, encryption, compressionTLS, SSL, JPEG, ASCII
5SessionDialog control, synchronisationNetBIOS, RPC, PPTP
4TransportEnd-to-end reliability, flow controlTCP, UDP, SCTP
3NetworkLogical addressing, routingIP, ICMP, ARP, OSPF
2Data LinkFraming, error detection, MACEthernet, Wi-Fi, PPP
1PhysicalBit transmission on the mediumCables, 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):

Data+thSegment+nhPacket+fh+ftFrameencodeBits\mathrm{Data} \xrightarrow{+\mathrm{th} \mathrm{Segment} \xrightarrow{+\mathrm{nh} \mathrm{Packet} \xrightarrow{+\mathrm{fh}+ft} \mathrm{Frame} \xrightarrow{\mathrm{encode} \mathrm{Bits}}}}

1.2 The TCP/IP Model

The TCP/IP model is the practical standard used on the Internet, with four layers:

LayerOSI EquivalentProtocols
Application5, 6, 7HTTP, DNS, SMTP, TLS
Transport4TCP, UDP
Internet3IP, ICMP, ARP
Network Access1, 2Ethernet, 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:

AspectOSI ModelTCP/IP Model
Layers74
NatureTheoretical reference modelPractical implementation model
Session/PresentationSeparate layers (5, 6)Merged into Application layer
Network layerConnection-oriented and connectionlessPrimarily connectionless (IP)
Transport layerTP4 (reliable) and TP0 (unreliable)TCP (reliable) and UDP (unreliable)
StandardisationISO/IECIETF (RFCs)
Adopted byAcademic, governmentThe global Internet
Protocol independenceLayer-independent protocolsProtocols tightly coupled
Service interfacePrecisely defined (SAPs)Loosely defined
Release1984Developed 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:

LayerPDU NameHeader AddedTrailerSize (typical)
ApplicationDataApplication-specificNoneVariable
TransportSegmentTCP/UDP headerNone20—60 bytes
NetworkPacketIP headerNone20—60 bytes
Data LinkFrameMAC headerFCS14—18 + 4 B
PhysicalBitsNone (encoding)NoneN/A

Encapsulation walkthrough. Consider sending an HTTP GET request of 500 bytes through TCP/IP over Ethernet:

  1. Application layer: HTTP creates a request message (500 bytes).
  2. Transport layer: TCP adds a 20-byte header. Segment = 520 bytes.
  3. Network layer: IP adds a 20-byte header. Packet = 540 bytes.
  4. Data Link layer: Ethernet adds 14-byte header + 4-byte FCS. Frame = 558 bytes.
  5. 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 HH Hz with VV discrete signal levels:

C=2Hlog2V  bpsC = 2H \log_2 V \;\mathrm{bps}

Theorem 2.1 (Nyquist—Shannon Sampling Theorem). A bandlimited signal of bandwidth HH Hz can Be perfectly reconstructed from samples taken at a rate of at least 2H2H samples per second.

Proof. Let x(t)x(t) be a signal with Fourier transform X(f)X(f) such that X(f)=0X(f) = 0 for f>H\lvert f \rvert \gt H. Sampling at rate fsf_s produces xs(t)=x(t)n=δ(tnTs)x_s(t) = x(t) \cdot \sum_{n=-\infty}^{\infty} \delta(t - nT_s) Where Ts=1/fsT_s = 1/f_s. In the frequency domain, Xs(f)=fsk=X(fkfs)X_s(f) = f_s \sum_{k=-\infty}^{\infty} X(f - kf_s). When fs2Hf_s \geq 2HThe spectral copies do not overlap, and x(t)x(t) can be recovered by an ideal Lowpass filter with cutoff HH. When fs<2Hf_s \lt 2HAliasing occurs and perfect recovery is Impossible. \blacksquare

  • Shannon capacity: For a noisy channel with signal-to-noise ratio SNR\mathrm{SNR}:

C=Hlog2(1+SNR)  bpsC = H \log_2(1 + \mathrm{SNR}) \;\mathrm{bps}

Theorem 2.2 (Shannon—Hartley Theorem). The channel capacity CC is the maximum error-free data Rate achievable on a channel of bandwidth HH with signal-to-noise ratio SNR\mathrm{SNR}.

Proof. For a bandlimited AWGN channel, the number of distinguishable signal levels is constrained By the noise power. Let SNR=S/N\mathrm{SNR} = S/N where SS is signal power and N=N0HN = N_0 H is noise Power. The number of distinguishable amplitude levels is proportional to 1+SNR\sqrt{1 + \mathrm{SNR}}. With log2\log_2 levels per signal element and 2H2H signal elements per second (Nyquist), the maximum Error-free rate is C=2H12log2(1+SNR)=Hlog2(1+SNR)C = 2H \cdot \tfrac{1}{2}\log_2(1 + \mathrm{SNR}) = H \log_2(1 + \mathrm{SNR}). \blacksquare

Example. A telephone line has H=3100H = 3100 Hz and SNR=3162\mathrm{SNR} = 3162 (35 dB). Shannon limit: C=3100×log2(3163)34860C = 3100 \times \log_2(3163) \approx 34860 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: C=2Hlog2VC = 2H \log_2 V 56000=2×4000×log2V56000 = 2 \times 4000 \times \log_2 V log2V=560008000=7\log_2 V = \frac{56000}{8000} = 7 V=27=128V = 2^7 = 128

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: C=Hlog2(1+SNR)=36×106×log2(1001)C = H \log_2(1 + \mathrm{SNR}) = 36 \times 10^6 \times \log_2(1001) log2(1001)=ln(1001)ln(2)9.967\log_2(1001) = \frac{\ln(1001)}{\ln(2)} \approx 9.967 C=36×106×9.967358.8×106  bps358.8  MbpsC = 36 \times 10^6 \times 9.967 \approx 358.8 \times 10^6 \;\mathrm{bps} \approx 358.8\;\mathrm{Mbps}

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 H=6000H = 6000 Hz and SNR=1023\mathrm{SNR} = 1023 (30 dB).

Shannon limit: C=6000×log2(1024)=6000×10=60000  bpsC = 6000 \times \log_2(1024) = 6000 \times 10 = 60000\;\mathrm{bps}

Nyquist limit with V=8V = 8: C=2×6000×log2(8)=12000×3=36000  bpsC = 2 \times 6000 \times \log_2(8) = 12000 \times 3 = 36000\;\mathrm{bps}

The Nyquist limit (36 kbps) is below the Shannon limit (60 kbps), so 8 signal levels are Achievable. With V=64V = 64: C=12000×6=72000  bpsC = 12000 \times 6 = 72000\;\mathrm{bps}

This exceeds Shannon’s limit of 60 kbps, meaning 64 levels would produce errors. The maximum Number of levels consistent with Shannon: CShannon=2Hlog2V    60000=12000×log2V    V=32C_{\mathrm{Shannon} = 2H \log_2 V \implies 60000 = 12000 \times \log_2 V \implies V = 32}

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 MM-ary QAM scheme where M=22kM = 2^{2k} has a spectral Efficiency of 2k2k bits/symbol, i.e., the bit rate equals 2k×B2k \times B where BB is the bandwidth In Hz.

Proof. QAM modulates both amplitude and phase of a carrier. With MM symbols, each symbol carries log2M=2k\log_2 M = 2k bits. The symbol rate equals the bandwidth BB (Nyquist: 2 symbols/Hz for Baseband, 1 symbol/Hz for passband). Therefore bit rate = 2k×B2k \times B. \blacksquare

Worked Example: QAM Data Rate Calculation

A 256-QAM modem operates over a 20 MHz channel. What is the maximum data rate?

M=256,log2256=8  bits/symbolM = 256, \quad \log_2 256 = 8 \;\mathrm{bits}/symbol

Bit  rate=8×20×106=160  Mbps\mathrm{Bit}\;rate = 8 \times 20 \times 10^6 = 160\;\mathrm{Mbps}

If the channel has SNR = 24 dB, verify against Shannon:

\mathrm{SNR_}{\mathrm{linear} = 10^{24/10} = 251.2} C=20×106×log2(252.2)20×106×7.98159.6  MbpsC = 20 \times 10^6 \times \log_2(252.2) \approx 20 \times 10^6 \times 7.98 \approx 159.6\;\mathrm{Mbps}

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.

EncodingDescriptionExample
NRZ (L)High = 1, Low = 0USB
NRZITransition = 1, no transition = 0USB
ManchesterTransition at mid-bit; low-to-high = 0802.3 (10 Mbps)
Differential ManchesterTransition at start of 0 bit only802.5 (Token Ring)
4B/5B4 data bits encoded as 5-bit codes100BASE-TX
8B/10B8 data bits encoded as 10-bit codesGigabit Ethernet
64B/66B64 data bits encoded as 66-bit codes10GBASE-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.1 Framing

The data link layer receives a bit stream and divides it into manageable frames.

Framing methods:

  1. Byte count: First field specifies frame length. Vulnerable to corrupted count.
  2. Flag bytes: Special flag byte (0x7E for HDLC) marks start/end. Byte stuffing with escape byte (0x7D) prevents ambiguity.
  3. Bit-oriented flags: Flag pattern 01111110. Bit stuffing: insert 0 after five consecutive 1S in the data.
  4. 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. d(x,y)d(x, y) is the number of bit positions where codewords xx and yy differ. The minimum distance dmind_{\min} determines capability:

  • Detect up to dmin1d_{\min} - 1 errors.
  • Correct up to (dmin1)/2\lfloor(d_{\min} - 1)/2\rfloor errors.

Hamming code. Adds rr parity bits to mm data bits where 2rm+r+12^r \geq m + r + 1. 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. dmin=3d_{\min} = 3: detects 2 errors, corrects 1.

Worked Example: Hamming(7,4) Encoding and Error Correction

Encoding. Transmit data bits d1d2d3d4=1011d_1 d_2 d_3 d_4 = 1011.

Codeword positions (1-indexed): p1  p2  d1  p3  d2  d3  d4p_1\; p_2\; d_1\; p_3\; d_2\; d_3\; d_4. 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:

p1p_1 covers positions with bit 0 set: {1, 3, 5, 7}. p2p_2 covers positions with bit 1 set: {2, 3, 6, 7}. p3p_3 covers positions with bit 2 set: {4, 5, 6, 7}.

Calculate parity bits (even parity):

p1p_1: positions 1, 3, 5, 7 \to data at 3, 5, 7 are 1, 0, 1. Sum = 0 (even) \to p1=0p_1 = 0.

p2p_2: positions 2, 3, 6, 7 \to data at 3, 6, 7 are 1, 1, 1. Sum = 1 (odd) \to p2=1p_2 = 1.

p3p_3: positions 4, 5, 6, 7 \to data at 5, 6, 7 are 0, 1, 1. Sum = 0 (even) \to p3=0p_3 = 0.

Transmitted codeword: 0  1  1  0  0  1  10\;1\;1\;0\;0\;1\;1

Error correction. Suppose bit 6 is flipped during transmission. Received word: 0  1  1  0  0  0  10\;1\;1\;0\;0\;0\;1

Compute syndrome bits:

S1S_1: check positions 1, 3, 5, 7 \to 0+1+0+1=00 + 1 + 0 + 1 = 0 (even, OK).

S2S_2: check positions 2, 3, 6, 7 \to 1+1+0+1=11 + 1 + 0 + 1 = 1 (odd, error).

S3S_3: check positions 4, 5, 6, 7 \to 0+0+0+1=10 + 0 + 0 + 1 = 1 (odd, error).

Syndrome = S3S2S1=1102=6S_3 S_2 S_1 = 110_2 = 6. The error is at position 6. Flip bit 6: Corrected word = 0  1  1  0  0  1  10\;1\;1\;0\;0\;1\;1.

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).

  1. Append rr zero bits to the message (rr = degree of generator polynomial G(x)G(x)).
  2. Divide the augmented message polynomial by G(x)G(x) using modulo-2 arithmetic.
  3. Append the remainder (CRC) to the original message.
  4. Receiver divides by G(x)G(x); zero remainder means no error.

Theorem 3.1. CRC detects all single-bit errors, all double-bit errors (if G(x)G(x) has factor (x+1)(x+1)), all odd-numbered errors, and all burst errors of length r\leq r.

Worked Example: CRC Polynomial Division

Compute the CRC for message 110100 using generator G(x)=x3+x+1G(x) = x^3 + x + 1 (binary 1011Degree r=3r = 3).

Step 1: Append r=3r = 3 zero bits \to augmented message: 110100000.

Step 2: Perform modulo-2 (XOR) polynomial division.

M(x)=x5+x4+x2,G(x)=x3+x+1M(x) = x^5 + x^4 + x^2, \quad G(x) = x^3 + x + 1

Maug(x)=x8+x7+x5M_{\mathrm{aug}(x) = x^8 + x^7 + x^5}

Division steps:

  1. x8/x3=x5x^8 / x^3 = x^5. Multiply: x5G(x)=x8+x6+x5x^5 G(x) = x^8 + x^6 + x^5. Subtract (XOR): (x8+x7+x5)+(x8+x6+x5)=x7+x6(x^8 + x^7 + x^5) + (x^8 + x^6 + x^5) = x^7 + x^6.

  2. x7/x3=x4x^7 / x^3 = x^4. Multiply: x4G(x)=x7+x5+x4x^4 G(x) = x^7 + x^5 + x^4. Subtract: (x7+x6)+(x7+x5+x4)=x6+x5+x4(x^7 + x^6) + (x^7 + x^5 + x^4) = x^6 + x^5 + x^4.

  3. x6/x3=x3x^6 / x^3 = x^3. Multiply: x3G(x)=x6+x4+x3x^3 G(x) = x^6 + x^4 + x^3. Subtract: (x6+x5+x4)+(x6+x4+x3)=x5+x3(x^6 + x^5 + x^4) + (x^6 + x^4 + x^3) = x^5 + x^3.

  4. x5/x3=x2x^5 / x^3 = x^2. Multiply: x2G(x)=x5+x3+x2x^2 G(x) = x^5 + x^3 + x^2. Subtract: (x5+x3)+(x5+x3+x2)=x2(x^5 + x^3) + (x^5 + x^3 + x^2) = x^2.

  5. Degree of x2x^2 (which is 2) is less than degree of G(x)G(x) (which is 3). Stop.

Remainder: x2x^2 = binary 100.

Step 3: Append remainder to original message. Transmitted codeword: 110100100.

Verification. The receiver divides 110100100 by 1011. Since x2x^2 was chosen as the remainder, (x8+x7+x5)+x2=(x5+x4+x3+x2)G(x)(x^8 + x^7 + x^5) + x^2 = (x^5 + x^4 + x^3 + x^2) \cdot G(x)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 S=Ge2GS = G e^{-2G}Maximum at G=0.5G = 0.5: Smax=1/(2e)18.4%S_{\max} = 1/(2e) \approx 18.4\%.
  • Slotted ALOHA: Time divided into slots; transmit at slot boundary. S=GeGS = G e^{-G}Maximum at G=1G = 1: Smax=1/e36.8%S_{\max} = 1/e \approx 36.8\%.

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 pp.

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 nn-th collision, choose random k0,1,,2min(n,10)1k \in \\{0, 1, \ldots, 2^{\min(n,10)} - 1\\} and wait K×512K \times 512 bit times.
  • Minimum frame size: Must be at least 2τ2\tau where τ\tau is the round-trip propagation delay. For 10 Mbps Ethernet with τ=51.2  μs\tau = 51.2\;\mu\mathrm{s}: 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 2τ2\tauWhere τ=d/v\tau = d/v (dd is the maximum cable length, vv is the signal propagation speed, 2×1082 \times 10^8 m/s in copper). The minimum frame size is therefore:

Lmin=R×2τ=2RdvL_{\min} = R \times 2\tau = \frac{2Rd}{v}

Where RR 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 2×1082 \times 10^8 m/s. Calculate the minimum frame size.

One-way propagation delay: τ=dv=20002×108=10  μs\tau = \frac{d}{v} = \frac{2000}{2 \times 10^8} = 10\;\mu\mathrm{s}

Worst case: collision occurs at the far end, signal must travel back. Total time is 2τ=20  μs2\tau = 20\;\mu\mathrm{s}.

The sender must still be transmitting after 2τ2\tau: Lmin=R×2τ=100×106×20×106=2000  bits=250  bytesL_{\min} = R \times 2\tau = 100 \times 10^6 \times 20 \times 10^{-6} = 2000\;\mathrm{bits} = 250\;\mathrm{bytes}

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.

StandardFrequencyMax PHY RateChannel Width
802.11a5 GHz54 Mbps20 MHz
802.11b2.4 GHz11 Mbps22 MHz
802.11g2.4 GHz54 Mbps20 MHz
802.11n2.4/5 GHz600 Mbps20/40 MHz
802.11ac5 GHz6.93 Gbps20-160 MHz
802.11ax2.4/5/69.6 Gbps20-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:

FieldSizeDescription
Preamble7 bytesAlternating 1s and 0s for sync
SFD1 byteStart of frame delimiter (10101011)
Dest MAC6 bytesDestination MAC address
Src MAC6 bytesSource MAC address
Type/Len2 bytesEtherType or frame length
Payload46-1500 BData
FCS4 bytesFrame 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:

StandardSpeedMediumMax Segment
10BASE-T10 MbpsCat3+ UTP100 m
100BASE-TX100 MbpsCat5+ UTP100 m
1000BASE-T1 GbpsCat5e+ UTP100 m
10GBASE-T10 GbpsCat6a+ UTP100 m
10GBASE-SR10 GbpsMulti-mode fibre26-300 m
10GBASE-LR10 GbpsSingle-mode fibre10 km
100GBASE-SR4100 GbpsMulti-mode fibre70-100 m
400GBASE-DR4400 GbpsSingle-mode fibre500 m

Theorem 3.3 (CSMA/CD efficiency). The maximum efficiency of CSMA/CD is:

η=11+5a\eta = \frac{1}{1 + 5a}

Where a=τ/Tfa = \tau / T_f is the ratio of propagation delay to frame transmission time.

Proof. In the worst case, a collision wastes 2τ2\tau time and one frame transmission time TfT_f. The useful time per cycle is TfT_f. The total cycle time is Tf+2τT_f + 2\tau in the worst case, but On average (with the binary exponential backoff), the effective overhead is approximately 5τ5\tau. Thus η=Tf/(Tf+5τ)=1/(1+5a)\eta = T_f / (T_f + 5\tau) = 1 / (1 + 5a). \blacksquare

When a1a \ll 1 (large frames or short distances), efficiency approaches 1. When aa 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:

FieldSizeDescription
TPID16 bitsTag Protocol Identifier (0x8100)
PCP3 bitsPriority Code Point (802.1p)
DEI1 bitDrop Eligible Indicator
VLAN ID (VID)12 bitsVLAN 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. \blacksquare

Switch forwarding methods. A layer-2 switch can forward frames using two strategies:

AspectStore-and-ForwardCut-Through
OperationReceives entire frame firstReads destination MAC only
LatencyL/R+dpropL/R + d_{\mathrm{prop}} per hopLh/R+dpropL_h/R + d_{\mathrm{prop}} per hop
Error detectionCan check FCS before forwardCannot check FCS
Memory requirementMust buffer full frameOnly needs header buffer
Use caseGeneral-purpose switchingLow-latency environments

Where LL is the full frame length, LhL_h is the header length (14 bytes for Ethernet), RR is the Link rate, and dpropd_{\mathrm{prop}} is the propagation delay.

For a path through nn 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 μ\muS Propagation delay.

Store-and-forward:

Latency=3×1500×8109+3×5×106=36  μs+15  μs=51  μs\mathrm{Latency} = 3 \times \frac{1500 \times 8}{10^9} + 3 \times 5 \times 10^{-6} = 36\;\mu\mathrm{s} + 15\;\mu\mathrm{s} = 51\;\mu\mathrm{s}

Cut-through:

Latency=1500×8109+2×14×8109+3×5×106=12  μs+0.224  μs+15  μs=27.2  μs\mathrm{Latency} = \frac{1500 \times 8}{10^9} + 2 \times \frac{14 \times 8}{10^9} + 3 \times 5 \times 10^{-6} = 12\;\mu\mathrm{s} + 0.224\;\mu\mathrm{s} + 15\;\mu\mathrm{s} = 27.2\;\mu\mathrm{s}

Answer: Cut-through saves approximately 23.8 μ\muS (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):

FieldSizeDescription
Version4 bitsAlways 4
IHL4 bitsHeader length in 32-bit words (5 = 20 bytes)
DSCP/ECN8 bitsDifferentiated services / Explicit congestion
Total Length16 bitsEntire packet size (header + data)
Identification16 bitsUnique ID for fragments of the same datagram
Flags3 bitsDF (Don’t Fragment), MF (More Fragments)
Fragment Off.13 bitsOffset in 8-byte units
TTL8 bitsTime to live; decremented by each router
Protocol8 bitsUpper-layer protocol (6=TCP, 17=UDP, 1=ICMP)
Checksum16 bitsHeader checksum only
Src Address32 bitsSource IPv4 address
Dst Address32 bitsDestination IPv4 address

Address classes:

ClassRangeDefault MaskFirst Bits
A1.0.0.0 — 126.255.255.255255.0.0.00
B128.0.0.0 — 191.255.255.255255.255.0.010
C192.0.0.0 — 223.255.255.255255.255.255.0110
D224.0.0.0 — 239.255.255.255Multicast1110
E240.0.0.0 — 255.255.255.255Reserved1111

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):

SubnetRangeBroadcast
192.168.1.0/26192.168.1.1 — 192.168.1.62192.168.1.63
192.168.1.64/26192.168.1.65 — 192.168.1.126192.168.1.127
192.168.1.128/26192.168.1.129 — 192.168.1.190192.168.1.191
192.168.1.192/26192.168.1.193 — 192.168.1.254192.168.1.255

Each subnet has 262=622^6 - 2 = 62 usable hosts.

CIDR (Classless Inter-Domain Routing). Notation: a.b.c.d/n where nn 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).

SubnetHosts needed2n2^nPrefixNetworkRangeBroadcast
LAN A6064/26192.168.10.0/26.1 — .62192.168.10.63
LAN B2832/27192.168.10.64/27.65 — .94192.168.10.95
LAN C1216/28192.168.10.96/28.97 — .110192.168.10.111
LAN D68/29192.168.10.112/29.113 — .118192.168.10.119
P2P Link 124/30192.168.10.120/30.121 — .122192.168.10.123
P2P Link 224/30192.168.10.124/30.125 — .126192.168.10.127
P2P Link 324/30192.168.10.128/30.129 — .130192.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 7×64=4487 \times 64 = 448 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: 21282^{128}.
  • 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):

FieldSizeDescription
Version4 bitsAlways 6
Traffic Class8 bitsECN and DSCP
Flow Label20 bitsQoS and flow identification
Payload Len16 bitsLength of the payload
Next Header8 bitsType of extension header
Hop Limit8 bitsReplaces 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 HeaderNext Header ValuePurpose
Hop-by-Hop Options0Options processed by every router
Routing (Type 0)43Source routing (deprecated)
Fragment44Fragmentation and reassembly
Destination Options60Options for destination only
Authentication Header51Integrity and authentication
Encapsulating Security50Confidentiality 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.

  1. Host needs to send a packet to IP address BB.
  2. Host checks its ARP cache for BB‘s MAC address.
  3. If not cached, broadcast an ARP request: “Who has BB? Tell AA.”
  4. Host BB replies with its MAC address (unicast).
  5. Host AA 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: dx(y)=minv{c(x,v)+dv(y)}d_x(y) = \min_v \{c(x,v) + d_v(y)\} where c(x,v)c(x,v) is the link cost to neighbour vv.
  • 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:

  1. B sets dB(A)=d_B(A) = \inftyAdvertises to C.
  2. C still has dC(A)=2d_C(A) = 2 via B, advertises dC(A)=2d_C(A) = 2 to B.
  3. B sets dB(A)=3d_B(A) = 3 via C. C then sets dC(A)=4d_C(A) = 4. This continues.

Solution: Split horizon with poisoned reverse. B advertises dB(A)=d_B(A) = \infty 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 = 108/bandwidth(bps)10^8 / \mathrm{bandwidth}(bps) 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:

FieldDescription
HeaderVersion, area ID, router ID, checksum
LSA typeRouter-LSA, Network-LSA, Summary-LSA
Link IDIdentifies the described object
Advertising routerRouter originating the LSA
Sequence numberDetects stale or duplicate LSAs
AgeTime 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_PREFShortest AS_PATHLowest origin, lowest MED eBGP over iBGP, lowest IGP cost to NEXT_HOPLowest router ID.

BGP route advertisement:

AS 65001 -> AS 65002: reach 203.0.113.0/24, AS_PATH = 65001
AS 65002 -> AS 65003: reach 203.0.113.0/24, AS_PATH = 65001 65002

AS 65003 rejects any route containing its own AS number (loop prevention).

BGP attributes in detail:

  • Well-known mandatory: AS_PATH``NEXT_HOP``ORIGIN (IGP <\lt EGP <\lt 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:

FeatureRIPOSPFBGP
TypeDistance VectorLink StatePath Vector
AlgorithmBellman-FordDijkstraPolicy-based
MetricHop count (max 15)Cost (bandwidth-based)AS_PATH + attributes
ScopeAS (interior)AS (interior)Inter-domain
ConvergenceSlowFastConfigurable
UpdatesPeriodic (30 s)Triggered (LSA flood)Incremental
ScalabilitySmall networksLarge networksInternet-scale
HierarchyFlatAreasAS-based
VLSM supportRIPv2 onlyYesYes
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--- F

Goal: Construct the routing table at router A using Dijkstra’s algorithm.

Initialisation. Set d(A)=0d(A) = 0, d(all  others)=d(\mathrm{all}\;others) = \infty. Unvisited = {A,B,C,D,E,F}\{A, B, C, D, E, F\}.

Visit A (d=0d = 0). Neighbours: B (cost 3), D (cost 4). Update: d(B)=3d(B) = 3Prev(B)=A(B) = A. d(D)=4d(D) = 4Prev(D)=A(D) = A.

Visit B (d=3d = 3Smallest unvisited). Neighbours: A (skip), C (3 + 2 = 5), E (3 + 1 = 4). Update: d(C)=5d(C) = 5Prev(C)=B(C) = B. d(E)=4d(E) = 4Prev(E)=B(E) = B.

Visit D (d=4d = 4). Neighbours: A (skip), E (4 + 6 = 10, worse than 4). No updates.

Visit E (d=4d = 4). Neighbours: B (skip), D (skip), F (4 + 3 = 7). Update: d(F)=7d(F) = 7Prev(F)=E(F) = E.

Visit C (d=5d = 5). Neighbours: B (skip), F (5 + 5 = 10, worse than 7). No updates.

Visit F (d=7d = 7). All neighbours visited. Done.

Routing table at A:

DestinationNext HopCostPath
BB3A — B
CB5A — B — C
DD4A — D
EB4A — B — E
FB7A — B — E — F

4.7 ICMP

Internet Control Message Protocol provides error reporting and diagnostics. Encapsulated in IP (protocol number 1).

TypeCodeMeaning
00Echo reply
30-15Destination unreachable
80Echo request (ping)
110-1Time 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:

  1. The Identification field is the same for all fragments of the original datagram.
  2. The MF (More Fragments) flag is 1 for all fragments except the last.
  3. The Fragment Offset specifies the position of the fragment’s data in the original datagram (in 8-byte units).
  4. Each fragment becomes an independent IP packet with its own IP header.
  5. 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 (1480/8=1851480/8 = 185), so this Works cleanly.

Number of fragments: 3980/1480=3\lceil 3980 / 1480 \rceil = 3.

FragmentHeaderDataMFOffsetTotal
120 B1480 B101500 B
220 B1480 B11851500 B
320 B1020 B03701040 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 2n22^n - 2 usable hosts applies only for prefixes of /30 or shorter. :::

5. Transport Layer

5.1 UDP

Connectionless, unreliable, message-oriented. 8-byte header.

FieldSizeDescription
Src port16 bitsSource port
Dst port16 bitsDestination port
Length16 bitsHeader + data length
Checksum16 bitsOptional (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.

FieldSizeDescription
Src port16 bitsSource port
Dst port16 bitsDestination port
Seq number32 bitsByte position of first data byte
Ack number32 bitsNext expected byte from other side
Data offset4 bitsHeader length in 32-bit words
Flags9 bitsURG, ACK, PSH, RST, SYN, FIN
Window16 bitsReceive window size (flow control)
Checksum16 bitsMandatory
Urgent ptr16 bitsPointer to urgent data

5.3 TCP Options

The TCP header can include options (within the data offset space):

OptionSizePurpose
MSS4 bytesMaximum Segment Size (announced in SYN)
Window Scale3 bytesScale the window field (RFC 7323)
SACK Permitted2 bytesAllow Selective Acknowledgements
SACKVariableSpecify blocks of received data
Timestamps10 bytesRTT 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 SS bits, allowing windows up to 216+S12^{16+S-1} bytes (maximum S=14S = 14Yielding a 1 GiB window).

5.4 TCP vs UDP Comparison

AspectTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed delivery, ACKsBest effort
OrderingOrdered deliveryNo ordering
Flow controlSliding windowNone
Congestion ctrlcwnd, ssthreshNone
Header size20—60 bytes8 bytes
OverheadHigher (handshake, ACKs)Lower
Use casesWeb, email, file transferDNS, VoIP, streaming, gaming
BroadcastNo (point-to-point)Yes (broadcast and multicast)
RetransmissionAutomaticApplication-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. \blacksquare

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) -------->| ESTABLISHED

Four-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: CLOSED

TIME_WAIT. Client waits 2×MSL2 \times \mathrm{MSL} (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):

FromEventTo
CLOSEDpassive openLISTEN
CLOSEDactive open, send SYNSYN_SENT
LISTENrecv SYN, send SYN+ACKSYN_RCVD
LISTENcloseCLOSED
SYN_SENTrecv SYN+ACK, send ACKESTABLISHED
SYN_RCVDrecv ACKESTABLISHED
ESTABLISHEDclose, send FINFIN_WAIT_1
ESTABLISHEDrecv FIN, send ACKCLOSE_WAIT
FIN_WAIT_1recv ACKFIN_WAIT_2
FIN_WAIT_1recv FIN, send ACKCLOSING
FIN_WAIT_2recv FIN, send ACKTIME_WAIT
CLOSE_WAITclose, send FINLAST_ACK
CLOSINGrecv ACKTIME_WAIT
LAST_ACKrecv ACKCLOSED
TIME_WAIT2 ×\times MSL timeoutCLOSED

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.

Effective  window=min(cwnd,rwnd)\mathrm{Effective}\;window = \min(\mathrm{cwnd},\, \mathrm{rwnd})

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 cwndssthresh\mathrm{cwnd} \geq \mathrm{ssthresh}Increase cwnd by MSS×(MSS/cwnd)\mathrm{MSS} \times (\mathrm{MSS} / \mathrm{cwnd}) 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: ssthresh=cwnd/2\mathrm{ssthresh} = \mathrm{cwnd}/2 cwnd=ssthresh+3\mathrm{cwnd} = \mathrm{ssthresh} + 3. 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 = 1

TCP 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:

  1. Connection established, enter slow start.
  2. After 4 RTTs, cwnd reaches ssthresh.
  3. 3 more RTTs in congestion avoidance.
  4. Three duplicate ACKs received (fast retransmit).
  5. New ACK arrives after fast recovery.

Slow start (cwnd doubles each RTT):

RTTcwnd (MSS)cwnd (bytes)Phase
122920Slow start
245840Slow start
3811680Slow start
41623360cwnd \geq ssthresh \to switch

Congestion avoidance (cwnd increases by ~1 MSS per RTT):

RTTcwnd (bytes)IncrementPhase
524820+1460Congestion avoidance
626280+1460Congestion avoidance
727740+1460Congestion avoidance

Fast retransmit and recovery (after 3 dup ACKs):

Ssthresh = 27740 / 2 = 13870 bytes Cwnd = 13870 + 3 ×\times 1460 = 18250 bytes

New ACK arrives (exit fast recovery):

Cwnd = ssthresh = 13870 bytes, continue congestion avoidance.

5.8 Retransmission Timer

RTTs=(1α)RTTs+αRTTm\mathrm{RTT_s} = (1 - \alpha)\,\mathrm{RTT_s} + \alpha \cdot \mathrm{RTT_m}

RTTd=(1β)RTTd+βRTTmRTTs\mathrm{RTT_d} = (1 - \beta)\,\mathrm{RTT_d} + \beta\,|\mathrm{RTT_m} - \mathrm{RTT_s}|

RTO=RTTs+4RTTd\mathrm{RTO} = \mathrm{RTT_s} + 4 \cdot \mathrm{RTT_d}

Where RTTm\mathrm{RTT_m} = measured RTT, α=1/8\alpha = 1/8, β=1/4\beta = 1/4. 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: α=1/8\alpha = 1/8, β=1/4\beta = 1/4Initial RTTs=0\mathrm{RTT_s} = 0, RTTd=0\mathrm{RTT_d} = 0. Measured RTTs: 220 ms, 240 ms, 230 ms, 260 ms, 250 ms.

After measurement 1 (220 ms):

RTTs=(7/8)(0)+(1/8)(220)=27.5\mathrm{RTT_s} = (7/8)(0) + (1/8)(220) = 27.5 ms RTTd=(3/4)(0)+(1/4)22027.5=48.125\mathrm{RTT_d} = (3/4)(0) + (1/4)|220 - 27.5| = 48.125 ms RTO=27.5+4(48.125)=220\mathrm{RTO} = 27.5 + 4(48.125) = 220 ms

After measurement 2 (240 ms):

RTTs=(7/8)(27.5)+(1/8)(240)=24.06+30=54.06\mathrm{RTT_s} = (7/8)(27.5) + (1/8)(240) = 24.06 + 30 = 54.06 ms RTTd=(3/4)(48.125)+(1/4)24054.06=36.09+46.49=82.58\mathrm{RTT_d} = (3/4)(48.125) + (1/4)|240 - 54.06| = 36.09 + 46.49 = 82.58 ms RTO=54.06+4(82.58)=384.38\mathrm{RTO} = 54.06 + 4(82.58) = 384.38 ms

After measurement 3 (230 ms):

RTTs=(7/8)(54.06)+(1/8)(230)=47.30+28.75=76.05\mathrm{RTT_s} = (7/8)(54.06) + (1/8)(230) = 47.30 + 28.75 = 76.05 ms RTTd=(3/4)(82.58)+(1/4)23076.05=61.94+38.49=100.43\mathrm{RTT_d} = (3/4)(82.58) + (1/4)|230 - 76.05| = 61.94 + 38.49 = 100.43 ms RTO=76.05+4(100.43)=477.77\mathrm{RTO} = 76.05 + 4(100.43) = 477.77 ms

After measurement 4 (260 ms):

RTTs=(7/8)(76.05)+(1/8)(260)=66.54+32.50=99.04\mathrm{RTT_s} = (7/8)(76.05) + (1/8)(260) = 66.54 + 32.50 = 99.04 ms RTTd=(3/4)(100.43)+(1/4)26099.04=75.32+40.24=115.56\mathrm{RTT_d} = (3/4)(100.43) + (1/4)|260 - 99.04| = 75.32 + 40.24 = 115.56 ms RTO=99.04+4(115.56)=561.28\mathrm{RTO} = 99.04 + 4(115.56) = 561.28 ms

After measurement 5 (250 ms):

RTTs=(7/8)(99.04)+(1/8)(250)=86.66+31.25=117.91\mathrm{RTT_s} = (7/8)(99.04) + (1/8)(250) = 86.66 + 31.25 = 117.91 ms RTTd=(3/4)(115.56)+(1/4)250117.91=86.67+33.02=119.69\mathrm{RTT_d} = (3/4)(115.56) + (1/4)|250 - 117.91| = 86.67 + 33.02 = 119.69 ms RTO=117.91+4(119.69)=596.67\mathrm{RTO} = 117.91 + 4(119.69) = 596.67 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 (.) \to TLD (com``org``net) \to second-level (example.com) \to subdomain (www.example.com).

Record types:

TypeNamePurpose
AIPv4IPv4 address
AAAAIPv6IPv6 address
CNAMEAliasAlias to another name
MXMailMail server for the domain
NSNameAuthoritative name server
SOAStartZone administration info
TXTTextArbitrary text (SPF, DKIM, verification)

Resolution process:

  1. Client queries the recursive resolver (e.g., 8.8.8.8).
  2. Resolver queries a root server for the TLD server.
  3. Root refers to the TLD server (e.g., for .com).
  4. TLD server refers to the authoritative server for the domain.
  5. Authoritative server returns the answer.
  6. 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:

  1. Client \to recursive resolver: “What is the A record for www.example.com?” (UDP, 1 RTT).
  2. Resolver \to root server: “Where is the .com TLD?” (1 RTT).
  3. Root \to resolver: “Ask the .com TLD server at 192.5.6.30.”
  4. Resolver \to .com TLD: “Where is example.com?” (1 RTT).
  5. TLD \to resolver: “Ask the example.com authoritative server at 93.184.216.34.”
  6. Resolver \to authoritative: “What is the A record for www.example.com?” (1 RTT).
  7. Authoritative \to resolver: “93.184.216.34, TTL = 300.”
  8. Resolver \to 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:

MethodIdempotentSafePurpose
GETYesYesRetrieve a resource
POSTNoNoSubmit data
PUTYesNoReplace a resource
DELETEYesNoDelete a resource
PATCHNoNoPartial modification
HEADYesYesLike GET but no body
OPTIONSYesYesDescribe communication options

Status codes:

Code RangeCategoryExamples
1xxInformational100 Continue
2xxSuccess200 OK, 201 Created
3xxRedirection301 Moved, 304 Not Modified
4xxClient Error400 Bad Request, 404 Not Found
5xxServer Error500 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.com
S: 250-smtp.example.com Hello
S: 250 AUTH PLAIN LOGIN
C: AUTH PLAIN <credentials>
S: 235 Authentication successful
C: MAIL FROM:<alice@example.com>
S: 250 OK
C: RCPT TO:<bob@example.org>
S: 250 OK
C: DATA
S: 354 Start mail input
C: From: alice@example.com
C: To: bob@example.org
C: Subject: Meeting
C:
C: Hi Bob, let's meet at 3pm.
C: .
S: 250 OK
C: QUIT
S: 221 Bye

IMAP (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).

AspectIMAPPOP3
ModeRemote accessDownload and delete
FoldersYes, server-sideNo
SearchServer-side searchNo
SyncMulti-device syncNo
ResourceHigher server storageLower 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): BDP=bandwidth×RTT\mathrm{BDP} = \mathrm{bandwidth} \times \mathrm{RTT}. The maximum amount of unacknowledged data that can be in flight. For a 10 Gbps link with 80 ms RTT: BDP=1010×0.08=800  Mb=100  MB\mathrm{BDP} = 10^{10} \times 0.08 = 800\;\mathrm{Mb} = 100\;\mathrm{MB}.

  • Throughput: Actual data rate achieved, less than bandwidth due to protocol overhead, congestion, and errors.

  • Latency components: Propagation delay (d/cd / cWhere dd is distance), transmission delay (L/RL / RWhere LL is frame length, RR 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: throughputmin(cwnd,rwnd)/RTT\mathrm{throughput} \leq \min(\mathrm{cwnd}, \mathrm{rwnd}) / \mathrm{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. \blacksquare

:::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.

AlgorithmKey SizeBlock SizeStatus
DES56 bits64 bitsInsecure
3DES168 bits64 bitsDeprecated
AES-128128 bits128 bitsSecure
AES-256256 bits128 bitsSecure
ChaCha20256 bitsStreamSecure

Block cipher modes of operation:

ModeDescriptionParallelisable
ECBEach block encrypted independentlyYes
CBCEach block XORed with previous ciphertextDecryption only
CTRCounter-based stream cipher from block cipherYes
GCMAuthenticated 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 Pi=PjP_i = P_jThen under ECB, Ci=EK(Pi)=EK(Pj)=CjC_i = E_K(P_i) = E_K(P_j) = C_j. An attacker observing identical ciphertext blocks knows the corresponding Plaintext blocks are identical, regardless of the key. \blacksquare

Key distribution problem. Symmetric encryption requires a secure channel to exchange keys. For nn parties, n(n1)/2n(n-1)/2 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.

  1. Choose two large primes pp and qq. Compute n=pqn = pq and ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1).
  2. Choose ee such that 1<e<ϕ(n)1 \lt e \lt \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1.
  3. Compute dd such that ed1(modϕ(n))e \cdot d \equiv 1 \pmod{\phi(n)}.
  4. Public key: (n,e)(n, e). Private key: (n,d)(n, d).
  5. Encrypt: c=memodnc = m^e \bmod n. Decrypt: m=cdmodnm = c^d \bmod n.

Diffie-Hellman key exchange. Allows two parties to establish a shared secret over an insecure Channel without prior shared key.

  1. Public parameters: prime pp and generator gg.
  2. Alice picks secret aaSends A=gamodpA = g^a \bmod p.
  3. Bob picks secret bbSends B=gbmodpB = g^b \bmod p.
  4. Shared secret: s=Bamodp=gabmodp=Abmodps = B^a \bmod p = g^{ab} \bmod p = A^b \bmod p.

An eavesdropper who sees gg, pp, AA, BB cannot compute gabg^{ab} 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:

  1. Server presents its certificate (signed by intermediate CA).
  2. Client verifies the signature chain up to a trusted root CA.
  3. Client checks: validity dates, hostname match (SAN), revocation (CRL/OCSP).
  4. 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:

TypeLayerMechanism
Packet filtering3Permit/deny based on src, dst, port, proto
Stateful inspection3—4Tracks connection state (TCP states)
Application gateway7Proxy for specific applications
Next-generation (NGFW)3—7Deep 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.

#DirSrcDstPortProtoAction
1InAny203.0.113.1080, 443TCPAllow
2InAny203.0.113.2025TCPAllow
3Out10.0.0.0/24AnyAnyAnyAllow
4InAny203.0.113.10AnyICMPAllow
5InAny10.0.0.5353UDPAllow
6InAnyAnyAnyAnyDeny

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.

TechnologyLayerProtocolUse Case
IPsec3AH, ESPSite-to-site, remote access
SSL/TLS4—7TLS 1.3Client-to-site (OpenVPN)
WireGuard3UDP, ChaCha20Modern, lightweight VPN
SSH tunnel7SSHAd-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):

FieldSource IPSrc PortDest IPDst PortProtocolAction
Rule 1AnyAny10.0.0.0/822TCPAllow
Rule 210.0.0.0/8AnyAny80, 443TCPAllow
Rule 3AnyAnyAnyAnyAnyDeny

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

  1. Nyquist theorem. A noiseless channel has bandwidth 8000 Hz. What is the maximum data rate with 16 signal levels? With 256 signal levels?

  2. 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?

  3. Nyquist vs Shannon. A channel has H=3000H = 3000 Hz and SNR=31\mathrm{SNR} = 31 (about 15 dB). What is the maximum number of signal levels VV that can be used reliably?

  4. Hamming code. Encode the data bits d1d2d3d4=0110d_1 d_2 d_3 d_4 = 0110 using Hamming(7,4). If bit 5 of the transmitted codeword is flipped, show how the receiver detects and corrects the error.

  5. CRC computation. Compute the CRC for the message 10110010 using the generator polynomial G(x)=x3+x+1G(x) = x^3 + x + 1 (binary 1011). Write the transmitted codeword.

  6. CRC verification. The receiver gets the codeword 101101110 and the generator is 1011. Perform modulo-2 division to determine whether the frame was received correctly.

  7. ALOHA throughput. A slotted ALOHA system has 4 stations, each transmitting with probability p=0.2p = 0.2 in each slot. Compute the throughput SS and compare it to the theoretical maximum.

  8. CSMA/CD minimum frame. A 1 Gbps Ethernet has a maximum segment length of 100 m and propagation speed 2×1082 \times 10^8 m/s. What is the minimum frame size? How does it compare to the standard Ethernet minimum of 64 bytes?

  9. 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.

  10. 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.

  11. 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.

  12. IPv6 addressing. Expand the IPv6 address 2001:db8::1 to its full 128-bit form. How many /64 subnets does a /56 prefix provide? How many /128 addresses per /64?

  13. 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-- E

    Construct the routing table at S.

  14. 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.

  15. TCP congestion control. Given MSS = 1000 bytes, initial ssthresh = 8000 bytes. Trace cwnd through: slow start for 3 RTTs, then 2 RTTs of congestion avoidance, then a timeout. What is the value of ssthresh after the timeout?

  16. RTT estimation. Using α=1/8\alpha = 1/8, β=1/4\beta = 1/4And measured RTTs of 100 ms, 120 ms, 80 ms, compute RTTs\mathrm{RTT_s}, RTTd\mathrm{RTT_d}And RTO after each measurement (starting from RTTs=RTTd=0\mathrm{RTT_s} = \mathrm{RTT_d} = 0).

  17. DNS resolution. A client at 192.168.1.100 wants to resolve www.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?

  18. 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 ×\times 150 + 504 = 954 ms.
  • HTTP/1.1: 1 connection, sequential requests. 1 RTT for handshake + 16 RTTs for requests (serial) + 504 ms = 1 ×\times 50 + 16 ×\times 50 + 504 = 1354 ms.
  • HTTP/2: 1 RTT for handshake, all requests multiplexed. 1 ×\times 50 + 504 = 554 ms.
  1. Firewall rules. A company has a web server at 203.0.113.10A mail server at 203.0.113.20And an internal network 10.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.

  2. RSA encryption. Given primes p=5p = 5, q=11q = 11And public exponent e=3e = 3: (a) Compute nn, ϕ(n)\phi(n)And the private key dd. (b) Encrypt the message m=7m = 7. (c) Decrypt the ciphertext to verify.

  3. TCP throughput bound. A TCP connection over a satellite link has RTT = 600 ms and bandwidth = 50 Mbps. The receiver advertises rwnd = 1 MB. If cwnd grows 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?

  4. CDMA orthogonality. Four stations share a channel using CDMA with chip codes: C1=(+1,1,+1,+1)C_1 = (+1, -1, +1, +1), C2=(+1,+1,1,+1)C_2 = (+1, +1, -1, +1), C3=(+1,+1,+1,1)C_3 = (+1, +1, +1, -1) C4=(1,+1,+1,+1)C_4 = (-1, +1, +1, +1). 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

  1. Forgetting edge cases in algorithm design (e.g., empty input, single element, already sorted data).

  2. Misunderstanding the difference between a stack (LIFO) and a queue (FIFO) in data structure applications.

  3. Confusing authentication (who you are) with authorisation (what you can do) in security contexts.

  4. Forgetting that O(nlogn)O(n \log n) average-case for quicksort becomes O(n2)O(n^2) 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).

\blacksquare

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 = 100

Transmitted frame: 11010011101100100. Receiver divides by 1011; remainder 0 → no error.

\blacksquare

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

TopicSiteLink
Advanced Computer NetworksWyattsNotesView
Operating SystemsWyattsNotesView
DatabasesWyattsNotesView
Computer Networking — StanfordStanford CS144View

:::