Search in sources :

Example 26 with SubRange

use of org.batfish.datamodel.SubRange 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 27 with SubRange

use of org.batfish.datamodel.SubRange 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)

Example 28 with SubRange

use of org.batfish.datamodel.SubRange 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 29 with SubRange

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

the class BDDAcl method computeValidRange.

/*
   * Convert a set of ranges and a packet field to a symbolic boolean expression
   */
private BDD computeValidRange(Set<SubRange> ranges, BDDInteger field) {
    BDD acc = _factory.zero();
    for (SubRange range : ranges) {
        int start = range.getStart();
        int end = range.getEnd();
        // System.out.println("Range: " + start + "--" + end);
        if (start == end) {
            BDD isValue = field.value(start);
            acc = acc.or(isValue);
        } else {
            BDD r = field.geq(start).and(field.leq(end));
            acc = acc.or(r);
        }
    }
    return acc;
}
Also used : BDD(net.sf.javabdd.BDD) SubRange(org.batfish.datamodel.SubRange)

Example 30 with SubRange

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

the class BoolExprTransformerTest method testVisitHeaderSpaceMatchExpr.

@Test
public void testVisitHeaderSpaceMatchExpr() {
    long ipCounter = 1L;
    int intCounter = 1;
    HeaderSpace.Builder<?, ?> hb = IpAccessListLine.builder();
    BooleanExpr expr = new HeaderSpaceMatchExpr(hb.setDscps(ImmutableSet.of(intCounter++, intCounter++)).setDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setDstProtocols(ImmutableSet.of(Protocol.DNS, Protocol.HTTP)).setEcns(ImmutableSet.of(intCounter++, intCounter++)).setFragmentOffsets(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIcmpCodes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIcmpTypes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIpProtocols(ImmutableSet.of(IpProtocol.AHP, IpProtocol.ARGUS)).setNegate(true).setNotDscps(ImmutableSet.of(intCounter++, intCounter++)).setNotDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setNotDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotDstProtocols(ImmutableSet.of(Protocol.HTTPS, Protocol.TELNET)).setNotEcns(ImmutableSet.of(intCounter++, intCounter++)).setNotFragmentOffsets(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIcmpCodes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIcmpTypes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIpProtocols(ImmutableSet.of(IpProtocol.BNA, IpProtocol.XNET)).setNotPacketLengths(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotSrcIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setNotSrcPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotSrcProtocols(ImmutableSet.of(Protocol.SSH, Protocol.TCP)).setPacketLengths(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setSrcOrDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setSrcOrDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcOrDstProtocols(ImmutableSet.of(Protocol.UDP, Protocol.HTTP)).setSrcPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcProtocols(ImmutableSet.of(Protocol.HTTPS, Protocol.DNS)).setStates(ImmutableSet.of(State.ESTABLISHED, State.NEW)).setTcpFlags(ImmutableSet.of(TcpFlags.builder().setAck(true).setUseAck(true).build(), TcpFlags.builder().setUseCwr(true).build())).build());
    assertThat(toBoolExpr(expr, _input, _nodContext), instanceOf(BoolExpr.class));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) SubRange(org.batfish.datamodel.SubRange) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Aggregations

SubRange (org.batfish.datamodel.SubRange)74 Prefix (org.batfish.datamodel.Prefix)18 IpWildcard (org.batfish.datamodel.IpWildcard)16 ArrayList (java.util.ArrayList)15 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)13 Ip (org.batfish.datamodel.Ip)11 FwFrom (org.batfish.representation.juniper.FwFrom)11 Test (org.junit.Test)11 BatfishException (org.batfish.common.BatfishException)9 LineAction (org.batfish.datamodel.LineAction)9 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)9 LinkedList (java.util.LinkedList)8 IpProtocol (org.batfish.datamodel.IpProtocol)8 RouteFilterList (org.batfish.datamodel.RouteFilterList)8 BoolExpr (com.microsoft.z3.BoolExpr)7 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)7 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)7 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)7 IpAccessList (org.batfish.datamodel.IpAccessList)6 PrefixRange (org.batfish.datamodel.PrefixRange)6