Struct bgpkit_parser::models::elem::BgpElem

source ·
pub struct BgpElem {
Show 18 fields pub timestamp: f64, pub elem_type: ElemType, pub peer_ip: IpAddr, pub peer_asn: Asn, pub prefix: NetworkPrefix, pub next_hop: Option<IpAddr>, pub as_path: Option<AsPath>, pub origin_asns: Option<Vec<Asn>>, pub origin: Option<Origin>, pub local_pref: Option<u32>, pub med: Option<u32>, pub communities: Option<Vec<MetaCommunity>>, pub atomic: bool, pub aggr_asn: Option<Asn>, pub aggr_ip: Option<BgpIdentifier>, pub only_to_customer: Option<Asn>, pub unknown: Option<Vec<AttrRaw>>, pub deprecated: Option<Vec<AttrRaw>>,
}
Expand description

BgpElem represents a per-prefix BGP element.

This struct contains information about an announced/withdrawn prefix.

Fields:

  • timestamp: The time when the BGP element was received.
  • elem_type: The type of BGP element.
  • peer_ip: The IP address of the BGP peer.
  • peer_asn: The ASN of the BGP peer.
  • prefix: The network prefix.
  • next_hop: The next hop IP address.
  • as_path: The AS path.
  • origin_asns: The list of origin ASNs.
  • origin: The origin attribute, i.e. IGP, EGP, or INCOMPLETE.
  • local_pref: The local preference value.
  • med: The multi-exit discriminator value.
  • communities: The list of BGP communities.
  • atomic: Flag indicating if the announcement is atomic.
  • aggr_asn: The aggregated ASN.
  • aggr_ip: The aggregated IP address.
  • only_to_customer: The AS number to which the prefix is only announced.
  • unknown: Unknown attributes formatted as (TYPE, RAW_BYTES).
  • deprecated: Deprecated attributes formatted as (TYPE, RAW_BYTES).

Note: Constructing BGP elements consumes more memory due to duplicate information shared between multiple elements of one MRT record.

Fields§

§timestamp: f64

The timestamp of the item in floating-point format.

§elem_type: ElemType

The element type of an item.

§peer_ip: IpAddr

The IP address of the peer associated with the item.

§peer_asn: Asn

The peer ASN (Autonomous System Number) of the item.

§prefix: NetworkPrefix

The network prefix of the item.

§next_hop: Option<IpAddr>

The next hop IP address for the item, if available.

§as_path: Option<AsPath>

The optional path representation of the item.

This field is of type Option<AsPath>, which means it can either contain a value of type AsPath or be None.

§origin_asns: Option<Vec<Asn>>

The origin ASNs associated with the prefix, if available.

§Remarks

An Option type is used to indicate that the origin_asns field may or may not have a value. If it has a value, it will be a Vec (vector) of Asn objects representing the ASNs. If it does not have a value, it will be None.

§origin: Option<Origin>

The origin of the item (IGP, EGP, INCOMPLETE), if known. Can be None if the origin is not available.

§local_pref: Option<u32>

The local preference of the item, if available, represented as an option of unsigned 32-bit integer.

§med: Option<u32>

The number of medical items in an option format.

§communities: Option<Vec<MetaCommunity>>

A vector of optional MetaCommunity values.

§Remarks

MetaCommunity represents a community metadata. The Option type indicates that the vector can be empty or contain MetaCommunity values. When the Option is Some, it means the vector is not empty and contains MetaCommunity values. When the Option is None, it means the vector is empty.

§atomic: bool

Indicates whether the item is atomic aggreagte or not.

§aggr_asn: Option<Asn>

The aggregated ASN of the item, represented as an optional Asn type.

§aggr_ip: Option<BgpIdentifier>

The aggregated IP address of the item, represented as an optional BgpIdentifier, i.e. Ipv4Addr.

§only_to_customer: Option<Asn>§unknown: Option<Vec<AttrRaw>>

unknown attributes formatted as (TYPE, RAW_BYTES)

§deprecated: Option<Vec<AttrRaw>>

deprecated attributes formatted as (TYPE, RAW_BYTES)

Implementations§

source§

impl BgpElem

source

pub fn is_announcement(&self) -> bool

Returns true if the element is an announcement.

Most of the time, users do not really need to get the type out, only needs to know if it is an announcement or a withdrawal.

source

pub fn get_origin_asn_opt(&self) -> Option<u32>

Returns the origin AS number as u32. Returns None if the origin AS number is not present or it’s a AS set.

source

pub fn get_psv_header() -> String

Returns the PSV header as a string.

The PSV header is a pipe-separated string that represents the fields present in PSV (Prefix Statement Format) records. PSV records are used to describe BGP (Border Gateway Protocol) routing information.

§Example
use bgpkit_parser::BgpElem;

let header = BgpElem::get_psv_header();
assert_eq!(header, "type|timestamp|peer_ip|peer_asn|prefix|as_path|origin_asns|origin|next_hop|local_pref|med|communities|atomic|aggr_asn|aggr_ip|only_to_customer");
source

pub fn to_psv(&self) -> String

Converts the struct fields into a pipe-separated values (PSV) formatted string.

§Returns

Returns a String representing the struct fields in PSV format.

§Example
use crate::bgpkit_parser::BgpElem;

let psv_string = BgpElem::default().to_psv();

println!("{}", psv_string);

Trait Implementations§

source§

impl Clone for BgpElem

source§

fn clone(&self) -> BgpElem

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BgpElem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for BgpElem

source§

fn default() -> Self

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

impl Display for BgpElem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Filterable for BgpElem

source§

fn match_filter(&self, filter: &Filter) -> bool

source§

fn match_filters(&self, filters: &[Filter]) -> bool

source§

impl From<&BgpElem> for Attributes

source§

fn from(value: &BgpElem) -> Self

Converts to this type from the input type.
source§

impl From<&BgpElem> for BgpUpdateMessage

source§

fn from(elem: &BgpElem) -> Self

Converts to this type from the input type.
source§

impl Ord for BgpElem

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for BgpElem

source§

fn eq(&self, other: &BgpElem) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for BgpElem

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for BgpElem

source§

impl StructuralPartialEq for BgpElem

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

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
source§

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

source§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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