@Test public void testGetIpsecEdges() { MutableValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); IpsecPeerConfigId peerId1 = new IpsecPeerConfigId("peer1", "host1"); IpsecPeerConfigId peerId2 = new IpsecPeerConfigId("peer2", "host1"); IpsecPeerConfigId peerId3 = new IpsecPeerConfigId("peer3", "host2"); IpsecPeerConfigId peerId4 = new IpsecPeerConfigId("peer4", "host2"); ipsecTopology.putEdgeValue( peerId1, peerId3, IpsecSession.builder().setNegotiatedIpsecP2Proposal(new IpsecPhase2Proposal()).build()); ipsecTopology.putEdgeValue(peerId2, peerId4, IpsecSession.builder().build()); IpsecStaticPeerConfig peer1 = IpsecStaticPeerConfig.builder() .setSourceInterface("int11") .setTunnelInterface("tunnel11") .build(); IpsecStaticPeerConfig peer2 = IpsecStaticPeerConfig.builder() .setSourceInterface("int12") .setTunnelInterface("tunnel12") .build(); IpsecStaticPeerConfig peer3 = IpsecStaticPeerConfig.builder() .setSourceInterface("int21") .setTunnelInterface("tunnel21") .build(); IpsecStaticPeerConfig peer4 = IpsecStaticPeerConfig.builder() .setSourceInterface("int22") .setTunnelInterface("tunnel22") .build(); _host1.setIpsecPeerConfigs(ImmutableSortedMap.of("peer1", peer1, "peer2", peer2)); _host2.setIpsecPeerConfigs(ImmutableSortedMap.of("peer3", peer3, "peer4", peer4)); Multiset<Row> rows = getIpsecEdges(ipsecTopology, _configurations); assertThat( rows, containsInAnyOrder( ImmutableList.of( allOf( hasColumn( COL_SOURCE_INTERFACE, equalTo(NodeInterfacePair.of("host1", "int11")), Schema.INTERFACE), hasColumn( COL_TUNNEL_INTERFACE, equalTo(NodeInterfacePair.of("host1", "tunnel11")), Schema.INTERFACE), hasColumn( COL_REMOTE_SOURCE_INTERFACE, equalTo(NodeInterfacePair.of("host2", "int21")), Schema.INTERFACE), hasColumn( COL_REMOTE_TUNNEL_INTERFACE, equalTo(NodeInterfacePair.of("host2", "tunnel21")), Schema.INTERFACE))))); }
@VisibleForTesting static Multiset<Row> getIpsecEdges( ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations nf = NetworkConfigurations.of(configurations); Multiset<Row> rows = HashMultiset.create(); ipsecTopology.edges().stream() .filter( endpoint -> { Optional<IpsecSession> ipsecSession = ipsecTopology.edgeValue(endpoint.nodeU(), endpoint.nodeV()); return ipsecSession.isPresent() && ipsecSession.get().getNegotiatedIpsecP2Proposal() != null; }) .forEach( endpoint -> { IpsecPeerConfig ipsecPeerConfigU = nf.getIpsecPeerConfig(endpoint.nodeU()); IpsecPeerConfig ipsecPeerConfigV = nf.getIpsecPeerConfig(endpoint.nodeV()); if (ipsecPeerConfigU == null || ipsecPeerConfigV == null) { return; } rows.add( getIpsecEdge( endpoint.nodeU().getHostName(), ipsecPeerConfigU, endpoint.nodeV().getHostName(), ipsecPeerConfigV)); }); return rows; }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getIpsecEdges( ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations nf = NetworkConfigurations.of(configurations); Multiset<Row> rows = HashMultiset.create(); ipsecTopology.edges().stream() .filter( endpoint -> { Optional<IpsecSession> ipsecSession = ipsecTopology.edgeValue(endpoint.nodeU(), endpoint.nodeV()); return ipsecSession.isPresent() && ipsecSession.get().getNegotiatedIpsecP2Proposal() != null; }) .forEach( endpoint -> { IpsecPeerConfig ipsecPeerConfigU = nf.getIpsecPeerConfig(endpoint.nodeU()); IpsecPeerConfig ipsecPeerConfigV = nf.getIpsecPeerConfig(endpoint.nodeV()); if (ipsecPeerConfigU == null || ipsecPeerConfigV == null) { return; } rows.add( getIpsecEdge( endpoint.nodeU().getHostName(), ipsecPeerConfigU, endpoint.nodeV().getHostName(), ipsecPeerConfigV)); }); return rows; } }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getIpsecEdges( ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations nf = NetworkConfigurations.of(configurations); Multiset<Row> rows = HashMultiset.create(); ipsecTopology.edges().stream() .filter( endpoint -> { Optional<IpsecSession> ipsecSession = ipsecTopology.edgeValue(endpoint.nodeU(), endpoint.nodeV()); return ipsecSession.isPresent() && ipsecSession.get().getNegotiatedIpsecP2Proposal() != null; }) .forEach( endpoint -> { IpsecPeerConfig ipsecPeerConfigU = nf.getIpsecPeerConfig(endpoint.nodeU()); IpsecPeerConfig ipsecPeerConfigV = nf.getIpsecPeerConfig(endpoint.nodeV()); if (ipsecPeerConfigU == null || ipsecPeerConfigV == null) { return; } rows.add( getIpsecEdge( endpoint.nodeU().getHostName(), ipsecPeerConfigU, endpoint.nodeV().getHostName(), ipsecPeerConfigV)); }); return rows; } EdgesAnswerer(Question question, IBatfish batfish); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getIpsecEdges( ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations nf = NetworkConfigurations.of(configurations); Multiset<Row> rows = HashMultiset.create(); ipsecTopology.edges().stream() .filter( endpoint -> { Optional<IpsecSession> ipsecSession = ipsecTopology.edgeValue(endpoint.nodeU(), endpoint.nodeV()); return ipsecSession.isPresent() && ipsecSession.get().getNegotiatedIpsecP2Proposal() != null; }) .forEach( endpoint -> { IpsecPeerConfig ipsecPeerConfigU = nf.getIpsecPeerConfig(endpoint.nodeU()); IpsecPeerConfig ipsecPeerConfigV = nf.getIpsecPeerConfig(endpoint.nodeV()); if (ipsecPeerConfigU == null || ipsecPeerConfigV == null) { return; } rows.add( getIpsecEdge( endpoint.nodeU().getHostName(), ipsecPeerConfigU, endpoint.nodeV().getHostName(), ipsecPeerConfigV)); }); return rows; } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
EdgesAnswerer extends Answerer { @VisibleForTesting static Multiset<Row> getIpsecEdges( ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations nf = NetworkConfigurations.of(configurations); Multiset<Row> rows = HashMultiset.create(); ipsecTopology.edges().stream() .filter( endpoint -> { Optional<IpsecSession> ipsecSession = ipsecTopology.edgeValue(endpoint.nodeU(), endpoint.nodeV()); return ipsecSession.isPresent() && ipsecSession.get().getNegotiatedIpsecP2Proposal() != null; }) .forEach( endpoint -> { IpsecPeerConfig ipsecPeerConfigU = nf.getIpsecPeerConfig(endpoint.nodeU()); IpsecPeerConfig ipsecPeerConfigV = nf.getIpsecPeerConfig(endpoint.nodeV()); if (ipsecPeerConfigU == null || ipsecPeerConfigV == null) { return; } rows.add( getIpsecEdge( endpoint.nodeU().getHostName(), ipsecPeerConfigU, endpoint.nodeV().getHostName(), ipsecPeerConfigV)); }); return rows; } EdgesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }