diff mbox

[ovs-dev,CudaMailTagged,RFC,v2,05/13] Add Meta flow key for NSH header

Message ID 1468344456-11308-1-git-send-email-johnson.li@intel.com
State Changes Requested
Headers show

Commit Message

Johnson.Li July 12, 2016, 5:27 p.m. UTC
Signed-off-by: Johnson Li <johnson.li@intel.com>
diff mbox

Patch

diff --git a/include/openvswitch/meta-flow.h b/include/openvswitch/meta-flow.h
index 84a0946..1f6277f 100644
--- a/include/openvswitch/meta-flow.h
+++ b/include/openvswitch/meta-flow.h
@@ -1720,6 +1720,132 @@  enum OVS_PACKED_ENUM mf_field_id {
      */
     MFF_ND_TLL,
 
+    /* "nsh_mdtype".
+     *
+     * For a packet received, it includes a (8-bit)
+     * nsh metadata type field (md-type).
+     *
+     * Type: u8.
+     * Maskable: bitwise.
+     * Formatting: decimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_MDTYPE(115) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_MDTYPE,
+
+    /* "nsh_np".
+     *
+     * For a packet received, it includes a (8-bit)
+     * nsh next protocol field (np).
+     *
+     * Type: u8.
+     * Maskable: bitwise.
+     * Formatting: decimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_NP(116) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_NP,
+
+    /* "nsi".
+     *
+     * For a packet received, it includes a (8-bit)
+     * network service index (nsi).
+     *
+     * Type: u8.
+     * Maskable: bitwise.
+     * Formatting: decimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSI(117) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSI,
+
+    /* "nsp".
+     *
+     * For a packet received including a (32-bit)
+     * network service path (nsp), the nsp is stored
+     * in the low 24-bits and the high bits are zeroed.  For
+     * other packets, the value is 0.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSP(118) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSP,
+
+    /* "nshc1".
+     *
+     * For a packet received including a (32-bit)
+     * Network Platform Context (nshc1), the nshc1 is stored
+     * in the 32-bits.  For other packets, the value is 0.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_C1(119) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_C1,
+
+    /* "nshc2".
+     *
+     * For a packet received including a (32-bit)
+     * Network Shared Context (nshc2), the nshc2 is stored
+     * in the 32-bits.  For other packets, the value is 0.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_C2(120) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_C2,
+
+    /* "nshc3".
+     *
+     * For a packet received via including a (32-bit)
+     * Service Platform Context (nshc3), the nshc3 is stored
+     * in the 32-bits.  For other packets, the value is 0.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_C3(121) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_C3,
+
+    /* "nshc4".
+     *
+     * For a packet received including a (32-bit)
+     * Service Shared Context (nshc4), the nshc4 is stored
+     * in the 32-bits.  For other packets, the value is 0.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_NSH_C4(122) since v2.5.
+     * OXM: none.
+     */
+    MFF_NSH_C4,
+
     MFF_N_IDS
 };
 
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index 136295d..1636a67 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -325,6 +325,23 @@  mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
     case MFF_TCP_FLAGS:
         return !wc->masks.tcp_flags;
 
+    case MFF_NSH_MDTYPE:
+        return !wc->masks.nsh.md_type;
+    case MFF_NSH_NP:
+        return !wc->masks.nsh.next_proto;
+    case MFF_NSI:
+        return !wc->masks.nsh.nsi;
+    case MFF_NSP:
+        return !wc->masks.nsh.nsp;
+    case MFF_NSH_C1:
+        return !wc->masks.nsh.nshc1;
+    case MFF_NSH_C2:
+        return !wc->masks.nsh.nshc2;
+    case MFF_NSH_C3:
+        return !wc->masks.nsh.nshc3;
+    case MFF_NSH_C4:
+        return !wc->masks.nsh.nshc4;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -610,6 +627,16 @@  mf_is_value_valid(const struct mf_field *mf, const union mf_value *value)
     case MFF_CT_STATE:
         return !(value->be32 & ~htonl(CS_SUPPORTED_MASK));
 
+    case MFF_NSH_MDTYPE:
+    case MFF_NSH_NP:
+    case MFF_NSI:
+    case MFF_NSP:
+    case MFF_NSH_C1:
+    case MFF_NSH_C2:
+    case MFF_NSH_C3:
+    case MFF_NSH_C4:
+        return true;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -852,6 +879,31 @@  mf_get_value(const struct mf_field *mf, const struct flow *flow,
         value->ipv6 = flow->nd_target;
         break;
 
+    case MFF_NSH_MDTYPE:
+        value->u8 = flow->nsh.md_type;
+        break;
+    case MFF_NSH_NP:
+        value->u8 = flow->nsh.next_proto;
+        break;
+    case MFF_NSI:
+        value->u8 = flow->nsh.nsi;
+        break;
+    case MFF_NSP:
+        value->be32 = flow->nsh.nsp;
+        break;
+    case MFF_NSH_C1:
+        value->be32 = flow->nsh.nshc1;
+        break;
+    case MFF_NSH_C2:
+        value->be32 = flow->nsh.nshc2;
+        break;
+    case MFF_NSH_C3:
+        value->be32 = flow->nsh.nshc3;
+        break;
+    case MFF_NSH_C4:
+        value->be32 = flow->nsh.nshc4;
+        break;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -1110,6 +1162,31 @@  mf_set_value(const struct mf_field *mf,
         match_set_nd_target(match, &value->ipv6);
         break;
 
+    case MFF_NSH_MDTYPE:
+        MATCH_SET_FIELD_UINT8(match, nsh.md_type, value->u8);
+        break;
+    case MFF_NSH_NP:
+        MATCH_SET_FIELD_UINT8(match, nsh.next_proto, value->u8);
+        break;
+    case MFF_NSI:
+        MATCH_SET_FIELD_UINT8(match, nsh.nsi, value->u8);
+        break;
+    case MFF_NSP:
+        MATCH_SET_FIELD_BE32(match, nsh.nsp, value->be32);
+        break;
+    case MFF_NSH_C1:
+        MATCH_SET_FIELD_BE32(match, nsh.nshc1, value->be32);
+        break;
+    case MFF_NSH_C2:
+        MATCH_SET_FIELD_BE32(match, nsh.nshc2, value->be32);
+        break;
+    case MFF_NSH_C3:
+        MATCH_SET_FIELD_BE32(match, nsh.nshc3, value->be32);
+        break;
+    case MFF_NSH_C4:
+        MATCH_SET_FIELD_BE32(match, nsh.nshc4, value->be32);
+        break;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -1423,6 +1500,31 @@  mf_set_flow_value(const struct mf_field *mf,
         flow->nd_target = value->ipv6;
         break;
 
+    case MFF_NSH_MDTYPE:
+        flow->nsh.md_type = value->u8;
+        break;
+    case MFF_NSH_NP:
+        flow->nsh.next_proto = value->u8;
+        break;
+    case MFF_NSI:
+        flow->nsh.nsi = value->u8;
+        break;
+    case MFF_NSP:
+        flow->nsh.nsp = value->be32;
+        break;
+    case MFF_NSH_C1:
+        flow->nsh.nshc1 = value->be32;
+        break;
+    case MFF_NSH_C2:
+        flow->nsh.nshc2 = value->be32;
+        break;
+    case MFF_NSH_C3:
+        flow->nsh.nshc3 = value->be32;
+        break;
+    case MFF_NSH_C4:
+        flow->nsh.nshc4 = value->be32;
+        break;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -1747,6 +1849,31 @@  mf_set_wild(const struct mf_field *mf, struct match *match, char **err_str)
         memset(&match->flow.nd_target, 0, sizeof match->flow.nd_target);
         break;
 
+    case MFF_NSH_MDTYPE:
+        MATCH_SET_FIELD_MASKED(match, nsh.md_type, 0, 0);
+        break;
+    case MFF_NSH_NP:
+        MATCH_SET_FIELD_MASKED(match, nsh.next_proto, 0, 0);
+        break;
+    case MFF_NSI:
+        MATCH_SET_FIELD_MASKED(match, nsh.nsi, 0, 0);
+        break;
+    case MFF_NSP:
+        MATCH_SET_FIELD_MASKED(match, nsh.nsp, 0, 0);
+        break;
+    case MFF_NSH_C1:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc1, 0, 0);
+        break;
+    case MFF_NSH_C2:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc2, 0, 0);
+        break;
+    case MFF_NSH_C3:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc3, 0, 0);
+        break;
+    case MFF_NSH_C4:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc4, 0, 0);
+        break;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
@@ -1970,6 +2097,31 @@  mf_set(const struct mf_field *mf,
         match_set_tcp_flags_masked(match, value->be16, mask->be16);
         break;
 
+    case MFF_NSH_MDTYPE:
+        MATCH_SET_FIELD_MASKED(match, nsh.md_type, value->u8, mask->u8);
+        break;
+    case MFF_NSH_NP:
+        MATCH_SET_FIELD_MASKED(match, nsh.next_proto, value->u8, mask->u8);
+        break;
+    case MFF_NSI:
+        MATCH_SET_FIELD_MASKED(match, nsh.nsi, value->u8, mask->u8);
+        break;
+    case MFF_NSP:
+        MATCH_SET_FIELD_MASKED(match, nsh.nsp, value->be32, mask->be32);
+        break;
+    case MFF_NSH_C1:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc1, value->be32, mask->be32);
+        break;
+    case MFF_NSH_C2:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc2, value->be32, mask->be32);
+        break;
+    case MFF_NSH_C3:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc3, value->be32, mask->be32);
+        break;
+    case MFF_NSH_C4:
+        MATCH_SET_FIELD_MASKED(match, nsh.nshc4, value->be32, mask->be32);
+        break;
+
     case MFF_N_IDS:
     default:
         OVS_NOT_REACHED();
diff --git a/lib/nx-match.c b/lib/nx-match.c
index aad6e02..05e4180 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -1039,6 +1039,24 @@  nx_put_raw(struct ofpbuf *b, enum ofp_version oxm, const struct match *match,
                flow->tunnel.gbp_flags, match->wc.masks.tunnel.gbp_flags);
     tun_metadata_to_nx_match(b, oxm, match);
 
+    /* Network Service Header */
+    nxm_put_8m(b, MFF_NSH_MDTYPE, oxm, flow->nsh.md_type,
+               match->wc.masks.nsh.md_type);
+    nxm_put_8m(b, MFF_NSH_NP, oxm, flow->nsh.next_proto,
+               match->wc.masks.nsh.next_proto);
+    nxm_put_8m(b, MFF_NSI, oxm, flow->nsh.nsi,
+               match->wc.masks.nsh.nsi);
+    nxm_put_32m(b, MFF_NSP, oxm, flow->nsh.nsp,
+                match->wc.masks.nsh.nsp);
+    nxm_put_32m(b, MFF_NSH_C1, oxm, flow->nsh.nshc1,
+                match->wc.masks.nsh.nshc1);
+    nxm_put_32m(b, MFF_NSH_C2, oxm, flow->nsh.nshc2,
+                match->wc.masks.nsh.nshc2);
+    nxm_put_32m(b, MFF_NSH_C3, oxm, flow->nsh.nshc3,
+                match->wc.masks.nsh.nshc3);
+    nxm_put_32m(b, MFF_NSH_C4, oxm, flow->nsh.nshc4,
+                match->wc.masks.nsh.nshc4);
+
     /* Registers. */
     if (oxm < OFP15_VERSION) {
         for (i = 0; i < FLOW_N_REGS; i++) {
diff --git a/tests/ofproto.at b/tests/ofproto.at
index c89c641..7f7ed12 100644
--- a/tests/ofproto.at
+++ b/tests/ofproto.at
@@ -1781,7 +1781,7 @@  head_table () {
         actions: output group set_field strip_vlan push_vlan mod_nw_ttl dec_ttl set_mpls_ttl dec_mpls_ttl push_mpls pop_mpls set_queue
         supported on Set-Field: tun_id tun_src tun_dst tun_ipv6_src tun_ipv6_dst tun_flags tun_gbp_id tun_gbp_flags tun_metadata0 dnl
 tun_metadata1 tun_metadata2 tun_metadata3 tun_metadata4 tun_metadata5 tun_metadata6 tun_metadata7 tun_metadata8 tun_metadata9 tun_metadata10 tun_metadata11 tun_metadata12 tun_metadata13 tun_metadata14 tun_metadata15 tun_metadata16 tun_metadata17 tun_metadata18 tun_metadata19 tun_metadata20 tun_metadata21 tun_metadata22 tun_metadata23 tun_metadata24 tun_metadata25 tun_metadata26 tun_metadata27 tun_metadata28 tun_metadata29 tun_metadata30 tun_metadata31 tun_metadata32 tun_metadata33 tun_metadata34 tun_metadata35 tun_metadata36 tun_metadata37 tun_metadata38 tun_metadata39 tun_metadata40 tun_metadata41 tun_metadata42 tun_metadata43 tun_metadata44 tun_metadata45 tun_metadata46 tun_metadata47 tun_metadata48 tun_metadata49 tun_metadata50 tun_metadata51 tun_metadata52 tun_metadata53 tun_metadata54 tun_metadata55 tun_metadata56 tun_metadata57 tun_metadata58 tun_metadata59 tun_metadata60 tun_metadata61 tun_metadata62 tun_metadata63 dnl
-metadata in_port in_port_oxm pkt_mark ct_mark ct_label reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 xreg0 xreg1 xreg2 xreg3 eth_src eth_dst vlan_tci vlan_vid vlan_pcp mpls_label mpls_tc mpls_ttl ip_src ip_dst ipv6_src ipv6_dst ipv6_label nw_tos ip_dscp nw_ecn nw_ttl arp_op arp_spa arp_tpa arp_sha arp_tha tcp_src tcp_dst udp_src udp_dst sctp_src sctp_dst icmp_type icmp_code icmpv6_type icmpv6_code nd_target nd_sll nd_tll
+metadata in_port in_port_oxm pkt_mark ct_mark ct_label reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 xreg0 xreg1 xreg2 xreg3 eth_src eth_dst vlan_tci vlan_vid vlan_pcp mpls_label mpls_tc mpls_ttl ip_src ip_dst ipv6_src ipv6_dst ipv6_label nw_tos ip_dscp nw_ecn nw_ttl arp_op arp_spa arp_tpa arp_sha arp_tha tcp_src tcp_dst udp_src udp_dst sctp_src sctp_dst icmp_type icmp_code icmpv6_type icmpv6_code nd_target nd_sll nd_tll nsh_mdtype nsh_np nsi nsp nshc1 nshc2 nshc3 nshc4
     matching:
       dp_hash: arbitrary mask
       recirc_id: exact match or wildcard
@@ -1919,6 +1919,14 @@  metadata in_port in_port_oxm pkt_mark ct_mark ct_label reg0 reg1 reg2 reg3 reg4
       nd_target: arbitrary mask
       nd_sll: arbitrary mask
       nd_tll: arbitrary mask
+      nsh_mdtype: arbitrary mask
+      nsh_np: arbitrary mask
+      nsi: arbitrary mask
+      nsp: arbitrary mask
+      nshc1: arbitrary mask
+      nshc2: arbitrary mask
+      nshc3: arbitrary mask
+      nshc4: arbitrary mask
 
 ' $1
 }