4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
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>
42 #include <rte_table_acl.h>
45 #include <rte_port_ring.h>
46 #include <rte_port_ethdev.h>
47 #include <rte_port_source_sink.h>
52 #define RING_SIZE 4096
56 #define TEST_RING_FULL_EMTPY_ITER 8
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 RTE_MBUF_DEFAULT_BUF_SIZE
69 #define POOL_SIZE (32 * 1024)
70 #define POOL_CACHE_SIZE 256
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
81 #define APP_METADATA_OFFSET(offset) (sizeof(struct rte_mbuf) + (offset))
83 #define RING_ENQUEUE(ring, value) do { \
85 uint32_t *k32, *signature; \
88 m = rte_pktmbuf_alloc(pool); \
91 signature = RTE_MBUF_METADATA_UINT32_PTR(m, \
92 APP_METADATA_OFFSET(0)); \
93 key = RTE_MBUF_METADATA_UINT8_PTR(m, \
94 APP_METADATA_OFFSET(32)); \
95 k32 = (uint32_t *) key; \
97 *signature = pipeline_test_hash(key, 0, 0); \
98 rte_ring_enqueue((ring), m); \
101 #define RUN_PIPELINE(pipeline) do { \
102 rte_pipeline_run((pipeline)); \
103 rte_pipeline_flush((pipeline)); \
106 #define VERIFY(var, value) do { \
107 if ((var) != -(value)) \
111 #define VERIFY_TRAFFIC(ring, sent, expected) do { \
115 for (i = 0; i < (sent); i++) { \
116 if (!rte_ring_dequeue((ring), &mbuf)) { \
120 rte_pktmbuf_free((struct rte_mbuf *)mbuf); \
125 printf("Expected %d, got %d\n", expected, n); \
126 if (n != (expected)) { \
131 /* Function definitions */
132 uint64_t pipeline_test_hash(
134 __attribute__((unused)) uint32_t key_size,
135 __attribute__((unused)) uint64_t seed);
137 /* Extern variables */
138 extern struct rte_pipeline *p;
139 extern struct rte_ring *rings_rx[N_PORTS];
140 extern struct rte_ring *rings_tx[N_PORTS];
141 extern struct rte_mempool *pool;
142 extern uint32_t port_in_id[N_PORTS];
143 extern uint32_t port_out_id[N_PORTS];
144 extern uint32_t port_out_id_type[3];
145 extern uint32_t table_id[N_PORTS*2];
146 extern uint64_t override_hit_mask;
147 extern uint64_t override_miss_mask;
148 extern uint64_t non_reserved_actions_hit;
149 extern uint64_t non_reserved_actions_miss;
150 extern uint8_t connect_miss_action_to_port_out;
151 extern uint8_t connect_miss_action_to_table;
152 extern uint32_t table_entry_default_action;
153 extern uint32_t table_entry_hit_action;
154 extern uint32_t table_entry_miss_action;
155 extern rte_pipeline_port_in_action_handler port_in_action;
156 extern rte_pipeline_port_out_action_handler port_out_action;
157 extern rte_pipeline_table_action_handler_hit action_handler_hit;
158 extern rte_pipeline_table_action_handler_miss action_handler_miss;
160 /* Global data types */
167 /* Internal pipeline structures */
169 struct rte_port_in_ops ops;
175 struct rte_port_out {
176 struct rte_port_out_ops ops;
181 struct rte_table_ops ops;
182 rte_pipeline_table_action_handler_hit f_action;
183 uint32_t table_next_id;
184 uint32_t table_next_id_valid;
185 uint8_t actions_lookup_miss[RTE_CACHE_LINE_SIZE];
186 uint32_t action_data_size;
190 #define RTE_PIPELINE_MAX_NAME_SZ 124
192 struct rte_pipeline {
193 char name[RTE_PIPELINE_MAX_NAME_SZ];
195 struct rte_port_in ports_in[16];
196 struct rte_port_out ports_out[16];
197 struct rte_table tables[64];
198 uint32_t num_ports_in;
199 uint32_t num_ports_out;
201 struct rte_mbuf *pkts[RTE_PORT_IN_BURST_SIZE_MAX];
202 struct rte_table_entry *actions[RTE_PORT_IN_BURST_SIZE_MAX];
203 uint64_t mask_action[64];
204 uint32_t mask_actions;