Skip to content

Dragonflare921/router.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Router.py

Simple IPv4 router implementation in python 2.7
Intended for use with the mininet virtual network

IMPORTANT NOTE:

This project was written to spec for an assignment, and as such requires a specific configuration for mininet which is not included as part of this repository.
There are also some bugs preventing the 1.0 version from performing as expected, as noted at the end of this README.

Future versions will be fixed to work independently and a configuration script will be provided.

Contents:

  • README.md: This file
  • router.py: Main file. Run this to run the router
  • eth.py: Holds ethernet frame wrapper class used for easier representation of data
  • ip.py: Holds IP packet wrapper class used for easier representation of data
  • arp.py: Holds ARP packet wrapper class used for easier representation of data
  • util.py: Holds helper functions for utility

Packet reception:

Packets are recieved by a thread which is dedicated to listening to one interface. The packet is "unpacked" into a wrapper class which eases the manipulation of header fields.

Packet forwarding:

Packet forwarding works by decrementing the TTL and recalculating a checksum for the IP header. The interface on which the packet is forwarded is found via a longest prefix match. This longest prefix match is performed against the routing table file at /proc/net/route. A new ethernet header is constructed based on the hardware addresses.

ARP cache:

The ARP cache is implemented using a dictionary which is indexed on the IP. The ARP cache was intended to be dynamic but was unfinished and replaced with a static cache. Some logic is built for TTL expiration but there is no TTL value on the entries. The intended structure was going to be a dictionary of tuples which contained the MAC as well as the TTL. Expiration of the TTL would be managed by its own thread which decrements the TTL on each entry every second. When the TTL has reached 0, it is removed from the cache.

Usage:

To run the router software, scp the files over to the virtual machine for use.
Set up the mininet environment using createNet.py.
Open a terminal on the host r0, and run router.py.
To exit, send a keyboard interrupt to kill the threads gracefully.

BUGS:

While logic is built for forwarding, checksum calculation is correct, address lookup performs correctly, longest prefix matching works as intended, and the correct values are packed and unpacked in the wrappers, I am unable to get any response from another host when pinging, even though the packet is sent over the matched interface.

About

simple IPv4 router implementation in python 2.7

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages