blob: 9a25dbb3cc6ce0511a5cb1515269baafac2c71e1 [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>
Matus Fabian4ac74c92016-05-31 07:33:29 -070025
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
27/* Dispatch functions meant to be instantiated elsewhere */
28
Damjan Marion3891cd82016-10-27 10:27:00 +020029typedef struct
30{
Ed Warnickecb9cada2015-12-08 15:45:58 -070031 u32 next_index;
32 u32 sw_if_index;
33 u32 policer_index;
34} vnet_policer_trace_t;
35
36/* packet trace format function */
Damjan Marion3891cd82016-10-27 10:27:00 +020037static u8 *
38format_policer_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070039{
40 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
41 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Damjan Marion3891cd82016-10-27 10:27:00 +020042 vnet_policer_trace_t *t = va_arg (*args, vnet_policer_trace_t *);
43
Ed Warnickecb9cada2015-12-08 15:45:58 -070044 s = format (s, "VNET_POLICER: sw_if_index %d policer_index %d next %d",
Damjan Marion3891cd82016-10-27 10:27:00 +020045 t->sw_if_index, t->policer_index, t->next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070046 return s;
47}
48
49#define foreach_vnet_policer_error \
50_(TRANSMIT, "Packets Transmitted") \
51_(DROP, "Packets Dropped")
52
Damjan Marion3891cd82016-10-27 10:27:00 +020053typedef enum
54{
Ed Warnickecb9cada2015-12-08 15:45:58 -070055#define _(sym,str) VNET_POLICER_ERROR_##sym,
56 foreach_vnet_policer_error
57#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +020058 VNET_POLICER_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -070059} vnet_policer_error_t;
60
Damjan Marion3891cd82016-10-27 10:27:00 +020061static char *vnet_policer_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070062#define _(sym,string) string,
63 foreach_vnet_policer_error
64#undef _
65};
66
Damjan Marion3891cd82016-10-27 10:27:00 +020067static inline uword
68vnet_policer_inline (vlib_main_t * vm,
69 vlib_node_runtime_t * node,
70 vlib_frame_t * frame, vnet_policer_index_t which)
Ed Warnickecb9cada2015-12-08 15:45:58 -070071{
Damjan Marion3891cd82016-10-27 10:27:00 +020072 u32 n_left_from, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 vnet_policer_next_t next_index;
Damjan Marion3891cd82016-10-27 10:27:00 +020074 vnet_policer_main_t *pm = &vnet_policer_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 u64 time_in_policer_periods;
76 u32 transmitted = 0;
77
Damjan Marion3891cd82016-10-27 10:27:00 +020078 time_in_policer_periods =
79 clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 from = vlib_frame_vector_args (frame);
82 n_left_from = frame->n_vectors;
83 next_index = node->cached_next_index;
84
85 while (n_left_from > 0)
86 {
87 u32 n_left_to_next;
88
Damjan Marion3891cd82016-10-27 10:27:00 +020089 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -070090
91 while (n_left_from >= 4 && n_left_to_next >= 2)
92 {
Damjan Marion3891cd82016-10-27 10:27:00 +020093 u32 bi0, bi1;
94 vlib_buffer_t *b0, *b1;
95 u32 next0, next1;
96 u32 sw_if_index0, sw_if_index1;
97 u32 pi0 = 0, pi1 = 0;
98 u8 act0, act1;
99
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 /* Prefetch next iteration. */
101 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200102 vlib_buffer_t *b2, *b3;
103
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104 b2 = vlib_get_buffer (vm, from[2]);
105 b3 = vlib_get_buffer (vm, from[3]);
Damjan Marion3891cd82016-10-27 10:27:00 +0200106
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107 vlib_prefetch_buffer_header (b2, LOAD);
108 vlib_prefetch_buffer_header (b3, LOAD);
109 }
110
Damjan Marion3891cd82016-10-27 10:27:00 +0200111 /* speculatively enqueue b0 and b1 to the current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112 to_next[0] = bi0 = from[0];
113 to_next[1] = bi1 = from[1];
114 from += 2;
115 to_next += 2;
116 n_left_from -= 2;
117 n_left_to_next -= 2;
118
119 b0 = vlib_get_buffer (vm, bi0);
120 b1 = vlib_get_buffer (vm, bi1);
121
Damjan Marion3891cd82016-10-27 10:27:00 +0200122 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
123 next0 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
Damjan Marion3891cd82016-10-27 10:27:00 +0200125 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
126 next1 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127
128
Damjan Marion3891cd82016-10-27 10:27:00 +0200129 if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX)
130 {
131 pi0 = pm->policer_index_by_sw_if_index[sw_if_index0];
132 pi1 = pm->policer_index_by_sw_if_index[sw_if_index1];
133 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Damjan Marion3891cd82016-10-27 10:27:00 +0200135 if (which == VNET_POLICER_INDEX_BY_OPAQUE)
136 {
137 pi0 = vnet_buffer (b0)->policer.index;
138 pi1 = vnet_buffer (b1)->policer.index;
139 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140
Damjan Marion3891cd82016-10-27 10:27:00 +0200141 if (which == VNET_POLICER_INDEX_BY_EITHER)
142 {
143 pi0 = vnet_buffer (b0)->policer.index;
144 pi0 = (pi0 != ~0) ? pi0 :
145 pm->policer_index_by_sw_if_index[sw_if_index0];
146 pi1 = vnet_buffer (b1)->policer.index;
147 pi1 = (pi1 != ~0) ? pi1 :
148 pm->policer_index_by_sw_if_index[sw_if_index1];
149 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150
Damjan Marion3891cd82016-10-27 10:27:00 +0200151 act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods,
152 POLICE_CONFORM /* no chaining */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
Damjan Marion3891cd82016-10-27 10:27:00 +0200154 act1 = vnet_policer_police (vm, b1, pi1, time_in_policer_periods,
155 POLICE_CONFORM /* no chaining */ );
Matus Fabian4ac74c92016-05-31 07:33:29 -0700156
Damjan Marion3891cd82016-10-27 10:27:00 +0200157 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */
158 {
159 next0 = VNET_POLICER_NEXT_DROP;
160 b0->error = node->errors[VNET_POLICER_ERROR_DROP];
161 }
162 else /* transmit or mark-and-transmit action */
163 {
164 transmitted++;
165 }
Matus Fabian4ac74c92016-05-31 07:33:29 -0700166
Damjan Marion3891cd82016-10-27 10:27:00 +0200167 if (PREDICT_FALSE (act1 == SSE2_QOS_ACTION_DROP)) /* drop action */
168 {
169 next1 = VNET_POLICER_NEXT_DROP;
170 b1->error = node->errors[VNET_POLICER_ERROR_DROP];
171 }
172 else /* transmit or mark-and-transmit action */
173 {
174 transmitted++;
175 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700176
177
Damjan Marion3891cd82016-10-27 10:27:00 +0200178 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
179 {
180 if (b0->flags & VLIB_BUFFER_IS_TRACED)
181 {
182 vnet_policer_trace_t *t =
183 vlib_add_trace (vm, node, b0, sizeof (*t));
184 t->sw_if_index = sw_if_index0;
185 t->next_index = next0;
186 }
187 if (b1->flags & VLIB_BUFFER_IS_TRACED)
188 {
189 vnet_policer_trace_t *t =
190 vlib_add_trace (vm, node, b1, sizeof (*t));
191 t->sw_if_index = sw_if_index1;
192 t->next_index = next1;
193 }
194 }
195
196 /* verify speculative enqueues, maybe switch current next frame */
197 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
198 to_next, n_left_to_next,
199 bi0, bi1, next0, next1);
200 }
201
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202 while (n_left_from > 0 && n_left_to_next > 0)
203 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200204 u32 bi0;
205 vlib_buffer_t *b0;
206 u32 next0;
207 u32 sw_if_index0;
208 u32 pi0 = 0;
209 u8 act0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210
211 bi0 = from[0];
212 to_next[0] = bi0;
213 from += 1;
214 to_next += 1;
215 n_left_from -= 1;
216 n_left_to_next -= 1;
217
218 b0 = vlib_get_buffer (vm, bi0);
219
Damjan Marion3891cd82016-10-27 10:27:00 +0200220 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
221 next0 = VNET_POLICER_NEXT_TRANSMIT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222
Damjan Marion3891cd82016-10-27 10:27:00 +0200223 if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX)
224 pi0 = pm->policer_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225
Damjan Marion3891cd82016-10-27 10:27:00 +0200226 if (which == VNET_POLICER_INDEX_BY_OPAQUE)
227 pi0 = vnet_buffer (b0)->policer.index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228
Damjan Marion3891cd82016-10-27 10:27:00 +0200229 if (which == VNET_POLICER_INDEX_BY_EITHER)
230 {
231 pi0 = vnet_buffer (b0)->policer.index;
232 pi0 = (pi0 != ~0) ? pi0 :
233 pm->policer_index_by_sw_if_index[sw_if_index0];
234 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
Damjan Marion3891cd82016-10-27 10:27:00 +0200236 act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods,
237 POLICE_CONFORM /* no chaining */ );
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700238
Damjan Marion3891cd82016-10-27 10:27:00 +0200239 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */
240 {
241 next0 = VNET_POLICER_NEXT_DROP;
242 b0->error = node->errors[VNET_POLICER_ERROR_DROP];
243 }
244 else /* transmit or mark-and-transmit action */
245 {
246 transmitted++;
247 }
248
249 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
250 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
251 {
252 vnet_policer_trace_t *t =
253 vlib_add_trace (vm, node, b0, sizeof (*t));
254 t->sw_if_index = sw_if_index0;
255 t->next_index = next0;
256 t->policer_index = pi0;
257 }
258
259 /* verify speculative enqueue, maybe switch current next frame */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
261 to_next, n_left_to_next,
262 bi0, next0);
263 }
264
265 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
266 }
267
Damjan Marion3891cd82016-10-27 10:27:00 +0200268 vlib_node_increment_counter (vm, node->node_index,
269 VNET_POLICER_ERROR_TRANSMIT, transmitted);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270 return frame->n_vectors;
271}
272
Damjan Marion3891cd82016-10-27 10:27:00 +0200273uword
274vnet_policer_by_sw_if_index (vlib_main_t * vm,
275 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700276{
Damjan Marion3891cd82016-10-27 10:27:00 +0200277 return vnet_policer_inline (vm, node, frame,
278 VNET_POLICER_INDEX_BY_SW_IF_INDEX);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279}
280
Damjan Marion3891cd82016-10-27 10:27:00 +0200281uword
282vnet_policer_by_opaque (vlib_main_t * vm,
283 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284{
Damjan Marion3891cd82016-10-27 10:27:00 +0200285 return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_OPAQUE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700286}
287
Damjan Marion3891cd82016-10-27 10:27:00 +0200288uword
289vnet_policer_by_either (vlib_main_t * vm,
290 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291{
Damjan Marion3891cd82016-10-27 10:27:00 +0200292 return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_EITHER);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293}
294
Damjan Marion3891cd82016-10-27 10:27:00 +0200295void
296vnet_policer_node_funcs_reference (void)
297{
298}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299
300
301#define TEST_CODE 1
302
303#ifdef TEST_CODE
304
Damjan Marion3891cd82016-10-27 10:27:00 +0200305/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306VLIB_REGISTER_NODE (policer_by_sw_if_index_node, static) = {
307 .function = vnet_policer_by_sw_if_index,
308 .name = "policer-by-sw-if-index",
309 .vector_size = sizeof (u32),
310 .format_trace = format_policer_trace,
311 .type = VLIB_NODE_TYPE_INTERNAL,
Damjan Marion3891cd82016-10-27 10:27:00 +0200312
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313 .n_errors = ARRAY_LEN(vnet_policer_error_strings),
314 .error_strings = vnet_policer_error_strings,
Damjan Marion3891cd82016-10-27 10:27:00 +0200315
Ed Warnickecb9cada2015-12-08 15:45:58 -0700316 .n_next_nodes = VNET_POLICER_N_NEXT,
317
318 /* edit / add dispositions here */
319 .next_nodes = {
320 [VNET_POLICER_NEXT_TRANSMIT] = "ethernet-input",
321 [VNET_POLICER_NEXT_DROP] = "error-drop",
322 },
323};
324
Damjan Marion1c80e832016-05-11 23:07:18 +0200325VLIB_NODE_FUNCTION_MULTIARCH (policer_by_sw_if_index_node,
326 vnet_policer_by_sw_if_index);
Damjan Marion3891cd82016-10-27 10:27:00 +0200327/* *INDENT-ON* */
Damjan Marion1c80e832016-05-11 23:07:18 +0200328
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
Damjan Marion3891cd82016-10-27 10:27:00 +0200330int
331test_policer_add_del (u32 rx_sw_if_index, u8 * config_name, int is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332{
Damjan Marion3891cd82016-10-27 10:27:00 +0200333 vnet_policer_main_t *pm = &vnet_policer_main;
334 policer_read_response_type_st *template;
335 policer_read_response_type_st *policer;
336 vnet_hw_interface_t *rxhi;
337 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700338
339 rxhi = vnet_get_sup_hw_interface (pm->vnet_main, rx_sw_if_index);
340
341 /* Make sure caller didn't pass a vlan subif, etc. */
342 if (rxhi->sw_if_index != rx_sw_if_index)
343 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
344
345 if (is_add)
346 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200347
Ed Warnickecb9cada2015-12-08 15:45:58 -0700348 p = hash_get_mem (pm->policer_config_by_name, config_name);
349
350 if (p == 0)
Damjan Marion3891cd82016-10-27 10:27:00 +0200351 return -2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352
353 template = pool_elt_at_index (pm->policer_templates, p[0]);
354
Damjan Marion3891cd82016-10-27 10:27:00 +0200355 vnet_hw_interface_rx_redirect_to_node
356 (pm->vnet_main, rxhi->hw_if_index, policer_by_sw_if_index_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
358 pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES);
359
360 policer[0] = template[0];
361
362 vec_validate (pm->policer_index_by_sw_if_index, rx_sw_if_index);
Damjan Marion3891cd82016-10-27 10:27:00 +0200363 pm->policer_index_by_sw_if_index[rx_sw_if_index]
364 = policer - pm->policers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700365 }
366 else
367 {
368 u32 pi;
Damjan Marion3891cd82016-10-27 10:27:00 +0200369 vnet_hw_interface_rx_redirect_to_node (pm->vnet_main,
370 rxhi->hw_if_index,
371 ~0 /* disable */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372
373 pi = pm->policer_index_by_sw_if_index[rx_sw_if_index];
374 pm->policer_index_by_sw_if_index[rx_sw_if_index] = ~0;
375 pool_put_index (pm->policers, pi);
376 }
Damjan Marion3891cd82016-10-27 10:27:00 +0200377
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378 return 0;
379}
380
381static clib_error_t *
382test_policer_command_fn (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200383 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700384{
Damjan Marion3891cd82016-10-27 10:27:00 +0200385 vnet_policer_main_t *pm = &vnet_policer_main;
386 unformat_input_t _line_input, *line_input = &_line_input;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700387 u32 rx_sw_if_index;
388 int rv;
Damjan Marion3891cd82016-10-27 10:27:00 +0200389 u8 *config_name = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 int rx_set = 0;
391 int is_add = 1;
392 int is_show = 0;
Billy McFalla9a20e72017-02-15 11:39:12 -0500393 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394
395 /* Get a line of input. */
Damjan Marion3891cd82016-10-27 10:27:00 +0200396 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700397 return 0;
398
399 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
400 {
401 if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface,
Damjan Marion3891cd82016-10-27 10:27:00 +0200402 pm->vnet_main, &rx_sw_if_index))
403 rx_set = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404 else if (unformat (line_input, "show"))
Damjan Marion3891cd82016-10-27 10:27:00 +0200405 is_show = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406 else if (unformat (line_input, "policer %s", &config_name))
Damjan Marion3891cd82016-10-27 10:27:00 +0200407 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408 else if (unformat (line_input, "del"))
Damjan Marion3891cd82016-10-27 10:27:00 +0200409 is_add = 0;
410 else
411 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412 }
413
414 if (rx_set == 0)
Billy McFalla9a20e72017-02-15 11:39:12 -0500415 {
416 error = clib_error_return (0, "interface not set");
417 goto done;
418 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419
420 if (is_show)
421 {
422 u32 pi = pm->policer_index_by_sw_if_index[rx_sw_if_index];
Damjan Marion3891cd82016-10-27 10:27:00 +0200423 policer_read_response_type_st *policer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424 policer = pool_elt_at_index (pm->policers, pi);
Damjan Marion3891cd82016-10-27 10:27:00 +0200425
Ed Warnickecb9cada2015-12-08 15:45:58 -0700426 vlib_cli_output (vm, "%U", format_policer_instance, policer);
Billy McFalla9a20e72017-02-15 11:39:12 -0500427 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428 }
429
430 if (is_add && config_name == 0)
431 {
Billy McFalla9a20e72017-02-15 11:39:12 -0500432 error = clib_error_return (0, "policer config name required");
433 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434 }
435
436 rv = test_policer_add_del (rx_sw_if_index, config_name, is_add);
437
438 switch (rv)
439 {
440 case 0:
441 break;
442
443 default:
Billy McFalla9a20e72017-02-15 11:39:12 -0500444 error = clib_error_return
Damjan Marion3891cd82016-10-27 10:27:00 +0200445 (0, "WARNING: vnet_vnet_policer_add_del returned %d", rv);
Billy McFalla9a20e72017-02-15 11:39:12 -0500446 goto done;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 }
Damjan Marion3891cd82016-10-27 10:27:00 +0200448
Billy McFalla9a20e72017-02-15 11:39:12 -0500449done:
450 unformat_free (line_input);
451
452 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453}
454
Damjan Marion3891cd82016-10-27 10:27:00 +0200455/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700456VLIB_CLI_COMMAND (test_patch_command, static) = {
457 .path = "test policer",
Damjan Marion3891cd82016-10-27 10:27:00 +0200458 .short_help =
Ed Warnickecb9cada2015-12-08 15:45:58 -0700459 "intfc <intfc> policer <policer-config-name> [del]",
460 .function = test_policer_command_fn,
461};
Damjan Marion3891cd82016-10-27 10:27:00 +0200462/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700463
464#endif /* TEST_CODE */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700465
466
Damjan Marion3891cd82016-10-27 10:27:00 +0200467typedef struct
468{
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700469 u32 sw_if_index;
470 u32 next_index;
471 u32 table_index;
472 u32 offset;
473 u32 policer_index;
474} policer_classify_trace_t;
475
476static u8 *
477format_policer_classify_trace (u8 * s, va_list * args)
478{
479 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
480 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Damjan Marion3891cd82016-10-27 10:27:00 +0200481 policer_classify_trace_t *t = va_arg (*args, policer_classify_trace_t *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700482
483 s = format (s, "POLICER_CLASSIFY: sw_if_index %d next %d table %d offset %d"
Damjan Marion3891cd82016-10-27 10:27:00 +0200484 " policer_index %d",
485 t->sw_if_index, t->next_index, t->table_index, t->offset,
486 t->policer_index);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700487 return s;
488}
489
490#define foreach_policer_classify_error \
491_(MISS, "Policer classify misses") \
492_(HIT, "Policer classify hits") \
493_(CHAIN_HIT, "Polcier classify hits after chain walk") \
494_(DROP, "Policer classify action drop")
495
Damjan Marion3891cd82016-10-27 10:27:00 +0200496typedef enum
497{
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700498#define _(sym,str) POLICER_CLASSIFY_ERROR_##sym,
499 foreach_policer_classify_error
500#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +0200501 POLICER_CLASSIFY_N_ERROR,
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700502} policer_classify_error_t;
503
Damjan Marion3891cd82016-10-27 10:27:00 +0200504static char *policer_classify_error_strings[] = {
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700505#define _(sym,string) string,
506 foreach_policer_classify_error
507#undef _
508};
509
510static inline uword
511policer_classify_inline (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200512 vlib_node_runtime_t * node,
513 vlib_frame_t * frame,
514 policer_classify_table_id_t tid)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700515{
Damjan Marion3891cd82016-10-27 10:27:00 +0200516 u32 n_left_from, *from, *to_next;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700517 policer_classify_next_index_t next_index;
Damjan Marion3891cd82016-10-27 10:27:00 +0200518 policer_classify_main_t *pcm = &policer_classify_main;
519 vnet_classify_main_t *vcm = pcm->vnet_classify_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700520 f64 now = vlib_time_now (vm);
521 u32 hits = 0;
522 u32 misses = 0;
523 u32 chain_hits = 0;
524 u32 drop = 0;
525 u32 n_next_nodes;
526 u64 time_in_policer_periods;
527
528 time_in_policer_periods =
Damjan Marion3891cd82016-10-27 10:27:00 +0200529 clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700530
531 n_next_nodes = node->n_next_nodes;
532
533 from = vlib_frame_vector_args (frame);
534 n_left_from = frame->n_vectors;
535
536 /* First pass: compute hashes */
537 while (n_left_from > 2)
538 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200539 vlib_buffer_t *b0, *b1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700540 u32 bi0, bi1;
Damjan Marion3891cd82016-10-27 10:27:00 +0200541 u8 *h0, *h1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700542 u32 sw_if_index0, sw_if_index1;
543 u32 table_index0, table_index1;
Damjan Marion3891cd82016-10-27 10:27:00 +0200544 vnet_classify_table_t *t0, *t1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700545
546 /* Prefetch next iteration */
547 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200548 vlib_buffer_t *p1, *p2;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700549
Damjan Marion3891cd82016-10-27 10:27:00 +0200550 p1 = vlib_get_buffer (vm, from[1]);
551 p2 = vlib_get_buffer (vm, from[2]);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700552
Damjan Marion3891cd82016-10-27 10:27:00 +0200553 vlib_prefetch_buffer_header (p1, STORE);
554 CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE);
555 vlib_prefetch_buffer_header (p2, STORE);
556 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700557 }
558
559 bi0 = from[0];
560 b0 = vlib_get_buffer (vm, bi0);
561 h0 = b0->data;
562
563 bi1 = from[1];
564 b1 = vlib_get_buffer (vm, bi1);
565 h1 = b1->data;
566
567 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200568 table_index0 =
569 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700570
571 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200572 table_index1 =
573 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index1];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700574
575 t0 = pool_elt_at_index (vcm->tables, table_index0);
576
577 t1 = pool_elt_at_index (vcm->tables, table_index1);
578
Damjan Marion3891cd82016-10-27 10:27:00 +0200579 vnet_buffer (b0)->l2_classify.hash =
580 vnet_classify_hash_packet (t0, (u8 *) h0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700581
Damjan Marion3891cd82016-10-27 10:27:00 +0200582 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700583
Damjan Marion3891cd82016-10-27 10:27:00 +0200584 vnet_buffer (b1)->l2_classify.hash =
585 vnet_classify_hash_packet (t1, (u8 *) h1);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700586
Damjan Marion3891cd82016-10-27 10:27:00 +0200587 vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700588
Damjan Marion3891cd82016-10-27 10:27:00 +0200589 vnet_buffer (b0)->l2_classify.table_index = table_index0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700590
Damjan Marion3891cd82016-10-27 10:27:00 +0200591 vnet_buffer (b1)->l2_classify.table_index = table_index1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700592
593 from += 2;
594 n_left_from -= 2;
595 }
596
597 while (n_left_from > 0)
598 {
Damjan Marion3891cd82016-10-27 10:27:00 +0200599 vlib_buffer_t *b0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700600 u32 bi0;
Damjan Marion3891cd82016-10-27 10:27:00 +0200601 u8 *h0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700602 u32 sw_if_index0;
603 u32 table_index0;
Damjan Marion3891cd82016-10-27 10:27:00 +0200604 vnet_classify_table_t *t0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700605
606 bi0 = from[0];
607 b0 = vlib_get_buffer (vm, bi0);
608 h0 = b0->data;
609
610 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
Damjan Marion3891cd82016-10-27 10:27:00 +0200611 table_index0 =
612 pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0];
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700613
614 t0 = pool_elt_at_index (vcm->tables, table_index0);
Damjan Marion3891cd82016-10-27 10:27:00 +0200615 vnet_buffer (b0)->l2_classify.hash =
616 vnet_classify_hash_packet (t0, (u8 *) h0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700617
Damjan Marion3891cd82016-10-27 10:27:00 +0200618 vnet_buffer (b0)->l2_classify.table_index = table_index0;
619 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700620
621 from++;
622 n_left_from--;
623 }
624
625 next_index = node->cached_next_index;
626 from = vlib_frame_vector_args (frame);
627 n_left_from = frame->n_vectors;
628
629 while (n_left_from > 0)
630 {
631 u32 n_left_to_next;
632
633 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
634
635 /* Not enough load/store slots to dual loop... */
636 while (n_left_from > 0 && n_left_to_next > 0)
Damjan Marion3891cd82016-10-27 10:27:00 +0200637 {
638 u32 bi0;
639 vlib_buffer_t *b0;
640 u32 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
641 u32 table_index0;
642 vnet_classify_table_t *t0;
643 vnet_classify_entry_t *e0;
644 u64 hash0;
645 u8 *h0;
646 u8 act0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700647
Damjan Marion3891cd82016-10-27 10:27:00 +0200648 /* Stride 3 seems to work best */
649 if (PREDICT_TRUE (n_left_from > 3))
650 {
651 vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]);
652 vnet_classify_table_t *tp1;
653 u32 table_index1;
654 u64 phash1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700655
Damjan Marion3891cd82016-10-27 10:27:00 +0200656 table_index1 = vnet_buffer (p1)->l2_classify.table_index;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700657
Damjan Marion3891cd82016-10-27 10:27:00 +0200658 if (PREDICT_TRUE (table_index1 != ~0))
659 {
660 tp1 = pool_elt_at_index (vcm->tables, table_index1);
661 phash1 = vnet_buffer (p1)->l2_classify.hash;
662 vnet_classify_prefetch_entry (tp1, phash1);
663 }
664 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700665
Damjan Marion3891cd82016-10-27 10:27:00 +0200666 /* Speculatively enqueue b0 to the current next frame */
667 bi0 = from[0];
668 to_next[0] = bi0;
669 from += 1;
670 to_next += 1;
671 n_left_from -= 1;
672 n_left_to_next -= 1;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700673
Damjan Marion3891cd82016-10-27 10:27:00 +0200674 b0 = vlib_get_buffer (vm, bi0);
675 h0 = b0->data;
676 table_index0 = vnet_buffer (b0)->l2_classify.table_index;
677 e0 = 0;
678 t0 = 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700679
Damjan Marion3891cd82016-10-27 10:27:00 +0200680 if (tid == POLICER_CLASSIFY_TABLE_L2)
681 {
John Lobeb0b2e2017-07-22 00:21:36 -0400682 /* Feature bitmap update and determine the next node */
683 next0 = vnet_l2_feature_next (b0, pcm->feat_next_node_index,
684 L2INPUT_FEAT_POLICER_CLAS);
Damjan Marion3891cd82016-10-27 10:27:00 +0200685 }
686 else
687 vnet_get_config_data (pcm->vnet_config_main[tid],
688 &b0->current_config_index, &next0,
689 /* # bytes of config data */ 0);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700690
Damjan Marion3891cd82016-10-27 10:27:00 +0200691 vnet_buffer (b0)->l2_classify.opaque_index = ~0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700692
Damjan Marion3891cd82016-10-27 10:27:00 +0200693 if (PREDICT_TRUE (table_index0 != ~0))
694 {
695 hash0 = vnet_buffer (b0)->l2_classify.hash;
696 t0 = pool_elt_at_index (vcm->tables, table_index0);
697 e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700698
Damjan Marion3891cd82016-10-27 10:27:00 +0200699 if (e0)
700 {
701 act0 = vnet_policer_police (vm,
702 b0,
703 e0->next_index,
704 time_in_policer_periods,
705 e0->opaque_index);
706 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP))
707 {
708 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
709 b0->error = node->errors[POLICER_CLASSIFY_ERROR_DROP];
710 drop++;
711 }
712 hits++;
713 }
714 else
715 {
716 while (1)
717 {
718 if (PREDICT_TRUE (t0->next_table_index != ~0))
719 {
720 t0 = pool_elt_at_index (vcm->tables,
721 t0->next_table_index);
722 }
723 else
724 {
725 next0 = (t0->miss_next_index < n_next_nodes) ?
726 t0->miss_next_index : next0;
727 misses++;
728 break;
729 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700730
Damjan Marion3891cd82016-10-27 10:27:00 +0200731 hash0 = vnet_classify_hash_packet (t0, (u8 *) h0);
732 e0 =
733 vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
734 if (e0)
735 {
736 act0 = vnet_policer_police (vm,
737 b0,
738 e0->next_index,
739 time_in_policer_periods,
740 e0->opaque_index);
741 if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP))
742 {
743 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP;
744 b0->error =
745 node->errors[POLICER_CLASSIFY_ERROR_DROP];
746 drop++;
747 }
748 hits++;
749 chain_hits++;
750 break;
751 }
752 }
753 }
754 }
755 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
756 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
757 {
758 policer_classify_trace_t *t =
759 vlib_add_trace (vm, node, b0, sizeof (*t));
760 t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
761 t->next_index = next0;
762 t->table_index = t0 ? t0 - vcm->tables : ~0;
763 t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0;
764 t->policer_index = e0 ? e0->next_index : ~0;
765 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700766
Damjan Marion3891cd82016-10-27 10:27:00 +0200767 /* Verify speculative enqueue, maybe switch current next frame */
768 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
769 n_left_to_next, bi0, next0);
770 }
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700771
772 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
773 }
774
775 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200776 POLICER_CLASSIFY_ERROR_MISS, misses);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700777 vlib_node_increment_counter (vm, node->node_index,
Damjan Marion3891cd82016-10-27 10:27:00 +0200778 POLICER_CLASSIFY_ERROR_HIT, hits);
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_CHAIN_HIT, chain_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_DROP, drop);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700783
784 return frame->n_vectors;
785}
786
787static uword
788ip4_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200789 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700790{
Damjan Marion3891cd82016-10-27 10:27:00 +0200791 return policer_classify_inline (vm, node, frame,
792 POLICER_CLASSIFY_TABLE_IP4);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700793}
794
Damjan Marion3891cd82016-10-27 10:27:00 +0200795/* *INDENT-OFF* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700796VLIB_REGISTER_NODE (ip4_policer_classify_node) = {
797 .function = ip4_policer_classify,
798 .name = "ip4-policer-classify",
799 .vector_size = sizeof (u32),
800 .format_trace = format_policer_classify_trace,
801 .n_errors = ARRAY_LEN(policer_classify_error_strings),
802 .error_strings = policer_classify_error_strings,
803 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
804 .next_nodes = {
805 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
806 },
807};
808
809VLIB_NODE_FUNCTION_MULTIARCH (ip4_policer_classify_node, ip4_policer_classify);
Damjan Marion3891cd82016-10-27 10:27:00 +0200810/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700811
812static uword
813ip6_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200814 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700815{
Damjan Marion3891cd82016-10-27 10:27:00 +0200816 return policer_classify_inline (vm, node, frame,
817 POLICER_CLASSIFY_TABLE_IP6);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700818}
819
Damjan Marion3891cd82016-10-27 10:27:00 +0200820/* *INDENT-OFF* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700821VLIB_REGISTER_NODE (ip6_policer_classify_node) = {
822 .function = ip6_policer_classify,
823 .name = "ip6-policer-classify",
824 .vector_size = sizeof (u32),
825 .format_trace = format_policer_classify_trace,
826 .n_errors = ARRAY_LEN(policer_classify_error_strings),
827 .error_strings = policer_classify_error_strings,
828 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
829 .next_nodes = {
830 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
831 },
832};
833
834VLIB_NODE_FUNCTION_MULTIARCH (ip6_policer_classify_node, ip6_policer_classify);
Damjan Marion3891cd82016-10-27 10:27:00 +0200835/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700836
837static uword
838l2_policer_classify (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200839 vlib_node_runtime_t * node, vlib_frame_t * frame)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700840{
Damjan Marion3891cd82016-10-27 10:27:00 +0200841 return policer_classify_inline (vm, node, frame, POLICER_CLASSIFY_TABLE_L2);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700842}
843
Krishanpal singhd2fec4a2017-11-27 19:40:56 +0530844/* *INDENT-OFF* */
845VLIB_REGISTER_NODE (l2_policer_classify_node) = {
846 .function = l2_policer_classify,
847 .name = "l2-policer-classify",
848 .vector_size = sizeof (u32),
849 .format_trace = format_policer_classify_trace,
850 .n_errors = ARRAY_LEN (policer_classify_error_strings),
851 .error_strings = policer_classify_error_strings,
852 .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,
853 .next_nodes = {
854 [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",
855 },
856};
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700857
858VLIB_NODE_FUNCTION_MULTIARCH (l2_policer_classify_node, l2_policer_classify);
Krishanpal singhd2fec4a2017-11-27 19:40:56 +0530859/* *INDENT-ON* */
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700860
861static clib_error_t *
Damjan Marion3891cd82016-10-27 10:27:00 +0200862policer_classify_init (vlib_main_t * vm)
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700863{
Damjan Marion3891cd82016-10-27 10:27:00 +0200864 policer_classify_main_t *pcm = &policer_classify_main;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700865
866 pcm->vlib_main = vm;
Damjan Marion3891cd82016-10-27 10:27:00 +0200867 pcm->vnet_main = vnet_get_main ();
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700868 pcm->vnet_classify_main = &vnet_classify_main;
869
870 /* Initialize L2 feature next-node indexes */
Damjan Marion3891cd82016-10-27 10:27:00 +0200871 feat_bitmap_init_next_nodes (vm,
872 l2_policer_classify_node.index,
873 L2INPUT_N_FEAT,
874 l2input_get_feat_names (),
875 pcm->feat_next_node_index);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700876
877 return 0;
878}
879
880VLIB_INIT_FUNCTION (policer_classify_init);
Damjan Marion3891cd82016-10-27 10:27:00 +0200881
882/*
883 * fd.io coding-style-patch-verification: ON
884 *
885 * Local Variables:
886 * eval: (c-set-style "gnu")
887 * End:
888 */