gbp: VRF scoped contracts
[vpp.git] / src / plugins / gbp / gbp_bridge_domain.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_BRIDGE_DOMAIN_H__
17 #define __GBP_BRIDGE_DOMAIN_H__
18
19 #include <plugins/gbp/gbp_types.h>
20
21 #include <vnet/fib/fib_types.h>
22
23 /**
24  * Bridge Domain Flags
25  */
26 typedef enum gbp_bridge_domain_flags_t_
27 {
28   GBP_BD_FLAG_NONE = 0,
29   GBP_BD_FLAG_DO_NOT_LEARN = (1 << 0),
30   GBP_BD_FLAG_UU_FWD_DROP = (1 << 1),
31   GBP_BD_FLAG_MCAST_DROP = (1 << 2),
32   GBP_BD_FLAG_UCAST_ARP = (1 << 3),
33 } gbp_bridge_domain_flags_t;
34
35 /**
36  * A bridge Domain Representation.
37  * This is a standard bridge-domain plus all the attributes it must
38  * have to supprt the GBP model.
39  */
40 typedef struct gbp_bridge_domain_t_
41 {
42   /**
43    * Bridge-domain ID
44    */
45   u32 gb_bd_id;
46   u32 gb_bd_index;
47
48   /**
49    * Index of the Route-domain this BD is associated with. This is used as the
50    * 'scope' of the packets for contract matching.
51    */
52   u32 gb_rdi;
53
54   /**
55    * Flags conttrolling behaviour
56    */
57   gbp_bridge_domain_flags_t gb_flags;
58
59   /**
60    * The BD's BVI interface (obligatory)
61    */
62   u32 gb_bvi_sw_if_index;
63
64   /**
65    * The BD's MAC spine-proxy interface (optional)
66    */
67   u32 gb_uu_fwd_sw_if_index;
68
69   /**
70    * The BD's interface to sned Broadcast and multicast packets
71    */
72   u32 gb_bm_flood_sw_if_index;
73
74   /**
75    * The index of the BD's VNI interface on which packets from
76    * unkown endpoints arrive
77    */
78   u32 gb_vni;
79
80   /**
81    * locks/references to the BD so it does not get deleted (from the API)
82    * whilst it is still being used
83    */
84   u32 gb_locks;
85 } gbp_bridge_domain_t;
86
87 extern int gbp_bridge_domain_add_and_lock (u32 bd_id,
88                                            u32 rd_id,
89                                            gbp_bridge_domain_flags_t flags,
90                                            u32 bvi_sw_if_index,
91                                            u32 uu_fwd_sw_if_index,
92                                            u32 bm_flood_sw_if_index);
93
94 extern void gbp_bridge_domain_unlock (index_t gbi);
95 extern index_t gbp_bridge_domain_find_and_lock (u32 bd_id);
96 extern int gbp_bridge_domain_delete (u32 bd_id);
97 extern index_t gbp_bridge_domain_index (const gbp_bridge_domain_t *);
98 extern u32 gbp_bridge_domain_get_bd_id (index_t gbdi);
99
100 typedef int (*gbp_bridge_domain_cb_t) (gbp_bridge_domain_t * gb, void *ctx);
101 extern void gbp_bridge_domain_walk (gbp_bridge_domain_cb_t bgpe, void *ctx);
102
103 extern u8 *format_gbp_bridge_domain (u8 * s, va_list * args);
104 extern u8 *format_gbp_bridge_domain_flags (u8 * s, va_list * args);
105
106 /**
107  * DB of bridge_domains
108  */
109 typedef struct gbp_bridge_domain_db_t
110 {
111   uword *gbd_by_bd_id;
112   index_t *gbd_by_bd_index;
113 } gbp_bridge_domain_db_t;
114
115 extern gbp_bridge_domain_db_t gbp_bridge_domain_db;
116 extern gbp_bridge_domain_t *gbp_bridge_domain_pool;
117
118 always_inline gbp_bridge_domain_t *
119 gbp_bridge_domain_get (index_t i)
120 {
121   return (pool_elt_at_index (gbp_bridge_domain_pool, i));
122 }
123
124 always_inline gbp_bridge_domain_t *
125 gbp_bridge_domain_get_by_bd_index (u32 bd_index)
126 {
127   return (gbp_bridge_domain_get
128           (gbp_bridge_domain_db.gbd_by_bd_index[bd_index]));
129 }
130
131 extern gbp_scope_t *gbp_scope_by_bd_index;
132
133 always_inline gbp_scope_t
134 gbp_bridge_domain_get_scope (u32 bd_index)
135 {
136   return (gbp_scope_by_bd_index[bd_index]);
137 }
138
139 #endif
140
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "gnu")
146  * End:
147  */