Search in sources :

Example 1 with Settings

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

the class Batfish method pathDiff.

@Override
public AnswerElement pathDiff(ReachabilitySettings reachabilitySettings) {
    Settings settings = getSettings();
    checkDifferentialDataPlaneQuestionDependencies();
    String tag = getDifferentialFlowTag();
    // load base configurations and generate base data plane
    pushBaseEnvironment();
    Map<String, Configuration> baseConfigurations = loadConfigurations();
    Synthesizer baseDataPlaneSynthesizer = synthesizeDataPlane();
    Topology baseTopology = getEnvironmentTopology();
    popEnvironment();
    // load diff configurations and generate diff data plane
    pushDeltaEnvironment();
    Map<String, Configuration> diffConfigurations = loadConfigurations();
    Synthesizer diffDataPlaneSynthesizer = synthesizeDataPlane();
    Topology diffTopology = getEnvironmentTopology();
    popEnvironment();
    pushDeltaEnvironment();
    SortedSet<String> blacklistNodes = getNodeBlacklist();
    Set<NodeInterfacePair> blacklistInterfaces = getInterfaceBlacklist();
    SortedSet<Edge> blacklistEdges = getEdgeBlacklist();
    popEnvironment();
    BlacklistDstIpQuerySynthesizer blacklistQuery = new BlacklistDstIpQuerySynthesizer(null, blacklistNodes, blacklistInterfaces, blacklistEdges, baseConfigurations);
    // compute composite program and flows
    List<Synthesizer> commonEdgeSynthesizers = ImmutableList.of(baseDataPlaneSynthesizer, diffDataPlaneSynthesizer, baseDataPlaneSynthesizer);
    List<CompositeNodJob> jobs = new ArrayList<>();
    // generate local edge reachability and black hole queries
    SortedSet<Edge> diffEdges = diffTopology.getEdges();
    for (Edge edge : diffEdges) {
        String ingressNode = edge.getNode1();
        String outInterface = edge.getInt1();
        String vrf = diffConfigurations.get(ingressNode).getInterfaces().get(outInterface).getVrf().getName();
        ReachEdgeQuerySynthesizer reachQuery = new ReachEdgeQuerySynthesizer(ingressNode, vrf, edge, true, reachabilitySettings.getHeaderSpace());
        ReachEdgeQuerySynthesizer noReachQuery = new ReachEdgeQuerySynthesizer(ingressNode, vrf, edge, true, new HeaderSpace());
        noReachQuery.setNegate(true);
        List<QuerySynthesizer> queries = ImmutableList.of(reachQuery, noReachQuery, blacklistQuery);
        SortedSet<Pair<String, String>> nodes = ImmutableSortedSet.of(new Pair<>(ingressNode, vrf));
        CompositeNodJob job = new CompositeNodJob(settings, commonEdgeSynthesizers, queries, nodes, tag);
        jobs.add(job);
    }
    // we also need queries for nodes next to edges that are now missing,
    // in the case that those nodes still exist
    List<Synthesizer> missingEdgeSynthesizers = ImmutableList.of(baseDataPlaneSynthesizer, baseDataPlaneSynthesizer);
    SortedSet<Edge> baseEdges = baseTopology.getEdges();
    SortedSet<Edge> missingEdges = ImmutableSortedSet.copyOf(Sets.difference(baseEdges, diffEdges));
    for (Edge missingEdge : missingEdges) {
        String ingressNode = missingEdge.getNode1();
        String outInterface = missingEdge.getInt1();
        if (diffConfigurations.containsKey(ingressNode) && diffConfigurations.get(ingressNode).getInterfaces().containsKey(outInterface)) {
            String vrf = diffConfigurations.get(ingressNode).getInterfaces().get(outInterface).getVrf().getName();
            ReachEdgeQuerySynthesizer reachQuery = new ReachEdgeQuerySynthesizer(ingressNode, vrf, missingEdge, true, reachabilitySettings.getHeaderSpace());
            List<QuerySynthesizer> queries = ImmutableList.of(reachQuery, blacklistQuery);
            SortedSet<Pair<String, String>> nodes = ImmutableSortedSet.of(new Pair<>(ingressNode, vrf));
            CompositeNodJob job = new CompositeNodJob(settings, missingEdgeSynthesizers, queries, nodes, tag);
            jobs.add(job);
        }
    }
    // TODO: maybe do something with nod answer element
    Set<Flow> flows = computeCompositeNodOutput(jobs, new NodAnswerElement());
    pushBaseEnvironment();
    getDataPlanePlugin().processFlows(flows, loadDataPlane());
    popEnvironment();
    pushDeltaEnvironment();
    getDataPlanePlugin().processFlows(flows, loadDataPlane());
    popEnvironment();
    AnswerElement answerElement = getHistory();
    return answerElement;
}
Also used : 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) HeaderSpace(org.batfish.datamodel.HeaderSpace) CompositeNodJob(org.batfish.z3.CompositeNodJob) ReachabilityQuerySynthesizer(org.batfish.z3.ReachabilityQuerySynthesizer) QuerySynthesizer(org.batfish.z3.QuerySynthesizer) AclReachabilityQuerySynthesizer(org.batfish.z3.AclReachabilityQuerySynthesizer) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) StandardReachabilityQuerySynthesizer(org.batfish.z3.StandardReachabilityQuerySynthesizer) EarliestMoreGeneralReachableLineQuerySynthesizer(org.batfish.z3.EarliestMoreGeneralReachableLineQuerySynthesizer) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) Synthesizer(org.batfish.z3.Synthesizer) MultipathInconsistencyQuerySynthesizer(org.batfish.z3.MultipathInconsistencyQuerySynthesizer) ReachabilitySettings(org.batfish.datamodel.questions.ReachabilitySettings) Settings(org.batfish.config.Settings) TestrigSettings(org.batfish.config.Settings.TestrigSettings) GrammarSettings(org.batfish.grammar.GrammarSettings) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) DataPlanePluginSettings(org.batfish.common.plugin.DataPlanePluginSettings) Pair(org.batfish.common.Pair) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) AnswerElement(org.batfish.datamodel.answers.AnswerElement) InitInfoAnswerElement(org.batfish.datamodel.answers.InitInfoAnswerElement) RunAnalysisAnswerElement(org.batfish.datamodel.answers.RunAnalysisAnswerElement) DataPlaneAnswerElement(org.batfish.datamodel.answers.DataPlaneAnswerElement) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) AclLinesAnswerElement(org.batfish.datamodel.answers.AclLinesAnswerElement) ParseEnvironmentRoutingTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement) NodAnswerElement(org.batfish.datamodel.answers.NodAnswerElement) NodFirstUnsatAnswerElement(org.batfish.datamodel.answers.NodFirstUnsatAnswerElement) InitStepAnswerElement(org.batfish.datamodel.answers.InitStepAnswerElement) NodSatAnswerElement(org.batfish.datamodel.answers.NodSatAnswerElement) ParseAnswerElement(org.batfish.datamodel.answers.ParseAnswerElement) FlattenVendorConfigurationAnswerElement(org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement) ValidateEnvironmentAnswerElement(org.batfish.datamodel.answers.ValidateEnvironmentAnswerElement) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) ReportAnswerElement(org.batfish.datamodel.answers.ReportAnswerElement) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) NodAnswerElement(org.batfish.datamodel.answers.NodAnswerElement) Topology(org.batfish.datamodel.Topology) Flow(org.batfish.datamodel.Flow) ReachabilityQuerySynthesizer(org.batfish.z3.ReachabilityQuerySynthesizer) QuerySynthesizer(org.batfish.z3.QuerySynthesizer) AclReachabilityQuerySynthesizer(org.batfish.z3.AclReachabilityQuerySynthesizer) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) StandardReachabilityQuerySynthesizer(org.batfish.z3.StandardReachabilityQuerySynthesizer) EarliestMoreGeneralReachableLineQuerySynthesizer(org.batfish.z3.EarliestMoreGeneralReachableLineQuerySynthesizer) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) MultipathInconsistencyQuerySynthesizer(org.batfish.z3.MultipathInconsistencyQuerySynthesizer) Edge(org.batfish.datamodel.Edge)

Example 2 with Settings

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

the class Driver method mainInit.

private static void mainInit(String[] args) {
    _taskLog = new ConcurrentHashMap<>();
    _mainArgs = args;
    try {
        _mainSettings = new Settings(args);
        networkListenerLogger.setLevel(Level.WARNING);
        httpServerLogger.setLevel(Level.WARNING);
    } catch (Exception e) {
        System.err.println("batfish: Initialization failed. Reason: " + ExceptionUtils.getStackTrace(e));
        System.exit(1);
    }
}
Also used : EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) Settings(org.batfish.config.Settings) TestrigSettings(org.batfish.config.Settings.TestrigSettings) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ProcessingException(javax.ws.rs.ProcessingException) QuestionException(org.batfish.common.QuestionException) BatfishException(org.batfish.common.BatfishException) IOException(java.io.IOException) CleanBatfishException(org.batfish.common.CleanBatfishException)

Example 3 with Settings

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

the class BdpDataPlanePluginTest method testBgpOscillationRecovery.

private void testBgpOscillationRecovery(MockBdpSettings bdpSettings) throws IOException {
    String testrigName = "bgp-oscillation";
    List<String> configurationNames = ImmutableList.of("r1", "r2", "r3");
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
    Settings settings = batfish.getSettings();
    settings.setBdpDetail(bdpSettings.getBdpDetail());
    settings.setBdpMaxOscillationRecoveryAttempts(bdpSettings.getBdpMaxOscillationRecoveryAttempts());
    settings.setBdpMaxRecordedIterations(bdpSettings.getBdpMaxRecordedIterations());
    settings.setBdpPrintAllIterations(bdpSettings.getBdpPrintAllIterations());
    settings.setBdpPrintOscillatingIterations(bdpSettings.getBdpPrintOscillatingIterations());
    settings.setBdpRecordAllIterations(bdpSettings.getBdpRecordAllIterations());
    BdpDataPlanePlugin dataPlanePlugin = new BdpDataPlanePlugin();
    dataPlanePlugin.initialize(batfish);
    /*
     * Data plane computation succeeds iff recovery is enabled. If disabled, an exception is thrown
     * and should be expected by caller.
     */
    batfish.computeDataPlane(false);
    SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> routes = dataPlanePlugin.getRoutes(batfish.loadDataPlane());
    Prefix bgpPrefix = Prefix.parse("1.1.1.1/32");
    SortedSet<AbstractRoute> r2Routes = routes.get("r2").get(DEFAULT_VRF_NAME);
    SortedSet<AbstractRoute> r3Routes = routes.get("r3").get(DEFAULT_VRF_NAME);
    Stream<AbstractRoute> r2MatchingRoutes = r2Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix));
    Stream<AbstractRoute> r3MatchingRoutes = r3Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix));
    AbstractRoute r2Route = r2Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix)).findAny().get();
    AbstractRoute r3Route = r3Routes.stream().filter(r -> r.getNetwork().equals(bgpPrefix)).findAny().get();
    String r2NextHop = r2Route.getNextHop();
    String r3NextHop = r3Route.getNextHop();
    int routesWithR1AsNextHop = 0;
    if (r2Route.getNextHop().equals("r1")) {
        routesWithR1AsNextHop++;
    }
    if (r3Route.getNextHop().equals("r1")) {
        routesWithR1AsNextHop++;
    }
    boolean r2AsNextHop = r3NextHop.equals("r2");
    boolean r3AsNextHop = r2NextHop.equals("r3");
    /*
     * Data plane computation should succeed as follows if recovery is enabled.
     */
    assertThat(r2MatchingRoutes.count(), equalTo(1L));
    assertThat(r3MatchingRoutes.count(), equalTo(1L));
    assertThat(routesWithR1AsNextHop, equalTo(1));
    assertTrue((r2AsNextHop && !r3AsNextHop) || (!r2AsNextHop && r3AsNextHop));
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) Matchers.containsString(org.hamcrest.Matchers.containsString) Prefix(org.batfish.datamodel.Prefix) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Batfish(org.batfish.main.Batfish) Settings(org.batfish.config.Settings)

Example 4 with Settings

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

the class FlatJuniperGrammarTest method testParsingRecovery.

@Test
public void testParsingRecovery() {
    String recoveryText = CommonUtil.readResource("org/batfish/grammar/juniper/testconfigs/recovery");
    Settings settings = new Settings();
    FlatJuniperCombinedParser cp = new FlatJuniperCombinedParser(recoveryText, settings);
    Flat_juniper_configurationContext ctx = cp.parse();
    FlatJuniperRecoveryExtractor extractor = new FlatJuniperRecoveryExtractor();
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(extractor, ctx);
    assertThat(extractor.getNumSets(), equalTo(8));
    assertThat(extractor.getNumErrorNodes(), equalTo(8));
}
Also used : Flat_juniper_configurationContext(org.batfish.grammar.flatjuniper.FlatJuniperParser.Flat_juniper_configurationContext) Settings(org.batfish.config.Settings) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Test(org.junit.Test)

Example 5 with Settings

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

the class BatfishJobExecutorTest method testHandleJobResultFailure.

@Test
public void testHandleJobResultFailure() {
    Settings settings = new Settings();
    // initializing executor
    BatfishJobExecutor executor = BatfishJobExecutor.getBatfishJobExecutor(settings, _logger);
    executor.initializeJobsStats(Lists.newArrayList(new BfTestJob(settings, "result1")), TEST_EXECUTOR_DESC);
    // Simulating failure of a job and handling the result
    // initiating a separate logger from the Executor logger
    BatfishLogger jobLogger = new BatfishLogger(BatfishLogger.LEVELSTR_INFO, false);
    BfTestResult bfTestResult = new BfTestResult(TEST_ELAPSED_TIME, jobLogger.getHistory(), new BatfishException("Test Job Failure Message"));
    Set<String> output = new HashSet<>();
    List<BatfishException> failureCauses = new ArrayList<>();
    BfTestAnswerElement ae = new BfTestAnswerElement();
    executor.markJobCompleted();
    executor.handleJobResult(bfTestResult, output, ae, failureCauses, false);
    // checking that correct failure message is written in the log
    assertEquals(failureCauses.get(0).getMessage(), executor.getFailureMessage(bfTestResult));
}
Also used : BatfishException(org.batfish.common.BatfishException) BatfishLogger(org.batfish.common.BatfishLogger) ArrayList(java.util.ArrayList) Settings(org.batfish.config.Settings) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Settings (org.batfish.config.Settings)15 ArrayList (java.util.ArrayList)7 BatfishException (org.batfish.common.BatfishException)7 BatfishLogger (org.batfish.common.BatfishLogger)7 EnvironmentSettings (org.batfish.config.Settings.EnvironmentSettings)7 TestrigSettings (org.batfish.config.Settings.TestrigSettings)7 HashSet (java.util.HashSet)5 Pair (org.batfish.common.Pair)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 SortedMap (java.util.SortedMap)4 CleanBatfishException (org.batfish.common.CleanBatfishException)4 Test (org.junit.Test)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ActiveSpan (io.opentracing.ActiveSpan)3 Nullable (javax.annotation.Nullable)3 Snapshot (org.batfish.common.Snapshot)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2