use of org.batfish.grammar.routing_table.nxos.NxosRoutingTableCombinedParser in project batfish by batfish.
the class ParseEnvironmentRoutingTableJob method call.
@Override
public ParseEnvironmentRoutingTableResult call() {
long startTime = System.currentTimeMillis();
long elapsedTime;
String currentPath = _file.toAbsolutePath().toString();
BatfishCombinedParser<?, ?> combinedParser = null;
ParserRuleContext tree = null;
RoutingTableExtractor extractor = null;
_logger.infof("Processing: '%s'\n", currentPath);
// String relativePathStr =
// _settings.getActiveTestrigSettings().getEnvironmentSettings().getEnvPath()
// .relativize(_file).toString();
RoutingTableFormat format = RoutingTableFormatDetector.identifyRoutingTableFormat(_fileText);
switch(format) {
case EMPTY:
_warnings.redFlag("Empty file: '" + currentPath + "'\n");
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.EMPTY);
case EOS:
EosRoutingTableCombinedParser eosRoutingTableParser = new EosRoutingTableCombinedParser(_fileText, _settings);
combinedParser = eosRoutingTableParser;
extractor = new EosRoutingTableExtractor(_hostname, _fileText, eosRoutingTableParser, _warnings, _batfish);
break;
case IOS:
IosRoutingTableCombinedParser iosRoutingTableParser = new IosRoutingTableCombinedParser(_fileText, _settings);
combinedParser = iosRoutingTableParser;
extractor = new IosRoutingTableExtractor(_hostname, _fileText, iosRoutingTableParser, _warnings, _batfish);
break;
case NXOS:
NxosRoutingTableCombinedParser nxosRoutingTableParser = new NxosRoutingTableCombinedParser(_fileText, _settings);
combinedParser = nxosRoutingTableParser;
extractor = new NxosRoutingTableExtractor(_hostname, _fileText, nxosRoutingTableParser, _warnings, _batfish);
break;
case UNKNOWN:
default:
String unknownError = "Unknown routing-table format for file: '" + currentPath + "'\n";
if (!_settings.ignoreUnknown()) {
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(unknownError));
} else {
_warnings.unimplemented(unknownError);
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _warnings, ParseStatus.UNKNOWN);
}
}
try {
_logger.info("\tParsing...");
tree = Batfish.parse(combinedParser, _logger, _settings);
if (_settings.getPrintParseTree()) {
_ptSentences = ParseTreePrettyPrinter.getParseTreeSentences(tree, combinedParser);
}
_logger.info("\tPost-processing...");
extractor.processParseTree(tree);
_logger.info("OK\n");
} catch (ParserBatfishException e) {
String error = "Error parsing configuration file: '" + currentPath + "'";
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(error, e));
} catch (Exception e) {
String error = "Error post-processing parse tree of configuration file: '" + currentPath + "'";
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, new BatfishException(error, e));
} finally {
Batfish.logWarnings(_logger, _warnings);
}
RoutesByVrf routesByVrf = extractor.getRoutesByVrf();
elapsedTime = System.currentTimeMillis() - startTime;
return new ParseEnvironmentRoutingTableResult(elapsedTime, _logger.getHistory(), _file, _hostname, routesByVrf, _warnings, _ptSentences);
}
Aggregations