pub struct BgpkitParser<R> { /* private fields */ }Implementations§
Source§impl<R> BgpkitParser<R>
impl<R> BgpkitParser<R>
pub fn into_record_iter(self) -> RecordIterator<R> ⓘ
pub fn into_elem_iter(self) -> ElemIterator<R> ⓘ
pub fn into_raw_record_iter(self) -> RawRecordIterator<R> ⓘ
Sourcepub fn into_update_iter(self) -> UpdateIterator<R> ⓘ
pub fn into_update_iter(self) -> UpdateIterator<R> ⓘ
Creates an iterator over BGP announcements from MRT data.
This iterator yields MrtUpdate items from both UPDATES files (BGP4MP messages)
and RIB dump files (TableDump/TableDumpV2 messages). It’s a middle ground
between into_record_iter() and into_elem_iter():
- More focused than
into_record_iter()as it only returns BGP announcements - More efficient than
into_elem_iter()as it doesn’t duplicate attributes per prefix
The iterator returns an MrtUpdate enum with variants:
Bgp4MpUpdate: BGP UPDATE messages from UPDATES filesTableDumpV2Entry: RIB entries from TableDumpV2 RIB dumpsTableDumpMessage: Legacy TableDump v1 messages
§Example
use bgpkit_parser::{BgpkitParser, MrtUpdate};
let parser = BgpkitParser::new("updates.mrt").unwrap();
for update in parser.into_update_iter() {
match update {
MrtUpdate::Bgp4MpUpdate(u) => {
println!("Peer {} announced {} prefixes",
u.peer_ip,
u.message.announced_prefixes.len()
);
}
MrtUpdate::TableDumpV2Entry(e) => {
println!("RIB entry for {} with {} peers",
e.prefix,
e.rib_entries.len()
);
}
MrtUpdate::TableDumpMessage(m) => {
println!("Legacy table dump for {}", m.prefix);
}
}
}Sourcepub fn into_fallible_record_iter(self) -> FallibleRecordIterator<R> ⓘ
pub fn into_fallible_record_iter(self) -> FallibleRecordIterator<R> ⓘ
Creates a fallible iterator over MRT records that returns parsing errors.
§Example
use bgpkit_parser::BgpkitParser;
let parser = BgpkitParser::new("updates.mrt").unwrap();
for result in parser.into_fallible_record_iter() {
match result {
Ok(record) => {
// Process the record
}
Err(e) => {
// Handle the error
eprintln!("Error parsing record: {}", e);
}
}
}Sourcepub fn into_fallible_elem_iter(self) -> FallibleElemIterator<R> ⓘ
pub fn into_fallible_elem_iter(self) -> FallibleElemIterator<R> ⓘ
Creates a fallible iterator over BGP elements that returns parsing errors.
§Example
use bgpkit_parser::BgpkitParser;
let parser = BgpkitParser::new("updates.mrt").unwrap();
for result in parser.into_fallible_elem_iter() {
match result {
Ok(elem) => {
// Process the element
}
Err(e) => {
// Handle the error
eprintln!("Error parsing element: {}", e);
}
}
}Sourcepub fn into_fallible_update_iter(self) -> FallibleUpdateIterator<R> ⓘ
pub fn into_fallible_update_iter(self) -> FallibleUpdateIterator<R> ⓘ
Creates a fallible iterator over BGP announcements that returns parsing errors.
Unlike the default into_update_iter(), this iterator returns
Result<MrtUpdate, ParserErrorWithBytes> allowing users to handle parsing
errors explicitly instead of having them logged and skipped.
§Example
use bgpkit_parser::{BgpkitParser, MrtUpdate};
let parser = BgpkitParser::new("updates.mrt").unwrap();
for result in parser.into_fallible_update_iter() {
match result {
Ok(MrtUpdate::Bgp4MpUpdate(update)) => {
println!("Peer {} announced {} prefixes",
update.peer_ip,
update.message.announced_prefixes.len()
);
}
Ok(_) => { /* handle other variants */ }
Err(e) => {
eprintln!("Error parsing: {}", e);
}
}
}Source§impl BgpkitParser<Box<dyn Read + Send>>
impl BgpkitParser<Box<dyn Read + Send>>
Sourcepub fn new(path: &str) -> Result<Self, ParserErrorWithBytes>
pub fn new(path: &str) -> Result<Self, ParserErrorWithBytes>
Creating a new parser from a object that implements Read trait.
Sourcepub fn new_cached(
path: &str,
cache_dir: &str,
) -> Result<Self, ParserErrorWithBytes>
pub fn new_cached( path: &str, cache_dir: &str, ) -> Result<Self, ParserErrorWithBytes>
Creating a new parser that also caches the remote content to a local cache directory.
The cache file name is generated by the following format: cache-<crc32 of file name>-<file name>.
For example, the remote file http://archive.routeviews.org/route-views.chile/bgpdata/2023.03/RIBS/rib.20230326.0600.bz2
will be cached as cache-682cb1eb-rib.20230326.0600.bz2 in the cache directory.
Source§impl<R: Read> BgpkitParser<R>
impl<R: Read> BgpkitParser<R>
Sourcepub fn from_reader(reader: R) -> Self
pub fn from_reader(reader: R) -> Self
Creating a new parser from an object that implements Read trait.
Sourcepub fn next_record(&mut self) -> Result<MrtRecord, ParserErrorWithBytes>
pub fn next_record(&mut self) -> Result<MrtRecord, ParserErrorWithBytes>
This is used in for loop for item in parser{}
Source§impl<R> BgpkitParser<R>
impl<R> BgpkitParser<R>
pub fn enable_core_dump(self) -> Self
pub fn disable_warnings(self) -> Self
pub fn add_filter( self, filter_type: &str, filter_value: &str, ) -> Result<Self, ParserErrorWithBytes>
Trait Implementations§
Source§impl<R: Read> IntoIterator for BgpkitParser<R>
Use ElemIterator as the default iterator to return BgpElems instead of [MrtRecord]s.
impl<R: Read> IntoIterator for BgpkitParser<R>
Use ElemIterator as the default iterator to return BgpElems instead of [MrtRecord]s.
Auto Trait Implementations§
impl<R> Freeze for BgpkitParser<R>where
R: Freeze,
impl<R> RefUnwindSafe for BgpkitParser<R>where
R: RefUnwindSafe,
impl<R> Send for BgpkitParser<R>where
R: Send,
impl<R> Sync for BgpkitParser<R>where
R: Sync,
impl<R> Unpin for BgpkitParser<R>where
R: Unpin,
impl<R> UnwindSafe for BgpkitParser<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more