-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system: introduce the
holo-system
component
Introduce `holo-system`, implementing the following subset of the ietf-system YANG module: module: ietf-system +--rw system | +--rw contact? string | +--rw hostname? inet:domain-name | +--rw location? string +--ro system-state +--ro platform | +--ro os-name? string | +--ro os-release? string | +--ro os-version? string | +--ro machine? string +--ro clock +--ro current-datetime? yang:date-and-time +--ro boot-datetime? yang:date-and-time The main motivation for this component is to provide a centralized place for storing hostname information and sharing it with protocol instances (both IS-IS and OSPF have TLVs for flooding hostname information). Additionally, including the hostname in the configuration is necessary for implementing a persistent hostname in holo-cli. Closes #20 Signed-off-by: Renato Westphal <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,445 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,7 @@ Holo supports the following IETF RFCs and Internet drafts: | |
| ietf-routing@2018-03-13 | 100.00% | 85.71% | - | - | [92.31%](http://westphal.com.br/holo/ietf-routing.html) | | ||
| ietf-segment-routing-mpls@2021-05-26 | 62.50% | 0.00% | - | 23.53% | [32.76%](http://westphal.com.br/holo/ietf-segment-routing-mpls.html) | | ||
| ietf-segment-routing@2021-05-26 | 100.00% | - | - | - | [100.00%](http://westphal.com.br/holo/ietf-segment-routing.html) | | ||
| ietf-system@2014-08-06 | 26.67% | 60.00% | 0.00% | - | [38.24%](http://westphal.com.br/holo/[email protected]) | | ||
|
||
## Funding | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "holo-system" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
sysinfo = "0.30" | ||
|
||
async-trait.workspace = true | ||
capctl.workspace = true | ||
chrono.workspace = true | ||
derive-new.workspace = true | ||
tokio.workspace = true | ||
tracing.workspace = true | ||
yang3.workspace = true | ||
|
||
holo-northbound = { path = "../holo-northbound" } | ||
holo-utils = { path = "../holo-utils" } | ||
holo-yang = { path = "../holo-yang" } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2023 The Holo Core Contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use holo_utils::ibus::{IbusMsg, IbusSender}; | ||
|
||
use crate::Master; | ||
|
||
// ===== global functions ===== | ||
|
||
pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) { | ||
match msg { | ||
IbusMsg::HostnameQuery => { | ||
notify_hostname_update( | ||
&master.ibus_tx, | ||
master.config.hostname.clone(), | ||
); | ||
} | ||
// Ignore other events. | ||
_ => {} | ||
} | ||
} | ||
|
||
pub(crate) fn notify_hostname_update( | ||
ibus_tx: &IbusSender, | ||
hostname: Option<String>, | ||
) { | ||
let msg = IbusMsg::HostnameUpdate(hostname); | ||
notify(ibus_tx, msg); | ||
} | ||
|
||
// ===== helper functions ===== | ||
|
||
fn notify(ibus_tx: &IbusSender, msg: IbusMsg) { | ||
let _ = ibus_tx.send(msg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
#![feature(let_chains)] | ||
|
||
mod ibus; | ||
pub mod northbound; | ||
|
||
use holo_northbound::{ | ||
process_northbound_msg, NbDaemonReceiver, NbDaemonSender, NbProviderSender, | ||
ProviderBase, | ||
}; | ||
use holo_utils::ibus::{IbusReceiver, IbusSender}; | ||
use northbound::configuration::SystemCfg; | ||
use tokio::sync::mpsc; | ||
use tracing::Instrument; | ||
|
||
#[derive(Debug)] | ||
pub struct Master { | ||
// Northbound Tx channel. | ||
pub nb_tx: NbProviderSender, | ||
// Internal bus Tx channel. | ||
pub ibus_tx: IbusSender, | ||
// System configuration. | ||
pub config: SystemCfg, | ||
} | ||
|
||
// ===== impl Master ===== | ||
|
||
impl Master { | ||
async fn run( | ||
&mut self, | ||
mut nb_rx: NbDaemonReceiver, | ||
mut ibus_rx: IbusReceiver, | ||
) { | ||
let mut resources = vec![]; | ||
|
||
loop { | ||
tokio::select! { | ||
Some(request) = nb_rx.recv() => { | ||
process_northbound_msg( | ||
self, | ||
&mut resources, | ||
request, | ||
) | ||
.await; | ||
} | ||
Ok(msg) = ibus_rx.recv() => { | ||
ibus::process_msg(self, msg); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ===== global functions ===== | ||
|
||
pub fn start( | ||
nb_tx: NbProviderSender, | ||
ibus_tx: IbusSender, | ||
ibus_rx: IbusReceiver, | ||
) -> NbDaemonSender { | ||
let (nb_daemon_tx, nb_daemon_rx) = mpsc::channel(4); | ||
|
||
tokio::spawn(async move { | ||
let mut master = Master { | ||
nb_tx, | ||
ibus_tx, | ||
config: Default::default(), | ||
}; | ||
|
||
// Run task main loop. | ||
let span = Master::debug_span(""); | ||
master.run(nb_daemon_rx, ibus_rx).instrument(span).await; | ||
}); | ||
|
||
nb_daemon_tx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
use std::sync::LazyLock as Lazy; | ||
|
||
use async_trait::async_trait; | ||
use holo_northbound::configuration::{ | ||
self, Callbacks, CallbacksBuilder, Provider, | ||
}; | ||
use holo_northbound::yang::system; | ||
use holo_utils::yang::DataNodeRefExt; | ||
|
||
use crate::{ibus, Master}; | ||
|
||
static CALLBACKS: Lazy<configuration::Callbacks<Master>> = | ||
Lazy::new(load_callbacks); | ||
|
||
#[derive(Debug, Default)] | ||
pub enum ListEntry { | ||
#[default] | ||
None, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Resource {} | ||
|
||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] | ||
pub enum Event { | ||
HostnameChange, | ||
} | ||
|
||
// ===== configuration structs ===== | ||
|
||
#[derive(Debug, Default)] | ||
pub struct SystemCfg { | ||
pub contact: Option<String>, | ||
pub hostname: Option<String>, | ||
pub location: Option<String>, | ||
} | ||
|
||
// ===== callbacks ===== | ||
|
||
fn load_callbacks() -> Callbacks<Master> { | ||
CallbacksBuilder::<Master>::default() | ||
.path(system::contact::PATH) | ||
.modify_apply(|master, args| { | ||
let contact = args.dnode.get_string(); | ||
master.config.contact = Some(contact); | ||
}) | ||
.delete_apply(|master, _args| { | ||
master.config.contact = None; | ||
}) | ||
.path(system::hostname::PATH) | ||
.modify_apply(|master, args| { | ||
let hostname = args.dnode.get_string(); | ||
master.config.hostname = Some(hostname); | ||
|
||
let event_queue = args.event_queue; | ||
event_queue.insert(Event::HostnameChange); | ||
}) | ||
.delete_apply(|master, args| { | ||
master.config.hostname = None; | ||
|
||
let event_queue = args.event_queue; | ||
event_queue.insert(Event::HostnameChange); | ||
}) | ||
.path(system::location::PATH) | ||
.modify_apply(|master, args| { | ||
let location = args.dnode.get_string(); | ||
master.config.location = Some(location); | ||
}) | ||
.delete_apply(|master, _args| { | ||
master.config.location = None; | ||
}) | ||
.build() | ||
} | ||
|
||
// ===== impl Master ===== | ||
|
||
#[async_trait] | ||
impl Provider for Master { | ||
type ListEntry = ListEntry; | ||
type Event = Event; | ||
type Resource = Resource; | ||
|
||
fn callbacks() -> Option<&'static Callbacks<Master>> { | ||
Some(&CALLBACKS) | ||
} | ||
|
||
async fn process_event(&mut self, event: Event) { | ||
match event { | ||
Event::HostnameChange => { | ||
ibus::notify_hostname_update( | ||
&self.ibus_tx, | ||
self.config.hostname.clone(), | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Copyright (c) The Holo Core Contributors | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
pub mod configuration; | ||
pub mod state; | ||
|
||
use holo_northbound::{rpc, ProviderBase}; | ||
use tracing::{debug_span, Span}; | ||
|
||
use crate::Master; | ||
|
||
// ===== impl Master ===== | ||
|
||
impl ProviderBase for Master { | ||
fn yang_modules() -> &'static [&'static str] { | ||
&["ietf-system"] | ||
} | ||
|
||
fn top_level_node(&self) -> String { | ||
"/ietf-system:system".to_owned() | ||
} | ||
|
||
fn debug_span(_name: &str) -> Span { | ||
debug_span!("system") | ||
} | ||
} | ||
|
||
// No RPC/Actions to implement. | ||
impl rpc::Provider for Master {} |
Oops, something went wrong.