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