Commit 66015051 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Added headers and some comments to ipassign sources

parent f06d9a59
// Exception.h
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// Exception.h defines all of the possible things that might go wrong with
// the program. Each one has a string associated with it that is printed
// to the user as output.
// Note that as of now, the strings are completely determined by the
// creator of an Exception object. I ought to go back and change this
// so that each Exception contributes its exception name to the beginning
// of the string and the Exception creator just provides the incidental
// information.
#ifndef EXCEPTION_H_IP_ASSIGN_1
#define EXCEPTION_H_IP_ASSIGN_1
......
// Graph.cc
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// This is the implementation for a Graph object. A Graph object is used
// to encapsulate the manipulations needed to assign IP addresses.
#include "lib.h"
#include "Exception.h"
#include "Graph.h"
......@@ -58,11 +67,14 @@ int Graph::getLanCount(void) const
void Graph::convert(std::vector<int> & indexes, std::vector<int> & neighbors,
std::vector<int> & weights) const
{
// ensure that there is no garbage in the output references.
indexes.clear();
neighbors.clear();
weights.clear();
indexes.reserve(m_nodes.size() + 1);
// fill them up with the graph.
// See the METIS manual, section [5.1 Graph Data Structure], page 18
list<Lan>::const_iterator lanPos = m_lanList.begin();
for ( ; lanPos != m_lanList.end(); ++lanPos)
{
......@@ -114,6 +126,9 @@ void Graph::reset(istream & input)
void Graph::partition(std::vector<int> & partitions)
{
// Each number in the partitions vector is the partition that
// the associated Lan in m_lanList belongs too.
// Let each Lan know where it belongs.
list<Lan>::iterator pos = m_lanList.begin();
vector<int>::iterator partPos = partitions.begin();
for ( ; pos != m_lanList.end() && partPos != partitions.end();
......@@ -130,12 +145,16 @@ void Graph::partition(std::vector<int> & partitions)
void Graph::assign(int networkSize, int lanSize, int hostSize,
int numPartitions) const
{
// If they don't specify which ostream they want, give
// them standard output.
assign(cout, networkSize, lanSize, hostSize, numPartitions);
}
void Graph::assign(ostream & output, int networkSize, int lanSize,
int hostSize, int numPartitions) const
{
// Do we output raw numbers for debugging purposes or do we output
// complete IP addresses?
#ifdef IP_ASSIGN_DEBUG
debugAssign(output, networkSize, lanSize, hostSize, numPartitions);
#else
......@@ -149,6 +168,9 @@ void Graph::assign(ostream & output, int networkSize, int lanSize,
int Graph::parseLine(string const & line, list<int> & nodes)
{
// This is called from reset. We want to take each line of input
// (which represents a LAN), verify that it is kosher, then
// create a LAN based on it.
int weight = 1;
size_t i = 0;
for (i = 0; i < line.size(); ++i)
......@@ -182,6 +204,9 @@ int Graph::parseLine(string const & line, list<int> & nodes)
return weight;
}
// The following two functions are auxilliary to the 'convert' function
// They were seperated out into different functions for conceptual simplicity.
void Graph::convertAddLan(Lan const & lanToAdd, std::vector<int> & neighbors,
std::vector<int> & weights) const
{
......@@ -213,6 +238,8 @@ void Graph::convertAddNode(Lan const & info, int currentNode,
void Graph::debugAssign(std::ostream & output, int networkSize, int lanSize,
int hostSize, int numPartitions) const
{
// Print out the raw numbers that we would assign for each part of the
// IP address.
vector<int> counter;
counter.resize(numPartitions);
fill(counter.begin(), counter.end(), 0);
......@@ -237,6 +264,7 @@ void Graph::debugAssign(std::ostream & output, int networkSize, int lanSize,
void Graph::releaseAssign(std::ostream & output, int networkSize, int lanSize,
int hostSize, int numPartitions) const
{
// set up a counter for each supernet (partition).
vector<int> counter;
counter.resize(numPartitions);
fill(counter.begin(), counter.end(), 0);
......@@ -253,6 +281,7 @@ void Graph::releaseAssign(std::ostream & output, int networkSize, int lanSize,
int lanShift = hostSize;
cout << networkSize << " " << lanSize << " " << hostSize << endl;
// For each lan, print out the IP addresses for every node on that lan.
list<Lan>::const_iterator pos = m_lanList.begin();
for ( ; pos != m_lanList.end(); ++pos)
{
......
// Graph.h
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// The Graph class is used to represent the network. Each node in the network
// is a LAN and each edge is a host connecting two LANs.
// First, the graph is populated from input using the constructor or reset()
// Second, the graph is converted to the METIS format
// Third, an array of numbers is used to assign each LAN its partition number
// Fourth, IP addresses are output.
#ifndef GRAPH_H_IP_ASSIGN_1
#define GRAPH_H_IP_ASSIGN_1
......
// autocheck.cpp
//
// Copyright (c) 2003 Jonathon Duerig.
// Usage is according to the BSD license (see license.txt).
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// autocheck is a utility for automated regression tests. For ipassign,
// it takes input from etc/autocheck.conf and uses this to determine which
// tests to run. Each test is run on a particular input, then the output is
// compared with a known good output using boolcmp. If the outputs are the
// same, the test passes. If they are different, it fails.
// This program needs to be rewritten so that it can be used for any similar
// program with the proper configuration file.
#include <cstring>
#include <cstdlib>
......
// boolcmp.cc
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// boolcmp.cc is used to create a utility program which checks whether two
// files are identical or not. The reason that the built in utility 'cmp'
// cannot be used is because a) 'cmp' is not guaranteed to work on binary
// files, and b) many implementations of 'cmp' treat two different files as
// the same if they are the same up to the last character and one ends with
// a newline and the other is one character short.
#include <iostream>
#include <fstream>
......
// ipassign.cc
//
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// Please note that if
// log_2(maxNodesPerLan) + log_2(numLans) + log_2(sqrt(numLans)) > 24
......@@ -8,29 +13,7 @@
// into subnets.
// This program processes from stdin to stdout.
// input line specification:
// <lan_weight> <node> <node> [node [node [...]]]
//
// lan_weight: A number representing how expensive crossing the lan is.
// This must be positive and integral.
//
// node: A unique integer representing a particular node.
// output header specification:
// <global_bits> <lan_bits> <host_bits>
//
// global_bits: The number of bits allocated to identify inter-lan nets
// lan_bits: The number of bits allocated to identify individual lans
// host_bits: The number of bits allocated to identify hosts within lans.
// output line specification:
// <lan_number> <node> <ip>
//
// lan_number: The ordinal number of the lan. The first line is lan 0, the
// second is lan 1, etc.
// node: the node number entered
// ip: an IP addresss in the form 'xxx.xxx.xxx.xxx'
// Input and output specifications can be found in README
#include "lib.h"
#include "Exception.h"
......
// lib.h
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// project-wide inclusions and declarations go here.
#ifndef LIB_H_IP_ASSIGN_1
......
// top2graph.cc
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2003 University of Utah and the Flux Group.
* All rights reserved.
*/
// top2graph is a utility which converts the .top files used for assign into
// .graph files used for ipassign. There is a single optional flag '-m'. If
// this flag is set, the mapping from assign names to ipassign numbers and
// the mapping from ipassign numbers to assign names is sent to the standard
// error in addition to the conversion being sent to the standard output.
#include <iostream>
#include <map>
#include <list>
......
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