@Test public void testResolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder() .setName("iface11") .setOwner(node1) .setAddress(ConcreteInterfaceAddress.parse("1.2.3.4/24")) .setActive(true) .build(); Interface iface12 = Interface.builder() .setName("iface12") .setActive(true) .setOwner(node1) .setAddress(ConcreteInterfaceAddress.parse("2.3.4.5/24")) .build(); node1.setInterfaces(ImmutableSortedMap.of("iface11", iface11, "iface12", iface12)); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface2 = Interface.builder() .setName("iface2") .setActive(true) .setOwner(node2) .setAddress(ConcreteInterfaceAddress.parse("1.2.3.5/30")) .build(); node2.setInterfaces(ImmutableSortedMap.of("iface2", iface2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of("node1", node1, "node2", node2)) .build(); assertThat( new InterfaceWithConnectedIpsSpecifier(Ip.parse("1.2.3.4").toIpSpace()) .resolve(ImmutableSet.of("node1", "node2"), ctxt), equalTo(ImmutableSet.of(NodeInterfacePair.of(iface11), NodeInterfacePair.of(iface2)))); assertThat( new InterfaceWithConnectedIpsSpecifier(Ip.parse("1.2.3.8").toIpSpace()) .resolve(ImmutableSet.of("node1", "node2"), ctxt), equalTo(ImmutableSet.of(NodeInterfacePair.of(iface11)))); assertThat( new InterfaceWithConnectedIpsSpecifier(Ip.parse("2.3.4.5").toIpSpace()) .resolve(ImmutableSet.of("node1", "node2"), ctxt), equalTo(ImmutableSet.of(NodeInterfacePair.of(iface12)))); assertThat( new InterfaceWithConnectedIpsSpecifier(Prefix.parse("3.0.0.0/24").toIpSpace()) .resolve(ImmutableSet.of("node1", "node2"), ctxt), empty()); }
@Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .flatMap(c -> c.getAllInterfaces().values().stream().filter(Interface::getActive)) .filter( i -> i.getAllConcreteAddresses().stream().anyMatch(this::interfaceAddressMatchesIpSpace)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); }
InterfaceWithConnectedIpsSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .flatMap(c -> c.getAllInterfaces().values().stream().filter(Interface::getActive)) .filter( i -> i.getAllConcreteAddresses().stream().anyMatch(this::interfaceAddressMatchesIpSpace)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } }
InterfaceWithConnectedIpsSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .flatMap(c -> c.getAllInterfaces().values().stream().filter(Interface::getActive)) .filter( i -> i.getAllConcreteAddresses().stream().anyMatch(this::interfaceAddressMatchesIpSpace)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } InterfaceWithConnectedIpsSpecifier(@Nonnull IpSpace ipSpace); }
InterfaceWithConnectedIpsSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .flatMap(c -> c.getAllInterfaces().values().stream().filter(Interface::getActive)) .filter( i -> i.getAllConcreteAddresses().stream().anyMatch(this::interfaceAddressMatchesIpSpace)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } InterfaceWithConnectedIpsSpecifier(@Nonnull IpSpace ipSpace); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt); }
InterfaceWithConnectedIpsSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .flatMap(c -> c.getAllInterfaces().values().stream().filter(Interface::getActive)) .filter( i -> i.getAllConcreteAddresses().stream().anyMatch(this::interfaceAddressMatchesIpSpace)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } InterfaceWithConnectedIpsSpecifier(@Nonnull IpSpace ipSpace); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt); static final String NAME; }