GBP V2
[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     u64 as_u64;
37   };
38 } gbp_contract_key_t;
39
40 /**
41  * A Group Based Policy Contract.
42  *  Determines the ACL that applies to traffic pass between two endpoint groups
43  */
44 typedef struct gbp_contract_t_
45 {
46   /**
47    * source and destination EPGs
48    */
49   gbp_contract_key_t gc_key;
50
51   /**
52    * The ACL to apply for packets from the source to the destination EPG
53    */
54   u32 gc_acl_index;;
55 } gbp_contract_t;
56
57 /**
58  * EPG src,dst pair to ACL mapping table, aka contract DB
59  */
60 typedef struct gbp_contract_db_t_
61 {
62   /**
63    * We can form a u64 key from the pair, so use a simple hash table
64    */
65   uword *gc_hash;
66 } gbp_contract_db_t;
67
68 extern void gbp_contract_update (epg_id_t src_epg,
69                                  epg_id_t dst_epg, u32 acl_index);
70 extern void gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg);
71
72 typedef int (*gbp_contract_cb_t) (gbp_contract_t * gbpe, void *ctx);
73 extern void gbp_contract_walk (gbp_contract_cb_t bgpe, void *ctx);
74
75
76 /**
77  * DP functions and databases
78  */
79 extern gbp_contract_db_t gbp_contract_db;
80
81 always_inline u32
82 gbp_acl_lookup (gbp_contract_key_t * key)
83 {
84   uword *p;
85
86   p = hash_get (gbp_contract_db.gc_hash, key->as_u64);
87
88   if (NULL != p)
89     return (p[0]);
90
91   return (~0);
92 }
93
94 #endif
95
96 /*
97  * fd.io coding-style-patch-verification: ON
98  *
99  * Local Variables:
100  * eval: (c-set-style "gnu")
101  * End:
102  */