Commit df603900 authored by Tarun Prabhu's avatar Tarun Prabhu

Modified the command line parameters to accept a format for the ptop/vtop

files. The rspec version  passed from the command line isn't being used right
now and the schema is validated against that provided in the schemaLocation tag in
the XML document. This is a bad idea and we should figure out a clean way of e
nsuring that we don't get passed nasty XMLs.
parent e4173cfa
......@@ -446,17 +446,19 @@ void print_help() {
cout << " -n - Don't anneal - just do the prechecks." << endl;
cout << " -x <file> - Specify a text ptop file" << endl;
#ifdef WITH_XML
cout << " -X <file> - Specify a XML ptop file" << endl;
#endif
// #ifdef WITH_XML
// cout << " -X <file> - Specify a XML ptop file" << endl;
// #endif
cout << " -y <file> - Specify a text top file" << endl;
// #ifdef WITH_XML
// cout << " -Y <file> - Specify a XML vtop file" << endl;
// #endif
#ifdef WITH_XML
cout << " -Y <file> - Specify a XML vtop file" << endl;
#endif
#ifdef WITH_XML
cout << " -q <file> - Specify a rspec ptop file" << endl;
cout << " -w <file> - Specify a rspec vtop file" << endl;
// cout << " -q <file> - Specify a rspec ptop file" << endl;
// cout << " -w <file> - Specify a rspec vtop file" << endl;
cout << " -W <file> - Specify the output rspec file" << endl;
cout << " -f <T>[/<T>] - Specify the ptop and vtop file formats ";
cout << "(text|xml|rspec-<ver>)" << endl;
#endif
cout << " -F - Apply additional checking to fixed nodes" << endl;
cout << " -D - Dump configuration options" << endl;
......@@ -851,7 +853,11 @@ int main(int argc,char **argv) {
char* vtopFilename = "";
char* vtopOutputFilename = 0;
while ((ch = getopt(argc,argv,"s:v:l:t:rpPTdH:oguc:nx:X:y:Y:q:w:W:FD")) != -1) {
const char* delims = "/";
char* ptopFileFormat = "";
char* vtopFileFormat = "";
while ((ch = getopt(argc,argv,"s:v:l:t:rpPTdH:oguc:nx:y:W:FDf:")) != -1) {
switch (ch) {
case 's':
if (sscanf(optarg,"%d",&seed) != 1) {
......@@ -918,15 +924,15 @@ int main(int argc,char **argv) {
dump_config = true;
break;
case 'x':
#ifdef WITH_XML
/*#ifdef WITH_XML
ptop_xml_input = false;
#endif
#endif*/
if (strcmp(optarg, "") == 0) {
print_help();
}
ptopFilename = optarg;
break;
#ifdef WITH_XML
/*#ifdef WITH_XML
case 'X':
ptop_xml_input = true;
if (strcmp(optarg, "") == 0) {
......@@ -934,51 +940,92 @@ int main(int argc,char **argv) {
}
ptopFilename = optarg;
break;
#endif
#endif*/
case 'y':
#ifdef WITH_XML
/*#ifdef WITH_XML
vtop_xml_input = false;
#endif
#endif*/
if (strcmp(optarg, "") == 0) {
print_help();
}
vtopFilename = optarg;
break;
// #ifdef WITH_XML
// case 'Y':
// vtop_xml_input = true;
// if (strcmp(optarg, "") == 0) {
// print_help();
// }
// vtopFilename = optarg;
// break;
// #endif
// #ifdef WITH_XML
// case 'q':
// ptop_rspec_input = true;
// if (strcmp(optarg, "") == 0) {
// print_help();
// }
// ptopFilename = optarg;
// break;
//
// case 'w':
// vtop_rspec_input = true;
// if (strcmp(optarg, "") == 0) {
// print_help();
// }
// vtopFilename = optarg;
// break;
#ifdef WITH_XML
case 'Y':
vtop_xml_input = true;
case 'W':
if (strcmp(optarg, "") == 0) {
print_help();
}
vtopFilename = optarg;
vtopOutputFilename = optarg;
break;
#endif
#ifdef WITH_XML
case 'q':
ptop_rspec_input = true;
if (strcmp(optarg, "") == 0) {
print_help();
}
ptopFilename = optarg;
case 'F':
check_fixed_nodes = true;
break;
case 'w':
vtop_rspec_input = true;
case 'f':
if (strcmp(optarg, "") == 0) {
print_help();
}
vtopFilename = optarg;
break;
case 'W':
if (strcmp(optarg, "") == 0) {
print_help();
ptopFileFormat = strtok(optarg, delims);
vtopFileFormat = strtok(NULL, delims);
if (strcmp(ptopFileFormat, "text") == 0) {
ptop_xml_input = false;
}
#ifdef WITH_XML
else if (strstr(ptopFileFormat, "rspec") != NULL) {
ptop_rspec_input = true;
}
else {
ptop_xml_input = true;
}
vtopOutputFilename = optarg;
break;
#endif
case 'F':
check_fixed_nodes = true;
if (vtopFileFormat == NULL)
{
vtop_xml_input = ptop_xml_input;
vtop_rspec_input = ptop_rspec_input;
}
else
{
if (strcmp(vtopFileFormat, "text") == 0) {
vtop_xml_input = false;
}
#ifdef WITH_XML
else if (strstr(vtopFileFormat, "rspec") != NULL) {
vtop_rspec_input = true;
}
else {
vtop_xml_input = true;
}
#endif
}
break;
default:
......
......@@ -86,21 +86,16 @@ int parse_ptop_rspec(tb_pgraph &pg, tb_sgraph &sg, char *filename) {
/*
* Enable some of the features we'll be using: validation, namespaces, etc.
*/
/* XXX: The schema to validate against is specificed in the xml document
* This could lead to security problems. There are some ways around it,
* but they aren't exactly elegant. But we do need to take care of it at
* some point
*/
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
/*
* Must validate against the ptop schema
*/
parser -> setExternalSchemaLocation ("http://www.protogeni.net/resources/rspec/0.1 " SCHEMA_LOCATION);
/*
* Just use a custom error handler - must admin it's not clear to me why
* we are supposed to use a SAX error handler for this, but this is what
* the docs say....
*/
ParseErrorHandler* errHandler = new ParseErrorHandler();
parser->setErrorHandler(errHandler);
......@@ -142,23 +137,21 @@ int parse_ptop_rspec(tb_pgraph &pg, tb_sgraph &sg, char *filename) {
* These three calls do the real work of populating the assign data
* structures
*/
// clock_t startNode = clock();
XMLDEBUG("starting node population" << endl);
if (!populate_nodes_rspec(advertisement_root,pg,sg,unavailable)) {
cerr << "Error reading nodes from physical topology " << filename << endl;
cerr << "Error reading nodes from physical topology "
<< filename << endl;
exit(EXIT_FATAL);
}
XMLDEBUG("finishing node population" << endl);
// //cerr << "Time taken : " << (clock() - startNode) / CLOCKS_PER_SEC << endl;
// clock_t startLink = clock();
XMLDEBUG("starting link population" << endl);
if (!populate_links_rspec(advertisement_root,pg,sg,unavailable)) {
cerr << "Error reading links from physical topology " << filename << endl;
cerr << "Error reading links from physical topology "
<< filename << endl;
exit(EXIT_FATAL);
}
XMLDEBUG("finishing link population" << endl);
// //cerr << "Time taken : " << (clock() - startLink) / CLOCKS_PER_SEC << endl;
// TODO: We need to do something about these policies
//populate_policies(root);
......
......@@ -89,21 +89,16 @@ int parse_vtop_rspec(tb_vgraph &vg, char *filename) {
/*
* Enable some of the features we'll be using: validation, namespaces, etc.
*/
/* XXX: The schema to validate against is specificed in the xml document
* This could lead to security problems. There are some ways around it,
* but they aren't exactly elegant. But we do need to take care of it at
* some point
*/
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
/*
* Must validate against the ptop schema
*/
parser -> setExternalSchemaLocation ("http://www.protogeni.net/resources/rspec/0.1 " SCHEMA_LOCATION);
/*
* Just use a custom error handler - must admin it's not clear to me why
* we are supposed to use a SAX error handler for this, but this is what
* the docs say....
*/
ParseErrorHandler* errHandler = new ParseErrorHandler();
parser->setErrorHandler(errHandler);
......@@ -117,7 +112,9 @@ int parse_vtop_rspec(tb_vgraph &vg, char *filename) {
* If there are any errors, do not go any further
*/
if (errHandler->sawError()) {
cerr << "There were " << parser -> getErrorCount () << " errors in your file. Please correct the errors and try again." << endl;
cerr << "There were " << parser -> getErrorCount ()
<< " errors in your file."
<< "Please correct the errors and try again." << endl;
exit(EXIT_FATAL);
}
else {
......@@ -136,7 +133,7 @@ int parse_vtop_rspec(tb_vgraph &vg, char *filename) {
exit (EXIT_FATAL);
}
// XXX: Not sure what to do with the datetimes, so they are strings for now
// XXX: Not sure what to do with the datetimes, they are strings for now
XStr generated (request_root->getAttribute(XStr("generated").x()));
XStr valid_until(request_root->getAttribute(XStr("valid_until").x()));
......@@ -147,23 +144,19 @@ int parse_vtop_rspec(tb_vgraph &vg, char *filename) {
* These three calls do the real work of populating the assign data
* structures
*/
// clock_t startNode = clock();
XMLDEBUG("starting node population" << endl);
if (!populate_nodes_rspec(request_root,vg, &fixed_interfaces)) {
cerr << "Error reading nodes from virtual topology " << filename << endl;
exit(EXIT_FATAL);
}
XMLDEBUG("finishing node population" << endl);
// //cerr << "Time taken : " << (clock() - startNode) / CLOCKS_PER_SEC << endl;
// clock_t startLink = clock();
XMLDEBUG("starting link population" << endl);
if (!populate_links_rspec(request_root,vg, &fixed_interfaces)) {
cerr << "Error reading links from virtual topology " << filename << endl;
exit(EXIT_FATAL);
}
XMLDEBUG("finishing link population" << endl);
// //cerr << "Time taken : " << (clock() - startLink) / CLOCKS_PER_SEC << endl;
/* TODO: We need to do something about policies at some point. */
//populate_policies(root);
......
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