-
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: fix a crash on certain BGP/Address-family combinations (#5124)
* XR: fix a crash on certain BGP/Address-family combinations
- Loading branch information
Showing
3 changed files
with
72 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
54 changes: 54 additions & 0 deletions
54
projects/batfish/src/test/java/org/batfish/grammar/cisco/CiscoXrGrammarTest.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,54 @@ | ||
package org.batfish.grammar.cisco; | ||
|
||
import static org.hamcrest.Matchers.hasKey; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
import org.batfish.datamodel.Configuration; | ||
import org.batfish.main.BatfishTestUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
/** Tests for {@link CiscoParser} and {@link CiscoControlPlaneExtractor} on IOS-XR files. */ | ||
public final class CiscoXrGrammarTest { | ||
|
||
private static final String TESTCONFIGS_PREFIX = "org/batfish/grammar/cisco/testconfigs/"; | ||
|
||
@Rule public TemporaryFolder _folder = new TemporaryFolder(); | ||
|
||
@Rule public ExpectedException _thrown = ExpectedException.none(); | ||
|
||
private Map<String, Configuration> parseTextConfigs(String... configurationNames) | ||
throws IOException { | ||
String[] names = | ||
Arrays.stream(configurationNames).map(s -> TESTCONFIGS_PREFIX + s).toArray(String[]::new); | ||
return BatfishTestUtils.parseTextConfigs(_folder, names); | ||
} | ||
|
||
private @Nonnull Configuration parseConfig(String hostname) { | ||
try { | ||
Map<String, Configuration> configs = parseTextConfigs(hostname); | ||
assertThat(configs, hasKey(hostname.toLowerCase())); | ||
return configs.get(hostname.toLowerCase()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Regression test for a parser crash related to peer stack indexing issues. | ||
* | ||
* <p>The test config is a minimized version of user configuration submitted through Batfish | ||
* diagnostics. | ||
*/ | ||
@Test | ||
public void testXrBgpNeighbors() { | ||
// Don't crash. | ||
parseConfig("xr-bgp-neighbors"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
projects/batfish/src/test/resources/org/batfish/grammar/cisco/testconfigs/xr-bgp-neighbors
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,17 @@ | ||
!RANCID-CONTENT-TYPE: cisco-xr | ||
hostname xr-bgp-neighbors | ||
! | ||
router bgp 65000 | ||
! | ||
! BGP neighbor enabled for ipv4 unicast family | ||
neighbor 1.2.3.4 | ||
address-family ipv4 unicast | ||
! | ||
! Process-level config of router id | ||
bgp router-id 1.2.3.5 | ||
! Process-level config of address family | ||
address-family ipv4 unicast | ||
! | ||
! BGP neighbor enabled for ipv4 unicast family | ||
neighbor 2.3.4.5 | ||
address-family ipv4 unicast |