Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1,173 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alt Text


CI Publish Rust 1.88+ License: MIT codecov

A BGP implementation in Rust. Usable as a standalone daemon or embedded directly into an application. It is under active development; see PRODUCTION_READINESS.md before deploying it.


BGP in 90 seconds

(Skip this if you already know BGP.)

The internet is not one network — it is tens of thousands of independent networks stitched together. Each network is called an Autonomous System (AS): a collection of IP prefixes under common administrative control. Your ISP is an AS. Google is an AS.

BGP (Border Gateway Protocol) is how these ASes tell each other what prefixes they can reach. It is the routing protocol of the public internet and has been since the early 1990s. BGP-4 is defined in RFC 4271.

BGP is a path vector protocol — every route advertisement carries the full sequence of autonomous systems it has passed through. That sequence is the AS path. When you receive a route, the AS path tells you: "to reach this prefix, packets will travel through AS 65001, then 65002, then 65003." If your own AS number appears in the path, the route has looped back — you reject it.

eBGP (external) is the session between two routers in different ASes. This is what ISPs use to exchange routes.

iBGP (internal) is the session between two routers in the same AS. Every BGP router inside a network must have the same view of the external routing table.

The three-table RIB model is how a BGP router organises what it knows:

  • Adj-RIB-In — one table per peer, routes exactly as received, before any filtering
  • Loc-RIB — the decision table; import policy filters here, best-path picks a winner
  • Adj-RIB-Out — one table per peer, routes after export policy, ready to advertise

Import policy decides which routes from a peer enter Loc-RIB. Export policy decides which Loc-RIB routes get advertised to each peer. pathvector defaults to reject-by-default for eBGP peers (RFC 8212) — you must explicitly accept routes.


Quick start

Prerequisites: Rust ≥ 1.88 and protoc ≥ 3 (brew install protobuf / apt install protobuf-compiler).

# config.toml — minimal eBGP peer config
[daemon]
local_as = 65002
bgp_id   = "10.0.0.2"   # must be a non-loopback address on this machine
# bgp_port = 1179       # on Linux without CAP_NET_BIND_SERVICE: the daemon
#                       # does not start if it cannot listen (default 179)

[[peers]]
address        = "10.0.0.1"
remote_as      = 65001
import_default = "accept"   # opt in: accept routes from this peer
export_default = "accept"   # opt in: advertise our routes to this peer
# Build and run the daemon
cargo build --release -p pathvectord
./target/release/pathvectord config.toml

# In another terminal — inspect peers and routes
cargo run -p pathvector -- peer list
cargo run -p pathvector -- route list
cargo run -p pathvector -- dashboard        # live ratatui TUI

⚠️ Security: the gRPC management API listens on 127.0.0.1 only, without authentication: any local process that can connect can add/remove peers and originate/withdraw routes. To reach it from another host, configure mutual TLS as described in Securing the management API. See PRODUCTION_READINESS.md before any real deployment.

See pathvectord/README.md for the full configuration reference, gRPC API, and GoBGP/BIRD interop guide.


Performance

All numbers on Apple M2 Max, release profile.

MRT replay — real internet table

Replaying a RIPE RIS full-table MRT dump (latest-bview.gz, 1.13M IPv4 prefixes) against a live pathvectord over a loopback BGP TCP session.

Metric Result Context
Prefixes announced 1,133,510 Full internet routing table
Announcement time 2.20 s Sender-side wall-clock to build and write every UPDATE
Announcement throughput 514,287 prefixes/sec The replayer's UPDATE construction plus transmission throughput
Unique path-attribute sets 168,840 The replayer packs prefixes that share a set into the same UPDATE
RIB convergence time 2.88 s From the end of the announcement until the route count stops changing
Routes accepted into Loc-RIB 1,133,415 / 1,133,510 95 rejected: MRT records multiple peer views per prefix
Total (announce + converge) 5.09 s End-to-end benchmark time

These figures measure pathvectord only. No other daemon has been run through this replay, so they are not a comparison.

To reproduce:

curl -O https://data.ris.ripe.net/rrc00/latest-bview.gz
just mrt ./latest-bview.gz

Head-to-head vs GoBGP — synthetic stress test

just stress runs both daemons (debug profile) on the same host with identical workloads. just stress-release runs both daemons (optimized profile) on the same host with identical workloads — use this for numbers worth recording.

Routes are injected through each daemon's gRPC API, not over a BGP session, and every route carries the same attributes. The results say nothing about wire-level convergence.

Time to add routes (lower is better, just stress-release):

Each step adds only the routes needed to reach the next table size, so compare times against the number of routes added, not the table size.

Table size afterwards Routes added pathvectord GoBGP Ratio
10k 10k 0.03 s 0.05 s 1.7× faster
100k 90k 0.16 s 0.36 s 2.3× faster
250k 150k 0.27 s 0.59 s 2.2× faster
500k 250k 0.46 s 0.93 s 2.0× faster
750k 250k 0.42 s 0.90 s 2.1× faster
900k 150k 0.27 s 0.54 s 2.0× faster

Peak RSS (lower is better, just stress-release):

RSS (resident set size) is the physical RAM the process actually occupies at a given moment.

Table size pathvectord GoBGP Ratio
10k 15.6 MB 51.1 MB 3.3× less
100k 48.8 MB 122.0 MB 2.5× less
250k 144.5 MB 252.9 MB 1.7× less
500k 279.1 MB 468.7 MB 1.7× less
750k 313.5 MB 691.0 MB 2.2× less
900k 334.2 MB 823.6 MB 2.5× less

Per-route cost at 900k: 0.37 KB (pathvectord) vs 0.91 KB (GoBGP). Because every synthetic route has identical attributes, this is a best case for attribute interning; a real table will cost more per route.

The numbers above are from just stress-release. To reproduce:

just stress          # debug build — fast to compile, slower numbers
just stress-release  # optimized build — numbers worth recording

Allocator

pathvectord and all criterion bench binaries use jemalloc as the global allocator via tikv-jemallocator.

BGP control-plane work is allocation-heavy: every route update clones AS paths, community vectors, and NLRI structs. jemalloc's thread-local magazine caches and aggressive memory-return behavior reduce fragmentation compared to the system allocator (glibc malloc on Linux, libmalloc on macOS), which matters for a long-running daemon processing millions of route events.

Measured improvement vs system allocator on M2 Max (criterion, release profile):

Benchmark System alloc jemalloc Delta
loc_rib_insert/10k 610 ns 459 ns −25%
loc_rib_insert/100k 615 ns 465 ns −24%
loc_rib_insert/500k 1.94 µs 1.56 µs −20%
outbound_pipeline/minimal/1 274 ns 174 ns −37%
outbound_pipeline/dense/1 441 ns 258 ns −41%
outbound_pipeline/minimal/10 1.35 µs 917 ns −32%
outbound_pipeline/dense/10 2.61 µs 1.31 µs −50%
outbound_pipeline/minimal/50 6.70 µs 4.62 µs −31%
outbound_pipeline/dense/50 13.12 µs 6.17 µs −53%
select_best/2 158 ns 97 ns −39%
select_best/10 505 ns 359 ns −29%
select_best/100 2.66 µs 2.42 µs −9%

The outbound pipeline benefits most because each peer advertisement clones the full attribute set — more allocations per iteration means more leverage from a faster allocator. select_best/100 is the floor case: at 100 candidates the comparison work dominates and allocator choice matters less.


Crate family

Each layer is a separate crate, so a library user can take only the pieces they need. None of them is on crates.io yet.

Crate Description Start here if you want to…
pathvector-credentials Validated, redacting secret types (TCP MD5 password) Handle BGP session secrets safely
pathvector-types AS numbers, AS paths, communities, NLRI, path attributes Understand BGP data structures
pathvector-policy Route policy engine: conditions, actions, term evaluation Write or test BGP route policies
pathvector-rib Adj-RIB-In, Loc-RIB, Adj-RIB-Out, best-path selection Understand route decision logic
pathvector-session BGP FSM, TCP transport, message codec Embed BGP session handling in an app
pathvector-sys Linux FIB (rtnetlink) and TCP MD5SIG Understand kernel integration
pathvector-bmp BMP receiver (RFC 7854) — planned Monitor a router's routing table passively
pathvector-client Typed async Rust client for the gRPC management API Control the daemon from Rust code
pathvectord BGP daemon: TOML config, gRPC management API Run a BGP router
pathvector CLI management tool (peer, route, policy, dashboard) Inspect a running daemon

Dependency graph (compile-time):

pathvector-types
├── pathvector-policy
│   └── pathvector-rib
│       └── pathvectord ──── gRPC (runtime) ──── pathvector-client ──── pathvector (CLI)
└── pathvector-session
    └── pathvectord
pathvector-sys
└── pathvectord

pathvector-credentials
├── pathvector-sys
├── pathvector-client
└── pathvectord

Reading guide

I want to… Read
Run the daemon and configure peers pathvectord/README.md
Use the CLI to inspect peers and routes pathvector/README.md
Control the daemon from Rust code pathvector-client/README.md
Understand BGP session and wire format pathvector-session/README.md
Understand the three-table RIB and best-path pathvector-rib/README.md
Write or test a route policy pathvector-policy/README.md
Understand BGP types (ASN, community, NLRI) pathvector-types/README.md
Understand Linux FIB / TCP MD5 integration pathvector-sys/README.md
Benchmark with a real internet table pathvector-mrt/README.md
Contribute code CONTRIBUTING.md
Understand the test strategy TESTING.md
Assess production deployment readiness PRODUCTION_READINESS.md
Review known gaps and planned work TODO.md

Docker

docker pull ghcr.io/dbrucknr/pathvector:latest

To peer pathvectord with GoBGP in Docker, save this as Dockerfile.gobgp:

FROM alpine

RUN wget -q https://github.com/osrg/gobgp/releases/download/v4.6.0/gobgp_4.6.0_linux_amd64.tar.gz \
    && tar xf gobgp_4.6.0_linux_amd64.tar.gz \
    && rm gobgp_4.6.0_linux_amd64.tar.gz

EXPOSE 179 50051

CMD ["./gobgpd", "--log-level=info", "--config-file=/gobgp.conf"]

This Dockerfile hardcodes linux_amd64. On Apple Silicon, Docker Desktop runs Linux/amd64 under emulation by default, so this works — but it will be slower than a native arm64 build.

Then a docker-compose.yml that wires them together:

services:
  pathvectord:
    image: ghcr.io/dbrucknr/pathvector:latest
    volumes:
      - ./config.toml:/etc/pathvectord/config.toml:ro
    command: ["/etc/pathvectord/config.toml"]
    ports:
      - "127.0.0.1:51200:51200"   # gRPC management API, host loopback only
    cap_add:
      - NET_ADMIN       # required for kernel route installation (RTPROT_BGP)
    networks:
      - bgp
    depends_on:
      - gobgp

  gobgp:
    build:
      context: .
      dockerfile: Dockerfile.gobgp
    volumes:
      - ./gobgp.conf:/gobgp.conf:ro
    networks:
      - bgp

networks:
  bgp:
    driver: bridge

With a minimal gobgp.conf:

[global.config]
  as        = 65001
  router-id = "1.0.0.1"

[[neighbors]]
  [neighbors.config]
    neighbor-address = "pathvectord"   # Docker DNS resolves the service name
    peer-as          = 65002
  [neighbors.transport.config]
    passive-mode = true

And config.toml for pathvectord pointing at the GoBGP container:

[daemon]
local_as  = 65002
bgp_id    = "10.0.0.2"
grpc_port = 51200
# Needed for the published port: the default is loopback inside the container.
# Unauthenticated, so for a throwaway lab only; otherwise use mutual TLS
# (pathvectord/README.md, "Securing the management API").
management = { address = "0.0.0.0", allow_insecure = true }

[[peers]]
address        = "gobgp"   # Docker DNS resolves the service name
remote_as      = 65001
import_default = "accept"
export_default = "accept"

NET_ADMIN is only needed for FIB (kernel routing table) updates. Omit it if you are using pathvectord purely as a route collector or policy engine.


Testing

The test suite combines seven layers: unit tests, compiled documentation examples, property-based tests (proptest), fuzz targets on the codec decode path, ratatui snapshot tests for the TUI dashboard, Docker-based end-to-end tests against a real GoBGP peer, and dependency-inversion tests that exercise every CLI subcommand through MockDaemonClient without a live daemon.

just ci          # unit + property + doc tests, clippy, fmt, MSRV — no Docker required
just e2e         # Docker-based end-to-end suite against a real GoBGP peer
just lint-linux  # run clippy inside a Linux container (catches macOS blind spots)

See TESTING.md for the full description of each layer.


Use cases

Full BGP daemon — run pathvectord on a Linux server and peer with upstream providers or route reflectors.

Embedded BGP speaker — link pathvector-session and pathvector-types directly into an application. Useful for load balancers advertising VIPs, or Kubernetes nodes announcing pod CIDRs.

BGP monitoring — deploy pathvector-bmp (planned) as a standalone BMP collector to receive and inspect route updates from existing routers without participating in routing.

Policy testing — use pathvector-policy in isolation to validate and unit-test BGP route policies before deploying them to production.


Ecosystem

pathvector builds on two standalone foundation crates:

  • ipnetx — set algebra on IP address space (union, intersection, difference)
  • routemap — in-memory longest-prefix-match table via stride-4 treebitmap

Both are independently published and have no dependency on pathvector.


Status

Active development. Crates are not yet published to crates.io.

Crate Status Notes
pathvector-types Stable Newtypes, AS path, communities, NLRI, all path attributes
pathvector-policy Stable Prefix-list, community, AS-path, local-pref, MED conditions and actions
pathvector-rib Stable Full three-table RIB; best-path steps 2–7, 9–10; LPM forwarding queries
pathvector-session Stable Full BGP FSM; all five message types; 4-byte ASN; GoBGP-validated
pathvector-client Stable Typed async Rust client wrapping all gRPC services
pathvectord Active Full BGP speaker; gRPC management API; dynamic peer add/remove; GoBGP-validated
pathvector Active CLI: peer/route/policy/origination subcommands; live ratatui dashboard
pathvector-bmp Planned BMP receiver for passive route monitoring

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages