Skip to content

Commit 415cd67

Browse files
author
Neale Ranns
committed
policer: Add CLI for all equivalent API functions
Type: improvement Signed-off-by: Neale Ranns <[email protected]> Change-Id: Ic17096c80fbde89f9bb74c29256abbe845130992
1 parent 5b3f523 commit 415cd67

File tree

1 file changed

+162
-6
lines changed

1 file changed

+162
-6
lines changed

src/vnet/policer/policer.c

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,8 @@ _(type) \
500500
_(action)
501501

502502
static clib_error_t *
503-
configure_policer_command_fn (vlib_main_t * vm,
504-
unformat_input_t * input,
505-
vlib_cli_command_t * cmd)
503+
policer_add_command_fn (vlib_main_t *vm, unformat_input_t *input,
504+
vlib_cli_command_t *cmd)
506505
{
507506
qos_pol_cfg_params_st c;
508507
unformat_input_t _line_input, *line_input = &_line_input;
@@ -545,11 +544,168 @@ configure_policer_command_fn (vlib_main_t * vm,
545544
return error;
546545
}
547546

547+
static clib_error_t *
548+
policer_del_command_fn (vlib_main_t *vm, unformat_input_t *input,
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 *
580+
policer_bind_command_fn (vlib_main_t *vm, unformat_input_t *input,
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, "unapply"))
601+
bind = 0;
602+
else if (unformat (line_input, "%d", &bind))
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 *
632+
policer_input_command_fn (vlib_main_t *vm, unformat_input_t *input,
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;
638+
u32 sw_if_index;
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,
655+
vnet_get_main (), &sw_if_index))
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+
{
672+
rv = policer_input (name, sw_if_index, apply);
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+
548684
/* *INDENT-OFF* */
549685
VLIB_CLI_COMMAND (configure_policer_command, static) = {
550-
.path = "configure policer",
551-
.short_help = "configure policer name <name> <params> ",
552-
.function = configure_policer_command_fn,
686+
.path = "configure policer",
687+
.short_help = "configure policer name <name> <params> ",
688+
.function = policer_add_command_fn,
689+
};
690+
VLIB_CLI_COMMAND (policer_add_command, static) = {
691+
.path = "policer add",
692+
.short_help = "policer name <name> <params> ",
693+
.function = policer_add_command_fn,
694+
};
695+
VLIB_CLI_COMMAND (policer_del_command, static) = {
696+
.path = "policer del",
697+
.short_help = "policer del name <name> ",
698+
.function = policer_del_command_fn,
699+
};
700+
VLIB_CLI_COMMAND (policer_bind_command, static) = {
701+
.path = "policer bind",
702+
.short_help = "policer bind [unbind] name <name> <worker>",
703+
.function = policer_bind_command_fn,
704+
};
705+
VLIB_CLI_COMMAND (policer_input_command, static) = {
706+
.path = "policer input",
707+
.short_help = "policer input [unapply] name <name> <interfac>",
708+
.function = policer_input_command_fn,
553709
};
554710
/* *INDENT-ON* */
555711

0 commit comments

Comments
 (0)