Search in sources :

Example 21 with SubRange

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

the class Route6FilterLineUpTo method applyTo.

@Override
public void applyTo(Route6FilterList rfl) {
    int prefixLength = _prefix6.getPrefixLength();
    org.batfish.datamodel.Route6FilterLine line = new org.batfish.datamodel.Route6FilterLine(LineAction.ACCEPT, _prefix6, new SubRange(prefixLength, _maxPrefixLength));
    rfl.addLine(line);
}
Also used : SubRange(org.batfish.datamodel.SubRange)

Example 22 with SubRange

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

the class Route4FilterLineOrLonger method applyTo.

@Override
public void applyTo(RouteFilterList rfl) {
    int prefixLength = _prefix.getPrefixLength();
    org.batfish.datamodel.RouteFilterLine line = new org.batfish.datamodel.RouteFilterLine(LineAction.ACCEPT, _prefix, new SubRange(prefixLength, Prefix.MAX_PREFIX_LENGTH));
    rfl.addLine(line);
}
Also used : SubRange(org.batfish.datamodel.SubRange)

Example 23 with SubRange

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

the class Route4FilterLineThrough method applyTo.

@Override
public void applyTo(RouteFilterList rfl) {
    int low = _prefix.getPrefixLength();
    int high = _throughPrefix.getPrefixLength();
    for (int i = low; i <= high; i++) {
        Ip currentNetworkAddress = _throughPrefix.getStartIp().getNetworkAddress(i);
        Prefix currentPrefix = new Prefix(currentNetworkAddress, i);
        org.batfish.datamodel.RouteFilterLine line = new org.batfish.datamodel.RouteFilterLine(LineAction.ACCEPT, currentPrefix, new SubRange(i, i));
        rfl.addLine(line);
    }
}
Also used : Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange)

Example 24 with SubRange

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

the class EncoderSlice method addHeaderSpaceConstraint.

/*
   * Add constraints for the type of packets we will consider in the model.
   * This can include restrictions on any packet field such as dstIp, protocol etc.
   */
private void addHeaderSpaceConstraint() {
    BoolExpr acc;
    if (_headerSpace.getDstIps().size() > 0) {
        acc = mkFalse();
        for (IpWildcard ipWildcard : _headerSpace.getDstIps()) {
            BoolExpr bound = ipWildCardBound(_symbolicPacket.getDstIp(), ipWildcard);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotDstIps().size() > 0) {
        acc = mkTrue();
        for (IpWildcard ipWildcard : _headerSpace.getNotDstIps()) {
            BoolExpr bound = ipWildCardBound(_symbolicPacket.getDstIp(), ipWildcard);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getSrcIps().size() > 0) {
        acc = mkFalse();
        for (IpWildcard ipWildcard : _headerSpace.getSrcIps()) {
            BoolExpr bound = ipWildCardBound(_symbolicPacket.getSrcIp(), ipWildcard);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotSrcIps().size() > 0) {
        acc = mkTrue();
        for (IpWildcard ipWildcard : _headerSpace.getNotSrcIps()) {
            BoolExpr bound = ipWildCardBound(_symbolicPacket.getSrcIp(), ipWildcard);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getSrcOrDstIps().size() > 0) {
        acc = mkFalse();
        for (IpWildcard ipWildcard : _headerSpace.getSrcOrDstIps()) {
            BoolExpr bound1 = ipWildCardBound(_symbolicPacket.getDstIp(), ipWildcard);
            BoolExpr bound2 = ipWildCardBound(_symbolicPacket.getSrcIp(), ipWildcard);
            acc = mkOr(acc, bound1, bound2);
        }
        add(acc);
    }
    if (_headerSpace.getDstPorts().size() > 0) {
        acc = mkFalse();
        for (SubRange subRange : _headerSpace.getDstPorts()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getDstPort(), subRange);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotDstPorts().size() > 0) {
        acc = mkTrue();
        for (SubRange subRange : _headerSpace.getNotDstPorts()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getDstPort(), subRange);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getSrcPorts().size() > 0) {
        acc = mkFalse();
        for (SubRange subRange : _headerSpace.getSrcPorts()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getDstPort(), subRange);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotSrcPorts().size() > 0) {
        acc = mkTrue();
        for (SubRange subRange : _headerSpace.getNotSrcPorts()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getDstPort(), subRange);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getSrcOrDstPorts().size() > 0) {
        acc = mkFalse();
        for (SubRange subRange : _headerSpace.getSrcOrDstPorts()) {
            BoolExpr bound1 = subRangeBound(_symbolicPacket.getDstPort(), subRange);
            BoolExpr bound2 = subRangeBound(_symbolicPacket.getSrcPort(), subRange);
            acc = mkOr(acc, bound1, bound2);
        }
        add(acc);
    }
    if (_headerSpace.getIcmpTypes().size() > 0) {
        acc = mkFalse();
        for (SubRange subRange : _headerSpace.getIcmpTypes()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getIcmpType(), subRange);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotIcmpTypes().size() > 0) {
        acc = mkTrue();
        for (SubRange subRange : _headerSpace.getNotIcmpTypes()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getIcmpType(), subRange);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getIcmpCodes().size() > 0) {
        acc = mkFalse();
        for (SubRange subRange : _headerSpace.getIcmpCodes()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getIcmpCode(), subRange);
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotIcmpCodes().size() > 0) {
        acc = mkTrue();
        for (SubRange subRange : _headerSpace.getNotIcmpCodes()) {
            BoolExpr bound = subRangeBound(_symbolicPacket.getIcmpCode(), subRange);
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
    if (_headerSpace.getIpProtocols().size() > 0) {
        acc = mkFalse();
        for (IpProtocol ipProtocol : _headerSpace.getIpProtocols()) {
            BoolExpr bound = mkEq(_symbolicPacket.getIpProtocol(), mkInt(ipProtocol.number()));
            acc = mkOr(acc, bound);
        }
        add(acc);
    }
    if (_headerSpace.getNotIpProtocols().size() > 0) {
        acc = mkTrue();
        for (IpProtocol ipProtocol : _headerSpace.getNotIpProtocols()) {
            BoolExpr bound = mkEq(_symbolicPacket.getIpProtocol(), mkInt(ipProtocol.number()));
            acc = mkAnd(acc, mkNot(bound));
        }
        add(acc);
    }
// TODO: need to implement fragment offsets, Ecns, states, etc
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BoolExpr(com.microsoft.z3.BoolExpr) IpProtocol(org.batfish.datamodel.IpProtocol) SubRange(org.batfish.datamodel.SubRange)

Example 25 with SubRange

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

the class EncoderSlice method computeValidRange.

/*
   * Convert a set of ranges and a packet field to a symbolic boolean expression
   */
private BoolExpr computeValidRange(Set<SubRange> ranges, ArithExpr field) {
    BoolExpr acc = mkFalse();
    for (SubRange range : ranges) {
        int start = range.getStart();
        int end = range.getEnd();
        if (start == end) {
            BoolExpr val = mkEq(field, mkInt(start));
            acc = mkOr(acc, val);
        } else {
            BoolExpr val1 = mkGe(field, mkInt(start));
            BoolExpr val2 = mkLe(field, mkInt(end));
            acc = mkOr(acc, mkAnd(val1, val2));
        }
    }
    return (BoolExpr) acc.simplify();
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) SubRange(org.batfish.datamodel.SubRange)

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