From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 6C3319A8A for ; Fri, 29 May 2015 18:24:45 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 29 May 2015 09:24:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,517,1427785200"; d="scan'208";a="737448010" Received: from unknown (HELO stargo) ([10.217.248.233]) by orsmga002.jf.intel.com with SMTP; 29 May 2015 09:24:32 -0700 Received: by stargo (sSMTP sendmail emulation); Fri, 29 May 2015 18:20:51 +0200 From: Maciej Gajdzica To: dev@dpdk.org Date: Fri, 29 May 2015 17:43:17 +0200 Message-Id: <1432914198-11812-11-git-send-email-maciejx.t.gajdzica@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432914198-11812-1-git-send-email-maciejx.t.gajdzica@intel.com> References: <1432914198-11812-1-git-send-email-maciejx.t.gajdzica@intel.com> Subject: [dpdk-dev] [PATCH 10/11] ip_pipeline: added new implementation of routing pipeline X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 May 2015 16:24:47 -0000 Routing pipeline implementation is split to two files. pipeline_routing.c file handles front-end functions (cli commands parsing) pipeline_routing_ops.c contains implementation of functions done by pipeline (back-end). Signed-off-by: Pawel Wodkowski --- examples/ip_pipeline/Makefile | 3 +- examples/ip_pipeline/init.c | 2 + examples/ip_pipeline/pipeline/pipeline_routing.c | 1660 +++++++++++++++----- examples/ip_pipeline/pipeline/pipeline_routing.h | 99 ++ .../ip_pipeline/pipeline/pipeline_routing_ops.c | 978 ++++++++++++ .../ip_pipeline/pipeline/pipeline_routing_ops.h | 231 +++ 6 files changed, 2618 insertions(+), 355 deletions(-) create mode 100644 examples/ip_pipeline/pipeline/pipeline_routing.h create mode 100644 examples/ip_pipeline/pipeline/pipeline_routing_ops.c create mode 100644 examples/ip_pipeline/pipeline/pipeline_routing_ops.h diff --git a/examples/ip_pipeline/Makefile b/examples/ip_pipeline/Makefile index 0f8b1cc..f8c7c5f 100644 --- a/examples/ip_pipeline/Makefile +++ b/examples/ip_pipeline/Makefile @@ -63,8 +63,9 @@ SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_passthrough_ops.c SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_passthrough.c SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_firewall_ops.c SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_firewall.c +SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_routing_ops.c +SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_routing.c #SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_flow_classification.c -#SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += pipeline_routing.c CFLAGS += -I$(SRCDIR) -I$(SRCDIR)/pipeline CFLAGS += -O3 diff --git a/examples/ip_pipeline/init.c b/examples/ip_pipeline/init.c index 29d87ae..29caae8 100644 --- a/examples/ip_pipeline/init.c +++ b/examples/ip_pipeline/init.c @@ -46,6 +46,7 @@ #include "pipeline_master.h" #include "pipeline_passthrough.h" #include "pipeline_firewall.h" +#include "pipeline_routing.h" #define APP_NAME_SIZE 32 @@ -1148,6 +1149,7 @@ int app_init(struct app_params *app) app_pipeline_type_register(app, &pipeline_master); app_pipeline_type_register(app, &pipeline_passthrough); app_pipeline_type_register(app, &pipeline_firewall); + app_pipeline_type_register(app, &pipeline_routing); app_init_pipelines(app); app_init_threads(app); diff --git a/examples/ip_pipeline/pipeline/pipeline_routing.c b/examples/ip_pipeline/pipeline/pipeline_routing.c index b1ce624..d7dd495 100644 --- a/examples/ip_pipeline/pipeline/pipeline_routing.c +++ b/examples/ip_pipeline/pipeline/pipeline_routing.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,444 +31,1396 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include +#include "app.h" +#include "pipeline_routing_ops.h" +#include "pipeline_routing.h" -#include -#include -#include -#include +#include "pipeline_common.h" -#include "main.h" +#define MSG_TIMEOUT 1000 -#include +struct app_pipeline_routing_arp_entry { + struct pipeline_routing_arp_key key; + struct ether_addr nh_arp; + void *entry_ptr; -struct app_routing_table_entry { - struct rte_pipeline_table_entry head; - uint32_t nh_ip; - uint32_t nh_iface; + TAILQ_ENTRY(app_pipeline_routing_arp_entry) node; }; -struct app_arp_table_entry { - struct rte_pipeline_table_entry head; - struct ether_addr nh_arp; +struct app_pipeline_routing_entry { + struct pipeline_routing_route_key key; + struct app_pipeline_routing_route_params params; + void *entry_ptr; + + TAILQ_ENTRY(app_pipeline_routing_entry) node; +}; + +struct pipeline_routing { + /* parameters */ + uint32_t n_ports_in; + uint32_t n_ports_out; + + /* ARP entries */ + TAILQ_HEAD(, app_pipeline_routing_arp_entry) arp_entries; + uint32_t n_arp_entries; + + uint32_t default_arp_entry_present; + uint32_t default_arp_entry_port_id; + void *default_arp_entry_ptr; + + /* Routing routes */ + TAILQ_HEAD(, app_pipeline_routing_entry) routes; + uint32_t n_routes; + + uint32_t default_route_present; + uint32_t default_route_port_id; + void *default_route_entry_ptr; }; -static inline void -app_routing_table_write_metadata( - struct rte_mbuf *pkt, - struct app_routing_table_entry *entry) +static void * +pipeline_routing_init(struct pipeline_params *params, + __rte_unused void *arg) { - struct app_pkt_metadata *c = - (struct app_pkt_metadata *) RTE_MBUF_METADATA_UINT8_PTR(pkt, 0); + struct pipeline_routing *p; + uint32_t size; + + /* Check input arguments */ + if ((params == NULL) || + (params->n_ports_in == 0) || + (params->n_ports_out == 0)) + return NULL; + + /* Memory allocation */ + size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_routing)); + p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (p == NULL) + return NULL; + + /* Initialization */ + p->n_ports_in = params->n_ports_in; + p->n_ports_out = params->n_ports_out; + + TAILQ_INIT(&p->arp_entries); + p->n_arp_entries = 0; - c->arp_key.nh_ip = entry->nh_ip; - c->arp_key.nh_iface = entry->nh_iface; + TAILQ_INIT(&p->routes); + p->n_routes = 0; + + return p; } static int -app_routing_table_ah( - struct rte_mbuf **pkts, - uint64_t *pkts_mask, - struct rte_pipeline_table_entry **entries, - __attribute__((unused)) void *arg) +app_pipeline_routing_free(void *pipeline) { - uint64_t pkts_in_mask = *pkts_mask; + struct pipeline_routing *p = pipeline; + struct app_pipeline_routing_arp_entry *arp_entry; - if ((pkts_in_mask & (pkts_in_mask + 1)) == 0) { - uint64_t n_pkts = __builtin_popcountll(pkts_in_mask); - uint32_t i; + /* Check input arguments */ + if (p == NULL) + return -1; + + /* Free resources */ + while (!TAILQ_EMPTY(&p->arp_entries)) { + arp_entry = TAILQ_FIRST(&p->arp_entries); + TAILQ_REMOVE(&p->arp_entries, arp_entry, node); + rte_free(arp_entry); + } + + rte_free(p); + return 0; +} - for (i = 0; i < n_pkts; i++) { - struct rte_mbuf *m = pkts[i]; - struct app_routing_table_entry *a = - (struct app_routing_table_entry *) entries[i]; +static struct app_pipeline_routing_arp_entry * +app_pipeline_routing_find_arp_entry(struct pipeline_routing *p, + const struct pipeline_routing_arp_key *key) +{ + struct app_pipeline_routing_arp_entry *it, *found; - app_routing_table_write_metadata(m, a); + found = NULL; + TAILQ_FOREACH(it, &p->arp_entries, node) { + if (memcmp(key, &it->key, sizeof(it->key)) == 0) { + found = it; + break; } - } else - for ( ; pkts_in_mask; ) { - struct rte_mbuf *m; - struct app_routing_table_entry *a; - uint64_t pkt_mask; - uint32_t packet_index; - - packet_index = __builtin_ctzll(pkts_in_mask); - pkt_mask = 1LLU << packet_index; - pkts_in_mask &= ~pkt_mask; - - m = pkts[packet_index]; - a = (struct app_routing_table_entry *) - entries[packet_index]; - app_routing_table_write_metadata(m, a); + } + + return found; +} + +static struct app_pipeline_routing_entry * +app_pipeline_routing_find_route(struct pipeline_routing *p, + const struct pipeline_routing_route_key *key) +{ + struct app_pipeline_routing_entry *it, *found; + + found = NULL; + TAILQ_FOREACH(it, &p->routes, node) { + if (memcmp(key, &it->key, sizeof(it->key)) == 0) { + found = it; + break; } + } - return 0; + return found; } -static inline void -app_arp_table_write_metadata( - struct rte_mbuf *pkt, - struct app_arp_table_entry *entry) +static void +print_route(const struct app_pipeline_routing_entry *route) +{ + APP_CHECK(route->key.type == PIPELINE_ROUTING_ROUTE_IPV4, "Only IPv6"); + if (route->key.type == PIPELINE_ROUTING_ROUTE_IPV4) { + const struct pipeline_routing_route_key_ipv4 *key = + &route->key.key.ipv4; + + printf("IP Prefix = %u.%u.%u.%u/%u => " + "(Port = %u, Next Hop = %u.%u.%u.%u)\n", + (key->ip >> 24) & 0xFF, + (key->ip >> 16) & 0xFF, + (key->ip >> 8) & 0xFF, + key->ip & 0xFF, + + key->depth, + route->params.port_id, + + (route->params.ip >> 24) & 0xFF, + (route->params.ip >> 16) & 0xFF, + (route->params.ip >> 8) & 0xFF, + route->params.ip & 0xFF); + } + +} + +static void +print_arp_entry(const struct app_pipeline_routing_arp_entry *entry) { - struct app_pkt_metadata *c = - (struct app_pkt_metadata *) RTE_MBUF_METADATA_UINT8_PTR(pkt, 0); - ether_addr_copy(&entry->nh_arp, &c->nh_arp); + printf("(Port = %u, IP = %u.%u.%u.%u) => " + "HWaddress = %02x:%02x:%02x:%02x:%02x:%02x\n", + entry->key.key.ipv4.port_id, + (entry->key.key.ipv4.ip >> 24) & 0xFF, + (entry->key.key.ipv4.ip >> 16) & 0xFF, + (entry->key.key.ipv4.ip >> 8) & 0xFF, + entry->key.key.ipv4.ip & 0xFF, + + entry->nh_arp.addr_bytes[0], + entry->nh_arp.addr_bytes[1], + entry->nh_arp.addr_bytes[2], + entry->nh_arp.addr_bytes[3], + entry->nh_arp.addr_bytes[4], + entry->nh_arp.addr_bytes[5]); } static int -app_arp_table_ah( - struct rte_mbuf **pkts, - uint64_t *pkts_mask, - struct rte_pipeline_table_entry **entries, - __attribute__((unused)) void *arg) +app_pipeline_routing_arp_ls(struct app_params *app, uint32_t pipeline_id) { - uint64_t pkts_in_mask = *pkts_mask; + struct pipeline_routing *p; + struct app_pipeline_routing_arp_entry *it; - if ((pkts_in_mask & (pkts_in_mask + 1)) == 0) { - uint64_t n_pkts = __builtin_popcountll(pkts_in_mask); - uint32_t i; + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; - for (i = 0; i < n_pkts; i++) { - struct rte_mbuf *m = pkts[i]; - struct app_arp_table_entry *a = - (struct app_arp_table_entry *) entries[i]; + TAILQ_FOREACH(it, &p->arp_entries, node) + print_arp_entry(it); - app_arp_table_write_metadata(m, a); - } - } else { - for ( ; pkts_in_mask; ) { - struct rte_mbuf *m; - struct app_arp_table_entry *a; - uint64_t pkt_mask; - uint32_t packet_index; - - packet_index = __builtin_ctzll(pkts_in_mask); - pkt_mask = 1LLU << packet_index; - pkts_in_mask &= ~pkt_mask; - - m = pkts[packet_index]; - a = (struct app_arp_table_entry *) - entries[packet_index]; - app_arp_table_write_metadata(m, a); - } + if (p->default_arp_entry_present) + printf("Default entry: port %u (entry ptr = %p)\n", + p->default_arp_entry_port_id, + p->default_arp_entry_ptr); + else + printf("Default: DROP\n"); /* FIXME: msg OK ? */ + + return 0; +} + +int +app_pipeline_routing_add_arp_entry(struct app_params *app, uint32_t pipeline_id, + struct pipeline_routing_arp_key *key, + struct ether_addr *macaddr) +{ + struct pipeline_routing *p; + + struct pipeline_routing_arp_add_msg_req *req; + struct pipeline_routing_arp_add_msg_rsp *rsp; + + struct app_pipeline_routing_arp_entry *entry; + + int new_entry; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Find existing entry or allocate new */ + entry = app_pipeline_routing_find_arp_entry(p, key); + new_entry = (entry == NULL); + if (entry == NULL) { + entry = rte_malloc(NULL, sizeof(*entry), RTE_CACHE_LINE_SIZE); + + if (entry == NULL) + return -1; + } + + /* Message buffer allocation */ + req = app_msg_alloc(app); + if (req == NULL) { + if (new_entry) + rte_free(entry); + return -1; } + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ARP_ADD; + memcpy(&req->key, key, sizeof(*key)); + ether_addr_copy(macaddr, &req->macaddr); + + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) { + if (new_entry) + rte_free(entry); + return -1; + } + + /* Read response and write entry */ + if (rsp->status || rsp->entry_ptr == NULL) { + app_msg_free(app, rsp); + if (new_entry) + rte_free(entry); + return -1; + } + + memcpy(&entry->key, key, sizeof(*key)); + ether_addr_copy(macaddr, &entry->nh_arp); + entry->entry_ptr = rsp->entry_ptr; + + /* Commit entry */ + if (new_entry) { + TAILQ_INSERT_TAIL(&p->arp_entries, entry, node); + p->n_arp_entries++; + } + + print_arp_entry(entry); + + /* Message buffer free */ + app_msg_free(app, rsp); return 0; } -static uint64_t app_arp_table_hash( - void *key, - __attribute__((unused)) uint32_t key_size, - __attribute__((unused)) uint64_t seed) +int +app_pipeline_routing_delete_arp_entry(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_arp_key *key) { - uint32_t *k = (uint32_t *) key; + struct pipeline_routing *p; + + struct pipeline_routing_arp_delete_msg_req *req; + struct pipeline_routing_arp_delete_msg_rsp *rsp; + + struct app_pipeline_routing_arp_entry *entry; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Find rule */ + entry = app_pipeline_routing_find_arp_entry(p, key); + if (entry == NULL) + return 0; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ARP_DEL; + memcpy(&req->key, key, sizeof(*key)); + + + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; - return k[1]; + /* Read response */ + if (rsp->status) { + app_msg_free(app, rsp); + return -1; + } + + /* Remove entry */ + TAILQ_REMOVE(&p->arp_entries, entry, node); + p->n_arp_entries--; + rte_free(entry); + + /* Free response */ + app_msg_free(app, rsp); + + return 0; } -struct app_core_routing_message_handle_params { - struct rte_ring *ring_req; - struct rte_ring *ring_resp; - struct rte_pipeline *p; - uint32_t *port_out_id; - uint32_t routing_table_id; - uint32_t arp_table_id; -}; +int +app_pipeline_routing_add_default_arp_entry(struct app_params *app, + uint32_t pipeline_id, + uint32_t port_id) +{ + struct pipeline_routing *p; -static void -app_message_handle(struct app_core_routing_message_handle_params *params); + struct pipeline_routing_arp_add_default_msg_req *req; + struct pipeline_routing_arp_add_default_msg_rsp *rsp; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT; + req->port_id = port_id; + + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + /* Read response and write entry */ + if (rsp->status || rsp->entry_ptr == NULL) { + app_msg_free(app, rsp); + return -1; + } + + p->default_arp_entry_port_id = port_id; + p->default_arp_entry_ptr = rsp->entry_ptr; + + /* Commit entry */ + p->default_arp_entry_present = 1; + + /* Free response */ + app_msg_free(app, rsp); + + return 0; +} + +int +app_pipeline_routing_delete_default_arp_entry(struct app_params *app, + uint32_t pipeline_id) +{ + struct pipeline_routing *p; + + struct pipeline_routing_arp_delete_default_msg_req *req; + struct pipeline_routing_arp_delete_default_msg_rsp *rsp; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -ENOMEM; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT; + + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -ETIMEDOUT; + + /* Read response and write entry */ + if (rsp->status) { + app_msg_free(app, rsp); + return -rsp->status; + } + + /* Commit entry */ + p->default_arp_entry_present = 0; + + /* Free response */ + app_msg_free(app, rsp); + + return 0; +} + +static int +app_pipeline_routing_ls(struct app_params *app, uint32_t pipeline_id) +{ + struct pipeline_routing *p; + struct app_pipeline_routing_entry *it; -void -app_main_loop_pipeline_routing(void) { - struct rte_pipeline_params pipeline_params = { - .name = "pipeline", - .socket_id = rte_socket_id(), - }; + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; - struct rte_pipeline *p; - uint32_t port_in_id[APP_MAX_PORTS]; - uint32_t port_out_id[APP_MAX_PORTS]; - uint32_t routing_table_id, arp_table_id; - uint32_t i; + TAILQ_FOREACH(it, &p->routes, node) + print_route(it); - uint32_t core_id = rte_lcore_id(); - struct app_core_params *core_params = app_get_core_params(core_id); - struct app_core_routing_message_handle_params mh_params; + if (p->default_route_present) + printf("Default route: port %u (entry ptr = %p)\n", + p->default_route_port_id, + p->default_route_entry_ptr); + else + printf("Default: DROP\n"); /* FIXME: msg OK ? */ - if ((core_params == NULL) || (core_params->core_type != APP_CORE_RT)) - rte_panic("Core %u misconfiguration\n", core_id); + return 0; +} + +int +app_pipeline_routing_add_route(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_route_key *key, + struct app_pipeline_routing_route_params *route_params) +{ + struct pipeline_routing *p; - RTE_LOG(INFO, USER1, "Core %u is doing routing\n", core_id); + struct pipeline_routing_route_add_msg_req *req; + struct pipeline_routing_route_add_msg_rsp *rsp; - /* Pipeline configuration */ - p = rte_pipeline_create(&pipeline_params); + struct app_pipeline_routing_entry *entry; + + int new_entry; + + p = app_pipeline_data_fe(app, pipeline_id); + /* Check input arguments */ if (p == NULL) - rte_panic("Unable to configure the pipeline\n"); - - /* Input port configuration */ - for (i = 0; i < app.n_ports; i++) { - struct rte_port_ring_reader_params port_ring_params = { - .ring = app.rings[core_params->swq_in[i]], - }; - - struct rte_pipeline_port_in_params port_params = { - .ops = &rte_port_ring_reader_ops, - .arg_create = (void *) &port_ring_params, - .f_action = NULL, - .arg_ah = NULL, - .burst_size = app.bsz_swq_rd, - }; - - if (rte_pipeline_port_in_create(p, &port_params, - &port_in_id[i])) - rte_panic("Unable to configure input port for " - "ring %d\n", i); + return -EINVAL; + + /* Find existing rule or allocate new rule */ + entry = app_pipeline_routing_find_route(p, key); + new_entry = (entry == NULL); + if (entry == NULL) { + entry = rte_malloc(NULL, sizeof(*entry), RTE_CACHE_LINE_SIZE); + + if (entry == NULL) + return -1; } - /* Output port configuration */ - for (i = 0; i < app.n_ports; i++) { - struct rte_port_ring_writer_params port_ring_params = { - .ring = app.rings[core_params->swq_out[i]], - .tx_burst_sz = app.bsz_swq_wr, - }; - - struct rte_pipeline_port_out_params port_params = { - .ops = &rte_port_ring_writer_ops, - .arg_create = (void *) &port_ring_params, - .f_action = NULL, - .f_action_bulk = NULL, - .arg_ah = NULL, - }; - - if (rte_pipeline_port_out_create(p, &port_params, - &port_out_id[i])) - rte_panic("Unable to configure output port for " - "ring %d\n", i); + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) { + if (new_entry) + rte_free(entry); + return -1; } - /* Routing table configuration */ - { - struct rte_table_lpm_params table_lpm_params = { - .n_rules = app.max_routing_rules, - .entry_unique_size = - sizeof(struct app_routing_table_entry), - .offset = __builtin_offsetof(struct app_pkt_metadata, - flow_key.ip_dst), - }; - - struct rte_pipeline_table_params table_params = { - .ops = &rte_table_lpm_ops, - .arg_create = &table_lpm_params, - .f_action_hit = app_routing_table_ah, - .f_action_miss = NULL, - .arg_ah = NULL, - .action_data_size = - sizeof(struct app_routing_table_entry) - - sizeof(struct rte_pipeline_table_entry), - }; - - if (rte_pipeline_table_create(p, &table_params, - &routing_table_id)) - rte_panic("Unable to configure the LPM table\n"); + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD; + memcpy(&req->key, key, sizeof(*key)); + req->flags = route_params->flags; + req->port_id = route_params->port_id; + req->ip = route_params->ip; + + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) { + if (new_entry) + rte_free(entry); + return -1; } - /* ARP table configuration */ - { - struct rte_table_hash_key8_lru_params table_arp_params = { - .n_entries = app.max_arp_rules, - .f_hash = app_arp_table_hash, - .seed = 0, - .signature_offset = 0, /* Unused */ - .key_offset = __builtin_offsetof( - struct app_pkt_metadata, arp_key), - }; - - struct rte_pipeline_table_params table_params = { - .ops = &rte_table_hash_key8_lru_dosig_ops, - .arg_create = &table_arp_params, - .f_action_hit = app_arp_table_ah, - .f_action_miss = NULL, - .arg_ah = NULL, - .action_data_size = sizeof(struct app_arp_table_entry) - - sizeof(struct rte_pipeline_table_entry), - }; - - if (rte_pipeline_table_create(p, &table_params, &arp_table_id)) - rte_panic("Unable to configure the ARP table\n"); + /* Read response and write entry */ + if (rsp->status || (rsp->entry_ptr == NULL)) { + app_msg_free(app, rsp); + if (new_entry) + rte_free(entry); + return -1; + } + + memcpy(&entry->key, key, sizeof(*key)); + memcpy(&entry->params, route_params, sizeof(*route_params)); + entry->entry_ptr = rsp->entry_ptr; + + /* Commit entry */ + if (new_entry) { + TAILQ_INSERT_TAIL(&p->routes, entry, node); + p->n_arp_entries++; + } + + print_route(entry); + + /* Message buffer free */ + app_msg_free(app, rsp); + return 0; +} + +int +app_pipeline_routing_delete_route(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_route_key *key) +{ + struct pipeline_routing *p; + + struct pipeline_routing_route_delete_msg_req *req; + struct pipeline_routing_route_delete_msg_rsp *rsp; + + struct app_pipeline_routing_entry *entry; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Find rule */ + entry = app_pipeline_routing_find_route(p, key); + if (entry == NULL) + return 0; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL; + memcpy(&req->key, key, sizeof(*key)); + + + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + /* Read response */ + if (rsp->status) { + app_msg_free(app, rsp); + return -1; + } + + /* Remove route */ + TAILQ_REMOVE(&p->routes, entry, node); + p->n_routes--; + + rte_free(entry); + + /* Free response */ + app_msg_free(app, rsp); + + return 0; +} + +int +app_pipeline_routing_add_default_route(struct app_params *app, + uint32_t pipeline_id, + uint32_t port_id) +{ + struct pipeline_routing *p; + + struct pipeline_routing_route_add_default_msg_req *req; + struct pipeline_routing_route_add_default_msg_rsp *rsp; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD_DEFAULT; + req->port_id = port_id; + + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + /* Read response and write route */ + if (rsp->status || (rsp->entry_ptr == NULL)) { + app_msg_free(app, rsp); + return -1; } - /* Interconnecting ports and tables */ - for (i = 0; i < app.n_ports; i++) { - if (rte_pipeline_port_in_connect_to_table(p, port_in_id[i], - routing_table_id)) - rte_panic("Unable to connect input port %u to " - "table %u\n", port_in_id[i], routing_table_id); + p->default_route_port_id = port_id; + p->default_route_entry_ptr = rsp->entry_ptr; + + /* Commit route */ + p->default_route_present = 1; + + /* Free response */ + app_msg_free(app, rsp); + + return 0; +} + +int +app_pipeline_routing_delete_default_route(struct app_params *app, + uint32_t pipeline_id) +{ + struct pipeline_routing *p; + + struct pipeline_routing_arp_delete_default_msg_req *req; + struct pipeline_routing_arp_delete_default_msg_rsp *rsp; + + p = app_pipeline_data_fe(app, pipeline_id); + if (p == NULL) + return -EINVAL; + + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL_DEFAULT; + + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT); + if (rsp == NULL) + return -1; + + /* Read response and write route */ + if (rsp->status) { + app_msg_free(app, rsp); + return -1; } - /* Enable input ports */ - for (i = 0; i < app.n_ports; i++) - if (rte_pipeline_port_in_enable(p, port_in_id[i])) - rte_panic("Unable to enable input port %u\n", - port_in_id[i]); - - /* Check pipeline consistency */ - if (rte_pipeline_check(p) < 0) - rte_panic("Pipeline consistency check failed\n"); - - /* Message handling */ - mh_params.ring_req = - app_get_ring_req(app_get_first_core_id(APP_CORE_RT)); - mh_params.ring_resp = - app_get_ring_resp(app_get_first_core_id(APP_CORE_RT)); - mh_params.p = p; - mh_params.port_out_id = port_out_id; - mh_params.routing_table_id = routing_table_id; - mh_params.arp_table_id = arp_table_id; - - /* Run-time */ - for (i = 0; ; i++) { - rte_pipeline_run(p); - - if ((i & APP_FLUSH) == 0) { - rte_pipeline_flush(p); - app_message_handle(&mh_params); + /* Commit route */ + p->default_route_present = 0; + + /* Free response */ + app_msg_free(app, rsp); + + return 0; +} + +/* CLI */ + +/* *** Routing - Add *** */ +struct cmd_route_add_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t route_string; + cmdline_fixed_string_t add_string; + cmdline_ipaddr_t ip; + uint8_t depth; + uint8_t port; + cmdline_ipaddr_t nh_ip; +}; + +static void +cmd_route_add_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_route_add_result *params = parsed_result; + struct app_params *app = data; + struct pipeline_routing_route_key key; + struct app_pipeline_routing_route_params rt_params; + uint32_t netmask; + + int status; + + APP_CHECK(params->ip.family == AF_INET, + "BUG: only IPv4 is supported for now.\n"); + if ((params->depth == 0) || (params->depth > 32)) { + printf("Illegal value for depth parameter (%u)\n", + params->depth); + return; } + + netmask = (~0) << (32 - params->depth); + + /* Create route */ + if (params->ip.family == AF_INET) { + key.type = PIPELINE_ROUTING_ROUTE_IPV4; + key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr) + & netmask; + key.key.ipv4.depth = params->depth; + } else + APP_CHECK(0, "IPv6 not implemented yet"); + + rt_params.flags = 0; /* FIXME: ? */ + rt_params.port_id = params->port; + rt_params.ip = rte_bswap32((uint32_t) params->nh_ip.addr.ipv4.s_addr); + status = app_pipeline_routing_add_route(app, params->p, &key, &rt_params); + + if (status != 0) { + printf("Command failed\n"); + return; } } -void -app_message_handle(struct app_core_routing_message_handle_params *params) +static cmdline_parse_token_string_t cmd_route_add_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_route_add_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_add_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_route_add_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_result, route_string, + "route"); + +static cmdline_parse_token_string_t cmd_route_add_add_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_result, add_string, + "add"); + +static cmdline_parse_token_ipaddr_t cmd_route_add_ip = + TOKEN_IPADDR_INITIALIZER(struct cmd_route_add_result, ip); + +static cmdline_parse_token_num_t cmd_route_add_depth = + TOKEN_NUM_INITIALIZER(struct cmd_route_add_result, depth, UINT8); + +static cmdline_parse_token_num_t cmd_route_add_port = + TOKEN_NUM_INITIALIZER(struct cmd_route_add_result, port, UINT8); + +static cmdline_parse_token_ipaddr_t cmd_route_add_nh_ip = + TOKEN_IPADDR_INITIALIZER(struct cmd_route_add_result, nh_ip); + +static cmdline_parse_inst_t cmd_route_add = { + .f = cmd_route_add_parsed, + .data = NULL, + .help_str = "Route add", + .tokens = { + (void *)&cmd_route_add_p_string, + (void *)&cmd_route_add_p, + (void *)&cmd_route_add_route_string, + (void *)&cmd_route_add_add_string, + (void *)&cmd_route_add_ip, + (void *)&cmd_route_add_depth, + (void *)&cmd_route_add_port, + (void *)&cmd_route_add_nh_ip, + NULL, + }, +}; + +/* *** Routing - Add Default *** */ +struct cmd_route_add_default_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t route_string; + cmdline_fixed_string_t add_string; + cmdline_fixed_string_t default_string; + uint8_t port; +}; + +static void +cmd_route_add_default_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + void *data) { - struct rte_ring *ring_req = params->ring_req; - struct rte_ring *ring_resp; - void *msg; - struct app_msg_req *req; - struct app_msg_resp *resp; - struct rte_pipeline *p; - uint32_t *port_out_id; - uint32_t routing_table_id, arp_table_id; - int result; - - /* Read request message */ - result = rte_ring_sc_dequeue(ring_req, &msg); - if (result != 0) + struct cmd_route_add_default_result *params = parsed_result; + struct app_params *app = data; + int status; + + status = app_pipeline_routing_add_default_route(app, params->p, + params->port); + + if (status != 0) { + printf("Command failed\n"); return; + } +} - ring_resp = params->ring_resp; - p = params->p; - port_out_id = params->port_out_id; - routing_table_id = params->routing_table_id; - arp_table_id = params->arp_table_id; - - /* Handle request */ - req = (struct app_msg_req *)rte_ctrlmbuf_data((struct rte_mbuf *)msg); - switch (req->type) { - case APP_MSG_REQ_PING: - { - result = 0; - break; +static cmdline_parse_token_string_t cmd_route_add_default_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_route_add_default_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_add_default_result, p, UINT32); + +cmdline_parse_token_string_t cmd_route_add_default_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, route_string, + "route"); + +cmdline_parse_token_string_t cmd_route_add_default_add_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, add_string, + "add"); + +cmdline_parse_token_string_t cmd_route_add_default_default_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, + default_string, "default"); + +cmdline_parse_token_num_t cmd_route_add_default_port = + TOKEN_NUM_INITIALIZER(struct cmd_route_add_default_result, port, UINT8); + +cmdline_parse_inst_t cmd_route_add_default = { + .f = cmd_route_add_default_parsed, + .data = NULL, + .help_str = "Set the default route", + .tokens = { + (void *)&cmd_route_add_default_p_string, + (void *)&cmd_route_add_default_p, + (void *)&cmd_route_add_default_route_string, + (void *)&cmd_route_add_default_add_string, + (void *)&cmd_route_add_default_default_string, + (void *)&cmd_route_add_default_port, + NULL, + }, +}; + +/* *** Routing - Del *** */ +struct cmd_route_del_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t route_string; + cmdline_fixed_string_t del_string; + cmdline_ipaddr_t ip; + uint8_t depth; +}; + +static void +cmd_route_del_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_route_del_result *params = parsed_result; + struct app_params *app = data; + struct pipeline_routing_route_key key; + uint32_t netmask; + + int status; + + APP_CHECK(params->ip.family == AF_INET, + "BUG: only IPv4 is supported for now.\n"); + if ((params->depth == 0) || (params->depth > 32)) { + printf("Illegal value for depth parameter (%u)\n", + params->depth); + return; } - case APP_MSG_REQ_RT_ADD: - { - struct app_routing_table_entry entry = { - .head = { - .action = RTE_PIPELINE_ACTION_TABLE, - {.table_id = arp_table_id}, - }, - .nh_ip = req->routing_add.nh_ip, - .nh_iface = port_out_id[req->routing_add.port], - }; - - struct rte_table_lpm_key key = { - .ip = req->routing_add.ip, - .depth = req->routing_add.depth, - }; - - struct rte_pipeline_table_entry *entry_ptr; - - int key_found; - - result = rte_pipeline_table_entry_add(p, routing_table_id, &key, - (struct rte_pipeline_table_entry *) &entry, &key_found, - &entry_ptr); - break; + netmask = (~0) << (32 - params->depth); + + /* Create route */ + if (params->ip.family == AF_INET) { + key.type = PIPELINE_ROUTING_ROUTE_IPV4; + key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr) + & netmask; + key.key.ipv4.depth = params->depth; + } else + APP_CHECK(0, "IPv6 not implemented yet"); + + status = app_pipeline_routing_delete_route(app, params->p, &key); + + if (status != 0) { + printf("Command failed\n"); + return; } +} - case APP_MSG_REQ_RT_DEL: - { - struct rte_table_lpm_key key = { - .ip = req->routing_del.ip, - .depth = req->routing_del.depth, - }; +static cmdline_parse_token_string_t cmd_route_del_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_route_del_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_del_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_route_del_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, route_string, + "route"); + +static cmdline_parse_token_string_t cmd_route_del_del_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, del_string, + "del"); + +static cmdline_parse_token_ipaddr_t cmd_route_del_ip = + TOKEN_IPADDR_INITIALIZER(struct cmd_route_del_result, ip); + +static cmdline_parse_token_num_t cmd_route_del_depth = + TOKEN_NUM_INITIALIZER(struct cmd_route_del_result, depth, UINT8); + +static cmdline_parse_inst_t cmd_route_del = { + .f = cmd_route_del_parsed, + .data = NULL, + .help_str = "Route delete", + .tokens = { + (void *)&cmd_route_del_p_string, + (void *)&cmd_route_del_p, + (void *)&cmd_route_del_route_string, + (void *)&cmd_route_del_del_string, + (void *)&cmd_route_del_ip, + (void *)&cmd_route_del_depth, + NULL, + }, +}; - int key_found; +/* *** Routing - Del default *** */ +struct cmd_route_del_default_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t route_string; + cmdline_fixed_string_t del_string; + cmdline_fixed_string_t default_string; + uint8_t out_iface; +}; + +static void +cmd_route_del_default_parsed( + __rte_unused void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_route_del_default_result *params = parsed_result; + struct app_params *app = data; + int status; - result = rte_pipeline_table_entry_delete(p, routing_table_id, - &key, &key_found, NULL); - break; + status = app_pipeline_routing_add_default_route(app, params->p, + params->out_iface); + + if (status != 0) { + printf("Command failed\n"); + return; } +} - case APP_MSG_REQ_ARP_ADD: - { +static cmdline_parse_token_string_t cmd_route_del_default_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_route_del_default_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_del_default_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_route_del_default_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, route_string, + "route"); + +static cmdline_parse_token_string_t cmd_route_del_default_del_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, del_string, + "del"); + +static cmdline_parse_token_string_t cmd_route_del_default_default_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, + default_string, "default"); + + +static cmdline_parse_inst_t cmd_route_del_default = { + .f = cmd_route_del_default_parsed, + .data = NULL, + .help_str = "Route delete", + .tokens = { + (void *)&cmd_route_del_default_p_string, + (void *)&cmd_route_del_default_p, + (void *)&cmd_route_del_default_route_string, + (void *)&cmd_route_del_default_del_string, + (void *)&cmd_route_del_default_default_string, + NULL, + }, +}; - struct app_arp_table_entry entry = { - .head = { - .action = RTE_PIPELINE_ACTION_PORT, - {.port_id = - port_out_id[req->arp_add.out_iface]}, - }, - .nh_arp = req->arp_add.nh_arp, - }; +/* *** Routing - List *** */ +struct cmd_route_ls_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t route_string; + cmdline_fixed_string_t ls_string; +}; - struct app_arp_key arp_key = { - .nh_ip = req->arp_add.nh_ip, - .nh_iface = port_out_id[req->arp_add.out_iface], - }; +static void +cmd_route_ls_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_route_ls_result *params = parsed_result; + struct app_params *app = data; + int status; - struct rte_pipeline_table_entry *entry_ptr; + status = app_pipeline_routing_ls(app, params->p); - int key_found; + if (status != 0) { + printf("Command failed\n"); + return; + } +} + +static cmdline_parse_token_string_t cmd_route_ls_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, p_string, "p"); + +static cmdline_parse_token_num_t cmd_route_ls_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_ls_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_route_ls_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, + route_string, "route"); + +static cmdline_parse_token_string_t cmd_route_ls_ls_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, ls_string, + "ls"); + +static cmdline_parse_inst_t cmd_route_ls = { + .f = cmd_route_ls_parsed, + .data = NULL, + .help_str = "Route list", + .tokens = { + (void *)&cmd_route_ls_p_string, + (void *)&cmd_route_ls_p, + (void *)&cmd_route_ls_route_string, + (void *)&cmd_route_ls_ls_string, + NULL, + }, +}; + +/* *** ARP - Add *** */ +struct cmd_arp_add_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t arp_string; + cmdline_fixed_string_t add_string; + uint8_t out_iface; + cmdline_ipaddr_t nh_ip; + struct ether_addr nh_arp; + +}; + +static void +cmd_arp_add_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_arp_add_result *params = parsed_result; + struct app_params *app = data; + + struct pipeline_routing_arp_key key; + int status; + + APP_CHECK(params->nh_ip.family == AF_INET, + "BUG: only IPv4 is supported for now.\n"); + + key.key.ipv4.port_id = params->out_iface; + key.key.ipv4.ip = rte_cpu_to_be_32(params->nh_ip.addr.ipv4.s_addr); - result = rte_pipeline_table_entry_add(p, arp_table_id, &arp_key, - (struct rte_pipeline_table_entry *) &entry, &key_found, - &entry_ptr); - break; + status = app_pipeline_routing_add_arp_entry(app, params->p, &key, + ¶ms->nh_arp); + + if (status != 0) { + printf("Command failed\n"); + return; } +} + +static cmdline_parse_token_string_t cmd_arp_add_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_arp_add_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_arp_add_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, arp_string, "arp"); + +static cmdline_parse_token_string_t cmd_arp_add_add_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, add_string, "add"); + +static cmdline_parse_token_num_t cmd_arp_add_out_iface = + TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, out_iface, UINT8); + +static cmdline_parse_token_ipaddr_t cmd_arp_add_nh_ip = + TOKEN_IPV4_INITIALIZER(struct cmd_arp_add_result, nh_ip); + +static cmdline_parse_token_etheraddr_t cmd_arp_add_nh_arp = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_arp_add_result, nh_arp); + +static cmdline_parse_inst_t cmd_arp_add = { + .f = cmd_arp_add_parsed, + .data = NULL, + .help_str = "ARP add", + .tokens = { + (void *)&cmd_arp_add_p_string, + (void *)&cmd_arp_add_p, + (void *)&cmd_arp_add_arp_string, + (void *)&cmd_arp_add_add_string, + (void *)&cmd_arp_add_out_iface, + (void *)&cmd_arp_add_nh_ip, + (void *)&cmd_arp_add_nh_arp, + NULL, + }, +}; + +/* *** ARP - Add default *** */ +struct cmd_arp_add_default_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t arp_string; + cmdline_fixed_string_t del_string; + cmdline_fixed_string_t default_string; + uint8_t out_iface; +}; + +static void +cmd_arp_add_default_parsed( + __rte_unused void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_arp_add_default_result *params = parsed_result; + struct app_params *app = data; + + int status; + + status = app_pipeline_routing_add_default_arp_entry(app, params->p, + params->out_iface); + + if (status != 0) { + printf("Command failed\n"); + return; + } +} + +static cmdline_parse_token_string_t cmd_arp_add_default_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_arp_add_default_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_add_default_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_arp_add_default_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, arp_string, + "arp"); + +static cmdline_parse_token_string_t cmd_arp_add_default_add_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, del_string, + "del"); + +static cmdline_parse_token_string_t cmd_arp_add_default_default_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, default_string, + "default"); + +static cmdline_parse_token_num_t cmd_arp_add_default_out_iface = + TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, out_iface, + UINT8); + +static cmdline_parse_inst_t cmd_arp_add_default = { + .f = cmd_arp_add_default_parsed, + .data = NULL, + .help_str = "ARP add default", + .tokens = { + (void *)&cmd_arp_add_default_p_string, + (void *)&cmd_arp_add_default_p, + (void *)&cmd_arp_add_default_arp_string, + (void *)&cmd_arp_add_default_add_string, + (void *)&cmd_arp_add_default_default_string, + (void *)&cmd_arp_add_default_out_iface, + NULL, + }, +}; + +/* *** ARP - Del *** */ +struct cmd_arp_del_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t arp_string; + cmdline_fixed_string_t del_string; + uint8_t out_iface; + cmdline_ipaddr_t nh_ip; +}; + +static void +cmd_arp_del_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_arp_del_result *params = parsed_result; + struct app_params *app = data; + + struct pipeline_routing_arp_key key; + int status; - case APP_MSG_REQ_ARP_DEL: - { - struct app_arp_key arp_key = { - .nh_ip = req->arp_del.nh_ip, - .nh_iface = port_out_id[req->arp_del.out_iface], - }; + APP_CHECK(params->nh_ip.family != AF_INET, + "BUG: only IPv4 is supported for now.\n"); - int key_found; + key.key.ipv4.ip = rte_cpu_to_be_32(params->nh_ip.addr.ipv4.s_addr); + key.key.ipv4.port_id = params->out_iface; - result = rte_pipeline_table_entry_delete(p, arp_table_id, - &arp_key, &key_found, NULL); - break; + status = app_pipeline_routing_delete_arp_entry(app, params->p, &key); + + if (status != 0) { + printf("Command failed\n"); + return; } +} + +static cmdline_parse_token_string_t cmd_arp_del_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_arp_del_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_arp_del_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, arp_string, "arp"); + +static cmdline_parse_token_string_t cmd_arp_del_del_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, del_string, "del"); + +static cmdline_parse_token_num_t cmd_arp_del_out_iface = + TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, out_iface, UINT8); + +static cmdline_parse_token_ipaddr_t cmd_arp_del_nh_ip = + TOKEN_IPV4_INITIALIZER(struct cmd_arp_del_result, nh_ip); + +static cmdline_parse_inst_t cmd_arp_del = { + .f = cmd_arp_del_parsed, + .data = NULL, + .help_str = "ARP delete", + .tokens = { + (void *)&cmd_arp_del_p_string, + (void *)&cmd_arp_del_p, + (void *)&cmd_arp_del_arp_string, + (void *)&cmd_arp_del_del_string, + (void *)&cmd_arp_del_out_iface, + (void *)&cmd_arp_del_nh_ip, + NULL, + }, +}; + +/* *** ARP - Del default *** */ +struct cmd_arp_del_default_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t arp_string; + cmdline_fixed_string_t del_string; + cmdline_fixed_string_t default_string; +}; + +static void +cmd_arp_del_default_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_arp_del_default_result *params = parsed_result; + struct app_params *app = data; + + int status; - default: - rte_panic("RT Unrecognized message type (%u)\n", req->type); + status = app_pipeline_routing_delete_default_arp_entry(app, params->p); + + if (status != 0) { + printf("Command failed\n"); + return; } +} - /* Fill in response message */ - resp = (struct app_msg_resp *)rte_ctrlmbuf_data((struct rte_mbuf *)msg); - resp->result = result; +static cmdline_parse_token_string_t cmd_arp_del_default_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_arp_del_default_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_del_default_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_arp_del_default_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, arp_string, + "arp"); + +static cmdline_parse_token_string_t cmd_arp_del_default_del_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, del_string, + "del"); + +static cmdline_parse_token_string_t cmd_arp_del_default_default_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, default_string, + "default"); + +static cmdline_parse_inst_t cmd_arp_del_default = { + .f = cmd_arp_del_default_parsed, + .data = NULL, + .help_str = "ARP delete default", + .tokens = { + (void *)&cmd_arp_del_default_p_string, + (void *)&cmd_arp_del_default_p, + (void *)&cmd_arp_del_default_arp_string, + (void *)&cmd_arp_del_default_del_string, + (void *)&cmd_arp_del_default_default_string, + NULL, + }, +}; - /* Send response */ - do { - result = rte_ring_sp_enqueue(ring_resp, msg); - } while (result == -ENOBUFS); +/* *** ARP - Print *** */ +struct cmd_arp_ls_result { + cmdline_fixed_string_t p_string; + uint32_t p; + cmdline_fixed_string_t arp_string; + cmdline_fixed_string_t ls_string; +}; + +static void +cmd_arp_ls_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_arp_ls_result *params = parsed_result; + struct app_params *app = data; + struct pipeline_routing *p; + + p = app_pipeline_data_fe(app, params->p); + if (p == NULL) + return; + + app_pipeline_routing_arp_ls(app, params->p); } + +static cmdline_parse_token_string_t cmd_arp_ls_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, p_string, + "p"); + +static cmdline_parse_token_num_t cmd_arp_ls_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, p, UINT32); + +static cmdline_parse_token_string_t cmd_arp_ls_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string, + "arp"); + +static cmdline_parse_token_string_t cmd_arp_ls_ls_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, ls_string, + "ls"); + +static cmdline_parse_inst_t cmd_arp_ls = { + .f = cmd_arp_ls_parsed, + .data = NULL, + .help_str = "ARP list", + .tokens = { + (void *)&cmd_arp_ls_p_string, + (void *)&cmd_arp_ls_p, + (void *)&cmd_arp_ls_arp_string, + (void *)&cmd_arp_ls_ls_string, + NULL, + }, +}; + + +static cmdline_parse_ctx_t pipeline_cmds[] = { + (cmdline_parse_inst_t *)&cmd_route_add, + (cmdline_parse_inst_t *)&cmd_route_del, + (cmdline_parse_inst_t *)&cmd_route_add_default, + (cmdline_parse_inst_t *)&cmd_route_del_default, + (cmdline_parse_inst_t *)&cmd_route_ls, + (cmdline_parse_inst_t *)&cmd_arp_add, + (cmdline_parse_inst_t *)&cmd_arp_del, + (cmdline_parse_inst_t *)&cmd_arp_add_default, + (cmdline_parse_inst_t *)&cmd_arp_del_default, + (cmdline_parse_inst_t *)&cmd_arp_ls, + NULL, +}; + +static struct pipeline_fe_ops pipeline_routing_fe_ops = { + .f_init = pipeline_routing_init, + .f_free = app_pipeline_routing_free, + .cmds = pipeline_cmds, +}; + +struct pipeline_type pipeline_routing = { + .name = "ROUTING", + .ops = &pipeline_routing_ops, + .fe_ops = &pipeline_routing_fe_ops, +}; diff --git a/examples/ip_pipeline/pipeline/pipeline_routing.h b/examples/ip_pipeline/pipeline/pipeline_routing.h new file mode 100644 index 0000000..c5892d8 --- /dev/null +++ b/examples/ip_pipeline/pipeline/pipeline_routing.h @@ -0,0 +1,99 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __INCLUDE_PIPELINE_ROUTING_H__ +#define __INCLUDE_PIPELINE_ROUTING_H__ + +#include "pipeline.h" +#include "pipeline_routing_ops.h" + +/* + * Route + */ + +struct app_pipeline_routing_route_params { + enum pipeline_routing_route_flags flags; + uint32_t port_id; /* Output port ID */ + uint32_t ip; /* IP address for the next hop (only for remote routes) */ +}; + +int +app_pipeline_routing_add_route(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_route_key *key, + struct app_pipeline_routing_route_params *route_params); + +int +app_pipeline_routing_delete_route(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_route_key *key); + +int +app_pipeline_routing_add_default_route(struct app_params *app, + uint32_t pipeline_id, + uint32_t port_id); + +int +app_pipeline_routing_delete_default_route(struct app_params *app, + uint32_t pipeline_id); + +/* + * ARP + */ + +int +app_pipeline_routing_add_arp_entry(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_arp_key *key, + struct ether_addr *macaddr); + +int +app_pipeline_routing_delete_arp_entry(struct app_params *app, + uint32_t pipeline_id, + struct pipeline_routing_arp_key *key); + +int +app_pipeline_routing_add_default_arp_entry(struct app_params *app, + uint32_t pipeline_id, + uint32_t port_id); + +int +app_pipeline_routing_delete_default_arp_entry(struct app_params *app, + uint32_t pipeline_id); + +/* + * Pipeline type + */ +extern struct pipeline_type pipeline_routing; + +#endif diff --git a/examples/ip_pipeline/pipeline/pipeline_routing_ops.c b/examples/ip_pipeline/pipeline/pipeline_routing_ops.c new file mode 100644 index 0000000..4a29502 --- /dev/null +++ b/examples/ip_pipeline/pipeline/pipeline_routing_ops.c @@ -0,0 +1,978 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pipeline_common_ops.h" +#include "pipeline_routing_ops.h" + +struct pipeline_routing { + struct pipeline p; + pipeline_msg_req_handler custom_handlers[PIPELINE_ROUTING_MSG_REQS]; + + uint32_t n_routes; + uint32_t n_arp_entries; + uint32_t n_arp_entries_ext; + uint32_t ip_da_offset; + uint32_t arp_key_offset; +} __rte_cache_aligned; + +static void * +pipeline_routing_msg_req_custom_handler(struct pipeline *p, void *msg); + +static pipeline_msg_req_handler handlers[] = { + [PIPELINE_MSG_REQ_PING] = pipeline_msg_req_ping_handler, + [PIPELINE_MSG_REQ_STATS_PORT_IN] = pipeline_msg_req_stats_port_in_handler, + [PIPELINE_MSG_REQ_STATS_PORT_OUT] = pipeline_msg_req_stats_port_out_handler, + [PIPELINE_MSG_REQ_STATS_TABLE] = pipeline_msg_req_stats_table_handler, + [PIPELINE_MSG_REQ_PORT_IN_ENABLE] = pipeline_msg_req_port_in_enable_handler, + [PIPELINE_MSG_REQ_PORT_IN_DISABLE] = pipeline_msg_req_port_in_disable_handler, + [PIPELINE_MSG_REQ_CUSTOM] = pipeline_routing_msg_req_custom_handler, +}; + +static void * +pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_route_del_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_route_add_default_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_route_del_default_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_arp_add_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_arp_del_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_arp_add_default_handler(struct pipeline *p, void *msg); + +static void * +pipeline_routing_msg_req_arp_del_default_handler(struct pipeline *p, void *msg); + +static pipeline_msg_req_handler custom_handlers[] = { + [PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD] = pipeline_routing_msg_req_route_add_handler, + [PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL] = pipeline_routing_msg_req_route_del_handler, + [PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD_DEFAULT] = pipeline_routing_msg_req_route_add_default_handler, + [PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL_DEFAULT] = pipeline_routing_msg_req_route_del_default_handler, + [PIPELINE_ROUTING_MSG_REQ_ARP_ADD] = pipeline_routing_msg_req_arp_add_handler, + [PIPELINE_ROUTING_MSG_REQ_ARP_DEL] = pipeline_routing_msg_req_arp_del_handler, + [PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT] = pipeline_routing_msg_req_arp_add_default_handler, + [PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT] = pipeline_routing_msg_req_arp_del_default_handler, +}; + +/* + * Routing table + */ +struct routing_table_entry { + struct rte_pipeline_table_entry head; + enum pipeline_routing_route_flags flags; + uint32_t port_id; /* Output port ID */ + uint32_t ip; /* IP address for the next hop (only valid for remote routes) */ +}; + +static inline void +pkt_work_routing( + struct pipeline_routing *p_rt, + struct rte_mbuf *pkt, + struct routing_table_entry *entry) +{ + struct pipeline_routing_arp_key_ipv4 *arp_key = + (struct pipeline_routing_arp_key_ipv4 *) RTE_MBUF_METADATA_UINT8_PTR(pkt, p_rt->arp_key_offset); + uint32_t ip = RTE_MBUF_METADATA_UINT32(pkt, p_rt->ip_da_offset); + + arp_key->port_id = entry->port_id; + arp_key->ip = entry->ip; + if (entry->flags & PIPELINE_ROUTING_ROUTE_LOCAL) + arp_key->ip = ip; +} + +static inline void +pkt4_work_routing( + struct pipeline_routing *p_rt, + struct rte_mbuf *pkt0, + struct rte_mbuf *pkt1, + struct rte_mbuf *pkt2, + struct rte_mbuf *pkt3, + struct routing_table_entry *entry0, + struct routing_table_entry *entry1, + struct routing_table_entry *entry2, + struct routing_table_entry *entry3) +{ + struct pipeline_routing_arp_key_ipv4 *arp_key0 = + (struct pipeline_routing_arp_key_ipv4 *) RTE_MBUF_METADATA_UINT8_PTR(pkt0, p_rt->arp_key_offset); + struct pipeline_routing_arp_key_ipv4 *arp_key1 = + (struct pipeline_routing_arp_key_ipv4 *) RTE_MBUF_METADATA_UINT8_PTR(pkt1, p_rt->arp_key_offset); + struct pipeline_routing_arp_key_ipv4 *arp_key2 = + (struct pipeline_routing_arp_key_ipv4 *) RTE_MBUF_METADATA_UINT8_PTR(pkt2, p_rt->arp_key_offset); + struct pipeline_routing_arp_key_ipv4 *arp_key3 = + (struct pipeline_routing_arp_key_ipv4 *) RTE_MBUF_METADATA_UINT8_PTR(pkt3, p_rt->arp_key_offset); + + uint32_t ip0 = RTE_MBUF_METADATA_UINT32(pkt0, p_rt->ip_da_offset); + uint32_t ip1 = RTE_MBUF_METADATA_UINT32(pkt1, p_rt->ip_da_offset); + uint32_t ip2 = RTE_MBUF_METADATA_UINT32(pkt2, p_rt->ip_da_offset); + uint32_t ip3 = RTE_MBUF_METADATA_UINT32(pkt3, p_rt->ip_da_offset); + + arp_key0->port_id = entry0->port_id; + arp_key1->port_id = entry1->port_id; + arp_key2->port_id = entry2->port_id; + arp_key3->port_id = entry3->port_id; + + arp_key0->ip = entry0->ip; + if (entry0->flags & PIPELINE_ROUTING_ROUTE_LOCAL) + arp_key0->ip = ip0; + arp_key1->ip = entry1->ip; + if (entry1->flags & PIPELINE_ROUTING_ROUTE_LOCAL) + arp_key1->ip = ip1; + arp_key2->ip = entry2->ip; + if (entry2->flags & PIPELINE_ROUTING_ROUTE_LOCAL) + arp_key2->ip = ip2; + arp_key3->ip = entry3->ip; + if (entry3->flags & PIPELINE_ROUTING_ROUTE_LOCAL) + arp_key3->ip = ip3; +} + +static int +routing_table_ah_hit( + struct rte_mbuf **pkts, + uint64_t *pkts_mask, + struct rte_pipeline_table_entry **entries, + void *arg) +{ + struct pipeline_routing *p_rt = arg; + uint64_t pkts_in_mask = *pkts_mask; + + if ((pkts_in_mask & (pkts_in_mask + 1)) == 0) { + uint64_t n_pkts = __builtin_popcountll(pkts_in_mask); + uint32_t i; + + for (i = 0; i < (n_pkts & 0x3); i += 4) { + struct rte_mbuf *pkt0 = pkts[i]; + struct rte_mbuf *pkt1 = pkts[i + 1]; + struct rte_mbuf *pkt2 = pkts[i + 2]; + struct rte_mbuf *pkt3 = pkts[i + 3]; + + struct routing_table_entry *e0 = + (struct routing_table_entry *) entries[i]; + struct routing_table_entry *e1 = + (struct routing_table_entry *) entries[i + 1]; + struct routing_table_entry *e2 = + (struct routing_table_entry *) entries[i + 2]; + struct routing_table_entry *e3 = + (struct routing_table_entry *) entries[i + 3]; + + pkt4_work_routing(p_rt, pkt0, pkt1, pkt2, pkt3, e0, e1, e2, e3); + } + + for ( ; i < n_pkts; i++) { + struct rte_mbuf *pkt = pkts[i]; + struct routing_table_entry *e = + (struct routing_table_entry *) entries[i]; + + pkt_work_routing(p_rt, pkt, e); + } + } else + for ( ; pkts_in_mask; ) { + struct rte_mbuf *pkt; + struct routing_table_entry *e; + uint64_t pkt_mask; + uint32_t packet_index; + + packet_index = __builtin_ctzll(pkts_in_mask); + pkt_mask = 1LLU << packet_index; + pkts_in_mask &= ~pkt_mask; + + pkt = pkts[packet_index]; + e = (struct routing_table_entry *) + entries[packet_index]; + pkt_work_routing(p_rt, pkt, e); + } + + return 0; +} + +/* + * ARP table + */ +struct arp_table_entry { + struct rte_pipeline_table_entry head; + uint64_t macaddr; +}; + +static uint64_t arp_table_hash( + void *key, + __rte_unused uint32_t key_size, + __rte_unused uint64_t seed) +{ + uint32_t *k = (uint32_t *) key; + + return k[1]; +} + +static inline void +pkt_work_arp( + __rte_unused struct pipeline_routing *p_rt, + struct rte_mbuf *pkt, + struct arp_table_entry *entry) +{ + /* Read: pkt buffer - mbuf */ + uint8_t *raw = rte_pktmbuf_mtod(pkt, uint8_t *); + + /* Read: table entry */ + uint64_t mac_addr_dst = entry->macaddr; + uint64_t mac_addr_src = 0; + + /* Compute: Ethernet header */ + uint64_t slab0 = mac_addr_dst | (mac_addr_src << 48); + uint32_t slab1 = mac_addr_src >> 16; + + /* Write: pkt buffer - pkt headers */ + *((uint64_t *) raw) = slab0; + *((uint32_t *) (raw + 8)) = slab1; +} + +static inline void +pkt4_work_arp( + __rte_unused struct pipeline_routing *p_rt, + struct rte_mbuf *pkt0, + struct rte_mbuf *pkt1, + struct rte_mbuf *pkt2, + struct rte_mbuf *pkt3, + struct arp_table_entry *entry0, + struct arp_table_entry *entry1, + struct arp_table_entry *entry2, + struct arp_table_entry *entry3) +{ + /* Read: pkt buffer - mbuf */ + uint8_t *raw0 = rte_pktmbuf_mtod(pkt0, uint8_t *); + uint8_t *raw1 = rte_pktmbuf_mtod(pkt1, uint8_t *); + uint8_t *raw2 = rte_pktmbuf_mtod(pkt2, uint8_t *); + uint8_t *raw3 = rte_pktmbuf_mtod(pkt3, uint8_t *); + + /* Read: table entry */ + uint64_t mac_addr_dst0 = entry0->macaddr; + uint64_t mac_addr_dst1 = entry1->macaddr; + uint64_t mac_addr_dst2 = entry2->macaddr; + uint64_t mac_addr_dst3 = entry3->macaddr; + + uint64_t mac_addr_src0 = 0; + uint64_t mac_addr_src1 = 0; + uint64_t mac_addr_src2 = 0; + uint64_t mac_addr_src3 = 0; + + /* Compute: Ethernet header */ + uint64_t pkt0_slab0 = mac_addr_dst0 | (mac_addr_src0 << 48); + uint64_t pkt1_slab0 = mac_addr_dst1 | (mac_addr_src1 << 48); + uint64_t pkt2_slab0 = mac_addr_dst2 | (mac_addr_src2 << 48); + uint64_t pkt3_slab0 = mac_addr_dst3 | (mac_addr_src3 << 48); + + uint32_t pkt0_slab1 = mac_addr_src0 >> 16; + uint32_t pkt1_slab1 = mac_addr_src1 >> 16; + uint32_t pkt2_slab1 = mac_addr_src2 >> 16; + uint32_t pkt3_slab1 = mac_addr_src3 >> 16; + + /* Write: pkt buffer - pkt headers */ + *((uint64_t *) raw0) = pkt0_slab0; + *((uint32_t *) (raw0 + 8)) = pkt0_slab1; + *((uint64_t *) raw1) = pkt1_slab0; + *((uint32_t *) (raw1 + 8)) = pkt1_slab1; + *((uint64_t *) raw2) = pkt2_slab0; + *((uint32_t *) (raw2 + 8)) = pkt2_slab1; + *((uint64_t *) raw3) = pkt3_slab0; + *((uint32_t *) (raw3 + 8)) = pkt3_slab1; +} + +static int +arp_table_ah_hit( + struct rte_mbuf **pkts, + uint64_t *pkts_mask, + struct rte_pipeline_table_entry **entries, + __rte_unused void *arg) +{ + struct pipeline_routing *p_rt = arg; + uint64_t pkts_in_mask = *pkts_mask; + + if ((pkts_in_mask & (pkts_in_mask + 1)) == 0) { + uint64_t n_pkts = __builtin_popcountll(pkts_in_mask); + uint32_t i; + + for (i = 0; i < (n_pkts & 0x3); i += 4) { + struct rte_mbuf *pkt0 = pkts[i]; + struct rte_mbuf *pkt1 = pkts[i + 1]; + struct rte_mbuf *pkt2 = pkts[i + 2]; + struct rte_mbuf *pkt3 = pkts[i + 3]; + + struct arp_table_entry *e0 = + (struct arp_table_entry *) entries[i]; + struct arp_table_entry *e1 = + (struct arp_table_entry *) entries[i + 1]; + struct arp_table_entry *e2 = + (struct arp_table_entry *) entries[i + 2]; + struct arp_table_entry *e3 = + (struct arp_table_entry *) entries[i + 3]; + + pkt4_work_arp(p_rt, pkt0, pkt1, pkt2, pkt3, e0, e1, e2, e3); + } + + for ( ; i < n_pkts; i++) { + struct rte_mbuf *pkt = pkts[i]; + struct arp_table_entry *e = + (struct arp_table_entry *) entries[i]; + + pkt_work_arp(p_rt, pkt, e); + } + } else + for ( ; pkts_in_mask; ) { + struct rte_mbuf *pkt; + struct arp_table_entry *e; + uint64_t pkt_mask; + uint32_t packet_index; + + packet_index = __builtin_ctzll(pkts_in_mask); + pkt_mask = 1LLU << packet_index; + pkts_in_mask &= ~pkt_mask; + + pkt = pkts[packet_index]; + e = (struct arp_table_entry *) + entries[packet_index]; + pkt_work_arp(p_rt, pkt, e); + } + + return 0; +} + +static int +pipeline_routing_parse_args(struct pipeline_routing *p, + struct pipeline_params *params) +{ + uint32_t n_routes_present = 0; + uint32_t n_arp_entries_present = 0; + uint32_t n_arp_entries_ext_present = 0; + uint32_t ip_da_offset_present = 0; + uint32_t arp_key_offset_present = 0; + uint32_t i; + + for (i = 0; i < params->n_args; i++) { + char *arg_name = params->args_name[i]; + char *arg_value = params->args_value[i]; + + /* n_routes */ + if (strcmp(arg_name, "n_routes") == 0) { + if (n_routes_present) + return -1; + n_routes_present = 1; + + p->n_routes = atoi(arg_value); + if (p->n_routes == 0) + return -1; + + continue; + } + + /* n_arp_entries */ + if (strcmp(arg_name, "n_arp_entries") == 0) { + if (n_arp_entries_present) + return -1; + n_arp_entries_present = 1; + + p->n_arp_entries = atoi(arg_value); + if (p->n_arp_entries == 0) + return -1; + + continue; + } + + /* n_arp_entries_ext */ + if (strcmp(arg_name, "n_arp_entries_ext") == 0) { + if (n_arp_entries_ext_present) + return -1; + n_arp_entries_ext_present = 1; + + p->n_arp_entries_ext = atoi(arg_value); + if (p->n_arp_entries_ext == 0) + return -1; + + continue; + } + + /* ip_da_offset */ + if (strcmp(arg_name, "ip_da_offset") == 0) { + if (ip_da_offset_present) + return -1; + ip_da_offset_present = 1; + + p->ip_da_offset = atoi(arg_value); + + continue; + } + + /* arp_key_offset */ + if (strcmp(arg_name, "arp_key_offset") == 0) { + if (arp_key_offset_present) + return -1; + arp_key_offset_present = 1; + + p->arp_key_offset = atoi(arg_value); + + continue; + } + + /* any other */ + return -1; + } + + /* Check that mandatory arguments are present */ + if ((n_routes_present == 0) || + (n_arp_entries_present == 0) || + (n_arp_entries_ext_present == 0) || + (ip_da_offset_present == 0) || + (n_arp_entries_present && (arp_key_offset_present == 0))) + return -1; + + return 0; +} + +static void * +pipeline_routing_init(struct pipeline_params *params, + __rte_unused void *arg) +{ + struct pipeline *p; + struct pipeline_routing *p_rt; + uint32_t size, i; + + /* Check input arguments */ + if ((params == NULL) || + (params->n_ports_in == 0) || + (params->n_ports_out == 0)) + return NULL; + + /* Memory allocation */ + size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_routing)); + p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); + p_rt = (struct pipeline_routing *) p; + if (p == NULL) + return NULL; + + strcpy(p->name, params->name); + + /* Parse arguments */ + if (pipeline_routing_parse_args(p_rt, params)) + return NULL; + + /* Pipeline */ + { + struct rte_pipeline_params pipeline_params = { + .name = params->name, + .socket_id = params->socket_id, + .offset_port_id = 0, + }; + + p->p = rte_pipeline_create(&pipeline_params); + if (p->p == NULL) { + rte_free(p); + return NULL; + } + } + + /* Input ports */ + p->n_ports_in = params->n_ports_in; + for (i = 0; i < p->n_ports_in; i++) { + struct rte_pipeline_port_in_params port_params = { + .ops = pipeline_port_in_params_get_ops(¶ms->port_in[i]), + .arg_create = pipeline_port_in_params_convert(¶ms->port_in[i]), + .f_action = NULL, + .arg_ah = NULL, + .burst_size = params->port_in[i].burst_size, + }; + + int status = rte_pipeline_port_in_create(p->p, + &port_params, + &p->port_in_id[i]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + } + + /* Output ports */ + p->n_ports_out = params->n_ports_out; + for (i = 0; i < p->n_ports_out; i++) { + struct rte_pipeline_port_out_params port_params = { + .ops = pipeline_port_out_params_get_ops(¶ms->port_out[i]), + .arg_create = pipeline_port_out_params_convert(¶ms->port_out[i]), + .f_action = NULL, + .f_action_bulk = NULL, + .arg_ah = NULL, + }; + + int status = rte_pipeline_port_out_create(p->p, + &port_params, + &p->port_out_id[i]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + } + + /* Routing table */ + p->n_tables = 1; + { + struct rte_table_lpm_params table_lpm_params = { + .n_rules = p_rt->n_routes, + .entry_unique_size = sizeof(struct routing_table_entry), + .offset = p_rt->ip_da_offset, + }; + + struct rte_pipeline_table_params table_params = { + .ops = &rte_table_lpm_ops, + .arg_create = &table_lpm_params, + .f_action_hit = routing_table_ah_hit, + .f_action_miss = NULL, + .arg_ah = p_rt, + .action_data_size = + sizeof(struct routing_table_entry) - + sizeof(struct rte_pipeline_table_entry), + }; + + int status; + + status = rte_pipeline_table_create(p->p, + &table_params, + &p->table_id[0]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + } + + /* ARP table configuration */ + if (p_rt->n_arp_entries) { + struct rte_table_hash_key8_ext_params table_arp_params = { + .n_entries = p_rt->n_arp_entries, + .n_entries_ext = p_rt->n_arp_entries_ext, + .f_hash = arp_table_hash, + .seed = 0, + .signature_offset = 0, /* Unused */ + .key_offset = p_rt->arp_key_offset, + }; + + struct rte_pipeline_table_params table_params = { + .ops = &rte_table_hash_key8_ext_dosig_ops, + .arg_create = &table_arp_params, + .f_action_hit = arp_table_ah_hit, + .f_action_miss = NULL, + .arg_ah = p_rt, + .action_data_size = sizeof(struct arp_table_entry) - + sizeof(struct rte_pipeline_table_entry), + }; + + int status; + + status = rte_pipeline_table_create(p->p, + &table_params, + &p->table_id[1]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + + p->n_tables ++; + } + + /* Connecting input ports to tables */ + for (i = 0; i < p->n_ports_in; i++) { + int status = rte_pipeline_port_in_connect_to_table(p->p, + p->port_in_id[i], + p->table_id[0]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + } + + /* Enable input ports */ + for (i = 0; i < p->n_ports_in; i++) { + int status = rte_pipeline_port_in_enable(p->p, + p->port_in_id[i]); + + if (status) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + } + + /* Check pipeline consistency */ + if (rte_pipeline_check(p->p) < 0) { + rte_pipeline_free(p->p); + rte_free(p); + return NULL; + } + + /* Message queues */ + p->n_msgq = params->n_msgq; + for (i = 0; i < p->n_msgq; i++) + p->msgq_in[i] = params->msgq_in[i]; + for (i = 0; i < p->n_msgq; i++) + p->msgq_out[i] = params->msgq_out[i]; + + /* Message handlers */ + memcpy(p->handlers, handlers, sizeof(p->handlers)); + memcpy(p_rt->custom_handlers, + custom_handlers, + sizeof(p_rt->custom_handlers)); + + return p; +} + +static int +pipeline_routing_free(void *pipeline) +{ + struct pipeline *p = (struct pipeline *) pipeline; + + /* Check input arguments */ + if (p == NULL) + return -1; + + /* Free resources */ + rte_pipeline_free(p->p); + rte_free(p); + return 0; +} + +static int +pipeline_routing_track(void *pipeline, + __rte_unused uint32_t port_in, + uint32_t *port_out) +{ + struct pipeline *p = (struct pipeline *) pipeline; + + /* Check input arguments */ + if ((p == NULL) || + (port_in >= p->n_ports_in) || + (port_out == NULL)) + return -1; + + if (p->n_ports_in == 1) { + *port_out = 0; + return 0; + } + + return -1; +} + +static int +pipeline_routing_timer(void *pipeline) +{ + struct pipeline *p = (struct pipeline *) pipeline; + + pipeline_msg_req_handle(p); + rte_pipeline_flush(p->p); + + return 0; +} + +void * +pipeline_routing_msg_req_custom_handler(struct pipeline *p, + void *msg) +{ + struct pipeline_routing *p_rt = (struct pipeline_routing *) p; + struct pipeline_custom_msg_req *req = msg; + pipeline_msg_req_handler f_handle; + + f_handle = (req->subtype < PIPELINE_ROUTING_MSG_REQS)? + p_rt->custom_handlers[req->subtype] : + pipeline_msg_req_invalid_handler; + + if (f_handle == NULL) + f_handle = pipeline_msg_req_invalid_handler; + + return f_handle(p, req); +} + +void * +pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_route_add_msg_req *req = msg; + struct pipeline_routing_route_add_msg_rsp *rsp = msg; + + struct rte_table_lpm_key key = { + .ip = req->key.key.ipv4.ip, + .depth = req->key.key.ipv4.depth, + }; + + struct routing_table_entry entry = { + .head = { + .action = RTE_PIPELINE_ACTION_TABLE, + {.table_id = p->table_id[1]}, + }, + + .flags = req->flags, + .port_id = req->port_id, + .ip = req->ip, + }; + + if (req->key.type != PIPELINE_ROUTING_ROUTE_IPV4) { + rsp->status = -1; + return rsp; + } + + rsp->status = rte_pipeline_table_entry_add(p->p, + p->table_id[0], + &key, + (struct rte_pipeline_table_entry *) &entry, + &rsp->key_found, + (struct rte_pipeline_table_entry **) &rsp->entry_ptr); + + RTE_LOG(INFO, USER1, "%s Back-End: Key %s\n", + p->name, + (rsp->key_found)? "found" : "not found"); + + return rsp; +} + +void * +pipeline_routing_msg_req_route_del_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_route_delete_msg_req *req = msg; + struct pipeline_routing_route_delete_msg_rsp *rsp = msg; + + struct rte_table_lpm_key key = { + .ip = req->key.key.ipv4.ip, + .depth = req->key.key.ipv4.depth, + }; + + if (req->key.type != PIPELINE_ROUTING_ROUTE_IPV4) { + rsp->status = -1; + return rsp; + } + + rsp->status = rte_pipeline_table_entry_delete(p->p, + p->table_id[0], + &key, + &rsp->key_found, + NULL); + + RTE_LOG(INFO, USER1, "%s Back-End: Key %s\n", + p->name, + (rsp->key_found)? "found" : "not found"); + + return rsp; +} + +void * +pipeline_routing_msg_req_route_add_default_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_route_add_default_msg_req *req = msg; + struct pipeline_routing_route_add_default_msg_rsp *rsp = msg; + + struct routing_table_entry default_entry = { + .head = { + .action = RTE_PIPELINE_ACTION_PORT, + {.port_id = p->port_out_id[req->port_id]}, + }, + + .flags = 0, + .port_id = 0, + .ip = 0, + }; + + rsp->status = rte_pipeline_table_default_entry_add(p->p, + p->table_id[0], + (struct rte_pipeline_table_entry *) &default_entry, + (struct rte_pipeline_table_entry **) &rsp->entry_ptr); + + return rsp; +} + +void * +pipeline_routing_msg_req_route_del_default_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_route_delete_default_msg_rsp *rsp = msg; + + rsp->status = rte_pipeline_table_default_entry_delete(p->p, + p->table_id[0], + NULL); + + return rsp; +} + +void * +pipeline_routing_msg_req_arp_add_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_arp_add_msg_req *req = msg; + struct pipeline_routing_arp_add_msg_rsp *rsp = msg; + + struct pipeline_routing_arp_key key = { + .type = PIPELINE_ROUTING_ARP_IPV4, + .key = { + .ipv4 = { + .port_id = req->key.key.ipv4.port_id, + .ip = req->key.key.ipv4.ip, + }, + }, + }; + + struct arp_table_entry entry = { + .head = { + .action = RTE_PIPELINE_ACTION_PORT, + {.port_id = p->port_out_id[req->key.key.ipv4.port_id]}, + }, + + .macaddr = 0, + }; + + if (req->key.type != PIPELINE_ROUTING_ARP_IPV4) { + rsp->status = -1; + return rsp; + } + + *((struct ether_addr *) &entry.macaddr) = req->macaddr; + + rsp->status = rte_pipeline_table_entry_add(p->p, + p->table_id[1], + &key.key.ipv4, + (struct rte_pipeline_table_entry *) &entry, + &rsp->key_found, + (struct rte_pipeline_table_entry **) &rsp->entry_ptr); + + RTE_LOG(INFO, USER1, "%s Back-End: Key %s\n", + p->name, + (rsp->key_found)? "found" : "not found"); + + return rsp; +} + +void * +pipeline_routing_msg_req_arp_del_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_arp_delete_msg_req *req = msg; + struct pipeline_routing_arp_delete_msg_rsp *rsp = msg; + + struct pipeline_routing_arp_key key = { + .type = PIPELINE_ROUTING_ARP_IPV4, + .key = { + .ipv4 = { + .port_id = req->key.key.ipv4.port_id, + .ip = req->key.key.ipv4.ip, + }, + }, + }; + + if (req->key.type != PIPELINE_ROUTING_ARP_IPV4) { + rsp->status = -1; + return rsp; + } + + rsp->status = rte_pipeline_table_entry_delete(p->p, + p->table_id[1], + &key, + &rsp->key_found, + NULL); + + RTE_LOG(INFO, USER1, "%s Back-End: Key %s\n", + p->name, + (rsp->key_found)? "found" : "not found"); + + return rsp; +} + +void * +pipeline_routing_msg_req_arp_add_default_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_arp_add_default_msg_req *req = msg; + struct pipeline_routing_arp_add_default_msg_rsp *rsp = msg; + + struct arp_table_entry default_entry = { + .head = { + .action = RTE_PIPELINE_ACTION_PORT, + {.port_id = p->port_out_id[req->port_id]}, + }, + + .macaddr = 0, + }; + + rsp->status = rte_pipeline_table_default_entry_add(p->p, + p->table_id[1], + (struct rte_pipeline_table_entry *) &default_entry, + (struct rte_pipeline_table_entry **) &rsp->entry_ptr); + + return rsp; +} + +void * +pipeline_routing_msg_req_arp_del_default_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing_arp_delete_default_msg_rsp *rsp = msg; + + rsp->status = rte_pipeline_table_default_entry_delete(p->p, + p->table_id[1], + NULL); + + return rsp; +} + +struct pipeline_ops pipeline_routing_ops = { + .f_init = pipeline_routing_init, + .f_free = pipeline_routing_free, + .f_run = NULL, + .f_timer = pipeline_routing_timer, + .f_track = pipeline_routing_track, +}; diff --git a/examples/ip_pipeline/pipeline/pipeline_routing_ops.h b/examples/ip_pipeline/pipeline/pipeline_routing_ops.h new file mode 100644 index 0000000..303b562 --- /dev/null +++ b/examples/ip_pipeline/pipeline/pipeline_routing_ops.h @@ -0,0 +1,231 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __INCLUDE_PIPELINE_ROUTING_OPS_H__ +#define __INCLUDE_PIPELINE_ROUTING_OPS_H__ + +#include + +#include "pipeline_common_ops.h" +#include "pipeline_ops.h" + +/* + * Route + */ +enum pipeline_routing_route_key_type { + PIPELINE_ROUTING_ROUTE_IPV4, +}; + +struct pipeline_routing_route_key_ipv4 { + uint32_t ip; + uint8_t depth; +}; + +struct pipeline_routing_route_key { + enum pipeline_routing_route_key_type type; + union { + struct pipeline_routing_route_key_ipv4 ipv4; + } key; +}; + +enum pipeline_routing_route_flags { + PIPELINE_ROUTING_ROUTE_LOCAL = 1 << 0, /* 0 = remote; 1 = local */ +}; + +/* + * ARP + */ +enum pipeline_routing_arp_key_type { + PIPELINE_ROUTING_ARP_IPV4, +}; + +struct pipeline_routing_arp_key_ipv4 { + uint32_t port_id; + uint32_t ip; +}; + +struct pipeline_routing_arp_key { + enum pipeline_routing_arp_key_type type; + union { + struct pipeline_routing_arp_key_ipv4 ipv4; + } key; +}; + +/* + * Messages + */ +enum pipeline_routing_msg_req_type { + PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD, + PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL, + PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD_DEFAULT, + PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL_DEFAULT, + PIPELINE_ROUTING_MSG_REQ_ARP_ADD, + PIPELINE_ROUTING_MSG_REQ_ARP_DEL, + PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT, + PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT, + PIPELINE_ROUTING_MSG_REQS +}; + +/* + * MSG ROUTE ADD + */ +struct pipeline_routing_route_add_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* key */ + struct pipeline_routing_route_key key; + + /* data */ + enum pipeline_routing_route_flags flags; + uint32_t port_id; /* Output port ID */ + uint32_t ip; /* IP address for the next hop (only valid for remote routes) */ +}; + +struct pipeline_routing_route_add_msg_rsp { + int status; + int key_found; + void *entry_ptr; +}; + +/* + * MSG ROUTE DELETE + */ +struct pipeline_routing_route_delete_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* key */ + struct pipeline_routing_route_key key; +}; + +struct pipeline_routing_route_delete_msg_rsp { + int status; + int key_found; +}; + +/* + * MSG ROUTE ADD DEFAULT + */ +struct pipeline_routing_route_add_default_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* data */ + uint32_t port_id; +}; + +struct pipeline_routing_route_add_default_msg_rsp { + int status; + void *entry_ptr; +}; + +/* + * MSG ROUTE DELETE DEFAULT + */ +struct pipeline_routing_route_delete_default_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; +}; + +struct pipeline_routing_route_delete_default_msg_rsp { + int status; +}; + +/* + * MSG ARP ADD + */ +struct pipeline_routing_arp_add_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* key */ + struct pipeline_routing_arp_key key; + + /* data */ + struct ether_addr macaddr; +}; + +struct pipeline_routing_arp_add_msg_rsp { + int status; + int key_found; + void *entry_ptr; +}; + +/* + * MSG ARP DELETE + */ +struct pipeline_routing_arp_delete_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* key */ + struct pipeline_routing_arp_key key; +}; + +struct pipeline_routing_arp_delete_msg_rsp { + int status; + int key_found; +}; + +/* + * MSG ARP ADD DEFAULT + */ +struct pipeline_routing_arp_add_default_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + /* data */ + uint32_t port_id; +}; + +struct pipeline_routing_arp_add_default_msg_rsp { + int status; + void *entry_ptr; +}; + +/* + * MSG ARP DELETE DEFAULT + */ +struct pipeline_routing_arp_delete_default_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; +}; + +struct pipeline_routing_arp_delete_default_msg_rsp { + int status; +}; + +extern struct pipeline_ops pipeline_routing_ops; + +#endif -- 1.7.9.5