Skip to content

Horiqq7/Ipv4-Router

Repository files navigation

🌐 IPv4 Router Data Plane Implementation

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.


🚀 Overview

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.


⚙️ Core Functionalities

📦 IPv4 Packet Forwarding

  • 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


🔁 ARP (Address Resolution Protocol)

  • Maintains a dynamic ARP cache

  • If MAC address is unknown:

    • Sends ARP Request (ARP_REQ)
    • Queues the packet
  • On receiving ARP Reply (ARP_REP):

    • Updates ARP cache
    • Dequeues and forwards pending packets
  • Responds to ARP requests targeting router interfaces


📡 ICMP (Internet Control Message Protocol)

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

🌲 Optimized Routing Table (Trie)

  • 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


📁 Project Structure

.
├── 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

💻 Build & Run

🔧 1. Compilation

make

🧪 2. Testing the Router

The project uses a virtual network environment to simulate hosts and router interfaces.

  • The checker script:

    • Builds network topology (using Mininet)

    • Runs tests like:

      • ping
      • traceroute
      • ARP scenarios
      • Packet forwarding validation
sudo ./checker/checker.sh

🧪 Testing Environment

The checker/ directory provides:

  • Automated validation scripts
  • Virtual network topologies
  • Traffic simulation scenarios

✔ Ensures correctness of:

  • Routing logic
  • ARP handling
  • ICMP responses

🎯 Design Goals

  • 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

📌 Future Improvements

  • Support for dynamic routing protocols (e.g., OSPF, RIP)
  • IPv6 compatibility
  • Advanced queue management (QoS)
  • Multithreaded packet processing
  • Enhanced ARP cache policies (timeouts, eviction)

📜 License

This project is open-source and available under the MIT License.


👨‍💻 Author

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!

About

A C implementation of an IPv4 Router Data Plane, featuring ARP resolution, ICMP generation, and a highly optimized Trie-based routing table for Longest Prefix Match.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors