lyd_free_all(dnode);
}
+void yang_dnode_rpc_output_add(struct lyd_node *output, const char *xpath,
+ const char *value)
+{
+ LY_ERR err;
+
+ err = lyd_new_path(output, ly_native_ctx, xpath, value,
+ LYD_NEW_PATH_OUTPUT | LYD_NEW_PATH_UPDATE, NULL);
+ assert(err == LY_SUCCESS);
+}
+
struct yang_data *yang_data_new(const char *xpath, const char *value)
{
struct yang_data *data;
*/
extern void yang_dnode_free(struct lyd_node *dnode);
+/*
+ * Add a libyang data node to an RPC/action output container.
+ *
+ * output
+ * RPC/action output container.
+ *
+ * xpath
+ * XPath of the data node to add, relative to the output container.
+ *
+ * value
+ * String representing the value of the data node.
+ */
+extern void yang_dnode_rpc_output_add(struct lyd_node *output,
+ const char *xpath, const char *value);
+
/*
* Create a new yang_data structure.
*
#include "lib_vty.h"
#include "log.h"
#include "northbound.h"
+#include "northbound_cli.h"
static struct event_loop *master;
return NULL;
}
+/*
+ * XPath: /frr-test-module:frr-test-module/vrfs/vrf/ping
+ */
+static int frr_test_module_vrfs_vrf_ping(struct nb_cb_rpc_args *args)
+{
+ const char *vrf = yang_dnode_get_string(args->input, "../name");
+ const char *data = yang_dnode_get_string(args->input, "data");
+
+ yang_dnode_rpc_output_add(args->output, "vrf", vrf);
+ yang_dnode_rpc_output_add(args->output, "data-out", data);
+
+ return NB_OK;
+}
/*
* XPath: /frr-test-module:frr-test-module/c1value
.xpath = "/frr-test-module:frr-test-module/vrfs/vrf/routes/route/active",
.cbs.get_elem = frr_test_module_vrfs_vrf_routes_route_active_get_elem,
},
+ {
+ .xpath = "/frr-test-module:frr-test-module/vrfs/vrf/ping",
+ .cbs.rpc = frr_test_module_vrfs_vrf_ping,
+ },
{
.xpath = "/frr-test-module:frr-test-module/c1value",
.cbs.get_elem = frr_test_module_c1value_get_elem,
};
/* clang-format on */
+DEFUN(test_rpc, test_rpc_cmd, "test rpc",
+ "Test\n"
+ "RPC\n")
+{
+ struct lyd_node *output = NULL;
+ char xpath[XPATH_MAXLEN];
+ int ret;
+
+ snprintf(xpath, sizeof(xpath),
+ "/frr-test-module:frr-test-module/vrfs/vrf[name='testname']/ping");
+
+ nb_cli_rpc_enqueue(vty, "data", "testdata");
+
+ ret = nb_cli_rpc(vty, xpath, &output);
+ if (ret != CMD_SUCCESS) {
+ vty_out(vty, "RPC failed\n");
+ return ret;
+ }
+
+ vty_out(vty, "vrf %s data %s\n", yang_dnode_get_string(output, "vrf"),
+ yang_dnode_get_string(output, "data-out"));
+
+ yang_dnode_free(output);
+
+ return CMD_SUCCESS;
+}
+
static const struct frr_yang_module_info *const modules[] = {
&frr_test_module_info,
};
lib_cmd_init();
nb_init(master, modules, array_size(modules), false);
+ install_element(ENABLE_NODE, &test_rpc_cmd);
+
/* Create artificial data. */
create_data(num_vrfs, num_interfaces, num_routes);