FD.io VPP  v19.04.2-12-g66b1689
Vector Packet Processing
gbp_endpoint.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #ifndef __GBP_ENDPOINT_H__
17 #define __GBP_ENDPOINT_H__
18 
19 #include <plugins/gbp/gbp_types.h>
20 #include <vnet/ip/ip.h>
22 
23 #include <vppinfra/bihash_16_8.h>
25 #include <vppinfra/bihash_24_8.h>
27 
28 /**
29  * Flags for each endpoint
30  */
32 {
40 
42 {
49 
50 #define GBP_ENDPOINT_ATTR_NAMES { \
51  [GBP_ENDPOINT_ATTR_BOUNCE] = "bounce", \
52  [GBP_ENDPOINT_ATTR_REMOTE] = "remote", \
53  [GBP_ENDPOINT_ATTR_LEARNT] = "learnt", \
54  [GBP_ENDPOINT_ATTR_EXTERNAL] = "external", \
55 }
56 
57 extern u8 *format_gbp_endpoint_flags (u8 * s, va_list * args);
58 
59 /**
60  * Sources of Endpoints in priority order. The best (lowest value) source
61  * provides the forwarding information
62  */
63 #define foreach_gbp_endpoint_src \
64  _(CP, "control-plane") \
65  _(DP, "data-plane") \
66  _(RR, "recursive-resolution")
67 
68 typedef enum gbp_endpoint_src_t_
69 {
70 #define _(v,s) GBP_ENDPOINT_SRC_##v,
72 #undef _
74 
75 #define GBP_ENDPOINT_SRC_MAX (GBP_ENDPOINT_SRC_RR+1)
76 
77 extern u8 *format_gbp_endpoint_src (u8 * s, va_list * args);
78 
79 /**
80  * This is the identity of an endpoint, as such it is information
81  * about an endpoint that is idempotent.
82  * The ID is used to add the EP into the various data-bases for retrieval.
83  */
84 typedef struct gbp_endpoint_key_t_
85 {
86  /**
87  * A vector of ip addresses that belong to the endpoint.
88  * Together with the route EPG's RD this forms the EP's L3 key
89  */
91 
92  /**
93  * MAC address of the endpoint.
94  * Together with the route EPG's BD this forms the EP's L2 key
95  */
97 
98  /**
99  * Index of the Bridge-Domain
100  */
102 
103  /**
104  * Index of the Route-Domain
105  */
108 
109 /**
110  * Information about the location of the endpoint provided by a source
111  * of endpoints
112  */
113 typedef struct gbp_endpoint_loc_t_
114 {
115  /**
116  * The source providing this location information
117  */
118  gbp_endpoint_src_t gel_src;
119 
120  /**
121  * The interface on which the EP is connected
122  */
124 
125  /**
126  * Endpoint flags
127  */
129 
130  /**
131  * Endpoint Group.
132  */
134 
135  /**
136  * number of times this source has locked this
137  */
139 
140  /**
141  * Tunnel info for remote endpoints
142  */
143  struct
144  {
146  ip46_address_t gel_src;
147  ip46_address_t gel_dst;
148  } tun;
150 
151 /**
152  * And endpoints current forwarding state
153  */
154 typedef struct gbp_endpoint_fwd_t_
155 {
156  /**
157  * The interface on which the EP is connected
158  */
160 
161  /**
162  * The L3 adj, if created
163  */
165 
166  /**
167  * Endpoint Group's sclass. cached for fast DP access.
168  */
170 
171  /**
172  * FIB index the EP is in
173  */
175 
178 
179 /**
180  * A Group Based Policy Endpoint.
181  * This is typically a VM or container. If the endpoint is local (i.e. on
182  * the same compute node as VPP) then there is one interface per-endpoint.
183  * If the EP is remote,e.g. reachable over a [vxlan] tunnel, then there
184  * will be multiple EPs reachable over the tunnel and they can be distinguished
185  * via either their MAC or IP Address[es].
186  */
187 typedef struct gbp_endpoint_t_
188 {
189  /**
190  * A FIB node that allows the tracking of children.
191  */
193 
194  /**
195  * The key/ID of this EP
196  */
198 
199  /**
200  * Location information provided by the various sources.
201  * These are sorted based on source priority.
202  */
204 
206 
207  /**
208  * The last time a packet from seen from this end point
209  */
212 
213 extern u8 *format_gbp_endpoint (u8 * s, va_list * args);
214 
215 /**
216  * GBP Endpoint Databases
217  */
219 {
221  clib_bihash_24_8_t ged_by_ip_rd;
222  clib_bihash_16_8_t ged_by_mac_bd;
223 } gbp_ep_db_t;
224 
225 extern int gbp_endpoint_update_and_lock (gbp_endpoint_src_t src,
227  const ip46_address_t * ip,
228  const mac_address_t * mac,
229  index_t gbd, index_t grd,
232  const ip46_address_t * tun_src,
233  const ip46_address_t * tun_dst,
234  u32 * handle);
235 extern void gbp_endpoint_unlock (gbp_endpoint_src_t src, index_t gbpei);
237  fib_node_type_t type,
238  fib_node_index_t index);
239 extern void gbp_endpoint_child_remove (index_t gei, u32 sibling);
240 
241 typedef walk_rc_t (*gbp_endpoint_cb_t) (index_t gbpei, void *ctx);
242 extern void gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx);
243 extern void gbp_endpoint_scan (vlib_main_t * vm);
244 extern int gbp_endpoint_is_remote (const gbp_endpoint_t * ge);
245 extern int gbp_endpoint_is_local (const gbp_endpoint_t * ge);
246 extern int gbp_endpoint_is_external (const gbp_endpoint_t * ge);
247 extern int gbp_endpoint_is_learnt (const gbp_endpoint_t * ge);
248 
249 
250 extern void gbp_endpoint_flush (gbp_endpoint_src_t src, u32 sw_if_index);
251 
252 /**
253  * DP functions and databases
254  */
255 extern gbp_ep_db_t gbp_ep_db;
257 
258 /**
259  * Get the endpoint from a port/interface
260  */
263 {
264  return (pool_elt_at_index (gbp_endpoint_pool, gbpei));
265 }
266 
269  u32 bd_index, clib_bihash_kv_16_8_t * key)
270 {
271  key->key[0] = ethernet_mac_address_u64 (mac);
272  key->key[1] = bd_index;
273 }
274 
276 gbp_endpoint_find_mac (const u8 * mac, u32 bd_index)
277 {
278  clib_bihash_kv_16_8_t key, value;
279  int rv;
280 
281  gbp_endpoint_mk_key_mac (mac, bd_index, &key);
282 
283  rv = clib_bihash_search_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, &value);
284 
285  if (0 != rv)
286  return NULL;
287 
288  return (gbp_endpoint_get (value.value));
289 }
290 
292 gbp_endpoint_mk_key_ip (const ip46_address_t * ip,
293  u32 fib_index, clib_bihash_kv_24_8_t * key)
294 {
295  key->key[0] = ip->as_u64[0];
296  key->key[1] = ip->as_u64[1];
297  key->key[2] = fib_index;
298 }
299 
302  u32 fib_index, clib_bihash_kv_24_8_t * key)
303 {
304  const ip46_address_t a = {
305  .ip4 = *ip,
306  };
307  gbp_endpoint_mk_key_ip (&a, fib_index, key);
308 }
309 
311 gbp_endpoint_find_ip4 (const ip4_address_t * ip, u32 fib_index)
312 {
313  clib_bihash_kv_24_8_t key, value;
314  int rv;
315 
316  gbp_endpoint_mk_key_ip4 (ip, fib_index, &key);
317 
318  rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
319 
320  if (0 != rv)
321  return NULL;
322 
323  return (gbp_endpoint_get (value.value));
324 }
325 
328  u32 fib_index, clib_bihash_kv_24_8_t * key)
329 {
330  key->key[0] = ip->as_u64[0];
331  key->key[1] = ip->as_u64[1];
332  key->key[2] = fib_index;
333 }
334 
336 gbp_endpoint_find_ip6 (const ip6_address_t * ip, u32 fib_index)
337 {
338  clib_bihash_kv_24_8_t key, value;
339  int rv;
340 
341  gbp_endpoint_mk_key_ip6 (ip, fib_index, &key);
342 
343  rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
344 
345  if (0 != rv)
346  return NULL;
347 
348  return (gbp_endpoint_get (value.value));
349 }
350 
353 {
354  index_t gei;
355 
356  gei = gbp_ep_db.ged_by_sw_if_index[sw_if_index];
357 
358  if (INDEX_INVALID != gei)
359  return (gbp_endpoint_get (gei));
360 
361  return (NULL);
362 }
363 
364 
365 #endif
366 
367 /*
368  * fd.io coding-style-patch-verification: ON
369  *
370  * Local Variables:
371  * eval: (c-set-style "gnu")
372  * End:
373  */
u32 sw_if_index
Definition: ipsec_gre.api:37
index_t gek_grd
Index of the Route-Domain.
Definition: gbp_endpoint.h:106
u32 flags
Definition: vhost_user.h:115
u32 gef_fib_index
FIB index the EP is in.
Definition: gbp_endpoint.h:174
static gbp_endpoint_t * gbp_endpoint_get(index_t gbpei)
Get the endpoint from a port/interface.
Definition: gbp_endpoint.h:262
f64 ge_last_time
The last time a packet from seen from this end point.
Definition: gbp_endpoint.h:210
u16 sclass_t
Definition: gbp_types.h:24
index_t * ged_by_sw_if_index
Definition: gbp_endpoint.h:220
A Group Based Policy Endpoint.
Definition: gbp_endpoint.h:187
fib_prefix_t * gek_ips
A vector of ip addresses that belong to the endpoint.
Definition: gbp_endpoint.h:90
a
Definition: bitmap.h:538
Information about the location of the endpoint provided by a source of endpoints. ...
Definition: gbp_endpoint.h:113
gbp_endpoint_fwd_t ge_fwd
Definition: gbp_endpoint.h:205
gbp_endpoint_key_t ge_key
The key/ID of this EP.
Definition: gbp_endpoint.h:197
index_t * gef_adjs
The L3 adj, if created.
Definition: gbp_endpoint.h:164
int gbp_endpoint_update_and_lock(gbp_endpoint_src_t src, u32 sw_if_index, const ip46_address_t *ip, const mac_address_t *mac, index_t gbd, index_t grd, sclass_t sclass, gbp_endpoint_flags_t flags, const ip46_address_t *tun_src, const ip46_address_t *tun_dst, u32 *handle)
Definition: gbp_endpoint.c:824
u64 as_u64[2]
Definition: ip6_packet.h:51
#define NULL
Definition: clib.h:58
gbp_endpoint_flags_t gef_flags
Definition: gbp_endpoint.h:176
index_t gef_itf
The interface on which the EP is connected.
Definition: gbp_endpoint.h:159
enum gbp_endpoint_src_t_ gbp_endpoint_src_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:41
gbp_endpoint_flags_t_
Definition: gbp_endpoint.h:41
gbp_endpoint_src_t gel_src
The source providing this location information.
Definition: gbp_endpoint.h:118
unsigned char u8
Definition: types.h:56
struct gbp_endpoint_key_t_ gbp_endpoint_key_t
This is the identity of an endpoint, as such it is information about an endpoint that is idempotent...
double f64
Definition: types.h:142
static_always_inline gbp_endpoint_t * gbp_endpoint_find_ip4(const ip4_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.h:311
enum walk_rc_t_ walk_rc_t
Walk return code.
struct gbp_endpoint_fwd_t_ gbp_endpoint_fwd_t
And endpoints current forwarding state.
#define static_always_inline
Definition: clib.h:99
gbp_endpoint_flags_t gel_flags
Endpoint flags.
Definition: gbp_endpoint.h:128
#define always_inline
Definition: clib.h:98
gbp_endpoint_t * gbp_endpoint_pool
Pool of GBP endpoints.
Definition: gbp_endpoint.c:57
gbp_endpoint_attr_t_
Flags for each endpoint.
Definition: gbp_endpoint.h:31
void gbp_endpoint_scan(vlib_main_t *vm)
clib_bihash_24_8_t ged_by_ip_rd
Definition: gbp_endpoint.h:221
u32 gel_sw_if_index
The interface on which the EP is connected.
Definition: gbp_endpoint.h:123
static_always_inline gbp_endpoint_t * gbp_endpoint_find_mac(const u8 *mac, u32 bd_index)
Definition: gbp_endpoint.h:276
Aggregrate type for a prefix.
Definition: fib_types.h:203
unsigned int u32
Definition: types.h:88
static_always_inline void gbp_endpoint_mk_key_ip6(const ip6_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:327
index_t gek_gbd
Index of the Bridge-Domain.
Definition: gbp_endpoint.h:101
u8 * format_gbp_endpoint_flags(u8 *s, va_list *args)
Definition: gbp_endpoint.c:70
u8 * format_gbp_endpoint_src(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
GBP Endpoint Databases.
Definition: gbp_endpoint.h:218
long ctx[MAX_CONNS]
Definition: main.c:144
u16 sclass
Definition: gbp.api:118
ip46_address_t gel_src
Definition: gbp_endpoint.h:146
clib_bihash_16_8_t ged_by_mac_bd
Definition: gbp_endpoint.h:222
void gbp_endpoint_unlock(gbp_endpoint_src_t src, index_t gbpei)
Definition: gbp_endpoint.c:920
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
An node in the FIB graph.
Definition: fib_node.h:291
sclass_t gef_sclass
Endpoint Group&#39;s sclass.
Definition: gbp_endpoint.h:169
mac_address_t gek_mac
MAC address of the endpoint.
Definition: gbp_endpoint.h:96
static_always_inline gbp_endpoint_t * gbp_endpoint_find_ip6(const ip6_address_t *ip, u32 fib_index)
Definition: gbp_endpoint.h:336
u8 * format_gbp_endpoint(u8 *s, va_list *args)
enum gbp_endpoint_attr_t_ gbp_endpoint_attr_t
Flags for each endpoint.
vlib_main_t * vm
Definition: buffer.c:312
void gbp_endpoint_flush(gbp_endpoint_src_t src, u32 sw_if_index)
remove all learnt endpoints using the interface
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
int gbp_endpoint_is_learnt(const gbp_endpoint_t *ge)
static u64 ethernet_mac_address_u64(const u8 *a)
Definition: mac_address.h:40
This is the identity of an endpoint, as such it is information about an endpoint that is idempotent...
Definition: gbp_endpoint.h:84
u32 gbp_endpoint_child_add(index_t gei, fib_node_type_t type, fib_node_index_t index)
struct gbp_endpoint_t_ gbp_endpoint_t
A Group Based Policy Endpoint.
enum gbp_endpoint_flags_t_ gbp_endpoint_flags_t
gbp_endpoint_src_t_
Definition: gbp_endpoint.h:68
gbp_ep_db_t gbp_ep_db
DP functions and databases.
Definition: gbp_endpoint.c:42
static_always_inline void gbp_endpoint_mk_key_mac(const u8 *mac, u32 bd_index, clib_bihash_kv_16_8_t *key)
Definition: gbp_endpoint.h:268
static_always_inline void gbp_endpoint_mk_key_ip(const ip46_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:292
fib_node_t ge_node
A FIB node that allows the tracking of children.
Definition: gbp_endpoint.h:192
u32 gel_locks
number of times this source has locked this
Definition: gbp_endpoint.h:138
And endpoints current forwarding state.
Definition: gbp_endpoint.h:154
void gbp_endpoint_walk(gbp_endpoint_cb_t cb, void *ctx)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
typedef key
Definition: ipsec.api:244
struct gbp_endpoint_loc_t_ gbp_endpoint_loc_t
Information about the location of the endpoint provided by a source of endpoints. ...
void gbp_endpoint_child_remove(index_t gei, u32 sibling)
vl_api_gbp_endpoint_tun_t tun
Definition: gbp.api:121
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
static_always_inline gbp_endpoint_t * gbp_endpoint_find_itf(u32 sw_if_index)
Definition: gbp_endpoint.h:352
int gbp_endpoint_is_external(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:99
int gbp_endpoint_is_remote(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:87
index_t gel_epg
Endpoint Group.
Definition: gbp_endpoint.h:133
static_always_inline void gbp_endpoint_mk_key_ip4(const ip4_address_t *ip, u32 fib_index, clib_bihash_kv_24_8_t *key)
Definition: gbp_endpoint.h:301
gbp_endpoint_loc_t * ge_locs
Location information provided by the various sources.
Definition: gbp_endpoint.h:203
ip46_address_t gel_dst
Definition: gbp_endpoint.h:147
vl_api_mac_address_t mac
Definition: gbp.api:120
#define foreach_gbp_endpoint_src
Sources of Endpoints in priority order.
Definition: gbp_endpoint.h:63
walk_rc_t(* gbp_endpoint_cb_t)(index_t gbpei, void *ctx)
Definition: gbp_endpoint.h:241
struct gbp_ep_by_ip_itf_db_t_ gbp_ep_db_t
GBP Endpoint Databases.
int gbp_endpoint_is_local(const gbp_endpoint_t *ge)
Definition: gbp_endpoint.c:93