Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ All notable changes to this project will be documented in this file.

### Breaking changes

* **`Afi` and `Safi` gain the EVPN family and `ExtendedCommunity` gains `MacMobility`**: `Afi::L2vpn` (25) and `Safi::Evpn` (70) now parse instead of failing, and the MAC Mobility extended community (type `0x06`, sub-type `0x00`) parses into `ExtendedCommunity::MacMobility { sticky, sequence }` instead of a raw 8-byte blob. `ExtendedCommunity::Raw` now reports the registered type of an undecoded community (`Evpn` for the other EVPN sub-types) rather than `Unknown`. Downstream exhaustive matches on these enums need a new arm.
* **`Afi` and `Safi` gain the EVPN family and `ExtendedCommunity` gains `MacMobility`**: `Afi::L2vpn` (25) and `Safi::Evpn` (70) now parse instead of failing, and the MAC Mobility extended community (type `0x06`, sub-type `0x00`) parses into `ExtendedCommunity::MacMobility { sticky, sequence }` instead of a raw 8-byte blob. `ExtendedCommunity::Raw` now reports the registered type of an undecoded community (`Evpn` for the other EVPN sub-types) rather than `Unknown`. Downstream exhaustive matches on these enums need a new arm. ([#355](https://github.com/bgpkit/bgpkit-parser/pull/355))

### Added

* **EVPN NLRI support** ([RFC 7432](https://datatracker.ietf.org/doc/html/rfc7432), [RFC 9136](https://datatracker.ietf.org/doc/html/rfc9136)): `MP_REACH_NLRI` and `MP_UNREACH_NLRI` for AFI 25 / SAFI 70 decode into `Nlri::evpn_nlris`, one `EvpnNlri` per route with its route distinguisher and a route-type-specific body: type 2 (MAC/IP advertisement: ESI, Ethernet tag, MAC, optional IP, label), type 3 (inclusive multicast), and type 5 (IP prefix). Route types 1 and 4 keep their octets in `EvpnRoutePayload::Raw`, and an EVPN end-of-RIB marker decodes to an empty list. Until now an EVPN BMP feed produced only `AttributeValue::Raw` and no fields at all. The encoder writes the same routes back, so `MrtRecord::try_from(&BmpMessage)` keeps converting EVPN route monitoring messages, and text output renders an `ANNOUNCED (EVPN)` / `WITHDRAWN (EVPN)` section instead of dropping them.
* **MAC Mobility extended community encoder**: `ExtendedCommunity::MacMobility` re-encodes to the 8 wire octets, so a decoded EVPN route survives a decode/encode round trip of its communities.
* **EVPN NLRI support** ([RFC 7432](https://datatracker.ietf.org/doc/html/rfc7432), [RFC 9136](https://datatracker.ietf.org/doc/html/rfc9136)): `MP_REACH_NLRI` and `MP_UNREACH_NLRI` for AFI 25 / SAFI 70 decode into `Nlri::evpn_nlris`, one `EvpnNlri` per route with its route distinguisher and a route-type-specific body: type 2 (MAC/IP advertisement: ESI, Ethernet tag, MAC, optional IP, label), type 3 (inclusive multicast), and type 5 (IP prefix). Route types 1 and 4 keep their octets in `EvpnRoutePayload::Raw`, and an EVPN end-of-RIB marker decodes to an empty list. Until now an EVPN BMP feed produced only `AttributeValue::Raw` and no fields at all. The encoder writes the same routes back, so `MrtRecord::try_from(&BmpMessage)` keeps converting EVPN route monitoring messages, and text output renders an `ANNOUNCED (EVPN)` / `WITHDRAWN (EVPN)` section instead of dropping them. ([#355](https://github.com/bgpkit/bgpkit-parser/pull/355))
* **MAC Mobility extended community encoder**: `ExtendedCommunity::MacMobility` re-encodes to the 8 wire octets, so a decoded EVPN route survives a decode/encode round trip of its communities. ([#355](https://github.com/bgpkit/bgpkit-parser/pull/355))

## v0.23.0 - 2026-10-17

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Construct and serialize BGP/MRT data, including the fallible encoders and the RF
- [real_time_routeviews_kafka_to_mrt.rs](real_time_routeviews_kafka_to_mrt.rs) — Consume RouteViews Kafka BMP messages and archive them into an MRT file for later analysis.
- [bmp_listener.rs](bmp_listener.rs) — Minimal TCP BMP listener that parses incoming BMP Route Monitoring messages and logs them.
- [parse_bmp_mpls.rs](parse_bmp_mpls.rs) — Construct and parse a synthetic BMP Route Monitoring message containing MPLS-labeled NLRI (SAFI 4), demonstrating label stack extraction.
- [evpn_mac_mobility.rs](evpn_mac_mobility.rs) — Decode EVPN (AFI 25 / SAFI 70) routes from a BMP capture: route type 2/3/5, route distinguisher, MAC, VTEP and MAC Mobility sequence. Runs on the committed capture of a real MAC move, where one host claims another's MAC and the two leaves trade sequence numbers.

## Attributes and Metadata

Expand Down
141 changes: 141 additions & 0 deletions examples/evpn_mac_mobility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! Example: decode EVPN routes from a BMP capture.
//!
//! EVPN (AFI 25 / SAFI 70) carries MAC learning in BGP, so the route
//! reflector's BMP feed is the only place where a MAC move is recorded as a
//! route. This example walks a capture and prints one line per EVPN NLRI:
//! route type, route distinguisher, the MAC or prefix it describes, the VTEP
//! that advertised it, and the MAC Mobility sequence number when one is
//! present.
//!
//! The default input is `tests/fixtures/evpn/mac-move.bmp`, captured from the
//! two-leaf FRR fabric in the BGPKIT Labs `evpn-mac-mobility` topology. One host
//! sent frames with another host's MAC address, so both leaves kept
//! re-advertising that MAC with an incremented MAC Mobility sequence number:
//! the same MAC appears from two VTEPs, sequence 1 then 2 then 3 then 4.
//!
//! ## Usage
//!
//! ```sh
//! cargo run --example evpn_mac_mobility
//! cargo run --example evpn_mac_mobility -- /path/to/capture.bmp
//! ```

use bgpkit_parser::models::*;
use bgpkit_parser::parse_bmp_msg;
use bgpkit_parser::parser::bmp::messages::BmpMessageBody;
use bytes::{Buf, Bytes};
use std::error::Error;

const DEFAULT_CAPTURE: &str = "tests/fixtures/evpn/mac-move.bmp";

fn main() -> Result<(), Box<dyn Error>> {
let path = std::env::args()
.nth(1)
.unwrap_or_else(|| DEFAULT_CAPTURE.to_string());
let mut data = Bytes::from(std::fs::read(&path)?);
println!("capture: {path}");

let mut routes = 0usize;

while data.remaining() > 0 {
let message = parse_bmp_msg(&mut data)?;
let BmpMessageBody::RouteMonitoring(monitoring) = &message.message_body else {
continue;
};
let BgpMessage::Update(update) = &monitoring.bgp_message else {
continue;
};
let peer = message
.per_peer_header
.map(|header| header.peer_ip.to_string())
.unwrap_or_else(|| "-".to_string());

for attribute in update.attributes.iter() {
let (nlri, announced) = match attribute {
AttributeValue::MpReachNlri(nlri) => (nlri, true),
AttributeValue::MpUnreachNlri(nlri) => (nlri, false),
_ => continue,
};
let Some(evpn_nlris) = &nlri.evpn_nlris else {
continue;
};

let next_hop = nlri
.next_hop
.map(|next_hop| next_hop.global_addr().to_string())
.unwrap_or_else(|| "-".to_string());
let sequence = mac_mobility_sequence(update);

for route in evpn_nlris {
routes += 1;
println!(
"{} vt={:<15} peer={:<15} rd={:<22} {}{}",
if announced { "ADD " } else { "DEL " },
next_hop,
peer,
route.route_distinguisher,
describe(route),
sequence
.map(|sequence| format!(" mm-seq={sequence}"))
.unwrap_or_default(),
);
}
}
}

println!("{routes} EVPN routes");
Ok(())
}

/// One line per route type: whatever an operator would look at first.
fn describe(route: &EvpnNlri) -> String {
let route_type = u8::from(route.route_type);
match &route.payload {
EvpnRoutePayload::MacIpAdvertisement(body) => format!(
"[{route_type}] mac={} ip={} eth-tag={} label={}",
format_mac(&body.mac),
body.ip
.map(|ip| ip.to_string())
.unwrap_or_else(|| "-".to_string()),
body.ethernet_tag_id,
body.raw_label,
),
EvpnRoutePayload::InclusiveMulticast(body) => format!(
"[{route_type}] originator={} eth-tag={}",
body.originating_router_ip, body.ethernet_tag_id,
),
EvpnRoutePayload::IpPrefix(body) => format!(
"[{route_type}] prefix={} gateway={} label={}",
body.ip_prefix, body.gateway_ip, body.raw_label,
),
EvpnRoutePayload::Raw(octets) => {
format!(
"[{route_type}] {} raw octets (route type not decoded)",
octets.len()
)
}
}
}

fn format_mac(mac: &[u8; 6]) -> String {
mac.iter()
.map(|octet| format!("{octet:02x}"))
.collect::<Vec<_>>()
.join(":")
}

/// The MAC Mobility sequence number carried by the update, if any - RFC 7432 §7.7.
fn mac_mobility_sequence(update: &BgpUpdateMessage) -> Option<u32> {
update
.attributes
.iter()
.find_map(|attribute| match attribute {
AttributeValue::ExtendedCommunities(communities) => {
communities.iter().find_map(|community| match community {
ExtendedCommunity::MacMobility(mobility) => Some(mobility.sequence),
_ => None,
})
}
_ => None,
})
}
Loading