Skip to content

feat: retain raw BGP attributes, add AIGP/BFD/Prefix-SID/BIER/SFP parsers#291

Merged
digizeph merged 7 commits into
mainfrom
feat/bgp-attribute-raw-retention-aigp
Jun 16, 2026
Merged

feat: retain raw BGP attributes, add AIGP/BFD/Prefix-SID/BIER/SFP parsers#291
digizeph merged 7 commits into
mainfrom
feat/bgp-attribute-raw-retention-aigp

Conversation

@digizeph

@digizeph digizeph commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

BGP path attributes that bgpkit-parser does not semantically decode are no longer silently dropped. The parser now distinguishes three undecoded buckets and preserves all original bytes for faithful re-encoding:

  • Raw: Known, assigned attribute codes whose value format is not yet parsed. These are preserved verbatim for inspection and round-trip.
  • Deprecated: Historic or deprecated code points per IANA. Preserved for archival fidelity and auditing.
  • Unknown: Unassigned or unrecognized code points. Preserved so that no wire data is ever lost.

Breaking changes

All breaking changes affect advanced attribute-level usage only:

  • AttrRaw fields changed: attr_type: AttrType to code: u8, bytes: Vec<u8> to Bytes. Use .attr_type() to recover the enum.
  • AttrType::CLUSTER_ID = 13 removed. Code 13 is the deprecated RCID_PATH / CLUSTER_ID per IANA registry; handled as Deprecated(AttrRaw).
  • AttributeValue gains variants: Raw(AttrRaw), BfdDiscriminator, BgpPrefixSid, Bier, Sfp.
  • AigpTlv.value: Vec<u8> to Bytes.

No changes to the common iteration/element APIs (into_elem_iter(), MrtElem / BgpElem fields, into_update_iter()). Raw-retained attributes are surfaced through the existing elem.unknown field.

New features

  • Raw retention: Known but undecoded codes (0, 22, 24, 27, 33, 128) retained as AttributeValue::Raw instead of dropped.
  • Deprecated handling: Removed CLUSTER_ID from AttrType; deprecated codes detected via helper before enum dispatch.
  • BIER code 41 (RFC 9793): Added to AttrType per IANA.
  • Typed parser failure fallback: Malformed known attributes retain original bytes as Raw after recording a validation warning.
  • Serialization: serde enabled on bytes to serialize AttrRaw.

New attribute parsers

RFC Code Attribute What it does
RFC 7311 26 AIGP Parses TLVs, preserves unknown, round-trip
RFC 9015 37 SFP Parses 1+2 TLVs, preserves unknown, round-trip
RFC 9026 38 BFD Discriminator Parses mode + discriminator + optional TLVs, round-trip
RFC 8669 40 BGP Prefix-SID Parses 1+2 TLVs, preserves unknown, round-trip
RFC 9793 41 BIER Parses 2+2 TLVs, preserves unknown, round-trip

Examples

  • examples/raw_attributes.rs -- API walkthrough for all attribute categories
  • examples/scan_path_attributes.rs -- scan RouteViews/RIS archives for rare attributes

What is intentionally raw-retained (deferred)

  • Traffic Engineering (code 24) -- tracked in #290
  • RTR v2 ASPA PDU support -- tracked in #289
  • PMSI_TUNNEL (22, 27), BGPsec_PATH (33), ATTR_SET (128) -- raw-retained

Test coverage

  • 641 tests pass (all features), including targeted tests for:
    • raw retention round-trip for all covered codes
    • deprecated code 13 handling
    • unassigned code to Unknown
    • malformed typed parser to warning + Raw retention
    • all 5 new TLV parsers (valid parse, empty, truncation, unknown TLV, round-trip)
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo llvm-cov shows >90% line coverage across all new parser files

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.52605% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.93%. Comparing base (d9889d1) to head (a29f9bf).

Files with missing lines Patch % Lines
src/parser/bgp/attributes/attr_26_aigp.rs 96.55% 3 Missing ⚠️
src/parser/bgp/attributes/attr_37_sfp.rs 95.31% 3 Missing ⚠️
...rc/parser/bgp/attributes/attr_40_bgp_prefix_sid.rs 95.52% 3 Missing ⚠️
src/parser/bgp/attributes/attr_41_bier.rs 95.45% 3 Missing ⚠️
...parser/bgp/attributes/attr_38_bfd_discriminator.rs 97.56% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
+ Coverage   89.69%   89.93%   +0.24%     
==========================================
  Files          86       91       +5     
  Lines       18334    18733     +399     
==========================================
+ Hits        16444    16848     +404     
+ Misses       1890     1885       -5     

☔ 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.

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.

Pull request overview

This PR extends bgpkit-parser’s BGP UPDATE path-attribute handling to (1) preserve undecoded attribute bytes for faithful round-trip encoding and (2) add typed TLV parsers/encoders for several RFC-defined attributes (AIGP, SFP, BFD Discriminator, Prefix-SID, BIER). It also updates the public models/API to carry raw bytes via bytes::Bytes and documents the breaking changes.

Changes:

  • Preserve attribute value bytes for known-but-unsupported codes (AttributeValue::Raw), deprecated codes (Deprecated), and unassigned/unknown codes (Unknown), with typed-parser failure fallback to Raw.
  • Add parsers/encoders for AIGP (26), SFP (37), BFD Discriminator (38), BGP Prefix-SID (40), and BIER (41), plus supporting model types (RawTlv*, new AttributeValue variants).
  • Update docs/examples/changelog and dependency features (enable bytes/serde, make bytes non-optional).

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/parser/mrt/mrt_elem.rs Updates MRT-to-BgpElem extraction to recognize new attribute variants (but currently drops Raw at this layer).
src/parser/bgp/attributes/README.md Refreshes attribute support matrix and limitations to reflect typed parsers + raw-retention behavior.
src/parser/bgp/attributes/mod.rs Implements raw/deprecated/unknown retention in attribute parsing and adds dispatch/encoding for new typed attributes.
src/parser/bgp/attributes/attr_26_aigp.rs New AIGP TLV parser/encoder with round-trip tests.
src/parser/bgp/attributes/attr_37_sfp.rs New SFP TLV parser/encoder with round-trip tests.
src/parser/bgp/attributes/attr_38_bfd_discriminator.rs New BFD Discriminator parser/encoder (mode + discriminator + optional TLVs) with tests.
src/parser/bgp/attributes/attr_40_bgp_prefix_sid.rs New BGP Prefix-SID TLV parser/encoder with tests.
src/parser/bgp/attributes/attr_41_bier.rs New BIER TLV parser/encoder with tests.
src/models/network/mpls.rs Adds an allow(unused_imports) workaround for feature-gated imports (can be made more precise).
src/models/bgp/attributes/mod.rs Updates attribute models for Bytes, adds new attribute variants + raw TLV helpers, removes CLUSTER_ID, adds BIER.
src/lib.rs Documents newly supported typed BGP path attributes and raw retention behavior.
README.md Mirrors crate-level documentation updates for new typed attributes and raw retention.
examples/scan_path_attributes.rs New example to scan MRT archives for deprecated/unknown/raw-retained attributes.
examples/raw_attributes.rs New example demonstrating inspecting/round-tripping raw/deprecated/unknown attributes.
CHANGELOG.md Adds an Unreleased entry documenting breaking changes, new features, and new parsers.
Cargo.toml Makes bytes non-optional and enables bytes/serde under the crate’s serde feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/parser/mrt/mrt_elem.rs Outdated
Comment thread src/models/network/mpls.rs Outdated
digizeph added 3 commits June 15, 2026 20:31
- Merge AttributeValue::Raw into Unknown arm in get_relevant_attributes
  so raw-retained codes (0,22,24,27,33,128) appear in elem.unknown
- Fix scan_path_attributes.rs comments and add date update note
- Add doc comment to AttrRaw::attr_type() explaining Raw vs Unknown
- Replace Bytes::from(v.to_owned()) with Bytes::copy_from_slice(v)
- Replace blanket #[allow(unused_imports)] with precise #[cfg] gating
- AIGP: test length<3 rejection, truncated value rejection, encode length correction
- BFD Discriminator: test truncated optional TLV header error path
- models: test attr_category() for BfdDiscriminator, BgpPrefixSid, Bier, Sfp
@digizeph digizeph merged commit 5a92246 into main Jun 16, 2026
9 checks passed
@digizeph digizeph deleted the feat/bgp-attribute-raw-retention-aigp branch June 16, 2026 03:38
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.

2 participants