Search in sources :

Example 41 with Prefix

use of org.batfish.datamodel.Prefix 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 42 with Prefix

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

the class PropertyChecker method checkRoutingLoop.

/*
   * Checks for routing loops in the network. For efficiency reasons,
   * we only check for loops with routers that use static routes since
   * these can override the usual loop-prevention mechanisms.
   */
public AnswerElement checkRoutingLoop(HeaderQuestion q) {
    Graph graph = new Graph(_batfish);
    // Collect all relevant destinations
    List<Prefix> prefixes = new ArrayList<>();
    graph.getStaticRoutes().forEach((router, ifaceName, srs) -> {
        for (StaticRoute sr : srs) {
            prefixes.add(sr.getNetwork());
        }
    });
    SortedSet<IpWildcard> pfxs = new TreeSet<>();
    for (Prefix prefix : prefixes) {
        pfxs.add(new IpWildcard(prefix));
    }
    q.getHeaderSpace().setDstIps(pfxs);
    // Collect all routers that use static routes as a
    // potential node along a loop
    List<String> routers = new ArrayList<>();
    for (Entry<String, Configuration> entry : graph.getConfigurations().entrySet()) {
        String router = entry.getKey();
        Configuration conf = entry.getValue();
        if (conf.getDefaultVrf().getStaticRoutes().size() > 0) {
            routers.add(router);
        }
    }
    Encoder enc = new Encoder(_settings, graph, q);
    enc.computeEncoding();
    Context ctx = enc.getCtx();
    EncoderSlice slice = enc.getMainSlice();
    PropertyAdder pa = new PropertyAdder(slice);
    BoolExpr someLoop = ctx.mkBool(false);
    for (String router : routers) {
        BoolExpr hasLoop = pa.instrumentLoop(router);
        someLoop = ctx.mkOr(someLoop, hasLoop);
    }
    enc.add(someLoop);
    VerificationResult result = enc.verify().getFirst();
    return new SmtOneAnswerElement(result);
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) StaticRoute(org.batfish.datamodel.StaticRoute) Configuration(org.batfish.datamodel.Configuration) ArrayList(java.util.ArrayList) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement) Prefix(org.batfish.datamodel.Prefix) IpWildcard(org.batfish.datamodel.IpWildcard) Graph(org.batfish.symbolic.Graph) TreeSet(java.util.TreeSet)

Example 43 with Prefix

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

the class PropertyChecker method ignoredDestinations.

/*
   * Creates a boolean variable representing destinations we don't want
   * to consider due to local differences.
   */
private BoolExpr ignoredDestinations(Context ctx, EncoderSlice e1, String r1, Configuration conf1) {
    BoolExpr validDest = ctx.mkBool(true);
    for (Protocol proto1 : e1.getProtocols().get(r1)) {
        Set<Prefix> prefixes = Graph.getOriginatedNetworks(conf1, proto1);
        BoolExpr dest = e1.relevantOrigination(prefixes);
        validDest = ctx.mkAnd(validDest, ctx.mkNot(dest));
    }
    return validDest;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Prefix(org.batfish.datamodel.Prefix) Protocol(org.batfish.symbolic.Protocol)

Example 44 with Prefix

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

the class TransferBDD method isRelevantFor.

/*
   * Check if a prefix range match is applicable for the packet destination
   * Ip address, given the prefix length variable.
   *
   * Since aggregation is modelled separately, we assume that prefixLen
   * is not modified, and thus will contain only the underlying variables:
   * [var(0), ..., var(n)]
   */
private BDD isRelevantFor(BDDRoute record, PrefixRange range) {
    Prefix p = range.getPrefix();
    SubRange r = range.getLengthRange();
    int len = p.getPrefixLength();
    int lower = r.getStart();
    int upper = r.getEnd();
    BDD lowerBitsMatch = firstBitsEqual(record.getPrefix().getBitvec(), p, len);
    BDD acc = factory.zero();
    if (lower == 0 && upper == 32) {
        acc = factory.one();
    } else {
        for (int i = lower; i <= upper; i++) {
            BDD equalLen = record.getPrefixLength().value(i);
            acc = acc.or(equalLen);
        }
    }
    return acc.and(lowerBitsMatch);
}
Also used : BDD(net.sf.javabdd.BDD) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange)

Example 45 with Prefix

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

the class TransferBDD method matchFilterList.

/*
   * Converts a route filter list to a boolean expression.
   */
private BDD matchFilterList(TransferParam<BDDRoute> p, RouteFilterList x, BDDRoute other) {
    BDD acc = factory.zero();
    List<RouteFilterLine> lines = new ArrayList<>(x.getLines());
    Collections.reverse(lines);
    for (RouteFilterLine line : lines) {
        Prefix pfx = line.getPrefix();
        if (!PrefixUtils.isContainedBy(pfx, _ignoredNetworks)) {
            SubRange r = line.getLengthRange();
            PrefixRange range = new PrefixRange(pfx, r);
            p.debug("Prefix Range: " + range);
            p.debug("Action: " + line.getAction());
            BDD matches = isRelevantFor(other, range);
            BDD action = mkBDD(line.getAction() == LineAction.ACCEPT);
            acc = ite(matches, action, acc);
        }
    }
    return acc;
}
Also used : PrefixRange(org.batfish.datamodel.PrefixRange) BDD(net.sf.javabdd.BDD) ArrayList(java.util.ArrayList) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Aggregations

Prefix (org.batfish.datamodel.Prefix)133 Ip (org.batfish.datamodel.Ip)53 Configuration (org.batfish.datamodel.Configuration)33 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)29 Interface (org.batfish.datamodel.Interface)28 BatfishException (org.batfish.common.BatfishException)22 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)20 SubRange (org.batfish.datamodel.SubRange)19 HashMap (java.util.HashMap)18 StaticRoute (org.batfish.datamodel.StaticRoute)18 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)17 BgpProcess (org.batfish.datamodel.BgpProcess)17 SortedSet (java.util.SortedSet)16 TreeSet (java.util.TreeSet)16 AbstractRoute (org.batfish.datamodel.AbstractRoute)16 RoutingProtocol (org.batfish.datamodel.RoutingProtocol)16 TreeMap (java.util.TreeMap)14 HashSet (java.util.HashSet)13