[ovs-dev] [PATCH] lib: support OF11 dec_nw_ttl

Isaku Yamahata yamahata at valinux.co.jp
Wed Oct 17 22:02:04 UTC 2012


action keyword dec_ttl is already used for NX dec_ttl. So dec_nw_ttl is
introduced to disambiguate them.

Signed-off-by: Isaku Yamahata <yamahata at valinux.co.jp>
---
 lib/ofp-actions.c        |   25 +++++++++++++++++++++----
 lib/ofp-actions.h        |    4 ++--
 lib/ofp-parse.c          |   12 +++++++++---
 lib/ofp-util.def         |    2 +-
 tests/ofp-actions.at     |    3 +++
 utilities/ovs-ofctl.8.in |    4 +++-
 6 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index cd8c432..a252f92 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -149,14 +149,14 @@ note_from_openflow(const struct nx_action_note *nan, struct ofpbuf *out)
 }
 
 static enum ofperr
-dec_ttl_from_openflow(struct ofpbuf *out)
+dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat)
 {
     uint16_t id = 0;
     struct ofpact_cnt_ids *ids;
     enum ofperr error = 0;
 
     ids = ofpact_put_DEC_TTL(out);
-    ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL;
+    ids->ofpact.compat = compat;
     ids->n_controllers = 1;
     ofpbuf_put(out, &id, sizeof id);
     ids = out->l2;
@@ -362,7 +362,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code,
         break;
 
     case OFPUTIL_NXAST_DEC_TTL:
-        error = dec_ttl_from_openflow(out);
+        error = dec_ttl_from_openflow(out, OFPUTIL_NXAST_DEC_TTL);
         break;
 
     case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
@@ -699,6 +699,10 @@ ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out)
                ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN);
         break;
 
+    case OFPUTIL_OFPAT11_DEC_NW_TTL:
+        dec_ttl_from_openflow(out, OFPUTIL_OFPAT11_DEC_NW_TTL);
+        break;
+
     case OFPUTIL_OFPAT11_SET_NW_SRC:
         ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
         break;
@@ -1481,6 +1485,15 @@ ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out)
             = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
         break;
 
+    case OFPACT_DEC_TTL:
+        if (ofpact_get_DEC_TTL(a)->ofpact.compat ==
+            OFPUTIL_OFPAT11_DEC_NW_TTL) {
+            ofputil_put_OFPAT11_DEC_NW_TTL(out);
+        } else {
+            ofpact_to_nxast(a, out);
+        }
+        break;
+
     case OFPACT_CLEAR_ACTIONS:
     case OFPACT_GOTO_TABLE:
         NOT_REACHED();
@@ -1490,7 +1503,6 @@ ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out)
     case OFPACT_BUNDLE:
     case OFPACT_REG_MOVE:
     case OFPACT_REG_LOAD:
-    case OFPACT_DEC_TTL:
     case OFPACT_SET_TUNNEL:
     case OFPACT_SET_QUEUE:
     case OFPACT_POP_QUEUE:
@@ -1667,6 +1679,11 @@ print_dec_ttl(const struct ofpact_cnt_ids *ids,
 {
     size_t i;
 
+    if (ids->ofpact.compat == OFPUTIL_OFPAT11_DEC_NW_TTL) {
+        ds_put_cstr(s, "dec_nw_ttl");
+        return;
+    }
+
     ds_put_cstr(s, "dec_ttl");
     if (ids->ofpact.compat == OFPUTIL_NXAST_DEC_TTL_CNT_IDS) {
         ds_put_cstr(s, "(");
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index b6b31b8..37a6082 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -176,7 +176,7 @@ ofpact_end(const struct ofpact *ofpacts, size_t ofpacts_len)
 
 /* OFPACT_STRIP_VLAN, OFPACT_POP_QUEUE, OFPACT_EXIT, OFPACT_CLEAR_ACTIONS.
  *
- * Used for OFPAT10_STRIP_VLAN, NXAST_DEC_TTL, NXAST_POP_QUEUE, NXAST_EXIT,
+ * Used for OFPAT10_STRIP_VLAN, NXAST_POP_QUEUE, NXAST_EXIT,
  * OFPAT11_POP_VLAN, OFPIT11_CLEAR_ACTIONS.
  *
  * Action structure for actions that do not have any extra data beyond the
@@ -412,7 +412,7 @@ struct ofpact_note {
 
 /* OFPACT_DEC_TTL.
  *
- * Used for NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */
+ * Used for OFPAT11_DEC_NW_TTL, NXAST_DEC_TTL and NXAST_DEC_TTL_CNT_IDS. */
 struct ofpact_cnt_ids {
     struct ofpact ofpact;
 
diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index 60d05f3..e50ca16 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -280,7 +280,7 @@ parse_controller(struct ofpbuf *b, char *arg)
 }
 
 static void
-parse_dec_ttl(struct ofpbuf *b, char *arg)
+parse_dec_ttl(struct ofpbuf *b, char *arg, enum ofputil_action_code compat)
 {
     struct ofpact_cnt_ids *ids;
 
@@ -289,7 +289,7 @@ parse_dec_ttl(struct ofpbuf *b, char *arg)
     if (*arg == '\0') {
         uint16_t id = 0;
 
-        ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL;
+        ids->ofpact.compat = compat;
         ofpbuf_put(b, &id, sizeof id);
         ids = b->l2;
         ids->n_controllers++;
@@ -433,6 +433,12 @@ parse_named_action(enum ofputil_action_code code, const struct flow *flow,
         ofpact_put_SET_IPV4_DSCP(ofpacts)->dscp = tos;
         break;
 
+    case OFPUTIL_OFPAT11_DEC_NW_TTL: {
+        char *dummy_arg = "";
+        parse_dec_ttl(ofpacts, dummy_arg, OFPUTIL_OFPAT11_DEC_NW_TTL);
+        break;
+    }
+
     case OFPUTIL_OFPAT10_SET_TP_SRC:
     case OFPUTIL_OFPAT11_SET_TP_SRC:
         ofpact_put_SET_L4_SRC_PORT(ofpacts)->port = str_to_u32(arg);
@@ -508,7 +514,7 @@ parse_named_action(enum ofputil_action_code code, const struct flow *flow,
         break;
 
     case OFPUTIL_NXAST_DEC_TTL:
-        parse_dec_ttl(ofpacts, arg);
+        parse_dec_ttl(ofpacts, arg, OFPUTIL_NXAST_DEC_TTL);
         break;
 
     case OFPUTIL_NXAST_FIN_TIMEOUT:
diff --git a/lib/ofp-util.def b/lib/ofp-util.def
index 26a0f1b..7bebf7e 100644
--- a/lib/ofp-util.def
+++ b/lib/ofp-util.def
@@ -34,7 +34,7 @@ OFPAT11_ACTION(OFPAT11_SET_TP_DST,   ofp_action_tp_port,  0, "mod_tp_dst")
 OFPAT11_ACTION(OFPAT11_POP_VLAN,     ofp_action_header,   0, "pop_vlan")
 //OFPAT11_ACTION(OFPAT11_SET_QUEUE,    ofp11_action_set_queue, 0, "set_queue")
 //OFPAT11_ACTION(OFPAT11_SET_NW_TTL,   ofp11_action_nw_ttl, 0, "set_nw_ttl")
-//OFPAT11_ACTION(OFPAT11_DEC_NW_TTL,   ofp_action_header,   0, "dec_ttl")
+OFPAT11_ACTION(OFPAT11_DEC_NW_TTL,   ofp_action_header,   0, "dec_nw_ttl")
 OFPAT11_ACTION(OFPAT12_SET_FIELD,    ofp12_action_set_field, 1, "set_field")
 
 #ifndef NXAST_ACTION
diff --git a/tests/ofp-actions.at b/tests/ofp-actions.at
index 68b5182..b33218d 100644
--- a/tests/ofp-actions.at
+++ b/tests/ofp-actions.at
@@ -221,6 +221,9 @@ ffff 0010 00002320 0011 000000000000
 # actions=dec_ttl
 ffff 0010 00002320 0012 000000000000
 
+# actions=dec_nw_ttl
+0018 0008 00000000
+
 # actions=fin_timeout(idle_timeout=10,hard_timeout=20)
 ffff 0010 00002320 0013 000a 0014 0000
 
diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in
index 63aa659..dfcf49c 100644
--- a/utilities/ovs-ofctl.8.in
+++ b/utilities/ovs-ofctl.8.in
@@ -300,7 +300,8 @@ specified, very little traffic will ordinarily be printed.)
 If \fBinvalid_ttl\fR is passed, \fBovs\-ofctl\fR sends an OpenFlow ``set
 configuration'' message at connection setup time that requests
 \fBINVALID_TTL_TO_CONTROLLER\fR, so that \fBovs\-ofctl monitor\fR can
-receive ``packet-in'' messages when TTL reaches zero on \fBdec_ttl\fR action.
+receive ``packet-in'' messages when TTL reaches zero on \fBdec_ttl\fR or
+\fBdec_nw_ttl\fR action.
 .IP
 \fBwatch:\fR[\fB\fIspec\fR...] causes \fBovs\-ofctl\fR to send a
 ``monitor request'' Nicira extension message to the switch at
@@ -959,6 +960,7 @@ actions were applied.
 .
 .IP \fBdec_ttl\fR
 .IQ \fBdec_ttl\fB[\fR(\fIid1,id2\fI)\fR]\fR
+.IP \fBdec_nw_ttl\fR
 Decrement TTL of IPv4 packet or hop limit of IPv6 packet.  If the
 TTL or hop limit is initially zero, no decrement occurs.  Instead,
 a ``packet-in'' message with reason code \fBOFPR_INVALID_TTL\fR is
-- 
1.7.10.4




More information about the dev mailing list