Search in sources :

Example 6 with ValueGraph

use of com.google.common.graph.ValueGraph in project batfish by batfish.

the class IpsecUtil method retainCompatibleTunnelEdges.

/**
 * Given an {@link IpsecTopology}, returns a new {@link IpsecTopology} containing only the edges
 * which use tunnel interfaces and are compatible
 *
 * @param ipsecTopology {@link IpsecTopology} corresponding to the compatible IPsec edges
 *     established between Tunnel interfaces
 * @param configurations {@link Map} of {@link Configuration} to configuration names
 * @return {@link IpsecTopology}
 */
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);
        // not considering endpoints not based on Tunnel interfaces
        if (ipsecPeerU == null || ipsecPeerU.getTunnelInterface() == null) {
            continue;
        }
        for (IpsecPeerConfigId endPointV : ipsecGraph.adjacentNodes(endPointU)) {
            IpsecPeerConfig ipsecPeerV = networkConfigurations.getIpsecPeerConfig(endPointV);
            // not considering endpoints not based on Tunnel interfaces
            if (ipsecPeerV == null || ipsecPeerV.getTunnelInterface() == null) {
                continue;
            }
            // checking IPsec session and adding edge
            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()) {
        // if reverse edge exists
        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);
}
Also used : IpProtocol(org.batfish.datamodel.IpProtocol) Hop(org.batfish.datamodel.flow.Hop) IpsecStaticPeerConfig(org.batfish.datamodel.IpsecStaticPeerConfig) EndpointPair(com.google.common.graph.EndpointPair) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Edge(org.batfish.datamodel.Edge) Trace(org.batfish.datamodel.flow.Trace) Interface(org.batfish.datamodel.Interface) ValueGraphBuilder(com.google.common.graph.ValueGraphBuilder) Flow(org.batfish.datamodel.Flow) IpWildcardSetIpSpace(org.batfish.datamodel.IpWildcardSetIpSpace) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) IkePhase1Key(org.batfish.datamodel.IkePhase1Key) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Map(java.util.Map) NamedPort(org.batfish.datamodel.NamedPort) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) FlowDisposition(org.batfish.datamodel.FlowDisposition) Set(java.util.Set) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) IpsecPeerConfigId(org.batfish.datamodel.IpsecPeerConfigId) TraceAndReverseFlow(org.batfish.datamodel.flow.TraceAndReverseFlow) Objects(java.util.Objects) IpsecProtocol(org.batfish.datamodel.IpsecProtocol) List(java.util.List) TransformationUtil.sourceNatPoolIps(org.batfish.datamodel.transformation.TransformationUtil.sourceNatPoolIps) ValueGraph(com.google.common.graph.ValueGraph) Entry(java.util.Map.Entry) IpWildcard(org.batfish.datamodel.IpWildcard) Ip(org.batfish.datamodel.Ip) IkePhase1Policy(org.batfish.datamodel.IkePhase1Policy) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) TransformationUtil.hasSourceNat(org.batfish.datamodel.transformation.TransformationUtil.hasSourceNat) TracerouteEngine(org.batfish.common.plugin.TracerouteEngine) HashMap(java.util.HashMap) IkePhase1Proposal(org.batfish.datamodel.IkePhase1Proposal) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.batfish.datamodel.Configuration) IpsecDynamicPeerConfig(org.batfish.datamodel.IpsecDynamicPeerConfig) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ConcreteInterfaceAddress(org.batfish.datamodel.ConcreteInterfaceAddress) IpsecTopology(org.batfish.datamodel.ipsec.IpsecTopology) IpsecPeerConfig(org.batfish.datamodel.IpsecPeerConfig) IkeKeyType(org.batfish.datamodel.IkeKeyType) IpsecSession(org.batfish.datamodel.IpsecSession) SetMultimap(com.google.common.collect.SetMultimap) IpsecPhase2Policy(org.batfish.datamodel.IpsecPhase2Policy) IpsecPhase2Proposal(org.batfish.datamodel.IpsecPhase2Proposal) MutableValueGraph(com.google.common.graph.MutableValueGraph) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) IpsecPeerConfigId(org.batfish.datamodel.IpsecPeerConfigId) IpsecSession(org.batfish.datamodel.IpsecSession) IpsecPeerConfig(org.batfish.datamodel.IpsecPeerConfig) IpsecTopology(org.batfish.datamodel.ipsec.IpsecTopology)

Example 7 with ValueGraph

use of com.google.common.graph.ValueGraph in project batfish by batfish.

the class FrrGrammarTest method testBgpNeighborCompatiblity.

@Test
public void testBgpNeighborCompatiblity() throws IOException {
    String snapshotName = "bgp-neighbor-compatibility";
    /*
    There are two nodes in the snapshot, each with XX interfaces
      u swp1: both nodes have an interface neighbor with no IP address
      n swp2: both nodes have an interface neighbor with a /31 address (same subnet)
      u swp3: both nodes have an interface neighbor with a /24 address (same subnet)
      u swp4: both nodes have an interface neighbor with a /31 and a /24 address
      - swp5: node1 has an interface neighbor with /31 and node2 has an interface neighbor with no IP address
      u swp6: node1 has an interface neighbor with /24 and node2 has an interface neighbor with no IP address
      u swp7: node1 has an interface neighbor with /31 and /24 addresses and node 2 has an interface neighbor with no IP address
      n swp8: node1 has an interface neighbor with /31 and node2 has an IP neighbor in the same subnet
      - swp9: node1 has an interface neighbor with /24 and node2 has an IP neighbor in the same subnet
      n swp10: both nodes have an interface neighbor with /30 addresses (host addresses in same subnet)

    The layer1 topology file connects matching swpX interfaces on each node (swp1<>swp1, ...)

    Combinations marked 'u' should be unnumbered sessions, combinations marked 'n' should be numbered sessions, and those marked '-' are invalid combinations.
     */
    List<String> configurationNames = ImmutableList.of("node1", "node2");
    Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationFiles(SNAPSHOTS_PREFIX + snapshotName, configurationNames).setLayer1TopologyPrefix(SNAPSHOTS_PREFIX + snapshotName).build(), _folder);
    batfish.computeDataPlane(batfish.getSnapshot());
    ValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpGraph = batfish.getTopologyProvider().getBgpTopology(batfish.getSnapshot()).getGraph();
    // unnumbered sessions
    assertThat(bgpGraph.edges().stream().map(e -> e.nodeU().getPeerInterface()).filter(Objects::nonNull).collect(Collectors.toSet()), containsInAnyOrder("swp1", "swp3", "swp4", "swp6", "swp7"));
    // numbered sessions: swp2 and swp8
    assertThat(bgpGraph.edges().stream().map(e -> e.nodeU().getRemotePeerPrefix()).filter(Objects::nonNull).collect(Collectors.toSet()), containsInAnyOrder(Prefix.parse("2.2.2.0/32"), Prefix.parse("2.2.2.1/32"), Prefix.parse("8.8.8.0/32"), Prefix.parse("8.8.8.1/32"), Prefix.parse("10.10.10.1/32"), Prefix.parse("10.10.10.2/32")));
}
Also used : OspfExternalType2Route(org.batfish.datamodel.OspfExternalType2Route) FrrConversions.computeOspfAreaRangeFilterName(org.batfish.representation.frr.FrrConversions.computeOspfAreaRangeFilterName) Matchers.hasToString(org.hamcrest.Matchers.hasToString) ConnectedRouteMetadata(org.batfish.datamodel.ConnectedRouteMetadata) BgpNeighborSourceInterface(org.batfish.representation.frr.BgpNeighborSourceInterface) Matchers.not(org.hamcrest.Matchers.not) RouteFilterList(org.batfish.datamodel.RouteFilterList) BGP_ADDRESS_FAMILY_IPV6_IMPORT_VRF(org.batfish.representation.frr.FrrStructureUsage.BGP_ADDRESS_FAMILY_IPV6_IMPORT_VRF) BatfishParseTreeWalker(org.batfish.grammar.BatfishParseTreeWalker) Interface(org.batfish.datamodel.Interface) OspfAreaSummary(org.batfish.datamodel.ospf.OspfAreaSummary) BgpNetwork(org.batfish.representation.frr.BgpNetwork) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) Bgpv4Route(org.batfish.datamodel.Bgpv4Route) BgpIpNeighbor(org.batfish.representation.frr.BgpIpNeighbor) BgpCommunityListExpandedLine(org.batfish.representation.frr.BgpCommunityListExpandedLine) CumulusConcatenatedConfiguration(org.batfish.representation.cumulus_concatenated.CumulusConcatenatedConfiguration) Protocol(org.batfish.representation.frr.RouteMapMatchSourceProtocol.Protocol) CONNECTED(org.batfish.representation.frr.FrrRoutingProtocol.CONNECTED) DataPlane(org.batfish.datamodel.DataPlane) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) ROUTE_MAP_MATCH_COMMUNITY_LIST(org.batfish.representation.frr.FrrStructureUsage.ROUTE_MAP_MATCH_COMMUNITY_LIST) OspfProcess(org.batfish.datamodel.ospf.OspfProcess) Set(java.util.Set) ValueGraph(com.google.common.graph.ValueGraph) FrrStructureType(org.batfish.representation.frr.FrrStructureType) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) MapMatchers.hasKeys(org.batfish.datamodel.matchers.MapMatchers.hasKeys) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkSnapshot(org.batfish.common.NetworkSnapshot) FrrConfiguration(org.batfish.representation.frr.FrrConfiguration) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) Iterables(com.google.common.collect.Iterables) BgpNeighborIpv4UnicastAddressFamily(org.batfish.representation.frr.BgpNeighborIpv4UnicastAddressFamily) SerializationUtils(org.apache.commons.lang3.SerializationUtils) BgpPeerConfigId(org.batfish.datamodel.BgpPeerConfigId) OSPF(org.batfish.representation.frr.FrrRoutingProtocol.OSPF) SilentSyntaxCollection(org.batfish.grammar.silent_syntax.SilentSyntaxCollection) LiteralLong(org.batfish.datamodel.routing_policy.expr.LiteralLong) RouteMapEntry(org.batfish.representation.frr.RouteMapEntry) Lists(com.google.common.collect.Lists) RouteMap(org.batfish.representation.frr.RouteMap) Matchers.hasSize(org.hamcrest.Matchers.hasSize) LineAction(org.batfish.datamodel.LineAction) TestrigText(org.batfish.main.TestrigText) StaticRoute(org.batfish.representation.frr.StaticRoute) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ConcreteInterfaceAddress(org.batfish.datamodel.ConcreteInterfaceAddress) Before(org.junit.Before) DefinedStructureInfo(org.batfish.datamodel.DefinedStructureInfo) BGP_AS_PATH_ACCESS_LIST(org.batfish.representation.frr.FrrStructureType.BGP_AS_PATH_ACCESS_LIST) OUT(org.batfish.datamodel.routing_policy.Environment.Direction.OUT) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) StandardCommunity(org.batfish.datamodel.bgp.community.StandardCommunity) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Vrf(org.batfish.representation.frr.Vrf) Test(org.junit.Test) InterfacesInterface(org.batfish.representation.cumulus_concatenated.InterfacesInterface) OspfNetworkArea(org.batfish.representation.frr.OspfNetworkArea) Ipv6PrefixListLine(org.batfish.representation.frr.Ipv6PrefixListLine) Builder(org.batfish.datamodel.StaticRoute.Builder) RemovePrivateAsMode(org.batfish.representation.frr.BgpNeighborIpv4UnicastAddressFamily.RemovePrivateAsMode) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assert.assertNull(org.junit.Assert.assertNull) OspfVrf(org.batfish.representation.frr.OspfVrf) BgpSessionProperties(org.batfish.datamodel.BgpSessionProperties) Assert.assertEquals(org.junit.Assert.assertEquals) BgpNeighborL2vpnEvpnAddressFamily(org.batfish.representation.frr.BgpNeighborL2vpnEvpnAddressFamily) Matchers.isA(org.hamcrest.Matchers.isA) BgpVrfAddressFamilyAggregateNetworkConfiguration(org.batfish.representation.frr.BgpVrfAddressFamilyAggregateNetworkConfiguration) BgpPeerGroupNeighbor(org.batfish.representation.frr.BgpPeerGroupNeighbor) Matchers.hasKey(org.hamcrest.Matchers.hasKey) Assert.assertThat(org.junit.Assert.assertThat) BgpAsPathAccessListLine(org.batfish.representation.frr.BgpAsPathAccessListLine) SnapshotRuntimeData(org.batfish.common.runtime.SnapshotRuntimeData) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) Prefix6(org.batfish.datamodel.Prefix6) OspfArea(org.batfish.representation.frr.OspfArea) RouteMapMetricType(org.batfish.representation.frr.RouteMapMetricType) BgpCommunityListExpanded(org.batfish.representation.frr.BgpCommunityListExpanded) SummaryRouteBehavior(org.batfish.datamodel.ospf.OspfAreaSummary.SummaryRouteBehavior) BgpRedistributionPolicy(org.batfish.representation.frr.BgpRedistributionPolicy) FrrRoutingProtocol(org.batfish.representation.frr.FrrRoutingProtocol) ImmutableSet(com.google.common.collect.ImmutableSet) FrrConfigurationBuilder.nextMultipleOfFive(org.batfish.grammar.frr.FrrConfigurationBuilder.nextMultipleOfFive) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) OriginType(org.batfish.datamodel.OriginType) AsPath(org.batfish.datamodel.AsPath) Objects(java.util.Objects) Settings(org.batfish.config.Settings) List(java.util.List) AbstractRouteDecoratorMatchers.hasPrefix(org.batfish.datamodel.matchers.AbstractRouteDecoratorMatchers.hasPrefix) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Warnings(org.batfish.common.Warnings) ROUTE_MAP_MATCH_AS_PATH(org.batfish.representation.frr.FrrStructureUsage.ROUTE_MAP_MATCH_AS_PATH) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SortedMap(java.util.SortedMap) BatfishLogger(org.batfish.common.BatfishLogger) Ip(org.batfish.datamodel.Ip) BatfishTestUtils(org.batfish.main.BatfishTestUtils) OspfNetworkType(org.batfish.representation.frr.OspfNetworkType) STATIC(org.batfish.representation.frr.FrrRoutingProtocol.STATIC) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) BgpAsPathAccessList(org.batfish.representation.frr.BgpAsPathAccessList) IpPrefixList(org.batfish.representation.frr.IpPrefixList) BgpNeighbor(org.batfish.representation.frr.BgpNeighbor) BgpInterfaceNeighbor(org.batfish.representation.frr.BgpInterfaceNeighbor) FrrStructureUsage(org.batfish.representation.frr.FrrStructureUsage) RemoteAs(org.batfish.representation.frr.BgpNeighbor.RemoteAs) DEFAULT_VRF_NAME(org.batfish.datamodel.Configuration.DEFAULT_VRF_NAME) ImmutableList(com.google.common.collect.ImmutableList) SubRange(org.batfish.datamodel.SubRange) RedistributionPolicy(org.batfish.representation.frr.RedistributionPolicy) ParseWarning(org.batfish.common.Warnings.ParseWarning) Configuration(org.batfish.datamodel.Configuration) BGP_COMMUNITY_LIST(org.batfish.representation.frr.FrrStructureType.BGP_COMMUNITY_LIST) IpPrefixListLine(org.batfish.representation.frr.IpPrefixListLine) Batfish(org.batfish.main.Batfish) BgpNeighborSourceAddress(org.batfish.representation.frr.BgpNeighborSourceAddress) ExpectedException(org.junit.rules.ExpectedException) FrrConversions.computeRouteMapEntryName(org.batfish.representation.frr.FrrConversions.computeRouteMapEntryName) Ipv6PrefixList(org.batfish.representation.frr.Ipv6PrefixList) ParseWarningMatchers.hasText(org.batfish.common.matchers.ParseWarningMatchers.hasText) Matchers.empty(org.hamcrest.Matchers.empty) Warning(org.batfish.common.Warning) BGP_ADDRESS_FAMILY_IPV4_IMPORT_VRF(org.batfish.representation.frr.FrrStructureUsage.BGP_ADDRESS_FAMILY_IPV4_IMPORT_VRF) ROUTE_MAP(org.batfish.representation.frr.FrrStructureType.ROUTE_MAP) Assert.assertNotNull(org.junit.Assert.assertNotNull) NextHopInterface(org.batfish.datamodel.route.nh.NextHopInterface) FrrInterface(org.batfish.representation.frr.FrrInterface) BgpRouteMatchers.isBgpv4RouteThat(org.batfish.datamodel.matchers.BgpRouteMatchers.isBgpv4RouteThat) Rule(org.junit.Rule) VRF(org.batfish.representation.frr.FrrStructureType.VRF) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) ParseWarningMatchers.hasComment(org.batfish.common.matchers.ParseWarningMatchers.hasComment) TemporaryFolder(org.junit.rules.TemporaryFolder) Prefix(org.batfish.datamodel.Prefix) Objects(java.util.Objects) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) BgpPeerConfigId(org.batfish.datamodel.BgpPeerConfigId) BgpSessionProperties(org.batfish.datamodel.BgpSessionProperties) Batfish(org.batfish.main.Batfish) Test(org.junit.Test)

Example 8 with ValueGraph

use of com.google.common.graph.ValueGraph in project batfish by batfish.

the class IpsecSessionStatusAnswerer method answer.

@Override
public AnswerElement answer(NetworkSnapshot snapshot) {
    IpsecSessionStatusQuestion question = (IpsecSessionStatusQuestion) _question;
    Map<String, Configuration> configurations = _batfish.loadConfigurations(snapshot);
    NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations);
    ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology = IpsecUtil.initIpsecTopology(configurations).getGraph();
    Set<String> initiatorNodes = SpecifierFactories.getNodeSpecifierOrDefault(question.getNodes(), AllNodesNodeSpecifier.INSTANCE).resolve(_batfish.specifierContext(snapshot));
    Set<String> responderNodes = SpecifierFactories.getNodeSpecifierOrDefault(question.getRemoteNodes(), AllNodesNodeSpecifier.INSTANCE).resolve(_batfish.specifierContext(snapshot));
    Set<IpsecSessionStatus> statuses = SpecifierFactories.getEnumSetSpecifierOrDefault(question.getStatus(), Grammar.IPSEC_SESSION_STATUS_SPECIFIER, new ConstantEnumSetSpecifier<>(ImmutableSet.copyOf(IpsecSessionStatus.values()))).resolve();
    TableAnswerElement answerElement = new TableAnswerElement(createTableMetaData(question));
    Multiset<IpsecSessionInfo> ipsecSessionInfos = rawAnswer(networkConfigurations, ipsecTopology, initiatorNodes, responderNodes);
    answerElement.postProcessAnswer(question, ipsecSessionInfos.stream().filter(ipsecSessionInfo -> statuses.contains(ipsecSessionInfo.getIpsecSessionStatus())).map(IpsecSessionStatusAnswerer::toRow).collect(ImmutableList.toImmutableList()));
    return answerElement;
}
Also used : NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Grammar(org.batfish.specifier.parboiled.Grammar) Multiset(com.google.common.collect.Multiset) TableMetadata(org.batfish.datamodel.table.TableMetadata) DisplayHints(org.batfish.datamodel.questions.DisplayHints) IKE_PHASE1_FAILED(org.batfish.datamodel.questions.IpsecSessionStatus.IKE_PHASE1_FAILED) TableAnswerElement(org.batfish.datamodel.table.TableAnswerElement) IPSEC_PHASE2_FAILED(org.batfish.datamodel.questions.IpsecSessionStatus.IPSEC_PHASE2_FAILED) ConstantEnumSetSpecifier(org.batfish.specifier.ConstantEnumSetSpecifier) ImmutableList(com.google.common.collect.ImmutableList) IpsecSessionStatus(org.batfish.datamodel.questions.IpsecSessionStatus) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Map(java.util.Map) IpsecUtil(org.batfish.common.util.IpsecUtil) LinkedHashMultiset(com.google.common.collect.LinkedHashMultiset) Configuration(org.batfish.datamodel.Configuration) IpsecDynamicPeerConfig(org.batfish.datamodel.IpsecDynamicPeerConfig) Nonnull(javax.annotation.Nonnull) Answerer(org.batfish.common.Answerer) IpsecPeerConfig(org.batfish.datamodel.IpsecPeerConfig) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) AllNodesNodeSpecifier(org.batfish.specifier.AllNodesNodeSpecifier) Schema(org.batfish.datamodel.answers.Schema) IpsecSession(org.batfish.datamodel.IpsecSession) MISSING_END_POINT(org.batfish.datamodel.questions.IpsecSessionStatus.MISSING_END_POINT) IpsecPeerConfigId(org.batfish.datamodel.IpsecPeerConfigId) IBatfish(org.batfish.common.plugin.IBatfish) Row(org.batfish.datamodel.table.Row) List(java.util.List) ValueGraph(com.google.common.graph.ValueGraph) RowBuilder(org.batfish.datamodel.table.Row.RowBuilder) Node(org.batfish.datamodel.pojo.Node) Question(org.batfish.datamodel.questions.Question) IKE_PHASE1_KEY_MISMATCH(org.batfish.datamodel.questions.IpsecSessionStatus.IKE_PHASE1_KEY_MISMATCH) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) AnswerElement(org.batfish.datamodel.answers.AnswerElement) IPSEC_SESSION_ESTABLISHED(org.batfish.datamodel.questions.IpsecSessionStatus.IPSEC_SESSION_ESTABLISHED) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NetworkSnapshot(org.batfish.common.NetworkSnapshot) ColumnMetadata(org.batfish.datamodel.table.ColumnMetadata) SpecifierFactories(org.batfish.specifier.SpecifierFactories) Configuration(org.batfish.datamodel.Configuration) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) ConstantEnumSetSpecifier(org.batfish.specifier.ConstantEnumSetSpecifier) TableAnswerElement(org.batfish.datamodel.table.TableAnswerElement) IpsecSessionStatus(org.batfish.datamodel.questions.IpsecSessionStatus) IpsecPeerConfigId(org.batfish.datamodel.IpsecPeerConfigId) IpsecSession(org.batfish.datamodel.IpsecSession)

Example 9 with ValueGraph

use of com.google.common.graph.ValueGraph in project batfish by batfish.

the class EdgesAnswerer method getIpsecEdges.

@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(// only considering endpoints with established IPsec session
    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;
}
Also used : BgpPeerConfigType(org.batfish.datamodel.BgpPeerConfigId.BgpPeerConfigType) VxlanTopology(org.batfish.datamodel.vxlan.VxlanTopology) BgpTopology(org.batfish.datamodel.bgp.BgpTopology) TableAnswerElement(org.batfish.datamodel.table.TableAnswerElement) EndpointPair(com.google.common.graph.EndpointPair) Edge(org.batfish.datamodel.Edge) IntegerSpace(org.batfish.datamodel.IntegerSpace) Interface(org.batfish.datamodel.Interface) TopologyProvider(org.batfish.common.topology.TopologyProvider) HashMultiset(com.google.common.collect.HashMultiset) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) IpsecUtil(org.batfish.common.util.IpsecUtil) VxlanNode(org.batfish.datamodel.vxlan.VxlanNode) Vrf(org.batfish.datamodel.Vrf) ImmutableSet(com.google.common.collect.ImmutableSet) BgpPeerConfig(org.batfish.datamodel.BgpPeerConfig) Collection(java.util.Collection) Range(com.google.common.collect.Range) Set(java.util.Set) IsisEdge(org.batfish.datamodel.isis.IsisEdge) Schema(org.batfish.datamodel.answers.Schema) Collectors(java.util.stream.Collectors) IpsecPeerConfigId(org.batfish.datamodel.IpsecPeerConfigId) IBatfish(org.batfish.common.plugin.IBatfish) Objects(java.util.Objects) Row(org.batfish.datamodel.table.Row) List(java.util.List) ValueGraph(com.google.common.graph.ValueGraph) Stream(java.util.stream.Stream) EigrpTopology(org.batfish.datamodel.eigrp.EigrpTopology) Question(org.batfish.datamodel.questions.Question) Optional(java.util.Optional) OspfTopology(org.batfish.datamodel.ospf.OspfTopology) AnswerElement(org.batfish.datamodel.answers.AnswerElement) NetworkSnapshot(org.batfish.common.NetworkSnapshot) ColumnMetadata(org.batfish.datamodel.table.ColumnMetadata) Ip(org.batfish.datamodel.Ip) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Multiset(com.google.common.collect.Multiset) TableMetadata(org.batfish.datamodel.table.TableMetadata) Layer1Topology(org.batfish.common.topology.Layer1Topology) BgpPeerConfigId(org.batfish.datamodel.BgpPeerConfigId) OspfNeighborConfigId(org.batfish.datamodel.ospf.OspfNeighborConfigId) Layer1Edge(org.batfish.common.topology.Layer1Edge) IsisTopology(org.batfish.datamodel.isis.IsisTopology) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) Configuration(org.batfish.datamodel.Configuration) EdgeType(org.batfish.question.edges.EdgesQuestion.EdgeType) Nullable(javax.annotation.Nullable) ConcreteInterfaceAddress(org.batfish.datamodel.ConcreteInterfaceAddress) Answerer(org.batfish.common.Answerer) Layer2Edge(org.batfish.common.topology.Layer2Edge) IpsecPeerConfig(org.batfish.datamodel.IpsecPeerConfig) Layer2Vni(org.batfish.datamodel.vxlan.Layer2Vni) IpsecSession(org.batfish.datamodel.IpsecSession) EigrpEdge(org.batfish.datamodel.eigrp.EigrpEdge) EigrpTopologyUtils(org.batfish.datamodel.eigrp.EigrpTopologyUtils) RowBuilder(org.batfish.datamodel.table.Row.RowBuilder) Node(org.batfish.datamodel.pojo.Node) BgpSessionProperties(org.batfish.datamodel.BgpSessionProperties) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Optional(java.util.Optional) NetworkConfigurations(org.batfish.datamodel.NetworkConfigurations) Row(org.batfish.datamodel.table.Row) IpsecPeerConfig(org.batfish.datamodel.IpsecPeerConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableSet (com.google.common.collect.ImmutableSet)9 ValueGraph (com.google.common.graph.ValueGraph)9 List (java.util.List)9 Map (java.util.Map)9 Set (java.util.Set)9 Configuration (org.batfish.datamodel.Configuration)9 NetworkSnapshot (org.batfish.common.NetworkSnapshot)8 Ip (org.batfish.datamodel.Ip)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Nonnull (javax.annotation.Nonnull)7 BgpPeerConfigId (org.batfish.datamodel.BgpPeerConfigId)7 BgpSessionProperties (org.batfish.datamodel.BgpSessionProperties)7 NetworkConfigurations (org.batfish.datamodel.NetworkConfigurations)7 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)7 Answerer (org.batfish.common.Answerer)6 IBatfish (org.batfish.common.plugin.IBatfish)6 AnswerElement (org.batfish.datamodel.answers.AnswerElement)6 Schema (org.batfish.datamodel.answers.Schema)6 Node (org.batfish.datamodel.pojo.Node)6