FD.io VPP  v16.06
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/pg/pg.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/ethernet/packet.h>
23 #include <vlib/cli.h>
24 #include <vnet/l2/l2_input.h>
25 #include <vnet/l2/feat_bitmap.h>
26 
27 #include <vppinfra/error.h>
28 #include <vppinfra/hash.h>
29 #include <vppinfra/cache.h>
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 #define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym,
48 #undef _
51 
52 static char * feat_bitmap_drop_error_strings[] = {
53 #define _(sym,string) string,
55 #undef _
56 };
57 
58 typedef enum {
62 
63 typedef struct {
66 
67 /* packet trace format function */
68 static u8 * format_feat_bitmap_drop_trace (u8 * s, va_list * args)
69 {
70  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
71  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
72  feat_bitmap_drop_trace_t * t = va_arg (*args, feat_bitmap_drop_trace_t *);
73 
74  s = format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap);
75  return s;
76 }
77 
78 static uword
80  vlib_node_runtime_t * node,
81  vlib_frame_t * frame)
82 {
83  u32 n_left_from, * from, * to_next;
84  feat_bitmap_drop_next_t next_index;
85 
86  from = vlib_frame_vector_args (frame);
87  n_left_from = frame->n_vectors; /* number of packets to process */
88  next_index = node->cached_next_index;
89 
90  while (n_left_from > 0)
91  {
92  u32 n_left_to_next;
93 
94  /* get space to enqueue frame to graph node "next_index" */
95  vlib_get_next_frame (vm, node, next_index,
96  to_next, n_left_to_next);
97 
98  while (n_left_from > 0 && n_left_to_next > 0)
99  {
100  u32 bi0;
101  vlib_buffer_t * b0;
102  u32 next0;
103 
104  /* speculatively enqueue b0 to the current next frame */
105  bi0 = from[0];
106  to_next[0] = bi0;
107  from += 1;
108  to_next += 1;
109  n_left_from -= 1;
110  n_left_to_next -= 1;
111 
112  b0 = vlib_get_buffer (vm, bi0);
113 
115  && (b0->flags & VLIB_BUFFER_IS_TRACED))) {
117  vlib_add_trace (vm, node, b0, sizeof (*t));
118  t->feature_bitmap = vnet_buffer(b0)->l2.feature_bitmap;
119  }
120 
121  if (vnet_buffer(b0)->l2.feature_bitmap == 1) {
122  // If we are executing the last feature, this is the
123  // No forwarding catch-all
124  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NO_FWD];
125  } else {
126  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NYI];
127  }
129 
130  /* verify speculative enqueue, maybe switch current next frame */
131  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
132  to_next, n_left_to_next,
133  bi0, next0);
134  }
135 
136  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
137  }
138  return frame->n_vectors;
139 }
140 
142 {
143  return 0;
144 }
145 
147 
149  .function = feat_bitmap_drop_node_fn,
150  .name = "feature-bitmap-drop",
151  .vector_size = sizeof (u32),
152  .format_trace = format_feat_bitmap_drop_trace,
154 
156  .error_strings = feat_bitmap_drop_error_strings,
157 
158  .n_next_nodes = FEAT_BITMAP_DROP_N_NEXT,
159 
160  /* edit / add dispositions here */
161  .next_nodes = {
162  [FEAT_BITMAP_DROP_NEXT_DROP] = "error-drop",
163  },
164 };
165 
166 
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Definition: main.c:459
clib_error_t * feat_bitmap_drop_init(vlib_main_t *vm)
Definition: feat_bitmap.c:141
#define CLIB_UNUSED(x)
Definition: clib.h:79
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
struct _vlib_node_registration vlib_node_registration_t
vlib_error_t * errors
Definition: node.h:378
static char * feat_bitmap_drop_error_strings[]
Definition: feat_bitmap.c:52
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
always_inline void * vlib_frame_vector_args(vlib_frame_t *f)
Definition: node_funcs.h:202
static u8 * format_feat_bitmap_drop_trace(u8 *s, va_list *args)
Definition: feat_bitmap.c:68
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Definition: buffer_node.h:83
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Definition: node_funcs.h:265
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:129
u16 n_vectors
Definition: node.h:307
#define ARRAY_LEN(x)
Definition: clib.h:59
u16 cached_next_index
Definition: node.h:422
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:300
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:225
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:91
u64 uword
Definition: types.h:112
static uword feat_bitmap_drop_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: feat_bitmap.c:79
unsigned char u8
Definition: types.h:56
feat_bitmap_drop_error_t
Definition: feat_bitmap.c:45
always_inline void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:140
static vlib_node_registration_t feat_bitmap_drop_node
(constructor) VLIB_REGISTER_NODE (feat_bitmap_drop_node)
Definition: feat_bitmap.c:39
#define foreach_feat_bitmap_drop_error
Definition: feat_bitmap.c:41
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:84
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
feat_bitmap_drop_next_t
Definition: feat_bitmap.c:58