Search in sources :

Example 1 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.

the class Batfish method synthesizeDataPlane.

public Synthesizer synthesizeDataPlane() {
    SortedMap<String, Configuration> configurations = loadConfigurations();
    DataPlane dataPlane = loadDataPlane();
    ForwardingAnalysis forwardingAnalysis = loadForwardingAnalysis(configurations, dataPlane);
    return synthesizeDataPlane(configurations, dataPlane, forwardingAnalysis, new HeaderSpace(), false);
}
Also used : DataPlane(org.batfish.datamodel.DataPlane) 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) HeaderSpace(org.batfish.datamodel.HeaderSpace) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis)

Example 2 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace 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 3 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.

the class DestinationClasses method addCatchAllCase.

/**
 * Adds a catch-all headerspace to the headerspace map. The catch-all case matches dstIps, does
 * not match notDstIps, and doesn't match anything matched by anything in destinationMap.
 *
 * @param dstIps A list of destination IPs that should be in the catch-all headerspace.
 * @param notDstIps A list of destination IPs that should not be in the catch-all headerspace.
 * @param destinationMap Inversion of the prefix trie -- from sets of destinations to prefixes
 */
private void addCatchAllCase(List<Prefix> dstIps, List<Prefix> notDstIps, Map<Set<String>, List<Prefix>> destinationMap) {
    HeaderSpace catchAll = createHeaderSpace(dstIps);
    catchAll.setNotDstIps(Stream.concat(notDstIps.stream(), destinationMap.values().stream().flatMap(Collection::stream)).map(IpWildcard::new).collect(Collectors.toSet()));
    if (_headerspace != null) {
        copyAllButDestinationIp(catchAll, _headerspace);
    }
    if (!catchAll.getNotDstIps().equals(catchAll.getDstIps())) {
        _headerspaceMap.put(new HashSet<>(), new Tuple<>(catchAll, new Tuple<>(null, true)));
    }
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Collection(java.util.Collection) HeaderSpace(org.batfish.datamodel.HeaderSpace) Tuple(org.batfish.symbolic.utils.Tuple)

Example 4 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.

the class PropertyChecker method inferDestinationHeaderSpace.

private void inferDestinationHeaderSpace(Graph g, Collection<GraphEdge> destPorts, HeaderLocationQuestion q) {
    // Skip inference if the destination IP headerspace does not need to be inferred.
    if (!q.getHeaderSpace().getDstIps().isEmpty()) {
        return;
    }
    // Infer relevant destination IP headerspace from interfaces
    HeaderSpace headerSpace = q.getHeaderSpace();
    for (GraphEdge ge : destPorts) {
        // it can be any prefix, so we leave it unconstrained
        if (g.isExternal(ge)) {
            headerSpace.setDstIps(Collections.emptySet());
            headerSpace.setNotDstIps(Collections.emptySet());
            break;
        }
        // If we don't know what is on the other end
        if (ge.getPeer() == null) {
            Prefix pfx = ge.getStart().getAddress().getPrefix();
            IpWildcard dst = new IpWildcard(pfx);
            headerSpace.setDstIps(Iterables.concat(headerSpace.getDstIps(), Collections.singleton(dst)));
        } else {
            // If host, add the subnet but not the neighbor's address
            if (g.isHost(ge.getRouter())) {
                Prefix pfx = ge.getStart().getAddress().getPrefix();
                IpWildcard dst = new IpWildcard(pfx);
                headerSpace.setDstIps(Iterables.concat(headerSpace.getDstIps(), Collections.singleton(dst)));
                Ip ip = ge.getEnd().getAddress().getIp();
                IpWildcard dst2 = new IpWildcard(ip);
                headerSpace.setNotDstIps(Iterables.concat(headerSpace.getNotDstIps(), Collections.singleton(dst2)));
            } else {
                // Otherwise, we add the exact address
                Ip ip = ge.getStart().getAddress().getIp();
                IpWildcard dst = new IpWildcard(ip);
                headerSpace.setDstIps(Iterables.concat(headerSpace.getDstIps(), Collections.singleton(dst)));
            }
        }
    }
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) Prefix(org.batfish.datamodel.Prefix) GraphEdge(org.batfish.symbolic.GraphEdge)

Example 5 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.

the class NodJobChunkingTest method getNodJob.

private NodJob getNodJob() {
    StandardReachabilityQuerySynthesizer querySynthesizer = StandardReachabilityQuerySynthesizer.builder().setActions(ImmutableSet.of(ForwardingAction.ACCEPT)).setHeaderSpace(new HeaderSpace()).setFinalNodes(ImmutableSet.of(_dstNode.getHostname())).setIngressNodeVrfs(ImmutableMap.of(_srcNode1.getHostname(), ImmutableSet.of(_srcVrf1.getName()), _srcNode2.getHostname(), ImmutableSet.of(_srcVrf2.getName()))).setTransitNodes(ImmutableSet.of()).setNonTransitNodes(ImmutableSet.of()).build();
    SortedSet<Pair<String, String>> ingressNodes = ImmutableSortedSet.of(new Pair<>(_srcNode1.getHostname(), _srcVrf1.getName()), new Pair<>(_srcNode2.getHostname(), _srcVrf2.getName()));
    return new NodJob(new Settings(), _synthesizer, querySynthesizer, ingressNodes, "tag", false);
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) Settings(org.batfish.config.Settings) Pair(org.batfish.common.Pair)

Aggregations

HeaderSpace (org.batfish.datamodel.HeaderSpace)22 IpWildcard (org.batfish.datamodel.IpWildcard)12 Test (org.junit.Test)8 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)7 Map (java.util.Map)7 SortedMap (java.util.SortedMap)7 Configuration (org.batfish.datamodel.Configuration)7 Ip (org.batfish.datamodel.Ip)7 Context (com.microsoft.z3.Context)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 Pair (org.batfish.common.Pair)6 DataPlane (org.batfish.datamodel.DataPlane)6 Flow (org.batfish.datamodel.Flow)6 Topology (org.batfish.datamodel.Topology)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)5 IBatfish (org.batfish.common.plugin.IBatfish)5