@Test public void testRetainCompatibleTunnelEdges() { Set<Edge> compatibleIpsecEdges = toEdgeSet(retainCompatibleTunnelEdges(_ipsecTopology, _configurations), _configurations); assertThat( compatibleIpsecEdges, containsInAnyOrder( new Edge( NodeInterfacePair.of("host1", "Tunnel1"), NodeInterfacePair.of("host2", "Tunnel2")), new Edge( NodeInterfacePair.of("host2", "Tunnel2"), NodeInterfacePair.of("host1", "Tunnel1")))); }
public static IpsecTopology retainCompatibleTunnelEdges( IpsecTopology ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); MutableValueGraph<IpsecPeerConfigId, IpsecSession> prunedIpsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecGraph = ipsecTopology.getGraph(); for (IpsecPeerConfigId endPointU : ipsecGraph.nodes()) { IpsecPeerConfig ipsecPeerU = networkConfigurations.getIpsecPeerConfig(endPointU); if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) { continue; } for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) { IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV); if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) { continue; } ipsecGraph .edgeValue(endPointU, endPointV) .filter(ipsecSession -> ipsecSession.getNegotiatedIpsecP2Proposal() != null) .ifPresent( ipsecSession -> prunedIpsecTopology.putEdgeValue(endPointU, endPointV, ipsecSession)); } } MutableValueGraph<IpsecPeerConfigId, IpsecSession> bidirCompatibleEdges = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); for (EndpointPair<IpsecPeerConfigId> endpointPair : prunedIpsecTopology.edges()) { IpsecPeerConfigId nodeU = endpointPair.nodeU(); IpsecPeerConfigId nodeV = endpointPair.nodeV(); if (prunedIpsecTopology.hasEdgeConnecting(nodeV, nodeU)) { bidirCompatibleEdges.putEdgeValue( nodeU, nodeV, prunedIpsecTopology.edgeValue(nodeU, nodeV).get()); } } return new IpsecTopology(bidirCompatibleEdges); }
IpsecUtil { public static IpsecTopology retainCompatibleTunnelEdges( IpsecTopology ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); MutableValueGraph<IpsecPeerConfigId, IpsecSession> prunedIpsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecGraph = ipsecTopology.getGraph(); for (IpsecPeerConfigId endPointU : ipsecGraph.nodes()) { IpsecPeerConfig ipsecPeerU = networkConfigurations.getIpsecPeerConfig(endPointU); if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) { continue; } for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) { IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV); if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) { continue; } ipsecGraph .edgeValue(endPointU, endPointV) .filter(ipsecSession -> ipsecSession.getNegotiatedIpsecP2Proposal() != null) .ifPresent( ipsecSession -> prunedIpsecTopology.putEdgeValue(endPointU, endPointV, ipsecSession)); } } MutableValueGraph<IpsecPeerConfigId, IpsecSession> bidirCompatibleEdges = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); for (EndpointPair<IpsecPeerConfigId> endpointPair : prunedIpsecTopology.edges()) { IpsecPeerConfigId nodeU = endpointPair.nodeU(); IpsecPeerConfigId nodeV = endpointPair.nodeV(); if (prunedIpsecTopology.hasEdgeConnecting(nodeV, nodeU)) { bidirCompatibleEdges.putEdgeValue( nodeU, nodeV, prunedIpsecTopology.edgeValue(nodeU, nodeV).get()); } } return new IpsecTopology(bidirCompatibleEdges); } }
IpsecUtil { public static IpsecTopology retainCompatibleTunnelEdges( IpsecTopology ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); MutableValueGraph<IpsecPeerConfigId, IpsecSession> prunedIpsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecGraph = ipsecTopology.getGraph(); for (IpsecPeerConfigId endPointU : ipsecGraph.nodes()) { IpsecPeerConfig ipsecPeerU = networkConfigurations.getIpsecPeerConfig(endPointU); if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) { continue; } for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) { IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV); if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) { continue; } ipsecGraph .edgeValue(endPointU, endPointV) .filter(ipsecSession -> ipsecSession.getNegotiatedIpsecP2Proposal() != null) .ifPresent( ipsecSession -> prunedIpsecTopology.putEdgeValue(endPointU, endPointV, ipsecSession)); } } MutableValueGraph<IpsecPeerConfigId, IpsecSession> bidirCompatibleEdges = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); for (EndpointPair<IpsecPeerConfigId> endpointPair : prunedIpsecTopology.edges()) { IpsecPeerConfigId nodeU = endpointPair.nodeU(); IpsecPeerConfigId nodeV = endpointPair.nodeV(); if (prunedIpsecTopology.hasEdgeConnecting(nodeV, nodeU)) { bidirCompatibleEdges.putEdgeValue( nodeU, nodeV, prunedIpsecTopology.edgeValue(nodeU, nodeV).get()); } } return new IpsecTopology(bidirCompatibleEdges); }  }
IpsecUtil { public static IpsecTopology retainCompatibleTunnelEdges( IpsecTopology ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); MutableValueGraph<IpsecPeerConfigId, IpsecSession> prunedIpsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecGraph = ipsecTopology.getGraph(); for (IpsecPeerConfigId endPointU : ipsecGraph.nodes()) { IpsecPeerConfig ipsecPeerU = networkConfigurations.getIpsecPeerConfig(endPointU); if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) { continue; } for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) { IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV); if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) { continue; } ipsecGraph .edgeValue(endPointU, endPointV) .filter(ipsecSession -> ipsecSession.getNegotiatedIpsecP2Proposal() != null) .ifPresent( ipsecSession -> prunedIpsecTopology.putEdgeValue(endPointU, endPointV, ipsecSession)); } } MutableValueGraph<IpsecPeerConfigId, IpsecSession> bidirCompatibleEdges = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); for (EndpointPair<IpsecPeerConfigId> endpointPair : prunedIpsecTopology.edges()) { IpsecPeerConfigId nodeU = endpointPair.nodeU(); IpsecPeerConfigId nodeV = endpointPair.nodeV(); if (prunedIpsecTopology.hasEdgeConnecting(nodeV, nodeU)) { bidirCompatibleEdges.putEdgeValue( nodeU, nodeV, prunedIpsecTopology.edgeValue(nodeU, nodeV).get()); } } return new IpsecTopology(bidirCompatibleEdges); }  static IpsecTopology initIpsecTopology(Map<String, Configuration> configurations); static IpsecTopology retainCompatibleTunnelEdges(
      IpsecTopology ipsecTopology, Map<String, Configuration> configurations); static Set<Edge> toEdgeSet(
      @Nonnull IpsecTopology ipsecTopology, @Nonnull Map<String, Configuration> configurations); static @Nonnull IpsecTopology retainReachableIpsecEdges(
      IpsecTopology ipsecTopology,
      Map<String, Configuration> configurations,
      TracerouteEngine tracerouteEngine); }
IpsecUtil { public static IpsecTopology retainCompatibleTunnelEdges( IpsecTopology ipsecTopology, Map<String, Configuration> configurations) { NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); MutableValueGraph<IpsecPeerConfigId, IpsecSession> prunedIpsecTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecGraph = ipsecTopology.getGraph(); for (IpsecPeerConfigId endPointU : ipsecGraph.nodes()) { IpsecPeerConfig ipsecPeerU = networkConfigurations.getIpsecPeerConfig(endPointU); if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) { continue; } for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) { IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV); if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) { continue; } ipsecGraph .edgeValue(endPointU, endPointV) .filter(ipsecSession -> ipsecSession.getNegotiatedIpsecP2Proposal() != null) .ifPresent( ipsecSession -> prunedIpsecTopology.putEdgeValue(endPointU, endPointV, ipsecSession)); } } MutableValueGraph<IpsecPeerConfigId, IpsecSession> bidirCompatibleEdges = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); for (EndpointPair<IpsecPeerConfigId> endpointPair : prunedIpsecTopology.edges()) { IpsecPeerConfigId nodeU = endpointPair.nodeU(); IpsecPeerConfigId nodeV = endpointPair.nodeV(); if (prunedIpsecTopology.hasEdgeConnecting(nodeV, nodeU)) { bidirCompatibleEdges.putEdgeValue( nodeU, nodeV, prunedIpsecTopology.edgeValue(nodeU, nodeV).get()); } } return new IpsecTopology(bidirCompatibleEdges); }  static IpsecTopology initIpsecTopology(Map<String, Configuration> configurations); static IpsecTopology retainCompatibleTunnelEdges(
      IpsecTopology ipsecTopology, Map<String, Configuration> configurations); static Set<Edge> toEdgeSet(
      @Nonnull IpsecTopology ipsecTopology, @Nonnull Map<String, Configuration> configurations); static @Nonnull IpsecTopology retainReachableIpsecEdges(
      IpsecTopology ipsecTopology,
      Map<String, Configuration> configurations,
      TracerouteEngine tracerouteEngine);  }