@Test public void testGetOspfEdges() { NetworkFactory nf = new NetworkFactory(); OspfProcess ospf1 = nf.ospfProcessBuilder().setRouterId(Ip.parse("1.1.1.1")).setReferenceBandwidth(1e8).build(); OspfProcess ospf2 = nf.ospfProcessBuilder().setRouterId(Ip.parse("2.2.2.2")).setReferenceBandwidth(1e8).build(); OspfArea.builder().setNumber(1L).setOspfProcess(ospf1).addInterface("int1").build(); OspfArea.builder().setNumber(1L).setOspfProcess(ospf2).addInterface("int2").build(); Vrf vrf1 = new Vrf("vrf1"); vrf1.setOspfProcesses(Stream.of(ospf1)); Vrf vrf2 = new Vrf("vrf2"); vrf2.setOspfProcesses(Stream.of(ospf2)); _host1.setVrfs(ImmutableSortedMap.of("vrf1", vrf1)); _host2.setVrfs(ImmutableSortedMap.of("vrf2", vrf2)); Interface i1 = _host1.getAllInterfaces().get("int1"); i1.setVrf(vrf1); i1.setAddress(ConcreteInterfaceAddress.parse("192.0.2.0/31")); i1.setAllAddresses(ImmutableSet.of(ConcreteInterfaceAddress.parse("192.0.2.0/31"))); i1.setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setCost(1) .setPassive(false) .setNetworkType(OspfNetworkType.POINT_TO_POINT) .setProcess(ospf1.getProcessId()) .build()); Interface i2 = _host2.getAllInterfaces().get("int2"); i2.setVrf(vrf2); i2.setAddress(ConcreteInterfaceAddress.parse("192.0.2.1/31")); i2.setAllAddresses(ImmutableSet.of(ConcreteInterfaceAddress.parse("192.0.2.1/31"))); i2.setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setCost(1) .setPassive(false) .setNetworkType(OspfNetworkType.POINT_TO_POINT) .setProcess(ospf2.getProcessId()) .build()); OspfTopologyUtils.initNeighborConfigs(NetworkConfigurations.of(_configurations)); Topology l3topo = new Topology( ImmutableSortedSet.of( Edge.of("host1", "int1", "host2", "int2"), Edge.of("host2", "int2", "host1", "int1"))); List<Row> rows = getOspfEdges( _includeNodes, _includeRemoteNodes, OspfTopologyUtils.computeOspfTopology( NetworkConfigurations.of(_configurations), l3topo)); assertThat( rows, contains( ImmutableList.of( allOf( hasColumn( COL_INTERFACE, equalTo(NodeInterfacePair.of("host1", "int1")), Schema.INTERFACE), hasColumn( COL_REMOTE_INTERFACE, equalTo(NodeInterfacePair.of("host2", "int2")), Schema.INTERFACE)), allOf( hasColumn( COL_INTERFACE, equalTo(NodeInterfacePair.of("host2", "int2")), Schema.INTERFACE), hasColumn( COL_REMOTE_INTERFACE, equalTo(NodeInterfacePair.of("host1", "int1")), Schema.INTERFACE))))); }
@VisibleForTesting static List<Row> getOspfEdges( Set<String> includeNodes, Set<String> includeRemoteNodes, OspfTopology topology) { ImmutableSet.Builder<Row> rows = ImmutableSet.builder(); topology .getGraph() .edges() .forEach( p -> { OspfNeighborConfigId sourceId = p.source(); OspfNeighborConfigId targetId = p.target(); String hostname = sourceId.getHostname(); String remoteHostname = targetId.getHostname(); if (!includeNodes.contains(hostname) || !includeRemoteNodes.contains(remoteHostname)) { return; } rows.add( getOspfEdgeRow( hostname, sourceId.getInterfaceName(), remoteHostname, targetId.getInterfaceName())); }); return ImmutableList.copyOf(rows.build()); }
EdgesAnswerer extends Answerer { @VisibleForTesting static List<Row> getOspfEdges( Set<String> includeNodes, Set<String> includeRemoteNodes, OspfTopology topology) { ImmutableSet.Builder<Row> rows = ImmutableSet.builder(); topology .getGraph() .edges() .forEach( p -> { OspfNeighborConfigId sourceId = p.source(); OspfNeighborConfigId targetId = p.target(); String hostname = sourceId.getHostname(); String remoteHostname = targetId.getHostname(); if (!includeNodes.contains(hostname) || !includeRemoteNodes.contains(remoteHostname)) { return; } rows.add( getOspfEdgeRow( hostname, sourceId.getInterfaceName(), remoteHostname, targetId.getInterfaceName())); }); return ImmutableList.copyOf(rows.build()); } }
EdgesAnswerer extends Answerer { @VisibleForTesting static List<Row> getOspfEdges( Set<String> includeNodes, Set<String> includeRemoteNodes, OspfTopology topology) { ImmutableSet.Builder<Row> rows = ImmutableSet.builder(); topology .getGraph() .edges() .forEach( p -> { OspfNeighborConfigId sourceId = p.source(); OspfNeighborConfigId targetId = p.target(); String hostname = sourceId.getHostname(); String remoteHostname = targetId.getHostname(); if (!includeNodes.contains(hostname) || !includeRemoteNodes.contains(remoteHostname)) { return; } rows.add( getOspfEdgeRow( hostname, sourceId.getInterfaceName(), remoteHostname, targetId.getInterfaceName())); }); return ImmutableList.copyOf(rows.build()); } EdgesAnswerer(Question question, IBatfish batfish); }
EdgesAnswerer extends Answerer { @VisibleForTesting static List<Row> getOspfEdges( Set<String> includeNodes, Set<String> includeRemoteNodes, OspfTopology topology) { ImmutableSet.Builder<Row> rows = ImmutableSet.builder(); topology .getGraph() .edges() .forEach( p -> { OspfNeighborConfigId sourceId = p.source(); OspfNeighborConfigId targetId = p.target(); String hostname = sourceId.getHostname(); String remoteHostname = targetId.getHostname(); if (!includeNodes.contains(hostname) || !includeRemoteNodes.contains(remoteHostname)) { return; } rows.add( getOspfEdgeRow( hostname, sourceId.getInterfaceName(), remoteHostname, targetId.getInterfaceName())); }); return ImmutableList.copyOf(rows.build()); } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
EdgesAnswerer extends Answerer { @VisibleForTesting static List<Row> getOspfEdges( Set<String> includeNodes, Set<String> includeRemoteNodes, OspfTopology topology) { ImmutableSet.Builder<Row> rows = ImmutableSet.builder(); topology .getGraph() .edges() .forEach( p -> { OspfNeighborConfigId sourceId = p.source(); OspfNeighborConfigId targetId = p.target(); String hostname = sourceId.getHostname(); String remoteHostname = targetId.getHostname(); if (!includeNodes.contains(hostname) || !includeRemoteNodes.contains(remoteHostname)) { return; } rows.add( getOspfEdgeRow( hostname, sourceId.getInterfaceName(), remoteHostname, targetId.getInterfaceName())); }); return ImmutableList.copyOf(rows.build()); } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }