@Override public IngressLocation visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { return IngressLocation.interfaceLink( interfaceLinkLocation.getNodeName(), interfaceLinkLocation.getInterfaceName()); }
@Override protected Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(node.getHostname(), iface.getName())); } }
@Override public String visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { return interfaceLinkLocation.getInterfaceName(); }
@Override public Boolean visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { return interfaceLinkLocation.getNodeName().equals(node); }
@Override Stream<Location> getNodeLocations(Configuration node) { return node.getAllInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(node.getHostname(), iface.getName())); } }
@Override public Optional<StateExpr> visitInterfaceLinkLocation( @Nonnull InterfaceLinkLocation interfaceLinkLocation) { return Optional.of( new OriginateInterfaceLink( interfaceLinkLocation.getNodeName(), interfaceLinkLocation.getInterfaceName())); }
@Override public Location visitInterfaceLocation(InterfaceLocation interfaceLocation) { return new InterfaceLinkLocation( interfaceLocation.getNodeName(), interfaceLocation.getInterfaceName()); } });
@Override public Void visitInterfaceLinkLocation( @Nonnull InterfaceLinkLocation interfaceLinkLocation) { flowBuilder .setIngressInterface(interfaceLinkLocation.getInterfaceName()) .setIngressNode(interfaceLinkLocation.getNodeName()) .setIngressVrf(null); return null; }
@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 Void visitInterfaceLinkLocation( @Nonnull InterfaceLinkLocation interfaceLinkLocation) { flowBuilder .setIngressInterface(interfaceLinkLocation.getInterfaceName()) .setIngressNode(interfaceLinkLocation.getNodeName()) .setIngressVrf(null); return null; }
@Override protected Stream<Location> getVrfLocations(Vrf vrf) { return vrf.getInterfaces().values().stream() .map(iface -> new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName())); } }
@Override public IpSpace visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { String node = interfaceLinkLocation.getNodeName(); String iface = interfaceLinkLocation.getInterfaceName(); @Nullable IpSpace linkIpSpace = AclIpSpace.union( interfaceAddresses(node, iface).stream() /* * Only include addresses on networks that might have hosts. */ .filter(address -> address.getNetworkBits() <= HOST_SUBNET_MAX_PREFIX_LENGTH) .map(address -> address.getPrefix().toHostIpSpace()) .collect(Collectors.toList())); return linkIpSpace == null ? EmptyIpSpace.INSTANCE : AclIpSpace.difference(linkIpSpace, _specifierContext.getSnapshotDeviceOwnedIps()); }
@Override protected Location getLocation(Interface iface) { return new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName()); } }
/** 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(); }
@Override protected Location getLocation(Interface iface) { return new InterfaceLinkLocation(iface.getOwner().getHostname(), iface.getName()); } }
/** 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")))); }
/** 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)); } }