Commit ef766011 authored by Tarun Prabhu's avatar Tarun Prabhu

Added support for set-type-limits in the advertisement. It is implemented as...

Added support for set-type-limits in the advertisement. It is implemented as an extension. There is no support for this in v1. It will only be in v2 and higher. To this end, ptopgen has been modified. ptopgen also now adds type slot information to nodes as an extension. However, support for other extensions still have to be added. Added another annotater class for rspec v2 but this in a very incomplete state as of now and the relevant code has been commented out of solution.cc temporarily. Assign's arguments have also been modified in mapper, so that it expects rspec inputs.
parent fc03e047
......@@ -8,8 +8,6 @@
* Base class for the annotater.
*/
/* This is ugly, but we only really need this file if we are building with XML support */
#ifdef WITH_XML
#ifndef __ANNOTATE_H
......@@ -25,26 +23,34 @@
class annotate
{
protected:
//xercesc::DOMDocument* doc;
xercesc::DOMElement* virtual_root;
std::map<std::string, xercesc::DOMElement*> *physical_elements;
public:
// Annotates nodes and direct links in the rspec
virtual void annotate_element(const char* v_name, const char* p_name) = 0;
// Annotates intraswitch and interswitch links in the rspec
virtual void annotate_element(const char* v_name, std::list<const char*>* links) = 0;
// Creates a hop from a switch till the next end point. Adds the hop to the vlink and returns the hop element that was created
virtual xercesc::DOMElement* create_component_hop (const xercesc::DOMElement* plink, xercesc::DOMElement* vlink, int endpoint_interface, const xercesc::DOMElement* prev_component_hop) = 0;
// Finds the next link in the path returned by assign
virtual xercesc::DOMElement* find_next_link_in_path (xercesc::DOMElement *prev, std::list<const char*>* links) = 0;
// Writes the annotated xml to disk
void write_annotated_file(const char* filename);
protected:
//xercesc::DOMDocument* doc;
xercesc::DOMElement* virtual_root;
std::map<std::string, xercesc::DOMElement*> *physical_elements;
public:
// Annotates nodes and direct links in the rspec
virtual void annotate_element(const char* v_name, const char* p_name) = 0;
// Annotates intraswitch and interswitch links in the rspec
virtual void annotate_element(const char* v_name,
std::list<const char*>* links) = 0;
// Creates a hop from a switch till the next end point.
// Adds the hop to the vlink and returns the hop element that was created
virtual xercesc::DOMElement*
create_component_hop (const xercesc::DOMElement* plink,
xercesc::DOMElement* vlink,
int endpoint_interface,
const xercesc::DOMElement* prev_component_hop) = 0;
// Finds the next link in the path returned by assign
virtual xercesc::DOMElement*
find_next_link_in_path (xercesc::DOMElement *prev,
std::list<const char*>* links) = 0;
// Writes the annotated xml to disk
void write_annotated_file(const char* filename);
};
#endif // for __ANNOTATE_H
......
......@@ -25,89 +25,89 @@
class annotate_rspec : public annotate
{
private:
// Enumeration of which interface in a hop
// is an interface to a link end point
enum endpoint_interface_enum { NEITHER, SOURCE, DESTINATION, BOTH };
std::map< std::string, std::set<std::string> > lan_links_map;
public:
annotate_rspec ();
~annotate_rspec () { ; }
// Annotates nodes and direct links in the rspec
void annotate_element(const char* v_name, const char* p_name);
// Annotates intraswitch and interswitch links in the rspec
void annotate_element(const char* v_name,
std::list<const char*>* links);
// Annotate a trivial link
void annotate_element(const char* v_name);
// Annotates an interface element on a link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number,
bool is_trivial_link);
// Annotates an interface element on a non-trivial link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number);
// Annotates an interface element on a trivial link
void annotate_interface (const xercesc::DOMElement* vlink,
int interface_number);
// Creates a hop from a switch till the next end point.
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement* create_component_hop
(const xercesc::DOMElement* plink,
xercesc::DOMElement* vlink,
int endpoint_interface,
const xercesc::DOMElement* prev_hop);
// Creates a component_hop for a trivial link
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement* create_component_hop (xercesc::DOMElement* vlink);
// If the interface is the end point of a link/path,
// add two additional attributes to it
void set_interface_as_link_endpoint (xercesc::DOMElement* interface,
const char* virtual_node_id,
const char* virtual_interface_id);
// Finds the next link in the path returned by assign
xercesc::DOMElement* find_next_link_in_path
(xercesc::DOMElement *prev,
std::list<const char*>* links);
// Copies the component spec from the source to the destination
void copy_component_spec(const xercesc::DOMElement* src,
xercesc::DOMElement* dst);
// Copies the component hop from the auto-generated link
// to the requested link
void copy_component_hop(xercesc::DOMElement* requested_link,
xercesc::DOMElement* component_hop);
// Checks if the link contains an interface with
// virtual_interface_id = id
bool has_interface_with_id (std::string link_id, std::string id);
// Removes all extra tags and generated elements from the XML document
void cleanup ();
// Checks whether an element of type tag
// with attr_name = attr_value is a generated element
bool is_generated_element (const char* tag,
const char* attr_name,
const char* attr_value);
private:
// Enumeration of which interface in a hop
// is an interface to a link end point
enum endpoint_interface_enum { NEITHER, SOURCE, DESTINATION, BOTH };
std::map< std::string, std::set<std::string> > lan_links_map;
public:
annotate_rspec ();
~annotate_rspec () { ; }
// Annotates nodes and direct links in the rspec
void annotate_element(const char* v_name, const char* p_name);
// Annotates intraswitch and interswitch links in the rspec
void annotate_element(const char* v_name,
std::list<const char*>* links);
// Annotate a trivial link
void annotate_element(const char* v_name);
// Annotates an interface element on a link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number,
bool is_trivial_link);
// Annotates an interface element on a non-trivial link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number);
// Annotates an interface element on a trivial link
void annotate_interface (const xercesc::DOMElement* vlink,
int interface_number);
// Creates a hop from a switch till the next end point.
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement*
create_component_hop (const xercesc::DOMElement* plink,
xercesc::DOMElement* vlink,
int endpoint_interface,
const xercesc::DOMElement* prev_hop);
// Creates a component_hop for a trivial link
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement* create_component_hop (xercesc::DOMElement* vlink);
// If the interface is the end point of a link/path,
// add two additional attributes to it
void set_interface_as_link_endpoint (xercesc::DOMElement* interface,
const char* virtual_node_id,
const char* virtual_interface_id);
// Finds the next link in the path returned by assign
xercesc::DOMElement* find_next_link_in_path
(xercesc::DOMElement *prev,
std::list<const char*>* links);
// Copies the component spec from the source to the destination
void copy_component_spec(const xercesc::DOMElement* src,
xercesc::DOMElement* dst);
// Copies the component hop from the auto-generated link
// to the requested link
void copy_component_hop(xercesc::DOMElement* requested_link,
xercesc::DOMElement* component_hop);
// Checks if the link contains an interface with
// virtual_interface_id = id
bool has_interface_with_id (std::string link_id, std::string id);
// Removes all extra tags and generated elements from the XML document
void cleanup ();
// Checks whether an element of type tag
// with attr_name = attr_value is a generated element
bool is_generated_element (const char* tag,
const char* attr_name,
const char* attr_value);
};
#endif //for __ANNOTATE_RSPEC_H
#endif // for WITH_XML
This diff is collapsed.
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2008 University of Utah and the Flux Group.
* All rights reserved.
*/
/*
* Base class for the annotater.
*/
#ifdef WITH_XML
#ifndef __ANNOTATE_RSPEC_V2_H
#define __ANNOTATE_RSPEC_V2_H
#include "annotate.h"
#include <list>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <xercesc/dom/DOM.hpp>
class annotate_rspec_v2 : public annotate
{
private:
// Enumeration of which interface in a hop
// is an interface to a link end point
enum endpoint_interface_enum { NEITHER, SOURCE, DESTINATION, BOTH };
std::map< std::string, std::set<std::string> > lan_links_map;
public:
annotate_rspec_v2 ();
~annotate_rspec_v2 () { ; }
// Annotates nodes and direct links in the rspec
void annotate_element(const char* v_name, const char* p_name);
// Annotates intraswitch and interswitch links in the rspec
void annotate_element(const char* v_name,
std::list<const char*>* links);
// Annotate a trivial link
void annotate_element(const char* v_name);
// Annotates an interface element on a link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number,
bool is_trivial_link);
// Annotates an interface element on a non-trivial link
void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number);
// Annotates an interface element on a trivial link
void annotate_interface (const xercesc::DOMElement* vlink,
int interface_number);
// Creates a hop from a switch till the next end point.
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement*
create_component_hop (const xercesc::DOMElement* plink,
xercesc::DOMElement* vlink,
int endpoint_interface,
const xercesc::DOMElement* prev_hop);
// Creates a component_hop for a trivial link
// Adds the hop to the vlink
// Returns the hop element that was created
xercesc::DOMElement* create_component_hop (xercesc::DOMElement* vlink);
// If the interface is the end point of a link/path,
// add two additional attributes to it
void set_interface_as_link_endpoint (xercesc::DOMElement* interface,
const char* virtual_node_id,
const char* virtual_interface_id);
// Finds the next link in the path returned by assign
xercesc::DOMElement* find_next_link_in_path
(xercesc::DOMElement *prev,
std::list<const char*>* links);
// Copies the component spec from the source to the destination
void copy_component_spec(const xercesc::DOMElement* src,
xercesc::DOMElement* dst);
// Copies the component hop from the auto-generated link
// to the requested link
void copy_component_hop(xercesc::DOMElement* requested_link,
xercesc::DOMElement* component_hop);
// Checks if the link contains an interface with
// virtual_interface_id = id
bool has_interface_with_id (std::string link_id, std::string id);
// Removes all extra tags and generated elements from the XML document
void cleanup ();
// Checks whether an element of type tag
// with attr_name = attr_value is a generated element
bool is_generated_element (const char* tag,
const char* attr_name,
const char* attr_value);
};
#endif //for __ANNOTATE_RSPEC_H
#endif // for WITH_XML
......@@ -19,122 +19,147 @@ using namespace rspec_emulab_extension;
emulab_operator emulab_extensions_parser::readOperator(DOMElement* tag)
{
struct emulab_operator op = { "", NORMAL_OPERATOR };
if (this->hasAttribute(tag, "global_operator")) {
op.op = this->getAttribute(tag, "global_operator");
op.type = GLOBAL_OPERATOR;
}
else if (this->hasAttribute(tag, "local_operator")) {
op.op = this->getAttribute(tag, "local_operator");
op.type = LOCAL_OPERATOR;
}
return op;
struct emulab_operator op = { "", NORMAL_OPERATOR };
if (this->hasAttribute(tag, "global_operator")) {
op.op = this->getAttribute(tag, "global_operator");
op.type = GLOBAL_OPERATOR;
}
else if (this->hasAttribute(tag, "local_operator")) {
op.op = this->getAttribute(tag, "local_operator");
op.type = LOCAL_OPERATOR;
}
return op;
}
vector<struct fd> emulab_extensions_parser::readAllFeaturesDesires
(DOMElement* elem)
vector<struct fd>
emulab_extensions_parser::readAllFeaturesDesires (DOMElement* elem)
{
DOMNodeList* fdNodes = elem->getElementsByTagName(XStr("fd").x());
vector<struct fd> fds;
for (int i = 0; i < fdNodes->getLength(); i++) {
fds.push_back(this->readFeatureDesire
(dynamic_cast<DOMElement*>(fdNodes->item(i))));
}
return fds;
DOMNodeList* fdNodes = elem->getElementsByTagName(XStr("emulab:fd").x());
vector<struct fd> fds;
for (int i = 0; i < fdNodes->getLength(); i++) {
fds.push_back(this->readFeatureDesire
(dynamic_cast<DOMElement*>(fdNodes->item(i))));
}
return fds;
}
struct fd emulab_extensions_parser::readFeatureDesire (DOMElement* tag)
{
struct fd fdObject = {
this->getAttribute(tag, "fd_name"),
rspec_parser_helper::stringToNum
(this->getAttribute(tag, "fd_weight")),
this->hasAttribute(tag, "violatable"),
this->readOperator(tag)
};
return fdObject;
struct fd fdObject = {
this->getAttribute(tag, "name"),
rspec_parser_helper::stringToNum
(this->getAttribute(tag, "weight")),
this->hasAttribute(tag, "violatable"),
this->readOperator(tag)
};
return fdObject;
}
vector<struct property> emulab_extensions_parser::readAllProperties
(DOMElement* elem)
(DOMElement* elem)
{
DOMNodeList* propNodes = elem->getElementsByTagName(XStr("property").x());
vector<struct property> properties;
for (int i = 0; i < propNodes->getLength(); i++) {
properties.push_back(this->readProperty
(dynamic_cast<DOMElement*>(propNodes->item(i))));
}
return properties;
DOMNodeList* propNodes = elem->getElementsByTagName(XStr("property").x());
vector<struct property> properties;
for (int i = 0; i < propNodes->getLength(); i++) {
properties.push_back(this->readProperty
(dynamic_cast<DOMElement*>(propNodes->item(i))));
}
return properties;
}
struct property emulab_extensions_parser::readProperty (DOMElement* tag)
{
struct property propertyObject = {
this->getAttribute(tag, "property_name"),
this->getAttribute(tag, "property_value"),
rspec_parser_helper::stringToNum
(this->getAttribute(tag, "property_penalty")),
this->hasAttribute(tag, "violatable"),
this->readOperator(tag)
};
return propertyObject;
struct property propertyObject = {
this->getAttribute(tag, "property_name"),
this->getAttribute(tag, "property_value"),
rspec_parser_helper::stringToNum
(this->getAttribute(tag, "property_penalty")),
this->hasAttribute(tag, "violatable"),
this->readOperator(tag)
};
return propertyObject;
}
struct hardness emulab_extensions_parser::readHardness (DOMElement* tag)
{
struct hardness hardnessObject;
if (this->hasChild(tag, "hard")) {
// XXX: This is a temporary fix. We will need to deal with hard
// vclasses correctly at some point
hardnessObject.type = HARD_VCLASS;
}
else /* (this->hasChildTag(tag, "soft")) */ {
hardnessObject.weight
= rspec_parser_helper::stringToNum (this->readChild(tag, "weight"));
hardnessObject.type = SOFT_VCLASS;
}
return hardnessObject;
struct hardness hardnessObject;
if (this->hasChild(tag, "hard")) {
// XXX: This is a temporary fix. We will need to deal with hard
// vclasses correctly at some point
hardnessObject.type = HARD_VCLASS;
}
else /* (this->hasChildTag(tag, "soft")) */ {
hardnessObject.weight
= rspec_parser_helper::stringToNum (this->readChild(tag, "weight"));
hardnessObject.type = SOFT_VCLASS;
}
return hardnessObject;
}
vector<struct vclass> emulab_extensions_parser::readAllVClasses
(DOMElement* elem)
vector<struct vclass>
emulab_extensions_parser::readAllVClasses (DOMElement* elem)
{
DOMNodeList* vclassNodes =
elem->getElementsByTagName(XStr("vtop_vclass").x());
vector<struct vclass> vclasses;
for (int i = 0; i < vclassNodes->getLength(); i++) {
vclasses.push_back(this->readVClass
(dynamic_cast<DOMElement*>(vclassNodes->item(i))));
}
return vclasses;
DOMNodeList* vclassNodes
= elem->getElementsByTagName(XStr("emulab:vclass").x());
vector<struct vclass> vclasses;
for (int i = 0; i < vclassNodes->getLength(); i++) {
vclasses.push_back(this->readVClass
(dynamic_cast<DOMElement*>
(vclassNodes->item(i))));
}
return vclasses;
}
struct vclass emulab_extensions_parser::readVClass (DOMElement* tag)
{
struct vclass vclassObject = {
this->getAttribute(tag, "name"),
this->readHardness(tag),
this->readChild(tag, "physical_type")
};
return vclassObject;
struct vclass vclassObject = {
this->getAttribute(tag, "name"),
this->readHardness(tag),
this->readChild(tag, "physical_type")
};
return vclassObject;
}
string emulab_extensions_parser::readTypeSlots (DOMElement* tag)
{
DOMElement* typeSlotsNode
= dynamic_cast<DOMElement*>
((tag->getElementsByTagName(XStr("emulab:ext_node_type").x()))
->item(0));
return (this->getAttribute(typeSlotsNode, "type_slots"));
DOMNodeList* typeSlotsNodes
= tag->getElementsByTagName(XStr("emulab:node_type").x());
if (typeSlotsNodes->getLength() == 0) {
return "";
}
DOMElement* typeSlotsNode = dynamic_cast<DOMElement*>(typeSlotsNodes->item(0));
return (this->getAttribute(typeSlotsNode, "type_slots"));
}
bool emulab_extensions_parser::readStaticType (DOMElement* tag)
{
DOMElement* typeSlotsNode
= dynamic_cast<DOMElement*>
((tag->getElementsByTagName(XStr("emulab:ext_node_type").x()))
->item(0));
return (typeSlotsNode->hasAttribute(XStr("static").x()));
DOMNodeList* typeSlotsNodes
= tag->getElementsByTagName(XStr("emulab:node_type").x());
if (typeSlotsNodes->getLength() == 0) {
return false;
}
DOMElement* typeSlotsNode = dynamic_cast<DOMElement*>(typeSlotsNodes->item(0));
return (typeSlotsNode->hasAttribute(XStr("static").x()));
}
vector<struct type_limit>
emulab_extensions_parser::readTypeLimits (const DOMElement* tag, int& count)
{
vector<struct type_limit> rv;
DOMNodeList* typeLimitNodes
= tag->getElementsByTagName(XStr("emulab:set_type_limit").x());
count = typeLimitNodes->getLength();
for (int i = 0; i < count; i++) {
DOMElement* limitNode = dynamic_cast<DOMElement*>(typeLimitNodes->item(i));
string typeClass = this->getAttribute(limitNode, "typeclass");
string typeCount = this->getAttribute(limitNode, "count");
struct type_limit limit = {
typeClass ,
(int)rspec_parser_helper::stringToNum(typeCount)
};
rv.push_back(limit);
}
return rv;
}
#endif // WITH_XML
......@@ -16,89 +16,96 @@
namespace rspec_emulab_extension {
#define LOCAL_OPERATOR 0
#define GLOBAL_OPERATOR 1
#define NORMAL_OPERATOR 2
#define HARD_VCLASS 0
#define SOFT_VCLASS 1
struct emulab_operator {
std::string op;
int type;
};
struct fd
{
std::string fd_name;
float fd_weight;
bool violatable;
struct emulab_operator op;
};
struct node_flags
{
int trivialBandwidth;
std::string subnodeOf;
bool unique;
bool disallowTrivialMix;
};
struct link_flags
{
bool noDelay;
bool multiplexOk;
bool trivialOk;
std::string fixSrcIface;
std::string fixDstIface;
};
struct hardness {
int type;
float weight;
};
struct vclass {
std::string name;
struct hardness type;
std::string physicalType;
};
struct property {
std::string name;
std::string value;
float penalty;
bool violatable;
struct emulab_operator op;
};
class emulab_extensions_parser : public rspec_parser_helper {
private:
int type;
struct emulab_operator readOperator(xercesc::DOMElement* tag);
struct hardness readHardness (xercesc::DOMElement* tag);
public:
// Constructor
emulab_extensions_parser(int type) { this->type = type; }
// Functions
std::vector<struct fd> readAllFeaturesDesires
(xercesc::DOMElement* ele);
struct fd readFeatureDesire (xercesc::DOMElement* tag);
struct node_flags readNodeFlag (xercesc::DOMElement* tag);
struct link_flags readLinkFlag (xercesc::DOMElement* tag);
std::vector<struct property> readAllProperties
(xercesc::DOMElement* elem);
struct property readProperty (xercesc::DOMElement* tag);
std::vector<struct vclass> readAllVClasses (xercesc::DOMElement*);
struct vclass readVClass (xercesc::DOMElement* tag);
std::string readAssignedTo (xercesc::DOMElement* tag);
std::string readHintTo (xercesc::DOMElement* tag);
std::string readTypeSlots (xercesc::DOMElement* tag);
bool readStaticType (xercesc::DOMElement* tag);
};
#define LOCAL_OPERATOR 0
#define GLOBAL_OPERATOR 1
#define NORMAL_OPERATOR 2
#define HARD_VCLASS 0
#define SOFT_VCLASS 1
struct emulab_operator {
std::string op;
int type;
};
struct fd
{
std::string fd_name;
float fd_weight;
bool violatable;
struct emulab_operator op;
};
struct node_flags
{
int trivialBandwidth;
std::string subnodeOf;
bool unique;
bool disallowTrivialMix;
};
struct link_flags
{
bool noDelay;
bool multiplexOk;
bool trivialOk;
std::string fixSrcIface;
std::string fixDstIface;
};
struct hardness {
int type;
float weight;
};
struct vclass {
std::string name;
struct hardness type;
std::string physicalType;
};