GBP plugin
[vpp.git] / src / plugins / gbp / gbp.h
1 /*
2  * Copyright (c) 2013 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 /**
17  * Group Base Policy (GBP) defines:
18  *  - endpoints: typically a VM or container that is connected to the
19  *               virtual switch/router (i.e. to VPP)
20  *  - endpoint-group: (EPG) a collection of endpoints
21  *  - policy: rules determining which traffic can pass between EPGs a.k.a
22  *            a 'contract'
23  *
24  * Here, policy is implemented via an ACL.
25  * EPG classification for transit packets is determined by:
26  *  - source EPG: from the packet's input interface
27  *  - destination EPG: from the packet's destination IP address.
28  *
29  */
30
31 #ifndef included_vnet_gbp_h
32 #define included_vnet_gbp_h
33
34 #include <vlib/vlib.h>
35 #include <vnet/vnet.h>
36 #include <vnet/ip/ip.h>
37
38 typedef u32 epg_id_t;
39 #define EPG_INVALID (~0)
40
41 /**
42  * The key for an Endpoint
43  */
44 typedef struct gbp_endpoint_key_t_
45 {
46   /**
47    * The interface on which the EP is connected
48    */
49   u32 gek_sw_if_index;
50
51   /**
52    * The IP[46] address of the endpoint
53    */
54   ip46_address_t gek_ip;
55 } gbp_endpoint_key_t;
56
57 /**
58  * A Group Based Policy Endpoint.
59  * This is typcially a VM on the local compute node for which policy must be
60  * locally applied
61  */
62 typedef struct gbp_endpoint_t_
63 {
64   /**
65    * The endpoint's interface and IP address
66    */
67   gbp_endpoint_key_t *ge_key;
68
69   /**
70    * The endpoint's designated EPG
71    */
72   epg_id_t ge_epg_id;
73 } gbp_endpoint_t;
74
75 extern void gbp_endpoint_update (u32 sw_if_index,
76                                  const ip46_address_t * ip, epg_id_t epg_id);
77 extern void gbp_endpoint_delete (u32 sw_if_index, const ip46_address_t * ip);
78
79 typedef int (*gbp_endpoint_cb_t) (gbp_endpoint_t * gbpe, void *ctx);
80 extern void gbp_endpoint_walk (gbp_endpoint_cb_t bgpe, void *ctx);
81
82
83 /**
84  * The key for an Contract
85  */
86 typedef struct gbp_contract_key_t_
87 {
88   union
89   {
90     struct
91     {
92       /**
93        * source and destination EPGs for which the ACL applies
94        */
95       epg_id_t gck_src;
96       epg_id_t gck_dst;
97     };
98     u64 as_u64;
99   };
100 } gbp_contract_key_t;
101
102 /**
103  * A Group Based Policy Contract.
104  *  Determines the ACL that applies to traffic pass between two endpoint groups
105  */
106 typedef struct gbp_contract_t_
107 {
108   /**
109    * source and destination EPGs
110    */
111   gbp_contract_key_t gc_key;
112
113   /**
114    * The ACL to apply for packets from the source to the destination EPG
115    */
116   u32 gc_acl_index;;
117 } gbp_contract_t;
118
119
120 extern void gbp_contract_update (epg_id_t src_epg,
121                                  epg_id_t dst_epg, u32 acl_index);
122 extern void gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg);
123
124 typedef int (*gbp_contract_cb_t) (gbp_contract_t * gbpe, void *ctx);
125 extern void gbp_contract_walk (gbp_contract_cb_t bgpe, void *ctx);
126
127 #endif
128
129 /*
130  * fd.io coding-style-patch-verification: ON
131  *
132  * Local Variables:
133  * eval: (c-set-style "gnu")
134  * End:
135  */