2 * Copyright (c) 2016 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef MAIN_DPDK_LEGACY_H_
17 #define MAIN_DPDK_LEGACY_H_
19 #include "dpdk_version.h"
22 * UDP IPv4 destination lookup callback.
25 lpm4_dst_lookup(void *data, const struct in_addr *addr,
29 #ifdef DPDK_VERSION_GE_1604
34 struct netbe_lcore *lc;
39 rc = rte_lpm_lookup(lc->lpm4, rte_be_to_cpu_32(addr->s_addr), &idx);
42 rte_memcpy(res, dst, dst->l2_len + dst->l3_len +
43 offsetof(struct tle_dest, hdr));
49 lcore_lpm_init(struct netbe_lcore *lc)
52 char str[RTE_LPM_NAMESIZE];
53 #ifdef DPDK_VERSION_GE_1604
54 const struct rte_lpm_config lpm4_cfg = {
55 .max_rules = MAX_RULES,
56 .number_tbl8s = MAX_TBL8,
59 const struct rte_lpm6_config lpm6_cfg = {
60 .max_rules = MAX_RULES,
61 .number_tbl8s = MAX_TBL8,
64 sid = rte_lcore_to_socket_id(lc->id);
66 snprintf(str, sizeof(str), "LPM4%u\n", lc->id);
67 #ifdef DPDK_VERSION_GE_1604
68 lc->lpm4 = rte_lpm_create(str, sid, &lpm4_cfg);
70 lc->lpm4 = rte_lpm_create(str, sid, MAX_RULES, 0);
72 RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm4=%p;\n",
73 __func__, lc->id, lc->lpm4);
77 snprintf(str, sizeof(str), "LPM6%u\n", lc->id);
78 lc->lpm6 = rte_lpm6_create(str, sid, &lpm6_cfg);
79 RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm6=%p;\n",
80 __func__, lc->id, lc->lpm6);
88 * Helper functions, finds BE by given local and remote addresses.
91 netbe_find4(const struct in_addr *laddr, const uint16_t lport,
92 const struct in_addr *raddr, const uint32_t belc)
95 #ifdef DPDK_VERSION_GE_1604
100 struct netbe_lcore *bc;
102 /* we have exactly one BE, use it for all traffic */
103 if (becfg.cpu_num == 1)
106 /* search by provided be_lcore */
107 if (belc != LCORE_ID_ANY) {
108 for (i = 0; i != becfg.cpu_num; i++) {
113 RTE_LOG(NOTICE, USER1, "%s: no stream with be_lcore=%u\n",
118 /* search by local address */
119 if (laddr->s_addr != INADDR_ANY) {
120 for (i = 0; i != becfg.cpu_num; i++) {
122 /* search by queue for the local port */
123 for (j = 0; j != bc->prtq_num; j++) {
124 if (laddr->s_addr == bc->prtq[j].port.ipv4) {
129 if (verify_queue_for_port(bc->prtq + j,
137 /* search by remote address */
138 if (raddr->s_addr != INADDR_ANY) {
139 for (i = 0; i != becfg.cpu_num; i++) {
141 if (rte_lpm_lookup(bc->lpm4,
142 rte_be_to_cpu_32(raddr->s_addr),
148 /* search by queue for the local port */
149 for (j = 0; j != bc->prtq_num; j++)
150 if (verify_queue_for_port(bc->prtq + j,
160 #endif /* MAIN_DPDK_LEGACY_H_ */