+/*************************** SR Policy plugins ******************************/
+/**
+ * @brief SR Policy plugin registry
+ */
+int
+sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
+ u8 * keyword_str, u8 * def_str,
+ u8 * params_str, u8 prefix_length,
+ dpo_type_t * dpo,
+ format_function_t * ls_format,
+ unformat_function_t * ls_unformat,
+ sr_p_plugin_callback_t * creation_fn,
+ sr_p_plugin_callback_t * removal_fn)
+{
+ ip6_sr_main_t *sm = &sr_main;
+ uword *p;
+
+ sr_policy_fn_registration_t *plugin;
+
+ /* Did this function exist? If so update it */
+ p = hash_get_mem (sm->policy_plugin_functions_by_key, fn_name);
+ if (p)
+ {
+ plugin = pool_elt_at_index (sm->policy_plugin_functions, p[0]);
+ }
+ /* Else create a new one and set hash key */
+ else
+ {
+ pool_get (sm->policy_plugin_functions, plugin);
+ hash_set_mem (sm->policy_plugin_functions_by_key, fn_name,
+ plugin - sm->policy_plugin_functions);
+ }
+
+ 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->prefix_length = prefix_length;
+ plugin->ls_format = ls_format;
+ plugin->ls_unformat = ls_unformat;
+ plugin->creation = creation_fn;
+ plugin->removal = removal_fn;
+ clib_memcpy (&plugin->dpo, dpo, sizeof (dpo_type_t));
+ plugin->function_name = format (0, "%s%c", fn_name, 0);
+ plugin->keyword_str = format (0, "%s%c", keyword_str, 0);
+ plugin->def_str = format (0, "%s%c", def_str, 0);
+ plugin->params_str = format (0, "%s%c", params_str, 0);
+
+ return plugin->sr_policy_function_number;
+}
+
+/**
+ * @brief CLI function to 'show' all available SR LocalSID behaviors
+ */
+static clib_error_t *
+show_sr_policy_behaviors_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ ip6_sr_main_t *sm = &sr_main;
+ sr_policy_fn_registration_t *plugin;
+ sr_policy_fn_registration_t **plugins_vec = 0;
+ int i;
+
+ vlib_cli_output (vm, "SR Policy behaviors:\n-----------------------\n\n");
+
+ /* *INDENT-OFF* */
+ pool_foreach (plugin, sm->policy_plugin_functions,
+ ({ vec_add1 (plugins_vec, plugin); }));
+ /* *INDENT-ON* */
+
+ vlib_cli_output (vm, "Plugin behaviors:\n");
+ for (i = 0; i < vec_len (plugins_vec); i++)
+ {
+ plugin = plugins_vec[i];
+ vlib_cli_output (vm, "\t%s\t-> %s.\n", plugin->keyword_str,
+ plugin->def_str);
+ vlib_cli_output (vm, "\t\tParameters: '%s'\n", plugin->params_str);
+ }
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_sr_policy_behaviors_command, static) = {
+ .path = "show sr policy behaviors",
+ .short_help = "show sr policy behaviors",
+ .function = show_sr_policy_behaviors_command_fn,
+};
+/* *INDENT-ON* */
+