summaryrefslogtreecommitdiffstats
path: root/src/vlibmemory
diff options
context:
space:
mode:
authorOle Troan <otroan@employees.org>2024-01-23 18:56:23 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2024-01-29 22:57:31 +0000
commitac0babd412e3b5282136a5c5c5be2c4cc4be6895 (patch)
tree5c58249463d7121a163534e55b1d5f6f27ae7967 /src/vlibmemory
parentf34b6800de78d99192dc5757a4845e2668749c40 (diff)
api: provide api definition over api
This patch allows a client to bootstrap itself by downloading the JSON API definitions over the API itself. This patch enables it for Python (probably need a dynamic language). Call VPPApiClient with the new bootstrapapi=True parameter. Example (Python): from vpp_papi import VPPApiClient vpp = VPPApiClient(bootstrapapi=True) rv = vpp.connect("foobar") assert rv == 0 print(f'SHOW VERSION: {vpp.api.show_version()}') vpp.disconnect() Type: feature Change-Id: Id903fdccc82b2e22aa1994331d2c150253f2ccae Signed-off-by: Ole Troan <otroan@employees.org>
Diffstat (limited to 'src/vlibmemory')
-rw-r--r--src/vlibmemory/memclnt.api19
-rw-r--r--src/vlibmemory/memclnt_api.c36
2 files changed, 50 insertions, 5 deletions
diff --git a/src/vlibmemory/memclnt.api b/src/vlibmemory/memclnt.api
index a8e7cfeaec0..dc0f4e1c8a7 100644
--- a/src/vlibmemory/memclnt.api
+++ b/src/vlibmemory/memclnt.api
@@ -27,7 +27,7 @@ service {
};
/*
- * Create a client registration
+ * Create a client registration
*/
define memclnt_create {
option deprecated;
@@ -50,7 +50,7 @@ define memclnt_create_reply {
};
/*
- * Delete a client registration
+ * Delete a client registration
*/
define memclnt_delete {
u32 index; /* index, used e.g. by API trace replay */
@@ -155,7 +155,7 @@ typedef message_table_entry
};
/*
- * Create a socket client registration.
+ * Create a socket client registration.
*/
define sockclnt_create {
u32 context; /* opaque value to be returned in the reply */
@@ -172,7 +172,7 @@ define sockclnt_create_reply {
};
/*
- * Delete a client registration
+ * Delete a client registration
*/
define sockclnt_delete {
u32 client_index;
@@ -252,3 +252,14 @@ define memclnt_create_v2_reply {
u32 index; /* index, used e.g. by API trace replay */
u64 message_table; /* serialized message table in shmem */
};
+
+define get_api_json {
+ u32 client_index;
+ u32 context;
+};
+
+define get_api_json_reply {
+ u32 context;
+ i32 retval;
+ string json[];
+};
diff --git a/src/vlibmemory/memclnt_api.c b/src/vlibmemory/memclnt_api.c
index 7eb61fe7875..299e8d93f02 100644
--- a/src/vlibmemory/memclnt_api.c
+++ b/src/vlibmemory/memclnt_api.c
@@ -145,10 +145,44 @@ vl_api_control_ping_t_handler (vl_api_control_ping_t *mp)
({ rmp->vpe_pid = ntohl (getpid ()); }));
}
+static void
+vl_api_get_api_json_t_handler (vl_api_get_api_json_t *mp)
+{
+ vl_api_get_api_json_reply_t *rmp;
+ api_main_t *am = vlibapi_get_main ();
+ int rv = 0, n = 0;
+ u8 *s = 0;
+
+ vl_api_registration_t *rp =
+ vl_api_client_index_to_registration (mp->client_index);
+ if (rp == 0)
+ return;
+
+ s = format (s, "[\n");
+ u8 **ptr;
+ vec_foreach (ptr, am->json_api_repr)
+ {
+ s = format (s, "%s,", ptr[0]);
+ }
+ s[vec_len (s) - 1] = ']'; // Replace last comma with a bracket
+ vec_terminate_c_string (s);
+ n = vec_len (s);
+
+done:
+ REPLY_MACRO3 (VL_API_GET_API_JSON_REPLY, n, ({
+ if (rv == 0)
+ {
+ vl_api_c_string_to_api_string ((char *) s, &rmp->json);
+ }
+ }));
+ vec_free (s);
+}
+
#define foreach_vlib_api_msg \
_ (GET_FIRST_MSG_ID, get_first_msg_id) \
_ (API_VERSIONS, api_versions) \
- _ (CONTROL_PING, control_ping)
+ _ (CONTROL_PING, control_ping) \
+ _ (GET_API_JSON, get_api_json)
/*
* vl_api_init