34 #define LB_DBG(_lb, _fmt, _args...) \ 37 clib_warning("lb:[%s]:" _fmt, \ 38 load_balance_format(load_balance_get_index((_lb)), \ 44 #define LB_DBG(_p, _fmt, _args...) 67 return (lb - load_balance_pool);
89 memset(lb, 0,
sizeof(*lb));
128 s =
format(s,
" via:[%Ld:%Ld]",
141 s =
format(s,
"\n%U[%d] %U",
145 &buckets[i], indent+6);
162 u32 indent = va_arg(*args,
u32);
231 ASSERT(bucket < lb->lb_n_buckets);
321 uword n_nhs, n_adj, n_adj_left,
i, sum_weight;
324 n_nhs =
vec_len (raw_next_hops);
330 nhs = *normalized_next_hops;
337 nhs[0] = raw_next_hops[0];
349 nhs[0] = raw_next_hops[cmp];
350 nhs[1] = raw_next_hops[cmp ^ 1];
353 if (nhs[0].path_weight == nhs[1].path_weight)
363 clib_memcpy (nhs, raw_next_hops, n_nhs *
sizeof (raw_next_hops[0]));
369 for (i = 0; i < n_nhs; i++)
370 sum_weight += nhs[i].path_weight;
375 for (i = 0; i < n_nhs; i++)
376 nhs[i].path_weight = 1;
381 for (i = 0; i < n_nhs; i++)
382 nhs[n_nhs + i].path_weight = nhs[i].path_weight;
386 for (n_adj =
max_pow2 (n_nhs); ; n_adj *= 2)
390 norm = n_adj / ((
f64) sum_weight);
392 for (i = 0; i < n_nhs; i++)
397 n = n > n_adj_left ? n_adj_left : n;
399 error +=
fabs (nf - n);
402 if (0 == nhs[i].path_weight)
419 if (error <= multipath_next_hop_error_tolerance*n_adj)
429 *normalized_next_hops = nhs;
430 *sum_weight_in = sum_weight;
479 ASSERT(bucket < n_buckets);
499 u32 sum_of_weights, n_buckets, ii;
624 dpo_id_t *new_buckets, *old_buckets, *tmp_dpo;
709 for (ii = n_buckets; ii < old_n_buckets; ii++)
900 .path =
"show load-balance",
901 .short_help =
"show load-balance [<index>]",
920 return (*((
u64 *) m) & 0xffffffffffff);
928 uword is_ip, eh_size;
932 eh_type = clib_net_to_host_u16 (eh->
type);
935 is_ip = (eh_type == ETHERNET_TYPE_IP4 || eh_type == ETHERNET_TYPE_IP6);
961 u32 n_left_from, next_index, *from, *to_next;
968 while (n_left_from > 0)
974 while (n_left_from > 0 && n_left_to_next > 0)
977 u32 bi0, lbi0, next0;
1019 n_left_to_next, bi0, next0);
1052 .name =
"l2-load-balance",
1053 .vector_size =
sizeof (
u32),
1067 u32 n_left_from, next_index, *from, *to_next;
1074 while (n_left_from > 0)
1080 while (n_left_from > 0 && n_left_to_next > 0)
1083 u32 bi0, lbi0, next0, *nsh0;
1092 n_left_to_next -= 1;
1117 n_left_to_next, bi0, next0);
1142 .name =
"nsh-load-balance",
1143 .vector_size =
sizeof (
u32),
1176 .name =
"bier-load-balance",
1177 .vector_size =
sizeof (
u32),
1180 .sibling_of =
"mpls-load-balance",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
u16 lb_n_buckets
number of buckets in the load-balance.
static const char *const load_balance_ip6_nodes[]
dpo_id_t * lb_buckets
Vector of buckets containing the next DPOs, sized as lbo_num.
dpo_lock_fn_t dv_lock
A reference counting lock function.
static u8 * format_l2_load_balance_trace(u8 *s, va_list *args)
void load_balance_map_unlock(index_t lbmi)
vlib_combined_counter_main_t lbm_to_counters
index_t load_balance_map_add_or_lock(u32 n_buckets, u32 sum_of_weights, const load_balance_path_t *paths)
fib_entry_flag_t lb_fib_entry_flags
Flags from the load-balance's associated fib_entry_t.
static index_t load_balance_get_index(const load_balance_t *lb)
sll srl srl sll sra u16x4 i
static const char *const *const load_balance_nodes[DPO_PROTO_NUM]
A virtual function table regisitered for a DPO type.
static const char *const load_balance_mpls_nodes[]
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
u16 load_balance_n_buckets(index_t lbi)
u8 * format_dpo_type(u8 *s, va_list *args)
format a DPO type
dpo_id_t path_dpo
ID of the Data-path object.
static void load_balance_set_n_buckets(load_balance_t *lb, u32 n_buckets)
static u32 ip_flow_hash(void *data)
enum load_balance_format_flags_t_ load_balance_format_flags_t
Flags controlling load-balance formatting/display.
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
void load_balance_set_urpf(index_t lbi, index_t urpf)
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
flow_hash_config_t lb_hash_config
the hash config to use when selecting a bucket.
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Combined counter to hold both packets and byte differences.
static const char *const load_balance_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a load-balance object.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static u8 * format_load_balance_dpo(u8 *s, va_list *args)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
static u8 * load_balance_format(index_t lbi, load_balance_format_flags_t flags, u32 indent, u8 *s)
static load_balance_t * load_balance_alloc_i(void)
index_t load_balance_get_urpf(index_t lbi)
static const char *const load_balance_l2_nodes[]
#define pool_len(p)
Number of elements in pool vector.
index_t load_balance_create(u32 n_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
load_balance_t * load_balance_pool
Pool of all DPOs.
void load_balance_map_module_init(void)
Make/add a new or lock an existing Load-balance map.
static dpo_id_t * load_balance_get_buckets(load_balance_t *lb)
void load_balance_module_init(void)
u16 lb_n_buckets_minus_1
number of buckets in the load-balance - 1.
static int next_hop_sort_by_weight(const load_balance_path_t *n1, const load_balance_path_t *n2)
static void load_balance_mem_show(void)
void fib_urpf_list_lock(index_t ui)
static load_balance_t * load_balance_create_i(u32 num_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
void load_balance_multipath_update(const dpo_id_t *dpo, const load_balance_path_t *raw_nhs, load_balance_flags_t flags)
f64 load_balance_get_multipath_tolerance(void)
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static void load_balance_lock(dpo_id_t *dpo)
int load_balance_is_drop(const dpo_id_t *dpo)
static void load_balance_unlock(dpo_id_t *dpo)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
static load_balance_path_t * load_balance_multipath_next_hop_fixup(const load_balance_path_t *nhs, dpo_proto_t drop_proto)
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
static uword bier_load_balance(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
counter_t packets
packet counter
u8 * format_load_balance(u8 *s, va_list *args)
dpo_type_t dpoi_type
the type
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
dpo_proto_t lb_proto
The protocol of packets that traverse this LB.
void load_balance_set_fib_entry_flags(index_t lbi, fib_entry_flag_t flags)
load-balancing over a choice of [un]equal cost paths
static u8 * format_bier_load_balance_trace(u8 *s, va_list *args)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
#define pool_put(P, E)
Free an object E in pool P.
u8 * format_load_balance_map(u8 *s, va_list *ap)
load_balance_main_t load_balance_main
The one instance of load-balance main.
static const char *const load_balance_bier_nodes[]
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static bier_hdr_entropy_t bier_hdr_get_entropy(const bier_hdr_t *bier_hdr)
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
The load-balance object represents an ECMP choice.
vlib_node_registration_t l2_load_balance_node
(constructor) VLIB_REGISTER_NODE (l2_load_balance_node)
dpo_id_t lb_buckets_inline[LB_NUM_INLINE_BUCKETS]
The rest of the cache line is used for buckets.
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
enum load_balance_flags_t_ load_balance_flags_t
Flags controlling load-balance creation and modification.
#define hash_mix64(a0, b0, c0)
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
#define vec_free(V)
Free vector's memory (no header).
static const char *const load_balance_nsh_nodes[]
void load_balance_map_show_mem(void)
#define VLIB_BUFFER_IS_TRACED
#define clib_memcpy(a, b, c)
static uword max_pow2(uword x)
static u8 * format_nsh_load_balance_trace(u8 *s, va_list *args)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
#define LB_NUM_INLINE_BUCKETS
The number of buckets that a load-balance object can have and still fit in one cache-line.
vlib_combined_counter_main_t lbm_via_counters
static void load_balance_fill_buckets(load_balance_t *lb, load_balance_path_t *nhs, dpo_id_t *buckets, u32 n_buckets)
enum fib_entry_flag_t_ fib_entry_flag_t
static uword nsh_load_balance(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_CLI_COMMAND(x,...)
vlib_node_registration_t bier_load_balance_node
(constructor) VLIB_REGISTER_NODE (bier_load_balance_node)
vlib_node_registration_t nsh_load_balance_node
(constructor) VLIB_REGISTER_NODE (nsh_load_balance_node)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
index_t lb_urpf
This is the index of the uRPF list for this LB.
static load_balance_t * load_balance_get(index_t lbi)
static clib_error_t * load_balance_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 lb_locks
The number of locks, which is approximately the number of users, of this load-balance.
static u64 mac_to_u64(u8 *m)
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
#define LB_HAS_INLINE_BUCKETS(_lb)
void load_balance_set_bucket(index_t lbi, u32 bucket, const dpo_id_t *next)
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
counter_t bytes
byte counter
static uword l2_load_balance(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
static word flt_round_nearest(f64 x)
void qsort(void *base, uword n, uword size, int(*compar)(const void *, const void *))
index_t dpoi_index
the index of objects of that type
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 path_weight
weight for the path.
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
static void load_balance_destroy(load_balance_t *lb)
static uword load_balance_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_l2)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
void fib_urpf_list_unlock(index_t ui)
One path from an [EU]CMP set that the client wants to add to a load-balance object.
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
static u32 l2_flow_hash(vlib_buffer_t *b0)
index_t lb_map
index of the load-balance map, INVALID if this LB does not use one
const f64 multipath_next_hop_error_tolerance
#define VLIB_REGISTER_NODE(x,...)
int dpo_is_drop(const dpo_id_t *dpo)
The Drop DPO will drop all packets, no questions asked.
u32 ip_multipath_normalize_next_hops(const load_balance_path_t *raw_next_hops, load_balance_path_t **normalized_next_hops, u32 *sum_weight_in, f64 multipath_next_hop_error_tolerance)
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
#define vec_foreach(var, vec)
Vector iterator.
#define CLIB_MEMORY_BARRIER()
u16 dpoi_next_node
The next VLIB node to follow.
#define LB_DBG(_p, _fmt, _args...)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
struct load_balance_trace_t_ load_balance_trace_t
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child-parent relationship.
static void load_balance_set_bucket_i(load_balance_t *lb, u32 bucket, dpo_id_t *buckets, const dpo_id_t *next)
static uword pool_elts(void *v)
Number of active elements in a pool.