Skip to content

Commit

Permalink
parsing for EIGRP distribute list out (#6269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratulm committed Oct 1, 2020
1 parent 777a7a1 commit 00c74bd
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.batfish.datamodel.acl.AclLineMatchExpr;
import org.batfish.datamodel.acl.PermittedByAcl;
import org.batfish.datamodel.answers.ConvertConfigurationAnswerElement;
import org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement;
import org.batfish.datamodel.eigrp.EigrpProcess;
import org.batfish.datamodel.isis.IsisProcess;
import org.batfish.datamodel.matchers.ConfigurationMatchersImpl.HasRoute6FilterList;
Expand All @@ -36,6 +37,7 @@
import org.batfish.datamodel.matchers.HeaderSpaceMatchersImpl.HasSrcOrDstPorts;
import org.batfish.datamodel.matchers.InterfaceMatchersImpl.HasBandwidth;
import org.batfish.datamodel.matchers.OspfProcessMatchersImpl.HasReferenceBandwidth;
import org.batfish.datamodel.matchers.ParseVendorConfigurationAnswerElementMatchers.HasParseWarning;
import org.batfish.datamodel.matchers.VrfMatchersImpl.HasEigrpProcesses;
import org.batfish.datamodel.matchers.VrfMatchersImpl.HasIsisProcess;
import org.batfish.datamodel.ospf.OspfProcess;
Expand Down Expand Up @@ -126,6 +128,15 @@ public static Matcher<Configuration> hasZone(
return hasOutgoingFilter(IpAccessListMatchers.hasName(expectedName));
}

/**
* Provides a matcher that matches if the provided {@link ParseVendorConfigurationAnswerElement}
* has a parse warning with comment matched by {@code subMatcher}.
*/
public static Matcher<ParseVendorConfigurationAnswerElement> hasParseWarning(
@Nonnull String filename, @Nonnull Matcher<? super String> subMatcher) {
return new HasParseWarning(filename, subMatcher);
}

/**
* Provides a matcher that matches if the provided {@code subMatcher} matches the {@link
* Interface}'s {@code postTransformationIncomingFilterName}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.batfish.datamodel.matchers;

import javax.annotation.Nonnull;
import org.batfish.common.Warnings;
import org.batfish.common.Warnings.ParseWarning;
import org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;

final class ParseVendorConfigurationAnswerElementMatchers {

static final class HasParseWarning
extends TypeSafeDiagnosingMatcher<ParseVendorConfigurationAnswerElement> {

private final @Nonnull Matcher<? super String> _subMatcher;

private final @Nonnull String _filename;

HasParseWarning(@Nonnull String filename, @Nonnull Matcher<? super String> subMatcher) {
_filename = filename;
_subMatcher = subMatcher;
}

@Override
public void describeTo(Description description) {
description
.appendText("A ParseVendorConfigurationAnswerElement with a parse warning with text:")
.appendDescriptionOf(_subMatcher);
}

@Override
protected boolean matchesSafely(
ParseVendorConfigurationAnswerElement item, Description mismatchDescription) {
Warnings warnings = item.getWarnings().get(_filename);
if (warnings == null) {
mismatchDescription.appendText(String.format("No warnings for filename '%s'", _filename));
return false;
}
if (warnings.getParseWarnings().stream()
.map(ParseWarning::getComment)
.noneMatch(_subMatcher::matches)) {
mismatchDescription.appendText(
String.format("No parse warnings for filename '%s' match", _filename));
return false;
}
return true;
}
}

private ParseVendorConfigurationAnswerElementMatchers() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ re_default_metric

re_distribute_list
:
DISTRIBUTE_LIST name = variable_distribute_list OUT (iname = interface_name_unstructured)? NEWLINE
DISTRIBUTE_LIST name = variable_distribute_list
(
IN
| OUT
)
(iname = interface_name_unstructured)? NEWLINE
;

re_eigrp_null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import static org.batfish.representation.cisco.CiscoStructureUsage.DOCSIS_POLICY_DOCSIS_POLICY_RULE;
import static org.batfish.representation.cisco.CiscoStructureUsage.DOMAIN_LOOKUP_SOURCE_INTERFACE;
import static org.batfish.representation.cisco.CiscoStructureUsage.EIGRP_AF_INTERFACE;
import static org.batfish.representation.cisco.CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN;
import static org.batfish.representation.cisco.CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT;
import static org.batfish.representation.cisco.CiscoStructureUsage.EIGRP_PASSIVE_INTERFACE;
import static org.batfish.representation.cisco.CiscoStructureUsage.EIGRP_REDISTRIBUTE_BGP_MAP;
Expand Down Expand Up @@ -7646,16 +7647,28 @@ public void exitRe_distribute_list(Re_distribute_listContext ctx) {
warn(ctx, "No EIGRP process available");
return;
}
if (ctx.iname == null) {
@Nullable
String ifaceName = ctx.iname == null ? null : getCanonicalInterfaceName(ctx.iname.getText());
String filterName = ctx.name.getText();
int line = ctx.name.getStart().getLine();
if (ctx.IN() != null) {
_w.addWarning(
ctx, getFullText(ctx), _parser, "Global distribute-list not supported for EIGRP");
ctx, getFullText(ctx), _parser, "Inbound distribute-list is not supported for EIGRP");
_configuration.referenceStructure(
IP_ACCESS_LIST, filterName, EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN, line);
if (ifaceName != null) {
_configuration.referenceStructure(
INTERFACE, ifaceName, EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN, line);
}
return;
}
String ifaceName = getCanonicalInterfaceName(ctx.iname.getText());
String filterName = ctx.name.getText();
int line = ctx.name.getStart().getLine();
_configuration.referenceStructure(
IP_ACCESS_LIST, filterName, EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT, line);
if (ifaceName == null) {
_w.addWarning(
ctx, getFullText(ctx), _parser, "Global distribute-list not supported for EIGRP");
return;
}
_configuration.referenceStructure(
INTERFACE, ifaceName, EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT, line);
_currentEigrpProcess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,8 @@ public List<Configuration> toVendorIndependentConfigurations() {
CiscoStructureUsage.BGP_UPDATE_SOURCE_INTERFACE,
CiscoStructureUsage.DOMAIN_LOOKUP_SOURCE_INTERFACE,
CiscoStructureUsage.EIGRP_AF_INTERFACE,
CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN,
CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT,
CiscoStructureUsage.EIGRP_PASSIVE_INTERFACE,
CiscoStructureUsage.FAILOVER_LAN_INTERFACE,
CiscoStructureUsage.FAILOVER_LINK_INTERFACE,
Expand Down Expand Up @@ -3486,6 +3488,8 @@ public List<Configuration> toVendorIndependentConfigurations() {
CiscoStructureUsage.COPS_LISTENER_ACCESS_LIST,
CiscoStructureUsage.CRYPTO_MAP_IPSEC_ISAKMP_ACL,
CiscoStructureUsage.CRYPTO_MAP_MATCH_ADDRESS,
CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN,
CiscoStructureUsage.EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT,
CiscoStructureUsage.INSPECT_CLASS_MAP_MATCH_ACCESS_GROUP,
CiscoStructureUsage.INTERFACE_IGMP_ACCESS_GROUP_ACL,
CiscoStructureUsage.INTERFACE_IGMP_HOST_PROXY_ACCESS_LIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum CiscoStructureUsage implements StructureUsage {
DOCSIS_GROUP_DOCSIS_POLICY("cable load-balance docsis-group docsis-policy"),
DOCSIS_POLICY_DOCSIS_POLICY_RULE("cable load-balance docsis-policy rule"),
EIGRP_AF_INTERFACE("eigrp address-family af-interface"),
EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_IN("router eigrp distribute-list in"),
EIGRP_DISTRIBUTE_LIST_ACCESS_LIST_OUT("router eigrp distribute-list out"),
EIGRP_PASSIVE_INTERFACE("eigrp passive-interface"),
EIGRP_REDISTRIBUTE_BGP_MAP("eigrp redistribute bgp route-map"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import static org.batfish.datamodel.matchers.DataModelMatchers.hasNumReferrers;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasOutgoingFilter;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasOutgoingFilterName;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasParseWarning;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasPostTransformationIncomingFilter;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasPreTransformationOutgoingFilter;
import static org.batfish.datamodel.matchers.DataModelMatchers.hasRedFlagWarning;
Expand Down Expand Up @@ -341,6 +342,7 @@
import org.batfish.datamodel.acl.MatchHeaderSpace;
import org.batfish.datamodel.acl.MatchSrcInterface;
import org.batfish.datamodel.answers.ConvertConfigurationAnswerElement;
import org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement;
import org.batfish.datamodel.bgp.BgpConfederation;
import org.batfish.datamodel.bgp.BgpTopologyUtils;
import org.batfish.datamodel.bgp.community.Community;
Expand Down Expand Up @@ -2784,6 +2786,32 @@ public void testIosEigrpMarkForRouting() throws IOException {
assertThat(c.getRouteFilterLists(), hasKey("2"));
}

@Test
public void testIosEigrpDistributeListRefsAndWarnings() throws IOException {
String hostname = "ios-eigrp-distribute-list-refs-and-warnings";
Batfish batfish = getBatfishForConfigurationNames(hostname);

String filename = "configs/" + hostname;

ConvertConfigurationAnswerElement ccae =
batfish.loadConvertConfigurationAnswerElementOrReparse(batfish.getSnapshot());
assertThat(ccae, hasNumReferrers(filename, IPV4_ACCESS_LIST_STANDARD, "1", 2));
assertThat(ccae, hasNumReferrers(filename, IPV4_ACCESS_LIST_STANDARD, "2", 2));
assertThat(ccae, hasNumReferrers(filename, INTERFACE, "GigabitEthernet0/0", 3));

ParseVendorConfigurationAnswerElement pvcae =
batfish.loadParseVendorConfigurationAnswerElement(batfish.getSnapshot());

assertThat(
pvcae,
hasParseWarning(
filename, containsString("Inbound distribute-list is not supported for EIGRP")));
assertThat(
pvcae,
hasParseWarning(
filename, containsString("Global distribute-list not supported for EIGRP")));
}

@Test
public void testIosEigrpNeighborConfigs() throws IOException {
Configuration c = parseConfig("ios-eigrp-classic");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
!
hostname ios-eigrp-distribute-list-refs-and-warnings
!
access-list 1 permit 172.21.30.0 0.0.0.255
!
access-list 2 permit 172.21.30.0 0.0.0.255
!
interface GigabitEthernet0/0
ip address 2.2.2.2 255.255.255.0
!
router eigrp 1
distribute-list 1 out GigabitEthernet0/0
distribute-list 2 out

distribute-list 1 in GigabitEthernet0/0
distribute-list 2 in
!

0 comments on commit 00c74bd

Please sign in to comment.