Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions holo-daemon/src/northbound/client/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub mod client {
pub struct GetRequest {
pub data_type: DataType,
pub path: Option<Path>,
pub exclude: Vec<Path>,
pub responder: Responder<Result<GetResponse>>,
}

Expand Down
4 changes: 4 additions & 0 deletions holo-daemon/src/northbound/client/gnmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl proto::GNmi for GNmiService {
let nb_request = api::client::GetRequest {
data_type,
path: Some(path),
exclude: vec![],
responder: responder_tx,
};
let nb_request = api::client::Request::Get(nb_request);
Expand Down Expand Up @@ -400,6 +401,7 @@ impl GNmiService {
let nb_request = api::client::GetRequest {
data_type: api::DataType::Configuration,
path: None,
exclude: vec![],
responder: responder_tx,
};
let nb_request = api::client::Request::Get(nb_request);
Expand All @@ -417,6 +419,8 @@ impl From<proto::Path> for Path {
fn from(path: proto::Path) -> Self {
Path {
elems: path.elem.into_iter().map(PathElem::from).collect(),
// gNMI paths carry no depth limit.
max_depth: None,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions holo-daemon/src/northbound/client/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ impl proto::Northbound for NorthboundService {
.map_err(|_| Status::invalid_argument("Invalid data encoding"))?;
let with_defaults = grpc_request.with_defaults;
let path = grpc_request.path.map(Path::from);
let exclude =
grpc_request.exclude.into_iter().map(Path::from).collect();
let nb_request = api::client::Request::Get(api::client::GetRequest {
data_type,
path,
exclude,
responder: responder_tx,
});
self.request_tx.send(nb_request).await.unwrap();
Expand Down Expand Up @@ -518,6 +521,8 @@ impl From<proto::Path> for Path {
fn from(path: proto::Path) -> Self {
Path {
elems: path.elem.into_iter().map(PathElem::from).collect(),
// Wire convention: 0 = unlimited.
max_depth: (path.max_depth != 0).then_some(path.max_depth),
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions holo-daemon/src/northbound/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ impl Northbound {
match request {
capi::client::Request::Get(request) => {
let response = self
.process_client_get(request.data_type, request.path)
.process_client_get(
request.data_type,
request.path,
request.exclude,
)
.await;
let _ = request.responder.send(response);
}
Expand Down Expand Up @@ -236,13 +240,16 @@ impl Northbound {
&self,
data_type: capi::DataType,
path: Option<Path>,
exclude: Vec<Path>,
) -> Result<capi::client::GetResponse> {
let path = path.as_ref();
let dtree = match data_type {
capi::DataType::State => self.get_state(path).await?,
capi::DataType::State => self.get_state(path, exclude).await?,
// Filtering applies only to state data; configuration is
// returned as-is from the running datastore.
capi::DataType::Configuration => self.get_configuration(path)?,
capi::DataType::All => {
let mut dtree_state = self.get_state(path).await?;
let mut dtree_state = self.get_state(path, exclude).await?;
let dtree_config = self.get_configuration(path)?;
dtree_state
.merge(&dtree_config)
Expand Down Expand Up @@ -571,6 +578,7 @@ impl Northbound {
async fn get_state(
&self,
path: Option<&Path>,
exclude: Vec<Path>,
) -> Result<DataTree<'static>> {
let yang_ctx = YANG_CTX.get().unwrap();
let mut dtree = DataTree::new(yang_ctx);
Expand All @@ -581,6 +589,7 @@ impl Northbound {
let request =
papi::daemon::Request::Get(papi::daemon::GetRequest {
path: path.cloned(),
exclude: exclude.clone(),
responder: Some(responder_tx),
});
daemon_tx.send(request).await.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions holo-northbound/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub mod daemon {
#[derive(Debug, Deserialize, Serialize)]
pub struct GetRequest {
pub path: Option<Path>,
#[serde(default)]
pub exclude: Vec<Path>,
#[serde(skip)]
pub responder: Option<Responder<Result<GetResponse, Error>>>,
}
Expand Down
17 changes: 14 additions & 3 deletions holo-northbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub struct YangPath(&'static str);
pub struct Path {
// Ordered list of elements forming the path.
pub elems: Vec<PathElem>,
// Maximum traversal depth beyond the target.
// `None` = unlimited; `Some(0)` = target only, no descendants.
#[serde(default)]
pub max_depth: Option<u32>,
}

// A single element within a YANG data path.
Expand Down Expand Up @@ -149,7 +153,10 @@ impl Path {
elems.push(PathElem { name, keys });
}

Path { elems }
Path {
elems,
max_depth: None,
}
}

pub fn from_yang_path(s: &str) -> Path {
Expand Down Expand Up @@ -182,7 +189,10 @@ impl Path {
})
.collect();

Path { elems }
Path {
elems,
max_depth: None,
}
}
}

Expand Down Expand Up @@ -249,7 +259,8 @@ pub fn process_northbound_msg<Provider>(
}
}
api::daemon::Request::Get(request) => {
let response = state::process_get(provider, request.path);
let response =
state::process_get(provider, request.path, request.exclude);
if let Some(responder) = request.responder {
responder.send(response).unwrap();
}
Expand Down
Loading
Loading