Search in sources :

Example 51 with Prefix

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

the class TransferSSA method matchFilterList.

/*
   * Converts a route filter list to a boolean expression.
   */
private BoolExpr matchFilterList(RouteFilterList x, SymbolicRoute other) {
    BoolExpr acc = _enc.mkFalse();
    List<RouteFilterLine> lines = new ArrayList<>(x.getLines());
    Collections.reverse(lines);
    for (RouteFilterLine line : lines) {
        Prefix p = line.getPrefix();
        SubRange r = line.getLengthRange();
        PrefixRange range = new PrefixRange(p, r);
        BoolExpr matches = _enc.isRelevantFor(other.getPrefixLength(), range);
        BoolExpr action = _enc.mkBool(line.getAction() == LineAction.ACCEPT);
        acc = _enc.mkIf(matches, action, acc);
    }
    return acc;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) PrefixRange(org.batfish.datamodel.PrefixRange) ArrayList(java.util.ArrayList) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Example 52 with Prefix

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

the class BDDAcl method computeWildcardMatch.

/*
   * Convert a set of wildcards and a packet field to a symbolic boolean expression
   */
private BDD computeWildcardMatch(Set<IpWildcard> wcs, BDDInteger field, @Nullable Set<Prefix> ignored) {
    BDD acc = _factory.zero();
    for (IpWildcard wc : wcs) {
        if (!wc.isPrefix()) {
            throw new BatfishException("ERROR: computeDstWildcards, non sequential mask detected");
        }
        Prefix p = wc.toPrefix();
        // if (!PrefixUtils.isContainedBy(p, ignored)) {
        acc = acc.or(isRelevantFor(p, field));
    // }
    }
    return acc;
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BatfishException(org.batfish.common.BatfishException) BDD(net.sf.javabdd.BDD) Prefix(org.batfish.datamodel.Prefix)

Example 53 with Prefix

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

the class BDDPacket method restrict.

public BDD restrict(BDD bdd, List<Prefix> prefixes) {
    if (prefixes.isEmpty()) {
        throw new BatfishException("Empty prefix list in BDDRecord restrict");
    }
    BDD r = restrict(bdd, prefixes.get(0));
    for (int i = 1; i < prefixes.size(); i++) {
        Prefix p = prefixes.get(i);
        BDD x = restrict(bdd, p);
        r = r.or(x);
    }
    return r;
}
Also used : BatfishException(org.batfish.common.BatfishException) BDD(net.sf.javabdd.BDD) Prefix(org.batfish.datamodel.Prefix)

Example 54 with Prefix

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

the class BDDRoute method restrict.

public BDDRoute restrict(List<Prefix> prefixes) {
    if (prefixes.isEmpty()) {
        throw new BatfishException("Empty prefix list in BDDRecord restrict");
    }
    BDDRoute r = restrict(prefixes.get(0));
    for (int i = 1; i < prefixes.size(); i++) {
        Prefix p = prefixes.get(i);
        BDDRoute x = restrict(p);
        r.orWith(x);
    }
    return r;
}
Also used : BatfishException(org.batfish.common.BatfishException) Prefix(org.batfish.datamodel.Prefix)

Example 55 with Prefix

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

the class AbstractRibTest method testGetRoutesWithReplacement.

/**
 * Check that getRoutes works as expected even when routes replace other routes based on
 * preference
 */
@Test
public void testGetRoutesWithReplacement() {
    // Use OSPF RIBs for this, as routes with better metric can replace other routes
    OspfIntraAreaRib rib = new OspfIntraAreaRib(null);
    Prefix prefix = Prefix.parse("1.1.1.1/32");
    rib.mergeRoute(new OspfIntraAreaRoute(prefix, null, 100, 30, 1));
    assertThat(rib.getRoutes(), hasSize(1));
    // This new route replaces old route
    OspfIntraAreaRoute newRoute = new OspfIntraAreaRoute(prefix, null, 100, 10, 1);
    rib.mergeRoute(newRoute);
    assertThat(rib.getRoutes(), contains(newRoute));
    // Add completely new route and check that the size increases
    rib.mergeRoute(new OspfIntraAreaRoute(Prefix.parse("2.2.2.2/32"), null, 100, 30, 1));
    assertThat(rib.getRoutes(), hasSize(2));
}
Also used : OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) Prefix(org.batfish.datamodel.Prefix) Test(org.junit.Test)

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