Search in sources :

Example 1 with FlowHistory

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

the class Batfish method getHistory.

@Override
public FlowHistory getHistory() {
    FlowHistory flowHistory = new FlowHistory();
    if (_settings.getDiffQuestion()) {
        String flowTag = getDifferentialFlowTag();
        // String baseEnvTag = _baseTestrigSettings.getEnvName() + ":"
        // + _baseTestrigSettings.getEnvironmentSettings().getEnvName();
        String baseEnvTag = getFlowTag(_baseTestrigSettings);
        // String deltaName = _deltaTestrigSettings.getEnvName() + ":"
        // + _deltaTestrigSettings.getEnvironmentSettings().getEnvName();
        String deltaEnvTag = getFlowTag(_deltaTestrigSettings);
        pushBaseEnvironment();
        Environment baseEnv = getEnvironment();
        populateFlowHistory(flowHistory, baseEnvTag, baseEnv, flowTag);
        popEnvironment();
        pushDeltaEnvironment();
        Environment deltaEnv = getEnvironment();
        populateFlowHistory(flowHistory, deltaEnvTag, deltaEnv, flowTag);
        popEnvironment();
    } else {
        String flowTag = getFlowTag();
        // String name = testrigSettings.getEnvName() + ":"
        // + testrigSettings.getEnvironmentSettings().getEnvName();
        String envTag = flowTag;
        Environment env = getEnvironment();
        populateFlowHistory(flowHistory, envTag, env, flowTag);
    }
    _logger.debug(flowHistory.toString());
    return flowHistory;
}
Also used : FlowHistory(org.batfish.datamodel.FlowHistory) Environment(org.batfish.datamodel.pojo.Environment)

Example 2 with FlowHistory

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

the class PropertyChecker method checkReachability.

/*
   * Check if a collection of routers will be reachable to
   * one or more destinations.
   */
public AnswerElement checkReachability(HeaderLocationQuestion q) {
    return checkProperty(q, (enc, srcRouters, destPorts) -> {
        PropertyAdder pa = new PropertyAdder(enc.getMainSlice());
        return pa.instrumentReachability(destPorts);
    }, (vp) -> {
        if (vp.getResult().isVerified()) {
            return new SmtReachabilityAnswerElement(vp.getResult(), new FlowHistory());
        } else {
            FlowHistory fh;
            CounterExample ce = new CounterExample(vp.getModel());
            String testrigName = _batfish.getTestrigName();
            if (q.getDiffType() != null) {
                fh = ce.buildFlowHistoryDiff(testrigName, vp.getSrcRouters(), vp.getEnc(), vp.getEncDiff(), vp.getProp(), vp.getPropDiff());
            } else {
                Map<String, Boolean> reachVals = vp.getProp().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> ce.isTrue(entry.getValue()) ^ q.getNegate()));
                fh = ce.buildFlowHistory(testrigName, vp.getSrcRouters(), vp.getEnc(), reachVals);
            }
            return new SmtReachabilityAnswerElement(vp.getResult(), fh);
        }
    });
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) PatternUtils(org.batfish.symbolic.utils.PatternUtils) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement) SortedSet(java.util.SortedSet) FlowHistory(org.batfish.datamodel.FlowHistory) Flow(org.batfish.datamodel.Flow) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) EnvironmentType(org.batfish.datamodel.questions.smt.EnvironmentType) Map(java.util.Map) NetworkSlice(org.batfish.symbolic.abstraction.NetworkSlice) SmtDeterminismAnswerElement(org.batfish.symbolic.answers.SmtDeterminismAnswerElement) EnumMap(java.util.EnumMap) Collection(java.util.Collection) Set(java.util.Set) SmtReachabilityAnswerElement(org.batfish.symbolic.answers.SmtReachabilityAnswerElement) Graph(org.batfish.symbolic.Graph) PathRegexes(org.batfish.symbolic.utils.PathRegexes) Collectors(java.util.stream.Collectors) IBatfish(org.batfish.common.plugin.IBatfish) Settings(org.batfish.config.Settings) Model(com.microsoft.z3.Model) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) TriFunction(org.batfish.symbolic.utils.TriFunction) Optional(java.util.Optional) AnswerElement(org.batfish.datamodel.answers.AnswerElement) Pattern(java.util.regex.Pattern) SortedMap(java.util.SortedMap) IpWildcard(org.batfish.datamodel.IpWildcard) Ip(org.batfish.datamodel.Ip) Iterables(com.google.common.collect.Iterables) CommunityVar(org.batfish.symbolic.CommunityVar) Context(com.microsoft.z3.Context) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Abstraction(org.batfish.symbolic.abstraction.Abstraction) BoolExpr(com.microsoft.z3.BoolExpr) Configuration(org.batfish.datamodel.Configuration) ArithExpr(com.microsoft.z3.ArithExpr) Nullable(javax.annotation.Nullable) SmtManyAnswerElement(org.batfish.symbolic.answers.SmtManyAnswerElement) StaticRoute(org.batfish.datamodel.StaticRoute) BitVecExpr(com.microsoft.z3.BitVecExpr) Tuple(org.batfish.symbolic.utils.Tuple) GraphEdge(org.batfish.symbolic.GraphEdge) TreeMap(java.util.TreeMap) Expr(com.microsoft.z3.Expr) Protocol(org.batfish.symbolic.Protocol) HeaderLocationQuestion(org.batfish.datamodel.questions.smt.HeaderLocationQuestion) Table2(org.batfish.symbolic.collections.Table2) Collections(java.util.Collections) Prefix(org.batfish.datamodel.Prefix) DestinationClasses(org.batfish.symbolic.abstraction.DestinationClasses) FlowHistory(org.batfish.datamodel.FlowHistory) SmtReachabilityAnswerElement(org.batfish.symbolic.answers.SmtReachabilityAnswerElement) Map(java.util.Map) EnumMap(java.util.EnumMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 3 with FlowHistory

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

the class CounterExample method buildFlowHistoryDiff.

/*
   * Create a trace-based counterexample demonstrating
   * the difference between two networks on a single packet.
   */
FlowHistory buildFlowHistoryDiff(String testRigName, Collection<String> sourceRouters, Encoder enc, Encoder enc2, Map<String, BoolExpr> reach, Map<String, BoolExpr> reach2) {
    FlowHistory fh = new FlowHistory();
    assert (reach2 != null);
    for (String source : sourceRouters) {
        BoolExpr sourceVar1 = reach.get(source);
        BoolExpr sourceVar2 = reach2.get(source);
        String val1 = evaluate(sourceVar1);
        String val2 = evaluate(sourceVar2);
        if (!Objects.equals(val1, val2)) {
            Tuple<Flow, FlowTrace> diff = buildFlowTrace(enc, source);
            Tuple<Flow, FlowTrace> base = buildFlowTrace(enc2, source);
            SortedSet<Edge> failedLinksDiff = buildFailedLinks(enc);
            SortedSet<Edge> failedLinksBase = buildFailedLinks(enc2);
            SortedSet<BgpAdvertisement> envRoutesDiff = buildEnvRoutingTable(enc);
            SortedSet<BgpAdvertisement> envRoutesBase = buildEnvRoutingTable(enc2);
            Environment baseEnv = new Environment("BASE", testRigName, failedLinksBase, null, null, null, null, envRoutesBase);
            Environment failedEnv = new Environment("DELTA", testRigName, failedLinksDiff, null, null, null, null, envRoutesDiff);
            fh.addFlowTrace(base.getFirst(), "BASE", baseEnv, base.getSecond());
            fh.addFlowTrace(diff.getFirst(), "DELTA", failedEnv, diff.getSecond());
        }
    }
    return fh;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) FlowHistory(org.batfish.datamodel.FlowHistory) FlowTrace(org.batfish.datamodel.FlowTrace) Environment(org.batfish.datamodel.pojo.Environment) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge) Flow(org.batfish.datamodel.Flow)

Example 4 with FlowHistory

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

the class CounterExample method buildFlowHistory.

/*
   * Creates a trace-based example of what happens
   * to a packet (e.g., why it is not reachable).
   */
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
    FlowHistory fh = new FlowHistory();
    for (String source : sourceRouters) {
        Boolean sourceVar = reach.get(source);
        if (!sourceVar) {
            Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
            SortedSet<Edge> failedLinks = buildFailedLinks(enc);
            SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
            Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
            fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
        }
    }
    return fh;
}
Also used : BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) FlowHistory(org.batfish.datamodel.FlowHistory) FlowTrace(org.batfish.datamodel.FlowTrace) Environment(org.batfish.datamodel.pojo.Environment) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge) Flow(org.batfish.datamodel.Flow)

Aggregations

FlowHistory (org.batfish.datamodel.FlowHistory)4 Flow (org.batfish.datamodel.Flow)3 Environment (org.batfish.datamodel.pojo.Environment)3 GraphEdge (org.batfish.symbolic.GraphEdge)3 BoolExpr (com.microsoft.z3.BoolExpr)2 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)2 Edge (org.batfish.datamodel.Edge)2 FlowTrace (org.batfish.datamodel.FlowTrace)2 Iterables (com.google.common.collect.Iterables)1 ArithExpr (com.microsoft.z3.ArithExpr)1 BitVecExpr (com.microsoft.z3.BitVecExpr)1 Context (com.microsoft.z3.Context)1 Expr (com.microsoft.z3.Expr)1 Model (com.microsoft.z3.Model)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1