Skip to content

Commit

Permalink
Merge pull request #469 from batfish/release-0.31-fix-vrrp
Browse files Browse the repository at this point in the history
Fix crash when a VRRP is configured but unusable
  • Loading branch information
dhalperi committed Sep 25, 2017
2 parents 692e476 + 5dbd6ba commit e5dfbba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions projects/batfish/src/main/java/org/batfish/main/Batfish.java
Expand Up @@ -920,6 +920,12 @@ public Map<Ip, Set<String>> computeIpOwners(
.forEach(
(groupNum, vrrpGroup) -> {
Prefix prefix = vrrpGroup.getVirtualAddress();
if (prefix == null) {
// This Vlan Interface has invalid configuration. The VRRP has no source
// IP address that would be used for VRRP election. This interface could
// never win the election, so is not a candidate.
return;
}
Pair<Prefix, Integer> key = new Pair<>(prefix, groupNum);
Set<Interface> candidates =
vrrpGroups.computeIfAbsent(
Expand Down
27 changes: 27 additions & 0 deletions projects/batfish/src/test/java/org/batfish/main/BatfishTest.java
Expand Up @@ -5,10 +5,13 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import com.google.common.collect.ImmutableSortedMap;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -334,6 +337,30 @@ public void testReadUnNestedPath() throws IOException {
assertThat(expected, equalTo(actual));
}

@Test
public void testUnusableVrrpHandledCorrectly() throws Exception {
String configurationText =
String.join(
"\n",
new String[] {
"hostname host1", "!", "interface Vlan65", " vrrp 1 ip 1.2.3.4", "!",
});
SortedMap<String, String> configMap = ImmutableSortedMap.of("host1", configurationText);
Batfish batfish =
BatfishTestUtils.getBatfishFromConfigurationText(
configMap, Collections.emptySortedMap(), Collections.emptySortedMap(), _folder);
SortedMap<String, Configuration> configs = batfish.loadConfigurations();

// Assert that the config parsed successfully
assertThat(configs, hasKey("host1"));
assertThat(configs.get("host1").getInterfaces(), hasKey("Vlan65"));
assertThat(
configs.get("host1").getInterfaces().get("Vlan65").getVrrpGroups().keySet(), hasSize(1));

// Tests that computing IP owners with such a bad interface does not crash.
batfish.computeIpOwners(configs, false);
}

@Test
public void testReadValidIptableFile() throws IOException {
HostConfiguration host1 = new HostConfiguration();
Expand Down

0 comments on commit e5dfbba

Please sign in to comment.