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