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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 34 additions & 20 deletions proto/holo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ service Northbound {
// Retrieve the specified schema data from the target.
rpc GetSchema(GetSchemaRequest) returns (GetSchemaResponse) {}

// Retrieve configuration data, state data or both from the target.
rpc Get(GetRequest) returns (GetResponse) {}
// Retrieve state data from the target.
rpc GetState(GetStateRequest) returns (GetStateResponse) {}

// Retrieve configuration data from the target.
rpc GetConfig(GetConfigRequest) returns (GetConfigResponse) {}

// Validate the configuration without committing it.
rpc Validate(ValidateRequest) returns (ValidateResponse) {}
Expand Down Expand Up @@ -106,43 +109,54 @@ message GetSchemaResponse {
}

//
// RPC: Get()
// RPC: GetState()
//
message GetRequest {
// Type of elements within the data tree.
enum DataType {
// All data elements.
ALL = 0;
message GetStateRequest {
// Encoding to be used.
Encoding encoding = 1;

// Config elements.
CONFIG = 1;
// Include implicit default nodes.
bool with_defaults = 2;

// State elements.
STATE = 2;
}
// Target YANG path.
Path path = 3;
}

message GetStateResponse {
// Return values:
// - grpc::StatusCode::OK: Success.
// - grpc::StatusCode::INVALID_ARGUMENT: Invalid YANG data path.

// The type of data being requested.
DataType type = 1;
// Timestamp in nanoseconds since Epoch.
int64 timestamp = 1;

// The requested state data.
DataTree data = 2;
}

//
// RPC: GetConfig()
//
message GetConfigRequest {
// Encoding to be used.
Encoding encoding = 2;
Encoding encoding = 1;

// Include implicit default nodes.
bool with_defaults = 3;
bool with_defaults = 2;

// Target YANG path.
Path path = 4;
Path path = 3;
}

message GetResponse {
message GetConfigResponse {
// Return values:
// - grpc::StatusCode::OK: Success.
// - grpc::StatusCode::INVALID_ARGUMENT: Invalid YANG data path.

// Timestamp in nanoseconds since Epoch.
int64 timestamp = 1;

// The requested data.
// The requested configuration data.
DataTree data = 2;
}

Expand Down
45 changes: 36 additions & 9 deletions src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,35 @@ impl GrpcClient {
}
}

pub fn get(
pub fn get_config(
&mut self,
data_type: proto::get_request::DataType,
format: DataFormat,
with_defaults: bool,
xpath: Option<String>,
) -> Result<proto::data_tree::Data, Error> {
let path = xpath.map(|x| proto::Path::from_xpath(&x));
let data = self
.rpc_sync_get(proto::GetRequest {
r#type: data_type as i32,
.rpc_sync_get_config(proto::GetConfigRequest {
encoding: proto::Encoding::from(format) as i32,
with_defaults,
path,
})
.map_err(Error::Backend)?
.into_inner()
.data
.unwrap();
Ok(data.data.unwrap())
}

pub fn get_state(
&mut self,
format: DataFormat,
with_defaults: bool,
xpath: Option<String>,
) -> Result<proto::data_tree::Data, Error> {
let path = xpath.map(|x| proto::Path::from_xpath(&x));
let data = self
.rpc_sync_get_state(proto::GetStateRequest {
encoding: proto::Encoding::from(format) as i32,
with_defaults,
path,
Expand Down Expand Up @@ -183,12 +201,20 @@ impl GrpcClient {
self.runtime.block_on(self.client.get_schema(request))
}

fn rpc_sync_get(
fn rpc_sync_get_config(
&mut self,
request: proto::GetConfigRequest,
) -> Result<tonic::Response<proto::GetConfigResponse>, tonic::Status> {
let request = tonic::Request::new(request);
self.runtime.block_on(self.client.get_config(request))
}

fn rpc_sync_get_state(
&mut self,
request: proto::GetRequest,
) -> Result<tonic::Response<proto::GetResponse>, tonic::Status> {
request: proto::GetStateRequest,
) -> Result<tonic::Response<proto::GetStateResponse>, tonic::Status> {
let request = tonic::Request::new(request);
self.runtime.block_on(self.client.get(request))
self.runtime.block_on(self.client.get_state(request))
}

fn rpc_sync_commit(
Expand Down Expand Up @@ -266,7 +292,8 @@ impl proto::Path {
Some(pos) => {
let name = &segment[..pos];
let mut keys = HashMap::new();
for kv in segment[pos..].split('[').filter(|s| !s.is_empty())
for kv in
segment[pos..].split('[').filter(|s| !s.is_empty())
{
let kv = kv.trim_end_matches(']');
if let Some(eq_pos) = kv.find('=') {
Expand Down
Loading
Loading