33 #define LB_DBG(_lb, _fmt, _args...) \ 36 clib_warning("lb:[%s]:" _fmt, \ 37 load_balance_format(load_balance_get_index((_lb)), \ 43 #define LB_DBG(_p, _fmt, _args...) 66 return (lb - load_balance_pool);
88 memset(lb, 0,
sizeof(*lb));
127 s =
format(s,
" via:[%Ld:%Ld]",
140 s =
format(s,
"\n%U[%d] %U",
144 &buckets[i], indent+6);
161 u32 indent = va_arg(*args,
u32);
220 ASSERT(bucket < lb->lb_n_buckets);
310 uword n_nhs, n_adj, n_adj_left,
i, sum_weight;
313 n_nhs =
vec_len (raw_next_hops);
319 nhs = *normalized_next_hops;
326 nhs[0] = raw_next_hops[0];
338 nhs[0] = raw_next_hops[cmp];
339 nhs[1] = raw_next_hops[cmp ^ 1];
342 if (nhs[0].path_weight == nhs[1].path_weight)
352 clib_memcpy (nhs, raw_next_hops, n_nhs *
sizeof (raw_next_hops[0]));
358 for (i = 0; i < n_nhs; i++)
359 sum_weight += nhs[i].path_weight;
364 for (i = 0; i < n_nhs; i++)
365 nhs[i].path_weight = 1;
370 for (i = 0; i < n_nhs; i++)
371 nhs[n_nhs + i].path_weight = nhs[i].path_weight;
375 for (n_adj =
max_pow2 (n_nhs); ; n_adj *= 2)
379 norm = n_adj / ((
f64) sum_weight);
381 for (i = 0; i < n_nhs; i++)
386 n = n > n_adj_left ? n_adj_left : n;
388 error +=
fabs (nf - n);
391 if (0 == nhs[i].path_weight)
408 if (error <= multipath_next_hop_error_tolerance*n_adj)
418 *normalized_next_hops = nhs;
419 *sum_weight_in = sum_weight;
468 ASSERT(bucket < n_buckets);
488 u32 sum_of_weights, n_buckets, ii;
613 dpo_id_t *new_buckets, *old_buckets, *tmp_dpo;
698 for (ii = n_buckets; ii < old_n_buckets; ii++)
883 .path =
"show load-balance",
884 .short_help =
"show load-balance [<index>]",
903 return (*((
u64 *) m) & 0xffffffffffff);
911 uword is_ip, eh_size;
915 eh_type = clib_net_to_host_u16 (eh->
type);
918 is_ip = (eh_type == ETHERNET_TYPE_IP4 || eh_type == ETHERNET_TYPE_IP6);
943 u32 n_left_from, next_index, *from, *to_next;
950 while (n_left_from > 0)
956 while (n_left_from > 0 && n_left_to_next > 0)
959 u32 bi0, lbi0, next0;
992 n_left_to_next, bi0, next0);
1017 .name =
"l2-load-balance",
1018 .vector_size =
sizeof (
u32),
1032 u32 n_left_from, next_index, *from, *to_next;
1039 while (n_left_from > 0)
1045 while (n_left_from > 0 && n_left_to_next > 0)
1048 u32 bi0, lbi0, next0, *nsh0;
1057 n_left_to_next -= 1;
1082 n_left_to_next, bi0, next0);
1107 .name =
"nsh-load-balance",
1108 .vector_size =
sizeof (
u32),
#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
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.
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.
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.
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 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.
load_balance_main_t load_balance_main
The one instance of load-balance main.
#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).
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)
#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 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)
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 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
u8 * format_load_balance_map(u8 *s, va_list ap)
u32 flags
buffer flags: 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.