@Test public void testUnnumberedStatuses() { BgpPeerConfigId id = new BgpPeerConfigId("c", "vrf", "iface"); BgpUnnumberedPeerConfig.Builder peerBuilder = BgpUnnumberedPeerConfig.builder() .setPeerInterface("iface") .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> topology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); assertThat( getConfiguredStatus(id, peerBuilder.build(), topology), equalTo(ConfiguredSessionStatus.NO_LOCAL_AS)); BgpUnnumberedPeerConfig peer = peerBuilder.setLocalAs(1L).build(); assertThat( getConfiguredStatus(id, peer, topology), equalTo(ConfiguredSessionStatus.NO_REMOTE_AS)); peer = peerBuilder.setRemoteAs(1L).build(); topology.addNode(id); assertThat(getConfiguredStatus(id, peer, topology), equalTo(ConfiguredSessionStatus.HALF_OPEN)); Ip unnumIp = Ip.parse("169.254.0.1"); peer = peerBuilder.setLocalIp(unnumIp).build(); BgpPeerConfigId id2 = new BgpPeerConfigId("c2", "vrf", "iface2"); BgpUnnumberedPeerConfig peer2 = peerBuilder.setPeerInterface("iface2").build(); topology.addNode(id2); topology.putEdgeValue(id, id2, BgpSessionProperties.from(peer, peer2, false)); topology.putEdgeValue(id2, id, BgpSessionProperties.from(peer, peer2, true)); assertThat( getConfiguredStatus(id, peer, topology), equalTo(ConfiguredSessionStatus.UNIQUE_MATCH)); BgpPeerConfigId id3 = new BgpPeerConfigId("c3", "vrf", "iface3"); BgpUnnumberedPeerConfig peer3 = peerBuilder.setPeerInterface("iface3").build(); topology.addNode(id3); topology.putEdgeValue(id, id3, BgpSessionProperties.from(peer, peer3, false)); topology.putEdgeValue(id3, id, BgpSessionProperties.from(peer, peer3, true)); assertThat( getConfiguredStatus(id, peer, topology), equalTo(ConfiguredSessionStatus.MULTIPLE_REMOTES)); }
static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId peerId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!ipVrfOwners .getOrDefault(localIp, ImmutableMap.of()) .getOrDefault(peerId.getHostname(), ImmutableSet.of()) .contains(peerId.getVrfName())) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!ipVrfOwners.containsKey(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(peerId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(peerId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; }
BgpSessionAnswererUtils { static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId peerId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!ipVrfOwners .getOrDefault(localIp, ImmutableMap.of()) .getOrDefault(peerId.getHostname(), ImmutableSet.of()) .contains(peerId.getVrfName())) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!ipVrfOwners.containsKey(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(peerId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(peerId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; } }
BgpSessionAnswererUtils { static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId peerId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!ipVrfOwners .getOrDefault(localIp, ImmutableMap.of()) .getOrDefault(peerId.getHostname(), ImmutableSet.of()) .contains(peerId.getVrfName())) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!ipVrfOwners.containsKey(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(peerId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(peerId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; } private  BgpSessionAnswererUtils(); }
BgpSessionAnswererUtils { static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId peerId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!ipVrfOwners .getOrDefault(localIp, ImmutableMap.of()) .getOrDefault(peerId.getHostname(), ImmutableSet.of()) .contains(peerId.getVrfName())) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!ipVrfOwners.containsKey(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(peerId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(peerId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; } private  BgpSessionAnswererUtils();  }
BgpSessionAnswererUtils { static @Nonnull ConfiguredSessionStatus getConfiguredStatus( BgpPeerConfigId peerId, BgpActivePeerConfig activePeerConfig, SessionType sessionType, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredBgpTopology) { ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(activePeerConfig, sessionType); if (brokenStatus != null) { return brokenStatus; } Ip localIp = activePeerConfig.getLocalIp(); Ip remoteIp = activePeerConfig.getPeerAddress(); if (!ipVrfOwners .getOrDefault(localIp, ImmutableMap.of()) .getOrDefault(peerId.getHostname(), ImmutableSet.of()) .contains(peerId.getVrfName())) { return ConfiguredSessionStatus.INVALID_LOCAL_IP; } else if (!ipVrfOwners.containsKey(remoteIp)) { return ConfiguredSessionStatus.UNKNOWN_REMOTE; } else if (configuredBgpTopology.adjacentNodes(peerId).isEmpty()) { return ConfiguredSessionStatus.HALF_OPEN; } else if (configuredBgpTopology.outDegree(peerId) > 1) { return ConfiguredSessionStatus.MULTIPLE_REMOTES; } return ConfiguredSessionStatus.UNIQUE_MATCH; } private  BgpSessionAnswererUtils();  static final String COL_ADDRESS_FAMILIES; static final String COL_LOCAL_INTERFACE; static final String COL_LOCAL_AS; static final String COL_LOCAL_IP; static final String COL_NODE; static final String COL_REMOTE_AS; static final String COL_REMOTE_NODE; static final String COL_REMOTE_INTERFACE; static final String COL_REMOTE_IP; static final String COL_SESSION_TYPE; static final String COL_VRF; }