[−][src]Crate bgp_rs
The bgp-rs crate provides functionality to parse BGP-formatted streams.
Examples
Reading a MRT file containing BPG messages
use std::fs::File; use std::io::Cursor; use std::io::Read; use std::io::BufReader; use mrt_rs::Record; use mrt_rs::bgp4mp::BGP4MP; use libflate::gzip::Decoder; fn main() { // Open an MRT-formatted file. let file = File::open("res/updates.20190101.0000.gz").unwrap(); // Decode the GZIP stream using BufReader for better performance. let mut decoder = Decoder::new(BufReader::new(file)).unwrap(); // Create a new MRTReader with a Cursor such that we can keep track of the position. let mut reader = mrt_rs::Reader { stream: decoder }; // Keep reading MRT (Header, Record) tuples till the end of the file has been reached. while let Ok(Some((_, record))) = reader.read() { match record { Record::BGP4MP(x) => match x { BGP4MP::MESSAGE(x) => { let cursor = Cursor::new(x.message); let mut reader = bgp_rs::Reader { stream: cursor }; reader.read().unwrap(); } BGP4MP::MESSAGE_AS4(x) => { let cursor = Cursor::new(x.message); let mut reader = bgp_rs::Reader { stream: cursor }; // Read BGP (Header, Message) tuples. match reader.read() { Err(x) => println!("Error: {}", x), Ok((_, message)) => println!("{:?}", message), } } _ => continue, }, _ => continue, } } }
Re-exports
pub use crate::attributes::*; |
Modules
| attributes | Contains the implementation of all BGP path attributes. |
Structs
| Header | Represents the BGP header accompanying every BGP message. |
| Notification | Represents a BGP Notification message. |
| Open | Represents a BGP Open message. |
| OpenParameter | Represents a parameter in the optional parameter section of an Open message. |
| Prefix | Represents a generic prefix. For example an IPv4 prefix or IPv6 prefix. |
| Reader | The BGPReader can read BGP messages from a BGP-formatted stream. |
| Update | Represents a BGP Update message. |
Enums
| AFI | Represents an Address Family Idenfitier. Currently only IPv4 and IPv6 are supported. |
| Message | Represents a single BGP message. |