blob: 5c185991e8b5f4cc8349745ab2d5e5650fe7e741 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
Damjan Marione936bbe2016-02-25 23:17:38 +010015
16#include <stdint.h>
17
Ed Warnickecb9cada2015-12-08 15:45:58 -070018#include <vlib/vlib.h>
19#include <vnet/vnet.h>
20#include <vnet/policer/policer.h>
Neale Rannsd91c1db2017-07-31 02:30:50 -070021#include <vnet/policer/police_inlines.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070022#include <vnet/ip/ip.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070023#include <vnet/classify/policer_classify.h>
24#include <vnet/classify/vnet_classify.h>
Neale Ranns3b81a1e2018-09-06 09:50:26 -070025#include <vnet/l2/feat_bitmap.h>
26#include <vnet/l2/l2_input.h>
Matus Fabian4ac74c92016-05-31 07:33:29 -070027
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
29/* Dispatch functions meant to be instantiated elsewhere */
30
Damjan Marion3891cd82016-10-27 10:27:00 +020031typedef struct
32{
Ed Warnickecb9cada2015-12-08 15:45:58 -070033 u32 next_index;
34 u32 sw_if_index;
35 u32 policer_index;
36} vnet_policer_trace_t;
37
38/* packet trace format function */
Damjan Marion3891cd82016-10-27 10:27:00 +020039static u8 *
40format_policer_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070041{
42 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
43 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Damjan Marion3891cd82016-10-27 10:27:00 +020044 vnet_policer_trace_t *t = va_arg (*args, vnet_policer_trace_t *);
45
Ed Warnickecb9cada2015-12-08 15:45:58 -070046 s = format (s, "VNET_POLICER: sw_if_index %d policer_index %d next %d",
Damjan Marion3891cd82016-10-27 10:27:00 +020047 t->sw_if_index, t->policer_index, t->next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070048 return s;
49}
50
51#define foreach_vnet_policer_error \
52_(TRANSMIT, "Packets Transmitted") \
53_(DROP, "Packets Dropped")
54
Damjan Marion3891cd82016-10-27 10:27:00 +020055typedef enum
56{
Ed Warnickecb9cada2015-12-08 15:45:58 -070057#define _(sym,str) VNET_POLICER_ERROR_##sym,
58 foreach_vnet_policer_error
59#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +020060 VNET_POLICER_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -070061} vnet_policer_error_t;
62
Damjan Marion3891cd82016-10-27 10:27:00 +020063static char *vnet_policer_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070064#define _(sym,string) string,
65 foreach_vnet_policer_error
66#undef _
67};
68
Damjan Marion3891cd82016-10-27 10:27:00 +020069static inline uword
70vnet_policer_inline (vlib_main_t * vm,
71 vlib_node_runtime_t * node,
72 vlib_frame_t * frame, vnet_policer_index_t which)
Ed Warnickecb9cada2015-12-08 15:45:58 -070073{
Damjan Marion3891cd82016-10-27 10:27:00 +020074 u32 n_left_from, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 vnet_policer_next_t next_index;
Damjan Marion3891cd82016-10-27 10:27:00 +020076 vnet_policer_main_t *pm = &vnet_policer_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 u64 time_in_policer_periods;
78 u32 transmitted = 0;
79
Damjan Marion3891cd82016-10-27 10:27:00 +020080 time_in_policer_periods =
81 clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082
83 from = vlib_frame_vector_args (frame);
84 n_left_from = frame->n_vectors;
85 next_index = node->cached_next_index;
86
87 while (n_left_from > 0)
88 {
89 u32 n_left_to_next;
90
Damjan Marion3891cd82016-10-27 10:27:00 +020091 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
93 while (n_left_from >= 4 && n_left_to_next >= 2)
94 {
Damjan Marion3891cd82016-10-27 10:27:00 +020095 u32 bi0, bi1;
96 vlib_buffer_t *b0, *b1;
97 u32 next0, next1;
98 u32 sw_if_index0, sw_if_index1;
99 u32 pi0 = 0, pi1 = 0;
100 u8 act0, act1;
101
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 /* Prefetch next iteration. */
103 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200104 vlib_buffer_t *b2, *b3;
105
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106 b2 = vlib_get_buffer (vm, from[2]);
107 b3 = vlib_get_buffer (vm, from[3]);
Damjan Marion3891cd82016-10-27 10:27:00 +0200108
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 vlib_prefetch_buffer_header (b2, LOAD);
110 vlib_prefetch_buffer_header (b3, LOAD);
111 }
112
Damjan Marion3891cd82016-10-27 10:27:00 +0200113 /* speculatively enqueue b0 and b1 to the current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114 to_next[0] = bi0 = from[0];
115 to_next[1] = bi1 = from[1];
116 from += 2;
117 to_next += 2;
118 n_left_from -= 2;
119 n_left_to_next -= 2;
120
121 b0 = vlib_get_buffer (vm, bi0);
122 b1 = vlib_get_buffer (vm, bi1);
123
Damjan Marion3891cd82016-10-27 10:27:00 +0200124 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
125 next0 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700126
Damjan Marion3891cd82016-10-27 10:27:00 +0200127 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
128 next1 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129
130
Damjan Marion3891cd82016-10-27 10:27:00 +0200131 if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX)
132 {
133 pi0 = pm->policer_index_by_sw_if_index[sw_if_index0];
134 pi1 = pm->policer_index_by_sw_if_index[sw_if_index1];
135 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136
Damjan Marion3891cd82016-10-27 10:27:00 +0200137 if (which == VNET_POLICER_INDEX_BY_OPAQUE)
138 {
139 pi0 = vnet_buffer (b0)->policer.index;
140 pi1 = vnet_buffer (b1)->policer.index;
141 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142
Damjan Marion3891cd82016-10-27 10:27:00 +0200143 if (which == VNET_POLICER_INDEX_BY_EITHER)
144 {
145 pi0 = vnet_buffer (b0)->policer.index;
146 pi0 = (pi0 != ~0) ? pi0 :
147 pm->policer_index_by_sw_if_index[sw_if_index0];
148 pi1 = vnet_buffer (b1)->policer.index;
149 pi1 = (pi1 != ~0) ? pi1 :
150 pm->policer_index_by_sw_if_index[sw_if_index1];
151 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
Damjan Marion3891cd82016-10-27 10:27:00 +0200153 act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods,
154 POLICE_CONFORM /* no chaining */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700155
Damjan Marion3891cd82016-10-27 10:27:00 +0200156 act1 = vnet_policer_police (vm, b1, pi1, time_in_policer_periods,
157 POLICE_CONFORM /* no chaining */ );
Matus Fabian4ac74c92016-05-31 07:33:29 -0700158
Damjan Marion3891cd82016-10-27 10:27:00 +0200159 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */
160 {
161 next0 = VNET_POLICER_NEXT_DROP;
162 b0->error = node->errors[VNET_POLICER_ERROR_DROP];
163 }
164 else /* transmit or mark-and-transmit action */
165 {
166 transmitted++;
167 }
Matus Fabian4ac74c92016-05-31 07:33:29 -0700168
Damjan Marion3891cd82016-10-27 10:27:00 +0200169 if (PREDICT_FALSE (act1 == SSE2_QOS_ACTION_DROP)) /* drop action */
170 {
171 next1 = VNET_POLICER_NEXT_DROP;
172 b1->error = node->errors[VNET_POLICER_ERROR_DROP];
173 }
174 else /* transmit or mark-and-transmit action */
175 {
176 transmitted++;
177 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
179
Damjan Marion3891cd82016-10-27 10:27:00 +0200180 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
181 {
182 if (b0->flags & VLIB_BUFFER_IS_TRACED)
183 {
184 vnet_policer_trace_t *t =
185 vlib_add_trace (vm, node, b0, sizeof (*t));
186 t->sw_if_index = sw_if_index0;
187 t->next_index = next0;
188 }
189 if (b1->flags & VLIB_BUFFER_IS_TRACED)
190 {
191 vnet_policer_trace_t *t =
192 vlib_add_trace (vm, node, b1, sizeof (*t));
193 t->sw_if_index = sw_if_index1;
194 t->next_index = next1;
195 }
196 }
197
198 /* verify speculative enqueues, maybe switch current next frame */
199 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
200 to_next, n_left_to_next,
201 bi0, bi1, next0, next1);
202 }
203
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204 while (n_left_from > 0 && n_left_to_next > 0)
205 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200206 u32 bi0;
207 vlib_buffer_t *b0;
208 u32 next0;
209 u32 sw_if_index0;
210 u32 pi0 = 0;
211 u8 act0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212
213 bi0 = from[0];
214 to_next[0] = bi0;
215 from += 1;
216 to_next += 1;
217 n_left_from -= 1;
218 n_left_to_next -= 1;
219
220 b0 = vlib_get_buffer (vm, bi0);
221
Damjan Marion3891cd82016-10-27 10:27:00 +0200222 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
223 next0 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224
Damjan Marion3891cd82016-10-27 10:27:00 +0200225 if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX)
226 pi0 = pm->policer_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700227
Damjan Marion3891cd82016-10-27 10:27:00 +0200228 if (which == VNET_POLICER_INDEX_BY_OPAQUE)
229 pi0 = vnet_buffer (b0)->policer.index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700230
Damjan Marion3891cd82016-10-27 10:27:00 +0200231 if (which == VNET_POLICER_INDEX_BY_EITHER)
232 {
233 pi0 = vnet_buffer (b0)->policer.index;
234 pi0 = (pi0 != ~0) ? pi0 :
235 pm->policer_index_by_sw_if_index[sw_if_index0];
236 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700237
Damjan Marion3891cd82016-10-27 10:27:00 +0200238 act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods,
239 POLICE_CONFORM /* no chaining */ );
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700240
Damjan Marion3891cd82016-10-27 10:27:00 +0200241 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */
242 {
243 next0 = VNET_POLICER_NEXT_DROP;
244 b0->error = node->errors[VNET_POLICER_ERROR_DROP];
245 }
246 else /* transmit or mark-and-transmit action */
247 {
248 transmitted++;
249 }
250
251 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
252 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
253 {
254 vnet_policer_trace_t *t =
255 vlib_add_trace (vm, node, b0, sizeof (*t));
256 t->sw_if_index = sw_if_index0;
257 t->next_index = next0;
258 t->policer_index = pi0;
259 }
260
261 /* verify speculative enqueue, maybe switch current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
263 to_next, n_left_to_next,
264 bi0, next0);
265 }
266
267 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
268 }
269
Damjan Marion3891cd82016-10-27 10:27:00 +0200270 vlib_node_increment_counter (vm, node->node_index,
271 VNET_POLICER_ERROR_TRANSMIT, transmitted);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272 return frame->n_vectors;
273}
274
Damjan Marion3891cd82016-10-27 10:27:00 +0200275uword
276vnet_policer_by_sw_if_index (vlib_main_t * vm,
277 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278{
Damjan Marion3891cd82016-10-27 10:27:00 +0200279 return vnet_policer_inline (vm, node, frame,
280 VNET_POLICER_INDEX_BY_SW_IF_INDEX);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281}
282
Damjan Marion3891cd82016-10-27 10:27:00 +0200283uword
284vnet_policer_by_opaque (vlib_main_t * vm,
285 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286{
Damjan Marion3891cd82016-10-27 10:27:00 +0200287 return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_OPAQUE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288}
289
Damjan Marion3891cd82016-10-27 10:27:00 +0200290uword
291vnet_policer_by_either (vlib_main_t * vm,
292 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293{
Damjan Marion3891cd82016-10-27 10:27:00 +0200294 return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_EITHER);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295}
296
Damjan Marion3891cd82016-10-27 10:27:00 +0200297void
298vnet_policer_node_funcs_reference (void)
299{
300}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301
302
303#define TEST_CODE 1
304
305#ifdef TEST_CODE
306
Damjan Marion3891cd82016-10-27 10:27:00 +0200307/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308VLIB_REGISTER_NODE (policer_by_sw_if_index_node, static) = {
309 .function = vnet_policer_by_sw_if_index,
310 .name = "policer-by-sw-if-index",
311 .vector_size = sizeof (u32),
312 .format_trace = format_policer_trace,
313 .type = VLIB_NODE_TYPE_INTERNAL,
Damjan Marion3891cd82016-10-27 10:27:00 +0200314
Ed Warnickecb9cada2015-12-08 15:45:58 -0700315 .n_errors = ARRAY_LEN(vnet_policer_error_strings),
316 .error_strings = vnet_policer_error_strings,
Damjan Marion3891cd82016-10-27 10:27:00 +0200317
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318 .n_next_nodes = VNET_POLICER_N_NEXT,
319
320 /* edit / add dispositions here */
321 .next_nodes = {
322 [VNET_POLICER_NEXT_TRANSMIT] = "ethernet-input",
323 [VNET_POLICER_NEXT_DROP] = "error-drop",
324 },
325};
326
Damjan Marion1c80e832016-05-11 23:07:18 +0200327VLIB_NODE_FUNCTION_MULTIARCH (policer_by_sw_if_index_node,
328 vnet_policer_by_sw_if_index);
Damjan Marion3891cd82016-10-27 10:27:00 +0200329/* *INDENT-ON* */
Damjan Marion1c80e832016-05-11 23:07:18 +0200330
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331
Damjan Marion3891cd82016-10-27 10:27:00 +0200332int
333test_policer_add_del (u32 rx_sw_if_index, u8 * config_name, int is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334{
Damjan Marion3891cd82016-10-27 10:27:00 +0200335 vnet_policer_main_t *pm = &vnet_policer_main;
336 policer_read_response_type_st *template;
337 policer_read_response_type_st *policer;
338 vnet_hw_interface_t *rxhi;
339 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700340
341 rxhi = vnet_get_sup_hw_interface (pm->vnet_main, rx_sw_if_index);
342
343 /* Make sure caller didn't pass a vlan subif, etc. */
344 if (rxhi->sw_if_index != rx_sw_if_index)
345 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
346
347 if (is_add)
348 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200349
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 p = hash_get_mem (pm->policer_config_by_name, config_name);
351
352 if (p == 0)
Damjan Marion3891cd82016-10-27 10:27:00 +0200353 return -2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354
355 template = pool_elt_at_index (pm->policer_templates, p[0]);
356
Damjan Marion3891cd82016-10-27 10:27:00 +0200357 vnet_hw_interface_rx_redirect_to_node
358 (pm->vnet_main, rxhi->hw_if_index, policer_by_sw_if_index_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359
360 pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES);
361
362 policer[0] = template[0];
363
364 vec_validate (pm->policer_index_by_sw_if_index, rx_sw_if_index);
Damjan Marion3891cd82016-10-27 10:27:00 +0200365 pm->policer_index_by_sw_if_index[rx_sw_if_index]
366 = policer - pm->policers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 }
368 else
369 {
370 u32 pi;
Damjan Marion3891cd82016-10-27 10:27:00 +0200371 vnet_hw_interface_rx_redirect_to_node (pm->vnet_main,
372 rxhi->hw_if_index,
373 ~0 /* disable */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374
375 pi = pm->policer_index_by_sw_if_index[rx_sw_if_index];
376 pm->policer_index_by_sw_if_index[rx_sw_if_index] = ~0;
377 pool_put_index (pm->policers, pi);
378 }
Damjan Marion3891cd82016-10-27 10:27:00 +0200379
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380 return 0;
381}
382
383static clib_error_t *
384test_policer_command_fn (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200385 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386{
Damjan Marion3891cd82016-10-27 10:27:00 +0200387 vnet_policer_main_t *pm = &vnet_policer_main;
388 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700389 u32 rx_sw_if_index;
390 int rv;
Damjan Marion3891cd82016-10-27 10:27:00 +0200391 u8 *config_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392 int rx_set = 0;
393 int is_add = 1;
394 int is_show = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500395 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700396
397 /* Get a line of input. */
Damjan Marion3891cd82016-10-27 10:27:00 +0200398 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700399 return 0;
400
401 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
402 {
403 if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface,
Damjan Marion3891cd82016-10-27 10:27:00 +0200404 pm->vnet_main, &rx_sw_if_index))
405 rx_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406 else if (unformat (line_input, "show"))
Damjan Marion3891cd82016-10-27 10:27:00 +0200407 is_show = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408 else if (unformat (line_input, "policer %s", &config_name))
Damjan Marion3891cd82016-10-27 10:27:00 +0200409 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 else if (unformat (line_input, "del"))
Damjan Marion3891cd82016-10-27 10:27:00 +0200411 is_add = 0;
412 else
413 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414 }
415
416 if (rx_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500417 {
418 error = clib_error_return (0, "interface not set");
419 goto done;
420 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421
422 if (is_show)
423 {
424 u32 pi = pm->policer_index_by_sw_if_index[rx_sw_if_index];
Damjan Marion3891cd82016-10-27 10:27:00 +0200425 policer_read_response_type_st *policer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700426 policer = pool_elt_at_index (pm->policers, pi);
Damjan Marion3891cd82016-10-27 10:27:00 +0200427
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428 vlib_cli_output (vm, "%U", format_policer_instance, policer);
Billy McFalla9a20e72017-02-15 11:39:12 -0500429 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 }
431
432 if (is_add && config_name == 0)
433 {
Billy McFalla9a20e72017-02-15 11:39:12 -0500434 error = clib_error_return (0, "policer config name required");
435 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436 }
437
438 rv = test_policer_add_del (rx_sw_if_index, config_name, is_add);
439
440 switch (rv)
441 {
442 case 0:
443 break;
444
445 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500446 error = clib_error_return
Damjan Marion3891cd82016-10-27 10:27:00 +0200447 (0, "WARNING: vnet_vnet_policer_add_del returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500448 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700449 }
Damjan Marion3891cd82016-10-27 10:27:00 +0200450
Billy McFalla9a20e72017-02-15 11:39:12 -0500451done:
452 unformat_free (line_input);
453
454 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700455}
456
Damjan Marion3891cd82016-10-27 10:27:00 +0200457/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700458VLIB_CLI_COMMAND (test_patch_command, static) = {
459 .path = "test policer",
Damjan Marion3891cd82016-10-27 10:27:00 +0200460 .short_help =
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461 "intfc <intfc> policer <policer-config-name> [del]",
462 .function = test_policer_command_fn,
463};
Damjan Marion3891cd82016-10-27 10:27:00 +0200464/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700465
466#endif /* TEST_CODE */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700467
468
Damjan Marion3891cd82016-10-27 10:27:00 +0200469typedef struct
470{
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700471 u32 sw_if_index;
472 u32 next_index;
473 u32 table_index;
474 u32 offset;
475 u32 policer_index;
476} policer_classify_trace_t;
477
478static u8 *
479format_policer_classify_trace (u8 * s, va_list * args)
480{
481 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
482 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Damjan Marion3891cd82016-10-27 10:27:00 +0200483 policer_classify_trace_t *t = va_arg (*args, policer_classify_trace_t *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700484
485 s = format (s, "POLICER_CLASSIFY: sw_if_index %d next %d table %d offset %d"
Damjan Marion3891cd82016-10-27 10:27:00 +0200486 " policer_index %d",
487 t->sw_if_index, t->next_index, t->table_index, t->offset,
488 t->policer_index);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700489 return s;
490}
491
492#define foreach_policer_classify_error \
493_(MISS, "Policer classify misses") \
494_(HIT, "Policer classify hits") \
495_(CHAIN_HIT, "Polcier classify hits after chain walk") \
496_(DROP, "Policer classify action drop")
497
Damjan Marion3891cd82016-10-27 10:27:00 +0200498typedef enum
499{
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700500#define _(sym,str) POLICER_CLASSIFY_ERROR_##sym,
501 foreach_policer_classify_error
502#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +0200503 POLICER_CLASSIFY_N_ERROR,
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700504} policer_classify_error_t;
505
Damjan Marion3891cd82016-10-27 10:27:00 +0200506static char *policer_classify_error_strings[] = {
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700507#define _(sym,string) string,
508 foreach_policer_classify_error
509#undef _
510};
511
512static inline uword
513policer_classify_inline (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200514 vlib_node_runtime_t * node,
515 vlib_frame_t * frame,
516 policer_classify_table_id_t tid)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700517{
Damjan Marion3891cd82016-10-27 10:27:00 +0200518 u32 n_left_from, *from, *to_next;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700519 policer_classify_next_index_t next_index;
Damjan Marion3891cd82016-10-27 10:27:00 +0200520 policer_classify_main_t *pcm = &policer_classify_main;
521 vnet_classify_main_t *vcm = pcm->vnet_classify_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700522 f64 now = vlib_time_now (vm);
523 u32 hits = 0;
524 u32 misses = 0;
525 u32 chain_hits = 0;
526 u32 drop = 0;
527 u32 n_next_nodes;
528 u64 time_in_policer_periods;
529
530 time_in_policer_periods =
Damjan Marion3891cd82016-10-27 10:27:00 +0200531 clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700532
533 n_next_nodes = node->n_next_nodes;
534
535 from = vlib_frame_vector_args (frame);
536 n_left_from = frame->n_vectors;
537
538 /* First pass: compute hashes */
539 while (n_left_from > 2)
540 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200541 vlib_buffer_t *b0, *b1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700542 u32 bi0, bi1;
Damjan Marion3891cd82016-10-27 10:27:00 +0200543 u8 *h0, *h1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700544 u32 sw_if_index0, sw_if_index1;
545 u32 table_index0, table_index1;
Damjan Marion3891cd82016-10-27 10:27:00 +0200546 vnet_classify_table_t *t0, *t1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700547
548 /* Prefetch next iteration */
549 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200550 vlib_buffer_t *p1, *p2;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700551
Damjan Marion3891cd82016-10-27 10:27:00 +0200552 p1 = vlib_get_buffer (vm, from[1]);
553 p2 = vlib_get_buffer (vm, from[2]);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700554
Damjan Marion3891cd82016-10-27 10:27:00 +0200555 vlib_prefetch_buffer_header (p1, STORE);
556 CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE);
557 vlib_prefetch_buffer_header (p2, STORE);
558 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700559 }
560
561 bi0 = from[0];
562 b0 = vlib_get_buffer (vm, bi0);
563 h0 = b0->data;
564
565 bi1 = from[1];
566 b1 = vlib_get_buffer (vm, bi1);
567 h1 = b1->data;
568
569 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200570 table_index0 =
571 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700572
573 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200574 table_index1 =
575 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index1];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700576
577 t0 = pool_elt_at_index (vcm->tables, table_index0);
578
579 t1 = pool_elt_at_index (vcm->tables, table_index1);
580
Damjan Marion3891cd82016-10-27 10:27:00 +0200581 vnet_buffer (b0)->l2_classify.hash =
582 vnet_classify_hash_packet (t0, (u8 *) h0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700583
Damjan Marion3891cd82016-10-27 10:27:00 +0200584 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700585
Damjan Marion3891cd82016-10-27 10:27:00 +0200586 vnet_buffer (b1)->l2_classify.hash =
587 vnet_classify_hash_packet (t1, (u8 *) h1);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700588
Damjan Marion3891cd82016-10-27 10:27:00 +0200589 vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700590
Damjan Marion3891cd82016-10-27 10:27:00 +0200591 vnet_buffer (b0)->l2_classify.table_index = table_index0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700592
Damjan Marion3891cd82016-10-27 10:27:00 +0200593 vnet_buffer (b1)->l2_classify.table_index = table_index1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700594
595 from += 2;
596 n_left_from -= 2;
597 }
598
599 while (n_left_from > 0)
600 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200601 vlib_buffer_t *b0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700602 u32 bi0;
Damjan Marion3891cd82016-10-27 10:27:00 +0200603 u8 *h0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700604 u32 sw_if_index0;
605 u32 table_index0;
Damjan Marion3891cd82016-10-27 10:27:00 +0200606 vnet_classify_table_t *t0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700607
608 bi0 = from[0];
609 b0 = vlib_get_buffer (vm, bi0);
610 h0 = b0->data;
611
612 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200613 table_index0 =
614 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700615
616 t0 = pool_elt_at_index (vcm->tables, table_index0);
Damjan Marion3891cd82016-10-27 10:27:00 +0200617 vnet_buffer (b0)->l2_classify.hash =
618 vnet_classify_hash_packet (t0, (u8 *) h0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700619
Damjan Marion3891cd82016-10-27 10:27:00 +0200620 vnet_buffer (b0)->l2_classify.table_index = table_index0;
621 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700622
623 from++;
624 n_left_from--;
625 }
626
627 next_index = node->cached_next_index;
628 from = vlib_frame_vector_args (frame);
629 n_left_from = frame->n_vectors;
630
631 while (n_left_from > 0)
632 {
633 u32 n_left_to_next;
634
635 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
636
637 /* Not enough load/store slots to dual loop... */
638 while (n_left_from > 0 && n_left_to_next > 0)
Damjan Marion3891cd82016-10-27 10:27:00 +0200639 {
640 u32 bi0;
641 vlib_buffer_t *b0;
642 u32 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
643 u32 table_index0;
644 vnet_classify_table_t *t0;
645 vnet_classify_entry_t *e0;
646 u64 hash0;
647 u8 *h0;
648 u8 act0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700649
Damjan Marion3891cd82016-10-27 10:27:00 +0200650 /* Stride 3 seems to work best */
651 if (PREDICT_TRUE (n_left_from > 3))
652 {
653 vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]);
654 vnet_classify_table_t *tp1;
655 u32 table_index1;
656 u64 phash1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700657
Damjan Marion3891cd82016-10-27 10:27:00 +0200658 table_index1 = vnet_buffer (p1)->l2_classify.table_index;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700659
Damjan Marion3891cd82016-10-27 10:27:00 +0200660 if (PREDICT_TRUE (table_index1 != ~0))
661 {
662 tp1 = pool_elt_at_index (vcm->tables, table_index1);
663 phash1 = vnet_buffer (p1)->l2_classify.hash;
664 vnet_classify_prefetch_entry (tp1, phash1);
665 }
666 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700667
Damjan Marion3891cd82016-10-27 10:27:00 +0200668 /* Speculatively enqueue b0 to the current next frame */
669 bi0 = from[0];
670 to_next[0] = bi0;
671 from += 1;
672 to_next += 1;
673 n_left_from -= 1;
674 n_left_to_next -= 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700675
Damjan Marion3891cd82016-10-27 10:27:00 +0200676 b0 = vlib_get_buffer (vm, bi0);
677 h0 = b0->data;
678 table_index0 = vnet_buffer (b0)->l2_classify.table_index;
679 e0 = 0;
680 t0 = 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700681
Damjan Marion3891cd82016-10-27 10:27:00 +0200682 if (tid == POLICER_CLASSIFY_TABLE_L2)
683 {
John Lobeb0b2e2017-07-22 00:21:36 -0400684 /* Feature bitmap update and determine the next node */
685 next0 = vnet_l2_feature_next (b0, pcm->feat_next_node_index,
686 L2INPUT_FEAT_POLICER_CLAS);
Damjan Marion3891cd82016-10-27 10:27:00 +0200687 }
688 else
689 vnet_get_config_data (pcm->vnet_config_main[tid],
690 &b0->current_config_index, &next0,
691 /* # bytes of config data */ 0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700692
Damjan Marion3891cd82016-10-27 10:27:00 +0200693 vnet_buffer (b0)->l2_classify.opaque_index = ~0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700694
Damjan Marion3891cd82016-10-27 10:27:00 +0200695 if (PREDICT_TRUE (table_index0 != ~0))
696 {
697 hash0 = vnet_buffer (b0)->l2_classify.hash;
698 t0 = pool_elt_at_index (vcm->tables, table_index0);
699 e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700700
Damjan Marion3891cd82016-10-27 10:27:00 +0200701 if (e0)
702 {
703 act0 = vnet_policer_police (vm,
704 b0,
705 e0->next_index,
706 time_in_policer_periods,
707 e0->opaque_index);
708 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP))
709 {
710 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
711 b0->error = node->errors[POLICER_CLASSIFY_ERROR_DROP];
712 drop++;
713 }
714 hits++;
715 }
716 else
717 {
718 while (1)
719 {
720 if (PREDICT_TRUE (t0->next_table_index != ~0))
721 {
722 t0 = pool_elt_at_index (vcm->tables,
723 t0->next_table_index);
724 }
725 else
726 {
727 next0 = (t0->miss_next_index < n_next_nodes) ?
728 t0->miss_next_index : next0;
729 misses++;
730 break;
731 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700732
Damjan Marion3891cd82016-10-27 10:27:00 +0200733 hash0 = vnet_classify_hash_packet (t0, (u8 *) h0);
734 e0 =
735 vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
736 if (e0)
737 {
738 act0 = vnet_policer_police (vm,
739 b0,
740 e0->next_index,
741 time_in_policer_periods,
742 e0->opaque_index);
743 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP))
744 {
745 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
746 b0->error =
747 node->errors[POLICER_CLASSIFY_ERROR_DROP];
748 drop++;
749 }
750 hits++;
751 chain_hits++;
752 break;
753 }
754 }
755 }
756 }
757 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
758 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
759 {
760 policer_classify_trace_t *t =
761 vlib_add_trace (vm, node, b0, sizeof (*t));
762 t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
763 t->next_index = next0;
764 t->table_index = t0 ? t0 - vcm->tables : ~0;
765 t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0;
766 t->policer_index = e0 ? e0->next_index : ~0;
767 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700768
Damjan Marion3891cd82016-10-27 10:27:00 +0200769 /* Verify speculative enqueue, maybe switch current next frame */
770 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
771 n_left_to_next, bi0, next0);
772 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700773
774 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
775 }
776
777 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200778 POLICER_CLASSIFY_ERROR_MISS, misses);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700779 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200780 POLICER_CLASSIFY_ERROR_HIT, hits);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700781 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200782 POLICER_CLASSIFY_ERROR_CHAIN_HIT, chain_hits);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700783 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200784 POLICER_CLASSIFY_ERROR_DROP, drop);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700785
786 return frame->n_vectors;
787}
788
789static uword
790ip4_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200791 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700792{
Damjan Marion3891cd82016-10-27 10:27:00 +0200793 return policer_classify_inline (vm, node, frame,
794 POLICER_CLASSIFY_TABLE_IP4);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700795}
796
Damjan Marion3891cd82016-10-27 10:27:00 +0200797/* *INDENT-OFF* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700798VLIB_REGISTER_NODE (ip4_policer_classify_node) = {
799 .function = ip4_policer_classify,
800 .name = "ip4-policer-classify",
801 .vector_size = sizeof (u32),
802 .format_trace = format_policer_classify_trace,
803 .n_errors = ARRAY_LEN(policer_classify_error_strings),
804 .error_strings = policer_classify_error_strings,
805 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
806 .next_nodes = {
807 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
808 },
809};
810
811VLIB_NODE_FUNCTION_MULTIARCH (ip4_policer_classify_node, ip4_policer_classify);
Damjan Marion3891cd82016-10-27 10:27:00 +0200812/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700813
814static uword
815ip6_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200816 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700817{
Damjan Marion3891cd82016-10-27 10:27:00 +0200818 return policer_classify_inline (vm, node, frame,
819 POLICER_CLASSIFY_TABLE_IP6);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700820}
821
Damjan Marion3891cd82016-10-27 10:27:00 +0200822/* *INDENT-OFF* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700823VLIB_REGISTER_NODE (ip6_policer_classify_node) = {
824 .function = ip6_policer_classify,
825 .name = "ip6-policer-classify",
826 .vector_size = sizeof (u32),
827 .format_trace = format_policer_classify_trace,
828 .n_errors = ARRAY_LEN(policer_classify_error_strings),
829 .error_strings = policer_classify_error_strings,
830 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
831 .next_nodes = {
832 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
833 },
834};
835
836VLIB_NODE_FUNCTION_MULTIARCH (ip6_policer_classify_node, ip6_policer_classify);
Damjan Marion3891cd82016-10-27 10:27:00 +0200837/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700838
839static uword
840l2_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200841 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700842{
Damjan Marion3891cd82016-10-27 10:27:00 +0200843 return policer_classify_inline (vm, node, frame, POLICER_CLASSIFY_TABLE_L2);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700844}
845
Krishanpal singhd2fec4a2017-11-27 19:40:56 +0530846/* *INDENT-OFF* */
847VLIB_REGISTER_NODE (l2_policer_classify_node) = {
848 .function = l2_policer_classify,
849 .name = "l2-policer-classify",
850 .vector_size = sizeof (u32),
851 .format_trace = format_policer_classify_trace,
852 .n_errors = ARRAY_LEN (policer_classify_error_strings),
853 .error_strings = policer_classify_error_strings,
854 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
855 .next_nodes = {
856 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
857 },
858};
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700859
860VLIB_NODE_FUNCTION_MULTIARCH (l2_policer_classify_node, l2_policer_classify);
Krishanpal singhd2fec4a2017-11-27 19:40:56 +0530861/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700862
863static clib_error_t *
Damjan Marion3891cd82016-10-27 10:27:00 +0200864policer_classify_init (vlib_main_t * vm)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700865{
Damjan Marion3891cd82016-10-27 10:27:00 +0200866 policer_classify_main_t *pcm = &policer_classify_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700867
868 pcm->vlib_main = vm;
Damjan Marion3891cd82016-10-27 10:27:00 +0200869 pcm->vnet_main = vnet_get_main ();
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700870 pcm->vnet_classify_main = &vnet_classify_main;
871
872 /* Initialize L2 feature next-node indexes */
Damjan Marion3891cd82016-10-27 10:27:00 +0200873 feat_bitmap_init_next_nodes (vm,
874 l2_policer_classify_node.index,
875 L2INPUT_N_FEAT,
876 l2input_get_feat_names (),
877 pcm->feat_next_node_index);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700878
879 return 0;
880}
881
882VLIB_INIT_FUNCTION (policer_classify_init);
Damjan Marion3891cd82016-10-27 10:27:00 +0200883
884/*
885 * fd.io coding-style-patch-verification: ON
886 *
887 * Local Variables:
888 * eval: (c-set-style "gnu")
889 * End:
890 */