diff options
-rw-r--r-- | src/vat/api_format.c | 485 | ||||
-rw-r--r-- | src/vnet/policer/policer.h | 2 | ||||
-rw-r--r-- | src/vnet/policer/policer_api.c | 60 | ||||
-rw-r--r-- | src/vnet/vnet_all_api_h.h | 1 |
4 files changed, 9 insertions, 539 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 5b28954af58..2907b888b2c 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -454,85 +454,6 @@ unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args) return 1; } -static uword -unformat_policer_rate_type (unformat_input_t * input, va_list * args) -{ - u8 *r = va_arg (*args, u8 *); - - if (unformat (input, "kbps")) - *r = QOS_RATE_KBPS; - else if (unformat (input, "pps")) - *r = QOS_RATE_PPS; - else - return 0; - return 1; -} - -static uword -unformat_policer_round_type (unformat_input_t * input, va_list * args) -{ - u8 *r = va_arg (*args, u8 *); - - if (unformat (input, "closest")) - *r = QOS_ROUND_TO_CLOSEST; - else if (unformat (input, "up")) - *r = QOS_ROUND_TO_UP; - else if (unformat (input, "down")) - *r = QOS_ROUND_TO_DOWN; - else - return 0; - return 1; -} - -static uword -unformat_policer_type (unformat_input_t * input, va_list * args) -{ - u8 *r = va_arg (*args, u8 *); - - if (unformat (input, "1r2c")) - *r = QOS_POLICER_TYPE_1R2C; - else if (unformat (input, "1r3c")) - *r = QOS_POLICER_TYPE_1R3C_RFC_2697; - else if (unformat (input, "2r3c-2698")) - *r = QOS_POLICER_TYPE_2R3C_RFC_2698; - else if (unformat (input, "2r3c-4115")) - *r = QOS_POLICER_TYPE_2R3C_RFC_4115; - else if (unformat (input, "2r3c-mef5cf1")) - *r = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1; - else - return 0; - return 1; -} - -static uword -unformat_dscp (unformat_input_t * input, va_list * va) -{ - u8 *r = va_arg (*va, u8 *); - - if (0); -#define _(v, f) else if (unformat (input, #f)) *r = IP_DSCP_##f; - foreach_ip_dscp -#undef _ - else return 0; - return 1; -} - -static uword -unformat_policer_action_type (unformat_input_t * input, va_list * va) -{ - qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *); - - if (unformat (input, "drop")) - a->action_type = QOS_ACTION_DROP; - else if (unformat (input, "transmit")) - a->action_type = QOS_ACTION_TRANSMIT; - else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp)) - a->action_type = QOS_ACTION_MARK_AND_TRANSMIT; - else - return 0; - return 1; -} - #if (VPP_API_TEST_BUILTIN==0) static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT; @@ -2468,269 +2389,6 @@ static void vl_api_get_node_graph_reply_t_handler_json vam->result_ready = 1; } -static u8 * -format_policer_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == QOS_POLICER_TYPE_1R2C) - s = format (s, "1r2c"); - else if (i == QOS_POLICER_TYPE_1R3C_RFC_2697) - s = format (s, "1r3c"); - else if (i == QOS_POLICER_TYPE_2R3C_RFC_2698) - s = format (s, "2r3c-2698"); - else if (i == QOS_POLICER_TYPE_2R3C_RFC_4115) - s = format (s, "2r3c-4115"); - else if (i == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) - s = format (s, "2r3c-mef5cf1"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_rate_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == QOS_RATE_KBPS) - s = format (s, "kbps"); - else if (i == QOS_RATE_PPS) - s = format (s, "pps"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_round_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == QOS_ROUND_TO_CLOSEST) - s = format (s, "closest"); - else if (i == QOS_ROUND_TO_UP) - s = format (s, "up"); - else if (i == QOS_ROUND_TO_DOWN) - s = format (s, "down"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_action_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == QOS_ACTION_DROP) - s = format (s, "drop"); - else if (i == QOS_ACTION_TRANSMIT) - s = format (s, "transmit"); - else if (i == QOS_ACTION_MARK_AND_TRANSMIT) - s = format (s, "mark-and-transmit"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_dscp (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - char *t = 0; - - switch (i) - { -#define _(v, f) \ - case IP_DSCP_##f: \ - return (format (s, "%s", #f)); - foreach_ip_dscp -#undef _ - } - s = format (s, "%s", t); - return (format (s, "ILLEGAL")); -} - -static void -vl_api_policer_details_t_handler (vl_api_policer_details_t * mp) -{ - vat_main_t *vam = &vat_main; - u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str; - - if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); - else - conform_dscp_str = format (0, ""); - - if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); - else - exceed_dscp_str = format (0, ""); - - if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); - else - violate_dscp_str = format (0, ""); - - print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, " - "rate type %U, round type %U, %s rate, %s color-aware, " - "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, " - "cur bkt %u, ext lim %u, ext bkt %u, last update %llu" - "conform action %U%s, exceed action %U%s, violate action %U%s", - mp->name, - format_policer_type, mp->type, - ntohl (mp->cir), - ntohl (mp->eir), - clib_net_to_host_u64 (mp->cb), - clib_net_to_host_u64 (mp->eb), - format_policer_rate_type, mp->rate_type, - format_policer_round_type, mp->round_type, - mp->single_rate ? "single" : "dual", - mp->color_aware ? "is" : "not", - ntohl (mp->cir_tokens_per_period), - ntohl (mp->pir_tokens_per_period), - ntohl (mp->scale), - ntohl (mp->current_limit), - ntohl (mp->current_bucket), - ntohl (mp->extended_limit), - ntohl (mp->extended_bucket), - clib_net_to_host_u64 (mp->last_update_time), - format_policer_action_type, mp->conform_action.type, - conform_dscp_str, - format_policer_action_type, mp->exceed_action.type, - exceed_dscp_str, - format_policer_action_type, mp->violate_action.type, - violate_dscp_str); - - vec_free (conform_dscp_str); - vec_free (exceed_dscp_str); - vec_free (violate_dscp_str); -} - -static void vl_api_policer_details_t_handler_json - (vl_api_policer_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node; - u8 *rate_type_str, *round_type_str, *type_str; - u8 *conform_action_str, *exceed_action_str, *violate_action_str; - - rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type); - round_type_str = - format (0, "%U", format_policer_round_type, mp->round_type); - type_str = format (0, "%U", format_policer_type, mp->type); - conform_action_str = format (0, "%U", format_policer_action_type, - mp->conform_action.type); - exceed_action_str = format (0, "%U", format_policer_action_type, - mp->exceed_action.type); - violate_action_str = format (0, "%U", format_policer_action_type, - mp->violate_action.type); - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "name", mp->name); - vat_json_object_add_uint (node, "cir", ntohl (mp->cir)); - vat_json_object_add_uint (node, "eir", ntohl (mp->eir)); - vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb)); - vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb)); - vat_json_object_add_string_copy (node, "rate_type", rate_type_str); - vat_json_object_add_string_copy (node, "round_type", round_type_str); - vat_json_object_add_string_copy (node, "type", type_str); - vat_json_object_add_uint (node, "single_rate", mp->single_rate); - vat_json_object_add_uint (node, "color_aware", mp->color_aware); - vat_json_object_add_uint (node, "scale", ntohl (mp->scale)); - vat_json_object_add_uint (node, "cir_tokens_per_period", - ntohl (mp->cir_tokens_per_period)); - vat_json_object_add_uint (node, "eir_tokens_per_period", - ntohl (mp->pir_tokens_per_period)); - vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit)); - vat_json_object_add_uint (node, "current_bucket", - ntohl (mp->current_bucket)); - vat_json_object_add_uint (node, "extended_limit", - ntohl (mp->extended_limit)); - vat_json_object_add_uint (node, "extended_bucket", - ntohl (mp->extended_bucket)); - vat_json_object_add_uint (node, "last_update_time", - ntohl (mp->last_update_time)); - vat_json_object_add_string_copy (node, "conform_action", - conform_action_str); - if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); - vat_json_object_add_string_copy (node, "conform_dscp", dscp_str); - vec_free (dscp_str); - } - vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str); - if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); - vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str); - vec_free (dscp_str); - } - vat_json_object_add_string_copy (node, "violate_action", - violate_action_str); - if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); - vat_json_object_add_string_copy (node, "violate_dscp", dscp_str); - vec_free (dscp_str); - } - - vec_free (rate_type_str); - vec_free (round_type_str); - vec_free (type_str); - vec_free (conform_action_str); - vec_free (exceed_action_str); - vec_free (violate_action_str); -} - -static void vl_api_policer_add_del_reply_t_handler - (vl_api_policer_add_del_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - } - else - { - vam->retval = retval; - vam->result_ready = 1; - if (retval == 0 && mp->policer_index != 0xFFFFFFFF) - /* - * Note: this is just barely thread-safe, depends on - * the main thread spinning waiting for an answer... - */ - errmsg ("policer index %d", ntohl (mp->policer_index)); - } -} - -static void vl_api_policer_add_del_reply_t_handler_json - (vl_api_policer_add_del_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_uint (&node, "policer_index", - ntohl (mp->policer_index)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - /* Format hex dump. */ u8 * format_hex_bytes (u8 * s, va_list * va) @@ -2980,8 +2638,6 @@ _(IOAM_DISABLE_REPLY, ioam_disable_reply) \ _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \ _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \ _(AF_PACKET_DETAILS, af_packet_details) \ -_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \ -_(POLICER_DETAILS, policer_details) \ _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \ _(MPLS_TABLE_DETAILS, mpls_table_details) \ _(MPLS_ROUTE_DETAILS, mpls_route_details) \ @@ -9611,145 +9267,6 @@ api_af_packet_dump (vat_main_t * vam) return ret; } -static int -api_policer_add_del (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_policer_add_del_t *mp; - u8 is_add = 1; - u8 *name = 0; - u32 cir = 0; - u32 eir = 0; - u64 cb = 0; - u64 eb = 0; - u8 rate_type = 0; - u8 round_type = 0; - u8 type = 0; - u8 color_aware = 0; - qos_pol_action_params_st conform_action, exceed_action, violate_action; - int ret; - - conform_action.action_type = QOS_ACTION_TRANSMIT; - conform_action.dscp = 0; - exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT; - exceed_action.dscp = 0; - violate_action.action_type = QOS_ACTION_DROP; - violate_action.dscp = 0; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "name %s", &name)) - vec_add1 (name, 0); - else if (unformat (i, "cir %u", &cir)) - ; - else if (unformat (i, "eir %u", &eir)) - ; - else if (unformat (i, "cb %u", &cb)) - ; - else if (unformat (i, "eb %u", &eb)) - ; - else if (unformat (i, "rate_type %U", unformat_policer_rate_type, - &rate_type)) - ; - else if (unformat (i, "round_type %U", unformat_policer_round_type, - &round_type)) - ; - else if (unformat (i, "type %U", unformat_policer_type, &type)) - ; - else if (unformat (i, "conform_action %U", unformat_policer_action_type, - &conform_action)) - ; - else if (unformat (i, "exceed_action %U", unformat_policer_action_type, - &exceed_action)) - ; - else if (unformat (i, "violate_action %U", unformat_policer_action_type, - &violate_action)) - ; - else if (unformat (i, "color-aware")) - color_aware = 1; - else - break; - } - - if (!vec_len (name)) - { - errmsg ("policer name must be specified"); - return -99; - } - - if (vec_len (name) > 64) - { - errmsg ("policer name too long"); - return -99; - } - - M (POLICER_ADD_DEL, mp); - - clib_memcpy (mp->name, name, vec_len (name)); - vec_free (name); - mp->is_add = is_add; - mp->cir = ntohl (cir); - mp->eir = ntohl (eir); - mp->cb = clib_net_to_host_u64 (cb); - mp->eb = clib_net_to_host_u64 (eb); - mp->rate_type = rate_type; - mp->round_type = round_type; - mp->type = type; - mp->conform_action.type = - (vl_api_sse2_qos_action_type_t) conform_action.action_type; - mp->conform_action.dscp = conform_action.dscp; - mp->exceed_action.type = - (vl_api_sse2_qos_action_type_t) exceed_action.action_type; - mp->exceed_action.dscp = exceed_action.dscp; - mp->violate_action.type = - (vl_api_sse2_qos_action_type_t) violate_action.action_type; - mp->violate_action.dscp = violate_action.dscp; - mp->color_aware = color_aware; - - S (mp); - W (ret); - return ret; -} - -static int -api_policer_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_policer_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u8 *match_name = 0; - u8 match_name_valid = 0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "name %s", &match_name)) - { - vec_add1 (match_name, 0); - match_name_valid = 1; - } - else - break; - } - - M (POLICER_DUMP, mp); - mp->match_name_valid = match_name_valid; - clib_memcpy (mp->match_name, match_name, vec_len (match_name)); - vec_free (match_name); - /* send it... */ - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ - W (ret); - return ret; -} - static u8 * format_fib_api_path_nh_proto (u8 * s, va_list * args) { @@ -12291,8 +11808,6 @@ _(ioam_disable, "") \ _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \ _(af_packet_delete, "name <host interface name>") \ _(af_packet_dump, "") \ -_(policer_add_del, "name <policer name> <params> [del]") \ -_(policer_dump, "[name <policer name>]") \ _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \ _(mpls_table_dump, "") \ _(mpls_route_dump, "table-id <ID>") \ diff --git a/src/vnet/policer/policer.h b/src/vnet/policer/policer.h index d9c4ed2a451..2687064bf0d 100644 --- a/src/vnet/policer/policer.h +++ b/src/vnet/policer/policer.h @@ -49,6 +49,8 @@ typedef struct /* frame queue for thread handoff */ u32 fq_index; + + u16 msg_id_base; } vnet_policer_main_t; extern vnet_policer_main_t vnet_policer_main; diff --git a/src/vnet/policer/policer_api.c b/src/vnet/policer/policer_api.c index c3a9800e201..1382d17e2de 100644 --- a/src/vnet/policer/policer_api.c +++ b/src/vnet/policer/policer_api.c @@ -24,30 +24,13 @@ #include <vnet/api_errno.h> #include <vnet/policer/policer.h> -#include <vnet/vnet_msg_enum.h> - -#define vl_typedefs /* define message structures */ -#include <vnet/vnet_all_api_h.h> -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include <vnet/vnet_all_api_h.h> -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include <vnet/vnet_all_api_h.h> -#undef vl_printfun +#include <vnet/format_fns.h> +#include <vnet/policer/policer.api_enum.h> +#include <vnet/policer/policer.api_types.h> +#define REPLY_MSG_ID_BASE vnet_policer_main.msg_id_base #include <vlibapi/api_helper_macros.h> -#define foreach_vpe_api_msg \ - _ (POLICER_ADD_DEL, policer_add_del) \ - _ (POLICER_BIND, policer_bind) \ - _ (POLICER_INPUT, policer_input) \ - _ (POLICER_DUMP, policer_dump) - static void vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp) { @@ -150,7 +133,7 @@ send_policer_details (u8 *name, qos_pol_cfg_params_st *config, mp = vl_msg_api_alloc (sizeof (*mp)); clib_memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS); + mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_POLICER_DETAILS); mp->context = context; mp->cir = htonl (config->rb.kbps.cir_kbps); mp->eir = htonl (config->rb.kbps.eir_kbps); @@ -233,43 +216,14 @@ vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp) } } -/* - * policer_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include <vnet/vnet_all_api_h.h> -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_policer; -#undef _ -} - +#include <vnet/policer/policer.api.c> static clib_error_t * policer_api_hookup (vlib_main_t * vm) { - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_vpe_api_msg; -#undef _ /* * Set up the (msg_name, crc, message-id) table */ - setup_message_id_table (am); + REPLY_MSG_ID_BASE = setup_message_id_table (); return 0; } diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index 53f61fa8803..872729cc441 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -46,7 +46,6 @@ #include <vnet/mpls/mpls.api.h> #include <vnet/srv6/sr.api.h> #include <vnet/srmpls/sr_mpls.api.h> -#include <vnet/policer/policer.api.h> #include <vnet/ethernet/p2p_ethernet.api.h> #include <vnet/tcp/tcp.api.h> #include <vnet/ip/punt.api.h> |