Search in sources :

Example 1 with RoutesByVrf

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

Example 2 with RoutesByVrf

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;
}
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) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf)

Example 3 with RoutesByVrf

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

Example 4 with RoutesByVrf

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

Example 5 with RoutesByVrf

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;
}
Also used : Path(java.nio.file.Path) ParseEnvironmentRoutingTableJob(org.batfish.job.ParseEnvironmentRoutingTableJob) 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) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) TreeMap(java.util.TreeMap) Warnings(org.batfish.common.Warnings)

Aggregations

RoutesByVrf (org.batfish.datamodel.collections.RoutesByVrf)7 Path (java.nio.file.Path)3 TreeMap (java.util.TreeMap)3 BatfishException (org.batfish.common.BatfishException)3 CleanBatfishException (org.batfish.common.CleanBatfishException)2 ParseEnvironmentRoutingTablesAnswerElement (org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SortedMap (java.util.SortedMap)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ImmutableConfiguration (org.apache.commons.configuration2.ImmutableConfiguration)1 Warnings (org.batfish.common.Warnings)1 EnvironmentSettings (org.batfish.config.Settings.EnvironmentSettings)1 AbstractRoute (org.batfish.datamodel.AbstractRoute)1 BgpRoute (org.batfish.datamodel.BgpRoute)1 Configuration (org.batfish.datamodel.Configuration)1 Prefix (org.batfish.datamodel.Prefix)1 Route (org.batfish.datamodel.Route)1 StaticRoute (org.batfish.datamodel.StaticRoute)1