FD.io VPP  v19.04-6-g6f05f72
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 /*
33  * Drop node for feature bitmaps
34  * For features that just do a drop, or are not yet implemented.
35  * Initial feature dispatch nodes don't need to set b0->error
36  * in case of a possible drop because that will be done here.
37  *The next node is always error-drop.
38  */
39 
41 
42 #define foreach_feat_bitmap_drop_error \
43 _(NO_FWD, "L2 feature forwarding disabled") \
44 _(NYI, "L2 feature not implemented")
45 
46 typedef enum
47 {
48 #define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym,
50 #undef _
53 
55 #define _(sym,string) string,
57 #undef _
58 };
59 
60 typedef enum
61 {
65 
66 typedef struct
67 {
70 
71 /* packet trace format function */
72 static u8 *
73 format_feat_bitmap_drop_trace (u8 * s, va_list * args)
74 {
75  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
76  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
78 
79  s =
80  format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap);
81  return s;
82 }
83 
84 static uword
86  vlib_node_runtime_t * node, vlib_frame_t * frame)
87 {
88  u32 n_left_from, *from, *to_next;
89  feat_bitmap_drop_next_t next_index;
90 
91  from = vlib_frame_vector_args (frame);
92  n_left_from = frame->n_vectors; /* number of packets to process */
93  next_index = node->cached_next_index;
94 
95  while (n_left_from > 0)
96  {
97  u32 n_left_to_next;
98 
99  /* get space to enqueue frame to graph node "next_index" */
100  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
101 
102  while (n_left_from > 0 && n_left_to_next > 0)
103  {
104  u32 bi0;
105  vlib_buffer_t *b0;
106  u32 next0;
107 
108  /* speculatively enqueue b0 to the current next frame */
109  bi0 = from[0];
110  to_next[0] = bi0;
111  from += 1;
112  to_next += 1;
113  n_left_from -= 1;
114  n_left_to_next -= 1;
115 
116  b0 = vlib_get_buffer (vm, bi0);
117 
119  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
120  {
122  vlib_add_trace (vm, node, b0, sizeof (*t));
123  t->feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap;
124  }
125 
126  if (vnet_buffer (b0)->l2.feature_bitmap == 1)
127  {
128  /*
129  * If we are executing the last feature, this is the
130  * No forwarding catch-all
131  */
132  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NO_FWD];
133  }
134  else
135  {
136  b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NYI];
137  }
139 
140  /* verify speculative enqueue, maybe switch current next frame */
141  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
142  to_next, n_left_to_next,
143  bi0, next0);
144  }
145 
146  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
147  }
148  return frame->n_vectors;
149 }
150 
151 clib_error_t *
153 {
154  return 0;
155 }
156 
158 
159 /* *INDENT-OFF* */
161  .function = feat_bitmap_drop_node_fn,
162  .name = "feature-bitmap-drop",
163  .vector_size = sizeof (u32),
164  .format_trace = format_feat_bitmap_drop_trace,
165  .type = VLIB_NODE_TYPE_INTERNAL,
166 
168  .error_strings = feat_bitmap_drop_error_strings,
169 
170  .n_next_nodes = FEAT_BITMAP_DROP_N_NEXT,
171 
172  /* edit / add dispositions here */
173  .next_nodes = {
174  [FEAT_BITMAP_DROP_NEXT_DROP] = "error-drop",
175  },
176 };
177 /* *INDENT-ON* */
178 
179 /*
180  * fd.io coding-style-patch-verification: ON
181  *
182  * Local Variables:
183  * eval: (c-set-style "gnu")
184  * End:
185  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
clib_error_t * feat_bitmap_drop_init(vlib_main_t *vm)
Definition: feat_bitmap.c:152
#define CLIB_UNUSED(x)
Definition: clib.h:82
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:469
unsigned char u8
Definition: types.h:56
static char * feat_bitmap_drop_error_strings[]
Definition: feat_bitmap.c:54
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
unsigned int u32
Definition: types.h:88
static vlib_node_registration_t feat_bitmap_drop_node
(constructor) VLIB_REGISTER_NODE (feat_bitmap_drop_node)
Definition: feat_bitmap.c:40
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
static u8 * format_feat_bitmap_drop_trace(u8 *s, va_list *args)
Definition: feat_bitmap.c:73
#define PREDICT_FALSE(x)
Definition: clib.h:111
#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:218
#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:368
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:395
vlib_main_t * vm
Definition: buffer.c:312
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:465
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:514
static 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:57
struct _vlib_node_registration vlib_node_registration_t
static uword feat_bitmap_drop_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: feat_bitmap.c:85
feat_bitmap_drop_error_t
Definition: feat_bitmap.c:46
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:274
#define vnet_buffer(b)
Definition: buffer.h:369
u16 flags
Copy of main node flags.
Definition: node.h:508
#define foreach_feat_bitmap_drop_error
Definition: feat_bitmap.c:42
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:301
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
feat_bitmap_drop_next_t
Definition: feat_bitmap.c:60