New upstream version 18.02
[deb_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_free_resources(void) {
59         int i;
60         for (i = 0; i < N_PORTS; i++)
61                 rte_ring_free(rings_rx[i]);
62         rte_mempool_free(pool);
63 }
64
65 static void
66 app_init_mbuf_pools(void)
67 {
68         /* Init the buffer pool */
69         printf("Getting/Creating the mempool ...\n");
70         pool = rte_mempool_lookup("mempool");
71         if (!pool) {
72                 pool = rte_pktmbuf_pool_create(
73                         "mempool",
74                         POOL_SIZE,
75                         POOL_CACHE_SIZE, 0, POOL_BUFFER_SIZE,
76                         0);
77                 if (pool == NULL)
78                         rte_panic("Cannot create mbuf pool\n");
79         }
80 }
81
82 static void
83 app_init_rings(void)
84 {
85         uint32_t i;
86
87         for (i = 0; i < N_PORTS; i++) {
88                 char name[32];
89
90                 snprintf(name, sizeof(name), "app_ring_rx_%u", i);
91                 rings_rx[i] = rte_ring_lookup(name);
92                 if (rings_rx[i] == NULL) {
93                         rings_rx[i] = rte_ring_create(
94                                 name,
95                                 RING_RX_SIZE,
96                                 0,
97                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
98                 }
99                 if (rings_rx[i] == NULL)
100                         rte_panic("Cannot create RX ring %u\n", i);
101         }
102
103         for (i = 0; i < N_PORTS; i++) {
104                 char name[32];
105
106                 snprintf(name, sizeof(name), "app_ring_tx_%u", i);
107                 rings_tx[i] = rte_ring_lookup(name);
108                 if (rings_tx[i] == NULL) {
109                         rings_tx[i] = rte_ring_create(
110                                 name,
111                                 RING_TX_SIZE,
112                                 0,
113                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
114                 }
115                 if (rings_tx[i] == NULL)
116                         rte_panic("Cannot create TX ring %u\n", i);
117         }
118
119 }
120
121 static int
122 test_table(void)
123 {
124         int status, ret;
125         unsigned i;
126
127         ret = TEST_SUCCESS;
128
129         app_init_rings();
130         app_init_mbuf_pools();
131
132         printf("\n\n\n\n************Pipeline tests************\n");
133
134         if (test_table_pipeline() < 0) {
135                 ret = TEST_FAILED;
136                 goto end;
137         }
138
139         printf("\n\n\n\n************Port tests************\n");
140         for (i = 0; i < n_port_tests; i++) {
141                 status = port_tests[i]();
142                 if (status < 0) {
143                         printf("\nPort test number %d failed (%d).\n", i,
144                                 status);
145                         ret = TEST_FAILED;
146                         goto end;
147                 }
148         }
149
150         printf("\n\n\n\n************Table tests************\n");
151         for (i = 0; i < n_table_tests; i++) {
152                 status = table_tests[i]();
153                 if (status < 0) {
154                         printf("\nTable test number %d failed (%d).\n", i,
155                                 status);
156                         ret = TEST_FAILED;
157                         goto end;
158                 }
159         }
160
161         printf("\n\n\n\n************Table tests************\n");
162         for (i = 0; i < n_table_tests_combined; i++) {
163                 status = table_tests_combined[i]();
164                 if (status < 0) {
165                         printf("\nCombined table test number %d failed with "
166                                 "reason number %d.\n", i, status);
167                         ret = TEST_FAILED;
168                         goto end;
169                 }
170         }
171
172 #ifdef RTE_LIBRTE_ACL
173         printf("\n\n\n\n************ACL tests************\n");
174         if (test_table_acl() < 0) {
175                 ret = TEST_FAILED;
176                 goto end;
177         }
178 #endif
179
180 end:
181         app_free_resources();
182
183         return ret;
184 }
185
186 REGISTER_TEST_COMMAND(table_autotest, test_table);