@Test public void testGetRows() { NetworkFactory nf = new NetworkFactory(); Configuration configuration = nf.configurationBuilder() .setHostname("test_conf") .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .build(); Vrf vrf = nf.vrfBuilder().setName("test_vrf").setOwner(configuration).build(); OspfArea ospfArea = nf.ospfAreaBuilder() .setStubType(StubType.STUB) .setInterfaces(ImmutableSortedSet.of("int1", "int2")) .setNumber(1L) .build(); nf.ospfProcessBuilder() .setProcessId("ospf_1") .setAreas(ImmutableSortedMap.of(1L, ospfArea)) .setRouterId(Ip.parse("1.1.1.1")) .setVrf(vrf) .build(); nf.interfaceBuilder() .setVrf(vrf) .setName("int1") .setOwner(configuration) .setBandwidth(2d) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(ospfArea.getAreaNumber()) .build()) .build(); ospfArea.addInterface("int1"); nf.interfaceBuilder() .setVrf(vrf) .setName("int2") .setOwner(configuration) .setBandwidth(2d) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(ospfArea.getAreaNumber()) .setPassive(true) .build()) .build(); ospfArea.addInterface("int2"); TableMetadata tableMetadata = OspfAreaConfigurationAnswerer.createTableMetadata(); Multiset<Row> rows = OspfAreaConfigurationAnswerer.getRows( ImmutableMap.of(configuration.getHostname(), configuration), ImmutableSet.of(configuration.getHostname()), tableMetadata.toColumnMap()); assertThat( rows.iterator().next(), allOf( hasColumn( OspfAreaConfigurationAnswerer.COL_NODE, equalTo(new Node("test_conf")), Schema.NODE), hasColumn(OspfAreaConfigurationAnswerer.COL_VRF, equalTo("test_vrf"), Schema.STRING), hasColumn( OspfAreaConfigurationAnswerer.COL_PROCESS_ID, equalTo("ospf_1"), Schema.STRING), hasColumn(OspfAreaConfigurationAnswerer.COL_AREA, equalTo("1"), Schema.STRING), hasColumn( OspfAreaConfigurationAnswerer.COL_AREA_TYPE, equalTo("STUB"), Schema.STRING))); assertThat( rows.iterator().next(), allOf( hasColumn( OspfAreaConfigurationAnswerer.COL_ACTIVE_INTERFACES, equalTo(ImmutableSet.of("int1")), Schema.set(Schema.STRING)), hasColumn( OspfAreaConfigurationAnswerer.COL_PASSIVE_INTERFACES, equalTo(ImmutableSet.of("int2")), Schema.set(Schema.STRING)))); }
@VisibleForTesting static Multiset<Row> getRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodes.forEach( nodeName -> { configurations .get(nodeName) .getVrfs() .values() .forEach( vrf -> { for (OspfProcess ospfProcess : vrf.getOspfProcesses().values()) { for (OspfArea area : ospfProcess.getAreas().values()) { rows.add( getRow( configurations.get(nodeName), nodeName, vrf.getName(), ospfProcess.getProcessId(), area, columnMetadata)); } } }); }); return rows; }
OspfAreaConfigurationAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodes.forEach( nodeName -> { configurations .get(nodeName) .getVrfs() .values() .forEach( vrf -> { for (OspfProcess ospfProcess : vrf.getOspfProcesses().values()) { for (OspfArea area : ospfProcess.getAreas().values()) { rows.add( getRow( configurations.get(nodeName), nodeName, vrf.getName(), ospfProcess.getProcessId(), area, columnMetadata)); } } }); }); return rows; } }
OspfAreaConfigurationAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodes.forEach( nodeName -> { configurations .get(nodeName) .getVrfs() .values() .forEach( vrf -> { for (OspfProcess ospfProcess : vrf.getOspfProcesses().values()) { for (OspfArea area : ospfProcess.getAreas().values()) { rows.add( getRow( configurations.get(nodeName), nodeName, vrf.getName(), ospfProcess.getProcessId(), area, columnMetadata)); } } }); }); return rows; } OspfAreaConfigurationAnswerer(Question question, IBatfish batfish); }
OspfAreaConfigurationAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodes.forEach( nodeName -> { configurations .get(nodeName) .getVrfs() .values() .forEach( vrf -> { for (OspfProcess ospfProcess : vrf.getOspfProcesses().values()) { for (OspfArea area : ospfProcess.getAreas().values()) { rows.add( getRow( configurations.get(nodeName), nodeName, vrf.getName(), ospfProcess.getProcessId(), area, columnMetadata)); } } }); }); return rows; } OspfAreaConfigurationAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
OspfAreaConfigurationAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata) { Multiset<Row> rows = HashMultiset.create(); nodes.forEach( nodeName -> { configurations .get(nodeName) .getVrfs() .values() .forEach( vrf -> { for (OspfProcess ospfProcess : vrf.getOspfProcesses().values()) { for (OspfArea area : ospfProcess.getAreas().values()) { rows.add( getRow( configurations.get(nodeName), nodeName, vrf.getName(), ospfProcess.getProcessId(), area, columnMetadata)); } } }); }); return rows; } OspfAreaConfigurationAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }