score.h 5.7 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1
/*
Robert Ricci's avatar
Robert Ricci committed
2
 * Copyright (c) 2000-2010 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Robert Ricci's avatar
Robert Ricci committed
22
 */
23 24 25 26

#ifndef _SCORE_H
#define _SCORE_H

27 28
#include "physical.h"
#include "virtual.h"
29 30 31 32 33 34 35 36

/*
 * Details about which violations are present
 */
class violated_info {

    /* Spit out the current violations (details only, not the total) */
    friend ostream &operator<<(ostream &o, const violated_info &vinfo) {
37 38 39 40 41 42 43 44
	o << "  unassigned:  " << vinfo.unassigned << endl;
	o << "  pnode_load:  " << vinfo.pnode_load << endl;
	o << "  no_connect:  " << vinfo.no_connection << endl;
	o << "  link_users:  " << vinfo.link_users << endl;
	o << "  bandwidth:   " << vinfo.bandwidth << endl;
	o << "  desires:     " << vinfo.desires << endl;
	o << "  vclass:      " << vinfo.vclass << endl;
	o << "  delay:       " << vinfo.delay << endl;
45 46
	o << "  trivial mix: " << vinfo.trivial_mix << endl;
	o << "  subnodes:    " << vinfo.subnodes << endl;
47
	o << "  max_types:   " << vinfo.max_types << endl;
48
#ifdef FIX_PLINK_ENDPOINTS
49
	o << "  endpoints:   " << vinfo.incorrect_endpoints << endl;
50 51 52 53 54 55 56 57
#endif
	return o;
    }
    
    public: /* No real reason to hide this stuff */
	violated_info():
	    unassigned(0), pnode_load(0), no_connection(0), link_users(0),
	    bandwidth(0), desires(0), vclass(0), delay(0),
58 59
	    incorrect_endpoints(0), trivial_mix(0), subnodes(0), max_types(0)
	{ }
60 61 62 63 64 65
	
	int count_violations() const {
	    return unassigned + pnode_load + no_connection + link_users + bandwidth
		+ desires + vclass + delay + incorrect_endpoints + trivial_mix 
		+ subnodes + max_types;
	}
66 67 68 69 70 71 72 73 74 75

	int unassigned;
	int pnode_load;
	int no_connection;
	int link_users;
	int bandwidth;
	int desires;
	int vclass;
	int delay;
	int incorrect_endpoints;
76
	int trivial_mix;
77
	int subnodes;
78
	int max_types;
79
};
80 81 82

extern int violated;
extern violated_info vinfo;
83
extern bool allow_trivial_links;
Robert Ricci's avatar
Robert Ricci committed
84
extern bool greedy_link_assignment;
85

86 87 88 89 90
/*
 * Vector used to hold several possible link resolutions
 */
typedef vector<tb_link_info> resolution_vector;

91 92 93
/*
 * Scoring functions
 */
94
void init_score();
95
void remove_node(vvertex vv);
96
int add_node(vvertex vv,pvertex pv,bool deterministic, bool is_fixed, bool skip_links = false);
97 98 99
double get_score();
pvertex make_lan_node(vvertex vv);
void delete_lan_node(pvertex pv);
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
/*
 * Functions specifically for dealing with links
 */
void score_link_info(vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode,
	tb_vnode *src_vnode, tb_vnode *dst_vnode);
void unscore_link_info(vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode,
	tb_vnode *src_vnode, tb_vnode *dst_vnode);
float find_link_resolutions(resolution_vector &resolutions, pvertex pv,
    pvertex dest_pv, tb_vlink *vlink, tb_pnode *pnode, tb_pnode *dest_pnode,
    bool flipped);
void resolve_link(vvertex vv, pvertex pv, tb_vnode *vnode, tb_pnode *pnode,
    bool deterministic, hash_set<const tb_vlink*, 
    hashptr<const tb_vlink*> > &seen_loopback_links, vedge edge);
void resolve_links(vvertex vv, pvertex pv, tb_vnode *vnode, tb_pnode *pnode,
    bool deterministic);
void mark_vlink_unassigned(tb_vlink *vlink);
117
void mark_vlink_assigned(tb_vlink *vlink);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

/*
 * Declaration of many of the variables used for scoring. Default values
 * are provided in score.cc, but these declarations are here so that other
 * parts of the code can see or modify their values.
 */
extern float SCORE_DIRECT_LINK; /* Cost of a direct link */
extern float SCORE_INTRASWITCH_LINK; /* Cost of an intraswitch link*/
extern float SCORE_INTERSWITCH_LINK; /* Cost of an interswitch link*/

extern float SCORE_DIRECT_LINK_PENALTY; /* Cost of overused direct link*/
extern float SCORE_NO_CONNECTION; /* Cost of not filling a virt. link*/
extern float SCORE_PNODE; /* Cost of using a pnode*/
extern float SCORE_PNODE_PENALTY; /* Cost of overusing a pnode*/
extern float SCORE_SWITCH; /* Cost of using a switch.*/
extern float SCORE_UNASSIGNED; /* Cost of an unassigned node*/
extern float SCORE_MISSING_LOCAL_FEATURE;
extern float SCORE_OVERUSED_LOCAL_FEATURE;
extern float SCORE_PCLASS; /* Cost of each pclass */

extern float SCORE_VCLASS; /* vclass score multiplier */
extern float SCORE_EMULATED_LINK; /* cost of an emualted link */
extern float SCORE_OUTSIDE_DELAY; /* penalty for going out of delay
requirements */
#ifdef PENALIZE_UNUSED_INTERFACES
extern float SCORE_UNUSED_INTERFACE;
#endif
extern float SCORE_TRIVIAL_PENALTY; /* Cost of over-using a trivial link */

extern float SCORE_TRIVIAL_MIX; /* Cost of mixing trivial and non-trivial
links */

extern float SCORE_SUBNODE; /* Cost of not properly assigning subnodes */
extern float SCORE_MAX_TYPES; /* Cost of going over type limits - low 
* enough that assign ususally picks this
* over leaving a node unassigned */

// The following are used to weight possible link resolutions.  Higher
// numbers mean a more likely resolution.
extern float LINK_RESOLVE_TRIVIAL;
extern float LINK_RESOLVE_DIRECT;
extern float LINK_RESOLVE_INTRASWITCH;
extern float LINK_RESOLVE_INTERSWITCH;

// The amount that each violation contributes to the total score
extern float VIOLATION_SCORE;

extern float opt_nodes_per_sw;

167
#endif