From 1c54c93809c226c3666b7c0a83a22d25618472d8 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Tue, 24 Apr 2018 17:59:00 +0200 Subject: [PATCH] ethdev: add TTL change actions to flow API Add support for the following OpenFlow-defined actions: - RTE_FLOW_ACTION_OF_SET_MPLS_TTL: MPLS TTL. - RTE_FLOW_ACTION_OF_DEC_MPLS_TTL: decrement MPLS TTL. - RTE_FLOW_ACTION_OF_SET_NW_TTL: IP TTL. - RTE_FLOW_ACTION_OF_DEC_NW_TTL: decrement IP TTL. - RTE_FLOW_ACTION_OF_COPY_TTL_OUT: copy TTL "outwards". - RTE_FLOW_ACTION_OF_COPY_TTL_IN: copy TTL "inwards". Signed-off-by: Qi Zhang Signed-off-by: Adrien Mazarguil --- app/test-pmd/cmdline_flow.c | 88 ++++++++++++++++++ app/test-pmd/config.c | 8 ++ doc/guides/prog_guide/rte_flow.rst | 99 +++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 16 ++++ lib/librte_ether/rte_flow.c | 8 ++ lib/librte_ether/rte_flow.h | 72 ++++++++++++++- 6 files changed, 290 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index c83199f107..5bda08f879 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -214,6 +214,14 @@ enum index { ACTION_PORT_ID_ID, ACTION_METER, ACTION_METER_ID, + ACTION_OF_SET_MPLS_TTL, + ACTION_OF_SET_MPLS_TTL_MPLS_TTL, + ACTION_OF_DEC_MPLS_TTL, + ACTION_OF_SET_NW_TTL, + ACTION_OF_SET_NW_TTL_NW_TTL, + ACTION_OF_DEC_NW_TTL, + ACTION_OF_COPY_TTL_OUT, + ACTION_OF_COPY_TTL_IN, }; /** Maximum size for pattern in struct rte_flow_item_raw. */ @@ -730,6 +738,12 @@ static const enum index next_action[] = { ACTION_PHY_PORT, ACTION_PORT_ID, ACTION_METER, + ACTION_OF_SET_MPLS_TTL, + ACTION_OF_DEC_MPLS_TTL, + ACTION_OF_SET_NW_TTL, + ACTION_OF_DEC_NW_TTL, + ACTION_OF_COPY_TTL_OUT, + ACTION_OF_COPY_TTL_IN, ZERO, }; @@ -783,6 +797,18 @@ static const enum index action_meter[] = { ZERO, }; +static const enum index action_of_set_mpls_ttl[] = { + ACTION_OF_SET_MPLS_TTL_MPLS_TTL, + ACTION_NEXT, + ZERO, +}; + +static const enum index action_of_set_nw_ttl[] = { + ACTION_OF_SET_NW_TTL_NW_TTL, + ACTION_NEXT, + ZERO, +}; + static int parse_init(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -2086,6 +2112,68 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)), .call = parse_vc_conf, }, + [ACTION_OF_SET_MPLS_TTL] = { + .name = "of_set_mpls_ttl", + .help = "OpenFlow's OFPAT_SET_MPLS_TTL", + .priv = PRIV_ACTION + (OF_SET_MPLS_TTL, + sizeof(struct rte_flow_action_of_set_mpls_ttl)), + .next = NEXT(action_of_set_mpls_ttl), + .call = parse_vc, + }, + [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = { + .name = "mpls_ttl", + .help = "MPLS TTL", + .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)), + .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl, + mpls_ttl)), + .call = parse_vc_conf, + }, + [ACTION_OF_DEC_MPLS_TTL] = { + .name = "of_dec_mpls_ttl", + .help = "OpenFlow's OFPAT_DEC_MPLS_TTL", + .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0), + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_TTL] = { + .name = "of_set_nw_ttl", + .help = "OpenFlow's OFPAT_SET_NW_TTL", + .priv = PRIV_ACTION + (OF_SET_NW_TTL, + sizeof(struct rte_flow_action_of_set_nw_ttl)), + .next = NEXT(action_of_set_nw_ttl), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_TTL_NW_TTL] = { + .name = "nw_ttl", + .help = "IP TTL", + .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)), + .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl, + nw_ttl)), + .call = parse_vc_conf, + }, + [ACTION_OF_DEC_NW_TTL] = { + .name = "of_dec_nw_ttl", + .help = "OpenFlow's OFPAT_DEC_NW_TTL", + .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0), + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc, + }, + [ACTION_OF_COPY_TTL_OUT] = { + .name = "of_copy_ttl_out", + .help = "OpenFlow's OFPAT_COPY_TTL_OUT", + .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0), + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc, + }, + [ACTION_OF_COPY_TTL_IN] = { + .name = "of_copy_ttl_in", + .help = "OpenFlow's OFPAT_COPY_TTL_IN", + .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0), + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc, + }, }; /** Remove and return last entry from argument stack. */ diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 7f5f40f30e..b05cd9c44d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1106,6 +1106,14 @@ static const struct { MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)), MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)), MK_FLOW_ACTION(METER, sizeof(struct rte_flow_action_meter)), + MK_FLOW_ACTION(OF_SET_MPLS_TTL, + sizeof(struct rte_flow_action_of_set_mpls_ttl)), + MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0), + MK_FLOW_ACTION(OF_SET_NW_TTL, + sizeof(struct rte_flow_action_of_set_nw_ttl)), + MK_FLOW_ACTION(OF_DEC_NW_TTL, 0), + MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0), + MK_FLOW_ACTION(OF_COPY_TTL_IN, 0), }; /** Compute storage space needed by action configuration and copy it. */ diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 9993c09079..50cb043a62 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -1716,6 +1716,103 @@ fields in the pattern items. | 1 | END | +-------+----------+ +Action: ``OF_SET_MPLS_TTL`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow +Switch Specification`_. + +.. _table_rte_flow_action_of_set_mpls_ttl: + +.. table:: OF_SET_MPLS_TTL + + +--------------+----------+ + | Field | Value | + +==============+==========+ + | ``mpls_ttl`` | MPLS TTL | + +--------------+----------+ + +Action: ``OF_DEC_MPLS_TTL`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_dec_mpls_ttl: + +.. table:: OF_DEC_MPLS_TTL + + +---------------+ + | Field | + +===============+ + | no properties | + +---------------+ + +Action: ``OF_SET_NW_TTL`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow +Switch Specification`_. + +.. _table_rte_flow_action_of_set_nw_ttl: + +.. table:: OF_SET_NW_TTL + + +------------+--------+ + | Field | Value | + +============+========+ + | ``nw_ttl`` | IP TTL | + +------------+--------+ + +Action: ``OF_DEC_NW_TTL`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_dec_nw_ttl: + +.. table:: OF_DEC_NW_TTL + + +---------------+ + | Field | + +===============+ + | no properties | + +---------------+ + +Action: ``OF_COPY_TTL_OUT`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from +next-to-outermost to outermost") as defined by the `OpenFlow Switch +Specification`_. + +.. _table_rte_flow_action_of_copy_ttl_out: + +.. table:: OF_COPY_TTL_OUT + + +---------------+ + | Field | + +===============+ + | no properties | + +---------------+ + +Action: ``OF_COPY_TTL_IN`` +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to +next-to-outermost") as defined by the `OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_copy_ttl_in: + +.. table:: OF_COPY_TTL_IN + + +---------------+ + | Field | + +===============+ + | no properties | + +---------------+ + Negative types ~~~~~~~~~~~~~~ @@ -2296,3 +2393,5 @@ Future evolutions - Optional software fallback when PMDs are unable to handle requested flow rules so applications do not have to implement their own. + +.. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/ diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 66602823f5..e2a967b7b4 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3503,6 +3503,22 @@ This section lists supported actions and their attributes, if any. - ``original {boolean}``: use original DPDK port ID if possible. - ``id {unsigned}``: DPDK port ID. +- ``of_set_mpls_ttl``: OpenFlow's ``OFPAT_SET_MPLS_TTL``. + + - ``mpls_ttl``: MPLS TTL. + +- ``of_dec_mpls_ttl``: OpenFlow's ``OFPAT_DEC_MPLS_TTL``. + +- ``of_set_nw_ttl``: OpenFlow's ``OFPAT_SET_NW_TTL``. + + - ``nw_ttl``: IP TTL. + +- ``of_dec_nw_ttl``: OpenFlow's ``OFPAT_DEC_NW_TTL``. + +- ``of_copy_ttl_out``: OpenFlow's ``OFPAT_COPY_TTL_OUT``. + +- ``of_copy_ttl_in``: OpenFlow's ``OFPAT_COPY_TTL_IN``. + Destroying flow rules ~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/librte_ether/rte_flow.c b/lib/librte_ether/rte_flow.c index 64e579d738..7c0ae5b173 100644 --- a/lib/librte_ether/rte_flow.c +++ b/lib/librte_ether/rte_flow.c @@ -90,6 +90,14 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = { MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)), MK_FLOW_ACTION(PHY_PORT, sizeof(struct rte_flow_action_phy_port)), MK_FLOW_ACTION(PORT_ID, sizeof(struct rte_flow_action_port_id)), + MK_FLOW_ACTION(OF_SET_MPLS_TTL, + sizeof(struct rte_flow_action_of_set_mpls_ttl)), + MK_FLOW_ACTION(OF_DEC_MPLS_TTL, 0), + MK_FLOW_ACTION(OF_SET_NW_TTL, + sizeof(struct rte_flow_action_of_set_nw_ttl)), + MK_FLOW_ACTION(OF_DEC_NW_TTL, 0), + MK_FLOW_ACTION(OF_COPY_TTL_OUT, 0), + MK_FLOW_ACTION(OF_COPY_TTL_IN, 0), }; static int diff --git a/lib/librte_ether/rte_flow.h b/lib/librte_ether/rte_flow.h index 2fde0f2136..b94ffb0c9c 100644 --- a/lib/librte_ether/rte_flow.h +++ b/lib/librte_ether/rte_flow.h @@ -1332,7 +1332,57 @@ enum rte_flow_action_type { * * See struct rte_flow_action_security. */ - RTE_FLOW_ACTION_TYPE_SECURITY + RTE_FLOW_ACTION_TYPE_SECURITY, + + /** + * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the + * OpenFlow Switch Specification. + * + * See struct rte_flow_action_of_set_mpls_ttl. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL, + + /** + * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined + * by the OpenFlow Switch Specification. + * + * No associated configuration structure. + */ + RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL, + + /** + * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow + * Switch Specification. + * + * See struct rte_flow_action_of_set_nw_ttl. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL, + + /** + * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by + * the OpenFlow Switch Specification. + * + * No associated configuration structure. + */ + RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL, + + /** + * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from + * next-to-outermost to outermost") as defined by the OpenFlow + * Switch Specification. + * + * No associated configuration structure. + */ + RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT, + + /** + * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from + * outermost to next-to-outermost") as defined by the OpenFlow + * Switch Specification. + * + * No associated configuration structure. + */ + RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN, }; /** @@ -1509,6 +1559,26 @@ struct rte_flow_action_security { void *security_session; /**< Pointer to security session structure. */ }; +/** + * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL + * + * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow + * Switch Specification. + */ +struct rte_flow_action_of_set_mpls_ttl { + uint8_t mpls_ttl; /**< MPLS TTL. */ +}; + +/** + * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL + * + * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch + * Specification. + */ +struct rte_flow_action_of_set_nw_ttl { + uint8_t nw_ttl; /**< IP TTL. */ +}; + /** * Definition of a single action. * -- 2.20.1