Search in sources :

Example 6 with RouteFilterLine

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

the class PsFromPrefixListFilterLonger method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) {
    PrefixList pl = jc.getPrefixLists().get(_prefixList);
    if (pl != null) {
        pl.getReferers().put(this, "from prefix-list-filter longer");
        if (pl.getIpv6()) {
            return BooleanExprs.False.toStaticBooleanExpr();
        }
        RouteFilterList rf = c.getRouteFilterLists().get(_prefixList);
        String longerListName = "~" + _prefixList + "~LONGER~";
        RouteFilterList longerList = c.getRouteFilterLists().get(longerListName);
        if (longerList == null) {
            longerList = new RouteFilterList(longerListName);
            for (RouteFilterLine line : rf.getLines()) {
                Prefix prefix = line.getPrefix();
                LineAction action = line.getAction();
                SubRange longerLineRange = new SubRange(line.getLengthRange().getStart() + 1, Prefix.MAX_PREFIX_LENGTH);
                if (longerLineRange.getStart() > Prefix.MAX_PREFIX_LENGTH) {
                    warnings.redFlag("'prefix-list-filter " + _prefixList + " longer' cannot match more specific prefix than " + prefix);
                    continue;
                }
                RouteFilterLine orLongerLine = new RouteFilterLine(action, prefix, longerLineRange);
                longerList.addLine(orLongerLine);
                c.getRouteFilterLists().put(longerListName, longerList);
            }
        }
        return new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(longerListName));
    } else {
        warnings.redFlag("Reference to undefined prefix-list: \"" + _prefixList + "\"");
        return BooleanExprs.False.toStaticBooleanExpr();
    }
}
Also used : LineAction(org.batfish.datamodel.LineAction) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) RouteFilterList(org.batfish.datamodel.RouteFilterList) NamedPrefixSet(org.batfish.datamodel.routing_policy.expr.NamedPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Example 7 with RouteFilterLine

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

the class PsFromPrefixListFilterOrLonger method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) {
    PrefixList pl = jc.getPrefixLists().get(_prefixList);
    if (pl != null) {
        pl.getReferers().put(this, "from prefix-list-filter or-longer");
        if (pl.getIpv6()) {
            return BooleanExprs.False.toStaticBooleanExpr();
        }
        RouteFilterList rf = c.getRouteFilterLists().get(_prefixList);
        String orLongerListName = "~" + _prefixList + "~ORLONGER~";
        RouteFilterList orLongerList = c.getRouteFilterLists().get(orLongerListName);
        if (orLongerList == null) {
            orLongerList = new RouteFilterList(orLongerListName);
            for (RouteFilterLine line : rf.getLines()) {
                Prefix prefix = line.getPrefix();
                LineAction action = line.getAction();
                SubRange orLongerLineRange = new SubRange(line.getLengthRange().getStart(), Prefix.MAX_PREFIX_LENGTH);
                RouteFilterLine orLongerLine = new RouteFilterLine(action, prefix, orLongerLineRange);
                orLongerList.addLine(orLongerLine);
                c.getRouteFilterLists().put(orLongerListName, orLongerList);
            }
        }
        return new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(orLongerListName));
    } else {
        warnings.redFlag("Reference to undefined prefix-list: \"" + _prefixList + "\"");
        return BooleanExprs.False.toStaticBooleanExpr();
    }
}
Also used : LineAction(org.batfish.datamodel.LineAction) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) RouteFilterList(org.batfish.datamodel.RouteFilterList) NamedPrefixSet(org.batfish.datamodel.routing_policy.expr.NamedPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Example 8 with RouteFilterLine

use of org.batfish.datamodel.RouteFilterLine 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 9 with RouteFilterLine

use of org.batfish.datamodel.RouteFilterLine 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 10 with RouteFilterLine

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

the class CiscoConfiguration method toRouteFilterLine.

private RouteFilterLine toRouteFilterLine(ExtendedAccessListLine fromLine) {
    LineAction action = fromLine.getAction();
    Ip ip = fromLine.getSourceIpWildcard().getIp();
    long minSubnet = fromLine.getDestinationIpWildcard().getIp().asLong();
    long maxSubnet = minSubnet | fromLine.getDestinationIpWildcard().getWildcard().asLong();
    int minPrefixLength = fromLine.getDestinationIpWildcard().getIp().numSubnetBits();
    int maxPrefixLength = new Ip(maxSubnet).numSubnetBits();
    int statedPrefixLength = fromLine.getSourceIpWildcard().getWildcard().inverted().numSubnetBits();
    int prefixLength = Math.min(statedPrefixLength, minPrefixLength);
    Prefix prefix = new Prefix(ip, prefixLength);
    return new RouteFilterLine(action, prefix, new SubRange(minPrefixLength, maxPrefixLength));
}
Also used : LineAction(org.batfish.datamodel.LineAction) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) SubRange(org.batfish.datamodel.SubRange) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Aggregations

RouteFilterLine (org.batfish.datamodel.RouteFilterLine)12 Prefix (org.batfish.datamodel.Prefix)10 SubRange (org.batfish.datamodel.SubRange)9 RouteFilterList (org.batfish.datamodel.RouteFilterList)8 Ip (org.batfish.datamodel.Ip)6 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)6 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)6 ArrayList (java.util.ArrayList)5 LineAction (org.batfish.datamodel.LineAction)5 PrefixRange (org.batfish.datamodel.PrefixRange)5 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)5 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)5 NamedPrefixSet (org.batfish.datamodel.routing_policy.expr.NamedPrefixSet)5 HashSet (java.util.HashSet)4 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)4 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)4 If (org.batfish.datamodel.routing_policy.statement.If)4 Statement (org.batfish.datamodel.routing_policy.statement.Statement)4 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)3 HashMap (java.util.HashMap)3