virtual.h 4.31 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 __VIRTUAL_H
#define __VIRTUAL_H

10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 63 64 65 66
#include <hash_set>

class tb_plink;
class tb_vnode;
class tb_vlink;
class tb_vclass;

typedef property<vertex_data_t,tb_vnode*> VNodeProperty;
typedef property<edge_data_t,tb_vlink*> VEdgeProperty;

typedef adjacency_list<listS,listS,undirectedS,
  VNodeProperty,VEdgeProperty> tb_vgraph;

typedef property_map<tb_vgraph,vertex_data_t>::type tb_vgraph_vertex_pmap;
typedef property_map<tb_vgraph,edge_data_t>::type tb_vgraph_edge_pmap;

typedef graph_traits<tb_vgraph>::vertex_descriptor vvertex;
typedef graph_traits<tb_vgraph>::edge_descriptor vedge;

typedef graph_traits<tb_vgraph>::vertex_iterator vvertex_iterator;
typedef graph_traits<tb_vgraph>::edge_iterator vedge_iterator;
typedef graph_traits<tb_vgraph>::out_edge_iterator voedge_iterator;

class tb_link_info {
public:
  typedef enum {LINK_UNKNOWN, LINK_DIRECT,
		LINK_INTRASWITCH, LINK_INTERSWITCH,
		LINK_TRIVIAL, LINK_DELAYED} linkType;
  linkType type;
  pedge_path plinks;		// the path of pedges
  pvertex_list switches;	// what switches were used

  friend ostream &operator<<(ostream &o, const tb_link_info& link)
  {
    o << "  Type: ";
    switch (link.type) {
    case LINK_UNKNOWN : o << "LINK_UNKNOWN"; break;
    case LINK_DIRECT : o << "LINK_DIRECT"; break;
    case LINK_INTRASWITCH : o << "LINK_INTRASWITCH"; break;
    case LINK_INTERSWITCH : o << "LINK_INTERSWITCH"; break;
    case LINK_TRIVIAL : o << "LINK_TRIVIAL"; break;
    }
    o << " Path: ";
    for (pedge_path::const_iterator it=link.plinks.begin();
	 it!=link.plinks.end();it++) {
      o << *it << " ";
    }
    o << " Switches: ";
    for (pvertex_list::const_iterator it=link.switches.begin();
	 it!=link.switches.end();it++) {
      o << *it << " ";
    }
    o << endl;
    return o;
  }
};

Mac Newbold's avatar
Mac Newbold committed
67 68 69
class tb_vnode {
public:
  tb_vnode() {;}
70

Mac Newbold's avatar
Mac Newbold committed
71
  friend ostream &operator<<(ostream &o, const tb_vnode& node)
72 73 74 75 76 77 78 79 80 81 82 83 84
  {
    o << "tb_vnode: " << node.name << " (" << &node << ")" << endl;
    o << "  Type: " << node.type << endl;
    o << "  Desires:" << endl;
    for (desires_map::const_iterator it = node.desires.begin();
	 it!=node.desires.end();it++) 
      o << "    " << (*it).first << " -> " << (*it).second << endl;
    o << " vclass=" << node.vclass << " fixed=" <<
      node.fixed << endl;
    return o;
  }

  typedef hash_map<crope,double> desires_map;
Robert Ricci's avatar
Robert Ricci committed
85
  typedef hash_map<crope,int> desires_count_map;
86 87 88

  // contains weight of each desire
  desires_map desires;
Mac Newbold's avatar
Mac Newbold committed
89

90
  crope type;			// the current type of the node
91
  tb_vclass *vclass;		// the virtual class of the node, if any
92
  crope name;			// string name of the node
93
  bool fixed;			// is this node fixed
94 95
  bool assigned;		// is this node assigned?
  pvertex assignment;		// the physical vertex assigned to
Mac Newbold's avatar
Mac Newbold committed
96

97 98
#ifdef PER_VNODE_TT
  int num_links;
99
  int total_bandwidth;
100
#endif
Mac Newbold's avatar
Mac Newbold committed
101

102
};
Mac Newbold's avatar
Mac Newbold committed
103 104 105 106

class tb_vlink {
public:
  tb_vlink() {;}
107 108 109 110 111 112 113 114 115 116 117 118 119 120

  friend ostream &operator<<(ostream &o, const tb_vlink& link)
  {
    o << "tb_vnode: " << link.name << " (" << &link << ")" << endl;
    o << " emulated=" << link.emulated << " allow_delayed=" <<
      link.allow_delayed << " no_connection=" << link.no_connection << endl;
    o << "delay_info: " << link.delay_info;
    o << link.link_info;
    return o;
  }

  tb_delay_info delay_info;	// the delay characteristics of the link
  tb_link_info link_info;	// what it's mapped to
  crope name;			// name
121 122
  bool emulated;		// is this an emulated link, i.e. can it
				// share a plink withouter emulated vlinks
123 124 125
  bool no_connection;		// true if this link should be satisfied
				// but isn't.
  bool allow_delayed;		// can this vlink by a delayed link
126
  bool allow_trivial;           // can this vlink be a trivial link?
127
  vvertex src, dst;		// Source and destination for this link
Mac Newbold's avatar
Mac Newbold committed
128 129
};

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
extern tb_vgraph_vertex_pmap vvertex_pmap;
extern tb_vgraph_edge_pmap vedge_pmap;

typedef hash_map<crope,vvertex> name_vvertex_map;
typedef pair<vvertex,int> vvertex_int_pair;
typedef vector<vvertex> vvertex_vector;

struct ltnodepq {
  bool operator()(const vvertex_int_pair &A,const vvertex_int_pair &B) const {
    return A.second < B.second;
  };
};

typedef priority_queue<vvertex_int_pair,
  vector<vvertex_int_pair>, ltnodepq> vvertex_int_priority_queue;
typedef list<vvertex> vvertex_list;

int parse_top(tb_vgraph &G, istream& i);
Mac Newbold's avatar
Mac Newbold committed
148 149

#endif
150 151