GBP: per-group EP retention policy
[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  * Endpoint Retnetion Policy
25  */
26 typedef struct gbp_endpoint_retention_t_
27 {
28   /** Aging timeout for remote endpoints */
29   u32 remote_ep_timeout;
30 } gbp_endpoint_retention_t;
31
32 /**
33  * An Endpoint Group representation
34  */
35 typedef struct gpb_endpoint_group_t_
36 {
37   /**
38    * ID
39    */
40   epg_id_t gg_id;
41
42   /**
43    * Sclass. Could be unset => ~0
44    */
45   u16 gg_sclass;
46
47   /**
48    * Bridge-domain ID the EPG is in
49    */
50   index_t gg_gbd;
51   index_t gg_bd_index;
52
53   /**
54    * route-domain/IP-table ID the EPG is in
55    */
56   index_t gg_rd;
57
58   /**
59    * Is the EPG an external/NAT
60    */
61   u8 gg_is_ext;
62
63   /**
64    * the uplink interface dedicated to the EPG
65    */
66   u32 gg_uplink_sw_if_index;
67
68   /**
69    * The DPO used in the L3 path for forwarding internal subnets
70    */
71   dpo_id_t gg_dpo[FIB_PROTOCOL_IP_MAX];
72
73   /**
74    * Locks/references to this EPG
75    */
76   u32 gg_locks;
77
78   /**
79    * EP retention policy
80    */
81   gbp_endpoint_retention_t gg_retention;
82 } gbp_endpoint_group_t;
83
84 /**
85  * EPG DB, key'd on EGP-ID
86  */
87 typedef struct gbp_endpoint_group_db_t_
88 {
89   uword *gg_hash;
90 } gbp_endpoint_group_db_t;
91
92 extern int gbp_endpoint_group_add_and_lock (epg_id_t epg_id,
93                                             u16 sclass,
94                                             u32 bd_id,
95                                             u32 rd_id,
96                                             u32 uplink_sw_if_index,
97                                             const gbp_endpoint_retention_t *
98                                             retention);
99 extern index_t gbp_endpoint_group_find (epg_id_t epg_id);
100 extern int gbp_endpoint_group_delete (epg_id_t epg_id);
101 extern void gbp_endpoint_group_unlock (index_t index);
102 extern void gbp_endpoint_group_lock (index_t index);
103 extern u32 gbp_endpoint_group_get_bd_id (const gbp_endpoint_group_t *);
104
105 extern gbp_endpoint_group_t *gbp_endpoint_group_get (index_t i);
106 extern index_t gbp_endpoint_group_get_fib_index (const gbp_endpoint_group_t *
107                                                  gg, fib_protocol_t fproto);
108
109 typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
110                                         void *ctx);
111 extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);
112
113
114 extern u8 *format_gbp_endpoint_group (u8 * s, va_list * args);
115
116 /**
117  * DP functions and databases
118  */
119 extern gbp_endpoint_group_db_t gbp_endpoint_group_db;
120 extern gbp_endpoint_group_t *gbp_endpoint_group_pool;
121 extern uword *gbp_epg_sclass_db;
122
123 always_inline gbp_endpoint_group_t *
124 gbp_epg_get (epg_id_t epg)
125 {
126   uword *p;
127
128   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
129
130   if (NULL != p)
131     return (pool_elt_at_index (gbp_endpoint_group_pool, p[0]));
132   return (NULL);
133 }
134
135 always_inline u32
136 gbp_epg_itf_lookup (epg_id_t epg)
137 {
138   uword *p;
139
140   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
141
142   if (NULL != p)
143     {
144       gbp_endpoint_group_t *gg;
145
146       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
147       return (gg->gg_uplink_sw_if_index);
148     }
149   return (~0);
150 }
151
152 always_inline epg_id_t
153 gbp_epg_sclass_2_id (u16 sclass)
154 {
155   uword *p;
156
157   p = hash_get (gbp_epg_sclass_db, sclass);
158
159   if (NULL != p)
160     {
161       return (p[0]);
162     }
163   return (EPG_INVALID);
164 }
165
166 always_inline const dpo_id_t *
167 gbp_epg_dpo_lookup (epg_id_t epg, fib_protocol_t fproto)
168 {
169   uword *p;
170
171   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
172
173   if (NULL != p)
174     {
175       gbp_endpoint_group_t *gg;
176
177       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
178       return (&gg->gg_dpo[fproto]);
179     }
180   return (NULL);
181 }
182
183 #endif
184
185 /*
186  * fd.io coding-style-patch-verification: ON
187  *
188  * Local Variables:
189  * eval: (c-set-style "gnu")
190  * End:
191  */