Assignment 4 Computer Science 441 Due: 23:55, Friday April 5, 2019 Instructor: Majid Ghaderi
Assignment 4 Computer Science 441 Due: 23:55, Friday April 5, 2019 Instructor: Majid Ghaderi
Assignment 4 Computer Science 441 Due: 23:55, Friday April 5, 2019 Instructor: Majid Ghaderi
1 Objective
The purpose of this assignment is to implement a distributed asynchronous distance vector
routing algorithm. By completing this assignment, you will learn about distributed computing
in a realistic network environment. You will also learn about broadcast in IP networks using
UDP sockets.
2 Specification
2.1 Overview
In this assignment, you will implement a router program that runs a modified version of the dis-
tance vector routing algorithm discussed in class. Several instances of your router program will
be started on different (virtual) hosts that communicate with each other using UDP broadcast.
To have a controlled environment for this assignment, Mininet is used to create a virtual net-
work. Your router program is then run on virtual nodes created in Mininet. Mininet creates a
virtual network on a single machine using real Linux kernel and software switches. A Mininet
network behaves very much like a real network and can be configured and controlled using
common networking tools, e.g., ifconfig. For this assignment, you do not really need to know
anything about Mininet. All required scripts to create and configure a network are given to you.
However, if you are interested to learn Mininet for your own curiosity, checkout the following
link: http://mininet.org/walkthrough/.
3 Implementation
The high-level structure of the router program is described in Program 1. Every router has
a unique name that is assigned to it when the router is started. Initially, each router knows
only about itself, but over time learns about other routers in the network as it receives update
messages from its neighboring routers.
In your implementation, you need to define two data structures, as described below:
1. DV Table: Each router has a distance vector (DV). In addition to its own DV, each router
has a copy of the DV of each one of its neighbors. These DVs are learned over time. The
collection of DVs at a router is referred to as the DV table throughput the assignment.
2. Forwarding Table: For each destination that is reachable from a router, the router needs to
2
Assignment 4 CPSC 441
keep track of the neighboring router that is on the least-cost path to that destination. The
structure that keeps this information is referred to as the forwarding table throughout the
assignment.
The DV and forwarding tables at a router are collectively referred to as the routing tables.
Program 1 Router
1: setup a UDP broadcast socket
2: initialize local DV
3: broadcast initial DV
4: while (shutdown == false) do
5: wait to receive a DV update
6: process the received DV
7: if local DV changes then broadcast DV
8: end while
9: clean up and exit
A single UDP broadcast socket is used to broadcast DV update messages over all network in-
terfaces of the host running the router instance. For this purpose, the router should open an
unbounded UDP socket with the specified port (given as input when the router starts). An un-
bounded UDP port is not attached to any specific source or destination IP address. This way,
the socket can be used to receive broadcast messages over all network interfaces. Additionally,
the same socket can be used to send broadcast messages over every network interface. The
following code shows how to open a broadcast UDP socket:
To broadcast a message, the router should broadcast the message on all its network interfaces,
as described in Program 2, where port is the common port number used by all router instances
for exchanging DV messages.
3.3 DV Update
Every router runs the Distance-Vector algorithm discussed in class (based on the Bellman-Ford
equation) to update its local DV in response to an update message from another router. To
run the DV algorithm, a router needs to know its own DV and DVs of its neighbors. This
information is recorded in the DV table of the router. Also, each router needs to know the cost
3
Assignment 4 CPSC 441
of links that connect it directly to its neighbors. In this assignment, we assume that every link
has the link cost of 1. After updating its local DV, if the local DV changes, then the router
has to broadcast the updated DV to its neighbors. While running the DV algorithm to update
local DV, the router should also update its forwarding table if necessary. If a destination that
was reachable previously becomes unreachable as the result of a DV update, that destination
should be removed from the forwarding table. On the other hand, if a new destination becomes
reachable, then that destination should be added to the forwarding table.
Every time a router receives an update message from another router X, it has to check if X is a
new router that was unknown before:
1. If the answer is yes, the receiving router has to: (i) add X’s DV to its DV table, (ii) check all
destinations in X’s DV and add them to its own DV and forwarding table as new destina-
tions, and (iii) update its local DV.
2. If the answer is no, the receiving router has to: (i) update its local copy of X’s DV with
the new information received in the message, (ii) if there are any new destinations in X’s
DV, add them to its own DV and forwarding table as new destinations, and (iii) update its
local DV.
A router should be able to detect and purge inactive neighbors from its routing tables. Essen-
tially, every DV from a neighboring router in the local DV table has a time-to-live. If the router
does not hear from a neighbor after the time-to-live interval, that neighbor is assumed to be
disconnected from the router. In this case, the router removes the corresponding neighbor’s DV
from its DV table and updates its DV following the normal update process. To detect inactive
neighbors, the router sets a timer event for each known neighbor. If the timer expires, the neigh-
bor is determined to be inactive. If a DV update is received from the neighbor before the timer
expires, the timer is restarted and the local DV is updated. Program 3 describes the procedure
for detecting inactive neighbors. This procedure is run every time a DV update is received.
4
Assignment 4 CPSC 441
Program 3 Inactivity
• DV update message received from neighbor X
1: if (X is a new neighbor) then
2: add DV to local routing tables
3: start an inactivity timer for X
4: update DV
5: else
6: restart the inactivity timer for X
7: update DV
8: end if
• Inactivity timer for neighbor X expires
1: remove X’s DV from local DV table
2: update local DV
3: remove all unreachable destinations from DV and forwarding tables
The time-out interval for the inactivity timer is specified as an input parameter.
After some iterations of the DV algorithm, the least-cost paths will be all determined, and con-
sequently there will be no further DV exchanges between routers. As such, a router may be
removed from its neighbors DVs thinking that it is inactive. To prevent this situation, each
router periodically sends its DV to its neighbors even if it has not been updated. These update
messages are referred to as keepalive messages and should be treated exactly as regular DV up-
date messages by the receiving routers. The keepalive procedure is described in Program 4. This
procedure is run every time a DV update is received.
Program 4 Keepalive
• DV update message received from neighbor X
1: update local DV
2: if (local DV changes) then
3: broadcast local DV
4: restart the keepalive timer
5: end if
• Keepalive timer expires
1: broadcast local DV
2: restart the keepalive timer
5
Assignment 4 CPSC 441
Notice that the timer is not modified if the local DV does not change. The keepalive timer is
started after the router sends its first initial DV message. The time-out interval for the keepalive
timer is specified as an input parameter.
4 Software Interfaces
The abstract class BasicRouter is provided to you. You are being asked to develop a Java
class named Router that extends BasicRouter. There are several abstract methods in
BasicRouter that you need to implement in Router. A brief description of these methods
is provided below. For detailed information about these methods, refer to the Javadoc
documentation provided in the source file BasicRouter.java.
• void run()
The method to start the router. This is the main method that implements Program 1.
• void shutdown()
To signal the router instance to terminate.
6
Assignment 4 CPSC 441
r0 eth1 r6 eth0
r5
eth1
10.0.6
network interface.
To test your router, you have to create a network in Mininet. A network in Mininet consists of a
number of nodes and the links that interconnect the nodes. A Python script is provided to you
to show you how you can create arbitrary network topologies in Mininet. Specifically, the script
network.py creates a network with the topology presented in Figure 1.
Feel free to modify the script as you wish. The script is self-explanatory and has proper code
documentation. Given that routers can dynamically discover/remove neighbors, you do not
need to start an instance of your router on every node. You can start router instances only
on a subset of nodes, and your routers should be able to find each other by running the DV
algorithm. As an example, in Figure 1, one can start routers only on r0, r1, and r2 in order to
have a network of three interconnected routers. You can even start and shutdown a router while
other routers are working, and the result should be reflected in the routing tables of all routers.
A drive class named RouterDriver is provided on D2L to demonstrate how we are going to
run your code. In addition to the source file, a README is also provided, which explains how
to use the driver class. Once you are in Mininet, start an xterm on each node that you want
to start a router on. After the xterm launches, you have a fully functional terminal that allows
you to start your router using the provided driver class like any normal Java program.
Your implementation should include exception handling code to deal with all checked excep-
tions in your program. Print exception messages to the standard system output.
7
Assignment 4 CPSC 441
at the top of BasicRouter. This statement indicates that your code should be organized as a
Java package with name cpsc441.a4.router.
Restrictions
• You are not allowed to modify classes BasicRouter and RouterDriver. Your changes
will be overwritten when marking your submission. However, you can (and should) im-
plement additional methods and classes as needed in your implementation.
• Your program can use whatever data structures are needed to implement the internal op-
eration of a router. However, the get methods getDvTable() and getFwTable() must
return these structures as Map objects as described earlier.
• You have to write your own code for sending and receiving UDP packets. Ask the in-
structor if you are in doubt about any specific Java classes that you want to use in your
program.