staticd: Add Northbound APIs for SRv6

Add Northbound APIs to create/modify/destroy an SRv6 SID

Signed-off-by: Yuqing Zhao <galadriel.zyq@alibaba-inc.com>
This commit is contained in:
Yuqing Zhao 2025-01-13 11:10:20 +01:00
parent 73fdae9bea
commit 07ba1cd8b8
3 changed files with 281 additions and 0 deletions

View 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,
},

View 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(

View 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;
}