Skip to content

Commit

Permalink
sharpd: support opaque zapi notifications
Browse files Browse the repository at this point in the history
Add cli and support to sharpd to exercise the zapi opaque
'notification' features.

Signed-off-by: Mark Stapp <[email protected]>
  • Loading branch information
Mark Stapp committed Jun 23, 2023
1 parent de1a9ce commit f6700b3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
19 changes: 19 additions & 0 deletions sharpd/sharp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);

Expand Down
34 changes: 34 additions & 0 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
*/
Expand Down Expand Up @@ -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'.
*/
Expand Down Expand Up @@ -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,
};
Expand Down
7 changes: 6 additions & 1 deletion sharpd/sharp_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f6700b3

Please sign in to comment.