@Override protected Boolean featureValueOf(Interface actual) { return actual.getActive(); } }
/** * Returns an active interface with the specified name for configuration. * * @param name The name to check * @param c The configuration object in which to check * @return Any Interface that matches the condition */ public static Optional<Interface> getActiveInterfaceWithName(String name, Configuration c) { return c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getName().equals(name)) .findAny(); }
/** * Returns an active interface with the specified IP address for configuration. * * @param ipAddress The IP address to check * @param c The configuration object in which to check * @return Any Interface that matches the condition */ public static Optional<Interface> getActiveInterfaceWithIp(Ip ipAddress, Configuration c) { return c.getAllInterfaces().values().stream() .filter( iface -> iface.getActive() && iface.getAllAddresses().stream() .anyMatch(ifAddr -> Objects.equals(ifAddr.getIp(), ipAddress))) .findAny(); }
private Map<String, Map<String, Set<String>>> computeEnabledInterfacesByNodeVrf() { return toImmutableMap( _enabledVrfs, Entry::getKey, enabledVrfsEntry -> { String hostname = enabledVrfsEntry.getKey(); Set<String> disabledInterfaces = _disabledInterfaces.get(hostname); Configuration c = _configurations.get(hostname); return toImmutableMap( enabledVrfsEntry.getValue(), Function.identity(), vrfName -> c.getVrfs().get(vrfName).getInterfaces().entrySet().stream() .filter( interfaceEntry -> disabledInterfaces == null || !disabledInterfaces.contains(interfaceEntry.getKey())) .filter(interfaceEntry -> interfaceEntry.getValue().getActive()) .filter(interfaceEntry -> !interfaceEntry.getValue().getBlacklisted()) .map(Entry::getKey) .collect(ImmutableSet.toImmutableSet())); }); }
public static @Nonnull Layer1Topology computeLayer1PhysicalTopology( @Nonnull Layer1Topology rawLayer1Topology, @Nonnull Map<String, Configuration> configurations) { /* Filter out inactive interfaces */ return new Layer1Topology( rawLayer1Topology.getGraph().edges().stream() .filter( edge -> { Interface i1 = getInterface(edge.getNode1(), configurations); Interface i2 = getInterface(edge.getNode2(), configurations); return i1 != null && i2 != null && i1.getActive() && i2.getActive(); }) .collect(ImmutableSet.toImmutableSet())); }
iface -> question.getInterfacesSpecifier().matches(iface) && (!question.getEnabledIpsOnly() || iface.getActive()))
/** 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); } }
/** * Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to * neighbors). */ @VisibleForTesting void initConnectedRib() { // Look at all connected interfaces for (Interface i : _vrf.getInterfaces().values()) { if (i.getActive()) { // Make sure the interface is active // Create a route for each interface prefix for (InterfaceAddress ifaceAddress : i.getAllAddresses()) { Prefix prefix = ifaceAddress.getPrefix(); ConnectedRoute cr = new ConnectedRoute(prefix, i.getName()); _connectedRib.mergeRoute(cr); } } } }
/** * Initialize the local RIB -- a RIB containing non-forwarding /32 routes for exact addresses of * interfaces */ @VisibleForTesting void initLocalRib() { // Look at all connected interfaces for (Interface i : _vrf.getInterfaces().values()) { if (i.getActive()) { // Make sure the interface is active // Create a route for each interface prefix for (InterfaceAddress ifaceAddress : i.getAllAddresses()) { if (ifaceAddress.getNetworkBits() < Prefix.MAX_PREFIX_LENGTH) { LocalRoute lr = new LocalRoute(ifaceAddress, i.getName()); _localRib.mergeRoute(lr); } } } } }
/** Initialize RIP routes from the interface prefixes */ @VisibleForTesting void initBaseRipRoutes() { if (_vrf.getRipProcess() == null) { return; // nothing to do } // init internal routes from connected routes for (String ifaceName : _vrf.getRipProcess().getInterfaces()) { Interface iface = _vrf.getInterfaces().get(ifaceName); if (iface.getActive()) { Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream() .map(InterfaceAddress::getPrefix) .collect(Collectors.toSet()); long cost = RipProcess.DEFAULT_RIP_COST; for (Prefix prefix : allNetworkPrefixes) { RipInternalRoute route = new RipInternalRoute( prefix, Route.UNSET_ROUTE_NEXT_HOP_IP, RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost); _ripInternalRib.mergeRouteGetDelta(route); } } } }
private BoolExpr interfaceActive(Interface iface, Protocol proto) { BoolExpr active = mkBool(iface.getActive()); if (proto.isOspf()) { active = mkAnd(active, mkBool(iface.getOspfEnabled())); } return active; }
@Test public void testBlacklisting() { Interface i = Interface.builder().setName("iface").build(); assertThat("Interface is not blacklisted", !i.getBlacklisted()); assertThat("Interface is not disabled", i.getActive()); i.blacklist(); assertThat("Interface is blacklisted", i.getBlacklisted()); assertThat("Interface is disabled", !i.getActive()); }
/** Returns {@code true} iff the given {@link Location} is active (aka, interface is up). */ @VisibleForTesting static boolean isActive(Location l, Map<String, Configuration> configs) { NodeInterfacePair iface; if (l instanceof InterfaceLocation) { iface = new NodeInterfacePair( ((InterfaceLocation) l).getNodeName(), ((InterfaceLocation) l).getInterfaceName()); } else { assert l instanceof InterfaceLinkLocation; iface = new NodeInterfacePair( ((InterfaceLinkLocation) l).getNodeName(), ((InterfaceLinkLocation) l).getInterfaceName()); } return configs .get(iface.getHostname()) .getAllInterfaces() .get(iface.getInterface()) .getActive(); }
.put(COL_IP, address.getIp()) .put(COL_MASK, address.getNetworkBits()) .put(COL_ACTIVE, iface.getActive()) .build());
if (!interfacesSpecifier.matches(iface) || (excludeShutInterfaces && !iface.getActive())) { continue;
/** * Initialize the static route RIBs from the VRF config. Interface routes go into {@link * #_staticInterfaceRib}; routes that only have next-hop-ip go into {@link #_staticNextHopRib} */ @VisibleForTesting void initStaticRibs() { for (StaticRoute sr : _vrf.getStaticRoutes()) { if (isInterfaceRoute(sr)) { // We have an interface route, check if interface is active Interface nextHopInterface = _c.getAllInterfaces().get(sr.getNextHopInterface()); if (Interface.NULL_INTERFACE_NAME.equals(sr.getNextHopInterface()) || (nextHopInterface != null && (nextHopInterface.getActive()))) { // Interface is active (or special null interface), install route _staticInterfaceRib.mergeRouteGetDelta(sr); } } else { if (Route.UNSET_ROUTE_NEXT_HOP_IP.equals(sr.getNextHopIp())) { continue; } // We have a next-hop-ip route, keep in it that RIB _staticNextHopRib.mergeRouteGetDelta(sr); } } }
@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)); } }
for (Interface iface : vrf.getInterfaces().values()) { Set<Prefix> ifaceBasePrefixes = new HashSet<>(); if (iface.getActive()) { for (InterfaceAddress address : iface.getAllAddresses()) { Prefix basePrefix = address.getPrefix();
return iface.getActive() && srs != null && !srs.isEmpty();