mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 15:24:43 +00:00
mgmtd: consolidate getcfg and getdata msgs into "get"
eliminates tons of copy and paste code.
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit dbb1bc6f35
)
This commit is contained in:
parent
97639da4e1
commit
caae820204
@ -267,36 +267,22 @@ message FeCommitConfigReply {
|
|||||||
optional string error_if_any = 8;
|
optional string error_if_any = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FeGetConfigReq {
|
message FeGetReq {
|
||||||
required uint64 session_id = 1;
|
required uint64 session_id = 1;
|
||||||
required DatastoreId ds_id = 2;
|
required bool config = 2;
|
||||||
required uint64 req_id = 3;
|
required DatastoreId ds_id = 3;
|
||||||
repeated YangGetDataReq data = 4;
|
required uint64 req_id = 4;
|
||||||
|
repeated YangGetDataReq data = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message FeGetConfigReply {
|
message FeGetReply {
|
||||||
required uint64 session_id = 1;
|
required uint64 session_id = 1;
|
||||||
required DatastoreId ds_id = 2;
|
required bool config = 2;
|
||||||
required uint64 req_id = 3;
|
required DatastoreId ds_id = 3;
|
||||||
required bool success = 4;
|
required uint64 req_id = 4;
|
||||||
optional string error_if_any = 5;
|
required bool success = 5;
|
||||||
optional YangDataReply data = 6;
|
optional string error_if_any = 6;
|
||||||
}
|
optional YangDataReply data = 7;
|
||||||
|
|
||||||
message FeGetDataReq {
|
|
||||||
required uint64 session_id = 1;
|
|
||||||
required DatastoreId ds_id = 2;
|
|
||||||
required uint64 req_id = 3;
|
|
||||||
repeated YangGetDataReq data = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message FeGetDataReply {
|
|
||||||
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 FeNotifyDataReq {
|
message FeNotifyDataReq {
|
||||||
@ -322,10 +308,8 @@ message FeMessage {
|
|||||||
FeSetConfigReply setcfg_reply = 8;
|
FeSetConfigReply setcfg_reply = 8;
|
||||||
FeCommitConfigReq commcfg_req = 9;
|
FeCommitConfigReq commcfg_req = 9;
|
||||||
FeCommitConfigReply commcfg_reply = 10;
|
FeCommitConfigReply commcfg_reply = 10;
|
||||||
FeGetConfigReq getcfg_req = 11;
|
FeGetReq get_req = 11;
|
||||||
FeGetConfigReply getcfg_reply = 12;
|
FeGetReply get_reply = 12;
|
||||||
FeGetDataReq getdata_req = 13;
|
|
||||||
FeGetDataReply getdata_reply = 14;
|
|
||||||
FeNotifyDataReq notify_data_req = 15;
|
FeNotifyDataReq notify_data_req = 15;
|
||||||
FeRegisterNotifyReq regnotify_req = 16;
|
FeRegisterNotifyReq regnotify_req = 16;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
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,
|
int mgmt_fe_send_get_req(struct mgmt_fe_client *client, uint64_t session_id,
|
||||||
uint64_t req_id, Mgmtd__DatastoreId ds_id,
|
uint64_t req_id, bool is_config,
|
||||||
Mgmtd__YangGetDataReq *data_req[],
|
Mgmtd__DatastoreId ds_id,
|
||||||
int num_data_reqs)
|
Mgmtd__YangGetDataReq *data_req[], int num_data_reqs)
|
||||||
{
|
{
|
||||||
(void)req_id;
|
(void)req_id;
|
||||||
Mgmtd__FeMessage fe_msg;
|
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.session_id = session_id;
|
||||||
|
getcfg_req.config = is_config;
|
||||||
getcfg_req.ds_id = ds_id;
|
getcfg_req.ds_id = ds_id;
|
||||||
getcfg_req.req_id = req_id;
|
getcfg_req.req_id = req_id;
|
||||||
getcfg_req.data = data_req;
|
getcfg_req.data = data_req;
|
||||||
getcfg_req.n_data = (size_t)num_data_reqs;
|
getcfg_req.n_data = (size_t)num_data_reqs;
|
||||||
|
|
||||||
mgmtd__fe_message__init(&fe_msg);
|
mgmtd__fe_message__init(&fe_msg);
|
||||||
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ;
|
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REQ;
|
||||||
fe_msg.getcfg_req = &getcfg_req;
|
fe_msg.get_req = &getcfg_req;
|
||||||
|
|
||||||
MGMTD_FE_CLIENT_DBG(
|
MGMTD_FE_CLIENT_DBG("Sending GET_REQ (iscfg %d) message for DS:%s session-id %" PRIu64
|
||||||
"Sending GET_CONFIG_REQ message for DS:%s session-id %" PRIu64
|
|
||||||
" (#xpaths:%d)",
|
" (#xpaths:%d)",
|
||||||
dsid2name(ds_id), session_id, num_data_reqs);
|
is_config, 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);
|
|
||||||
|
|
||||||
return mgmt_fe_client_send_msg(client, &fe_msg, false);
|
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->validate_only,
|
||||||
fe_msg->commcfg_reply->error_if_any);
|
fe_msg->commcfg_reply->error_if_any);
|
||||||
break;
|
break;
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY:
|
case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY:
|
||||||
MGMTD_FE_CLIENT_DBG("Got GETCFG_REPLY for session-id %" PRIu64,
|
MGMTD_FE_CLIENT_DBG("Got GET_REPLY for session-id %" PRIu64,
|
||||||
fe_msg->getcfg_reply->session_id);
|
fe_msg->get_reply->session_id);
|
||||||
|
|
||||||
session = mgmt_fe_find_session_by_session_id(
|
session =
|
||||||
client, fe_msg->getcfg_reply->session_id);
|
mgmt_fe_find_session_by_session_id(client,
|
||||||
|
fe_msg->get_reply
|
||||||
|
->session_id);
|
||||||
|
|
||||||
if (session && session->client &&
|
if (session && session->client &&
|
||||||
session->client->cbs.get_data_notify)
|
session->client->cbs.get_data_notify)
|
||||||
(*session->client->cbs.get_data_notify)(
|
(*session->client->cbs.get_data_notify)(
|
||||||
client, client->user_data, session->client_id,
|
client, client->user_data, session->client_id,
|
||||||
fe_msg->getcfg_reply->session_id,
|
fe_msg->get_reply->session_id,
|
||||||
session->user_ctx, fe_msg->getcfg_reply->req_id,
|
session->user_ctx, fe_msg->get_reply->req_id,
|
||||||
fe_msg->getcfg_reply->success,
|
fe_msg->get_reply->success,
|
||||||
fe_msg->getcfg_reply->ds_id,
|
fe_msg->get_reply->ds_id,
|
||||||
fe_msg->getcfg_reply->data
|
fe_msg->get_reply->data
|
||||||
? fe_msg->getcfg_reply->data->data
|
? fe_msg->get_reply->data->data
|
||||||
: NULL,
|
: NULL,
|
||||||
fe_msg->getcfg_reply->data
|
fe_msg->get_reply->data
|
||||||
? fe_msg->getcfg_reply->data->n_data
|
? fe_msg->get_reply->data->n_data
|
||||||
: 0,
|
: 0,
|
||||||
fe_msg->getcfg_reply->data
|
fe_msg->get_reply->data
|
||||||
? fe_msg->getcfg_reply->data->next_indx
|
? fe_msg->get_reply->data->next_indx
|
||||||
: 0,
|
: 0,
|
||||||
fe_msg->getcfg_reply->error_if_any);
|
fe_msg->get_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
|
|
||||||
: NULL,
|
|
||||||
fe_msg->getdata_reply->data
|
|
||||||
? fe_msg->getdata_reply->data->n_data
|
|
||||||
: 0,
|
|
||||||
fe_msg->getdata_reply->data
|
|
||||||
? fe_msg->getdata_reply->data->next_indx
|
|
||||||
: 0,
|
|
||||||
fe_msg->getdata_reply->error_if_any);
|
|
||||||
break;
|
break;
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_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_LOCKDS_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ:
|
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
|
case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
|
@ -294,7 +294,10 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
|
|||||||
bool validate_only, bool abort);
|
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
|
* lib_hndl
|
||||||
* Client library handler.
|
* Client library handler.
|
||||||
@ -302,6 +305,9 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
|
|||||||
* session_id
|
* session_id
|
||||||
* Client session ID.
|
* Client session ID.
|
||||||
*
|
*
|
||||||
|
* is_config
|
||||||
|
* True if get-config else get-data.
|
||||||
|
*
|
||||||
* req_id
|
* req_id
|
||||||
* Client request ID.
|
* Client request ID.
|
||||||
*
|
*
|
||||||
@ -309,31 +315,19 @@ extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client,
|
|||||||
* Datastore ID (Running/Candidate)
|
* Datastore ID (Running/Candidate)
|
||||||
*
|
*
|
||||||
* data_req
|
* data_req
|
||||||
* Get config requested.
|
* Get xpaths requested.
|
||||||
*
|
*
|
||||||
* num_req
|
* num_req
|
||||||
* Number of get config requests.
|
* Number of get xpath requests.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 on success, otherwise msg_conn_send_msg() return values.
|
* 0 on success, otherwise msg_conn_send_msg() return values.
|
||||||
*/
|
*/
|
||||||
extern int mgmt_fe_send_getcfg_req(struct mgmt_fe_client *client,
|
extern int mgmt_fe_send_get_req(struct mgmt_fe_client *client,
|
||||||
uint64_t session_id, uint64_t req_id,
|
uint64_t session_id, uint64_t req_id,
|
||||||
Mgmtd__DatastoreId ds_id,
|
bool is_config, Mgmtd__DatastoreId ds_id,
|
||||||
Mgmtd__YangGetDataReq **data_req,
|
Mgmtd__YangGetDataReq **data_req, int num_reqs);
|
||||||
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.
|
* Send NOTIFY_REGISTER_REQ to MGMTD daemon.
|
||||||
|
47
lib/vty.c
47
lib/vty.c
@ -3822,8 +3822,9 @@ int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
|
int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
|
||||||
const char **xpath_list, int num_req)
|
Mgmtd__DatastoreId datastore, const char **xpath_list,
|
||||||
|
int num_req)
|
||||||
{
|
{
|
||||||
Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
|
Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
|
||||||
Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
|
Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
|
||||||
@ -3841,12 +3842,10 @@ int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
|
|||||||
get_req[i].data = &yang_data[i];
|
get_req[i].data = &yang_data[i];
|
||||||
getreq[i] = &get_req[i];
|
getreq[i] = &get_req[i];
|
||||||
}
|
}
|
||||||
if (mgmt_fe_send_getcfg_req(mgmt_fe_client, vty->mgmt_session_id,
|
if (mgmt_fe_send_get_req(mgmt_fe_client, vty->mgmt_session_id,
|
||||||
vty->mgmt_req_id, datastore, getreq,
|
vty->mgmt_req_id, is_config, datastore, getreq,
|
||||||
num_req)) {
|
num_req)) {
|
||||||
zlog_err(
|
zlog_err("Failed to send GET- to MGMTD for req-id %" PRIu64 ".",
|
||||||
"Failed to send GET-CONFIG to MGMTD for req-id %" PRIu64
|
|
||||||
".",
|
|
||||||
vty->mgmt_req_id);
|
vty->mgmt_req_id);
|
||||||
vty_out(vty, "Failed to send GET-CONFIG to MGMTD!\n");
|
vty_out(vty, "Failed to send GET-CONFIG to MGMTD!\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -3857,40 +3856,6 @@ int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
|
|||||||
return 0;
|
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. */
|
/* Install vty's own commands like `who' command. */
|
||||||
void vty_init(struct event_loop *master_thread, bool do_command_logging)
|
void vty_init(struct event_loop *master_thread, bool do_command_logging)
|
||||||
{
|
{
|
||||||
|
@ -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_config_data(struct vty *vty, bool implicit_commit);
|
||||||
extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
|
extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
|
||||||
bool abort);
|
bool abort);
|
||||||
extern int vty_mgmt_send_get_config(struct vty *vty,
|
extern int vty_mgmt_send_get_req(struct vty *vty, bool is_config,
|
||||||
Mgmtd__DatastoreId datastore,
|
Mgmtd__DatastoreId datastore,
|
||||||
const char **xpath_list, int num_req);
|
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_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
|
extern int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
|
||||||
bool lock, bool scok);
|
bool lock, bool scok);
|
||||||
extern void vty_mgmt_resume_response(struct vty *vty, bool success);
|
extern void vty_mgmt_resume_response(struct vty *vty, bool success);
|
||||||
|
@ -273,9 +273,8 @@ mgmt_fe_create_session(struct mgmt_fe_client_adapter *adapter,
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter,
|
static int fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter,
|
||||||
Mgmtd__FeMessage *fe_msg,
|
Mgmtd__FeMessage *fe_msg, bool short_circuit_ok)
|
||||||
bool short_circuit_ok)
|
|
||||||
{
|
{
|
||||||
return msg_conn_send_msg(
|
return msg_conn_send_msg(
|
||||||
adapter->conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg,
|
adapter->conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg,
|
||||||
@ -284,8 +283,7 @@ static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter,
|
|||||||
short_circuit_ok);
|
short_circuit_ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int fe_adapter_send_session_reply(struct mgmt_fe_client_adapter *adapter,
|
||||||
mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter,
|
|
||||||
struct mgmt_fe_session_ctx *session,
|
struct mgmt_fe_session_ctx *session,
|
||||||
bool create, bool success)
|
bool create, bool success)
|
||||||
{
|
{
|
||||||
@ -309,10 +307,10 @@ mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter,
|
|||||||
"Sending SESSION_REPLY message to MGMTD Frontend client '%s'",
|
"Sending SESSION_REPLY message to MGMTD Frontend client '%s'",
|
||||||
adapter->name);
|
adapter->name);
|
||||||
|
|
||||||
return mgmt_fe_adapter_send_msg(adapter, &fe_msg, true);
|
return fe_adapter_send_msg(adapter, &fe_msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mgmt_fe_send_lockds_reply(struct mgmt_fe_session_ctx *session,
|
static int fe_adapter_send_lockds_reply(struct mgmt_fe_session_ctx *session,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id,
|
||||||
uint64_t req_id, bool lock_ds,
|
uint64_t req_id, bool lock_ds,
|
||||||
bool success, const char *error_if_any)
|
bool success, const char *error_if_any)
|
||||||
@ -340,10 +338,10 @@ static int mgmt_fe_send_lockds_reply(struct mgmt_fe_session_ctx *session,
|
|||||||
"Sending LOCK_DS_REPLY message to MGMTD Frontend client '%s' scok: %d",
|
"Sending LOCK_DS_REPLY message to MGMTD Frontend client '%s' scok: %d",
|
||||||
session->adapter->name, scok);
|
session->adapter->name, scok);
|
||||||
|
|
||||||
return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, scok);
|
return fe_adapter_send_msg(session->adapter, &fe_msg, scok);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session,
|
static int fe_adapter_send_set_cfg_reply(struct mgmt_fe_session_ctx *session,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id,
|
||||||
uint64_t req_id, bool success,
|
uint64_t req_id, bool success,
|
||||||
const char *error_if_any,
|
const char *error_if_any,
|
||||||
@ -387,10 +385,10 @@ static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session,
|
|||||||
gettimeofday(&session->adapter->setcfg_stats.last_end, NULL);
|
gettimeofday(&session->adapter->setcfg_stats.last_end, NULL);
|
||||||
mgmt_fe_adapter_compute_set_cfg_timers(&session->adapter->setcfg_stats);
|
mgmt_fe_adapter_compute_set_cfg_timers(&session->adapter->setcfg_stats);
|
||||||
|
|
||||||
return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
return fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mgmt_fe_send_commitcfg_reply(
|
static int fe_adapter_send_commit_cfg_reply(
|
||||||
struct mgmt_fe_session_ctx *session, Mgmtd__DatastoreId src_ds_id,
|
struct mgmt_fe_session_ctx *session, Mgmtd__DatastoreId src_ds_id,
|
||||||
Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, enum mgmt_result result,
|
Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, enum mgmt_result result,
|
||||||
bool validate_only, const char *error_if_any)
|
bool validate_only, const char *error_if_any)
|
||||||
@ -433,83 +431,43 @@ static int mgmt_fe_send_commitcfg_reply(
|
|||||||
if (mm->perf_stats_en)
|
if (mm->perf_stats_en)
|
||||||
gettimeofday(&session->adapter->cmt_stats.last_end, NULL);
|
gettimeofday(&session->adapter->cmt_stats.last_end, NULL);
|
||||||
mgmt_fe_session_compute_commit_timers(&session->adapter->cmt_stats);
|
mgmt_fe_session_compute_commit_timers(&session->adapter->cmt_stats);
|
||||||
return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
return fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mgmt_fe_send_getcfg_reply(struct mgmt_fe_session_ctx *session,
|
static int fe_adapter_send_get_reply(struct mgmt_fe_session_ctx *session,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
||||||
uint64_t req_id, bool success,
|
bool success, Mgmtd__YangDataReply *data,
|
||||||
Mgmtd__YangDataReply *data,
|
|
||||||
const char *error_if_any)
|
const char *error_if_any)
|
||||||
{
|
{
|
||||||
Mgmtd__FeMessage fe_msg;
|
Mgmtd__FeMessage fe_msg;
|
||||||
Mgmtd__FeGetConfigReply getcfg_reply;
|
Mgmtd__FeGetReply get_reply;
|
||||||
|
|
||||||
assert(session->adapter);
|
assert(session->adapter);
|
||||||
|
|
||||||
mgmtd__fe_get_config_reply__init(&getcfg_reply);
|
mgmtd__fe_get_reply__init(&get_reply);
|
||||||
getcfg_reply.session_id = session->session_id;
|
get_reply.session_id = session->session_id;
|
||||||
getcfg_reply.ds_id = ds_id;
|
get_reply.ds_id = ds_id;
|
||||||
getcfg_reply.req_id = req_id;
|
get_reply.req_id = req_id;
|
||||||
getcfg_reply.success = success;
|
get_reply.success = success;
|
||||||
getcfg_reply.data = data;
|
get_reply.data = data;
|
||||||
if (error_if_any)
|
if (error_if_any)
|
||||||
getcfg_reply.error_if_any = (char *)error_if_any;
|
get_reply.error_if_any = (char *)error_if_any;
|
||||||
|
|
||||||
mgmtd__fe_message__init(&fe_msg);
|
mgmtd__fe_message__init(&fe_msg);
|
||||||
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY;
|
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY;
|
||||||
fe_msg.getcfg_reply = &getcfg_reply;
|
fe_msg.get_reply = &get_reply;
|
||||||
|
|
||||||
MGMTD_FE_ADAPTER_DBG(
|
MGMTD_FE_ADAPTER_DBG("Sending GET_REPLY message to MGMTD Frontend client '%s'",
|
||||||
"Sending GET_CONFIG_REPLY message to MGMTD Frontend client '%s'",
|
|
||||||
session->adapter->name);
|
session->adapter->name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cleanup the SHOW transaction associated with this session.
|
* Cleanup the SHOW transaction associated with this session.
|
||||||
*/
|
*/
|
||||||
if (session->txn_id && (!success || (data && data->next_indx < 0)))
|
if (session->txn_id && (!success || (data && data->next_indx < 0)))
|
||||||
mgmt_fe_session_register_event(
|
mgmt_fe_session_register_event(session,
|
||||||
session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP);
|
MGMTD_FE_SESSION_SHOW_TXN_CLNUP);
|
||||||
|
|
||||||
return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
return fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
||||||
}
|
|
||||||
|
|
||||||
static int mgmt_fe_send_getdata_reply(struct mgmt_fe_session_ctx *session,
|
|
||||||
Mgmtd__DatastoreId ds_id,
|
|
||||||
uint64_t req_id, bool success,
|
|
||||||
Mgmtd__YangDataReply *data,
|
|
||||||
const char *error_if_any)
|
|
||||||
{
|
|
||||||
Mgmtd__FeMessage fe_msg;
|
|
||||||
Mgmtd__FeGetDataReply getdata_reply;
|
|
||||||
|
|
||||||
assert(session->adapter);
|
|
||||||
|
|
||||||
mgmtd__fe_get_data_reply__init(&getdata_reply);
|
|
||||||
getdata_reply.session_id = session->session_id;
|
|
||||||
getdata_reply.ds_id = ds_id;
|
|
||||||
getdata_reply.req_id = req_id;
|
|
||||||
getdata_reply.success = success;
|
|
||||||
getdata_reply.data = data;
|
|
||||||
if (error_if_any)
|
|
||||||
getdata_reply.error_if_any = (char *)error_if_any;
|
|
||||||
|
|
||||||
mgmtd__fe_message__init(&fe_msg);
|
|
||||||
fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY;
|
|
||||||
fe_msg.getdata_reply = &getdata_reply;
|
|
||||||
|
|
||||||
MGMTD_FE_ADAPTER_DBG(
|
|
||||||
"Sending GET_DATA_REPLY message to MGMTD Frontend client '%s'",
|
|
||||||
session->adapter->name);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Cleanup the SHOW transaction associated with this session.
|
|
||||||
*/
|
|
||||||
if (session->txn_id && (!success || (data && data->next_indx < 0)))
|
|
||||||
mgmt_fe_session_register_event(
|
|
||||||
session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP);
|
|
||||||
|
|
||||||
return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mgmt_fe_session_cfg_txn_clnup(struct event *thread)
|
static void mgmt_fe_session_cfg_txn_clnup(struct event *thread)
|
||||||
@ -562,19 +520,6 @@ mgmt_fe_find_adapter_by_fd(int conn_fd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mgmt_fe_client_adapter *
|
|
||||||
mgmt_fe_find_adapter_by_name(const char *name)
|
|
||||||
{
|
|
||||||
struct mgmt_fe_client_adapter *adapter;
|
|
||||||
|
|
||||||
FOREACH_ADAPTER_IN_LIST (adapter) {
|
|
||||||
if (!strncmp(adapter->name, name, sizeof(adapter->name)))
|
|
||||||
return adapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mgmt_fe_adapter_delete(struct mgmt_fe_client_adapter *adapter)
|
static void mgmt_fe_adapter_delete(struct mgmt_fe_client_adapter *adapter)
|
||||||
{
|
{
|
||||||
struct mgmt_fe_session_ctx *session;
|
struct mgmt_fe_session_ctx *session;
|
||||||
@ -631,7 +576,7 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
|
|
||||||
if (lockds_req->ds_id != MGMTD_DS_CANDIDATE &&
|
if (lockds_req->ds_id != MGMTD_DS_CANDIDATE &&
|
||||||
lockds_req->ds_id != MGMTD_DS_RUNNING) {
|
lockds_req->ds_id != MGMTD_DS_RUNNING) {
|
||||||
mgmt_fe_send_lockds_reply(
|
fe_adapter_send_lockds_reply(
|
||||||
session, lockds_req->ds_id, lockds_req->req_id,
|
session, lockds_req->ds_id, lockds_req->req_id,
|
||||||
lockds_req->lock, false,
|
lockds_req->lock, false,
|
||||||
"Lock/Unlock on DS other than candidate or running DS not supported");
|
"Lock/Unlock on DS other than candidate or running DS not supported");
|
||||||
@ -640,8 +585,8 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
|
|
||||||
ds_ctx = mgmt_ds_get_ctx_by_id(mm, lockds_req->ds_id);
|
ds_ctx = mgmt_ds_get_ctx_by_id(mm, lockds_req->ds_id);
|
||||||
if (!ds_ctx) {
|
if (!ds_ctx) {
|
||||||
mgmt_fe_send_lockds_reply(
|
fe_adapter_send_lockds_reply(session, lockds_req->ds_id,
|
||||||
session, lockds_req->ds_id, lockds_req->req_id,
|
lockds_req->req_id,
|
||||||
lockds_req->lock, false,
|
lockds_req->lock, false,
|
||||||
"Failed to retrieve handle for DS!");
|
"Failed to retrieve handle for DS!");
|
||||||
return -1;
|
return -1;
|
||||||
@ -651,7 +596,7 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id,
|
if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id,
|
||||||
ds_ctx, session)
|
ds_ctx, session)
|
||||||
!= 0) {
|
!= 0) {
|
||||||
mgmt_fe_send_lockds_reply(
|
fe_adapter_send_lockds_reply(
|
||||||
session, lockds_req->ds_id, lockds_req->req_id,
|
session, lockds_req->ds_id, lockds_req->req_id,
|
||||||
lockds_req->lock, false,
|
lockds_req->lock, false,
|
||||||
"Lock already taken on DS by another session!");
|
"Lock already taken on DS by another session!");
|
||||||
@ -659,7 +604,7 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!session->ds_locked[lockds_req->ds_id]) {
|
if (!session->ds_locked[lockds_req->ds_id]) {
|
||||||
mgmt_fe_send_lockds_reply(
|
fe_adapter_send_lockds_reply(
|
||||||
session, lockds_req->ds_id, lockds_req->req_id,
|
session, lockds_req->ds_id, lockds_req->req_id,
|
||||||
lockds_req->lock, false,
|
lockds_req->lock, false,
|
||||||
"Lock on DS was not taken by this session!");
|
"Lock on DS was not taken by this session!");
|
||||||
@ -669,10 +614,9 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
mgmt_fe_session_unlock_ds(lockds_req->ds_id, ds_ctx, session);
|
mgmt_fe_session_unlock_ds(lockds_req->ds_id, ds_ctx, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mgmt_fe_send_lockds_reply(session, lockds_req->ds_id,
|
if (fe_adapter_send_lockds_reply(session, lockds_req->ds_id,
|
||||||
lockds_req->req_id, lockds_req->lock,
|
lockds_req->req_id, lockds_req->lock,
|
||||||
true, NULL)
|
true, NULL) != 0) {
|
||||||
!= 0) {
|
|
||||||
MGMTD_FE_ADAPTER_DBG(
|
MGMTD_FE_ADAPTER_DBG(
|
||||||
"Failed to send LOCK_DS_REPLY for DS %u session-id: %" PRIu64
|
"Failed to send LOCK_DS_REPLY for DS %u session-id: %" PRIu64
|
||||||
" from %s",
|
" from %s",
|
||||||
@ -700,7 +644,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
|
|
||||||
/* MGMTD currently only supports editing the candidate DS. */
|
/* MGMTD currently only supports editing the candidate DS. */
|
||||||
if (setcfg_req->ds_id != MGMTD_DS_CANDIDATE) {
|
if (setcfg_req->ds_id != MGMTD_DS_CANDIDATE) {
|
||||||
mgmt_fe_send_setcfg_reply(
|
fe_adapter_send_set_cfg_reply(
|
||||||
session, setcfg_req->ds_id, setcfg_req->req_id, false,
|
session, setcfg_req->ds_id, setcfg_req->req_id, false,
|
||||||
"Set-Config on datastores other than Candidate DS not supported",
|
"Set-Config on datastores other than Candidate DS not supported",
|
||||||
setcfg_req->implicit_commit);
|
setcfg_req->implicit_commit);
|
||||||
@ -712,7 +656,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
/* MGMTD currently only supports targetting the running DS. */
|
/* MGMTD currently only supports targetting the running DS. */
|
||||||
if (setcfg_req->implicit_commit &&
|
if (setcfg_req->implicit_commit &&
|
||||||
setcfg_req->commit_ds_id != MGMTD_DS_RUNNING) {
|
setcfg_req->commit_ds_id != MGMTD_DS_RUNNING) {
|
||||||
mgmt_fe_send_setcfg_reply(
|
fe_adapter_send_set_cfg_reply(
|
||||||
session, setcfg_req->ds_id, setcfg_req->req_id, false,
|
session, setcfg_req->ds_id, setcfg_req->req_id, false,
|
||||||
"Implicit commit on datastores other than running DS not supported",
|
"Implicit commit on datastores other than running DS not supported",
|
||||||
setcfg_req->implicit_commit);
|
setcfg_req->implicit_commit);
|
||||||
@ -723,7 +667,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
|
|
||||||
/* User should have write lock to change the DS */
|
/* User should have write lock to change the DS */
|
||||||
if (!session->ds_locked[setcfg_req->ds_id]) {
|
if (!session->ds_locked[setcfg_req->ds_id]) {
|
||||||
mgmt_fe_send_setcfg_reply(session, setcfg_req->ds_id,
|
fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id,
|
||||||
setcfg_req->req_id, false,
|
setcfg_req->req_id, false,
|
||||||
"Candidate DS is not locked",
|
"Candidate DS is not locked",
|
||||||
setcfg_req->implicit_commit);
|
setcfg_req->implicit_commit);
|
||||||
@ -738,7 +682,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
session->cfg_txn_id = mgmt_create_txn(session->session_id,
|
session->cfg_txn_id = mgmt_create_txn(session->session_id,
|
||||||
MGMTD_TXN_TYPE_CONFIG);
|
MGMTD_TXN_TYPE_CONFIG);
|
||||||
if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
|
if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
|
||||||
mgmt_fe_send_setcfg_reply(
|
fe_adapter_send_set_cfg_reply(
|
||||||
session, setcfg_req->ds_id, setcfg_req->req_id,
|
session, setcfg_req->ds_id, setcfg_req->req_id,
|
||||||
false,
|
false,
|
||||||
"Failed to create a Configuration session!",
|
"Failed to create a Configuration session!",
|
||||||
@ -761,7 +705,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
* In this scenario need to skip cleanup of the txn,
|
* In this scenario need to skip cleanup of the txn,
|
||||||
* so setting implicit commit to false.
|
* so setting implicit commit to false.
|
||||||
*/
|
*/
|
||||||
mgmt_fe_send_setcfg_reply(
|
fe_adapter_send_set_cfg_reply(
|
||||||
session, setcfg_req->ds_id, setcfg_req->req_id,
|
session, setcfg_req->ds_id, setcfg_req->req_id,
|
||||||
false,
|
false,
|
||||||
"A Configuration transaction is already in progress!",
|
"A Configuration transaction is already in progress!",
|
||||||
@ -771,14 +715,14 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the SETConfig request under the transaction. */
|
/* Create the SETConfig request under the transaction. */
|
||||||
if (mgmt_txn_send_set_config_req(
|
if (mgmt_txn_send_set_config_req(session->cfg_txn_id, setcfg_req->req_id,
|
||||||
session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id,
|
setcfg_req->ds_id, ds_ctx,
|
||||||
ds_ctx, setcfg_req->data, setcfg_req->n_data,
|
setcfg_req->data, setcfg_req->n_data,
|
||||||
setcfg_req->implicit_commit, setcfg_req->commit_ds_id,
|
setcfg_req->implicit_commit,
|
||||||
dst_ds_ctx)
|
setcfg_req->commit_ds_id,
|
||||||
!= 0) {
|
dst_ds_ctx) != 0) {
|
||||||
mgmt_fe_send_setcfg_reply(
|
fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id,
|
||||||
session, setcfg_req->ds_id, setcfg_req->req_id, false,
|
setcfg_req->req_id, false,
|
||||||
"Request processing for SET-CONFIG failed!",
|
"Request processing for SET-CONFIG failed!",
|
||||||
setcfg_req->implicit_commit);
|
setcfg_req->implicit_commit);
|
||||||
|
|
||||||
@ -790,33 +734,27 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int mgmt_fe_session_handle_get_req_msg(struct mgmt_fe_session_ctx *session,
|
||||||
mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
Mgmtd__FeGetReq *get_req)
|
||||||
Mgmtd__FeGetConfigReq *getcfg_req)
|
|
||||||
{
|
{
|
||||||
struct mgmt_ds_ctx *ds_ctx;
|
struct mgmt_ds_ctx *ds_ctx;
|
||||||
struct nb_config *cfg_root = NULL;
|
struct nb_config *cfg_root = NULL;
|
||||||
|
Mgmtd__DatastoreId ds_id = get_req->ds_id;
|
||||||
|
uint64_t req_id = get_req->req_id;
|
||||||
|
bool is_cfg = get_req->config;
|
||||||
|
bool ds_ok = true;
|
||||||
|
|
||||||
/*
|
if (is_cfg && ds_id != MGMTD_DS_CANDIDATE && ds_id != MGMTD_DS_RUNNING)
|
||||||
* Get the DS handle.
|
ds_ok = false;
|
||||||
*/
|
else if (!is_cfg && ds_id != MGMTD_DS_OPERATIONAL)
|
||||||
ds_ctx = mgmt_ds_get_ctx_by_id(mm, getcfg_req->ds_id);
|
ds_ok = false;
|
||||||
if (!ds_ctx) {
|
if (!ds_ok) {
|
||||||
mgmt_fe_send_getcfg_reply(session, getcfg_req->ds_id,
|
fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL,
|
||||||
getcfg_req->req_id, false, NULL,
|
"get-req on unsupported datastore");
|
||||||
"No such DS exists!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GETCFG must be on candidate or running DS */
|
|
||||||
if (getcfg_req->ds_id != MGMTD_DS_CANDIDATE
|
|
||||||
&& getcfg_req->ds_id != MGMTD_DS_RUNNING) {
|
|
||||||
mgmt_fe_send_getcfg_reply(
|
|
||||||
session, getcfg_req->ds_id, getcfg_req->req_id, false,
|
|
||||||
NULL,
|
|
||||||
"Get-Config on datastores other than Candidate or Running DS not permitted!");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id);
|
||||||
|
assert(ds_ctx);
|
||||||
|
|
||||||
if (session->txn_id == MGMTD_TXN_ID_NONE) {
|
if (session->txn_id == MGMTD_TXN_ID_NONE) {
|
||||||
/*
|
/*
|
||||||
@ -825,44 +763,43 @@ mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session,
|
|||||||
session->txn_id = mgmt_create_txn(session->session_id,
|
session->txn_id = mgmt_create_txn(session->session_id,
|
||||||
MGMTD_TXN_TYPE_SHOW);
|
MGMTD_TXN_TYPE_SHOW);
|
||||||
if (session->txn_id == MGMTD_SESSION_ID_NONE) {
|
if (session->txn_id == MGMTD_SESSION_ID_NONE) {
|
||||||
mgmt_fe_send_getcfg_reply(
|
fe_adapter_send_get_reply(session, ds_id, req_id, false,
|
||||||
session, getcfg_req->ds_id, getcfg_req->req_id,
|
NULL,
|
||||||
false, NULL,
|
|
||||||
"Failed to create a Show transaction!");
|
"Failed to create a Show transaction!");
|
||||||
goto mgmt_fe_sess_handle_getcfg_req_failed;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MGMTD_FE_ADAPTER_DBG("Created new show txn-id: %" PRIu64
|
MGMTD_FE_ADAPTER_DBG("Created new show txn-id: %" PRIu64
|
||||||
" for session-id: %" PRIu64,
|
" for session-id: %" PRIu64,
|
||||||
session->txn_id, session->session_id);
|
session->txn_id, session->session_id);
|
||||||
} else {
|
} else {
|
||||||
MGMTD_FE_ADAPTER_DBG("Show txn-id: %" PRIu64
|
fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL,
|
||||||
" for session-id: %" PRIu64
|
"Request processing for GET failed!");
|
||||||
" already created",
|
MGMTD_FE_ADAPTER_DBG("Transaction in progress txn-id: %" PRIu64
|
||||||
|
" for session-id: %" PRIu64,
|
||||||
session->txn_id, session->session_id);
|
session->txn_id, session->session_id);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a copy of the datastore config root, avoids locking.
|
* Get a copy of the datastore config root, avoids locking.
|
||||||
*/
|
*/
|
||||||
|
if (is_cfg)
|
||||||
cfg_root = nb_config_dup(mgmt_ds_get_nb_config(ds_ctx));
|
cfg_root = nb_config_dup(mgmt_ds_get_nb_config(ds_ctx));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a GETConfig request under the transaction.
|
* Create a GET request under the transaction.
|
||||||
*/
|
*/
|
||||||
if (mgmt_txn_send_get_config_req(
|
if (mgmt_txn_send_get_req(session->txn_id, req_id, ds_id, cfg_root,
|
||||||
session->txn_id, getcfg_req->req_id, getcfg_req->ds_id,
|
get_req->data, get_req->n_data)) {
|
||||||
cfg_root, getcfg_req->data, getcfg_req->n_data) != 0) {
|
fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL,
|
||||||
mgmt_fe_send_getcfg_reply(
|
"Request processing for GET failed!");
|
||||||
session, getcfg_req->ds_id, getcfg_req->req_id, false,
|
|
||||||
NULL, "Request processing for GET-CONFIG failed!");
|
goto failed;
|
||||||
goto mgmt_fe_sess_handle_getcfg_req_failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
failed:
|
||||||
mgmt_fe_sess_handle_getcfg_req_failed:
|
|
||||||
|
|
||||||
if (cfg_root)
|
if (cfg_root)
|
||||||
nb_config_free(cfg_root);
|
nb_config_free(cfg_root);
|
||||||
/*
|
/*
|
||||||
@ -874,79 +811,6 @@ mgmt_fe_sess_handle_getcfg_req_failed:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
mgmt_fe_session_handle_getdata_req_msg(struct mgmt_fe_session_ctx *session,
|
|
||||||
Mgmtd__FeGetDataReq *getdata_req)
|
|
||||||
{
|
|
||||||
struct mgmt_ds_ctx *ds_ctx;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the DS handle.
|
|
||||||
*/
|
|
||||||
ds_ctx = mgmt_ds_get_ctx_by_id(mm, getdata_req->ds_id);
|
|
||||||
if (!ds_ctx) {
|
|
||||||
mgmt_fe_send_getdata_reply(session, getdata_req->ds_id,
|
|
||||||
getdata_req->req_id, false, NULL,
|
|
||||||
"No such DS exists!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GETDATA must be on operational DS */
|
|
||||||
if (getdata_req->ds_id != MGMTD_DS_OPERATIONAL) {
|
|
||||||
mgmt_fe_send_getdata_reply(
|
|
||||||
session, getdata_req->ds_id, getdata_req->req_id, false,
|
|
||||||
NULL,
|
|
||||||
"Get-Data on datastore other than Operational DS not permitted!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session->txn_id == MGMTD_TXN_ID_NONE) {
|
|
||||||
/*
|
|
||||||
* Start a SHOW Transaction (if not started already)
|
|
||||||
*/
|
|
||||||
session->txn_id = mgmt_create_txn(session->session_id,
|
|
||||||
MGMTD_TXN_TYPE_SHOW);
|
|
||||||
if (session->txn_id == MGMTD_SESSION_ID_NONE) {
|
|
||||||
mgmt_fe_send_getdata_reply(
|
|
||||||
session, getdata_req->ds_id,
|
|
||||||
getdata_req->req_id, false, NULL,
|
|
||||||
"Failed to create a Show transaction!");
|
|
||||||
goto mgmt_fe_sess_handle_getdata_req_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
MGMTD_FE_ADAPTER_DBG("Created new Show Txn %" PRIu64
|
|
||||||
" for session %" PRIu64,
|
|
||||||
session->txn_id, session->session_id);
|
|
||||||
} else {
|
|
||||||
MGMTD_FE_ADAPTER_DBG("Show txn-id: %" PRIu64
|
|
||||||
" for session %" PRIu64 " already created",
|
|
||||||
session->txn_id, session->session_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a GETData request under the transaction.
|
|
||||||
*/
|
|
||||||
if (mgmt_txn_send_get_data_req(session->txn_id, getdata_req->req_id,
|
|
||||||
getdata_req->ds_id, getdata_req->data,
|
|
||||||
getdata_req->n_data) != 0) {
|
|
||||||
mgmt_fe_send_getdata_reply(
|
|
||||||
session, getdata_req->ds_id, getdata_req->req_id, false,
|
|
||||||
NULL, "Request processing for GET-CONFIG failed!");
|
|
||||||
goto mgmt_fe_sess_handle_getdata_req_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
mgmt_fe_sess_handle_getdata_req_failed:
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Destroy the transaction created recently.
|
|
||||||
*/
|
|
||||||
if (session->txn_id != MGMTD_TXN_ID_NONE)
|
|
||||||
mgmt_destroy_txn(&session->txn_id);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mgmt_fe_session_handle_commit_config_req_msg(
|
static int mgmt_fe_session_handle_commit_config_req_msg(
|
||||||
struct mgmt_fe_session_ctx *session,
|
struct mgmt_fe_session_ctx *session,
|
||||||
@ -961,7 +825,7 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
|
|||||||
/* Validate source and dest DS */
|
/* Validate source and dest DS */
|
||||||
if (commcfg_req->src_ds_id != MGMTD_DS_CANDIDATE ||
|
if (commcfg_req->src_ds_id != MGMTD_DS_CANDIDATE ||
|
||||||
commcfg_req->dst_ds_id != MGMTD_DS_RUNNING) {
|
commcfg_req->dst_ds_id != MGMTD_DS_RUNNING) {
|
||||||
mgmt_fe_send_commitcfg_reply(
|
fe_adapter_send_commit_cfg_reply(
|
||||||
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
||||||
commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
|
commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
|
||||||
commcfg_req->validate_only,
|
commcfg_req->validate_only,
|
||||||
@ -976,7 +840,7 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
|
|||||||
/* User should have lock on both source and dest DS */
|
/* User should have lock on both source and dest DS */
|
||||||
if (!session->ds_locked[commcfg_req->dst_ds_id] ||
|
if (!session->ds_locked[commcfg_req->dst_ds_id] ||
|
||||||
!session->ds_locked[commcfg_req->src_ds_id]) {
|
!session->ds_locked[commcfg_req->src_ds_id]) {
|
||||||
mgmt_fe_send_commitcfg_reply(
|
fe_adapter_send_commit_cfg_reply(
|
||||||
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
||||||
commcfg_req->req_id, MGMTD_DS_LOCK_FAILED,
|
commcfg_req->req_id, MGMTD_DS_LOCK_FAILED,
|
||||||
commcfg_req->validate_only,
|
commcfg_req->validate_only,
|
||||||
@ -991,11 +855,10 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
|
|||||||
session->cfg_txn_id = mgmt_create_txn(session->session_id,
|
session->cfg_txn_id = mgmt_create_txn(session->session_id,
|
||||||
MGMTD_TXN_TYPE_CONFIG);
|
MGMTD_TXN_TYPE_CONFIG);
|
||||||
if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
|
if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
|
||||||
mgmt_fe_send_commitcfg_reply(
|
fe_adapter_send_commit_cfg_reply(
|
||||||
session, commcfg_req->src_ds_id,
|
session, commcfg_req->src_ds_id,
|
||||||
commcfg_req->dst_ds_id, commcfg_req->req_id,
|
commcfg_req->dst_ds_id, commcfg_req->req_id,
|
||||||
MGMTD_INTERNAL_ERROR,
|
MGMTD_INTERNAL_ERROR, commcfg_req->validate_only,
|
||||||
commcfg_req->validate_only,
|
|
||||||
"Failed to create a Configuration session!");
|
"Failed to create a Configuration session!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1013,7 +876,7 @@ static int mgmt_fe_session_handle_commit_config_req_msg(
|
|||||||
commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id,
|
commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id,
|
||||||
dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort,
|
dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort,
|
||||||
false) != 0) {
|
false) != 0) {
|
||||||
mgmt_fe_send_commitcfg_reply(
|
fe_adapter_send_commit_cfg_reply(
|
||||||
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
|
||||||
commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
|
commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
|
||||||
commcfg_req->validate_only,
|
commcfg_req->validate_only,
|
||||||
@ -1058,7 +921,7 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
|
|||||||
|
|
||||||
session = mgmt_fe_create_session(
|
session = mgmt_fe_create_session(
|
||||||
adapter, fe_msg->session_req->client_conn_id);
|
adapter, fe_msg->session_req->client_conn_id);
|
||||||
mgmt_fe_send_session_reply(adapter, session, true,
|
fe_adapter_send_session_reply(adapter, session, true,
|
||||||
session ? true : false);
|
session ? true : false);
|
||||||
} else if (
|
} else if (
|
||||||
!fe_msg->session_req->create
|
!fe_msg->session_req->create
|
||||||
@ -1071,7 +934,7 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
|
|||||||
|
|
||||||
session = mgmt_session_id2ctx(
|
session = mgmt_session_id2ctx(
|
||||||
fe_msg->session_req->session_id);
|
fe_msg->session_req->session_id);
|
||||||
mgmt_fe_send_session_reply(adapter, session, false,
|
fe_adapter_send_session_reply(adapter, session, false,
|
||||||
true);
|
true);
|
||||||
mgmt_fe_cleanup_session(&session);
|
mgmt_fe_cleanup_session(&session);
|
||||||
}
|
}
|
||||||
@ -1116,29 +979,15 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
|
|||||||
mgmt_fe_session_handle_commit_config_req_msg(
|
mgmt_fe_session_handle_commit_config_req_msg(
|
||||||
session, fe_msg->commcfg_req);
|
session, fe_msg->commcfg_req);
|
||||||
break;
|
break;
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ:
|
||||||
session = mgmt_session_id2ctx(
|
session = mgmt_session_id2ctx(fe_msg->get_req->session_id);
|
||||||
fe_msg->getcfg_req->session_id);
|
MGMTD_FE_ADAPTER_DBG("Got GET_REQ (iscfg %d) for DS:%s (xpaths: %d) on session-id %" PRIu64
|
||||||
MGMTD_FE_ADAPTER_DBG(
|
|
||||||
"Got GETCFG_REQ for DS:%s (xpaths: %d) on session-id %" PRIu64
|
|
||||||
" from '%s'",
|
" from '%s'",
|
||||||
mgmt_ds_id2name(fe_msg->getcfg_req->ds_id),
|
(int)fe_msg->get_req->config,
|
||||||
(int)fe_msg->getcfg_req->n_data,
|
mgmt_ds_id2name(fe_msg->get_req->ds_id),
|
||||||
fe_msg->getcfg_req->session_id, adapter->name);
|
(int)fe_msg->get_req->n_data,
|
||||||
mgmt_fe_session_handle_getcfg_req_msg(
|
fe_msg->get_req->session_id, adapter->name);
|
||||||
session, fe_msg->getcfg_req);
|
mgmt_fe_session_handle_get_req_msg(session, fe_msg->get_req);
|
||||||
break;
|
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ:
|
|
||||||
session = mgmt_session_id2ctx(
|
|
||||||
fe_msg->getdata_req->session_id);
|
|
||||||
MGMTD_FE_ADAPTER_DBG(
|
|
||||||
"Got GETDATA_REQ for DS:%s (xpaths: %d) on session-id %" PRIu64
|
|
||||||
" from '%s'",
|
|
||||||
mgmt_ds_id2name(fe_msg->getdata_req->ds_id),
|
|
||||||
(int)fe_msg->getdata_req->n_data,
|
|
||||||
fe_msg->getdata_req->session_id, adapter->name);
|
|
||||||
mgmt_fe_session_handle_getdata_req_msg(
|
|
||||||
session, fe_msg->getdata_req);
|
|
||||||
break;
|
break;
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ:
|
case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ:
|
||||||
@ -1157,8 +1006,7 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
|
|||||||
case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY:
|
case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY:
|
case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY:
|
case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY:
|
case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY:
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY:
|
|
||||||
case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
|
case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
@ -1293,11 +1141,6 @@ struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *from)
|
|||||||
return adapter->conn;
|
return adapter->conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mgmt_fe_client_adapter *mgmt_fe_get_adapter(const char *name)
|
|
||||||
{
|
|
||||||
return mgmt_fe_find_adapter_by_name(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
||||||
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
||||||
enum mgmt_result result,
|
enum mgmt_result result,
|
||||||
@ -1316,8 +1159,9 @@ int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mgmt_fe_send_setcfg_reply(
|
return fe_adapter_send_set_cfg_reply(session, ds_id, req_id,
|
||||||
session, ds_id, req_id, result == MGMTD_SUCCESS ? true : false,
|
result == MGMTD_SUCCESS ? true
|
||||||
|
: false,
|
||||||
error_if_any, implicit_commit);
|
error_if_any, implicit_commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1334,12 +1178,12 @@ int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
|||||||
if (!session || session->cfg_txn_id != txn_id)
|
if (!session || session->cfg_txn_id != txn_id)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return mgmt_fe_send_commitcfg_reply(session, src_ds_id, dst_ds_id,
|
return fe_adapter_send_commit_cfg_reply(session, src_ds_id, dst_ds_id,
|
||||||
req_id, result, validate_only,
|
req_id, result, validate_only,
|
||||||
error_if_any);
|
error_if_any);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id,
|
||||||
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
||||||
enum mgmt_result result,
|
enum mgmt_result result,
|
||||||
Mgmtd__YangDataReply *data_resp,
|
Mgmtd__YangDataReply *data_resp,
|
||||||
@ -1351,36 +1195,11 @@ int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
|||||||
if (!session || session->txn_id != txn_id)
|
if (!session || session->txn_id != txn_id)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return mgmt_fe_send_getcfg_reply(session, ds_id, req_id,
|
return fe_adapter_send_get_reply(session, ds_id, req_id,
|
||||||
result == MGMTD_SUCCESS, data_resp,
|
result == MGMTD_SUCCESS, data_resp,
|
||||||
error_if_any);
|
error_if_any);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mgmt_fe_send_get_data_reply(uint64_t session_id, uint64_t txn_id,
|
|
||||||
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
|
||||||
enum mgmt_result result,
|
|
||||||
Mgmtd__YangDataReply *data_resp,
|
|
||||||
const char *error_if_any)
|
|
||||||
{
|
|
||||||
struct mgmt_fe_session_ctx *session;
|
|
||||||
|
|
||||||
session = mgmt_session_id2ctx(session_id);
|
|
||||||
if (!session || session->txn_id != txn_id)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return mgmt_fe_send_getdata_reply(session, ds_id, req_id,
|
|
||||||
result == MGMTD_SUCCESS,
|
|
||||||
data_resp, error_if_any);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
|
|
||||||
Mgmtd__YangData * data_resp[], int num_data)
|
|
||||||
{
|
|
||||||
/* struct mgmt_fe_session_ctx *session; */
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct mgmt_setcfg_stats *
|
struct mgmt_setcfg_stats *
|
||||||
mgmt_fe_get_session_setcfg_stats(uint64_t session_id)
|
mgmt_fe_get_session_setcfg_stats(uint64_t session_id)
|
||||||
{
|
{
|
||||||
|
@ -87,10 +87,6 @@ mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter);
|
|||||||
extern struct msg_conn *mgmt_fe_create_adapter(int conn_fd,
|
extern struct msg_conn *mgmt_fe_create_adapter(int conn_fd,
|
||||||
union sockunion *su);
|
union sockunion *su);
|
||||||
|
|
||||||
/* Fetch frontend adapter given a name */
|
|
||||||
extern struct mgmt_fe_client_adapter *
|
|
||||||
mgmt_fe_get_adapter(const char *name);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send set-config reply to the frontend client.
|
* Send set-config reply to the frontend client.
|
||||||
*
|
*
|
||||||
@ -134,30 +130,14 @@ extern int mgmt_fe_send_commit_cfg_reply(
|
|||||||
enum mgmt_result result, const char *error_if_any);
|
enum mgmt_result result, const char *error_if_any);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send get-config reply to the frontend client.
|
* Send get-config/get-data reply to the frontend client.
|
||||||
*/
|
*/
|
||||||
extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
|
extern int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id, uint64_t req_id,
|
||||||
uint64_t req_id,
|
|
||||||
enum mgmt_result result,
|
enum mgmt_result result,
|
||||||
Mgmtd__YangDataReply *data_resp,
|
Mgmtd__YangDataReply *data_resp,
|
||||||
const char *error_if_any);
|
const char *error_if_any);
|
||||||
|
|
||||||
/*
|
|
||||||
* Send get-data reply to the frontend client.
|
|
||||||
*/
|
|
||||||
extern int mgmt_fe_send_get_data_reply(
|
|
||||||
uint64_t session_id, uint64_t txn_id, Mgmtd__DatastoreId ds_id,
|
|
||||||
uint64_t req_id, enum mgmt_result result,
|
|
||||||
Mgmtd__YangDataReply *data_resp, const char *error_if_any);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send data notify to the frontend client.
|
|
||||||
*/
|
|
||||||
extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
|
|
||||||
Mgmtd__YangData * data_resp[],
|
|
||||||
int num_data);
|
|
||||||
|
|
||||||
/* Fetch frontend client session set-config stats */
|
/* Fetch frontend client session set-config stats */
|
||||||
extern struct mgmt_setcfg_stats *
|
extern struct mgmt_setcfg_stats *
|
||||||
mgmt_fe_get_session_setcfg_stats(uint64_t session_id);
|
mgmt_fe_get_session_setcfg_stats(uint64_t session_id);
|
||||||
|
@ -1659,11 +1659,10 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req,
|
|||||||
|
|
||||||
switch (txn_req->req_event) {
|
switch (txn_req->req_event) {
|
||||||
case MGMTD_TXN_PROC_GETCFG:
|
case MGMTD_TXN_PROC_GETCFG:
|
||||||
if (mgmt_fe_send_get_cfg_reply(txn_req->txn->session_id,
|
if (mgmt_fe_send_get_reply(txn_req->txn->session_id,
|
||||||
txn_req->txn->txn_id,
|
txn_req->txn->txn_id, get_req->ds_id,
|
||||||
get_req->ds_id, txn_req->req_id,
|
txn_req->req_id, MGMTD_SUCCESS,
|
||||||
MGMTD_SUCCESS, data_reply,
|
data_reply, NULL) != 0) {
|
||||||
NULL) != 0) {
|
|
||||||
MGMTD_TXN_ERR("Failed to send GET-CONFIG-REPLY txn-id: %" PRIu64
|
MGMTD_TXN_ERR("Failed to send GET-CONFIG-REPLY txn-id: %" PRIu64
|
||||||
" session-id: %" PRIu64
|
" session-id: %" PRIu64
|
||||||
" req-id: %" PRIu64,
|
" req-id: %" PRIu64,
|
||||||
@ -1672,11 +1671,10 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MGMTD_TXN_PROC_GETDATA:
|
case MGMTD_TXN_PROC_GETDATA:
|
||||||
if (mgmt_fe_send_get_data_reply(txn_req->txn->session_id,
|
if (mgmt_fe_send_get_reply(txn_req->txn->session_id,
|
||||||
txn_req->txn->txn_id,
|
txn_req->txn->txn_id, get_req->ds_id,
|
||||||
get_req->ds_id, txn_req->req_id,
|
txn_req->req_id, MGMTD_SUCCESS,
|
||||||
MGMTD_SUCCESS, data_reply,
|
data_reply, NULL) != 0) {
|
||||||
NULL) != 0) {
|
|
||||||
MGMTD_TXN_ERR("Failed to send GET-DATA-REPLY txn-id: %" PRIu64
|
MGMTD_TXN_ERR("Failed to send GET-DATA-REPLY txn-id: %" PRIu64
|
||||||
" session-id: %" PRIu64
|
" session-id: %" PRIu64
|
||||||
" req-id: %" PRIu64,
|
" req-id: %" PRIu64,
|
||||||
@ -1755,7 +1753,7 @@ static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn,
|
|||||||
get_data->reply = XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REPLY,
|
get_data->reply = XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REPLY,
|
||||||
sizeof(struct mgmt_get_data_reply));
|
sizeof(struct mgmt_get_data_reply));
|
||||||
if (!get_data->reply) {
|
if (!get_data->reply) {
|
||||||
mgmt_fe_send_get_cfg_reply(
|
mgmt_fe_send_get_reply(
|
||||||
txn->session_id, txn->txn_id, get_data->ds_id,
|
txn->session_id, txn->txn_id, get_data->ds_id,
|
||||||
txn_req->req_id, MGMTD_INTERNAL_ERROR, NULL,
|
txn_req->req_id, MGMTD_INTERNAL_ERROR, NULL,
|
||||||
"Internal error: Unable to allocate reply buffers!");
|
"Internal error: Unable to allocate reply buffers!");
|
||||||
@ -1783,9 +1781,8 @@ static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn,
|
|||||||
(void *)txn_req) == -1) {
|
(void *)txn_req) == -1) {
|
||||||
MGMTD_TXN_DBG("Invalid Xpath '%s",
|
MGMTD_TXN_DBG("Invalid Xpath '%s",
|
||||||
get_data->xpaths[indx]);
|
get_data->xpaths[indx]);
|
||||||
mgmt_fe_send_get_cfg_reply(txn->session_id, txn->txn_id,
|
mgmt_fe_send_get_reply(txn->session_id, txn->txn_id,
|
||||||
get_data->ds_id,
|
get_data->ds_id, txn_req->req_id,
|
||||||
txn_req->req_id,
|
|
||||||
MGMTD_INTERNAL_ERROR, NULL,
|
MGMTD_INTERNAL_ERROR, NULL,
|
||||||
"Invalid xpath");
|
"Invalid xpath");
|
||||||
goto mgmt_txn_get_config_failed;
|
goto mgmt_txn_get_config_failed;
|
||||||
@ -1884,11 +1881,10 @@ static void mgmt_txn_process_get_data(struct event *thread)
|
|||||||
* TODO: Trigger GET procedures for Backend
|
* TODO: Trigger GET procedures for Backend
|
||||||
* For now return back error.
|
* For now return back error.
|
||||||
*/
|
*/
|
||||||
mgmt_fe_send_get_data_reply(txn->session_id, txn->txn_id,
|
mgmt_fe_send_get_reply(txn->session_id, txn->txn_id,
|
||||||
txn_req->req.get_data->ds_id,
|
txn_req->req.get_data->ds_id,
|
||||||
txn_req->req_id,
|
txn_req->req_id, MGMTD_INTERNAL_ERROR,
|
||||||
MGMTD_INTERNAL_ERROR, NULL,
|
NULL, "GET-DATA is not supported yet!");
|
||||||
"GET-DATA on Oper DS is not supported yet!");
|
|
||||||
/*
|
/*
|
||||||
* Delete the txn request.
|
* Delete the txn request.
|
||||||
* Note: The following will remove it from the list
|
* Note: The following will remove it from the list
|
||||||
@ -2532,21 +2528,22 @@ int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
|
int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id, struct nb_config *cfg_root,
|
||||||
struct nb_config *cfg_root,
|
Mgmtd__YangGetDataReq **data_req, size_t num_reqs)
|
||||||
Mgmtd__YangGetDataReq **data_req,
|
|
||||||
size_t num_reqs)
|
|
||||||
{
|
{
|
||||||
struct mgmt_txn_ctx *txn;
|
struct mgmt_txn_ctx *txn;
|
||||||
struct mgmt_txn_req *txn_req;
|
struct mgmt_txn_req *txn_req;
|
||||||
|
enum mgmt_txn_event req_event;
|
||||||
size_t indx;
|
size_t indx;
|
||||||
|
|
||||||
txn = mgmt_txn_id2ctx(txn_id);
|
txn = mgmt_txn_id2ctx(txn_id);
|
||||||
if (!txn)
|
if (!txn)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETCFG);
|
req_event = cfg_root ? MGMTD_TXN_PROC_GETCFG : MGMTD_TXN_PROC_GETDATA;
|
||||||
|
|
||||||
|
txn_req = mgmt_txn_req_alloc(txn, req_id, req_event);
|
||||||
txn_req->req.get_data->ds_id = ds_id;
|
txn_req->req.get_data->ds_id = ds_id;
|
||||||
txn_req->req.get_data->cfg_root = cfg_root;
|
txn_req->req.get_data->cfg_root = cfg_root;
|
||||||
for (indx = 0;
|
for (indx = 0;
|
||||||
@ -2558,36 +2555,7 @@ int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
|
|||||||
txn_req->req.get_data->num_xpaths++;
|
txn_req->req.get_data->num_xpaths++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETCFG);
|
mgmt_txn_register_event(txn, req_event);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id,
|
|
||||||
Mgmtd__DatastoreId ds_id,
|
|
||||||
Mgmtd__YangGetDataReq **data_req, size_t num_reqs)
|
|
||||||
{
|
|
||||||
struct mgmt_txn_ctx *txn;
|
|
||||||
struct mgmt_txn_req *txn_req;
|
|
||||||
size_t indx;
|
|
||||||
|
|
||||||
txn = mgmt_txn_id2ctx(txn_id);
|
|
||||||
if (!txn)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETDATA);
|
|
||||||
txn_req->req.get_data->ds_id = ds_id;
|
|
||||||
txn_req->req.get_data->cfg_root = NULL;
|
|
||||||
for (indx = 0;
|
|
||||||
indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH;
|
|
||||||
indx++) {
|
|
||||||
MGMTD_TXN_DBG("XPath: '%s'", data_req[indx]->data->xpath);
|
|
||||||
txn_req->req.get_data->xpaths[indx] =
|
|
||||||
strdup(data_req[indx]->data->xpath);
|
|
||||||
txn_req->req.get_data->num_xpaths++;
|
|
||||||
}
|
|
||||||
|
|
||||||
mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -177,26 +177,17 @@ extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
|
|||||||
bool implicit);
|
bool implicit);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send get-config request to be processed later in transaction.
|
* Send get-{cfg,data} request to be processed later in transaction.
|
||||||
*
|
*
|
||||||
* Similar to set-config request.
|
* Is get-config if cfg_root is provided and the config is gathered locally,
|
||||||
|
* otherwise it's get-data and data is fetched from backedn clients.
|
||||||
*/
|
*/
|
||||||
extern int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
|
extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id,
|
||||||
Mgmtd__DatastoreId ds_id,
|
Mgmtd__DatastoreId ds_id,
|
||||||
struct nb_config *cfg_root,
|
struct nb_config *cfg_root,
|
||||||
Mgmtd__YangGetDataReq **data_req,
|
Mgmtd__YangGetDataReq **data_req,
|
||||||
size_t num_reqs);
|
size_t num_reqs);
|
||||||
|
|
||||||
/*
|
|
||||||
* Send get-data request to be processed later in transaction.
|
|
||||||
*
|
|
||||||
* Similar to get-config request, but here data is fetched from backedn client.
|
|
||||||
*/
|
|
||||||
extern int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id,
|
|
||||||
Mgmtd__DatastoreId ds_id,
|
|
||||||
Mgmtd__YangGetDataReq **data_req,
|
|
||||||
size_t num_reqs);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notifiy backend adapter on connection.
|
* Notifiy backend adapter on connection.
|
||||||
*/
|
*/
|
||||||
|
@ -194,7 +194,7 @@ DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd,
|
|||||||
datastore = mgmt_ds_name2id(dsname);
|
datastore = mgmt_ds_name2id(dsname);
|
||||||
|
|
||||||
xpath_list[0] = path;
|
xpath_list[0] = path;
|
||||||
vty_mgmt_send_get_config(vty, datastore, xpath_list, 1);
|
vty_mgmt_send_get_req(vty, true, datastore, xpath_list, 1);
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
|
|||||||
datastore = mgmt_ds_name2id(dsname);
|
datastore = mgmt_ds_name2id(dsname);
|
||||||
|
|
||||||
xpath_list[0] = path;
|
xpath_list[0] = path;
|
||||||
vty_mgmt_send_get_data(vty, datastore, xpath_list, 1);
|
vty_mgmt_send_get_req(vty, false, datastore, xpath_list, 1);
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user