@Test public void testGetActivePeerRowUniqueMatch() { Ip localIp = Ip.parse("1.1.1.1"); Ip remoteIp = Ip.parse("2.2.2.2"); BgpPeerConfigId peerId = new BgpPeerConfigId("c1", "vrf1", remoteIp.toPrefix(), false); BgpActivePeerConfig peer = BgpActivePeerConfig.builder() .setLocalIp(localIp) .setPeerAddress(remoteIp) .setLocalAs(1L) .setRemoteAs(2L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpPeerConfigId remotePeerId = new BgpPeerConfigId("c2", "vrf2", localIp.toPrefix(), false); BgpActivePeerConfig remotePeer = BgpActivePeerConfig.builder() .setLocalAs(2L) .setRemoteAs(1L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); Map<Ip, Map<String, Set<String>>> ipVrfOwners = ImmutableMap.of( localIp, ImmutableMap.of("c1", ImmutableSet.of("vrf1")), remoteIp, ImmutableMap.of("c2", ImmutableSet.of("vrf2"))); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); bgpTopology.putEdgeValue( peerId, remotePeerId, BgpSessionProperties.from(peer, remotePeer, false)); bgpTopology.putEdgeValue( remotePeerId, peerId, BgpSessionProperties.from(peer, remotePeer, true)); Row row = getActivePeerRow(peerId, peer, ipVrfOwners, bgpTopology); Row expected = Row.builder() .put(COL_CONFIGURED_STATUS, ConfiguredSessionStatus.UNIQUE_MATCH) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST)) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_IP, localIp) .put(COL_LOCAL_AS, 1L) .put(COL_NODE, new Node("c1")) .put(COL_REMOTE_AS, LongSpace.of(2L).toString()) .put(COL_REMOTE_NODE, new Node("c2")) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, remoteIp)) .put(COL_SESSION_TYPE, SessionType.EBGP_SINGLEHOP) .put(COL_VRF, "vrf1") .build(); assertThat(row, equalTo(expected)); }
@Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { SessionType type = getSessionType(activePeer); ConfiguredSessionStatus status = getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology); Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (status == UNIQUE_MATCH) { BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); Optional<BgpSessionProperties> sessionProps = configuredTopology.edgeValue(activeId, remoteId); if (sessionProps.isPresent()) { remoteAs = Long.toString(sessionProps.get().getHeadAs()); localAs = sessionProps.get().getTailAs(); addressFamilies = sessionProps.get().getAddressFamilies(); } } return Row.builder(METADATA_MAP) .put(COL_CONFIGURED_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(); }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { SessionType type = getSessionType(activePeer); ConfiguredSessionStatus status = getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology); Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (status == UNIQUE_MATCH) { BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); Optional<BgpSessionProperties> sessionProps = configuredTopology.edgeValue(activeId, remoteId); if (sessionProps.isPresent()) { remoteAs = Long.toString(sessionProps.get().getHeadAs()); localAs = sessionProps.get().getTailAs(); addressFamilies = sessionProps.get().getAddressFamilies(); } } return Row.builder(METADATA_MAP) .put(COL_CONFIGURED_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(); } }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { SessionType type = getSessionType(activePeer); ConfiguredSessionStatus status = getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology); Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (status == UNIQUE_MATCH) { BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); Optional<BgpSessionProperties> sessionProps = configuredTopology.edgeValue(activeId, remoteId); if (sessionProps.isPresent()) { remoteAs = Long.toString(sessionProps.get().getHeadAs()); localAs = sessionProps.get().getTailAs(); addressFamilies = sessionProps.get().getAddressFamilies(); } } return Row.builder(METADATA_MAP) .put(COL_CONFIGURED_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(); } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { SessionType type = getSessionType(activePeer); ConfiguredSessionStatus status = getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology); Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (status == UNIQUE_MATCH) { BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); Optional<BgpSessionProperties> sessionProps = configuredTopology.edgeValue(activeId, remoteId); if (sessionProps.isPresent()) { remoteAs = Long.toString(sessionProps.get().getHeadAs()); localAs = sessionProps.get().getTailAs(); addressFamilies = sessionProps.get().getAddressFamilies(); } } return Row.builder(METADATA_MAP) .put(COL_CONFIGURED_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(); } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getActivePeerRow( BgpPeerConfigId activeId, BgpActivePeerConfig activePeer, Map<Ip, Map<String, Set<String>>> ipVrfOwners, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { SessionType type = getSessionType(activePeer); ConfiguredSessionStatus status = getConfiguredStatus(activeId, activePeer, type, ipVrfOwners, configuredTopology); Node remoteNode = null; Long localAs = activePeer.getLocalAs(); String remoteAs = activePeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (status == UNIQUE_MATCH) { BgpPeerConfigId remoteId = configuredTopology.adjacentNodes(activeId).iterator().next(); String remoteNodeName = remoteId.getHostname(); remoteNode = new Node(remoteNodeName); Optional<BgpSessionProperties> sessionProps = configuredTopology.edgeValue(activeId, remoteId); if (sessionProps.isPresent()) { remoteAs = Long.toString(sessionProps.get().getHeadAs()); localAs = sessionProps.get().getTailAs(); addressFamilies = sessionProps.get().getAddressFamilies(); } } return Row.builder(METADATA_MAP) .put(COL_CONFIGURED_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(); } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); static final String COL_CONFIGURED_STATUS; }