sharpd: support opaque zapi notifications

Add cli and support to sharpd to exercise the zapi opaque
'notification' features.

Signed-off-by: Mark Stapp <mjs@labn.net>
This commit is contained in:
Mark Stapp 2023-06-12 16:14:45 -04:00
parent de1a9ce0a7
commit f6700b3491
3 changed files with 59 additions and 1 deletions

View file

@ -865,6 +865,24 @@ DEFPY (send_opaque_reg,
return CMD_SUCCESS;
}
/* Opaque notifications - register or unregister */
DEFPY (send_opaque_notif_reg,
send_opaque_notif_reg_cmd,
"sharp send opaque notify <reg$reg | unreg> type (1-1000)",
SHARP_STR
"Send messages for testing\n"
"Send opaque messages\n"
"Opaque notification messages\n"
"Send notify registration\n"
"Send notify unregistration\n"
"Opaque sub-type code\n"
"Opaque sub-type code\n")
{
sharp_zebra_opaque_notif_reg((reg != NULL), type);
return CMD_SUCCESS;
}
DEFPY (neigh_discover,
neigh_discover_cmd,
"sharp neigh discover [vrf NAME$vrf_name] <A.B.C.D$dst4|X:X::X:X$dst6> IFNAME$ifname",
@ -1406,6 +1424,7 @@ void sharp_vty_init(void)
install_element(ENABLE_NODE, &send_opaque_cmd);
install_element(ENABLE_NODE, &send_opaque_unicast_cmd);
install_element(ENABLE_NODE, &send_opaque_reg_cmd);
install_element(ENABLE_NODE, &send_opaque_notif_reg_cmd);
install_element(ENABLE_NODE, &neigh_discover_cmd);
install_element(ENABLE_NODE, &import_te_cmd);

View file

@ -805,6 +805,28 @@ static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
return 0;
}
/* Handler for opaque notification messages */
static int sharp_opq_notify_handler(ZAPI_CALLBACK_ARGS)
{
struct stream *s;
struct zapi_opaque_notif_info info;
s = zclient->ibuf;
if (zclient_opaque_notif_decode(s, &info) != 0)
return -1;
if (info.reg)
zlog_debug("%s: received opaque notification REG, type %u => %d/%d/%d",
__func__, info.msg_type, info.proto, info.instance,
info.session_id);
else
zlog_debug("%s: received opaque notification UNREG, type %u",
__func__, info.msg_type);
return 0;
}
/*
* Send OPAQUE messages, using subtype 'type'.
*/
@ -840,6 +862,17 @@ void sharp_opaque_send(uint32_t type, uint32_t proto, uint32_t instance,
}
}
/*
* Register/unregister for opaque notifications from zebra about 'type'.
*/
void sharp_zebra_opaque_notif_reg(bool is_reg, uint32_t type)
{
if (is_reg)
zclient_opaque_request_notify(zclient, type);
else
zclient_opaque_drop_notify(zclient, type);
}
/*
* Send OPAQUE registration messages, using subtype 'type'.
*/
@ -1036,6 +1069,7 @@ static zclient_handler *const sharp_handlers[] = {
[ZEBRA_REDISTRIBUTE_ROUTE_ADD] = sharp_redistribute_route,
[ZEBRA_REDISTRIBUTE_ROUTE_DEL] = sharp_redistribute_route,
[ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler,
[ZEBRA_OPAQUE_NOTIFY] = sharp_opq_notify_handler,
[ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] =
sharp_zebra_process_srv6_locator_chunk,
};

View file

@ -39,10 +39,15 @@ int sharp_install_lsps_helper(bool install_p, bool update_p,
void sharp_opaque_send(uint32_t type, uint32_t proto, uint32_t instance,
uint32_t session_id, uint32_t count);
/* Send OPAQUE registration messages, using subtype 'type'. */
/* Send OPAQUE registration or notification registration messages,
* for opaque subtype 'type'.
*/
void sharp_opaque_reg_send(bool is_reg, uint32_t proto, uint32_t instance,
uint32_t session_id, uint32_t type);
/* Register/unregister for opaque notifications from zebra about 'type'. */
void sharp_zebra_opaque_notif_reg(bool is_reg, uint32_t type);
extern void sharp_zebra_send_arp(const struct interface *ifp,
const struct prefix *p);