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

Junos: Add missing vxlan grammar #8112

Merged
merged 22 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 10 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
Expand Up @@ -570,6 +570,8 @@ DTCP_ONLY: 'dtcp-only';

DUMP_ON_PANIC: 'dump-on-panic';

DUPLICATE_MAC_DETECTION: 'duplicate-mac-detection';

DVMRP: 'dvmrp';

DYNAMIC: 'dynamic';
Expand Down Expand Up @@ -1978,6 +1980,8 @@ OUTPUT_VLAN_MAP: 'output-vlan-map';

OUTER: 'outer';

OVERLAY_ECMP: 'overlay-ecmp';

OVERLOAD: 'overload';

OVERRIDE_METRIC: 'override-metric';
Expand Down Expand Up @@ -2862,6 +2866,8 @@ VTEP_SOURCE_INTERFACE

VXLAN: 'vxlan';

VXLAN_ROUTING: 'vxlan-routing';

WEB_MANAGEMENT: 'web-management';

WEBAPI: 'webapi';
Expand Down
Expand Up @@ -177,6 +177,7 @@ s_vlans_named
| vlt_interface
| vlt_l3_interface
| vlt_vlan_id
| vlt_vni_id
)
;

Expand Down Expand Up @@ -220,3 +221,8 @@ vlt_vlan_id
:
VLAN_ID id = dec
;

vlt_vni_id
:
VXLAN VNI vni_number
;
Expand Up @@ -671,3 +671,10 @@ wildcard
WILDCARD
| WILDCARD_ARTIFACT
;

vni_number
:
// 0 through 16,777,215
// https://www.juniper.net/documentation/us/en/software/junos/evpn-vxlan/topics/ref/statement/vni-vxlan.html#id-vni__d49551e60
uint32
;
Expand Up @@ -18,7 +18,15 @@ e_encapsulation

e_extended_vni_list
:
EXTENDED_VNI_LIST range
EXTENDED_VNI_LIST (
range
| ALL
)
;

e_duplicate_mac_detection_null
:
DUPLICATE_MAC_DETECTION null_filler
;

e_multicast_mode
Expand Down Expand Up @@ -80,6 +88,7 @@ p_evpn
| e_extended_vni_list
| e_multicast_mode
| e_vni_options
| e_duplicate_mac_detection_null
)
;

Expand Down
Expand Up @@ -41,6 +41,14 @@ fo_null
) null_filler
;

fo_vxlan_routing
:
VXLAN_ROUTING
(
fov_overlay_ecmp
)
;

fod_active_server_group
:
ACTIVE_SERVER_GROUP name = junos_name
Expand Down Expand Up @@ -148,6 +156,11 @@ fohb_server_null
)?
;

fov_overlay_ecmp
:
OVERLAY_ECMP
;

s_forwarding_options
:
FORWARDING_OPTIONS
Expand All @@ -156,5 +169,6 @@ s_forwarding_options
| fo_dhcp_relay
| fo_helpers
| fo_null
| fo_vxlan_routing
)
;
Expand Up @@ -292,6 +292,7 @@
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Filter_nameContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Flat_juniper_configurationContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Fo_dhcp_relayContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Fo_vxlan_routingContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Fod_active_server_groupContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Fod_groupContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Fod_server_groupContext;
Expand Down Expand Up @@ -673,6 +674,8 @@
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Vlt_interfaceContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Vlt_l3_interfaceContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Vlt_vlan_idContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Vlt_vni_idContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.Vni_numberContext;
import org.batfish.grammar.flatjuniper.FlatJuniperParser.ZoneContext;
import org.batfish.grammar.silent_syntax.SilentSyntaxCollection;
import org.batfish.representation.juniper.AddressAddressBookEntry;
Expand Down Expand Up @@ -893,6 +896,8 @@ public class ConfigurationBuilder extends FlatJuniperParserBaseListener

private static final StaticRoute DUMMY_STATIC_ROUTE = new StaticRoute(Prefix.ZERO);

private static final IntegerSpace VNI_NUMBER_RANGE = IntegerSpace.of(new SubRange(0, 16777215));

private String convErrorMessage(Class<?> type, ParserRuleContext ctx) {
return String.format("Could not convert to %s: %s", type.getSimpleName(), getFullText(ctx));
}
Expand Down Expand Up @@ -1817,6 +1822,11 @@ private static int toInt(Named_portContext ctx) {
return getNamedPort(ctx).number();
}

private @Nonnull Optional<Integer> toInteger(
ParserRuleContext messageCtx, Vni_numberContext ctx) {
return toIntegerInSpace(messageCtx, ctx, VNI_NUMBER_RANGE, "vni");
}

private static @Nonnull IpOptions toIpOptions(Ip_optionContext ctx) {
if (ctx.LOOSE_SOURCE_ROUTE() != null) {
return IpOptions.LOOSE_SOURCE_ROUTE;
Expand Down Expand Up @@ -2389,6 +2399,11 @@ public void enterFf_term(Ff_termContext ctx) {
FIREWALL_FILTER_TERM, defName, FIREWALL_FILTER_TERM_DEFINITION, getLine(ctx.name.start));
}

@Override
public void exitFo_vxlan_routing(Fo_vxlan_routingContext ctx) {
todo(ctx);
}

@Override
public void enterFo_dhcp_relay(Fo_dhcp_relayContext ctx) {
_currentDhcpRelayGroup =
Expand Down Expand Up @@ -6527,6 +6542,17 @@ public void exitVlt_vlan_id(Vlt_vlan_idContext ctx) {
_currentNamedVlan.setVlanId(vlan);
}

@Override
public void exitVlt_vni_id(Vlt_vni_idContext ctx) {
Optional<Integer> maybeVniNumber = toInteger(ctx, ctx.vni_number());
if (!maybeVniNumber.isPresent()) {
// already warned
return;
}
int vni = maybeVniNumber.get();
_currentNamedVlan.setVniId(vni);
}

@Override
public void exitVlt_interface(Vlt_interfaceContext ctx) {
String name = getInterfaceFullName(ctx.interface_id());
Expand Down
Expand Up @@ -15,6 +15,7 @@ public class Vlan implements Serializable {
private @Nonnull Set<String> _interfaces;
private @Nullable String _l3Interface;
private @Nullable Integer _vlanId;
private @Nullable Integer _vniId;

public Vlan(String name) {
_name = name;
Expand All @@ -41,10 +42,18 @@ public void addInterface(String ifname) {
return _vlanId;
}

public @Nullable Integer getVniId() {
return _vniId;
}

public void setVlanId(int vlanId) {
_vlanId = vlanId;
}

public void setVniId(int vniId) {
_vniId = vniId;
}

public void setL3Interface(String l3Interface) {
_l3Interface = l3Interface;
}
Expand Down
Expand Up @@ -193,6 +193,7 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -1539,6 +1540,12 @@ public void testEthernetSwitchingFilterReference() throws IOException {
assertThat(ccae, hasNumReferrers(filename, FIREWALL_FILTER, "esfilter2", 0));
}

@Test
public void testEvpnExtraction() {
JuniperConfiguration c = parseJuniperConfig("juniper-evpn");
// TODO
}

@Test
public void testFirewallFilterReferences() throws IOException {
String hostname = "firewall-filters";
Expand Down Expand Up @@ -2889,6 +2896,14 @@ public void testInterfacePrimary() throws IOException {
+ " primary.")));
}

@Test
public void testInterfaceVniExtraction() {
JuniperConfiguration c = parseJuniperConfig("interface-vni");
Integer vni = c.getMasterLogicalSystem().getNamedVlans().get("VLAN_TEST").getVniId();
Integer vni0 = 10101;
assertEquals(vni, vni0);
}

@Test
public void testJuniperOspfIntervals() {
JuniperConfiguration config = parseJuniperConfig("ospf-intervals");
Expand Down Expand Up @@ -5000,6 +5015,19 @@ public void testOspfSummaries() {
LineAction.PERMIT, Prefix.ZERO, new SubRange(0, Prefix.MAX_PREFIX_LENGTH)))));
}

@Test
public void testOverlayEcmp() throws IOException {
String hostname = "juniper-overlay-ecmp";
Batfish batfish = getBatfishForConfigurationNames(hostname);
ParseVendorConfigurationAnswerElement pvcae =
batfish.loadParseVendorConfigurationAnswerElement(batfish.getSnapshot());
assertThat(
pvcae,
hasParseWarning(
"configs/" + hostname,
equalTo("Batfish does not enable two-level equal-cost multipath next hops.")));
}

@Test
public void testParsingRecovery() {
String recoveryText = readResource("org/batfish/grammar/juniper/testconfigs/recovery", UTF_8);
Expand Down
@@ -0,0 +1,10 @@
#
set system host-name interface-vni
#
set interfaces ge-0/0/0 unit 0 family ethernet-switching vlan members VLAN_TEST
set interfaces ge-0/0/0 unit 0 family ethernet-switching interface-mode trunk

set vlans VLAN_TEST vlan-id 101

set vlans VLAN_TEST vlan-id 101
set vlans VLAN_TEST vxlan vni 10101
@@ -0,0 +1,18 @@
#
set system host-name juniper-evpn
#
set interfaces ge-0/0/0 unit 0 family ethernet-switching vlan members VLAN_TEST
set interfaces ge-0/0/0 unit 0 family ethernet-switching interface-mode trunk

set vlans VLAN_TEST vlan-id 101

set vlans VLAN_TEST vlan-id 101
set vlans VLAN_TEST vxlan vni 10101


set protocols evpn vni-options vni 10101 vrf-target target:65310:11003
set protocols evpn encapsulation vxlan
set protocols evpn multicast-mode ingress-replication
set protocols evpn default-gateway no-gateway-community
set protocols evpn extended-vni-list all
set protocols evpn duplicate-mac-detection auto-recovery-time 15
@@ -0,0 +1,4 @@
#
set system host-name juniper-overlay-ecmp
#
set forwarding-options vxlan-routing overlay-ecmp