Search in sources :

Example 16 with SubRange

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

the class JuniperConfiguration method toAggregateRoute.

private org.batfish.datamodel.GeneratedRoute toAggregateRoute(AggregateRoute route) {
    Prefix prefix = route.getPrefix();
    int prefixLength = prefix.getPrefixLength();
    int administrativeCost = route.getMetric();
    String policyNameSuffix = route.getPrefix().toString().replace('/', '_').replace('.', '_');
    String policyName = "~AGGREGATE_" + policyNameSuffix + "~";
    RoutingPolicy routingPolicy = new RoutingPolicy(policyName, _c);
    If routingPolicyConditional = new If();
    routingPolicy.getStatements().add(routingPolicyConditional);
    routingPolicyConditional.getTrueStatements().add(Statements.ExitAccept.toStaticStatement());
    routingPolicyConditional.getFalseStatements().add(Statements.ExitReject.toStaticStatement());
    String rflName = "~AGGREGATE_" + policyNameSuffix + "_RF~";
    MatchPrefixSet isContributingRoute = new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(rflName));
    routingPolicyConditional.setGuard(isContributingRoute);
    RouteFilterList rfList = new RouteFilterList(rflName);
    rfList.addLine(new org.batfish.datamodel.RouteFilterLine(LineAction.ACCEPT, prefix, new SubRange(prefixLength + 1, Prefix.MAX_PREFIX_LENGTH)));
    org.batfish.datamodel.GeneratedRoute.Builder newRoute = new org.batfish.datamodel.GeneratedRoute.Builder();
    newRoute.setNetwork(prefix);
    newRoute.setAdmin(administrativeCost);
    newRoute.setDiscard(true);
    newRoute.setGenerationPolicy(policyName);
    _c.getRoutingPolicies().put(policyName, routingPolicy);
    _c.getRouteFilterLists().put(rflName, rfList);
    return newRoute.build();
}
Also used : NamedPrefixSet(org.batfish.datamodel.routing_policy.expr.NamedPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Prefix(org.batfish.datamodel.Prefix) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) RouteFilterList(org.batfish.datamodel.RouteFilterList) SubRange(org.batfish.datamodel.SubRange) If(org.batfish.datamodel.routing_policy.statement.If)

Example 17 with SubRange

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

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

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

the class Route6FilterLineLengthRange method applyTo.

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

Example 20 with SubRange

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

the class Route6FilterLineLonger method applyTo.

@Override
public void applyTo(Route6FilterList rfl) {
    int prefixLength = _prefix6.getPrefixLength();
    if (prefixLength >= Prefix6.MAX_PREFIX_LENGTH) {
        throw new BatfishException("Route filter prefix length cannot be 'longer' than " + Prefix6.MAX_PREFIX_LENGTH);
    }
    org.batfish.datamodel.Route6FilterLine line = new org.batfish.datamodel.Route6FilterLine(LineAction.ACCEPT, _prefix6, new SubRange(prefixLength + 1, Prefix6.MAX_PREFIX_LENGTH));
    rfl.addLine(line);
}
Also used : BatfishException(org.batfish.common.BatfishException) 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