export: advertise every route for a prefix with ADD-PATH (all_paths)
Before this change, a session on which ADD-PATH (RFC 7911) was
negotiated in the sending direction was sent path identifiers, but only
the best route for each prefix. A route collector such as bgp.tools
wants every route a router has accepted, from every neighbor, and from
one session: without this the collector saw one path per prefix, nearly
always the same neighbor's.
This change adds `all_paths` to the export policy. On a session with it,
and ADD-PATH send negotiated for a family, every accepted route for a
prefix of that family is advertised, each with a path identifier of its
own; for a family without ADD-PATH send the best route goes as before.
`all_paths` needs `learned_routes` (a configuration error otherwise) and
the peer's `add_path` to offer sending. The export policy, the role
rules, the well-known communities and the export limits apply to every
route alike, and the export limits count every route.
Implementation, in the advertiser:
* An exporter with `all_paths` follows the table's journal of all routes
(`RibTable::reader_of_all_routes`, until now unused) instead of the
best-route journal, and is given all the routes of a prefix whenever
one of them changes (`News::Routes`).
* What the peer holds is `Announced`: the set of prefixes for a
best-route session, as before; or for an all-paths session, for each
prefix the routes announced, keyed by the peer they came from and that
peer's own identifier, with the identifier they went out with and the
form they went out in. A route keeps its identifier for as long as it
is announced, goes out again only if it changed, and is withdrawn by
its identifier; a new route gets the lowest identifier not in use for
the prefix, from 1.
* Verdicts carry either kind (`Verdict::Best`, `Verdict::All`), and a
reset of the table puts what was announced in doubt until heard of
again, as before, with the same identifiers kept across the reset.
* The record for an all-paths session is about 50 bytes a route, some
tens of megabytes for a full table from several neighbors; the
best-route bookkeeping is unchanged in size.
Also, so that a collector session can be watched: the number of routes
advertised to each peer and not withdrawn since, every route counted
where several are sent for a prefix. The exporter keeps it in the
session's counters after every change; it is `advertised_routes` in
`/api/peers`, the "sent" column of the status page's neighbor table,
and the gauge `bgp_peer_advertised_routes{peer}`.
Documentation: a "Feeding a Route Collector" section in the guide to
passing routes on, with the configuration for a collector; `all_paths`
in the configuration reference; the ADD-PATH sections of the neighbor
guide and the standards reference; the limitation that was removed;
the new field, column and metric in the HTTP API, monitoring and
metrics references.
Testing: an integration test with two feeders and a collector that
negotiated ADD-PATH receive, which checks the two routes with their
identifiers, the withdrawal of one by its identifier, a changed route
keeping its identifier and a new route taking the free one; a
configuration test for `all_paths` without `learned_routes`; a new
`collector` phase of the interoperability lab in which FRR, as a route
collector, is told both of BIRD's routes for a prefix from BIRD's two
sessions and holds them apart, and loses one when its session is
disabled, with the advertised count checked at each step. The workspace tests, the kernel tests and every lab phase pass.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
03f4f58ecb
commit
ec5c9be454
24 files changed
+660
-75
No files matched your search
@@ -29,6 +29,9 @@ pub struct TestServer {
|
||||
handle: JoinHandle<Result<(), ServerError>>,
|
||||
/// The single IPv4 loopback address the server is bound to.
|
||||
pub addr: SocketAddr,
|
||||
/// Every address it is bound to, in the order configured: `addr`
|
||||
/// first.
|
||||
pub addrs: Vec<SocketAddr>,
|
||||
/// The server's routing table.
|
||||
pub rib: Arc<RibTable>,
|
||||
/// Handle to the server's locally originated routes.
|
||||
@@ -85,11 +88,8 @@ impl TestServer {
|
||||
customize(&mut config);
|
||||
|
||||
let bound = BgpServer::bind(config).await?;
|
||||
let addr = bound
|
||||
.local_addrs()
|
||||
.into_iter()
|
||||
.next()
|
||||
.expect("at least one listener");
|
||||
let addrs = bound.local_addrs();
|
||||
let addr = *addrs.first().expect("at least one listener");
|
||||
let rib = Arc::clone(&bound.rib);
|
||||
let local_rib = bound.local_rib.clone();
|
||||
let registry = bound.registry.clone();
|
||||
@@ -102,6 +102,7 @@ impl TestServer {
|
||||
Ok(Self {
|
||||
handle,
|
||||
addr,
|
||||
addrs,
|
||||
rib,
|
||||
local_rib,
|
||||
registry,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! End-to-end tests of ADD-PATH (RFC 7911): a peer sending several routes
|
||||
//! for one prefix, told apart by path identifiers.
|
||||
|
||||
use std::net::{Ipv4Addr, SocketAddr};
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use bgp_integration_tests::announcement::{Announcement, withdrawal};
|
||||
@@ -15,7 +17,7 @@ use bgp_primitives::ip_prefix::Nlri;
|
||||
use bgp_rib::{LocalRoute, LocalRouteAttrs};
|
||||
use bgp_server::config::PeerConfig;
|
||||
use bgp_server::family::SUPPORTED;
|
||||
use bgp_server::policy::ImportPolicy;
|
||||
use bgp_server::policy::{ExportPolicy, ImportPolicy};
|
||||
use eyre::Result;
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -242,3 +244,148 @@ async fn test_prefixes_are_sent_with_path_identifiers_when_agreed() -> Result<()
|
||||
assert_eq!(held(&server), [(0, vec![PEER_ASN], true)]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const COLLECTOR_ASN: u32 = 65100;
|
||||
|
||||
/// What a collector holds: for each prefix and path identifier, the
|
||||
/// route's AS path.
|
||||
type Held = BTreeMap<(String, u32), Vec<u32>>;
|
||||
|
||||
/// Reads what the collector is told, into `held`, until `done` says so.
|
||||
async fn told(
|
||||
collector: &mut TestPeer,
|
||||
held: &mut Held,
|
||||
done: impl Fn(&Held) -> bool,
|
||||
) -> Result<()> {
|
||||
while !done(held) {
|
||||
let update = collector.recv_update().await?;
|
||||
let path = update
|
||||
.path_attributes
|
||||
.iter()
|
||||
.find_map(|attribute| match attribute {
|
||||
PathAttribute::AsPath(path) => Some(path.segments[0].path.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_default();
|
||||
for nlri in &update.withdrawn_routes {
|
||||
held.remove(&(nlri.prefix.to_string(), nlri.path_id));
|
||||
}
|
||||
for nlri in &update.announced_routes {
|
||||
held.insert((nlri.prefix.to_string(), nlri.path_id), path.clone());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The routes held for 203.0.113.0/24, by path identifier.
|
||||
fn paths(held: &Held) -> Vec<(u32, Vec<u32>)> {
|
||||
held.iter()
|
||||
.map(|((prefix, id), path)| {
|
||||
assert_eq!(prefix, "203.0.113.0/24");
|
||||
(*id, path.clone())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A collector that agreed to be sent several routes for a prefix, and
|
||||
/// whose export policy says to send it every route, is told of every
|
||||
/// peer's route for a prefix, each with a path identifier of its own that
|
||||
/// stays with the route; a route that goes is withdrawn by its identifier.
|
||||
#[tokio::test]
|
||||
async fn test_every_route_goes_to_a_collector_told_apart_by_path_identifiers() -> Result<()> {
|
||||
let server = TestServer::start_with(LOCAL_ASN, |c| {
|
||||
// The collector is the configured peer at the IPv4 loopback
|
||||
// address; the feeders come over IPv6 loopback as peers of no
|
||||
// account.
|
||||
c.listen_endpoints
|
||||
.push(SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 0));
|
||||
c.peers = vec![PeerConfig {
|
||||
add_path: Some(SendReceive::Send),
|
||||
import: ImportPolicy::permissive(),
|
||||
export: Arc::new(ExportPolicy {
|
||||
learned_routes: true,
|
||||
all_paths: true,
|
||||
..ExportPolicy::default()
|
||||
}),
|
||||
..peer_config(
|
||||
"collector",
|
||||
SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 1),
|
||||
COLLECTOR_ASN,
|
||||
)
|
||||
}];
|
||||
c.connect_retry = Duration::from_secs(3600);
|
||||
})
|
||||
.await?;
|
||||
let route = |path: &[u32]| Announcement::of([prefix("203.0.113.0/24").into()], path);
|
||||
let feeder = async |n: u32| -> Result<TestPeer> {
|
||||
let mut peer = TestPeer::connect(server.addrs[1]).await?;
|
||||
peer.handshake(PEER_ASN + n, Ipv4Addr::new(10, 0, 0, n as u8 + 1), 90)
|
||||
.await?;
|
||||
Ok(peer)
|
||||
};
|
||||
let mut a = feeder(0).await?;
|
||||
let mut b = feeder(1).await?;
|
||||
server.wait_for_sessions(2).await?;
|
||||
a.announce(route(&[PEER_ASN, 64510])).await?;
|
||||
b.announce(route(&[PEER_ASN + 1, 64510])).await?;
|
||||
server.wait_for_routes(2).await?;
|
||||
|
||||
let mut capabilities = vec![Capability::FourByteAsn { asn: COLLECTOR_ASN }];
|
||||
capabilities.extend(SUPPORTED.into_iter().map(Capability::multiprotocol));
|
||||
capabilities.push(Capability::AddPath {
|
||||
entries: vec![AddPathEntry {
|
||||
afi: AfiSafi::IPV4_UNICAST.afi,
|
||||
safi: AfiSafi::IPV4_UNICAST.safi,
|
||||
send_recv: SendReceive::Receive,
|
||||
}],
|
||||
});
|
||||
let mut collector = TestPeer::connect(server.addr).await?;
|
||||
collector
|
||||
.handshake_with(
|
||||
COLLECTOR_ASN,
|
||||
Ipv4Addr::new(10, 0, 0, 100),
|
||||
90,
|
||||
capabilities,
|
||||
)
|
||||
.await?;
|
||||
collector.ctx.add_path = vec![AfiSafi::IPV4_UNICAST];
|
||||
|
||||
// Both routes, told apart.
|
||||
let mut held = Held::new();
|
||||
told(&mut collector, &mut held, |held| held.len() == 2).await?;
|
||||
assert_eq!(
|
||||
paths(&held),
|
||||
[
|
||||
(1, vec![LOCAL_ASN, PEER_ASN, 64510]),
|
||||
(2, vec![LOCAL_ASN, PEER_ASN + 1, 64510]),
|
||||
]
|
||||
);
|
||||
|
||||
// The second peer's route goes: withdrawn by its identifier, the
|
||||
// first's untouched.
|
||||
b.announce(withdrawal([prefix("203.0.113.0/24").into()]))
|
||||
.await?;
|
||||
told(&mut collector, &mut held, |held| held.len() == 1).await?;
|
||||
assert_eq!(paths(&held), [(1, vec![LOCAL_ASN, PEER_ASN, 64510])]);
|
||||
|
||||
// The first peer's route changes: it goes out again with the same
|
||||
// identifier. A third peer's route gets the lowest free one.
|
||||
a.announce(route(&[PEER_ASN, 64511, 64510])).await?;
|
||||
let mut c = feeder(2).await?;
|
||||
server.wait_for_sessions(4).await?;
|
||||
c.announce(route(&[PEER_ASN + 2, 64510])).await?;
|
||||
let changed = |held: &Held| {
|
||||
held.len() == 2
|
||||
&& held.get(&("203.0.113.0/24".to_string(), 1))
|
||||
== Some(&vec![LOCAL_ASN, PEER_ASN, 64511, 64510])
|
||||
};
|
||||
told(&mut collector, &mut held, changed).await?;
|
||||
assert_eq!(
|
||||
paths(&held),
|
||||
[
|
||||
(1, vec![LOCAL_ASN, PEER_ASN, 64511, 64510]),
|
||||
(2, vec![LOCAL_ASN, PEER_ASN + 2, 64510]),
|
||||
]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -27,6 +27,7 @@ async fn transit(customize: impl FnOnce(&mut bgp_server::config::Config)) -> Res
|
||||
TestServer::start_with(LOCAL_ASN, |config| {
|
||||
config.export = Arc::new(ExportPolicy {
|
||||
learned_routes: true,
|
||||
all_paths: false,
|
||||
..ExportPolicy::default()
|
||||
});
|
||||
customize(config);
|
||||
@@ -264,6 +265,7 @@ async fn test_communities_say_who_is_told() -> Result<()> {
|
||||
});
|
||||
config.export = Arc::new(ExportPolicy {
|
||||
learned_routes: true,
|
||||
all_paths: false,
|
||||
marks: Marks::parse(&[], &["64601:7".to_string()], &[]).unwrap(),
|
||||
prepend: 1,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user