@Test public void testGetDynamicPeerRowNoRemoteAs() { Prefix remotePrefix = Prefix.parse("2.2.2.0/24"); BgpPeerConfigId peerId = new BgpPeerConfigId("c1", "vrf1", remotePrefix, true); BgpPassivePeerConfig peer = BgpPassivePeerConfig.builder() .setLocalIp(Ip.AUTO) .setPeerPrefix(remotePrefix) .setLocalAs(1L) .setIpv4UnicastAddressFamily(Ipv4UnicastAddressFamily.builder().build()) .build(); List<Row> rows = getPassivePeerRows(peerId, peer, null, null, null); Row expected = Row.builder() .put(COL_ESTABLISHED_STATUS, BgpSessionStatus.NOT_COMPATIBLE) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_IP, Ip.AUTO) .put(COL_LOCAL_AS, 1L) .put(COL_NODE, new Node("c1")) .put(COL_REMOTE_AS, "") .put(COL_REMOTE_NODE, null) .put(COL_REMOTE_INTERFACE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, remotePrefix)) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, "vrf1") .build(); assertThat(rows, contains(expected)); }
@Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, passivePeer.getRemoteAsns().toString()) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); if (getLocallyBrokenStatus(passivePeer) != null) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_COMPATIBLE).build()); } Set<BgpPeerConfigId> compatibleRemotes = configuredTopology.adjacentNodes(passiveId); if (compatibleRemotes.isEmpty()) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_ESTABLISHED).build()); } Set<BgpPeerConfigId> establishedRemotes = establishedTopology.nodes().contains(passiveId) ? establishedTopology.adjacentNodes(passiveId) : ImmutableSet.of(); return compatibleRemotes.stream() .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; BgpSessionStatus status = establishedRemotes.contains(remoteId) ? ESTABLISHED : NOT_ESTABLISHED; return rb.put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, sessionProps.getAddressFamilies()) .put(COL_LOCAL_IP, sessionProps.getTailIp()) .put(COL_LOCAL_AS, sessionProps.getTailAs()) .put(COL_REMOTE_AS, Long.toString(sessionProps.getHeadAs())) .put(COL_REMOTE_NODE, new Node(remoteId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, sessionProps.getHeadIp())) .put(COL_SESSION_TYPE, sessionProps.getSessionType()) .build(); }) .collect(ImmutableList.toImmutableList()); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, passivePeer.getRemoteAsns().toString()) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); if (getLocallyBrokenStatus(passivePeer) != null) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_COMPATIBLE).build()); } Set<BgpPeerConfigId> compatibleRemotes = configuredTopology.adjacentNodes(passiveId); if (compatibleRemotes.isEmpty()) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_ESTABLISHED).build()); } Set<BgpPeerConfigId> establishedRemotes = establishedTopology.nodes().contains(passiveId) ? establishedTopology.adjacentNodes(passiveId) : ImmutableSet.of(); return compatibleRemotes.stream() .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; BgpSessionStatus status = establishedRemotes.contains(remoteId) ? ESTABLISHED : NOT_ESTABLISHED; return rb.put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, sessionProps.getAddressFamilies()) .put(COL_LOCAL_IP, sessionProps.getTailIp()) .put(COL_LOCAL_AS, sessionProps.getTailAs()) .put(COL_REMOTE_AS, Long.toString(sessionProps.getHeadAs())) .put(COL_REMOTE_NODE, new Node(remoteId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, sessionProps.getHeadIp())) .put(COL_SESSION_TYPE, sessionProps.getSessionType()) .build(); }) .collect(ImmutableList.toImmutableList()); } }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, passivePeer.getRemoteAsns().toString()) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); if (getLocallyBrokenStatus(passivePeer) != null) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_COMPATIBLE).build()); } Set<BgpPeerConfigId> compatibleRemotes = configuredTopology.adjacentNodes(passiveId); if (compatibleRemotes.isEmpty()) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_ESTABLISHED).build()); } Set<BgpPeerConfigId> establishedRemotes = establishedTopology.nodes().contains(passiveId) ? establishedTopology.adjacentNodes(passiveId) : ImmutableSet.of(); return compatibleRemotes.stream() .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; BgpSessionStatus status = establishedRemotes.contains(remoteId) ? ESTABLISHED : NOT_ESTABLISHED; return rb.put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, sessionProps.getAddressFamilies()) .put(COL_LOCAL_IP, sessionProps.getTailIp()) .put(COL_LOCAL_AS, sessionProps.getTailAs()) .put(COL_REMOTE_AS, Long.toString(sessionProps.getHeadAs())) .put(COL_REMOTE_NODE, new Node(remoteId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, sessionProps.getHeadIp())) .put(COL_SESSION_TYPE, sessionProps.getSessionType()) .build(); }) .collect(ImmutableList.toImmutableList()); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, passivePeer.getRemoteAsns().toString()) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); if (getLocallyBrokenStatus(passivePeer) != null) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_COMPATIBLE).build()); } Set<BgpPeerConfigId> compatibleRemotes = configuredTopology.adjacentNodes(passiveId); if (compatibleRemotes.isEmpty()) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_ESTABLISHED).build()); } Set<BgpPeerConfigId> establishedRemotes = establishedTopology.nodes().contains(passiveId) ? establishedTopology.adjacentNodes(passiveId) : ImmutableSet.of(); return compatibleRemotes.stream() .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; BgpSessionStatus status = establishedRemotes.contains(remoteId) ? ESTABLISHED : NOT_ESTABLISHED; return rb.put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, sessionProps.getAddressFamilies()) .put(COL_LOCAL_IP, sessionProps.getTailIp()) .put(COL_LOCAL_AS, sessionProps.getTailAs()) .put(COL_REMOTE_AS, Long.toString(sessionProps.getHeadAs())) .put(COL_REMOTE_NODE, new Node(remoteId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, sessionProps.getHeadIp())) .put(COL_SESSION_TYPE, sessionProps.getSessionType()) .build(); }) .collect(ImmutableList.toImmutableList()); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
BgpSessionStatusAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology, ValueGraph<BgpPeerConfigId, BgpSessionProperties> establishedTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .put(COL_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put(COL_REMOTE_AS, passivePeer.getRemoteAsns().toString()) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); if (getLocallyBrokenStatus(passivePeer) != null) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_COMPATIBLE).build()); } Set<BgpPeerConfigId> compatibleRemotes = configuredTopology.adjacentNodes(passiveId); if (compatibleRemotes.isEmpty()) { return ImmutableList.of(rb.put(COL_ESTABLISHED_STATUS, NOT_ESTABLISHED).build()); } Set<BgpPeerConfigId> establishedRemotes = establishedTopology.nodes().contains(passiveId) ? establishedTopology.adjacentNodes(passiveId) : ImmutableSet.of(); return compatibleRemotes.stream() .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; BgpSessionStatus status = establishedRemotes.contains(remoteId) ? ESTABLISHED : NOT_ESTABLISHED; return rb.put(COL_ESTABLISHED_STATUS, status) .put(COL_ADDRESS_FAMILIES, sessionProps.getAddressFamilies()) .put(COL_LOCAL_IP, sessionProps.getTailIp()) .put(COL_LOCAL_AS, sessionProps.getTailAs()) .put(COL_REMOTE_AS, Long.toString(sessionProps.getHeadAs())) .put(COL_REMOTE_NODE, new Node(remoteId.getHostname())) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, sessionProps.getHeadIp())) .put(COL_SESSION_TYPE, sessionProps.getSessionType()) .build(); }) .collect(ImmutableList.toImmutableList()); } BgpSessionStatusAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }