Your assignment is to simulate a routing protocol and routing table. Your program will take as input a configuration file specifying the interfaces and route entries. Then it will prompt the user for input. The user will input a destination IP address. The program must then determine the interface that the packet must be sent out on and display that result to the user. A sample configuration file would be a series of 'interface' and 'route' lines. The interface line specifies a name and an IP address of an interface on the router. A route lines specifies the interface the route came in on, the IP address and netmask of the route, and its metric. A route entry might be marked as default. In that case, if no other route macthes, then that interface is used. A sample configuration file is below.
interface eth0 192.168.0.1
interface eth1 192.168.1.1
route eth0 192.168.2.0 255.255.255.0 1
route eth0 192.168.3.0 255.255.255.0 3
route eth1 192.168.2.0 255.255.255.0 2
route eth1 192.168.4.0 255.255.255.240 4
route eth0 default
An invocation of the program should take as its argument
a configuration file name. An example run using the above
configuration file is below and asking to route for 157.182.194.39
and 192.168.2.10.
$ router routes.config
Router reading configuration file "routes.config".
Read configuration file.
Destination to route to: 157.182.194.39
Route from interface 192.168.0.1 (eth0) by default route
Destination to route to: 192.168.2.10
Route from interface 192.168.0.1 (eth0) by 192.168.2.0 route (metric 1)
Destination to route to: quit
$
For extra credit, make this dynamic and take its configuration from the network (+6%). The program must be configured from the configuration file, but only for 'interface' lines and and a single default 'route' line. The other route entries are sent to the program dynamically via a set of UDP ports and RIP format. One UDP port per interface given in the configuration file. Each route has a lifetime of 2 minutes and is deleted if no update is seen within that period of time.