BGPKIT Parser
BGPKIT Parser aims to provides the most ergonomic MRT/BGP/BMP message parsing Rust API.
BGPKIT Parser has the following features:
- performant: comparable to C-based implementations like
bgpdump
orbgpreader
. - actively maintained: we consistently introduce feature updates and bug fixes, and support most of the relevant BGP RFCs.
- ergonomic API: a three-line for loop can already get you started.
- battery-included: ready to handle remote or local, bzip2 or gz data files out of the box
Examples
For complete examples, check out the examples folder.
Parsing single MRT file
Let's say we want to print out all the BGP announcements/withdrawal from a single MRT file, either located remotely or locally. Here is an example that does so.
use BgpkitParser;
Yes, it is this simple!
You can even do some more interesting iterator operations that are event shorter. For example, counting the number of announcements/withdrawals in that file:
use BgpkitParser;
and it prints out
total: 255849
Parsing multiple MRT files with BGPKIT Broker
BGPKIT Broker library provides search API for all RouteViews and RIPE RIS MRT data files. Using the
broker's Rust API (bgpkit-broker
), we can easily compile a list of MRT files that we are interested
in for any time period and any data type (update
or rib
). This allows users to gather information without needing to
know about locations of specific data files.
The example below shows a relatively more interesting example that does the following:
- find all BGP archive data created on time 1634693400
- filter to only BGP updates files
- find all announcements originated from AS13335
- print out the total count of the announcements
Parsing Real-time Data Streams
BGPKIT Parser also provides parsing functionalities for real-time data streams, including RIS-Live and BMP/OpenBMP messages. See the examples below and the documentation for more.
Parsing Messages From RIS-Live
Here is an example of handling RIS-Live message streams. After connecting to the websocket server,
we need to subscribe to a specific data stream. In this example, we subscribe to the data stream
from on collector (rrc21
). We can then loop and read messages from the websocket.
use parse_ris_live_message;
use json;
use ;
use Url;
const RIS_LIVE_URL: &str = "ws://ris-live.ripe.net/v1/ws/?client=rust-bgpkit-parser";
/// This is an example of subscribing to RIS-Live's streaming data from one host (`rrc21`).
///
/// For more RIS-Live details, check out their documentation at https://ris-live.ripe.net/manual/
Parsing OpenBMP Messages From RouteViews Kafka Stream
RouteViews provides a real-time Kafka stream of the OpenBMP data received from their collectors. Below is an partial example of how we handle the raw bytes received from the Kafka stream. For full examples, check out the examples folder on GitHub.
let bytes = m.value;
let mut reader = new;
let header = parse_openbmp_header.unwrap;
let bmp_msg = parse_bmp_msg;
match bmp_msg
Data Representation
There are two key data structure to understand for the parsing results:MrtRecord
and BgpElem
.
MrtRecord
: unmodified MRT information representation
The MrtRecord
is the data strcutrue that holds the unmodified, complete information parsed
from the MRT data file. The code definition of the MrtRecord
is defined in the crate bgp-models
(documentation).
MrtRecord
record representation is concise, storage efficient, but often less convenient to use. For example, when
trying to find out specific BGP announcements for certain IP prefix, we often needs to go through nested layers of
internal data structure (NLRI, announced, prefix, or even looking up peer index table for Table Dump V2 format), which
could be irrelevant to what users really want to do.
BgpElem
: per-prefix BGP information, MRT-format-agnostic
To facilitate simpler data analysis of BGP data, we defined a new data structure called BgpElem
in this crate. Each
BgpElem
contains a piece of self-containing BGP information about one single IP prefix.
For example, when a bundled announcement of three prefixes P1, P2, P3 that shares the same AS path is processed, we break
the single record into three different BgpElem
objects, each presenting a prefix.
The main benefit of using BgpElem
is that the analysis can be executed on a per-prefix basis, generic to what the
backend MRT data format (bgp4mp, tabledumpv1, tabledumpv2, etc.). The obvious drawback is that we will have to duplicate
information to save at each elem, that consuming more memory.
Contribution
Issues and pull requests are welcome!
Built with ❤️ by BGPKIT Team
BGPKIT is a small-team start-up that focus on building the best tooling for BGP data in Rust. We have 10 years of experience working with BGP data and believe that our work can enable more companies to start keeping tracks of BGP data on their own turf. Learn more about what services we provide at https://bgpkit.com.