Provides parsing functions for RIS-Live real-time BGP message stream JSON data.
The main parsing function, parse_ris_live_message
converts a JSON-formatted message string into a
vector of BgpElem
s.
```rust use serdejson::json; use tungstenite::{connect, Message}; use url::Url; use rislivers::error::ParserRisliveError; use rislivers::parserislivemessage;
const RISLIVEURL: &str = "ws://ris-live.ripe.net/v1/ws/?client=rust-bgpkit-parser";
/// This is an example of subscribing to RIS-Live's streaming data. /// /// For more RIS-Live details, check out their documentation at https://ris-live.ripe.net/manual/ fn main() { // connect to RIPE RIS Live websocket server let (mut socket, response) = connect(Url::parse(RISLIVE_URL).unwrap()) .expect("Can't connect to RIS Live websocket server");
// subscribe to messages from one collector
let msg = json!({"type": "ris_subscribe", "data": null}).to_string();
socket.write_message(Message::Text(msg)).unwrap();
loop {
let msg = socket.read_message().expect("Error reading message").to_string();
if msg.is_empty() {
continue
}
match parse_ris_live_message(msg.as_str()) {
Ok(elems) => {
for e in elems {
println!("{}", e);
}
}
Err(error) => {
if let ParserRisliveError::ElemEndOfRibPrefix = error {
println!("{:?}", &error);
println!("{}", msg);
continue
}
break;
}
}
}
} ```
ris-live-rs
support filtering message by composing customized
ris-live subscription message. Use the compose_subscription_message
function to create a filtering message.
```rust
pub fn composesubscriptionmessage(
host: Option
// subscribe to messages from one collector let msg = composesubscriptionmessage( opts.host, opts.msgtype, opts.require, opts.peer, opts.prefix, opts.path, opts.morespecific, opts.lessspecific ); println!("{}", &msg); socket.writemessage(Message::Text(msg)).unwrap(); ```
ris-live-reader
ris-live-rs
library also comes with a simple command-line program
that supports filtering and different output formats: ris-live-reader
.
Full command-line options are: ``` ris-live-rs 0.1.0
Mingwei Zhang mingwei@bgpkit.com
ris-live-reader is a simple cli tool that can stream BGP data from RIS-Live project with websocket
USAGE: ris-live-reader [OPTIONS]
OPTIONS:
--client prefix
--more-specific Match prefixes that are more specific (part of) prefix
--msg-type
Install via cargo by:
bash
cargo install ris-live-rs
Or checkout the repo and run:
bash
cargo install --path .
The program ris-live-reader
will be installed to your $CARGO_HOME/bin
(e.g. ~/.cargo/bin
).
bash
docker run --rm -it bgpkit/ris-live-reader --help
1.46.0
BGPKIT is a small-team start-up that focuses 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.