@@ -23,6 +23,7 @@ ethdev_rx map port <STRING>dev queue <UINT32>qid core <UINT32>core_id # Port-Que
help ethdev_rx # Print help on ethdev_rx commands
ipv4_lookup route add ipv4 <IPv4>ip netmask <IPv4>mask via <IPv4>via_ip # Add IPv4 route to LPM table
+ipv4_lookup mode <STRING>lkup_mode # Set IPv4 lookup mode
help ipv4_lookup # Print help on ipv4_lookup commands
ipv6_lookup route add ipv6 <IPv6>ip netmask <IPv6>mask via <IPv6>via_ip # Add IPv6 route to LPM6 table
@@ -18,8 +18,13 @@
static const char
cmd_ipv4_lookup_help[] = "ipv4_lookup route add ipv4 <ip> netmask <mask> via <ip>";
+static const char
+cmd_ipv4_lookup_mode_help[] = "ipv4_lookup mode <lpm|fib>";
+
struct ip4_route route4 = TAILQ_HEAD_INITIALIZER(route4);
+enum ip4_lookup_mode ip4_lookup_m = IP4_LOOKUP_LPM;
+
void
route_ip4_list_clean(void)
{
@@ -62,6 +67,7 @@ route4_rewirte_table_update(struct route_ipv4_config *ipv4route)
{
uint8_t depth;
int portid;
+ int rc;
portid = ethdev_portid_by_ip4(ipv4route->via, ipv4route->netmask);
if (portid < 0) {
@@ -71,8 +77,14 @@ route4_rewirte_table_update(struct route_ipv4_config *ipv4route)
depth = convert_netmask_to_depth(ipv4route->netmask);
- return rte_node_ip4_route_add(ipv4route->ip, depth, portid,
- RTE_NODE_IP4_LOOKUP_NEXT_REWRITE);
+ if (ip4_lookup_m == IP4_LOOKUP_FIB)
+ rc = rte_node_ip4_fib_route_add(ipv4route->ip, depth, portid,
+ RTE_NODE_IP4_LOOKUP_NEXT_REWRITE);
+ else
+ rc = rte_node_ip4_route_add(ipv4route->ip, depth, portid,
+ RTE_NODE_IP4_LOOKUP_NEXT_REWRITE);
+
+ return rc;
}
static int
@@ -134,9 +146,9 @@ cmd_help_ipv4_lookup_parsed(__rte_unused void *parsed_result, __rte_unused struc
len = strlen(conn->msg_out);
conn->msg_out += len;
- snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n",
+ snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n%s\n",
"--------------------------- ipv4_lookup command help ---------------------------",
- cmd_ipv4_lookup_help);
+ cmd_ipv4_lookup_help, cmd_ipv4_lookup_mode_help);
len = strlen(conn->msg_out);
conn->msg_out_len_max -= len;
@@ -158,3 +170,17 @@ cmd_ipv4_lookup_route_add_ipv4_parsed(void *parsed_result, __rte_unused struct c
if (rc < 0)
printf(MSG_CMD_FAIL, res->ipv4_lookup);
}
+
+void
+cmd_ipv4_lookup_mode_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
+ void *data __rte_unused)
+{
+ struct cmd_ipv4_lookup_mode_result *res = parsed_result;
+
+ if (!strcmp(res->lkup_mode, "lpm"))
+ ip4_lookup_m = IP4_LOOKUP_LPM;
+ else if (!strcmp(res->lkup_mode, "fib"))
+ ip4_lookup_m = IP4_LOOKUP_FIB;
+ else
+ printf(MSG_CMD_FAIL, res->ipv4_lookup);
+}
@@ -15,9 +15,28 @@
#include <rte_graph_worker.h>
#include <rte_lcore.h>
#include <rte_node_eth_api.h>
+#include <rte_node_ip4_api.h>
+#include <rte_node_pkt_cls_api.h>
#include "module_api.h"
+static int
+setup_fib(int socket)
+{
+ struct rte_fib_conf conf;
+
+#define FIB_MAX_ROUTES (UINT16_MAX)
+#define FIB_NUM_TBL8 (UINT16_MAX / 2)
+ conf.type = RTE_FIB_DIR24_8;
+ conf.max_routes = FIB_MAX_ROUTES;
+ conf.rib_ext_sz = 0;
+ conf.dir24_8.nh_sz = RTE_FIB_DIR24_8_4B;
+ conf.dir24_8.num_tbl8 = FIB_NUM_TBL8;
+ conf.flags = 0;
+
+ return rte_node_ip4_fib_create(socket, &conf);
+}
+
static int
l3fwd_pattern_configure(void)
{
@@ -53,6 +72,16 @@ l3fwd_pattern_configure(void)
graph_conf.num_pkt_to_capture = pcap_pkts_count;
graph_conf.pcap_filename = strdup(pcap_file);
+ if (ip4_lookup_m == IP4_LOOKUP_FIB) {
+ const char *fib_n = "ip4_lookup_fib";
+ const char *lpm_n = "ip4_lookup";
+ rte_node_t pkt_cls;
+
+ pkt_cls = rte_node_from_name("pkt_cls");
+ rte_node_edge_update(pkt_cls, RTE_NODE_PKT_CLS_NEXT_IP4_LOOKUP, &fib_n, 1);
+ rte_node_edge_update(pkt_cls, RTE_NODE_PKT_CLS_NEXT_IP4_LOOKUP_FIB, &lpm_n, 1);
+ }
+
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
rte_graph_t graph_id;
rte_edge_t i;
@@ -78,6 +107,13 @@ l3fwd_pattern_configure(void)
snprintf(qconf->name, sizeof(qconf->name), "worker_%u",
lcore_id);
+ if (ip4_lookup_m == IP4_LOOKUP_FIB) {
+ rc = setup_fib(graph_conf.socket_id);
+ if (rc < 0)
+ rte_exit(EXIT_FAILURE, "Unable to setup fib for socket %u\n",
+ graph_conf.socket_id);
+ }
+
graph_id = rte_graph_create(qconf->name, &graph_conf);
if (graph_id == RTE_GRAPH_ID_INVALID)
rte_exit(EXIT_FAILURE,
@@ -27,6 +27,13 @@
extern volatile bool force_quit;
extern struct conn *conn;
+enum ip4_lookup_mode {
+ IP4_LOOKUP_LPM,
+ IP4_LOOKUP_FIB
+};
+
+extern enum ip4_lookup_mode ip4_lookup_m;
+
bool app_graph_stats_enabled(void);
bool app_graph_exit(void);
@@ -235,10 +235,14 @@ file to express the requested use case configuration.
| | | message. | | |
+--------------------------------------+-----------------------------------+-------------------+----------+
| | ipv4_lookup route add ipv4 <ip> | | Command to add a route into | :ref:`3 <scopes>` | Yes |
- | | netmask <mask> via <ip> | | ``ipv4_lookup`` LPM table. It is| | |
- | | | needed if user wishes to route | | |
- | | | the packets based on LPM lookup | | |
- | | | table. | | |
+ | | netmask <mask> via <ip> | | ``ipv4_lookup`` LPM table or | | |
+ | | | FIB. It is needed if user wishes| | |
+ | | | to route the packets based on | | |
+ | | | LPM lookup table or FIB. | | |
+ +--------------------------------------+-----------------------------------+-------------------+----------+
+ | | ipv4_lookup mode <lpm|fib> | | Command to set ipv4 lookup mode | :ref:`1 <scopes>` | Yes |
+ | | | to either LPM or FIB. By default| | |
+ | | | the lookup mode is LPM. | | |
+--------------------------------------+-----------------------------------+-------------------+----------+
| help ipv4_lookup | | Command to dump ``ipv4_lookup`` | :ref:`2 <scopes>` | Yes |
| | | help message. | | |