25 #define IP4_NON_DSCP_BITS 0x03 26 #define IP4_DSCP_SHIFT 2 27 #define IP6_NON_DSCP_BITS 0xf03fffff 28 #define IP6_DSCP_SHIFT 22 45 s =
format (s,
"VNET_POLICER: sw_if_index %d policer_index %d next %d",
50 #define foreach_vnet_policer_error \ 51 _(TRANSMIT, "Packets Transmitted") \ 52 _(DROP, "Packets Dropped") 55 #define _(sym,str) VNET_POLICER_ERROR_##sym, 62 #define _(sym,string) string, 76 type = clib_net_to_host_u16 (eh->
type);
102 u64 time_in_policer_periods,
112 pol = &pm->
policers [policer_index];
115 time_in_policer_periods);
129 u32 n_left_from, * from, * to_next;
132 u64 time_in_policer_periods;
135 time_in_policer_periods =
142 while (n_left_from > 0)
147 to_next, n_left_to_next);
149 while (n_left_from >= 4 && n_left_to_next >= 2)
154 u32 sw_if_index0, sw_if_index1;
155 u32 pi0 = 0, pi1 = 0;
170 to_next[0] = bi0 = from[0];
171 to_next[1] = bi1 = from[1];
202 pi0 = (pi0 != ~0) ? pi0 :
205 pi1 = (pi1 != ~0) ? pi1 :
256 to_next, n_left_to_next,
257 bi0, bi1, next0, next1);
260 while (n_left_from > 0 && n_left_to_next > 0)
290 pi0 = (pi0 != ~0) ? pi0 :
319 to_next, n_left_to_next,
327 VNET_POLICER_ERROR_TRANSMIT,
365 .name =
"policer-by-sw-if-index",
366 .vector_size =
sizeof (
u32),
399 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
418 policer[0] =
template[0];
448 u8 * config_name = 0;
462 else if (
unformat (line_input,
"show"))
464 else if (
unformat (line_input,
"policer %s", &config_name))
466 else if (
unformat (line_input,
"del"))
484 if (is_add && config_name == 0)
498 (0,
"WARNING: vnet_vnet_policer_add_del returned %d", rv);
505 .path =
"test policer",
507 "intfc <intfc> policer <policer-config-name> [del]",
530 s =
format (s,
"POLICER_CLASSIFY: sw_if_index %d next %d table %d offset %d" 537 #define foreach_policer_classify_error \ 538 _(MISS, "Policer classify misses") \ 539 _(HIT, "Policer classify hits") \ 540 _(CHAIN_HIT, "Polcier classify hits after chain walk") \ 541 _(DROP, "Policer classify action drop") 544 #define _(sym,str) POLICER_CLASSIFY_ERROR_##sym, 551 #define _(sym,string) string, 562 u32 n_left_from, * from, * to_next;
572 u64 time_in_policer_periods;
574 time_in_policer_periods =
583 while (n_left_from > 2)
588 u32 sw_if_index0, sw_if_index1;
589 u32 table_index0, table_index1;
633 vnet_buffer(b0)->l2_classify.table_index = table_index0;
635 vnet_buffer(b1)->l2_classify.table_index = table_index1;
641 while (n_left_from > 0)
661 vnet_buffer(b0)->l2_classify.table_index = table_index0;
672 while (n_left_from > 0)
679 while (n_left_from > 0 && n_left_to_next > 0)
686 vnet_classify_entry_t * e0;
699 table_index1 =
vnet_buffer(p1)->l2_classify.table_index;
719 table_index0 =
vnet_buffer(b0)->l2_classify.table_index;
726 vnet_buffer(b0)->l2.feature_bitmap &= ~L2INPUT_FEAT_POLICER_CLAS;
750 time_in_policer_periods,
755 b0->
error = node->
errors[POLICER_CLASSIFY_ERROR_DROP];
784 time_in_policer_periods,
789 b0->
error = node->
errors[POLICER_CLASSIFY_ERROR_DROP];
813 n_left_to_next, bi0, next0);
820 POLICER_CLASSIFY_ERROR_MISS,
823 POLICER_CLASSIFY_ERROR_HIT,
826 POLICER_CLASSIFY_ERROR_CHAIN_HIT,
829 POLICER_CLASSIFY_ERROR_DROP,
845 .name =
"ip4-policer-classify",
846 .vector_size =
sizeof (
u32),
868 .name =
"ip6-policer-classify",
869 .vector_size =
sizeof (
u32),
891 .name =
"l2-policer-classify",
892 .vector_size =
sizeof (
u32),
u64 vnet_classify_hash_packet(vnet_classify_table_t *t, u8 *h)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
#define foreach_vnet_policer_error
#define POLICER_TICKS_PER_PERIOD_SHIFT
VLIB_NODE_FUNCTION_MULTIARCH(policer_by_sw_if_index_node, vnet_policer_by_sw_if_index)
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
vlib_node_registration_t ip6_policer_classify_node
(constructor) VLIB_REGISTER_NODE (ip6_policer_classify_node)
uword * policer_config_by_name
static_always_inline void vnet_policer_mark(vlib_buffer_t *b, u8 dscp)
int vnet_hw_interface_rx_redirect_to_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
static f64 vlib_time_now(vlib_main_t *vm)
static uword l2_policer_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline u8 vnet_policer_police(vlib_main_t *vm, vlib_buffer_t *b, u32 policer_index, u64 time_in_policer_periods, policer_result_e packet_color)
static uword vnet_policer_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vnet_policer_index_t which)
int test_policer_add_del(u32 rx_sw_if_index, u8 *config_name, int is_add)
static u64 clib_cpu_time_now(void)
unformat_function_t unformat_vnet_sw_interface
u8 * format_policer_instance(u8 *s, va_list *va)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
policer_classify_table_id_t
static vlib_node_registration_t policer_by_sw_if_index_node
(constructor) VLIB_REGISTER_NODE (policer_by_sw_if_index_node)
vnet_main_t * vnet_get_main(void)
#define static_always_inline
uword vnet_policer_by_opaque(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_INIT_FUNCTION(x)
static char * vnet_policer_error_strings[]
static policer_result_e vnet_police_packet(policer_read_response_type_st *policer, uint32_t packet_length, policer_result_e packet_color, uint64_t time)
static void vnet_classify_prefetch_bucket(vnet_classify_table_t *t, u64 hash)
u32 * classify_table_index_by_sw_if_index[POLICER_CLASSIFY_N_TABLES]
static clib_error_t * policer_classify_init(vlib_main_t *vm)
static void vnet_classify_prefetch_entry(vnet_classify_table_t *t, u64 hash)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vnet_config_main_t * vnet_config_main[POLICER_CLASSIFY_N_TABLES]
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
static uword policer_classify_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, policer_classify_table_id_t tid)
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
policer_read_response_type_st * policers
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void vnet_policer_node_funcs_reference(void)
uword vnet_policer_by_sw_if_index(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
uword vnet_policer_by_either(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u32 * policer_index_by_sw_if_index
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static char * policer_classify_error_strings[]
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
static uword vnet_classify_get_offset(vnet_classify_table_t *t, vnet_classify_entry_t *v)
static uword ip4_policer_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define CLIB_PREFETCH(addr, size, type)
u32 feat_next_node_index[32]
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
#define IP4_NON_DSCP_BITS
struct _vnet_classify_main vnet_classify_main_t
#define foreach_policer_classify_error
#define pool_put_index(p, i)
Free pool element with given index.
#define VLIB_NODE_FLAG_TRACE
vnet_classify_main_t vnet_classify_main
policer_classify_next_index_t
#define IP6_NON_DSCP_BITS
#define VLIB_BUFFER_IS_TRACED
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vnet_classify_main_t * vnet_classify_main
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
vlib_node_registration_t ip4_policer_classify_node
(constructor) VLIB_REGISTER_NODE (ip4_policer_classify_node)
static clib_error_t * test_policer_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define hash_get_mem(h, key)
static uword ip6_policer_classify(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
policer_read_response_type_st * policer_templates
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
policer_classify_main_t policer_classify_main
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t l2_policer_classify_node
(constructor) VLIB_REGISTER_NODE (l2_policer_classify_node)
#define clib_error_return(e, args...)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
vnet_policer_main_t vnet_policer_main
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
vnet_classify_entry_t * vnet_classify_find_entry(vnet_classify_table_t *t, u8 *h, u64 hash, f64 now)
static u16 ip4_header_checksum(ip4_header_t *i)
static u8 * format_policer_trace(u8 *s, va_list *args)
static u8 * format_policer_classify_trace(u8 *s, va_list *args)