38 #define LB_DBG(_lb, _fmt, _args...) \ 40 vlib_log_debug(load_balance_logger, \ 42 format_load_balance, load_balance_get_index(_lb), \ 43 LOAD_BALANCE_FORMAT_NONE, \ 58 .stat_segment_name =
"/net/route/to",
62 .stat_segment_name =
"/net/route/via",
75 return (lb - load_balance_pool);
151 s =
format(s,
" via:[%Ld:%Ld]",
164 s =
format(s,
"\n%U[%d] %U",
168 &buckets[i], indent+6);
186 u32 indent = va_arg(*args,
u32);
244 ASSERT(bucket < lb->lb_n_buckets);
347 n_nhs =
vec_len (raw_next_hops);
353 nhs = *normalized_next_hops;
360 nhs[0] = raw_next_hops[0];
372 nhs[0] = raw_next_hops[cmp];
373 nhs[1] = raw_next_hops[cmp ^ 1];
376 if (nhs[0].path_weight == nhs[1].path_weight)
392 for (i = 0; i <
n_nhs; i++)
393 sum_weight += nhs[i].path_weight;
398 for (i = 0; i <
n_nhs; i++)
399 nhs[i].path_weight = 1;
404 for (i = 0; i <
n_nhs; i++)
405 nhs[n_nhs + i].path_weight = nhs[i].path_weight;
409 for (n_adj =
max_pow2 (n_nhs); ; n_adj *= 2)
413 norm = n_adj / ((
f64) sum_weight);
415 for (i = 0; i <
n_nhs; i++)
420 n = n > n_adj_left ? n_adj_left : n;
422 error +=
fabs (nf - n);
425 if (0 == nhs[i].path_weight)
442 if (error <= multipath_next_hop_error_tolerance*n_adj)
452 *normalized_next_hops =
nhs;
453 *sum_weight_in = sum_weight;
502 ASSERT(bucket < n_buckets);
514 u16 ii, bucket, fpath;
526 if (
vec_len(fwding_paths) == 0)
537 ASSERT(bucket < n_buckets);
546 fpath = (fpath + 1) %
vec_len(fwding_paths);
585 u32 sum_of_weights, n_buckets, ii;
711 dpo_id_t *new_buckets, *old_buckets, *tmp_dpo;
796 for (ii = n_buckets; ii < old_n_buckets; ii++)
997 .path =
"show load-balance",
998 .short_help =
"show load-balance [<index>]",
1017 return (*((
u64 *) m) & 0xffffffffffff);
1025 uword is_ip, eh_size;
1029 eh_type = clib_net_to_host_u16 (eh->
type);
1032 is_ip = (eh_type == ETHERNET_TYPE_IP4 || eh_type == ETHERNET_TYPE_IP6);
1058 u32 n_left_from, next_index, *from, *to_next;
1065 while (n_left_from > 0)
1071 while (n_left_from > 0 && n_left_to_next > 0)
1074 u32 bi0, lbi0, next0;
1083 n_left_to_next -= 1;
1116 n_left_to_next, bi0, next0);
1149 .name =
"l2-load-balance",
1150 .vector_size =
sizeof (
u32),
1164 u32 n_left_from, next_index, *from, *to_next;
1171 while (n_left_from > 0)
1177 while (n_left_from > 0 && n_left_to_next > 0)
1180 u32 bi0, lbi0, next0, *nsh0;
1189 n_left_to_next -= 1;
1214 n_left_to_next, bi0, next0);
1239 .name =
"nsh-load-balance",
1240 .vector_size =
sizeof (
u32),
1273 .name =
"bier-load-balance",
1274 .vector_size =
sizeof (
u32),
1277 .sibling_of =
"mpls-load-balance",
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
#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.
vlib_log_class_t load_balance_logger
the logger
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)
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)
#define LOAD_BALANCE_ATTR_NAMES
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.
#define clib_memcpy_fast(a, b, c)
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
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...
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static const char * load_balance_attr_names[]
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)
load_balance_flags_t lb_flags
Flags concenring the LB's creation and modification.
#define FOR_EACH_LOAD_BALANCE_ATTR(_attr)
#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)
static void load_balance_fill_buckets(load_balance_t *lb, load_balance_path_t *nhs, dpo_id_t *buckets, u32 n_buckets, load_balance_flags_t flags)
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.
static_always_inline u32 bier_compute_flow_hash(const bier_hdr_t *hdr)
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.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
u8 * format_load_balance_map(u8 *s, va_list *ap)
#define LB_DBG(_lb, _fmt, _args...)
vl_api_gbp_next_hop_t nhs[8]
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).
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 with alignment A.
static void load_balance_fill_buckets_norm(load_balance_t *lb, load_balance_path_t *nhs, dpo_id_t *buckets, u32 n_buckets)
#define VLIB_REGISTER_NODE(x,...)
#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)
enum load_balance_attr_t_ load_balance_attr_t
Flags controlling load-balance creation and modification.
static uword max_pow2(uword x)
static u8 * format_nsh_load_balance_trace(u8 *s, va_list *args)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
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
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)
enum load_balance_flags_t_ load_balance_flags_t
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.
char * name
The counter collection's name.
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 void load_balance_fill_buckets_sticky(load_balance_t *lb, load_balance_path_t *nhs, dpo_id_t *buckets, u32 n_buckets)
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
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 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.