In addition to the above-mentioned keyboardinterrupt


If you are referencing any outside sources you must cite them clearly.

In this assignment you will write a program that does simple packet routing. Your program will take three command-line arguments:

Then your program will:

  • read its routing table from the specified file

? The file will consist of multiple lines with the format:

The subnet and netmask will be in IPv4 dotted decimal. The nexthop value will be a port number, not an address. The three values will be separated by spaces. For example:

112.23.56.0 255.255.255.0 45334

  • listen on the specified UDP port
  • accept simplified IP packets in the format:

,,,,

Example:

23921,192.168.0.1,192.168.45.102,64,testing

For each received packet, your program will:

  • decrement the TTL field of the packet

? if it reaches zero, the packet will be dropped and the "expired packets" counter will be updated

  • figure out which of the entries in the routing table (if any) match the packet

? it will do this by checking whether the destination address in the packet matches the subnet entry for a particular route, after being ANDed with the netmask of that entry in the routing table.

? it will scan the routing table sequentially and will use the first route that matches (you can assume the table is sorted longest-prefix first)

? if there is no matching entry, the packet will be dropped and the "unroutable packets" counter will be updated

  • if the value of the nexthop field for the entry is 0:

? print the following:

Delivering direct: packet ID=, dest=

? update the "delivered direct" counter

? not process the packet any further

  • if the value of the nexthop field for the entry is a valid port number

? forward the IP packet, as a UDP packet to address 127.0.0.1 and UDP port equal to the nexthop value

? update the counter corresponding to the packets forwarded to that router

Note: whenever a packet is dropped, it should not be processed any further. Statistics file:

After every 100 processed packets you will update the statistics file (the path to which was given as a

command-line argument). The format of the file will be:
expired packets:
unroutable packets:
delivered direct:
router :
router :
...

And so on, for each router. is the port number corresponding to this router.

You will also update the statistics file before the program exits, when the user interrupts with Ctrl+C.

To do this you will need to handle the KeyboardInterrupt exception.

Error handling:

In addition to the above-mentioned  KeyboardInterrupt (used to terminate the program), you will need to handle any I/O-related exceptions.

If the routing table file does not exist or cannot be read, your program should print an error message and exit. If the statistics file does not exist and it is unable to create it, it should print an error message and exit. If, later, an error occurs while trying to update the statistics file, it should print an error message and it should continue running (i.e. it should not exit in this case).

If your program is unable to listen on the specified UDP port it should print an error message and exit.

If an error occurs while receiving an incoming packet, or while trying to forward the packet, it should print an error message and it should continue running (i.e. it should not exit in this case).

Solution Preview :

Prepared by a verified Expert
Computer Networking: In addition to the above-mentioned keyboardinterrupt
Reference No:- TGS0653873

Now Priced at $70 (50% Discount)

Recommended (91%)

Rated (4.3/5)