Commit 62e61fd9 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Added comments

parent 7f85cb21
......@@ -7,7 +7,6 @@
*/
#include "lib.h"
#include "Exception.h"
#include "bitmath.h"
#include "LanRouter.h"
#include "coprocess.h"
......@@ -15,7 +14,6 @@
using namespace std;
LanRouter::LanRouter()
: routeCount(0)
{
}
......@@ -286,7 +284,6 @@ std::pair<size_t,size_t> LanRouter::chooseLan(size_t nodeNumber,
void LanRouter::print(ostream & output) const
{
routeCount = 0;
output << "%%" << endl;
for (size_t i = 0; i < routingTable.size(); ++i)
{
......@@ -322,7 +319,6 @@ void LanRouter::print(ostream & output) const
<< ipToString(m_levelPrefix[0][firstLan]
+ increment)
<< endl;
++routeCount;
}
}
......@@ -338,30 +334,6 @@ void LanRouter::print(ostream & output) const
}
}
void LanRouter::printStatistics(ostream & output) const
{
size_t hostCount = m_nodeToLevel[0].size();
output << "Total Number of Routes: " << routeCount << endl;
// calculate route length from every node to every interface.
// This should be equivalent to calculating a route length from every
// interface to every node.
int totalRouteLength = 0;
// for each node
for (size_t i = 0; i < hostCount; ++i)
{
if (isValidNode(i))
{
// for each LAN in the graph
for (size_t j = 0; j < m_levelMakeup.size(); ++j)
{
totalRouteLength += distanceToLan(i, j);
}
}
}
output << "Total Route Length: " << totalRouteLength << endl;
}
int LanRouter::distanceToLan(size_t sourceNode, size_t destLan) const
{
int routeLength = 0;
......
......@@ -6,6 +6,11 @@
* All rights reserved.
*/
// This routing strategy finds routes from every host to every LAN. Non-optimal
// routes are possible, but routes are stretched by at most one hop. If a few
// large LANs are used, this strategy is optimal. If many small LANs are used,
// this peforms worse time-wise than HostRouter.
#ifndef LAN_ROUTER_H_IP_ASSIGN_2
#define LAN_ROUTER_H_IP_ASSIGN_2
......@@ -20,7 +25,6 @@ public:
virtual void calculateRoutes(void);
virtual void print(std::ostream & output) const;
virtual void printStatistics(std::ostream & output) const;
private:
void calculateRoutesFrom(
size_t lanNumber,
......@@ -41,7 +45,6 @@ private:
// and the data is the first hop
// vector< vector< pair<FirstNode,FirstLan> > >
std::vector< std::vector< std::pair<size_t,size_t> > > routingTable;
mutable int routeCount;
};
#endif
......@@ -560,10 +560,6 @@ void NetRouter::print(std::ostream & output) const
}
}
void NetRouter::printStatistics(std::ostream & output) const
{
}
void NetRouter::addBorderConnection(size_t first, size_t second,
size_t firstHop, int weight)
{
......
......@@ -6,6 +6,14 @@
* All rights reserved.
*/
// This strategy takes advantage of all layers of hierarchy given to us by
// IP assignment. I use a method that is akin to dynamic programming. I
// Approximate a solution at the lowest level of the hierarchy, then use that
// approximation to get an approximate solution at the next higher level and
// so on until I reach the top.
// TODO: Change this so that disconnected graphs are accepted.
#ifndef NET_ROUTER_H_IP_ASSIGN_2
#define NET_ROUTER_H_IP_ASSIGN_2
......@@ -20,21 +28,51 @@ public:
virtual void calculateRoutes(void);
virtual void print(std::ostream & output) const;
virtual void printStatistics(std::ostream & output) const;
private:
struct RouteInfo
{
RouteInfo() : firstLan(0), firstNode(0), destination(0), distance(INT_MAX) {}
// The source in RouteInfo is always a host.
RouteInfo() : firstLan(0), firstNode(0),
destination(0), distance(INT_MAX) {}
// The first LAN on the path to the destination (If there is only one
// hop, this is the destination).
size_t firstLan;
// The first node on the path to the destination. If the destination
// is a LAN connected to this host, the firstNode is this host.
size_t firstNode;
// In most cases, this is a border LAN number. But see nodeToPartition
// for the exception.
size_t destination;
// Weight of the route to destination. node-lan routes include both
// the first LAN weight and the destination weight. This meshes with
// how lan-lan distances are stored. See below for details.
int distance;
};
// This is a map associating (source-host,destination-LAN) pairs with
// routing info.
// map<pair<node number,destination>,route>
typedef std::map<pair<size_t,size_t>,RouteInfo> NodeBorderMap;
private:
// Set up the data structures for the LAN level. This is the lowest
// level and represents a sort of base-case which is then used to
// calculate the routes on each higher level in turn.
void setup(void);
// Is this LAN a border LAN at a particular level? A LAN may be a border
// LAN at some level, but be an internal LAN at higher level. At the very
// bottom level, each LAN is its own partition and therefore every LAN is
// a border LAN.
bool isBorderLan(size_t level, size_t lan) const;
// We have a partition on a certain level. That partition is made
// up of sub-partitions on the level below. Each sub-partition has
// borders to other sub-partitions within the partition. This
// method calculates the paths between all-pairs of borders on a
// particular sub-partition.
void calculateBorderToBorderPaths(size_t level, size_t partition);
void calculateNodeToBorderPaths(size_t level, size_t partition);
void findNodeToBorder(NodeBorderMap::iterator searchPos,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment