Expand description
§Message Filters
The filter module defines a number of available filters that users can use, and implements the filtering mechanism for BgpElem.
The available filters are:
origin_asn
– origin AS numberprefix
– network prefix and match typepeer_ip
– peer’s IP addresspeer_ips
– peers’ IP addressespeer_asn
– peer’s IP addresstype
– message type (withdraw
orannounce
)ts_start
– start and end unix timestampas_path
– regular expression for AS path stringip_version
– IP version (ipv4
oripv6
)
Filter::new function takes a str
as the filter type and str
as the filter value and returns a
Result of a Filter or a parsing error.
BgpkitParser implements the function add_filter("filter_type", "filter_value")
that takes the parser’s ownership itself
and returns a new parser with specified filter added. See the example below.
§Example
use bgpkit_parser::BgpkitParser;
/// This example shows how to parse a MRT file and filter by prefix.
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
log::info!("downloading updates file");
let parser = BgpkitParser::new("http://archive.routeviews.org/bgpdata/2021.10/UPDATES/updates.20211001.0000.bz2").unwrap()
.add_filter("prefix", "211.98.251.0/24").unwrap()
.add_filter("type", "a").unwrap();
// iterating through the parser. the iterator returns `BgpElem` one at a time.
log::info!("parsing updates file");
for elem in parser {
log::info!("{}", &elem);
}
log::info!("done");
Note, by default, the prefix filtering is for the exact prefix. You can include super-prefixes or
sub-prefixes when fitlering by using "prefix_super"
, "prefix_sub"
, or "prefix_super_sub"
as
the filter type string.
§Note
Currently, only BgpElem implements the filtering capability. Support for MrtRecord will come in later releases.
Enums§
- Filter
- Filter enum: definition o types of filters
- IpVersion
- Prefix
Match Type