@Test public void testLayer3ToRow() { Map<String, Configuration> configurationMap = ImmutableSortedMap.of("host1", _host1, "host2", _host2); Row row = layer3EdgeToRow(configurationMap, Edge.of("host1", "int1", "host2", "int2")); assertThat( row, allOf( hasColumn( COL_INTERFACE, equalTo(NodeInterfacePair.of("host1", "int1")), Schema.INTERFACE), hasColumn( COL_IPS, equalTo(ImmutableSet.of(Ip.parse("1.1.1.1"))), Schema.set(Schema.IP)), hasColumn( COL_REMOTE_INTERFACE, equalTo(NodeInterfacePair.of("host2", "int2")), Schema.INTERFACE), hasColumn( COL_REMOTE_IPS, equalTo(ImmutableSet.of(Ip.parse("2.2.2.2"))), Schema.set(Schema.IP)))); }
@VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, NodeInterfacePair.of(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, NodeInterfacePair.of(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); } }
EdgesAnswerer extends Answerer { @VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, NodeInterfacePair.of(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); } EdgesAnswerer(Question question, IBatfish batfish); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, NodeInterfacePair.of(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllConcreteAddresses().stream() .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, NodeInterfacePair.of(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }