@Override protected Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLocation(node.getHostname(), iface.getName())); } }
@Override 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 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 InterfaceLocation(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()); } }
/** Do we convert locations properly? */ @Test public void toInterfaceLinkLocation() { InterfaceLocation ifaceLocation = new InterfaceLocation("foo", "bar"); InterfaceLinkLocation ifaceLinkLocation = new InterfaceLinkLocation("foo", "bar"); assertThat( ToInterfaceLinkLocationSpecifier.toInterfaceLinkLocation(ifaceLocation), equalTo(ifaceLinkLocation)); assertThat( ToInterfaceLinkLocationSpecifier.toInterfaceLinkLocation(ifaceLinkLocation), equalTo(ifaceLinkLocation)); } }
@Test public void testClone() throws IOException { InterfaceLocation orig = new InterfaceLocation("foo", "bar"); assertThat(orig, equalTo(BatfishObjectMapper.clone(orig, new TypeReference<Location>() {}))); } }
/** Do we resolve non empty sets properly? */ @Test public void resolveNonEmptySet() { LocationSpecifier inner = new MockLocationSpecifier( ImmutableSet.of( new InterfaceLocation("foo1", "bar1"), new InterfaceLinkLocation("foo2", "bar2"))); assertThat( new ToInterfaceLinkLocationSpecifier(inner).resolve(_mockContext), equalTo( ImmutableSet.of( new InterfaceLinkLocation("foo1", "bar1"), new InterfaceLinkLocation("foo2", "bar2")))); }
if (!sourceLocations.contains(new InterfaceLocation(ingressNode, outInterface))) { continue; if (!sourceLocations.contains(new InterfaceLocation(ingressNode, outInterface))) { continue;
@Test public void resolveLocationTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.LOCATION); question.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATION, new InterfaceLocation(_c1.getHostname(), _iface1.getName()).toString())))); }
@Test public void resolveIpSpaceOfLocationTestDefault() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); assertThat( resolveIpSpaceOfLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString()), Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c2.getHostname(), _iface2.getName())) .toString(), COL_IP_SPACE, _iface2.getAddress().getIp().toIpSpace().toString())))); }
@Test public void resolveIpSpaceOfLocationTest() { SpecifiersQuestion questionWithLocation = new SpecifiersQuestion(QueryType.IP_SPACE_OF_LOCATION); questionWithLocation.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveIpSpaceOfLocation(questionWithLocation, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString())))); }