GBP: learn from ARP and L2 packets
[vpp.git] / src / plugins / gbp / gbp_vxlan.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_VXLAN_H__
17 #define __GBP_VXLAN_H__
18
19 #include <vnet/fib/fib_types.h>
20
21 #define forecah_gbp_vxlan_tunnel_layer          \
22   _(L2, "l2")                                   \
23   _(L3, "l3")
24
25 typedef enum gbp_vxlan_tunnel_layer_t_
26 {
27 #define _(s,n) GBP_VXLAN_TUN_##s,
28   forecah_gbp_vxlan_tunnel_layer
29 #undef _
30 } gbp_vxlan_tunnel_layer_t;
31
32 /**
33  * GBP VXLAN (template) tunnel.
34  * A template tunnel has only a VNI, it does not have src,dst address.
35  * As such it cannot be used to send traffic. It is used in the RX path
36  * to RX vxlan-gbp packets that do not match an existing tunnel;
37  */
38 typedef struct gbp_vxlan_tunnel_t_
39 {
40   u32 gt_hw_if_index;
41   u32 gt_sw_if_index;
42   u32 gt_vni;
43
44   /**
45    * The BD or RD value (depending on the layer) that the tunnel is bound to
46    */
47   u32 gt_bd_rd_id;
48   gbp_vxlan_tunnel_layer_t gt_layer;
49
50   union
51   {
52     struct
53     {
54       /**
55        * BD index (if L2)
56        */
57       u32 gt_bd_index;
58       /**
59        * Reference to the GPB-BD
60        */
61       index_t gt_gbd;
62     };
63     struct
64     {
65       /**
66        * FIB inidices (if L3)
67        */
68       u32 gt_fib_index[FIB_PROTOCOL_IP_MAX];
69       /**
70        * References to the GBP-RD
71        */
72       index_t gt_grd;
73     };
74   };
75
76   /**
77    * gbp-itf config for this interface
78    */
79   index_t gt_itf;
80
81   /**
82    * list of child vxlan-gbp tunnels built from this template
83    */
84   index_t *gt_tuns;
85
86   /**
87    * The source address to use for child tunnels
88    */
89   ip46_address_t gt_src;
90 } gbp_vxlan_tunnel_t;
91
92 /**
93  * The different types of interfaces that endpoints are learned on
94  */
95 typedef enum gbp_vxlan_tunnel_type_t_
96 {
97   /**
98    * This is the object type deifend above.
99    *  A template representation of a vxlan-gbp tunnel. from this tunnel
100    *  type, real vxlan-gbp tunnels are created (by cloning the VNI)
101    */
102   GBP_VXLAN_TEMPLATE_TUNNEL,
103
104   /**
105    * A real VXLAN-GBP tunnel (from vnet/vxlan-gbp/...)
106    */
107   VXLAN_GBP_TUNNEL,
108 } gbp_vxlan_tunnel_type_t;
109
110 extern int gbp_vxlan_tunnel_add (u32 vni, gbp_vxlan_tunnel_layer_t layer,
111                                  u32 bd_rd_id,
112                                  const ip4_address_t * src,
113                                  u32 * sw_if_indexp);
114 extern int gbp_vxlan_tunnel_del (u32 vni);
115
116 extern gbp_vxlan_tunnel_type_t gbp_vxlan_tunnel_get_type (u32 sw_if_index);
117
118 extern u32 gbp_vxlan_tunnel_clone_and_lock (u32 parent_tunnel,
119                                             const ip46_address_t * src,
120                                             const ip46_address_t * dst);
121
122 extern void vxlan_gbp_tunnel_lock (u32 sw_if_index);
123 extern void vxlan_gbp_tunnel_unlock (u32 sw_if_index);
124 extern u32 vxlan_gbp_tunnel_get_parent (u32 sw_if_index);
125
126 typedef walk_rc_t (*gbp_vxlan_cb_t) (gbp_vxlan_tunnel_t * gt, void *ctx);
127 extern void gbp_vxlan_walk (gbp_vxlan_cb_t cb, void *ctx);
128
129 extern u8 *format_gbp_vxlan_tunnel (u8 * s, va_list * args);
130 extern u8 *format_gbp_vxlan_tunnel_layer (u8 * s, va_list * args);
131
132 extern gbp_vxlan_tunnel_t *gbp_vxlan_tunnel_get (index_t gti);
133 #endif
134
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */