/** Create an Edge from {@link Interface}s */ public Edge(Interface tail, Interface head) { this(new NodeInterfacePair(tail), new NodeInterfacePair(head)); }
public OspfInfo(String hostname, String interfaceName, OspfStatus status) { this(new NodeInterfacePair(hostname, interfaceName), status); }
@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); }
@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)); }
@VisibleForTesting static void tryAddInterfaceToVlan( Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces, String node, Interface iface, @Nullable Integer vlan, IntegerSpace vlans) { if (vlan != null && vlans.contains(vlan)) { switchedVlanInterfaces .computeIfAbsent(vlan, v -> ImmutableSet.builder()) .add(new NodeInterfacePair(node, iface.getName())); } }
@VisibleForTesting static Row getOspfEdgeRow(String node, String iface, String remoteNode, String remoteIface) { RowBuilder row = Row.builder(); row.put(COL_INTERFACE, new NodeInterfacePair(node, iface)) .put(COL_REMOTE_INTERFACE, new NodeInterfacePair(remoteNode, remoteIface)); return row.build(); }
static @Nullable NodeInterfacePair getInterface(Configuration config, Ip localIp) { return CommonUtil.getActiveInterfaceWithIp(localIp, config) .map(iface -> new NodeInterfacePair(config.getHostname(), iface.getName())) .orElse(null); }
static Row getRipEdgeRow(String node, String iface, String remoteNode, String remoteIface) { RowBuilder row = Row.builder(); row.put(COL_INTERFACE, new NodeInterfacePair(node, iface)) .put(COL_REMOTE_INTERFACE, new NodeInterfacePair(remoteNode, remoteIface)); return row.build(); }
@Override protected boolean matchesSafely(String item, Description mismatchDescription) { NodeInterfacePair pair = new NodeInterfacePair(_node, item); if (!_subMatcher.matches(pair)) { mismatchDescription .appendText(String.format("%s as interface of %s did not satisfy: ", item, _node)) .appendDescriptionOf(_subMatcher); return false; } return true; } }
@Test public void testReverse() { assertThat( EDGE.reverse(), equalTo( new Edge( new NodeInterfacePair("head", "headInt"), new NodeInterfacePair("tail", "tailInt")))); } }
@Test public void testRipToRow() { Row row = getRipEdgeRow("host1", "int1", "host2", "int2"); assertThat( row, allOf( hasColumn( COL_INTERFACE, equalTo(new NodeInterfacePair("host1", "int1")), Schema.INTERFACE), hasColumn( COL_REMOTE_INTERFACE, equalTo(new NodeInterfacePair("host2", "int2")), Schema.INTERFACE))); }
@Test public void testOspfToRow() { Row row = getOspfEdgeRow("host1", "int1", "host2", "int2"); assertThat( row, allOf( hasColumn( COL_INTERFACE, equalTo(new NodeInterfacePair("host1", "int1")), Schema.INTERFACE), hasColumn( COL_REMOTE_INTERFACE, equalTo(new NodeInterfacePair("host2", "int2")), Schema.INTERFACE))); }
@Test public void testGetInterfaces() { String nodeName = "nodeName"; String int1 = "int1"; String int2 = "int2"; Map<String, Configuration> configs = new HashMap<>(); Configuration config = createTestConfiguration(nodeName, ConfigurationFormat.HOST, int1, int2); configs.put(nodeName, config); assertThat( getInterfaces(configs), equalTo( ImmutableSet.of( new NodeInterfacePair(nodeName, int1), new NodeInterfacePair(nodeName, int2)))); }
@Test public void testLayer1ToRow() { Row row = layer1EdgeToRow(new Layer1Edge("host1", "int1", "host2", "int2")); assertThat( row, allOf( hasColumn( COL_INTERFACE, equalTo(new NodeInterfacePair("host1", "int1")), Schema.INTERFACE), hasColumn( COL_REMOTE_INTERFACE, equalTo(new NodeInterfacePair("host2", "int2")), Schema.INTERFACE))); }
@Test public void testTryAddInterfaceToVlanIncludedVlan() { Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); Interface iface = _ib.build(); int vlan = 1; IntegerSpace vlans = IntegerSpace.of(vlan); tryAddInterfaceToVlan(switchedVlanInterfaces, NODE, iface, vlan, vlans); assertThat(switchedVlanInterfaces, hasKey(vlan)); assertThat( switchedVlanInterfaces.get(vlan).build(), contains(new NodeInterfacePair(NODE, INTERFACE))); }
@VisibleForTesting static Row eigrpEdgeToRow(EigrpEdge eigrpEdge) { RowBuilder row = Row.builder(); row.put( COL_INTERFACE, new NodeInterfacePair( eigrpEdge.getNode1().getHostname(), eigrpEdge.getNode1().getInterfaceName())) .put( COL_REMOTE_INTERFACE, new NodeInterfacePair( eigrpEdge.getNode2().getHostname(), eigrpEdge.getNode2().getInterfaceName())); return row.build(); }
@VisibleForTesting static Row layer1EdgeToRow(Layer1Edge layer1Edge) { RowBuilder row = Row.builder(); row.put( COL_INTERFACE, new NodeInterfacePair( layer1Edge.getNode1().getHostname(), layer1Edge.getNode1().getInterfaceName())) .put( COL_REMOTE_INTERFACE, new NodeInterfacePair( layer1Edge.getNode2().getHostname(), layer1Edge.getNode2().getInterfaceName())); return row.build(); }
static Row isisEdgeToRow(IsisEdge isisEdge) { RowBuilder row = Row.builder(); row.put( COL_INTERFACE, new NodeInterfacePair( isisEdge.getNode1().getNode(), isisEdge.getNode1().getInterfaceName())) .put( COL_REMOTE_INTERFACE, new NodeInterfacePair( isisEdge.getNode2().getNode(), isisEdge.getNode2().getInterfaceName())); return row.build(); }
@Test public void testColumnComparatorInterface() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.INTERFACE, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new NodeInterfacePair("a", "a")); Row r2 = Row.of(col, new NodeInterfacePair("a", "b")); Row r3 = Row.of(col, new NodeInterfacePair("b", "a")); assertThat(comparator.compare(r1, r2), lessThan(0)); assertThat(comparator.compare(r1, r3), lessThan(0)); assertThat(comparator.compare(r2, r3), lessThan(0)); }
@Test public void testEmptyTopology() { SortedSet<Edge> edges = ImmutableSortedSet.of(); Topology topo = new Topology(edges); assertThat(topo.getEdges(), equalTo(ImmutableSet.of())); assertThat(topo.getInterfaceEdges(), equalTo(ImmutableMap.of())); assertThat(topo.getNodeEdges(), equalTo(ImmutableMap.of())); assertThat( topo.getNeighbors(new NodeInterfacePair("node", "iface")), equalTo(ImmutableSet.of())); }