|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
18 #include <vpp/app/version.h>
24 #define LB_GARBAGE_RUN 60
27 #define LB_CONCURRENCY_TIMEOUT 10
34 #define lb_get_writer_lock() clib_spinlock_lock (&lb_main.writer_lock)
35 #define lb_put_writer_lock() clib_spinlock_unlock (&lb_main.writer_lock)
116 s =
format(s,
" timeout: %ds\n",
h->timeout);
141 return format(s,
"_WRONG_TYPE_");
159 s =
format(s,
"%U %U new_size:%u #as:%u%s",
178 s =
format (s,
" type:%s port:%u target_port:%u",
201 s =
format(s,
"%U %U [%lu] %U%s\n"
213 s =
format(s,
"%U protocol:%u port:%u\n",
220 s =
format(s,
"%U dscp:%u\n",
227 s =
format (s,
"%U type:%s port:%u target_port:%u",
235 s =
format(s,
"%U counters:\n",
239 s =
format(s,
"%U %s: %Lu\n",
245 s =
format(s,
"%U #as:%u\n",
259 as = &lbm->
ass[*as_index];
260 s =
format(s,
"%U %U %u buckets %Lu flows dpo:%u %s\n",
306 as = &lbm->
ass[*as_index];
337 if (!clib_bihash_search_24_8 (&lbm->
mapping_by_as6, &kv6, &value6))
362 u32 *to_be_removed_vips = 0, *
i;
373 vip = &lbm->
vips[*
i];
396 as = &lbm->
ass[*as_index];
408 new_flow_table[
i].as_index = 0;
418 as = &lbm->
ass[*as_index];
425 _vec_len(sort_arr) =
i;
449 new_flow_table[
i].as_index = 0;
457 if (new_flow_table[
last].as_index == 0) {
463 if (done ==
vec_len(new_flow_table))
477 u32 per_cpu_sticky_buckets,
u32 flow_timeout)
481 if (!
is_pow2(per_cpu_sticky_buckets))
482 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
521 *vip_index = vip - lbm->
vips;
526 return VNET_API_ERROR_NO_SUCH_ENTRY;
573 as = &lbm->
ass[*asi];
578 *as_index = as - lbm->
ass;
592 return VNET_API_ERROR_NO_SUCH_ENTRY;
596 u32 *to_be_added = 0;
597 u32 *to_be_updated = 0;
610 return VNET_API_ERROR_VALUE_EXIST;
620 return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
626 if (addresses[n2].
as_u64[0] == addresses[n].
as_u64[0] &&
652 *as_index = as - lbm->
ass;
775 if ((vip_index == ~0)
776 || ((
b->vip[
i] == vip_index) && (as_index == ~0))
777 || ((
b->vip[
i] == vip_index) && (
b->value[
i] == as_index)))
806 return VNET_API_ERROR_NO_SUCH_ENTRY;
813 return VNET_API_ERROR_NO_SUCH_ENTRY;
819 if (addresses[n2].
as_u64[0] == addresses[n].
as_u64[0] &&
833 if (indexes != NULL) {
896 u32 *vip_prefix_index)
919 *vip_prefix_index = vip - lbm->
vips;
966 u32 vip_prefix_index,
u32 vip_idx)
971 key.vip_prefix_index = vip_prefix_index;
973 key.port = clib_host_to_net_u16(vip->
port);
994 key.port = clib_host_to_net_u16(vip->
port);
1001 return VNET_API_ERROR_NO_SUCH_ENTRY;
1054 u32 vip_prefix_index = 0;
1064 return VNET_API_ERROR_VALUE_EXIST;
1069 if ((args.
port != 0) &&
1073 return VNET_API_ERROR_VALUE_EXIST;
1078 if ((args.
port == 0) &&
1083 return VNET_API_ERROR_VALUE_EXIST;
1087 if ((args.
port != 0) &&
1093 return VNET_API_ERROR_INVALID_ARGUMENT;
1098 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
1104 return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
1110 return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
1117 return VNET_API_ERROR_VALUE_EXIST;
1176 key = clib_host_to_net_u16(args.
port);
1180 return VNET_API_ERROR_VALUE_EXIST;
1190 *vip_index = vip - lbm->
vips;
1210 return VNET_API_ERROR_INVALID_VALUE;
1215 return VNET_API_ERROR_NO_SUCH_ENTRY;
1223 ip46_address_t *ass = 0;
1228 as = &lbm->
ass[*as_index];
1254 .version = VPP_BUILD_VER,
1255 .description =
"Load Balancer (LB)",
1387 default_vip->
prefix.ip6.as_u64[0] = 0xffffffffffffffffL;
1388 default_vip->
prefix.ip6.as_u64[1] = 0xffffffffffffffffL;
1390 default_vip->
port = 0;
1423 default_as->
flags = 0;
1426 default_as->
address.ip6.as_u64[0] = 0xffffffffffffffffL;
1427 default_as->
address.ip6.as_u64[1] = 0xffffffffffffffffL;
1450 #define _(a,b,c) lbm->vip_counters[c].name = b;
static void lb_as_stack(lb_as_t *as)
static void clib_spinlock_init(clib_spinlock_t *p)
const static char *const *const lb_dpo_l3dsr_nodes[DPO_PROTO_NUM]
clib_bihash_8_8_t vip_index_per_port
#define LB_DEFAULT_PER_CPU_STICKY_BUCKETS
lb-plugin implements a MagLev-like load balancer.
u16 dpoi_next_node
The next VLIB node to follow.
ip46_address_t prefix
A Virtual IP represents a given service delivered by a set of application servers.
const static char *const lb_dpo_gre4_ip4[]
const static char *const lb_dpo_gre6_ip4[]
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
static int lb_vip_add_port_filter(lb_main_t *lbm, lb_vip_t *vip, u32 vip_prefix_index, u32 vip_idx)
Add the VIP filter entry.
#define lb_vip_is_ip4(type)
index_t dpoi_index
the index of objects of that type
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Each VIP is configured with a set of application server.
u32 per_cpu_sticky_buckets
Number of buckets in the per-cpu sticky hash table.
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a 'special' entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
fib_node_index_t next_hop_fib_entry_index
The FIB entry index for the next-hop.
u16 src_port
Network byte order for vip + port case, src_port = port; for node ip + node_port, src_port = node_por...
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
static lb_as_t * lb_as_from_fib_node(fib_node_t *node)
u8 * format_lb_main(u8 *s, va_list *args)
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip, u32 *vip_prefix_index)
Add the VIP adjacency to the ip4 or ip6 fib.
uword * vip_index_by_nodeport
const static char *const *const lb_dpo_gre6_port_nodes[DPO_PROTO_NUM]
lb_vip_t * vips
Pool of all Virtual IPs.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
const static char *const lb_dpo_gre6_ip6[]
static counter_t vlib_get_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Get the value of a simple counter Scrapes the entire set of per-thread counters.
#define LB_MAPPING_BUCKETS
static_always_inline u32 lb_hash_elts(lb_hash_t *h, u32 time_now)
vlib_main_t vlib_node_runtime_t * node
A FIB graph nodes virtual function table.
const static char *const lb_dpo_l3dsr_ip4[]
#define lb_hash_foreach_entry(h, bucket, i)
#define CLIB_SPINLOCK_ASSERT_LOCKED(_p)
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
#define FIB_NODE_INDEX_INVALID
int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
#define LB_CONCURRENCY_TIMEOUT
ip46_address_t address
Destination address used to tunnel traffic towards that application server.
int lb_nat6_interface_add_del(u32 sw_if_index, int is_del)
int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
static int lb_vip_del_port_filter(lb_main_t *lbm, lb_vip_t *vip)
Del the VIP filter entry.
#define lb_get_writer_lock()
u16 fp_len
The mask length.
ip4_address_t ip4_src_address
Source address used for IPv4 encapsulated traffic.
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
#define LB_MAPPING_MEMORY_SIZE
static_always_inline void vlib_refcount_init(vlib_refcount_t *r)
u32 last_used
Rotating timestamp of when LB_AS_FLAGS_USED flag was last set.
u8 plen
The VIP prefix length.
lb_per_cpu_t * per_cpu
Some global data is per-cpu.
uword * vip_prefix_indexes
bitmap for vip prefix to support per-port vip
vlib_refcount_t as_refcount
Each AS has an associated reference counter.
const static char *const lb_dpo_nat6_ip6_port[]
int lb_nat4_interface_add_del(u32 sw_if_index, int is_del)
@ FIB_ENTRY_FLAG_EXCLUSIVE
const static char *const *const lb_dpo_nat4_port_nodes[DPO_PROTO_NUM]
#define lb_vip_is_ip6(type)
vlib_simple_counter_main_t vip_counters[LB_N_VIP_COUNTERS]
Per VIP counter.
void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen)
static void lb_fib_node_last_lock_gone(fib_node_t *node)
int lb_vip_del(u32 vip_index)
static uword clib_bitmap_first_clear(uword *ai)
Return the lowest numbered clear bit in a bitmap.
u8 * format_lb_as(u8 *s, va_list *args)
dpo_type_t dpo_nat4_port_type
u32 vip_index
ASs are indexed by address and VIP Index.
#define LB_VIP_FLAGS_USED
static fib_source_t lb_fib_src
#define LB_DEFAULT_FLOW_TIMEOUT
int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
static int lb_vip_port_find_all_port_vip(ip46_address_t *prefix, u8 plen, u32 *vip_index)
dpo_type_t dpo_l3dsr_port_type
#define STRUCT_OFFSET_OF(t, f)
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a 'special' entry from the FIB.
#define pool_foreach(VAR, POOL)
Iterate through pool.
#define lb_vip_is_gre4(vip)
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
dpo_type_t dpo_gre4_port_type
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define LB_VIP_PER_PORT_BUCKETS
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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.
dpo_type_t dpo_l3dsr_type
dpo_type_t dpo_gre6_port_type
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
vnet_main_t * vnet_get_main(void)
static int lb_vip_port_find_diff_port(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
uword unformat_lb_vip_type(unformat_input_t *input, va_list *args)
lb_lkp_type_t
Lookup type.
#define lb_vip_get_by_index(index)
#define lb_encap_is_ip4(vip)
dpo_type_t dpo_nat6_port_type
dpo_type_t dpo_gre4_type
DPO used to send packet from IP4/6 lookup to LB node.
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
static void lb_vip_garbage_collection(lb_vip_t *vip)
u32 fib_node_index_t
A typedef of a node index.
u32 last_garbage_collection
Last time garbage collection was run to free the ASs.
static heap_elt_t * last(heap_header_t *h)
const static char *const *const lb_dpo_gre4_nodes[DPO_PROTO_NUM]
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
#define hash_create_mem(elts, key_bytes, value_bytes)
#define lb_vip_is_gre6(vip)
#define hash_set_mem(h, key, value)
static bool lb_vip_is_nat6_port(const lb_vip_t *vip)
char * name
The counter collection's name.
static_always_inline void lb_hash_free(lb_hash_t *h)
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type()
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
static void lb_vip_update_new_flow_table(lb_vip_t *vip)
sll srl srl sll sra u16x4 i
const static char *const lb_dpo_nat4_ip4_port[]
lb_vip_type_t type
The type of traffic for this.
static int lb_vip_port_find_index_with_lock(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
lb_vip_encap_args_t encap_args
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static int lb_vip_prefix_index_free(lb_main_t *lbm, u32 instance)
u8 * format_ip46_prefix(u8 *s, va_list *args)
const static char *const *const lb_dpo_l3dsr_port_nodes[DPO_PROTO_NUM]
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
manual_print typedef address
ip6_address_t ip6_src_address
Source address used in IPv6 encapsulated traffic.
static u64 clib_xxhash(u64 key)
dpo_lock_fn_t dv_lock
A reference counting lock function.
static void lb_dpo_unlock(dpo_id_t *dpo)
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap.
Load balancing service is provided per VIP+protocol+port.
u8 * format_lb_vip(u8 *s, va_list *args)
#define lb_vip_is_gre6_port(vip)
#define lb_vip_is_gre4_port(vip)
@ FIB_NODE_BACK_WALK_CONTINUE
static fib_node_back_walk_rc_t lb_fib_node_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
fib_source_t fib_source_allocate(const char *name, fib_source_priority_t prio, fib_source_behaviour_t bh)
lb_vip_encap_args_t encap_args
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
fib_node_t fib_node
Registration to FIB event.
int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
#define FIB_SOURCE_PRIORITY_HI
Some priority values that plugins might use when they are not to concerned where in the list they'll ...
clib_spinlock_t writer_lock
const static char *const *const lb_dpo_nat6_port_nodes[DPO_PROTO_NUM]
#define vec_free(V)
Free vector's memory (no header).
#define lb_put_writer_lock()
#define pool_len(p)
Number of elements in pool vector.
clib_error_t * lb_init(vlib_main_t *vm)
#define ip46_address_type(ip46)
static fib_node_t * lb_fib_node_get_node(fib_node_index_t index)
const static char *const lb_dpo_gre6_ip6_port[]
#define hash_get_mem(h, key)
const static char *const lb_dpo_gre4_ip6[]
description fragment has unexpected format
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
const static char *const lb_dpo_gre4_ip6_port[]
format_function_t format_ip46_address
lb_hash_t * sticky_ht
Each CPU has its own sticky flow hash table.
vlib_node_registration_t lb4_nodeport_node
(constructor) VLIB_REGISTER_NODE (lb4_nodeport_node)
#define VLIB_INIT_FUNCTION(x)
const static char *const *const lb_dpo_gre6_nodes[DPO_PROTO_NUM]
vl_api_ip_proto_t protocol
void vlib_validate_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
validate a simple counter
manual_print typedef u8 ip4_address[4]
dpo_id_t dpo
The next DPO in the graph to follow.
manual_print typedef u8 ip6_address[16]
#define vec_foreach(var, vec)
Vector iterator.
8 octet key, 8 octet key value pair
static uword pool_elts(void *v)
Number of active elements in a pool.
int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
static void lb_dpo_lock(dpo_id_t *dpo)
clib_bihash_8_8_t mapping_by_as4
fib_protocol_t fp_proto
protocol type
static int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, lb_lkp_type_t lkp_type, u32 *vip_index)
clib_bihash_24_8_t mapping_by_as6
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
An node in the FIB graph.
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
const static char *const *const lb_dpo_gre4_port_nodes[DPO_PROTO_NUM]
lb_vip_type_t
The load balancer supports IPv4 and IPv6 traffic and GRE4, GRE6, L3DSR and NAT4, NAT6 encap.
u8 flags
Flags related to this VIP.
lb_new_flow_entry_t * new_flow_table
Vector mapping (flow-hash & new_connect_table_mask) to AS index.
vlib_node_registration_t lb6_nodeport_node
(constructor) VLIB_REGISTER_NODE (lb6_nodeport_node)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static bool lb_vip_is_l3dsr_port(const lb_vip_t *vip)
A virtual function table regisitered for a DPO type.
static vlib_main_t * vlib_get_main(void)
u32 lb_hash_time_now(vlib_main_t *vm)
int lb_flush_vip_as(u32 vip_index, u32 as_index)
#define LB_VIP_PER_PORT_MEMORY_SIZE
static bool lb_vip_is_l3dsr(const lb_vip_t *vip)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
lb_as_t * ass
Pool of ASs.
const static char *const lb_dpo_gre4_ip4_port[]
@ FIB_SOURCE_BH_SIMPLE
add paths without path extensions
#define pool_free(p)
Free a pool.
Context passed between object during a back walk.
static int lb_vip_prefix_index_alloc(lb_main_t *lbm)
@ FIB_SOURCE_RR
Recursive resolution source.
u8 flags
Some per-AS flags.
#define clib_warning(format, args...)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
enum fib_source_t_ fib_source_t
The different sources that can create a route.
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
u32 flow_timeout
Flow timeout in seconds.
ip46_address_t src_ip
for vip + port case, src_ip = vip; for node ip + node_port, src_ip = node_ip
static int lb_pseudorand_compare(void *a, void *b)
fib_node_type_t fib_node_type
Node type for registering to fib changes.
static f64 vlib_time_now(vlib_main_t *vm)
u32 new_flow_table_mask
New flows table length - 1 (length MUST be a power of 2)
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
u32 * as_indexes
Pool of AS indexes used for this VIP.
u64 vlib_refcount_get(vlib_refcount_t *r, u32 index)
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a 'special' entry to the FIB.
static bool lb_vip_is_nat4_port(const lb_vip_t *vip)
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
#define lb_foreach_vip_counter
const static char *const lb_dpo_l3dsr_ip4_port[]
const static dpo_vft_t lb_vft
#define clib_u32_loop_gt(a, b)
32 bits integer comparison for running values.
static vlib_thread_main_t * vlib_get_thread_main()
static uword is_pow2(uword x)
u32 next_hop_child_index
The child index on the FIB entry.
vl_api_interface_index_t sw_if_index
lb_snat_mapping_t * snat_mappings
#define ip46_prefix_is_ip4(ip46, len)
static_always_inline void vlib_refcount_add(vlib_refcount_t *r, u32 thread_index, u32 counter_index, i32 v)
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
Deletes the adjacency associated with the VIP.
u8 * format_lb_dpo(u8 *s, va_list *va)
fib_node_type_t fib_node_register_new_type(const fib_node_vft_t *vft)
Create a new FIB node type and Register the function table for it.
int lb_conf(ip4_address_t *ip4_address, ip6_address_t *ip6_address, u32 per_cpu_sticky_buckets, u32 flow_timeout)
Fix global load-balancer parameters.
Aggregate type for a prefix.
void lb_garbage_collection()
vl_api_fib_path_type_t type
u8 * format_lb_vip_detailed(u8 *s, va_list *args)
u8 * format_lb_vip_type(u8 *s, va_list *args)
const static char *const lb_dpo_gre6_ip4_port[]
static char * lb_vip_type_strings[]