FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
feat_bitmap.c
Go to the documentation of this file.
1 /*
2  * feat_bitmap.c: bitmap for managing feature invocation
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 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/ethernet/packet.h>
22 #include <vlib/cli.h>
23 #include <vnet/l2/l2_input.h>
24 #include <vnet/l2/feat_bitmap.h>
25 
26 #include <vppinfra/error.h>
27 #include <vppinfra/hash.h>
28 #include <vppinfra/cache.h>
29 
30 
31 /*
32  * Drop node for feature bitmaps
33  * For features that just do a drop, or are not yet implemented.
34  * Initial feature dispatch nodes don't need to set b0->error
35  * in case of a possible drop because that will be done here.
36  *The next node is always error-drop.
37  */
38 
40 
41 #define foreach_feat_bitmap_drop_error \
42 _(NO_FWD, "L2 feature forwarding disabled") \
43 _(NYI, "L2 feature not implemented")
44 
45 typedef enum
46 {
47 #define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym,
49 #undef _
52 
54 #define _(sym,string) string,
56 #undef _
57 };
58 
59 typedef enum
60 {
64 
65 typedef struct
66 {
69 
70 /* packet trace format function */
71 static u8 *
72 format_feat_bitmap_drop_trace (u8 * s, va_list * args)
73 {
74  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
75  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
77 
78  s =
79  format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap);
80  return s;
81 }
82 
83 static uword
86 {
87  u32 n_left_from, *from, *to_next;
89 
91  n_left_from = frame->n_vectors; /* number of packets to process */
92  next_index = node->cached_next_index;
93 
94  while (n_left_from > 0)
95  {
96  u32 n_left_to_next;
97 
98  /* get space to enqueue frame to graph node "next_index" */
99  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
100 
101  while (n_left_from > 0 && n_left_to_next > 0)
102  {
103  u32 bi0;
104  vlib_buffer_t *b0;
105  u32 next0;
106 
107  /* speculatively enqueue b0 to the current next frame */
108  bi0 = from[0];
109  to_next[0] = bi0;
110  from += 1;
111  to_next += 1;
112  n_left_from -= 1;
113  n_left_to_next -= 1;
114 
115  b0 = vlib_get_buffer (vm, bi0);
116 
117  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
118  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
119  {
121  vlib_add_trace (vm, node, b0, sizeof (*t));
122  t->feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap;
123  }
124 
125  if (vnet_buffer (b0)->l2.feature_bitmap == 1)
126  {
127  /*
128  * If we are executing the last feature, this is the
129  * No forwarding catch-all
130  */
131  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NO_FWD];
132  }
133  else
134  {
135  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NYI];
136  }
138 
139  /* verify speculative enqueue, maybe switch current next frame */
141  to_next, n_left_to_next,
142  bi0, next0);
143  }
144 
145  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
146  }
147  return frame->n_vectors;
148 }
149 
150 clib_error_t *
152 {
153  return 0;
154 }
155 
157 
158 /* *INDENT-OFF* */
160  .function = feat_bitmap_drop_node_fn,
161  .name = "feature-bitmap-drop",
162  .vector_size = sizeof (u32),
163  .format_trace = format_feat_bitmap_drop_trace,
165 
167  .error_strings = feat_bitmap_drop_error_strings,
168 
169  .n_next_nodes = FEAT_BITMAP_DROP_N_NEXT,
170 
171  /* edit / add dispositions here */
172  .next_nodes = {
173  [FEAT_BITMAP_DROP_NEXT_DROP] = "error-drop",
174  },
175 };
176 /* *INDENT-ON* */
177 
178 /*
179  * fd.io coding-style-patch-verification: ON
180  *
181  * Local Variables:
182  * eval: (c-set-style "gnu")
183  * End:
184  */
vlib.h
feat_bitmap_drop_error_strings
static char * feat_bitmap_drop_error_strings[]
Definition: feat_bitmap.c:53
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
feat_bitmap_drop_trace_t
Definition: feat_bitmap.c:65
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
feat_bitmap_drop_node
static vlib_node_registration_t feat_bitmap_drop_node
(constructor) VLIB_REGISTER_NODE (feat_bitmap_drop_node)
Definition: feat_bitmap.c:39
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
feat_bitmap_drop_error_t
feat_bitmap_drop_error_t
Definition: feat_bitmap.c:45
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
FEAT_BITMAP_DROP_N_NEXT
@ FEAT_BITMAP_DROP_N_NEXT
Definition: feat_bitmap.c:62
vlib_frame_t
Definition: node.h:372
ethernet.h
feat_bitmap_drop_trace_t::feature_bitmap
u32 feature_bitmap
Definition: feat_bitmap.c:67
vlib_buffer_t::error
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
packet.h
error.h
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
format_feat_bitmap_drop_trace
static u8 * format_feat_bitmap_drop_trace(u8 *s, va_list *args)
Definition: feat_bitmap.c:72
uword
u64 uword
Definition: types.h:112
foreach_feat_bitmap_drop_error
#define foreach_feat_bitmap_drop_error
Definition: feat_bitmap.c:41
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
l2_input.h
FEAT_BITMAP_DROP_NEXT_DROP
@ FEAT_BITMAP_DROP_NEXT_DROP
Definition: feat_bitmap.c:61
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
FEAT_BITMAP_DROP_N_ERROR
@ FEAT_BITMAP_DROP_N_ERROR
Definition: feat_bitmap.c:50
format
description fragment has unexpected format
Definition: map.api:433
cache.h
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
cli.h
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
hash.h
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
feat_bitmap.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
feat_bitmap_drop_node_fn
static uword feat_bitmap_drop_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: feat_bitmap.c:84
feat_bitmap_drop_next_t
feat_bitmap_drop_next_t
Definition: feat_bitmap.c:59
feat_bitmap_drop_init
clib_error_t * feat_bitmap_drop_init(vlib_main_t *vm)
Definition: feat_bitmap.c:151
vnet.h
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169