@Test public void testEstablishedWithMultipleRemotes() { Ip localIp = Ip.parse("1.1.1.1"); Ip remoteIp = Ip.parse("2.2.2.2"); BgpPeerConfigId peerXId = new BgpPeerConfigId("c", DEFAULT_VRF_NAME, remoteIp.toPrefix(), false); BgpActivePeerConfig peerX = BgpActivePeerConfig.builder() .setLocalIp(localIp) .setPeerAddress(remoteIp) .setLocalAs(1L) .setRemoteAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpPeerConfigId compat1Id = new BgpPeerConfigId("c2", DEFAULT_VRF_NAME, remoteIp.toPrefix(), false); BgpPeerConfigId compat2Id = new BgpPeerConfigId("c3", DEFAULT_VRF_NAME, remoteIp.toPrefix(), false); BgpPeerConfigId establishedId = new BgpPeerConfigId("c4", DEFAULT_VRF_NAME, remoteIp.toPrefix(), false); BgpActivePeerConfig remotePeer = BgpActivePeerConfig.builder() .setLocalIp(remoteIp) .setPeerAddress(localIp) .setLocalAs(2L) .setRemoteAs(1L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); configuredTopology.putEdgeValue( peerXId, compat1Id, BgpSessionProperties.from(peerX, remotePeer, false)); configuredTopology.putEdgeValue( compat1Id, peerXId, BgpSessionProperties.from(peerX, remotePeer, true)); configuredTopology.putEdgeValue( peerXId, compat2Id, BgpSessionProperties.from(peerX, remotePeer, false)); configuredTopology.putEdgeValue( compat2Id, peerXId, BgpSessionProperties.from(peerX, remotePeer, true)); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); establishedTopology.putEdgeValue( peerXId, establishedId, BgpSessionProperties.from(peerX, remotePeer, false)); establishedTopology.putEdgeValue( establishedId, peerXId, BgpSessionProperties.from(peerX, remotePeer, true)); Map<Ip, Map<String, Set<String>>> ipVrfOwners = ImmutableMap.of( localIp, ImmutableMap.of("c", ImmutableSet.of(DEFAULT_VRF_NAME)), remoteIp, ImmutableMap.of( "c2", ImmutableSet.of(DEFAULT_VRF_NAME), "c3", ImmutableSet.of(DEFAULT_VRF_NAME), "c4", ImmutableSet.of(DEFAULT_VRF_NAME))); Row row = getActivePeerRow(peerXId, peerX, ipVrfOwners, configuredTopology, establishedTopology); assertThat(row, hasColumn(COL_REMOTE_NODE, new Node("c4"), Schema.NODE)); }
@Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { SessionType type = getSessionType(activePeer); BgpSessionStatus status = NOT_COMPATIBLE; Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(activeId) && establishedTopology.outDegree(activeId) == 1) { status = ESTABLISHED; BgpPeerConfigId remoteId = establishedTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(establishedTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(establishedTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(establishedTopology, activeId, remoteId); } else if (getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(configuredTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(configuredTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(configuredTopology, activeId, remoteId); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, getSessionType(activePeer)) .put(COL_VRF, activeId.getVrfName()) .build(); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { SessionType type = getSessionType(activePeer); BgpSessionStatus status = NOT_COMPATIBLE; Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(activeId) && establishedTopology.outDegree(activeId) == 1) { status = ESTABLISHED; BgpPeerConfigId remoteId = establishedTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(establishedTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(establishedTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(establishedTopology, activeId, remoteId); } else if (getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(configuredTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(configuredTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(configuredTopology, activeId, remoteId); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, getSessionType(activePeer)) .put(COL_VRF, activeId.getVrfName()) .build(); } }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { SessionType type = getSessionType(activePeer); BgpSessionStatus status = NOT_COMPATIBLE; Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(activeId) && establishedTopology.outDegree(activeId) == 1) { status = ESTABLISHED; BgpPeerConfigId remoteId = establishedTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(establishedTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(establishedTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(establishedTopology, activeId, remoteId); } else if (getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(configuredTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(configuredTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(configuredTopology, activeId, remoteId); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, getSessionType(activePeer)) .put(COL_VRF, activeId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { SessionType type = getSessionType(activePeer); BgpSessionStatus status = NOT_COMPATIBLE; Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(activeId) && establishedTopology.outDegree(activeId) == 1) { status = ESTABLISHED; BgpPeerConfigId remoteId = establishedTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(establishedTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(establishedTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(establishedTopology, activeId, remoteId); } else if (getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(configuredTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(configuredTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(configuredTopology, activeId, remoteId); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, getSessionType(activePeer)) .put(COL_VRF, activeId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { SessionType type = getSessionType(activePeer); BgpSessionStatus status = NOT_COMPATIBLE; Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(activeId) && establishedTopology.outDegree(activeId) == 1) { status = ESTABLISHED; BgpPeerConfigId remoteId = establishedTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(establishedTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(establishedTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(establishedTopology, activeId, remoteId); } else if (getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); localAs = getLocalAs(configuredTopology, activeId, remoteId, activePeer); remoteAs = getRemoteAs(configuredTopology, activeId, remoteId, activePeer); addressFamilies = getAddressFamilies(configuredTopology, activeId, remoteId); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, activePeer.getLocalIp()) .put(COL_NODE, new Node(activeId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, activePeer.getPeerAddress())) .put(COL_SESSION_TYPE, getSessionType(activePeer)) .put(COL_VRF, activeId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }