use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class Batfish method loadEnvironmentRoutingTables.
@Override
public SortedMap<String, RoutesByVrf> loadEnvironmentRoutingTables() {
EnvironmentSettings envSettings = _testrigSettings.getEnvironmentSettings();
SortedMap<String, RoutesByVrf> environmentRoutingTables = _cachedEnvironmentRoutingTables.get(envSettings);
if (environmentRoutingTables == null) {
ParseEnvironmentRoutingTablesAnswerElement pertae = loadParseEnvironmentRoutingTablesAnswerElement();
if (!Version.isCompatibleVersion("Service", "Old processed environment routing tables", pertae.getVersion())) {
repairEnvironmentRoutingTables();
}
environmentRoutingTables = deserializeEnvironmentRoutingTables(envSettings.getSerializeEnvironmentRoutingTablesPath());
_cachedEnvironmentRoutingTables.put(envSettings, environmentRoutingTables);
}
return environmentRoutingTables;
}
use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class Batfish method deserializeEnvironmentRoutingTables.
private SortedMap<String, RoutesByVrf> deserializeEnvironmentRoutingTables(Path serializeEnvironmentRoutingTablesPath) {
_logger.info("\n*** DESERIALIZING ENVIRONMENT ROUTING TABLES ***\n");
_logger.resetTimer();
Map<Path, String> namesByPath = new TreeMap<>();
try (DirectoryStream<Path> serializedRoutingTables = Files.newDirectoryStream(serializeEnvironmentRoutingTablesPath)) {
for (Path serializedRoutingTable : serializedRoutingTables) {
String name = serializedRoutingTable.getFileName().toString();
namesByPath.put(serializedRoutingTable, name);
}
} catch (IOException e) {
throw new BatfishException("Error reading serialized routing tables directory", e);
}
SortedMap<String, RoutesByVrf> routingTables = deserializeObjects(namesByPath, RoutesByVrf.class);
_logger.printElapsedTime();
return routingTables;
}
use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class Batfish method serializeEnvironmentRoutingTables.
private void serializeEnvironmentRoutingTables(SortedMap<String, RoutesByVrf> routingTables, Path outputPath) {
if (routingTables == null) {
throw new BatfishException("Exiting due to parsing error(s)");
}
_logger.info("\n*** SERIALIZING ENVIRONMENT ROUTING TABLES ***\n");
_logger.resetTimer();
outputPath.toFile().mkdirs();
SortedMap<Path, RoutesByVrf> output = new TreeMap<>();
routingTables.forEach((name, rt) -> {
Path currentOutputPath = outputPath.resolve(name);
output.put(currentOutputPath, rt);
});
serializeObjects(output);
_logger.printElapsedTime();
}
use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class Batfish method serializeEnvironmentRoutingTables.
private Answer serializeEnvironmentRoutingTables(Path inputPath, Path outputPath) {
Answer answer = new Answer();
ParseEnvironmentRoutingTablesAnswerElement answerElement = new ParseEnvironmentRoutingTablesAnswerElement();
answerElement.setVersion(Version.getVersion());
answer.addAnswerElement(answerElement);
SortedMap<String, RoutesByVrf> routingTables = getEnvironmentRoutingTables(inputPath, answerElement);
serializeEnvironmentRoutingTables(routingTables, outputPath);
serializeObject(answerElement, _testrigSettings.getEnvironmentSettings().getParseEnvironmentRoutingTablesAnswerPath());
return answer;
}
use of org.batfish.datamodel.collections.RoutesByVrf in project batfish by batfish.
the class Batfish method parseEnvironmentRoutingTables.
private SortedMap<String, RoutesByVrf> parseEnvironmentRoutingTables(SortedMap<Path, String> inputData, ParseEnvironmentRoutingTablesAnswerElement answerElement) {
_logger.info("\n*** PARSING ENVIRONMENT ROUTING TABLES ***\n");
_logger.resetTimer();
SortedMap<String, RoutesByVrf> routingTables = new TreeMap<>();
List<ParseEnvironmentRoutingTableJob> jobs = new ArrayList<>();
SortedMap<String, Configuration> configurations = loadConfigurations();
for (Entry<Path, String> routingFile : inputData.entrySet()) {
Path currentFile = routingFile.getKey();
String fileText = routingFile.getValue();
String hostname = currentFile.getFileName().toString();
if (!configurations.containsKey(hostname)) {
continue;
}
Warnings warnings = buildWarnings(_settings);
ParseEnvironmentRoutingTableJob job = new ParseEnvironmentRoutingTableJob(_settings, fileText, currentFile, warnings, this);
jobs.add(job);
}
BatfishJobExecutor.runJobsInExecutor(_settings, _logger, jobs, routingTables, answerElement, _settings.getHaltOnParseError(), "Parse environment routing tables");
_logger.printElapsedTime();
return routingTables;
}
Aggregations