[−][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; use bgp_rs::{Identifier, PathAttribute}; fn main() { // Download an update message. let file = File::open("res/updates.20190101.0000.gz").unwrap(); // Decode the GZIP stream. let 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() { // Extract BGP4MP::MESSAGE_AS4 entries. if let Record::BGP4MP(BGP4MP::MESSAGE_AS4(x)) = record { // Read each BGP (Header, Message) let cursor = Cursor::new(x.message); let mut reader = bgp_rs::Reader { stream: cursor }; let (_, message) = reader.read().unwrap(); // If this is an UPDATE message that contains announcements, extract its origin. if let bgp_rs::Message::Update(x) = message { if x.is_announcement() { if let PathAttribute::AS_PATH(path) = x.get(Identifier::AS_PATH).unwrap() { // Test the path.origin() method. let origin = path.origin(); // Do other stuff ... } } } } } }
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. |