66 memset (segment_list, 0,
sizeof (*segment_list));
80 .frp_sw_if_index = ~0,
82 .frp_weight = segment_list->
weight,
84 .frp_label_stack =
NULL,
85 .frp_local_label = sl[0],
97 .fp_label = sr_policy->
bsid,
135 u8 behavior,
u32 weight)
153 memset (sr_policy, 0,
sizeof (*sr_policy));
154 sr_policy->
bsid = bsid;
155 sr_policy->
type = behavior;
203 .frp_sw_if_index = ~0,
205 .frp_weight = segment_list->
weight,
207 .frp_local_label = segment_list->
segments[0],
223 .fp_label = sr_policy->
bsid,
272 u32 *sl_index_iterate;
287 segment_list =
create_sl (sr_policy, segments, weight);
290 else if (operation == 2)
302 if (*sl_index_iterate == sl_index)
305 if (*sl_index_iterate != sl_index)
314 .frp_sw_if_index = ~0,
316 .frp_weight = segment_list->
weight,
318 .frp_local_label = segment_list->
segments[0],
333 .fp_label = sr_policy->
bsid,
348 else if (operation == 3)
353 if (*sl_index_iterate == sl_index)
356 if (*sl_index_iterate != sl_index)
366 .frp_sw_if_index = ~0,
368 .frp_weight = segment_list->
weight,
370 .frp_local_label = segment_list->
segments[0],
385 .fp_label = sr_policy->
bsid,
394 segment_list->
weight = weight;
408 .fp_label = sr_policy->
bsid,
434 char is_del = 0, is_add = 0, is_mod = 0;
445 if (!is_add && !is_mod && !is_del &&
unformat (input,
"add"))
447 else if (!is_add && !is_mod && !is_del &&
unformat (input,
"del"))
449 else if (!is_add && !is_mod && !is_del &&
unformat (input,
"mod"))
455 else if (
unformat (input,
"weight %d", &weight));
459 vec_add (segments, &next_label, 1);
461 else if (
unformat (input,
"add sl"))
463 else if (
unformat (input,
"del sl index %d", &sl_index))
465 else if (
unformat (input,
"mod sl index %d", &sl_index))
473 if (!is_add && !is_mod && !is_del)
494 if (operation != 1 && sl_index == (
u32) ~ 0)
496 if (operation == 1 &&
vec_len (segments) == 0)
498 if (operation == 3 && weight == (
u32) ~ 0)
510 "There is already a FIB entry for the BindingSID address.\n" 511 "The SR policy could not be created.");
514 "The selected SR policy only contains ONE segment list. " 515 "Please remove the SR policy instead");
518 "Could not delete the segment list. " 519 "It is not associated with that SR policy.");
522 "Could not delete the segment list. " 523 "It is not associated with that SR policy.");
526 "Could not modify the segment list. " 527 "The given SL is not associated with such SR policy.");
537 .path =
"sr mpls policy",
538 .short_help =
"sr mpls policy [add||del||mod] bsid 2999 " 539 "next 10 next 20 next 30 (weight 1) (spray)",
540 .long_help =
"TBD.\n",
565 vec_add1(vec_policies, sr_policy);
571 sr_policy = vec_policies[
i];
598 s =
format (s,
"\t[%u].- ", *sl_index);
604 s =
format (s,
"\b\b > ");
616 .path =
"show sr mpls policies",
617 .short_help =
"show sr mpls policies",
635 ip46_address_t * endpoint,
636 u8 endpoint_type,
u32 color)
640 uword *endpoint_table, *p, *old_value;
643 any.as_u64[0] = any.as_u64[1] = (
u64) ~ 0;
713 sr_policy->
endpoint.as_u64[0] = endpoint->as_u64[0];
714 sr_policy->
endpoint.as_u64[1] = endpoint->as_u64[1];
715 sr_policy->
color = color;
725 "SR-MPLS Traffic Engineering (NextHop,Color)");
737 .frp_sw_if_index = ~0,
800 ip46_address_t endpoint;
803 u8 endpoint_type = 0;
804 char clear = 0, color_set = 0, bsid_set = 0;
806 memset (&endpoint, 0,
sizeof (ip46_address_t));
815 else if (!endpoint_type
819 else if (!color_set &&
unformat (input,
"color %u", &color))
825 else if (!clear &&
unformat (input,
"clear"))
833 if (!endpoint_type && !clear)
835 if (!color_set && !clear)
857 .path =
"sr mpls policy te",
858 .short_help =
"sr mpls policy te bsid xxxxx endpoint x.x.x.x color 12341234",
fib_protocol_t fp_proto
protocol type
static clib_error_t * sr_mpls_policy_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI for 'sr mpls policies' command family.
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define hash_set(h, key, value)
mpls_eos_bit_t frp_eos
EOS bit for the resolving label.
#define hash_unset(h, key)
int sr_mpls_policy_del(mpls_label_t bsid)
Delete a SR policy.
A representation of a path as described by a route producer.
fib_node_index_t fib_table_entry_update(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_route_path_t *paths)
Update an entry to have a new set of paths.
fib_node_index_t fib_table_entry_path_add2(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_route_path_t *rpath)
Add n paths to an entry (aka route) in the FIB.
u32 mpls_label_t
A label value only, i.e.
#define MPLS_IETF_IMPLICIT_NULL_LABEL
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int sr_mpls_policy_assign_endpoint_color(mpls_label_t bsid, ip46_address_t *endpoint, u8 endpoint_type, u32 color)
Update the Endpoint,Color tuple of an SR policy.
dpo_proto_t frp_proto
The protocol of the address below.
SR Segment List (SID list)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
unformat_function_t unformat_mpls_unicast_label
static clib_error_t * cli_sr_mpls_policy_ec_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI to modify the Endpoint,Color of an SR policy.
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
clib_error_t * sr_mpls_policy_rewrite_init(vlib_main_t *vm)
SR MPLS Policy initialization.
void fib_table_flush(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Flush all entries from a table for the source.
Aggregrate type for a prefix.
#define clib_error_return(e, args...)
mpls_sr_main_t sr_mpls_main
u16 fp_len
The mask length.
#define SR_POLICY_TYPE_DEFAULT
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
void fib_table_entry_path_remove2(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_route_path_t *rpath)
Remove n paths to an entry (aka route) in the FIB.
Configuration for each label value in the output-stack.
fib_mpls_label_t * frp_label_stack
The outgoing MPLS label Stack.
#define vec_del1(v, i)
Delete the element at index I.
mpls_label_t bsid
BindingSID (key)
int sr_mpls_policy_add(mpls_label_t bsid, mpls_label_t *segments, u8 behavior, u32 weight)
Create a new SR policy.
static clib_error_t * show_sr_mpls_policies_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI to display onscreen all the SR MPLS policies.
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
int sr_mpls_policy_mod(mpls_label_t bsid, u8 operation, mpls_label_t *segments, u32 sl_index, u32 weight)
Modify an existing SR policy.
static void ip6_address_set_zero(ip6_address_t *a)
#define vec_free(V)
Free vector's memory (no header).
mpls_label_t fml_value
The label value.
mpls_sr_policy_t * sr_policies
static mpls_sr_sl_t * create_sl(mpls_sr_policy_t *sr_policy, mpls_label_t *sl, u32 weight)
Creates a Segment List and adds it to an SR policy.
#define VLIB_CLI_COMMAND(x,...)
#define FOR_EACH_MPLS_EOS_BIT(_eos)
#define hash_create(elts, value_bytes)
Segment Routing main datastructure.
#define pool_put_index(p, i)
Free pool element with given index.
static uword * mhash_get(mhash_t *h, const void *key)
void internal_label_lock(ip46_address_t endpoint, u32 color)
lock the label for (NH, C) endpoint might be NULL or ANY NULL = 0, ANY=~0
#define SR_POLICY_TYPE_SPRAY
ip46_address_t endpoint
Optional NH for SR TE.
uword * sr_policies_index_hash
u32 find_or_create_internal_label(ip46_address_t endpoint, u32 color)
find the corresponding label for (endpoint, color) and lock it endpoint might be NULL or ANY NULL = 0...
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
#define SR_SEGMENT_LIST_WEIGHT_DEFAULT
format_function_t format_mpls_unicast_label
mpls_label_t frp_local_label
The MPLS local Label to reursively resolve through.
mhash_t sr_policies_c2e2eclabel_hash
SR TE.
u32 color
Optional color for SR TE.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 type
Type (default is 0)
Segment Routing MPLS data structures definitions.
u32 * segments_lists
Pool of SID lists indexes.
#define vec_foreach(var, vec)
Vector iterator.
u8 frp_weight
[un]equal cost path weight
void internal_label_unlock(ip46_address_t endpoint, u32 color)
Release lock on label for (endpoint, color) endpoint might be NULL or ANY NULL = 0, ANY=~0.
u32 fib_table_create_and_lock(fib_protocol_t proto, fib_source_t src, const char *const fmt,...)
Create a new table with no table ID.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
enum mpls_eos_bit_t_ mpls_eos_bit_t