/** * Returns {@code true} iff the given process has any BGP peer configured as a route reflector * client. */ @VisibleForTesting static boolean isRouteReflector(BgpProcess p) { return p.getActiveNeighbors().values().stream() .anyMatch(BgpActivePeerConfig::getRouteReflectorClient) || p.getPassiveNeighbors().values().stream() .anyMatch(BgpPassivePeerConfig::getRouteReflectorClient); } }
@Override protected Map<Prefix, BgpActivePeerConfig> featureValueOf(BgpProcess actual) { return actual.getActiveNeighbors(); } }
@Override protected BgpActivePeerConfig featureValueOf(BgpProcess actual) { return actual.getActiveNeighbors().get(_prefix); } }
if (_bgpProcess != null) { _bgpProcess .getActiveNeighbors() .put( Prefix.create(Objects.requireNonNull(_peerAddress), Prefix.MAX_PREFIX_LENGTH),
@VisibleForTesting public static Multiset<Row> getAnswerRows( Map<String, Configuration> configurations, Set<String> nodes, Map<String, ColumnMetadata> columnMetadata, BgpPeerPropertySpecifier propertySpecifier) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodes) { for (Vrf vrf : configurations.get(nodeName).getVrfs().values()) { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess == null) { continue; } Node node = new Node(nodeName); for (BgpActivePeerConfig peer : bgpProcess.getActiveNeighbors().values()) { rows.add(getRow(node, vrf.getName(), peer, columnMetadata, propertySpecifier)); } for (BgpPassivePeerConfig peer : bgpProcess.getPassiveNeighbors().values()) { rows.add(getRow(node, vrf.getName(), peer, columnMetadata, propertySpecifier)); } } } return rows; }
if (conf.getDefaultVrf().getBgpProcess() != null) { BgpProcess bgp = conf.getDefaultVrf().getBgpProcess(); for (BgpActivePeerConfig neighbor : bgp.getActiveNeighbors().values()) { ipList.add(neighbor.getPeerAddress()); ns.add(neighbor);
public BgpProcessDiff(BgpProcess before, BgpProcess after) { if (before != null && after == null) { _inBeforeOnly = true; } else if (before == null && after != null) { _inAfterOnly = true; } else if (before != null && after != null) { _neighborsDiff = new NeighborsDiff(before.getActiveNeighbors(), after.getActiveNeighbors()); if (_neighborsDiff.isEmpty()) { _neighborsDiff = null; } _dynamicNeighborsDiff = new NeighborsDiff(before.getPassiveNeighbors(), after.getPassiveNeighbors()); if (_dynamicNeighborsDiff.isEmpty()) { _dynamicNeighborsDiff = null; } } }
/** * Initialize incoming BGP message queues. * * @param bgpTopology source of truth for which sessions get established. */ void initBgpQueues(ValueGraph<BgpPeerConfigId, BgpSessionProperties> bgpTopology) { if (_vrf.getBgpProcess() == null) { _bgpIncomingRoutes = ImmutableSortedMap.of(); } else { _bgpIncomingRoutes = Stream.concat( _vrf.getBgpProcess().getActiveNeighbors().entrySet().stream() .map( e -> new BgpPeerConfigId( getHostname(), _vrf.getName(), e.getKey(), false)), _vrf.getBgpProcess().getPassiveNeighbors().entrySet().stream() .map( e -> new BgpPeerConfigId(getHostname(), _vrf.getName(), e.getKey(), true))) .filter(bgpTopology.nodes()::contains) .flatMap( dst -> bgpTopology.adjacentNodes(dst).stream().map(src -> new BgpEdgeId(src, dst))) .collect( toImmutableSortedMap(Function.identity(), e -> new ConcurrentLinkedQueue<>())); } }
@Override @Nullable public Ip getNextHopIp(Environment environment) { Prefix peerPrefix = environment.getPeerPrefix(); if (peerPrefix == null) { return null; } BgpPeerConfig neighbor = environment.getVrf().getBgpProcess().getActiveNeighbors().get(peerPrefix); if (neighbor == null) { neighbor = environment.getVrf().getBgpProcess().getPassiveNeighbors().get(peerPrefix); } if (neighbor == null) { return null; } return neighbor.getLocalIp(); }
for (BgpActivePeerConfig n : p.getActiveNeighbors().values()) { if (n.getLocalAs() == null || n.getRemoteAs() == null) { for (Entry<Prefix, BgpActivePeerConfig> entry2 : proc.getActiveNeighbors().entrySet()) { Prefix remotePrefix = entry2.getKey(); BgpActivePeerConfig localBgpConfig = entry2.getValue();
for (BgpPeerConfig neighbor : Iterables.concat( bgpProc.getActiveNeighbors().values(), bgpProc.getPassiveNeighbors().values())) { asns.put(neighbor.getLocalAs(), hostname);
for (BgpPeerConfig neighbor : Iterables.concat( proc.getActiveNeighbors().values(), proc.getPassiveNeighbors().values())) { String exportPolicyName = neighbor.getExportPolicy(); if (exportPolicyName != null) {
BgpProcess p = conf.getDefaultVrf().getBgpProcess(); for (Map.Entry<Prefix, BgpActivePeerConfig> e : p.getActiveNeighbors().entrySet()) { BgpActivePeerConfig n = e.getValue();
proc.getActiveNeighbors().entrySet(), proc.getPassiveNeighbors().entrySet())) { Prefix prefix = entry.getKey(); BgpPeerConfig bgpPeerConfig = entry.getValue();
public void computeRoutingPolicySources(Warnings w) { for (String rpName : _routingPolicies.keySet()) { computeRoutingPolicySources(rpName, w); } for (Vrf vrf : _vrfs.values()) { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess != null) { for (BgpPeerConfig neighbor : Iterables.concat( bgpProcess.getActiveNeighbors().values(), bgpProcess.getPassiveNeighbors().values())) { neighbor.setExportPolicySources(getRoutingPolicySources(neighbor.getExportPolicy())); neighbor.setImportPolicySources(getRoutingPolicySources(neighbor.getImportPolicy())); } } OspfProcess ospfProcess = vrf.getOspfProcess(); if (ospfProcess != null) { ospfProcess.setExportPolicySources(getRoutingPolicySources(ospfProcess.getExportPolicy())); } for (GeneratedRoute gr : vrf.getGeneratedRoutes()) { gr.setAttributePolicySources(getRoutingPolicySources(gr.getAttributePolicy())); gr.setGenerationPolicySources(getRoutingPolicySources(gr.getGenerationPolicy())); } } }
@Override public long evaluate(Environment environment) { BgpProcess proc = environment.getVrf().getBgpProcess(); if (proc == null) { throw new BatfishException("Expected BGP process"); } Direction direction = environment.getDirection(); long as; Ip peerAddress = environment.getPeerAddress(); if (peerAddress == null) { throw new BatfishException("Expected a peer address"); } Prefix peerPrefix = Prefix.create(peerAddress, Prefix.MAX_PREFIX_LENGTH); // TODO: what not sure what happens with dynamic neighbors here BgpActivePeerConfig neighbor = proc.getActiveNeighbors().get(peerPrefix); if (neighbor == null) { throw new BatfishException("Expected a peer with address: " + peerAddress); } if (direction == Direction.IN) { as = neighbor.getRemoteAs(); } else if (direction == Direction.OUT) { as = neighbor.getLocalAs(); } else { throw new BatfishException("Expected to be applied in a direction"); } return as; }
for (Entry<Prefix, BgpActivePeerConfig> entry2 : bgp.getActiveNeighbors().entrySet()) { Prefix prefix = entry2.getKey(); BgpActivePeerConfig neighbor = entry2.getValue();
BgpActivePeerConfig peer1 = BgpActivePeerConfig.builder().setLocalIp(Ip.parse("1.1.1.1")).setLocalAs(1L).build(); bgp1.getActiveNeighbors().put(Prefix.create(Ip.parse("2.2.2.2"), 24), peer1); BgpPeerConfigId neighborId1 = new BgpPeerConfigId("host1", "vrf1", Prefix.create(Ip.parse("2.2.2.2"), 24), false); BgpActivePeerConfig peer2 = BgpActivePeerConfig.builder().setLocalIp(Ip.parse("2.2.2.2")).setLocalAs(2L).build(); bgp2.getActiveNeighbors().put(Prefix.create(Ip.parse("1.1.1.1"), 24), peer2); BgpPeerConfigId neighborId2 = new BgpPeerConfigId("host2", "vrf2", Prefix.create(Ip.parse("1.1.1.1"), 24), false);
BgpPeerConfig neighbor = _vrf.getBgpProcess().getActiveNeighbors().get(srcPrefix); if (neighbor == null) { continue;
fromVrf .getBgpProcess() .getActiveNeighbors() .get(Prefix.create(remoteReceivedFromIp, Prefix.MAX_PREFIX_LENGTH)); long newClusterId = remoteReceivedFromSession.getClusterId();