kvargs: use SPDX tags
[dpdk.git] / test / 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 #include "test_table.h"
11 #include "test_table_pipeline.h"
12 #include "test_table_ports.h"
13 #include "test_table_tables.h"
14 #include "test_table_combined.h"
15 #include "test_table_acl.h"
16
17 /* Global variables */
18 struct rte_pipeline *p;
19 struct rte_ring *rings_rx[N_PORTS];
20 struct rte_ring *rings_tx[N_PORTS];
21 struct rte_mempool *pool = NULL;
22
23 uint32_t port_in_id[N_PORTS];
24 uint32_t port_out_id[N_PORTS];
25 uint32_t port_out_id_type[3];
26 uint32_t table_id[N_PORTS*2];
27 uint64_t override_hit_mask = 0xFFFFFFFF;
28 uint64_t override_miss_mask = 0xFFFFFFFF;
29 uint64_t non_reserved_actions_hit = 0;
30 uint64_t non_reserved_actions_miss = 0;
31 uint8_t connect_miss_action_to_port_out = 0;
32 uint8_t connect_miss_action_to_table = 0;
33 uint32_t table_entry_default_action = RTE_PIPELINE_ACTION_DROP;
34 uint32_t table_entry_hit_action = RTE_PIPELINE_ACTION_PORT;
35 uint32_t table_entry_miss_action = RTE_PIPELINE_ACTION_DROP;
36 rte_pipeline_port_in_action_handler port_in_action = NULL;
37 rte_pipeline_port_out_action_handler port_out_action = NULL;
38 rte_pipeline_table_action_handler_hit action_handler_hit = NULL;
39 rte_pipeline_table_action_handler_miss action_handler_miss = NULL;
40
41 /* Function prototypes */
42 static void app_init_rings(void);
43 static void app_init_mbuf_pools(void);
44
45 uint64_t pipeline_test_hash(void *key,
46                 __attribute__((unused)) void *key_mask,
47                 __attribute__((unused)) uint32_t key_size,
48                 __attribute__((unused)) uint64_t seed)
49 {
50         uint32_t *k32 = key;
51         uint32_t ip_dst = rte_be_to_cpu_32(k32[0]);
52         uint64_t signature = ip_dst;
53
54         return signature;
55 }
56
57 static void
58 app_init_mbuf_pools(void)
59 {
60         /* Init the buffer pool */
61         printf("Getting/Creating the mempool ...\n");
62         pool = rte_mempool_lookup("mempool");
63         if (!pool) {
64                 pool = rte_pktmbuf_pool_create(
65                         "mempool",
66                         POOL_SIZE,
67                         POOL_CACHE_SIZE, 0, POOL_BUFFER_SIZE,
68                         0);
69                 if (pool == NULL)
70                         rte_panic("Cannot create mbuf pool\n");
71         }
72 }
73
74 static void
75 app_init_rings(void)
76 {
77         uint32_t i;
78
79         for (i = 0; i < N_PORTS; i++) {
80                 char name[32];
81
82                 snprintf(name, sizeof(name), "app_ring_rx_%u", i);
83                 rings_rx[i] = rte_ring_lookup(name);
84                 if (rings_rx[i] == NULL) {
85                         rings_rx[i] = rte_ring_create(
86                                 name,
87                                 RING_RX_SIZE,
88                                 0,
89                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
90                 }
91                 if (rings_rx[i] == NULL)
92                         rte_panic("Cannot create RX ring %u\n", i);
93         }
94
95         for (i = 0; i < N_PORTS; i++) {
96                 char name[32];
97
98                 snprintf(name, sizeof(name), "app_ring_tx_%u", i);
99                 rings_tx[i] = rte_ring_lookup(name);
100                 if (rings_tx[i] == NULL) {
101                         rings_tx[i] = rte_ring_create(
102                                 name,
103                                 RING_TX_SIZE,
104                                 0,
105                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
106                 }
107                 if (rings_tx[i] == NULL)
108                         rte_panic("Cannot create TX ring %u\n", i);
109         }
110
111 }
112
113 static int
114 test_table(void)
115 {
116         int status, failures;
117         unsigned i;
118
119         failures = 0;
120
121         app_init_rings();
122         app_init_mbuf_pools();
123
124         printf("\n\n\n\n************Pipeline tests************\n");
125
126         if (test_table_pipeline() < 0)
127                 return -1;
128
129         printf("\n\n\n\n************Port tests************\n");
130         for (i = 0; i < n_port_tests; i++) {
131                 status = port_tests[i]();
132                 if (status < 0) {
133                         printf("\nPort test number %d failed (%d).\n", i,
134                                 status);
135                         failures++;
136                         return -1;
137                 }
138         }
139
140         printf("\n\n\n\n************Table tests************\n");
141         for (i = 0; i < n_table_tests; i++) {
142                 status = table_tests[i]();
143                 if (status < 0) {
144                         printf("\nTable test number %d failed (%d).\n", i,
145                                 status);
146                         failures++;
147                         return -1;
148                 }
149         }
150
151         printf("\n\n\n\n************Table tests************\n");
152         for (i = 0; i < n_table_tests_combined; i++) {
153                 status = table_tests_combined[i]();
154                 if (status < 0) {
155                         printf("\nCombined table test number %d failed with "
156                                 "reason number %d.\n", i, status);
157                         failures++;
158                         return -1;
159                 }
160         }
161
162         if (failures)
163                 return -1;
164
165 #ifdef RTE_LIBRTE_ACL
166         printf("\n\n\n\n************ACL tests************\n");
167         if (test_table_acl() < 0)
168                 return -1;
169 #endif
170
171         return 0;
172 }
173
174 REGISTER_TEST_COMMAND(table_autotest, test_table);