Skip to main content

ExtendedCommunity

Struct ExtendedCommunity 

Source
pub struct ExtendedCommunity(/* private fields */);
Expand description

RFC 4360 Extended Community — 8-byte value stored as u64.

Wire layout: type (1) + sub-type (1) + value (6). Bit 6 of the type byte: 0 = transitive, 1 = non-transitive.

Implementations§

Source§

impl ExtendedCommunity

Source

pub fn new(raw: u64) -> Self

Create from a raw 8-byte value.

Source

pub fn as_u64(self) -> u64

Return the raw 8-byte value.

Source

pub fn type_byte(self) -> u8

High byte — IANA-assigned type.

Source

pub fn subtype(self) -> u8

Second byte — sub-type within the type.

Source

pub fn is_transitive(self) -> bool

Transitive if bit 6 of the type byte is 0.

Source

pub fn value_bytes(self) -> [u8; 6]

Bytes 2-7 of the community value.

Source

pub fn route_target(self) -> Option<(u32, u32)>

Decode as Route Target (sub-type 0x02).

Returns (global_admin, local_admin) as raw u32 values. The interpretation of global_admin depends on the type byte:

  • Type 0x00 (2-octet AS specific): global = ASN (fits u16), local = u32
  • Type 0x01 (IPv4 address specific): global = IPv4 addr as u32, local = u16
  • Type 0x02 (4-octet AS specific): global = ASN (u32), local = u16

Callers that need to distinguish these encodings (e.g. for display as RT:192.0.2.1:100 vs RT:65001:100) must also check type_byte().

Source

pub fn route_origin(self) -> Option<(u32, u32)>

Decode as Route Origin (sub-type 0x03).

Same layout as route_target() — returns raw (global_admin, local_admin) with the same type-byte-dependent interpretation. Check type_byte() to distinguish 2-octet AS, IPv4-address, and 4-octet AS encodings.

Source

pub fn as_bgp_encapsulation(self) -> Option<u16>

Decode as BGP Encapsulation Extended Community (RFC 9012 §4.1, encoded per the widely-deployed RFC 5512 layout: 4-byte reserved + 2-byte Tunnel Type). Type 0x03, subtype 0x0C.

Returns the Tunnel Type code. For VXLAN-EVPN (RFC 8365), the value is 8. Other common values: 7 = NVGRE, 11 = MPLS-over-GRE.

The reserved bytes are intentionally not validated here: RFC 5512 specifies MUST-zero on send, ignored on receive. FRR, GoBGP, Cisco, and Juniper all emit zeros in practice; rejecting non-zero reserves would break interop in the rare case an unknown implementation re-purposes those bytes. Consumers should treat the returned tunnel_type as the semantic signal.

Source

pub fn bgp_encapsulation(tunnel_type: u16) -> Self

Construct a BGP Encapsulation Extended Community (RFC 9012 §4.1).

Writes 4 bytes of reserved zero followed by the 16-bit tunnel type.

Source

pub fn as_mac_mobility(self) -> Option<(bool, u32)>

Decode as MAC Mobility Extended Community (RFC 7432 §7.7). Type 0x06, subtype 0x00.

Returns (sticky, sequence_number). The sticky bit (bit 0 of the flags byte) marks the MAC as non-movable; receivers must not displace a sticky MAC with a higher-sequence non-sticky advertisement.

Source

pub fn mac_mobility(sticky: bool, sequence: u32) -> Self

Construct a MAC Mobility Extended Community (RFC 7432 §7.7).

Source

pub fn as_esi_label(self) -> Option<(bool, u32)>

Decode as ESI Label Extended Community (RFC 7432 §7.5). Type 0x06, subtype 0x01.

Returns (single_active, label). The single-active flag (bit 0 of the flags byte) signals single-active multi-homing mode.

Source

pub fn esi_label(single_active: bool, label: u32) -> Self

Construct an ESI Label Extended Community (RFC 7432 §7.5).

label is a 24-bit MPLS label or VXLAN VNI; high 8 bits are masked.

Source

pub fn as_es_import_rt(self) -> Option<[u8; 6]>

Decode as ES-Import Route Target Extended Community (RFC 7432 §7.6). Type 0x06, subtype 0x02.

Returns the 6-byte MAC address that serves as the import target for Type 4 ES routes.

Source

pub fn es_import_rt(mac: [u8; 6]) -> Self

Construct an ES-Import Route Target Extended Community.

Source

pub fn as_df_election(self) -> Option<DfElectionExtendedCommunity>

Decode as DF Election Extended Community (RFC 8584 §2.2, updated by RFC 9785 §3). Type 0x06, subtype 0x06.

Source

pub fn df_election( algorithm_id: u8, capabilities: u16, preference: Option<u16>, ) -> Self

Construct a DF Election Extended Community (RFC 8584 §2.2, RFC 9785 §3).

algorithm_id is masked to the five-bit DF Alg field. For DefaultModulo and HRW, pass None for preference so the reserved trailing bytes are emitted as zero.

Decode as Link Bandwidth Extended Community (draft-ietf-idr-link-bandwidth): non-transitive two-octet-AS-specific, type 0x40, subtype 0x04. The value carries the 2-octet AS plus the bandwidth as an IEEE-754 single-precision float in bytes per second. Returns (asn, bytes_per_sec).

Construct a Link Bandwidth Extended Community (draft-ietf-idr-link-bandwidth): non-transitive two-octet-AS-specific, type 0x40, subtype 0x04. bytes_per_sec is encoded as an IEEE-754 single-precision float.

Source

pub fn as_router_mac(self) -> Option<[u8; 6]>

Decode as Router MAC Extended Community (RFC 9135 §4.1). Type 0x06, subtype 0x03.

Returns the 6-byte router MAC used for symmetric IRB.

Source

pub fn router_mac(mac: [u8; 6]) -> Self

Construct a Router MAC Extended Community (RFC 9135 §4.1).

Source

pub fn as_default_gateway(self) -> bool

Decode as Default Gateway Extended Community (RFC 4761 §3.2.5 / RFC 7432). Type 0x03, subtype 0x0D. This is a flag-only community: presence is the signal and the 6-byte value field must be all zeros. Malformed advertisements with non-zero value bytes are treated as non-matches rather than silently accepted — downstream policy and validation consumers treat this accessor as semantic truth.

Source

pub fn default_gateway() -> Self

Construct a Default Gateway Extended Community.

Source§

impl ExtendedCommunity

Source

pub fn as_flowspec_action(&self) -> Option<FlowSpecAction>

Try to decode this extended community as a FlowSpec action.

Source

pub fn from_flowspec_action(action: &FlowSpecAction) -> Self

Create an extended community from a FlowSpec action.

Trait Implementations§

Source§

impl Clone for ExtendedCommunity

Source§

fn clone(&self) -> ExtendedCommunity

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ExtendedCommunity

Source§

impl Debug for ExtendedCommunity

Source§

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

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

impl Display for ExtendedCommunity

Source§

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

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

impl Eq for ExtendedCommunity

Source§

impl Hash for ExtendedCommunity

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ExtendedCommunity

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ExtendedCommunity

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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§

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>,

Source§

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>,

Source§

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.