Improve L2 Input/Output Feature Infrastructure and Usage
[vpp.git] / src / vnet / l2 / l2_output.h
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
31   u32 feature_bitmap;
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    */
38   vtr_config_t input_vtr;
39   vtr_config_t output_vtr;
40   ptr_config_t input_pbb_vtr;
41   ptr_config_t output_pbb_vtr;
42
43   /* some of these flags may get integrated into the feature bitmap */
44   u8 fwd_enable;
45   u8 flood_enable;
46
47   /* split horizon group */
48   u8 shg;
49
50   /* flag for output vtr operation */
51   u8 out_vtr_flag;
52
53 } l2_output_config_t;
54
55 typedef struct
56 {
57   /*
58    * vector of output next node index, indexed by sw_if_index.
59    * used when all output features have been executed and the
60    * next nodes are the interface output nodes.
61    */
62   u32 *output_node_index_vec;
63
64   /*
65    * array of next node index for each output feature, indexed
66    * by l2output_feat_t. Used to determine next feature node.
67    */
68   u32 l2_out_feat_next[32];
69
70   /* config vector indexed by sw_if_index */
71   l2_output_config_t *configs;
72
73   /* Convenience variables */
74   vlib_main_t *vlib_main;
75   vnet_main_t *vnet_main;
76 } l2output_main_t;
77
78 l2output_main_t l2output_main;
79
80 /* L2 output features */
81
82 /* Mappings from feature ID to graph node name */
83 #define foreach_l2output_feat \
84  _(OUTPUT,            "interface-output")           \
85  _(SPAN,              "feature-bitmap-drop")        \
86  _(CFM,               "feature-bitmap-drop")        \
87  _(QOS,               "feature-bitmap-drop")        \
88  _(ACL,               "l2-output-acl")              \
89  _(L2PT,              "feature-bitmap-drop")        \
90  _(EFP_FILTER,        "l2-efp-filter")              \
91  _(IPIW,              "feature-bitmap-drop")        \
92  _(STP_BLOCKED,       "feature-bitmap-drop")        \
93  _(LINESTATUS_DOWN,   "feature-bitmap-drop")        \
94  _(OUTPUT_CLASSIFY,   "l2-output-classify")         \
95  _(XCRW,              "l2-xcrw")
96
97 /* Feature bitmap positions */
98 typedef enum
99 {
100 #define _(sym,str) L2OUTPUT_FEAT_##sym##_BIT,
101   foreach_l2output_feat
102 #undef _
103     L2OUTPUT_N_FEAT,
104 } l2output_feat_t;
105
106 /* Feature bit masks */
107 typedef enum
108 {
109 #define _(sym,str) L2OUTPUT_FEAT_##sym = (1<<L2OUTPUT_FEAT_##sym##_BIT),
110   foreach_l2output_feat
111 #undef _
112 } l2output_feat_masks_t;
113
114 #define foreach_l2output_error                          \
115 _(L2OUTPUT,     "L2 output packets")                    \
116 _(EFP_DROP,     "L2 EFP filter pre-rewrite drops")      \
117 _(VTR_DROP,     "L2 output tag rewrite drops")          \
118 _(SHG_DROP,     "L2 split horizon drops")               \
119 _(DROP,         "L2 output drops")                      \
120 _(MAPPING_DROP, "L2 Output interface not valid")
121
122 typedef enum
123 {
124   L2OUTPUT_NEXT_DROP,
125   L2OUTPUT_NEXT_BAD_INTF,
126   L2OUTPUT_N_NEXT,
127 } l2output_next_t;
128
129 typedef enum
130 {
131 #define _(sym,str) L2OUTPUT_ERROR_##sym,
132   foreach_l2output_error
133 #undef _
134     L2OUTPUT_N_ERROR,
135 } l2output_error_t;
136
137 /* Return an array of strings containing graph node names of each feature */
138 char **l2output_get_feat_names (void);
139
140
141 /**
142  * The next set of functions is for use by output feature graph nodes.
143  * When the last bit has been cleared from the output feature bitmap,
144  * the next node is the output graph node for the TX sw_if_index.
145  * These functions help the feature nodes get that node index.
146  */
147
148 /* Create a mapping to the output graph node for the given sw_if_index */
149 void l2output_create_output_node_mapping (vlib_main_t * vlib_main,
150                                           vnet_main_t * vnet_main,
151                                           u32 sw_if_index);
152
153 /** Get a pointer to the config for the given interface */
154 l2_output_config_t *l2output_intf_config (u32 sw_if_index);
155
156 /** Enable (or disable) the feature in the bitmap for the given interface */
157 void l2output_intf_bitmap_enable (u32 sw_if_index,
158                                   u32 feature_bitmap, u32 enable);
159
160 #endif
161
162 /*
163  * fd.io coding-style-patch-verification: ON
164  *
165  * Local Variables:
166  * eval: (c-set-style "gnu")
167  * End:
168  */