A complete implementation in C of an IPv4 Router Data Plane, simulating the essential packet-processing logic of a real network router. This project handles Ethernet frames, IPv4 forwarding, ARP resolution, and ICMP message generation, with a strong focus on performance and correctness.
At its core, the routing process is optimized using a Trie (Prefix Tree) to efficiently perform Longest Prefix Match (LPM) lookups.
This router processes network traffic by:
- Receiving raw Ethernet frames
- Parsing and validating IPv4 packets
- Determining optimal routes
- Resolving MAC addresses dynamically
- Generating ICMP responses when required
The system closely mimics how real routers operate at the data plane level.
-
Validates IPv4 headers:
- Checksum verification
- TTL decrement
-
Performs Longest Prefix Match (LPM) on the routing table
-
Determines next-hop IP address
-
Updates Ethernet headers:
- Source MAC
- Destination MAC
-
Forwards packets to the appropriate interface
-
Maintains a dynamic ARP cache
-
If MAC address is unknown:
- Sends
ARP Request (ARP_REQ) - Queues the packet
- Sends
-
On receiving
ARP Reply (ARP_REP):- Updates ARP cache
- Dequeues and forwards pending packets
-
Responds to ARP requests targeting router interfaces
Handles key ICMP message types:
-
Echo Reply (
ICMP_ECHO_REP)- Responds to ping requests directed at router interfaces
-
Time Exceeded (
ICMP_TIME_EXC)- Triggered when TTL reaches 0 or 1
-
Destination Unreachable (
ICMP_DEST_UNREACH)- Sent when no valid route exists
-
Routing tables (
rtable0.txt,rtable1.txt) are parsed at startup -
Stored in a Trie (Prefix Tree) structure
-
Enables:
- Extremely fast Longest Prefix Match
- Lookup complexity ≈ O(1) relative to fixed 32-bit IPv4 length
✔ Eliminates inefficient linear searches ✔ Scales efficiently with large routing tables
.
├── router.c # Main packet processing loop
├── include/ # Header files (Ethernet, IP, ARP, ICMP)
├── lib/ # Utility libraries and data structures
├── rtable0.txt # Routing table (instance 0)
├── rtable1.txt # Routing table (instance 1)
├── checker/ # Automated testing environment (Mininet)
└── README.md # Project documentation
makeThe project uses a virtual network environment to simulate hosts and router interfaces.
-
The checker script:
-
Builds network topology (using Mininet)
-
Runs tests like:
pingtraceroute- ARP scenarios
- Packet forwarding validation
-
sudo ./checker/checker.shThe checker/ directory provides:
- Automated validation scripts
- Virtual network topologies
- Traffic simulation scenarios
✔ Ensures correctness of:
- Routing logic
- ARP handling
- ICMP responses
- High-performance packet forwarding
- Accurate simulation of router data plane behavior
- Efficient routing using Trie-based LPM
- Modular and clean C implementation
- Realistic networking environment testing
- Support for dynamic routing protocols (e.g., OSPF, RIP)
- IPv6 compatibility
- Advanced queue management (QoS)
- Multithreaded packet processing
- Enhanced ARP cache policies (timeouts, eviction)
This project is open-source and available under the MIT License.
Developed as a systems programming project focused on:
- Computer Networks
- Low-level packet processing
- Data structures for performance optimization
⭐ If you found this project useful, consider giving it a star!