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 (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
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 MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
77 #define MP_CACHE_SZ 256
82 #define RING_ENQUEUE(ring, value) do { \
84 uint32_t *k32, *signature; \
87 m = rte_pktmbuf_alloc(pool); \
90 signature = RTE_MBUF_METADATA_UINT32_PTR(m, 0); \
91 key = RTE_MBUF_METADATA_UINT8_PTR(m, 32); \
92 k32 = (uint32_t *) key; \
94 *signature = pipeline_test_hash(key, 0, 0); \
95 rte_ring_enqueue((ring), m); \
98 #define RUN_PIPELINE(pipeline) do { \
99 rte_pipeline_run((pipeline)); \
100 rte_pipeline_flush((pipeline)); \
103 #define VERIFY(var, value) do { \
104 if ((var) != -(value)) \
108 #define VERIFY_TRAFFIC(ring, sent, expected) do { \
112 for (i = 0; i < (sent); i++) { \
113 if (!rte_ring_dequeue((ring), &mbuf)) { \
117 rte_pktmbuf_free((struct rte_mbuf *)mbuf); \
122 printf("Expected %d, got %d\n", expected, n); \
123 if (n != (expected)) { \
128 /* Function definitions */
129 uint64_t pipeline_test_hash(
131 __attribute__((unused)) uint32_t key_size,
132 __attribute__((unused)) uint64_t seed);
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;
157 /* Global data types */
164 /* Internal pipeline structures */
166 struct rte_port_in_ops ops;
172 struct rte_port_out {
173 struct rte_port_out_ops ops;
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;
187 #define RTE_PIPELINE_MAX_NAME_SZ 124
189 struct rte_pipeline {
190 char name[RTE_PIPELINE_MAX_NAME_SZ];
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;
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;