-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include io libraries to simplify API; flesh out documentation
- Loading branch information
Showing
12 changed files
with
368 additions
and
610 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,6 +1,6 @@ | ||
[package] | ||
name = "bgpkit-parser" | ||
version = "0.3.0" | ||
version = "0.4.0" | ||
authors = ["Mingwei Zhang <[email protected]>"] | ||
edition = "2021" | ||
readme = "README.md" | ||
|
@@ -25,7 +25,9 @@ log="0.4" | |
env_logger="0.9" | ||
itertools = "0.10.1" | ||
|
||
bzip2="0.4.3" | ||
flate2="1.0.22" | ||
reqwest = { version = "0.11", features = ["json", "blocking", "stream"]} | ||
|
||
[dev-dependencies] | ||
bzip2="0.4" | ||
reqwest = { version = "0.11", features = ["json", "blocking", "stream"] } | ||
bgpkit-broker = "0.3.0" |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use bgpkit_parser::BgpkitParser; | ||
|
||
/// an very simple example that reads a remote BGP data file and print out the message count. | ||
fn main() { | ||
let url = "http://archive.routeviews.org/bgpdata/2021.10/UPDATES/updates.20211001.0000.bz2"; | ||
let count = BgpkitParser::new(url).into_iter().count(); | ||
println!("{}", count); | ||
} |
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,36 +1,18 @@ | ||
use std::io::BufReader; | ||
use bzip2::read::BzDecoder; | ||
use bgpkit_parser::BgpkitParser; | ||
|
||
/// This example shows how to download and process a single BGP archive file with BGPKIT Parser. | ||
/// | ||
/// The dependency needed for this example are: | ||
/// ``` | ||
/// bzip2="0.4" | ||
/// reqwest = { version = "0.11", features = ["json", "blocking", "stream"] } | ||
/// ``` | ||
fn main() { | ||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); | ||
|
||
log::info!("downloading updates file"); | ||
// read updates data into bytes | ||
let data_bytes = reqwest::blocking::get("http://archive.routeviews.org/bgpdata/2021.10/UPDATES/updates.20211001.0000.bz2") | ||
.unwrap().bytes().unwrap().to_vec(); | ||
// create a buffered reader that wraps around a bzip2 decoder | ||
let reader = BufReader::new(BzDecoder::new(&*data_bytes)); | ||
|
||
// create a parser that takes the buffered reader | ||
let parser = BgpkitParser::new(reader); | ||
let parser = BgpkitParser::new("http://archive.routeviews.org/bgpdata/2021.10/UPDATES/updates.20211001.0000.bz2"); | ||
|
||
log::info!("parsing updates file"); | ||
// iterating through the parser. the iterator returns `BgpElem` one at a time. | ||
for elem in parser { | ||
// each BGP announcement contains one AS path, which depending on the path segment's type | ||
// there could be multiple origin ASNs (e.g. AS-Set as the origin) | ||
if let Some(origins) = &elem.origin_asns { | ||
if origins.contains(&13335) { | ||
log::info!("{}", &elem); | ||
} | ||
} | ||
log::info!("{}", &elem); | ||
} | ||
log::info!("done"); | ||
} |
Oops, something went wrong.