Skip to content

feat: decode EVPN NLRI and the MAC Mobility extended community - #355

Merged
digizeph merged 5 commits into
mainfrom
feat/evpn-nlri
Oct 28, 2026
Merged

digizeph merged 5 commits into
mainfrom
feat/evpn-nlri

Conversation

@digizeph

Copy link
Copy Markdown
Member

EVPN (AFI 25 / SAFI 70) used to land in AttributeValue::Raw, so a BMP feed from an EVPN route reflector produced no fields at all: no route, no MAC, no VTEP. This adds the family and the semantics.

What changes

  • Afi::L2vpn (25) and Safi::Evpn (70).
  • Nlri::evpn_nlris, one EvpnNlri per route with its route type, route distinguisher, and a typed body for route 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 as EvpnRoutePayload::Raw.
  • ExtendedCommunity::MacMobility { sticky, sequence } for type 0x06 / sub-type 0x00, with its encoder. Other EVPN sub-types stay raw, and ExtendedCommunity::Raw now reports the registered type (Evpn) instead of Unknown.

A Type-2 route is how a fabric distributes a MAC address, and a MAC move is an explicit BGP event carrying a sequence number. That makes the route reflector the only place where a MAC mobility record exists, and BMP the only way to get it out: public MRT archives never carry the family.

Decisions a reviewer may want to weigh in on

  • Afi, Safi and ExtendedCommunity gain variants, so downstream exhaustive matches need a new arm. That is the cost of the family being representable at all; the alternative was a separate parallel type.
  • EVPN end-of-RIB decodes to evpn_nlris: Some(vec![]). An MP_UNREACH carrying the family and no NLRI is exactly what the wire says, so it stays distinguishable from a family that was not monitored.
  • Encoding is refused, not approximated. encode_to returns EncodingError::Unencodable for EVPN NLRI rather than writing an update whose NLRI a receiver would read as an empty prefix list. Decode-only is the scope here; the encoder can follow once something needs it.
  • The type-5 prefix family follows from the prefix length. RFC 9136 does not signal it separately, so a length above 32 means IPv6 and the gateway address length is validated against that; a mismatch is a parse error rather than a guess.

Evidence

tests/evpn.rs decodes a capture from a real fabric: FRR 10.7.1, two leaves and a route reflector, VXLAN VNI 100, exported with bmp monitor l2vpn evpn post-policy. One host starts sending frames with another host's MAC, and both leaves re-advertise it with MAC Mobility sequence 1, then 2, 3 and 4, each round preceded by a withdrawal of the previous claim, with the originator alternating between the two VTEPs. Every announcement names its own leaf as next hop and route distinguisher, which is what a consumer needs to tell the two claimants apart.

The capture is committed as tests/fixtures/evpn/mac-move.bmp (2881 bytes), so the test is a real-device fixture rather than hand-built bytes.

Closes #354

EVPN (AFI 25 / SAFI 70) used to land in `AttributeValue::Raw`, so a BMP feed
from an EVPN route reflector produced no usable fields at all. This adds the
family and the semantics a consumer needs to follow a MAC move:

- `Afi::L2vpn` (25) and `Safi::Evpn` (70).
- `Nlri::evpn_nlris` with one `EvpnNlri` per route: route type, route
  distinguisher, and a typed body for route type 2 (MAC/IP advertisement:
  ESI, Ethernet tag, MAC, optional IP, label), type 3 (inclusive multicast)
  and type 5 (IP prefix). Types 1 and 4 keep their octets as
  `EvpnRoutePayload::Raw`; an EVPN end-of-RIB marker decodes to an empty list.
- `ExtendedCommunity::MacMobility` for type 0x06 / sub-type 0x00, with its
  encoder, so a route survives a decode/encode round trip of its communities.
  Other EVPN sub-types stay raw, and `Raw` now reports the registered type
  instead of `Unknown`.
- The encoder refuses EVPN NLRI instead of writing an empty prefix list.

Checked against a capture from a real fabric (BGPKIT Labs topologies/
evpn-mac-mobility, FRR 10.7.1, two leaves and a route reflector): one host
sending frames with another host's MAC makes both leaves re-advertise it with
MAC Mobility sequence 1, 2, 3 and 4, each announcement naming its own VTEP as
next hop and route distinguisher. The capture is the test fixture and is
committed with the test.

Closes #354
Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:41
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.21942% with 131 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.02%. Comparing base (061b6b2) to head (4c4fe94).

Files with missing lines Patch % Lines
src/parser/bgp/attributes/attr_14_15_nlri.rs 87.69% 80 Missing ⚠️
src/models/bgp/evpn.rs 0.00% 16 Missing ⚠️
src/models/bgp/community.rs 30.00% 14 Missing ⚠️
src/render/text.rs 91.46% 7 Missing ⚠️
src/parser/mrt/messages/bgp4mp.rs 95.71% 6 Missing ⚠️
src/models/bgp/attributes/nlri.rs 91.30% 4 Missing ⚠️
.../bgp/attributes/attr_16_25_extended_communities.rs 94.64% 3 Missing ⚠️
src/parser/utils.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
- Coverage   92.16%   92.02%   -0.14%     
==========================================
  Files          96       97       +1     
  Lines       23661    24759    +1098     
==========================================
+ Hits        21807    22785     +978     
- Misses       1854     1974     +120     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical EVPN parsing and withdrawal-handling defects can crash consumers or misinterpret routes, and the committed WASM bindings are stale.

7 open issues
What changed in this PR

Adds typed EVPN decoding to the existing BGP/BMP parser, making MAC advertisements and mobility events available through the Rust models.

Changes:

  • Adds EVPN family identifiers and route models, with decoding for route types 2, 3 and 5.
  • Decodes and encodes MAC Mobility extended communities while explicitly refusing EVPN NLRI encoding.
  • Adds capture-based integration tests and updates existing fixtures and documentation.
File Description
tests/​test_wasm_type_fixtures.rs Initializes the new NLRI field in fixtures.
tests/​test_encoding_errors.rs Updates NLRI construction for encoding tests.
tests/​evpn.rs Tests fabric announcements, mobility events and withdrawals.
src/​wasm/​test/​fixtures/​ris_live_raw_full.json Adds the serialized EVPN field.
src/​wasm/​test/​fixtures/​attribute_values.json Updates serialized NLRI fixtures.
src/​render/​text.rs Updates renderer test inputs.
src/​parser/​utils.rs Handles L2VPN in address-family matches.
src/​parser/​mrt/​messages/​table_dump.rs Adds L2VPN placeholder handling.
src/​parser/​mrt/​messages/​bgp4mp.rs Rejects L2VPN in BGP4MP envelopes.
src/​parser/​iters/​route.rs Extends the unsupported table-dump family arm.
src/​parser/​bmp/​messages/​peer_up_notification.rs Handles L2VPN in local-address matching.
src/​parser/​bmp/​messages/​headers.rs Handles L2VPN in peer-address matching.
src/​parser/​bgp/​messages.rs Updates fixtures and the unknown-family test.
src/​parser/​bgp/​attributes/​attr_36_domain_path.rs Updates comments about EVPN support.
src/​parser/​bgp/​attributes/​attr_16_25_extended_communities.rs Adds MAC Mobility parsing, encoding and tests.
src/​parser/​bgp/​attributes/​attr_14_15_nlri.rs Adds EVPN decoding, encoding refusal and unit tests.
src/​models/​network/​afi.rs Defines L2VPN and EVPN identifiers.
src/​models/​bgp/​mod.rs Exports EVPN models.
src/​models/​bgp/​evpn.rs Defines typed EVPN routes and payloads.
src/​models/​bgp/​community.rs Models and formats MAC Mobility communities.
src/​models/​bgp/​attributes/​nlri.rs Adds EVPN storage, constructors and family detection.
src/​lib.rs Documents EVPN support.
CHANGELOG.md Records functionality and breaking enum changes.

Review effort: Balanced

Comment thread src/models/bgp/attributes/nlri.rs Resolved
- Reject address-family combinations that mix L2VPN or EVPN with another
  family. AFI 1 with SAFI 70 was reaching the IP-prefix parser and becoming an
  IPv4 default-route withdrawal instead of staying raw.
- Parse the RFC 9136 type-5 layout: a 10-octet ESI before the Ethernet tag, and
  full-width 4 or 16-octet prefix and gateway fields. The family comes from the
  NLRI length (34 or 58), so an IPv6 prefix of /32 or shorter decodes, and the
  ESI is exposed on `IpPrefixRoute`.
- Bound the MAC read before copying. A body that declares MAC length 48 and
  ends there passed the fixed-field check and then panicked in `copy_to_slice`;
  it is a parse error now.
- Keep the optional Label2 of a MAC/IP advertisement (IP-VRF forwarding) and the
  ADD-PATH path identifier on each `EvpnNlri`, instead of discarding both.
- Fix `is_end_of_rib`: an EVPN withdrawal carries its routes in `evpn_nlris`, so
  an empty `prefixes` no longer reads as an end-of-RIB marker.
- Regenerate the WASM TypeScript bindings for the new family and community.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues remain in EVPN ADD-PATH handling, label interpretation, BMP-to-MRT conversion, route validation, and text rendering, along with an outdated README.

4 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Reject trailing bytes in type-3 EVPN route bodies

src/​parser/​bgp/​attributes/​attr_14_15_nlri.rs:308

Unlike the type-2 and type-5 parsers, this accepts and silently discards trailing bytes in the route body. A type-3 NLRI with a valid IP followed by extra octets is therefore reported as a valid typed route with different wire contents; reject it so the attribute is retained raw instead.

Low severity Regenerate README to keep release synchronization check passing

src/​lib.rs:863

Please regenerate and commit README.md with cargo readme > README.md. It still goes directly from “Advanced Features” to FlowSpec, so the synchronization check in .github/workflows/release.yml:74 will fail for releases containing this change.

7 resolved since last review

Review effort: Balanced

Comment thread src/models/bgp/attributes/nlri.rs Resolved
…e does

Second review round on the EVPN decoding.

- Text output gains an `ANNOUNCED (EVPN)` / `WITHDRAWN (EVPN)` section with one
  line per route (type, RD, MAC or prefix, label, path id). Before this an EVPN
  update rendered no route at all, only the attribute summary line.
- The encoder writes EVPN NLRI instead of refusing them, so
  `MrtRecord::try_from(&BmpMessage)` converts EVPN route monitoring messages
  again; it re-encodes the parsed update, and the refusal broke that path.
  Routes round-trip byte for byte, ADD-PATH identifiers included, and a path
  identifier without ADD-PATH is an error rather than a silent drop.
- The label fields are `raw_label` / `raw_label2`: the 24-bit wire value is a
  VNI in a VXLAN fabric and an MPLS label with TC/S/TTL in the low bits
  elsewhere. `mpls_label()` gives the label interpretation without shifting a
  VNI.

Declined: threading ADD-PATH state through the BMP entry points. Route
monitoring frames an Adj-RIB-In message, and neither RFC 7854's per-peer header
nor this crate's `parse_bmp_msg` carries the session's ADD-PATH negotiation for
any family, so EVPN is not specially affected; a collector today cannot express
it at all. `parse_evpn_nlri` already takes the flag and preserves the identifier
when a caller supplies it.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 02:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues leave EVPN ADD-PATH handling incomplete, permit malformed or lossy encoding, and leave the public encoding round-trip insufficiently tested.

5 open issues
4 resolved since last review

Review effort: Balanced

Comment thread tests/evpn.rs Resolved
Third review round.

- A type-3 route with octets after the originating address is rejected, like
  types 2 and 5. Accepting them meant dropping bytes on re-encode.
- The encoder refuses the two impossible next-hop states: an EVPN announcement
  without a VTEP (the next-hop length would be missing and a receiver would read
  the reserved octet as it) and a withdrawal with one (MP_UNREACH has no such
  field). Both are checked before a byte is written.
- A route type that disagrees with its payload is an error instead of a header
  describing one family and a body describing another; raw payloads keep the
  type they were decoded with.
- `Attribute::encode_to` infers ADD-PATH from EVPN path identifiers as well as
  labeled prefixes, and does so for withdrawals too, so a parsed ADD-PATH EVPN
  route survives the public encoder.
- The BMP-to-MRT conversion test now encodes the record and parses the bytes
  back. `TryFrom` clones the parsed message, so the previous assertion only
  proved the conversion returned Ok, not that its encoding was valid.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 02:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

BMP decoding does not propagate negotiated ADD-PATH state, and encoding can include path identifiers in non-ADD-PATH records, leaving EVPN routes undecoded.

1 open issue
5 resolved since last review

Review effort: Balanced

Comment thread src/parser/bgp/attributes/mod.rs Resolved
Fourth review round. ADD-PATH is signalled by the MRT record subtype
(RFC 8050), so an update carrying path identifiers under `MessageAs4` decodes
with the identifier read as NLRI.

- `Bgp4MpMessage::encode` refuses a subtype that disagrees with the payload:
  identifiers under a plain subtype, or an ADD-PATH subtype without them.
- `MrtRecord::try_from(&BmpMessage)` picks `MessageAs4Addpath` when the parsed
  update carries identifiers. A BMP session cannot express the negotiation, so
  the update itself is the only evidence available.
- Round-trip tests for both directions, including the BMP conversion.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

BMP route-monitoring always disables ADD-PATH parsing, causing EVPN routes with path IDs to be misdecoded or fall back to raw attributes; existing tests do not exercise this path with a wire message.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@digizeph
digizeph merged commit 89e172c into main Oct 28, 2026
10 checks passed
@digizeph
digizeph deleted the feat/evpn-nlri branch October 28, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EVPN NLRI (AFI 25 / SAFI 70) and MAC Mobility extended community: add typed decoding

2 participants