1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![deny(missing_docs)]

//! A basic decoder for BMP messages ([RFC7854](https://tools.ietf.org/html/rfc7854))
//!
//! BMP (BGP Monitoring Protocol) is a method for BGP-speakers, typically network routers
//! to provide telemetry relating to BGP state.
//!
//! ## Errors
//! This crate will panic if the BMP headers don't decode correctly, but as soon as we have
//! a valid set of headers, failures on decoding the inner BGP messages will be handled via Result<T>

mod decoder;
mod error;

/// Contains types and decode implementations
pub mod types;

/// Error type
pub use error::Error;
/// Some docs ay
pub use decoder::BmpDecoder;

/// Result type wrapper
pub type Result<T> = std::result::Result<T, error::Error>;

#[cfg(test)]
mod tests {
    use super::*;

    use tokio::{
        fs::File,
        stream::StreamExt,
    };
    use tokio_util::codec::FramedRead;

    use std::ffi::OsStr;
    use std::fs;

    #[tokio::test]
    async fn test_data() {
        for entry in fs::read_dir("test_data/").unwrap() {
            let entry = entry.unwrap();

            match entry.path().extension() {
                Some(ext) if ext == OsStr::new("dump") => {
                    println!("Testing {}", entry.path().display());
                    let fh = File::open(&entry.path()).await.unwrap();
                    let mut rdr = FramedRead::new(fh, BmpDecoder::new());

                    while let Some(msg) = rdr.next().await {
                        match msg {
                            Ok(_) => {},
                            Err(err) => panic!("Error: {}", err)
                        };
                    }
                },
                _ => {}
            };
        }
    }
}