add minimal route-level parser#284
Open
ties wants to merge 3 commits intobgpkit:mainfrom
Open
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% 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. 🚀 New features to boost your workflow:
|
Contributor
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.
| } | ||
|
|
||
| fn match_route_view_filter<T: RouteFilterView>(view: &T, filter: &Filter) -> bool { | ||
| match filter { |
| ) -> Result<Vec<BgpRouteElem>, ParserError> { | ||
| let total_size = data.len(); | ||
| data.has_n_remaining(19)?; | ||
| data.advance(16); |
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 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.