Skip to content
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

Merged
merged 8 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,54 @@ vrf_name
word
:
WORD
;

vni_number
:
// 0-16777214
uint32
;

vlan_id
:
// 1-4094
uint16
;


vlan_range
:
(
vlan_range_list += vlan_subrange
(
COMMA vlan_range_list += vlan_subrange
)*
)
| NONE
;

vlan_subrange
:
low = vlan_id
(
DASH high = vlan_id
)?
;

vni_range
:
(
vni_range_list += vni_subrange
(
COMMA vni_range_list += vni_subrange
)*
)
;

vni_subrange
:
low = vni_number
(
DASH high = vni_number
)?
;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parser grammar Legacy_interface;

import Legacy_common, Arista_interface;
import Legacy_common, Arista_interface, Arista_common;

options {
tokenVocab = AristaLexer;
Expand Down Expand Up @@ -42,6 +42,7 @@ eos_vxif_vxlan
| eos_vxif_vxlan_source_interface
| eos_vxif_vxlan_udp_port
| eos_vxif_vxlan_virtual_router
| eos_vxif_vxlan_vlan_vni_range
| eos_vxif_vxlan_vlan
| eos_vxif_vxlan_vrf
)
Expand Down Expand Up @@ -74,6 +75,11 @@ eos_vxif_vxlan_virtual_router
(ENCAPSULATION MAC_ADDRESS MLAG_SYSTEM_ID) NEWLINE
;

eos_vxif_vxlan_vlan_vni_range
:
VLAN vlans = vlan_range VNI vnis = vni_range NEWLINE
;

eos_vxif_vxlan_vlan
:
VLAN num = dec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
import org.batfish.grammar.arista.AristaParser.Eos_vxif_vxlan_udp_portContext;
import org.batfish.grammar.arista.AristaParser.Eos_vxif_vxlan_vlanContext;
import org.batfish.grammar.arista.AristaParser.Eos_vxif_vxlan_vlan_vniContext;
import org.batfish.grammar.arista.AristaParser.Eos_vxif_vxlan_vlan_vni_rangeContext;
import org.batfish.grammar.arista.AristaParser.Eos_vxif_vxlan_vrfContext;
import org.batfish.grammar.arista.AristaParser.Extended_access_list_additional_featureContext;
import org.batfish.grammar.arista.AristaParser.Extended_access_list_tailContext;
Expand Down Expand Up @@ -847,12 +848,16 @@
import org.batfish.grammar.arista.AristaParser.Vlan_d_nameContext;
import org.batfish.grammar.arista.AristaParser.Vlan_d_stateContext;
import org.batfish.grammar.arista.AristaParser.Vlan_d_trunkContext;
import org.batfish.grammar.arista.AristaParser.Vlan_idContext;
import org.batfish.grammar.arista.AristaParser.Vlan_nameContext;
import org.batfish.grammar.arista.AristaParser.Vlan_no_nameContext;
import org.batfish.grammar.arista.AristaParser.Vlan_no_stateContext;
import org.batfish.grammar.arista.AristaParser.Vlan_no_trunkContext;
import org.batfish.grammar.arista.AristaParser.Vlan_stateContext;
import org.batfish.grammar.arista.AristaParser.Vlan_subrangeContext;
import org.batfish.grammar.arista.AristaParser.Vlan_trunkContext;
import org.batfish.grammar.arista.AristaParser.Vni_numberContext;
import org.batfish.grammar.arista.AristaParser.Vni_subrangeContext;
import org.batfish.grammar.arista.AristaParser.Vrf_nameContext;
import org.batfish.grammar.arista.AristaParser.Vrfd_descriptionContext;
import org.batfish.grammar.arista.AristaParser.Wccp_idContext;
Expand Down Expand Up @@ -1032,6 +1037,14 @@ private static int toInteger(Token t) {
return Integer.parseInt(t.getText());
}

private static int toInteger(Vlan_idContext ctx) {
return Integer.parseInt(ctx.getText());
}

private static int toInteger(Vni_numberContext ctx) {
return Integer.parseInt(ctx.getText());
}

private static String toInterfaceName(Interface_nameContext ctx) {
StringBuilder name =
new StringBuilder(
Expand Down Expand Up @@ -1126,6 +1139,28 @@ private static SubRange toSubRange(SubrangeContext ctx) {
}
}

private static SubRange toSubRange(Vlan_subrangeContext ctx) {
// TODO: validate values
int low = toInteger(ctx.low);
if (ctx.DASH() != null) {
int high = toInteger(ctx.high);
return new SubRange(low, high);
} else {
return SubRange.singleton(low);
}
}

private static SubRange toSubRange(Vni_subrangeContext ctx) {
// TODO: validate values
int low = toInteger(ctx.low);
if (ctx.DASH() != null) {
int high = toInteger(ctx.high);
return new SubRange(low, high);
} else {
return SubRange.singleton(low);
}
}

private static String unquote(String text) {
if (text.length() == 0) {
return text;
Expand Down Expand Up @@ -3509,6 +3544,42 @@ public void exitEos_vxif_vxlan_udp_port(Eos_vxif_vxlan_udp_portContext ctx) {
_eosVxlan.setUdpPort(toInteger(ctx.num));
}

@Override
public void enterEos_vxif_vxlan_vlan_vni_range(Eos_vxif_vxlan_vlan_vni_rangeContext ctx) {
List<Integer> vnis = new ArrayList<>();
List<Integer> vlans = new ArrayList<>();

List<SubRange> vlanRange =
ctx.vlans.vlan_range_list.stream()
.map(AristaControlPlaneExtractor::toSubRange)
.collect(Collectors.toList());

for (SubRange subRange : vlanRange) {
for (int i = subRange.getStart(); i <= subRange.getEnd(); i++) {
vlans.add(i);
}
}
List<SubRange> vniRange =
ctx.vnis.vni_range_list.stream()
.map(AristaControlPlaneExtractor::toSubRange)
.collect(Collectors.toList());

for (SubRange subRange : vniRange) {
for (int i = subRange.getStart(); i <= subRange.getEnd(); i++) {
vnis.add(i);
}
}

if (vlans.size() != vnis.size()) {
warn(ctx, "Need to have 1:1 mapping of vlan to vni");
return;
}

for (int i = 0; i < vnis.size(); i++) {
_eosVxlan.getVlanVnis().put(vlans.get(i), vnis.get(i));
}
}

@Override
public void enterEos_vxif_vxlan_vlan(Eos_vxif_vxlan_vlanContext ctx) {
_currentVxlanVlanNum = toInteger(ctx.num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import static org.batfish.representation.arista.eos.AristaRedistributeType.OSPF_NSSA_EXTERNAL_TYPE_2;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -113,6 +114,7 @@
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -371,6 +373,56 @@ public void testOspfNetworkExtraction() {
new OspfNetwork(Prefix.strict("10.0.1.1/32"), 90L)));
}

@Test
public void testVxlanVniNewSyntax() {
{
AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_1_to_1");
assertThat(
config.getEosVxlan().getVlanVnis(),
equalTo(
ImmutableMap.of(
1, 1,
2, 2)));
}
{
AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_matching_ranges");
assertThat(
config.getEosVxlan().getVlanVnis(),
equalTo(
ImmutableMap.of(
3, 3,
4, 4,
5, 5)));
}
{
AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_range_on_left");
assertThat(
config.getEosVxlan().getVlanVnis(),
equalTo(
ImmutableMap.of(
9, 11,
10, 10,
11, 9)));
}
{
AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_range_on_right");
assertThat(
config.getEosVxlan().getVlanVnis(),
equalTo(
ImmutableMap.of(
8, 6,
7, 7,
6, 8)));
}
{
AristaConfiguration config = parseVendorConfig("arista_vxlan_new_syntax_invalid");
assertThat(
config.getWarnings().getParseWarnings(),
contains(hasComment("Need to have 1:1 mapping of vlan to vni")));
assertThat(config.getEosVxlan().getVlanVnis(), anEmptyMap());
}
}

@Test
public void testOspfNetworkConversion() {
String hostname = "arista_ospf_network";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RANCID-CONTENT-TYPE: arista
!
! boot system flash:/eos-4.24.2fx-evpn.swi
hostname arista_vxlan_new_syntax
!
interface Vxlan1
vxlan udp-port 4789
! New Syntax
! 1:1
vxlan vlan 1,2 vni 1,2
!
no ip routing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RANCID-CONTENT-TYPE: arista
!
! boot system flash:/eos-4.24.2fx-evpn.swi
hostname arista_vxlan_new_syntax
!
interface Vxlan1
vxlan udp-port 4789
! New Syntax
! invalid size not equal (test absence of key `12`)
vxlan vlan 12 vni 13,14
!
no ip routing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RANCID-CONTENT-TYPE: arista
!
! boot system flash:/eos-4.24.2fx-evpn.swi
hostname arista_vxlan_new_syntax
!
interface Vxlan1
vxlan udp-port 4789
! New Syntax
! matching ranges
vxlan vlan 3-5 vni 3-5
!
no ip routing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RANCID-CONTENT-TYPE: arista
!
! boot system flash:/eos-4.24.2fx-evpn.swi
hostname arista_vxlan_new_syntax
!
interface Vxlan1
vxlan udp-port 4789
! New Syntax
! range on left
vxlan vlan 9-11 vni 11,10,9
!
no ip routing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RANCID-CONTENT-TYPE: arista
!
! boot system flash:/eos-4.24.2fx-evpn.swi
hostname arista_vxlan_new_syntax
!
interface Vxlan1
vxlan udp-port 4789
! New Syntax
! range on right
vxlan vlan 8,7,6 vni 6-8
!
no ip routing