diff options
author | Christian Hopps <chopps@labn.net> | 2023-06-27 19:58:54 +0200 |
---|---|---|
committer | Christian Hopps <chopps@labn.net> | 2023-06-28 00:00:56 +0200 |
commit | dbb1bc6f355ae53ce1f2402a1ac196e9f9e18a42 (patch) | |
tree | 95440d9560362977bbd485ffdab1b30f7f8f5cc0 | |
parent | mgmtd: inclusive language change (diff) | |
download | frr-dbb1bc6f355ae53ce1f2402a1ac196e9f9e18a42.tar.xz frr-dbb1bc6f355ae53ce1f2402a1ac196e9f9e18a42.zip |
mgmtd: consolidate getcfg and getdata msgs into "get"
eliminates tons of copy and paste code.
Signed-off-by: Christian Hopps <chopps@labn.net>
-rw-r--r-- | lib/mgmt.proto | 44 | ||||
-rw-r--r-- | lib/mgmt_fe_client.c | 117 | ||||
-rw-r--r-- | lib/mgmt_fe_client.h | 32 | ||||
-rw-r--r-- | lib/vty.c | 51 | ||||
-rw-r--r-- | lib/vty.h | 8 | ||||
-rw-r--r-- | mgmtd/mgmt_fe_adapter.c | 439 | ||||
-rw-r--r-- | mgmtd/mgmt_fe_adapter.h | 32 | ||||
-rw-r--r-- | mgmtd/mgmt_txn.c | 82 | ||||
-rw-r--r-- | mgmtd/mgmt_txn.h | 25 | ||||
-rw-r--r-- | mgmtd/mgmt_vty.c | 4 |
10 files changed, 240 insertions, 594 deletions
diff --git a/lib/mgmt.proto b/lib/mgmt.proto index ac44eefd9..14d00fa10 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 45d57175d..da19db463 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 532fee439..286141da4 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. @@ -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) { @@ -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); diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c index 70c08d5cb..c12d8646b 100644 --- a/mgmtd/mgmt_fe_adapter.c +++ b/mgmtd/mgmt_fe_adapter.c @@ -273,9 +273,8 @@ mgmt_fe_create_session(struct mgmt_fe_client_adapter *adapter, return session; } -static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, - Mgmtd__FeMessage *fe_msg, - bool short_circuit_ok) +static int fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, + Mgmtd__FeMessage *fe_msg, bool short_circuit_ok) { return msg_conn_send_msg( adapter->conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg, @@ -284,10 +283,9 @@ static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, short_circuit_ok); } -static int -mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter, - struct mgmt_fe_session_ctx *session, - bool create, bool success) +static int fe_adapter_send_session_reply(struct mgmt_fe_client_adapter *adapter, + struct mgmt_fe_session_ctx *session, + bool create, bool success) { Mgmtd__FeMessage fe_msg; Mgmtd__FeSessionReply session_reply; @@ -309,13 +307,13 @@ mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter, "Sending SESSION_REPLY message to MGMTD Frontend client '%s'", 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, - Mgmtd__DatastoreId ds_id, - uint64_t req_id, bool lock_ds, - bool success, const char *error_if_any) +static int fe_adapter_send_lockds_reply(struct mgmt_fe_session_ctx *session, + Mgmtd__DatastoreId ds_id, + uint64_t req_id, bool lock_ds, + bool success, const char *error_if_any) { Mgmtd__FeMessage fe_msg; Mgmtd__FeLockDsReply lockds_reply; @@ -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", 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, uint64_t req_id, bool success, 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); 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, Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, enum mgmt_result result, bool validate_only, const char *error_if_any) @@ -433,83 +431,43 @@ static int mgmt_fe_send_commitcfg_reply( if (mm->perf_stats_en) gettimeofday(&session->adapter->cmt_stats.last_end, NULL); mgmt_fe_session_compute_commit_timers(&session->adapter->cmt_stats); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); -} - -static int mgmt_fe_send_getcfg_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__FeGetConfigReply getcfg_reply; - - assert(session->adapter); - - mgmtd__fe_get_config_reply__init(&getcfg_reply); - getcfg_reply.session_id = session->session_id; - getcfg_reply.ds_id = ds_id; - getcfg_reply.req_id = req_id; - getcfg_reply.success = success; - getcfg_reply.data = data; - if (error_if_any) - getcfg_reply.error_if_any = (char *)error_if_any; - - mgmtd__fe_message__init(&fe_msg); - fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY; - fe_msg.getcfg_reply = &getcfg_reply; - - MGMTD_FE_ADAPTER_DBG( - "Sending GET_CONFIG_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); + 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) +static int fe_adapter_send_get_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; + Mgmtd__FeGetReply get_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; + mgmtd__fe_get_reply__init(&get_reply); + get_reply.session_id = session->session_id; + get_reply.ds_id = ds_id; + get_reply.req_id = req_id; + get_reply.success = success; + get_reply.data = data; if (error_if_any) - getdata_reply.error_if_any = (char *)error_if_any; + get_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; + fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY; + fe_msg.get_reply = &get_reply; - MGMTD_FE_ADAPTER_DBG( - "Sending GET_DATA_REPLY message to MGMTD Frontend client '%s'", - session->adapter->name); + MGMTD_FE_ADAPTER_DBG("Sending GET_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); + mgmt_fe_session_register_event(session, + 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 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; } -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) { 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 && 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, lockds_req->lock, false, "Lock/Unlock on DS other than candidate or running DS not supported"); @@ -640,10 +585,10 @@ 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); if (!ds_ctx) { - mgmt_fe_send_lockds_reply( - session, lockds_req->ds_id, lockds_req->req_id, - lockds_req->lock, false, - "Failed to retrieve handle for DS!"); + fe_adapter_send_lockds_reply(session, lockds_req->ds_id, + lockds_req->req_id, + lockds_req->lock, false, + "Failed to retrieve handle for DS!"); 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, ds_ctx, session) != 0) { - mgmt_fe_send_lockds_reply( + fe_adapter_send_lockds_reply( session, lockds_req->ds_id, lockds_req->req_id, lockds_req->lock, false, "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 { 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, lockds_req->lock, false, "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); } - if (mgmt_fe_send_lockds_reply(session, lockds_req->ds_id, - lockds_req->req_id, lockds_req->lock, - true, NULL) - != 0) { + if (fe_adapter_send_lockds_reply(session, lockds_req->ds_id, + lockds_req->req_id, lockds_req->lock, + true, NULL) != 0) { MGMTD_FE_ADAPTER_DBG( "Failed to send LOCK_DS_REPLY for DS %u session-id: %" PRIu64 " 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. */ 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, "Set-Config on datastores other than Candidate DS not supported", 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. */ if (setcfg_req->implicit_commit && 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, "Implicit commit on datastores other than running DS not supported", setcfg_req->implicit_commit); @@ -723,10 +667,10 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, /* User should have write lock to change the DS */ if (!session->ds_locked[setcfg_req->ds_id]) { - mgmt_fe_send_setcfg_reply(session, setcfg_req->ds_id, - setcfg_req->req_id, false, - "Candidate DS is not locked", - setcfg_req->implicit_commit); + fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id, + setcfg_req->req_id, false, + "Candidate DS is not locked", + setcfg_req->implicit_commit); return 0; } @@ -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, MGMTD_TXN_TYPE_CONFIG); 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, false, "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, * 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, false, "A Configuration transaction is already in progress!", @@ -771,16 +715,16 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, } /* Create the SETConfig request under the transaction. */ - if (mgmt_txn_send_set_config_req( - session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id, - ds_ctx, setcfg_req->data, setcfg_req->n_data, - setcfg_req->implicit_commit, setcfg_req->commit_ds_id, - dst_ds_ctx) - != 0) { - mgmt_fe_send_setcfg_reply( - session, setcfg_req->ds_id, setcfg_req->req_id, false, - "Request processing for SET-CONFIG failed!", - setcfg_req->implicit_commit); + if (mgmt_txn_send_set_config_req(session->cfg_txn_id, setcfg_req->req_id, + setcfg_req->ds_id, ds_ctx, + setcfg_req->data, setcfg_req->n_data, + setcfg_req->implicit_commit, + setcfg_req->commit_ds_id, + dst_ds_ctx) != 0) { + fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id, + setcfg_req->req_id, false, + "Request processing for SET-CONFIG failed!", + setcfg_req->implicit_commit); /* delete transaction if we just created it */ if (txn_created) @@ -790,33 +734,27 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, return 0; } -static int -mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session, - Mgmtd__FeGetConfigReq *getcfg_req) +static int mgmt_fe_session_handle_get_req_msg(struct mgmt_fe_session_ctx *session, + Mgmtd__FeGetReq *get_req) { struct mgmt_ds_ctx *ds_ctx; struct nb_config *cfg_root = NULL; - - /* - * Get the DS handle. - */ - ds_ctx = mgmt_ds_get_ctx_by_id(mm, getcfg_req->ds_id); - if (!ds_ctx) { - mgmt_fe_send_getcfg_reply(session, getcfg_req->ds_id, - getcfg_req->req_id, false, NULL, - "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!"); + 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) + ds_ok = false; + else if (!is_cfg && ds_id != MGMTD_DS_OPERATIONAL) + ds_ok = false; + if (!ds_ok) { + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "get-req on unsupported datastore"); return 0; } + ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id); + assert(ds_ctx); 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, MGMTD_TXN_TYPE_SHOW); if (session->txn_id == MGMTD_SESSION_ID_NONE) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, getcfg_req->req_id, - false, NULL, - "Failed to create a Show transaction!"); - goto mgmt_fe_sess_handle_getcfg_req_failed; + fe_adapter_send_get_reply(session, ds_id, req_id, false, + NULL, + "Failed to create a Show transaction!"); + return -1; } MGMTD_FE_ADAPTER_DBG("Created new show txn-id: %" PRIu64 " for session-id: %" PRIu64, session->txn_id, session->session_id); } else { - MGMTD_FE_ADAPTER_DBG("Show txn-id: %" PRIu64 - " for session-id: %" PRIu64 - " already created", + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "Request processing for GET failed!"); + MGMTD_FE_ADAPTER_DBG("Transaction in progress txn-id: %" PRIu64 + " for session-id: %" PRIu64, session->txn_id, session->session_id); + return -1; } /* * Get a copy of the datastore config root, avoids locking. */ - cfg_root = nb_config_dup(mgmt_ds_get_nb_config(ds_ctx)); + if (is_cfg) + 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( - session->txn_id, getcfg_req->req_id, getcfg_req->ds_id, - cfg_root, getcfg_req->data, getcfg_req->n_data) != 0) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, getcfg_req->req_id, false, - NULL, "Request processing for GET-CONFIG failed!"); - goto mgmt_fe_sess_handle_getcfg_req_failed; + if (mgmt_txn_send_get_req(session->txn_id, req_id, ds_id, cfg_root, + get_req->data, get_req->n_data)) { + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "Request processing for GET failed!"); + + goto failed; } return 0; - -mgmt_fe_sess_handle_getcfg_req_failed: - +failed: if (cfg_root) nb_config_free(cfg_root); /* @@ -874,79 +811,6 @@ mgmt_fe_sess_handle_getcfg_req_failed: 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( 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 */ if (commcfg_req->src_ds_id != MGMTD_DS_CANDIDATE || 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, commcfg_req->req_id, MGMTD_INTERNAL_ERROR, 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 */ if (!session->ds_locked[commcfg_req->dst_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, commcfg_req->req_id, MGMTD_DS_LOCK_FAILED, 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, MGMTD_TXN_TYPE_CONFIG); 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, commcfg_req->dst_ds_id, commcfg_req->req_id, - MGMTD_INTERNAL_ERROR, - commcfg_req->validate_only, + MGMTD_INTERNAL_ERROR, commcfg_req->validate_only, "Failed to create a Configuration session!"); 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, dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort, false) != 0) { - mgmt_fe_send_commitcfg_reply( + fe_adapter_send_commit_cfg_reply( session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, commcfg_req->req_id, MGMTD_INTERNAL_ERROR, commcfg_req->validate_only, @@ -1058,8 +921,8 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_fe_create_session( adapter, fe_msg->session_req->client_conn_id); - mgmt_fe_send_session_reply(adapter, session, true, - session ? true : false); + fe_adapter_send_session_reply(adapter, session, true, + session ? true : false); } else if ( !fe_msg->session_req->create && fe_msg->session_req->id_case @@ -1071,8 +934,8 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_session_id2ctx( fe_msg->session_req->session_id); - mgmt_fe_send_session_reply(adapter, session, false, - true); + fe_adapter_send_session_reply(adapter, session, false, + true); mgmt_fe_cleanup_session(&session); } break; @@ -1116,29 +979,15 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, mgmt_fe_session_handle_commit_config_req_msg( session, fe_msg->commcfg_req); break; - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ: - session = mgmt_session_id2ctx( - fe_msg->getcfg_req->session_id); - MGMTD_FE_ADAPTER_DBG( - "Got GETCFG_REQ for DS:%s (xpaths: %d) on session-id %" PRIu64 - " from '%s'", - mgmt_ds_id2name(fe_msg->getcfg_req->ds_id), - (int)fe_msg->getcfg_req->n_data, - fe_msg->getcfg_req->session_id, adapter->name); - mgmt_fe_session_handle_getcfg_req_msg( - session, fe_msg->getcfg_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); + case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ: + session = mgmt_session_id2ctx(fe_msg->get_req->session_id); + MGMTD_FE_ADAPTER_DBG("Got GET_REQ (iscfg %d) for DS:%s (xpaths: %d) on session-id %" PRIu64 + " from '%s'", + (int)fe_msg->get_req->config, + mgmt_ds_id2name(fe_msg->get_req->ds_id), + (int)fe_msg->get_req->n_data, + fe_msg->get_req->session_id, adapter->name); + mgmt_fe_session_handle_get_req_msg(session, fe_msg->get_req); break; case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_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_SETCFG_REPLY: case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY: - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY: - case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY: + case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY: case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET: default: /* @@ -1293,11 +1141,6 @@ struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *from) 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, Mgmtd__DatastoreId ds_id, uint64_t req_id, enum mgmt_result result, @@ -1316,9 +1159,10 @@ int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id, return -1; } - return mgmt_fe_send_setcfg_reply( - session, ds_id, req_id, result == MGMTD_SUCCESS ? true : false, - error_if_any, implicit_commit); + return fe_adapter_send_set_cfg_reply(session, ds_id, req_id, + result == MGMTD_SUCCESS ? true + : false, + error_if_any, implicit_commit); } int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id, @@ -1334,16 +1178,16 @@ int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id, if (!session || session->cfg_txn_id != txn_id) 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, error_if_any); } -int mgmt_fe_send_get_cfg_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) +int mgmt_fe_send_get_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; @@ -1351,34 +1195,9 @@ int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id, if (!session || session->txn_id != txn_id) return -1; - return mgmt_fe_send_getcfg_reply(session, ds_id, req_id, - result == MGMTD_SUCCESS, data_resp, - 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; + return fe_adapter_send_get_reply(session, ds_id, req_id, + result == MGMTD_SUCCESS, data_resp, + error_if_any); } struct mgmt_setcfg_stats * diff --git a/mgmtd/mgmt_fe_adapter.h b/mgmtd/mgmt_fe_adapter.h index fef205f36..d2991ec1d 100644 --- a/mgmtd/mgmt_fe_adapter.h +++ b/mgmtd/mgmt_fe_adapter.h @@ -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, 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. * @@ -134,29 +130,13 @@ extern int mgmt_fe_send_commit_cfg_reply( enum mgmt_result result, const char *error_if_any); /* - * Send get-config reply to the frontend client. - */ -extern int mgmt_fe_send_get_cfg_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 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. + * Send get-config/get-data reply to the frontend client. */ -extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id, - Mgmtd__YangData * data_resp[], - int num_data); +extern int mgmt_fe_send_get_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); /* Fetch frontend client session set-config stats */ extern struct mgmt_setcfg_stats * diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c index d3f321807..eff3b7e34 100644 --- a/mgmtd/mgmt_txn.c +++ b/mgmtd/mgmt_txn.c @@ -1659,11 +1659,10 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req, switch (txn_req->req_event) { case MGMTD_TXN_PROC_GETCFG: - if (mgmt_fe_send_get_cfg_reply(txn_req->txn->session_id, - txn_req->txn->txn_id, - get_req->ds_id, txn_req->req_id, - MGMTD_SUCCESS, data_reply, - NULL) != 0) { + if (mgmt_fe_send_get_reply(txn_req->txn->session_id, + txn_req->txn->txn_id, get_req->ds_id, + txn_req->req_id, MGMTD_SUCCESS, + data_reply, NULL) != 0) { MGMTD_TXN_ERR("Failed to send GET-CONFIG-REPLY txn-id: %" PRIu64 " session-id: %" PRIu64 " req-id: %" PRIu64, @@ -1672,11 +1671,10 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req, } break; case MGMTD_TXN_PROC_GETDATA: - if (mgmt_fe_send_get_data_reply(txn_req->txn->session_id, - txn_req->txn->txn_id, - get_req->ds_id, txn_req->req_id, - MGMTD_SUCCESS, data_reply, - NULL) != 0) { + if (mgmt_fe_send_get_reply(txn_req->txn->session_id, + txn_req->txn->txn_id, get_req->ds_id, + txn_req->req_id, MGMTD_SUCCESS, + data_reply, NULL) != 0) { MGMTD_TXN_ERR("Failed to send GET-DATA-REPLY txn-id: %" PRIu64 " session-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, sizeof(struct mgmt_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_req->req_id, MGMTD_INTERNAL_ERROR, NULL, "Internal error: Unable to allocate reply buffers!"); @@ -1783,11 +1781,10 @@ static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn, (void *)txn_req) == -1) { MGMTD_TXN_DBG("Invalid Xpath '%s", get_data->xpaths[indx]); - mgmt_fe_send_get_cfg_reply(txn->session_id, txn->txn_id, - get_data->ds_id, - txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, - "Invalid xpath"); + mgmt_fe_send_get_reply(txn->session_id, txn->txn_id, + get_data->ds_id, txn_req->req_id, + MGMTD_INTERNAL_ERROR, NULL, + "Invalid xpath"); goto mgmt_txn_get_config_failed; } MGMTD_TXN_DBG("Got %d remaining data-replies for xpath '%s'", @@ -1884,11 +1881,10 @@ static void mgmt_txn_process_get_data(struct event *thread) * TODO: Trigger GET procedures for Backend * For now return back error. */ - mgmt_fe_send_get_data_reply(txn->session_id, txn->txn_id, - txn_req->req.get_data->ds_id, - txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, - "GET-DATA on Oper DS is not supported yet!"); + mgmt_fe_send_get_reply(txn->session_id, txn->txn_id, + txn_req->req.get_data->ds_id, + txn_req->req_id, MGMTD_INTERNAL_ERROR, + NULL, "GET-DATA is not supported yet!"); /* * Delete the txn request. * Note: The following will remove it from the list @@ -2532,52 +2528,24 @@ int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success, return 0; } -int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct nb_config *cfg_root, - Mgmtd__YangGetDataReq **data_req, - size_t num_reqs) +int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, struct nb_config *cfg_root, + Mgmtd__YangGetDataReq **data_req, size_t num_reqs) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; + enum mgmt_txn_event req_event; 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_GETCFG); - txn_req->req.get_data->ds_id = ds_id; - txn_req->req.get_data->cfg_root = cfg_root; - 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_GETCFG); + req_event = cfg_root ? MGMTD_TXN_PROC_GETCFG : MGMTD_TXN_PROC_GETDATA; - 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 = mgmt_txn_req_alloc(txn, req_id, req_event); txn_req->req.get_data->ds_id = ds_id; - txn_req->req.get_data->cfg_root = NULL; + txn_req->req.get_data->cfg_root = cfg_root; for (indx = 0; indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH; indx++) { @@ -2587,7 +2555,7 @@ int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id, txn_req->req.get_data->num_xpaths++; } - mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA); + mgmt_txn_register_event(txn, req_event); return 0; } diff --git a/mgmtd/mgmt_txn.h b/mgmtd/mgmt_txn.h index 69d75fed0..068f07a5c 100644 --- a/mgmtd/mgmt_txn.h +++ b/mgmtd/mgmt_txn.h @@ -177,25 +177,16 @@ extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id, 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, - Mgmtd__DatastoreId ds_id, - struct nb_config *cfg_root, - Mgmtd__YangGetDataReq **data_req, - 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); +extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, + struct nb_config *cfg_root, + Mgmtd__YangGetDataReq **data_req, + size_t num_reqs); /* * Notifiy backend adapter on connection. diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 6a6f32353..44c6c0097 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -194,7 +194,7 @@ DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd, datastore = mgmt_ds_name2id(dsname); 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; } @@ -214,7 +214,7 @@ DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd, datastore = mgmt_ds_name2id(dsname); 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; } |