app/test: fix packet framework table unit tests
[dpdk.git] / app / test / test_table_combined.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 };
73
74 unsigned n_table_tests_combined = RTE_DIM(table_tests_combined);
75
76 /* Generic port tester function */
77 static int
78 test_table_type(struct rte_table_ops *table_ops, void *table_args,
79         void *key, struct table_packets *table_packets,
80         struct manage_ops *manage_ops, unsigned n_ops)
81 {
82         uint32_t ring_in_id, table_id, ring_out_id, ring_out_2_id;
83         unsigned i;
84
85         RTE_SET_USED(manage_ops);
86         RTE_SET_USED(n_ops);
87         /* Create pipeline */
88         struct rte_pipeline_params pipeline_params = {
89                 .name = "pipeline",
90                 .socket_id = 0,
91         };
92
93         struct rte_pipeline *pipeline = rte_pipeline_create(&pipeline_params);
94
95         /* Create input ring */
96         struct rte_port_ring_reader_params ring_params_rx = {
97                 .ring = RING_RX,
98         };
99
100         struct rte_port_ring_writer_params ring_params_tx = {
101                 .ring = RING_RX,
102                 .tx_burst_sz = RTE_PORT_IN_BURST_SIZE_MAX,
103         };
104
105         struct rte_pipeline_port_in_params ring_in_params = {
106                 .ops = &rte_port_ring_reader_ops,
107                 .arg_create = (void *)&ring_params_rx,
108                 .f_action = NULL,
109                 .burst_size = RTE_PORT_IN_BURST_SIZE_MAX,
110         };
111
112         if (rte_pipeline_port_in_create(pipeline, &ring_in_params,
113                 &ring_in_id) != 0) {
114                 rte_pipeline_free(pipeline);
115                 return -CHECK_TABLE_PORT_CONFIG;
116         }
117
118         /* Create table */
119         struct rte_pipeline_table_params table_params = {
120                 .ops = table_ops,
121                 .arg_create = table_args,
122                 .f_action_hit = NULL,
123                 .f_action_miss = NULL,
124                 .arg_ah = NULL,
125                 .action_data_size = 0,
126         };
127
128         if (rte_pipeline_table_create(pipeline, &table_params,
129                 &table_id) != 0) {
130                 rte_pipeline_free(pipeline);
131                 return -CHECK_TABLE_TABLE_CONFIG;
132         }
133
134         /* Create output ports */
135         ring_params_tx.ring = RING_TX;
136
137         struct rte_pipeline_port_out_params ring_out_params = {
138                 .ops = &rte_port_ring_writer_ops,
139                 .arg_create = (void *)&ring_params_tx,
140                 .f_action = NULL,
141         };
142
143         if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
144                 &ring_out_id) != 0) {
145                 rte_pipeline_free(pipeline);
146                 return -CHECK_TABLE_PORT_CONFIG;
147         }
148
149         ring_params_tx.ring = RING_TX_2;
150
151         if (rte_pipeline_port_out_create(pipeline, &ring_out_params,
152                 &ring_out_2_id) != 0) {
153                 rte_pipeline_free(pipeline);
154                 return -CHECK_TABLE_PORT_CONFIG;
155         }
156
157         /* Add entry to the table */
158         struct rte_pipeline_table_entry default_entry = {
159                 .action = RTE_PIPELINE_ACTION_DROP,
160                 {.table_id = ring_out_id},
161         };
162
163         struct rte_pipeline_table_entry table_entry = {
164                 .action = RTE_PIPELINE_ACTION_PORT,
165                 {.table_id = ring_out_id},
166         };
167
168         struct rte_pipeline_table_entry *default_entry_ptr, *entry_ptr;
169
170         int key_found;
171
172         if (rte_pipeline_table_default_entry_add(pipeline, table_id,
173                 &default_entry, &default_entry_ptr) != 0) {
174                 rte_pipeline_free(pipeline);
175                 return -CHECK_TABLE_DEFAULT_ENTRY_ADD;
176         }
177
178         if (rte_pipeline_table_entry_add(pipeline, table_id,
179                 key ? key : &table_entry, &table_entry, &key_found,
180                         &entry_ptr) != 0) {
181                 rte_pipeline_free(pipeline);
182                 return -CHECK_TABLE_ENTRY_ADD;
183         }
184
185         /* Create connections and check consistency */
186         if (rte_pipeline_port_in_connect_to_table(pipeline, ring_in_id,
187                 table_id) != 0) {
188                 rte_pipeline_free(pipeline);
189                 return -CHECK_TABLE_CONNECT;
190         }
191
192         if (rte_pipeline_port_in_enable(pipeline, ring_in_id) != 0) {
193                 rte_pipeline_free(pipeline);
194                 return -CHECK_TABLE_PORT_ENABLE;
195         }
196
197         if (rte_pipeline_check(pipeline) != 0) {
198                 rte_pipeline_free(pipeline);
199                 return -CHECK_TABLE_CONSISTENCY;
200         }
201
202
203
204         /* Flow test - All hits */
205         if (table_packets->n_hit_packets) {
206                 for (i = 0; i < table_packets->n_hit_packets; i++)
207                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
208
209                 RUN_PIPELINE(pipeline);
210
211                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
212                                 table_packets->n_hit_packets);
213         }
214
215         /* Flow test - All misses */
216         if (table_packets->n_miss_packets) {
217                 for (i = 0; i < table_packets->n_miss_packets; i++)
218                         RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
219
220                 RUN_PIPELINE(pipeline);
221
222                 VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
223         }
224
225         /* Flow test - Half hits, half misses */
226         if (table_packets->n_hit_packets && table_packets->n_miss_packets) {
227                 for (i = 0; i < (table_packets->n_hit_packets) / 2; i++)
228                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
229
230                 for (i = 0; i < (table_packets->n_miss_packets) / 2; i++)
231                         RING_ENQUEUE(RING_RX, table_packets->miss_packet[i]);
232
233                 RUN_PIPELINE(pipeline);
234                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets,
235                         table_packets->n_hit_packets / 2);
236         }
237
238         /* Flow test - Single packet */
239         if (table_packets->n_hit_packets) {
240                 RING_ENQUEUE(RING_RX, table_packets->hit_packet[0]);
241                 RUN_PIPELINE(pipeline);
242                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 1);
243         }
244         if (table_packets->n_miss_packets) {
245                 RING_ENQUEUE(RING_RX, table_packets->miss_packet[0]);
246                 RUN_PIPELINE(pipeline);
247                 VERIFY_TRAFFIC(RING_TX, table_packets->n_miss_packets, 0);
248         }
249
250
251         /* Change table entry action */
252         printf("Change entry action\n");
253         table_entry.table_id = ring_out_2_id;
254
255         if (rte_pipeline_table_default_entry_add(pipeline, table_id,
256                 &default_entry, &default_entry_ptr) != 0) {
257                 rte_pipeline_free(pipeline);
258                 return -CHECK_TABLE_ENTRY_ADD;
259         }
260
261         if (rte_pipeline_table_entry_add(pipeline, table_id,
262                 key ? key : &table_entry, &table_entry, &key_found,
263                         &entry_ptr) != 0) {
264                 rte_pipeline_free(pipeline);
265                 return -CHECK_TABLE_ENTRY_ADD;
266         }
267
268         /* Check that traffic destination has changed */
269         if (table_packets->n_hit_packets) {
270                 for (i = 0; i < table_packets->n_hit_packets; i++)
271                         RING_ENQUEUE(RING_RX, table_packets->hit_packet[i]);
272
273                 RUN_PIPELINE(pipeline);
274                 VERIFY_TRAFFIC(RING_TX, table_packets->n_hit_packets, 0);
275                 VERIFY_TRAFFIC(RING_TX_2, table_packets->n_hit_packets,
276                         table_packets->n_hit_packets);
277         }
278
279         printf("delete entry\n");
280         /* Delete table entry */
281         rte_pipeline_table_entry_delete(pipeline, table_id,
282                 key ? key : &table_entry, &key_found, NULL);
283
284         rte_pipeline_free(pipeline);
285
286         return 0;
287 }
288
289 /* Table tests */
290 int
291 test_table_stub_combined(void)
292 {
293         int status, i;
294         struct table_packets table_packets;
295
296         printf("--------------\n");
297         printf("RUNNING TEST - %s\n", __func__);
298         printf("--------------\n");
299         for (i = 0; i < N_PACKETS; i++)
300                 table_packets.hit_packet[i] = i;
301
302         table_packets.n_hit_packets = N_PACKETS;
303         table_packets.n_miss_packets = 0;
304
305         status = test_table_type(&rte_table_stub_ops, NULL, NULL,
306                 &table_packets, NULL, 1);
307         VERIFY(status, CHECK_TABLE_OK);
308
309         return 0;
310 }
311
312 int
313 test_table_lpm_combined(void)
314 {
315         int status, i;
316
317         /* Traffic flow */
318         struct rte_table_lpm_params lpm_params = {
319                 .name = "LPM",
320                 .n_rules = 1 << 16,
321                 .number_tbl8s = 1 << 8,
322                 .flags = 0,
323                 .entry_unique_size = 8,
324                 .offset = APP_METADATA_OFFSET(0),
325         };
326
327         struct rte_table_lpm_key lpm_key = {
328                 .ip = 0xadadadad,
329                 .depth = 16,
330         };
331
332         struct table_packets table_packets;
333
334         printf("--------------\n");
335         printf("RUNNING TEST - %s\n", __func__);
336         printf("--------------\n");
337
338         for (i = 0; i < N_PACKETS; i++)
339                 table_packets.hit_packet[i] = 0xadadadad;
340
341         for (i = 0; i < N_PACKETS; i++)
342                 table_packets.miss_packet[i] = 0xfefefefe;
343
344         table_packets.n_hit_packets = N_PACKETS;
345         table_packets.n_miss_packets = N_PACKETS;
346
347         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
348                 (void *)&lpm_key, &table_packets, NULL, 0);
349         VERIFY(status, CHECK_TABLE_OK);
350
351         /* Invalid parameters */
352         lpm_params.n_rules = 0;
353
354         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
355                 (void *)&lpm_key, &table_packets, NULL, 0);
356         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
357
358         lpm_params.n_rules = 1 << 24;
359         lpm_key.depth = 0;
360
361         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
362                 (void *)&lpm_key, &table_packets, NULL, 0);
363         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
364
365         lpm_key.depth = 33;
366
367         status = test_table_type(&rte_table_lpm_ops, (void *)&lpm_params,
368                 (void *)&lpm_key, &table_packets, NULL, 0);
369         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
370
371         return 0;
372 }
373
374 int
375 test_table_lpm_ipv6_combined(void)
376 {
377         int status, i;
378
379         /* Traffic flow */
380         struct rte_table_lpm_ipv6_params lpm_ipv6_params = {
381                 .name = "LPM",
382                 .n_rules = 1 << 16,
383                 .number_tbl8s = 1 << 13,
384                 .entry_unique_size = 8,
385                 .offset = APP_METADATA_OFFSET(32),
386         };
387
388         struct rte_table_lpm_ipv6_key lpm_ipv6_key = {
389                 .depth = 16,
390         };
391         memset(lpm_ipv6_key.ip, 0xad, 16);
392
393         struct table_packets table_packets;
394
395         printf("--------------\n");
396         printf("RUNNING TEST - %s\n", __func__);
397         printf("--------------\n");
398         for (i = 0; i < N_PACKETS; i++)
399                 table_packets.hit_packet[i] = 0xadadadad;
400
401         for (i = 0; i < N_PACKETS; i++)
402                 table_packets.miss_packet[i] = 0xadadadab;
403
404         table_packets.n_hit_packets = N_PACKETS;
405         table_packets.n_miss_packets = N_PACKETS;
406
407         status = test_table_type(&rte_table_lpm_ipv6_ops,
408                 (void *)&lpm_ipv6_params,
409                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
410         VERIFY(status, CHECK_TABLE_OK);
411
412         /* Invalid parameters */
413         lpm_ipv6_params.n_rules = 0;
414
415         status = test_table_type(&rte_table_lpm_ipv6_ops,
416                 (void *)&lpm_ipv6_params,
417                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
418         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
419
420         lpm_ipv6_params.n_rules = 1 << 24;
421         lpm_ipv6_key.depth = 0;
422
423         status = test_table_type(&rte_table_lpm_ipv6_ops,
424                 (void *)&lpm_ipv6_params,
425                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
426         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
427
428         lpm_ipv6_key.depth = 129;
429         status = test_table_type(&rte_table_lpm_ipv6_ops,
430                 (void *)&lpm_ipv6_params,
431                 (void *)&lpm_ipv6_key, &table_packets, NULL, 0);
432         VERIFY(status, CHECK_TABLE_ENTRY_ADD);
433
434         return 0;
435 }
436
437 int
438 test_table_hash8lru(void)
439 {
440         int status, i;
441
442         /* Traffic flow */
443         struct rte_table_hash_key8_lru_params key8lru_params = {
444                 .n_entries = 1<<24,
445                 .f_hash = pipeline_test_hash,
446                 .signature_offset = APP_METADATA_OFFSET(0),
447                 .key_offset = APP_METADATA_OFFSET(32),
448                 .key_mask = NULL,
449         };
450
451         uint8_t key8lru[8];
452         uint32_t *k8lru = (uint32_t *) key8lru;
453
454         memset(key8lru, 0, sizeof(key8lru));
455         k8lru[0] = 0xadadadad;
456
457         struct table_packets table_packets;
458
459         printf("--------------\n");
460         printf("RUNNING TEST - %s\n", __func__);
461         printf("--------------\n");
462         for (i = 0; i < 50; i++)
463                 table_packets.hit_packet[i] = 0xadadadad;
464
465         for (i = 0; i < 50; i++)
466                 table_packets.miss_packet[i] = 0xfefefefe;
467
468         table_packets.n_hit_packets = 50;
469         table_packets.n_miss_packets = 50;
470
471         status = test_table_type(&rte_table_hash_key8_lru_ops,
472                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
473                         NULL, 0);
474         VERIFY(status, CHECK_TABLE_OK);
475
476         /* Invalid parameters */
477         key8lru_params.n_entries = 0;
478
479         status = test_table_type(&rte_table_hash_key8_lru_ops,
480                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
481                         NULL, 0);
482         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
483
484         key8lru_params.n_entries = 1<<16;
485         key8lru_params.f_hash = NULL;
486
487         status = test_table_type(&rte_table_hash_key8_lru_ops,
488                 (void *)&key8lru_params, (void *)key8lru, &table_packets,
489                         NULL, 0);
490         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
491
492         return 0;
493 }
494
495 int
496 test_table_hash16lru(void)
497 {
498         int status, i;
499
500         /* Traffic flow */
501         struct rte_table_hash_key16_lru_params key16lru_params = {
502                 .n_entries = 1<<16,
503                 .f_hash = pipeline_test_hash,
504                 .seed = 0,
505                 .signature_offset = APP_METADATA_OFFSET(0),
506                 .key_offset = APP_METADATA_OFFSET(32),
507                 .key_mask = NULL,
508         };
509
510         uint8_t key16lru[16];
511         uint32_t *k16lru = (uint32_t *) key16lru;
512
513         memset(key16lru, 0, sizeof(key16lru));
514         k16lru[0] = 0xadadadad;
515
516         struct table_packets table_packets;
517
518         printf("--------------\n");
519         printf("RUNNING TEST - %s\n", __func__);
520         printf("--------------\n");
521         for (i = 0; i < 50; i++)
522                 table_packets.hit_packet[i] = 0xadadadad;
523
524         for (i = 0; i < 50; i++)
525                 table_packets.miss_packet[i] = 0xfefefefe;
526
527         table_packets.n_hit_packets = 50;
528         table_packets.n_miss_packets = 50;
529
530         status = test_table_type(&rte_table_hash_key16_lru_ops,
531                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
532                         NULL, 0);
533         VERIFY(status, CHECK_TABLE_OK);
534
535         /* Invalid parameters */
536         key16lru_params.n_entries = 0;
537
538         status = test_table_type(&rte_table_hash_key16_lru_ops,
539                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
540                         NULL, 0);
541         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
542
543         key16lru_params.n_entries = 1<<16;
544         key16lru_params.f_hash = NULL;
545
546         status = test_table_type(&rte_table_hash_key16_lru_ops,
547                 (void *)&key16lru_params, (void *)key16lru, &table_packets,
548                         NULL, 0);
549         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
550
551         return 0;
552 }
553
554 int
555 test_table_hash32lru(void)
556 {
557         int status, i;
558
559         /* Traffic flow */
560         struct rte_table_hash_key32_lru_params key32lru_params = {
561                 .n_entries = 1<<16,
562                 .f_hash = pipeline_test_hash,
563                 .seed = 0,
564                 .signature_offset = APP_METADATA_OFFSET(0),
565                 .key_offset = APP_METADATA_OFFSET(32),
566         };
567
568         uint8_t key32lru[32];
569         uint32_t *k32lru = (uint32_t *) key32lru;
570
571         memset(key32lru, 0, sizeof(key32lru));
572         k32lru[0] = 0xadadadad;
573
574         struct table_packets table_packets;
575
576         printf("--------------\n");
577         printf("RUNNING TEST - %s\n", __func__);
578         printf("--------------\n");
579         for (i = 0; i < 50; i++)
580                 table_packets.hit_packet[i] = 0xadadadad;
581
582         for (i = 0; i < 50; i++)
583                 table_packets.miss_packet[i] = 0xbdadadad;
584
585         table_packets.n_hit_packets = 50;
586         table_packets.n_miss_packets = 50;
587
588         status = test_table_type(&rte_table_hash_key32_lru_ops,
589                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
590                 NULL, 0);
591         VERIFY(status, CHECK_TABLE_OK);
592
593         /* Invalid parameters */
594         key32lru_params.n_entries = 0;
595
596         status = test_table_type(&rte_table_hash_key32_lru_ops,
597                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
598                 NULL, 0);
599         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
600
601         key32lru_params.n_entries = 1<<16;
602         key32lru_params.f_hash = NULL;
603
604         status = test_table_type(&rte_table_hash_key32_lru_ops,
605                 (void *)&key32lru_params, (void *)key32lru, &table_packets,
606                 NULL, 0);
607         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
608
609         return 0;
610 }
611
612 int
613 test_table_hash8ext(void)
614 {
615         int status, i;
616
617         /* Traffic flow */
618         struct rte_table_hash_key8_ext_params key8ext_params = {
619                 .n_entries = 1<<16,
620                 .n_entries_ext = 1<<15,
621                 .f_hash = pipeline_test_hash,
622                 .seed = 0,
623                 .signature_offset = APP_METADATA_OFFSET(0),
624                 .key_offset = APP_METADATA_OFFSET(32),
625                 .key_mask = NULL,
626         };
627
628         uint8_t key8ext[8];
629         uint32_t *k8ext = (uint32_t *) key8ext;
630
631         memset(key8ext, 0, sizeof(key8ext));
632         k8ext[0] = 0xadadadad;
633
634         struct table_packets table_packets;
635
636         printf("--------------\n");
637         printf("RUNNING TEST - %s\n", __func__);
638         printf("--------------\n");
639         for (i = 0; i < 50; i++)
640                 table_packets.hit_packet[i] = 0xadadadad;
641
642         for (i = 0; i < 50; i++)
643                 table_packets.miss_packet[i] = 0xbdadadad;
644
645         table_packets.n_hit_packets = 50;
646         table_packets.n_miss_packets = 50;
647
648         status = test_table_type(&rte_table_hash_key8_ext_ops,
649                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
650                 NULL, 0);
651         VERIFY(status, CHECK_TABLE_OK);
652
653         /* Invalid parameters */
654         key8ext_params.n_entries = 0;
655
656         status = test_table_type(&rte_table_hash_key8_ext_ops,
657                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
658                 NULL, 0);
659         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
660
661         key8ext_params.n_entries = 1<<16;
662         key8ext_params.f_hash = NULL;
663
664         status = test_table_type(&rte_table_hash_key8_ext_ops,
665                 (void *)&key8ext_params, (void *)key8ext, &table_packets,
666                 NULL, 0);
667         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
668
669         key8ext_params.f_hash = pipeline_test_hash;
670         key8ext_params.n_entries_ext = 0;
671
672         status = test_table_type(&rte_table_hash_key8_ext_ops,
673         (void *)&key8ext_params, (void *)key8ext, &table_packets, NULL, 0);
674         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
675
676         return 0;
677 }
678
679 int
680 test_table_hash16ext(void)
681 {
682         int status, i;
683
684         /* Traffic flow */
685         struct rte_table_hash_key16_ext_params key16ext_params = {
686                 .n_entries = 1<<16,
687                 .n_entries_ext = 1<<15,
688                 .f_hash = pipeline_test_hash,
689                 .seed = 0,
690                 .signature_offset = APP_METADATA_OFFSET(0),
691                 .key_offset = APP_METADATA_OFFSET(32),
692                 .key_mask = NULL,
693         };
694
695         uint8_t key16ext[16];
696         uint32_t *k16ext = (uint32_t *) key16ext;
697
698         memset(key16ext, 0, sizeof(key16ext));
699         k16ext[0] = 0xadadadad;
700
701         struct table_packets table_packets;
702
703         printf("--------------\n");
704         printf("RUNNING TEST - %s\n", __func__);
705         printf("--------------\n");
706         for (i = 0; i < 50; i++)
707                 table_packets.hit_packet[i] = 0xadadadad;
708
709         for (i = 0; i < 50; i++)
710                 table_packets.miss_packet[i] = 0xbdadadad;
711
712         table_packets.n_hit_packets = 50;
713         table_packets.n_miss_packets = 50;
714
715         status = test_table_type(&rte_table_hash_key16_ext_ops,
716                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
717                 NULL, 0);
718         VERIFY(status, CHECK_TABLE_OK);
719
720         /* Invalid parameters */
721         key16ext_params.n_entries = 0;
722
723         status = test_table_type(&rte_table_hash_key16_ext_ops,
724                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
725                 NULL, 0);
726         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
727
728         key16ext_params.n_entries = 1<<16;
729         key16ext_params.f_hash = NULL;
730
731         status = test_table_type(&rte_table_hash_key16_ext_ops,
732                 (void *)&key16ext_params, (void *)key16ext, &table_packets,
733                 NULL, 0);
734         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
735
736         key16ext_params.f_hash = pipeline_test_hash;
737         key16ext_params.n_entries_ext = 0;
738
739         status = test_table_type(&rte_table_hash_key16_ext_ops,
740         (void *)&key16ext_params, (void *)key16ext, &table_packets, NULL, 0);
741         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
742
743         return 0;
744 }
745
746 int
747 test_table_hash32ext(void)
748 {
749         int status, i;
750
751         /* Traffic flow */
752         struct rte_table_hash_key32_ext_params key32ext_params = {
753                 .n_entries = 1<<16,
754                 .n_entries_ext = 1<<15,
755                 .f_hash = pipeline_test_hash,
756                 .seed = 0,
757                 .signature_offset = APP_METADATA_OFFSET(0),
758                 .key_offset = APP_METADATA_OFFSET(32),
759         };
760
761         uint8_t key32ext[32];
762         uint32_t *k32ext = (uint32_t *) key32ext;
763
764         memset(key32ext, 0, sizeof(key32ext));
765         k32ext[0] = 0xadadadad;
766
767         struct table_packets table_packets;
768
769         printf("--------------\n");
770         printf("RUNNING TEST - %s\n", __func__);
771         printf("--------------\n");
772         for (i = 0; i < 50; i++)
773                 table_packets.hit_packet[i] = 0xadadadad;
774
775         for (i = 0; i < 50; i++)
776                 table_packets.miss_packet[i] = 0xbdadadad;
777
778         table_packets.n_hit_packets = 50;
779         table_packets.n_miss_packets = 50;
780
781         status = test_table_type(&rte_table_hash_key32_ext_ops,
782                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
783                 NULL, 0);
784         VERIFY(status, CHECK_TABLE_OK);
785
786         /* Invalid parameters */
787         key32ext_params.n_entries = 0;
788
789         status = test_table_type(&rte_table_hash_key32_ext_ops,
790                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
791                 NULL, 0);
792         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
793
794         key32ext_params.n_entries = 1<<16;
795         key32ext_params.f_hash = NULL;
796
797         status = test_table_type(&rte_table_hash_key32_ext_ops,
798                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
799                 NULL, 0);
800         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
801
802         key32ext_params.f_hash = pipeline_test_hash;
803         key32ext_params.n_entries_ext = 0;
804
805         status = test_table_type(&rte_table_hash_key32_ext_ops,
806                 (void *)&key32ext_params, (void *)key32ext, &table_packets,
807                 NULL, 0);
808         VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
809
810         return 0;
811 }