Skip to content

Commit

Permalink
Batfish: unusableVlanShutdown should only count active interfaces (#6368
Browse files Browse the repository at this point in the history
)

If an interface is shutdown, it will not keep a Vlan up. (The autostate flag is
still supported below).
  • Loading branch information
dhalperi committed Oct 28, 2020
1 parent b5a74ce commit 080a0fc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions projects/batfish/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ java_library(
runtime_deps = [
"//projects/question",
"@maven//:io_jaegertracing_jaeger_thrift",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
],
deps = [
"//projects/batfish-common-protocol:common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ private void disableUnusableVlanInterfaces(Map<String, Configuration> configurat
Integer vlanNumber = null;
// Populate vlanInterface and nonVlanInterfaces, and initialize
// vlanMemberCounts:
for (Interface iface : c.getAllInterfaces().values()) {
for (Interface iface : c.getActiveInterfaces().values()) {
if ((iface.getInterfaceType() == InterfaceType.VLAN)
&& ((vlanNumber = CommonUtil.getInterfaceVlanNumber(iface.getName())) != null)) {
vlanInterfaces.put(vlanNumber, iface);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.batfish.main;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasKey;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.util.Map;
import org.batfish.common.plugin.IBatfish;
import org.batfish.datamodel.Configuration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class VlanInterfacesTest {
private static final String TESTCONFIGS_PREFIX = "org/batfish/main/testconfigs/";
@Rule public TemporaryFolder _folder = new TemporaryFolder();

private Configuration parseConfig(String hostname) {
try {
IBatfish batfish =
BatfishTestUtils.getBatfishForTextConfigs(_folder, TESTCONFIGS_PREFIX + hostname);
Map<String, Configuration> configs = batfish.loadConfigurations(batfish.getSnapshot());
assertThat(configs, hasKey(hostname.toLowerCase()));
return configs.get(hostname.toLowerCase());
} catch (IOException e) {
throw new AssertionError("Failed to parse " + hostname, e);
}
}

/** Tests Batfish#disableUnusableVlanInterfaces. */
@Test
public void testDisableUnusableInterfaces() {
Configuration c = parseConfig("vlan");
assertThat(
c.getAllInterfaces().keySet(),
containsInAnyOrder("Ethernet1", "Ethernet2", "Vlan1", "Vlan2"));
assertThat(c.getActiveInterfaces().keySet(), containsInAnyOrder("Ethernet1", "Vlan1"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!RANCID-CONTENT-TYPE: cisco
hostname vlan
!
interface Vlan1
no shutdown
!
interface Ethernet1
no shutdown
switchport mode access
switchport access vlan 1
!
interface Vlan2
no shutdown
!
interface Ethernet2
shutdown
switchport mode access
switchport access vlan 2
!

0 comments on commit 080a0fc

Please sign in to comment.