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