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