bmp_protocol/
lib.rs

1#![deny(missing_docs)]
2
3//! A basic decoder for BMP messages ([RFC7854](https://tools.ietf.org/html/rfc7854))
4//!
5//! BMP (BGP Monitoring Protocol) is a method for BGP-speakers, typically network routers
6//! to provide telemetry relating to BGP state.
7//!
8//! ## Errors
9//! This crate will panic if the BMP headers don't decode correctly, but as soon as we have
10//! a valid set of headers, failures on decoding the inner BGP messages will be handled via Result<T>
11
12mod decoder;
13mod error;
14
15/// Contains types and decode implementations
16pub mod types;
17
18/// Error type
19pub use error::Error;
20/// Some docs ay
21pub use decoder::BmpDecoder;
22
23/// Result type wrapper
24pub type Result<T> = std::result::Result<T, error::Error>;
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    use tokio::{
31        fs::File,
32        stream::StreamExt,
33    };
34    use tokio_util::codec::FramedRead;
35
36    use std::ffi::OsStr;
37    use std::fs;
38
39    #[tokio::test]
40    async fn test_data() {
41        for entry in fs::read_dir("test_data/").unwrap() {
42            let entry = entry.unwrap();
43
44            match entry.path().extension() {
45                Some(ext) if ext == OsStr::new("dump") => {
46                    println!("Testing {}", entry.path().display());
47                    let fh = File::open(&entry.path()).await.unwrap();
48                    let mut rdr = FramedRead::new(fh, BmpDecoder::new());
49
50                    while let Some(msg) = rdr.next().await {
51                        match msg {
52                            Ok(_) => {},
53                            Err(err) => panic!("Error: {}", err)
54                        };
55                    }
56                },
57                _ => {}
58            };
59        }
60    }
61}