FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
l2_output.h
Go to the documentation of this file.
1 /*
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 
27 /* The L2 output feature configuration, a per-interface struct */
28 typedef struct
29 {
30 
32 
33  /*
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  */
42 
43  /* some of these flags may get integrated into the feature bitmap */
46 
47  /* split horizon group */
49 
50  /* flag for output vtr operation */
52 
54 
55 
56 /*
57  * The set of next nodes for features and interface output.
58  * Each output feature node should include this.
59  */
60 typedef 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  */
68 
69  /*
70  * array of next node index for each output feature, indexed
71  * by l2output_feat_t. Used to determine next feature node.
72  */
73  u32 feat_next_node_index[32];
74 
76 
77 
78 typedef struct
79 {
80  /* Next nodes for features and output interfaces */
82 
83  /* config vector indexed by sw_if_index */
85 
86  /* Convenience variables */
90 
92 
93 /* L2 output features */
94 
95 /* Mappings from feature ID to graph node name */
96 #define foreach_l2output_feat \
97  _(OUTPUT, "interface-output") \
98  _(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") \
107  _(OUTPUT_CLASSIFY, "l2-output-classify") \
108  _(XCRW, "l2-xcrw")
109 
110 /* Feature bitmap positions */
111 typedef enum
112 {
113 #define _(sym,str) L2OUTPUT_FEAT_##sym##_BIT,
115 #undef _
118 
119 /* Feature bit masks */
120 typedef enum
121 {
122 #define _(sym,str) L2OUTPUT_FEAT_##sym = (1<<L2OUTPUT_FEAT_##sym##_BIT),
124 #undef _
126 
127 #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") \
132 _(DROP, "L2 output drops") \
133 _(MAPPING_DROP, "L2 Output interface not valid")
134 
135 typedef enum
136 {
141 
142 typedef enum
143 {
144 #define _(sym,str) L2OUTPUT_ERROR_##sym,
146 #undef _
149 
150 /* Return an array of strings containing graph node names of each feature */
151 char **l2output_get_feat_names (void);
152 
153 
154 /**
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  */
160 
161 /* Create a mapping to the output graph node for the given sw_if_index */
164  u32 sw_if_index);
165 
166 /** Determine the next L2 node based on the output feature bitmap */
167 always_inline void
170  vlib_node_runtime_t * node,
171  u32 node_index,
172  u32 * cached_sw_if_index,
173  u32 * cached_next_index,
174  l2_output_next_nodes_st * next_nodes,
175  vlib_buffer_t * b0,
176  u32 sw_if_index, u32 feature_bitmap, u32 * next0)
177 {
178  /*
179  * The output feature bitmap always have at least the output feature bit set
180  * for a normal L2 interface (or all 0's if the interface is changed from L2
181  * to L3 mode). So if next_nodes specified is that from the l2-output node and
182  * the bitmap is all clear except output feature bit, we know there is no more
183  * feature and will fall through to output packet. If next_nodes is from a L2
184  * output feature node (and not l2-output), we always want to get the node for
185  * the next L2 output feature, including the last feature being interface-
186  * output node to output packet.
187  */
188  if ((next_nodes != &l2output_main.next_nodes)
189  || ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0))
190  {
191  /* There are some features to execute */
192  ASSERT (feature_bitmap != 0);
193 
194  /* Save bitmap for the next feature graph nodes */
195  vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap;
196 
197  /* Determine the next node */
198  *next0 =
200  feature_bitmap);
201  }
202  else
203  {
204  /*
205  * There are no features. Send packet to TX node for sw_if_index0
206  * This is a little tricky in that the output interface next node indexes
207  * are not precomputed at init time.
208  */
209 
210  if (sw_if_index == *cached_sw_if_index)
211  {
212  /* We hit in the one-entry cache. Use it. */
213  *next0 = *cached_next_index;
214  }
215  else
216  {
217  /* Look up the output TX node for the sw_if_index */
218  *next0 = vec_elt (l2output_main.next_nodes.output_node_index_vec,
219  sw_if_index);
220 
221  if (*next0 == L2OUTPUT_NEXT_DROP)
222  b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP];
223 
224  /* Update the one-entry cache */
225  *cached_sw_if_index = sw_if_index;
226  *cached_next_index = *next0;
227  }
228  }
229 }
230 
231 /** Get a pointer to the config for the given interface */
233 
234 /** Enable (or disable) the feature in the bitmap for the given interface */
235 void l2output_intf_bitmap_enable (u32 sw_if_index,
236  u32 feature_bitmap, u32 enable);
237 
238 #endif
239 
240 /*
241  * fd.io coding-style-patch-verification: ON
242  *
243  * Local Variables:
244  * eval: (c-set-style "gnu")
245  * End:
246  */
#define foreach_l2output_error
Definition: l2_output.h:127
char ** l2output_get_feat_names(void)
Definition: l2_output.c:38
l2output_next_t
Definition: l2_output.h:135
void l2output_intf_bitmap_enable(u32 sw_if_index, u32 feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_output.c:639
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:419
l2_output_next_nodes_st next_nodes
Definition: l2_output.h:81
Per-interface vlan tag rewrite configuration There will be one instance of this struct for each sw_if...
Definition: l2_vtr.h:45
#define always_inline
Definition: clib.h:84
ptr_config_t output_pbb_vtr
Definition: l2_output.h:41
u32 feat_next_node_index[32]
Definition: l2_output.h:73
void l2output_create_output_node_mapping(vlib_main_t *vlib_main, vnet_main_t *vnet_main, u32 sw_if_index)
The next set of functions is for use by output feature graph nodes.
Definition: l2_output.c:615
vtr_config_t input_vtr
Definition: l2_output.h:38
l2output_main_t l2output_main
Definition: l2_output.h:91
vnet_main_t vnet_main
Definition: misc.c:43
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
Definition: feat_bitmap.h:79
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:113
vlib_main_t * vlib_main
Definition: l2_output.h:87
#define foreach_l2output_feat
Definition: l2_output.h:96
vtr_config_t output_vtr
Definition: l2_output.h:39
int vlib_main(vlib_main_t *volatile vm, unformat_input_t *input)
Definition: main.c:1692
#define ASSERT(truth)
l2output_feat_masks_t
Definition: l2_output.h:120
unsigned int u32
Definition: types.h:88
#define vec_elt(v, i)
Get vector value at index i.
ptr_config_t input_pbb_vtr
Definition: l2_output.h:40
unsigned char u8
Definition: types.h:56
l2_output_config_t * l2output_intf_config(u32 sw_if_index)
Get a pointer to the config for the given interface.
Definition: l2_output.c:629
l2output_feat_t
Definition: l2_output.h:111
l2_output_config_t * configs
Definition: l2_output.h:84
#define vnet_buffer(b)
Definition: buffer.h:304
static void l2_output_dispatch(vlib_main_t *vlib_main, vnet_main_t *vnet_main, vlib_node_runtime_t *node, u32 node_index, u32 *cached_sw_if_index, u32 *cached_next_index, l2_output_next_nodes_st *next_nodes, vlib_buffer_t *b0, u32 sw_if_index, u32 feature_bitmap, u32 *next0)
Determine the next L2 node based on the output feature bitmap.
Definition: l2_output.h:168
l2output_error_t
Definition: l2_output.h:142
vnet_main_t * vnet_main
Definition: l2_output.h:88