Addressing, transport, routing & error control
Six self-contained experiments, each a genuinely working simulator written in plain JavaScript — no libraries. Subnet masks are computed with real 32-bit arithmetic, the TCP state machine steps through actual segment exchanges, sliding windows animate frame and ACK timelines, Dijkstra and Bellman-Ford run on a graph you build, and CRC, checksum and Hamming codes do their true bitwise math. Pick an experiment on the left, then move through Aim, Theory, Procedure, the live Simulation, a graded Self-assessment, and References.
1 · IP addressing & subnetting
An IPv4 address is a 32-bit number, usually written as four dotted octets. A prefix length /p marks how many leading bits identify the network; the remaining 32 minus p bits identify the host inside it. The subnet mask is the 32-bit value with the first p bits set and the rest clear, for example /24 gives 255.255.255.0.
Given an address A and mask M, the network address is the bitwise AND A AND M, and the broadcast address is the network OR the inverted mask, network OR (NOT M). The usable hosts run from network plus one to broadcast minus one. The host count is a power of two minus the two reserved values.
network = address AND mask
broadcast = network OR (NOT mask)
usable hosts = 2 ^ (32 - p) - 2 (for p up to 30)
To carve a block into N subnets of equal size you borrow b host bits where 2^b is at least N, lengthening the prefix to p plus b. Each child subnet then spans 2^(32 - p - b) addresses, and successive networks step by that stride.
- Open the Simulation tab. Type an address such as 192.168.10.130 and a prefix such as 26.
- Press Compute. Read the mask, network, broadcast, first and last usable host, and the usable count. The 32-bit bar shows network bits in cyan and host bits in amber.
- Set Split into to 4 and press Subnet. The table lists the four child networks, their new prefix, range and broadcast.
- Try a /31 and a /32 and note the special host-count rules that apply.
- Enter a malformed address to see input validation reject it.
32-bit view --
Subnets
| # | Network | Range (usable) | Broadcast |
|---|
Input
- Fuller & Li — RFC 4632, Classless Inter-Domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan. IETF, 2006.
- Kurose & Ross — Computer Networking: A Top-Down Approach, Ch. 4 (The Network Layer: Data Plane). Pearson.
- Virtual Labs (IIT) — Computer Networks: IP Addressing & Subnetting, cse29-iiith.vlabs.ac.in.
2 · TCP three-way handshake
TCP is connection oriented: before any data flows, the two endpoints synchronise sequence numbers with a three-way handshake. The client sends a segment with the SYN flag and an initial sequence number x. The server replies with SYN and ACK, its own initial sequence y, and acknowledgement x + 1. The client completes the handshake with an ACK carrying acknowledgement y + 1. Each SYN consumes one sequence number, which is why the acknowledgements add one.
The handshake drives a finite state machine. A passive server moves CLOSED, LISTEN, then SYN-RCVD on the SYN, then ESTABLISHED on the final ACK. The active client moves CLOSED, SYN-SENT, then ESTABLISHED on the SYN-ACK. Teardown is symmetric: the closing side sends FIN and passes through FIN-WAIT-1, FIN-WAIT-2 and TIME-WAIT, while the peer goes CLOSE-WAIT then LAST-ACK.
server -- SYN,ACK seq=y ack=x+1 --> client
client -- ACK ack=y+1 --> server (both ESTABLISHED)
TIME-WAIT lasts twice the maximum segment lifetime so that any straggling segments drain before the same socket pair is reused.
- Open the Simulation. Set an initial client sequence and server sequence, or keep the random defaults.
- Press Connect. Watch the SYN packet travel to the server, the SYN-ACK return, and the final ACK complete the handshake. The two state lamps update at each step.
- Read the sequence and acknowledgement numbers printed on each segment and confirm the plus-one rule.
- Once ESTABLISHED, press Close to run the FIN / ACK teardown through TIME-WAIT.
- Use Step to advance one segment at a time, or Reset to return both ends to CLOSED.
Segment exchange
Control
- Postel — RFC 793, Transmission Control Protocol. IETF, 1981 (updated by RFC 9293, 2022).
- Stevens — TCP/IP Illustrated, Vol. 1, Ch. 18 (TCP Connection Establishment and Termination). Addison-Wesley.
- Tanenbaum & Wetherall — Computer Networks, 5th ed., Sec. 6.5. Pearson.
3 · Sliding window flow control
Pipelining lets a sender transmit a window of W frames before any acknowledgement returns, which keeps a long, fast link full. With sequence numbers drawn from a field of k bits there are 2^k numbers; the window must be small enough that old and new frames are never confused.
Go-Back-N uses a single timer for the oldest unacknowledged frame and cumulative ACKs. If a frame is lost the receiver discards every later frame as out of order, so on timeout the sender retransmits the lost frame and all frames after it. Its window may be up to 2^k - 1.
Selective Repeat ACKs each frame individually and buffers out-of-order arrivals, so only the genuinely lost frame is resent. To avoid ambiguity its window must not exceed 2^(k-1), half the sequence space.
SR sender window = receiver window ≤ 2^(k-1)
utilisation = W / (1 + 2a), with a = propagation / transmission
The simulation animates each frame leaving the sender, the matching ACK returning, and the timeout-driven retransmission, tallying how many frames cross the link in total.
- Open the Simulation. Choose Go-Back-N or Selective Repeat, set the window size and the number of frames to send.
- Set a loss probability so some frames are dropped, then press Run.
- Watch frames descend from sender to receiver; red frames are lost, and a timeout triggers retransmission.
- Compare the total transmissions for the two protocols on the same loss pattern: Go-Back-N resends a burst, Selective Repeat resends only one frame.
- Use Step to advance one event at a time and read the running window in the log.
Timeline Go-Back-N
Control
- Tanenbaum & Wetherall — Computer Networks, 5th ed., Sec. 3.4 (Sliding Window Protocols). Pearson.
- Kurose & Ross — Computer Networking: A Top-Down Approach, Sec. 3.4 (Principles of Reliable Data Transfer). Pearson.
- Virtual Labs (IIT) — Computer Networks: Sliding Window Protocol, cse29-iiith.vlabs.ac.in.
4 · Routing — Dijkstra & Bellman-Ford
Dijkstra's algorithm grows a set of finalised nodes outward from the source. At each step it picks the unfinalised node with the smallest tentative distance, finalises it, and relaxes its outgoing edges. Because edge weights are non-negative, once a node is finalised its distance is optimal. With a priority queue it runs in O((V + E) log V).
then dist[v] = dist[u] + w(u,v); prev[v] = u
Distance-vector routing (Bellman-Ford) is decentralised: every node knows only the cost to its direct neighbours and the distance vectors they advertise. On each iteration a node recomputes, for every destination t, the minimum over its neighbours n of cost(node, n) + dist[n][t]. After enough rounds the tables converge to the true shortest distances; a single synchronous iteration is shown here as one column of updates.
Link-state floods the whole topology and each router computes its own tree; distance-vector exchanges only summaries with neighbours but converges more slowly and can suffer the count-to-infinity problem.
- Open the Simulation. Click empty canvas to add a node; click one node then another to add an edge, typing its weight.
- Or press Sample graph for a ready six-node network.
- Choose the source node and press Run Dijkstra. Finalised nodes turn green, the shortest-path tree edges light up, and the distance to each node is labelled.
- Press One DV iteration to apply a single synchronous Bellman-Ford update; the table shows each node's estimate before and after.
- Use Clear to start a fresh topology.
Network add nodes
| Node | Dist from src | Via (prev) |
|---|
Control
| Dest | Old | New |
|---|
- Dijkstra — A note on two problems in connexion with graphs. Numerische Mathematik 1 (1959).
- Bellman / Ford — On a routing problem (1958); Network flow theory (1956).
- Kurose & Ross — Computer Networking: A Top-Down Approach, Sec. 5.2 (Routing Algorithms). Pearson.
5 · Error detection & correction
A cyclic redundancy check treats the message as a polynomial over GF(2) and divides it, with XOR-based long division, by a fixed generator polynomial. The r-bit remainder is appended so the transmitted frame is exactly divisible by the generator. The receiver divides again; a non-zero remainder means an error. CRC catches all burst errors shorter than the generator.
divide by generator with XOR (no carries)
CRC = remainder (r bits); frame = message followed by CRC
The Internet checksum adds the data in 16-bit words with end-around carry, then takes the one's complement. The receiver adds everything including the checksum; a correct frame sums to all ones. It is cheap but weaker than a CRC.
Hamming(7,4) protects 4 data bits with 3 parity bits placed at positions 1, 2 and 4. Each parity bit covers the positions whose index has a particular bit set. On reception the three parity checks form a syndrome; if non-zero, its value is the binary index of the single flipped bit, which is then corrected.
syndrome s = (c4 c2 c1) gives the position to flip
- Open the Simulation. In the CRC block enter a binary message and a generator, then press Compute CRC; read the long-division trace and the transmitted frame.
- In the Checksum block, enter words and press Checksum to see the wrapped sum and its complement.
- In the Hamming block, enter 4 data bits and press Encode to get the 7-bit codeword.
- Click any bit of the codeword to flip it, then press Decode. The syndrome names the error position and the lab corrects it.
- Verify that with no error the syndrome is zero.
CRC — polynomial division
Internet checksum (16-bit words)
Hamming(7,4) --
- Hamming — Error detecting and error correcting codes. Bell System Technical Journal 29 (1950).
- Peterson & Brown — Cyclic codes for error detection. Proc. IRE 49 (1961).
- Tanenbaum & Wetherall — Computer Networks, 5th ed., Sec. 3.2 (Error Detection and Correction). Pearson.
6 · CIDR aggregation helper
Route aggregation (supernetting) replaces several adjacent prefixes with one shorter prefix that covers them all, shrinking routing tables. Two prefixes of the same length p can merge into a single /(p-1) only when they are sibling blocks: they differ in exactly the p-th bit and the first p-1 bits are identical, so their common /(p-1) network address has a clear host part.
result = network(A, p-1) with prefix p-1
Repeatedly merging mergeable siblings, bottom-up, yields a minimal cover. For example 192.168.0.0/24 and 192.168.1.0/24 are siblings and collapse to 192.168.0.0/23.
Longest-prefix match is how a router forwards: among all prefixes that contain the destination, it picks the one with the longest mask, because that is the most specific route. Containment is tested by comparing the masked address against the prefix network.
- Open the Simulation. Type a list of prefixes, one per line, such as the four contiguous /24s already provided.
- Press Aggregate. The lab sorts, removes any prefix already covered, and repeatedly merges sibling blocks, printing the minimal set of supernets.
- Read the before / after counts to see how many routes were saved.
- Enter a target address and press Lookup; the lab reports the longest-prefix match among your original prefixes, or no route.
Aggregation result
| # | Supernet | Covers (addresses) |
|---|
Longest-prefix lookup
Input prefixes
- Fuller & Li — RFC 4632, Classless Inter-Domain Routing (CIDR). IETF, 2006.
- Rekhter et al. — RFC 1518 / 1519, An Architecture for IP Address Allocation with CIDR. IETF, 1993.
- Kurose & Ross — Computer Networking: A Top-Down Approach, Sec. 4.3 (The Internet Protocol). Pearson.