Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batfish: unusableVlanShutdown should only count active interfaces #6368

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
!