GBP: Sclass to src-epg conversions
[vpp.git] / src / plugins / gbp / gbp_endpoint_group.h
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_GROUP_H__
17 #define __GBP_ENDPOINT_GROUP_H__
18
19 #include <plugins/gbp/gbp_types.h>
20
21 #include <vnet/fib/fib_types.h>
22
23 /**
24  * An Endpoint Group representation
25  */
26 typedef struct gpb_endpoint_group_t_
27 {
28   /**
29    * ID
30    */
31   epg_id_t gg_id;
32
33   /**
34    * Sclass. Could be unset => ~0
35    */
36   u16 gg_sclass;
37
38   /**
39    * Bridge-domain ID the EPG is in
40    */
41   index_t gg_gbd;
42   index_t gg_bd_index;
43
44   /**
45    * route-domain/IP-table ID the EPG is in
46    */
47   index_t gg_rd;
48
49   /**
50    * Is the EPG an external/NAT
51    */
52   u8 gg_is_ext;
53
54   /**
55    * the uplink interface dedicated to the EPG
56    */
57   u32 gg_uplink_sw_if_index;
58
59   /**
60    * The DPO used in the L3 path for forwarding internal subnets
61    */
62   dpo_id_t gg_dpo[FIB_PROTOCOL_IP_MAX];
63
64   /**
65    * Locks/references to this EPG
66    */
67   u32 gg_locks;
68 } gbp_endpoint_group_t;
69
70 /**
71  * EPG DB, key'd on EGP-ID
72  */
73 typedef struct gbp_endpoint_group_db_t_
74 {
75   uword *gg_hash;
76 } gbp_endpoint_group_db_t;
77
78 extern int gbp_endpoint_group_add_and_lock (epg_id_t epg_id,
79                                             u16 sclass,
80                                             u32 bd_id,
81                                             u32 rd_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 *);
88
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);
92
93 typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
94                                         void *ctx);
95 extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);
96
97
98 extern u8 *format_gbp_endpoint_group (u8 * s, va_list * args);
99
100 /**
101  * DP functions and databases
102  */
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;
106
107 always_inline gbp_endpoint_group_t *
108 gbp_epg_get (epg_id_t epg)
109 {
110   uword *p;
111
112   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
113
114   if (NULL != p)
115     return (pool_elt_at_index (gbp_endpoint_group_pool, p[0]));
116   return (NULL);
117 }
118
119 always_inline u32
120 gbp_epg_itf_lookup (epg_id_t epg)
121 {
122   uword *p;
123
124   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
125
126   if (NULL != p)
127     {
128       gbp_endpoint_group_t *gg;
129
130       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
131       return (gg->gg_uplink_sw_if_index);
132     }
133   return (~0);
134 }
135
136 always_inline epg_id_t
137 gbp_epg_sclass_2_id (u16 sclass)
138 {
139   uword *p;
140
141   p = hash_get (gbp_epg_sclass_db, sclass);
142
143   if (NULL != p)
144     {
145       return (p[0]);
146     }
147   return (EPG_INVALID);
148 }
149
150 always_inline const dpo_id_t *
151 gbp_epg_dpo_lookup (epg_id_t epg, fib_protocol_t fproto)
152 {
153   uword *p;
154
155   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
156
157   if (NULL != p)
158     {
159       gbp_endpoint_group_t *gg;
160
161       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
162       return (&gg->gg_dpo[fproto]);
163     }
164   return (NULL);
165 }
166
167 #endif
168
169 /*
170  * fd.io coding-style-patch-verification: ON
171  *
172  * Local Variables:
173  * eval: (c-set-style "gnu")
174  * End:
175  */