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