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.
39 #include <rte_ethdev.h>
40 #include <rte_ether.h>
42 #include <rte_byteorder.h>
44 #include <rte_port_ring.h>
45 #include <rte_table_lpm_ipv6.h>
46 #include <rte_pipeline.h>
51 app_main_loop_worker_pipeline_lpm_ipv6(void) {
52 struct rte_pipeline_params pipeline_params = {
54 .socket_id = rte_socket_id(),
57 struct rte_pipeline *p;
58 uint32_t port_in_id[APP_MAX_PORTS];
59 uint32_t port_out_id[APP_MAX_PORTS];
64 "Core %u is doing work (pipeline with IPv6 LPM table)\n",
67 /* Pipeline configuration */
68 p = rte_pipeline_create(&pipeline_params);
70 rte_panic("Unable to configure the pipeline\n");
72 /* Input port configuration */
73 for (i = 0; i < app.n_ports; i++) {
74 struct rte_port_ring_reader_params port_ring_params = {
75 .ring = app.rings_rx[i],
78 struct rte_pipeline_port_in_params port_params = {
79 .ops = &rte_port_ring_reader_ops,
80 .arg_create = (void *) &port_ring_params,
83 .burst_size = app.burst_size_worker_read,
86 if (rte_pipeline_port_in_create(p, &port_params,
88 rte_panic("Unable to configure input port for "
92 /* Output port configuration */
93 for (i = 0; i < app.n_ports; i++) {
94 struct rte_port_ring_writer_params port_ring_params = {
95 .ring = app.rings_tx[i],
96 .tx_burst_sz = app.burst_size_worker_write,
99 struct rte_pipeline_port_out_params port_params = {
100 .ops = &rte_port_ring_writer_ops,
101 .arg_create = (void *) &port_ring_params,
103 .f_action_bulk = NULL,
107 if (rte_pipeline_port_out_create(p, &port_params,
109 rte_panic("Unable to configure output port for "
113 /* Table configuration */
115 struct rte_table_lpm_ipv6_params table_lpm_ipv6_params = {
117 .number_tbl8s = 1 << 21,
119 sizeof(struct rte_pipeline_table_entry),
123 struct rte_pipeline_table_params table_params = {
124 .ops = &rte_table_lpm_ipv6_ops,
125 .arg_create = &table_lpm_ipv6_params,
126 .f_action_hit = NULL,
127 .f_action_miss = NULL,
129 .action_data_size = 0,
132 if (rte_pipeline_table_create(p, &table_params, &table_id))
133 rte_panic("Unable to configure the IPv6 LPM table\n");
136 /* Interconnecting ports and tables */
137 for (i = 0; i < app.n_ports; i++)
138 if (rte_pipeline_port_in_connect_to_table(p, port_in_id[i],
140 rte_panic("Unable to connect input port %u to "
141 "table %u\n", port_in_id[i], table_id);
143 /* Add entries to tables */
144 for (i = 0; i < app.n_ports; i++) {
145 struct rte_pipeline_table_entry entry = {
146 .action = RTE_PIPELINE_ACTION_PORT,
147 {.port_id = port_out_id[i & (app.n_ports - 1)]},
150 struct rte_table_lpm_ipv6_key key;
151 struct rte_pipeline_table_entry *entry_ptr;
153 int key_found, status;
155 key.depth = 8 + __builtin_popcount(app.n_ports - 1);
157 ip = rte_bswap32(i << (24 -
158 __builtin_popcount(app.n_ports - 1)));
159 memcpy(key.ip, &ip, sizeof(uint32_t));
161 printf("Adding rule to IPv6 LPM table (IPv6 destination = "
162 "%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:"
163 "%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x/%u => "
165 key.ip[0], key.ip[1], key.ip[2], key.ip[3],
166 key.ip[4], key.ip[5], key.ip[6], key.ip[7],
167 key.ip[8], key.ip[9], key.ip[10], key.ip[11],
168 key.ip[12], key.ip[13], key.ip[14], key.ip[15],
171 status = rte_pipeline_table_entry_add(p, table_id, &key, &entry,
172 &key_found, &entry_ptr);
174 rte_panic("Unable to add entry to table %u (%d)\n",
178 /* Enable input ports */
179 for (i = 0; i < app.n_ports; i++)
180 if (rte_pipeline_port_in_enable(p, port_in_id[i]))
181 rte_panic("Unable to enable input port %u\n",
184 /* Check pipeline consistency */
185 if (rte_pipeline_check(p) < 0)
186 rte_panic("Pipeline consistency check failed\n");
196 if ((i & APP_FLUSH) == 0)
197 rte_pipeline_flush(p);