vxlan: multiarch optimization of vxlan
[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 #include <plugins/gbp/gbp_itf.h>
21
22 #include <vnet/fib/fib_types.h>
23
24 /**
25  * Endpoint Retnetion Policy
26  */
27 typedef struct gbp_endpoint_retention_t_
28 {
29   /** Aging timeout for remote endpoints */
30   u32 remote_ep_timeout;
31 } gbp_endpoint_retention_t;
32
33 /**
34  * An Endpoint Group representation
35  */
36 typedef struct gpb_endpoint_group_t_
37 {
38   /**
39    * ID
40    */
41   vnid_t gg_vnid;
42
43   /**
44    * Sclass. Could be unset => ~0
45    */
46   u16 gg_sclass;
47
48   /**
49    * Bridge-domain ID the EPG is in
50    */
51   index_t gg_gbd;
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   gbp_itf_hdl_t gg_uplink_itf;
68
69   /**
70    * The DPO used in the L3 path for forwarding internal subnets
71    */
72   dpo_id_t gg_dpo[FIB_PROTOCOL_IP_MAX];
73
74   /**
75    * Locks/references to this EPG
76    */
77   u32 gg_locks;
78
79   /**
80    * EP retention policy
81    */
82   gbp_endpoint_retention_t gg_retention;
83 } gbp_endpoint_group_t;
84
85 /**
86  * EPG DB, key'd on EGP-ID
87  */
88 typedef struct gbp_endpoint_group_db_t_
89 {
90   uword *gg_hash_sclass;
91 } gbp_endpoint_group_db_t;
92
93 extern int gbp_endpoint_group_add_and_lock (vnid_t vnid,
94                                             u16 sclass,
95                                             u32 bd_id,
96                                             u32 rd_id,
97                                             u32 uplink_sw_if_index,
98                                             const gbp_endpoint_retention_t *
99                                             retention);
100 extern index_t gbp_endpoint_group_find (sclass_t sclass);
101 extern int gbp_endpoint_group_delete (sclass_t sclass);
102 extern void gbp_endpoint_group_unlock (index_t index);
103 extern void gbp_endpoint_group_lock (index_t index);
104 extern u32 gbp_endpoint_group_get_bd_id (const gbp_endpoint_group_t *);
105
106 extern gbp_endpoint_group_t *gbp_endpoint_group_get (index_t i);
107 extern index_t gbp_endpoint_group_get_fib_index (const gbp_endpoint_group_t *
108                                                  gg, fib_protocol_t fproto);
109
110 typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
111                                         void *ctx);
112 extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);
113
114
115 extern u8 *format_gbp_endpoint_group (u8 * s, va_list * args);
116
117 /**
118  * DP functions and databases
119  */
120 extern gbp_endpoint_group_db_t gbp_endpoint_group_db;
121 extern gbp_endpoint_group_t *gbp_endpoint_group_pool;
122 extern uword *gbp_epg_sclass_db;
123
124 always_inline u32
125 gbp_epg_itf_lookup_sclass (sclass_t sclass)
126 {
127   uword *p;
128
129   p = hash_get (gbp_endpoint_group_db.gg_hash_sclass, sclass);
130
131   if (NULL != p)
132     {
133       gbp_endpoint_group_t *gg;
134
135       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
136       return (gg->gg_uplink_sw_if_index);
137     }
138   return (~0);
139 }
140
141 always_inline const dpo_id_t *
142 gbp_epg_dpo_lookup (sclass_t sclass, fib_protocol_t fproto)
143 {
144   uword *p;
145
146   p = hash_get (gbp_endpoint_group_db.gg_hash_sclass, sclass);
147
148   if (NULL != p)
149     {
150       gbp_endpoint_group_t *gg;
151
152       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
153       return (&gg->gg_dpo[fproto]);
154     }
155   return (NULL);
156 }
157
158 #endif
159
160 /*
161  * fd.io coding-style-patch-verification: ON
162  *
163  * Local Variables:
164  * eval: (c-set-style "gnu")
165  * End:
166  */