34 #if VALIDATION_SCAFFOLDING 51 u32 active_elements = 0;
74 clib_warning (
"found %u expected %u elts", active_elements,
94 vec_add1 (cm->unformat_l2_next_index_fns, fn);
102 vec_add1 (cm->unformat_ip_next_index_fns, fn);
110 vec_add1 (cm->unformat_acl_next_index_fns, fn);
119 vec_add1 (cm->unformat_policer_next_index_fns, fn);
127 vec_add1 (cm->unformat_opaque_index_fns, fn);
138 nbuckets = 1 << (
max_log2 (nbuckets));
165 u32 table_index,
int del_chain)
236 int working_copy_length, required_length;
261 if (required_length > working_copy_length)
276 working_bucket.as_u64 = b->
as_u64;
279 b->
as_u64 = working_bucket.as_u64;
289 int i, j, length_in_entries;
294 for (i = 0; i < length_in_entries; i++)
304 key_minus_skip = (
u8 *) v->key;
309 new_hash &= (1 << new_log2_pages) - 1;
337 u32 old_log2_pages,
u32 new_log2_pages)
340 int i, j, new_length_in_entries, old_length_in_entries;
347 for (i = 0; i < old_length_in_entries; i++)
353 for (; j < new_length_in_entries; j++)
359 clib_warning (
"BUG: linear rehash new entry not free!");
429 u32 old_log2_pages, new_log2_pages;
432 int resplit_once = 0;
433 int mark_bucket_linear;
437 key_minus_skip = (
u8 *) add_v->key;
442 bucket_index = hash & (t->
nbuckets - 1);
481 limit *= (1 << b->log2_pages);
491 for (i = 0; i < limit; i++)
509 for (i = 0; i < limit; i++)
530 for (i = 0; i < limit; i++)
554 new_log2_pages = old_log2_pages + 1;
560 mark_bucket_linear = 0;
584 mark_bucket_linear = 1;
591 key_minus_skip = (
u8 *) add_v->key;
596 new_hash &= (1 << new_log2_pages) - 1;
599 if (mark_bucket_linear)
601 limit *= (1 << new_log2_pages);
605 for (i = 0; i < limit; i++)
647 }) classify_data_or_mask_t;
670 (s,
"[%u]: next_index %d advance %d opaque %d action %d metadata %d\n",
672 e->opaque_index, e->action, e->metadata);
679 s =
format (s,
" hits %lld, last_heard %.2f\n",
680 e->hits, e->last_heard);
682 s =
format (s,
" entry is free\n");
690 int verbose = va_arg (*args,
int);
694 u64 active_elements = 0;
702 s =
format (s,
"[%d]: empty\n", i);
708 s =
format (s,
"[%d]: heap offset %d, elts %d, %s\n", i,
725 s =
format (s,
" %d: empty\n",
731 s =
format (s,
" %d: %U\n",
740 s =
format (s,
" %lld active elements\n", active_elements);
749 u32 match,
u32 next_table_index,
750 u32 miss_next_index,
u32 *table_index,
751 u8 current_data_flag,
i16 current_data_offset,
752 int is_add,
int del_chain)
758 if (*table_index == ~0)
760 if (memory_size == 0)
761 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
764 return VNET_API_ERROR_INVALID_VALUE;
766 if (match < 1 || match > 5)
767 return VNET_API_ERROR_INVALID_VALUE;
775 *table_index = t - cm->tables;
791 #define foreach_tcp_proto_field \ 795 #define foreach_udp_proto_field \ 799 #define foreach_ip4_proto_field \ 812 u8 **maskp = va_arg (*args,
u8 **);
814 u8 found_something = 0;
824 #define _(a) else if (unformat (input, #a)) a=1; 831 #define _(a) found_something += a; 835 if (found_something == 0)
842 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a)); 853 u8 **maskp = va_arg (*args,
u8 **);
855 u8 found_something = 0;
865 #define _(a) else if (unformat (input, #a)) a=1; 872 #define _(a) found_something += a; 876 if (found_something == 0)
883 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a)); 899 u8 **maskp = va_arg (*args,
u8 **);
909 else if (
unformat (input,
"src_port"))
911 else if (
unformat (input,
"dst_port"))
935 u8 **maskp = va_arg (*args,
u8 **);
937 u8 found_something = 0;
939 u32 src_prefix_len = 32;
940 u32 src_prefix_mask = ~0;
941 u32 dst_prefix_len = 32;
942 u32 dst_prefix_mask = ~0;
955 else if (
unformat (input,
"hdr_length"))
957 else if (
unformat (input,
"src/%d", &src_prefix_len))
960 src_prefix_mask &= ~((1 << (32 - src_prefix_len)) - 1);
961 src_prefix_mask = clib_host_to_net_u32 (src_prefix_mask);
963 else if (
unformat (input,
"dst/%d", &dst_prefix_len))
966 dst_prefix_mask &= ~((1 << (32 - dst_prefix_len)) - 1);
967 dst_prefix_mask = clib_host_to_net_u32 (dst_prefix_mask);
976 #define _(a) else if (unformat (input, #a)) a=1; 983 found_something = version + hdr_length;
984 #define _(a) found_something += a; 988 if (found_something == 0)
995 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); 1017 #define foreach_ip6_proto_field \ 1027 u8 **maskp = va_arg (*args,
u8 **);
1031 u32 ip_version_traffic_class_and_flow_label;
1033 #define _(a) u8 a=0; 1037 u8 traffic_class = 0;
1044 else if (
unformat (input,
"traffic-class"))
1046 else if (
unformat (input,
"flow-label"))
1052 else if (
unformat (input,
"proto"))
1055 #define _(a) else if (unformat (input, #a)) a=1; 1063 found_something = version + traffic_class + flow_label
1066 #define _(a) found_something += a; 1070 if (found_something == 0)
1077 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); 1081 ip_version_traffic_class_and_flow_label = 0;
1084 ip_version_traffic_class_and_flow_label |= 0xF0000000;
1087 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
1090 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
1093 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
1102 u8 **maskp = va_arg (*args,
u8 **);
1119 u8 **maskp = va_arg (*args,
u8 **);
1140 else if (
unformat (input,
"proto"))
1146 else if (
unformat (input,
"ignore-tag1"))
1148 else if (
unformat (input,
"ignore-tag2"))
1154 else if (
unformat (input,
"dot1q"))
1156 else if (
unformat (input,
"dot1ad"))
1161 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
1162 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
1165 if (tag1 || ignore_tag1 || cos1 || dot1q)
1167 if (tag2 || ignore_tag2 || cos2 || dot1ad)
1189 mask[21] = mask[20] = 0xff;
1210 mask[16] = mask[17] = 0xff;
1219 mask[12] = mask[13] = 0xff;
1228 u8 **maskp = va_arg (*args,
u8 **);
1229 u32 *skipp = va_arg (*args,
u32 *);
1230 u32 *matchp = va_arg (*args,
u32 *);
1260 if (mask || l2 || l3 || l4)
1281 for (i = 0; i <
vec_len (mask); i++)
1286 *skipp = i /
sizeof (
u32x4);
1290 while (vec_len (mask) %
sizeof (
u32x4))
1295 for (i = match *
sizeof (
u32x4); i > 0; i -=
sizeof (
u32x4))
1298 if (*tmp || *(tmp + 1))
1305 _vec_len (mask) = match *
sizeof (
u32x4);
1316 #define foreach_l2_input_next \ 1318 _(ethernet, ETHERNET_INPUT) \ 1327 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1333 for (i = 0; i <
vec_len (cm->unformat_l2_next_index_fns); i++)
1335 if (
unformat (input,
"%U", cm->unformat_l2_next_index_fns[i], &tmp))
1343 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;} 1360 #define foreach_l2_output_next \ 1367 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1373 for (i = 0; i <
vec_len (cm->unformat_l2_next_index_fns); i++)
1375 if (
unformat (input,
"%U", cm->unformat_l2_next_index_fns[i], &tmp))
1383 if (unformat (input, #n)) { next_index = L2_OUTPUT_CLASSIFY_NEXT_##N; goto out;} 1400 #define foreach_ip_next \ 1407 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1414 for (i = 0; i <
vec_len (cm->unformat_ip_next_index_fns); i++)
1416 if (
unformat (input,
"%U", cm->unformat_ip_next_index_fns[i], &tmp))
1424 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;} 1441 #define foreach_acl_next \ 1447 u32 *next_indexp = va_arg (*args,
u32 *);
1454 for (i = 0; i <
vec_len (cm->unformat_acl_next_index_fns); i++)
1456 if (
unformat (input,
"%U", cm->unformat_acl_next_index_fns[i], &tmp))
1464 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;} 1473 else if (
unformat (input,
"%d", &tmp))
1489 u32 *next_indexp = va_arg (*args,
u32 *);
1496 for (i = 0; i <
vec_len (cm->unformat_policer_next_index_fns); i++)
1499 (input,
"%U", cm->unformat_policer_next_index_fns[i], &tmp))
1528 u32 table_index = ~0;
1529 u32 next_table_index = ~0;
1530 u32 miss_next_index = ~0;
1533 u32 current_data_flag = 0;
1534 int current_data_offset = 0;
1544 else if (
unformat (input,
"del-chain"))
1549 else if (
unformat (input,
"buckets %d", &nbuckets))
1551 else if (
unformat (input,
"skip %d", &skip))
1553 else if (
unformat (input,
"match %d", &match))
1555 else if (
unformat (input,
"table %d", &table_index))
1558 &mask, &skip, &match))
1560 else if (
unformat (input,
"memory-size %uM", &tmp))
1561 memory_size = tmp << 20;
1562 else if (
unformat (input,
"memory-size %uG", &tmp))
1563 memory_size = tmp << 30;
1564 else if (
unformat (input,
"next-table %d", &next_table_index))
1582 else if (
unformat (input,
"current-data-flag %d", ¤t_data_flag))
1585 if (
unformat (input,
"current-data-offset %d", ¤t_data_offset))
1592 if (is_add && mask == 0 && table_index == ~0)
1595 if (is_add && skip == ~0 && table_index == ~0)
1598 if (is_add && match == ~0 && table_index == ~0)
1601 if (!is_add && table_index == ~0)
1605 skip, match, next_table_index,
1606 miss_next_index, &table_index,
1607 current_data_flag, current_data_offset,
1624 .path =
"classify table",
1626 "classify table [miss-next|l2-miss_next|acl-miss-next <next_index>]" 1627 "\n mask <mask-value> buckets <nn> [skip <n>] [match <n>]" 1628 "\n [current-data-flag <n>] [current-data-offset <n>] [table <n>]" 1629 "\n [memory-size <nn>[M][G]] [next-table <n>]" 1630 "\n [del] [del-chain]",
1703 for (i = 0; i <
vec_len (tables); i++)
1707 if ((i + 1) < vec_len (tables))
1713 table_index = tables[0];
1736 if (table_index == ~0)
1738 u32 old_table_index;
1751 u32 table_index = ~0;
1753 if (sw_if_index != ~0
1754 && (sw_if_index <
vec_len (cm->classify_table_index_by_sw_if_index)))
1755 table_index = cm->classify_table_index_by_sw_if_index[
sw_if_index];
1766 if (sw_if_index != ~0 && table_index != ~0)
1770 if (table_index == ~0)
1772 u32 old_table_index = ~0;
1774 if (sw_if_index <
vec_len (cm->classify_table_index_by_sw_if_index))
1776 cm->classify_table_index_by_sw_if_index[
sw_if_index];
1785 if (
vec_len (cm->classify_table_index_by_sw_if_index) > sw_if_index)
1786 cm->classify_table_index_by_sw_if_index[
sw_if_index] = table_index;
1787 if (sw_if_index > 0)
1806 if (table_index == ~0)
1845 u32 table_index = ~0;
1846 u32 next_table_index = ~0;
1847 u32 miss_next_index = ~0;
1848 u32 current_data_flag = 0;
1849 int current_data_offset = 0;
1868 else if (
unformat (line_input,
"pcap %=", &pcap, 1))
1870 else if (
unformat (line_input,
"trace"))
1872 else if (
unformat (line_input,
"%U",
1875 if (sw_if_index == 0)
1878 else if (
unformat (line_input,
"buckets %d", &nbuckets))
1881 &mask, &skip, &match))
1890 if (is_add && mask == 0)
1893 else if (is_add && skip == ~0)
1896 else if (is_add && match == ~0)
1899 else if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
1902 else if (pkt_trace && pcap)
1904 (0,
"Packet trace and pcap are mutually exclusive...");
1906 else if (pkt_trace && sw_if_index != ~0)
1939 if (table_index != ~0)
1949 next_table_index = table_index;
1956 if (table_index == ~0)
1965 skip, match, next_table_index,
1966 miss_next_index, &table_index,
1968 current_data_offset, 1, 0);
1975 "vnet_classify_add_del_table returned %d",
2000 cm, &match_vector, table_index) == 0)
2110 .path =
"classify filter",
2112 "classify filter <intfc> | pcap mask <mask-value> match <match-value>\n" 2113 " | trace mask <mask-value> match <match-value> [del]\n" 2114 " [buckets <nn>] [memory-size <n>]",
2132 (void)
unformat (input,
"verbose %=", &verbose, 1);
2137 limit =
vec_len (cm->classify_table_index_by_sw_if_index);
2139 for (i = -1; i < limit; i++)
2145 name =
format (0,
"packet tracer:");
2149 table_index = cm->classify_table_index_by_sw_if_index[
i];
2150 name =
format (0,
"pcap rx/tx/drop:");
2154 table_index = cm->classify_table_index_by_sw_if_index[
i];
2169 s =
format (s,
" %u", j);
2181 if (table_index != ~0)
2182 s =
format (s,
" %u", table_index);
2200 .path =
"show classify filter",
2201 .short_help =
"show classify filter [verbose [nn]]",
2210 int verbose = va_arg (*args,
int);
2216 s =
format (s,
"%10s%10s%10s%10s",
"TableIdx",
"Sessions",
"NextTbl",
2217 "NextNode", verbose ?
"Details" :
"");
2228 s =
format (s,
"\n nbuckets %d, skip %d match %d flag %d offset %d",
2250 u32 match_index = ~0;
2257 if (
unformat (input,
"index %d", &match_index))
2259 else if (
unformat (input,
"verbose %d", &verbose))
2261 else if (
unformat (input,
"verbose"))
2270 if (match_index == ~0 || (match_index == t - cm->tables))
2271 vec_add1 (indices, t - cm->tables);
2279 for (i = 0; i <
vec_len (indices); i++)
2281 verbose, indices[i]);
2293 .path =
"show classify tables",
2294 .short_help =
"show classify tables [index <nn>]",
2302 u8 **matchp = va_arg (*args,
u8 **);
2304 u8 *proto_header = 0;
2312 if (
unformat (input,
"src_port %d", &src_port))
2314 else if (
unformat (input,
"dst_port %d", &dst_port))
2320 h.
src_port = clib_host_to_net_u16 (src_port);
2321 h.
dst_port = clib_host_to_net_u16 (dst_port);
2323 memcpy (proto_header, &h,
sizeof (h));
2325 *matchp = proto_header;
2333 u8 **matchp = va_arg (*args,
u8 **);
2348 int fragment_id = 0;
2349 u32 fragment_id_val;
2357 if (
unformat (input,
"version %d", &version_val))
2359 else if (
unformat (input,
"hdr_length %d", &hdr_length_val))
2365 else if (
unformat (input,
"proto %d", &proto_val))
2367 else if (
unformat (input,
"tos %d", &tos_val))
2369 else if (
unformat (input,
"length %d", &length_val))
2371 else if (
unformat (input,
"fragment_id %d", &fragment_id_val))
2373 else if (
unformat (input,
"ttl %d", &ttl_val))
2375 else if (
unformat (input,
"checksum %d", &checksum_val))
2381 if (version + hdr_length + src +
dst + proto + tos + length + fragment_id
2382 + ttl + checksum == 0)
2414 ip->
length = clib_host_to_net_u16 (length_val);
2420 ip->
checksum = clib_host_to_net_u16 (checksum_val);
2429 u8 **matchp = va_arg (*args,
u8 **);
2434 u8 traffic_class = 0;
2435 u32 traffic_class_val;
2439 ip6_address_t src_val, dst_val;
2442 int payload_length = 0;
2443 u32 payload_length_val;
2446 u32 ip_version_traffic_class_and_flow_label;
2450 if (
unformat (input,
"version %d", &version_val))
2452 else if (
unformat (input,
"traffic_class %d", &traffic_class_val))
2454 else if (
unformat (input,
"flow_label %d", &flow_label_val))
2460 else if (
unformat (input,
"proto %d", &proto_val))
2462 else if (
unformat (input,
"payload_length %d", &payload_length_val))
2464 else if (
unformat (input,
"hop_limit %d", &hop_limit_val))
2470 if (version + traffic_class + flow_label + src +
dst + proto +
2471 payload_length + hop_limit == 0)
2490 ip_version_traffic_class_and_flow_label = 0;
2493 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
2496 ip_version_traffic_class_and_flow_label |=
2497 (traffic_class_val & 0xFF) << 20;
2500 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
2503 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
2518 u8 **matchp = va_arg (*args,
u8 **);
2536 u8 *tagp = va_arg (*args,
u8 *);
2541 tagp[0] = (tag >> 8) & 0x0F;
2542 tagp[1] = tag & 0xFF;
2552 u8 **matchp = va_arg (*args,
u8 **);
2579 else if (
unformat (input,
"proto %U",
2586 else if (
unformat (input,
"ignore-tag1"))
2588 else if (
unformat (input,
"ignore-tag2"))
2590 else if (
unformat (input,
"cos1 %d", &cos1_val))
2592 else if (
unformat (input,
"cos2 %d", &cos2_val))
2597 if ((src + dst + proto + tag1 + tag2 +
2598 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
2601 if (tag1 || ignore_tag1 || cos1)
2603 if (tag2 || ignore_tag2 || cos2)
2617 match[19] = tag2_val[1];
2618 match[18] = tag2_val[0];
2620 match[18] |= (cos2_val & 0x7) << 5;
2623 match[21] = proto_val & 0xff;
2624 match[20] = proto_val >> 8;
2628 match[15] = tag1_val[1];
2629 match[14] = tag1_val[0];
2632 match[14] |= (cos1_val & 0x7) << 5;
2638 match[15] = tag1_val[1];
2639 match[14] = tag1_val[0];
2642 match[17] = proto_val & 0xff;
2643 match[16] = proto_val >> 8;
2646 match[14] |= (cos1_val & 0x7) << 5;
2652 match[18] |= (cos2_val & 0x7) << 5;
2654 match[14] |= (cos1_val & 0x7) << 5;
2657 match[13] = proto_val & 0xff;
2658 match[12] = proto_val >> 8;
2670 u8 **matchp = va_arg (*args,
u8 **);
2671 u32 table_index = va_arg (*args,
u32);
2706 if (match || l2 || l3 || l4)
2746 const u8 *match,
u32 hit_next_index,
2748 u16 metadata,
int is_add)
2751 vnet_classify_entry_5_t _max_e __attribute__ ((aligned (16)));
2756 return VNET_API_ERROR_NO_SUCH_TABLE;
2761 e->next_index = hit_next_index;
2762 e->opaque_index = opaque_index;
2763 e->advance = advance;
2777 e->metadata = metadata;
2787 e->key[i] &= t->
mask[i];
2794 return VNET_API_ERROR_NO_SUCH_ENTRY;
2805 u32 table_index = ~0;
2806 u32 hit_next_index = ~0;
2807 u64 opaque_index = ~0;
2834 else if (
unformat (input,
"policer-hit-next %U",
2837 else if (
unformat (input,
"opaque-index %lld", &opaque_index))
2840 cm, &match, table_index))
2842 else if (
unformat (input,
"advance %d", &advance))
2844 else if (
unformat (input,
"table-index %d", &table_index))
2846 else if (
unformat (input,
"action set-ip4-fib-id %d", &metadata))
2848 else if (
unformat (input,
"action set-ip6-fib-id %d", &metadata))
2850 else if (
unformat (input,
"action set-sr-policy-index %d", &metadata))
2855 for (i = 0; i <
vec_len (cm->unformat_opaque_index_fns); i++)
2857 if (
unformat (input,
"%U", cm->unformat_opaque_index_fns[i],
2867 if (table_index == ~0)
2870 if (is_add && match == 0)
2875 opaque_index, advance,
2876 action, metadata, is_add);
2885 "vnet_classify_add_del_session returned %d",
2894 .path =
"classify session",
2896 "classify session [hit-next|l2-input-hit-next|l2-output-hit-next|" 2897 "acl-hit-next <next_index>|policer-hit-next <policer_name>]" 2898 "\n table-index <nn> match [hex] [l2] [l3 ip4] [opaque-index <index>]" 2899 "\n [action set-ip4-fib-id|set-ip6-fib-id|set-sr-policy-index <n>] [del]",
2907 u64 *opaquep = va_arg (*args,
u64 *);
2923 u32 *next_indexp = va_arg (*args,
u32 *);
2928 cm->vlib_main, &node_index))
2934 cm->vlib_main, &node_index))
2950 u32 *next_indexp = va_arg (*args,
u32 *);
2955 cm->vlib_main, &node_index))
2961 cm->vlib_main, &node_index))
2977 u32 *next_indexp = va_arg (*args,
u32 *);
2982 cm->vlib_main, &node_index))
2997 u32 *next_indexp = va_arg (*args,
u32 *);
3002 cm->vlib_main, &node_index))
3076 classify_data_or_mask_t *
mask;
3077 classify_data_or_mask_t *
data;
3083 } test_classify_main_t;
3085 static test_classify_main_t test_classify_main;
3088 test_classify_churn (test_classify_main_t * tm)
3090 classify_data_or_mask_t *
mask, *
data;
3093 u8 *mp = 0, *dp = 0;
3100 mask = (classify_data_or_mask_t *) mp;
3101 data = (classify_data_or_mask_t *) dp;
3106 tmp = clib_host_to_net_u32 (tm->src.as_u32);
3108 for (i = 0; i < tm->sessions; i++)
3111 ep->addr.as_u32 = clib_host_to_net_u32 (tmp);
3119 tm->memory_size, 0 ,
3122 tm->table_index = tm->table - tm->classify_main->tables;
3124 tm->table_index, tm->buckets);
3126 vlib_cli_output (vm,
"Initialize: add %d (approx. half of %d sessions)...",
3127 tm->sessions / 2, tm->sessions);
3129 for (i = 0; i < tm->sessions / 2; i++)
3133 data->ip.src_address.as_u32 = ep->addr.as_u32;
3156 for (i = 0; i < tm->iterations; i++)
3161 index =
random_u32 (&tm->seed) % tm->sessions;
3165 data->ip.src_address.as_u32 = ep->addr.as_u32;
3168 is_add = !ep->in_table;
3172 is_add ?
"add" :
"del",
3186 "%s[%d]: %U returned %d", is_add ?
"add" :
"del",
3189 ep->in_table = is_add;
3193 tm->table->active_elements);
3195 for (i = 0; i < tm->sessions; i++)
3201 ep = tm->entries +
i;
3202 if (ep->in_table == 0)
3205 data->ip.src_address.as_u32 = ep->addr.as_u32;
3210 (
u8 *) data, hash, 0 );
3213 clib_warning (
"Couldn't find %U index %d which should be present",
3218 key_minus_skip = (
u8 *) e->key;
3219 key_minus_skip -= tm->table->skip_n_vectors * sizeof (
u32x4);
3236 tm->table->active_elements);
3245 tm->table_index, 1 );
3247 tm->table_index = ~0;
3257 test_classify_main_t *tm = &test_classify_main;
3264 tm->sessions = 8192;
3265 tm->iterations = 8192;
3266 tm->memory_size = 64 << 20;
3267 tm->src.as_u32 = clib_net_to_host_u32 (0x0100000A);
3269 tm->seed = 0xDEADDABE;
3270 tm->classify_main =
cm;
3278 if (
unformat (input,
"sessions %d", &tmp))
3283 else if (
unformat (input,
"buckets %d", &tm->buckets))
3285 else if (
unformat (input,
"memory-size %uM", &tmp))
3286 tm->memory_size = tmp << 20;
3287 else if (
unformat (input,
"memory-size %uG", &tmp))
3288 tm->memory_size = tmp << 30;
3289 else if (
unformat (input,
"seed %d", &tm->seed))
3291 else if (
unformat (input,
"verbose"))
3294 else if (
unformat (input,
"iterations %d", &tm->iterations))
3296 else if (
unformat (input,
"churn-test"))
3305 error = test_classify_churn (tm);
3317 .path =
"test classify",
3319 "test classify [src <ip>] [sessions <nn>] [buckets <nn>] [seed <nnn>]\n" 3320 " [memory-size <nn>[M|G]]\n" 3322 .function = test_classify_command_fn,
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) ...
vnet_classify_entry_t ** working_copies
uword unformat_classify_mask(unformat_input_t *input, va_list *args)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
void rogue(vnet_classify_table_t *t)
static clib_error_t * show_classify_tables_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * classify_filter_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define pool_foreach(VAR, POOL)
Iterate through pool.
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
#define VNET_CLASSIFY_ENTRY_FREE
vl_api_ip_port_and_mask_t dst_port
vl_api_ip_proto_t protocol
vnet_feature_config_main_t * cm
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
uword unformat_vlan_tag(unformat_input_t *input, va_list *args)
static clib_error_t * classify_table_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void vnet_classify_entry_claim_resource(vnet_classify_entry_t *e)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int vnet_is_packet_traced(vlib_buffer_t *b, u32 classify_table_index, int func)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
for(i=1;i<=collision_buckets;i++)
u32 classify_lookup_chain(u32 table_index, u8 *mask, u32 n_skip, u32 n_match)
vnet_classify_flags_t current_data_flag
unformat_function_t unformat_vnet_sw_interface
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
#define foreach_ip6_proto_field
void vnet_classify_register_unformat_acl_next_index_fn(unformat_function_t *fn)
struct _tcp_header tcp_header_t
int vnet_classify_add_del_table(vnet_classify_main_t *cm, const u8 *mask, u32 nbuckets, u32 memory_size, u32 skip, u32 match, u32 next_table_index, u32 miss_next_index, u32 *table_index, u8 current_data_flag, i16 current_data_offset, int is_add, int del_chain)
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
vlib_node_registration_t ip4_classify_node
(constructor) VLIB_REGISTER_NODE (ip4_classify_node)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
uword unformat_l2_output_next_index(unformat_input_t *input, va_list *args)
u32 classify_get_pcap_chain(vnet_classify_main_t *cm, u32 sw_if_index)
void mv(vnet_classify_table_t *t)
vlib_node_registration_t l2_input_classify_node
(constructor) VLIB_REGISTER_NODE (l2_input_classify_node)
#define VLIB_INIT_FUNCTION(x)
clib_spinlock_t writer_lock
static clib_error_t * classify_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword unformat_l2_mask(unformat_input_t *input, va_list *args)
int vnet_classify_add_del_session(vnet_classify_main_t *cm, u32 table_index, const u8 *match, u32 hit_next_index, u32 opaque_index, i32 advance, u8 action, u16 metadata, int is_add)
vlib_node_registration_t l2_output_classify_node
(constructor) VLIB_REGISTER_NODE (l2_output_classify_node)
description fragment has unexpected format
static uword unformat_l2_input_next_node(unformat_input_t *input, va_list *args)
uword unformat_classify_match(unformat_input_t *input, va_list *args)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
vnet_main_t * vnet_get_main(void)
#define foreach_ip4_proto_field
Use the vpp classifier to decide whether to trace packets.
struct _vnet_classify_entry vnet_classify_entry_t
static void clib_spinlock_init(clib_spinlock_t *p)
static uword unformat_opaque_sw_if_index(unformat_input_t *input, va_list *args)
static int vnet_classify_entry_is_free(vnet_classify_entry_t *e)
uword unformat_l4_match(unformat_input_t *input, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vl_api_interface_index_t sw_if_index
void clib_mem_destroy_heap(clib_mem_heap_t *heap)
uword unformat_ip4_mask(unformat_input_t *input, va_list *args)
uword unformat_l2_input_next_index(unformat_input_t *input, va_list *args)
uword unformat_ip6_mask(unformat_input_t *input, va_list *args)
void vnet_classify_delete_table_index(vnet_classify_main_t *cm, u32 table_index, int del_chain)
static clib_error_t * show_classify_filter_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_put(P, E)
Free an object E in pool P.
vnet_classify_table_t * vnet_classify_new_table(vnet_classify_main_t *cm, const u8 *mask, u32 nbuckets, u32 memory_size, u32 skip_n_vectors, u32 match_n_vectors)
static vnet_classify_entry_t * split_and_rehash_linear(vnet_classify_table_t *t, vnet_classify_entry_t *old_values, u32 old_log2_pages, u32 new_log2_pages)
void vnet_classify_register_unformat_opaque_index_fn(unformat_function_t *fn)
#define pool_get_aligned_zero(P, E, A)
Allocate an object E from a pool P with alignment A and zero it.
vl_api_address_union_t src_address
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static vnet_classify_entry_t * vnet_classify_entry_at_index(vnet_classify_table_t *t, vnet_classify_entry_t *e, u32 index)
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
uword unformat_policer_next_index(unformat_input_t *input, va_list *args)
vlib_node_registration_t ip4_inacl_node
(constructor) VLIB_REGISTER_NODE (ip4_inacl_node)
#define foreach_udp_proto_field
static vnet_classify_entry_t * split_and_rehash(vnet_classify_table_t *t, vnet_classify_entry_t *old_values, u32 old_log2_pages, u32 new_log2_pages)
vl_api_ip_port_and_mask_t src_port
uword unformat_udp_mask(unformat_input_t *input, va_list *args)
static uword vnet_classify_get_offset(vnet_classify_table_t *t, vnet_classify_entry_t *v)
static u8 * format_classify_entry(u8 *s, va_list *args)
uword unformat_l2_match(unformat_input_t *input, va_list *args)
vnet_classify_bucket_t saved_bucket
Adjacency to drop this packet.
static uword unformat_acl_next_node(unformat_input_t *input, va_list *args)
static_always_inline uword vlib_get_thread_index(void)
vlib_node_registration_t ip6_inacl_node
(constructor) VLIB_REGISTER_NODE (ip6_inacl_node)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
uword unformat_acl_next_index(unformat_input_t *input, va_list *args)
static uword unformat_ip_next_node(unformat_input_t *input, va_list *args)
static void vnet_classify_entry_free(vnet_classify_table_t *t, vnet_classify_entry_t *v, u32 log2_pages)
u8 * format_classify_table(u8 *s, va_list *args)
#define clib_warning(format, args...)
uword unformat_l3_match(unformat_input_t *input, va_list *args)
uword unformat_ip4_match(unformat_input_t *input, va_list *args)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static int vnet_is_packet_traced_inline(vlib_buffer_t *b, u32 classify_table_index, int func)
vnet_is_packet_traced
u8 * format_vnet_classify_table(u8 *s, va_list *args)
static clib_error_t * vnet_classify_init(vlib_main_t *vm)
u32 trace_classify_table_index
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
#define VLIB_CLI_COMMAND(x,...)
struct _vnet_classify_main vnet_classify_main_t
static uword unformat_l2_output_next_node(unformat_input_t *input, va_list *args)
static void make_working_copy(vnet_classify_table_t *t, vnet_classify_bucket_t *b)
static int vnet_classify_add_del(vnet_classify_table_t *t, vnet_classify_entry_t *add_v, int is_add)
static vnet_classify_entry_t * vnet_classify_find_entry_inline(vnet_classify_table_t *t, const u8 *h, u64 hash, f64 now)
uword unformat_l3_mask(unformat_input_t *input, va_list *args)
static int filter_table_mask_compare(void *a1, void *a2)
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
u8 * format_clib_mem_heap(u8 *s, va_list *va)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
uword unformat_ip6_match(unformat_input_t *input, va_list *args)
static void clib_mem_free(void *p)
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
#define vec_append(v1, v2)
Append v2 after v1.
uword unformat_ip_next_index(unformat_input_t *input, va_list *args)
vnet_classify_main_t vnet_classify_main
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
nat44_ei_hairpin_src_next_t next_index
static u64 vnet_classify_hash_packet_inline(vnet_classify_table_t *t, const u8 *h)
static void vnet_classify_entry_release_resource(vnet_classify_entry_t *e)
vlib_trace_filter_t trace_filter
int vlib_main(vlib_main_t *volatile vm, unformat_input_t *input)
static int vnet_classify_entry_is_busy(vnet_classify_entry_t *e)
#define CLIB_SPINLOCK_ASSERT_LOCKED(_p)
uword unformat_tcp_mask(unformat_input_t *input, va_list *args)
uword unformat_ethernet_type_host_byte_order(unformat_input_t *input, va_list *args)
vl_api_mac_event_action_t action
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_classify_bucket_t * buckets
void vnet_classify_register_unformat_ip_next_index_fn(unformat_function_t *fn)
static uword max_log2(uword x)
u32 classify_sort_table_chain(vnet_classify_main_t *cm, u32 table_index)
typedef CLIB_PACKED(struct { ethernet_header_t eh;ip4_header_t ip;})
VLIB buffer representation.
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
uword unformat_l4_mask(unformat_input_t *input, va_list *args)
#define vec_append_aligned(v1, v2, align)
Append v2 after v1.
void classify_set_pcap_chain(vnet_classify_main_t *cm, u32 sw_if_index, u32 table_index)
static vnet_classify_entry_t * vnet_classify_entry_alloc(vnet_classify_table_t *t, u32 log2_pages)
unformat_function_t unformat_vlib_node
static void * clib_mem_alloc_aligned(uword size, uword align)
int vlib_enable_disable_pkt_trace_filter(int enable)
Enable / disable packet trace filter.
static u32 random_u32(u32 *seed)
32-bit random number generator
u32 classify_get_trace_chain(void)
static uword count_set_bits(uword x)
#define foreach_l2_output_next
#define foreach_l2_input_next
int * working_copy_lengths
#define CLIB_MEMORY_BARRIER()
void vnet_classify_register_unformat_policer_next_index_fn(unformat_function_t *fn)
vlib_node_registration_t ip6_classify_node
(constructor) VLIB_REGISTER_NODE (ip6_classify_node)
#define foreach_tcp_proto_field
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
#define CLIB_CACHE_LINE_BYTES
vnet_classify_entry_t ** freelists
void classify_set_trace_chain(vnet_classify_main_t *cm, u32 table_index)
vnet_classify_entry_t * vnet_classify_find_entry(vnet_classify_table_t *t, u8 *h, u64 hash, f64 now)
vlib_global_main_t vlib_global_main
void vnet_classify_register_unformat_l2_next_index_fn(unformat_function_t *fn)
static vnet_classify_entry_t * vnet_classify_get_entry(vnet_classify_table_t *t, uword offset)