Search in sources :

Example 11 with RouteFilterList

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

the class VyosConfiguration method toRouteFilterList.

private RouteFilterList toRouteFilterList(PrefixList prefixList) {
    String name = prefixList.getName();
    RouteFilterList newList = new RouteFilterList(name);
    List<RouteFilterLine> newLines = prefixList.getRules().values().stream().map(l -> new RouteFilterLine(l.getAction(), l.getPrefix(), l.getLengthRange())).collect(ImmutableList.toImmutableList());
    newList.setLines(newLines);
    return newList;
}
Also used : IpsecVpn(org.batfish.datamodel.IpsecVpn) SortedSet(java.util.SortedSet) If(org.batfish.datamodel.routing_policy.statement.If) Statements(org.batfish.datamodel.routing_policy.statement.Statements) IkePolicy(org.batfish.datamodel.IkePolicy) HashMap(java.util.HashMap) RouteFilterList(org.batfish.datamodel.RouteFilterList) BatfishException(org.batfish.common.BatfishException) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpsecPolicy(org.batfish.datamodel.IpsecPolicy) IkeGateway(org.batfish.datamodel.IkeGateway) ImmutableList(com.google.common.collect.ImmutableList) RouteFilterLine(org.batfish.datamodel.RouteFilterLine) Map(java.util.Map) Configuration(org.batfish.datamodel.Configuration) LineAction(org.batfish.datamodel.LineAction) Statement(org.batfish.datamodel.routing_policy.statement.Statement) Conjunction(org.batfish.datamodel.routing_policy.expr.Conjunction) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) IpsecProposal(org.batfish.datamodel.IpsecProposal) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) IpsecProtocol(org.batfish.datamodel.IpsecProtocol) List(java.util.List) TreeMap(java.util.TreeMap) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Entry(java.util.Map.Entry) VendorConversionException(org.batfish.common.VendorConversionException) Ip(org.batfish.datamodel.Ip) RouteFilterList(org.batfish.datamodel.RouteFilterList) RouteFilterLine(org.batfish.datamodel.RouteFilterLine)

Example 12 with RouteFilterList

use of org.batfish.datamodel.RouteFilterList 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 13 with RouteFilterList

use of org.batfish.datamodel.RouteFilterList 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 14 with RouteFilterList

use of org.batfish.datamodel.RouteFilterList 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 15 with RouteFilterList

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

the class PsFromRouteFilter method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) {
    RouteFilterList rfl = c.getRouteFilterLists().get(_routeFilterName);
    Route6FilterList rfl6 = c.getRoute6FilterLists().get(_routeFilterName);
    BooleanExpr match4 = null;
    BooleanExpr match6 = null;
    if (rfl != null) {
        match4 = new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(_routeFilterName));
    }
    if (rfl6 != null) {
        match6 = new MatchPrefix6Set(new DestinationNetwork6(), new NamedPrefix6Set(_routeFilterName));
    }
    if (match4 != null && match6 == null) {
        return match4;
    } else if (rfl == null && rfl6 != null) {
        return match6;
    } else if (rfl != null && rfl6 != null) {
        Disjunction d = new Disjunction();
        d.getDisjuncts().add(match4);
        d.getDisjuncts().add(match6);
        return d;
    } else {
        throw new VendorConversionException("missing route filter list: \"" + _routeFilterName + "\"");
    }
}
Also used : MatchPrefix6Set(org.batfish.datamodel.routing_policy.expr.MatchPrefix6Set) VendorConversionException(org.batfish.common.VendorConversionException) Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) 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) Route6FilterList(org.batfish.datamodel.Route6FilterList) NamedPrefix6Set(org.batfish.datamodel.routing_policy.expr.NamedPrefix6Set) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) DestinationNetwork6(org.batfish.datamodel.routing_policy.expr.DestinationNetwork6)

Aggregations

RouteFilterList (org.batfish.datamodel.RouteFilterList)24 Prefix (org.batfish.datamodel.Prefix)11 NamedPrefixSet (org.batfish.datamodel.routing_policy.expr.NamedPrefixSet)11 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)10 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)10 SubRange (org.batfish.datamodel.SubRange)9 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)9 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)8 Ip (org.batfish.datamodel.Ip)7 If (org.batfish.datamodel.routing_policy.statement.If)7 ArrayList (java.util.ArrayList)6 BatfishException (org.batfish.common.BatfishException)6 IpWildcard (org.batfish.datamodel.IpWildcard)6 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)6 Statement (org.batfish.datamodel.routing_policy.statement.Statement)6 Configuration (org.batfish.datamodel.Configuration)5 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)5 PrefixRange (org.batfish.datamodel.PrefixRange)5 Route6FilterList (org.batfish.datamodel.Route6FilterList)5 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)5