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
Added support for Arista vlan to vni mapping new syntax #8197
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8197 +/- ##
============================================
+ Coverage 74.50% 74.51% +0.01%
- Complexity 43496 43584 +88
============================================
Files 3385 3394 +9
Lines 168700 168953 +253
Branches 20174 20204 +30
============================================
+ Hits 125686 125902 +216
- Misses 33469 33498 +29
- Partials 9545 9553 +8
|
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 5 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @drosarius)
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 1100 at r2 (raw file):
@Nonnull private static IntegerSpace toIntegerSpace(Vlan_rangeContext ctx) {
For this and the toIntegerSpace
function below, please add a comment: // TODO: validate values
.
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 3565 at r2 (raw file):
@Override public void enterEos_vxif_vxlan_vlan_vni_range(Eos_vxif_vxlan_vlan_vni_rangeContext ctx) { List<Integer> vnis = new ArrayList<>();
I'm not sure this extraction strategy works.
What is the semantics of this line?
Do you enumerate vlans and vnis one by one in order declared and map them accordingly? If so, your iteration method will mess up the order, since you end up enumerating each space in sorted order (not to mention contiguous ranges are coalesced in IntegerSpace enumeration of ranges).
If the semantics is map each vlan subrange in order to each vxlan range in order, then you shouldn't use IntegerSpace
at all.
Either way, you should check that the mappings are 1:1 and abort with a warning (warn(ctx, "some message")
) if not.
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 3568 at r2 (raw file):
List<Integer> vlans = new ArrayList<>(); if (ctx.vlans != null) {
Remove. This is always true.
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 3575 at r2 (raw file):
} } if (ctx.vnis != null) {
Remove. This is always true.
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 3584 at r2 (raw file):
for (int i = 0; i < vnis.size(); i++) { int idx = i; _eosVxlan.getVlanVnis().computeIfAbsent(vlans.get(idx), n -> vnis.get(idx));
FYI If it's typical to use large ranges here, the current use of individual mappings in the vendor model is a bad (inefficient) representation. But fixing that is out of scope for this PR.
projects/batfish/src/test/resources/org/batfish/grammar/arista/testconfigs/arista_vxlan_new_syntax, line 3 at r2 (raw file):
!RANCID-CONTENT-TYPE: arista ! hostname arista_vxlan_new_syntax
Which lines are new syntax? Please add a !
comment above each line that is new syntax, and identify (any) version using this new syntax.
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 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @drosarius)
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 1142 at r3 (raw file):
} private static SubRange toSubRange(Vlan_subrangeContext ctx) {
Please add the comment: // TODO: validate values
to each of the toSubRange
functions you added..
projects/batfish/src/main/java/org/batfish/grammar/arista/AristaControlPlaneExtractor.java, line 3578 at r3 (raw file):
for (int i = 0; i < vnis.size(); i++) { int idx = i; _eosVxlan.getVlanVnis().computeIfAbsent(vlans.get(idx), n -> vnis.get(idx));
Regarding use of computeIfAbsent
:
So you cannot overwrite a mapping with this line? Are you sure you shouldn't just put
instead?
projects/batfish/src/test/java/org/batfish/grammar/arista/AristaGrammarTest.java, line 377 at r3 (raw file):
public void testVxlanVniNewSyntax() { AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax"); assertThat(config.getEosVxlan().getVlanVnis(), hasEntry(1, 222));
Please test every mapping.
I'd suggest a pattern that is slightly more verbose but still complete and gives good assertion failure messages:
// (with static import of Maps.immutableEntry)
assertThat(config.getEosVxlan().getVlanVnis().entrySet(), containsInAnyOrder(
immutableEntry(k1, v1),
immutableEntry(k2,v2),
// ...
immutableEntry(kn,vn)));
projects/batfish/src/test/resources/org/batfish/grammar/arista/testconfigs/arista_vxlan_new_syntax, line 9 at r3 (raw file):
vxlan udp-port 4789 !New Syntax vxlan vlan 1,2,3,5-10,11-20 vni 222,111,2,555-560,11-20
Can you split this up into qualitatively different cases so each is easy to read and reason about?
E.g.
! 1:1
vxlan vlan 1,2 vni 1,2
! matching ranges
vxlan vlan 3-5 vni 3-5
! range on right
vxlan vlan 8,7,6 vni 6-8
! range on left
vxlan vlan 9-11 vni 11,10,9
! invalid size not equal (test absence of key `12`)
vxlan vlan 12 vni 13,14
If the semantics of the vxlan vlan
line is to clear and replace all mappings, then you'll have to split each interesting case into a separate file and junit test.
Else if the semantics of the vxlan vlan
line is to append (and replace existing?) mappings, can just split into separate lines as in example code given above.
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 7 of 7 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @drosarius)
projects/batfish/src/test/java/org/batfish/grammar/arista/AristaGrammarTest.java, line 413 at r4 (raw file):
{ AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_invalid"); assertThat(
Please also test that the mapping was not saved.
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 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @drosarius)
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 1 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @drosarius)
fix #8164