Programming Assignment
: Distributed Asynchronous Distance Vector Routing

 


Overview

In this second (and final) programming assignment, you will be writing a ``distributed'' set of procedures that implement a distributed asynchronous distance vector routing for the network shown below.

The Basic Assignment

The routines you will write. For the basic part of the assignment, you are to write the following routines which will ``execute'' asynchronously within the emulated environment that we have written for this assignment.

For node 0, you will write the routines:

rtupdate0() is the "heart" of the distance vector algorithm. The values it receives in a routing packet from some other node j contain j's current shortest path costs (j's distance vector) to all other network nodes. rtupdate0() uses these received values to update its own "distance table." The distance table inside each node is the principal data structure used by the distance vector algorithm. You will find it convenient to declare the distance table as a 4-by-4 array of int's, where entry [i,j] in the distance table in node 0 is node 0's currently computed cost to node i via direct neighbor j; node 0 (re)computes its distable table entries for column j after receiving j's distance vector. If 0 is not directly connected to j, you can ignore this entry. We will use the convention that the integer value 999 is ``infinity.''

As specified by the distance vector algorithm we studied in class and in the text, if node 0's own minimum cost to another node changes as a result of the update, node 0 informs its directly connected neighbors of this change in minimum cost by sending them a routing packet. Recall that in the distance vector algorithm, only directly connected nodes will exchange routing packets. Thus nodes 1 and 2 will communicate with each other, but nodes 1 and 3 will node communicate with each other.

Similar routines are defined for nodes 1, 2 and 3. Thus, you will write 8 procedures in all: rtinit0(), rtinit1(), rtinit2(), rtinit3(),rtupdate0(), rtupdate1(), rtupdate2(), rtupdate3()

 

Software Interfaces

The procedures described above are the ones that you will write. We have written the following routines that can be called by your routines:

tolayer2(struct rtpkt pkt2send)
where rtpkt is the following structure, which is already declared for you. The procedure tolayer2() is defined in the file distance_vector.c
 
extern struct rtpkt {
  int sourceid;  /* id of node sending this pkt, 0, 1, 2, or 3 */
  int destid;    /* id of router to which pkt being sent
                    (must be an immediate neighbor) */
  int mincost[4];    /* min cost to node 0 ... 3 */
  };
Note that tolayer2() is passed a structure, not a pointer to a structure.
 
printdt0()
will pretty print the distance table for node 0. It is passed a pointer to a structure of type distance_table. printdt0() and the structure declaration for the node 0 distance table are declared in the file node0.c. Similar pretty-print routines are defined for you in the files node1.c, node2.c node3.c.
The simulated network environment

Your procedures rtinit0(), rtinit1(), rtinit2(), rtinit3() and rtupdate0(), rtupdate1(), rtupdate2(), rtupdate3() send routing packets (whose format is described above) into the medium. The medium will deliver packets in-order, and without loss to the specified destination. Only directly-connected nodes can communicate. The delay between is sender and receiver is variable (and unknown).

When you compile your procedures and my procedures together and run the resulting program, you will be asked to specify only one value regarding the simulated network environment:

A tracing value of 2 may be helpful to you in debugging your code. You should keep in mind that real implementers do not have underlying networks that provide such nice information about what is going to happen to their packets!

The Basic Assignment

You are to write the procedures rtinit0(), rtinit1(), rtinit2(), rtinit3() and rtupdate0(), rtupdate1(), rtupdate2(), rtupdate3() which together will implement a distributed, asynchronous computation of the distance tables for the topology and costs shown in the first figure above.

You should put your procedures for nodes 0 through 3 in files called node0.c, .... node3.c. You are NOT allowed to declare any global variables that are visible outside of a given C file (e.g., any global variables you define in node0.c. may only be accessed inside node0.c). This is to force you to abide by the coding conventions that you would have to adopt is you were really running the procedures in four distinct nodes. To compile your routines: cc distance_vector.c node0.c node1.c node2.c node3.Prototype versions of these files are here: node0.c, node1.c, node2.c, node3.c. You can pick up a copy of the file distance_vector.c here. You can pick up the node*.c and distance_vector.c routines that have been modified scpeficically for linux here.

This assignment can be completed on any machine supporting C, C++, or JAVA . It makes no use of UNIX features.

Please read the information posted on the class WWW site about what to hand with your assignment. For your sample output, your procedures should print out a message whenever your rtinit0(), rtinit1(), rtinit2(), rtinit3() or rtupdate0(), rtupdate1(), rtupdate2(), rtupdate3() procedures are called, giving the time (available via my global variable clocktime). For rtupdate0(), rtupdate1(), rtupdate2(), rtupdate3() you should print the identity of the sender of the routing packet that is being passed to your routine, whether or not the distance table is updated, the contents of the distance table (you can use my pretty-print routines), and a description of any messages sent to neighboring nodes as a result of any distance table updates.

The sample output should be an output listing with a TRACE value of 2. Highlight the final distance table produced in each node. Your program will run until there are no more routing packets in-transit in the network, at which point our emulator will terminate.

Note that a short design document is required.Your should program your each process to print an informative statement whenever it takes an action (e.g., sends or receives a message, detects termination of input, etc), so that you can see that your processes are working correctly (or not!). This also allows the TA to also determine from this output if your processes are working correctly. You should hand in screen shots (or file content, if your process is writing to a file) of these informative messages.

Extra Credit

You are to write two procedures, rtlinkhandler0(int linkid, int newcost) and rtlinkhandler1(int linkid, int newcost), which will be called if (and when) the cost of the link between 0 and 1 changes. These routines should be defined in the files node0.c and node1.c, respectively. The routines will be passed the name (id) of the neighboring node on the other side of the link whose cost has changed, and the new cost of the link. Note that when a link cost changes, these routines will have to update the distance table and may (or may not) have to send updated routing packets to neighboring nodes.

In order to complete the advanced part of the assignment, you will need to change the value of the constant LINKCHANGES (line 3 in distance_vector.c) to 1. FYI, the cost of the link will change from 1 to 20 at time 10000 and then change back to 1 at time 20000. Your routines will be invoked at these times.

We would again STRONGLY recommend that you first implement the basic assignment and then extend your code to implement the extra credit assignment. It will not be time wasted. (Believe me, I learned this the hard way!)

JAVA version of this assignment

The documentation above describes the project in detail.  Here we provide a link to the code needed to do the assignment in JAVA.  Make sure you understand the material above.

The JAVA code you'll need can be found here. Here are the individual files you'll need:

Entity.java,  Entity0.java,  Entity1.java,   Entity2.java,  Entity3.java,  NetworkSimulator.java,  Event.java, Packet.java,   EventList.java,  EventListImpl.java,  Project.java
You'll the write the constructors of Entity0.java, Entity1.java, Entity2.java, and Entity3.java  which are analogous to rtinit0(), rtinit1(), rtinit2() and rtinit3() in the C version. You will also need to write the update() methods for Entity0.java, Entity1.java, Entity2.java, and Entity3.java  which are analogous to  rtupdate0(), rtupdate1(), riupdate2() and rtupdate3() in the C version.

Note that the Java code will allow you to hang yourself by sending incorrect packets via the toLayer2()method of NetworkSimulator.  So please be extra careful there.

Q&A

Here is a list of questions received (and answers), check out the question-and-answer-page.