Commit 1c7a53f0 authored by Mac Newbold's avatar Mac Newbold

moved here from ../assign_hw

parent bcbe559d
CXX=/usr/gnu/bin/g++
CC=/usr/gnu/bin/gcc
LEDA=/n/paria/z/dga/LEDA-4.0
OBJS=score.o parse_top.o parse_ptop.o
LIBS+=-L${LEDA} -lD3 -lW -lP -lG -lL -L/usr/X11R6/lib -lX11 -lm -L.
LDFLAGS+= -O3 -fomit-frame-pointer -m486
CXXFLAGS = -I${LEDA}/incl
# Pick one of the two below.
CXXFLAGS += -Wall -O3 -fomit-frame-pointer -m486
#CXXFLAGS += -O0 -g -Wall -DSCORE_DEBUG -DVERBOSE -DSCORE_DEBUG_MORE
DEPLIBS=$(OBJS)
all: assign
assign: ${DEPLIBS} ${OBJS} assign.o
${CXX} assign.o -o assign ${LIBS} $(OBJS) ${LDFLAGS}
assign_p: assign.po $(DEPLIBS) $(POBJS)
${CXX} assign.po -pg -g -o assign_p ${LIBS} $(POBJS)
assign.po: assign.cc
${CXX} -c -pg -g -o assign.po assign.cc ${CXXFLAGS}
clean:
/bin/rm -f *.o assign
This diff is collapsed.
#ifndef __COMON_H
#define __COMON_H
const int MAX_PNODES = 1024; // maximum # of physical nodes
#endif
/*
* parse ptop files. These are basic topologies
* that are used to represent the physical topology.
*
* format:
* node <name> <type> [<type2> ...]
* <type> = <t>[:<max>]
* <t> = pc | switch | dnard
* <max> = how many virtual entities of that type per physical entity.
* link <name> <src>[:<mac>] <dst>[:<mac>] <size> <number>
*/
#include <LEDA/graph_alg.h>
#include <LEDA/graphwin.h>
#include <LEDA/dictionary.h>
#include <LEDA/map.h>
#include <LEDA/graph_iterator.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include "common.h"
#include "physical.h"
extern node pnodes[MAX_PNODES]; // int -> node map
node_array<int> switch_index;
int parse_ptop(tb_pgraph &PG, istream& i)
{
int switchi=0;
dictionary<string, node> nmap;
node no1;
edge ed1;
string s1, s2;
char inbuf[255];
char n1[32], n2[32];
int size, num;
int n=1;
char *snext;
char *snode;
char *scur;
char lname[32];
int isswitch;
switch_index.init(PG,MAX_PNODES,0);
pnodes[0] = NULL;
while (!i.eof()) {
char *ret;
i.getline(inbuf, 254);
ret = strchr(inbuf, '\n');
if (ret) *ret = 0;
if (strlen(inbuf) == 0) { continue; }
if (!strncmp(inbuf, "node", 4)) {
isswitch = 0;
snext = inbuf;
scur = strsep(&snext," ");
if (strcmp("node",scur) != 0) {
fprintf(stderr, "bad node line: %s\n", inbuf);
} else {
scur = strsep(&snext," ");
snode = scur;
string s(snode);
no1 = PG.new_node();
PG[no1].name=strdup(snode);
PG[no1].typed = false;
PG[no1].max_load = 0;
PG[no1].current_load = 0;
PG[no1].pnodes_used=0;
while ((scur = strsep(&snext," ")) != NULL) {
char *t,*load=scur;
int iload;
t = strsep(&load,":");
string stype(t);
if (load) {
if (sscanf(load,"%d",&iload) != 1) {
fprintf(stderr,"Bad load specifier: %s\n",load);
iload=1;
}
} else {
iload=1;
}
if (strcmp(t,"switch") == 0) {
isswitch = 1;
PG[no1].types.insert(stype,1);
PG[no1].the_switch = no1;
switch_index[no1] = switchi++;
} else {
PG[no1].types.insert(stype,iload);
}
}
if (! isswitch)
pnodes[n++]=no1;
nmap.insert(s, no1);
}
}
else if (!strncmp(inbuf, "link", 4)) {
if (sscanf(inbuf, "link %s %s %s %d %d", lname, n1, n2, &size, &num)
!= 5) {
fprintf(stderr, "bad link line: %s\n", inbuf);
} else {
char *snode,*smac;
char *dnode,*dmac;
smac = n1;
dmac = n2;
snode = strsep(&smac,":");
dnode = strsep(&dmac,":");
string s1(snode);
string s2(dnode);
if (nmap.lookup(s1) == nil) {
fprintf(stderr,"PTOP error: Unknown source node %s\n",snode);
exit(1);
}
if (nmap.lookup(s2) == nil) {
fprintf(stderr,"PTOP error: Unknown destination node %s\n",dnode);
exit(1);
}
node node1 = nmap.access(s1);
node node2 = nmap.access(s2);
for (int i = 0; i < num; ++i) {
ed1=PG.new_edge(node1, node2);
PG[ed1].bandwidth=size;
PG[ed1].bw_used=0;
PG[ed1].users=0;
PG[ed1].name=strdup(lname);
if (smac)
PG[ed1].srcmac = strdup(smac);
else
PG[ed1].srcmac = NULL;
if (dmac)
PG[ed1].dstmac = strdup(dmac);
else
PG[ed1].dstmac = NULL;
}
#define ISSWITCH(n) (PG[n].types.lookup("switch") != nil)
if (ISSWITCH(node1) &&
! ISSWITCH(node2))
PG[node2].the_switch = node1;
else if (ISSWITCH(node2) &&
! ISSWITCH(node1))
PG[node1].the_switch = node2;
}
} else {
fprintf(stderr, "unknown directive: %s\n", inbuf);
}
}
return n-1;
}
/*
* Parse chris' ".top" file format into a LEDA graph
*/
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <LEDA/graph_alg.h>
#include <LEDA/graphwin.h>
#include <LEDA/dictionary.h>
#include <LEDA/map.h>
#include <LEDA/graph_iterator.h>
#include <LEDA/node_pq.h>
#include "common.h"
#include "virtual.h"
extern tb_vgraph G;
extern node_pq<int> unassigned_nodes;
int parse_top(tb_vgraph &G, istream& i)
{
dictionary<string, node> nmap;
node no1;
string s1, s2;
char inbuf[255];
char n1[32], n2[32], type[32];
char lname[32];
int num_nodes = 0;
int bw;
int r;
while (!i.eof()) {
char *ret;
i.getline(inbuf, 254);
ret = strchr(inbuf, '\n');
if (ret) *ret = 0;
if (strlen(inbuf) == 0) { continue; }
if (!strncmp(inbuf, "node", 4)) {
if (sscanf(inbuf, "node %s %s", n1, type) < 1) {
fprintf(stderr, "bad node line: %s\n", inbuf);
} else {
num_nodes++;
string s1(n1);
no1 = G.new_node();
unassigned_nodes.insert(no1,random());
G[no1].name=strdup(n1);
G[no1].posistion = 0;
G[no1].no_connections=0;
nmap.insert(s1, no1);
G[no1].type=string(type);
}
} else if (!strncmp(inbuf, "link", 4)) {
r=sscanf(inbuf, "link %s %s %s %d", lname, n1, n2,&bw);
if (r < 2) {
fprintf(stderr, "bad link line: %s\n", inbuf);
} else {
if (r == 2) bw = 10;
string s1(n1);
string s2(n2);
edge e;
node node1 = nmap.access(s1);
node node2 = nmap.access(s2);
e = G.new_edge(node1, node2);
G[e].bandwidth = bw;
G[e].type = tb_vlink::LINK_UNKNOWN;
G[e].plink = NULL;
G[e].plink_two = NULL;
G[e].name = strdup(lname);
}
}
else {
fprintf(stderr, "unknown directive: %s\n", inbuf);
}
}
return num_nodes;
}
#ifndef __PHYSICAL_H
#define __PHYSICAL_H
class tb_pnode {
public:
tb_pnode() {;}
friend ostream &operator<<(ostream &o, const tb_pnode& node)
{
o << "TBNode: " << node.name << endl;
return o;
}
friend istream &operator>>(istream &i, const tb_pnode& node)
{
return i;
}
dictionary<string,int> types; // contains max nodes for each type
string current_type;
bool typed; // has it been typed
int max_load; // maxmium load for current type
int current_load; // how many vnodes are assigned to this pnode
char *name;
node the_switch; // the switch the node is attached to
int pnodes_used; // for switch nodes
};
class tb_plink {
public:
tb_plink() {;}
friend ostream &operator<<(ostream &o, const tb_plink& edge)
{
o << "unimplemeted ostream << for tb_plinke " << endl;
return o;
}
friend istream & operator>>(istream &i, const tb_plink& edge)
{
return i;
}
int bandwidth; // maximum bandwidth of this link
int bw_used; // how much is used
int users; // number of users in direct links
char *srcmac,*dstmac; // source and destination MAC addresses.
char *name; // The name
};
class tb_route {
public:
private:
int length;
list<tb_plink> links;
};
typedef GRAPH<tb_pnode,tb_plink> tb_pgraph;
#endif
This diff is collapsed.
#ifndef _SCORE_H
#define _SCORE_H
// Cost of a direct link
const float SCORE_DIRECT_LINK = 0.01;
// Cost of overusing a direct link
const float SCORE_DIRECT_LINK_PENALTY = 0.5;
// Cost of an intraswitch link
const float SCORE_INTRASWITCH_LINK = 0.02;
// Cost of an interswitch link
const float SCORE_INTERSWITCH_LINK = 0.05;
// Cost of being unable to fulfill a virtual link
const float SCORE_NO_CONNECTION = 0.5;
// Cost of using a pnode
const float SCORE_PNODE = 0.05;
// Cost of overusing a pnode
const float SCORE_PNODE_PENALTY = 0.5;
// Cost of using a switch.
const float SCORE_SWITCH = 0.5;
// Cost of an unassigned node
const float SCORE_UNASSIGNED = 1;
// Cost of going over bandwidth
const float SCORE_OVER_BANDWIDTH = 0.5;
typedef struct {
int unassigned;
int pnode_load;
int no_connection;
int link_users;
int bandwidth;
} violated_info;
extern float score;
extern int violated;
extern violated_info vinfo;
void init_score();
void remove_node(node n);
int add_node(node n,int loc);
float get_score();
#endif
node pa pc
node pb pc
node pc pc
node pd pc
link pa pb 100 1
link pa pc 100 1
link pa pd 100 1
link pb pc 100 1
link pb pd 100 1
link pc pd 100 1
node A pc
node B pc
node C pc
link A B 100
link A C 100
link B C 100
node switch_a switch
node switch_b switch
node a_1 pc
node a_2 pc
node a_3 pc
node b_1 pc
node b_2 pc
link a_1 switch_a 100 3
link a_2 switch_a 100 3
link a_3 switch_a 100 3
link b_1 switch_b 100 2
link b_2 switch_b 100 2
link switch_a switch_b 400 1
node A pc
node B pc
node C pc
node D pc
node E pc
link A C 100
link B C 100
link C D 100
link A E 100
node 1 pc
node 2 pc
node 3 pc
node 4 pc
node 5 pc
node 6 pc
node 7 pc
node 8 pc
node 9 pc
node 10 pc
node 11 pc
node 12 pc
node 13 pc
node 14 pc
node 15 pc
node 16 pc
node 17 pc
node 18 pc
node 19 pc
node 20 pc
link l12 1 2 100
link l23 2 3 100
link l34 3 4 100
link l37 3 7 100
link l411 4 11 100
link l412 4 12 100
link l57 5 7 100
link l59 5 9 100
link l67 6 7 100
link l78 7 8 100
link l89 8 9 100
link l910 9 10 100
link l1011 10 11 100
link l1213 12 13 100
link l1314 13 14 100
link l1415 14 15 100
link l1516 15 16 100
link l1617 16 17 100
link l1720 17 20 100
link l1815 18 15 100
link l1819 18 19 100
link l1920 19 20 100
link l201 20 1 100
link l212 2 12 100
node switch switch
node tri1 pc
node tri2 pc
node tri3 pc
link tri1 switch 100 1
link tri2 tri1 100 1
link tri2 tri3 100 1
link tri3 tri1 100 1
node two pc
link two switch 100 2
node three pc
link three switch 100 3
node a pc
link a three 100 1
node b pc
link b three 100 1
node center pc
link center b 100 1
link center two 100 1
node d pc
link d center 100 1
node fanbase pc
link fanbase center 100 1
node fan1 pc
node fan2 pc
node fan3 pc
link fan1 fanbase 100 1
link fan2 fanbase 100 1
link fan3 fanbase 100 1
node fA pc
node fB pc
node fC pc
node f_ pc
link fA f_ 100
link fB f_ 100
link fC f_ 100
node C pc
link C f_ 100
node l1 pc
node l2 pc
node l3 pc
link l3 l2 100
link l2 l1 100
link l1 C 100
node r1 pc
node r2 pc
node r3 pc
link r3 r2 100
link r2 r1 100
link r1 C 100
node s_0 switch
node n_0_0 pc:1 delay:2
link link0 n_0_0:mac_0 s_0 100 4
node n_0_1 pc:1 delay:2
link link1 n_0_1:mac_1 s_0 100 4
node n_0_2 pc:1 delay:2
link link2 n_0_2:mac_2 s_0 100 4
node n_0_3 pc:1 delay:2
link link3 n_0_3:mac_3 s_0 100 4
node n_0_4 pc:1 delay:2
link link4 n_0_4:mac_4 s_0 100 4
node n_0_5 pc:1 delay:2
link link5 n_0_5:mac_5 s_0 100 4
node s_1 switch
node n_1_0 pc:1 delay:2
link link6 n_1_0:mac_6 s_1 100 4
node n_1_1 pc:1 delay:2
link link7 n_1_1:mac_7 s_1 100 4
node n_1_2 pc:1 delay:2
link link8 n_1_2:mac_8 s_1 100 4
node n_1_3 pc:1 delay:2
link link9 n_1_3:mac_9 s_1 100 4
node n_1_4 pc:1 delay:2
link link10 n_1_4:mac_10 s_1 100 4
node n_1_5 pc:1 delay:2
link link11 n_1_5:mac_11 s_1 100 4
node s_2 switch
node n_2_0 pc:1 delay:2
link link12 n_2_0:mac_12 s_2 100 4
node n_2_1 pc:1 delay:2
link link13 n_2_1:mac_13 s_2 100 4
node n_2_2 pc:1 delay:2
link link14 n_2_2:mac_14 s_2 100 4
node n_2_3 pc:1 delay:2
link link15 n_2_3:mac_15 s_2 100 4
node n_2_4 pc:1 delay:2
link link16 n_2_4:mac_16 s_2 100 4
node n_2_5 pc:1 delay:2
link link17 n_2_5:mac_17 s_2 100 4
node s_3 switch
node n_3_0 pc:1 delay:2
link link18 n_3_0:mac_18 s_3 100 4
node n_3_1 pc:1 delay:2
link link19 n_3_1:mac_19 s_3 100 4
node n_3_2 pc:1 delay:2
link link20 n_3_2:mac_20 s_3 100 4
node n_3_3 pc:1 delay:2
link link21 n_3_3:mac_21 s_3 100 4
node n_3_4 pc:1 delay:2
link link22 n_3_4:mac_22 s_3 100 4
node n_3_5 pc:1 delay:2
link link23 n_3_5:mac_23 s_3 100 4
node s_4 switch
node n_4_0 pc:1 delay:2
link link24 n_4_0:mac_24 s_4 100 4
node n_4_1 pc:1 delay:2
link link25 n_4_1:mac_25 s_4 100 4
node n_4_2 pc:1 delay:2
link link26 n_4_2:mac_26 s_4 100 4
node n_4_3 pc:1 delay:2
link link27 n_4_3:mac_27 s_4 100 4
node n_4_4 pc:1 delay:2
link link28 n_4_4:mac_28 s_4 100 4
node n_4_5 pc:1 delay:2
link link29 n_4_5:mac_29 s_4 100 4
link link30 s_0 s_1 400 1
link link31 s_0 s_2 400 1
link link32 s_0 s_3 400 1
link link33 s_0 s_4 400 1
link link34 s_1 s_2 400 1
link link35 s_1 s_3 400 1
link link36 s_1 s_4 400 1
link link37 s_2 s_3 400 1
link link38 s_2 s_4 400 1
link link39 s_3 s_4 400 1
#ifndef __VIRTUAL_H
#define __VIRTUAL_H
class tb_vnode {
public:
tb_vnode() {;}
friend ostream &operator<<(ostream &o, const tb_vnode& node)
{
o << "TBVNode: " << node.name << endl;
return o;
}
friend istream &operator>>(istream &i, const tb_vnode& node)
{
return i;
}
int posistion; // index into pnode array
int no_connections; // how many unfulfilled connections from this node
string type;
char *name; // string name of the node
};
typedef enum {LINK_DIRECT,LINK_INTRASWITCH,LINK_INTERSWITCH} tb_link_type;
class tb_plink;
class tb_vlink {
public:
tb_vlink() {;}
friend ostream &operator<<(ostream &o, const tb_vlink& edge)
{
o << "unimplemeted ostream << for tb_vlink " << endl;
return o;
}
friend istream & operator>>(istream &i, const tb_vlink& edge)
{
return i;
}
typedef enum {LINK_UNKNOWN, LINK_DIRECT,
LINK_INTRASWITCH, LINK_INTERSWITCH} linkType;
int bandwidth; // how much bandwidth this uses
linkType type; // link type
edge plink; // plink this belongs to
edge plink_two; // second plink for INTRA and INTER links
edge plink_local_one; // only used in inter - link to local switch
edge plink_local_two; // only used in inter - link to local switch
char *name; // name
};
typedef GRAPH<tb_vnode,tb_vlink> tb_vgraph;
#endif
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