68 memset (segment_list, 0,
sizeof (*segment_list));
79 .frp_sw_if_index = ~0,
81 .frp_weight = segment_list->
weight,
83 .frp_label_stack =
NULL,
84 .frp_local_label = sl[0],
99 .fp_label = sr_policy->
bsid,
138 u8 behavior,
u32 weight)
154 memset (sr_policy, 0,
sizeof (*sr_policy));
155 sr_policy->
bsid = bsid;
156 sr_policy->
type = behavior;
207 .frp_sw_if_index = ~0,
209 .frp_weight = segment_list->
weight,
211 .frp_local_label = segment_list->
segments[0],
224 .fp_label = sr_policy->
bsid,
268 u32 *sl_index_iterate;
289 segment_list =
create_sl (sr_policy, segments, weight);
292 else if (operation == 2)
300 if (*sl_index_iterate == sl_index)
303 if (*sl_index_iterate != sl_index)
312 .frp_sw_if_index = ~0,
314 .frp_weight = segment_list->
weight,
316 .frp_local_label = segment_list->
segments[0],
328 .fp_label = sr_policy->
bsid,
343 else if (operation == 3)
347 if (*sl_index_iterate == sl_index)
350 if (*sl_index_iterate != sl_index)
355 segment_list->
weight = weight;
371 char is_del = 0, is_add = 0, is_mod = 0;
374 u32 sr_policy_index = (
u32) ~ 0, sl_index = (
u32) ~ 0;
382 if (!is_add && !is_mod && !is_del &&
unformat (input,
"add"))
384 else if (!is_add && !is_mod && !is_del &&
unformat (input,
"del"))
386 else if (!is_add && !is_mod && !is_del &&
unformat (input,
"mod"))
392 else if (!is_add && !policy_set
393 &&
unformat (input,
"index %d", &sr_policy_index))
395 else if (
unformat (input,
"weight %d", &weight));
400 vec_add (segments, &next_label, 1);
402 else if (
unformat (input,
"add sl"))
404 else if (
unformat (input,
"del sl index %d", &sl_index))
406 else if (
unformat (input,
"mod sl index %d", &sl_index))
414 if (!is_add && !is_mod && !is_del)
437 if (operation != 1 && sl_index == (
u32) ~ 0)
439 if (operation == 1 &&
vec_len (segments) == 0)
441 if (operation == 3 && weight == (
u32) ~ 0)
445 sr_policy_index, operation, segments,
457 "There is already a FIB entry for the BindingSID address.\n" 458 "The SR policy could not be created.");
461 "The selected SR policy only contains ONE segment list. " 462 "Please remove the SR policy instead");
465 "Could not delete the segment list. " 466 "It is not associated with that SR policy.");
469 "Could not modify the segment list. " 470 "The given SL is not associated with such SR policy.");
479 .path =
"sr mpls policy",
480 .short_help =
"sr mpls policy [add||del||mod] bsid 2999 " 481 "next 10 next 20 next 30 (weight 1) (spray)",
482 .long_help =
"TBD.\n",
511 sr_policy = vec_policies[
i];
523 s =
format (s,
"\t[%u].- ", *sl_index);
529 s =
format (s,
"\b\b > ");
540 .path =
"show sr mpls policies",
541 .short_help =
"show sr mpls policies",
#define SR_POLICY_TYPE_DEFAULT
fib_protocol_t frp_proto
The protocol of the address below.
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)
sll srl srl sll sra u16x4 i
#define hash_unset(h, key)
A representation of a path as described by a route producer.
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 vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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
#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.
mpls_label_t * frp_label_stack
The outgoing MPLS label Stack.
#define VLIB_INIT_FUNCTION(x)
clib_error_t * sr_mpls_policy_rewrite_init(vlib_main_t *vm)
SR MPLS Policy initialization.
Aggregrate type for a prefix.
#define clib_error_return(e, args...)
mpls_sr_sl_t * sid_lists
SR SID lists.
#define SR_POLICY_TYPE_SPRAY
mpls_sr_main_t sr_mpls_main
u16 fp_len
The mask length.
#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.
#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...
#define vec_free(V)
Free vector's memory (no header).
mpls_sr_policy_t * sr_policies
SR MPLS 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.
uword * sr_policies_index_hash
Hash table mapping BindingSID to SR MPLS policy.
format_function_t format_mpls_unicast_label
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define SR_SEGMENT_LIST_WEIGHT_DEFAULT
u8 type
Type (default is 0)
Segment Routing MPLS data structures definitions.
mpls_label_t * segments
SIDs (key)
u32 * segments_lists
Pool of SID lists indexes.
#define vec_foreach(var, vec)
Vector iterator.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
int sr_mpls_policy_mod(mpls_label_t bsid, u32 index, u8 operation, mpls_label_t *segments, u32 sl_index, u32 weight)
Modify an existing SR policy.
int sr_mpls_policy_del(mpls_label_t bsid, u32 index)
Delete a SR policy.
u32 weight
SID list weight (wECMP / UCMP)
enum mpls_eos_bit_t_ mpls_eos_bit_t