@Test public void testGenerateRowsIke1Fail() { _graph.putEdgeValue( new IpsecPeerConfigId(INITIATOR_IPSEC_PEER_CONFIG, INITIATOR_HOST_NAME), new IpsecPeerConfigId(RESPONDER_IPSEC_PEER_CONFIG, RESPONDER_HOST_NAME), _ipsecSessionBuilder.build()); Multiset<IpsecSessionInfo> sessions = rawAnswer( _networkConfigurations, _graph, ImmutableSet.of(INITIATOR_HOST_NAME), ImmutableSet.of(RESPONDER_HOST_NAME)); assertThat(sessions, hasSize(1)); assertThat(sessions.iterator().next(), hasIpsecSessionStatus(equalTo(IKE_PHASE1_FAILED))); }
@VisibleForTesting static Multiset<IpsecSessionInfo> rawAnswer( NetworkConfigurations networkConfigurations, ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Set<String> initiatorNodes, Set<String> responderNodes) { Multiset<IpsecSessionInfo> ipsecSessionInfos = HashMultiset.create(); for (IpsecPeerConfigId node : ipsecTopology.nodes()) { IpsecPeerConfig ipsecPeerConfig = networkConfigurations.getIpsecPeerConfig(node); if (ipsecPeerConfig == null || ipsecPeerConfig instanceof IpsecDynamicPeerConfig || !initiatorNodes.contains(node.getHostName())) { continue; } IpsecSessionInfo.Builder ipsecSessionInfoBuilder = IpsecSessionInfo.builder(); ipsecSessionInfoBuilder.setInitiatorHostname(node.getHostName()); ipsecSessionInfoBuilder.setInitiatorInterface(ipsecPeerConfig.getSourceInterface()); ipsecSessionInfoBuilder.setInitiatorIp(ipsecPeerConfig.getLocalAddress()); ipsecSessionInfoBuilder.setInitiatorTunnelInterface(ipsecPeerConfig.getTunnelInterface()); Set<IpsecPeerConfigId> neighbors = ipsecTopology.adjacentNodes(node); if (neighbors.isEmpty()) { ipsecSessionInfoBuilder.setIpsecSessionStatus(MISSING_END_POINT); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); continue; } for (IpsecPeerConfigId neighbor : neighbors) { if (!responderNodes.contains(neighbor.getHostName())) { continue; } IpsecSession ipsecSession = ipsecTopology.edgeValueOrDefault(node, neighbor, null); if (ipsecSession == null) { continue; } IpsecPeerConfig ipsecPeerConfigNeighbor = networkConfigurations.getIpsecPeerConfig(neighbor); if (ipsecPeerConfigNeighbor == null) { continue; } processNeighbor(neighbor, ipsecSessionInfoBuilder, ipsecPeerConfigNeighbor, ipsecSession); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); } } return ipsecSessionInfos; }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Multiset<IpsecSessionInfo> rawAnswer( NetworkConfigurations networkConfigurations, ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Set<String> initiatorNodes, Set<String> responderNodes) { Multiset<IpsecSessionInfo> ipsecSessionInfos = HashMultiset.create(); for (IpsecPeerConfigId node : ipsecTopology.nodes()) { IpsecPeerConfig ipsecPeerConfig = networkConfigurations.getIpsecPeerConfig(node); if (ipsecPeerConfig == null || ipsecPeerConfig instanceof IpsecDynamicPeerConfig || !initiatorNodes.contains(node.getHostName())) { continue; } IpsecSessionInfo.Builder ipsecSessionInfoBuilder = IpsecSessionInfo.builder(); ipsecSessionInfoBuilder.setInitiatorHostname(node.getHostName()); ipsecSessionInfoBuilder.setInitiatorInterface(ipsecPeerConfig.getSourceInterface()); ipsecSessionInfoBuilder.setInitiatorIp(ipsecPeerConfig.getLocalAddress()); ipsecSessionInfoBuilder.setInitiatorTunnelInterface(ipsecPeerConfig.getTunnelInterface()); Set<IpsecPeerConfigId> neighbors = ipsecTopology.adjacentNodes(node); if (neighbors.isEmpty()) { ipsecSessionInfoBuilder.setIpsecSessionStatus(MISSING_END_POINT); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); continue; } for (IpsecPeerConfigId neighbor : neighbors) { if (!responderNodes.contains(neighbor.getHostName())) { continue; } IpsecSession ipsecSession = ipsecTopology.edgeValueOrDefault(node, neighbor, null); if (ipsecSession == null) { continue; } IpsecPeerConfig ipsecPeerConfigNeighbor = networkConfigurations.getIpsecPeerConfig(neighbor); if (ipsecPeerConfigNeighbor == null) { continue; } processNeighbor(neighbor, ipsecSessionInfoBuilder, ipsecPeerConfigNeighbor, ipsecSession); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); } } return ipsecSessionInfos; } }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Multiset<IpsecSessionInfo> rawAnswer( NetworkConfigurations networkConfigurations, ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Set<String> initiatorNodes, Set<String> responderNodes) { Multiset<IpsecSessionInfo> ipsecSessionInfos = HashMultiset.create(); for (IpsecPeerConfigId node : ipsecTopology.nodes()) { IpsecPeerConfig ipsecPeerConfig = networkConfigurations.getIpsecPeerConfig(node); if (ipsecPeerConfig == null || ipsecPeerConfig instanceof IpsecDynamicPeerConfig || !initiatorNodes.contains(node.getHostName())) { continue; } IpsecSessionInfo.Builder ipsecSessionInfoBuilder = IpsecSessionInfo.builder(); ipsecSessionInfoBuilder.setInitiatorHostname(node.getHostName()); ipsecSessionInfoBuilder.setInitiatorInterface(ipsecPeerConfig.getSourceInterface()); ipsecSessionInfoBuilder.setInitiatorIp(ipsecPeerConfig.getLocalAddress()); ipsecSessionInfoBuilder.setInitiatorTunnelInterface(ipsecPeerConfig.getTunnelInterface()); Set<IpsecPeerConfigId> neighbors = ipsecTopology.adjacentNodes(node); if (neighbors.isEmpty()) { ipsecSessionInfoBuilder.setIpsecSessionStatus(MISSING_END_POINT); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); continue; } for (IpsecPeerConfigId neighbor : neighbors) { if (!responderNodes.contains(neighbor.getHostName())) { continue; } IpsecSession ipsecSession = ipsecTopology.edgeValueOrDefault(node, neighbor, null); if (ipsecSession == null) { continue; } IpsecPeerConfig ipsecPeerConfigNeighbor = networkConfigurations.getIpsecPeerConfig(neighbor); if (ipsecPeerConfigNeighbor == null) { continue; } processNeighbor(neighbor, ipsecSessionInfoBuilder, ipsecPeerConfigNeighbor, ipsecSession); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); } } return ipsecSessionInfos; } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Multiset<IpsecSessionInfo> rawAnswer( NetworkConfigurations networkConfigurations, ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Set<String> initiatorNodes, Set<String> responderNodes) { Multiset<IpsecSessionInfo> ipsecSessionInfos = HashMultiset.create(); for (IpsecPeerConfigId node : ipsecTopology.nodes()) { IpsecPeerConfig ipsecPeerConfig = networkConfigurations.getIpsecPeerConfig(node); if (ipsecPeerConfig == null || ipsecPeerConfig instanceof IpsecDynamicPeerConfig || !initiatorNodes.contains(node.getHostName())) { continue; } IpsecSessionInfo.Builder ipsecSessionInfoBuilder = IpsecSessionInfo.builder(); ipsecSessionInfoBuilder.setInitiatorHostname(node.getHostName()); ipsecSessionInfoBuilder.setInitiatorInterface(ipsecPeerConfig.getSourceInterface()); ipsecSessionInfoBuilder.setInitiatorIp(ipsecPeerConfig.getLocalAddress()); ipsecSessionInfoBuilder.setInitiatorTunnelInterface(ipsecPeerConfig.getTunnelInterface()); Set<IpsecPeerConfigId> neighbors = ipsecTopology.adjacentNodes(node); if (neighbors.isEmpty()) { ipsecSessionInfoBuilder.setIpsecSessionStatus(MISSING_END_POINT); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); continue; } for (IpsecPeerConfigId neighbor : neighbors) { if (!responderNodes.contains(neighbor.getHostName())) { continue; } IpsecSession ipsecSession = ipsecTopology.edgeValueOrDefault(node, neighbor, null); if (ipsecSession == null) { continue; } IpsecPeerConfig ipsecPeerConfigNeighbor = networkConfigurations.getIpsecPeerConfig(neighbor); if (ipsecPeerConfigNeighbor == null) { continue; } processNeighbor(neighbor, ipsecSessionInfoBuilder, ipsecPeerConfigNeighbor, ipsecSession); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); } } return ipsecSessionInfos; } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
IpsecSessionStatusAnswerer extends Answerer { @VisibleForTesting static Multiset<IpsecSessionInfo> rawAnswer( NetworkConfigurations networkConfigurations, ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology, Set<String> initiatorNodes, Set<String> responderNodes) { Multiset<IpsecSessionInfo> ipsecSessionInfos = HashMultiset.create(); for (IpsecPeerConfigId node : ipsecTopology.nodes()) { IpsecPeerConfig ipsecPeerConfig = networkConfigurations.getIpsecPeerConfig(node); if (ipsecPeerConfig == null || ipsecPeerConfig instanceof IpsecDynamicPeerConfig || !initiatorNodes.contains(node.getHostName())) { continue; } IpsecSessionInfo.Builder ipsecSessionInfoBuilder = IpsecSessionInfo.builder(); ipsecSessionInfoBuilder.setInitiatorHostname(node.getHostName()); ipsecSessionInfoBuilder.setInitiatorInterface(ipsecPeerConfig.getSourceInterface()); ipsecSessionInfoBuilder.setInitiatorIp(ipsecPeerConfig.getLocalAddress()); ipsecSessionInfoBuilder.setInitiatorTunnelInterface(ipsecPeerConfig.getTunnelInterface()); Set<IpsecPeerConfigId> neighbors = ipsecTopology.adjacentNodes(node); if (neighbors.isEmpty()) { ipsecSessionInfoBuilder.setIpsecSessionStatus(MISSING_END_POINT); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); continue; } for (IpsecPeerConfigId neighbor : neighbors) { if (!responderNodes.contains(neighbor.getHostName())) { continue; } IpsecSession ipsecSession = ipsecTopology.edgeValueOrDefault(node, neighbor, null); if (ipsecSession == null) { continue; } IpsecPeerConfig ipsecPeerConfigNeighbor = networkConfigurations.getIpsecPeerConfig(neighbor); if (ipsecPeerConfigNeighbor == null) { continue; } processNeighbor(neighbor, ipsecSessionInfoBuilder, ipsecPeerConfigNeighbor, ipsecSession); ipsecSessionInfos.add(ipsecSessionInfoBuilder.build()); } } return ipsecSessionInfos; } IpsecSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }