Commit 01cb06e9 authored by Jonathon Duerig's avatar Jonathon Duerig

Assign now accepts _urn fields as well as _uuid fields. If no link_type is...

Assign now accepts _urn fields as well as _uuid fields. If no link_type is given, the type defaults to "ethernet". Fixed memory leak in xstr by changing its data structure.
parent 79519149
......@@ -4,7 +4,7 @@
* All rights reserved.
*/
static const char rcsid[] = "$Id: annotate_rspec.cc,v 1.5 2009-07-20 15:36:21 gtw Exp $";
static const char rcsid[] = "$Id: annotate_rspec.cc,v 1.6 2009-10-06 23:53:10 duerig Exp $";
#ifdef WITH_XML
......@@ -133,12 +133,15 @@ DOMElement* annotate_rspec::create_component_hop (const DOMElement* plink, DOMEl
{
// Find the destination of the previous component hop
DOMElement* prev_hop_dst_iface = dynamic_cast<DOMElement*>((prev_component_hop->getElementsByTagName(XStr("interface_ref").x()))->item(1));
XStr prev_hop_dst_uuid (prev_hop_dst_iface->getAttribute(XStr("component_node_uuid").x()));
XStr prev_hop_dst_uuid (find_urn(prev_hop_dst_iface,
"component_node"));
// We need to do this because in advertisements, all links are from nodes to switches
// and we need to reverse this order for the last hop of a multi-hop path
// This is slightly more expensive, but definitely more robust than checking based on whether a destination interface was specified
if (strcmp(prev_hop_dst_uuid.c(), XStr(plink_dst_iface->getAttribute(XStr("component_node_uuid").x())).c()) == 0)
if (strcmp(prev_hop_dst_uuid.c(),
XStr(find_urn(plink_dst_iface,
"component_node")).c()) == 0)
{
plink_src_iface_clone = dynamic_cast<DOMElement*>(doc->importNode(dynamic_cast<DOMNode*>(plink_dst_iface), true));
plink_dst_iface_clone = dynamic_cast<DOMElement*>(doc->importNode(dynamic_cast<DOMNode*>(plink_src_iface), true));
......@@ -170,9 +173,14 @@ void annotate_rspec::annotate_interface (const DOMElement* plink, DOMElement* vl
// Get the virtual_id on the end points of the interface
XStr vlink_iface_virtual_id (vlink_iface->getAttribute(XStr("virtual_node_id").x()));
DOMElement* vnode = getElementByAttributeValue(this->virtual_root, "node", "virtual_id", vlink_iface_virtual_id.c());
XStr node_component_uuid (vnode->getAttribute(XStr("component_uuid").x()));
XStr node_component_uuid (find_urn(vnode, "component"));
// XStr node_component_uuid (vnode->getAttribute(XStr("component_uuid").x()));
DOMElement* p_iface = getElementByAttributeValue(plink, "interface_ref", "component_node_uuid", node_component_uuid.c());
if (p_iface == NULL)
{
p_iface = getElementByAttributeValue(plink, "interface_ref", "component_node_urn", node_component_uuid.c());
}
vlink_iface->setAttribute(XStr("component_node_uuid").x(), p_iface->getAttribute(XStr("component_node_uuid").x()));
vlink_iface->setAttribute(XStr("component_interface_id").x(), p_iface->getAttribute(XStr("component_interface_id").x()));
......@@ -210,9 +218,12 @@ DOMElement* annotate_rspec::find_next_link_in_path (DOMElement *prev, list<const
for (it = links->begin(); it != links->end(); ++it)
{
link = (this->physical_elements->find(*it))->second;
XStr link_src(getNthInterface(link,0)->getAttribute(XStr("component_node_uuid").x()));
XStr link_dst(getNthInterface(link,1)->getAttribute(XStr("component_node_uuid").x()));
XStr prev_dst(getNthInterface(prev,1)->getAttribute(XStr("component_node_uuid").x()));
XStr link_src(find_urn(getNthInterface(link,0),
"component_node"));
XStr link_dst(find_urn(getNthInterface(link,1),
"component_node"));
XStr prev_dst(find_urn(getNthInterface(prev,1),
"component_node"));
if (strcmp(link_src.c(), prev_dst.c()) == 0 || strcmp(link_dst.c(), prev_dst.c()) == 0)
{
links->remove(*it);
......
......@@ -8,7 +8,7 @@
* XML Parser for RSpec ptop files
*/
static const char rcsid[] = "$Id: parse_request_rspec.cc,v 1.12 2009-07-20 15:36:21 gtw Exp $";
static const char rcsid[] = "$Id: parse_request_rspec.cc,v 1.13 2009-10-06 23:53:11 duerig Exp $";
#ifdef WITH_XML
......@@ -537,7 +537,11 @@ bool populate_links_rspec(DOMElement *root, tb_vgraph &vg) {
DOMElement *type_tag = dynamic_cast<DOMElement*>(type->item(0));
XStr link_type(type_tag->getAttribute(XStr("type_name").x()));
*/
XStr link_type(elt->getAttribute(XStr("link_type").x()));
string str_link_type(XStr(elt->getAttribute(XStr("link_type").x())).c());
if (str_link_type == "")
{
str_link_type = "ethernet";
}
/* ------------------- vtop stuff goes here --------------------------- */
......@@ -593,8 +597,8 @@ bool populate_links_rspec(DOMElement *root, tb_vgraph &vg) {
{
src_vnode->num_links++;
dst_vnode->num_links++;
src_vnode->link_counts[link_type.c()]++;
dst_vnode->link_counts[link_type.c()]++;
src_vnode->link_counts[str_link_type.c_str()]++;
dst_vnode->link_counts[str_link_type.c_str()]++;
}
/*
......@@ -605,7 +609,7 @@ bool populate_links_rspec(DOMElement *root, tb_vgraph &vg) {
tb_vlink *virt_link = new tb_vlink();
virt_link-> name = str_virtual_uuid;
virt_link-> type = link_type.f();
virt_link-> type = fstring(str_link_type.c_str());
virt_link-> fix_src_iface = fix_src_iface;
virt_link-> src_iface = (fixed_src_iface);//.f();
......
......@@ -206,7 +206,7 @@ interface_spec parse_interface_rspec_xml(const DOMElement *tag)
{
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("component_node_uuid").x())).c()),
string(XStr(find_urn(tag, "component_node"))),
string(XStr(tag->getAttribute(XStr("component_interface_id").x())).c())
};
return rv;
......@@ -214,21 +214,37 @@ interface_spec parse_interface_rspec_xml(const DOMElement *tag)
component_spec parse_component_spec (const DOMElement *elt) {
component_spec rv = {string(""), string(""), string(""), string("")};
rv.component_manager_uuid = string (XStr(elt->getAttribute(XStr("component_manager_uuid").x())).c());
rv.component_manager_uuid = string(XStr(find_urn(elt, "component_manager")));
if (elt->hasAttribute(XStr("component_name").x()))
rv.component_name = string (XStr(elt->getAttribute(XStr("component_name").x())).c());
rv.component_uuid = string (XStr(elt->getAttribute(XStr("component_uuid").x())).c());
rv.component_uuid = string(XStr(find_urn(elt, "component")));
if (elt->hasAttribute(XStr("sliver_uuid").x()))
rv.sliver_uuid = string (XStr(elt->getAttribute(XStr("sliver_uuid").x())).c());
return rv;
}
XMLCh const * find_urn(const xercesc::DOMElement* element,
string const & prefix)
{
string uuid = prefix + "_uuid";
string urn = prefix + "_urn";
if (element->hasAttribute(XStr(uuid.c_str()).x()))
{
return element->getAttribute(XStr(uuid.c_str()).x());
}
else //if (element->hasAttribute(XStr(urn.c_str()).x()))
{
return element->getAttribute(XStr(urn.c_str()).x());
}
}
// Check if the component spec is present. We check if the aggregate UUID and the component UUID are both present
bool hasComponentSpec (DOMElement* elt)
{
if (elt->hasAttribute(XStr("component_manager_uuid").x()) && elt->hasAttribute(XStr("component_uuid").x()))
return true;
return false;
return ((elt->hasAttribute(XStr("component_manager_uuid").x())
|| elt->hasAttribute(XStr("component_manager_urn").x()))
&& (elt->hasAttribute(XStr("component_uuid").x())
|| elt->hasAttribute(XStr("component_urn").x())));
}
#endif
......@@ -114,6 +114,13 @@ typedef struct interface_spec
*/
interface_spec parse_interface_rspec_xml (const xercesc::DOMElement* element);
/*
* Get the _uuid or _urn attribute value based on the prefix. If neither
* exists, return the empty string.
*/
XMLCh const * find_urn(xercesc::DOMElement const * element,
std::string const & prefix);
/*
* Check if the component spec is present. We check if the aggregate UUID and the component UUID are both present
*/
......
......@@ -28,26 +28,24 @@ XERCES_CPP_NAMESPACE_USE
*/
class XStr {
public:
XStr(const char *_str) : cstr(_str), cstr_mine(false), xmlstr(NULL),
xmlstr_mine(false) /*, fstr(NULL),
XStr(const char *_str) : cstr(_str), transcoded(NULL), xmlstr(NULL)
/*, fstr(NULL),
fstr_mine(false) */ { ; };
XStr(const XMLCh *_str) : cstr(NULL), cstr_mine(false), xmlstr(NULL),
xmlstr_mine(true) /*, fstr(NULL), fstr_mine(false) */ {
XStr(const XMLCh *_str) : cstr(NULL), transcoded(NULL), xmlstr(NULL)
/*, fstr(NULL), fstr_mine(false) */ {
xmlstr = XMLString::replicate(_str);
};
XStr(const fstring &_str) : /* fstr_mine(true), */ cstr_mine(false), xmlstr(NULL),
xmlstr_mine(false) {
XStr(const fstring &_str) : /* fstr_mine(true), */
transcoded(NULL), xmlstr(NULL) {
//fstr = new fstring(_str);
cstr = _str.c_str();
};
~XStr() {
if (cstr_mine && cstr != NULL) {
// XXX: This sure looks like a bug!
//XMLString::release(&cstr);
delete cstr;
if (transcoded != NULL) {
XMLString::release(&transcoded);
}
if (xmlstr_mine && xmlstr != NULL) {
if (xmlstr != NULL) {
XMLString::release(&xmlstr);
}
/*if (fstr_mine && fstr != NULL) {
......@@ -61,7 +59,6 @@ public:
const XMLCh *x() {
if (this->xmlstr == NULL) {
this->xmlstr = XMLString::transcode(this->cstr);
this->xmlstr_mine = true;
}
return this->xmlstr;
};
......@@ -71,8 +68,8 @@ public:
*/
const char *c() {
if (this->cstr == NULL) {
this->cstr = XMLString::transcode(this->xmlstr);
this->cstr_mine = true;
this->transcoded = XMLString::transcode(this->xmlstr);
this->cstr = this->transcoded;
}
return this->cstr;
};
......@@ -134,9 +131,8 @@ public:
private:
const char *cstr;
bool cstr_mine;
char * transcoded;
XMLCh *xmlstr;
bool xmlstr_mine;
/*
* Make the copy and assignment constructors private - I haven't decided
......
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