A Rust library and CLI tool for processing BGP RIB dump files to extract peer statistics, AS relationships, and prefix-to-AS mappings.
Hosted Results: Processed data is available at:
- data.bgpkit.com/peer-stats - Peer statistics
- data.bgpkit.com/as2rel - AS relationship inferences
- data.bgpkit.com/pfx2as - Prefix-to-AS mappings
This crate provides three main processors for analyzing BGP data:
- Peer Stats (
peer_stats.rs): Collects per-peer statistics including ASN, IP, and prefix counts - AS2Rel (
as2rel.rs): Infers AS relationships (provider-customer) using a tier-1 transit algorithm - Pfx2As (
pfx2as.rs): Maps IP prefixes to their origin ASes
All processors use a consistent pattern: new() → process_*() → into_*()
- Modular Architecture: Each processor is self-contained in its own module
- Tier-1 Transit Algorithm: Distinguishes between true tier-1 ASes and candidate tier-1 ASes (Zayo 6461, Hurricane Electric 6939) to prevent over-counting downstream ASes
- Processor Pattern: Consistent API across all modules
- SQLite Indexing: Tools to index processed data into SQLite databases
The AS2Rel processor uses a two-tier algorithm to infer provider-customer relationships:
- True Tier-1 ASes (14 networks): Always considered transit providers
- Cogent (174), Lumen (3356), NTT (2914), Verizon (701), etc.
- Candidate Tier-1 ASes: Only transit providers when next hop is tier-1
- AS 6461 (Zayo) - IPv4 and IPv6
- AS 6939 (Hurricane Electric) - IPv6 only
This prevents over-counting downstream ASes for networks that peer extensively but don't sell transit service.
Rust toolchain is required:
cargo install --path .The project builds 5 binaries:
Process a single RIB dump file (outputs all three data types):
peer-stats-single-file --debug http://archive.routeviews.org/route-views.sg/bgpdata/2022.02/RIBS/rib.20220205.1800.bz2Bootstrap historical data collection:
MAX_THREADS=8 peer-stats-bootstrap --output-dir ./data --ts-start 2022-01-01 --ts-end 2022-02-01Index peer statistics into SQLite:
peer-stats-index --db-path ./peer-stats.db --input-dir ./dataIndex AS relationships into SQLite:
as2rel-index --db-path ./as2rel.db --input-dir ./dataIndex prefix-to-AS mappings into SQLite:
pfx2as-index --db-path ./pfx2as.db --input-dir ./datause peer_stats::parse_rib_file;
let (peer_stats, pfx2as, (as2rel_global, as2rel_v4, as2rel_v6)) =
parse_rib_file(
"http://archive.routeviews.org/.../rib.20220205.1800.bz2",
"route-views",
"route-views.sg"
).unwrap();{
"project": "route-views",
"collector": "route-views.sg",
"rib_dump_url": "...",
"peers": {
"2001:de8:4::13:6168:1": {
"asn": 136168,
"ip": "2001:de8:4::13:6168:1",
"num_v4_pfxs": 0,
"num_v6_pfxs": 40,
"num_connected_asns": 4
}
}
}{
"project": "route-views",
"collector": "route-views.sg",
"rib_dump_url": "...",
"as2rel": [
{
"asn1": 174,
"asn2": 13335,
"rel": 1,
"paths_count": 42,
"peers_count": 3
}
]
}{
"project": "route-views",
"collector": "route-views.sg",
"rib_dump_url": "...",
"pfx2as": [
{
"prefix": "1.1.1.0/24",
"asn": 13335,
"count": 5
}
]
}We provide a publicly available dataset at https://data.bgpkit.com.
This work is under MIT license.