add minimal route-level parser#284
Conversation
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.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
BgpRouteElemplusinto_route_iter/into_fallible_route_iteriterators that parse MRT records into lightweight per-prefix route elements. - Refactors filter matching so both
BgpElemandBgpRouteElemcan 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.
| 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); |
- 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 |
|
Ready from my perspective. LGTM 👍 |
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_itertakes ~1.83 ms versus ~2.09 ms forinto_update_iter, about 12% faster.On the small RIB fixture,
into_route_itertakes ~24.2 ms versus ~60.0 ms forinto_update_iter, about 60% faster / 2.5x as fast.