Commit 5652b392 authored by David G Andersen's avatar David G Andersen

Parse simple physical topology description

parent ee20c53d
CXX=/usr/gnu/bin/g++
CC=/usr/gnu/bin/gcc
LEDA=/n/paria/z/dga/LEDA-4.0
OBJS=testbed.o parse_top.o parse_ir.o parse_ptop.o
OBJS=testbed.o parse_top.o parse_ir.o phys.o parse_phys.o parse_ptop.o
LIBS+=-L${LEDA} -lD3 -lW -lP -lG -lL -L/usr/X11R6/lib -lX11 -lm -L. -lg2c
LDFLAGS+= -O3 -fomit-frame-pointer -m486
CXXFLAGS = -I${LEDA}/incl
......
......@@ -13,6 +13,9 @@
#include "testbed.h"
#include "phys.h"
topology *topo = NULL;
/* How can we chop things up? */
#define PARTITION_BY_ANNEALING 0
......@@ -463,6 +466,7 @@ void usage() {
" (# of links which can go between switches\n"
" -a ...... Use simulated annealing (default)\n"
" -o ...... Update on-line (vs batch, default)\n"
" -t <file> Input topology desc. from <file>\n"
);
}
......@@ -471,12 +475,13 @@ int main(int argc, char **argv)
int h_menu;
extern char *optarg;
extern int optind;
char *topofile = NULL;
int ch;
partition_mechanism = PARTITION_BY_ANNEALING;
while ((ch = getopt(argc, argv, "oas:n:c:h")) != -1)
while ((ch = getopt(argc, argv, "oas:n:c:t:h")) != -1)
switch(ch) {
case 'h': usage(); exit(0);
case 'n': nodecap = atoi(optarg); break;
......@@ -484,6 +489,7 @@ int main(int argc, char **argv)
case 'c': intercap = atoi(optarg); break;
case 'a': partition_mechanism = PARTITION_BY_ANNEALING; break;
case 'o': on_line = 1; break;
case 't': topofile = optarg; break;
default: usage(); exit(-1);
}
......@@ -513,7 +519,7 @@ int main(int argc, char **argv)
if (argc == 1) {
ifstream infile;
infile.open(argv[0]);
if (!infile) {
if (!infile || !infile.good()) {
cerr << "Error opening file: " << argv[0] << "\n";
exit(1);
}
......@@ -526,6 +532,16 @@ int main(int argc, char **argv)
point(random() % 200, random() % 200));
}
}
if (topofile != NULL) {
topo = parse_phys(topofile);
if (!topo) {
cerr << "Could not read in topofile "
<< topofile << endl;
exit(-1);
}
nparts = topo->switchcount;
}
gw.display();
......
/*
* Input a simple topology.
*/
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
* Simple topology description:
*
* topology :: 1 or more lines
* line :: <comment> | <switch>
* comment :: # followed by anything
* switch :: <switchname> <nodecount> <nodelist>
*
* nodelist :: <interfaces> <count> <nodelist>
*
* switchname :: [a-z0-9_]+
* interfaces :: number
* count :: number
*
* Example:
*
* # A switch with 6 computers with 4 interfaces, and 2 computers with 8
* # interfaces
* switch1 2 4 6 8 2
* # A switch with 8 computers with 4 interfaces
* switch2 1 4 8
*
*/
#define MAXSW 32
#include "phys.h"
topology *parse_phys(char *filename)
{
char name[64];
char linebuf[256];
ifstream infile(filename);
topology *topo;
if (!infile.good()) { return NULL; }
topo = new topology(MAXSW); // XXX
topo->switchcount = 0;
for (int i = 0; i < MAXSW; i++)
topo->switches[i] = NULL;
while (!infile.eof()) {
infile >> name;
if (infile.eof()) { break; }
if (name[0] == '#') {
infile.getline(linebuf, 255);
} else {
int nodecount;
infile >> nodecount;
tbswitch *newsw;
newsw = new tbswitch(nodecount, name);
topo->switches[topo->switchcount++] = newsw;
#ifdef VERBOSE
printf("Creating switch %d : %s\n",
topo->switchcount-1, name);
#endif
if (!newsw) {
perror("Could not allocate a tbswitch");
exit(-1);
}
for (int i = 0; i < nodecount; i++) {
infile >> newsw->nodes[i].ints;
infile >> newsw->nodes[i].count;
newsw->nodes[i].used = 0;
#ifdef VERBOSE
printf("Adding node %d with %d %d\n",
i, newsw->nodes[i].ints,
newsw->nodes[i].count);
#endif
}
}
}
return topo;
}
# Two switches, configured identically - 8 nodes with 4 interfaces
switch1 4 8
switch2 4 8
#include <stdlib.h>
#include <string.h>
#include "phys.h"
toponode::toponode() {
ints = count = used = 0;
}
tbswitch::tbswitch() {
nodes = NULL;
nodecount = 0;
}
tbswitch::tbswitch(int ncount, char *newname) {
nodecount = ncount;
nodes = new toponode[ncount];
name = strdup(newname);
}
void tbswitch::setsize(int ncount) {
if (nodes) { delete(nodes); }
nodecount = ncount;
nodes = new toponode[ncount];
}
tbswitch::~tbswitch() {
if (nodes) { delete(nodes); }
nodecount = 0;
}
topology::topology(int nswitches) {
switchcount = nswitches;
switches = new tbswitch *[switchcount];
}
topology::~topology() {
if (switches) delete(switches);
}
class toponode {
public:
toponode();
int ints;
int count;
int used;
};
class tbswitch {
public:
tbswitch();
virtual ~tbswitch();
tbswitch(int ncount, char *newname); // Specify number of toponodes
void setsize(int ncount);
int nodecount;
toponode *nodes;
char *name;
};
class topology {
public:
topology(int nswitches);
virtual ~topology();
int switchcount;
tbswitch **switches;
};
topology *parse_phys(char *filename);
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