X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fpolicer%2Fpolicer.c;h=e3cc8f75f3a0f48ab65a5a047f8a5af9566ad92a;hb=3001c0344e4fce34b824df988ced2c8ccbee82e3;hp=fb2ce7598faec445bd1b9a994871ca131144f14f;hpb=15c18e3e40d3bf754e5b6969c7478ad9f1d5e95b;p=vpp.git diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c index fb2ce7598fa..e3cc8f75f3a 100644 --- a/src/vnet/policer/policer.c +++ b/src/vnet/policer/policer.c @@ -165,6 +165,38 @@ policer_bind_worker (u8 *name, u32 worker, bool bind) return 0; } +int +policer_input (u8 *name, u32 sw_if_index, bool apply) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + policer_t *policer; + u32 policer_index; + uword *p; + + p = hash_get_mem (pm->policer_index_by_name, name); + if (p == 0) + { + return VNET_API_ERROR_NO_SUCH_ENTRY; + } + + policer = &pm->policers[p[0]]; + policer_index = policer - pm->policers; + + if (apply) + { + vec_validate (pm->policer_index_by_sw_if_index, sw_if_index); + pm->policer_index_by_sw_if_index[sw_if_index] = policer_index; + } + else + { + pm->policer_index_by_sw_if_index[sw_if_index] = ~0; + } + + vnet_feature_enable_disable ("device-input", "policer-input", sw_if_index, + apply, 0, 0); + return 0; +} + u8 * format_policer_instance (u8 * s, va_list * va) { @@ -468,9 +500,8 @@ _(type) \ _(action) static clib_error_t * -configure_policer_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) +policer_add_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) { qos_pol_cfg_params_st c; unformat_input_t _line_input, *line_input = &_line_input; @@ -513,11 +544,168 @@ done: return error; } +static clib_error_t * +policer_del_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + u8 *name = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "name %s", &name)) + ; + else + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } + } + + error = policer_add_del (vm, name, NULL, NULL, 0); + +done: + unformat_free (line_input); + + return error; +} + +static clib_error_t * +policer_bind_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + u8 bind, *name = 0; + u32 worker; + int rv; + + bind = 1; + worker = ~0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "name %s", &name)) + ; + else if (unformat (line_input, "unapply")) + bind = 0; + else if (unformat (line_input, "%d", &bind)) + ; + else + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (bind && ~0 == worker) + { + error = clib_error_return (0, "specify worker to bind to: `%U'", + format_unformat_error, line_input); + } + else + { + rv = policer_bind_worker (name, worker, bind); + + if (rv) + error = clib_error_return (0, "failed: `%d'", rv); + } + +done: + unformat_free (line_input); + + return error; +} + +static clib_error_t * +policer_input_command_fn (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + u8 apply, *name = 0; + u32 sw_if_index; + int rv; + + apply = 1; + sw_if_index = ~0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "name %s", &name)) + ; + else if (unformat (line_input, "unapply")) + apply = 0; + else if (unformat (line_input, "%U", unformat_vnet_sw_interface, + vnet_get_main (), &sw_if_index)) + ; + else + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (~0 == sw_if_index) + { + error = clib_error_return (0, "specify interface to apply to: `%U'", + format_unformat_error, line_input); + } + else + { + rv = policer_input (name, sw_if_index, apply); + + if (rv) + error = clib_error_return (0, "failed: `%d'", rv); + } + +done: + unformat_free (line_input); + + return error; +} + /* *INDENT-OFF* */ VLIB_CLI_COMMAND (configure_policer_command, static) = { - .path = "configure policer", - .short_help = "configure policer name ", - .function = configure_policer_command_fn, + .path = "configure policer", + .short_help = "configure policer name ", + .function = policer_add_command_fn, +}; +VLIB_CLI_COMMAND (policer_add_command, static) = { + .path = "policer add", + .short_help = "policer name ", + .function = policer_add_command_fn, +}; +VLIB_CLI_COMMAND (policer_del_command, static) = { + .path = "policer del", + .short_help = "policer del name ", + .function = policer_del_command_fn, +}; +VLIB_CLI_COMMAND (policer_bind_command, static) = { + .path = "policer bind", + .short_help = "policer bind [unbind] name ", + .function = policer_bind_command_fn, +}; +VLIB_CLI_COMMAND (policer_input_command, static) = { + .path = "policer input", + .short_help = "policer input [unapply] name ", + .function = policer_input_command_fn, }; /* *INDENT-ON* */ @@ -596,6 +784,7 @@ policer_init (vlib_main_t * vm) pm->vlib_main = vm; pm->vnet_main = vnet_get_main (); pm->log_class = vlib_log_register_class ("policer", 0); + pm->fq_index = vlib_frame_queue_main_init (policer_input_node.index, 0); pm->policer_config_by_name = hash_create_string (0, sizeof (uword)); pm->policer_index_by_name = hash_create_string (0, sizeof (uword));