Module filter

Module filter 

Source
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 number
  • prefix – network prefix and match type
  • peer_ip – peer’s IP address
  • peer_ips – peers’ IP addresses
  • peer_asn – peer’s IP address
  • type – message type (withdraw or announce)
  • ts_start – start and end unix timestamp
  • as_path – regular expression for AS path string
  • ip_version – IP version (ipv4 or ipv6)

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
PrefixMatchType

Traits§

Filterable