Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 27 | /* The L2 output feature configuration, a per-interface struct */ |
| 28 | typedef struct |
| 29 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | |
| 31 | u32 feature_bitmap; |
| 32 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 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 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | vtr_config_t input_vtr; |
| 39 | vtr_config_t output_vtr; |
Pavel Kotucek | 95300d1 | 2016-08-26 16:11:36 +0200 | [diff] [blame] | 40 | ptr_config_t input_pbb_vtr; |
| 41 | ptr_config_t output_pbb_vtr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 43 | /* some of these flags may get integrated into the feature bitmap */ |
| 44 | u8 fwd_enable; |
| 45 | u8 flood_enable; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 47 | /* split horizon group */ |
| 48 | u8 shg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | |
Pavel Kotucek | 95300d1 | 2016-08-26 16:11:36 +0200 | [diff] [blame] | 50 | /* flag for output vtr operation */ |
| 51 | u8 out_vtr_flag; |
| 52 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | } l2_output_config_t; |
| 54 | |
| 55 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 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 | */ |
| 67 | u32 *output_node_index_vec; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 69 | /* |
| 70 | * array of next node index for each output feature, indexed |
| 71 | * by l2output_feat_t. Used to determine next feature node. |
| 72 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | u32 feat_next_node_index[32]; |
| 74 | |
| 75 | } l2_output_next_nodes_st; |
| 76 | |
| 77 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 78 | typedef struct |
| 79 | { |
| 80 | /* Next nodes for features and output interfaces */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | 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 Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 87 | vlib_main_t *vlib_main; |
| 88 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | } l2output_main_t; |
| 90 | |
| 91 | l2output_main_t l2output_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 93 | /* L2 output features */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 95 | /* Mappings from feature ID to graph node name */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | #define foreach_l2output_feat \ |
| 97 | _(SPAN, "feature-bitmap-drop") \ |
| 98 | _(CFM, "feature-bitmap-drop") \ |
| 99 | _(QOS, "feature-bitmap-drop") \ |
| 100 | _(ACL, "l2-output-acl") \ |
| 101 | _(L2PT, "feature-bitmap-drop") \ |
| 102 | _(EFP_FILTER, "l2-efp-filter") \ |
| 103 | _(IPIW, "feature-bitmap-drop") \ |
| 104 | _(STP_BLOCKED, "feature-bitmap-drop") \ |
| 105 | _(LINESTATUS_DOWN, "feature-bitmap-drop") \ |
Dave Barach | b84a3e5 | 2016-08-30 17:01:52 -0400 | [diff] [blame] | 106 | _(OUTPUT_CLASSIFY, "l2-output-classify") \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | _(XCRW, "l2-xcrw") |
| 108 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 109 | /* Feature bitmap positions */ |
| 110 | typedef enum |
| 111 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | #define _(sym,str) L2OUTPUT_FEAT_##sym##_BIT, |
| 113 | foreach_l2output_feat |
| 114 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 115 | L2OUTPUT_N_FEAT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | } l2output_feat_t; |
| 117 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 118 | /* Feature bit masks */ |
| 119 | typedef enum |
| 120 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | #define _(sym,str) L2OUTPUT_FEAT_##sym = (1<<L2OUTPUT_FEAT_##sym##_BIT), |
| 122 | foreach_l2output_feat |
| 123 | #undef _ |
| 124 | } l2output_feat_masks_t; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 125 | |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 126 | #define foreach_l2output_error \ |
| 127 | _(L2OUTPUT, "L2 output packets") \ |
| 128 | _(EFP_DROP, "L2 EFP filter pre-rewrite drops") \ |
| 129 | _(VTR_DROP, "L2 output tag rewrite drops") \ |
| 130 | _(SHG_DROP, "L2 split horizon drops") \ |
Damjan Marion | b113658 | 2016-09-22 16:37:29 +0200 | [diff] [blame] | 131 | _(DROP, "L2 output drops") \ |
| 132 | _(MAPPING_DROP, "L2 Output interface mapping in progress") |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 133 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 134 | typedef enum |
| 135 | { |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 136 | L2OUTPUT_NEXT_DROP, |
John Lo | 0fc9bc1 | 2016-10-27 11:17:02 -0400 | [diff] [blame] | 137 | L2OUTPUT_NEXT_BAD_INTF, |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 138 | L2OUTPUT_N_NEXT, |
| 139 | } l2output_next_t; |
| 140 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 141 | typedef enum |
| 142 | { |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 143 | #define _(sym,str) L2OUTPUT_ERROR_##sym, |
| 144 | foreach_l2output_error |
| 145 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 146 | L2OUTPUT_N_ERROR, |
John Lo | 3ef822e | 2016-06-07 09:14:07 -0400 | [diff] [blame] | 147 | } l2output_error_t; |
| 148 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 149 | /* Return an array of strings containing graph node names of each feature */ |
| 150 | char **l2output_get_feat_names (void); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | |
| 152 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 153 | /** |
| 154 | * The next set of functions is for use by output feature graph nodes. |
| 155 | * When the last bit has been cleared from the output feature bitmap, |
| 156 | * the next node is the output graph node for the TX sw_if_index. |
| 157 | * These functions help the feature nodes get that node index. |
| 158 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 160 | /* Create a mapping to the output graph node for the given sw_if_index */ |
| 161 | u32 l2output_create_output_node_mapping (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 node_index, /* index of current node */ |
| 162 | u32 * output_node_index_vec, |
| 163 | u32 sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 165 | /* Initialize the next node mapping table */ |
| 166 | always_inline void |
| 167 | l2output_init_output_node_vec (u32 ** output_node_index_vec) |
| 168 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 170 | /* |
| 171 | * Size it at 100 sw_if_indexes initially |
| 172 | * Uninitialized mappings are set to ~0 |
| 173 | */ |
| 174 | vec_validate_init_empty (*output_node_index_vec, 100, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 178 | /** |
| 179 | * Get a mapping from the output node mapping table, |
| 180 | * creating the entry if necessary. |
| 181 | */ |
| 182 | always_inline u32 |
| 183 | l2output_get_output_node (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 node_index, /* index of current node */ |
| 184 | u32 sw_if_index, u32 ** output_node_index_vec) /* may be updated */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 186 | u32 next; /* index of next graph node */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 188 | /* Insure the vector is big enough */ |
| 189 | vec_validate_init_empty (*output_node_index_vec, sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 191 | /* Get the mapping for the sw_if_index */ |
| 192 | next = vec_elt (*output_node_index_vec, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 194 | if (next == ~0) |
| 195 | { |
| 196 | /* Mapping doesn't exist so create it */ |
| 197 | next = l2output_create_output_node_mapping (vlib_main, |
| 198 | vnet_main, |
| 199 | node_index, |
| 200 | *output_node_index_vec, |
| 201 | sw_if_index); |
| 202 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
| 204 | return next; |
| 205 | } |
| 206 | |
| 207 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 208 | /** Determine the next L2 node based on the output feature bitmap */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | always_inline void |
| 210 | l2_output_dispatch (vlib_main_t * vlib_main, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 211 | vnet_main_t * vnet_main, |
| 212 | vlib_node_runtime_t * node, |
| 213 | u32 node_index, |
| 214 | u32 * cached_sw_if_index, |
| 215 | u32 * cached_next_index, |
| 216 | l2_output_next_nodes_st * next_nodes, |
| 217 | vlib_buffer_t * b0, |
| 218 | u32 sw_if_index, u32 feature_bitmap, u32 * next0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 220 | if (feature_bitmap) |
| 221 | { |
| 222 | /* There are some features to execute */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 224 | /* Save bitmap for the next feature graph nodes */ |
| 225 | vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 227 | /* Determine the next node */ |
| 228 | *next0 = |
| 229 | feat_bitmap_get_next_node_index (next_nodes->feat_next_node_index, |
| 230 | feature_bitmap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 232 | else |
| 233 | { |
| 234 | /* |
| 235 | * There are no features. Send packet to TX node for sw_if_index0 |
| 236 | * This is a little tricky in that the output interface next node indexes |
| 237 | * are not precomputed at init time. |
| 238 | */ |
| 239 | |
| 240 | if (sw_if_index == *cached_sw_if_index) |
| 241 | { |
| 242 | /* We hit in the one-entry cache. Use it. */ |
| 243 | *next0 = *cached_next_index; |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | /* Look up the output TX node */ |
| 248 | *next0 = l2output_get_output_node (vlib_main, |
| 249 | vnet_main, |
| 250 | node_index, |
| 251 | sw_if_index, |
| 252 | &next_nodes->output_node_index_vec); |
| 253 | |
Damjan Marion | b113658 | 2016-09-22 16:37:29 +0200 | [diff] [blame] | 254 | if (*next0 == L2OUTPUT_NEXT_DROP) |
| 255 | { |
| 256 | vnet_hw_interface_t *hw0; |
| 257 | hw0 = vnet_get_sup_hw_interface (vnet_main, sw_if_index); |
| 258 | |
| 259 | if (hw0->flags & VNET_HW_INTERFACE_FLAG_L2OUTPUT_MAPPED) |
| 260 | b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP]; |
| 261 | } |
| 262 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 263 | /* Update the one-entry cache */ |
| 264 | *cached_sw_if_index = sw_if_index; |
| 265 | *cached_next_index = *next0; |
| 266 | } |
| 267 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 270 | /** Get a pointer to the config for the given interface */ |
| 271 | l2_output_config_t *l2output_intf_config (u32 sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 273 | /** Enable (or disable) the feature in the bitmap for the given interface */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | void l2output_intf_bitmap_enable (u32 sw_if_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 275 | u32 feature_bitmap, u32 enable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
| 277 | #endif |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * fd.io coding-style-patch-verification: ON |
| 281 | * |
| 282 | * Local Variables: |
| 283 | * eval: (c-set-style "gnu") |
| 284 | * End: |
| 285 | */ |