-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XR: parse and warn on ACL udf statements (#6006)
Fix #6004 - UDFs are not supported but they are warned on.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
projects/batfish/src/test/java/org/batfish/grammar/cisco_xr/GitHub6004Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.batfish.grammar.cisco_xr; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.batfish.common.util.Resources.readResource; | ||
import static org.batfish.datamodel.matchers.MapMatchers.hasKeys; | ||
import static org.batfish.main.BatfishTestUtils.TEST_SNAPSHOT; | ||
import static org.batfish.main.BatfishTestUtils.configureBatfishTestSettings; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import org.antlr.v4.runtime.ParserRuleContext; | ||
import org.apache.commons.lang3.SerializationUtils; | ||
import org.batfish.common.BatfishLogger; | ||
import org.batfish.common.Warnings; | ||
import org.batfish.config.Settings; | ||
import org.batfish.datamodel.ConfigurationFormat; | ||
import org.batfish.main.Batfish; | ||
import org.batfish.representation.cisco_xr.CiscoXrConfiguration; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
/** Tests for https://github.com/batfish/batfish/issues/6004. */ | ||
@ParametersAreNonnullByDefault | ||
public final class GitHub6004Test { | ||
|
||
private static final String TESTCONFIGS_PREFIX = "org/batfish/grammar/cisco_xr/testconfigs/"; | ||
|
||
@Rule public ExpectedException _thrown = ExpectedException.none(); | ||
|
||
private @Nonnull CiscoXrConfiguration parseVendorConfig(String hostname) { | ||
String src = readResource(TESTCONFIGS_PREFIX + hostname, UTF_8); | ||
Settings settings = new Settings(); | ||
configureBatfishTestSettings(settings); | ||
CiscoXrCombinedParser ciscoXrParser = new CiscoXrCombinedParser(src, settings); | ||
CiscoXrControlPlaneExtractor extractor = | ||
new CiscoXrControlPlaneExtractor( | ||
src, ciscoXrParser, ConfigurationFormat.CISCO_IOS_XR, new Warnings()); | ||
ParserRuleContext tree = | ||
Batfish.parse( | ||
ciscoXrParser, new BatfishLogger(BatfishLogger.LEVELSTR_FATAL, false), settings); | ||
extractor.processParseTree(TEST_SNAPSHOT, tree); | ||
CiscoXrConfiguration vendorConfiguration = | ||
(CiscoXrConfiguration) extractor.getVendorConfiguration(); | ||
vendorConfiguration.setFilename(TESTCONFIGS_PREFIX + hostname); | ||
// crash if not serializable | ||
return SerializationUtils.clone(vendorConfiguration); | ||
} | ||
|
||
@Test | ||
public void testGitHub6004() { | ||
CiscoXrConfiguration c = parseVendorConfig("gh6004"); | ||
assertThat(c.getIpv4Acls(), hasKeys("FOO", "BAR", "BAZ")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
projects/batfish/src/test/resources/org/batfish/grammar/cisco_xr/testconfigs/gh6004
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
!RANCID-CONTENT-TYPE: cisco-xr | ||
hostname gh6004 | ||
interface Bundle-ether1 | ||
ipv4 address 1.1.1.1 255.255.255.248 | ||
ipv4 access-group FOO ingress | ||
! | ||
ipv4 access-list FOO | ||
10 permit icmp any any echo-reply | ||
30 permit ipv4 any any udf vlanid 0xcb1 0xfff set ttl 100 nexthop1 ipv4 2.2.2.2 | ||
50 permit icmp any any | ||
70 permit ipv4 any any udf vlanid 0xcb2 0xfff set ttl 100 nexthop1 ipv4 2.2.2.2 | ||
! | ||
ipv4 access-list BAR | ||
20 permit icmp any any echo-reply | ||
40 permit ipv4 any any udf vlanid 0x111 0xfff set ttl 100 nexthop1 ipv4 2.2.2.2 | ||
! | ||
ipv4 access-list BAZ | ||
15 permit icmp any any echo-reply | ||
25 permit ipv4 any any udf vlanid 0xaaa 0x222 set ttl 100 nexthop1 ipv4 2.2.2.2 |