Skip to content

add minimal route-level parser#284

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

add minimal route-level parser#284
ties wants to merge 10 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 96.02763% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.63%. Comparing base (bfb960f) to head (ac97c9e).

Files with missing lines Patch % Lines
src/parser/iters/route.rs 95.54% 63 Missing ⚠️
src/parser/filter.rs 98.93% 3 Missing ⚠️
src/parser/iters/mod.rs 85.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #284      +/-   ##
==========================================
+ Coverage   88.94%   89.63%   +0.69%     
==========================================
  Files          85       86       +1     
  Lines       16563    18228    +1665     
==========================================
+ Hits        14732    16339    +1607     
- Misses       1831     1889      +58     

☔ 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
Comment thread src/parser/iters/route.rs Outdated
Comment thread src/parser/iters/route.rs Outdated
Comment thread src/parser/iters/route.rs Outdated
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread src/parser/iters/route.rs Outdated
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread src/parser/iters/route.rs Outdated
let _sequence_number = data.read_u32()?;
let prefix = data.read_nlri_prefix(&afi, false)?;
let entry_count = data.read_u16()?;
let mut routes = Vec::with_capacity(entry_count as usize);
digizeph and others added 3 commits May 8, 2026 17:16
- Move write_mrt_core_dump helpers to iters/mod.rs to avoid duplication
- Remove redundant data.has_n_remaining() check after explicit length guard
- Add default match_filters to Filterable trait; remove identical overrides
  * Shared AS-path, since we can still change the public API at the
    moment.
  * Introduce RouteUpdateIter to prevent materialisin routes.
  * Lookup peer by index/more dense.

Speedup seems to be ±10%.
Benchmark setup (Macbook Air M4):

- before: 5d9337c (532b05b^)
- after: 532b05b
- input: /tmp/bview.20260509.0000.gz
- command shape: release-mode temporary example calling BgpkitParser::new(...).into_route_iter() over the full file
- routes parsed each run: 56,051,677

Results:

| revision | runs, seconds | median |
|---|---:|---:|
| before | 10.943, 10.813, 10.881 | 10.881s |
| after | 9.749, 9.766, 9.835 | 9.766s |
@ties
Copy link
Copy Markdown
Contributor Author

ties commented May 9, 2026

Ready from my perspective. LGTM 👍

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.

3 participants