-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from bgpkit/develop
Release 0.1.1: `msrv` down to 1.46.0
- Loading branch information
Showing
4 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "ris-live-rs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
version = "0.1.1" | ||
edition = "2018" | ||
authors = ["Mingwei Zhang <[email protected]>"] | ||
readme = "README.md" | ||
license = "MIT" | ||
|
@@ -14,16 +14,18 @@ keywords = ["bgp"] | |
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[package.metadata] | ||
msrv = "1.46.0" | ||
|
||
[dependencies] | ||
|
||
serde={version="1.0", features=["derive"]} | ||
serde_json = "1.0.69" | ||
bgp-models = "0.5.0" | ||
|
||
# cli-tool dependencies | ||
tungstenite="0.16.0" | ||
url = "2.1.0" | ||
clap = "3.0.0-beta.5" | ||
tungstenite="0.12.0" | ||
structopt = "0.3" | ||
|
||
[[bin]] | ||
name="ris-live-reader" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,74 @@ | ||
use tungstenite::{connect, Message}; | ||
use url::Url; | ||
use ris_live_rs::error::ParserRisliveError; | ||
use ris_live_rs::{compose_subscription_message, parse_ris_live_message}; | ||
use clap::Parser; | ||
use structopt::StructOpt; | ||
|
||
const RIS_LIVE_URL_BASE: &str = "ws://ris-live.ripe.net/v1/ws/"; | ||
|
||
/// ris-live-reader is a simple cli tool that can stream BGP data from RIS-Live project with websocket. | ||
#[derive(Parser)] | ||
#[clap(version = "0.1.0", author = "Mingwei Zhang <[email protected]>")] | ||
#[derive(StructOpt, Debug)] | ||
#[structopt(name = "ris-live-reader")] | ||
struct Opts { | ||
|
||
/// client name to identify the stream | ||
#[clap(long, default_value="ris-live-rs")] | ||
#[structopt(long, default_value="ris-live-rs")] | ||
client: String, | ||
|
||
/// Filter by RRC host: e.g. rrc01 | ||
#[clap(long)] | ||
#[structopt(long)] | ||
host: Option<String>, | ||
|
||
/// Only include messages of a given BGP or RIS type: UPDATE, OPEN, NOTIFICATION, KEEPALIVE, or RIS_PEER_STATE | ||
#[clap(long)] | ||
#[structopt(long)] | ||
msg_type: Option<String>, | ||
|
||
/// Only include messages containing a given key | ||
#[clap(long)] | ||
#[structopt(long)] | ||
require: Option<String>, | ||
|
||
/// Only include messages sent by the given BGP peer | ||
#[clap(long)] | ||
#[structopt(long)] | ||
peer: Option<String>, | ||
|
||
/// Filter UPDATE messages by prefixes in announcements or withdrawals | ||
#[clap(long)] | ||
#[structopt(long)] | ||
prefix: Option<String>, | ||
|
||
/// Match prefixes that are more specific (part of) `prefix` | ||
#[clap(long, parse(from_flag = std::ops::Not::not))] | ||
#[structopt(long, parse(from_flag = std::ops::Not::not))] | ||
more_specific: bool, | ||
|
||
/// Match prefixes that are less specific (contain) `prefix` | ||
#[clap(long)] | ||
#[structopt(long)] | ||
less_specific: bool, | ||
|
||
/// ASN or pattern to match against the AS PATH attribute | ||
#[clap(long)] | ||
#[structopt(long)] | ||
path: Option<String>, | ||
|
||
/// Output as JSON objects | ||
#[clap(long)] | ||
#[structopt(long)] | ||
json: bool, | ||
|
||
/// Pretty-print JSON output | ||
#[clap(long)] | ||
#[structopt(long)] | ||
pretty: bool, | ||
|
||
/// Print out raw message without parsing | ||
#[clap(long)] | ||
#[structopt(long)] | ||
raw: bool, | ||
} | ||
|
||
/// 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() { | ||
let opts: Opts = Opts::parse(); | ||
let opts: Opts = Opts::from_args(); | ||
|
||
let url = format!("{}?client={}", RIS_LIVE_URL_BASE, opts.client); | ||
// connect to RIPE RIS Live websocket server | ||
let (mut socket, _response) = | ||
connect(Url::parse(url.as_str()).unwrap()) | ||
connect(url.as_str()) | ||
.expect("Can't connect to RIS Live websocket server"); | ||
|
||
// subscribe to messages from one collector | ||
|