Skip to content

Commit 134728b

Browse files
committed
northbound: replace callback-based model with struct-based model
Refactor the northbound layer to move away from a callback-based design and implement YANG-related logic directly on the auto-generated YANG structs. This ensures that when a YANG module is added or modified, the code must be updated accordingly or it will fail to compile. Previously, missing callbacks went unnoticed at build time and were only detected at daemon startup. This change applies to YANG-modeled state and RPCs. Configuration handling will be refactored separately. As a positive side effect, implementing logic directly on YANG structs results in cleaner code compared to callbacks initialized via the builder pattern. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
1 parent c428bbc commit 134728b

File tree

86 files changed

+9025
-9293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+9025
-9293
lines changed

Cargo.lock

Lines changed: 64 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ netlink-packet-route = "0.28"
6464
netlink-sys = "0.8"
6565
num-derive = "0.4"
6666
num-traits = "0.2"
67+
phf = { version = "0.13", features = ["macros"] }
6768
pickledb = "0.5"
6869
prefix-trie = { version = "0.8", default-features = false, features = ["ipnetwork"] }
6970
prost = "0.14"
@@ -97,6 +98,7 @@ borrowed_box = "allow"
9798
field_reassign_with_default = "allow"
9899
large_enum_variant = "allow"
99100
manual_range_contains = "allow"
101+
match_single_binding = "allow"
100102
single_match = "allow"
101103
too_many_arguments = "allow"
102104

holo-bfd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ libc.workspace = true
1818
nix.workspace = true
1919
num-derive.workspace = true
2020
num-traits.workspace = true
21+
phf.workspace = true
2122
rand.workspace = true
2223
serde.workspace = true
2324
serde_json.workspace = true

holo-bfd/build.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
// SPDX-License-Identifier: MIT
55
//
66

7+
use holo_northbound::yang_codegen;
8+
use holo_yang as yang;
9+
710
fn main() {
8-
let modules = holo_yang::implemented_modules::BFD;
9-
holo_northbound::yang_codegen::build(modules);
11+
let mut yang_ctx = yang::new_context();
12+
let modules = yang::implemented_modules::BFD;
13+
yang::load_modules(&mut yang_ctx, modules);
14+
yang_codegen::build_yang_objects(&yang_ctx, modules, "yang_objects.rs");
15+
yang_codegen::build_yang_ops(&yang_ctx, modules, None, "yang_ops.rs");
1016
}

holo-bfd/src/northbound/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ use crate::master::Master;
1919
// Autogenerated code from YANG modules.
2020
#[allow(unused_imports, unused_variables)]
2121
pub mod yang_gen {
22-
pub use crate::northbound::yang_gen::routing::control_plane_protocols::control_plane_protocol::bfd;
23-
include!(concat!(env!("OUT_DIR"), "/yang_gen.rs"));
22+
pub use routing::control_plane_protocols::control_plane_protocol::bfd;
23+
24+
include!(concat!(env!("OUT_DIR"), "/yang_objects.rs"));
25+
pub mod ops {
26+
use crate::master::Master;
27+
type Provider = Master;
28+
include!(concat!(env!("OUT_DIR"), "/yang_ops.rs"));
29+
}
2430
}
2531

2632
// ===== impl Master =====

holo-bfd/src/northbound/rpc.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@
44
// SPDX-License-Identifier: MIT
55
//
66

7-
use std::sync::LazyLock as Lazy;
8-
9-
use holo_northbound::rpc::{Callbacks, CallbacksBuilder, Provider};
7+
use holo_northbound::rpc::{Provider, YangOps};
108

119
use crate::master::Master;
12-
13-
pub static CALLBACKS: Lazy<Callbacks<Master>> = Lazy::new(load_callbacks);
14-
15-
// ===== callbacks =====
16-
17-
fn load_callbacks() -> Callbacks<Master> {
18-
CallbacksBuilder::<Master>::default().build()
19-
}
20-
21-
// ===== impl Master =====
10+
use crate::northbound::yang_gen;
2211

2312
impl Provider for Master {
24-
fn callbacks() -> &'static Callbacks<Master> {
25-
&CALLBACKS
26-
}
13+
const YANG_OPS: YangOps<Self> = yang_gen::ops::YANG_OPS_RPC;
2714
}

0 commit comments

Comments
 (0)