970d15cdc65ecc955d715f5ad43b195ba88cd4f5
[dpdk.git] / app / test / test_table.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
35 #ifndef RTE_LIBRTE_TABLE
36
37 #include "test.h"
38
39 int
40 test_table(void)
41 {
42         return 0;
43 }
44
45 #else
46
47 #include <rte_byteorder.h>
48 #include <rte_hexdump.h>
49 #include <rte_string_fns.h>
50 #include <string.h>
51 #include "test.h"
52 #include "test_table.h"
53 #include "test_table_pipeline.h"
54 #include "test_table_ports.h"
55 #include "test_table_tables.h"
56 #include "test_table_combined.h"
57 #include "test_table_acl.h"
58
59 /* Global variables */
60 struct rte_pipeline *p;
61 struct rte_ring *rings_rx[N_PORTS];
62 struct rte_ring *rings_tx[N_PORTS];
63 struct rte_mempool *pool = NULL;
64
65 uint32_t port_in_id[N_PORTS];
66 uint32_t port_out_id[N_PORTS];
67 uint32_t port_out_id_type[3];
68 uint32_t table_id[N_PORTS*2];
69 uint64_t override_hit_mask = 0xFFFFFFFF;
70 uint64_t override_miss_mask = 0xFFFFFFFF;
71 uint64_t non_reserved_actions_hit = 0;
72 uint64_t non_reserved_actions_miss = 0;
73 uint8_t connect_miss_action_to_port_out = 0;
74 uint8_t connect_miss_action_to_table = 0;
75 uint32_t table_entry_default_action = RTE_PIPELINE_ACTION_DROP;
76 uint32_t table_entry_hit_action = RTE_PIPELINE_ACTION_PORT;
77 uint32_t table_entry_miss_action = RTE_PIPELINE_ACTION_DROP;
78 rte_pipeline_port_in_action_handler port_in_action = NULL;
79 rte_pipeline_port_out_action_handler port_out_action = NULL;
80 rte_pipeline_table_action_handler_hit action_handler_hit = NULL;
81 rte_pipeline_table_action_handler_miss action_handler_miss = NULL;
82
83 /* Function prototypes */
84 static void app_init_rings(void);
85 static void app_init_mbuf_pools(void);
86
87 uint64_t pipeline_test_hash(void *key,
88                 __attribute__((unused)) uint32_t key_size,
89                 __attribute__((unused)) uint64_t seed)
90 {
91         uint32_t *k32 = (uint32_t *) key;
92         uint32_t ip_dst = rte_be_to_cpu_32(k32[0]);
93         uint64_t signature = ip_dst;
94
95         return signature;
96 }
97
98 static void
99 app_init_mbuf_pools(void)
100 {
101         /* Init the buffer pool */
102         printf("Getting/Creating the mempool ...\n");
103         pool = rte_mempool_lookup("mempool");
104         if (!pool) {
105                 pool = rte_mempool_create(
106                         "mempool",
107                         POOL_SIZE,
108                         POOL_BUFFER_SIZE,
109                         POOL_CACHE_SIZE,
110                         sizeof(struct rte_pktmbuf_pool_private),
111                         rte_pktmbuf_pool_init, NULL,
112                         rte_pktmbuf_init, NULL,
113                         0,
114                         0);
115                 if (pool == NULL)
116                         rte_panic("Cannot create mbuf pool\n");
117         }
118 }
119
120 static void
121 app_init_rings(void)
122 {
123         uint32_t i;
124
125         for (i = 0; i < N_PORTS; i++) {
126                 char name[32];
127
128                 snprintf(name, sizeof(name), "app_ring_rx_%u", i);
129                 rings_rx[i] = rte_ring_lookup(name);
130                 if (rings_rx[i] == NULL) {
131                         rings_rx[i] = rte_ring_create(
132                                 name,
133                                 RING_RX_SIZE,
134                                 0,
135                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
136                 }
137                 if (rings_rx[i] == NULL)
138                         rte_panic("Cannot create RX ring %u\n", i);
139         }
140
141         for (i = 0; i < N_PORTS; i++) {
142                 char name[32];
143
144                 snprintf(name, sizeof(name), "app_ring_tx_%u", i);
145                 rings_tx[i] = rte_ring_lookup(name);
146                 if (rings_tx[i] == NULL) {
147                         rings_tx[i] = rte_ring_create(
148                                 name,
149                                 RING_TX_SIZE,
150                                 0,
151                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
152                 }
153                 if (rings_tx[i] == NULL)
154                         rte_panic("Cannot create TX ring %u\n", i);
155         }
156
157 }
158
159 int
160 test_table(void)
161 {
162         int status, failures;
163         unsigned i;
164
165         failures = 0;
166
167         app_init_rings();
168         app_init_mbuf_pools();
169
170         printf("\n\n\n\n************Pipeline tests************\n");
171
172         if (test_table_pipeline() < 0)
173                 return -1;
174
175         printf("\n\n\n\n************Port tests************\n");
176         for (i = 0; i < n_port_tests; i++) {
177                 status = port_tests[i]();
178                 if (status < 0) {
179                         printf("\nPort test number %d failed (%d).\n", i,
180                                 status);
181                         failures++;
182                         return -1;
183                 }
184         }
185
186         printf("\n\n\n\n************Table tests************\n");
187         for (i = 0; i < n_table_tests; i++) {
188                 status = table_tests[i]();
189                 if (status < 0) {
190                         printf("\nTable test number %d failed (%d).\n", i,
191                                 status);
192                         failures++;
193                         return -1;
194                 }
195         }
196
197         printf("\n\n\n\n************Table tests************\n");
198         for (i = 0; i < n_table_tests_combined; i++) {
199                 status = table_tests_combined[i]();
200                 if (status < 0) {
201                         printf("\nCombined table test number %d failed with "
202                                 "reason number %d.\n", i, status);
203                         failures++;
204                         return -1;
205                 }
206         }
207
208         if (failures)
209                 return -1;
210
211 #ifdef RTE_LIBRTE_ACL
212         printf("\n\n\n\n************ACL tests************\n");
213         if (test_table_ACL() < 0)
214                 return -1;
215 #endif
216
217         return 0;
218 }
219
220 #endif