Skip to content

add minimal route-level parser#284

Open
ties wants to merge 3 commits intobgpkit:mainfrom
ties:feature/minimal-update-level-parser
Open

add minimal route-level parser#284
ties wants to merge 3 commits intobgpkit:mainfrom
ties:feature/minimal-update-level-parser

Conversation

@ties
Copy link
Copy Markdown
Contributor

@ties ties commented May 6, 2026

Add a parser that parses the basic information for a route (prefix, as_path, peer_ip, peer_as). The validation logic is shared with the regular element level iterator.

On the update fixture, into_route_iter takes ~1.83 ms versus ~2.09 ms for into_update_iter, about 12% faster.

On the small RIB fixture, into_route_iter takes ~24.2 ms versus ~60.0 ms for into_update_iter, about 60% faster / 2.5x as fast.

Add a parser that parses the basic information for a route (prefix,
as_path, peer_ip, peer_as). The validation logic is shared with the regular
element level iterator.

On the update fixture, `into_route_iter` takes ~1.83 ms versus
~2.09 ms for `into_update_iter`, about 12% faster.

On the small RIB fixture, `into_route_iter` takes ~24.2 ms versus
~60.0 ms for `into_update_iter`, about 60% faster / 2.5x as fast.
@ties ties changed the title add minimal route-level add minimal route-level parser May 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 87.52456% with 127 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.86%. Comparing base (bfb960f) to head (041453c).

Files with missing lines Patch % Lines
src/parser/iters/route.rs 83.04% 127 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #284      +/-   ##
==========================================
- Coverage   88.94%   88.86%   -0.08%     
==========================================
  Files          85       86       +1     
  Lines       16563    17520     +957     
==========================================
+ Hits        14732    15570     +838     
- Misses       1831     1950     +119     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds a new lightweight, route-level parsing path to bgpkit-parser for faster scans that only need per-prefix identity plus minimal metadata (timestamp, peer, prefix, AS path), while keeping filter support for route-relevant fields.

Changes:

  • Introduces BgpRouteElem plus into_route_iter / into_fallible_route_iter iterators that parse MRT records into lightweight per-prefix route elements.
  • Refactors filter matching so both BgpElem and BgpRouteElem can be filtered via a shared route-view abstraction (with community filtering intentionally unsupported for route elems).
  • Extracts attribute validation state into a reusable helper and adds benchmarks for the new iterator.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/parser/iters/route.rs Adds the minimal route parser and route iterators over BgpRouteElem.
src/parser/iters/mod.rs Wires the new route iterator APIs into BgpkitParser and exports iterator types.
src/parser/filter.rs Extends filtering to BgpRouteElem via a shared route-view matcher and updates docs/tests.
src/parser/bgp/attributes/mod.rs Factors attribute validation tracking into AttributeValidationState and re-exports needed parsers internally.
src/models/bgp/elem.rs Introduces the BgpRouteElem data model.
src/lib.rs Re-exports BgpRouteElem from the crate root.
benches/internals.rs Adds Criterion benchmarks for into_route_iter on updates and RIB fixtures.

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

Comment thread src/parser/filter.rs
}

fn match_route_view_filter<T: RouteFilterView>(view: &T, filter: &Filter) -> bool {
match filter {
Comment thread src/parser/iters/route.rs
) -> Result<Vec<BgpRouteElem>, ParserError> {
let total_size = data.len();
data.has_n_remaining(19)?;
data.advance(16);
Comment thread src/parser/iters/route.rs
Comment on lines +541 to +543
if let Some(bytes) = e.bytes {
std::fs::write("mrt_core_dump", bytes)
.expect("Unable to write to mrt_core_dump");
Comment thread src/parser/iters/route.rs
Comment on lines +281 to +292
fn total_should_read(afi: &Afi, asn_len: &AsnLength, total_size: usize) -> usize {
let ip_size = match afi {
Afi::Ipv4 => 4 * 2,
Afi::Ipv6 => 16 * 2,
Afi::LinkState => 4 * 2,
};
let asn_size = match asn_len {
AsnLength::Bits16 => 2 * 2,
AsnLength::Bits32 => 2 * 4,
};
total_size - asn_size - 2 - 2 - ip_size
}
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