Search in sources :

Example 6 with EnvironmentSettings

use of org.batfish.config.Settings.EnvironmentSettings in project batfish by batfish.

the class Batfish method compileEnvironmentConfigurations.

private Answer compileEnvironmentConfigurations(TestrigSettings testrigSettings) {
    Answer answer = new Answer();
    EnvironmentSettings envSettings = testrigSettings.getEnvironmentSettings();
    Path deltaConfigurationsDir = envSettings.getDeltaConfigurationsDir();
    Path vendorConfigsDir = envSettings.getDeltaVendorConfigurationsDir();
    if (deltaConfigurationsDir != null) {
        if (Files.exists(deltaConfigurationsDir)) {
            answer.append(serializeVendorConfigs(envSettings.getEnvPath(), vendorConfigsDir));
            answer.append(serializeIndependentConfigs(vendorConfigsDir));
        }
        return answer;
    } else {
        throw new BatfishException("Delta configurations directory cannot be null");
    }
}
Also used : Path(java.nio.file.Path) Answer(org.batfish.datamodel.answers.Answer) CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings)

Example 7 with EnvironmentSettings

use of org.batfish.config.Settings.EnvironmentSettings in project batfish by batfish.

the class Batfish method computeEnvironmentRoutingTables.

private void computeEnvironmentRoutingTables() {
    EnvironmentSettings envSettings = _testrigSettings.getEnvironmentSettings();
    Path outputPath = envSettings.getSerializeEnvironmentRoutingTablesPath();
    Path inputPath = envSettings.getEnvironmentRoutingTablesPath();
    serializeEnvironmentRoutingTables(inputPath, outputPath);
}
Also used : Path(java.nio.file.Path) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings)

Example 8 with EnvironmentSettings

use of org.batfish.config.Settings.EnvironmentSettings in project batfish by batfish.

the class Batfish method repairEnvironmentBgpTables.

private void repairEnvironmentBgpTables() {
    EnvironmentSettings envSettings = _testrigSettings.getEnvironmentSettings();
    Path answerPath = envSettings.getParseEnvironmentBgpTablesAnswerPath();
    Path bgpTablesOutputPath = envSettings.getSerializeEnvironmentBgpTablesPath();
    CommonUtil.deleteIfExists(answerPath);
    CommonUtil.deleteDirectory(bgpTablesOutputPath);
    computeEnvironmentBgpTables();
}
Also used : Path(java.nio.file.Path) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings)

Example 9 with EnvironmentSettings

use of org.batfish.config.Settings.EnvironmentSettings 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)

Example 10 with EnvironmentSettings

use of org.batfish.config.Settings.EnvironmentSettings in project batfish by batfish.

the class BatfishTestUtils method getBatfishFromTestrigText.

/**
 * Get a new Batfish instance with given configurations, tempFolder should be present for
 * non-empty configurations
 *
 * @param testrigText Structure containing names and content of testrig input files
 * @param tempFolder Temporary folder to be used to files required for Batfish
 * @return Batfish instance pointing at new testrig comprising testrigText
 */
public static Batfish getBatfishFromTestrigText(TestrigText testrigText, TemporaryFolder tempFolder) throws IOException {
    Map<String, String> awsText = testrigText.getAwsText();
    Map<String, String> bgpTablesText = testrigText.getBgpTablesText();
    Map<String, String> configurationText = testrigText.getConfigurationText();
    Map<String, String> hostsText = testrigText.getHostsText();
    Map<String, String> iptablesFilesText = testrigText.getIptablesFilesText();
    Map<String, String> routingTablesText = testrigText.getRoutingTablesText();
    Settings settings = new Settings(new String[] {});
    settings.setLogger(new BatfishLogger("debug", false));
    settings.setDisableUnrecognized(true);
    settings.setHaltOnConvertError(true);
    settings.setHaltOnParseError(true);
    settings.setThrowOnLexerError(true);
    settings.setThrowOnParserError(true);
    settings.setVerboseParse(true);
    Path containerDir = tempFolder.newFolder().toPath();
    settings.setContainerDir(containerDir);
    settings.setTestrig("tempTestrig");
    settings.setEnvironmentName("tempEnvironment");
    settings.setDataplaneEngineName(BdpDataPlanePlugin.PLUGIN_NAME);
    Batfish.initTestrigSettings(settings);
    Path testrigPath = settings.getBaseTestrigSettings().getTestRigPath();
    settings.setActiveTestrigSettings(settings.getBaseTestrigSettings());
    EnvironmentSettings envSettings = settings.getBaseTestrigSettings().getEnvironmentSettings();
    envSettings.getEnvPath().toFile().mkdirs();
    writeTemporaryTestrigFiles(configurationText, testrigPath.resolve(BfConsts.RELPATH_CONFIGURATIONS_DIR));
    writeTemporaryTestrigFiles(awsText, testrigPath.resolve(BfConsts.RELPATH_AWS_CONFIGS_DIR));
    writeTemporaryTestrigFiles(bgpTablesText, envSettings.getEnvironmentBgpTablesPath());
    writeTemporaryTestrigFiles(hostsText, testrigPath.resolve(BfConsts.RELPATH_HOST_CONFIGS_DIR));
    writeTemporaryTestrigFiles(iptablesFilesText, testrigPath.resolve("iptables"));
    writeTemporaryTestrigFiles(routingTablesText, envSettings.getEnvironmentRoutingTablesPath());
    Batfish batfish = new Batfish(settings, makeTestrigCache(), makeTestrigCache(), makeDataPlaneCache(), makeDataPlaneCache(), makeEnvBgpCache(), makeEnvRouteCache(), makeForwardingAnalysisCache());
    return batfish;
}
Also used : Path(java.nio.file.Path) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) BatfishLogger(org.batfish.common.BatfishLogger) TestrigSettings(org.batfish.config.Settings.TestrigSettings) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) Settings(org.batfish.config.Settings)

Aggregations

EnvironmentSettings (org.batfish.config.Settings.EnvironmentSettings)10 Path (java.nio.file.Path)8 BatfishException (org.batfish.common.BatfishException)1 BatfishLogger (org.batfish.common.BatfishLogger)1 CleanBatfishException (org.batfish.common.CleanBatfishException)1 Settings (org.batfish.config.Settings)1 TestrigSettings (org.batfish.config.Settings.TestrigSettings)1 Answer (org.batfish.datamodel.answers.Answer)1 ParseEnvironmentBgpTablesAnswerElement (org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement)1 ParseEnvironmentRoutingTablesAnswerElement (org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement)1 BgpAdvertisementsByVrf (org.batfish.datamodel.collections.BgpAdvertisementsByVrf)1 RoutesByVrf (org.batfish.datamodel.collections.RoutesByVrf)1