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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __GBP_ENDPOINT_H__
17 #define __GBP_ENDPOINT_H__
19 #include <plugins/gbp/gbp_types.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/ethernet/mac_address.h>
23 #include <vppinfra/bihash_16_8.h>
24 #include <vppinfra/bihash_template.h>
25 #include <vppinfra/bihash_24_8.h>
26 #include <vppinfra/bihash_template.h>
29 * Flags for each endpoint
31 typedef enum gbp_endpoint_attr_t_
33 GBP_ENDPOINT_ATTR_FIRST = 0,
34 GBP_ENDPOINT_ATTR_BOUNCE = GBP_ENDPOINT_ATTR_FIRST,
35 GBP_ENDPOINT_ATTR_REMOTE = 1,
36 GBP_ENDPOINT_ATTR_LEARNT = 2,
37 GBP_ENDPOINT_ATTR_LAST,
38 } gbp_endpoint_attr_t;
40 typedef enum gbp_endpoint_flags_t_
42 GBP_ENDPOINT_FLAG_NONE = 0,
43 GBP_ENDPOINT_FLAG_BOUNCE = (1 << GBP_ENDPOINT_ATTR_BOUNCE),
44 GBP_ENDPOINT_FLAG_REMOTE = (1 << GBP_ENDPOINT_ATTR_REMOTE),
45 GBP_ENDPOINT_FLAG_LEARNT = (1 << GBP_ENDPOINT_ATTR_LEARNT),
46 } gbp_endpoint_flags_t;
48 #define GBP_ENDPOINT_ATTR_NAMES { \
49 [GBP_ENDPOINT_ATTR_BOUNCE] = "bounce", \
50 [GBP_ENDPOINT_ATTR_REMOTE] = "remote", \
51 [GBP_ENDPOINT_ATTR_LEARNT] = "learnt", \
54 extern u8 *format_gbp_endpoint_flags (u8 * s, va_list * args);
57 * Sources of Endpoints in priority order. The best (lowest value) source
58 * provides the forwarding information
60 #define foreach_gbp_endpoint_src \
61 _(CP, "control-plane") \
63 _(RR, "recursive-resolution")
65 typedef enum gbp_endpoint_src_t_
67 #define _(v,s) GBP_ENDPOINT_SRC_##v,
68 foreach_gbp_endpoint_src
72 #define GBP_ENDPOINT_SRC_MAX (GBP_ENDPOINT_SRC_RR+1)
74 extern u8 *format_gbp_endpoint_src (u8 * s, va_list * args);
77 * This is the identity of an endpoint, as such it is information
78 * about an endpoint that is idempotent.
79 * The ID is used to add the EP into the various data-bases for retrieval.
81 typedef struct gbp_endpoint_key_t_
84 * A vector of ip addresses that belong to the endpoint.
85 * Together with the route EPG's RD this forms the EP's L3 key
87 fib_prefix_t *gek_ips;
90 * MAC address of the endpoint.
91 * Together with the route EPG's BD this forms the EP's L2 key
93 mac_address_t gek_mac;
96 * Index of the Bridge-Domain
101 * Index of the Route-Domain
104 } gbp_endpoint_key_t;
107 * Information about the location of the endpoint provided by a source
110 typedef struct gbp_endpoint_loc_t_
113 * The source providing this location information
115 gbp_endpoint_src_t gel_src;
118 * The interface on which the EP is connected
125 gbp_endpoint_flags_t gel_flags;
133 * number of times this source has locked this
138 * Tunnel info for remote endpoints
142 u32 gel_parent_sw_if_index;
143 ip46_address_t gel_src;
144 ip46_address_t gel_dst;
146 } gbp_endpoint_loc_t;
149 * And endpoints current forwarding state
151 typedef struct gbp_endpoint_fwd_t_
154 * The interface on which the EP is connected
159 * The L3 adj, if created
164 * Endpoint Group's ID. cached for fast DP access.
168 gbp_endpoint_flags_t gef_flags;
169 } gbp_endpoint_fwd_t;
172 * A Group Based Policy Endpoint.
173 * This is typically a VM or container. If the endpoint is local (i.e. on
174 * the same compute node as VPP) then there is one interface per-endpoint.
175 * If the EP is remote,e.g. reachable over a [vxlan] tunnel, then there
176 * will be multiple EPs reachable over the tunnel and they can be distinguished
177 * via either their MAC or IP Address[es].
179 typedef struct gbp_endpoint_t_
182 * A FIB node that allows the tracking of children.
187 * The key/ID of this EP
189 gbp_endpoint_key_t ge_key;
192 * Location information provided by the various sources.
193 * These are sorted based on source priority.
195 gbp_endpoint_loc_t *ge_locs;
197 gbp_endpoint_fwd_t ge_fwd;
200 * The last time a packet from seen from this end point
205 extern u8 *format_gbp_endpoint (u8 * s, va_list * args);
208 * GBP Endpoint Databases
210 typedef struct gbp_ep_by_ip_itf_db_t_
212 index_t *ged_by_sw_if_index;
213 clib_bihash_24_8_t ged_by_ip_rd;
214 clib_bihash_16_8_t ged_by_mac_bd;
217 extern int gbp_endpoint_update_and_lock (gbp_endpoint_src_t src,
219 const ip46_address_t * ip,
220 const mac_address_t * mac,
221 index_t gbd, index_t grd,
223 gbp_endpoint_flags_t flags,
224 const ip46_address_t * tun_src,
225 const ip46_address_t * tun_dst,
227 extern void gbp_endpoint_unlock (gbp_endpoint_src_t src, index_t gbpei);
228 extern u32 gbp_endpoint_child_add (index_t gei,
229 fib_node_type_t type,
230 fib_node_index_t index);
231 extern void gbp_endpoint_child_remove (index_t gei, u32 sibling);
233 typedef walk_rc_t (*gbp_endpoint_cb_t) (index_t gbpei, void *ctx);
234 extern void gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx);
235 extern void gbp_endpoint_scan (vlib_main_t * vm);
236 extern f64 gbp_endpoint_scan_threshold (void);
237 extern int gbp_endpoint_is_remote (const gbp_endpoint_t * ge);
238 extern int gbp_endpoint_is_learnt (const gbp_endpoint_t * ge);
241 extern void gbp_endpoint_flush (gbp_endpoint_src_t src, u32 sw_if_index);
244 * DP functions and databases
246 extern gbp_ep_db_t gbp_ep_db;
247 extern gbp_endpoint_t *gbp_endpoint_pool;
250 * Get the endpoint from a port/interface
252 always_inline gbp_endpoint_t *
253 gbp_endpoint_get (index_t gbpei)
255 return (pool_elt_at_index (gbp_endpoint_pool, gbpei));
258 static_always_inline void
259 gbp_endpoint_mk_key_mac (const u8 * mac,
260 u32 bd_index, clib_bihash_kv_16_8_t * key)
262 key->key[0] = ethernet_mac_address_u64 (mac);
263 key->key[1] = bd_index;
266 static_always_inline gbp_endpoint_t *
267 gbp_endpoint_find_mac (const u8 * mac, u32 bd_index)
269 clib_bihash_kv_16_8_t key, value;
272 gbp_endpoint_mk_key_mac (mac, bd_index, &key);
274 rv = clib_bihash_search_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, &value);
279 return (gbp_endpoint_get (value.value));
282 static_always_inline void
283 gbp_endpoint_mk_key_ip (const ip46_address_t * ip,
284 u32 fib_index, clib_bihash_kv_24_8_t * key)
286 key->key[0] = ip->as_u64[0];
287 key->key[1] = ip->as_u64[1];
288 key->key[2] = fib_index;
291 static_always_inline void
292 gbp_endpoint_mk_key_ip4 (const ip4_address_t * ip,
293 u32 fib_index, clib_bihash_kv_24_8_t * key)
295 const ip46_address_t a = {
298 gbp_endpoint_mk_key_ip (&a, fib_index, key);
301 static_always_inline gbp_endpoint_t *
302 gbp_endpoint_find_ip4 (const ip4_address_t * ip, u32 fib_index)
304 clib_bihash_kv_24_8_t key, value;
307 gbp_endpoint_mk_key_ip4 (ip, fib_index, &key);
309 rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
314 return (gbp_endpoint_get (value.value));
317 static_always_inline void
318 gbp_endpoint_mk_key_ip6 (const ip6_address_t * ip,
319 u32 fib_index, clib_bihash_kv_24_8_t * key)
321 key->key[0] = ip->as_u64[0];
322 key->key[1] = ip->as_u64[1];
323 key->key[2] = fib_index;
326 static_always_inline gbp_endpoint_t *
327 gbp_endpoint_find_ip6 (const ip6_address_t * ip, u32 fib_index)
329 clib_bihash_kv_24_8_t key, value;
332 gbp_endpoint_mk_key_ip6 (ip, fib_index, &key);
334 rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
339 return (gbp_endpoint_get (value.value));
342 static_always_inline gbp_endpoint_t *
343 gbp_endpoint_find_itf (u32 sw_if_index)
347 gei = gbp_ep_db.ged_by_sw_if_index[sw_if_index];
349 if (INDEX_INVALID != gei)
350 return (gbp_endpoint_get (gei));
359 * fd.io coding-style-patch-verification: ON
362 * eval: (c-set-style "gnu")