From 2ac6c90d1866517628c6325c411c3fae526b9225 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 15 Apr 2020 16:31:57 -0400 Subject: [PATCH] sharpd: send new OPAQUE messages Add a simple cli to exercise the new OPAQUE messages. Signed-off-by: Mark Stapp --- sharpd/sharp_vty.c | 15 +++++++++++++++ sharpd/sharp_zebra.c | 29 +++++++++++++++++++++++++++++ sharpd/sharp_zebra.h | 3 +++ 3 files changed, 47 insertions(+) diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 987588947e..873d36a997 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -547,6 +547,20 @@ DEFPY (logpump, return CMD_SUCCESS; } +DEFPY (send_opaque, + send_opaque_cmd, + "sharp send opaque type (1-255) (1-1000)$count", + "Sharp Routing Protocol\n" + "Send messages for testing\n" + "Send opaque messages\n" + "Type code to send\n" + "Type code to send\n" + "Number of messages to send\n") +{ + sharp_opaque_send(type, count); + return CMD_SUCCESS; +} + void sharp_vty_init(void) { install_element(ENABLE_NODE, &install_routes_data_dump_cmd); @@ -559,6 +573,7 @@ void sharp_vty_init(void) install_element(ENABLE_NODE, &sharp_lsp_prefix_v4_cmd); install_element(ENABLE_NODE, &sharp_remove_lsp_prefix_v4_cmd); install_element(ENABLE_NODE, &logpump_cmd); + install_element(ENABLE_NODE, &send_opaque_cmd); install_element(VIEW_NODE, &show_debugging_sharpd_cmd); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 0795096440..1be6ec197b 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -480,6 +480,35 @@ static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS) return 0; } +/* + * Send OPAQUE messages, using subtype 'type'. + */ +void sharp_opaque_send(uint32_t type, uint32_t count) +{ + uint8_t buf[100]; + int ret; + uint32_t i; + + /* Prepare a small payload */ + for (i = 0; i < sizeof(buf); i++) { + if (type < 255) + buf[i] = type; + else + buf[i] = 255; + } + + /* Send some messages */ + for (i = 0; i < count; i++) { + ret = zclient_send_opaque(zclient, type, buf, sizeof(buf)); + if (ret < 0) { + zlog_debug("%s: send_opaque() failed => %d", + __func__, ret); + break; + } + } + +} + extern struct zebra_privs_t sharp_privs; void sharp_zebra_init(void) diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index 2b8e19dd97..ca7900b8c2 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -44,5 +44,8 @@ int sharp_install_lsps_helper(bool install_p, const struct prefix *p, uint8_t type, int instance, uint32_t in_label, const struct nexthop_group *nhg, const struct nexthop_group *backup_nhg); +/* Send OPAQUE messages, using subtype 'type'. */ +void sharp_opaque_send(uint32_t type, uint32_t count); + #endif -- 2.39.5