app/testpmd: support metadata as flow rule item
[dpdk.git] / app / test-pmd / cmdline_flow.c
index a9888ca..7932b54 100644 (file)
@@ -178,6 +178,8 @@ enum index {
        ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
        ITEM_ICMP6_ND_OPT_TLA_ETH,
        ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
+       ITEM_META,
+       ITEM_META_DATA,
 
        /* Validate/create actions. */
        ACTIONS,
@@ -255,6 +257,14 @@ enum index {
        ACTION_SET_TP_SRC_TP_SRC,
        ACTION_SET_TP_DST,
        ACTION_SET_TP_DST_TP_DST,
+       ACTION_MAC_SWAP,
+       ACTION_DEC_TTL,
+       ACTION_SET_TTL,
+       ACTION_SET_TTL_TTL,
+       ACTION_SET_MAC_SRC,
+       ACTION_SET_MAC_SRC_MAC_SRC,
+       ACTION_SET_MAC_DST,
+       ACTION_SET_MAC_DST_MAC_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -538,6 +548,11 @@ static const enum index item_param[] = {
        ZERO,
 };
 
+static const enum index item_param_is[] = {
+       ITEM_PARAM_IS,
+       ZERO,
+};
+
 static const enum index next_item[] = {
        ITEM_END,
        ITEM_VOID,
@@ -576,6 +591,7 @@ static const enum index next_item[] = {
        ITEM_ICMP6_ND_OPT,
        ITEM_ICMP6_ND_OPT_SLA_ETH,
        ITEM_ICMP6_ND_OPT_TLA_ETH,
+       ITEM_META,
        ZERO,
 };
 
@@ -796,6 +812,12 @@ static const enum index item_icmp6_nd_opt_tla_eth[] = {
        ZERO,
 };
 
+static const enum index item_meta[] = {
+       ITEM_META_DATA,
+       ITEM_NEXT,
+       ZERO,
+};
+
 static const enum index next_action[] = {
        ACTION_END,
        ACTION_VOID,
@@ -834,6 +856,11 @@ static const enum index next_action[] = {
        ACTION_SET_IPV6_DST,
        ACTION_SET_TP_SRC,
        ACTION_SET_TP_DST,
+       ACTION_MAC_SWAP,
+       ACTION_DEC_TTL,
+       ACTION_SET_TTL,
+       ACTION_SET_MAC_SRC,
+       ACTION_SET_MAC_DST,
        ZERO,
 };
 
@@ -942,6 +969,12 @@ static const enum index action_set_ipv4_src[] = {
        ZERO,
 };
 
+static const enum index action_set_mac_src[] = {
+       ACTION_SET_MAC_SRC_MAC_SRC,
+       ACTION_NEXT,
+       ZERO,
+};
+
 static const enum index action_set_ipv4_dst[] = {
        ACTION_SET_IPV4_DST_IPV4_DST,
        ACTION_NEXT,
@@ -972,12 +1005,24 @@ static const enum index action_set_tp_dst[] = {
        ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+       ACTION_SET_TTL_TTL,
+       ACTION_NEXT,
+       ZERO,
+};
+
 static const enum index action_jump[] = {
        ACTION_JUMP_GROUP,
        ACTION_NEXT,
        ZERO,
 };
 
+static const enum index action_set_mac_dst[] = {
+       ACTION_SET_MAC_DST_MAC_DST,
+       ACTION_NEXT,
+       ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
                      const char *, unsigned int,
                      void *, unsigned int);
@@ -2039,6 +2084,20 @@ static const struct token token_list[] = {
                .args = ARGS(ARGS_ENTRY_HTON
                             (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
        },
+       [ITEM_META] = {
+               .name = "meta",
+               .help = "match metadata header",
+               .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
+               .next = NEXT(item_meta),
+               .call = parse_vc,
+       },
+       [ITEM_META_DATA] = {
+               .name = "data",
+               .help = "metadata value",
+               .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param_is),
+               .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_meta,
+                                                 data, "\xff\xff\xff\xff")),
+       },
 
        /* Validate/create actions. */
        [ACTIONS] = {
@@ -2626,6 +2685,69 @@ static const struct token token_list[] = {
                             (struct rte_flow_action_set_tp, port)),
                .call = parse_vc_conf,
        },
+       [ACTION_MAC_SWAP] = {
+               .name = "mac_swap",
+               .help = "Swap the source and destination MAC addresses"
+                       " in the outermost Ethernet header",
+               .priv = PRIV_ACTION(MAC_SWAP, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_DEC_TTL] = {
+               .name = "dec_ttl",
+               .help = "decrease network TTL if available",
+               .priv = PRIV_ACTION(DEC_TTL, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_SET_TTL] = {
+               .name = "set_ttl",
+               .help = "set ttl value",
+               .priv = PRIV_ACTION(SET_TTL,
+                       sizeof(struct rte_flow_action_set_ttl)),
+               .next = NEXT(action_set_ttl),
+               .call = parse_vc,
+       },
+       [ACTION_SET_TTL_TTL] = {
+               .name = "ttl_value",
+               .help = "new ttl value to set",
+               .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY_HTON
+                            (struct rte_flow_action_set_ttl, ttl_value)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_SET_MAC_SRC] = {
+               .name = "set_mac_src",
+               .help = "set source mac address",
+               .priv = PRIV_ACTION(SET_MAC_SRC,
+                       sizeof(struct rte_flow_action_set_mac)),
+               .next = NEXT(action_set_mac_src),
+               .call = parse_vc,
+       },
+       [ACTION_SET_MAC_SRC_MAC_SRC] = {
+               .name = "mac_addr",
+               .help = "new source mac address",
+               .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+               .args = ARGS(ARGS_ENTRY_HTON
+                            (struct rte_flow_action_set_mac, mac_addr)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_SET_MAC_DST] = {
+               .name = "set_mac_dst",
+               .help = "set destination mac address",
+               .priv = PRIV_ACTION(SET_MAC_DST,
+                       sizeof(struct rte_flow_action_set_mac)),
+               .next = NEXT(action_set_mac_dst),
+               .call = parse_vc,
+       },
+       [ACTION_SET_MAC_DST_MAC_DST] = {
+               .name = "mac_addr",
+               .help = "new destination mac address to set",
+               .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+               .args = ARGS(ARGS_ENTRY_HTON
+                            (struct rte_flow_action_set_mac, mac_addr)),
+               .call = parse_vc_conf,
+       },
 };
 
 /** Remove and return last entry from argument stack. */