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_GROUP_H__
17 #define __GBP_ENDPOINT_GROUP_H__
19 #include <plugins/gbp/gbp_types.h>
21 #include <vnet/fib/fib_types.h>
24 * An Endpoint Group representation
26 typedef struct gpb_endpoint_group_t_
34 * Sclass. Could be unset => ~0
39 * Bridge-domain ID the EPG is in
45 * route-domain/IP-table ID the EPG is in
50 * Is the EPG an external/NAT
55 * the uplink interface dedicated to the EPG
57 u32 gg_uplink_sw_if_index;
60 * The DPO used in the L3 path for forwarding internal subnets
62 dpo_id_t gg_dpo[FIB_PROTOCOL_IP_MAX];
65 * Locks/references to this EPG
68 } gbp_endpoint_group_t;
71 * EPG DB, key'd on EGP-ID
73 typedef struct gbp_endpoint_group_db_t_
76 } gbp_endpoint_group_db_t;
78 extern int gbp_endpoint_group_add_and_lock (epg_id_t epg_id,
82 u32 uplink_sw_if_index);
83 extern index_t gbp_endpoint_group_find (epg_id_t epg_id);
84 extern int gbp_endpoint_group_delete (epg_id_t epg_id);
85 extern void gbp_endpoint_group_unlock (index_t index);
86 extern void gbp_endpoint_group_lock (index_t index);
87 extern u32 gbp_endpoint_group_get_bd_id (const gbp_endpoint_group_t *);
89 extern gbp_endpoint_group_t *gbp_endpoint_group_get (index_t i);
90 extern index_t gbp_endpoint_group_get_fib_index (const gbp_endpoint_group_t *
91 gg, fib_protocol_t fproto);
93 typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
95 extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);
98 extern u8 *format_gbp_endpoint_group (u8 * s, va_list * args);
101 * DP functions and databases
103 extern gbp_endpoint_group_db_t gbp_endpoint_group_db;
104 extern gbp_endpoint_group_t *gbp_endpoint_group_pool;
105 extern uword *gbp_epg_sclass_db;
107 always_inline gbp_endpoint_group_t *
108 gbp_epg_get (epg_id_t epg)
112 p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
115 return (pool_elt_at_index (gbp_endpoint_group_pool, p[0]));
120 gbp_epg_itf_lookup (epg_id_t epg)
124 p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
128 gbp_endpoint_group_t *gg;
130 gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
131 return (gg->gg_uplink_sw_if_index);
136 always_inline epg_id_t
137 gbp_epg_sclass_2_id (u16 sclass)
141 p = hash_get (gbp_epg_sclass_db, sclass);
147 return (EPG_INVALID);
150 always_inline const dpo_id_t *
151 gbp_epg_dpo_lookup (epg_id_t epg, fib_protocol_t fproto)
155 p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
159 gbp_endpoint_group_t *gg;
161 gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
162 return (&gg->gg_dpo[fproto]);
170 * fd.io coding-style-patch-verification: ON
173 * eval: (c-set-style "gnu")