GBP V2
[vpp.git] / src / plugins / gbp / gbp_endpoint.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_H__
17 #define __GBP_ENDPOINT_H__
18
19 #include <plugins/gbp/gbp_types.h>
20 #include <vnet/ip/ip.h>
21
22 /**
23  * The key for an Endpoint
24  */
25 typedef struct gbp_endpoint_key_t_
26 {
27   /**
28    * The interface on which the EP is connected
29    */
30   u32 gek_sw_if_index;
31
32   /**
33    * The IP[46] address of the endpoint
34    */
35   ip46_address_t gek_ip;
36 } gbp_endpoint_key_t;
37
38 /**
39  * A Group Based Policy Endpoint.
40  * This is typcially a VM on the local compute node for which policy must be
41  * locally applied
42  */
43 typedef struct gbp_endpoint_t_
44 {
45   /**
46    * The endpoint's interface and IP address
47    */
48   gbp_endpoint_key_t *ge_key;
49
50   /**
51    * The endpoint's designated EPG
52    */
53   epg_id_t ge_epg_id;
54 } gbp_endpoint_t;
55
56 /**
57  * Result of a interface to EPG mapping.
58  * multiple Endpoints can occur on the same interface, so this
59  * mapping needs to be reference counted.
60  */
61 typedef struct gbp_itf_t_
62 {
63   epg_id_t gi_epg;
64   u32 gi_ref_count;
65 } gbp_itf_t;
66
67 /**
68  * Interface to source EPG DB - a per-interface vector
69  */
70 typedef struct gbp_itf_to_epg_db_t_
71 {
72   gbp_itf_t *gte_vec;
73 } gbp_itf_to_epg_db_t;
74
75 extern int 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 cb, void *ctx);
81
82 /**
83  * Port to EPG mapping management
84  */
85 extern void gbp_itf_epg_update (u32 sw_if_index, epg_id_t src_epg,
86                                 u8 do_policy);
87 extern void gbp_itf_epg_delete (u32 sw_if_index);
88
89 /**
90  * DP functions and databases
91  */
92 extern gbp_itf_to_epg_db_t gbp_itf_to_epg_db;
93
94 /**
95  * Get the source EPG for a port/interface
96  */
97 always_inline u32
98 gbp_port_to_epg (u32 sw_if_index)
99 {
100   return (gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_epg);
101 }
102
103 #endif
104
105 /*
106  * fd.io coding-style-patch-verification: ON
107  *
108  * Local Variables:
109  * eval: (c-set-style "gnu")
110  * End:
111  */