sr : enable SRv6 uSID in the SRv6 API

Type: improvement

Change-Id: I026b1a8fd1df0e6ac1dba8df78b12cde95aae419
Signed-off-by: Ahmed Abdelsalam <ahabdels@cisco.com>
This commit is contained in:
Ahmed Abdelsalam 2024-11-12 08:56:45 -06:00 committed by Damjan Marion
parent 27a901ece3
commit c68c970838
5 changed files with 48 additions and 32 deletions

View File

@ -43,10 +43,22 @@
#define SR_BEHAVIOR_DX4 7
#define SR_BEHAVIOR_DT6 8
#define SR_BEHAVIOR_DT4 9
#define SR_BEHAVIOR_END_UN_PERF 10
#define SR_BEHAVIOR_END_UN 11
#define SR_BEHAVIOR_UA 12
#define SR_BEHAVIOR_LAST 13 /* Must always be the last one */
/**
* SR_BEHAVIOR_LAST
* Not used anymore. Kept not to break the API.
* We use SR_BEHAVIOR_CURRENT_LAST going forward
* */
#define SR_BEHAVIOR_LAST 10
#define SR_BEHAVIOR_END_UN_PERF 11
#define SR_BEHAVIOR_END_UN 12
#define SR_BEHAVIOR_UA 13
/**
* SR_BEHAVIOR_CURRENT_LAST
* MUST be updated everytime we add new behaviors.
* MUST be set to value of last added behavior + 1.
* */
#define SR_BEHAVIOR_CURRENT_LAST 14
#define SR_STEER_L2 2
#define SR_STEER_IPV4 4
@ -165,7 +177,8 @@ typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
*/
typedef struct
{
u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
u16 sr_localsid_function_number; /**< SR LocalSID plugin function
(>SR_BEHAVIOR_CURRENT_LAST) */
u8 *function_name; /**< Function name. (key). */

View File

@ -100,10 +100,10 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
{
/* Retrieve localsid */
ls = pool_elt_at_index (sm->localsids, p[0]);
if (ls->behavior >= SR_BEHAVIOR_LAST)
if (ls->behavior >= SR_BEHAVIOR_CURRENT_LAST)
{
plugin = pool_elt_at_index (sm->plugin_functions,
ls->behavior - SR_BEHAVIOR_LAST);
plugin = pool_elt_at_index (
sm->plugin_functions, ls->behavior - SR_BEHAVIOR_CURRENT_LAST);
pref_length = plugin->prefix_length;
}
@ -130,7 +130,7 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
|| ls->behavior == SR_BEHAVIOR_DX4)
adj_unlock (ls->nh_adj);
if (ls->behavior >= SR_BEHAVIOR_LAST)
if (ls->behavior >= SR_BEHAVIOR_CURRENT_LAST)
{
/* Callback plugin removal function */
rv = plugin->removal (ls);
@ -149,13 +149,13 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
if (is_del)
return -2;
if (behavior >= SR_BEHAVIOR_LAST)
{
sr_localsid_fn_registration_t *plugin = 0;
plugin =
pool_elt_at_index (sm->plugin_functions, behavior - SR_BEHAVIOR_LAST);
pref_length = plugin->prefix_length;
}
if (behavior >= SR_BEHAVIOR_CURRENT_LAST)
{
sr_localsid_fn_registration_t *plugin = 0;
plugin = pool_elt_at_index (sm->plugin_functions,
behavior - SR_BEHAVIOR_CURRENT_LAST);
pref_length = plugin->prefix_length;
}
if (localsid_prefix_len != 0)
{
@ -294,14 +294,14 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
ls->behavior == SR_BEHAVIOR_UA)
dpo_set (&dpo, sr_localsid_un_perf_dpo_type, DPO_PROTO_IP6,
ls - sm->localsids);
else if (ls->behavior > SR_BEHAVIOR_D_FIRST
&& ls->behavior < SR_BEHAVIOR_LAST)
else if (ls->behavior > SR_BEHAVIOR_D_FIRST &&
ls->behavior < SR_BEHAVIOR_CURRENT_LAST)
dpo_set (&dpo, sr_localsid_d_dpo_type, DPO_PROTO_IP6, ls - sm->localsids);
else if (ls->behavior >= SR_BEHAVIOR_LAST)
else if (ls->behavior >= SR_BEHAVIOR_CURRENT_LAST)
{
sr_localsid_fn_registration_t *plugin = 0;
plugin = pool_elt_at_index (sm->plugin_functions,
ls->behavior - SR_BEHAVIOR_LAST);
ls->behavior - SR_BEHAVIOR_CURRENT_LAST);
/* Copy the unformat memory result */
ls->plugin_mem = ls_plugin_mem;
/* Callback plugin creation function */
@ -672,11 +672,10 @@ show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
FIB_PROTOCOL_IP4));
break;
default:
if (ls->behavior >= SR_BEHAVIOR_LAST)
if (ls->behavior >= SR_BEHAVIOR_CURRENT_LAST)
{
sr_localsid_fn_registration_t *plugin =
pool_elt_at_index (sm->plugin_functions,
ls->behavior - SR_BEHAVIOR_LAST);
sr_localsid_fn_registration_t *plugin = pool_elt_at_index (
sm->plugin_functions, ls->behavior - SR_BEHAVIOR_CURRENT_LAST);
vlib_cli_output (vm, "\tAddress: \t%U/%u\n"
"\tBehavior: \t%s (%s)\n\t%U",
@ -2404,7 +2403,7 @@ sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name,
clib_memset (plugin, 0, sizeof (*plugin));
plugin->sr_localsid_function_number = (plugin - sm->plugin_functions);
plugin->sr_localsid_function_number += SR_BEHAVIOR_LAST;
plugin->sr_localsid_function_number += SR_BEHAVIOR_CURRENT_LAST;
plugin->prefix_length = prefix_length;
plugin->ls_format = ls_format;
plugin->ls_unformat = ls_unformat;

View File

@ -418,7 +418,7 @@ create_sl (ip6_sr_policy_t *sr_policy, ip6_address_t *sl,
{
plugin =
pool_elt_at_index (sm->policy_plugin_functions,
sr_policy->plugin - SR_BEHAVIOR_LAST);
sr_policy->plugin - SR_BEHAVIOR_CURRENT_LAST);
segment_list->plugin = sr_policy->plugin;
segment_list->plugin_mem = sr_policy->plugin_mem;
@ -828,7 +828,7 @@ sr_policy_del (ip6_address_t * bsid, u32 index)
plugin =
pool_elt_at_index (sm->policy_plugin_functions,
sr_policy->plugin - SR_BEHAVIOR_LAST);
sr_policy->plugin - SR_BEHAVIOR_CURRENT_LAST);
plugin->removal (sr_policy);
sr_policy->plugin = 0;
@ -3499,7 +3499,7 @@ sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
clib_memset (plugin, 0, sizeof (*plugin));
plugin->sr_policy_function_number = (plugin - sm->policy_plugin_functions);
plugin->sr_policy_function_number += SR_BEHAVIOR_LAST;
plugin->sr_policy_function_number += SR_BEHAVIOR_CURRENT_LAST;
plugin->prefix_length = prefix_length;
plugin->ls_format = ls_format;
plugin->ls_unformat = ls_unformat;

View File

@ -35,7 +35,10 @@ enum sr_behavior : u8
SR_BEHAVIOR_API_DX4 = 7,
SR_BEHAVIOR_API_DT6 = 8,
SR_BEHAVIOR_API_DT4 = 9,
SR_BEHAVIOR_API_LAST = 10, /* Must always be the last one */
SR_BEHAVIOR_API_LAST = 10, /* Not used. Kept not to break the API */
SR_BEHAVIOR_API_END_UN_PERF = 11 [backwards_compatible],
SR_BEHAVIOR_API_END_UN = 12 [backwards_compatible],
SR_BEHAVIOR_API_UA = 13 [backwards_compatible],
};
enum sr_steer : u8

View File

@ -20,9 +20,10 @@ class SRv6LocalSIDBehaviors:
SR_BEHAVIOR_DX4 = 7
SR_BEHAVIOR_DT6 = 8
SR_BEHAVIOR_DT4 = 9
SR_BEHAVIOR_END_UN_PERF = 10
SR_BEHAVIOR_END_UN = 11
SR_BEHAVIOR_LAST = 12 # Must always be the last one
SR_BEHAVIOR_LAST = 10 # Not used anymore. Kept not to break the API.
SR_BEHAVIOR_END_UN_PERF = 11
SR_BEHAVIOR_END_UN = 12
SR_BEHAVIOR_END_UA = 13
class SRv6PolicyType: