Level 3 — ProductionComputer Networks

Computer Networks

45 minutes60 marksprintable — key stays hidden on paper

Level: 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60

Instructions: Show all working. Where code is asked, write it from memory — syntax lapses are tolerated if logic is sound. Where an "explain-out-loud" prompt appears, write a clear technical narrative.


Question 1 — Physical Layer Capacity (10 marks)

A telephone-grade channel has a bandwidth of 30003000 Hz.

(a) State the Nyquist formula for maximum data rate on a noiseless channel and compute the max bit rate if the signal uses M=8M = 8 discrete levels. (3)

(b) The channel is now noisy with SNR = 3030 dB. State the Shannon–Hartley theorem and compute the theoretical channel capacity (round to nearest kbps). (4)

(c) Explain out loud: why does Nyskvist give a higher rate than Shannon in part (a) vs (b), and which bound governs a real modem's design choice? (3)


Question 2 — CRC From Scratch (10 marks)

Given data bits D=1101011011D = 1101011011 and generator polynomial G=10011G = 10011 (x4+x+1x^4 + x + 1).

(a) Derive the CRC (FCS) bits by binary polynomial long division. Show the division steps. (6)

(b) State the transmitted frame. (2)

(c) Explain out loud how the receiver detects an error, and why a degree-rr generator guarantees detection of all burst errors of length r\le r. (2)


Question 3 — Subnetting & VLSM (12 marks)

You are given the block 172.16.0.0/22.

(a) How many host addresses are usable in this block? Show the calculation. (2)

(b) Using VLSM, carve subnets for these departments (in this order), giving for each the network address, subnet mask (CIDR), and usable host range:

  • Dept A: 500 hosts
  • Dept B: 200 hosts
  • Dept C: 50 hosts
  • Point-to-point link: 2 hosts (8)

(c) Explain out loud why VLSM must allocate largest-first to avoid fragmentation. (2)


Question 4 — Socket Programming From Memory (12 marks)

(a) Write a minimal TCP echo server in Python that listens on 0.0.0.0:5000, accepts one client, echoes received bytes back until the client closes, then exits. (7)

(b) Write the matching TCP client that connects, sends b"hello", prints the echoed reply, and closes. (3)

(c) Explain out loud one line-level change needed to make this a UDP server instead, and why listen()/accept() disappear. (2)


Question 5 — TCP Congestion Control Trace (10 marks)

A TCP connection uses slow start and congestion avoidance. Initial cwnd = 1 MSS, ssthresh = 8 MSS. Every RTT completes successfully until a timeout occurs at the end of RTT 7.

(a) Give cwnd (in MSS) at the start of each RTT from RTT 1 to RTT 8, stating whether the phase is slow start or congestion avoidance. (6)

(b) State the new ssthresh and cwnd immediately after the timeout. (2)

(c) Explain out loud how fast retransmit / fast recovery (as in TCP Reno) would have differed from the timeout behaviour. (2)


Question 6 — TLS Handshake & Security (6 marks)

(a) List, in order, the key messages of a (TLS 1.2) handshake and name what each contributes to confidentiality/authentication. (3)

(b) Explain out loud how a man-in-the-middle attack is prevented by the certificate chain to a trusted CA, and one countermeasure against a replay attack on the handshake. (3)


Answer keyMark scheme & solutions

Question 1 (10 marks)

(a) Nyquist: C=2Blog2MC = 2B \log_2 M. (1) C=2×3000×log28=6000×3=18000C = 2 \times 3000 \times \log_2 8 = 6000 \times 3 = 18000 bps = 18 kbps. (2)

(b) Shannon–Hartley: C=Blog2(1+SNR)C = B \log_2(1 + \text{SNR}). (1) SNR = 30 dB \Rightarrow SNRlinear=1030/10=1000_{\text{linear}} = 10^{30/10} = 1000. (1) C=3000×log2(1001)=3000×9.967229901C = 3000 \times \log_2(1001) = 3000 \times 9.9672 \approx 29901 bps ≈ 30 kbps. (2)

(c) Nyquist assumes a noiseless channel where the number of levels MM is a free design parameter, so its bound depends on chosen MM (here 8). Shannon incorporates noise, which limits how many levels can be reliably distinguished. In part (a) M=8M=8 was fixed low, giving 18 kbps; Shannon's 30 kbps is the true ceiling under the given noise. A real modem's design is governed by the Shannon bound — you cannot reliably exceed it regardless of coding; Nyquist tells you the levels needed to approach it. (3) (1 for Nyquist depends on M, 1 for Shannon = noise ceiling, 1 for Shannon governs design)


Question 2 (10 marks)

(a) Append r=4r=4 zeros: dividend = 11010110110000. Divide by 10011 mod-2 (XOR). (4 for correct division)

Performing mod-2 division, the remainder is 1110. (2)

(Standard textbook result: data 1101011011, G 10011 → CRC 1110.)

(b) Transmitted frame = data + CRC = 1101011011 + 1110 = 11010110111110. (2)

(c) Receiver divides the received frame (data+CRC) by the same GG; a nonzero remainder ⇒ error detected. A degree-rr generator produces an rr-bit FCS; any error pattern E(x)E(x) is undetected only if G(x)E(x)G(x) \mid E(x). A burst of length r\le r has degree <r< r (i.e. spans r\le r bits) and cannot be divisible by the degree-rr GG unless zero — hence all such bursts are caught. (2)


Question 3 (12 marks)

(a) /22 → host bits = 3222=1032-22 = 10. Total = 210=10242^{10} = 1024, usable = 10242=1024 - 2 = 1022. (2)

(b) Block starts 172.16.0.0, range .0.0–.3.255. Largest-first: (2 each)

  • Dept A (500): need 29=5125022^9=512 \ge 502 → /23. Network 172.16.0.0/23, mask 255.255.254.0, hosts 172.16.0.1 – 172.16.1.254.
  • Dept B (200): need 28=2562022^8=256 \ge 202 → /24. Network 172.16.2.0/24, mask 255.255.255.0, hosts 172.16.2.1 – 172.16.2.254.
  • Dept C (50): need 26=64522^6=64 \ge 52 → /26. Network 172.16.3.0/26, mask 255.255.255.192, hosts 172.16.3.1 – 172.16.3.62.
  • P2P (2): need 22=442^2=4 \ge 4 → /30. Network 172.16.3.64/30, mask 255.255.255.252, hosts 172.16.3.65 – 172.16.3.66.

(c) Allocating largest-first ensures each big subnet lands on its required power-of-two boundary before smaller ones consume aligned space; small-first would scatter allocations and leave non-contiguous gaps too small to satisfy a later large request — external fragmentation. (2)


Question 4 (12 marks)

(a) TCP echo server (7 marks: socket/bind/listen/accept 3, loop+echo 3, cleanup 1):

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("0.0.0.0", 5000))
s.listen(1)
conn, addr = s.accept()
while True:
    data = conn.recv(1024)
    if not data:
        break
    conn.sendall(data)
conn.close()
s.close()

(b) Client (3 marks):

import socket
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c.connect(("127.0.0.1", 5000))
c.sendall(b"hello")
print(c.recv(1024))
c.close()

(c) Change SOCK_STREAM to SOCK_DGRAM; use recvfrom()/sendto(). listen()/accept() disappear because UDP is connectionless — there is no handshake or per-connection socket; the single socket receives datagrams from any peer directly. (2)


Question 5 (10 marks)

(a) Slow start doubles each RTT until reaching ssthresh (8), then linear (+1) increase. (6, ~0.75 each)

RTT cwnd (MSS) Phase
1 1 Slow start
2 2 Slow start
3 4 Slow start
4 8 reached ssthresh → congestion avoidance
5 9 Congestion avoidance
6 10 Congestion avoidance
7 11 Congestion avoidance
8 (after timeout, see b)

At end of RTT 7 (cwnd = 11) timeout occurs.

(b) On timeout: ssthresh = cwnd/2 = 11/2 = 5 MSS (floor of 5.5), cwnd = 1 MSS, restart slow start. (2)

(c) Fast retransmit triggers on 3 duplicate ACKs (not a timeout), so the network is only mildly congested. TCP Reno's fast recovery sets ssthresh = cwnd/2 and then cwnd = ssthresh (halving, not collapse to 1), continuing in congestion avoidance — avoiding the throughput crash of restarting slow start from 1. (2)


Question 6 (6 marks)

(a) (3, 1 per grouping)

  1. ClientHello (offers cipher suites, random nonce).
  2. ServerHello + Certificate + ServerKeyExchange + ServerHelloDone (server's chosen suite, cert for authentication, DH params).
  3. ClientKeyExchange, ChangeCipherSpec, Finished (establishes shared premaster → session keys for confidentiality); server responds ChangeCipherSpec, Finished. Confidentiality from the negotiated symmetric session key; authentication from the server certificate.

(b) The certificate is signed by a CA whose public key the client already trusts (root store). A MITM cannot forge a valid signature for the target domain's name, so its substituted certificate fails chain validation → connection aborts. (1.5) Against handshake replay: the fresh per-session random nonces (client/server randoms) feed key derivation, so a replayed old handshake produces keys the server won't accept / cannot decrypt matching data — plus sequence numbers/MACs bind messages to the current session. (1.5)


[
  {"claim":"Nyquist rate for B=3000, M=8 is 18000 bps","code":"import math\nresult = (2*3000*math.log2(8))==18000"},
  {"claim":"Shannon capacity B=3000 SNR=1000 rounds to 30 kbps","code":"import math\nC=3000*math.log2(1001)\nresult = round(C/1000)==30"},
  {"claim":"/22 usable hosts = 1022","code":"result = (2**(32-22)-2)==1022"},
  {"claim":"Dept A needs /23 (512>=502), Dept C needs /26 (64>=52)","code":"result = (2**9>=502) and (2**8>=202) and (2**6>=52) and (2**2>=4)"},
  {"claim":"Timeout ssthresh = floor(11/2) = 5","code":"result = (11//2)==5"}
]