Skip to content

Commit

Permalink
bgp: implement YANG notifications
Browse files Browse the repository at this point in the history
Implement the "established" and "backward-transition" notifications
defined in the IETF BGP model.

The topology tests data have been update accordingly.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed May 1, 2024
1 parent f171242 commit 6ddbbc4
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 0 deletions.
8 changes: 8 additions & 0 deletions holo-bgp/src/neighbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::debug::Debug;
use crate::error::Error;
use crate::instance::{Instance, InstanceUpView};
use crate::northbound::configuration::{InstanceCfg, NeighborCfg};
use crate::northbound::notification;
use crate::packet::attribute::Attrs;
use crate::packet::consts::{
Afi, ErrorCode, FsmErrorSubcode, Safi, AS_TRANS, BGP_VERSION,
Expand Down Expand Up @@ -482,6 +483,13 @@ impl Neighbor {
Debug::NbrFsmTransition(&self.remote_addr, &self.state, &next_state)
.log();

// Send YANG-modeled notification.
if next_state == fsm::State::Established {
notification::established(instance, self);
} else if self.state == fsm::State::Established {
notification::backward_transition(instance, self);
}

// Keep track of the time that the BGP session last transitioned in or
// out of the Established state.
if self.state == fsm::State::Established
Expand Down
1 change: 1 addition & 0 deletions holo-bgp/src/northbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

pub mod configuration;
pub mod notification;
pub mod rpc;
pub mod state;
pub mod yang;
Expand Down
77 changes: 77 additions & 0 deletions holo-bgp/src/northbound/notification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Copyright (c) The Holo Core Contributors
//
// SPDX-License-Identifier: MIT
//

use holo_northbound::notification;
use holo_northbound::paths::control_plane_protocol;
use holo_northbound::paths::control_plane_protocol::bgp;
use holo_utils::protocol::Protocol;
use holo_yang::ToYang;

use crate::instance::InstanceUpView;
use crate::neighbor::Neighbor;

// ===== global functions =====

pub(crate) fn established(instance: &InstanceUpView<'_>, nbr: &Neighbor) {
use bgp::neighbors::established::{self, Established};

let path = format!(
"{}{}{}",
control_plane_protocol::PATH,
control_plane_protocol::list_keys(
Protocol::BGP.to_yang(),
instance.name
),
established::RELATIVE_PATH,
);
let data = Established {
remote_address: Some(nbr.remote_addr.to_string().into()),
};
notification::send(&instance.tx.nb, path, data);
}

pub(crate) fn backward_transition(
instance: &InstanceUpView<'_>,
nbr: &Neighbor,
) {
use bgp::neighbors::backward_transition::notification_received::NotificationReceived;
use bgp::neighbors::backward_transition::notification_sent::NotificationSent;
use bgp::neighbors::backward_transition::{self, BackwardTransition};

let path = format!(
"{}{}{}",
control_plane_protocol::PATH,
control_plane_protocol::list_keys(
Protocol::BGP.to_yang(),
instance.name
),
backward_transition::RELATIVE_PATH,
);
let data = BackwardTransition {
remote_addr: Some(nbr.remote_addr.to_string().into()),
notification_received: nbr.notification_rcvd.as_ref().map(
|(time, notif)| NotificationReceived {
last_notification: Some(time.to_rfc3339().into()),
last_error: Some(notif.to_yang()),
last_error_code: Some(notif.error_code.to_string().into()),
last_error_subcode: Some(
notif.error_subcode.to_string().into(),
),
},
),
notification_sent: nbr.notification_sent.as_ref().map(
|(time, notif)| NotificationSent {
last_notification: Some(time.to_rfc3339().into()),
last_error: Some(notif.to_yang()),
last_error_code: Some(notif.error_code.to_string().into()),
last_error_subcode: Some(
notif.error_subcode.to_string().into(),
),
},
),
};
notification::send(&instance.tx.nb, path, data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.1.2"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.2.3"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.1.1"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.3.4"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.2.1"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"4.4.4.4"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.3.2"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"3.3.3.3"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.1.2"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.2.4"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.3.5"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.1.1"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.4.3"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.4.2"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.5.6"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.2.1"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.6.6"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.3.1"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.7.6"}}}}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.7.5"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.5.3"}}}}]}}}
{"ietf-routing:routing":{"control-plane-protocols":{"control-plane-protocol":[{"type":"ietf-bgp:bgp","name":"test","ietf-bgp:bgp":{"neighbors":{"established":{"remote-address":"10.0.6.4"}}}}]}}}
36 changes: 36 additions & 0 deletions holo-yang/modules/deviations/ietf-bgp-holo-deviations.yang
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,42 @@ module ietf-bgp-holo-deviations {
}
*/

/*
deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:established" {
deviate not-supported;
}
*/

/*
deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:established/bgp:remote-address" {
deviate not-supported;
}
*/

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-received/bgp:last-encapsulated-error" {
deviate not-supported;
}

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-received/bgp:last-encapsulated-error-code" {
deviate not-supported;
}

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-received/bgp:last-encapsulated-error-subcode" {
deviate not-supported;
}

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-sent/bgp:last-encapsulated-error" {
deviate not-supported;
}

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-sent/bgp:last-encapsulated-error-code" {
deviate not-supported;
}

deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:backward-transition/bgp:notification-sent/bgp:last-encapsulated-error-subcode" {
deviate not-supported;
}

/*
deviation "/rt:routing/rt:control-plane-protocols/rt:control-plane-protocol/bgp:bgp/bgp:neighbors/bgp:neighbor" {
deviate not-supported;
Expand Down

0 comments on commit 6ddbbc4

Please sign in to comment.