← All virtual labs
Computer Networks · Virtual lab

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

Compute the network, broadcast, mask, host range and usable count — then split into N subnets
To take an IPv4 address with a prefix length, compute its subnet mask, network address, broadcast address, usable host range and host count using exact 32-bit arithmetic, and then divide the block into N equal subnets while reading off each new prefix.

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.

mask = (0xFFFFFFFF left-shift (32 - p)) AND 0xFFFFFFFF
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.

  1. Open the Simulation tab. Type an address such as 192.168.10.130 and a prefix such as 26.
  2. 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.
  3. Set Split into to 4 and press Subnet. The table lists the four child networks, their new prefix, range and broadcast.
  4. Try a /31 and a /32 and note the special host-count rules that apply.
  5. Enter a malformed address to see input validation reject it.

32-bit view --

enter an address and compute
all results from exact 32-bit integer AND / OR / shift

Subnets

#NetworkRange (usable)Broadcast

Input

/26
Usable hosts
--
Block size
--
New prefix
--
Per subnet
--
Tip: a host part of all zeros is the network; all ones is the broadcast. Neither is assignable, hence the minus two.
  • 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

Animate SYN / SYN-ACK / ACK and the connection state machine through to FIN teardown
To trace the establishment and teardown of a TCP connection: to watch the client and server exchange SYN, SYN-ACK and ACK with real sequence and acknowledgement numbers, and to follow each endpoint through its connection states from CLOSED to ESTABLISHED and back through the FIN 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.

client -- SYN seq=x --> server  (state SYN-SENT / SYN-RCVD)
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.

  1. Open the Simulation. Set an initial client sequence and server sequence, or keep the random defaults.
  2. 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.
  3. Read the sequence and acknowledgement numbers printed on each segment and confirm the plus-one rule.
  4. Once ESTABLISHED, press Close to run the FIN / ACK teardown through TIME-WAIT.
  5. Use Step to advance one segment at a time, or Reset to return both ends to CLOSED.

Segment exchange

Client state: CLOSED  ·  Server state: CLOSED
sequence numbers advance by SYN/FIN = 1 octet each

Control

5x
Phase
idle
Segments
0
  • 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

Go-Back-N and Selective Repeat — animate frames, ACKs, losses and timeouts under a window
To compare the two pipelined ARQ protocols, Go-Back-N and Selective Repeat, by sending a stream of numbered frames under a fixed sender window, injecting random losses, and observing how each protocol recovers from a lost frame and how many retransmissions it costs.

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.

GBN  sender window ≤ 2^k - 1, receiver window = 1
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.

  1. Open the Simulation. Choose Go-Back-N or Selective Repeat, set the window size and the number of frames to send.
  2. Set a loss probability so some frames are dropped, then press Run.
  3. Watch frames descend from sender to receiver; red frames are lost, and a timeout triggers retransmission.
  4. 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.
  5. Use Step to advance one event at a time and read the running window in the log.

Timeline Go-Back-N

Window: --  ·  green = delivered, red = lost, amber = retransmit
GBN resends N frames on a loss · SR resends one

Control

Go-Back-N
Selective
4
10
0.25
5x
Delivered
0
Transmissions
0
Retransmits
0
Efficiency
--
  • 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

Build a weighted graph, run Dijkstra for the shortest-path tree, then a Distance-Vector iteration table
To compute least-cost routes through a network: to run Dijkstra's link-state algorithm from a source node on a graph you build interactively, reading off the shortest-path tree, and then to step the distance-vector (Bellman-Ford) update one iteration at a time and watch the distance table converge.

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

relax(u, v): if dist[u] + w(u,v) < dist[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.

D[x][t] = min over neighbours n of ( c(x, n) + D[n][t] )

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.

  1. Open the Simulation. Click empty canvas to add a node; click one node then another to add an edge, typing its weight.
  2. Or press Sample graph for a ready six-node network.
  3. 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.
  4. Press One DV iteration to apply a single synchronous Bellman-Ford update; the table shows each node's estimate before and after.
  5. Use Clear to start a fresh topology.

Network add nodes

Click empty space to add a node · click two nodes to add a weighted edge · right-click a node to set it as source
NodeDist from srcVia (prev)

Control

default
Nodes
0
Edges
0
Distance-vector table (one synchronous round):
DestOldNew
  • 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

CRC polynomial division, the Internet checksum, and Hamming(7,4) single-bit correction
To compute and verify error-control codes by hand-rolled bit arithmetic: to generate a CRC remainder by binary polynomial division, to form the one's-complement Internet checksum, and to encode four data bits into a Hamming(7,4) codeword, then inject a single-bit error and watch the syndrome locate and correct it.

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.

augment: shift message left by r zero bits
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.

p1 covers bits 1,3,5,7  p2 covers 2,3,6,7  p4 covers 4,5,6,7
syndrome s = (c4 c2 c1) gives the position to flip
  1. 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.
  2. In the Checksum block, enter words and press Checksum to see the wrapped sum and its complement.
  3. In the Hamming block, enter 4 data bits and press Encode to get the 7-bit codeword.
  4. Click any bit of the codeword to flip it, then press Decode. The syndrome names the error position and the lab corrects it.
  5. Verify that with no error the syndrome is zero.

CRC — polynomial division

 

Internet checksum (16-bit words)

Hamming(7,4) --

Codeword (click a bit to flip / inject error):
Syndrome
--
Error pos
--
Hamming distance 3: corrects 1 error, detects 2
  • 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

Summarise a list of prefixes into the smallest covering supernets and check containment
To aggregate a list of contiguous IPv4 prefixes into the fewest possible supernets using route summarisation, and to confirm whether a target address falls inside any advertised block by longest-prefix matching.

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.

mergeable(A/p, B/p): network(A, p-1) == network(B, p-1)
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.

contains(prefix P/p, addr A): (A AND mask(p)) == network(P, p)
  1. Open the Simulation. Type a list of prefixes, one per line, such as the four contiguous /24s already provided.
  2. Press Aggregate. The lab sorts, removes any prefix already covered, and repeatedly merges sibling blocks, printing the minimal set of supernets.
  3. Read the before / after counts to see how many routes were saved.
  4. Enter a target address and press Lookup; the lab reports the longest-prefix match among your original prefixes, or no route.

Aggregation result

#SupernetCovers (addresses)
merges only true sibling blocks — no over-aggregation

Longest-prefix lookup

Input prefixes

Input routes
0
After merge
0
Note: only adjacent, equal-size, correctly aligned blocks merge. Three /24s cannot become one /22 without a fourth.
  • 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.