app/testpmd: add queue actions to flow command
[dpdk.git] / app / test-pmd / cmdline_flow.c
index 1f6a5a0..db680c6 100644 (file)
@@ -132,6 +132,20 @@ enum index {
        ITEM_IPV6,
        ITEM_IPV6_SRC,
        ITEM_IPV6_DST,
+       ITEM_ICMP,
+       ITEM_ICMP_TYPE,
+       ITEM_ICMP_CODE,
+       ITEM_UDP,
+       ITEM_UDP_SRC,
+       ITEM_UDP_DST,
+       ITEM_TCP,
+       ITEM_TCP_SRC,
+       ITEM_TCP_DST,
+       ITEM_SCTP,
+       ITEM_SCTP_SRC,
+       ITEM_SCTP_DST,
+       ITEM_VXLAN,
+       ITEM_VXLAN_VNI,
 
        /* Validate/create actions. */
        ACTIONS,
@@ -139,6 +153,22 @@ enum index {
        ACTION_END,
        ACTION_VOID,
        ACTION_PASSTHRU,
+       ACTION_MARK,
+       ACTION_MARK_ID,
+       ACTION_FLAG,
+       ACTION_QUEUE,
+       ACTION_QUEUE_INDEX,
+       ACTION_DROP,
+       ACTION_COUNT,
+       ACTION_DUP,
+       ACTION_DUP_INDEX,
+       ACTION_RSS,
+       ACTION_RSS_QUEUES,
+       ACTION_RSS_QUEUE,
+       ACTION_PF,
+       ACTION_VF,
+       ACTION_VF_ORIGINAL,
+       ACTION_VF_ID,
 };
 
 /** Size of pattern[] field in struct rte_flow_item_raw. */
@@ -148,6 +178,14 @@ enum index {
 #define ITEM_RAW_SIZE \
        (offsetof(struct rte_flow_item_raw, pattern) + ITEM_RAW_PATTERN_SIZE)
 
+/** Number of queue[] entries in struct rte_flow_action_rss. */
+#define ACTION_RSS_NUM 32
+
+/** Storage size for struct rte_flow_action_rss including queues. */
+#define ACTION_RSS_SIZE \
+       (offsetof(struct rte_flow_action_rss, queue) + \
+        sizeof(*((struct rte_flow_action_rss *)0)->queue) * ACTION_RSS_NUM)
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -359,6 +397,11 @@ static const enum index next_item[] = {
        ITEM_VLAN,
        ITEM_IPV4,
        ITEM_IPV6,
+       ITEM_ICMP,
+       ITEM_UDP,
+       ITEM_TCP,
+       ITEM_SCTP,
+       ITEM_VXLAN,
        ZERO,
 };
 
@@ -419,10 +462,84 @@ static const enum index item_ipv6[] = {
        ZERO,
 };
 
+static const enum index item_icmp[] = {
+       ITEM_ICMP_TYPE,
+       ITEM_ICMP_CODE,
+       ITEM_NEXT,
+       ZERO,
+};
+
+static const enum index item_udp[] = {
+       ITEM_UDP_SRC,
+       ITEM_UDP_DST,
+       ITEM_NEXT,
+       ZERO,
+};
+
+static const enum index item_tcp[] = {
+       ITEM_TCP_SRC,
+       ITEM_TCP_DST,
+       ITEM_NEXT,
+       ZERO,
+};
+
+static const enum index item_sctp[] = {
+       ITEM_SCTP_SRC,
+       ITEM_SCTP_DST,
+       ITEM_NEXT,
+       ZERO,
+};
+
+static const enum index item_vxlan[] = {
+       ITEM_VXLAN_VNI,
+       ITEM_NEXT,
+       ZERO,
+};
+
 static const enum index next_action[] = {
        ACTION_END,
        ACTION_VOID,
        ACTION_PASSTHRU,
+       ACTION_MARK,
+       ACTION_FLAG,
+       ACTION_QUEUE,
+       ACTION_DROP,
+       ACTION_COUNT,
+       ACTION_DUP,
+       ACTION_RSS,
+       ACTION_PF,
+       ACTION_VF,
+       ZERO,
+};
+
+static const enum index action_mark[] = {
+       ACTION_MARK_ID,
+       ACTION_NEXT,
+       ZERO,
+};
+
+static const enum index action_queue[] = {
+       ACTION_QUEUE_INDEX,
+       ACTION_NEXT,
+       ZERO,
+};
+
+static const enum index action_dup[] = {
+       ACTION_DUP_INDEX,
+       ACTION_NEXT,
+       ZERO,
+};
+
+static const enum index action_rss[] = {
+       ACTION_RSS_QUEUES,
+       ACTION_NEXT,
+       ZERO,
+};
+
+static const enum index action_vf[] = {
+       ACTION_VF_ORIGINAL,
+       ACTION_VF_ID,
+       ACTION_NEXT,
        ZERO,
 };
 
@@ -434,6 +551,11 @@ static int parse_vc(struct context *, const struct token *,
                    void *, unsigned int);
 static int parse_vc_spec(struct context *, const struct token *,
                         const char *, unsigned int, void *, unsigned int);
+static int parse_vc_conf(struct context *, const struct token *,
+                        const char *, unsigned int, void *, unsigned int);
+static int parse_vc_action_rss_queue(struct context *, const struct token *,
+                                    const char *, unsigned int, void *,
+                                    unsigned int);
 static int parse_destroy(struct context *, const struct token *,
                         const char *, unsigned int,
                         void *, unsigned int);
@@ -483,6 +605,8 @@ static int comp_port(struct context *, const struct token *,
                     unsigned int, char *, unsigned int);
 static int comp_rule_id(struct context *, const struct token *,
                        unsigned int, char *, unsigned int);
+static int comp_vc_action_rss_queue(struct context *, const struct token *,
+                                   unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -930,6 +1054,103 @@ static const struct token token_list[] = {
                .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
                                             hdr.dst_addr)),
        },
+       [ITEM_ICMP] = {
+               .name = "icmp",
+               .help = "match ICMP header",
+               .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
+               .next = NEXT(item_icmp),
+               .call = parse_vc,
+       },
+       [ITEM_ICMP_TYPE] = {
+               .name = "type",
+               .help = "ICMP packet type",
+               .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
+                                            hdr.icmp_type)),
+       },
+       [ITEM_ICMP_CODE] = {
+               .name = "code",
+               .help = "ICMP packet code",
+               .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
+                                            hdr.icmp_code)),
+       },
+       [ITEM_UDP] = {
+               .name = "udp",
+               .help = "match UDP header",
+               .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
+               .next = NEXT(item_udp),
+               .call = parse_vc,
+       },
+       [ITEM_UDP_SRC] = {
+               .name = "src",
+               .help = "UDP source port",
+               .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
+                                            hdr.src_port)),
+       },
+       [ITEM_UDP_DST] = {
+               .name = "dst",
+               .help = "UDP destination port",
+               .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
+                                            hdr.dst_port)),
+       },
+       [ITEM_TCP] = {
+               .name = "tcp",
+               .help = "match TCP header",
+               .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
+               .next = NEXT(item_tcp),
+               .call = parse_vc,
+       },
+       [ITEM_TCP_SRC] = {
+               .name = "src",
+               .help = "TCP source port",
+               .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
+                                            hdr.src_port)),
+       },
+       [ITEM_TCP_DST] = {
+               .name = "dst",
+               .help = "TCP destination port",
+               .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
+                                            hdr.dst_port)),
+       },
+       [ITEM_SCTP] = {
+               .name = "sctp",
+               .help = "match SCTP header",
+               .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
+               .next = NEXT(item_sctp),
+               .call = parse_vc,
+       },
+       [ITEM_SCTP_SRC] = {
+               .name = "src",
+               .help = "SCTP source port",
+               .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
+                                            hdr.src_port)),
+       },
+       [ITEM_SCTP_DST] = {
+               .name = "dst",
+               .help = "SCTP destination port",
+               .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
+                                            hdr.dst_port)),
+       },
+       [ITEM_VXLAN] = {
+               .name = "vxlan",
+               .help = "match VXLAN header",
+               .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
+               .next = NEXT(item_vxlan),
+               .call = parse_vc,
+       },
+       [ITEM_VXLAN_VNI] = {
+               .name = "vni",
+               .help = "VXLAN identifier",
+               .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
+               .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
+       },
        /* Validate/create actions. */
        [ACTIONS] = {
                .name = "actions",
@@ -962,6 +1183,118 @@ static const struct token token_list[] = {
                .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
                .call = parse_vc,
        },
+       [ACTION_MARK] = {
+               .name = "mark",
+               .help = "attach 32 bit value to packets",
+               .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
+               .next = NEXT(action_mark),
+               .call = parse_vc,
+       },
+       [ACTION_MARK_ID] = {
+               .name = "id",
+               .help = "32 bit value to return with packets",
+               .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_FLAG] = {
+               .name = "flag",
+               .help = "flag packets",
+               .priv = PRIV_ACTION(FLAG, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_QUEUE] = {
+               .name = "queue",
+               .help = "assign packets to a given queue index",
+               .priv = PRIV_ACTION(QUEUE,
+                                   sizeof(struct rte_flow_action_queue)),
+               .next = NEXT(action_queue),
+               .call = parse_vc,
+       },
+       [ACTION_QUEUE_INDEX] = {
+               .name = "index",
+               .help = "queue index to use",
+               .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_DROP] = {
+               .name = "drop",
+               .help = "drop packets (note: passthru has priority)",
+               .priv = PRIV_ACTION(DROP, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_COUNT] = {
+               .name = "count",
+               .help = "enable counters for this rule",
+               .priv = PRIV_ACTION(COUNT, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_DUP] = {
+               .name = "dup",
+               .help = "duplicate packets to a given queue index",
+               .priv = PRIV_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
+               .next = NEXT(action_dup),
+               .call = parse_vc,
+       },
+       [ACTION_DUP_INDEX] = {
+               .name = "index",
+               .help = "queue index to duplicate packets to",
+               .next = NEXT(action_dup, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_dup, index)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_RSS] = {
+               .name = "rss",
+               .help = "spread packets among several queues",
+               .priv = PRIV_ACTION(RSS, ACTION_RSS_SIZE),
+               .next = NEXT(action_rss),
+               .call = parse_vc,
+       },
+       [ACTION_RSS_QUEUES] = {
+               .name = "queues",
+               .help = "queue indices to use",
+               .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_RSS_QUEUE] = {
+               .name = "{queue}",
+               .help = "queue index",
+               .call = parse_vc_action_rss_queue,
+               .comp = comp_vc_action_rss_queue,
+       },
+       [ACTION_PF] = {
+               .name = "pf",
+               .help = "redirect packets to physical device function",
+               .priv = PRIV_ACTION(PF, 0),
+               .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+               .call = parse_vc,
+       },
+       [ACTION_VF] = {
+               .name = "vf",
+               .help = "redirect packets to virtual device function",
+               .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
+               .next = NEXT(action_vf),
+               .call = parse_vc,
+       },
+       [ACTION_VF_ORIGINAL] = {
+               .name = "original",
+               .help = "use original VF ID if possible",
+               .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
+               .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
+                                          original, 1)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_VF_ID] = {
+               .name = "id",
+               .help = "VF ID to redirect packets to",
+               .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
+               .call = parse_vc_conf,
+       },
 };
 
 /** Remove and return last entry from argument stack. */
@@ -1296,6 +1629,78 @@ parse_vc_spec(struct context *ctx, const struct token *token,
        return len;
 }
 
+/** Parse action configuration field. */
+static int
+parse_vc_conf(struct context *ctx, const struct token *token,
+             const char *str, unsigned int len,
+             void *buf, unsigned int size)
+{
+       struct buffer *out = buf;
+       struct rte_flow_action *action;
+
+       (void)size;
+       /* Token name must match. */
+       if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+               return -1;
+       /* Nothing else to do if there is no buffer. */
+       if (!out)
+               return len;
+       if (!out->args.vc.actions_n)
+               return -1;
+       action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+       /* Point to selected object. */
+       ctx->object = out->args.vc.data;
+       ctx->objmask = NULL;
+       /* Update configuration pointer. */
+       action->conf = ctx->object;
+       return len;
+}
+
+/**
+ * Parse queue field for RSS action.
+ *
+ * Valid tokens are queue indices and the "end" token.
+ */
+static int
+parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
+                         const char *str, unsigned int len,
+                         void *buf, unsigned int size)
+{
+       static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
+       int ret;
+       int i;
+
+       (void)token;
+       (void)buf;
+       (void)size;
+       if (ctx->curr != ACTION_RSS_QUEUE)
+               return -1;
+       i = ctx->objdata >> 16;
+       if (!strncmp(str, "end", len)) {
+               ctx->objdata &= 0xffff;
+               return len;
+       }
+       if (i >= ACTION_RSS_NUM)
+               return -1;
+       if (push_args(ctx, ARGS_ENTRY(struct rte_flow_action_rss, queue[i])))
+               return -1;
+       ret = parse_int(ctx, token, str, len, NULL, 0);
+       if (ret < 0) {
+               pop_args(ctx);
+               return -1;
+       }
+       ++i;
+       ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
+       /* Repeat token. */
+       if (ctx->next_num == RTE_DIM(ctx->next))
+               return -1;
+       ctx->next[ctx->next_num++] = next;
+       if (!ctx->object)
+               return len;
+       ((struct rte_flow_action_rss *)ctx->object)->num = i;
+       return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -1502,6 +1907,19 @@ objmask:
        case sizeof(uint16_t):
                *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
                break;
+       case sizeof(uint8_t [3]):
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+               if (!arg->hton) {
+                       ((uint8_t *)buf)[0] = u;
+                       ((uint8_t *)buf)[1] = u >> 8;
+                       ((uint8_t *)buf)[2] = u >> 16;
+                       break;
+               }
+#endif
+               ((uint8_t *)buf)[0] = u >> 16;
+               ((uint8_t *)buf)[1] = u >> 8;
+               ((uint8_t *)buf)[2] = u;
+               break;
        case sizeof(uint32_t):
                *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
                break;
@@ -1857,6 +2275,24 @@ comp_rule_id(struct context *ctx, const struct token *token,
        return i;
 }
 
+/** Complete queue field for RSS action. */
+static int
+comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
+                        unsigned int ent, char *buf, unsigned int size)
+{
+       static const char *const str[] = { "", "end", NULL };
+       unsigned int i;
+
+       (void)ctx;
+       (void)token;
+       for (i = 0; str[i] != NULL; ++i)
+               if (buf && i == ent)
+                       return snprintf(buf, size, "%s", str[i]);
+       if (buf)
+               return -1;
+       return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;