Module bgpkit_parser::parser::filter[][src]

Expand description

Message Filters

The filters package defines a number of available filters that users can utilize, and implements the filtering mechanism for BgpElem.

The available filters are (filter_type (FilterType) – definition):

  • origin_asn (OriginAsn(u32)) – origin AS number
  • prefix(_super, _sub, _super_sub) (Prefix(IpNetwork, PrefixMatchType)) – network prefix and match type
  • peer_ip (PeerIp(IpAddr)) – peer’s IP address
  • peer_asn (PeerAsn(u32)) – peer’s IP address
  • type (Type(ElemType)) – message type (withdraw or announce)
  • ts_start (TsStart(f64)) and ts_end (TsEnd(f64)) – start and end unix timestamp
  • as_path (AsPath(Regex)) – regular expression for AS path string

Filter::new function takes a str for filter type and str for filter value and returns a Result of a Filter or a parsing error.

[BgpkitParser] also 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.

Example

use bgpkit_parser::BgpkitParser;

/// This example shows how to parse a MRT file and filter by prefix.
fn main() {
    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();

    // 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 enum: definition o types of filters

Traits