-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "set comm-list delete" for standard comm-lists in FRR. #5549
Support "set comm-list delete" for standard comm-lists in FRR. #5549
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5549 +/- ##
============================================
+ Coverage 73.53% 73.67% +0.14%
- Complexity 32410 32505 +95
============================================
Files 2643 2648 +5
Lines 130041 130090 +49
Branches 15593 15554 -39
============================================
+ Hits 95625 95844 +219
+ Misses 26826 26661 -165
+ Partials 7590 7585 -5
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 6 of 9 files at r1, 1 of 2 files at r2.
Reviewable status: 7 of 9 files reviewed, 5 unresolved discussions (waiting on @arifogel and @raveranj)
projects/batfish/src/main/java/org/batfish/grammar/cumulus_frr/CumulusFrrConfigurationBuilder.java, line 301 at r2 (raw file):
} private @Nonnull String toString(ParserRuleContext ctx) {
Don't make this change. If you need to add another toString
function taking a different type, do so.
The point of using specific arguments is to force a compile error if someone accidentally passes in the wrong thing.
projects/batfish/src/main/java/org/batfish/representation/cumulus/CumulusConversions.java, line 1316 at r2 (raw file):
Set<Community> blacklist = new HashSet<>(); for (IpCommunityListStandardLine line : ipCommunityListStandard.getLines()) { // Cumulus lets one specify multiple communities in a line.
Add a TODO comment, e.g.
// TODO: support set comm-list delete semantics for line with more than one community
projects/batfish/src/main/java/org/batfish/representation/cumulus/CumulusConversions.java, line 1321 at r2 (raw file):
} line.getCommunities() .forEach(
You cannot do this for each community in the line. It will not implement the correct semantics.
Cumulus semantics for set comm-list delete
with more than one community on a line in the referenced list are not expressible via a context-free CommunityMatchExpr
. Whether or not a given community is removed by a list depends on all the communities in the route, not just the community under consideration.
We do not support this type of operation at the moment further down the pipeline.
I suggest for now you keep the old implementation for this function, and just add the TODO as suggested above.
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 417 at r2 (raw file):
// RMs using expanded comm-lists. RoutingPolicy rpExtended1 =
nit: Expanded
, not Extended
. Otherwise it sounds like a policy for extended communities.
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 436 at r2 (raw file):
c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_COMM_BEGIN_WITH_3"); Bgpv4Route outputRoute1 = processRouteIn(rpExtended1, inRoute);
This style is very error-prone. You can get around declaring multiple variables and keeping track of numbers by using lexical scoping.
For instance:
...
{
RoutingPolicy rp = c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_ALL_COMMUNITIES");
assertThat(processRouteIn(rp, inRoute).getCommunities(), empty()); // prefer empty() to hasSize(0)
}
{
RoutingPolicy rp = c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_COMM_BEGIN_WITH_1");
assertThat(
processRouteIn(rp, inRoute).getCommunities(),
containsInAnyOrder( // use containsInAnyOrder because we are asserting properties of a set, not a list
StandardCommunity.of(2, 1),
StandardCommunity.of(2, 2),
StandardCommunity.of(3, 1),
StandardCommunity.of(3, 2)));
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 7 of 9 files reviewed, 5 unresolved discussions (waiting on @arifogel and @raveranj)
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 436 at r2 (raw file):
Previously, arifogel (Ari Fogel) wrote…
This style is very error-prone. You can get around declaring multiple variables and keeping track of numbers by using lexical scoping.
For instance:... { RoutingPolicy rp = c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_ALL_COMMUNITIES"); assertThat(processRouteIn(rp, inRoute).getCommunities(), empty()); // prefer empty() to hasSize(0) } { RoutingPolicy rp = c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_COMM_BEGIN_WITH_1"); assertThat( processRouteIn(rp, inRoute).getCommunities(), containsInAnyOrder( // use containsInAnyOrder because we are asserting properties of a set, not a list StandardCommunity.of(2, 1), StandardCommunity.of(2, 2), StandardCommunity.of(3, 1), StandardCommunity.of(3, 2))); } ...
As I side note, this suggested style keeps the name of the policy near the thing being asserted; this makes it much easier to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r2.
Reviewable status: 8 of 9 files reviewed, 6 unresolved discussions (waiting on @arifogel and @raveranj)
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 428 at r2 (raw file):
// RMs using standard comm-lists. RoutingPolicy rpStandard1 = c.getRoutingPolicies().get("RM_STANDARD_TEST_DELETE_ALL_COMMUNITIES");
My takeaway from our offline conversation about multiple communities per line was that this policy would delete all communities only if all are present. If only some are present, it should do nothing. In this case, you really need to test more than one input route to prove correct behavior.
If I misunderstood, we should have a longer discussion offline.
My suggestion above to add a TODO would make this moot; you wouldn't then be able to test correct semantics for this policy yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 9 files at r1.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @raveranj)
…support only comm-lists with one community; refactor UT.
projects/batfish/src/main/java/org/batfish/grammar/cumulus_frr/CumulusFrrConfigurationBuilder.java, line 301 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Reverted it. |
projects/batfish/src/main/java/org/batfish/representation/cumulus/CumulusConversions.java, line 1316 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. |
projects/batfish/src/main/java/org/batfish/representation/cumulus/CumulusConversions.java, line 1321 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. Reverted to align with the TODO. |
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 417 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Removed the variables. Used lexical scoping instead as mentioned below. Thanks! |
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 428 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Yes, we are on the page w.r.t. the expected aforementioned behavior. Fixed up the tests to have only 1 community per line to align with the TODO for now. |
projects/batfish/src/test/java/org/batfish/grammar/cumulus_concatenated/CumulusConcatenatedGrammarTest.java, line 436 at r2 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. Agree. This is much cleaner & easier to maintain. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @raveranj)
projects/batfish/src/test/resources/org/batfish/grammar/cumulus_concatenated/testconfigs/set_comm_list_delete_test, line 25 at r3 (raw file):
ip community-list expanded test_expanded_delete_all_communities permit "[0-9]+:[0-9]+" ip community-list expanded test_expanded_delete_comm_begin_with_1 permit "1:.*" ip community-list expanded test_expanded_delete_comm_begin_with_2 permit "2:.*"
For coverage, please add 1 or more community lists that have multiple lines, at least one of which is a deny line.
E.g. the following should only delete 1:2
deny 1:1
permit 1:1
permit 1:2
projects/batfish/src/test/resources/org/batfish/grammar/cumulus_concatenated/testconfigs/set_comm_list_delete_test, line 25 at r3 (raw file): Previously, arifogel (Ari Fogel) wrote…
Done. Added coverage for both expanded and standard comm-lists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4.
Reviewable status: complete! all files reviewed, all discussions resolved
No description provided.