diff mbox series

[ovs-dev,45/62] netdev-offload-dpdk: Add geneve option header parse/encap

Message ID 20201228092520.11807-46-taoyunxiang@cmss.chinamobile.com
State Not Applicable
Headers show
Series DPDK Offload API to test | expand

Commit Message

Tao YunXiang Dec. 28, 2020, 9:25 a.m. UTC
From: Taoyunxiang <taoyunxiang@cmss.chinamobile.com>

Code Source From: Self Code
Description:
     Add geneve tunnel header parse/encap support.

Jira:  #[Optional]
市场项目编号(名称):[Optional]
---
 lib/netdev-offload-dpdk.c | 96 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 77 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index 12aa5c1..fb36466 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -413,12 +413,37 @@  dump_flow_pattern(struct ds *s, const struct rte_flow_item *item)
             ds_put_cstr(s, "  Spec = null\n");
         }
         if (geneve_mask) {
-            ds_put_format(s, "vni mask 0x%06x ",
+            ds_put_format(s, "vni mask 0x%06x \n",
                           ntohl(*(ovs_be32 *)geneve_mask->vni) >> 8);
         } else {
             ds_put_cstr(s, "  Mask = null\n");
         }
         ds_put_cstr(s, "/ ");
+    } else if (item->type == RTE_FLOW_ITEM_TYPE_GENEVE_OPTIONS) {
+        const struct rte_flow_item_geneve_options *op_spec = item->spec;
+        const struct rte_flow_item_geneve_options *op_mask = item->mask;
+
+        ds_put_cstr(s, "rte flow geneve options pattern:\n");
+        ds_put_cstr(s, "geneve op \n");
+        if (op_spec) {
+            ds_put_format(s, "class spec 0x%04x \n", ntohs(op_spec->class));
+            ds_put_format(s, "type  spec 0x%02x \n", op_spec->type);
+            ds_put_format(s, "len   spec %d \n", op_spec->len);
+            ds_put_format(s, "opdata spec 0x%08x \n",
+                              ntohl(op_spec->option_data));
+        } else {
+            ds_put_cstr(s, "  Spec = null\n");
+        }
+        if (op_mask) {
+            ds_put_format(s, "class mask 0x%04x \n", ntohs(op_mask->class));
+            ds_put_format(s, "type  mask 0x%02x \n", op_mask->type);
+            ds_put_format(s, "len   mask %d \n", op_mask->len);
+            ds_put_format(s, "opdata mask 0x%08x \n",
+                              ntohl(op_mask->option_data));
+        } else {
+            ds_put_cstr(s, "  Mask = null\n");
+        }
+        ds_put_cstr(s, "/ ");
     } else {
         ds_put_format(s, "unknown rte flow pattern (%d)\n", item->type);
     }
@@ -489,7 +514,6 @@  dump_flow_action(struct ds *s, const struct rte_flow_action *actions)
         }
     } else if (actions->type == RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) {
         ds_put_format(s, "vxlan-decap: nop\n");
-    /* TBD
     } else if (actions->type == RTE_FLOW_ACTION_TYPE_GENEVE_ENCAP) {
         const struct rte_flow_action_geneve_encap *geneve_encap = actions->conf;
         const struct rte_flow_item *items = geneve_encap->definition;
@@ -501,7 +525,6 @@  dump_flow_action(struct ds *s, const struct rte_flow_action *actions)
         }
     } else if (actions->type == RTE_FLOW_ACTION_TYPE_GENEVE_DECAP) {
         ds_put_format(s, "geneve-decap: nop\n");
-     */
     } else if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN) {
         const struct rte_flow_action_of_push_vlan *vlan_tci = actions->conf;
          
@@ -760,10 +783,11 @@  parse_geneve_match(struct flow_patterns *patterns,
                    const struct match *match)
 {
     struct rte_flow_item_geneve *vx_spec, *vx_mask;
-    /* TBD */
+    struct rte_flow_item_geneve_options *op_spec, *op_mask;
     uint8_t data_len;
     uint32_t len,opt_data;
     struct geneve_opt *opt;
+    const void *gnv;
     uint8_t i;
 
     if (is_all_zeros(&match->wc.masks.tunnel, sizeof match->wc.masks.tunnel)) {
@@ -789,17 +813,28 @@  parse_geneve_match(struct flow_patterns *patterns,
 
     add_flow_pattern(patterns, RTE_FLOW_ITEM_TYPE_GENEVE, vx_spec, vx_mask);
 
-    /* TBD: add option hdr */
     len = match->flow.tunnel.metadata.present.len;
     if (len > 0) {
-        opt = &match->flow.tunnel.metadata.opts.gnv;
+        gnv = &(match->flow.tunnel.metadata.opts.gnv);
+        opt = (struct geneve_opt *)gnv;
         data_len = opt->length*4;
-        uint8_t *buf = (opt+1);
+        uint8_t *buf = (uint8_t *)(opt+1);
         for (i=0; i<data_len; i++) {
             uint8_t val = *(buf+i);
             opt_data = opt_data | val ;
             opt_data = (i==data_len-1)? opt_data: opt_data<< 8;
+            VLOG_DBG("TIMO DBG. geneve op hdr =0x%08x",opt_data);
         }
+        /* GENEVE option */
+        op_spec = xzalloc(sizeof *op_spec);
+        op_mask = xzalloc(sizeof *op_mask);
+
+        op_spec->class = opt->opt_class;
+        op_spec->type = opt->type;
+        op_spec->len  = opt->length;
+        op_spec->option_data  = htonl(opt_data);
+
+        add_flow_pattern(patterns, RTE_FLOW_ITEM_TYPE_GENEVE_OPTIONS, op_spec, op_mask);
     }
     return 0;
 }
@@ -1461,7 +1496,7 @@  err:
     return -1;
 }
 
-#define ACTION_GENEVE_ENCAP_ITEMS_NUM 5
+#define ACTION_GENEVE_ENCAP_ITEMS_NUM 6
 
 static int
 add_geneve_encap_action(struct flow_actions *actions,
@@ -1469,18 +1504,21 @@  add_geneve_encap_action(struct flow_actions *actions,
 {
     const struct eth_header *eth;
     const struct udp_header *udp;
+    const struct genevehdr *geneve;
     struct geneve_data {
-        /* TBD
         struct rte_flow_action_geneve_encap conf;
-         */
-        struct rte_flow_action_vxlan_encap conf;
         struct rte_flow_item items[0];
     } *geneve_data;
     BUILD_ASSERT_DECL(offsetof(struct geneve_data, conf) == 0);
-    const void *geneve;
     const void *l3;
     const void *l4;
+    const void *l5;
+    struct rte_flow_item_geneve_options *op_spec;
+    struct rte_flow_item_geneve *gnv_spec;
+    struct geneve_opt *opt;
     int field;
+    uint8_t data_len,i;
+    uint32_t opt_data = 0;
 
     VLOG_DBG("TIMO DBG: in add_geneve_encap_action");
     geneve_data = xzalloc(sizeof *geneve_data +
@@ -1529,21 +1567,44 @@  add_geneve_encap_action(struct flow_actions *actions,
     geneve_data->items[field].type = RTE_FLOW_ITEM_TYPE_UDP;
     geneve_data->items[field].spec = udp;
     geneve_data->items[field].mask = &rte_flow_item_udp_mask;
+    l5 = (udp + 1);
     field++;
 
-    geneve = (udp + 1);
+    geneve = (const struct genevehdr *)l5;
+    gnv_spec = xzalloc(sizeof *gnv_spec);
     geneve_data->items[field].type = RTE_FLOW_ITEM_TYPE_GENEVE;
-    geneve_data->items[field].spec = geneve;
+    gnv_spec->protocol = geneve->proto_type;
+    put_unaligned_be32((ovs_be32 *)gnv_spec->vni,
+                       get_16aligned_be32(&geneve->vni));
+    geneve_data->items[field].spec = gnv_spec;
     geneve_data->items[field].mask = &rte_flow_item_geneve_mask;
     field++;
 
+    opt =(struct geneve_opt *)&geneve->options;
+    data_len = opt->length*4;
+    if (data_len) {
+        uint8_t *buf = (uint8_t *)(opt+1);
+        for (i=0; i<data_len; i++) {
+            uint8_t val = *(buf+i);
+            opt_data = opt_data | val ;
+            opt_data = (i==data_len-1)? opt_data: opt_data<< 8;
+        }
+        op_spec = xzalloc(sizeof *op_spec);
+        op_spec->class = opt->opt_class;
+        op_spec->type = opt->type;
+        op_spec->len  = opt->length;
+        op_spec->option_data  = htonl(opt_data);
+        geneve_data->items[field].type = RTE_FLOW_ITEM_TYPE_GENEVE_OPTIONS;
+        geneve_data->items[field].spec = op_spec;
+        geneve_data->items[field].mask = &rte_flow_item_geneve_options_mask;
+        field++;
+    }
+
     geneve_data->items[field].type = RTE_FLOW_ITEM_TYPE_END;
 
     geneve_data->conf.definition = geneve_data->items;
 
-    /* TBD 
     add_flow_action(actions, RTE_FLOW_ACTION_TYPE_GENEVE_ENCAP, geneve_data);
-     */
 
     return 0;
 err:
@@ -1562,10 +1623,7 @@  static void
 add_geneve_decap_action(struct flow_actions *actions)
 {
     VLOG_DBG("TIMO DBG: in add_geneve_decap_action");
-    /* TBD need change to geneve decap 
     add_flow_action(actions, RTE_FLOW_ACTION_TYPE_GENEVE_DECAP, NULL);
-     */
-    add_flow_action(actions, RTE_FLOW_ACTION_TYPE_VXLAN_DECAP, NULL);
 }
 
 static int