Skip to content

Cristinaaa12/Dataplane-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Dataplane-router

Dataplane – the part that implements the actual routing process, based on entries in the routing table.
This project implements a simple Layer 3 router capable of forwarding IPv4 packets, performing Longest Prefix Match (LPM), handling ARP (requests, replies, and caching), and generating ICMP messages.
It is based on the skeleton provided in Laboratory 4 of the Communication Protocols course.


1. Packet Forwarding Process

When the router receives an IPv4 packet, it follows these steps:

  • Destination check
    If the destination IP matches one of the router’s interfaces, the router does not forward the packet but replies with an ICMP Echo Reply.

  • Checksum verification
    The IP header checksum is recalculated. If it differs from the original, the packet is dropped (corrupted data).

  • TTL (Time To Live)

    • If TTL <= 1: the packet is dropped and an ICMP Time Exceeded message is sent.
    • Otherwise, TTL is decremented and the checksum is recalculated.
  • Route lookup (LPM)
    The function get_best_route(IP_node *root, uint32_t IP) searches the Trie to find the most specific route (Longest Prefix Match).
    If no valid route is found, an ICMP Destination Unreachable message is sent.

  • Next-hop MAC resolution
    After identifying the route, the router looks for the next hop’s MAC address in the ARP table before forwarding the packet.


2. Longest Prefix Match (LPM)

Implemented using a binary Trie structure:

  • Each node represents one bit of the IP address (0 or 1).
  • Each node can store a pointer to a valid routing table entry.
  • The insert_ip_route() function inserts a route bit by bit according to its mask.
  • The get_best_route() function traverses the Trie and returns the longest matching prefix for a given IP.

3. ARP Protocol

After determining the best route, the router must find the MAC address of the next hop:

  • If the MAC address is cached:
    The packet is immediately sent.

  • If the MAC address is missing:

    • The packet is stored in a waiting queue.
    • An ARP Request is sent for the next hop’s IP.
  • Upon receiving an ARP Reply:

    • The router updates the ARP table.
    • All queued packets waiting for that IP are transmitted.
    • Packets without a resolved address remain in the queue.

4. ICMP Protocol

Implemented in the send_icmp() function, which builds and sends ICMP messages in the following cases:

  • TTL expiredICMP Time Exceeded
  • No valid routeICMP Destination Unreachable
  • Packet addressed to the routerICMP Echo Reply

Steps to build and send an ICMP packet:

  1. Construct a new IP + ICMP packet based on the original.
  2. Set the source MAC to the router’s interface MAC.
  3. Set the destination MAC to the original sender’s MAC.
  4. Swap source/destination IPs.
  5. Set ICMP header fields (type, code, checksum).
  6. Recalculate the IP checksum.
  7. Send the packet on the same interface where it was received.

Assignment Source

This project was developed for the Communications Protocols course, based on the Dataplane router assignment:

https://pcom.pages.upb.ro/tema1/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors