@Override public void applyTo(RouteFilterList rfl) { int prefixLength = _prefix.getPrefixLength(); if (prefixLength >= 32) { throw new BatfishException("Route filter prefix length cannot be 'longer' than 32"); } org.batfish.datamodel.RouteFilterLine line = new org.batfish.datamodel.RouteFilterLine( LineAction.PERMIT, PrefixRange.moreSpecificThan(_prefix)); rfl.addLine(line); }
p -> matchLonger.addLine( new RouteFilterLine(LineAction.PERMIT, PrefixRange.moreSpecificThan(p))));
/** * Generates and returns a {@link RoutingPolicy} that matches routes that should be aggregated for * aggregate network indicated by the given {@link Prefix}. * * <p>Does the bookkeeping in the provided {@link Configuration} to ensure the generated policy is * available and tracked. */ static RoutingPolicy generateAggregateRoutePolicy( Configuration c, String vrfName, Prefix prefix) { BooleanExpr matchLongerNetworks = new MatchPrefixSet( DestinationNetwork.instance(), new ExplicitPrefixSet(new PrefixSpace(PrefixRange.moreSpecificThan(prefix)))); If currentGeneratedRouteConditional = new If(matchLongerNetworks, singletonList(Statements.ReturnTrue.toStaticStatement())); RoutingPolicy policy = new RoutingPolicy("~AGGREGATE_ROUTE_GEN:" + vrfName + ":" + prefix + "~", c); policy.setStatements(ImmutableList.of(currentGeneratedRouteConditional)); c.getRoutingPolicies().put(policy.getName(), policy); return policy; }
/** * Tests that getting a range more specific than a /32 does not crash and is empty -- or at least * does not contain the initial /32. */ @Test public void testEmptyRange() { Prefix slash32 = Prefix.parse("1.2.3.4/32"); PrefixRange empty = PrefixRange.moreSpecificThan(slash32); assertFalse(empty.includesPrefixRange(PrefixRange.fromPrefix(slash32))); } }