A packet lab
The problem
Build a small Python program that models a network of hosts, switches and routers on paper: it plans the subnets, builds the forwarding tables, and follows one packet from a source host to a destination, printing the frame and TTL on every link.
Requirements
- Plan three subnets of different sizes inside one private network with VLSM and print each as network/prefix
- Give each router a forwarding table and choose the next hop by longest prefix match, with a default route
- Follow a packet hop by hop: the IP addresses stay the same, the MAC addresses change on each link and the TTL falls by 1 at each router
- Stop and report when the TTL reaches 0 or no route matches
Technologies
- Python 3
- The ipaddress module
- Dictionaries and lists
- Bit operations for masks
Step by step
- Choose a private network and the number of hosts for each subnet, then allocate the blocks, biggest first.
- Write the forwarding table of each router as (network, prefix, next hop) entries.
- Write a function that picks the next hop by longest prefix match.
- Send a packet through the network and print one line per link with the MAC addresses, IP addresses and TTL, then test a packet that has no route.
Expected result
A program that prints the full path of a packet through a small network, and reports clearly when it is dropped.
How it is evaluated
- Subnets do not overlap and each is large enough for its hosts
- The longest matching prefix is always chosen
- IP addresses never change on the path while MAC addresses do
- Dropped packets are explained
Ways to improve it
- Compute the tables automatically with Dijkstra on the topology
- Add a NAT router and show the rewritten source address
- Add a learning switch on each LAN segment