blob: 6c046467f2ccee4cf06cec0c8b8ee9b080b1a5de [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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
Dave Barach97d8dc22016-08-15 15:31:15 -040032/*
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 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070039
40static vlib_node_registration_t feat_bitmap_drop_node;
41
42#define foreach_feat_bitmap_drop_error \
43_(NO_FWD, "L2 feature forwarding disabled") \
44_(NYI, "L2 feature not implemented")
45
Dave Barach97d8dc22016-08-15 15:31:15 -040046typedef enum
47{
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym,
49 foreach_feat_bitmap_drop_error
50#undef _
Dave Barach97d8dc22016-08-15 15:31:15 -040051 FEAT_BITMAP_DROP_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -070052} feat_bitmap_drop_error_t;
53
Dave Barach97d8dc22016-08-15 15:31:15 -040054static char *feat_bitmap_drop_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070055#define _(sym,string) string,
56 foreach_feat_bitmap_drop_error
57#undef _
58};
59
Dave Barach97d8dc22016-08-15 15:31:15 -040060typedef enum
61{
Ed Warnickecb9cada2015-12-08 15:45:58 -070062 FEAT_BITMAP_DROP_NEXT_DROP,
63 FEAT_BITMAP_DROP_N_NEXT,
64} feat_bitmap_drop_next_t;
65
Dave Barach97d8dc22016-08-15 15:31:15 -040066typedef struct
67{
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 u32 feature_bitmap;
69} feat_bitmap_drop_trace_t;
70
71/* packet trace format function */
Dave Barach97d8dc22016-08-15 15:31:15 -040072static u8 *
73format_feat_bitmap_drop_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070074{
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 *);
Dave Barach97d8dc22016-08-15 15:31:15 -040077 feat_bitmap_drop_trace_t *t = va_arg (*args, feat_bitmap_drop_trace_t *);
78
79 s =
80 format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap);
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 return s;
82}
83
84static uword
85feat_bitmap_drop_node_fn (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -040086 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -070087{
Dave Barach97d8dc22016-08-15 15:31:15 -040088 u32 n_left_from, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 feat_bitmap_drop_next_t next_index;
90
91 from = vlib_frame_vector_args (frame);
Dave Barach97d8dc22016-08-15 15:31:15 -040092 n_left_from = frame->n_vectors; /* number of packets to process */
Ed Warnickecb9cada2015-12-08 15:45:58 -070093 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" */
Dave Barach97d8dc22016-08-15 15:31:15 -0400100 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
101
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 while (n_left_from > 0 && n_left_to_next > 0)
103 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400104 u32 bi0;
105 vlib_buffer_t *b0;
106 u32 next0;
107
108 /* speculatively enqueue b0 to the current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 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
Dave Barach97d8dc22016-08-15 15:31:15 -0400118 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
119 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
120 {
121 feat_bitmap_drop_trace_t *t =
122 vlib_add_trace (vm, node, b0, sizeof (*t));
123 t->feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap;
124 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Dave Barach97d8dc22016-08-15 15:31:15 -0400126 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 }
138 next0 = FEAT_BITMAP_DROP_NEXT_DROP;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139
Dave Barach97d8dc22016-08-15 15:31:15 -0400140 /* verify speculative enqueue, maybe switch current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 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
Dave Barach97d8dc22016-08-15 15:31:15 -0400151clib_error_t *
152feat_bitmap_drop_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153{
154 return 0;
155}
156
157VLIB_INIT_FUNCTION (feat_bitmap_drop_init);
158
Dave Barach97d8dc22016-08-15 15:31:15 -0400159/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160VLIB_REGISTER_NODE (feat_bitmap_drop_node,static) = {
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,
Dave Barach97d8dc22016-08-15 15:31:15 -0400166
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167 .n_errors = ARRAY_LEN(feat_bitmap_drop_error_strings),
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 = {
Dave Barach97d8dc22016-08-15 15:31:15 -0400174 [FEAT_BITMAP_DROP_NEXT_DROP] = "error-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 },
176};
Dave Barach97d8dc22016-08-15 15:31:15 -0400177/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
Dave Barach97d8dc22016-08-15 15:31:15 -0400179/*
180 * fd.io coding-style-patch-verification: ON
181 *
182 * Local Variables:
183 * eval: (c-set-style "gnu")
184 * End:
185 */