summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2023-06-27 13:58:54 -0400
committerChristian Hopps <chopps@labn.net>2023-06-27 18:00:56 -0400
commitdbb1bc6f355ae53ce1f2402a1ac196e9f9e18a42 (patch)
tree95440d9560362977bbd485ffdab1b30f7f8f5cc0 /lib
parent6267c2aaad2a503ae24885d3ffc9a7867fccb6c0 (diff)
mgmtd: consolidate getcfg and getdata msgs into "get"
eliminates tons of copy and paste code. Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/mgmt.proto44
-rw-r--r--lib/mgmt_fe_client.c117
-rw-r--r--lib/mgmt_fe_client.h32
-rw-r--r--lib/vty.c51
-rw-r--r--lib/vty.h8
5 files changed, 70 insertions, 182 deletions
diff --git a/lib/mgmt.proto b/lib/mgmt.proto
index ac44eefd9e..14d00fa100 100644
--- a/lib/mgmt.proto
+++ b/lib/mgmt.proto
@@ -267,36 +267,22 @@ message FeCommitConfigReply {
optional string error_if_any = 8;
}
-message FeGetConfigReq {
+message FeGetReq {
required uint64 session_id = 1;
- required DatastoreId ds_id = 2;
- required uint64 req_id = 3;
- repeated YangGetDataReq data = 4;
-}
-
-message FeGetConfigReply {
- required uint64 session_id = 1;
- required DatastoreId ds_id = 2;
- required uint64 req_id = 3;
- required bool success = 4;
- optional string error_if_any = 5;
- optional YangDataReply data = 6;
-}
-
-message FeGetDataReq {
- required uint64 session_id = 1;
- required DatastoreId ds_id = 2;
- required uint64 req_id = 3;
- repeated YangGetDataReq data = 4;
+ required bool config = 2;
+ required DatastoreId ds_id = 3;
+ required uint64 req_id = 4;
+ repeated YangGetDataReq data = 5;
}
-message FeGetDataReply {
+message FeGetReply {
required uint64 session_id = 1;
- required DatastoreId ds_id = 2;
- required uint64 req_id = 3;
- required bool success = 4;
- optional string error_if_any = 5;
- optional YangDataReply data = 6;
+ required bool config = 2;
+ required DatastoreId ds_id = 3;
+ required uint64 req_id = 4;
+ required bool success = 5;
+ optional string error_if_any = 6;
+ optional YangDataReply data = 7;
}
message FeNotifyDataReq {
@@ -322,10 +308,8 @@ message FeMessage {
FeSetConfigReply setcfg_reply = 8;
FeCommitConfigReq commcfg_req = 9;
FeCommitConfigReply commcfg_reply = 10;
- FeGetConfigReq getcfg_req = 11;
- FeGetConfigReply getcfg_reply = 12;
- FeGetDataReq getdata_req = 13;
- FeGetDataReply getdata_reply = 14;
+ FeGetReq get_req = 11;
+ FeGetReply get_reply = 12;
FeNotifyDataReq notify_data_req = 15;
FeRegisterNotifyReq regnotify_req = 16;
}
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c
index 45d57175d6..da19db463f 100644
--- a/lib/mgmt_fe_client.c
+++ b/lib/mgmt_fe_client.c
@@ -247,58 +247,31 @@ int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
return mgmt_fe_client_send_msg(client, &fe_msg, false);
}
-int mgmt_fe_send_getcfg_req(struct mgmt_fe_client *client, uint64_t session_id,
- uint64_t req_id, Mgmtd__DatastoreId ds_id,
- Mgmtd__YangGetDataReq *data_req[],
- int num_data_reqs)
+int mgmt_fe_send_get_req(struct mgmt_fe_client *client, uint64_t session_id,
+ uint64_t req_id, bool is_config,
+ Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq *data_req[], int num_data_reqs)
{
(void)req_id;
Mgmtd__FeMessage fe_msg;
- Mgmtd__FeGetConfigReq getcfg_req;
+ Mgmtd__FeGetReq getcfg_req;
- mgmtd__fe_get_config_req__init(&getcfg_req);
+ mgmtd__fe_get_req__init(&getcfg_req);
getcfg_req.session_id = session_id;
+ getcfg_req.config = is_config;
getcfg_req.ds_id = ds_id;
getcfg_req.req_id = req_id;
getcfg_req.data = data_req;
getcfg_req.n_data = (size_t)num_data_reqs;
mgmtd__fe_message__init(&fe_msg);
- fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ;
- fe_msg.getcfg_req = &getcfg_req;
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REQ;
+ fe_msg.get_req = &getcfg_req;
- MGMTD_FE_CLIENT_DBG(
- "Sending GET_CONFIG_REQ message for DS:%s session-id %" PRIu64
- " (#xpaths:%d)",
- dsid2name(ds_id), session_id, num_data_reqs);
-
- return mgmt_fe_client_send_msg(client, &fe_msg, false);
-}
-
-int mgmt_fe_send_getdata_req(struct mgmt_fe_client *client, uint64_t session_id,
- uint64_t req_id, Mgmtd__DatastoreId ds_id,
- Mgmtd__YangGetDataReq *data_req[],
- int num_data_reqs)
-{
- (void)req_id;
- Mgmtd__FeMessage fe_msg;
- Mgmtd__FeGetDataReq getdata_req;
-
- mgmtd__fe_get_data_req__init(&getdata_req);
- getdata_req.session_id = session_id;
- getdata_req.ds_id = ds_id;
- getdata_req.req_id = req_id;
- getdata_req.data = data_req;
- getdata_req.n_data = (size_t)num_data_reqs;
-
- mgmtd__fe_message__init(&fe_msg);
- fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ;
- fe_msg.getdata_req = &getdata_req;
-
- MGMTD_FE_CLIENT_DBG(
- "Sending GET_CONFIG_REQ message for DS:%s session-id %" PRIu64
- " (#xpaths:%d)",
- dsid2name(ds_id), session_id, num_data_reqs);
+ MGMTD_FE_CLIENT_DBG("Sending GET_REQ (iscfg %d) message for DS:%s session-id %" PRIu64
+ " (#xpaths:%d)",
+ is_config, dsid2name(ds_id), session_id,
+ num_data_reqs);
return mgmt_fe_client_send_msg(client, &fe_msg, false);
}
@@ -434,58 +407,33 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
fe_msg->commcfg_reply->validate_only,
fe_msg->commcfg_reply->error_if_any);
break;
- case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY:
- MGMTD_FE_CLIENT_DBG("Got GETCFG_REPLY for session-id %" PRIu64,
- fe_msg->getcfg_reply->session_id);
+ case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY:
+ MGMTD_FE_CLIENT_DBG("Got GET_REPLY for session-id %" PRIu64,
+ fe_msg->get_reply->session_id);
- session = mgmt_fe_find_session_by_session_id(
- client, fe_msg->getcfg_reply->session_id);
+ session =
+ mgmt_fe_find_session_by_session_id(client,
+ fe_msg->get_reply
+ ->session_id);
if (session && session->client &&
session->client->cbs.get_data_notify)
(*session->client->cbs.get_data_notify)(
client, client->user_data, session->client_id,
- fe_msg->getcfg_reply->session_id,
- session->user_ctx, fe_msg->getcfg_reply->req_id,
- fe_msg->getcfg_reply->success,
- fe_msg->getcfg_reply->ds_id,
- fe_msg->getcfg_reply->data
- ? fe_msg->getcfg_reply->data->data
- : NULL,
- fe_msg->getcfg_reply->data
- ? fe_msg->getcfg_reply->data->n_data
- : 0,
- fe_msg->getcfg_reply->data
- ? fe_msg->getcfg_reply->data->next_indx
- : 0,
- fe_msg->getcfg_reply->error_if_any);
- break;
- case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY:
- MGMTD_FE_CLIENT_DBG("Got GETDATA_REPLY for session-id %" PRIu64,
- fe_msg->getdata_reply->session_id);
-
- session = mgmt_fe_find_session_by_session_id(
- client, fe_msg->getdata_reply->session_id);
-
- if (session && session->client &&
- session->client->cbs.get_data_notify)
- (*session->client->cbs.get_data_notify)(
- client, client->user_data, session->client_id,
- fe_msg->getdata_reply->session_id,
- session->user_ctx,
- fe_msg->getdata_reply->req_id,
- fe_msg->getdata_reply->success,
- fe_msg->getdata_reply->ds_id,
- fe_msg->getdata_reply->data
- ? fe_msg->getdata_reply->data->data
+ fe_msg->get_reply->session_id,
+ session->user_ctx, fe_msg->get_reply->req_id,
+ fe_msg->get_reply->success,
+ fe_msg->get_reply->ds_id,
+ fe_msg->get_reply->data
+ ? fe_msg->get_reply->data->data
: NULL,
- fe_msg->getdata_reply->data
- ? fe_msg->getdata_reply->data->n_data
+ fe_msg->get_reply->data
+ ? fe_msg->get_reply->data->n_data
: 0,
- fe_msg->getdata_reply->data
- ? fe_msg->getdata_reply->data->next_indx
+ fe_msg->get_reply->data
+ ? fe_msg->get_reply->data->next_indx
: 0,
- fe_msg->getdata_reply->error_if_any);
+ fe_msg->get_reply->error_if_any);
break;
case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ:
@@ -502,8 +450,7 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client,
case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ:
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ:
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ:
- case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ:
- case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ:
case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
default:
/*
diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h
index 532fee4397..286141da44 100644
--- a/lib/mgmt_fe_client.h
+++ b/lib/mgmt_fe_client.h
@@ -294,7 +294,10 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
bool validate_only, bool abort);
/*
- * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
+ * Send GET_REQ to MGMTD for one or more config data item(s).
+ *
+ * If is_config is true gets config from the MGMTD datastore, otherwise
+ * operational state is queried from the backend clients.
*
* lib_hndl
* Client library handler.
@@ -302,6 +305,9 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
* session_id
* Client session ID.
*
+ * is_config
+ * True if get-config else get-data.
+ *
* req_id
* Client request ID.
*
@@ -309,31 +315,19 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
* Datastore ID (Running/Candidate)
*
* data_req
- * Get config requested.
+ * Get xpaths requested.
*
* num_req
- * Number of get config requests.
+ * Number of get xpath requests.
*
* Returns:
* 0 on success, otherwise msg_conn_send_msg() return values.
*/
-extern int mgmt_fe_send_getcfg_req(struct mgmt_fe_client *client,
- uint64_t session_id, uint64_t req_id,
- Mgmtd__DatastoreId ds_id,
- Mgmtd__YangGetDataReq **data_req,
- int num_reqs);
+extern int mgmt_fe_send_get_req(struct mgmt_fe_client *client,
+ uint64_t session_id, uint64_t req_id,
+ bool is_config, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq **data_req, int num_reqs);
-/*
- * Send GET_DATA_REQ to MGMTD for one or more data item(s).
- *
- * Similar to get config request but supports getting data
- * from operational ds aka backend clients directly.
- */
-extern int mgmt_fe_send_getdata_req(struct mgmt_fe_client *client,
- uint64_t session_id, uint64_t req_id,
- Mgmtd__DatastoreId ds_id,
- Mgmtd__YangGetDataReq **data_req,
- int num_reqs);
/*
* Send NOTIFY_REGISTER_REQ to MGMTD daemon.
diff --git a/lib/vty.c b/lib/vty.c
index fc6bed6a0a..c9de00a271 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -3822,8 +3822,9 @@ int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort)
return 0;
}
-int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
- const char **xpath_list, int num_req)
+int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
+ Mgmtd__DatastoreId datastore, const char **xpath_list,
+ int num_req)
{
Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
@@ -3841,13 +3842,11 @@ int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
get_req[i].data = &yang_data[i];
getreq[i] = &get_req[i];
}
- if (mgmt_fe_send_getcfg_req(mgmt_fe_client, vty->mgmt_session_id,
- vty->mgmt_req_id, datastore, getreq,
- num_req)) {
- zlog_err(
- "Failed to send GET-CONFIG to MGMTD for req-id %" PRIu64
- ".",
- vty->mgmt_req_id);
+ if (mgmt_fe_send_get_req(mgmt_fe_client, vty->mgmt_session_id,
+ vty->mgmt_req_id, is_config, datastore, getreq,
+ num_req)) {
+ zlog_err("Failed to send GET- to MGMTD for req-id %" PRIu64 ".",
+ vty->mgmt_req_id);
vty_out(vty, "Failed to send GET-CONFIG to MGMTD!\n");
return -1;
}
@@ -3857,40 +3856,6 @@ int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
return 0;
}
-int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
- const char **xpath_list, int num_req)
-{
- Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
- Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
- Mgmtd__YangGetDataReq *getreq[VTY_MAXCFGCHANGES];
- int i;
-
- vty->mgmt_req_id++;
-
- for (i = 0; i < num_req; i++) {
- mgmt_yang_get_data_req_init(&get_req[i]);
- mgmt_yang_data_init(&yang_data[i]);
-
- yang_data->xpath = (char *)xpath_list[i];
-
- get_req[i].data = &yang_data[i];
- getreq[i] = &get_req[i];
- }
- if (mgmt_fe_send_getdata_req(mgmt_fe_client, vty->mgmt_session_id,
- vty->mgmt_req_id, datastore, getreq,
- num_req)) {
- zlog_err("Failed to send GET-DATA to MGMTD for req-id %" PRIu64
- ".",
- vty->mgmt_req_id);
- vty_out(vty, "Failed to send GET-DATA to MGMTD!\n");
- return -1;
- }
-
- vty->mgmt_req_pending_cmd = "MESSAGE_GETDATA_REQ";
-
- return 0;
-}
-
/* Install vty's own commands like `who' command. */
void vty_init(struct event_loop *master_thread, bool do_command_logging)
{
diff --git a/lib/vty.h b/lib/vty.h
index 8fb1483e5b..ac3d2e5019 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -411,11 +411,9 @@ extern bool mgmt_vty_read_configs(void);
extern int vty_mgmt_send_config_data(struct vty *vty, bool implicit_commit);
extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
bool abort);
-extern int vty_mgmt_send_get_config(struct vty *vty,
- Mgmtd__DatastoreId datastore,
- const char **xpath_list, int num_req);
-extern int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
- const char **xpath_list, int num_req);
+extern int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
+ Mgmtd__DatastoreId datastore,
+ const char **xpath_list, int num_req);
extern int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
bool lock, bool scok);
extern void vty_mgmt_resume_response(struct vty *vty, bool success);