]> git.puffer.fish Git - mirror/frr.git/commitdiff
staticd: Add Northbound APIs for SRv6
authorYuqing Zhao <galadriel.zyq@alibaba-inc.com>
Mon, 13 Jan 2025 10:10:20 +0000 (11:10 +0100)
committerYuqing Zhao <galadriel.zyq@alibaba-inc.com>
Sat, 18 Jan 2025 10:28:49 +0000 (10:28 +0000)
Add Northbound APIs to create/modify/destroy an SRv6 SID

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
staticd/static_nb.c
staticd/static_nb.h
staticd/static_nb_config.c

index e6aa71a77b48afc61950fb1c83afa142937a82dc..356324126a44cb970c39d38c41e5495bb3c4e01f 100644 (file)
@@ -224,6 +224,35 @@ const struct frr_yang_module_info frr_staticd_info = {
                                .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/static-sids/sid",
+                       .cbs = {
+                               .apply_finish = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_apply_finish,
+                               .create = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_create,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/static-sids/sid/behavior",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/static-sids/sid/vrf-name",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/static-sids/sid/locator-name",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_destroy,
+                       }
+               },
                {
                        .xpath = NULL,
                },
index be75d9d38ce3bd83ebd10a82573dac21d6c4f629..9cf4126ba53f05ad750b0809e0a50c66c76023af 100644 (file)
@@ -118,6 +118,34 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr
        struct nb_cb_modify_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
        struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_modify(
+       struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_modify(
+       struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_modify(
+       struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_destroy(
+       struct nb_cb_destroy_args *args);
 
 /* Optional 'apply_finish' callbacks. */
 
@@ -125,6 +153,8 @@ void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_p
        struct nb_cb_apply_finish_args *args);
 void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish(
        struct nb_cb_apply_finish_args *args);
+void routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_apply_finish(
+       struct nb_cb_apply_finish_args *args);
 
 /* Optional 'pre_validate' callbacks. */
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate(
index 7de5f0474aad9a03dcfcc421f27948b4f84aabe7..51de05c2eaa98d4252d143aaddd36c8703ffc1bb 100644 (file)
@@ -20,6 +20,9 @@
 #include "static_nb.h"
 #include "static_zebra.h"
 
+#include "static_srv6.h"
+#include "static_debug.h"
+
 
 static int static_path_list_create(struct nb_cb_create_args *args)
 {
@@ -1367,3 +1370,222 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr
 
        return NB_OK;
 }
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_create(
+       struct nb_cb_create_args *args)
+{
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_create(
+       struct nb_cb_create_args *args)
+{
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/static-sids
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_create(
+       struct nb_cb_create_args *args)
+{
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/locators/locator/static-sids/sid
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_create(
+       struct nb_cb_create_args *args)
+{
+       struct static_srv6_sid *sid;
+       struct prefix_ipv6 sid_value;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       yang_dnode_get_ipv6p(&sid_value, args->dnode, "sid");
+       sid = static_srv6_sid_alloc(&sid_value);
+       nb_running_set_entry(args->dnode, sid);
+
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       struct static_srv6_sid *sid;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       sid = nb_running_unset_entry(args->dnode);
+       listnode_delete(srv6_sids, sid);
+       static_srv6_sid_del(sid);
+
+       return NB_OK;
+}
+
+void routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_apply_finish(
+       struct nb_cb_apply_finish_args *args)
+{
+       struct static_srv6_sid *sid;
+       struct static_srv6_locator *locator;
+
+       sid = nb_running_get_entry(args->dnode, NULL, true);
+
+       locator = static_srv6_locator_lookup(sid->locator_name);
+       if (!locator) {
+               DEBUGD(&static_dbg_srv6,
+                      "%s: Locator %s not found, trying to get locator information from zebra",
+                      __func__, sid->locator_name);
+               static_zebra_srv6_manager_get_locator(sid->locator_name);
+               listnode_add(srv6_sids, sid);
+               return;
+       }
+
+       sid->locator = locator;
+
+       listnode_add(srv6_sids, sid);
+       static_zebra_request_srv6_sid(sid);
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/locators/locator/static-sids/sid/behavior
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct static_srv6_sid *sid;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       sid = nb_running_get_entry(args->dnode, NULL, true);
+
+       /* Release and uninstall existing SID, if any, before requesting the new one */
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID)) {
+               static_zebra_release_srv6_sid(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID);
+       }
+
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA)) {
+               static_zebra_srv6_sid_uninstall(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA);
+       }
+
+       sid->behavior = yang_dnode_get_enum(args->dnode, "../behavior");
+
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_behavior_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/locators/locator/static-sids/sid/vrf-name
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct static_srv6_sid *sid;
+       const char *vrf_name;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       sid = nb_running_get_entry(args->dnode, NULL, true);
+
+       /* Release and uninstall existing SID, if any, before requesting the new one */
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID)) {
+               static_zebra_release_srv6_sid(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID);
+       }
+
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA)) {
+               static_zebra_srv6_sid_uninstall(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA);
+       }
+
+       vrf_name = yang_dnode_get_string(args->dnode, "../vrf-name");
+       snprintf(sid->attributes.vrf_name, sizeof(sid->attributes.vrf_name), "%s", vrf_name);
+
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_vrf_name_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/segment-routing/srv6/locators/locator/static-sids/sid/vrf-name
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct static_srv6_sid *sid;
+       const char *loc_name;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       sid = nb_running_get_entry(args->dnode, NULL, true);
+
+       /* Release and uninstall existing SID, if any, before requesting the new one */
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID)) {
+               static_zebra_release_srv6_sid(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_VALID);
+       }
+
+       if (CHECK_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA)) {
+               static_zebra_srv6_sid_uninstall(sid);
+               UNSET_FLAG(sid->flags, STATIC_FLAG_SRV6_SID_SENT_TO_ZEBRA);
+       }
+
+       loc_name = yang_dnode_get_string(args->dnode, "../locator-name");
+       snprintf(sid->locator_name, sizeof(sid->locator_name), "%s", loc_name);
+
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_segment_routing_srv6_local_sids_sid_locator_name_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return NB_OK;
+}