Signed-off-by: Johnson Li <johnson...@intel.com>

diff --git a/lib/odp-util.c b/lib/odp-util.c
index f970e86..056b0be 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -550,6 +550,41 @@ format_odp_tnl_push_action(struct ds *ds, const struct 
nlattr *attr)
     ds_put_format(ds, ",out_port(%"PRIu32"))", data->out_port);
 }
 
+static void
+format_push_nsh_header(struct ds *ds, const struct ovs_action_push_nsh * nsh)
+{
+    const struct nsh_header *nsh_hdr = (struct nsh_header *) (nsh->header);
+
+    ds_put_format(ds, "flags=0x%"PRIx8",md_type=%"PRIu8",next_proto=%"PRIu8
+            ",nsp=0x%"PRIx32",nsi=0x%"PRIx8,
+            nsh_hdr->base.flags,
+            nsh_hdr->base.md_type,
+            nsh_hdr->base.next_proto,
+            ntohl(nsh_hdr->base.sfp << 8),
+            (nsh_hdr->base.sfp >> 24));
+
+    /* MD Type 1 only, Todo: Type 2 support */
+    if (nsh_hdr->base.md_type == NSH_MD_TYPE1) {
+        ds_put_format(ds, ",nshc1=0x%"PRIx32",nshc2=0x%"PRIx32
+                ",nshc3=0x%"PRIx32",nshc4=0x%"PRIx32,
+                ntohl(nsh_hdr->ctx.nshc1),
+                ntohl(nsh_hdr->ctx.nshc2),
+                ntohl(nsh_hdr->ctx.nshc3),
+                ntohl(nsh_hdr->ctx.nshc4));
+    }
+}
+
+static void
+format_push_nsh_action(struct ds *ds, const struct nlattr *attr)
+{
+    struct ovs_action_push_nsh *data;
+
+    data = (struct ovs_action_push_nsh *)nl_attr_get(attr);
+    ds_put_cstr(ds, "push_nsh(");
+    format_push_nsh_header(ds, data);
+    ds_put_char(ds, ')');
+}
+
 static const struct nl_policy ovs_nat_policy[] = {
     [OVS_NAT_ATTR_SRC] = { .type = NL_A_FLAG, .optional = true, },
     [OVS_NAT_ATTR_DST] = { .type = NL_A_FLAG, .optional = true, },
@@ -852,7 +887,10 @@ format_odp_action(struct ds *ds, const struct nlattr *a)
         format_odp_conntrack_action(ds, a);
         break;
     case OVS_ACTION_ATTR_PUSH_NSH:
+        format_push_nsh_action(ds, a);
+        break;
     case OVS_ACTION_ATTR_POP_NSH:
+        ds_put_cstr(ds, "pop_nsh");
         break;
     case OVS_ACTION_ATTR_UNSPEC:
     case __OVS_ACTION_ATTR_MAX:
@@ -1624,6 +1662,54 @@ parse_odp_action(const char *s, const struct simap 
*port_names,
     }
 
     {
+        struct ovs_action_push_nsh push;
+        struct nsh_header *nsh_hdr = (struct nsh_header *)push.header;
+        ovs_be32 nsp = 0;
+        int n = -1, m = -1;
+        uint8_t flags = 0, nsi = 0, md_type = 0, next_proto = 0;
+
+        if (ovs_scan_len(s, &n, "push_nsh(flags=0x%"SCNx8",md_type=%"SCNi8
+                ",next_proto=%"SCNi8",nsp=0x%"SCNx32",nsi=0x%"SCNx8,
+                &flags, &md_type, &next_proto, &nsp, &nsi)) {
+
+            /* MD Type 1 only, Todo: Type 2 support */
+            if (md_type == NSH_MD_TYPE1 ) {
+                ovs_be32 nshc1 = 0, nshc2 = 0, nshc3 = 0, nshc4 = 0;
+
+                if (!ovs_scan_len(s, &m, ",nshc1=0x%"SCNx32",nshc2=0x%"SCNx32
+                        ",nshc3=0x%"SCNx32",nshc4=0x%"SCNx32")",
+                        &nshc1, &nshc2, &nshc3, &nshc4)) {
+                        nshc1 = 0;
+                        nshc2 = 0;
+                        nshc3 = 0;
+                        nshc4 = 0;
+                }
+
+                nsh_hdr->base.flags = flags;
+                nsh_hdr->base.length = NSH_TYPE1_LEN >> 2;
+                nsh_hdr->base.md_type = NSH_MD_TYPE1;
+                nsh_hdr->base.next_proto = next_proto;
+                nsh_hdr->base.sfp = (nsp >> 8) | (nsi << 24);
+                nsh_hdr->ctx.nshc1 = nshc1;
+                nsh_hdr->ctx.nshc2 = nshc2;
+                nsh_hdr->ctx.nshc3 = nshc3;
+                nsh_hdr->ctx.nshc4 = nshc4;
+
+                push.len = NSH_TYPE1_LEN;
+            }
+
+            nl_msg_put_unspec(actions, OVS_ACTION_ATTR_PUSH_NSH,
+                          &push, sizeof push);
+            return n + m;
+        }
+    }
+
+    if (!strncmp(s, "pop_nsh", 7)) {
+        nl_msg_put_flag(actions, OVS_ACTION_ATTR_POP_NSH);
+        return 7;
+    }
+
+    {
         double percentage;
         int n = -1;
 
-- 
1.8.4.2

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to