Commit 4d7f2e92 authored by Jonathon Duerig's avatar Jonathon Duerig

Modified routecalc, adding a command line option to dump all route lengths to...

Modified routecalc, adding a command line option to dump all route lengths to a file for statistical analysis.
parent f67ad04b
......@@ -11,5 +11,9 @@ assumed that the METIS library files are kept in
'/home/duerig/metis/metis-4.0/'. If this is not the case, alter the shell
variables at the top.
To use 'compile.sh', make sure that there are 'ipassign/bin' and
'ipassign/tmp' directories to hold the various files created.
Until integration, this program should always be run from the 'ipassign'
directory and should be located (along with routecalc) in 'bin/ipassign'.
......@@ -2,6 +2,7 @@
export EXTRA_LIB_PATH=/home/duerig/metis/metis-4.0
export EXTRA_INCLUDE_PATH=/home/duerig/metis/metis-4.0/Lib/
g++ -O3 -c -o tmp/ipassign.o -I${EXTRA_INCLUDE_PATH} src/ipassign.cc
g++ -O3 -c -o tmp/bitmath.o -I${EXTRA_INCLUDE_PATH} src/bitmath.cc
g++ -O3 -c -o tmp/Assigner.o -I${EXTRA_INCLUDE_PATH} src/Assigner.cc
......@@ -21,6 +22,5 @@ g++ -O3 -o bin/routecalc src/routecalc.cc
g++ -o bin/inet2graph src/inet2graph.cc -lm
g++ -o bin/brite2graph src/brite2graph.cc -lm
g++ -o bin/top2graph src/top2graph.cc -lm
......@@ -6,8 +6,17 @@
* All rights reserved.
*/
// Checks that a set of routes is valid and provides statistics on how
// good the routes are.
// If the arguments are '-l <filename>' then the lengths from each node
// to each interface will be sent to <filename> in turn. The order of the
// output is first by node number and second by the order the interface is
// listed in the .route file.
#include "lib.h"
#include "Exception.h"
#include <fstream>
using namespace std;
......@@ -77,6 +86,24 @@ public:
}
};
class FailedFileOpenException : public StringException
{
public:
explicit FailedFileOpenException(string const & file)
: StringException("Could not open file: " + file)
{
}
};
class LogException : public StringException
{
public:
explicit LogException(std::exception const & other)
: StringException(string("Log Error: ") + other.what())
{
}
};
class Route
{
public:
......@@ -216,6 +243,14 @@ private:
bool valid;
};
namespace arg
{
bool shouldLog = false;
ofstream log;
}
void parseArgs(int argc, char * argv[]);
// take the ip assignment portion of the output and use that to set up
// ip addresses and adjascency for the nodes
void setupNodes(vector<Node> & nodes, map<IPAddress,size_t> & interfaces);
......@@ -250,11 +285,12 @@ void displayResults(size_t routeCount, size_t routeLength);
// cycles in a route.
void clearVisited(vector<Node> & nodes);
int main()
int main(int argc, char * argv[])
{
int result = 0;
try
{
parseArgs(argc, argv);
vector<Node> nodes;
map<IPAddress,size_t> interfaces;
setupNodes(nodes, interfaces);
......@@ -270,6 +306,22 @@ int main()
return result;
}
void parseArgs(int argc, char * argv[])
{
if (argc == 3)
{
if (argv[1] == string("-l") && argv[2] != string(""))
{
arg::shouldLog = true;
arg::log.open(argv[2], ios::out | ios::trunc);
if (!(arg::log))
{
throw LogException(FailedFileOpenException(argv[2]));
}
}
}
}
void setupNodes(vector<Node> & nodes, map<IPAddress,size_t> & interfaces)
{
string bufferString;
......@@ -412,6 +464,10 @@ int64 followRoute(size_t source, IPAddress destination, size_t destNode,
error.addToMessage(currentBuffer.str());
throw error;
}
if (arg::shouldLog)
{
arg::log << result << endl;
}
return result;
}
......
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