vxlan-gbp: Add support for vxlan gbp
[vpp.git] / src / plugins / gbp / gbp_contract.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_CONTRACT_H__
17 #define __GBP_CONTRACT_H__
18
19 #include <plugins/gbp/gbp_types.h>
20
21 /**
22  * The key for an Contract
23  */
24 typedef struct gbp_contract_key_t_
25 {
26   union
27   {
28     struct
29     {
30       /**
31        * source and destination EPGs for which the ACL applies
32        */
33       epg_id_t gck_src;
34       epg_id_t gck_dst;
35     };
36     u32 as_u32;
37   };
38 } gbp_contract_key_t;
39
40 /**
41  * The value for an Contract
42  */
43 typedef struct gbp_contract_value_t_
44 {
45   union
46   {
47     struct
48     {
49       /**
50        * lookup context and acl index
51        */
52       u32 gc_lc_index;
53       u32 gc_acl_index;
54     };
55     u64 as_u64;
56   };
57 } gbp_contract_value_t;
58
59 /**
60  * A Group Based Policy Contract.
61  *  Determines the ACL that applies to traffic pass between two endpoint groups
62  */
63 typedef struct gbp_contract_t_
64 {
65   /**
66    * source and destination EPGs
67    */
68   gbp_contract_key_t gc_key;
69
70   /**
71    * The ACL to apply for packets from the source to the destination EPG
72    */
73   gbp_contract_value_t gc_value;
74 } gbp_contract_t;
75
76 /**
77  * EPG src,dst pair to ACL mapping table, aka contract DB
78  */
79 typedef struct gbp_contract_db_t_
80 {
81   /**
82    * We can form a u64 key from the pair, so use a simple hash table
83    */
84   uword *gc_hash;
85 } gbp_contract_db_t;
86
87 extern void gbp_contract_update (epg_id_t src_epg,
88                                  epg_id_t dst_epg, u32 acl_index);
89 extern void gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg);
90
91 typedef int (*gbp_contract_cb_t) (gbp_contract_t * gbpe, void *ctx);
92 extern void gbp_contract_walk (gbp_contract_cb_t bgpe, void *ctx);
93
94
95 /**
96  * DP functions and databases
97  */
98 extern gbp_contract_db_t gbp_contract_db;
99
100 always_inline u64
101 gbp_acl_lookup (gbp_contract_key_t * key)
102 {
103   uword *p;
104
105   p = hash_get (gbp_contract_db.gc_hash, key->as_u32);
106
107   if (NULL != p)
108     return (p[0]);
109
110   return (~0);
111 }
112
113 #endif
114
115 /*
116  * fd.io coding-style-patch-verification: ON
117  *
118  * Local Variables:
119  * eval: (c-set-style "gnu")
120  * End:
121  */