/** Create an Edge from {@link Interface}s */ public Edge(Interface tail, Interface head) { this(new NodeInterfacePair(tail), new NodeInterfacePair(head)); }
/** 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(); }
public Set<NodeInterfacePair> getNeighbors(NodeInterfacePair iface) { return getInterfaceEdges().getOrDefault(iface, ImmutableSortedSet.of()).stream() .filter(e -> e.getTail().equals(iface)) .map(Edge::getHead) .collect(ImmutableSet.toImmutableSet()); }
/** * Return the representative of the broadcast domain of {@code nodeInterfacePair}, or {@link * Optional#empty} if not represented in the layer-2 topology. */ public @Nonnull Optional<Layer2Node> getBroadcastDomainRepresentative( NodeInterfacePair nodeInterfacePair) { return getBroadcastDomainRepresentative( nodeInterfacePair.getHostname(), nodeInterfacePair.getInterface()); }
@Test public void testInterfaceAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; NodeInterfacePair suggested = new NodeInterfacePair("hostname", "interface"); NodeInterfacePair notSuggested = new NodeInterfacePair("blah", "blahhh"); CompletionMetadata completionMetadata = CompletionMetadata.builder() .setInterfaces(ImmutableSet.of(suggested, notSuggested)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.INTERFACE, "int", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested.toString()))); }
@JsonProperty(PROP_NODE2) public String getNode2() { return _head.getHostname(); }
@JsonProperty(PROP_INT2) public String getInt2() { return _head.getInterface(); }
/** Return whether the two interfaces are in the same broadcast domain. */ public boolean inSameBroadcastDomain(NodeInterfacePair i1, NodeInterfacePair i2) { return inSameBroadcastDomain( layer2Node(i1.getHostname(), i1.getInterface()), layer2Node(i2.getHostname(), i2.getInterface())); }
@JsonProperty(PROP_NODE1) public String getNode1() { return _tail.getHostname(); }
@JsonProperty(PROP_INT1) public String getInt1() { return _tail.getInterface(); }
public OspfInfo(String hostname, String interfaceName, OspfStatus status) { this(new NodeInterfacePair(hostname, interfaceName), status); }
(outInterface, candidateRoutes) -> { Fib fib = fibs.get(hostname).get(vrf); NodeInterfacePair out = new NodeInterfacePair(hostname, outInterface); Set<NodeInterfacePair> receivers = topology.getNeighbors(out); receivers.forEach( receiver -> { String recvNode = receiver.getHostname(); String recvInterface = receiver.getInterface(); IpSpace recvReplies = _arpReplies.get(recvNode).get(recvInterface);
/** Function that processes an interface blacklist across all configurations */ private static void processInterfaceBlacklist( Set<NodeInterfacePair> interfaceBlacklist, NetworkConfigurations configurations) { interfaceBlacklist.stream() .map(iface -> configurations.getInterface(iface.getHostname(), iface.getInterface())) .filter(Optional::isPresent) .map(Optional::get) .forEach(Interface::blacklist); }
@Override protected boolean matchesSafely(NodeInterfacePair item, Description mismatchDescription) { Set<NodeInterfacePair> neighbors = _topology.getNeighbors(item); if (neighbors == null || neighbors.isEmpty()) { mismatchDescription.appendText( String.format( "%s has no neighbors in provided topology: %s", item, _topology.getEdges())); return false; } if (neighbors.stream().noneMatch(neighbor -> neighbor.getHostname().equals(_node))) { mismatchDescription.appendText( String.format("%s was not among the neighbors of %s: %s", _node, item, neighbors)); return false; } return true; } }
@JsonCreator private static NodeInterfacePair create( @Nullable @JsonProperty(PROP_HOSTNAME) String node, @Nullable @JsonProperty(PROP_INTERFACE) String iface) { checkArgument(node != null, "Cannot create NodeInterfacePair with null node"); checkArgument(iface != null, "Cannot create NodeInterfacePair with null interface"); return new NodeInterfacePair(node, iface); }
outFilter, FlowDisposition.DENIED_OUT, new NodeInterfacePair(transmissionContext._currentNodeName, nextHopInterfaceName), transmissionContext); if (denied) { FlowDisposition disposition = computeDisposition( nextHopInterface.getHostname(), nextHopInterface.getInterface(), dstIp); FlowTrace trace = neighborUnreachableOrExitsNetworkTrace(
@Override public String toString() { return "<" + getTail().getHostname() + ":" + getTail().getInterface() + ", " + getHead().getHostname() + ":" + getHead().getInterface() + ">"; } }
@JsonCreator private static Edge create( @Nullable @JsonProperty(PROP_NODE1) String node1, @Nullable @JsonProperty(PROP_INT1) String int1, @Nullable @JsonProperty(PROP_NODE2) String node2, @Nullable @JsonProperty(PROP_INT2) String int2) { checkArgument(!Strings.isNullOrEmpty(node1), "Missing %s", PROP_NODE1); checkArgument(!Strings.isNullOrEmpty(int1), "Missing %s", PROP_INT1); checkArgument(!Strings.isNullOrEmpty(node2), "Missing %s", PROP_NODE2); checkArgument(!Strings.isNullOrEmpty(int2), "Missing %s", PROP_INT2); return new Edge(new NodeInterfacePair(node1, int1), new NodeInterfacePair(node2, int2)); }
new NodeInterfacePair(currentNodeName, nextHopInterfaceName); resolvedNextHopWithRoutes .asMap() new Edge( nextHopInterface, new NodeInterfacePair( Configuration.NODE_NONE_NAME, Interface.NULL_INTERFACE_NAME)); FlowTraceHop newHop = return; Configuration nodeConfig = _configurations.get(nextHopInterface.getHostname()); Interface outgoingInterface = nodeConfig.getAllInterfaces().get(nextHopInterface.getInterface()); new Edge( nextHopInterface, new NodeInterfacePair( Configuration.NODE_NONE_NAME, Interface.NULL_INTERFACE_NAME)); FlowTraceHop nextHop =
@Test public void testGetterEquivalence() { assertThat(EDGE.getNode1(), equalTo(EDGE.getTail().getHostname())); assertThat(EDGE.getNode2(), equalTo(EDGE.getHead().getHostname())); assertThat(EDGE.getInt1(), equalTo(EDGE.getTail().getInterface())); assertThat(EDGE.getInt2(), equalTo(EDGE.getHead().getInterface())); }