@Test public void testGetUnnumberedPeerRowEstablished() { Ip unnumIp = Ip.parse("169.254.0.1"); BgpPeerConfigId peerId = new BgpPeerConfigId("c1", "vrf1", "iface"); BgpUnnumberedPeerConfig peer = BgpUnnumberedPeerConfig.builder() .setPeerInterface("iface") .setLocalAs(1L) .setRemoteAs(2L) .setLocalIp(unnumIp) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); BgpPeerConfigId remoteId = new BgpPeerConfigId("c2", "vrf2", "iface2"); BgpUnnumberedPeerConfig remote = BgpUnnumberedPeerConfig.builder() .setPeerInterface("iface2") .setLocalAs(2L) .setRemoteAs(1L) .setLocalIp(unnumIp) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); MutableValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology = ValueGraphBuilder.directed().allowsSelfLoops(false).build(); bgpTopology.putEdgeValue(peerId, remoteId, BgpSessionProperties.from(peer, remote, false)); bgpTopology.putEdgeValue(remoteId, peerId, BgpSessionProperties.from(peer, remote, true)); Row row = getUnnumberedPeerRow(peerId, peer, bgpTopology, bgpTopology); Row expected = Row.builder() .put(COL_ESTABLISHED_STATUS, BgpSessionStatus.ESTABLISHED) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of(Type.IPV4_UNICAST)) .put(COL_LOCAL_INTERFACE, NodeInterfacePair.of("c1", "iface")) .put(COL_LOCAL_IP, null) .put(COL_LOCAL_AS, 1L) .put(COL_NODE, new Node("c1")) .put(COL_REMOTE_AS, "2") .put(COL_REMOTE_NODE, new Node("c2")) .put(COL_REMOTE_INTERFACE, NodeInterfacePair.of("c2", "iface2")) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, SessionType.EBGP_UNNUMBERED) .put(COL_VRF, "vrf1") .build(); assertThat(row, equalTo(expected)); }
@Nonnull @VisibleForTesting static Row getUnnumberedPeerRow( BgpPeerConfigId unnumId, BgpUnnumberedPeerConfig unnumPeer, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { BgpSessionStatus status = NOT_COMPATIBLE; BgpPeerConfigId remoteId = null; Long localAs = unnumPeer.getLocalAs(); String remoteAs = unnumPeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(unnumId) && establishedTopology.outDegree(unnumId) == 1) { status = ESTABLISHED; remoteId = establishedTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(establishedTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(establishedTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(establishedTopology, unnumId, remoteId); } else if (getConfiguredStatus(unnumId, unnumPeer, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; remoteId = configuredTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(configuredTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(configuredTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(configuredTopology, unnumId, remoteId); } Node remoteNode = null; NodeInterfacePair remoteInterface = null; if (remoteId != null) { remoteNode = new Node(remoteId.getHostname()); remoteInterface = NodeInterfacePair.of(remoteId.getHostname(), remoteId.getPeerInterface()); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put( COL_LOCAL_INTERFACE, NodeInterfacePair.of(unnumId.getHostname(), unnumPeer.getPeerInterface())) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, null) .put(COL_NODE, new Node(unnumId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, remoteInterface) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, getSessionType(unnumPeer)) .put(COL_VRF, unnumId.getVrfName()) .build(); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getUnnumberedPeerRow( BgpPeerConfigId unnumId, BgpUnnumberedPeerConfig unnumPeer, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { BgpSessionStatus status = NOT_COMPATIBLE; BgpPeerConfigId remoteId = null; Long localAs = unnumPeer.getLocalAs(); String remoteAs = unnumPeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(unnumId) && establishedTopology.outDegree(unnumId) == 1) { status = ESTABLISHED; remoteId = establishedTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(establishedTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(establishedTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(establishedTopology, unnumId, remoteId); } else if (getConfiguredStatus(unnumId, unnumPeer, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; remoteId = configuredTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(configuredTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(configuredTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(configuredTopology, unnumId, remoteId); } Node remoteNode = null; NodeInterfacePair remoteInterface = null; if (remoteId != null) { remoteNode = new Node(remoteId.getHostname()); remoteInterface = NodeInterfacePair.of(remoteId.getHostname(), remoteId.getPeerInterface()); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put( COL_LOCAL_INTERFACE, NodeInterfacePair.of(unnumId.getHostname(), unnumPeer.getPeerInterface())) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, null) .put(COL_NODE, new Node(unnumId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, remoteInterface) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, getSessionType(unnumPeer)) .put(COL_VRF, unnumId.getVrfName()) .build(); } }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getUnnumberedPeerRow( BgpPeerConfigId unnumId, BgpUnnumberedPeerConfig unnumPeer, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { BgpSessionStatus status = NOT_COMPATIBLE; BgpPeerConfigId remoteId = null; Long localAs = unnumPeer.getLocalAs(); String remoteAs = unnumPeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(unnumId) && establishedTopology.outDegree(unnumId) == 1) { status = ESTABLISHED; remoteId = establishedTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(establishedTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(establishedTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(establishedTopology, unnumId, remoteId); } else if (getConfiguredStatus(unnumId, unnumPeer, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; remoteId = configuredTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(configuredTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(configuredTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(configuredTopology, unnumId, remoteId); } Node remoteNode = null; NodeInterfacePair remoteInterface = null; if (remoteId != null) { remoteNode = new Node(remoteId.getHostname()); remoteInterface = NodeInterfacePair.of(remoteId.getHostname(), remoteId.getPeerInterface()); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put( COL_LOCAL_INTERFACE, NodeInterfacePair.of(unnumId.getHostname(), unnumPeer.getPeerInterface())) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, null) .put(COL_NODE, new Node(unnumId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, remoteInterface) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, getSessionType(unnumPeer)) .put(COL_VRF, unnumId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getUnnumberedPeerRow( BgpPeerConfigId unnumId, BgpUnnumberedPeerConfig unnumPeer, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { BgpSessionStatus status = NOT_COMPATIBLE; BgpPeerConfigId remoteId = null; Long localAs = unnumPeer.getLocalAs(); String remoteAs = unnumPeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(unnumId) && establishedTopology.outDegree(unnumId) == 1) { status = ESTABLISHED; remoteId = establishedTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(establishedTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(establishedTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(establishedTopology, unnumId, remoteId); } else if (getConfiguredStatus(unnumId, unnumPeer, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; remoteId = configuredTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(configuredTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(configuredTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(configuredTopology, unnumId, remoteId); } Node remoteNode = null; NodeInterfacePair remoteInterface = null; if (remoteId != null) { remoteNode = new Node(remoteId.getHostname()); remoteInterface = NodeInterfacePair.of(remoteId.getHostname(), remoteId.getPeerInterface()); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put( COL_LOCAL_INTERFACE, NodeInterfacePair.of(unnumId.getHostname(), unnumPeer.getPeerInterface())) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, null) .put(COL_NODE, new Node(unnumId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, remoteInterface) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, getSessionType(unnumPeer)) .put(COL_VRF, unnumId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static Row getUnnumberedPeerRow( BgpPeerConfigId unnumId, BgpUnnumberedPeerConfig unnumPeer, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { BgpSessionStatus status = NOT_COMPATIBLE; BgpPeerConfigId remoteId = null; Long localAs = unnumPeer.getLocalAs(); String remoteAs = unnumPeer.getRemoteAsns().toString(); Set<Type> addressFamilies = ImmutableSet.of(); if (establishedTopology.nodes().contains(unnumId) && establishedTopology.outDegree(unnumId) == 1) { status = ESTABLISHED; remoteId = establishedTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(establishedTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(establishedTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(establishedTopology, unnumId, remoteId); } else if (getConfiguredStatus(unnumId, unnumPeer, configuredTopology) == UNIQUE_MATCH) { status = NOT_ESTABLISHED; remoteId = configuredTopology.adjacentNodes(unnumId).iterator().next(); localAs = getLocalAs(configuredTopology, unnumId, remoteId, unnumPeer); remoteAs = getRemoteAs(configuredTopology, unnumId, remoteId, unnumPeer); addressFamilies = getAddressFamilies(configuredTopology, unnumId, remoteId); } Node remoteNode = null; NodeInterfacePair remoteInterface = null; if (remoteId != null) { remoteNode = new Node(remoteId.getHostname()); remoteInterface = NodeInterfacePair.of(remoteId.getHostname(), remoteId.getPeerInterface()); } return Row.builder(METADATA_MAP) .put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, addressFamilies) .put( COL_LOCAL_INTERFACE, NodeInterfacePair.of(unnumId.getHostname(), unnumPeer.getPeerInterface())) .put(COL_LOCAL_AS, localAs) .put(COL_LOCAL_IP, null) .put(COL_NODE, new Node(unnumId.getHostname())) .put(COL_REMOTE_AS, remoteAs) .put(COL_REMOTE_NODE, remoteNode) .put(COL_REMOTE_INTERFACE, remoteInterface) .put(COL_REMOTE_IP, null) .put(COL_SESSION_TYPE, getSessionType(unnumPeer)) .put(COL_VRF, unnumId.getVrfName()) .build(); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }