You are on page 1of 11

CS 542 PROJECT REPORT

DISTANCE VECTOR ROUTING ALGORITHM

Submitted To :

Submitted By :

Dr. Marius D. Soneru (Instructor) Rao, Sheshagiri, A20262604, Section 1 Chao Ma (TA) Anekere Narayan, Srinath, A20261802, Section 1 Atwal, Diwakar, A20269416, Section1 Kenchanna Parvathamma, Kushal Kumar, A20274773, Section 1

TABLE OF CONTENTS :
Table of Contents .... 2 1. Abstract ... 3 2. Introduction ....... 3 3. Design and Test Report . 4 3.1. 3.2. Method Description 5 Test Run ..6

4. Detailed Description of DV Algorithm Implementation .. 8 4.1. 4.2. 4.3. Router Configuration at startup ...8 Routing Table Updation ( by AlgorithmImplementer )8 Shortest Path Calculation .9

5. Procedure to Compile and Run . 10 5.1. Compilation and Execution .11

Distance Vector Routing Algorithm

Page 2

1. ABSTRACT :
In this project we simulate a Distance Vector Routing Algorithm for a given network. Using this simulation we measure the total cost associated with a path from source to destination router. The simulator determines cost by calculating the optimal path based on our Distance Vector Routing Algorithm implementation.

2. INTRODUCTION :
To calculate the cost, the Distance Vector Routing Algorithm determines the best path to the destination. The path with lowest cost is considered to be the best path among all the paths. Using the Distance Vector Routing Algorithm different costs are calculated by each router. These costs are then placed within the routers routing table and then these are used by the algorithm to calculate a best path from source to destination.

Distance Vector Routing Algorithm

Page 3

3. DESIGN AND TEST REPORT :


Every router has its own routing table, which is consulted before the network forwards a packet from source to destination. The implementation of Distance Vector routing algorithm comprises of the following entities: Router Routing table with routing entries. Events representing a change in the network. Distance Vector Algorithm implementation. The following classes are implemented for the simulation of DV algorithm. 1. RoutingTableEntry : This class represents an entry in a router table. This class contains the following information: destNetwork : This is the destination router. cost : Cost to the destination router. nextHop : Next hop router. 2. RecordEvent : This class represents an event that is sent from a router to its neighbor. record : RoutingTableEntry source : Source router that is sending the event. destination : Destination router that receives the event. 3. Router : This class represents a router. This class has methods to send and receive events. This class holds the following information : routerTable : Routing table at the router. name : Name of the router. eventQueue : Variable representing the queue which holds events from its neighbors. dvThread : Thread that updates routing table using DV algorithm. neighbors : List of neighbors.

Distance Vector Routing Algorithm

Page 4

4. AlgorithmImplementor : This class implements the Distance Vector Routing algorithm. This class is initiated as a separate Thread. router : Maintains reference to a router. recordQ : Queue holding records pushed by Router class. Router is considered to be in stable state if it is in PROCESSING STATE and there are no events to process for a maximum of three seconds. 5. driver : Main class that simulates the DV algorithm. routingTable : This represents the network wide routing table. numOfRouters : The number of routers in the network. MAX_ROUTERS : A constant that represents the maximum number of routers in the network. This is a tunable parameter which is currently set to 20. routersList : Contains the list of Routers in the network. observersMap : Holds a map of router as the key and list of neighbors as its value. This map gets used when the routing table is updated and the value is sent from one router to its neighbors.

3.1. METHOD DESCRIPTION :


readDefaultConfiguration() : Reads the input file, parses it and build the network routing table. InitaliseRouters() : Creates the Router entities. Set the routing table pertaining to the router. Register the router with its neighbors for event notifications. computeShortestPath() : This method calculates the shortest path between source and destination routers. The path to destination router is traced by starting from source routing table and traversing through all the intermediate hop routing tables.

Distance Vector Routing Algorithm

Page 5

3.2. TEST RUN :


1. LOAD FILE 2. COMPUTE FINAL ROUTING TABLE 3. OUTPUT OPTIMAL PATH AND MINIMUM COST 4. EXIT Select Option : 1 Enter name of input file : testfile.txt ############### Original routing table is as follows ################ R1 R2 R3 R4 R5 --------------------------------------------------0 2 5 1 -1 2 0 8 7 9 5 8 0 -1 4 1 7 -1 0 2 -1 9 4 2 0 Distance Vector Routing Algorithm. Please mention what you would like to do now ? 1. LOAD FILE 2. COMPUTE FINAL ROUTING TABLE 3. OUTPUT OPTIMAL PATH AND MINIMUM COST 4. EXIT Select Option : 2 ########## Final Routing Table Computed by DV Algorithm ########### R1 R2 R3 R4 R5 ----------------------------------------------------0 2 5 1 3 2 0 7 3 5 5 7 0 6 4 1 3 6 0 2 3 5 4 2 0
Distance Vector Routing Algorithm Page 6

Distance Vector Routing Algorithm. Please mention what you would like to do now ? 1. LOAD FILE 2. COMPUTE FINAL ROUTING TABLE 3. OUTPUT OPTIMAL PATH AND MINIMUM COST 4. EXIT Select Option : 3 Please input the source router number : 1 Please input the destination router number : 5 The shortest path from 1 to 5 is 1-4-5 Minimum Cost = 3 End of Distance Vector program .

Distance Vector Routing Algorithm

Page 7

5. Detailed Description of DV Algorithm Implementation


5.1. Router Configuration at Startup:During startup each router sends the routing table information to all its neighbors in the network. This is achieved using Router.init() method. This method calls Router.sendEventToNeighbors() on all the entries in the routing table.

5.2. Routing Table Updation ( by AlgorithmImplementer):In the run() method, AlgorithmImplementer waits for Record (RecordEvent) from its neighbor. For each record event pulled from eventQueue it calls the updateRoutingTable () to perform necessary updation of the routing table. The updateRoutingTable () method contains the DV algorithm logic for updating the routing table and sending updates to the neighboring routers.

The following is the pseudo code of the implementation : If (Event E of Record R = Update Event) { Search RoutingTable T for a destination matching the one in Record R If(TableEntry Entry is found for destination ) { If( netcost < Entry.cost or R.nexthop == Entry.nexthop) { Entry.cost = netcost Entry.nexthop = sourceRouter Update all neighbors with the modified routing table } // netcost = cost(sourcerouter to destination) + cost(currentRouter TO sourceRouter) } Else {
Distance Vector Routing Algorithm Page 8

Create new Routing TableEntry Entry Entry.cost = netcost Entry .destination = R.destination Entry.nexthop = sourceRouter } }

5.3. Shortest Path Calculation :Route updation of DV Algorithm updates the routing tables of all the routers with the minimum cost. The path to destination router is traced by starting from source routing table and traversing through all the intermediate hop routing tables. driver.computeShortestPath () is responsible for calculating the shortest path. The following is the pseudo code for calculating the shortest path . Given :- Source Router SR , Destination Router DR Router R = SR SPATH = SR.name // Shortest Path While Path to destination not Found { Search R for a TableEntry T such that T.destination equals DR If (T is null) { //No path found RETURN } Else if (TableEntry T found) { If(R.name equals SR.name) { // R is the source Router itself. Cost field contains the minimum cost MinCost = T.cost
Distance Vector Routing Algorithm Page 9

} If (T.nexthop equals -) { // Path found Path found = true SPATH = SPATH + T.DR.name } Else { //Traverse the routing table of the Router in NextHop // field to find the destination R = T.nexthop SPATH = SPATH + - + R.name } } }

SPATH AND MinCost contains the shortest path and the minimum cost respectively.

6. Procedure to compile and run :Operating System : Windows 7 IDE: Eclipse JDK : 1.5 and above Note :- Please ensure that you have jdk 1.5 installed in your system. The code uses some of the functionality which is present in Java 1.5 and above. It will not compile for jdk 1.4 and below.
Distance Vector Routing Algorithm Page 10

Extract the archive in a directory. The extracted directory shall contain the following folders and files: src testfile.txt - This is the same file as provided in the blackboard.

6.1. Compilation and Execution: Go to the src folder :- cd src/edu/iit/cs542/ Run the following command to compile the source code : On windows :- javac cs542Project\src\edu\iit\cs542\*.java Run the following command to run the main class : On Windows :- java cs542Project\src\edu\iit\cs542\driver The argument to the class can be changed for different input files. For example : To run the implementation with input file test_1.txt, run the following command : On Windows :- java cs542Project\src\edu\iit\cs542\driver

Distance Vector Routing Algorithm

Page 11

You might also like