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);
}
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;
}
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;
}
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;
}
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));
}
Aggregations