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.
38 #include <rte_malloc.h>
40 #include <rte_ethdev.h>
41 #include <rte_ether.h>
43 #include <rte_byteorder.h>
45 #include <rte_port_ring.h>
46 #include <rte_table_hash.h>
47 #include <rte_pipeline.h>
51 struct app_core_fc_message_handle_params {
52 struct rte_ring *ring_req;
53 struct rte_ring *ring_resp;
55 struct rte_pipeline *p;
56 uint32_t *port_out_id;
61 app_message_handle(struct app_core_fc_message_handle_params *params);
63 static int app_flow_classification_table_init(
64 struct rte_pipeline *p,
65 uint32_t *port_out_id,
68 struct app_flow_key flow_key;
71 /* Add entries to tables */
72 for (i = 0; i < (1 << 24); i++) {
73 struct rte_pipeline_table_entry entry = {
74 .action = RTE_PIPELINE_ACTION_PORT,
75 {.port_id = port_out_id[i & (app.n_ports - 1)]},
77 struct rte_pipeline_table_entry *entry_ptr;
78 int key_found, status;
81 flow_key.proto = 6; /* TCP */
82 flow_key.header_checksum = 0;
84 flow_key.ip_dst = rte_bswap32(i);
85 flow_key.port_src = 0;
86 flow_key.port_dst = 0;
88 status = rte_pipeline_table_entry_add(p, table_id,
89 (void *) &flow_key, &entry, &key_found, &entry_ptr);
91 rte_panic("Unable to add entry to table %u (%d)\n",
99 app_main_loop_pipeline_flow_classification(void) {
100 struct rte_pipeline_params pipeline_params = {
102 .socket_id = rte_socket_id(),
105 struct rte_pipeline *p;
106 uint32_t port_in_id[APP_MAX_PORTS];
107 uint32_t port_out_id[APP_MAX_PORTS];
111 uint32_t core_id = rte_lcore_id();
112 struct app_core_params *core_params = app_get_core_params(core_id);
113 struct app_core_fc_message_handle_params mh_params;
115 if ((core_params == NULL) || (core_params->core_type != APP_CORE_FC))
116 rte_panic("Core %u misconfiguration\n", core_id);
118 RTE_LOG(INFO, USER1, "Core %u is doing flow classification "
119 "(pipeline with hash table, 16-byte key, LRU)\n", core_id);
121 /* Pipeline configuration */
122 p = rte_pipeline_create(&pipeline_params);
124 rte_panic("Unable to configure the pipeline\n");
126 /* Input port configuration */
127 for (i = 0; i < app.n_ports; i++) {
128 struct rte_port_ring_reader_params port_ring_params = {
129 .ring = app.rings[core_params->swq_in[i]],
132 struct rte_pipeline_port_in_params port_params = {
133 .ops = &rte_port_ring_reader_ops,
134 .arg_create = (void *) &port_ring_params,
137 .burst_size = app.bsz_swq_rd,
140 if (rte_pipeline_port_in_create(p, &port_params,
142 rte_panic("Unable to configure input port for "
146 /* Output port configuration */
147 for (i = 0; i < app.n_ports; i++) {
148 struct rte_port_ring_writer_params port_ring_params = {
149 .ring = app.rings[core_params->swq_out[i]],
150 .tx_burst_sz = app.bsz_swq_wr,
153 struct rte_pipeline_port_out_params port_params = {
154 .ops = &rte_port_ring_writer_ops,
155 .arg_create = (void *) &port_ring_params,
157 .f_action_bulk = NULL,
161 if (rte_pipeline_port_out_create(p, &port_params,
163 rte_panic("Unable to configure output port for "
167 /* Table configuration */
169 struct rte_table_hash_key16_lru_params table_hash_params = {
170 .n_entries = 1 << 24,
171 .signature_offset = __builtin_offsetof(
172 struct app_pkt_metadata, signature),
173 .key_offset = __builtin_offsetof(
174 struct app_pkt_metadata, flow_key),
179 struct rte_pipeline_table_params table_params = {
180 .ops = &rte_table_hash_key16_lru_ops,
181 .arg_create = &table_hash_params,
182 .f_action_hit = NULL,
183 .f_action_miss = NULL,
185 .action_data_size = 0,
188 if (rte_pipeline_table_create(p, &table_params, &table_id))
189 rte_panic("Unable to configure the hash table\n");
192 /* Interconnecting ports and tables */
193 for (i = 0; i < app.n_ports; i++)
194 if (rte_pipeline_port_in_connect_to_table(p, port_in_id[i],
196 rte_panic("Unable to connect input port %u to "
197 "table %u\n", port_in_id[i], table_id);
199 /* Enable input ports */
200 for (i = 0; i < app.n_ports; i++)
201 if (rte_pipeline_port_in_enable(p, port_in_id[i]))
202 rte_panic("Unable to enable input port %u\n",
205 /* Check pipeline consistency */
206 if (rte_pipeline_check(p) < 0)
207 rte_panic("Pipeline consistency check failed\n");
209 /* Message handling */
210 mh_params.ring_req = app_get_ring_req(
211 app_get_first_core_id(APP_CORE_FC));
212 mh_params.ring_resp = app_get_ring_resp(
213 app_get_first_core_id(APP_CORE_FC));
215 mh_params.port_out_id = port_out_id;
216 mh_params.table_id = table_id;
222 if ((i & APP_FLUSH) == 0) {
223 rte_pipeline_flush(p);
224 app_message_handle(&mh_params);
230 app_message_handle(struct app_core_fc_message_handle_params *params)
232 struct rte_ring *ring_req = params->ring_req;
233 struct rte_ring *ring_resp;
235 struct app_msg_req *req;
236 struct app_msg_resp *resp;
237 struct rte_pipeline *p;
238 uint32_t *port_out_id;
242 /* Read request message */
243 result = rte_ring_sc_dequeue(ring_req, &msg);
247 ring_resp = params->ring_resp;
249 port_out_id = params->port_out_id;
250 table_id = params->table_id;
253 req = (struct app_msg_req *)rte_ctrlmbuf_data((struct rte_mbuf *)msg);
255 case APP_MSG_REQ_PING:
261 case APP_MSG_REQ_FC_ADD_ALL:
263 result = app_flow_classification_table_init(p, port_out_id,
268 case APP_MSG_REQ_FC_ADD:
270 struct rte_pipeline_table_entry entry = {
271 .action = RTE_PIPELINE_ACTION_PORT,
272 {.port_id = port_out_id[req->flow_classif_add.port]},
275 struct rte_pipeline_table_entry *entry_ptr;
279 result = rte_pipeline_table_entry_add(p, table_id,
280 req->flow_classif_add.key_raw, &entry, &key_found,
285 case APP_MSG_REQ_FC_DEL:
289 result = rte_pipeline_table_entry_delete(p, table_id,
290 req->flow_classif_add.key_raw, &key_found, NULL);
295 rte_panic("FC Unrecognized message type (%u)\n", req->type);
298 /* Fill in response message */
299 resp = (struct app_msg_resp *)rte_ctrlmbuf_data((struct rte_mbuf *)msg);
300 resp->result = result;
304 result = rte_ring_sp_enqueue(ring_resp, msg);
305 } while (result == -ENOBUFS);