test/event: add asymmetric cases for crypto adapter
[dpdk.git] / app / test / test_table.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <rte_byteorder.h>
6 #include <rte_hexdump.h>
7 #include <rte_string_fns.h>
8 #include <string.h>
9 #include "test.h"
10
11 #ifdef RTE_EXEC_ENV_WINDOWS
12 static int
13 test_table(void)
14 {
15         printf("table not supported on Windows, skipping test\n");
16         return TEST_SKIPPED;
17 }
18 #else
19
20 #include "test_table.h"
21 #include "test_table_pipeline.h"
22 #include "test_table_ports.h"
23 #include "test_table_tables.h"
24 #include "test_table_combined.h"
25 #include "test_table_acl.h"
26
27 /* Global variables */
28 struct rte_pipeline *p;
29 struct rte_ring *rings_rx[N_PORTS];
30 struct rte_ring *rings_tx[N_PORTS];
31 struct rte_mempool *pool = NULL;
32
33 uint32_t port_in_id[N_PORTS];
34 uint32_t port_out_id[N_PORTS];
35 uint32_t port_out_id_type[3];
36 uint32_t table_id[N_PORTS*2];
37 uint64_t override_hit_mask = 0xFFFFFFFF;
38 uint64_t override_miss_mask = 0xFFFFFFFF;
39 uint64_t non_reserved_actions_hit = 0;
40 uint64_t non_reserved_actions_miss = 0;
41 uint8_t connect_miss_action_to_port_out = 0;
42 uint8_t connect_miss_action_to_table = 0;
43 uint32_t table_entry_default_action = RTE_PIPELINE_ACTION_DROP;
44 uint32_t table_entry_hit_action = RTE_PIPELINE_ACTION_PORT;
45 uint32_t table_entry_miss_action = RTE_PIPELINE_ACTION_DROP;
46 rte_pipeline_port_in_action_handler port_in_action = NULL;
47 rte_pipeline_port_out_action_handler port_out_action = NULL;
48 rte_pipeline_table_action_handler_hit action_handler_hit = NULL;
49 rte_pipeline_table_action_handler_miss action_handler_miss = NULL;
50
51 /* Function prototypes */
52 static void app_init_rings(void);
53 static void app_init_mbuf_pools(void);
54
55 uint64_t pipeline_test_hash(void *key,
56                 __rte_unused void *key_mask,
57                 __rte_unused uint32_t key_size,
58                 __rte_unused uint64_t seed)
59 {
60         uint32_t *k32 = key;
61         uint32_t ip_dst = rte_be_to_cpu_32(k32[0]);
62         uint64_t signature = ip_dst;
63
64         return signature;
65 }
66
67 uint32_t pipeline_test_hash_cuckoo(const void *key,
68                 __rte_unused uint32_t key_size,
69                 __rte_unused uint32_t seed)
70 {
71         const uint32_t *k32 = key;
72         uint32_t ip_dst = rte_be_to_cpu_32(k32[0]);
73         uint32_t signature = ip_dst;
74
75         return signature;
76 }
77
78 static void
79 app_free_resources(void) {
80         int i;
81         for (i = 0; i < N_PORTS; i++)
82                 rte_ring_free(rings_rx[i]);
83         rte_mempool_free(pool);
84 }
85
86 static void
87 app_init_mbuf_pools(void)
88 {
89         /* Init the buffer pool */
90         printf("Getting/Creating the mempool ...\n");
91         pool = rte_mempool_lookup("mempool");
92         if (!pool) {
93                 pool = rte_pktmbuf_pool_create(
94                         "mempool",
95                         POOL_SIZE,
96                         POOL_CACHE_SIZE, 0, POOL_BUFFER_SIZE,
97                         0);
98                 if (pool == NULL)
99                         rte_panic("Cannot create mbuf pool\n");
100         }
101 }
102
103 static void
104 app_init_rings(void)
105 {
106         uint32_t i;
107
108         for (i = 0; i < N_PORTS; i++) {
109                 char name[32];
110
111                 snprintf(name, sizeof(name), "app_ring_rx_%u", i);
112                 rings_rx[i] = rte_ring_lookup(name);
113                 if (rings_rx[i] == NULL) {
114                         rings_rx[i] = rte_ring_create(
115                                 name,
116                                 RING_RX_SIZE,
117                                 0,
118                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
119                 }
120                 if (rings_rx[i] == NULL)
121                         rte_panic("Cannot create RX ring %u\n", i);
122         }
123
124         for (i = 0; i < N_PORTS; i++) {
125                 char name[32];
126
127                 snprintf(name, sizeof(name), "app_ring_tx_%u", i);
128                 rings_tx[i] = rte_ring_lookup(name);
129                 if (rings_tx[i] == NULL) {
130                         rings_tx[i] = rte_ring_create(
131                                 name,
132                                 RING_TX_SIZE,
133                                 0,
134                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
135                 }
136                 if (rings_tx[i] == NULL)
137                         rte_panic("Cannot create TX ring %u\n", i);
138         }
139
140 }
141
142 static int
143 test_table(void)
144 {
145         int status, ret;
146         unsigned i;
147
148         ret = TEST_SUCCESS;
149
150         app_init_rings();
151         app_init_mbuf_pools();
152
153         printf("\n\n\n\n************Pipeline tests************\n");
154
155         if (test_table_pipeline() < 0) {
156                 ret = TEST_FAILED;
157                 goto end;
158         }
159
160         printf("\n\n\n\n************Port tests************\n");
161         for (i = 0; i < n_port_tests; i++) {
162                 status = port_tests[i]();
163                 if (status < 0) {
164                         printf("\nPort test number %d failed (%d).\n", i,
165                                 status);
166                         ret = TEST_FAILED;
167                         goto end;
168                 }
169         }
170
171         printf("\n\n\n\n************Table tests************\n");
172         for (i = 0; i < n_table_tests; i++) {
173                 status = table_tests[i]();
174                 if (status < 0) {
175                         printf("\nTable test number %d failed (%d).\n", i,
176                                 status);
177                         ret = TEST_FAILED;
178                         goto end;
179                 }
180         }
181
182         printf("\n\n\n\n************Table tests************\n");
183         for (i = 0; i < n_table_tests_combined; i++) {
184                 status = table_tests_combined[i]();
185                 if (status < 0) {
186                         printf("\nCombined table test number %d failed with "
187                                 "reason number %d.\n", i, status);
188                         ret = TEST_FAILED;
189                         goto end;
190                 }
191         }
192
193 #ifdef RTE_LIB_ACL
194         printf("\n\n\n\n************ACL tests************\n");
195         if (test_table_acl() < 0) {
196                 ret = TEST_FAILED;
197                 goto end;
198         }
199 #endif
200
201 end:
202         app_free_resources();
203
204         return ret;
205 }
206
207 #endif /* !RTE_EXEC_ENV_WINDOWS */
208
209 REGISTER_TEST_COMMAND(table_autotest, test_table);