From 7bcb1506ee2de6a460db35404e642f21d8219b5f Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 18 Oct 2012 07:02:04 +0900 Subject: [PATCH] lib: support OF11 dec_nw_ttl Signed-off-by: Isaku Yamahata [blp@nicira.com changed code to use "dec_ttl" instead of "dec_nw_ttl"] Signed-off-by: Ben Pfaff --- 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 4a63acb34..0d1a2acdd 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 c62020de1..3049aaafd 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 8941e1759..ea0703a38 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 4d451b05d..e61049bbd 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 68b51823c..c5d666cec 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 -- 2.20.1