Search in sources :

Example 1 with BgpAdvertisementsByVrf

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;
}
Also used : Path(java.nio.file.Path) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) IOException(java.io.IOException) TreeMap(java.util.TreeMap) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Example 2 with BgpAdvertisementsByVrf

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;
}
Also used : Path(java.nio.file.Path) HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ParseEnvironmentBgpTableJob(org.batfish.job.ParseEnvironmentBgpTableJob) Warnings(org.batfish.common.Warnings) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Example 3 with BgpAdvertisementsByVrf

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;
}
Also used : Answer(org.batfish.datamodel.answers.Answer) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Example 4 with BgpAdvertisementsByVrf

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();
}
Also used : Path(java.nio.file.Path) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) TreeMap(java.util.TreeMap) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Example 5 with BgpAdvertisementsByVrf

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;
}
Also used : EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf)

Aggregations

BgpAdvertisementsByVrf (org.batfish.datamodel.collections.BgpAdvertisementsByVrf)6 Path (java.nio.file.Path)3 TreeMap (java.util.TreeMap)3 BatfishException (org.batfish.common.BatfishException)3 CleanBatfishException (org.batfish.common.CleanBatfishException)2 ParseEnvironmentBgpTablesAnswerElement (org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ImmutableConfiguration (org.apache.commons.configuration2.ImmutableConfiguration)1 Warnings (org.batfish.common.Warnings)1 BgpTablePlugin (org.batfish.common.plugin.BgpTablePlugin)1 EnvironmentSettings (org.batfish.config.Settings.EnvironmentSettings)1 Configuration (org.batfish.datamodel.Configuration)1 Answer (org.batfish.datamodel.answers.Answer)1 BgpTableExtractor (org.batfish.grammar.BgpTableExtractor)1 BgpTableFormat (org.batfish.grammar.BgpTableFormat)1 ParseEnvironmentBgpTableJob (org.batfish.job.ParseEnvironmentBgpTableJob)1 ParserBatfishException (org.batfish.main.ParserBatfishException)1 AwsConfiguration (org.batfish.representation.aws.AwsConfiguration)1