Commit db9d77f7 authored by Leigh B Stoller's avatar Leigh B Stoller

Merge in master after Taruns changes

parents dd427042 10c5face
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved.
#
SRCDIR = @srcdir@
......@@ -37,11 +37,11 @@ CXXFLAGS += -I/sw/include
ifeq ($(HAVE_XERCES),yes)
CXXFLAGS += -DWITH_XML
LIBS += -L/usr/local/lib -lxerces-c
OBJS += parse_ptop_xml.o parse_vtop_xml.o parse_policy_xml.o parse_error_handler.o xmlhelpers.o parse_advertisement_rspec.o parse_request_rspec.o annotate_rspec.o annotate_vtop.o annotate.o
OBJS += parse_ptop_xml.o parse_vtop_xml.o parse_policy_xml.o parse_error_handler.o xmlhelpers.o parse_advertisement_rspec.o parse_request_rspec.o annotate_rspec_v2.o annotate_rspec.o annotate_vtop.o annotate.o rspec_parser_helper.o rspec_parser.o rspec_parser_v1.o rspec_parser_v2.o emulab_extensions_parser.o
endif
# Pick either this
CXXFLAGS += -O3
CXXFLAGS += -O3
# or this
#CXXFLAGS += -O0 -g -Wall -DVERBOSE
# and then zero or more of these
......@@ -54,6 +54,10 @@ CXXFLAGS += -O3
# And then, regardless, you can also have this
#CXXFLAGS += -DSTATS
# This is added to disable link mapping while we figure out how to get assign
# to deal with interfaces on switches
#CXXFLAGS += -DDISABLE_LINK_ANNOTATION
# assign now supports a dizzing array of defines, which are as-yet undocumented
# Here are the ones used for a typical build:
# Pick cooling schedule
......@@ -114,12 +118,14 @@ anneal.o: anneal.cc anneal.h port.h delay.h physical.h common.h fstring.h \
solution.h vclass.h neighborhood.h
annotate.o: annotate.cc
annotate_rspec.o: annotate_rspec.cc
annotate_rspec_v2.o: annotate_rspec_v2.cc
annotate_vtop.o: annotate_vtop.cc
assign.o: assign.cc port.h common.h fstring.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h vclass.h pclass.h score.h \
solution.h maps.h anneal.h config.h
config.o: config.cc config.h common.h port.h fstring.h score.h physical.h \
delay.h featuredesire.h forwarding.h virtual.h anneal.h pclass.h
emulab_extensions_parser.o: emulab_extensions_parser.cc
featuredesire.o: featuredesire.cc featuredesire.h common.h port.h \
fstring.h score.h physical.h delay.h forwarding.h virtual.h
forwarding.o: forwarding.cc forwarding.h port.h fstring.h physical.h \
......@@ -143,6 +149,10 @@ parse_vtop_xml.o: parse_vtop_xml.cc
parser.o: parser.cc parser.h port.h
pclass.o: pclass.cc port.h common.h fstring.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h pclass.h
rspec_parser.o: rspec_parser.cc
rspec_parser_helper.o: rspec_parser_helper.cc
rspec_parser_v1.o: rspec_parser_v1.cc
rspec_parser_v2.o: rspec_parser_v2.cc
score.o: score.cc port.h common.h fstring.h vclass.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h pclass.h score.h
solution.o: solution.cc solution.h port.h delay.h physical.h common.h \
......
......@@ -13,6 +13,9 @@ static const char rcsid[] = "$Id: annotate.cc,v 1.2 2009-05-20 18:06:07 tarunp E
#ifdef WITH_XML
#include "annotate.h"
#include "common.h"
#include "xstr.h"
#include <string>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
......@@ -24,31 +27,80 @@ using namespace std;
void annotate::write_annotated_file (const char* filename)
{
// Get the current implementation
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(NULL);
// Construct the DOMWriter
DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
// Make the output look pretty
if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// Set the byte-order-mark feature
if (writer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
writer->setFeature(XMLUni::fgDOMWRTBOM, true);
// Construct the LocalFileFormatTarget
XMLFormatTarget *outputFile = new xercesc::LocalFileFormatTarget(filename);
// Serialize a DOMNode to the local file "<some-file-name>.xml"
writer->writeNode(outputFile, *dynamic_cast<DOMNode*>(this->virtual_root));
// Flush the buffer to ensure all contents are written
outputFile->flush();
// Release the memory
writer->release();
// Get the current implementation
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(NULL);
if (!impl) {
cout << "*** Could not create DOMImplementationRegistry" << endl;
exit(EXIT_FATAL);
}
// Construct the DOMWriter
DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
if (!writer) {
cout << "*** Could not create DOMWriter" << endl;
exit(EXIT_FATAL);
}
// Make the output look pretty
if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// Set the byte-order-mark feature
if (writer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
writer->setFeature(XMLUni::fgDOMWRTBOM, true);
// Set the XML declaration feature
if (writer->canSetFeature(XMLUni::fgDOMXMLDeclaration, true))
writer->setFeature(XMLUni::fgDOMXMLDeclaration, true);
// Construct the LocalFileFormatTarget
XMLFormatTarget *outputFile = new xercesc::LocalFileFormatTarget(filename);
if (!outputFile) {
cout << "*** Could not create output file " << filename << endl;
exit(EXIT_FATAL);
}
if (!(this->document)) {
cout << "*** INTERNAL ERROR: this->document was NULL" << endl;
exit(EXIT_FATAL);
}
// Serialize a DOMNode to the local file "<some-file-name>.xml"
writer->writeNode(outputFile, *(this->virtual_root));
// Flush the buffer to ensure all contents are written
outputFile->flush();
// Release the memory
writer->release();
}
string annotate::printXML (const DOMElement* input)
{
DOMElement* tag = (DOMElement*)(input);
// Get the current implementation
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(NULL);
// Construct the DOMWriter
DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
// Make the output look pretty
if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// Set the byte-order-mark feature
if (writer->canSetFeature(XMLUni::fgDOMWRTBOM, true))
writer->setFeature(XMLUni::fgDOMWRTBOM, true);
// Serialize a DOMNode to the local file "<some-file-name>.xml"
string rv = XStr(writer->writeToString(*dynamic_cast<DOMNode*>(tag))).c();
// Release the memory
writer->release();
return rv;
}
#endif
......@@ -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,38 @@
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* document;
xercesc::DOMElement* physical_root;
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);
// Writes an XML element to a string
std::string printXML (const xercesc::DOMElement* tag);
};
#endif // for __ANNOTATE_H
......
This diff is collapsed.
......@@ -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
virtual void annotate_element(const char* v_name, const char* p_name);
// Annotates intraswitch and interswitch links in the rspec
virtual void annotate_element(const char* v_name,
std::list<const char*>* links);
// Annotate a trivial link
virtual void annotate_element(const char* v_name);
// Annotates an interface element on a link
virtual 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
virtual void annotate_interface (const xercesc::DOMElement* plink,
const xercesc::DOMElement* vlink,
int interface_number);
// Annotates an interface element on a trivial link
virtual 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
virtual 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
virtual 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
virtual 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
virtual 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
virtual void copy_component_spec(const xercesc::DOMElement* src,
xercesc::DOMElement* dst);
// Copies the component hop from the auto-generated link
// to the requested link
virtual void copy_component_hop(xercesc::DOMElement* requested_link,
xercesc::DOMElement* component_hop);
// Checks if the link contains an interface with
// virtual_interface_id = id
virtual bool has_interface_with_id (std::string link_id, std::string id);
// Removes all extra tags and generated elements from the XML document
virtual void cleanup ();
// Checks whether an element of type tag
// with attr_name = attr_value is a generated element
virtual 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 "annotate_rspec.h"
#include <list>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <xercesc/dom/DOM.hpp>
class annotate_rspec_v2 : public annotate_rspec
{
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;
std::map< std::string, std::string >* vInterfaceMap;
std::map< std::string, std::string >* pInterfaceMap;
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);
// 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);
// Given an interface Id, returns the node on which the interface is present
std::string lookupIface (std::map<std::string, std::string>* map,
std::string ifaceId, bool&);
// Returns the interface on the physical link
// which is declared on the physical node with component_id, physNodeId
const xercesc::DOMElement*
getIfaceOnNode(const xercesc::DOMElement* plink, std::string physNodeId);
// Retuns the component id of the nth interface of a link
std::string getNthInterface (const xercesc::DOMElement* link, int n);
// Annotates the end point of a link
bool annotate_endpoint(xercesc::DOMElement* iface, std::string virtId);
// Extracts the short interface name from the interface URN
std::string getShortInterfaceName (std::string interfaceURN);
// Adds a fixed interface element to an interface
void addFixedInterface(xercesc::DOMElement* interface,std::string shortname);
// Orders the links in the specified list of links from head to tail
// The first element in the list MUST be the head
// WARNING: This will destroy in the input list
std::list<const char*>* reorderLinks (std::list<const char*>* links);
};
#endif //for __ANNOTATE_RSPEC_H
#endif // for WITH_XML
......@@ -187,9 +187,10 @@ void read_physical_topology(char *filename) {
#ifdef WITH_XML
if (ptop_xml_input) {
cout << "Physical Graph: " << parse_ptop_xml(PG,SG,filename) << endl;
} else if (ptop_rspec_input) {
cout << "Physical Graph: " << parse_ptop_rspec (PG, SG, filename) << endl;
cout << "Physical Graph: " << parse_ptop_xml(PG,SG,filename) << endl;
}
else if (ptop_rspec_input) {
cout << "Physical Graph: " << parse_advertisement(PG, SG, filename) << endl;
}
else {
cout << "Physical Graph: " << parse_ptop(PG,SG,ptopfile) << endl;
......@@ -310,7 +311,7 @@ void read_virtual_topology(char *filename) {
cout << "Virtual Graph: " << parse_vtop_xml(VG,filename) << endl;
}
else if (vtop_rspec_input){
cout << "Virtual Graph: " << parse_vtop_rspec (VG, filename) << endl ;
cout << "Virtual Graph: " << parse_request (VG, filename) << endl;
}
else {
cout << "Virtual Graph: " << parse_top(VG,topfile) << endl;
......
......@@ -16,6 +16,7 @@
#ifdef NEW_GCC
#include <ext/hash_map>
#include <ext/hash_fun.h>
using namespace __gnu_cxx;
#define RANDOM() random()
#else
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2008, 2009 University of Utah and the Flux Group.
* All rights reserved.
*/