Skip to content

Commit

Permalink
Merge pull request #131 from bgpkit/feature/mrt-adj-rib-out
Browse files Browse the repository at this point in the history
Support Adj-RIB-out for BMP
  • Loading branch information
digizeph authored Oct 23, 2023
2 parents 9c367db + 74e66e5 commit ffd159d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bitflags = {version="2.3.3", features = ["serde"], optional = true}
bytes = {version = "1.4.0", optional = true}
hex= {version = "0.4.3", optional = true} # bmp/openbmp parsing
log= {version = "0.4", optional = true }
oneio = {version= "0.13.1", default-features = false, optional = true }
oneio = {version= "0.13.2", default-features = false, optional = true }
regex = {version = "1", optional = true} # used in parser filter
chrono = {version="0.4.24", optional = true} # parser filter
serde_json = {version = "1.0", optional = true } # RIS Live parsing
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BGPKIT Parser

*This readme is generated from the library's doc comments using [cargo-readme](https://github.com/livioribeiro/cargo-readme). Please refer to the Rust docs website for the full documentation: [latest stable](https://docs.rs/bgpkit-parser/latest/bgpkit_parser/); [bleeding-edge](https://docs.rs/bgpkit-parser/0.10.0-alpha.1/bgpkit_parser/).*
*This readme is generated from the library's doc comments using [cargo-readme](https://github.com/livioribeiro/cargo-readme). Please refer to the Rust docs website for the full documentation: [latest stable](https://docs.rs/bgpkit-parser/latest/bgpkit_parser/); [bleeding-edge](https://docs.rs/bgpkit-parser/0.10.0-alpha.2/bgpkit_parser/).*

[![Rust](https://github.com/bgpkit/bgpkit-parser/actions/workflows/rust.yml/badge.svg)](https://github.com/bgpkit/bgpkit-parser/actions/workflows/rust.yml)
[![Crates.io](https://img.shields.io/crates/v/bgpkit-parser)](https://crates.io/crates/bgpkit-parser)
Expand Down Expand Up @@ -343,7 +343,7 @@ If you would like to see any specific RFC's support, please submit an issue on G
### BMP

- [X] [RFC 7854](https://datatracker.ietf.org/doc/html/rfc7854): BGP Monitoring Protocol (BMP)
- [ ] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP)
- [X] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP)

### Communities

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ If you would like to see any specific RFC's support, please submit an issue on G
## BMP
- [X] [RFC 7854](https://datatracker.ietf.org/doc/html/rfc7854): BGP Monitoring Protocol (BMP)
- [ ] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP)
- [X] [RFC 8671](https://datatracker.ietf.org/doc/html/rfc8671): Support for Adj-RIB-Out in the BGP Monitoring Protocol (BMP)
## Communities
Expand Down
1 change: 0 additions & 1 deletion src/models/bgp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use role::*;

use crate::models::network::*;
use capabilities::BgpCapabilityType;
use error::BgpError;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use std::net::Ipv4Addr;

Expand Down
40 changes: 37 additions & 3 deletions src/parser/bmp/messages/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,36 @@ pub enum PeerType {
}

bitflags! {
/// BMP per-peer header flags
///
/// RFC section at
/// - RFC 7854: https://www.rfc-editor.org/rfc/rfc7854#section-4.2.
/// - RFC 8671: https://www.rfc-editor.org/rfc/rfc8671#section-4
///
/// RFC 8671 extended the flags definition by adding one additional flag to indicate whenther
/// the messages are Adj-RIB-in or Adj-RIB-out.
///
/// ```text
/// 0 1 2 3 4 5 6 7
/// +-+-+-+-+-+-+-+-+
/// |V|L|A|O| Resv |
/// +-+-+-+-+-+-+-+-+
/// ```
/// When the O flag is set to 1, the following fields in the per-peer header are redefined:
/// - Peer Address: The remote IP address associated with the TCP session over which the encapsulated Protocol Data Unit (PDU) is sent.
/// - Peer AS: The Autonomous System number of the peer to which the encapsulated PDU is sent.
/// - Peer BGP ID: The BGP Identifier of the peer to which the encapsulated PDU is sent.
/// - Timestamp: The time when the encapsulated routes were advertised (one may also think of
/// this as the time when they were installed in the Adj-RIB-Out), expressed in seconds and
/// microseconds since midnight (zero hour), January 1, 1970 (UTC). If zero, the time is
/// unavailable. Precision of the timestamp is implementation-dependent.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PeerFlags: u8 {
const ADDRESS_FAMILY_IPV6 = 0x80;
const IS_POST_POLICY = 0x40;
const AS_SIZE_16BIT = 0x20;
const ADDRESS_FAMILY_IPV6 = 0b1000_0000;
const IS_POST_POLICY = 0b0100_0000;
const AS_SIZE_16BIT = 0b0010_0000;
const IS_ADJ_RIB_OUT = 0b0001_0000;
}
}

Expand All @@ -146,6 +170,16 @@ impl PeerFlags {

AsnLength::Bits32
}

/// Returns true if the peer streams Adj-RIB-out BMP messages
pub fn is_adj_rib_out(&self) -> bool {
self.contains(PeerFlags::IS_ADJ_RIB_OUT)
}

/// Returns true if the peer streams post-policy BMP messages
pub fn is_post_policy(&self) -> bool {
self.contains(PeerFlags::IS_POST_POLICY)
}
}

pub fn parse_per_peer_header(data: &mut Bytes) -> Result<BmpPerPeerHeader, ParserBmpError> {
Expand Down
3 changes: 3 additions & 0 deletions src/parser/bmp/messages/stats_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub struct StatsReport {
pub counters: Vec<StatCounter>,
}

/// Statistics count values
///
/// Types of BMP statistics are listed here: <https://www.iana.org/assignments/bmp-parameters/bmp-parameters.xhtml#statistics-types>
#[derive(Debug)]
pub struct StatCounter {
pub stat_type: u16,
Expand Down
2 changes: 0 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ pub mod rislive;

pub(crate) use self::utils::*;
pub(crate) use bgp::attributes::AttributeParser;
pub(crate) use mrt::{parse_bgp4mp, parse_table_dump_message, parse_table_dump_v2_message};

use crate::models::MrtRecord;
use filter::Filter;
pub use mrt::mrt_elem::Elementor;
use oneio::{get_cache_reader, get_reader};

Expand Down

0 comments on commit ffd159d

Please sign in to comment.