blob: 9597205caed524916b3ab996e788ff0cdd323bec [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * l2_output.h : layer 2 output packet processing
3 *
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef included_vnet_l2_output_h
19#define included_vnet_l2_output_h
20
21#include <vlib/vlib.h>
22#include <vnet/vnet.h>
23#include <vnet/l2/feat_bitmap.h>
24#include <vnet/l2/l2_vtr.h>
25
26
Dave Barach97d8dc22016-08-15 15:31:15 -040027/* The L2 output feature configuration, a per-interface struct */
28typedef struct
29{
Ed Warnickecb9cada2015-12-08 15:45:58 -070030
31 u32 feature_bitmap;
32
Dave Barach97d8dc22016-08-15 15:31:15 -040033 /*
34 * vlan tag rewrite for ingress and egress
35 * ingress vtr is located here because the same config data is used for
36 * the egress EFP filter check
37 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070038 vtr_config_t input_vtr;
39 vtr_config_t output_vtr;
Pavel Kotucek95300d12016-08-26 16:11:36 +020040 ptr_config_t input_pbb_vtr;
41 ptr_config_t output_pbb_vtr;
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
Dave Barach97d8dc22016-08-15 15:31:15 -040043 /* some of these flags may get integrated into the feature bitmap */
44 u8 fwd_enable;
45 u8 flood_enable;
Ed Warnickecb9cada2015-12-08 15:45:58 -070046
Dave Barach97d8dc22016-08-15 15:31:15 -040047 /* split horizon group */
48 u8 shg;
Ed Warnickecb9cada2015-12-08 15:45:58 -070049
Pavel Kotucek95300d12016-08-26 16:11:36 +020050 /* flag for output vtr operation */
51 u8 out_vtr_flag;
52
Ed Warnickecb9cada2015-12-08 15:45:58 -070053} l2_output_config_t;
54
55
Dave Barach97d8dc22016-08-15 15:31:15 -040056/*
57 * The set of next nodes for features and interface output.
58 * Each output feature node should include this.
59 */
60typedef struct
61{
62 /*
63 * vector of output next node index, indexed by sw_if_index.
64 * used when all output features have been executed and the
65 * next nodes are the interface output nodes.
66 */
67 u32 *output_node_index_vec;
Ed Warnickecb9cada2015-12-08 15:45:58 -070068
Dave Barach97d8dc22016-08-15 15:31:15 -040069 /*
70 * array of next node index for each output feature, indexed
71 * by l2output_feat_t. Used to determine next feature node.
72 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 u32 feat_next_node_index[32];
74
75} l2_output_next_nodes_st;
76
77
Dave Barach97d8dc22016-08-15 15:31:15 -040078typedef struct
79{
80 /* Next nodes for features and output interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 l2_output_next_nodes_st next_nodes;
82
83 /* config vector indexed by sw_if_index */
84 l2_output_config_t *configs;
85
86 /* Convenience variables */
Dave Barach97d8dc22016-08-15 15:31:15 -040087 vlib_main_t *vlib_main;
88 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070089} l2output_main_t;
90
91l2output_main_t l2output_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Dave Barach97d8dc22016-08-15 15:31:15 -040093/* L2 output features */
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
Dave Barach97d8dc22016-08-15 15:31:15 -040095/* Mappings from feature ID to graph node name */
Ed Warnickecb9cada2015-12-08 15:45:58 -070096#define foreach_l2output_feat \
Andrew Yourtchenkocc405652017-03-03 13:11:30 +000097 _(OUTPUT, "interface-output") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070098 _(SPAN, "feature-bitmap-drop") \
99 _(CFM, "feature-bitmap-drop") \
100 _(QOS, "feature-bitmap-drop") \
101 _(ACL, "l2-output-acl") \
102 _(L2PT, "feature-bitmap-drop") \
103 _(EFP_FILTER, "l2-efp-filter") \
104 _(IPIW, "feature-bitmap-drop") \
105 _(STP_BLOCKED, "feature-bitmap-drop") \
106 _(LINESTATUS_DOWN, "feature-bitmap-drop") \
Dave Barachb84a3e52016-08-30 17:01:52 -0400107 _(OUTPUT_CLASSIFY, "l2-output-classify") \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 _(XCRW, "l2-xcrw")
109
Dave Barach97d8dc22016-08-15 15:31:15 -0400110/* Feature bitmap positions */
111typedef enum
112{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113#define _(sym,str) L2OUTPUT_FEAT_##sym##_BIT,
114 foreach_l2output_feat
115#undef _
Dave Barach97d8dc22016-08-15 15:31:15 -0400116 L2OUTPUT_N_FEAT,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117} l2output_feat_t;
118
Dave Barach97d8dc22016-08-15 15:31:15 -0400119/* Feature bit masks */
120typedef enum
121{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122#define _(sym,str) L2OUTPUT_FEAT_##sym = (1<<L2OUTPUT_FEAT_##sym##_BIT),
123 foreach_l2output_feat
124#undef _
125} l2output_feat_masks_t;
Dave Barach97d8dc22016-08-15 15:31:15 -0400126
John Lo3ef822e2016-06-07 09:14:07 -0400127#define foreach_l2output_error \
128_(L2OUTPUT, "L2 output packets") \
129_(EFP_DROP, "L2 EFP filter pre-rewrite drops") \
130_(VTR_DROP, "L2 output tag rewrite drops") \
131_(SHG_DROP, "L2 split horizon drops") \
Damjan Marionb1136582016-09-22 16:37:29 +0200132_(DROP, "L2 output drops") \
133_(MAPPING_DROP, "L2 Output interface mapping in progress")
John Lo3ef822e2016-06-07 09:14:07 -0400134
Dave Barach97d8dc22016-08-15 15:31:15 -0400135typedef enum
136{
John Lo3ef822e2016-06-07 09:14:07 -0400137 L2OUTPUT_NEXT_DROP,
John Lo0fc9bc12016-10-27 11:17:02 -0400138 L2OUTPUT_NEXT_BAD_INTF,
John Lo3ef822e2016-06-07 09:14:07 -0400139 L2OUTPUT_N_NEXT,
140} l2output_next_t;
141
Dave Barach97d8dc22016-08-15 15:31:15 -0400142typedef enum
143{
John Lo3ef822e2016-06-07 09:14:07 -0400144#define _(sym,str) L2OUTPUT_ERROR_##sym,
145 foreach_l2output_error
146#undef _
Dave Barach97d8dc22016-08-15 15:31:15 -0400147 L2OUTPUT_N_ERROR,
John Lo3ef822e2016-06-07 09:14:07 -0400148} l2output_error_t;
149
Dave Barach97d8dc22016-08-15 15:31:15 -0400150/* Return an array of strings containing graph node names of each feature */
151char **l2output_get_feat_names (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
153
Dave Barach97d8dc22016-08-15 15:31:15 -0400154/**
155 * The next set of functions is for use by output feature graph nodes.
156 * When the last bit has been cleared from the output feature bitmap,
157 * the next node is the output graph node for the TX sw_if_index.
158 * These functions help the feature nodes get that node index.
159 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160
Dave Barach97d8dc22016-08-15 15:31:15 -0400161/* Create a mapping to the output graph node for the given sw_if_index */
162u32 l2output_create_output_node_mapping (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 node_index, /* index of current node */
163 u32 * output_node_index_vec,
164 u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165
Dave Barach97d8dc22016-08-15 15:31:15 -0400166/* Initialize the next node mapping table */
167always_inline void
168l2output_init_output_node_vec (u32 ** output_node_index_vec)
169{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Dave Barach97d8dc22016-08-15 15:31:15 -0400171 /*
172 * Size it at 100 sw_if_indexes initially
173 * Uninitialized mappings are set to ~0
174 */
175 vec_validate_init_empty (*output_node_index_vec, 100, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700176}
177
178
Dave Barach97d8dc22016-08-15 15:31:15 -0400179/**
180 * Get a mapping from the output node mapping table,
181 * creating the entry if necessary.
182 */
183always_inline u32
184l2output_get_output_node (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 node_index, /* index of current node */
185 u32 sw_if_index, u32 ** output_node_index_vec) /* may be updated */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186{
Dave Barach97d8dc22016-08-15 15:31:15 -0400187 u32 next; /* index of next graph node */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188
Dave Barach97d8dc22016-08-15 15:31:15 -0400189 /* Insure the vector is big enough */
190 vec_validate_init_empty (*output_node_index_vec, sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Dave Barach97d8dc22016-08-15 15:31:15 -0400192 /* Get the mapping for the sw_if_index */
193 next = vec_elt (*output_node_index_vec, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194
Dave Barach97d8dc22016-08-15 15:31:15 -0400195 if (next == ~0)
196 {
197 /* Mapping doesn't exist so create it */
198 next = l2output_create_output_node_mapping (vlib_main,
199 vnet_main,
200 node_index,
201 *output_node_index_vec,
202 sw_if_index);
203 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204
205 return next;
206}
207
208
Dave Barach97d8dc22016-08-15 15:31:15 -0400209/** Determine the next L2 node based on the output feature bitmap */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210always_inline void
211l2_output_dispatch (vlib_main_t * vlib_main,
Dave Barach97d8dc22016-08-15 15:31:15 -0400212 vnet_main_t * vnet_main,
213 vlib_node_runtime_t * node,
214 u32 node_index,
215 u32 * cached_sw_if_index,
216 u32 * cached_next_index,
217 l2_output_next_nodes_st * next_nodes,
218 vlib_buffer_t * b0,
219 u32 sw_if_index, u32 feature_bitmap, u32 * next0)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220{
Andrew Yourtchenkocc405652017-03-03 13:11:30 +0000221 /*
222 * The output feature bitmap always have at least the output feature bit set
223 * for a normal L2 interface (or all 0's if the interface is changed from L2
224 * to L3 mode). So if next_nodes specified is that from the l2-output node and
225 * the bitmap is all clear except output feature bit, we know there is no more
226 * feature and will fall through to output packet. If next_nodes is from a L2
227 * output feature node (and not l2-output), we always want to get the node for
228 * the next L2 output feature, including the last feature being interface-
229 * output node to output packet.
230 */
231 if ((next_nodes != &l2output_main.next_nodes)
232 || ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0))
Dave Barach97d8dc22016-08-15 15:31:15 -0400233 {
234 /* There are some features to execute */
Andrew Yourtchenkocc405652017-03-03 13:11:30 +0000235 ASSERT (feature_bitmap != 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700236
Dave Barach97d8dc22016-08-15 15:31:15 -0400237 /* Save bitmap for the next feature graph nodes */
238 vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700239
Dave Barach97d8dc22016-08-15 15:31:15 -0400240 /* Determine the next node */
241 *next0 =
242 feat_bitmap_get_next_node_index (next_nodes->feat_next_node_index,
243 feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700244 }
Dave Barach97d8dc22016-08-15 15:31:15 -0400245 else
246 {
247 /*
248 * There are no features. Send packet to TX node for sw_if_index0
249 * This is a little tricky in that the output interface next node indexes
250 * are not precomputed at init time.
251 */
252
253 if (sw_if_index == *cached_sw_if_index)
254 {
255 /* We hit in the one-entry cache. Use it. */
256 *next0 = *cached_next_index;
257 }
258 else
259 {
260 /* Look up the output TX node */
261 *next0 = l2output_get_output_node (vlib_main,
262 vnet_main,
263 node_index,
264 sw_if_index,
265 &next_nodes->output_node_index_vec);
266
Damjan Marionb1136582016-09-22 16:37:29 +0200267 if (*next0 == L2OUTPUT_NEXT_DROP)
268 {
269 vnet_hw_interface_t *hw0;
270 hw0 = vnet_get_sup_hw_interface (vnet_main, sw_if_index);
271
272 if (hw0->flags & VNET_HW_INTERFACE_FLAG_L2OUTPUT_MAPPED)
273 b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP];
274 }
275
Dave Barach97d8dc22016-08-15 15:31:15 -0400276 /* Update the one-entry cache */
277 *cached_sw_if_index = sw_if_index;
278 *cached_next_index = *next0;
279 }
280 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281}
282
Dave Barach97d8dc22016-08-15 15:31:15 -0400283/** Get a pointer to the config for the given interface */
284l2_output_config_t *l2output_intf_config (u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285
Dave Barach97d8dc22016-08-15 15:31:15 -0400286/** Enable (or disable) the feature in the bitmap for the given interface */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287void l2output_intf_bitmap_enable (u32 sw_if_index,
Dave Barach97d8dc22016-08-15 15:31:15 -0400288 u32 feature_bitmap, u32 enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289
290#endif
Dave Barach97d8dc22016-08-15 15:31:15 -0400291
292/*
293 * fd.io coding-style-patch-verification: ON
294 *
295 * Local Variables:
296 * eval: (c-set-style "gnu")
297 * End:
298 */