apps: use helper to create mbuf pools
[dpdk.git] / app / test / test_table.h
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 #include <rte_table_stub.h>
35 #include <rte_table_lpm.h>
36 #include <rte_table_lpm_ipv6.h>
37 #include <rte_table_hash.h>
38 #include <rte_table_array.h>
39 #include <rte_pipeline.h>
40
41 #ifdef RTE_LIBRTE_ACL
42 #include <rte_table_acl.h>
43 #endif
44
45 #include <rte_port_ring.h>
46 #include <rte_port_ethdev.h>
47 #include <rte_port_source_sink.h>
48
49 #ifndef TEST_TABLE_H_
50 #define TEST_TABLE_H_
51
52 #define RING_SIZE 4096
53 #define MAX_BULK 32
54 #define N 65536
55 #define TIME_S 5
56 #define TEST_RING_FULL_EMTPY_ITER   8
57 #define N_PORTS             2
58 #define N_PKTS              2
59 #define N_PKTS_EXT          6
60 #define RING_RX rings_rx[0]
61 #define RING_RX_2 rings_rx[1]
62 #define RING_TX rings_tx[0]
63 #define RING_TX_2 rings_tx[1]
64 #define PORT_RX_RING_SIZE   128
65 #define PORT_TX_RING_SIZE   512
66 #define RING_RX_SIZE        128
67 #define RING_TX_SIZE        128
68 #define POOL_BUFFER_SIZE    (2048 + RTE_PKTMBUF_HEADROOM)
69 #define POOL_SIZE           (32 * 1024)
70 #define POOL_CACHE_SIZE     256
71 #define BURST_SIZE          8
72 #define WORKER_TYPE         1
73 #define MAX_DUMMY_PORTS     2
74 #define MP_NAME             "dummy_port_mempool"
75 #define MBUF_COUNT          (8000 * MAX_DUMMY_PORTS)
76 #define MP_CACHE_SZ         256
77 #define MP_SOCKET           0
78 #define MP_FLAGS            0
79
80 /* Macros */
81 #define RING_ENQUEUE(ring, value) do {                                  \
82         struct rte_mbuf *m;                                             \
83         uint32_t *k32, *signature;                                      \
84         uint8_t *key;                                                   \
85                                                                         \
86         m = rte_pktmbuf_alloc(pool);                                    \
87         if (m == NULL)                                                  \
88                 return -1;                                              \
89         signature = RTE_MBUF_METADATA_UINT32_PTR(m, 0);                 \
90         key = RTE_MBUF_METADATA_UINT8_PTR(m, 32);                       \
91         k32 = (uint32_t *) key;                                         \
92         k32[0] = (value);                                               \
93         *signature = pipeline_test_hash(key, 0, 0);                     \
94         rte_ring_enqueue((ring), m);                                    \
95 } while (0)
96
97 #define RUN_PIPELINE(pipeline) do {                                     \
98         rte_pipeline_run((pipeline));                                   \
99         rte_pipeline_flush((pipeline));                                 \
100 } while (0)
101
102 #define VERIFY(var, value) do {                                         \
103         if ((var) != -(value))                                          \
104                 return var;                                             \
105 } while (0)
106
107 #define VERIFY_TRAFFIC(ring, sent, expected) do {                       \
108         unsigned i, n = 0;                                              \
109         void *mbuf = NULL;                                              \
110                                                                         \
111         for (i = 0; i < (sent); i++) {                                  \
112                 if (!rte_ring_dequeue((ring), &mbuf)) {                 \
113                         if (mbuf == NULL)                               \
114                                 continue;                               \
115                         n++;                                            \
116                         rte_pktmbuf_free((struct rte_mbuf *)mbuf);      \
117                 }                                                       \
118                 else                                                    \
119                         break;                                          \
120         }                                                               \
121         printf("Expected %d, got %d\n", expected, n);                   \
122         if (n != (expected)) {                                          \
123                 return -21;                                             \
124         }                                                               \
125 } while (0)
126
127 /* Function definitions */
128 uint64_t pipeline_test_hash(
129         void *key,
130         __attribute__((unused)) uint32_t key_size,
131         __attribute__((unused)) uint64_t seed);
132
133 /* Extern variables */
134 extern struct rte_pipeline *p;
135 extern struct rte_ring *rings_rx[N_PORTS];
136 extern struct rte_ring *rings_tx[N_PORTS];
137 extern struct rte_mempool *pool;
138 extern uint32_t port_in_id[N_PORTS];
139 extern uint32_t port_out_id[N_PORTS];
140 extern uint32_t port_out_id_type[3];
141 extern uint32_t table_id[N_PORTS*2];
142 extern uint64_t override_hit_mask;
143 extern uint64_t override_miss_mask;
144 extern uint64_t non_reserved_actions_hit;
145 extern uint64_t non_reserved_actions_miss;
146 extern uint8_t connect_miss_action_to_port_out;
147 extern uint8_t connect_miss_action_to_table;
148 extern uint32_t table_entry_default_action;
149 extern uint32_t table_entry_hit_action;
150 extern uint32_t table_entry_miss_action;
151 extern rte_pipeline_port_in_action_handler port_in_action;
152 extern rte_pipeline_port_out_action_handler port_out_action;
153 extern rte_pipeline_table_action_handler_hit action_handler_hit;
154 extern rte_pipeline_table_action_handler_miss action_handler_miss;
155
156 /* Global data types */
157 struct manage_ops {
158         uint32_t op_id;
159         void *op_data;
160         int expected_result;
161 };
162
163 /* Internal pipeline structures */
164 struct rte_port_in {
165         struct rte_port_in_ops ops;
166         uint32_t burst_size;
167         uint32_t table_id;
168         void *h_port;
169 };
170
171 struct rte_port_out {
172         struct rte_port_out_ops ops;
173         void *h_port;
174 };
175
176 struct rte_table {
177         struct rte_table_ops ops;
178         rte_pipeline_table_action_handler_hit f_action;
179         uint32_t table_next_id;
180         uint32_t table_next_id_valid;
181         uint8_t actions_lookup_miss[RTE_CACHE_LINE_SIZE];
182         uint32_t action_data_size;
183         void *h_table;
184 };
185
186 #define RTE_PIPELINE_MAX_NAME_SZ                           124
187
188 struct rte_pipeline {
189         char name[RTE_PIPELINE_MAX_NAME_SZ];
190         uint32_t socket_id;
191         struct rte_port_in ports_in[16];
192         struct rte_port_out ports_out[16];
193         struct rte_table tables[64];
194         uint32_t num_ports_in;
195         uint32_t num_ports_out;
196         uint32_t num_tables;
197         struct rte_mbuf *pkts[RTE_PORT_IN_BURST_SIZE_MAX];
198         struct rte_table_entry *actions[RTE_PORT_IN_BURST_SIZE_MAX];
199         uint64_t mask_action[64];
200         uint32_t mask_actions;
201 };
202 #endif