]> git.puffer.fish Git - matthieu/frr.git/commitdiff
sharpd: support opaque zapi notifications
authorMark Stapp <mjs@labn.net>
Mon, 12 Jun 2023 20:14:45 +0000 (16:14 -0400)
committerMark Stapp <mjs@labn.net>
Fri, 23 Jun 2023 12:57:37 +0000 (08:57 -0400)
Add cli and support to sharpd to exercise the zapi opaque
'notification' features.

Signed-off-by: Mark Stapp <mjs@labn.net>
sharpd/sharp_vty.c
sharpd/sharp_zebra.c
sharpd/sharp_zebra.h

index ca2212cd87136a0af224f5e7ca3aec2737d794c0..3a2a7aa407d2697b2e7ab962801a99075444291c 100644 (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);
 
index 91fb7f03b107c822e6de1b54fc7a31b606493ebf..df18118b028d36eb121ceed3489b7c633564c97e 100644 (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,
 };
index cf8689799aa518b125f15330b853e768682f923a..025b4d8f82577942c7e3b7c7691ef1bcb6214bae 100644 (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);