use of org.batfish.datamodel.collections.BgpAdvertisementsByVrf in project batfish by batfish.
the class Batfish method deserializeEnvironmentBgpTables.
private SortedMap<String, BgpAdvertisementsByVrf> deserializeEnvironmentBgpTables(Path serializeEnvironmentBgpTablesPath) {
_logger.info("\n*** DESERIALIZING ENVIRONMENT BGP TABLES ***\n");
_logger.resetTimer();
Map<Path, String> namesByPath = new TreeMap<>();
try (DirectoryStream<Path> serializedBgpTables = Files.newDirectoryStream(serializeEnvironmentBgpTablesPath)) {
for (Path serializedBgpTable : serializedBgpTables) {
String name = serializedBgpTable.getFileName().toString();
namesByPath.put(serializedBgpTable, name);
}
} catch (IOException e) {
throw new BatfishException("Error reading serialized BGP tables directory", e);
}
SortedMap<String, BgpAdvertisementsByVrf> bgpTables = deserializeObjects(namesByPath, BgpAdvertisementsByVrf.class);
_logger.printElapsedTime();
return bgpTables;
}
use of org.batfish.datamodel.collections.BgpAdvertisementsByVrf in project batfish by batfish.
the class Batfish method parseEnvironmentBgpTables.
private SortedMap<String, BgpAdvertisementsByVrf> parseEnvironmentBgpTables(SortedMap<Path, String> inputData, ParseEnvironmentBgpTablesAnswerElement answerElement) {
_logger.info("\n*** PARSING ENVIRONMENT BGP TABLES ***\n");
_logger.resetTimer();
SortedMap<String, BgpAdvertisementsByVrf> bgpTables = new TreeMap<>();
List<ParseEnvironmentBgpTableJob> jobs = new ArrayList<>();
SortedMap<String, Configuration> configurations = loadConfigurations();
for (Entry<Path, String> bgpFile : inputData.entrySet()) {
Path currentFile = bgpFile.getKey();
String fileText = bgpFile.getValue();
String hostname = currentFile.getFileName().toString();
String optionalSuffix = ".bgp";
if (hostname.endsWith(optionalSuffix)) {
hostname = hostname.substring(0, hostname.length() - optionalSuffix.length());
}
if (!configurations.containsKey(hostname)) {
continue;
}
Warnings warnings = buildWarnings(_settings);
ParseEnvironmentBgpTableJob job = new ParseEnvironmentBgpTableJob(_settings, fileText, hostname, currentFile, warnings, _bgpTablePlugins);
jobs.add(job);
}
BatfishJobExecutor.runJobsInExecutor(_settings, _logger, jobs, bgpTables, answerElement, _settings.getHaltOnParseError(), "Parse environment BGP tables");
_logger.printElapsedTime();
return bgpTables;
}
use of org.batfish.datamodel.collections.BgpAdvertisementsByVrf in project batfish by batfish.
the class Batfish method serializeEnvironmentBgpTables.
private Answer serializeEnvironmentBgpTables(Path inputPath, Path outputPath) {
Answer answer = new Answer();
ParseEnvironmentBgpTablesAnswerElement answerElement = new ParseEnvironmentBgpTablesAnswerElement();
answerElement.setVersion(Version.getVersion());
answer.addAnswerElement(answerElement);
SortedMap<String, BgpAdvertisementsByVrf> bgpTables = getEnvironmentBgpTables(inputPath, answerElement);
serializeEnvironmentBgpTables(bgpTables, outputPath);
serializeObject(answerElement, _testrigSettings.getEnvironmentSettings().getParseEnvironmentBgpTablesAnswerPath());
return answer;
}
use of org.batfish.datamodel.collections.BgpAdvertisementsByVrf in project batfish by batfish.
the class Batfish method serializeEnvironmentBgpTables.
private void serializeEnvironmentBgpTables(SortedMap<String, BgpAdvertisementsByVrf> bgpTables, Path outputPath) {
if (bgpTables == null) {
throw new BatfishException("Exiting due to parsing error(s)");
}
_logger.info("\n*** SERIALIZING ENVIRONMENT BGP TABLES ***\n");
_logger.resetTimer();
outputPath.toFile().mkdirs();
SortedMap<Path, BgpAdvertisementsByVrf> output = new TreeMap<>();
bgpTables.forEach((name, rt) -> {
Path currentOutputPath = outputPath.resolve(name);
output.put(currentOutputPath, rt);
});
serializeObjects(output);
_logger.printElapsedTime();
}
use of org.batfish.datamodel.collections.BgpAdvertisementsByVrf in project batfish by batfish.
the class Batfish method loadEnvironmentBgpTables.
@Override
public SortedMap<String, BgpAdvertisementsByVrf> loadEnvironmentBgpTables() {
EnvironmentSettings envSettings = _testrigSettings.getEnvironmentSettings();
SortedMap<String, BgpAdvertisementsByVrf> environmentBgpTables = _cachedEnvironmentBgpTables.get(envSettings);
if (environmentBgpTables == null) {
ParseEnvironmentBgpTablesAnswerElement ae = loadParseEnvironmentBgpTablesAnswerElement();
if (!Version.isCompatibleVersion("Service", "Old processed environment BGP tables", ae.getVersion())) {
repairEnvironmentBgpTables();
}
environmentBgpTables = deserializeEnvironmentBgpTables(envSettings.getSerializeEnvironmentBgpTablesPath());
_cachedEnvironmentBgpTables.put(envSettings, environmentBgpTables);
}
return environmentBgpTables;
}
Aggregations