From 312327b43748c5ea38b3244fbb7b56ab86225b22 Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Thu, 9 Nov 2023 15:43:31 -0800 Subject: [PATCH] add support for end-of-RIB message test --- README.md | 1 + src/lib.rs | 1 + src/models/bgp/attributes/mod.rs | 2 +- src/parser/bgp/messages.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1f7607..634918f 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,7 @@ If you would like to see any specific RFC's support, please submit an issue on G - [X] [RFC 2042](https://datatracker.ietf.org/doc/html/rfc2042): Registering New BGP Attribute Types - [X] [RFC 3392](https://datatracker.ietf.org/doc/html/rfc3392): Capabilities Advertisement with BGP-4 - [X] [RFC 4271](https://datatracker.ietf.org/doc/html/rfc4271): A Border Gateway Protocol 4 (BGP-4) +- [X] [RFC 4724](https://datatracker.ietf.org/doc/html/rfc4724): Graceful Restart Mechanism for BGP - [X] [RFC 4456](https://datatracker.ietf.org/doc/html/rfc4456): BGP Route Reflection: An Alternative to Full Mesh Internal BGP (IBGP) - [X] [RFC 5065](https://datatracker.ietf.org/doc/html/rfc5065): Autonomous System Confederations for BGP - [X] [RFC 6793](https://datatracker.ietf.org/doc/html/rfc6793): BGP Support for Four-Octet Autonomous System (AS) Number Space diff --git a/src/lib.rs b/src/lib.rs index 23bfbc9..802e480 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,6 +371,7 @@ If you would like to see any specific RFC's support, please submit an issue on G - [X] [RFC 2042](https://datatracker.ietf.org/doc/html/rfc2042): Registering New BGP Attribute Types - [X] [RFC 3392](https://datatracker.ietf.org/doc/html/rfc3392): Capabilities Advertisement with BGP-4 - [X] [RFC 4271](https://datatracker.ietf.org/doc/html/rfc4271): A Border Gateway Protocol 4 (BGP-4) +- [X] [RFC 4724](https://datatracker.ietf.org/doc/html/rfc4724): Graceful Restart Mechanism for BGP - [X] [RFC 4456](https://datatracker.ietf.org/doc/html/rfc4456): BGP Route Reflection: An Alternative to Full Mesh Internal BGP (IBGP) - [X] [RFC 5065](https://datatracker.ietf.org/doc/html/rfc5065): Autonomous System Confederations for BGP - [X] [RFC 6793](https://datatracker.ietf.org/doc/html/rfc6793): BGP Support for Four-Octet Autonomous System (AS) Number Space diff --git a/src/models/bgp/attributes/mod.rs b/src/models/bgp/attributes/mod.rs index 0aa828a..08cae6e 100644 --- a/src/models/bgp/attributes/mod.rs +++ b/src/models/bgp/attributes/mod.rs @@ -133,7 +133,7 @@ pub fn get_deprecated_attr_type(attr_type: u8) -> Option<&'static str> { } /// Convenience wrapper for a list of attributes -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Default)] pub struct Attributes { // Black box type to allow for later changes/optimizations. The most common attributes could be // added as fields to allow for easier lookup. diff --git a/src/parser/bgp/messages.rs b/src/parser/bgp/messages.rs index c2a0f23..efc4389 100644 --- a/src/parser/bgp/messages.rs +++ b/src/parser/bgp/messages.rs @@ -326,6 +326,17 @@ impl BgpUpdateMessage { bytes.extend(encode_nlri_prefixes(&self.announced_prefixes, add_path)); bytes.freeze() } + + /// Check if this is an end-of-rib message. + /// + /// + /// End-of-rib message is a special update message that contains no NLRI or withdrawal NLRI. + pub fn is_end_of_rib(&self) -> bool { + self.announced_prefixes.is_empty() + && self.withdrawn_prefixes.is_empty() + && self.attributes.get_reachable().is_none() + && self.attributes.get_unreachable().is_none() + } } impl BgpMessage { @@ -350,3 +361,18 @@ impl BgpMessage { bytes.freeze() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_end_of_rib() { + let msg = BgpUpdateMessage { + withdrawn_prefixes: vec![], + attributes: Attributes::default(), + announced_prefixes: vec![], + }; + assert!(msg.is_end_of_rib()); + } +}