Skip to content

Commit

Permalink
XR: fix a crash on certain BGP/Address-family combinations (#5124)
Browse files Browse the repository at this point in the history
* XR: fix a crash on certain BGP/Address-family combinations
  • Loading branch information
dhalperi committed Nov 5, 2019
1 parent 100245e commit efd398b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Expand Up @@ -7949,6 +7949,7 @@ public void exitNeighbor_block_address_family(Neighbor_block_address_familyConte
public void exitNeighbor_block_rb_stanza(Neighbor_block_rb_stanzaContext ctx) {
resetPeerGroups();
if (_inBlockNeighbor) {
_inBlockNeighbor = false;
popPeer();
}
}
Expand Down
@@ -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");
}
}
@@ -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

0 comments on commit efd398b

Please sign in to comment.