private Map<String, GraphEdge> interfaceMap(List<GraphEdge> edges) { Map<String, GraphEdge> ifaceMap = new HashMap<>(); for (GraphEdge edge : edges) { ifaceMap.put(edge.getStart().getName(), edge); } return ifaceMap; }
/** * 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(); }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .flatMap(node -> node.getAllInterfaces().values().stream()) .filter(iface -> _pattern.matcher(iface.getName()).matches()) .map(this::getLocation) .collect(ImmutableSet.toImmutableSet()); } }
@Override protected Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLocation(node.getHostname(), iface.getName())); } }
static @Nullable NodeInterfacePair getInterface(Configuration config, Ip localIp) { return CommonUtil.getActiveInterfaceWithIp(localIp, config) .map(iface -> new NodeInterfacePair(config.getHostname(), iface.getName())) .orElse(null); }
@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())); } }
@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 Set<Location> resolve(SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .flatMap(node -> node.getAllInterfaces().values().stream()) .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(ImmutableSet.toImmutableSet()); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { return _interfaceSpecifier.resolve(ctxt.getConfigs().keySet(), ctxt).stream() .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())) .collect(Collectors.toSet()); } }
@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())); } }
@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLocation(iface.getOwner().getHostname(), iface.getName())); } }
private FlowTraceHop buildFlowTraceHop(GraphEdge graphEdge, String route) { String node1 = graphEdge.getRouter(); String int1 = graphEdge.getStart().getName(); String node2 = graphEdge.getPeer() == null ? "(none)" : graphEdge.getPeer(); String int2 = graphEdge.getEnd() == null ? "null_interface" : graphEdge.getEnd().getName(); Edge edge = Edge.of(node1, int1, node2, int2); SortedSet<String> routes = new TreeSet<>(); routes.add(route); return new FlowTraceHop(edge, routes, null, null, null); }
@Override protected Location getLocation(Interface iface) { return new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override protected Location getLocation(Interface iface) { return new InterfaceLocation(iface.getOwner().getHostname(), iface.getName()); } }
@Override protected Location getLocation(Interface iface) { return new InterfaceLocation(iface.getOwner().getHostname(), iface.getName()); } }
@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)); } }