diff mbox series

[ovs-dev,v8,3/3] nsh: add dec_nsh_ttl action

Message ID 1515506178-79052-4-git-send-email-yi.y.yang@intel.com
State Changes Requested
Headers show
Series nsh: add new nsh key ttl and action dec_nsh_ttl | expand

Commit Message

Yang, Yi Jan. 9, 2018, 1:56 p.m. UTC
NSH ttl is a 6-bit field ranged from 0 to 63, it should be
decremented by 1 every hop, if it is 0 or it is so after
decremented, the packet should be dropped and a packet-in
message is sent to main controller.

Signed-off-by: Yi Yang <yi.y.yang@intel.com>
---
 include/openvswitch/ofp-actions.h |  1 +
 lib/ofp-actions.c                 | 49 +++++++++++++++++++++++++++++++++++++++
 ofproto/ofproto-dpif-xlate.c      | 31 +++++++++++++++++++++++++
 tests/nsh.at                      |  6 ++---
 utilities/ovs-ofctl.8.in          | 13 ++++++++++-
 5 files changed, 96 insertions(+), 4 deletions(-)

Comments

Ben Pfaff Jan. 10, 2018, 10:52 p.m. UTC | #1
On Tue, Jan 09, 2018 at 09:56:18PM +0800, Yi Yang wrote:
> NSH ttl is a 6-bit field ranged from 0 to 63, it should be
> decremented by 1 every hop, if it is 0 or it is so after
> decremented, the packet should be dropped and a packet-in
> message is sent to main controller.
> 
> Signed-off-by: Yi Yang <yi.y.yang@intel.com>

This change is user-visible so it should add a NEWS item.

Thanks,

Ben.
Ben Pfaff Jan. 10, 2018, 11:02 p.m. UTC | #2
On Wed, Jan 10, 2018 at 02:52:00PM -0800, Ben Pfaff wrote:
> On Tue, Jan 09, 2018 at 09:56:18PM +0800, Yi Yang wrote:
> > NSH ttl is a 6-bit field ranged from 0 to 63, it should be
> > decremented by 1 every hop, if it is 0 or it is so after
> > decremented, the packet should be dropped and a packet-in
> > message is sent to main controller.
> > 
> > Signed-off-by: Yi Yang <yi.y.yang@intel.com>
> 
> This change is user-visible so it should add a NEWS item.

Oh, and I get several failures with the patches applied:

## ------------------------------ ##
## openvswitch 2.8.90 test suite. ##
## ------------------------------ ##

454: learning action - satisfied prerequisites       FAILED (learn.at:74)
452: learning action - parsing and formatting - OXM  FAILED (learn.at:42)
453: learning action - examples                      FAILED (learn.at:58)
455: learning action - invalid prerequisites         FAILED (learn.at:86)
450: learning action - parsing and formatting        FAILED (learn.at:14)
456: learning action - too-long immediate value      FAILED (learn.at:106)
457: learning action - standard VLAN+MAC learning    FAILED (learn.at:122)
460: learning action - TCPv6 port learning           FAILED (learn.at:277)
458: learning action - learn refreshes hard_age      FAILED (learn.at:191)
459: learning action - TCPv4 port learning           FAILED (learn.at:250)
461: learning action - self-modifying flow           FAILED (learn.at:306)
463: learning action - self-modifying flow with hard_timeout FAILED (learn.at:406)
466: learning action - limit                         FAILED (learn.at:635)
465: learning action - delete_learned feature        FAILED (learn.at:522)
464: learning action - fin_timeout feature           FAILED (learn.at:502)
462: learning action - self-modifying flow with idle_timeout FAILED (learn.at:348)
467: learning action - limit result_dst              FAILED (learn.at:674)
468: learning action - different limits              FAILED (learn.at:721)
1187: ofproto-dpif megaflow - learning                FAILED (ofproto-dpif.at:7974)
1077: ofproto-dpif - MPLS handling                    FAILED (ofproto-dpif.at:1760)
1094: ofproto-dpif - fragment handling - actions      FAILED (ofproto-dpif.at:4118)
999: ofproto - flow mod with tunnel metadata         FAILED (ofproto.at:5987)
786: tunnel - Geneve metadata                        FAILED (tunnel.at:582)
939: ofproto - table features (OpenFlow 1.3)         FAILED (ofproto.at:2607)
2326: ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS       FAILED (ovn.at:2031)

## ------------- ##
## Test results. ##
## ------------- ##

ERROR: All 25 tests were run,
25 failed unexpectedly.
## -------------------------- ##
## testsuite.log was created. ##
## -------------------------- ##

Please send `tests/testsuite.log' and all information you think might help:

   To: <bugs@openvswitch.org>
   Subject: [openvswitch 2.8.90] testsuite: 450 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 786 939 999 1077 1094 1187 2326 failed
Yang, Yi Jan. 11, 2018, 5:30 a.m. UTC | #3
On Thu, Jan 11, 2018 at 06:52:00AM +0800, Ben Pfaff wrote:
> On Tue, Jan 09, 2018 at 09:56:18PM +0800, Yi Yang wrote:
> > NSH ttl is a 6-bit field ranged from 0 to 63, it should be
> > decremented by 1 every hop, if it is 0 or it is so after
> > decremented, the packet should be dropped and a packet-in
> > message is sent to main controller.
> > 
> > Signed-off-by: Yi Yang <yi.y.yang@intel.com>
> 
> This change is user-visible so it should add a NEWS item.

Added NEWS item in v9, thanks.
Yang, Yi Jan. 11, 2018, 5:32 a.m. UTC | #4
On Thu, Jan 11, 2018 at 07:02:29AM +0800, Ben Pfaff wrote:
> On Wed, Jan 10, 2018 at 02:52:00PM -0800, Ben Pfaff wrote:
> > On Tue, Jan 09, 2018 at 09:56:18PM +0800, Yi Yang wrote:
> > > NSH ttl is a 6-bit field ranged from 0 to 63, it should be
> > > decremented by 1 every hop, if it is 0 or it is so after
> > > decremented, the packet should be dropped and a packet-in
> > > message is sent to main controller.
> > > 
> > > Signed-off-by: Yi Yang <yi.y.yang@intel.com>
> > 
> > This change is user-visible so it should add a NEWS item.
> 
> Oh, and I get several failures with the patches applied:
> 
> ## ------------------------------ ##
> ## openvswitch 2.8.90 test suite. ##
> ## ------------------------------ ##
> 
> 454: learning action - satisfied prerequisites       FAILED (learn.at:74)
> 452: learning action - parsing and formatting - OXM  FAILED (learn.at:42)
> 453: learning action - examples                      FAILED (learn.at:58)
> 455: learning action - invalid prerequisites         FAILED (learn.at:86)
> 450: learning action - parsing and formatting        FAILED (learn.at:14)
> 456: learning action - too-long immediate value      FAILED (learn.at:106)
> 457: learning action - standard VLAN+MAC learning    FAILED (learn.at:122)
> 460: learning action - TCPv6 port learning           FAILED (learn.at:277)
> 458: learning action - learn refreshes hard_age      FAILED (learn.at:191)
> 459: learning action - TCPv4 port learning           FAILED (learn.at:250)
> 461: learning action - self-modifying flow           FAILED (learn.at:306)
> 463: learning action - self-modifying flow with hard_timeout FAILED (learn.at:406)
> 466: learning action - limit                         FAILED (learn.at:635)
> 465: learning action - delete_learned feature        FAILED (learn.at:522)
> 464: learning action - fin_timeout feature           FAILED (learn.at:502)
> 462: learning action - self-modifying flow with idle_timeout FAILED (learn.at:348)
> 467: learning action - limit result_dst              FAILED (learn.at:674)
> 468: learning action - different limits              FAILED (learn.at:721)
> 1187: ofproto-dpif megaflow - learning                FAILED (ofproto-dpif.at:7974)
> 1077: ofproto-dpif - MPLS handling                    FAILED (ofproto-dpif.at:1760)
> 1094: ofproto-dpif - fragment handling - actions      FAILED (ofproto-dpif.at:4118)
> 999: ofproto - flow mod with tunnel metadata         FAILED (ofproto.at:5987)
> 786: tunnel - Geneve metadata                        FAILED (tunnel.at:582)
> 939: ofproto - table features (OpenFlow 1.3)         FAILED (ofproto.at:2607)
> 2326: ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS       FAILED (ovn.at:2031)
> 
> ## ------------- ##
> ## Test results. ##
> ## ------------- ##
> 
> ERROR: All 25 tests were run,
> 25 failed unexpectedly.
> ## -------------------------- ##
> ## testsuite.log was created. ##
> ## -------------------------- ##
> 
> Please send `tests/testsuite.log' and all information you think might help:
> 
>    To: <bugs@openvswitch.org>
>    Subject: [openvswitch 2.8.90] testsuite: 450 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 786 939 999 1077 1094 1187 2326 failed

All these unit tests failures are led by "939: ofproto - table features
(OpenFlow 1.3)", the first patch in v9 has fixed it.
diff mbox series

Patch

diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h
index 3d97755..c82dae0 100644
--- a/include/openvswitch/ofp-actions.h
+++ b/include/openvswitch/ofp-actions.h
@@ -93,6 +93,7 @@  struct vl_mff_map;
     OFPACT(DEC_MPLS_TTL,    ofpact_null,        ofpact, "dec_mpls_ttl") \
     OFPACT(PUSH_MPLS,       ofpact_push_mpls,   ofpact, "push_mpls")    \
     OFPACT(POP_MPLS,        ofpact_pop_mpls,    ofpact, "pop_mpls")     \
+    OFPACT(DEC_NSH_TTL,     ofpact_null,        ofpact, "dec_nsh_ttl")  \
                                                                         \
     /* Generic encap & decap */                                         \
     OFPACT(ENCAP,           ofpact_encap,       props, "encap")         \
diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index 4918498..7acf05f 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -350,6 +350,9 @@  enum ofp_raw_action_type {
     /* NX1.3+(47): struct nx_action_decap, ... */
     NXAST_RAW_DECAP,
 
+    /* NX1.3+(48): void. */
+    NXAST_RAW_DEC_NSH_TTL,
+
 /* ## ------------------ ## */
 /* ## Debugging actions. ## */
 /* ## ------------------ ## */
@@ -482,6 +485,7 @@  ofpact_next_flattened(const struct ofpact *ofpact)
     case OFPACT_NAT:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
         return ofpact_next(ofpact);
 
     case OFPACT_CLONE:
@@ -4332,6 +4336,39 @@  format_DECAP(const struct ofpact_decap *a,
     ds_put_format(s, "%s)%s", colors.paren, colors.end);
 }
 
+/* Action dec_nsh_ttl */
+
+static enum ofperr
+decode_NXAST_RAW_DEC_NSH_TTL(struct ofpbuf *out)
+{
+    ofpact_put_DEC_NSH_TTL(out);
+    return 0;
+}
+
+static void
+encode_DEC_NSH_TTL(const struct ofpact_null *null OVS_UNUSED,
+            enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out)
+{
+    put_NXAST_DEC_NSH_TTL(out);
+}
+
+static char * OVS_WARN_UNUSED_RESULT
+parse_DEC_NSH_TTL(char *arg OVS_UNUSED,
+           const struct ofputil_port_map *port_map OVS_UNUSED,
+           struct ofpbuf *ofpacts,
+           enum ofputil_protocol *usable_protocols OVS_UNUSED)
+{
+    ofpact_put_DEC_NSH_TTL(ofpacts);
+    return NULL;
+}
+
+static void
+format_DEC_NSH_TTL(const struct ofpact_null *a OVS_UNUSED,
+            const struct ofputil_port_map *port_map OVS_UNUSED, struct ds *s)
+{
+    ds_put_format(s, "%sdec_nsh_ttl%s", colors.special, colors.end);
+}
+
 
 /* Action structures for NXAST_RESUBMIT, NXAST_RESUBMIT_TABLE, and
  * NXAST_RESUBMIT_TABLE_CT.
@@ -7115,6 +7152,7 @@  ofpact_is_set_or_move_action(const struct ofpact *a)
     case OFPACT_SET_VLAN_VID:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
         return true;
     case OFPACT_BUNDLE:
     case OFPACT_CLEAR_ACTIONS:
@@ -7192,6 +7230,7 @@  ofpact_is_allowed_in_actions_set(const struct ofpact *a)
     case OFPACT_STRIP_VLAN:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
         return true;
 
     /* In general these actions are excluded because they are not part of
@@ -7305,6 +7344,7 @@  ofpacts_execute_action_set(struct ofpbuf *action_list,
     ofpacts_copy_last(action_list, action_set, OFPACT_PUSH_VLAN);
     ofpacts_copy_last(action_list, action_set, OFPACT_DEC_TTL);
     ofpacts_copy_last(action_list, action_set, OFPACT_DEC_MPLS_TTL);
+    ofpacts_copy_last(action_list, action_set, OFPACT_DEC_NSH_TTL);
     ofpacts_copy_all(action_list, action_set, ofpact_is_set_or_move_action);
     ofpacts_copy_last(action_list, action_set, OFPACT_SET_QUEUE);
 
@@ -7446,6 +7486,7 @@  ovs_instruction_type_from_ofpact_type(enum ofpact_type type)
     case OFPACT_NAT:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
     default:
         return OVSINST_OFPIT11_APPLY_ACTIONS;
     }
@@ -8132,6 +8173,13 @@  ofpact_check__(enum ofputil_protocol *usable_protocols, struct ofpact *a,
         }
         return 0;
 
+    case OFPACT_DEC_NSH_TTL:
+        if ((flow->packet_type != htonl(PT_NSH)) &&
+            (flow->dl_type != htons(ETH_TYPE_NSH))) {
+            inconsistent_match(usable_protocols);
+        }
+        return 0;
+
     default:
         OVS_NOT_REACHED();
     }
@@ -8627,6 +8675,7 @@  ofpact_outputs_to_port(const struct ofpact *ofpact, ofp_port_t port)
     case OFPACT_NAT:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
     default:
         return false;
     }
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index bf8b060..989d51e 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -4795,6 +4795,28 @@  compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
     }
 }
 
+static bool
+compose_dec_nsh_ttl_action(struct xlate_ctx *ctx)
+{
+    struct flow *flow = &ctx->xin->flow;
+
+    if ((flow->packet_type == htonl(PT_NSH)) ||
+        (flow->dl_type == htons(ETH_TYPE_NSH))) {
+        ctx->wc->masks.nsh.ttl = 0xff;
+        if (flow->nsh.ttl > 1) {
+            flow->nsh.ttl--;
+            return false;
+        } else {
+            execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0,
+                                      NULL, 0);
+        }
+    }
+
+    /* Stop processing for current table. */
+    xlate_report(ctx, OFT_WARN, "NSH decrement TTL exception");
+    return true;
+}
+
 static void
 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
 {
@@ -5349,6 +5371,7 @@  reversible_actions(const struct ofpact *ofpacts, size_t ofpacts_len)
         case OFPACT_OUTPUT_TRUNC:
         case OFPACT_ENCAP:
         case OFPACT_DECAP:
+        case OFPACT_DEC_NSH_TTL:
             return false;
         }
     }
@@ -5576,6 +5599,7 @@  freeze_unroll_actions(const struct ofpact *a, const struct ofpact *end,
         case OFPACT_OUTPUT:
         case OFPACT_CONTROLLER:
         case OFPACT_DEC_MPLS_TTL:
+        case OFPACT_DEC_NSH_TTL:
         case OFPACT_DEC_TTL:
             /* These actions may generate asynchronous messages, which include
              * table ID and flow cookie information. */
@@ -6123,6 +6147,7 @@  recirc_for_mpls(const struct ofpact *a, struct xlate_ctx *ctx)
     case OFPACT_CLONE:
     case OFPACT_ENCAP:
     case OFPACT_DECAP:
+    case OFPACT_DEC_NSH_TTL:
     case OFPACT_UNROLL_XLATE:
     case OFPACT_CT:
     case OFPACT_CT_CLEAR:
@@ -6448,6 +6473,12 @@  do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             }
             break;
 
+        case OFPACT_DEC_NSH_TTL:
+            if (compose_dec_nsh_ttl_action(ctx)) {
+                return;
+            }
+            break;
+
         case OFPACT_DEC_TTL:
             wc->masks.nw_ttl = 0xff;
             if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
diff --git a/tests/nsh.at b/tests/nsh.at
index 6177cea..e6a8345 100644
--- a/tests/nsh.at
+++ b/tests/nsh.at
@@ -542,7 +542,7 @@  AT_DATA([br-in2.txt], [dnl
     table=2,packet_type=(1,0x894f),nsh_spi=0x1020,nsh_si=255,actions=encap(ethernet),set_field:77:88:99:aa:bb:cc->dl_dst,goto_table:4
     table=2,packet_type=(1,0x894f),nsh_spi=0x1020,nsh_si=254,actions=output:2010
     table=4,dl_type=0x894f,dl_dst=11:22:33:44:55:66,actions=set_field:254->nsh_si,decap(),resubmit(,2)
-    table=4,dl_type=0x894f,dl_dst=77:88:99:aa:bb:cc,actions=set_field:254->nsh_si,decap(),resubmit(,2)
+    table=4,dl_type=0x894f,dl_dst=77:88:99:aa:bb:cc,actions=dec_nsh_ttl,decap(),resubmit(,2)
 ])
 
 # br-in3 is SFC classifier (table 1) and final SFF (tables 2,3)
@@ -607,7 +607,7 @@  AT_CHECK([
  table=2, packet_type=(1,0x894f),nsh_spi=0x3020,nsh_si=254 actions=output:2030
  table=2, packet_type=(1,0x894f),nsh_spi=0x3020,nsh_si=255 actions=encap(ethernet),set_field:11:22:33:44:55:66->eth_dst,goto_table:4
  table=4, dl_dst=11:22:33:44:55:66,dl_type=0x894f actions=set_field:254->nsh_si,decap(),resubmit(,2)
- table=4, dl_dst=77:88:99:aa:bb:cc,dl_type=0x894f actions=set_field:254->nsh_si,decap(),resubmit(,2)
+ table=4, dl_dst=77:88:99:aa:bb:cc,dl_type=0x894f actions=dec_nsh_ttl,decap(),resubmit(,2)
  ip,in_port=30 actions=decap(),goto_table:1
  n_packets=2, n_bytes=216, packet_type=(1,0x894f),in_port=3010 actions=goto_table:2
  packet_type=(1,0x800),in_port=30 actions=goto_table:1
@@ -661,7 +661,7 @@  AT_CHECK([
  table=2, n_packets=2, n_bytes=216, packet_type=(1,0x894f),nsh_spi=0x3020,nsh_si=255 actions=encap(ethernet),set_field:11:22:33:44:55:66->eth_dst,goto_table:4
  table=2, packet_type=(1,0x894f),nsh_spi=0x1020,nsh_si=254 actions=output:2010
  table=2, packet_type=(1,0x894f),nsh_spi=0x1020,nsh_si=255 actions=encap(ethernet),set_field:77:88:99:aa:bb:cc->eth_dst,goto_table:4
- table=4, dl_dst=77:88:99:aa:bb:cc,dl_type=0x894f actions=set_field:254->nsh_si,decap(),resubmit(,2)
+ table=4, dl_dst=77:88:99:aa:bb:cc,dl_type=0x894f actions=dec_nsh_ttl,decap(),resubmit(,2)
  table=4, n_packets=2, n_bytes=216, dl_dst=11:22:33:44:55:66,dl_type=0x894f actions=set_field:254->nsh_si,decap(),resubmit(,2)
  ip,in_port=30 actions=decap(),goto_table:1
  n_packets=2, n_bytes=216, packet_type=(1,0x894f),in_port=3010 actions=goto_table:2
diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in
index 5cdf48c..95344c7 100644
--- a/utilities/ovs-ofctl.8.in
+++ b/utilities/ovs-ofctl.8.in
@@ -1280,6 +1280,15 @@  Processing the current set of actions then stops.  However, if the current
 set of actions was reached through ``resubmit'' then remaining actions in
 outer levels resume processing.
 .
+.IP \fBdec_nsh_ttl\fR
+Decrement TTL of the outer NSH header of a packet.  If the TTL
+is initially zero or decrementing would make it so, no decrement occurs.
+Instead, a ``packet-in'' message with reason code \fBOFPR_INVALID_TTL\fR
+is sent to the main controller (id zero), if it has enabled receiving them.
+Processing the current set of actions then stops.  However, if the current
+set of actions was reached through ``resubmit'' then remaining actions in
+outer levels resume processing.
+.
 .IP \fBnote:\fR[\fIhh\fR]...
 Does nothing at all.  Any number of bytes represented as hex digits
 \fIhh\fR may be included.  Pairs of hex digits may be separated by
@@ -1587,6 +1596,8 @@  the action set, the one written later replaces the earlier action:
 \fBdec_ttl\fR
 .IQ
 \fBdec_mpls_ttl\fR
+.IQ
+\fBdec_nsh_ttl\fR
 .
 .IP 7.
 \fBload\fR
@@ -1647,7 +1658,7 @@  not visible.)
 .RE
 .IP
 Only the actions listed above may be written to the action set.
-\fBencap\fR and \fBdecap\fR actions are nonstandard.
+\fBencap\fR, \fBdecap\fR and \fBdec_nsh_ttl\fR actions are nonstandard.
 .
 .IP \fBwrite_metadata\fB:\fIvalue\fR[/\fImask\fR]
 Updates the metadata field for the flow. If \fImask\fR is omitted, the