Skip to content

Commit

Permalink
northbound: refactor infrastructure for operational-data retrieval
Browse files Browse the repository at this point in the history
Replace the `get_element` callback by the `get_object` callback,
which returns an entire YANG object (container or list) at once.
The returned YANG objects are auto-generated structs with typed fields,
ensuring compile-time checks.

This refactor brings significant optimizations, improving performance
in operational data retrieval by approximately 90%.

Additionally, it includes several simplifications and enhancements to
the API for improved maintainability.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed May 28, 2024
1 parent 671b049 commit 9968094
Show file tree
Hide file tree
Showing 36 changed files with 4,452 additions and 8,552 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ capctl = "0.2"
check_keyword = "0.2"
clap = "2.33"
chrono = { version = "0.4", features = ["serde"] }
convert_case = "0.6"
criterion = "0.4"
crossbeam-channel = "0.5"
derive-new = "0.5"
Expand Down Expand Up @@ -72,7 +73,7 @@ tonic = { version = "0.11", features = ["tls"] }
tonic-build = "0.11"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
yang2 = { version = "0.12", features = ["bundled"] }
yang2 = { version = "0.13", features = ["bundled"] }

[workspace.lints.rust]
rust_2018_idioms = { level = "warn", priority = -1 }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Holo supports the following IETF RFCs and Internet drafts:
| ietf-bfd-ip-sh@2022-09-22 | 100.00% | 100.00% | - | 100.00% | [100.00%](http://westphal.com.br/holo/ietf-bfd-ip-sh.html) |
| ietf-bfd@2022-09-22 | 100.00% | 100.00% | - | - | [100.00%](http://westphal.com.br/holo/ietf-bfd.html) |
| ietf-bgp-policy@2023-07-05 | 100.00% | - | - | - | [100.00%](http://westphal.com.br/holo/ietf-bgp-policy.html) |
| ietf-bgp@2023-07-05 | 32.38% | 87.86% | - | - | [61.39%](http://westphal.com.br/holo/ietf-bgp.html) |
| ietf-bgp@2023-07-05 | 32.38% | 85.95% | - | - | [60.40%](http://westphal.com.br/holo/ietf-bgp.html) |
| ietf-if-extensions@2023-01-26 | 100.00% | 0.00% | - | - | [50.00%](http://westphal.com.br/holo/ietf-if-extensions.html) |
| ietf-if-vlan-encapsulation@2023-01-26 | 42.86% | - | - | - | [42.86%](http://westphal.com.br/holo/ietf-if-vlan-encapsulation.html) |
| ietf-interfaces@2018-01-09 | 100.00% | 0.00% | - | - | [22.22%](http://westphal.com.br/holo/ietf-interfaces.html) |
Expand Down
22 changes: 21 additions & 1 deletion holo-bfd/src/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use derive_new::new;
use holo_protocol::{
InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance,
};
use holo_utils::bfd::PathType;
use holo_utils::bfd::{PathType, State};
use holo_utils::ibus::IbusMsg;
use holo_utils::ip::AddressFamily;
use holo_utils::protocol::Protocol;
Expand Down Expand Up @@ -97,6 +97,26 @@ impl Master {
self.udp_mh_rx_tasks = None;
}
}

// Counts the number of sessions that match the given path type and local
// state.
pub(crate) fn sessions_count(
&self,
path_type: Option<PathType>,
local_state: Option<State>,
) -> usize {
self.sessions
.iter()
.filter(|sess| match path_type {
Some(path_type) => sess.key.path_type() == path_type,
None => true,
})
.filter(|sess| match local_state {
Some(local_state) => sess.state.local_state == local_state,
None => true,
})
.count()
}
}

#[async_trait]
Expand Down
9 changes: 5 additions & 4 deletions holo-bfd/src/northbound/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: MIT
//

use std::borrow::Cow;
use std::net::IpAddr;

use holo_northbound::{notification, yang, NbProviderSender};
Expand Down Expand Up @@ -44,8 +45,8 @@ fn state_change_singlehop(
.statistics
.last_state_change_time
.as_ref(),
dest_addr: Some(dst),
source_addr: sess.config.src.as_ref(),
dest_addr: Some(Cow::Borrowed(dst)),
source_addr: sess.config.src.as_ref().map(Cow::Borrowed),
session_index: Some(sess.id as u32),
path_type: Some(sess.key.path_type().to_yang()),
interface: Some(ifname.into()),
Expand All @@ -71,8 +72,8 @@ fn state_change_multihop(
.statistics
.last_state_change_time
.as_ref(),
dest_addr: Some(dst),
source_addr: Some(src),
dest_addr: Some(Cow::Borrowed(dst)),
source_addr: Some(Cow::Borrowed(src)),
session_index: Some(sess.id as u32),
path_type: Some(sess.key.path_type().to_yang()),
};
Expand Down
Loading

0 comments on commit 9968094

Please sign in to comment.