@JsonIgnore @Deprecated // to enable users to migrate to new API. public NavigableMap<String, Interface> getInterfaces() { return getAllInterfaces(); }
@VisibleForTesting public static Set<NodeInterfacePair> getInterfaces(Map<String, Configuration> configurations) { ImmutableSet.Builder<NodeInterfacePair> interfaces = ImmutableSet.builder(); configurations .values() .forEach( configuration -> configuration.getAllInterfaces().values().stream() .map(NodeInterfacePair::new) .forEach(interfaces::add)); return interfaces.build(); }
@Override protected Map<String, Interface> featureValueOf(Configuration actual) { return actual.getAllInterfaces(); } }
private boolean isFilterOnInterface( Configuration c, Function<Interface, IpAccessList> filterGetter, IpAccessList filter) { InterfacesSpecifier interfaceSpecifiers = new InterfacesSpecifier(_regex); return c.getAllInterfaces().values().stream() .filter(interfaceSpecifiers::matches) .map(filterGetter) .anyMatch(o -> o == filter); }
/** * 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(); }
public static @Nullable Interface getInterface( @Nonnull Layer1Node layer1Node, @Nonnull Map<String, Configuration> configurations) { Configuration c = getConfiguration(layer1Node, configurations); if (c == null) { return null; } return c.getAllInterfaces().get(layer1Node.getInterfaceName()); }
@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()); }
private Map<String, List<String>> computeNodeInterfaces() { return _enabledNodes.stream() .collect( ImmutableMap.toImmutableMap( Function.identity(), node -> ImmutableList.sortedCopyOf( _configurations.get(node).getAllInterfaces().keySet()))); }
/** Initialize interface costs for all interfaces that belong to this process */ public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .forEach(i -> i.setOspfCost(computeInterfaceCost(i))); }
@Override protected Interface featureValueOf(Configuration actual) { return actual.getAllInterfaces().get(_name); } }
@Override Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(node.getHostname(), iface.getName())); } }
@Override Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLocation(node.getHostname(), iface.getName())); } }
@Override protected Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(node.getHostname(), iface.getName())); } }
private static SortedSet<VerboseEdge> getLayer3Edges( Map<String, Configuration> configs, Topology topology) { SortedSet<VerboseEdge> layer3Edges = new TreeSet<>(); for (Edge edge : topology.getEdges()) { Configuration n1 = configs.get(edge.getNode1()); Interface i1 = n1.getAllInterfaces().get(edge.getInt1()); Configuration n2 = configs.get(edge.getNode2()); Interface i2 = n2.getAllInterfaces().get(edge.getInt2()); layer3Edges.add(new VerboseEdge(i1, i2, edge)); } return layer3Edges; }
@Override protected Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLocation(node.getHostname(), iface.getName())); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return _nodeSpecifier.resolve(ctxt).stream() .map(n -> ctxt.getConfigs().get(n).getAllInterfaces().values()) .flatMap(Collection::stream) .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(Collectors.toSet()); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .flatMap(node -> node.getAllInterfaces().values().stream()) .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())) .collect(ImmutableSet.toImmutableSet()); } }
@Override public IngressLocation visitInterfaceLocation(InterfaceLocation interfaceLocation) { String node = interfaceLocation.getNodeName(); String iface = interfaceLocation.getInterfaceName(); return IngressLocation.vrf(node, _configs.get(node).getAllInterfaces().get(iface).getVrfName()); } }
private static Configuration createTestConfiguration( String nodeName, ConfigurationFormat configFormat, String... interfaceNames) { Configuration config = new Configuration(nodeName, configFormat); for (String interfaceName : interfaceNames) { config.getAllInterfaces().put(interfaceName, new Interface(interfaceName, config)); } return config; }
@Test public void testGetInterface() { Configuration c = new Configuration("foo", ConfigurationFormat.CISCO_IOS); Interface i = Interface.builder().setBandwidth(1e9).setName("eth0").build(); c.getAllInterfaces().put(i.getName(), i); NetworkConfigurations nc = NetworkConfigurations.of(ImmutableMap.of("foo", c)); assertThat(nc.getInterface("bar", "missingIface"), equalTo(Optional.empty())); assertThat(nc.getInterface("foo", "missingIface"), equalTo(Optional.empty())); assertThat(nc.getInterface("foo", "eth0").orElse(null), equalTo(i)); } }