FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
load_balance.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * \brief
17  * The load-balance object represents an ECMP choice. The buckets of a load
18  * balance object point to the sub-graph after the choice is made.
19  * THe load-balance object is also object type returned from a FIB table lookup.
20  * As such it needs to represent the case where there is only one coice. It may
21  * seem like overkill to use a load-balance object in this case, but the reason
22  * is for performance. If the load-balance object were not the result of the FIB
23  * lookup, then some other object would be. The case where there was ECMP
24  * this other object would need a load-balance as a parent and hence just add
25  * an unnecessary indirection.
26  *
27  * It is also the object in the DP that represents a via-fib-entry in a recursive
28  * route.
29  *
30  */
31 
32 #ifndef __LOAD_BALANCE_H__
33 #define __LOAD_BALANCE_H__
34 
35 #include <vlib/vlib.h>
36 #include <vnet/ip/lookup.h>
37 #include <vnet/dpo/dpo.h>
38 #include <vnet/fib/fib_types.h>
39 #include <vnet/fib/fib_entry.h>
40 
41 /**
42  * Load-balance main
43  */
44 typedef struct load_balance_main_t_
45 {
49 
51 
52 /**
53  * The number of buckets that a load-balance object can have and still
54  * fit in one cache-line
55  */
56 #define LB_NUM_INLINE_BUCKETS 4
57 
58 /**
59  * @brief One path from an [EU]CMP set that the client wants to add to a
60  * load-balance object
61  */
62 typedef struct load_balance_path_t_ {
63  /**
64  * ID of the Data-path object.
65  */
67 
68  /**
69  * The index of the FIB path
70  */
72 
73  /**
74  * weight for the path.
75  */
78 
79 /**
80  * Flags controlling load-balance creation and modification
81  */
82 typedef enum load_balance_attr_t_ {
86 
87 #define LOAD_BALANCE_ATTR_NAMES { \
88  [LOAD_BALANCE_ATTR_USES_MAP] = "uses-map", \
89  [LOAD_BALANCE_ATTR_STICKY] = "sticky", \
90 }
91 
92 #define FOR_EACH_LOAD_BALANCE_ATTR(_attr) \
93  for (_attr = 0; _attr <= LOAD_BALANCE_ATTR_STICKY; _attr++)
94 
95 typedef enum load_balance_flags_t_ {
99 } __attribute__((packed)) load_balance_flags_t;
100 
101 /**
102  * The FIB DPO provieds;
103  * - load-balancing over the next DPOs in the chain/graph
104  * - per-route counters
105  */
106 typedef struct load_balance_t_ {
107  /**
108  * required for pool_get_aligned.
109  * memebers used in the switch path come first!
110  */
111  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
112 
113  /**
114  * number of buckets in the load-balance. always a power of 2.
115  */
117  /**
118  * number of buckets in the load-balance - 1. used in the switch path
119  * as part of the hash calculation.
120  */
122 
123  /**
124  * The protocol of packets that traverse this LB.
125  * need in combination with the flow hash config to determine how to hash.
126  * u8.
127  */
129 
130  /**
131  * Flags concenring the LB's creation and modification
132  */
134 
135  /**
136  * Flags from the load-balance's associated fib_entry_t
137  */
139 
140  /**
141  * The number of locks, which is approximately the number of users,
142  * of this load-balance.
143  * Load-balance objects of via-entries are heavily shared by recursives,
144  * so the lock count is a u32.
145  */
147 
148  /**
149  * index of the load-balance map, INVALID if this LB does not use one
150  */
152 
153  /**
154  * This is the index of the uRPF list for this LB
155  */
157 
158  /**
159  * the hash config to use when selecting a bucket. this is a u16
160  */
162 
163  /**
164  * Vector of buckets containing the next DPOs, sized as lbo_num
165  */
167 
168  /**
169  * The rest of the cache line is used for buckets. In the common case
170  * where there there are less than 4 buckets, then the buckets are
171  * on the same cachlie and we save ourselves a pointer dereferance in
172  * the data-path.
173  */
176 
178  "A load_balance object size exceeds one cacheline");
179 
180 /**
181  * Flags controlling load-balance formatting/display
182  */
187 
188 extern index_t load_balance_create(u32 num_buckets,
189  dpo_proto_t lb_proto,
190  flow_hash_config_t fhc);
193  const dpo_id_t *dpo,
194  const load_balance_path_t * raw_next_hops,
196 
197 extern void load_balance_set_bucket(index_t lbi,
198  u32 bucket,
199  const dpo_id_t *next);
200 extern void load_balance_set_urpf(index_t lbi,
201  index_t urpf);
205 
206 extern u8* format_load_balance(u8 * s, va_list * args);
207 
208 extern const dpo_id_t *load_balance_get_bucket(index_t lbi,
209  u32 bucket);
210 extern int load_balance_is_drop(const dpo_id_t *dpo);
212 
214 
215 /**
216  * The encapsulation breakages are for fast DP access
217  */
219 static inline load_balance_t*
221 {
222  return (pool_elt_at_index(load_balance_pool, lbi));
223 }
224 
225 #define LB_HAS_INLINE_BUCKETS(_lb) \
226  ((_lb)->lb_n_buckets <= LB_NUM_INLINE_BUCKETS)
227 
228 static inline const dpo_id_t *
230  u32 bucket)
231 {
232  ASSERT(bucket < lb->lb_n_buckets);
233 
235  {
236  return (&lb->lb_buckets_inline[bucket]);
237  }
238  else
239  {
240  return (&lb->lb_buckets[bucket]);
241  }
242 }
243 
244 extern void load_balance_module_init(void);
245 
246 #endif
vlib.h
load_balance_path_t
struct load_balance_path_t_ load_balance_path_t
One path from an [EU]CMP set that the client wants to add to a load-balance object.
load_balance_set_bucket
void load_balance_set_bucket(index_t lbi, u32 bucket, const dpo_id_t *next)
Definition: load_balance.c:283
fib_entry.h
load_balance_t_::lb_n_buckets
u16 lb_n_buckets
number of buckets in the load-balance.
Definition: load_balance.h:116
load_balance_multipath_update
void load_balance_multipath_update(const dpo_id_t *dpo, const load_balance_path_t *raw_next_hops, load_balance_flags_t flags)
Definition: load_balance.c:629
load_balance_set_fib_entry_flags
void load_balance_set_fib_entry_flags(index_t lbi, fib_entry_flag_t flags)
Definition: load_balance.c:326
load_balance_path_t_::path_weight
u32 path_weight
weight for the path.
Definition: load_balance.h:76
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
load_balance_format_flags_t_
load_balance_format_flags_t_
Flags controlling load-balance formatting/display.
Definition: load_balance.h:183
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
load_balance_get_bucket
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
Definition: load_balance.c:366
next
u16 * next
Definition: nat44_ei_out2in.c:718
load_balance_get_urpf
index_t load_balance_get_urpf(index_t lbi)
Definition: load_balance.c:356
load_balance_t_::lb_hash_config
flow_hash_config_t lb_hash_config
the hash config to use when selecting a bucket.
Definition: load_balance.h:161
load_balance_format_flags_t
enum load_balance_format_flags_t_ load_balance_format_flags_t
Flags controlling load-balance formatting/display.
load_balance_flags_t_
load_balance_flags_t_
Definition: load_balance.h:95
u16
unsigned short u16
Definition: types.h:57
load_balance_t_::lb_map
index_t lb_map
index of the load-balance map, INVALID if this LB does not use one
Definition: load_balance.h:151
load_balance_main_t_::lbm_via_counters
vlib_combined_counter_main_t lbm_via_counters
Definition: load_balance.h:47
load_balance_module_init
void load_balance_module_init(void)
Definition: load_balance.c:1001
load_balance_main_t
struct load_balance_main_t_ load_balance_main_t
The load-balance object represents an ECMP choice.
load_balance_get_multipath_tolerance
f64 load_balance_get_multipath_tolerance(void)
Definition: load_balance.c:71
LOAD_BALANCE_FORMAT_DETAIL
@ LOAD_BALANCE_FORMAT_DETAIL
Definition: load_balance.h:185
fib_entry_flag_t
enum fib_entry_flag_t_ fib_entry_flag_t
dpo.h
load_balance_path_t_::path_index
fib_node_index_t path_index
The index of the FIB path.
Definition: load_balance.h:71
load_balance_flags_t
enum load_balance_flags_t_ load_balance_flags_t
load_balance_attr_t_
load_balance_attr_t_
Flags controlling load-balance creation and modification.
Definition: load_balance.h:82
load_balance_set_urpf
void load_balance_set_urpf(index_t lbi, index_t urpf)
Definition: load_balance.c:337
fib_types.h
flow_hash_config_t
enum flow_hash_config_t_ flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
load_balance_t_::lb_fib_entry_flags
fib_entry_flag_t lb_fib_entry_flags
Flags from the load-balance's associated fib_entry_t.
Definition: load_balance.h:138
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
LOAD_BALANCE_FLAG_NONE
@ LOAD_BALANCE_FLAG_NONE
Definition: load_balance.h:96
LOAD_BALANCE_FLAG_USES_MAP
@ LOAD_BALANCE_FLAG_USES_MAP
Definition: load_balance.h:97
LOAD_BALANCE_FORMAT_NONE
@ LOAD_BALANCE_FORMAT_NONE
Definition: load_balance.h:184
format_load_balance
u8 * format_load_balance(u8 *s, va_list *args)
Definition: load_balance.c:202
load_balance_get_bucket_i
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:229
f64
double f64
Definition: types.h:142
LOAD_BALANCE_ATTR_USES_MAP
@ LOAD_BALANCE_ATTR_USES_MAP
Definition: load_balance.h:83
load_balance_pool
load_balance_t * load_balance_pool
The encapsulation breakages are for fast DP access.
Definition: load_balance.c:54
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
LB_HAS_INLINE_BUCKETS
#define LB_HAS_INLINE_BUCKETS(_lb)
Definition: load_balance.h:225
LB_NUM_INLINE_BUCKETS
#define LB_NUM_INLINE_BUCKETS
The number of buckets that a load-balance object can have and still fit in one cache-line.
Definition: load_balance.h:56
LOAD_BALANCE_FLAG_STICKY
@ LOAD_BALANCE_FLAG_STICKY
Definition: load_balance.h:98
load_balance_attr_t
enum load_balance_attr_t_ load_balance_attr_t
Flags controlling load-balance creation and modification.
load_balance_t_::lb_flags
load_balance_flags_t lb_flags
Flags concenring the LB's creation and modification.
Definition: load_balance.h:133
load_balance_main_t_::lbm_to_counters
vlib_combined_counter_main_t lbm_to_counters
Definition: load_balance.h:46
load_balance_create
index_t load_balance_create(u32 num_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
Definition: load_balance.c:266
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
load_balance_t_::CLIB_CACHE_LINE_ALIGN_MARK
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
required for pool_get_aligned.
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
load_balance_get_default_flow_hash
flow_hash_config_t load_balance_get_default_flow_hash(dpo_proto_t lb_proto)
Definition: load_balance.c:220
u32
unsigned int u32
Definition: types.h:88
STATIC_ASSERT
STATIC_ASSERT(sizeof(load_balance_t)<=CLIB_CACHE_LINE_BYTES, "A load_balance object size exceeds one cacheline")
load_balance_t
struct load_balance_t_ load_balance_t
The FIB DPO provieds;.
load_balance_get
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:220
LOAD_BALANCE_ATTR_STICKY
@ LOAD_BALANCE_ATTR_STICKY
Definition: load_balance.h:84
u8
unsigned char u8
Definition: types.h:56
load_balance_t_::lb_buckets
dpo_id_t * lb_buckets
Vector of buckets containing the next DPOs, sized as lbo_num.
Definition: load_balance.h:166
lookup.h
load_balance_t_::lb_proto
dpo_proto_t lb_proto
The protocol of packets that traverse this LB.
Definition: load_balance.h:128
load_balance_t_::lb_buckets_inline
dpo_id_t lb_buckets_inline[LB_NUM_INLINE_BUCKETS]
The rest of the cache line is used for buckets.
Definition: load_balance.h:174
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
load_balance_t_::lb_n_buckets_minus_1
u16 lb_n_buckets_minus_1
number of buckets in the load-balance - 1.
Definition: load_balance.h:121
load_balance_path_t_::path_dpo
dpo_id_t path_dpo
ID of the Data-path object.
Definition: load_balance.h:66
load_balance_t_
The FIB DPO provieds;.
Definition: load_balance.h:106
load_balance_t_::lb_urpf
index_t lb_urpf
This is the index of the uRPF list for this LB.
Definition: load_balance.h:156
load_balance_main_t_
The load-balance object represents an ECMP choice.
Definition: load_balance.h:44
load_balance_is_drop
int load_balance_is_drop(const dpo_id_t *dpo)
Definition: load_balance.c:299
load_balance_t_::lb_locks
u32 lb_locks
The number of locks, which is approximately the number of users, of this load-balance.
Definition: load_balance.h:146
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
load_balance_path_t_
One path from an [EU]CMP set that the client wants to add to a load-balance object.
Definition: load_balance.h:62
load_balance_main
load_balance_main_t load_balance_main
The one instance of load-balance main.
Definition: load_balance.c:59
load_balance_n_buckets
u16 load_balance_n_buckets(index_t lbi)
Definition: load_balance.c:316
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105