fix declaration of symbol of different size
[vpp.git] / vnet / 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   u32 feature_bitmap;
31
32   // vlan tag rewrite for ingress and egress
33   // ingress vtr is located here because the same config data is used for
34   // the egress EFP filter check
35   vtr_config_t input_vtr;
36   vtr_config_t output_vtr;
37
38   // some of these flags may get integrated into the feature bitmap
39   u8  fwd_enable;    
40   u8  flood_enable;
41
42   // split horizon group
43   u8  shg;
44
45 } l2_output_config_t;
46
47
48 // The set of next nodes for features and interface output.
49 // Each output feature node should include this.
50 typedef struct {
51   // vector of output next node index, indexed by sw_if_index.
52   // used when all output features have been executed and the
53   // next nodes are the interface output nodes.
54   u32 * output_node_index_vec;
55
56   // array of next node index for each output feature, indexed
57   // by l2output_feat_t. Used to determine next feature node.
58   u32 feat_next_node_index[32];
59
60 } l2_output_next_nodes_st;
61
62
63 typedef struct {
64   // Next nodes for features and output interfaces
65   l2_output_next_nodes_st next_nodes;
66
67   /* config vector indexed by sw_if_index */
68   l2_output_config_t *configs;
69
70   /* Convenience variables */
71   vlib_main_t * vlib_main;
72   vnet_main_t * vnet_main;
73 } l2output_main_t;
74
75 l2output_main_t l2output_main;
76
77 // L2 output features
78
79 // Mappings from feature ID to graph node name
80 #define foreach_l2output_feat \
81  _(SPAN,              "feature-bitmap-drop")        \
82  _(CFM,               "feature-bitmap-drop")        \
83  _(QOS,               "feature-bitmap-drop")        \
84  _(ACL,               "l2-output-acl")              \
85  _(L2PT,              "feature-bitmap-drop")        \
86  _(EFP_FILTER,        "l2-efp-filter")              \
87  _(IPIW,              "feature-bitmap-drop")        \
88  _(STP_BLOCKED,       "feature-bitmap-drop")        \
89  _(LINESTATUS_DOWN,   "feature-bitmap-drop")        \
90  _(XCRW,              "l2-xcrw")
91
92 // Feature bitmap positions
93 typedef enum {
94 #define _(sym,str) L2OUTPUT_FEAT_##sym##_BIT,
95   foreach_l2output_feat
96 #undef _
97   L2OUTPUT_N_FEAT,
98 } l2output_feat_t;
99
100 // Feature bit masks
101 typedef enum {
102 #define _(sym,str) L2OUTPUT_FEAT_##sym = (1<<L2OUTPUT_FEAT_##sym##_BIT),
103   foreach_l2output_feat
104 #undef _
105 } l2output_feat_masks_t;
106            
107 // Return an array of strings containing graph node names of each feature
108 char **l2output_get_feat_names(void);
109
110
111 // The next set of functions is for use by output feature graph nodes.
112 // When the last bit has been cleared from the output feature bitmap,
113 // the next node is the output graph node for the TX sw_if_index.
114 // These functions help the feature nodes get that node index.
115
116 // Create a mapping to the output graph node for the given sw_if_index
117 u32 l2output_create_output_node_mapping (
118             vlib_main_t * vlib_main,
119             vnet_main_t * vnet_main,
120             u32           node_index,  // index of current node
121             u32         * output_node_index_vec,
122             u32           sw_if_index);
123
124 // Initialize the next node mapping table
125 always_inline
126 void l2output_init_output_node_vec (u32 **output_node_index_vec) {
127
128   // Size it at 100 sw_if_indexes initially
129   // Uninitialized mappings are set to ~0
130   vec_validate_init_empty(*output_node_index_vec, 100, ~0);
131 }
132
133
134 // Get a mapping from the output node mapping table,
135 // creating the entry if necessary.
136 always_inline
137 u32 l2output_get_output_node (vlib_main_t * vlib_main,
138                               vnet_main_t * vnet_main,
139                               u32           node_index,  // index of current node
140                               u32           sw_if_index,
141                               u32         ** output_node_index_vec)  // may be updated
142 {
143   u32 next;  // index of next graph node
144
145   // Insure the vector is big enough
146   vec_validate_init_empty(*output_node_index_vec, sw_if_index, ~0);
147
148   // Get the mapping for the sw_if_index
149   next = vec_elt(*output_node_index_vec, sw_if_index);
150
151   if (next == ~0) {
152     // Mapping doesn't exist so create it
153     next = l2output_create_output_node_mapping (vlib_main,
154                                                 vnet_main,
155                                                 node_index,
156                                                 *output_node_index_vec,
157                                                 sw_if_index);
158   } 
159
160   return next;
161 }
162
163
164 // Determine the next L2 node based on the output feature bitmap
165 always_inline void
166 l2_output_dispatch (vlib_main_t * vlib_main,
167                     vnet_main_t * vnet_main,
168                     vlib_node_runtime_t * node,
169                     u32 node_index,
170                     u32 * cached_sw_if_index,
171                     u32 * cached_next_index,
172                     l2_output_next_nodes_st *next_nodes,
173                     vlib_buffer_t * b0,
174                     u32 sw_if_index,
175                     u32 feature_bitmap,
176                     u32 *next0)
177 {
178   if (feature_bitmap) {
179     // There are some features to execute
180
181     // Save bitmap for the next feature graph nodes
182     vnet_buffer(b0)->l2.feature_bitmap = feature_bitmap;
183
184     // Determine the next node
185     *next0 = feat_bitmap_get_next_node_index(next_nodes->feat_next_node_index,
186                                              feature_bitmap);
187   } else {
188     // There are no features. Send packet to TX node for sw_if_index0
189     // This is a little tricky in that the output interface next node indexes
190     // are not precomputed at init time.
191
192     if (sw_if_index == *cached_sw_if_index) {
193       // We hit in the one-entry cache. Use it.
194       *next0 = *cached_next_index;
195     } else {
196       // Look up the output TX node
197       *next0 = l2output_get_output_node(vlib_main,
198                                         vnet_main,
199                                         node_index,
200                                         sw_if_index,
201                                         &next_nodes->output_node_index_vec);
202
203       // Update the one-entry cache
204       *cached_sw_if_index = sw_if_index;
205       *cached_next_index = *next0;
206     }
207   }
208 }
209
210 // Get a pointer to the config for the given interface
211 l2_output_config_t * l2output_intf_config (u32 sw_if_index);
212
213 // Enable (or disable) the feature in the bitmap for the given interface
214 void l2output_intf_bitmap_enable (u32 sw_if_index,
215                                   u32 feature_bitmap,
216                                   u32 enable);
217
218 #endif