@Override public Set<Interface> resolve(Set<String> nodes, SpecifierContext ctxt) { Map<String, Configuration> configs = ctxt.getConfigs(); return nodes.stream() .map(configs::get) .flatMap(config -> config.getAllInterfaces().values().stream()) .filter(iface -> _interfaceTypes.contains(iface.getInterfaceType())) .collect(ImmutableSet.toImmutableSet()); }
public boolean matches(Interface iface) { switch (_type) { case DESC: return _regex.matcher(iface.getDescription()).matches(); case NAME: return _regex.matcher(iface.getName()).matches(); case TYPE: return _regex.matcher(iface.getInterfaceType().toString()).matches(); case VRF: return _regex.matcher(iface.getVrfName()).matches(); default: throw new BatfishException("Unhandled InterfacesSpecifier type: " + _type); } }
private static void computeAggregatedInterfaceBandwidth( Interface iface, Map<String, Interface> interfaces) { if (iface.getInterfaceType() == InterfaceType.AGGREGATED) { /* Bandwidth should be sum of bandwidth of channel-group members. */ iface.setBandwidth( iface.getChannelGroupMembers().stream() .mapToDouble(ifaceName -> interfaces.get(ifaceName).getBandwidth()) .sum()); } else if (iface.getInterfaceType() == InterfaceType.AGGREGATE_CHILD) { /* Bandwidth for aggregate child interfaces (e.g. units) should be inherited from the parent. */ iface.getDependencies().stream() .filter(d -> d.getType() == DependencyType.BIND) .findFirst() .map(Dependency::getInterfaceName) .map(interfaces::get) .map(Interface::getBandwidth) .ifPresent(iface::setBandwidth); } }
private void postProcessAggregatedInterfacesHelper(Map<String, Interface> interfaces) { /* Populate aggregated interfaces with members referring to them. */ interfaces.forEach( (ifaceName, iface) -> populateChannelGroupMembers(interfaces, ifaceName, iface)); /* Compute bandwidth for aggregated interfaces. */ interfaces.values().forEach(iface -> computeAggregatedInterfaceBandwidth(iface, interfaces)); /* * For aggregated logical interfaces, inherit a subset of properties * from the parent aggregated interfaces */ interfaces.values().stream() .filter(iface -> iface.getInterfaceType() == InterfaceType.AGGREGATED) .filter(iface -> !iface.getDependencies().isEmpty()) .forEach( iface -> iface.setBandwidth( iface.getDependencies().stream() .map(dependency -> interfaces.get(dependency.getInterfaceName())) .filter(Objects::nonNull) .map(Interface::getBandwidth) .filter(Objects::nonNull) .mapToDouble(Double::doubleValue) .sum())); }
/** Deactivate an interface if it is blacklisted or its dependencies are not active */ private static void deactivateInterfaceIfNeeded(Interface iface) { Configuration config = iface.getOwner(); Set<Dependency> dependencies = iface.getDependencies(); if (dependencies.stream() // Look at bind dependencies .filter(d -> d.getType() == DependencyType.BIND) .map(d -> config.getAllInterfaces().get(d.getInterfaceName())) // Find any missing or inactive interfaces .anyMatch(parent -> parent == null || !parent.getActive())) { iface.setActive(false); } // Look at aggregate dependencies only now Set<Dependency> aggregateDependencies = dependencies.stream() .filter(d -> d.getType() == DependencyType.AGGREGATE) .collect(ImmutableSet.toImmutableSet()); if (iface.getInterfaceType() == InterfaceType.AGGREGATED && aggregateDependencies.stream() // Extract existing and active interfaces .map(d -> config.getAllInterfaces().get(d.getInterfaceName())) .filter(Objects::nonNull) .noneMatch(Interface::getActive)) { iface.setActive(false); } }
}); vrf.getInterfaces().values().stream() .filter(i -> i.getInterfaceType() == InterfaceType.VLAN) .forEach( irbInterface -> {
@VisibleForTesting static void tryAddInterfaceToVlans( SpecifierContext ctxt, InterfaceSpecifier interfacesSpecifier, boolean excludeShutInterfaces, IntegerSpace vlans, Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, String node, Interface iface) { if (!interfacesSpecifier.resolve(ImmutableSet.of(node), ctxt).contains(iface) || (excludeShutInterfaces && !iface.getActive()) || (iface.getInterfaceType() != InterfaceType.VLAN && !Boolean.TRUE.equals(iface.getSwitchport()))) { return; } if (iface.getInterfaceType() == InterfaceType.VLAN) { // Add VLAN associated with IRB-type interface tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, iface.getVlan(), vlans); } else if (iface.getSwitchportMode() == SwitchportMode.ACCESS) { // Add access VLAN when in ACCESS mode tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, iface.getAccessVlan(), vlans); } else if (iface.getSwitchportMode() == SwitchportMode.TRUNK) { // Add allowed VLANs when in TRUNK mode iface.getAllowedVlans().stream() .forEach( allowedVlan -> tryAddInterfaceToVlan(switchedVlanInterfaces, node, iface, allowedVlan, vlans)); } }
if ((iface.getInterfaceType() == InterfaceType.VLAN) && ((vlanNumber = CommonUtil.getInterfaceVlanNumber(iface.getName())) != null)) { vlanInterfaces.put(vlanNumber, iface);
? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; InterfaceType iface2type = nodeInterfaces.containsKey(interface2) ? nodeInterfaces.get(interface2).getInterfaceType() : InterfaceType.UNKNOWN;
new org.batfish.datamodel.Interface( ifaceName, c, computeInterfaceType(iface.getName(), c.getConfigurationFormat())); if (newIface.getInterfaceType() == InterfaceType.VLAN) { newIface.setVlan(CommonUtil.getInterfaceVlanNumber(ifaceName));