feat: retain raw BGP attributes, add AIGP/BFD/Prefix-SID/BIER/SFP parsers#291
Conversation
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 toRaw. - Add parsers/encoders for AIGP (26), SFP (37), BFD Discriminator (38), BGP Prefix-SID (40), and BIER (41), plus supporting model types (
RawTlv*, newAttributeValuevariants). - Update docs/examples/changelog and dependency features (enable
bytes/serde, makebytesnon-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.
- 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
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:
Breaking changes
All breaking changes affect advanced attribute-level usage only:
AttrRawfields changed:attr_type: AttrTypetocode: u8,bytes: Vec<u8>toBytes. Use.attr_type()to recover the enum.AttrType::CLUSTER_ID = 13removed. Code 13 is the deprecatedRCID_PATH / CLUSTER_IDper IANA registry; handled asDeprecated(AttrRaw).AttributeValuegains variants:Raw(AttrRaw),BfdDiscriminator,BgpPrefixSid,Bier,Sfp.AigpTlv.value:Vec<u8>toBytes.No changes to the common iteration/element APIs (
into_elem_iter(),MrtElem/BgpElemfields,into_update_iter()). Raw-retained attributes are surfaced through the existingelem.unknownfield.New features
AttributeValue::Rawinstead of dropped.AttrType; deprecated codes detected via helper before enum dispatch.AttrTypeper IANA.Rawafter recording a validation warning.serdeenabled onbytesto serializeAttrRaw.New attribute parsers
Examples
examples/raw_attributes.rs-- API walkthrough for all attribute categoriesexamples/scan_path_attributes.rs-- scan RouteViews/RIS archives for rare attributesWhat is intentionally raw-retained (deferred)
Test coverage
cargo clippy --all-targets --all-features -- -D warningscleancargo llvm-covshows >90% line coverage across all new parser files