[ovs-dev] [PATCH] lib: support OF11 dec_nw_ttl
Ben Pfaff
blp at nicira.com
Thu Oct 18 15:57:47 UTC 2012
On Thu, Oct 18, 2012 at 07:02:04AM +0900, Isaku Yamahata wrote:
> 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>
Thanks for the patch.
I don't like the idea of having separate keywords "dec_ttl" and
"dec_nw_ttl" that really mean the same thing. So I changed the patch to
use "dec_ttl" for OF1.1+ also, and pushed it as follows:
--8<--------------------------cut here-------------------------->8--
From: Isaku Yamahata <yamahata at valinux.co.jp>
Date: Thu, 18 Oct 2012 07:02:04 +0900
Subject: [PATCH] lib: support OF11 dec_nw_ttl
Signed-off-by: Isaku Yamahata <yamahata at valinux.co.jp>
[blp at nicira.com changed code to use "dec_ttl" instead of "dec_nw_ttl"]
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/ofp-actions.c | 19 +++++++++++++++----
lib/ofp-actions.h | 4 ++--
lib/ofp-parse.c | 30 ++++++++++++++++++++----------
lib/ofp-util.def | 2 +-
tests/ofp-actions.at | 5 +++++
5 files changed, 43 insertions(+), 17 deletions(-)
diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index 4a63acb..0d1a2ac 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, code);
break;
case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
@@ -695,6 +695,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, code);
+ break;
+
case OFPUTIL_OFPAT11_SET_NW_SRC:
ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr;
break;
@@ -1477,6 +1481,14 @@ 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 (a->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();
@@ -1486,7 +1498,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:
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index c62020d..3049aaa 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,
* 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 8941e17..ea0703a 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -280,22 +280,29 @@ parse_controller(struct ofpbuf *b, char *arg)
}
static void
-parse_dec_ttl(struct ofpbuf *b, char *arg)
+parse_noargs_dec_ttl(struct ofpbuf *b, enum ofputil_action_code compat)
{
struct ofpact_cnt_ids *ids;
+ uint16_t id = 0;
ids = ofpact_put_DEC_TTL(b);
+ ids->ofpact.compat = compat;
+ ofpbuf_put(b, &id, sizeof id);
+ ids = b->l2;
+ ids->n_controllers++;
+ ofpact_update_len(b, &ids->ofpact);
+}
+static void
+parse_dec_ttl(struct ofpbuf *b, char *arg, enum ofputil_action_code compat)
+{
if (*arg == '\0') {
- uint16_t id = 0;
-
- ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL;
- ofpbuf_put(b, &id, sizeof id);
- ids = b->l2;
- ids->n_controllers++;
+ parse_noargs_dec_ttl(b, compat);
} else {
+ struct ofpact_cnt_ids *ids;
char *cntr;
+ ids = ofpact_put_DEC_TTL(b);
ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL_CNT_IDS;
for (cntr = strtok_r(arg, ", ", &arg); cntr != NULL;
cntr = strtok_r(NULL, ", ", &arg)) {
@@ -309,9 +316,8 @@ parse_dec_ttl(struct ofpbuf *b, char *arg)
ovs_fatal(0, "dec_ttl_cnt_ids: expected at least one controller "
"id.");
}
-
+ ofpact_update_len(b, &ids->ofpact);
}
- ofpact_update_len(b, &ids->ofpact);
}
static void
@@ -432,6 +438,10 @@ 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:
+ parse_noargs_dec_ttl(ofpacts, code);
+ 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);
@@ -507,7 +517,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, code);
break;
case OFPUTIL_NXAST_FIN_TIMEOUT:
diff --git a/lib/ofp-util.def b/lib/ofp-util.def
index 4d451b0..e61049b 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, NULL)
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..c5d666c 100644
--- a/tests/ofp-actions.at
+++ b/tests/ofp-actions.at
@@ -218,9 +218,14 @@ ffff 0048 00002320 0010 000a 0014 0050 123456789abcdef0 0000 02 00 0002 0004 dnl
# actions=exit
ffff 0010 00002320 0011 000000000000
+dnl NXAST_DEC_TTL
# actions=dec_ttl
ffff 0010 00002320 0012 000000000000
+dnl OpenFlow 1.1 OFPAT_DEC_TTL
+# actions=dec_ttl
+0018 0008 00000000
+
# actions=fin_timeout(idle_timeout=10,hard_timeout=20)
ffff 0010 00002320 0013 000a 0014 0000
--
1.7.10.4
More information about the dev
mailing list