FD.io VPP  v17.01-9-ge7dcee4
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 
40 /**
41  * Load-balance main
42  */
43 typedef struct load_balance_main_t_
44 {
48 
50 
51 /**
52  * The number of buckets that a load-balance object can have and still
53  * fit in one cache-line
54  */
55 #define LB_NUM_INLINE_BUCKETS 4
56 
57 /**
58  * @brief One path from an [EU]CMP set that the client wants to add to a
59  * load-balance object
60  */
61 typedef struct load_balance_path_t_ {
62  /**
63  * ID of the Data-path object.
64  */
66 
67  /**
68  * The index of the FIB path
69  */
71 
72  /**
73  * weight for the path.
74  */
77 
78 /**
79  * The FIB DPO provieds;
80  * - load-balancing over the next DPOs in the chain/graph
81  * - per-route counters
82  */
83 typedef struct load_balance_t_ {
84  /**
85  * number of buckets in the load-balance. always a power of 2.
86  */
88  /**
89  * number of buckets in the load-balance - 1. used in the switch path
90  * as part of the hash calculation.
91  */
93 
94  /**
95  * The protocol of packets that traverse this LB.
96  * need in combination with the flow hash config to determine how to hash.
97  * u8.
98  */
100 
101  /**
102  * The number of locks, which is approximately the number of users,
103  * of this load-balance.
104  * Load-balance objects of via-entries are heavily shared by recursives,
105  * so the lock count is a u32.
106  */
108 
109  /**
110  * index of the load-balance map, INVALID if this LB does not use one
111  */
113 
114  /**
115  * This is the index of the uRPF list for this LB
116  */
118 
119  /**
120  * the hash config to use when selecting a bucket. this is a u16
121  */
123 
124  /**
125  * Vector of buckets containing the next DPOs, sized as lbo_num
126  */
128 
129  /**
130  * The rest of the cache line is used for buckets. In the common case
131  * where there there are less than 4 buckets, then the buckets are
132  * on the same cachlie and we save ourselves a pointer dereferance in
133  * the data-path.
134  */
135  dpo_id_t lb_buckets_inline[LB_NUM_INLINE_BUCKETS];
137 
139  "A load_balance object size exceeds one cachline");
140 
141 /**
142  * Flags controlling load-balance formatting/display
143  */
148 
149 /**
150  * Flags controlling load-balance creation and modification
151  */
152 typedef enum load_balance_flags_t_ {
156 
157 extern index_t load_balance_create(u32 num_buckets,
158  dpo_proto_t lb_proto,
159  flow_hash_config_t fhc);
161  const dpo_id_t *dpo,
162  const load_balance_path_t * raw_next_hops,
164 
165 extern void load_balance_set_bucket(index_t lbi,
166  u32 bucket,
167  const dpo_id_t *next);
168 extern void load_balance_set_urpf(index_t lbi,
169  index_t urpf);
171 
172 extern u8* format_load_balance(u8 * s, va_list * args);
173 
174 extern const dpo_id_t *load_balance_get_bucket(index_t lbi,
175  u32 bucket);
176 extern int load_balance_is_drop(const dpo_id_t *dpo);
177 
179 
180 /**
181  * The encapsulation breakages are for fast DP access
182  */
184 static inline load_balance_t*
186 {
187  return (pool_elt_at_index(load_balance_pool, lbi));
188 }
189 
190 #define LB_HAS_INLINE_BUCKETS(_lb) \
191  ((_lb)->lb_n_buckets <= LB_NUM_INLINE_BUCKETS)
192 
193 static inline const dpo_id_t *
195  u32 bucket)
196 {
197  ASSERT(bucket < lb->lb_n_buckets);
198 
200  {
201  return (&lb->lb_buckets_inline[bucket]);
202  }
203  else
204  {
205  return (&lb->lb_buckets[bucket]);
206  }
207 }
208 
209 extern void load_balance_module_init(void);
210 
211 #endif
u16 lb_n_buckets
number of buckets in the load-balance.
Definition: load_balance.h:87
index_t load_balance_get_urpf(index_t lbi)
Definition: load_balance.c:261
dpo_id_t * lb_buckets
Vector of buckets containing the next DPOs, sized as lbo_num.
Definition: load_balance.h:127
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:471
vlib_combined_counter_main_t lbm_to_counters
Definition: load_balance.h:45
STATIC_ASSERT(sizeof(load_balance_t)<=CLIB_CACHE_LINE_BYTES,"A load_balance object size exceeds one cachline")
fib_node_index_t path_index
The index of the FIB path.
Definition: load_balance.h:70
dpo_id_t path_dpo
ID of the Data-path object.
Definition: load_balance.h:65
void load_balance_module_init(void)
Definition: load_balance.c:811
load_balance_main_t load_balance_main
The one instance of load-balance main.
Definition: load_balance.c:55
#define PREDICT_TRUE(x)
Definition: clib.h:98
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.
f64 load_balance_get_multipath_tolerance(void)
Definition: load_balance.c:58
flow_hash_config_t lb_hash_config
the hash config to use when selecting a bucket.
Definition: load_balance.h:122
void load_balance_set_bucket(index_t lbi, u32 bucket, const dpo_id_t *next)
Definition: load_balance.c:209
load_balance_format_flags_t_
Flags controlling load-balance formatting/display.
Definition: load_balance.h:144
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:41
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
Definition: load_balance.c:271
u16 lb_n_buckets_minus_1
number of buckets in the load-balance - 1.
Definition: load_balance.h:92
load_balance_flags_t_
Flags controlling load-balance creation and modification.
Definition: load_balance.h:152
void load_balance_set_urpf(index_t lbi, index_t urpf)
Definition: load_balance.c:242
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
Definition: load_balance.h:194
dpo_proto_t lb_proto
The protocol of packets that traverse this LB.
Definition: load_balance.h:99
The FIB DPO provieds;.
Definition: load_balance.h:83
struct load_balance_main_t_ load_balance_main_t
The load-balance object represents an ECMP choice.
The load-balance object represents an ECMP choice.
Definition: load_balance.h:43
dpo_id_t lb_buckets_inline[LB_NUM_INLINE_BUCKETS]
The rest of the cache line is used for buckets.
Definition: load_balance.h:135
enum load_balance_flags_t_ load_balance_flags_t
Flags controlling load-balance creation and modification.
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
index_t load_balance_create(u32 num_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
Definition: load_balance.c:192
#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:55
vlib_combined_counter_main_t lbm_via_counters
Definition: load_balance.h:46
u8 * format_load_balance(u8 *s, va_list *args)
Definition: load_balance.c:149
#define ASSERT(truth)
index_t lb_urpf
This is the index of the uRPF list for this LB.
Definition: load_balance.h:117
unsigned int u32
Definition: types.h:88
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:185
load_balance_t * load_balance_pool
The encapsulation breakages are for fast DP access.
Definition: load_balance.c:50
u32 lb_locks
The number of locks, which is approximately the number of users, of this load-balance.
Definition: load_balance.h:107
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.
struct load_balance_t_ load_balance_t
The FIB DPO provieds;.
#define LB_HAS_INLINE_BUCKETS(_lb)
Definition: load_balance.h:190
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:160
unsigned short u16
Definition: types.h:57
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u32 path_weight
weight for the path.
Definition: load_balance.h:75
One path from an [EU]CMP set that the client wants to add to a load-balance object.
Definition: load_balance.h:61
A collection of combined counters.
Definition: counter.h:212
index_t lb_map
index of the load-balance map, INVALID if this LB does not use one
Definition: load_balance.h:112
u32 flags
Definition: vhost-user.h:75
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
int load_balance_is_drop(const dpo_id_t *dpo)
Definition: load_balance.c:225