COMMON_FLEX_TOKEN,
COMMON_PATTERN_TEMPLATE_ID,
COMMON_ACTIONS_TEMPLATE_ID,
+ COMMON_TABLE_ID,
/* TOP-level command. */
ADD,
CONFIGURE,
PATTERN_TEMPLATE,
ACTIONS_TEMPLATE,
+ TABLE,
INDIRECT_ACTION,
VALIDATE,
CREATE,
ACTIONS_TEMPLATE_SPEC,
ACTIONS_TEMPLATE_MASK,
+ /* Table arguments. */
+ TABLE_CREATE,
+ TABLE_DESTROY,
+ TABLE_CREATE_ID,
+ TABLE_DESTROY_ID,
+ TABLE_GROUP,
+ TABLE_PRIORITY,
+ TABLE_INGRESS,
+ TABLE_EGRESS,
+ TABLE_TRANSFER,
+ TABLE_RULES_NUMBER,
+ TABLE_PATTERN_TEMPLATE,
+ TABLE_ACTIONS_TEMPLATE,
+
/* Tunnel arguments. */
TUNNEL_CREATE,
TUNNEL_CREATE_TYPE,
uint32_t *template_id;
uint32_t template_id_n;
} templ_destroy; /**< Template destroy arguments. */
+ struct {
+ uint32_t id;
+ struct rte_flow_template_table_attr attr;
+ uint32_t *pat_templ_id;
+ uint32_t pat_templ_id_n;
+ uint32_t *act_templ_id;
+ uint32_t act_templ_id_n;
+ } table; /**< Table arguments. */
+ struct {
+ uint32_t *table_id;
+ uint32_t table_id_n;
+ } table_destroy; /**< Template destroy arguments. */
struct {
uint32_t *action_id;
uint32_t action_id_n;
ZERO,
};
+static const enum index next_table_subcmd[] = {
+ TABLE_CREATE,
+ TABLE_DESTROY,
+ ZERO,
+};
+
+static const enum index next_table_attr[] = {
+ TABLE_CREATE_ID,
+ TABLE_GROUP,
+ TABLE_PRIORITY,
+ TABLE_INGRESS,
+ TABLE_EGRESS,
+ TABLE_TRANSFER,
+ TABLE_RULES_NUMBER,
+ TABLE_PATTERN_TEMPLATE,
+ TABLE_ACTIONS_TEMPLATE,
+ END,
+ ZERO,
+};
+
+static const enum index next_table_destroy_attr[] = {
+ TABLE_DESTROY_ID,
+ END,
+ ZERO,
+};
+
static const enum index next_ia_create_attr[] = {
INDIRECT_ACTION_CREATE_ID,
INDIRECT_ACTION_INGRESS,
static int parse_template_destroy(struct context *, const struct token *,
const char *, unsigned int,
void *, unsigned int);
+static int parse_table(struct context *, const struct token *,
+ const char *, unsigned int, void *, unsigned int);
+static int parse_table_destroy(struct context *, const struct token *,
+ const char *, unsigned int,
+ void *, unsigned int);
static int parse_tunnel(struct context *, const struct token *,
const char *, unsigned int,
void *, unsigned int);
unsigned int, char *, unsigned int);
static int comp_actions_template_id(struct context *, const struct token *,
unsigned int, char *, unsigned int);
+static int comp_table_id(struct context *, const struct token *,
+ unsigned int, char *, unsigned int);
/** Token definitions. */
static const struct token token_list[] = {
.call = parse_int,
.comp = comp_actions_template_id,
},
+ [COMMON_TABLE_ID] = {
+ .name = "{table_id}",
+ .type = "TABLE_ID",
+ .help = "table id",
+ .call = parse_int,
+ .comp = comp_table_id,
+ },
/* Top-level command. */
[FLOW] = {
.name = "flow",
CONFIGURE,
PATTERN_TEMPLATE,
ACTIONS_TEMPLATE,
+ TABLE,
INDIRECT_ACTION,
VALIDATE,
CREATE,
.call = parse_template,
},
/* Top-level command. */
+ [TABLE] = {
+ .name = "template_table",
+ .type = "{command} {port_id} [{arg} [...]]",
+ .help = "manage template tables",
+ .next = NEXT(next_table_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+ .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+ .call = parse_table,
+ },
+ /* Sub-level commands. */
+ [TABLE_CREATE] = {
+ .name = "create",
+ .help = "create template table",
+ .next = NEXT(next_table_attr),
+ .call = parse_table,
+ },
+ [TABLE_DESTROY] = {
+ .name = "destroy",
+ .help = "destroy template table",
+ .next = NEXT(NEXT_ENTRY(TABLE_DESTROY_ID)),
+ .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+ .call = parse_table_destroy,
+ },
+ /* Table arguments. */
+ [TABLE_CREATE_ID] = {
+ .name = "table_id",
+ .help = "specify table id to create",
+ .next = NEXT(next_table_attr,
+ NEXT_ENTRY(COMMON_TABLE_ID)),
+ .args = ARGS(ARGS_ENTRY(struct buffer, args.table.id)),
+ },
+ [TABLE_DESTROY_ID] = {
+ .name = "table",
+ .help = "specify table id to destroy",
+ .next = NEXT(next_table_destroy_attr,
+ NEXT_ENTRY(COMMON_TABLE_ID)),
+ .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+ args.table_destroy.table_id)),
+ .call = parse_table_destroy,
+ },
+ [TABLE_GROUP] = {
+ .name = "group",
+ .help = "specify a group",
+ .next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
+ .args = ARGS(ARGS_ENTRY(struct buffer,
+ args.table.attr.flow_attr.group)),
+ },
+ [TABLE_PRIORITY] = {
+ .name = "priority",
+ .help = "specify a priority level",
+ .next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_PRIORITY_LEVEL)),
+ .args = ARGS(ARGS_ENTRY(struct buffer,
+ args.table.attr.flow_attr.priority)),
+ },
+ [TABLE_EGRESS] = {
+ .name = "egress",
+ .help = "affect rule to egress",
+ .next = NEXT(next_table_attr),
+ .call = parse_table,
+ },
+ [TABLE_INGRESS] = {
+ .name = "ingress",
+ .help = "affect rule to ingress",
+ .next = NEXT(next_table_attr),
+ .call = parse_table,
+ },
+ [TABLE_TRANSFER] = {
+ .name = "transfer",
+ .help = "affect rule to transfer",
+ .next = NEXT(next_table_attr),
+ .call = parse_table,
+ },
+ [TABLE_RULES_NUMBER] = {
+ .name = "rules_number",
+ .help = "number of rules in table",
+ .next = NEXT(next_table_attr,
+ NEXT_ENTRY(COMMON_UNSIGNED)),
+ .args = ARGS(ARGS_ENTRY(struct buffer,
+ args.table.attr.nb_flows)),
+ },
+ [TABLE_PATTERN_TEMPLATE] = {
+ .name = "pattern_template",
+ .help = "specify pattern template id",
+ .next = NEXT(next_table_attr,
+ NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
+ .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+ args.table.pat_templ_id)),
+ .call = parse_table,
+ },
+ [TABLE_ACTIONS_TEMPLATE] = {
+ .name = "actions_template",
+ .help = "specify actions template id",
+ .next = NEXT(next_table_attr,
+ NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
+ .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+ args.table.act_templ_id)),
+ .call = parse_table,
+ },
+ /* Top-level command. */
[INDIRECT_ACTION] = {
.name = "indirect_action",
.type = "{command} {port_id} [{arg} [...]]",
return len;
}
+/** Parse tokens for table create command. */
+static int
+parse_table(struct context *ctx, const struct token *token,
+ const char *str, unsigned int len,
+ void *buf, unsigned int size)
+{
+ struct buffer *out = buf;
+ uint32_t *template_id;
+
+ /* 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->command) {
+ if (ctx->curr != TABLE)
+ return -1;
+ if (sizeof(*out) > size)
+ return -1;
+ out->command = ctx->curr;
+ ctx->objdata = 0;
+ ctx->object = out;
+ ctx->objmask = NULL;
+ return len;
+ }
+ switch (ctx->curr) {
+ case TABLE_CREATE:
+ out->command = ctx->curr;
+ ctx->objdata = 0;
+ ctx->object = out;
+ ctx->objmask = NULL;
+ out->args.table.id = UINT32_MAX;
+ return len;
+ case TABLE_PATTERN_TEMPLATE:
+ out->args.table.pat_templ_id =
+ (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+ sizeof(double));
+ template_id = out->args.table.pat_templ_id
+ + out->args.table.pat_templ_id_n++;
+ if ((uint8_t *)template_id > (uint8_t *)out + size)
+ return -1;
+ ctx->objdata = 0;
+ ctx->object = template_id;
+ ctx->objmask = NULL;
+ return len;
+ case TABLE_ACTIONS_TEMPLATE:
+ out->args.table.act_templ_id =
+ (void *)RTE_ALIGN_CEIL((uintptr_t)
+ (out->args.table.pat_templ_id +
+ out->args.table.pat_templ_id_n),
+ sizeof(double));
+ template_id = out->args.table.act_templ_id
+ + out->args.table.act_templ_id_n++;
+ if ((uint8_t *)template_id > (uint8_t *)out + size)
+ return -1;
+ ctx->objdata = 0;
+ ctx->object = template_id;
+ ctx->objmask = NULL;
+ return len;
+ case TABLE_INGRESS:
+ out->args.table.attr.flow_attr.ingress = 1;
+ return len;
+ case TABLE_EGRESS:
+ out->args.table.attr.flow_attr.egress = 1;
+ return len;
+ case TABLE_TRANSFER:
+ out->args.table.attr.flow_attr.transfer = 1;
+ return len;
+ default:
+ return -1;
+ }
+}
+
+/** Parse tokens for table destroy command. */
+static int
+parse_table_destroy(struct context *ctx, const struct token *token,
+ const char *str, unsigned int len,
+ void *buf, unsigned int size)
+{
+ struct buffer *out = buf;
+ uint32_t *table_id;
+
+ /* 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->command || out->command == TABLE) {
+ if (ctx->curr != TABLE_DESTROY)
+ return -1;
+ if (sizeof(*out) > size)
+ return -1;
+ out->command = ctx->curr;
+ ctx->objdata = 0;
+ ctx->object = out;
+ ctx->objmask = NULL;
+ out->args.table_destroy.table_id =
+ (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+ sizeof(double));
+ return len;
+ }
+ table_id = out->args.table_destroy.table_id
+ + out->args.table_destroy.table_id_n++;
+ if ((uint8_t *)table_id > (uint8_t *)out + size)
+ return -1;
+ ctx->objdata = 0;
+ ctx->object = table_id;
+ ctx->objmask = NULL;
+ return len;
+}
+
static int
parse_flex(struct context *ctx, const struct token *token,
const char *str, unsigned int len,
return i;
}
+/** Complete available table IDs. */
+static int
+comp_table_id(struct context *ctx, const struct token *token,
+ unsigned int ent, char *buf, unsigned int size)
+{
+ unsigned int i = 0;
+ struct rte_port *port;
+ struct port_table *pt;
+
+ (void)token;
+ if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+ ctx->port == (portid_t)RTE_PORT_ALL)
+ return -1;
+ port = &ports[ctx->port];
+ for (pt = port->table_list; pt != NULL; pt = pt->next) {
+ if (buf && i == ent)
+ return snprintf(buf, size, "%u", pt->id);
+ ++i;
+ }
+ if (buf)
+ return -1;
+ return i;
+}
+
/** Internal context. */
static struct context cmd_flow_context;
in->args.templ_destroy.template_id_n,
in->args.templ_destroy.template_id);
break;
+ case TABLE_CREATE:
+ port_flow_template_table_create(in->port, in->args.table.id,
+ &in->args.table.attr, in->args.table.pat_templ_id_n,
+ in->args.table.pat_templ_id, in->args.table.act_templ_id_n,
+ in->args.table.act_templ_id);
+ break;
+ case TABLE_DESTROY:
+ port_flow_template_table_destroy(in->port,
+ in->args.table_destroy.table_id_n,
+ in->args.table_destroy.table_id);
+ break;
case INDIRECT_ACTION_CREATE:
port_action_handle_create(
in->port, in->args.vc.attr.group,
return 0;
}
+static int
+table_alloc(uint32_t id, struct port_table **table,
+ struct port_table **list)
+{
+ struct port_table *lst = *list;
+ struct port_table **ppt;
+ struct port_table *pt = NULL;
+
+ *table = NULL;
+ if (id == UINT32_MAX) {
+ /* taking first available ID */
+ if (lst) {
+ if (lst->id == UINT32_MAX - 1) {
+ printf("Highest table ID is already"
+ " assigned, delete it first\n");
+ return -ENOMEM;
+ }
+ id = lst->id + 1;
+ } else {
+ id = 0;
+ }
+ }
+ pt = calloc(1, sizeof(*pt));
+ if (!pt) {
+ printf("Allocation of table failed\n");
+ return -ENOMEM;
+ }
+ ppt = list;
+ while (*ppt && (*ppt)->id > id)
+ ppt = &(*ppt)->next;
+ if (*ppt && (*ppt)->id == id) {
+ printf("Table #%u is already assigned,"
+ " delete it first\n", id);
+ free(pt);
+ return -EINVAL;
+ }
+ pt->next = *ppt;
+ pt->id = id;
+ *ppt = pt;
+ *table = pt;
+ return 0;
+}
+
/** Get info about flow management resources. */
int
port_flow_get_info(portid_t port_id)
return ret;
}
+/** Create table */
+int
+port_flow_template_table_create(portid_t port_id, uint32_t id,
+ const struct rte_flow_template_table_attr *table_attr,
+ uint32_t nb_pattern_templates, uint32_t *pattern_templates,
+ uint32_t nb_actions_templates, uint32_t *actions_templates)
+{
+ struct rte_port *port;
+ struct port_table *pt;
+ struct port_template *temp = NULL;
+ int ret;
+ uint32_t i;
+ struct rte_flow_error error;
+ struct rte_flow_pattern_template
+ *flow_pattern_templates[nb_pattern_templates];
+ struct rte_flow_actions_template
+ *flow_actions_templates[nb_actions_templates];
+
+ if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+ port_id == (portid_t)RTE_PORT_ALL)
+ return -EINVAL;
+ port = &ports[port_id];
+ for (i = 0; i < nb_pattern_templates; ++i) {
+ bool found = false;
+ temp = port->pattern_templ_list;
+ while (temp) {
+ if (pattern_templates[i] == temp->id) {
+ flow_pattern_templates[i] =
+ temp->template.pattern_template;
+ found = true;
+ break;
+ }
+ temp = temp->next;
+ }
+ if (!found) {
+ printf("Pattern template #%u is invalid\n",
+ pattern_templates[i]);
+ return -EINVAL;
+ }
+ }
+ for (i = 0; i < nb_actions_templates; ++i) {
+ bool found = false;
+ temp = port->actions_templ_list;
+ while (temp) {
+ if (actions_templates[i] == temp->id) {
+ flow_actions_templates[i] =
+ temp->template.actions_template;
+ found = true;
+ break;
+ }
+ temp = temp->next;
+ }
+ if (!found) {
+ printf("Actions template #%u is invalid\n",
+ actions_templates[i]);
+ return -EINVAL;
+ }
+ }
+ ret = table_alloc(id, &pt, &port->table_list);
+ if (ret)
+ return ret;
+ /* Poisoning to make sure PMDs update it in case of error. */
+ memset(&error, 0x22, sizeof(error));
+ pt->table = rte_flow_template_table_create(port_id, table_attr,
+ flow_pattern_templates, nb_pattern_templates,
+ flow_actions_templates, nb_actions_templates,
+ &error);
+
+ if (!pt->table) {
+ uint32_t destroy_id = pt->id;
+ port_flow_template_table_destroy(port_id, 1, &destroy_id);
+ return port_flow_complain(&error);
+ }
+ pt->nb_pattern_templates = nb_pattern_templates;
+ pt->nb_actions_templates = nb_actions_templates;
+ printf("Template table #%u created\n", pt->id);
+ return 0;
+}
+
+/** Destroy table */
+int
+port_flow_template_table_destroy(portid_t port_id,
+ uint32_t n, const uint32_t *table)
+{
+ struct rte_port *port;
+ struct port_table **tmp;
+ uint32_t c = 0;
+ int ret = 0;
+
+ if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+ port_id == (portid_t)RTE_PORT_ALL)
+ return -EINVAL;
+ port = &ports[port_id];
+ tmp = &port->table_list;
+ while (*tmp) {
+ uint32_t i;
+
+ for (i = 0; i != n; ++i) {
+ struct rte_flow_error error;
+ struct port_table *pt = *tmp;
+
+ if (table[i] != pt->id)
+ continue;
+ /*
+ * Poisoning to make sure PMDs update it in case
+ * of error.
+ */
+ memset(&error, 0x33, sizeof(error));
+
+ if (pt->table &&
+ rte_flow_template_table_destroy(port_id,
+ pt->table,
+ &error)) {
+ ret = port_flow_complain(&error);
+ continue;
+ }
+ *tmp = pt->next;
+ printf("Template table #%u destroyed\n", pt->id);
+ free(pt);
+ break;
+ }
+ if (i == n)
+ tmp = &(*tmp)->next;
+ ++c;
+ }
+ return ret;
+}
+
/** Create flow rule. */
int
port_flow_create(portid_t port_id,