-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRR: implement route-map match ip address prefix-len (#6617)
- Loading branch information
Showing
10 changed files
with
213 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,12 @@ ip_prefix_list_name | |
WORD | ||
; | ||
|
||
ip_prefix_length | ||
: | ||
// 0-32 | ||
UINT8 | ||
; | ||
|
||
line_action | ||
: | ||
deny = DENY | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ish/src/main/java/org/batfish/representation/cumulus/RouteMapMatchIpAddressPrefixLen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.batfish.representation.cumulus; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.batfish.common.Warnings; | ||
import org.batfish.datamodel.Configuration; | ||
import org.batfish.datamodel.Prefix; | ||
import org.batfish.datamodel.PrefixRange; | ||
import org.batfish.datamodel.PrefixSpace; | ||
import org.batfish.datamodel.SubRange; | ||
import org.batfish.datamodel.routing_policy.expr.BooleanExpr; | ||
import org.batfish.datamodel.routing_policy.expr.DestinationNetwork; | ||
import org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet; | ||
import org.batfish.datamodel.routing_policy.expr.MatchPrefixSet; | ||
|
||
/** | ||
* A {@link RouteMapMatch} that matches routes based on whether the route's network has the given | ||
* prefix length. | ||
*/ | ||
public final class RouteMapMatchIpAddressPrefixLen implements RouteMapMatch { | ||
|
||
private final int _len; | ||
|
||
public RouteMapMatchIpAddressPrefixLen(int len) { | ||
_len = len; | ||
} | ||
|
||
@Override | ||
public @Nonnull BooleanExpr toBooleanExpr( | ||
Configuration c, CumulusNodeConfiguration vc, Warnings w) { | ||
return new MatchPrefixSet( | ||
DestinationNetwork.instance(), | ||
new ExplicitPrefixSet( | ||
new PrefixSpace(new PrefixRange(Prefix.ZERO, SubRange.singleton(_len))))); | ||
} | ||
|
||
public int getLen() { | ||
return _len; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...src/test/java/org/batfish/representation/cumulus/RouteMapMatchIpAddressPrefixLenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.batfish.representation.cumulus; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.batfish.common.Warnings; | ||
import org.batfish.datamodel.Configuration; | ||
import org.batfish.datamodel.Prefix; | ||
import org.batfish.datamodel.StaticRoute; | ||
import org.batfish.datamodel.routing_policy.Environment; | ||
import org.batfish.datamodel.routing_policy.Result; | ||
import org.batfish.datamodel.routing_policy.expr.BooleanExpr; | ||
import org.junit.Test; | ||
|
||
public class RouteMapMatchIpAddressPrefixLenTest { | ||
|
||
@Test | ||
public void testConstructionAndGetter() { | ||
RouteMapMatchIpAddressPrefixLen match = new RouteMapMatchIpAddressPrefixLen(7); | ||
assertThat(match.getLen(), equalTo(7)); | ||
} | ||
|
||
@Test | ||
public void testToBooleanExpr() { | ||
RouteMapMatchIpAddressPrefixLen match = new RouteMapMatchIpAddressPrefixLen(7); | ||
CumulusNcluConfiguration config = new CumulusNcluConfiguration(); | ||
Configuration c = Configuration.builder().setHostname("c").build(); | ||
BooleanExpr expr = match.toBooleanExpr(c, config, new Warnings()); | ||
for (Prefix p : | ||
new Prefix[] {Prefix.ZERO, Prefix.parse("10.0.0.0/6"), Prefix.parse("10.0.0.0/8")}) { | ||
StaticRoute route = StaticRoute.testBuilder().setNetwork(p).build(); | ||
assertThat( | ||
expr.evaluate(Environment.builder(c).setOriginalRoute(route).build()), | ||
equalTo(Result.builder().setBooleanValue(false).build())); | ||
} | ||
for (Prefix p : new Prefix[] {Prefix.parse("10.0.0.0/7"), Prefix.parse("20.0.0.0/7")}) { | ||
StaticRoute route = StaticRoute.testBuilder().setNetwork(p).build(); | ||
assertThat( | ||
expr.evaluate(Environment.builder(c).setOriginalRoute(route).build()), | ||
equalTo(Result.builder().setBooleanValue(true).build())); | ||
} | ||
} | ||
} |