FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
policer.c
Go to the documentation of this file.
1 /*
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  */
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include <vnet/policer/policer.h>
20 #include <vnet/ip/ip_packet.h>
21 
23 
24 u8 *
25 format_policer_handoff_trace (u8 *s, va_list *args)
26 {
27  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
28  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
29  policer_handoff_trace_t *t = va_arg (*args, policer_handoff_trace_t *);
30 
31  s = format (s, "policer %d, handoff thread %d to %d", t->policer_index,
33 
34  return s;
35 }
36 
38  {
39  .name = "Policer-Conform",
40  .stat_segment_name = "/net/policer/conform",
41  },
42  {
43  .name = "Policer-Exceed",
44  .stat_segment_name = "/net/policer/exceed",
45  },
46  {
47  .name = "Policer-Violate",
48  .stat_segment_name = "/net/policer/violate",
49  },
50 };
51 
54  u32 *policer_index, u8 is_add)
55 {
57  policer_t test_policer;
58  policer_t *policer;
59  uword *p;
60  u32 pi;
61  int rv;
62 
64 
65  if (is_add == 0)
66  {
67  /* free policer config and template */
68  if (p == 0)
69  {
70  vec_free (name);
71  return clib_error_return (0, "No such policer configuration");
72  }
73  pool_put_index (pm->configs, p[0]);
76 
77  /* free policer */
79  if (p == 0)
80  {
81  vec_free (name);
82  return clib_error_return (0, "No such policer");
83  }
84  pool_put_index (pm->policers, p[0]);
86 
87  vec_free (name);
88  return 0;
89  }
90 
91  if (p != 0)
92  {
93  vec_free (name);
94  return clib_error_return (0, "Policer already exists");
95  }
96 
97  /* Vet the configuration before adding it to the table */
98  rv = pol_logical_2_physical (cfg, &test_policer);
99 
100  if (rv == 0)
101  {
102  policer_t *pp;
104  int i;
105 
106  pool_get (pm->configs, cp);
107  pool_get (pm->policer_templates, pp);
108 
109  ASSERT (cp - pm->configs == pp - pm->policer_templates);
110 
111  clib_memcpy (cp, cfg, sizeof (*cp));
112  clib_memcpy (pp, &test_policer, sizeof (*pp));
113 
116  policer[0] = pp[0];
117  pi = policer - pm->policers;
119  *policer_index = pi;
120  policer->thread_index = ~0;
121 
122  for (i = 0; i < NUM_POLICE_RESULTS; i++)
123  {
126  }
127  }
128  else
129  {
130  vec_free (name);
131  return clib_error_return (0, "Config failed sanity check");
132  }
133 
134  return 0;
135 }
136 
137 int
138 policer_bind_worker (u8 *name, u32 worker, bool bind)
139 {
141  policer_t *policer;
142  uword *p;
143 
145  if (p == 0)
146  {
147  return VNET_API_ERROR_NO_SUCH_ENTRY;
148  }
149 
150  policer = &pm->policers[p[0]];
151 
152  if (bind)
153  {
154  if (worker >= vlib_num_workers ())
155  {
156  return VNET_API_ERROR_INVALID_WORKER;
157  }
158 
159  policer->thread_index = vlib_get_worker_thread_index (worker);
160  }
161  else
162  {
163  policer->thread_index = ~0;
164  }
165  return 0;
166 }
167 
168 int
170 {
172  policer_t *policer;
173  u32 policer_index;
174  uword *p;
175 
177  if (p == 0)
178  {
179  return VNET_API_ERROR_NO_SUCH_ENTRY;
180  }
181 
182  policer = &pm->policers[p[0]];
183  policer_index = policer - pm->policers;
184 
185  if (apply)
186  {
188  pm->policer_index_by_sw_if_index[sw_if_index] = policer_index;
189  }
190  else
191  {
193  }
194 
195  vnet_feature_enable_disable ("device-input", "policer-input", sw_if_index,
196  apply, 0, 0);
197  return 0;
198 }
199 
200 u8 *
201 format_policer_instance (u8 * s, va_list * va)
202 {
203  policer_t *i = va_arg (*va, policer_t *);
204  uword pi = va_arg (*va, uword);
205  int result;
207 
208  for (result = 0; result < NUM_POLICE_RESULTS; result++)
209  {
211  &counts[result]);
212  }
213 
214  s = format (s, "policer at %llx: %s rate, %s color-aware\n",
215  i, i->single_rate ? "single" : "dual",
216  i->color_aware ? "is" : "not");
217  s = format (s, "cir %u tok/period, pir %u tok/period, scale %u\n",
218  i->cir_tokens_per_period, i->pir_tokens_per_period, i->scale);
219  s = format (s, "cur lim %u, cur bkt %u, ext lim %u, ext bkt %u\n",
220  i->current_limit,
221  i->current_bucket, i->extended_limit, i->extended_bucket);
222  s = format (s, "last update %llu\n", i->last_update_time);
223  s = format (s, "conform %llu packets, %llu bytes\n",
224  counts[POLICE_CONFORM].packets, counts[POLICE_CONFORM].bytes);
225  s = format (s, "exceed %llu packets, %llu bytes\n",
226  counts[POLICE_EXCEED].packets, counts[POLICE_EXCEED].bytes);
227  s = format (s, "violate %llu packets, %llu bytes\n",
228  counts[POLICE_VIOLATE].packets, counts[POLICE_VIOLATE].bytes);
229  return s;
230 }
231 
232 static u8 *
233 format_policer_round_type (u8 * s, va_list * va)
234 {
235  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
236 
237  if (c->rnd_type == QOS_ROUND_TO_CLOSEST)
238  s = format (s, "closest");
239  else if (c->rnd_type == QOS_ROUND_TO_UP)
240  s = format (s, "up");
241  else if (c->rnd_type == QOS_ROUND_TO_DOWN)
242  s = format (s, "down");
243  else
244  s = format (s, "ILLEGAL");
245  return s;
246 }
247 
248 
249 static u8 *
250 format_policer_rate_type (u8 * s, va_list * va)
251 {
252  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
253 
254  if (c->rate_type == QOS_RATE_KBPS)
255  s = format (s, "kbps");
256  else if (c->rate_type == QOS_RATE_PPS)
257  s = format (s, "pps");
258  else
259  s = format (s, "ILLEGAL");
260  return s;
261 }
262 
263 static u8 *
264 format_policer_type (u8 * s, va_list * va)
265 {
266  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
267 
268  if (c->rfc == QOS_POLICER_TYPE_1R2C)
269  s = format (s, "1r2c");
270 
271  else if (c->rfc == QOS_POLICER_TYPE_1R3C_RFC_2697)
272  s = format (s, "1r3c");
273 
274  else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_2698)
275  s = format (s, "2r3c-2698");
276 
277  else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_4115)
278  s = format (s, "2r3c-4115");
279 
280  else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
281  s = format (s, "2r3c-mef5cf1");
282  else
283  s = format (s, "ILLEGAL");
284  return s;
285 }
286 
287 static u8 *
288 format_policer_action_type (u8 * s, va_list * va)
289 {
291 
292  if (a->action_type == QOS_ACTION_DROP)
293  s = format (s, "drop");
294  else if (a->action_type == QOS_ACTION_TRANSMIT)
295  s = format (s, "transmit");
296  else if (a->action_type == QOS_ACTION_MARK_AND_TRANSMIT)
297  s = format (s, "mark-and-transmit %U", format_ip_dscp, a->dscp);
298  else
299  s = format (s, "ILLEGAL");
300  return s;
301 }
302 
303 u8 *
304 format_policer_config (u8 * s, va_list * va)
305 {
306  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
307 
308  s = format (s, "type %U cir %u eir %u cb %u eb %u\n",
310  c->rb.kbps.cir_kbps,
311  c->rb.kbps.eir_kbps, c->rb.kbps.cb_bytes, c->rb.kbps.eb_bytes);
312  s = format (s, "rate type %U, round type %U\n",
314  s = format (s, "conform action %U, exceed action %U, violate action %U\n",
315  format_policer_action_type, &c->conform_action,
316  format_policer_action_type, &c->exceed_action,
317  format_policer_action_type, &c->violate_action);
318  return s;
319 }
320 
321 static uword
323 {
324  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
325 
326  if (!unformat (input, "type"))
327  return 0;
328 
329  if (unformat (input, "1r2c"))
330  c->rfc = QOS_POLICER_TYPE_1R2C;
331  else if (unformat (input, "1r3c"))
333  else if (unformat (input, "2r3c-2698"))
335  else if (unformat (input, "2r3c-4115"))
337  else if (unformat (input, "2r3c-mef5cf1"))
339  else
340  return 0;
341  return 1;
342 }
343 
344 static uword
346 {
347  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
348 
349  if (!unformat (input, "round"))
350  return 0;
351 
352  if (unformat (input, "closest"))
353  c->rnd_type = QOS_ROUND_TO_CLOSEST;
354  else if (unformat (input, "up"))
355  c->rnd_type = QOS_ROUND_TO_UP;
356  else if (unformat (input, "down"))
357  c->rnd_type = QOS_ROUND_TO_DOWN;
358  else
359  return 0;
360  return 1;
361 }
362 
363 static uword
365 {
366  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
367 
368  if (!unformat (input, "rate"))
369  return 0;
370 
371  if (unformat (input, "kbps"))
372  c->rate_type = QOS_RATE_KBPS;
373  else if (unformat (input, "pps"))
374  c->rate_type = QOS_RATE_PPS;
375  else
376  return 0;
377  return 1;
378 }
379 
380 static uword
381 unformat_policer_cir (unformat_input_t * input, va_list * va)
382 {
383  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
384 
385  if (unformat (input, "cir %u", &c->rb.kbps.cir_kbps))
386  return 1;
387  return 0;
388 }
389 
390 static uword
391 unformat_policer_eir (unformat_input_t * input, va_list * va)
392 {
393  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
394 
395  if (unformat (input, "eir %u", &c->rb.kbps.eir_kbps))
396  return 1;
397  return 0;
398 }
399 
400 static uword
401 unformat_policer_cb (unformat_input_t * input, va_list * va)
402 {
403  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
404 
405  if (unformat (input, "cb %u", &c->rb.kbps.cb_bytes))
406  return 1;
407  return 0;
408 }
409 
410 static uword
411 unformat_policer_eb (unformat_input_t * input, va_list * va)
412 {
413  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
414 
415  if (unformat (input, "eb %u", &c->rb.kbps.eb_bytes))
416  return 1;
417  return 0;
418 }
419 
420 static uword
422 {
424 
425  if (unformat (input, "drop"))
426  a->action_type = QOS_ACTION_DROP;
427  else if (unformat (input, "transmit"))
428  a->action_type = QOS_ACTION_TRANSMIT;
429  else if (unformat (input, "mark-and-transmit %U", unformat_ip_dscp,
430  &a->dscp))
431  a->action_type = QOS_ACTION_MARK_AND_TRANSMIT;
432  else
433  return 0;
434  return 1;
435 }
436 
437 static uword
439 {
440  qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *);
441 
442  if (unformat (input, "conform-action %U", unformat_policer_action_type,
443  &c->conform_action))
444  return 1;
445  else if (unformat (input, "exceed-action %U", unformat_policer_action_type,
446  &c->exceed_action))
447  return 1;
448  else if (unformat (input, "violate-action %U", unformat_policer_action_type,
449  &c->violate_action))
450  return 1;
451  return 0;
452 }
453 
454 static uword
456 {
457  u32 *r = va_arg (*va, u32 *);
459  uword *p;
460  u8 *match_name = 0;
461 
462  if (unformat (input, "%s", &match_name))
463  ;
464  else
465  return 0;
466 
467  p = hash_get_mem (pm->policer_index_by_name, match_name);
468 
469  if (p == 0)
470  return 0;
471 
472  *r = p[0];
473 
474  return 1;
475 }
476 
477 static uword
479 {
480  u32 *r = va_arg (*va, u32 *);
481 
482  if (unformat (input, "conform-color"))
483  *r = POLICE_CONFORM;
484  else if (unformat (input, "exceed-color"))
485  *r = POLICE_EXCEED;
486  else
487  return 0;
488 
489  return 1;
490 }
491 
492 #define foreach_config_param \
493 _(eb) \
494 _(cb) \
495 _(eir) \
496 _(cir) \
497 _(rate_type) \
498 _(round_type) \
499 _(type) \
500 _(action)
501 
502 static clib_error_t *
504  vlib_cli_command_t *cmd)
505 {
507  unformat_input_t _line_input, *line_input = &_line_input;
508  u8 is_add = 1;
509  u8 *name = 0;
510  u32 pi;
511  clib_error_t *error = NULL;
512 
513  /* Get a line of input. */
514  if (!unformat_user (input, unformat_line_input, line_input))
515  return 0;
516 
517  clib_memset (&c, 0, sizeof (c));
518 
519  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
520  {
521  if (unformat (line_input, "del"))
522  is_add = 0;
523  else if (unformat (line_input, "name %s", &name))
524  ;
525  else if (unformat (line_input, "color-aware"))
526  c.color_aware = 1;
527 
528 #define _(a) else if (unformat (line_input, "%U", unformat_policer_##a, &c)) ;
530 #undef _
531  else
532  {
533  error = clib_error_return (0, "unknown input `%U'",
534  format_unformat_error, line_input);
535  goto done;
536  }
537  }
538 
539  error = policer_add_del (vm, name, &c, &pi, is_add);
540 
541 done:
542  unformat_free (line_input);
543 
544  return error;
545 }
546 
547 static clib_error_t *
549  vlib_cli_command_t *cmd)
550 {
551  unformat_input_t _line_input, *line_input = &_line_input;
552  clib_error_t *error = NULL;
553  u8 *name = 0;
554 
555  /* Get a line of input. */
556  if (!unformat_user (input, unformat_line_input, line_input))
557  return 0;
558 
559  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
560  {
561  if (unformat (line_input, "name %s", &name))
562  ;
563  else
564  {
565  error = clib_error_return (0, "unknown input `%U'",
566  format_unformat_error, line_input);
567  goto done;
568  }
569  }
570 
571  error = policer_add_del (vm, name, NULL, NULL, 0);
572 
573 done:
574  unformat_free (line_input);
575 
576  return error;
577 }
578 
579 static clib_error_t *
581  vlib_cli_command_t *cmd)
582 {
583  unformat_input_t _line_input, *line_input = &_line_input;
584  clib_error_t *error = NULL;
585  u8 bind, *name = 0;
586  u32 worker;
587  int rv;
588 
589  bind = 1;
590  worker = ~0;
591 
592  /* Get a line of input. */
593  if (!unformat_user (input, unformat_line_input, line_input))
594  return 0;
595 
596  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
597  {
598  if (unformat (line_input, "name %s", &name))
599  ;
600  else if (unformat (line_input, "unbind"))
601  bind = 0;
602  else if (unformat (line_input, "%d", &worker))
603  ;
604  else
605  {
606  error = clib_error_return (0, "unknown input `%U'",
607  format_unformat_error, line_input);
608  goto done;
609  }
610  }
611 
612  if (bind && ~0 == worker)
613  {
614  error = clib_error_return (0, "specify worker to bind to: `%U'",
615  format_unformat_error, line_input);
616  }
617  else
618  {
619  rv = policer_bind_worker (name, worker, bind);
620 
621  if (rv)
622  error = clib_error_return (0, "failed: `%d'", rv);
623  }
624 
625 done:
626  unformat_free (line_input);
627 
628  return error;
629 }
630 
631 static clib_error_t *
633  vlib_cli_command_t *cmd)
634 {
635  unformat_input_t _line_input, *line_input = &_line_input;
636  clib_error_t *error = NULL;
637  u8 apply, *name = 0;
639  int rv;
640 
641  apply = 1;
642  sw_if_index = ~0;
643 
644  /* Get a line of input. */
645  if (!unformat_user (input, unformat_line_input, line_input))
646  return 0;
647 
648  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
649  {
650  if (unformat (line_input, "name %s", &name))
651  ;
652  else if (unformat (line_input, "unapply"))
653  apply = 0;
654  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
656  ;
657  else
658  {
659  error = clib_error_return (0, "unknown input `%U'",
660  format_unformat_error, line_input);
661  goto done;
662  }
663  }
664 
665  if (~0 == sw_if_index)
666  {
667  error = clib_error_return (0, "specify interface to apply to: `%U'",
668  format_unformat_error, line_input);
669  }
670  else
671  {
673 
674  if (rv)
675  error = clib_error_return (0, "failed: `%d'", rv);
676  }
677 
678 done:
679  unformat_free (line_input);
680 
681  return error;
682 }
683 
684 /* *INDENT-OFF* */
686  .path = "configure policer",
687  .short_help = "configure policer name <name> <params> ",
688  .function = policer_add_command_fn,
689 };
691  .path = "policer add",
692  .short_help = "policer name <name> <params> ",
693  .function = policer_add_command_fn,
694 };
696  .path = "policer del",
697  .short_help = "policer del name <name> ",
698  .function = policer_del_command_fn,
699 };
701  .path = "policer bind",
702  .short_help = "policer bind [unbind] name <name> <worker>",
703  .function = policer_bind_command_fn,
704 };
706  .path = "policer input",
707  .short_help = "policer input [unapply] name <name> <interfac>",
708  .function = policer_input_command_fn,
709 };
710 /* *INDENT-ON* */
711 
712 static clib_error_t *
714  unformat_input_t * input, vlib_cli_command_t * cmd)
715 {
717  hash_pair_t *p;
718  u32 pool_index;
719  u8 *match_name = 0;
720  u8 *name;
721  uword *pi;
722  qos_pol_cfg_params_st *config;
723  policer_t *templ;
724 
725  (void) unformat (input, "name %s", &match_name);
726 
727  /* *INDENT-OFF* */
729  ({
730  name = (u8 *) p->key;
731  if (match_name == 0 || !strcmp((char *) name, (char *) match_name))
732  {
733  pi = hash_get_mem (pm->policer_index_by_name, name);
734 
735  pool_index = p->value[0];
736  config = pool_elt_at_index (pm->configs, pool_index);
737  templ = pool_elt_at_index (pm->policer_templates, pool_index);
738  vlib_cli_output (vm, "Name \"%s\" %U ", name, format_policer_config,
739  config);
740  vlib_cli_output (vm, "Template %U", format_policer_instance, templ,
741  pi[0]);
742  vlib_cli_output (vm, "-----------");
743  }
744  }));
745  /* *INDENT-ON* */
746  return 0;
747 }
748 
749 
750 /* *INDENT-OFF* */
752  .path = "show policer",
753  .short_help = "show policer [name]",
754  .function = show_policer_command_fn,
755 };
756 /* *INDENT-ON* */
757 
758 static clib_error_t *
760  unformat_input_t * input,
761  vlib_cli_command_t * cmd)
762 {
764 
765  vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d",
766  pool_elts (pm->configs),
768  pool_elts (pm->policers));
769  return 0;
770 }
771 /* *INDENT-OFF* */
773  .path = "show policer pools",
774  .short_help = "show policer pools",
775  .function = show_policer_pools_command_fn,
776 };
777 /* *INDENT-ON* */
778 
779 clib_error_t *
781 {
783 
784  pm->vlib_main = vm;
785  pm->vnet_main = vnet_get_main ();
786  pm->log_class = vlib_log_register_class ("policer", 0);
788 
789  pm->policer_config_by_name = hash_create_string (0, sizeof (uword));
790  pm->policer_index_by_name = hash_create_string (0, sizeof (uword));
791 
796 
797  return 0;
798 }
799 
801 
802 
803 
804 /*
805  * fd.io coding-style-patch-verification: ON
806  *
807  * Local Variables:
808  * eval: (c-set-style "gnu")
809  * End:
810  */
unformat_policer_classify_precolor
static uword unformat_policer_classify_precolor(unformat_input_t *input, va_list *va)
Definition: policer.c:478
NUM_POLICE_RESULTS
#define NUM_POLICE_RESULTS
Definition: police.h:25
vnet_policer_main_t::configs
qos_pol_cfg_params_st * configs
Definition: policer.h:32
vnet_classify_register_unformat_policer_next_index_fn
void vnet_classify_register_unformat_policer_next_index_fn(unformat_function_t *fn)
Definition: vnet_classify.c:114
vnet_policer_main_t
Definition: policer.h:26
vnet_policer_main_t::policer_config_by_name
uword * policer_config_by_name
Definition: policer.h:36
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
foreach_config_param
#define foreach_config_param
Definition: policer.c:492
policer_input
int policer_input(u8 *name, u32 sw_if_index, bool apply)
Definition: policer.c:169
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_policer_type
static uword unformat_policer_type(unformat_input_t *input, va_list *va)
Definition: policer.c:322
format_policer_instance
u8 * format_policer_instance(u8 *s, va_list *va)
Definition: policer.c:201
QOS_RATE_KBPS
@ QOS_RATE_KBPS
Definition: xlate.h:64
policer_bind_command
static vlib_cli_command_t policer_bind_command
(constructor) VLIB_CLI_COMMAND (policer_bind_command)
Definition: policer.c:700
QOS_POLICER_TYPE_2R3C_RFC_4115
@ QOS_POLICER_TYPE_2R3C_RFC_4115
Definition: xlate.h:35
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
QOS_POLICER_TYPE_2R3C_RFC_2698
@ QOS_POLICER_TYPE_2R3C_RFC_2698
Definition: xlate.h:34
unformat_policer_eir
static uword unformat_policer_eir(unformat_input_t *input, va_list *va)
Definition: policer.c:391
vnet_policer_main
vnet_policer_main_t vnet_policer_main
Definition: policer.c:22
format_policer_round_type
static u8 * format_policer_round_type(u8 *s, va_list *va)
Definition: policer.c:233
vlib_get_worker_thread_index
static u32 vlib_get_worker_thread_index(u32 worker_index)
Definition: threads.h:339
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
policer_del_command_fn
static clib_error_t * policer_del_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:548
hash_foreach_pair
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
Definition: hash.h:373
name
string name[64]
Definition: fib.api:25
show_policer_command_fn
static clib_error_t * show_policer_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:713
pool_get_aligned
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:249
policer_handoff_trace_t_
Definition: police_inlines.h:107
vlib_log_register_class
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:339
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
unformat_policer_action_type
static uword unformat_policer_action_type(unformat_input_t *input, va_list *va)
Definition: policer.c:421
hash_create_string
#define hash_create_string(elts, value_bytes)
Definition: hash.h:689
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
policer_t
Definition: police.h:73
vlib_cli_command_t::path
char * path
Definition: cli.h:96
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
vlib_validate_combined_counter
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:119
qos_pol_cfg_params_st_
Definition: xlate.h:115
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
QOS_POLICER_TYPE_1R3C_RFC_2697
@ QOS_POLICER_TYPE_1R3C_RFC_2697
Definition: xlate.h:33
vnet_policer_main_t::vnet_main
vnet_main_t * vnet_main
Definition: policer.h:46
POLICE_VIOLATE
@ POLICE_VIOLATE
Definition: police.h:22
vlib_combined_counter_main_t::name
char * name
The counter collection's name.
Definition: counter.h:206
vnet_policer_main_t::log_class
vlib_log_class_t log_class
Definition: policer.h:48
policer.h
ip_packet.h
policer_init
clib_error_t * policer_init(vlib_main_t *vm)
Definition: policer.c:780
unformat_input_t
struct _unformat_input_t unformat_input_t
policer_bind_command_fn
static clib_error_t * policer_bind_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:580
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
policer_input_command_fn
static clib_error_t * policer_input_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:632
POLICE_EXCEED
@ POLICE_EXCEED
Definition: police.h:21
error
Definition: cJSON.c:88
qos_pol_action_params_st_
Definition: xlate.h:78
vlib_frame_queue_main_init
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1561
vnet_classify_register_unformat_opaque_index_fn
void vnet_classify_register_unformat_opaque_index_fn(unformat_function_t *fn)
Definition: vnet_classify.c:123
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
policer_handoff_trace_t_::current_worker_index
u32 current_worker_index
Definition: police_inlines.h:110
format_policer_handoff_trace
u8 * format_policer_handoff_trace(u8 *s, va_list *args)
Definition: policer.c:25
policer_counters
vlib_combined_counter_main_t policer_counters[]
Definition: policer.c:37
unformat_policer_rate_type
static uword unformat_policer_rate_type(unformat_input_t *input, va_list *va)
Definition: policer.c:364
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
policer_del_command
static vlib_cli_command_t policer_del_command
(constructor) VLIB_CLI_COMMAND (policer_del_command)
Definition: policer.c:695
format_policer_rate_type
static u8 * format_policer_rate_type(u8 *s, va_list *va)
Definition: policer.c:250
policer_handoff_trace_t_::policer_index
u32 policer_index
Definition: police_inlines.h:109
policer_add_del
clib_error_t * policer_add_del(vlib_main_t *vm, u8 *name, qos_pol_cfg_params_st *cfg, u32 *policer_index, u8 is_add)
Definition: policer.c:53
hash_unset_mem
#define hash_unset_mem(h, key)
Definition: hash.h:291
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_policer_main_t::vlib_main
vlib_main_t * vlib_main
Definition: policer.h:45
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_policer_round_type
static uword unformat_policer_round_type(unformat_input_t *input, va_list *va)
Definition: policer.c:345
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
unformat_policer_classify_next_index
static uword unformat_policer_classify_next_index(unformat_input_t *input, va_list *va)
Definition: policer.c:455
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
configure_policer_command
static vlib_cli_command_t configure_policer_command
(constructor) VLIB_CLI_COMMAND (configure_policer_command)
Definition: policer.c:685
policer_add_command_fn
static clib_error_t * policer_add_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:503
policer_t::thread_index
u32 thread_index
Definition: police.h:98
uword
u64 uword
Definition: types.h:112
vlib_zero_combined_counter
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:298
QOS_POLICER_TYPE_1R2C
@ QOS_POLICER_TYPE_1R2C
Definition: xlate.h:32
QOS_ACTION_MARK_AND_TRANSMIT
@ QOS_ACTION_MARK_AND_TRANSMIT
Definition: police.h:31
vnet_policer_main_t::policer_index_by_sw_if_index
u32 * policer_index_by_sw_if_index
Definition: policer.h:42
QOS_ACTION_DROP
@ QOS_ACTION_DROP
Definition: police.h:29
QOS_ROUND_TO_DOWN
@ QOS_ROUND_TO_DOWN
Definition: xlate.h:48
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
apply
static int apply(phash_main_t *pm, u32 tail, u32 rollback)
Definition: phash.c:408
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
unformat_policer_cir
static uword unformat_policer_cir(unformat_input_t *input, va_list *va)
Definition: policer.c:381
police_inlines.h
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_policer_main_t::policer_templates
policer_t * policer_templates
Definition: policer.h:33
vlib_get_combined_counter
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:272
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
policer_add_command
static vlib_cli_command_t policer_add_command
(constructor) VLIB_CLI_COMMAND (policer_add_command)
Definition: policer.c:690
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
QOS_ACTION_TRANSMIT
@ QOS_ACTION_TRANSMIT
Definition: police.h:30
pol_logical_2_physical
int pol_logical_2_physical(qos_pol_cfg_params_st *cfg, policer_t *phys)
Definition: xlate.c:1061
POLICE_CONFORM
@ POLICE_CONFORM
Definition: police.h:20
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
QOS_ROUND_TO_UP
@ QOS_ROUND_TO_UP
Definition: xlate.h:47
policer_handoff_trace_t_::next_worker_index
u32 next_worker_index
Definition: police_inlines.h:111
QOS_ROUND_TO_CLOSEST
@ QOS_ROUND_TO_CLOSEST
Definition: xlate.h:46
format_policer_type
static u8 * format_policer_type(u8 *s, va_list *va)
Definition: policer.c:264
policer_input_node
vlib_node_registration_t policer_input_node
(constructor) VLIB_REGISTER_NODE (policer_input_node)
Definition: node_funcs.c:262
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
policer_input_command
static vlib_cli_command_t policer_input_command
(constructor) VLIB_CLI_COMMAND (policer_input_command)
Definition: policer.c:705
policer_bind_worker
int policer_bind_worker(u8 *name, u32 worker, bool bind)
Definition: policer.c:138
vnet_classify.h
show_policer_pools_command_fn
static clib_error_t * show_policer_pools_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: policer.c:759
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
i
int i
Definition: flowhash_template.h:376
show_policer_command
static vlib_cli_command_t show_policer_command
(constructor) VLIB_CLI_COMMAND (show_policer_command)
Definition: policer.c:751
QOS_RATE_PPS
@ QOS_RATE_PPS
Definition: xlate.h:65
rv
int __clib_unused rv
Definition: application.c:491
unformat_policer_action
static uword unformat_policer_action(unformat_input_t *input, va_list *va)
Definition: policer.c:438
vnet_policer_main_t::policers
policer_t * policers
Definition: policer.h:29
vlib_cli_command_t
Definition: cli.h:92
show_policer_pools_command
static vlib_cli_command_t show_policer_pools_command
(constructor) VLIB_CLI_COMMAND (show_policer_pools_command)
Definition: policer.c:772
unformat_policer_cb
static uword unformat_policer_cb(unformat_input_t *input, va_list *va)
Definition: policer.c:401
unformat_ip_dscp
unformat_function_t unformat_ip_dscp
Definition: ip_packet.h:123
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
unformat_policer_eb
static uword unformat_policer_eb(unformat_input_t *input, va_list *va)
Definition: policer.c:411
format_ip_dscp
u8 * format_ip_dscp(u8 *s, va_list *va)
Definition: ip.c:285
QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1
@ QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1
Definition: xlate.h:36
format_policer_config
u8 * format_policer_config(u8 *s, va_list *va)
Definition: policer.c:304
vnet_policer_main_t::fq_index
u32 fq_index
Definition: policer.h:51
vnet_policer_main_t::policer_index_by_name
uword * policer_index_by_name
Definition: policer.h:39
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
hash_pair_t
Definition: hash.h:159
format_policer_action_type
static u8 * format_policer_action_type(u8 *s, va_list *va)
Definition: policer.c:288
packets
units packets
Definition: map.api:366