physical.h 8.88 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1 2 3 4 5 6
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2003 University of Utah and the Flux Group.
 * All rights reserved.
 */

Mac Newbold's avatar
Mac Newbold committed
7 8 9
#ifndef __PHYSICAL_H
#define __PHYSICAL_H

10
#include "common.h"
11

12 13 14 15
// Icky, but I can't include virtual.h here
class tb_vnode;
typedef hash_set<tb_vnode*,hashptr<tb_vnode*> > tb_vnode_set;

16
// Class forward declarations - defined below
Christopher Alfeld's avatar
 
Christopher Alfeld committed
17
class tb_pclass;
18 19 20 21 22
class tb_pnode;
class tb_switch;
class tb_plink;
class tb_slink;

23
// typedefs
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
typedef property<vertex_data_t,tb_pnode*> PNodeProperty;
typedef property<edge_data_t,tb_plink*> PEdgeProperty;
typedef property<vertex_data_t,tb_switch*> SNodeProperty;
typedef property<edge_data_t,tb_slink*,
  property<edge_weight_t,long> > SEdgeProperty;

typedef adjacency_list<listS,listS,undirectedS,
  PNodeProperty,PEdgeProperty> tb_pgraph;
typedef adjacency_list<listS,vecS,undirectedS,
  SNodeProperty,SEdgeProperty> tb_sgraph;

typedef property_map<tb_pgraph,vertex_data_t>::type tb_pgraph_vertex_pmap;
typedef property_map<tb_pgraph,edge_data_t>::type tb_pgraph_edge_pmap;
typedef property_map<tb_sgraph,vertex_data_t>::type tb_sgraph_vertex_pmap;
typedef property_map<tb_sgraph,edge_data_t>::type tb_sgraph_edge_pmap;
typedef property_map<tb_sgraph,edge_weight_t>::type tb_sgraph_weight_pmap;

typedef graph_traits<tb_pgraph>::vertex_descriptor pvertex;
typedef graph_traits<tb_pgraph>::edge_descriptor pedge;
typedef graph_traits<tb_sgraph>::vertex_descriptor svertex;
typedef graph_traits<tb_sgraph>::edge_descriptor sedge;

typedef graph_traits<tb_pgraph>::vertex_iterator pvertex_iterator;
typedef graph_traits<tb_pgraph>::edge_iterator pedge_iterator;
typedef graph_traits<tb_pgraph>::out_edge_iterator poedge_iterator;
typedef graph_traits<tb_sgraph>::vertex_iterator svertex_iterator;
typedef graph_traits<tb_sgraph>::edge_iterator sedge_iterator;
typedef graph_traits<tb_sgraph>::out_edge_iterator soedge_iterator;

typedef hash_set<pvertex,hashptr<void*> > pvertex_set;
typedef hash_map<tb_pnode*,pvertex,hashptr<tb_pnode*> > pnode_pvertex_map;
typedef hash_map<crope,pvertex> name_pvertex_map;
typedef vector<svertex> switch_pred_map;
typedef hash_map<svertex,switch_pred_map*>switch_pred_map_map;
typedef vector<svertex> switch_dist_map;
typedef hash_map<svertex,switch_dist_map*>switch_dist_map_map;
typedef list<pedge> pedge_path;
typedef list<pvertex> pvertex_list;

63 64
// Globals, declared in assign.cc

65 66 67 68
extern tb_pgraph_vertex_pmap pvertex_pmap;
extern tb_pgraph_edge_pmap pedge_pmap;
extern tb_sgraph_vertex_pmap svertex_pmap;
extern tb_sgraph_edge_pmap sedge_pmap;
Christopher Alfeld's avatar
 
Christopher Alfeld committed
69

Mac Newbold's avatar
Mac Newbold committed
70 71
class tb_pnode {
public:
72 73
  tb_pnode() { tb_pnode("(unnamed)"); }
  tb_pnode(crope _name) : types(), features(), name(_name), typed(false),
74 75
  			  current_type_record(NULL), total_load(0),
			  switches(), sgraph_switch(), switch_used_links(0),
76 77 78 79
			  total_interfaces(0), used_interfaces(0),
			  total_bandwidth(0), my_class(NULL), assigned_nodes(),
			  trivial_bw(0), trivial_bw_used(0) {;}

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  class type_record {
      public:
	  type_record(int _max_load, bool _is_static) :
	      max_load(_max_load), current_load(0),
	      is_static(_is_static) { ; }
	  int max_load;		// maximum load for this type
	  int current_load;	// how many vnodes are assigned of this type
	  bool is_static;	// whether this type is static or dynamic

	  bool operator==(const type_record &b) {
	      return ((max_load == b.max_load) && (is_static == b.is_static));
	  }

	  friend ostream &operator<<(ostream &o, const type_record& node)
	  {
	      o << "max_load = " << node.max_load <<
		   " current_load = " << node.current_load <<
		   " is_static = " << node.is_static;
	  }
  };

  typedef hash_map<crope,type_record*> types_map;
102
  typedef hash_map<crope,double> features_map;
103

104 105 106 107 108 109 110 111 112
  // contains max nodes for each type
  types_map types;

  // contains cost of each feature
  features_map features;

  crope name;			// name of the node
  bool typed;			// has it been typed
  crope current_type;		// type the node is currently being used as
113 114 115 116
  type_record* current_type_record;
  int total_load;		// total load for all types
  //int max_load;			// maxmium load for current type
  //int current_load;		// how many vnodes are assigned to this pnode
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  pvertex_set switches;		// what switches the node is attached to

  svertex sgraph_switch;	// only for switches, the corresponding
				// sgraph switch.
  int switch_used_links;	// only for switches, how many links are
				// in use.  Switch is in use whenever > 0

  int total_interfaces;		// total number of links leaving the node
  int used_interfaces;		// number of links that are currently in use
  int total_bandwidth;		// total bandwidth of all this nodes' links

  tb_pclass *my_class;		// the pclass this node belongs to

  tb_vnode_set assigned_nodes;	// the set of vnodes currently assigned

  int trivial_bw;		// the maximum amount of trivial bandwidth
  				// available
  int trivial_bw_used;		// the amount of bandwidth currently used by
  				// trivial links
	
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  bool set_current_type(crope type) {
      if (types.find(type) == types.end()) {
	  //cout << "Failed to find type " << type << endl;
	  return false;
      }
      current_type = type;
      typed = true;
      current_type_record = types[type];
      return true;
  }

  void remove_current_type() {
      typed = false;
      current_type_record = NULL;
  }

153
  // Output operator for debugging
Mac Newbold's avatar
Mac Newbold committed
154 155
  friend ostream &operator<<(ostream &o, const tb_pnode& node)
    {
156 157 158 159 160 161 162 163 164
      o << "tb_pnode: " << node.name << " (" << &node << ")" << endl;
      o << "  Types:" << endl;
      for (types_map::const_iterator it = node.types.begin();
	   it!=node.types.end();it++) 
	o << "    " << (*it).first << " -> " << (*it).second << endl;
      o << "  Features:" << endl;
      for (features_map::const_iterator it = node.features.begin();
	   it!=node.features.end();it++) 
	cout << "    " << (*it).first << " -> " << (*it).second << endl;
165 166
      o << "  Current Type: " << node.current_type << endl; /* <<
	" (" << node.current_load << "/" << node.max_load << ")" <<  endl; */
167 168 169 170 171 172
      o << "  switches=";
      for (pvertex_set::const_iterator it = node.switches.begin();
	   it != node.switches.end();++it) {
	o << " " << get(pvertex_pmap,*it)->name;
      }
      o << endl;
173 174
      o << " sgraph_switch=" << node.sgraph_switch
	  << " my_class=" << node.my_class << endl;
Mac Newbold's avatar
Mac Newbold committed
175 176
      return o;
    }
Christopher Alfeld's avatar
 
Christopher Alfeld committed
177

178 179 180 181
};

class tb_switch {
public:
182 183 184 185 186 187
  friend ostream &operator<<(ostream &o, const tb_switch& node)
  {
    o << "tb_switch: " << &node << endl;
    o << "  mate=" << node.mate << endl;
    return o;
  }
188
  
189 190 191
  tb_switch() {;}
  pvertex mate;			// match in PG
};
Mac Newbold's avatar
Mac Newbold committed
192

193 194 195 196 197 198
// Hasher for pairs
template <class T> struct pairhash { 
    size_t operator()(pair<T,T> const &A) const {
	hash<T> H;
	return (H(A.first) | H(A.second));
    }
199
};
200

201 202 203
typedef pair<crope,crope> nodepair;
typedef hash_map<nodepair,int,pairhash<crope> > nodepair_count_map;

Mac Newbold's avatar
Mac Newbold committed
204 205
class tb_plink {
public:
206 207 208 209 210 211 212 213 214 215 216 217 218 219
  typedef enum {PLINK_NORMAL,PLINK_INTERSWITCH,PLINK_LAN} plinkType;

  tb_plink(crope _name, plinkType _type, crope _srcmac, crope _dstmac)
    : name(_name), srcmac(_srcmac), dstmac(_dstmac), type(_type),
      delay_info(), bw_used(0), emulated(0), nonemulated(0),
      penalty(0.0), fixends(false), current_endpoints(), current_count(0),
      vedge_counts() {;}

  crope name;			// the name
  crope srcmac,dstmac;		// source and destination MAC addresses.

  plinkType type;		// type of the link
  tb_delay_info delay_info;	// the delay characteristics of this link
  int bw_used;			// how much is used
220

221 222 223 224 225 226 227 228 229 230 231 232
  int emulated;			// number of emulated vlinks
  int nonemulated;		// number of nonemulated vlinks
  float penalty;		// penaly for bandwidth used

  bool fixends;                 // if using as a emulated link, fix endpoints
  nodepair current_endpoints;	// pnodes at the endpoints of the vlink using
  				// this plink
  int current_count;		// number of mapped vlinks that share these
				// pnode endpoints
  nodepair_count_map vedge_counts; // list, and count, of all pairs of pnode
				   // endpoints sharing this link
				   
233 234 235 236 237 238 239 240 241 242 243 244 245 246
  friend ostream &operator<<(ostream &o, const tb_plink& link)
  {
    o << "tb_plink: " << link.name << " (" << &link << ")" << endl;
    o << "  type: ";
    switch (link.type) {
    case tb_plink::PLINK_NORMAL:
      o << "normal" << endl;
      break;
    case tb_plink::PLINK_INTERSWITCH:
      o << "interswitch" << endl;
      break;
    case tb_plink::PLINK_LAN:
      o << "lan" << endl;
      break;
247
    }
248 249 250 251 252 253 254
    o << "  bw_used=" << link.bw_used <<
      " srcmac=" << link.srcmac << " dstmac=" << link.dstmac <<
      " emulated=" << link.emulated << " nonemulated=" <<
      link.nonemulated << endl;
    o << link.delay_info;
    return o;
  }
Mac Newbold's avatar
Mac Newbold committed
255 256
};

257
class tb_slink {
Mac Newbold's avatar
Mac Newbold committed
258
public:
259
  tb_slink() {;}
260 261 262 263 264 265 266 267

  friend ostream &operator<<(ostream &o, const tb_slink &link)
  {
    o << "tb_slink: " << &link << endl;
    o << "  mate=" << link.mate << endl;
    return o;
  }
  pedge mate;			// match in PG
Mac Newbold's avatar
Mac Newbold committed
268 269
};

270
int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i);
Mac Newbold's avatar
Mac Newbold committed
271

272 273 274 275 276 277 278
/*
 * Globals
 */

/* The physical graph, defined in assign.cc */
extern tb_pgraph PG;

Mac Newbold's avatar
Mac Newbold committed
279
#endif