table: rework 8-byte key hash tables
[dpdk.git] / test / test / test_table_combined.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <string.h>
35 #include "test_table_combined.h"
36 #include "test_table.h"
37 #include <rte_table_lpm_ipv6.h>
38
39 #define MAX_TEST_KEYS 128
40 #define N_PACKETS 50
41
42 enum check_table_result {
43         CHECK_TABLE_OK,
44         CHECK_TABLE_PORT_CONFIG,
45         CHECK_TABLE_PORT_ENABLE,
46         CHECK_TABLE_TABLE_CONFIG,
47         CHECK_TABLE_ENTRY_ADD,
48         CHECK_TABLE_DEFAULT_ENTRY_ADD,
49         CHECK_TABLE_CONNECT,
50         CHECK_TABLE_MANAGE_ERROR,
51         CHECK_TABLE_CONSISTENCY,
52         CHECK_TABLE_NO_TRAFFIC,
53         CHECK_TABLE_INVALID_PARAMETER,
54 };
55
56 struct table_packets {
57         uint32_t hit_packet[MAX_TEST_KEYS];
58         uint32_t miss_packet[MAX_TEST_KEYS];
59         uint32_t n_hit_packets;
60         uint32_t n_miss_packets;
61 };
62
63 combined_table_test table_tests_combined[] = {
64         test_table_lpm_combined,
65         test_table_lpm_ipv6_combined,
66         test_table_hash8lru,
67         test_table_hash8ext,
68         test_table_hash16lru,
69         test_table_hash16ext,
70         test_table_hash32lru,
71         test_table_hash32ext,
72         test_table_hash_cuckoo_combined,
73 };
74
75 unsigned n_table_tests_combined = RTE_DIM(table_tests_combined);
76
77 /* Generic port tester function */
78 static int
79 test_table_type(struct rte_table_ops *table_ops, void *table_args,
80         void *key, struct table_packets *table_packets,
81         struct manage_ops *manage_ops, unsigned n_ops)
82 {
83         uint32_t ring_in_id, table_id, ring_out_id, ring_out_2_id;
84         unsigned i;
85
86         RTE_SET_USED(manage_ops);
87         RTE_SET_USED(n_ops);
88         /* Create pipeline */
89         struct rte_pipeline_params pipeline_params = {
90                 .name = "pipeline",
91                 .socket_id = 0,
92         };
93
94         struct rte_pipeline *pipeline = rte_pipeline_create(&pipeline_params);
95
96         /* Create input ring */
97         struct rte_port_ring_reader_params ring_params_rx = {
98                 .ring = RING_RX,
99         };
100
101         struct rte_port_ring_writer_params ring_params_tx = {
102                 .ring = RING_RX,
103                 .tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX,
104         };
105
106         struct rte_pipeline_port_in_params ring_in_params = {
107                 .ops = &rte_port_ring_reader_ops,
108                 .arg_create = (void *)&ring_params_rx,
109                 .f_action = NULL,
110                 .burst_size = RTE_PORT_IN_BURST_SIZE_MAX,
111         };
112
113         if (rte_pipeline_port_in_create(pipeline, &ring_in_params,
114                 &ring_in_id) != 0) {
115                 rte_pipeline_free(pipeline);
116                 return -CHECK_TABLE_PORT_CONFIG;
117         }
118
119         /* Create table */
120         struct rte_pipeline_table_params table_params = {
121                 .ops = table_ops,
122                 .arg_create = table_args,
123                 .f_action_hit = NULL,
124                 .f_action_miss = NULL,
125                 .arg_ah = NULL,
126                 .action_data_size = 0,
127         };
128
129         if (rte_pipeline_table_create(pipeline, &table_params,
130                 &table_id) != 0) {
131                 rte_pipeline_free(pipeline);
132                 return -CHECK_TABLE_TABLE_CONFIG;
133         }
134
135         /* Create output ports */
136         ring_params_tx.ring = RING_TX;
137
138         struct rte_pipeline_port_out_params ring_out_params = {
139                 .ops = &rte_port_ring_writer_ops,
140                 .arg_create = (void *)&ring_params_tx,
141                 .f_action = NULL,
142         };
143
144         if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
145                 &ring_out_id) != 0) {
146                 rte_pipeline_free(pipeline);
147                 return -CHECK_TABLE_PORT_CONFIG;
148         }
149
150         ring_params_tx.ring = RING_TX_2;
151
152         if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
153                 &ring_out_2_id) != 0) {
154                 rte_pipeline_free(pipeline);
155                 return -CHECK_TABLE_PORT_CONFIG;
156         }
157
158         /* Add entry to the table */
159         struct rte_pipeline_table_entry default_entry = {
160                 .action = RTE_PIPELINE_ACTION_DROP,
161                 {.table_id = ring_out_id},
162         };
163
164         struct rte_pipeline_table_entry table_entry = {
165                 .action = RTE_PIPELINE_ACTION_PORT,
166                 {.table_id = ring_out_id},
167         };
168
169         struct rte_pipeline_table_entry *default_entry_ptr, *entry_ptr;
170
171         int key_found;
172
173         if (rte_pipeline_table_default_entry_add(pipeline, table_id,
174                 &default_entry, &default_entry_ptr) != 0) {
175                 rte_pipeline_free(pipeline);
176                 return -CHECK_TABLE_DEFAULT_ENTRY_ADD;
177         }
178
179         if (rte_pipeline_table_entry_add(pipeline, table_id,
180                 key ? key : &table_entry, &table_entry, &key_found,
181                         &entry_ptr) != 0) {
182                 rte_pipeline_free(pipeline);
183                 return -CHECK_TABLE_ENTRY_ADD;
184         }
185
186         /* Create connections and check consistency */
187         if (rte_pipeline_port_in_connect_to_table(pipeline, ring_in_id,
188                 table_id) != 0) {
189                 rte_pipeline_free(pipeline);
190                 return -CHECK_TABLE_CONNECT;
191         }
192
193         if (rte_pipeline_port_in_enable(pipeline, ring_in_id) != 0) {
194                 rte_pipeline_free(pipeline);
195                 return -CHECK_TABLE_PORT_ENABLE;
196         }
197
198         if (rte_pipeline_check(pipeline) != 0) {
199                 rte_pipeline_free(pipeline);
200                 return -CHECK_TABLE_CONSISTENCY;
201         }
202
203
204
205         /* Flow test - All hits */
206         if (table_packets->n_hit_packets) {
207                 for (i = 0; i < table_packets->n_hit_packets; i++)
208                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
209
210                 RUN_PIPELINE(pipeline);
211
212                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
213                                 table_packets->n_hit_packets);
214         }
215
216         /* Flow test - All misses */
217         if (table_packets->n_miss_packets) {
218                 for (i = 0; i < table_packets->n_miss_packets; i++)
219                         RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
220
221                 RUN_PIPELINE(pipeline);
222
223                 VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
224         }
225
226         /* Flow test - Half hits, half misses */
227         if (table_packets->n_hit_packets && table_packets->n_miss_packets) {
228                 for (i = 0; i < (table_packets->n_hit_packets) / 2; i++)
229                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
230
231                 for (i = 0; i < (table_packets->n_miss_packets) / 2; i++)
232                         RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
233
234                 RUN_PIPELINE(pipeline);
235                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
236                         table_packets->n_hit_packets / 2);
237         }
238
239         /* Flow test - Single packet */
240         if (table_packets->n_hit_packets) {
241                 RING_ENQUEUE(RING_RX, table_packets->hit_packet[0]);
242                 RUN_PIPELINE(pipeline);
243                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 1);
244         }
245         if (table_packets->n_miss_packets) {
246                 RING_ENQUEUE(RING_RX, table_packets->miss_packet[0]);
247                 RUN_PIPELINE(pipeline);
248                 VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
249         }
250
251
252         /* Change table entry action */
253         printf("Change entry action\n");
254         table_entry.table_id = ring_out_2_id;
255
256         if (rte_pipeline_table_default_entry_add(pipeline, table_id,
257                 &default_entry, &default_entry_ptr) != 0) {
258                 rte_pipeline_free(pipeline);
259                 return -CHECK_TABLE_ENTRY_ADD;
260         }
261
262         if (rte_pipeline_table_entry_add(pipeline, table_id,
263                 key ? key : &table_entry, &table_entry, &key_found,
264                         &entry_ptr) != 0) {
265                 rte_pipeline_free(pipeline);
266                 return -CHECK_TABLE_ENTRY_ADD;
267         }
268
269         /* Check that traffic destination has changed */
270         if (table_packets->n_hit_packets) {
271                 for (i = 0; i < table_packets->n_hit_packets; i++)
272                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
273
274                 RUN_PIPELINE(pipeline);
275                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 0);
276                 VERIFY_TRAFFIC(RING_TX_2, table_packets->n_hit_packets,
277                         table_packets->n_hit_packets);
278         }
279
280         printf("delete entry\n");
281         /* Delete table entry */
282         rte_pipeline_table_entry_delete(pipeline, table_id,
283                 key ? key : &table_entry, &key_found, NULL);
284
285         rte_pipeline_free(pipeline);
286
287         return 0;
288 }
289
290 /* Table tests */
291 int
292 test_table_stub_combined(void)
293 {
294         int status, i;
295         struct table_packets table_packets;
296
297         printf("--------------\n");
298         printf("RUNNING TEST - %s\n", __func__);
299         printf("--------------\n");
300         for (i = 0; i < N_PACKETS; i++)
301                 table_packets.hit_packet[i] = i;
302
303         table_packets.n_hit_packets = N_PACKETS;
304         table_packets.n_miss_packets = 0;
305
306         status = test_table_type(&rte_table_stub_ops, NULL, NULL,
307                 &table_packets, NULL, 1);
308         VERIFY(status, CHECK_TABLE_OK);
309
310         return 0;
311 }
312
313 int
314 test_table_lpm_combined(void)
315 {
316         int status, i;
317
318         /* Traffic flow */
319         struct rte_table_lpm_params lpm_params = {
320                 .name = "LPM",
321                 .n_rules = 1 << 16,
322                 .number_tbl8s = 1 << 8,
323                 .flags = 0,
324                 .entry_unique_size = 8,
325                 .offset = APP_METADATA_OFFSET(0),
326         };
327
328         struct rte_table_lpm_key lpm_key = {
329                 .ip = 0xadadadad,
330                 .depth = 16,
331         };
332
333         struct table_packets table_packets;
334
335         printf("--------------\n");
336         printf("RUNNING TEST - %s\n", __func__);
337         printf("--------------\n");
338
339         for (i = 0; i < N_PACKETS; i++)
340                 table_packets.hit_packet[i] = 0xadadadad;
341
342         for (i = 0; i < N_PACKETS; i++)
343                 table_packets.miss_packet[i] = 0xfefefefe;
344
345         table_packets.n_hit_packets = N_PACKETS;
346         table_packets.n_miss_packets = N_PACKETS;
347
348         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
349                 (void *)&lpm_key, &table_packets, NULL, 0);
350         VERIFY(status, CHECK_TABLE_OK);
351
352         /* Invalid parameters */
353         lpm_params.n_rules = 0;
354
355         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
356                 (void *)&lpm_key, &table_packets, NULL, 0);
357         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
358
359         lpm_params.n_rules = 1 << 24;
360         lpm_key.depth = 0;
361
362         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
363                 (void *)&lpm_key, &table_packets, NULL, 0);
364         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
365
366         lpm_key.depth = 33;
367
368         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
369                 (void *)&lpm_key, &table_packets, NULL, 0);
370         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
371
372         return 0;
373 }
374
375 int
376 test_table_lpm_ipv6_combined(void)
377 {
378         int status, i;
379
380         /* Traffic flow */
381         struct rte_table_lpm_ipv6_params lpm_ipv6_params = {
382                 .name = "LPM",
383                 .n_rules = 1 << 16,
384                 .number_tbl8s = 1 << 13,
385                 .entry_unique_size = 8,
386                 .offset = APP_METADATA_OFFSET(32),
387         };
388
389         struct rte_table_lpm_ipv6_key lpm_ipv6_key = {
390                 .depth = 16,
391         };
392         memset(lpm_ipv6_key.ip, 0xad, 16);
393
394         struct table_packets table_packets;
395
396         printf("--------------\n");
397         printf("RUNNING TEST - %s\n", __func__);
398         printf("--------------\n");
399         for (i = 0; i < N_PACKETS; i++)
400                 table_packets.hit_packet[i] = 0xadadadad;
401
402         for (i = 0; i < N_PACKETS; i++)
403                 table_packets.miss_packet[i] = 0xadadadab;
404
405         table_packets.n_hit_packets = N_PACKETS;
406         table_packets.n_miss_packets = N_PACKETS;
407
408         status = test_table_type(&rte_table_lpm_ipv6_ops,
409                 (void *)&lpm_ipv6_params,
410                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
411         VERIFY(status, CHECK_TABLE_OK);
412
413         /* Invalid parameters */
414         lpm_ipv6_params.n_rules = 0;
415
416         status = test_table_type(&rte_table_lpm_ipv6_ops,
417                 (void *)&lpm_ipv6_params,
418                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
419         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
420
421         lpm_ipv6_params.n_rules = 1 << 24;
422         lpm_ipv6_key.depth = 0;
423
424         status = test_table_type(&rte_table_lpm_ipv6_ops,
425                 (void *)&lpm_ipv6_params,
426                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
427         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
428
429         lpm_ipv6_key.depth = 129;
430         status = test_table_type(&rte_table_lpm_ipv6_ops,
431                 (void *)&lpm_ipv6_params,
432                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
433         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
434
435         return 0;
436 }
437
438 int
439 test_table_hash8lru(void)
440 {
441         int status, i;
442
443         /* Traffic flow */
444         struct rte_table_hash_params key8lru_params = {
445                 .name = "TABLE",
446                 .key_size = 8,
447                 .key_offset = APP_METADATA_OFFSET(32),
448                 .key_mask = NULL,
449                 .n_keys = 1 << 16,
450                 .n_buckets = 1 << 16,
451                 .f_hash = (rte_table_hash_op_hash)pipeline_test_hash,
452                 .seed = 0,
453         };
454
455         uint8_t key8lru[8];
456         uint32_t *k8lru = (uint32_t *) key8lru;
457
458         memset(key8lru, 0, sizeof(key8lru));
459         k8lru[0] = 0xadadadad;
460
461         struct table_packets table_packets;
462
463         printf("--------------\n");
464         printf("RUNNING TEST - %s\n", __func__);
465         printf("--------------\n");
466         for (i = 0; i < 50; i++)
467                 table_packets.hit_packet[i] = 0xadadadad;
468
469         for (i = 0; i < 50; i++)
470                 table_packets.miss_packet[i] = 0xfefefefe;
471
472         table_packets.n_hit_packets = 50;
473         table_packets.n_miss_packets = 50;
474
475         status = test_table_type(&rte_table_hash_key8_lru_ops,
476                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
477                         NULL, 0);
478         VERIFY(status, CHECK_TABLE_OK);
479
480         /* Invalid parameters */
481         key8lru_params.n_keys = 0;
482
483         status = test_table_type(&rte_table_hash_key8_lru_ops,
484                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
485                         NULL, 0);
486         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
487
488         key8lru_params.n_keys = 1<<16;
489         key8lru_params.f_hash = NULL;
490
491         status = test_table_type(&rte_table_hash_key8_lru_ops,
492                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
493                         NULL, 0);
494         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
495
496         return 0;
497 }
498
499 int
500 test_table_hash16lru(void)
501 {
502         int status, i;
503
504         /* Traffic flow */
505         struct rte_table_hash_key16_lru_params key16lru_params = {
506                 .n_entries = 1<<16,
507                 .f_hash = pipeline_test_hash,
508                 .seed = 0,
509                 .signature_offset = APP_METADATA_OFFSET(0),
510                 .key_offset = APP_METADATA_OFFSET(32),
511                 .key_mask = NULL,
512         };
513
514         uint8_t key16lru[16];
515         uint32_t *k16lru = (uint32_t *) key16lru;
516
517         memset(key16lru, 0, sizeof(key16lru));
518         k16lru[0] = 0xadadadad;
519
520         struct table_packets table_packets;
521
522         printf("--------------\n");
523         printf("RUNNING TEST - %s\n", __func__);
524         printf("--------------\n");
525         for (i = 0; i < 50; i++)
526                 table_packets.hit_packet[i] = 0xadadadad;
527
528         for (i = 0; i < 50; i++)
529                 table_packets.miss_packet[i] = 0xfefefefe;
530
531         table_packets.n_hit_packets = 50;
532         table_packets.n_miss_packets = 50;
533
534         status = test_table_type(&rte_table_hash_key16_lru_ops,
535                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
536                         NULL, 0);
537         VERIFY(status, CHECK_TABLE_OK);
538
539         /* Invalid parameters */
540         key16lru_params.n_entries = 0;
541
542         status = test_table_type(&rte_table_hash_key16_lru_ops,
543                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
544                         NULL, 0);
545         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
546
547         key16lru_params.n_entries = 1<<16;
548         key16lru_params.f_hash = NULL;
549
550         status = test_table_type(&rte_table_hash_key16_lru_ops,
551                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
552                         NULL, 0);
553         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
554
555         return 0;
556 }
557
558 int
559 test_table_hash32lru(void)
560 {
561         int status, i;
562
563         /* Traffic flow */
564         struct rte_table_hash_key32_lru_params key32lru_params = {
565                 .n_entries = 1<<16,
566                 .f_hash = pipeline_test_hash,
567                 .seed = 0,
568                 .signature_offset = APP_METADATA_OFFSET(0),
569                 .key_offset = APP_METADATA_OFFSET(32),
570         };
571
572         uint8_t key32lru[32];
573         uint32_t *k32lru = (uint32_t *) key32lru;
574
575         memset(key32lru, 0, sizeof(key32lru));
576         k32lru[0] = 0xadadadad;
577
578         struct table_packets table_packets;
579
580         printf("--------------\n");
581         printf("RUNNING TEST - %s\n", __func__);
582         printf("--------------\n");
583         for (i = 0; i < 50; i++)
584                 table_packets.hit_packet[i] = 0xadadadad;
585
586         for (i = 0; i < 50; i++)
587                 table_packets.miss_packet[i] = 0xbdadadad;
588
589         table_packets.n_hit_packets = 50;
590         table_packets.n_miss_packets = 50;
591
592         status = test_table_type(&rte_table_hash_key32_lru_ops,
593                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
594                 NULL, 0);
595         VERIFY(status, CHECK_TABLE_OK);
596
597         /* Invalid parameters */
598         key32lru_params.n_entries = 0;
599
600         status = test_table_type(&rte_table_hash_key32_lru_ops,
601                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
602                 NULL, 0);
603         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
604
605         key32lru_params.n_entries = 1<<16;
606         key32lru_params.f_hash = NULL;
607
608         status = test_table_type(&rte_table_hash_key32_lru_ops,
609                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
610                 NULL, 0);
611         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
612
613         return 0;
614 }
615
616 int
617 test_table_hash8ext(void)
618 {
619         int status, i;
620
621         /* Traffic flow */
622         struct rte_table_hash_params key8ext_params = {
623                 .name = "TABLE",
624                 .key_size = 8,
625                 .key_offset = APP_METADATA_OFFSET(32),
626                 .key_mask = NULL,
627                 .n_keys = 1 << 16,
628                 .n_buckets = 1 << 16,
629                 .f_hash = (rte_table_hash_op_hash)pipeline_test_hash,
630                 .seed = 0,
631         };
632
633         uint8_t key8ext[8];
634         uint32_t *k8ext = (uint32_t *) key8ext;
635
636         memset(key8ext, 0, sizeof(key8ext));
637         k8ext[0] = 0xadadadad;
638
639         struct table_packets table_packets;
640
641         printf("--------------\n");
642         printf("RUNNING TEST - %s\n", __func__);
643         printf("--------------\n");
644         for (i = 0; i < 50; i++)
645                 table_packets.hit_packet[i] = 0xadadadad;
646
647         for (i = 0; i < 50; i++)
648                 table_packets.miss_packet[i] = 0xbdadadad;
649
650         table_packets.n_hit_packets = 50;
651         table_packets.n_miss_packets = 50;
652
653         status = test_table_type(&rte_table_hash_key8_ext_ops,
654                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
655                 NULL, 0);
656         VERIFY(status, CHECK_TABLE_OK);
657
658         /* Invalid parameters */
659         key8ext_params.n_keys = 0;
660
661         status = test_table_type(&rte_table_hash_key8_ext_ops,
662                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
663                 NULL, 0);
664         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
665
666         key8ext_params.n_keys = 1<<16;
667         key8ext_params.f_hash = NULL;
668
669         status = test_table_type(&rte_table_hash_key8_ext_ops,
670                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
671                 NULL, 0);
672         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
673
674         return 0;
675 }
676
677 int
678 test_table_hash16ext(void)
679 {
680         int status, i;
681
682         /* Traffic flow */
683         struct rte_table_hash_key16_ext_params key16ext_params = {
684                 .n_entries = 1<<16,
685                 .n_entries_ext = 1<<15,
686                 .f_hash = pipeline_test_hash,
687                 .seed = 0,
688                 .signature_offset = APP_METADATA_OFFSET(0),
689                 .key_offset = APP_METADATA_OFFSET(32),
690                 .key_mask = NULL,
691         };
692
693         uint8_t key16ext[16];
694         uint32_t *k16ext = (uint32_t *) key16ext;
695
696         memset(key16ext, 0, sizeof(key16ext));
697         k16ext[0] = 0xadadadad;
698
699         struct table_packets table_packets;
700
701         printf("--------------\n");
702         printf("RUNNING TEST - %s\n", __func__);
703         printf("--------------\n");
704         for (i = 0; i < 50; i++)
705                 table_packets.hit_packet[i] = 0xadadadad;
706
707         for (i = 0; i < 50; i++)
708                 table_packets.miss_packet[i] = 0xbdadadad;
709
710         table_packets.n_hit_packets = 50;
711         table_packets.n_miss_packets = 50;
712
713         status = test_table_type(&rte_table_hash_key16_ext_ops,
714                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
715                 NULL, 0);
716         VERIFY(status, CHECK_TABLE_OK);
717
718         /* Invalid parameters */
719         key16ext_params.n_entries = 0;
720
721         status = test_table_type(&rte_table_hash_key16_ext_ops,
722                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
723                 NULL, 0);
724         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
725
726         key16ext_params.n_entries = 1<<16;
727         key16ext_params.f_hash = NULL;
728
729         status = test_table_type(&rte_table_hash_key16_ext_ops,
730                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
731                 NULL, 0);
732         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
733
734         key16ext_params.f_hash = pipeline_test_hash;
735         key16ext_params.n_entries_ext = 0;
736
737         status = test_table_type(&rte_table_hash_key16_ext_ops,
738         (void *)&key16ext_params, (void *)key16ext, &table_packets, NULL, 0);
739         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
740
741         return 0;
742 }
743
744 int
745 test_table_hash32ext(void)
746 {
747         int status, i;
748
749         /* Traffic flow */
750         struct rte_table_hash_key32_ext_params key32ext_params = {
751                 .n_entries = 1<<16,
752                 .n_entries_ext = 1<<15,
753                 .f_hash = pipeline_test_hash,
754                 .seed = 0,
755                 .signature_offset = APP_METADATA_OFFSET(0),
756                 .key_offset = APP_METADATA_OFFSET(32),
757         };
758
759         uint8_t key32ext[32];
760         uint32_t *k32ext = (uint32_t *) key32ext;
761
762         memset(key32ext, 0, sizeof(key32ext));
763         k32ext[0] = 0xadadadad;
764
765         struct table_packets table_packets;
766
767         printf("--------------\n");
768         printf("RUNNING TEST - %s\n", __func__);
769         printf("--------------\n");
770         for (i = 0; i < 50; i++)
771                 table_packets.hit_packet[i] = 0xadadadad;
772
773         for (i = 0; i < 50; i++)
774                 table_packets.miss_packet[i] = 0xbdadadad;
775
776         table_packets.n_hit_packets = 50;
777         table_packets.n_miss_packets = 50;
778
779         status = test_table_type(&rte_table_hash_key32_ext_ops,
780                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
781                 NULL, 0);
782         VERIFY(status, CHECK_TABLE_OK);
783
784         /* Invalid parameters */
785         key32ext_params.n_entries = 0;
786
787         status = test_table_type(&rte_table_hash_key32_ext_ops,
788                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
789                 NULL, 0);
790         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
791
792         key32ext_params.n_entries = 1<<16;
793         key32ext_params.f_hash = NULL;
794
795         status = test_table_type(&rte_table_hash_key32_ext_ops,
796                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
797                 NULL, 0);
798         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
799
800         key32ext_params.f_hash = pipeline_test_hash;
801         key32ext_params.n_entries_ext = 0;
802
803         status = test_table_type(&rte_table_hash_key32_ext_ops,
804                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
805                 NULL, 0);
806         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
807
808         return 0;
809 }
810
811 int
812 test_table_hash_cuckoo_combined(void)
813 {
814         int status, i;
815
816         /* Traffic flow */
817         struct rte_table_hash_cuckoo_params cuckoo_params = {
818                 .key_size = 32,
819                 .n_keys = 1<<16,
820                 .f_hash = pipeline_test_hash,
821                 .seed = 0,
822                 .signature_offset = APP_METADATA_OFFSET(0),
823                 .key_offset = APP_METADATA_OFFSET(32),
824                 .name = "CUCKOO_HASH",
825         };
826
827         uint8_t key_cuckoo[32];
828         uint32_t *kcuckoo = (uint32_t *) key_cuckoo;
829
830         memset(key_cuckoo, 0, sizeof(key_cuckoo));
831         kcuckoo[0] = 0xadadadad;
832
833         struct table_packets table_packets;
834
835         printf("--------------\n");
836         printf("RUNNING TEST - %s\n", __func__);
837         printf("--------------\n");
838         for (i = 0; i < 50; i++)
839                 table_packets.hit_packet[i] = 0xadadadad;
840
841         for (i = 0; i < 50; i++)
842                 table_packets.miss_packet[i] = 0xbdadadad;
843
844         table_packets.n_hit_packets = 50;
845         table_packets.n_miss_packets = 50;
846
847         status = test_table_type(&rte_table_hash_cuckoo_ops,
848                 (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
849                 NULL, 0);
850         VERIFY(status, CHECK_TABLE_OK);
851
852         /* Invalid parameters */
853         cuckoo_params.key_size = 0;
854
855         status = test_table_type(&rte_table_hash_cuckoo_ops,
856                 (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
857                 NULL, 0);
858         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
859
860         cuckoo_params.key_size = 32;
861         cuckoo_params.n_keys = 0;
862
863         status = test_table_type(&rte_table_hash_cuckoo_ops,
864                 (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
865                 NULL, 0);
866         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
867
868         cuckoo_params.n_keys = 1<<16;
869         cuckoo_params.f_hash = NULL;
870
871         status = test_table_type(&rte_table_hash_cuckoo_ops,
872                 (void *)&cuckoo_params, (void *)key_cuckoo, &table_packets,
873                 NULL, 0);
874         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
875
876         return 0;
877 }
878