31 #if VALIDATION_SCAFFOLDING 47 vnet_classify_entry_t *v, *save_v;
48 u32 active_elements = 0;
71 clib_warning (
"found %u expected %u elts", active_elements,
91 vec_add1 (cm->unformat_l2_next_index_fns, fn);
99 vec_add1 (cm->unformat_ip_next_index_fns, fn);
107 vec_add1 (cm->unformat_acl_next_index_fns, fn);
116 vec_add1 (cm->unformat_policer_next_index_fns, fn);
124 vec_add1 (cm->unformat_opaque_index_fns, fn);
130 u32 skip_n_vectors,
u32 match_n_vectors)
135 nbuckets = 1 << (
max_log2 (nbuckets));
150 #if USE_DLMALLOC == 0 168 u32 table_index,
int del_chain)
183 #if USE_DLMALLOC == 0 192 static vnet_classify_entry_t *
195 vnet_classify_entry_t *rv = 0;
239 vnet_classify_entry_t *v;
242 vnet_classify_entry_t *working_copy;
244 int working_copy_length, required_length;
269 if (required_length > working_copy_length)
284 working_bucket.as_u64 = b->
as_u64;
287 b->
as_u64 = working_bucket.as_u64;
291 static vnet_classify_entry_t *
293 vnet_classify_entry_t * old_values,
u32 old_log2_pages,
296 vnet_classify_entry_t *new_values, *v, *new_v;
297 int i, j, length_in_entries;
302 for (i = 0; i < length_in_entries; i++)
312 key_minus_skip = (
u8 *) v->key;
317 new_hash &= (1 << new_log2_pages) - 1;
342 static vnet_classify_entry_t *
344 vnet_classify_entry_t * old_values,
345 u32 old_log2_pages,
u32 new_log2_pages)
347 vnet_classify_entry_t *new_values, *v, *new_v;
348 int i, j, new_length_in_entries, old_length_in_entries;
355 for (i = 0; i < old_length_in_entries; i++)
361 for (; j < new_length_in_entries; j++)
367 clib_warning (
"BUG: linear rehash new entry not free!");
425 vnet_classify_entry_t * add_v,
int is_add)
429 vnet_classify_entry_t *v, *new_v, *save_new_v, *working_copy, *save_v;
435 u32 old_log2_pages, new_log2_pages;
438 int resplit_once = 0;
439 int mark_bucket_linear;
443 key_minus_skip = (
u8 *) add_v->key;
448 bucket_index = hash & (t->
nbuckets - 1);
487 limit *= (1 << b->log2_pages);
497 for (i = 0; i < limit; i++)
515 for (i = 0; i < limit; i++)
536 for (i = 0; i < limit; i++)
544 clib_memset (v, 0xff,
sizeof (vnet_classify_entry_t) +
560 new_log2_pages = old_log2_pages + 1;
566 mark_bucket_linear = 0;
590 mark_bucket_linear = 1;
597 key_minus_skip = (
u8 *) add_v->key;
602 new_hash &= (1 << new_log2_pages) - 1;
605 if (mark_bucket_linear)
607 limit *= (1 << new_log2_pages);
611 for (i = 0; i < limit; i++)
653 }) classify_data_or_mask_t;
662 vnet_classify_entry_t *
673 vnet_classify_entry_t *e = va_arg (*args, vnet_classify_entry_t *);
676 (s,
"[%u]: next_index %d advance %d opaque %d action %d metadata %d\n",
678 e->opaque_index, e->action, e->metadata);
685 s =
format (s,
" hits %lld, last_heard %.2f\n",
686 e->hits, e->last_heard);
688 s =
format (s,
" entry is free\n");
696 int verbose = va_arg (*args,
int);
698 vnet_classify_entry_t *v, *save_v;
700 u64 active_elements = 0;
708 s =
format (s,
"[%d]: empty\n", i);
714 s =
format (s,
"[%d]: heap offset %d, elts %d, %s\n", i,
731 s =
format (s,
" %d: empty\n",
737 s =
format (s,
" %d: %U\n",
746 s =
format (s,
" %lld active elements\n", active_elements);
759 u32 next_table_index,
762 u8 current_data_flag,
763 i16 current_data_offset,
764 int is_add,
int del_chain)
770 if (*table_index == ~0)
772 if (memory_size == 0)
773 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
776 return VNET_API_ERROR_INVALID_VALUE;
778 if (match < 1 || match > 5)
779 return VNET_API_ERROR_INVALID_VALUE;
787 *table_index = t - cm->tables;
803 #define foreach_tcp_proto_field \ 807 #define foreach_udp_proto_field \ 811 #define foreach_ip4_proto_field \ 824 u8 **maskp = va_arg (*args,
u8 **);
826 u8 found_something = 0;
836 #define _(a) else if (unformat (input, #a)) a=1; 843 #define _(a) found_something += a; 847 if (found_something == 0)
854 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a)); 865 u8 **maskp = va_arg (*args,
u8 **);
867 u8 found_something = 0;
877 #define _(a) else if (unformat (input, #a)) a=1; 884 #define _(a) found_something += a; 888 if (found_something == 0)
895 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a)); 911 u8 **maskp = va_arg (*args,
u8 **);
921 else if (
unformat (input,
"src_port"))
923 else if (
unformat (input,
"dst_port"))
947 u8 **maskp = va_arg (*args,
u8 **);
949 u8 found_something = 0;
951 u32 src_prefix_len = 32;
952 u32 src_prefix_mask = ~0;
953 u32 dst_prefix_len = 32;
954 u32 dst_prefix_mask = ~0;
967 else if (
unformat (input,
"hdr_length"))
969 else if (
unformat (input,
"src/%d", &src_prefix_len))
972 src_prefix_mask &= ~((1 << (32 - src_prefix_len)) - 1);
973 src_prefix_mask = clib_host_to_net_u32 (src_prefix_mask);
975 else if (
unformat (input,
"dst/%d", &dst_prefix_len))
978 dst_prefix_mask &= ~((1 << (32 - dst_prefix_len)) - 1);
979 dst_prefix_mask = clib_host_to_net_u32 (dst_prefix_mask);
988 #define _(a) else if (unformat (input, #a)) a=1; 995 #define _(a) found_something += a; 999 if (found_something == 0)
1006 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); 1028 #define foreach_ip6_proto_field \ 1038 u8 **maskp = va_arg (*args,
u8 **);
1042 u32 ip_version_traffic_class_and_flow_label;
1044 #define _(a) u8 a=0; 1048 u8 traffic_class = 0;
1055 else if (
unformat (input,
"traffic-class"))
1057 else if (
unformat (input,
"flow-label"))
1063 else if (
unformat (input,
"proto"))
1066 #define _(a) else if (unformat (input, #a)) a=1; 1074 found_something = version + traffic_class + flow_label
1077 #define _(a) found_something += a; 1081 if (found_something == 0)
1088 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); 1092 ip_version_traffic_class_and_flow_label = 0;
1095 ip_version_traffic_class_and_flow_label |= 0xF0000000;
1098 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
1101 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
1104 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
1113 u8 **maskp = va_arg (*args,
u8 **);
1130 u8 **maskp = va_arg (*args,
u8 **);
1151 else if (
unformat (input,
"proto"))
1157 else if (
unformat (input,
"ignore-tag1"))
1159 else if (
unformat (input,
"ignore-tag2"))
1165 else if (
unformat (input,
"dot1q"))
1167 else if (
unformat (input,
"dot1ad"))
1172 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
1173 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
1176 if (tag1 || ignore_tag1 || cos1 || dot1q)
1178 if (tag2 || ignore_tag2 || cos2 || dot1ad)
1200 mask[21] = mask[20] = 0xff;
1221 mask[16] = mask[17] = 0xff;
1230 mask[12] = mask[13] = 0xff;
1239 u8 **maskp = va_arg (*args,
u8 **);
1240 u32 *skipp = va_arg (*args,
u32 *);
1241 u32 *matchp = va_arg (*args,
u32 *);
1271 if (mask || l2 || l3 || l4)
1292 for (i = 0; i <
vec_len (mask); i++)
1297 *skipp = i /
sizeof (
u32x4);
1301 while (vec_len (mask) %
sizeof (
u32x4))
1306 for (i = match *
sizeof (
u32x4); i > 0; i -=
sizeof (
u32x4))
1309 if (*tmp || *(tmp + 1))
1316 _vec_len (mask) = match *
sizeof (
u32x4);
1327 #define foreach_l2_input_next \ 1329 _(ethernet, ETHERNET_INPUT) \ 1338 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1344 for (i = 0; i <
vec_len (cm->unformat_l2_next_index_fns); i++)
1346 if (
unformat (input,
"%U", cm->unformat_l2_next_index_fns[i], &tmp))
1354 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;} 1367 *miss_next_indexp = next_index;
1371 #define foreach_l2_output_next \ 1378 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1384 for (i = 0; i <
vec_len (cm->unformat_l2_next_index_fns); i++)
1386 if (
unformat (input,
"%U", cm->unformat_l2_next_index_fns[i], &tmp))
1394 if (unformat (input, #n)) { next_index = L2_OUTPUT_CLASSIFY_NEXT_##N; goto out;} 1407 *miss_next_indexp = next_index;
1411 #define foreach_ip_next \ 1418 u32 *miss_next_indexp = va_arg (*args,
u32 *);
1425 for (i = 0; i <
vec_len (cm->unformat_ip_next_index_fns); i++)
1427 if (
unformat (input,
"%U", cm->unformat_ip_next_index_fns[i], &tmp))
1435 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;} 1448 *miss_next_indexp = next_index;
1452 #define foreach_acl_next \ 1458 u32 *next_indexp = va_arg (*args,
u32 *);
1465 for (i = 0; i <
vec_len (cm->unformat_acl_next_index_fns); i++)
1467 if (
unformat (input,
"%U", cm->unformat_acl_next_index_fns[i], &tmp))
1475 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;} 1484 else if (
unformat (input,
"%d", &tmp))
1493 *next_indexp = next_index;
1500 u32 *next_indexp = va_arg (*args,
u32 *);
1507 for (i = 0; i <
vec_len (cm->unformat_policer_next_index_fns); i++)
1510 (input,
"%U", cm->unformat_policer_next_index_fns[i], &tmp))
1526 *next_indexp = next_index;
1539 u32 table_index = ~0;
1540 u32 next_table_index = ~0;
1541 u32 miss_next_index = ~0;
1544 u32 current_data_flag = 0;
1545 int current_data_offset = 0;
1555 else if (
unformat (input,
"del-chain"))
1560 else if (
unformat (input,
"buckets %d", &nbuckets))
1562 else if (
unformat (input,
"skip %d", &skip))
1564 else if (
unformat (input,
"match %d", &match))
1566 else if (
unformat (input,
"table %d", &table_index))
1569 &mask, &skip, &match))
1571 else if (
unformat (input,
"memory-size %uM", &tmp))
1572 memory_size = tmp << 20;
1573 else if (
unformat (input,
"memory-size %uG", &tmp))
1574 memory_size = tmp << 30;
1575 else if (
unformat (input,
"next-table %d", &next_table_index))
1593 else if (
unformat (input,
"current-data-flag %d", ¤t_data_flag))
1596 if (
unformat (input,
"current-data-offset %d", ¤t_data_offset))
1603 if (is_add && mask == 0 && table_index == ~0)
1606 if (is_add && skip == ~0 && table_index == ~0)
1609 if (is_add && match == ~0 && table_index == ~0)
1612 if (!is_add && table_index == ~0)
1616 skip, match, next_table_index,
1617 miss_next_index, &table_index,
1618 current_data_flag, current_data_offset,
1635 .path =
"classify table",
1637 "classify table [miss-next|l2-miss_next|acl-miss-next <next_index>]" 1638 "\n mask <mask-value> buckets <nn> [skip <n>] [match <n>]" 1639 "\n [current-data-flag <n>] [current-data-offset <n>] [table <n>]" 1640 "\n [memory-size <nn>[M][G]] [next-table <n>]" 1641 "\n [del] [del-chain]",
1697 u32 table_index = ~0;
1698 u32 next_table_index = ~0;
1699 u32 miss_next_index = ~0;
1700 u32 current_data_flag = 0;
1701 int current_data_offset = 0;
1717 else if (
unformat (input,
"pcap %=", &pcap, 1))
1719 else if (
unformat (input,
"trace"))
1724 if (sw_if_index == 0)
1727 else if (
unformat (input,
"buckets %d", &nbuckets))
1730 &mask, &skip, &match))
1739 if (is_add && mask == 0 && table_index == ~0)
1742 if (is_add && skip == ~0 && table_index == ~0)
1745 if (is_add && match == ~0 && table_index == ~0)
1748 if (sw_if_index == ~0 && pkt_trace == 0 && pcap == 0)
1751 if (pkt_trace && pcap)
1753 (0,
"Packet trace and pcap are mutually exclusive...");
1755 if (pkt_trace && sw_if_index != ~0)
1763 else if (sw_if_index <
vec_len (cm->filter_set_by_sw_if_index))
1764 set_index = cm->filter_set_by_sw_if_index[
sw_if_index];
1766 if (set_index == ~0)
1770 "No pkt trace classify filter set...");
1771 if (sw_if_index == 0)
1782 ASSERT (set->refcnt >= 0);
1783 if (set->refcnt == 0)
1786 table_index =
set->table_indices[0];
1797 if (sw_if_index > 0)
1811 else if (sw_if_index <
vec_len (cm->filter_set_by_sw_if_index))
1812 set_index = cm->filter_set_by_sw_if_index[
sw_if_index];
1815 if (set_index == ~0)
1818 set_index =
set - cm->filter_sets;
1824 for (i = 0; i <
vec_len (set->table_indices); i++)
1831 if (vec_len (t->
mask) != vec_len (mask))
1834 if (memcmp (t->
mask, mask, vec_len (mask)))
1844 skip, match, next_table_index,
1845 miss_next_index, &table_index,
1846 current_data_flag, current_data_offset,
1864 vec_add1 (set->table_indices, table_index);
1872 cm->filter_set_by_sw_if_index[
sw_if_index] =
set - cm->filter_sets;
1876 if (sw_if_index > 0 && pkt_trace == 0)
1889 for (i = 0; i <
vec_len (set->table_indices); i++)
1893 if ((i + 1) < vec_len (set->table_indices))
1903 cm, &match_vector, table_index) == 0)
1933 if (set_index == ~0)
1938 set->table_indices[0];
2023 .path =
"classify filter",
2025 "classify filter <intfc> | pcap mask <mask-value> match <match-value>\n" 2026 " | trace mask <mask-value> match <match-value> [del]\n" 2027 " [buckets <nn>] [memory-size <n>]",
2047 (void)
unformat (input,
"verbose %=", &verbose, 1);
2052 limit =
vec_len (cm->filter_set_by_sw_if_index);
2054 for (i = -1; i < limit; i++)
2059 set_index = cm->filter_set_by_sw_if_index[
i];
2061 if (set_index == ~0)
2069 name =
format (0,
"packet tracer:");
2072 name =
format (0,
"pcap rx/tx/drop:");
2083 for (j = 0; j <
vec_len (set->table_indices); j++)
2085 table_index =
set->table_indices[j];
2086 if (table_index != ~0)
2087 s =
format (s,
" %u", table_index);
2097 table_index =
set->table_indices ?
set->table_indices[0] : ~0;
2099 if (table_index != ~0)
2100 s =
format (s,
" %u", table_index);
2118 .path =
"show classify filter",
2119 .short_help =
"show classify filter [verbose [nn]]",
2131 int verbose = va_arg (*args,
int);
2132 u32 index = va_arg (*args,
u32);
2137 s =
format (s,
"%10s%10s%10s%10s",
"TableIdx",
"Sessions",
"NextTbl",
2138 "NextNode", verbose ?
"Details" :
"");
2148 s =
format (s,
"\n nbuckets %d, skip %d match %d flag %d offset %d",
2170 u32 match_index = ~0;
2177 if (
unformat (input,
"index %d", &match_index))
2179 else if (
unformat (input,
"verbose %d", &verbose))
2181 else if (
unformat (input,
"verbose"))
2190 if (match_index == ~0 || (match_index == t - cm->tables))
2191 vec_add1 (indices, t - cm->tables);
2199 for (i = 0; i <
vec_len (indices); i++)
2201 verbose, indices[i]);
2213 .path =
"show classify tables",
2214 .short_help =
"show classify tables [index <nn>]",
2222 u8 **matchp = va_arg (*args,
u8 **);
2224 u8 *proto_header = 0;
2232 if (
unformat (input,
"src_port %d", &src_port))
2234 else if (
unformat (input,
"dst_port %d", &dst_port))
2240 h.
src_port = clib_host_to_net_u16 (src_port);
2241 h.
dst_port = clib_host_to_net_u16 (dst_port);
2243 memcpy (proto_header, &h,
sizeof (h));
2245 *matchp = proto_header;
2253 u8 **matchp = va_arg (*args,
u8 **);
2268 int fragment_id = 0;
2269 u32 fragment_id_val;
2277 if (
unformat (input,
"version %d", &version_val))
2279 else if (
unformat (input,
"hdr_length %d", &hdr_length_val))
2285 else if (
unformat (input,
"proto %d", &proto_val))
2287 else if (
unformat (input,
"tos %d", &tos_val))
2289 else if (
unformat (input,
"length %d", &length_val))
2291 else if (
unformat (input,
"fragment_id %d", &fragment_id_val))
2293 else if (
unformat (input,
"ttl %d", &ttl_val))
2295 else if (
unformat (input,
"checksum %d", &checksum_val))
2301 if (version + hdr_length + src +
dst + proto + tos + length + fragment_id
2302 + ttl + checksum == 0)
2334 ip->
length = clib_host_to_net_u16 (length_val);
2340 ip->
checksum = clib_host_to_net_u16 (checksum_val);
2349 u8 **matchp = va_arg (*args,
u8 **);
2354 u8 traffic_class = 0;
2355 u32 traffic_class_val;
2362 int payload_length = 0;
2363 u32 payload_length_val;
2366 u32 ip_version_traffic_class_and_flow_label;
2370 if (
unformat (input,
"version %d", &version_val))
2372 else if (
unformat (input,
"traffic_class %d", &traffic_class_val))
2374 else if (
unformat (input,
"flow_label %d", &flow_label_val))
2380 else if (
unformat (input,
"proto %d", &proto_val))
2382 else if (
unformat (input,
"payload_length %d", &payload_length_val))
2384 else if (
unformat (input,
"hop_limit %d", &hop_limit_val))
2390 if (version + traffic_class + flow_label + src +
dst + proto +
2391 payload_length + hop_limit == 0)
2410 ip_version_traffic_class_and_flow_label = 0;
2413 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
2416 ip_version_traffic_class_and_flow_label |=
2417 (traffic_class_val & 0xFF) << 20;
2420 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
2423 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
2438 u8 **matchp = va_arg (*args,
u8 **);
2456 u8 *tagp = va_arg (*args,
u8 *);
2461 tagp[0] = (tag >> 8) & 0x0F;
2462 tagp[1] = tag & 0xFF;
2472 u8 **matchp = va_arg (*args,
u8 **);
2499 else if (
unformat (input,
"proto %U",
2506 else if (
unformat (input,
"ignore-tag1"))
2508 else if (
unformat (input,
"ignore-tag2"))
2510 else if (
unformat (input,
"cos1 %d", &cos1_val))
2512 else if (
unformat (input,
"cos2 %d", &cos2_val))
2517 if ((src + dst + proto + tag1 + tag2 +
2518 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
2521 if (tag1 || ignore_tag1 || cos1)
2523 if (tag2 || ignore_tag2 || cos2)
2537 match[19] = tag2_val[1];
2538 match[18] = tag2_val[0];
2540 match[18] |= (cos2_val & 0x7) << 5;
2543 match[21] = proto_val & 0xff;
2544 match[20] = proto_val >> 8;
2548 match[15] = tag1_val[1];
2549 match[14] = tag1_val[0];
2552 match[14] |= (cos1_val & 0x7) << 5;
2558 match[15] = tag1_val[1];
2559 match[14] = tag1_val[0];
2562 match[17] = proto_val & 0xff;
2563 match[16] = proto_val >> 8;
2566 match[14] |= (cos1_val & 0x7) << 5;
2572 match[18] |= (cos2_val & 0x7) << 5;
2574 match[14] |= (cos1_val & 0x7) << 5;
2577 match[13] = proto_val & 0xff;
2578 match[12] = proto_val >> 8;
2590 u8 **matchp = va_arg (*args,
u8 **);
2591 u32 table_index = va_arg (*args,
u32);
2626 if (match || l2 || l3 || l4)
2671 u8 action,
u32 metadata,
int is_add)
2674 vnet_classify_entry_5_t _max_e __attribute__ ((aligned (16)));
2675 vnet_classify_entry_t *e;
2679 return VNET_API_ERROR_NO_SUCH_TABLE;
2683 e = (vnet_classify_entry_t *) & _max_e;
2684 e->next_index = hit_next_index;
2685 e->opaque_index = opaque_index;
2686 e->advance = advance;
2700 e->metadata = metadata;
2710 e->key[i] &= t->
mask[i];
2717 return VNET_API_ERROR_NO_SUCH_ENTRY;
2728 u32 table_index = ~0;
2729 u32 hit_next_index = ~0;
2730 u64 opaque_index = ~0;
2757 else if (
unformat (input,
"policer-hit-next %U",
2760 else if (
unformat (input,
"opaque-index %lld", &opaque_index))
2763 cm, &match, table_index))
2765 else if (
unformat (input,
"advance %d", &advance))
2767 else if (
unformat (input,
"table-index %d", &table_index))
2769 else if (
unformat (input,
"action set-ip4-fib-id %d", &metadata))
2771 else if (
unformat (input,
"action set-ip6-fib-id %d", &metadata))
2773 else if (
unformat (input,
"action set-sr-policy-index %d", &metadata))
2778 for (i = 0; i <
vec_len (cm->unformat_opaque_index_fns); i++)
2780 if (
unformat (input,
"%U", cm->unformat_opaque_index_fns[i],
2790 if (table_index == ~0)
2793 if (is_add && match == 0)
2798 opaque_index, advance,
2799 action, metadata, is_add);
2808 "vnet_classify_add_del_session returned %d",
2817 .path =
"classify session",
2819 "classify session [hit-next|l2-input-hit-next|l2-output-hit-next|" 2820 "acl-hit-next <next_index>|policer-hit-next <policer_name>]" 2821 "\n table-index <nn> match [hex] [l2] [l3 ip4] [opaque-index <index>]" 2822 "\n [action set-ip4-fib-id|set-ip6-fib-id|set-sr-policy-index <n>] [del]",
2830 u64 *opaquep = va_arg (*args,
u64 *);
2846 u32 *next_indexp = va_arg (*args,
u32 *);
2848 u32 next_index = ~0;
2851 cm->vlib_main, &node_index))
2857 cm->vlib_main, &node_index))
2865 *next_indexp = next_index;
2873 u32 *next_indexp = va_arg (*args,
u32 *);
2878 cm->vlib_main, &node_index))
2884 cm->vlib_main, &node_index))
2892 *next_indexp = next_index;
2900 u32 *next_indexp = va_arg (*args,
u32 *);
2905 cm->vlib_main, &node_index))
2910 *next_indexp = next_index;
2920 u32 *next_indexp = va_arg (*args,
u32 *);
2925 cm->vlib_main, &node_index))
2930 *next_indexp = next_index;
2960 set->refcnt = 0x7FFFFFFF;
2963 cm->filter_set_by_sw_if_index[0] = 0;
3007 classify_data_or_mask_t *mask;
3008 classify_data_or_mask_t *
data;
3014 } test_classify_main_t;
3016 static test_classify_main_t test_classify_main;
3019 test_classify_churn (test_classify_main_t * tm)
3021 classify_data_or_mask_t *mask, *
data;
3024 u8 *mp = 0, *dp = 0;
3031 mask = (classify_data_or_mask_t *) mp;
3032 data = (classify_data_or_mask_t *) dp;
3037 tmp = clib_host_to_net_u32 (tm->src.as_u32);
3039 for (i = 0; i < tm->sessions; i++)
3042 ep->addr.as_u32 = clib_host_to_net_u32 (tmp);
3050 tm->memory_size, 0 ,
3053 tm->table_index = tm->table - tm->classify_main->tables;
3055 tm->table_index, tm->buckets);
3057 vlib_cli_output (vm,
"Initialize: add %d (approx. half of %d sessions)...",
3058 tm->sessions / 2, tm->sessions);
3060 for (i = 0; i < tm->sessions / 2; i++)
3064 data->ip.src_address.as_u32 = ep->addr.as_u32;
3087 for (i = 0; i < tm->iterations; i++)
3092 index =
random_u32 (&tm->seed) % tm->sessions;
3096 data->ip.src_address.as_u32 = ep->addr.as_u32;
3099 is_add = !ep->in_table;
3103 is_add ?
"add" :
"del",
3117 "%s[%d]: %U returned %d", is_add ?
"add" :
"del",
3120 ep->in_table = is_add;
3124 tm->table->active_elements);
3126 for (i = 0; i < tm->sessions; i++)
3130 vnet_classify_entry_t *e;
3132 ep = tm->entries +
i;
3133 if (ep->in_table == 0)
3136 data->ip.src_address.as_u32 = ep->addr.as_u32;
3141 (
u8 *) data, hash, 0 );
3144 clib_warning (
"Couldn't find %U index %d which should be present",
3149 key_minus_skip = (
u8 *) e->key;
3150 key_minus_skip -= tm->table->skip_n_vectors * sizeof (
u32x4);
3167 tm->table->active_elements);
3176 tm->table_index, 1 );
3178 tm->table_index = ~0;
3188 test_classify_main_t *tm = &test_classify_main;
3195 tm->sessions = 8192;
3196 tm->iterations = 8192;
3197 tm->memory_size = 64 << 20;
3198 tm->src.as_u32 = clib_net_to_host_u32 (0x0100000A);
3200 tm->seed = 0xDEADDABE;
3201 tm->classify_main =
cm;
3209 if (
unformat (input,
"sessions %d", &tmp))
3214 else if (
unformat (input,
"buckets %d", &tm->buckets))
3216 else if (
unformat (input,
"memory-size %uM", &tmp))
3217 tm->memory_size = tmp << 20;
3218 else if (
unformat (input,
"memory-size %uG", &tmp))
3219 tm->memory_size = tmp << 30;
3220 else if (
unformat (input,
"seed %d", &tm->seed))
3222 else if (
unformat (input,
"verbose"))
3225 else if (
unformat (input,
"iterations %d", &tm->iterations))
3227 else if (
unformat (input,
"churn-test"))
3236 error = test_classify_churn (tm);
3248 .path =
"test classify",
3250 "test classify [src <ip>] [sessions <nn>] [buckets <nn>] [seed <nnn>]\n" 3251 " [memory-size <nn>[M|G]]\n" 3253 .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
vlib_main_t vlib_global_main
void clib_mem_validate(void)
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)
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
static vnet_classify_entry_t * vnet_classify_find_entry_inline(vnet_classify_table_t *t, u8 *h, u64 hash, f64 now)
void * mheap_alloc(void *memory, uword size)
#define VNET_CLASSIFY_ENTRY_FREE
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static u8 * format_vnet_classify_table(u8 *s, va_list *args)
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++)
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)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
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)
void mv(vnet_classify_table_t *t)
vlib_node_registration_t l2_input_classify_node
(constructor) VLIB_REGISTER_NODE (l2_input_classify_node)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
clib_spinlock_t writer_lock
int vnet_classify_add_del(vnet_classify_table_t *t, vnet_classify_entry_t *add_v, int is_add)
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)
vlib_node_registration_t l2_output_classify_node
(constructor) VLIB_REGISTER_NODE (l2_output_classify_node)
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)
vnet_classify_table_t * vnet_classify_new_table(vnet_classify_main_t *cm, u8 *mask, u32 nbuckets, u32 memory_size, u32 skip_n_vectors, u32 match_n_vectors)
#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...)
#define foreach_ip4_proto_field
Use the vpp classifier to decide whether to trace packets.
static void clib_spinlock_init(clib_spinlock_t *p)
static uword unformat_opaque_sw_if_index(unformat_input_t *input, va_list *args)
u32 trace_filter_set_index
static int vnet_classify_entry_is_free(vnet_classify_entry_t *e)
int vnet_classify_add_del_session(vnet_classify_main_t *cm, u32 table_index, u8 *match, u32 hit_next_index, u32 opaque_index, i32 advance, u8 action, u32 metadata, int is_add)
u8 * format_mheap(u8 *s, va_list *va)
static u64 vnet_classify_hash_packet_inline(vnet_classify_table_t *t, u8 *h)
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.
uword unformat_ip4_mask(unformat_input_t *input, va_list *args)
uword unformat_l2_input_next_index(unformat_input_t *input, va_list *args)
vl_api_ip_proto_t protocol
uword unformat_ip6_mask(unformat_input_t *input, va_list *args)
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
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.
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)
vl_api_address_union_t src_address
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
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
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)
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)
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
static_always_inline uword vlib_get_thread_index(void)
vlib_node_registration_t ip6_inacl_node
(constructor) VLIB_REGISTER_NODE (ip6_inacl_node)
#define vec_free(V)
Free vector's memory (no header).
uword unformat_acl_next_index(unformat_input_t *input, va_list *args)
static void * clib_mem_set_heap(void *heap)
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
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)
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)
#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 void vnet_classify_entry_release_resource(vnet_classify_entry_t *e)
int vnet_classify_add_del_table(vnet_classify_main_t *cm, 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)
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)
#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)
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.
static vnet_classify_entry_t * vnet_classify_entry_alloc(vnet_classify_table_t *t, u32 log2_pages)
unformat_function_t unformat_vlib_node
DLMALLOC_EXPORT size_t destroy_mspace(mspace msp)
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
vlib_trace_filter_t trace_filter
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
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vnet_classify_entry_t ** freelists
vnet_classify_entry_t * vnet_classify_find_entry(vnet_classify_table_t *t, u8 *h, u64 hash, f64 now)
u32 trace_classify_table_index
vl_api_fib_path_nh_proto_t proto
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)