BgpkitCommons

Struct BgpkitCommons 

Source
pub struct BgpkitCommons { /* private fields */ }

Implementations§

Source§

impl BgpkitCommons

Source

pub fn as2rel_lookup( &self, asn1: u32, asn2: u32, ) -> Result<(Vec<As2relBgpkitData>, Vec<As2relBgpkitData>)>

Source§

impl BgpkitCommons

Source

pub fn asinfo_all(&self) -> Result<HashMap<u32, AsInfo>>

Returns a HashMap containing all AS information.

§Returns
  • Ok(HashMap<u32, AsInfo>): A HashMap where the key is the ASN and the value is the corresponding AsInfo.
  • Err: If the asinfo is not loaded.
§Examples
use bgpkit_commons::BgpkitCommons;

let mut bgpkit = BgpkitCommons::new();
bgpkit.load_asinfo(false, false, false, false).unwrap();
let all_asinfo = bgpkit.asinfo_all().unwrap();
Source

pub fn asinfo_get(&self, asn: u32) -> Result<Option<AsInfo>>

Retrieves AS information for a specific ASN.

§Arguments
  • asn - The Autonomous System Number to look up.
§Returns
  • Ok(Some(AsInfo)): The AS information if found.
  • Ok(None): If the ASN is not found in the database.
  • Err: If the asinfo is not loaded.
§Examples
use bgpkit_commons::BgpkitCommons;

let mut bgpkit = BgpkitCommons::new();
bgpkit.load_asinfo(false, false, false, false).unwrap();
let asinfo = bgpkit.asinfo_get(3333).unwrap();
Source

pub fn asinfo_are_siblings(&self, asn1: u32, asn2: u32) -> Result<bool>

Checks if two ASNs are siblings (belong to the same organization).

§Arguments
  • asn1 - The first Autonomous System Number.
  • asn2 - The second Autonomous System Number.
§Returns
  • Ok(bool): True if the ASNs are siblings, false otherwise.
  • Err: If the asinfo is not loaded or not loaded with as2org data.
§Examples
use bgpkit_commons::BgpkitCommons;

let mut bgpkit = BgpkitCommons::new();
bgpkit.load_asinfo(true, false, false, false).unwrap();
let are_siblings = bgpkit.asinfo_are_siblings(3333, 3334).unwrap();
§Note

This function requires the asinfo to be loaded with as2org data.

Source§

impl BgpkitCommons

Source

pub fn bogons_match(&self, s: &str) -> Result<bool>

Source

pub fn bogons_match_prefix(&self, prefix: &str) -> Result<bool>

Source

pub fn bogons_match_asn(&self, asn: u32) -> Result<bool>

Source

pub fn get_bogon_prefixes(&self) -> Result<Vec<BogonPrefix>>

Get all bogon prefixes.

Source

pub fn get_bogon_asns(&self) -> Result<Vec<BogonAsn>>

Get all bogon ASNs.

Source§

impl BgpkitCommons

Source

pub fn country_all(&self) -> Result<Vec<Country>>

Source

pub fn country_by_code(&self, code: &str) -> Result<Option<Country>>

Source

pub fn country_by_name(&self, name: &str) -> Result<Vec<Country>>

Source

pub fn country_by_code3(&self, code: &str) -> Result<Option<Country>>

Source§

impl BgpkitCommons

Source§

impl BgpkitCommons

Source

pub fn rpki_lookup_by_prefix(&self, prefix: &str) -> Result<Vec<Roa>>

Source

pub fn rpki_validate(&self, asn: u32, prefix: &str) -> Result<RpkiValidation>

Source

pub fn rpki_validate_check_expiry( &self, asn: u32, prefix: &str, check_time: Option<NaiveDateTime>, ) -> Result<RpkiValidation>

Source§

impl BgpkitCommons

Source

pub fn new() -> Self

Source

pub fn reload(&mut self) -> Result<()>

Reload all data sources that are already loaded

Source

pub fn loading_status(&self) -> Vec<(&'static str, &'static str)>

Get loading status for all available modules

Source

pub fn load_countries(&mut self) -> Result<()>

Load countries data

Source

pub fn load_rpki(&mut self, date_opt: Option<NaiveDate>) -> Result<()>

Load RPKI data from Cloudflare (real-time) or historical archives

  • If date_opt is None, loads real-time data from Cloudflare
  • If date_opt is Some(date), loads historical data from RIPE NCC by default

For more control over the data source, use load_rpki_historical() instead.

Source

pub fn load_rpki_historical( &mut self, date: NaiveDate, source: HistoricalRpkiSource, ) -> Result<()>

Load RPKI data from a specific historical data source

This allows you to choose between RIPE NCC and RPKIviews for historical data.

§Example
use bgpkit_commons::BgpkitCommons;
use bgpkit_commons::rpki::{HistoricalRpkiSource, RpkiViewsCollector};
use chrono::NaiveDate;

let mut commons = BgpkitCommons::new();
let date = NaiveDate::from_ymd_opt(2024, 1, 4).unwrap();

// Load from RIPE NCC
commons.load_rpki_historical(date, HistoricalRpkiSource::Ripe).unwrap();

// Or load from RPKIviews
let source = HistoricalRpkiSource::RpkiViews(RpkiViewsCollector::KerfuffleNet);
commons.load_rpki_historical(date, source).unwrap();
Source

pub fn load_rpki_from_files( &mut self, urls: &[String], source: HistoricalRpkiSource, date: Option<NaiveDate>, ) -> Result<()>

Load RPKI data from specific file URLs

This allows loading from specific archive files, which is useful when you want to process multiple files or use specific timestamps.

§Arguments
  • urls - A slice of URLs pointing to RPKI data files
  • source - The type of data source (RIPE or RPKIviews) - determines how files are parsed
  • date - Optional date to associate with the loaded data
§Example
use bgpkit_commons::BgpkitCommons;
use bgpkit_commons::rpki::HistoricalRpkiSource;

let mut commons = BgpkitCommons::new();
let urls = vec![
    "https://example.com/rpki-20240104T144128Z.tgz".to_string(),
];
commons.load_rpki_from_files(&urls, HistoricalRpkiSource::RpkiViews(
    bgpkit_commons::rpki::RpkiViewsCollector::KerfuffleNet
), None).unwrap();
Source

pub fn list_rpki_files( &self, date: NaiveDate, source: HistoricalRpkiSource, ) -> Result<Vec<RpkiFile>>

List available RPKI files for a given date from a specific source

§Example
use bgpkit_commons::BgpkitCommons;
use bgpkit_commons::rpki::{HistoricalRpkiSource, RpkiViewsCollector};
use chrono::NaiveDate;

let commons = BgpkitCommons::new();
let date = NaiveDate::from_ymd_opt(2024, 1, 4).unwrap();

// List files from RIPE NCC
let ripe_files = commons.list_rpki_files(date, HistoricalRpkiSource::Ripe).unwrap();

// List files from RPKIviews
let source = HistoricalRpkiSource::RpkiViews(RpkiViewsCollector::KerfuffleNet);
let rpkiviews_files = commons.list_rpki_files(date, source).unwrap();
Source

pub fn load_mrt_collectors(&mut self) -> Result<()>

Load MRT mrt_collectors data

Source

pub fn load_mrt_collector_peers(&mut self) -> Result<()>

Load MRT mrt_collectors data

Source

pub fn load_bogons(&mut self) -> Result<()>

Load bogons data

Source

pub fn load_asinfo( &mut self, load_as2org: bool, load_population: bool, load_hegemony: bool, load_peeringdb: bool, ) -> Result<()>

Load AS name and country data

Source

pub fn load_asinfo_cached(&mut self) -> Result<()>

Source

pub fn asinfo_builder(&self) -> AsInfoBuilder

Returns a builder for loading AS information with specific data sources.

This provides a more ergonomic way to configure which data sources to load compared to the load_asinfo() method with boolean parameters.

§Example
use bgpkit_commons::BgpkitCommons;

let mut commons = BgpkitCommons::new();
let builder = commons.asinfo_builder()
    .with_as2org()
    .with_peeringdb();
commons.load_asinfo_with(builder).unwrap();
Source

pub fn load_asinfo_with(&mut self, builder: AsInfoBuilder) -> Result<()>

Load AS information using a pre-configured builder.

§Example
use bgpkit_commons::BgpkitCommons;

let mut commons = BgpkitCommons::new();
let builder = commons.asinfo_builder()
    .with_as2org()
    .with_hegemony();
commons.load_asinfo_with(builder).unwrap();
Source

pub fn load_as2rel(&mut self) -> Result<()>

Load AS-level relationship data

Trait Implementations§

Source§

impl Default for BgpkitCommons

Source§

fn default() -> BgpkitCommons

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more