@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); Row expected = Row.builder() .put(COL_CONFIGURED_STATUS, ConfiguredSessionStatus.NO_REMOTE_AS) .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) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .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_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(passivePeer); if (brokenStatus != null) { return ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, brokenStatus).build()); } List<Row> rows = configuredTopology.adjacentNodes(passiveId).stream() .filter(remoteId -> configuredTopology.inDegree(remoteId) == 1) .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; return rb.put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .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, getSessionType(activeRemote)) .build(); }) .collect(ImmutableList.toImmutableList()); return rows.isEmpty() ? ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, NO_MATCH_FOUND).build()) : rows; }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .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_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(passivePeer); if (brokenStatus != null) { return ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, brokenStatus).build()); } List<Row> rows = configuredTopology.adjacentNodes(passiveId).stream() .filter(remoteId -> configuredTopology.inDegree(remoteId) == 1) .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; return rb.put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .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, getSessionType(activeRemote)) .build(); }) .collect(ImmutableList.toImmutableList()); return rows.isEmpty() ? ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, NO_MATCH_FOUND).build()) : rows; } }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .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_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(passivePeer); if (brokenStatus != null) { return ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, brokenStatus).build()); } List<Row> rows = configuredTopology.adjacentNodes(passiveId).stream() .filter(remoteId -> configuredTopology.inDegree(remoteId) == 1) .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; return rb.put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .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, getSessionType(activeRemote)) .build(); }) .collect(ImmutableList.toImmutableList()); return rows.isEmpty() ? ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, NO_MATCH_FOUND).build()) : rows; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .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_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(passivePeer); if (brokenStatus != null) { return ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, brokenStatus).build()); } List<Row> rows = configuredTopology.adjacentNodes(passiveId).stream() .filter(remoteId -> configuredTopology.inDegree(remoteId) == 1) .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; return rb.put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .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, getSessionType(activeRemote)) .build(); }) .collect(ImmutableList.toImmutableList()); return rows.isEmpty() ? ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, NO_MATCH_FOUND).build()) : rows; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); }
BgpSessionCompatibilityAnswerer extends Answerer { @Nonnull @VisibleForTesting static List<Row> getPassivePeerRows( BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, NetworkConfigurations nc, ValueGraph<BgpPeerConfigId, BgpSessionProperties> configuredTopology) { Row.TypedRowBuilder rb = Row.builder(METADATA_MAP) .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_ADDRESS_FAMILIES, ImmutableSet.of()) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()); ConfiguredSessionStatus brokenStatus = getLocallyBrokenStatus(passivePeer); if (brokenStatus != null) { return ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, brokenStatus).build()); } List<Row> rows = configuredTopology.adjacentNodes(passiveId).stream() .filter(remoteId -> configuredTopology.inDegree(remoteId) == 1) .map( remoteId -> { BgpSessionProperties sessionProps = configuredTopology.edgeValue(passiveId, remoteId).orElse(null); assert sessionProps != null; BgpActivePeerConfig activeRemote = nc.getBgpPointToPointPeerConfig(remoteId); assert activeRemote != null; return rb.put(COL_CONFIGURED_STATUS, DYNAMIC_MATCH) .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, getSessionType(activeRemote)) .build(); }) .collect(ImmutableList.toImmutableList()); return rows.isEmpty() ? ImmutableList.of(rb.put(COL_CONFIGURED_STATUS, NO_MATCH_FOUND).build()) : rows; } BgpSessionCompatibilityAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata createMetadata(Question question); static final String COL_CONFIGURED_STATUS; }