Commit 09cdc850 authored by Tarun Prabhu's avatar Tarun Prabhu

Per Jon's suggestion, removed all suspicious XStr references and

pointers not copied from the values returned by XStr. To test if this
was the cause of the memory corruption, the "fix" of performing a deep
copy of the virtual root before annotating. If this doesn't work,
re-enabling the fix should be easy enough.
parent fd697af0
This diff is collapsed.
......@@ -44,6 +44,7 @@ annotate_rspec_v2 :: annotate_rspec_v2 ()
{
this->document = doc;
this->virtual_root = request_root;
// this->virtual_root = dynamic_cast<DOMElement*>(dynamic_cast<DOMNode*>(request_root)->cloneNode(true));
this->physical_root = advt_root;
this->physical_elements = advertisement_elements;
......@@ -64,7 +65,7 @@ annotate_rspec_v2 :: annotate_rspec_v2 ()
set<string> virtual_interface_ids;
DOMNodeList* interfaces
= lan_link->getElementsByTagName(XStr("interface_ref").x());
for (int j = 0; j < interfaces->getLength(); j++) {
for (unsigned int j = 0; j < interfaces->getLength(); j++) {
DOMElement* interface = dynamic_cast<DOMElement*>(interfaces->item(j));
virtual_interface_ids.insert
(string(XStr(interface->getAttribute
......@@ -86,8 +87,8 @@ void annotate_rspec_v2::annotate_element (const char* v_name)
"link", "client_id", v_name);
annotate_interface (vlink, 0);
annotate_interface (vlink, 1);
DOMElement* hop = create_component_hop(vlink);
#ifndef DISABLE_LINK_ANNOTATION
DOMElement* hop = create_component_hop(vlink);
vlink->appendChild(hop);
#endif
}
......@@ -156,7 +157,7 @@ annotate_rspec_v2::annotate_element (const char* v_name, const char* p_name)
// This is called when an intraswitch or interswitch link has to be annotated
void annotate_rspec_v2::annotate_element (const char* v_name,
list<const char*>* links)
list<const char*>* links)
{
// We can't locate interfaces on the switches, so we don't add those
// to the annotation. The warning is only given the one time
......@@ -227,13 +228,6 @@ DOMElement* annotate_rspec_v2::create_component_hop (DOMElement* vlink)
string srcIfaceNodeId =this->lookupIface(this->vInterfaceMap,srcIfaceId,fnd);
string dstIfaceNodeId =this->lookupIface(this->vInterfaceMap,dstIfaceId,fnd);
DOMElement* srcVnode
= getElementByAttributeValue(this->virtual_root,
"node", "client_id", srcIfaceNodeId.c_str());
DOMElement* dstVnode
= getElementByAttributeValue(this->virtual_root,
"node", "client_id", dstIfaceNodeId.c_str());
DOMElement* srcIfaceClone
= dynamic_cast<DOMElement*>(doc->importNode
(dynamic_cast<DOMNode*>(srcIface),true));
......@@ -379,7 +373,7 @@ void annotate_rspec_v2::copy_component_hop(DOMElement* lan_link,
= string(XStr(lan_link->getAttribute(XStr("client_id").x())).c());
DOMNodeList* interfaces
= component_hop->getElementsByTagName(XStr("interface_ref").x());
for (int i = 0; i < interfaces->getLength(); i++) {
for (unsigned int i = 0; i < interfaces->getLength(); i++) {
DOMElement* interface = dynamic_cast<DOMElement*>(interfaces->item(i));
if (interface->hasAttribute(XStr("virtual_interface_id").x())) {
string str_virtual_interface_id
......@@ -621,12 +615,11 @@ string annotate_rspec_v2::getNodeForNthInterface (const DOMElement* link,
DOMNodeList* ifaces = link->getElementsByTagName(XStr("interface_ref").x());
if (ifaces->getLength() < number) {
cerr << "*** Link "
<< XStr(link->getAttribute(XStr("component_id").x())).c()
<< " has only " << ifaces->getLength() << " interfaces. "
<< "Interface number " << number << " requested." << endl;
<< XStr(link->getAttribute(XStr("component_id").x())).c()
<< " has only " << ifaces->getLength() << " interfaces. "
<< "Interface number " << number << " requested." << endl;
exit(EXIT_FATAL);
}
DOMElement* iface = dynamic_cast<DOMElement*>(ifaces->item(number));
string ifaceId = XStr(link->getAttribute(XStr("component_id").x())).c();
return (this->lookupIface(this->pInterfaceMap, ifaceId, found));
}
......
......@@ -37,7 +37,7 @@ emulab_extensions_parser::readFeaturesDesires (const DOMElement* ele, int& count
vector<struct fd> fds;
DOMNodeList* fdNodes = ele->getElementsByTagName(XStr("emulab:fd").x());
count = fdNodes->getLength();
for (int i = 0; i < fdNodes->getLength(); i++) {
for (unsigned int i = 0; i < fdNodes->getLength(); i++) {
fds.push_back(this->readFeatureDesire
(dynamic_cast<DOMElement*>(fdNodes->item(i))));
}
......@@ -61,7 +61,7 @@ vector<struct property> emulab_extensions_parser::readProperties
{
DOMNodeList* propNodes = elem->getElementsByTagName(XStr("property").x());
vector<struct property> properties;
for (int i = 0; i < propNodes->getLength(); i++) {
for (unsigned int i = 0; i < propNodes->getLength(); i++) {
properties.push_back(this->readProperty
(dynamic_cast<DOMElement*>(propNodes->item(i))));
}
......@@ -102,7 +102,7 @@ emulab_extensions_parser::readVClasses (const DOMElement* elem)
DOMNodeList* vclassNodes
= elem->getElementsByTagName(XStr("emulab:vclass").x());
vector<struct vclass> vclasses;
for (int i = 0; i < vclassNodes->getLength(); i++) {
for (unsigned int i = 0; i < vclassNodes->getLength(); i++) {
vclasses.push_back(this->readVClass
(dynamic_cast<DOMElement*>
(vclassNodes->item(i))));
......@@ -116,7 +116,7 @@ emulab_extensions_parser::readVClass (const DOMElement* tag)
vector<string> physTypes;
DOMNodeList* physNodes
= tag->getElementsByTagName(XStr("emulab:physical_type").x());
for (int i = 0; i < physNodes->getLength(); i++) {
for (unsigned int i = 0; i < physNodes->getLength(); i++) {
DOMElement* physNode = dynamic_cast<DOMElement*>(physNodes->item(i));
// XXX: This is nasty because the type name that we give assign
// has to be the concatation of the hardware type and sliver type
......
......@@ -149,7 +149,6 @@ int parse_advertisement(tb_pgraph &pg, tb_sgraph &sg, char *filename) {
}
XMLDEBUG("Found rspec ver. " << rspecVersion << endl);
bool is_physical;
string type = XStr(advt_root->getAttribute(XStr("type").x())).c();
if (type != "advertisement") {
cout << "*** Rspec type must be \"advertisement\" in " << filename
......@@ -215,7 +214,6 @@ bool populate_nodes(DOMElement *root,
XMLDEBUG("Found " << nodeCount << " nodes in rspec" << endl);
int availableCount = 0;
int counter = 0;
for (size_t i = 0; i < nodeCount; i++) {
DOMNode *node = nodes->item(i);
// This should not be able to fail, because all elements in
......@@ -273,7 +271,6 @@ bool populate_nodes(DOMElement *root,
int typeCount;
vector<struct node_type>types = rspecParser->readNodeTypes(elt, typeCount);
bool switchAdded = false;
for (int i = 0; i < typeCount; i++) {
node_type type = types[i];
string typeName = type.typeName;
......
......@@ -288,7 +288,6 @@ bool populate_node(DOMElement* elt,
ptypes[typeName_c] = new tb_ptype(typeName_c);
}
ptypes[typeName_c]->add_slots(typeSlots);
tb_ptype *ptype = ptypes[typeName_c];
name_vclass_map::iterator dit = vclass_map.find(fstring(typeName.c_str()));
if (dit != vclass_map.end()) {
......@@ -537,8 +536,8 @@ bool populate_link (DOMElement* elt,
list<DOMElement*>::iterator it = links.begin();
for (int i = 0; i < ifaceCount; ++i) {
link_interface interface = interfaces[i];
const XMLCh* virtualIfaceId = XStr(interface.virtualIfaceId.c_str()).x();
const XMLCh* virtualNodeId = XStr(interface.virtualNodeId.c_str()).x();
string virtualIfaceId = XStr(interface.virtualIfaceId.c_str()).c();
string virtualNodeId = XStr(interface.virtualNodeId.c_str()).c();
string str_lan_interface_id = generate_virtualIfaceId(str_lan_id, i);
DOMElement* lan_interface = doc->createElement(XStr("interface").x());
......@@ -550,8 +549,8 @@ bool populate_link (DOMElement* elt,
DOMElement* link = doc->createElement(XStr("link").x());
request_root->appendChild(link);
link->setAttribute(XStr("virtual_id").x(),
XStr(interface.virtualNodeId
+ string(":") + str_lan_id).x());
XStr(interface.virtualNodeId
+ string(":") + str_lan_id).x());
appendChildTagWithData(link, "bandwidth",
rspecParser->numToString(bandwidth).c_str());
appendChildTagWithData(link, "latency",
......@@ -560,23 +559,23 @@ bool populate_link (DOMElement* elt,
rspecParser->numToString(packetLoss).c_str());
DOMElement* src_interface_ref
= doc->createElement(XStr("interface_ref").x());
= doc->createElement(XStr("interface_ref").x());
src_interface_ref->setAttribute(XStr("clientId").x(),
virtualIfaceId);
XStr(virtualIfaceId.c_str()).x());
link->appendChild(src_interface_ref);
DOMElement* dst_interface_ref
= doc->createElement(XStr("interface_ref").x());
= doc->createElement(XStr("interface_ref").x());
dst_interface_ref->setAttribute(XStr("clientId").x(),
XStr(str_lan_interface_id.c_str()).x());
XStr(str_lan_interface_id.c_str()).x());
link->appendChild(dst_interface_ref);
// Adding attributes to ensure that the element is handled
// correctly during annotation.
link->setAttribute(XStr("generated_by_assign").x(),
XStr("true").x());
XStr("true").x());
link->setAttribute(XStr("lan_link").x(),
XStr(virtualId.c_str()).x());
XStr(virtualId.c_str()).x());
links.insert(it, link);
}
......@@ -780,7 +779,7 @@ DOMElement* appendChildTagWithData (DOMElement* parent,
string generate_virtualNodeId (string virtual_id)
{
std::ostringstream oss;
ostringstream oss;
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
......@@ -790,7 +789,7 @@ string generate_virtualNodeId (string virtual_id)
string generate_virtualIfaceId (string lan_name, int interface_number)
{
std::ostringstream oss;
ostringstream oss;
oss << lan_name << ":" << interface_number;
return oss.str();
}
......
......@@ -33,7 +33,6 @@ rspec_parser :: ~rspec_parser ()
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()),
......@@ -109,7 +108,7 @@ vector<struct node_type> rspec_parser::readNodeTypes (const DOMElement* node,
bool isSwitch = false;
DOMNodeList* nodeTypes = node->getElementsByTagName(XStr("node_type").x());
vector<struct node_type> types;
for (int i = 0; i < nodeTypes->getLength(); i++) {
for (unsigned int i = 0; i < nodeTypes->getLength(); i++) {
DOMElement *tag = dynamic_cast<DOMElement*>(nodeTypes->item(i));
string typeName = XStr(tag->getAttribute(XStr("type_name").x())).c();
......@@ -143,32 +142,32 @@ rspec_parser::readInterfacesOnNode (const DOMElement* node,
DOMNodeList* ifaces = node->getElementsByTagName(XStr("interface").x());
map< pair<string, string>, pair<string, string> > fixedInterfaces;
allUnique = true;
for (int i = 0; i < ifaces->getLength(); i++)
for (unsigned 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();
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();
if (iface->hasAttribute(XStr("component_id").x())) {
bool hasComponentId;
string componentNodeId =
this->readPhysicalId (node, hasComponentId);
string componentIfaceId =
this->getAttribute(iface, "component_id");
fixedInterfaces.insert (make_pair
(make_pair(nodeId,ifaceId),
make_pair(componentNodeId,componentIfaceId)));
}
nodeId = this->readVirtualId (node, hasAttr);
ifaceId = XStr(iface->getAttribute(XStr("client_id").x())).c();
if (iface->hasAttribute(XStr("component_id").x())) {
bool hasComponentId;
string componentNodeId =
this->readPhysicalId (node, hasComponentId);
string componentIfaceId =
this->getAttribute(iface, "component_id");
fixedInterfaces.insert (make_pair
(make_pair(nodeId,ifaceId),
make_pair(componentNodeId,componentIfaceId)));
}
}
allUnique &= ((this->ifacesSeen).insert
(pair<string, string>(nodeId, ifaceId))).second;
(pair<string, string>(nodeId, ifaceId))).second;
}
return (fixedInterfaces);
}
......@@ -177,9 +176,9 @@ rspec_parser::readInterfacesOnNode (const DOMElement* node,
// count should be 1 on success.
struct link_characteristics
rspec_parser :: readLinkCharacteristics (const DOMElement* link,
int& count,
int defaultBandwidth,
int unlimitedBandwidth)
int& count,
int defaultBandwidth,
int unlimitedBandwidth)
{
bool hasBandwidth, hasLatency, hasPacketLoss;
string strBw = this->readChild(link, "bandwidth", hasBandwidth);
......@@ -253,7 +252,7 @@ vector<struct link_type> rspec_parser::readLinkTypes (const DOMElement* link,
{
DOMNodeList* linkTypes = link->getElementsByTagName(XStr("link_type").x());
vector<struct link_type> types;
for (int i = 0; i < linkTypes->getLength(); i++) {
for (unsigned int i = 0; i < linkTypes->getLength(); i++) {
DOMElement *tag = dynamic_cast<DOMElement*>(linkTypes->item(i));
string name = XStr(tag->getAttribute(XStr("name").x())).c();
......
......@@ -136,41 +136,40 @@ map< pair<string, string>, pair<string, string> >
rspec_parser_v1::readInterfacesOnNode (const DOMElement* node,
bool& allUnique)
{
bool exists;
DOMNodeList* ifaces = node->getElementsByTagName(XStr("interface").x());
map< pair<string, string>, pair<string, string> > fixedInterfaces;
allUnique = true;
for (int i = 0; i < ifaces->getLength(); i++) {
for (unsigned 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();
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("virtual_id").x())).c();
if (iface->hasAttribute(XStr("component_id").x())) {
bool hasComponentId;
string componentNodeId = this->readPhysicalId (node, hasComponentId);
string componentIfaceId = this->getAttribute(iface, "component_id");
fixedInterfaces.insert (make_pair
(make_pair(nodeId,ifaceId),
make_pair(componentNodeId,
componentIfaceId)));
}
nodeId = this->readVirtualId (node, hasAttr);
ifaceId = XStr(iface->getAttribute(XStr("virtual_id").x())).c();
if (iface->hasAttribute(XStr("component_id").x())) {
bool hasComponentId;
string componentNodeId = this->readPhysicalId (node, hasComponentId);
string componentIfaceId = this->getAttribute(iface, "component_id");
fixedInterfaces.insert (make_pair
(make_pair(nodeId,ifaceId),
make_pair(componentNodeId,
componentIfaceId)));
}
}
//cout << "(" << nodeId << "," << ifaceId << ")" << endl;
allUnique &= ((this->ifacesSeen).insert
(pair<string, string>(nodeId, ifaceId))).second;
(pair<string, string>(nodeId, ifaceId))).second;
}
return fixedInterfaces;
}
string rspec_parser_v1 :: readSubnodeOf (const DOMElement* tag,
bool& isSubnode,
bool& isSubnode,
int& count)
{
count = (tag->getElementsByTagName(XStr("subnode_of").x()))->getLength();
......
......@@ -143,7 +143,7 @@ rspec_parser_v2::readNodeTypes (const DOMElement* node,
return vector<struct node_type>();
}
for (int j = 0; j < sliverTypes->getLength(); j++) {
for (unsigned int j = 0; j < sliverTypes->getLength(); j++) {
DOMElement* slNode = dynamic_cast<DOMElement*>(sliverTypes->item(j));
string slTypeName = this->getAttribute(slNode, "name");
string typeName = this->convertType(defHw, slTypeName);
......@@ -152,7 +152,7 @@ rspec_parser_v2::readNodeTypes (const DOMElement* node,
}
}
for (int i = 0; i < hardwareTypes->getLength(); i++) {
for (unsigned int i = 0; i < hardwareTypes->getLength(); i++) {
DOMElement* hardwareNode
= dynamic_cast<DOMElement*>(hardwareTypes->item(i));
......@@ -186,7 +186,7 @@ rspec_parser_v2::readNodeTypes (const DOMElement* node,
types.push_back(type);
}
for (int j = 0; j < sliverTypes->getLength(); j++) {
for (unsigned int j = 0; j < sliverTypes->getLength(); j++) {
DOMElement* slNode = dynamic_cast<DOMElement*>(sliverTypes->item(j));
string slTypeName = this->getAttribute(slNode, "name");
string typeName = this->convertType(hwTypeName, slTypeName);
......@@ -211,7 +211,7 @@ rspec_parser_v2::readInterfacesOnNode (const DOMElement* node,
DOMNodeList* ifaces = node->getElementsByTagName(XStr("interface").x());
map< pair<string, string>, pair<string, string> > fixedInterfaces;
allUnique = true;
for (int i = 0; i < ifaces->getLength(); i++) {
for (unsigned int i = 0; i < ifaces->getLength(); i++) {
DOMElement* iface = dynamic_cast<DOMElement*>(ifaces->item(i));
bool hasAttr;
string nodeId = "";
......@@ -261,7 +261,7 @@ rspec_parser_v2::readLinkTypes (const DOMElement* link, int& typeCount)
{
DOMNodeList* linkTypes = link->getElementsByTagName(XStr("link_type").x());
vector<struct link_type> types;
for (int i = 0; i < linkTypes->getLength(); i++) {
for (unsigned int i = 0; i < linkTypes->getLength(); i++) {
DOMElement* tag = dynamic_cast<DOMElement*>(linkTypes->item(i));
string name = this->getAttribute(tag, "name");
......@@ -279,7 +279,7 @@ string rspec_parser_v2::readSubnodeOf (const DOMElement* node,
int cnt = 0;
string parent = "";
DOMNodeList* relations = node->getElementsByTagName(XStr("relations").x());
for (int i = 0, cnt = 0; i < relations->getLength(); i++) {
for (unsigned int i = 0, cnt = 0; i < relations->getLength(); i++) {
DOMElement* relation = dynamic_cast<DOMElement*>(relations->item(0));
string type = this->getAttribute(node, "type");
if (type == "parent") {
......
......@@ -82,18 +82,17 @@ void print_solution(const solution &s) {
cout << "unassigned: " << vn->name << endl;
} else {
#ifdef WITH_XML
const char* node_name = XStr(vn -> name).c();
const char* assigned_to
= XStr (get(pvertex_pmap,s.get_assignment(*vit))->name).c() ;
string node_name = XStr(vn -> name).c();
string assigned_to =XStr(get(pvertex_pmap,s.get_assignment(*vit))->name).c();
if (both_inputs_rspec) {
rspec_annotater->annotate_element(node_name, assigned_to);
if (rspec_annotater->is_generated_element("node",
"virtual_id",
node_name))
rspec_annotater->annotate_element(node_name.c_str(), assigned_to.c_str());
if (rspec_annotater->is_generated_element("node", "virtual_id",
node_name.c_str())) {
continue;
}
}
else if (both_inputs_xml) {
vtop_annotater->annotate_element(node_name, assigned_to);
vtop_annotater->annotate_element(node_name.c_str(), assigned_to.c_str());
}
#endif
cout << vn->name << " "
......
......@@ -36,7 +36,7 @@ void setChildValue(const DOMElement* parent, const char* tag, const char* value)
DOMElement* getNodeByName (const DOMElement *root, const char* name)
{
DOMNodeList *list = root -> getElementsByTagName(XStr("node").x());
for (int i = 0; i < list -> getLength() ; ++i)
for (unsigned int i = 0; i < list -> getLength() ; ++i)
{
DOMElement *ele = dynamic_cast<DOMElement*>(list->item(i));
if (strcmp(XStr(ele->getAttribute(XStr("name").x())).c(),name) == 0)
......@@ -48,7 +48,7 @@ DOMElement* getNodeByName (const DOMElement *root, const char* name)
DOMElement* getElementByAttributeValue (const DOMElement* root, const char* tag, const char* attribute_name, const char* attribute_value)
{
DOMNodeList *list = root -> getElementsByTagName(XStr(tag).x());
for (int i = 0; i < list -> getLength() ; ++i)
for (unsigned int i = 0; i < list -> getLength() ; ++i)
{
DOMElement *ele = dynamic_cast<DOMElement*>(list->item(i));
if (strcmp(XStr(ele->getAttribute(XStr(attribute_name).x())).c(),attribute_value) == 0)
......@@ -62,7 +62,7 @@ DOMElement* getElementByAttributeValue (vector<const DOMElement*> roots, const c
for (vector<const DOMElement*>::iterator it = roots.begin(); it != roots.end(); ++it)
{
DOMNodeList *list = (*it)->getElementsByTagName(XStr(tag).x());
for (int i = 0; i < list -> getLength() ; ++i)
for (unsigned int i = 0; i < list -> getLength() ; ++i)
{
DOMElement *ele = dynamic_cast<DOMElement*>(list->item(i));
if (strcmp(XStr(ele->getAttribute(XStr(attribute_name).x())).c(),attribute_value) == 0)
......@@ -76,7 +76,7 @@ vector<const DOMElement*> getElementsByAttributeValue (const DOMElement* root, c
{
DOMNodeList *list = root -> getElementsByTagName(XStr(tag).x());
vector<const DOMElement*> elements;
for (int i = 0; i < list -> getLength() ; ++i)
for (unsigned int i = 0; i < list -> getLength() ; ++i)
{
DOMElement *ele = dynamic_cast<DOMElement*>(list->item(i));
if (strcmp(XStr(ele->getAttribute(XStr(attribute_name).x())).c(),attribute_value) == 0)
......@@ -89,7 +89,7 @@ vector<DOMElement*> getElementsHavingAttribute(const DOMElement* root, const cha
{
DOMNodeList* list = root->getElementsByTagName(XStr(tag).x());
vector<DOMElement*> elements;
for (int i = 0; i < list->getLength(); ++i)
for (unsigned int i = 0; i < list->getLength(); ++i)
{
DOMElement* ele = dynamic_cast<DOMElement*>(list->item(i));
if (ele->hasAttribute(XStr(attribute_name).x()))
......
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