64e9427e338c546f5b120026f9433e594cdebe22
[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 + sizeof(struct rte_mbuf) + 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 MBUF_SIZE        (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
77 #define MP_CACHE_SZ         256
78 #define MP_SOCKET           0
79 #define MP_FLAGS            0
80
81 /* Macros */
82 #define RING_ENQUEUE(ring, value) do {                                  \
83         struct rte_mbuf *m;                                             \
84         uint32_t *k32, *signature;                                      \
85         uint8_t *key;                                                   \
86                                                                         \
87         m = rte_pktmbuf_alloc(pool);                                    \
88         if (m == NULL)                                                  \
89                 return -1;                                              \
90         signature = RTE_MBUF_METADATA_UINT32_PTR(m, 0);                 \
91         key = RTE_MBUF_METADATA_UINT8_PTR(m, 32);                       \
92         k32 = (uint32_t *) key;                                         \
93         k32[0] = (value);                                               \
94         *signature = pipeline_test_hash(key, 0, 0);                     \
95         rte_ring_enqueue((ring), m);                                    \
96 } while (0)
97
98 #define RUN_PIPELINE(pipeline) do {                                     \
99         rte_pipeline_run((pipeline));                                   \
100         rte_pipeline_flush((pipeline));                                 \
101 } while (0)
102
103 #define VERIFY(var, value) do {                                         \
104         if ((var) != -(value))                                          \
105                 return var;                                             \
106 } while (0)
107
108 #define VERIFY_TRAFFIC(ring, sent, expected) do {                       \
109         unsigned i, n = 0;                                              \
110         void *mbuf = NULL;                                              \
111                                                                         \
112         for (i = 0; i < (sent); i++) {                                  \
113                 if (!rte_ring_dequeue((ring), &mbuf)) {                 \
114                         if (mbuf == NULL)                               \
115                                 continue;                               \
116                         n++;                                            \
117                         rte_pktmbuf_free((struct rte_mbuf *)mbuf);      \
118                 }                                                       \
119                 else                                                    \
120                         break;                                          \
121         }                                                               \
122         printf("Expected %d, got %d\n", expected, n);                   \
123         if (n != (expected)) {                                          \
124                 return -21;                                             \
125         }                                                               \
126 } while (0)
127
128 /* Function definitions */
129 uint64_t pipeline_test_hash(
130         void *key,
131         __attribute__((unused)) uint32_t key_size,
132         __attribute__((unused)) uint64_t seed);
133
134 /* Extern variables */
135 extern struct rte_pipeline *p;
136 extern struct rte_ring *rings_rx[N_PORTS];
137 extern struct rte_ring *rings_tx[N_PORTS];
138 extern struct rte_mempool *pool;
139 extern uint32_t port_in_id[N_PORTS];
140 extern uint32_t port_out_id[N_PORTS];
141 extern uint32_t port_out_id_type[3];
142 extern uint32_t table_id[N_PORTS*2];
143 extern uint64_t override_hit_mask;
144 extern uint64_t override_miss_mask;
145 extern uint64_t non_reserved_actions_hit;
146 extern uint64_t non_reserved_actions_miss;
147 extern uint8_t connect_miss_action_to_port_out;
148 extern uint8_t connect_miss_action_to_table;
149 extern uint32_t table_entry_default_action;
150 extern uint32_t table_entry_hit_action;
151 extern uint32_t table_entry_miss_action;
152 extern rte_pipeline_port_in_action_handler port_in_action;
153 extern rte_pipeline_port_out_action_handler port_out_action;
154 extern rte_pipeline_table_action_handler_hit action_handler_hit;
155 extern rte_pipeline_table_action_handler_miss action_handler_miss;
156
157 /* Global data types */
158 struct manage_ops {
159         uint32_t op_id;
160         void *op_data;
161         int expected_result;
162 };
163
164 /* Internal pipeline structures */
165 struct rte_port_in {
166         struct rte_port_in_ops ops;
167         uint32_t burst_size;
168         uint32_t table_id;
169         void *h_port;
170 };
171
172 struct rte_port_out {
173         struct rte_port_out_ops ops;
174         void *h_port;
175 };
176
177 struct rte_table {
178         struct rte_table_ops ops;
179         rte_pipeline_table_action_handler_hit f_action;
180         uint32_t table_next_id;
181         uint32_t table_next_id_valid;
182         uint8_t actions_lookup_miss[RTE_CACHE_LINE_SIZE];
183         uint32_t action_data_size;
184         void *h_table;
185 };
186
187 #define RTE_PIPELINE_MAX_NAME_SZ                           124
188
189 struct rte_pipeline {
190         char name[RTE_PIPELINE_MAX_NAME_SZ];
191         uint32_t socket_id;
192         struct rte_port_in ports_in[16];
193         struct rte_port_out ports_out[16];
194         struct rte_table tables[64];
195         uint32_t num_ports_in;
196         uint32_t num_ports_out;
197         uint32_t num_tables;
198         struct rte_mbuf *pkts[RTE_PORT_IN_BURST_SIZE_MAX];
199         struct rte_table_entry *actions[RTE_PORT_IN_BURST_SIZE_MAX];
200         uint64_t mask_action[64];
201         uint32_t mask_actions;
202 };
203 #endif