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;
}
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);
}
}
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));
}
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));
}
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));
}
Aggregations