Commit aa1dd338 authored by Tarun Prabhu's avatar Tarun Prabhu

Merging conflicts caused by stash pop

parent 08bc4884
This diff is collapsed.
......@@ -40,7 +40,7 @@ static const char rcsid[] = "$Id: parse_request_rspec.cc,v 1.16 2009-10-21 20:49
*/
extern name_pvertex_map pname2vertex;
/* ------------------- Have to include the vnode data structures as well -------------------- */
/* --- Have to include the vnode data structures as well --- */
extern name_vvertex_map vname2vertex;
extern name_name_map fixed_nodes;
extern name_name_map node_hints;
......@@ -48,15 +48,13 @@ extern name_count_map vtypes;
extern name_list_map vclasses;
extern vvertex_vector virtual_nodes;
extern name_vclass_map vclass_map;
/* ---------------------------------- end of vtop stuff ----------------------------------- */
/* --- end of vtop stuff --- */
DOMElement* request_root = NULL;
DOMDocument* doc = NULL;
/*
* TODO: This should be moved out of parse_top.cc, where it currently
* resides.
*/
int rspec_version = -1;
int bind_ptop_subnodes(tb_pgraph &pg);
int bind_vtop_subnodes(tb_vgraph &vg);
......@@ -64,13 +62,19 @@ int bind_vtop_subnodes(tb_vgraph &vg);
* These are not meant to be used outside of this file, so they are only
* declared in here
*/
bool populate_nodes_rspec(DOMElement *root, tb_vgraph &vg, map< pair<string, string>, pair<string, string> >* fixed_interfaces);
bool populate_links_rspec(DOMElement *root, tb_vgraph &vg, map< pair<string, string>, pair<string, string> >* fixed_interfaces);
bool populate_nodes_rspec(DOMElement *root,
tb_vgraph &vg,
map< pair<string, string>,
pair<string, string> >* fixed_interfaces);
bool populate_links_rspec(DOMElement *root, tb_vgraph &vg,
map< pair<string, string>,
pair<string, string> >* fixed_interfaces);
bool populate_vclasses_rspec (DOMElement *root, tb_vgraph &vg);
string generate_virtual_node_id (string virtual_id);
string generate_virtual_interface_id(string node_name, int interface_number);
DOMElement* appendChildTagWithData (DOMElement* parent, const char*tag_name, const char* child_value);
DOMElement* appendChildTagWithData (DOMElement* parent,
const char*tag_name,
const char* child_value);
bool hasComponentSpec (DOMElement* element);
......@@ -97,6 +101,12 @@ int parse_vtop_rspec(tb_vgraph &vg, char *filename) {
/*
* Must validate against the ptop schema
*/
/* This is a problem
* We can only know the schema location if we know the rspec version
* But we only know the rspec version after it has been validated
* And we can only validate it if we know the schema location.
* Whoops!
*/
parser -> setExternalSchemaLocation
("http://www.protogeni.net/resources/rspec/0.1 " SCHEMA_LOCATION);
......@@ -558,8 +568,7 @@ bool populate_link (DOMElement* elt, tb_vgraph &vg, map< pair<string,string>, pa
DOMElement* src_interface_ref =
doc->createElement(XStr("interface_ref").x());
src_interface_ref->setAttribute(
XStr("virtual_interface_id").x(),
src_interface_ref->setAttribute(XStr("virtual_interface_id").x(),
virtual_interface_id.x());
src_interface_ref->setAttribute(XStr("virtual_node_id").x(),
virtual_node_id.x());
......
......@@ -11,141 +11,220 @@
# ifdef WITH_XML
#include "rspec_parser.h"
#include "xmlhelpers.h"
#include <string>
#include <vector>
#include "xstr.h"
#include <xercesc/dom/DOM.hpp>
// Returns true if the attribute exists and it's value is a non-empty string
// Returns the attribute value and an out paramter if the attribute exists
string rspec_parser :: getAttribute(const DOMElement* tag,
const string attrName,
bool& hasAttr)
const string attrName,
bool& hasAttr)
{
XMLCh* attr = XStr(attrName.c_str()).x();
attrValue = XStr(tag->getAttribute(attr)).c();
hasAttr = tag->hasAttribute(attrName) && attrValue != "";
return attrValue;
hasAttr = tag->hasAttribute(XStr(attrName.c_str()).x());
if (hasAttr)
return XStr(tag->getAttribute(XStr(attrName.c_str()).x())).c();
return "";
}
struct link_interface rspec_parser :: getIface (DOMElement* tag)
bool rspec_parser :: hasAttribute(const DOMElement* tag, const string attrName)
{
return (tag->hasAttribute(XStr(attrName).x()));
}
string rspec_parser :: readSubnodeOf (const DOMElement* tag, bool& isSubnode)
{
isSubnode = hasChildTag(tag, "subnode_of");
string rv = "";
if (isSubnode)
rv = XStr(getChildValue(tag, "subnode_of")).c();
return rv;
}
struct link_interface rspec_parser :: getIface (const DOMElement* tag)
{
bool exists;
struct link_interface rv =
{
string(XStr(tag->getAttribute(XStr("virtual_node_id").x())).c()),
string(XStr(tag->getAttribute(XStr("virtual_interface_id").x())).c()),
string(XStr(find_urn(tag, "component_node"))),
string(XStr(tag->getAttribute(XStr("component_node_uuid").x())).c()),
string(XStr(tag->getAttribute(XStr("component_interface_id").x())).c())
};
return rv;
}
// Returns true if the attribute exists and its value is a non-empty string
string rspec_parser :: readComponentId (const DOMElement* tag,
bool& hasComponentId)
// Returns the component_id. Sets an out parameter to true if an ID is present
string rspec_parser :: readPhysicalId (const DOMElement* tag,
bool& hasComponentId)
{
return (this->getAttribute(tag, "component_id", hasComponentId));
}
// Returns true if the attribute exists and its value is a non-empty string
string rspec_parser :: readVirtualId (const DOMElement* tag, bool& hasVirtualId)
// Returns the client_id Sets an out parameter to true if an ID is present
string rspec_parser :: readVirtualId (const DOMElement* tag, bool& hasClientId)
{
return (this->getAttribute(tag, "virtual_id", hasVirtualId));
return (this->getAttribute(tag, "client_id", hasClientId));
}
// Returns true if the attribute exists and its value is a non-empty string
// Returns the CMID and sets an out parameter to true if an ID is present
string rspec_parser :: readComponentManagerId (const DOMElement* tag,
bool& cmId)
{
return (this->getAttribute(tag, "component_manager_id", cmId));
}
//
// Returns true if the latitude and longitude tags are present
// Absence of the country tag will be caught by the schema validator
list<string> rspec_parser :: readLocation (DOMElement* tag, int& rvLength)
vector<string> rspec_parser :: readLocation (const DOMElement* tag,
int& rvLength)
{
XMLCh* country_attr = XStr("country").x();
XMLCh* latitude_attr = XStr("latitude").x();
XMLCh* longitude_attr = XStr("longitude").x();
bool hasCountry, hasLatitude, hasLongitude;
country = string(XStr(tag->getAttribute(country_attr).c());
latitude = string(Xstr(tag->getAttribute(latitude_attr)).c());
longitude = string(XStr(tag->getAttribute(longitude_attr)).c());
rvLength = ((country == "" ? 0 : 1)
+ (latitude == "" ? 0 : 1)
+ (longitude == "" ? 0 : 1));
string country = this->getAttribute(tag, "country", hasCountry);
string latitude = this->getAttribute(tag, "latitude", hasLatitude);
string longitude = this->getAttribute(tag, "longitude", hasLongitude);
rvLength = (hasLatitude && hasLongitude) ? 3 : 1;
return (list<string> (country, latitude, longitude));
vector<string> rv;
rv.push_back(country);
rv.push_back(latitude);
rv.push_back(longitude);
return rv;
}
// Returns a list of node_type elements
// The out parameter contains the number of elements found
list< struct node_type > rspec_parser :: readNodeTypes (DOMElement* node,
int& typeCount)
list<struct node_type> rspec_parser::readNodeTypes (const DOMElement* node,
int& typeCount)
{
DOMNodeList* nodeTypes = node->getElementsByTagName(XStr("node_type").x());
list< node_type > types;
for (int i = 0; i < types->getLength(); i++)
list<struct node_type> types;
for (int i = 0; i < nodeTypes->getLength(); i++)
{
DOMElement *tag = dynamic_cast<DOMElement*>(types->item(i));
DOMElement *tag = dynamic_cast<DOMElement*>(nodeTypes->item(i));
string typeName = XStr(tag->getAttribute(XStr("type_name").x())).c();
int typeSlots;
string slot = XStr(tag->getAttribute(XStr("type_slots").x())).c();
if (slotString.compare("unlimited") == 0)
if (slot.compare("unlimited") == 0)
typeSlots = 1000;
else
typeSlots = slotString.i();
typeSlots = atoi(slot.c_str());
bool isStatic = tag->hasAttribute("static");
node_type type (typeName, typeSlots, isStatic);
bool isStatic = tag->hasAttribute(XStr("static").x());
struct node_type type = {typeName, typeSlots, isStatic};
types.push_back(type);
}
typeCount = types->getLength();
typeCount = nodeTypes->getLength();
return types;
}
int rspec_parser::readInterfacesOnNode (const DOMElement* node, bool& allUnique)
{
DOMNodeList* ifaces = node->getElementsByTagName(XStr("interface").x());
allUnique = true;
for (int i = 0; i < ifaces->getLength(); i++)
{
DOMElement* iface = dynamic_cast<DOMElement*>(ifaces->item(i));
bool hasAttr;
string nodeId = "";
string ifaceId = "";
if (this->rspecType == RSPEC_TYPE_ADVT)
{
nodeId = this->readPhysicalId (node, hasAttr);
ifaceId = XStr(iface->getAttribute(XStr("component_id").x())).c();
}
else //(this->rspecType == RSPEC_TYPE_REQ)
{
nodeId = this->readVirtualId (node, hasAttr);
ifaceId = XStr(iface->getAttribute(XStr("client_id").x())).c();
}
allUnique &= ((this->ifacesSeen).insert
(pair<string, string>(nodeId, ifaceId))).second;
}
return (ifaces->getLength());
}
// Returns a link_characteristics element
struct link_characteristics rspec_parser :: readLinkCharacteristics
(const DOMElement* link,
int defaultBandwidth,
int unlimitedBandwidth,
int& count)
{
bool hasBandwidth, hasLatency, hasPacketLoss;
string strBw = this->getAttribute(link, "bandwidth", hasBandwidth&);
string strLat = this->getAttribute(link, "latency", hasLatency&);
string strLoss = this->getAttribute(link, "packet_loss", hasPacketLoss&);
string strBw = this->getAttribute(link, "bandwidth", hasBandwidth);
string strLat = this->getAttribute(link, "latency", hasLatency);
string strLoss = this->getAttribute(link, "packet_loss", hasPacketLoss);
int bandwidth, latency, packetLoss;
if (!hasLatency)
bandwidth = DEFAULT_BANDWIDTH;
int bandwidth = 0, latency = 0;
float packetLoss = 0.0;
if (!hasBandwidth)
bandwidth = defaultBandwidth;
else if(strBw == "unlimited")
// This is the bandwidth used to simulate an unlimited value
// We don't expect it to change, so it's constant here
bandwidth = UNLIMITED_BANDWIDTH;
bandwidth = unlimitedBandwidth;
else
bandwidth = strBw.i();
bandwidth = atoi(strBw.c_str());
latency = (hasLatency ? strLat.i() : 0);
packetLoss = (hasPacketLoss ? strLoss.d() : 0);
latency = hasLatency ? atoi(strLat.c_str()) : 0 ;
packetLoss = hasPacketLoss ? atof(strLoss.c_str()) : 0.0;
return (link_characteristics(bandwidth, latency, packetLoss));
struct link_characteristics rv = {bandwidth, latency, packetLoss};
return rv;
}
struct list<link_interface> rspec_parser :: readLinkInterface
vector<struct link_interface> rspec_parser :: readLinkInterface
(const DOMElement* link, int& ifaceCount)
{
DOMNodeList* ifaceRefs =
link->getElementsByTagName(XStr("interface_ref").x());
ifaceCount = ifaceRefs->getLength()
ifaceCount = ifaceRefs->getLength();
if (ifaceCount > 2)
return NULL;
srcIface = this->getIface (ifaceRefs->item(0));
dstIface = this->getIface (ifaceRefs->item(1));
if (ifaceCount != 2) {
ifaceCount = -1;
return vector<link_interface>();
}
struct link_interface srcIface
= this->getIface(dynamic_cast<DOMElement*>(ifaceRefs->item(0)));
struct link_interface dstIface
= this->getIface(dynamic_cast<DOMElement*>(ifaceRefs->item(1)));
pair<string, string> srcNodeIface;
pair<string, string> dstNodeIface;
if (this->rspecType == RSPEC_TYPE_ADVT)
{
srcNodeIface = make_pair(srcIface.physicalNodeId, srcIface.physicalIfaceId);
dstNodeIface = make_pair(dstIface.physicalNodeId, dstIface.physicalIfaceId);
}
else // (this->rspecType == RSPEC_TYPE_REQ)
{
srcNodeIface = make_pair(srcIface.virtualNodeId, srcIface.virtualIfaceId);
dstNodeIface = make_pair(dstIface.virtualNodeId, dstIface.virtualIfaceId);
}
return list<link_interface>(srcIface, dstIface)
vector<struct link_interface> rv;
// Check if the node-interface pair has been seen before.
// If it hasn't, it is an error
if ((this->ifacesSeen).find(srcNodeIface) == (this->ifacesSeen).end()
|| (this->ifacesSeen).find(dstNodeIface) == (this->ifacesSeen).end())
{
ifaceCount = -1;
return rv;
}
rv.push_back(srcIface);
rv.push_back(dstIface);
return rv;
}
#endif
\ No newline at end of file
#endif
......@@ -15,15 +15,19 @@
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <xercesc/dom/DOM.hpp>
#define RSPEC_TYPE_ADVT 0
#define RSPEC_TYPE_REQ 1
struct node_type
{
std::string typeName;
int typeCount;
int typeSlots;
bool isStatic;
};
......@@ -36,48 +40,67 @@ struct link_characteristics
struct link_interface
{
std::string srcNode;
std::string srcIface;
std::string dstNode;
std::string dstIface;
std::string virtualNodeId;
std::string virtualIfaceId;
std::string physicalNodeId;
std::string physicalIfaceId;
};
struct node_interface
{
std::string componentId;
std::string clientId;
};
class rspec_parser
{
private:
std::map<std::string, std::string> interfacesSeen;
protected:
bool getAttribute (const xercesc::DOMElement*, const std::string,
std::string&);
int rspecType;
std::set< std::pair<std::string, std::string> >ifacesSeen;
std::string getAttribute (const xercesc::DOMElement*, const std::string,
bool&);
bool hasAttribute (const xercesc::DOMElement*, const std::string);
struct link_interface getIface (const xercesc::DOMElement*);
public:
const int LINK_BANDWIDTH = 0;
const int LINK_LATENCY = 1;
const int LINK_PACKET_LOSS = 2;
rspec_parser () { }
rspec_parser(int type) { this->rspecType = type; }
// Common functions
virtual std::string readComponentId (const xercesc::DOMElement*, bool&);
virtual std::string readVirtualid (const xercesc::DOMElement*, bool&);
virtual std::string readPhysicalId (const xercesc::DOMElement*, bool&);
virtual std::string readVirtualId (const xercesc::DOMElement*, bool&);
virtual std::string readComponentManagerId (const xercesc::DOMElement*,
bool&);
// Reads subnode tag
virtual std::string readSubnodeOf (const xercesc::DOMElement*, bool&);
// Functions for nodes
virtual std::list<std::string>
readLocation(const xercesc::DOMElement*, int&);
virtual std::vector<std::string> readLocation(const xercesc::DOMElement*,
int&);
virtual std::list<struct node_type>
readNodeTypes (const xercesc::DOMElement*, int&);
virtual std::string readIfaceDecl (const xercesc::DOMElement*);
// Functions for links
virtual struct link_characteristics
readLinkCharacteristics (const xercesc::DOMElement*, int&);
readLinkCharacteristics (const xercesc::DOMElement*,
int defaultBandwidth,
int unlimitedBandwidth,
int&);
virtual std::vector< struct link_interface >
readLinkInterface (const xercesc::DOMElement*, int&);
virtual struct link_interface
readInterface (const xercesc::DOMElement*);
// Reads all the interfaces on a node
// Returns the number of interfaces found.
// This only populates the internal data structures of the object.
// Ideally, this ought to be done automatically, but in the current setup,
// there doesn't seem to be a clean way of making it happen.
virtual int readInterfacesOnNode (const xercesc::DOMElement*, bool&);
virtual void dummyFun();
};
......
......@@ -165,7 +165,7 @@ int rspec_parser_v1::readInterfacesOnNode (const DOMElement* node,
nodeId = this->readVirtualId (node, hasAttr);
ifaceId = XStr(iface->getAttribute(XStr("virtual_id").x())).c();
}
//cout << "(" << nodeId << "," << ifaceId << ")" << endl;
cout << "(" << nodeId << "," << ifaceId << ")" << endl;
allUnique &= ((this->ifacesSeen).insert
(pair<string, string>(nodeId, ifaceId))).second;
}
......
......@@ -19,18 +19,35 @@
#include <string>
#include <xercesc/dom/DOM.hpp>
struct node_interface_v1 : node_interface
{
std::string componentName;
};
class rspec_parser_v1 : public rspec_parser
{
// Functions specific to rspec version 1 should be declared here.
// Most of the functions needed to parse rspecs in general should
// already have been inherited from rspec parser
private:
std::string find_urn(const xercesc::DOMElement* element,
std::string const& prefix, bool&);
public:
std::string find_urn(const xercesc::DOMElement* element,
std::string const& prefix);
rspec_parser_v1 (int type) { this->rspecType = type; }
std::string readPhysicalId (const xercesc::DOMElement*, bool&);
std::string readVirtualId (const xercesc::DOMElement*, bool&);
std::string readComponentManagerId (const xercesc::DOMElement*, bool&);
int readInterfacesOnNode (const xercesc::DOMElement* node, bool& allUnique);
std::vector<struct link_interface> readLinkInterface
(const xercesc::DOMElement* link, int& ifaceCount);
struct link_interface getIface (const xercesc::DOMElement*);
void dummyFun ();
};
#endif
......
......@@ -215,12 +215,12 @@ int parse_fds_vnode_xml (const DOMElement *tag, node_fd_set *fd_set)
interface_spec parse_interface_rspec_xml(const DOMElement *tag)
{
interface_spec rv =
{
string(XStr(tag->getAttribute(XStr("virtual_node_id").x())).c()),
string(XStr(tag->getAttribute(XStr("virtual_interface_id").x())).c()),
string(XStr(find_urn(tag, "component_node"))),
string(XStr(tag->getAttribute(XStr("component_interface_id").x())).c())
};
{
string(XStr(tag->getAttribute(XStr("virtual_node_id").x())).c()),
string(XStr(tag->getAttribute(XStr("virtual_interface_id").x())).c()),
string(XStr(find_urn(tag, "component_node"))),
string(XStr(tag->getAttribute(XStr("component_interface_id").x())).c())
};
return rv;
}
......
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