2 * feat_bitmap.h: bitmap for managing feature invocation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef included_vnet_l2_feat_bitmap_h
19 #define included_vnet_l2_feat_bitmap_h
21 #include <vlib/vlib.h>
22 #include <vnet/vnet.h>
25 * The feature bitmap is a way of organizing input and output feature graph nodes.
26 * The set of features to be executed are arranged in a bitmap with one bit per
27 * feature and each bit positioned in the same order that the features should be
28 * executed. Features can be dynamically removed from the set by masking off their
29 * corresponding bits. The bitmap is stored in packet context. Each feature clears
30 * its bit and then calls feat_bitmap_get_next_node_index() to go to the next
35 /* 32 features in a u32 bitmap */
39 Initialize the feature next-node indexes of a graph node.
40 Should be called by the init function of each feature graph node.
43 feat_bitmap_init_next_nodes (vlib_main_t * vm, u32 node_index, /* the current graph node index */
44 u32 num_features, /* number of entries in feat_names */
45 char **feat_names, /* array of feature graph node names */
46 u32 * next_nodes) /* array of 32 next indexes to init */
50 ASSERT (num_features <= FEAT_MAX);
52 for (idx = 0; idx < num_features; idx++)
54 if (vlib_get_node_by_name (vm, (u8 *) feat_names[idx]))
57 vlib_node_add_named_next (vm, node_index, feat_names[idx]);
60 { // Node may be in plugin which is not installed, use drop node
62 vlib_node_add_named_next (vm, node_index, "feature-bitmap-drop");
66 /* All unassigned bits go to the drop node */
67 for (; idx < FEAT_MAX; idx++)
69 next_nodes[idx] = vlib_node_add_named_next (vm, node_index,
70 "feature-bitmap-drop");
75 Return the graph node index for the feature corresponding to the
76 first set bit in the bitmap.
79 feat_bitmap_get_next_node_index (u32 * next_nodes, u32 bitmap)
83 count_leading_zeros (first_bit, bitmap);
84 first_bit = uword_bits - 1 - first_bit;
85 return next_nodes[first_bit];
89 Return the graph node index for the feature corresponding to the next
90 set bit after clearing the current feature bit in the feature_bitmap
91 of the current packet.
94 vnet_l2_feature_next (vlib_buffer_t * b, u32 * next_nodes, u32 feat_bit)
96 vnet_buffer (b)->l2.feature_bitmap &= ~feat_bit;
97 u32 fb = vnet_buffer (b)->l2.feature_bitmap;
99 return feat_bitmap_get_next_node_index (next_nodes, fb);
102 #endif /* included_vnet_l2_feat_bitmap_h */
105 * fd.io coding-style-patch-verification: ON
108 * eval: (c-set-style "gnu")