Skip to content

Commit

Permalink
bdp: remove queues for sending BGP messages (#6217)
Browse files Browse the repository at this point in the history
* use deltas instead of queues for outgoing route advertisements
  • Loading branch information
anothermattbrown committed Sep 19, 2020
1 parent 0cfc4c7 commit edaa1aa
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ final class BgpRoutingProcess implements RoutingProcess<BgpTopology, BgpRoute<?,
@Nonnull Bgpv4Rib _ebgpv4StagingRib;
/** RIB containing paths obtained with iBGP, for IPv4 unicast */
@Nonnull Bgpv4Rib _ibgpv4Rib;

// outgoing RIB deltas for the current round.
RibDelta<Bgpv4Route> _ebgpDelta = null;
RibDelta<AnnotatedRoute<AbstractRoute>> _mainRibBgpv4RouteDelta = null;
RibDelta<Bgpv4Route> _bgpv4Delta = null;

/**
* Helper RIB containing paths obtained with iBGP during current iteration. An Adj-RIB-in of sorts
* for IPv4 unicast
Expand Down Expand Up @@ -1067,6 +1073,10 @@ int iterationHashCode() {
// RIBs
_bgpv4Rib.getTypedRoutes(),
_evpnRib.getTypedRoutes(),
// Outgoing RIB deltas
_ebgpDelta,
_bgpv4Delta,
_mainRibBgpv4RouteDelta,
// Message queues
_bgpv4IncomingRoutes,
_evpnType3IncomingRoutes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentracing.Span;
import io.opentracing.util.GlobalTracer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
Expand All @@ -27,6 +28,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.batfish.common.BatfishLogger;
Expand Down Expand Up @@ -427,7 +429,6 @@ private static void computeDependentRoutesIteration(
}

computeIterationOfBgpRoutes(
nodes,
iterationLabel,
allNodes,
topologyContext.getBgpTopology(),
Expand All @@ -454,7 +455,6 @@ private static void computeDependentRoutesIteration(
}

private static void computeIterationOfBgpRoutes(
Map<String, Node> nodes,
String iterationLabel,
Map<String, Node> allNodes,
BgpTopology bgpTopology,
Expand All @@ -465,7 +465,7 @@ private static void computeIterationOfBgpRoutes(
LOGGER.info("{}: Init for new BGP iteration", iterationLabel);
try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) {
assert scope != null; // avoid unused warning
nodes
allNodes
.values()
.parallelStream()
.forEach(
Expand All @@ -487,7 +487,7 @@ private static void computeIterationOfBgpRoutes(
try (Scope innerScope = GlobalTracer.get().scopeManager().activate(genSpan)) {
assert innerScope != null; // avoid unused warning
// first let's initialize nodes-level generated/aggregate routes
nodes
allNodes
.values()
.parallelStream()
.forEach(
Expand All @@ -499,29 +499,51 @@ private static void computeIterationOfBgpRoutes(
Span propSpan =
GlobalTracer.get().buildSpan(iterationLabel + ": Propagate BGP v4 routes").start();
LOGGER.info("{}: Propagate BGP v4 routes", iterationLabel);

try (Scope innerScope = GlobalTracer.get().scopeManager().activate(propSpan)) {
assert innerScope != null; // avoid unused warning
nodes
.values()
.parallelStream()
.flatMap(n -> n.getVirtualRouters().values().stream())
.forEach(
vr -> {
Map<Bgpv4Rib, RibDelta<Bgpv4Route>> deltas =
vr.processBgpMessages(bgpTopology, networkConfigurations, nodes);
vr.finalizeBgpRoutesAndQueueOutgoingMessages(
deltas, allNodes, bgpTopology, networkConfigurations);
});

/*
In a round, each VR will process BGP messages from its neighbors, adding them to the right
RIBs and building a RibDelta containing messages that will be sent to neighbors in the next
round (the "outgoing delta"). Processing messages from a neighbor requires reading from
their outgoing delta. We do this for all VRs in parallel, so we need to be careful not to
read from and write to the same delta simultaneously. We separate reading and writing into
two stages. In the first stage, all VRs read from their neighbors' deltas, and build
Runnables (thunks) to clear and then write to their own deltas. In the second stage, we
simply run these Runnables (also in parallel).
*/
List<Runnable> finalizeBgpRoutesAndQueueOutgoingMessages =
allNodes
.values()
.parallelStream()
.flatMap(n -> n.getVirtualRouters().values().stream())
.map(
vr -> {
// Stage 1: read from all eighbors' queues.
Map<Bgpv4Rib, RibDelta<Bgpv4Route>> deltas =
vr.processBgpMessages(bgpTopology, networkConfigurations, allNodes);
// return a runnable for stage 2.
return (Runnable)
() -> {
vr.clearBgpOutgoingDeltas();
vr.finalizeBgpRoutesAndBuildOutgoingDeltas(deltas);
};
})
.collect(Collectors.toList());

// Stage 2: update all the outgoing queues
finalizeBgpRoutesAndQueueOutgoingMessages.parallelStream().forEach(Runnable::run);

// Merge BGP routes from BGP process into the main RIB
nodes
allNodes
.values()
.parallelStream()
.flatMap(n -> n.getVirtualRouters().values().stream())
.forEach(VirtualRouter::mergeBgpRoutesToMainRib);

// Multi-VRF redistribution of BGP routes:
nodes
allNodes
.values()
.parallelStream()
.forEach(
Expand Down Expand Up @@ -738,8 +760,7 @@ private boolean computeNonMonotonicPortionOfDataPlane(
.flatMap(n -> n.getVirtualRouters().values().stream())
.forEach(
vr -> {
vr.processExternalBgpAdvertisements(
externalAdverts, ipVrfOwners, nodes, bgpTopology, networkConfigurations);
vr.processExternalBgpAdvertisements(externalAdverts, ipVrfOwners);
vr.queueInitialBgpMessages(bgpTopology, nodes, networkConfigurations);
});
} finally {
Expand Down

0 comments on commit edaa1aa

Please sign in to comment.