use of org.batfish.datamodel.collections.RoutesByVrf 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);
}
use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class BdpDataPlanePluginTest method testIosRtStaticMatchesBdp.
@Test
public void testIosRtStaticMatchesBdp() throws IOException {
String testrigResourcePrefix = TESTRIGS_PREFIX + "ios-rt-static-ad";
List<String> configurationNames = ImmutableList.of("r1");
List<String> routingTableNames = ImmutableList.of("r1");
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(testrigResourcePrefix, configurationNames).setRoutingTablesText(testrigResourcePrefix, routingTableNames).build(), _folder);
BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
dataPlanePlugin.initialize(batfish);
batfish.computeDataPlane(false);
SortedMap<String, RoutesByVrf> environmentRoutes = batfish.loadEnvironmentRoutingTables();
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
Prefix staticRoutePrefix = Prefix.parse("10.0.0.0/8");
SortedSet<AbstractRoute> r1BdpRoutes = routes.get("r1").get(DEFAULT_VRF_NAME);
AbstractRoute r1BdpRoute = r1BdpRoutes.stream().filter(r -> r.getNetwork().equals(staticRoutePrefix)).findFirst().get();
SortedSet<Route> r1EnvironmentRoutes = environmentRoutes.get("r1").get(DEFAULT_VRF_NAME);
Route r1EnvironmentRoute = r1EnvironmentRoutes.stream().filter(r -> r.getNetwork().equals(staticRoutePrefix)).findFirst().get();
assertThat(r1BdpRoute.getAdministrativeCost(), equalTo(r1EnvironmentRoute.getAdministrativeCost()));
assertThat(r1BdpRoute.getMetric(), equalTo(r1EnvironmentRoute.getMetric()));
assertThat(r1BdpRoute.getProtocol(), equalTo(r1EnvironmentRoute.getProtocol()));
}
Aggregations