examples/ip_pipeline: track table rules on add
Support table rule tracking on table rule add operation. Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com> Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
This commit is contained in:
parent
35c10b587d
commit
4c65163ec2
@ -4321,7 +4321,6 @@ cmd_pipeline_table_rule_add(char **tokens,
|
|||||||
struct table_rule_match m;
|
struct table_rule_match m;
|
||||||
struct table_rule_action a;
|
struct table_rule_action a;
|
||||||
char *pipeline_name;
|
char *pipeline_name;
|
||||||
void *data;
|
|
||||||
uint32_t table_id, t0, n_tokens_parsed;
|
uint32_t table_id, t0, n_tokens_parsed;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -4379,8 +4378,7 @@ cmd_pipeline_table_rule_add(char **tokens,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pipeline_table_rule_add(pipeline_name, table_id,
|
status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
|
||||||
&m, &a, &data);
|
|
||||||
if (status) {
|
if (status) {
|
||||||
snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
|
snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
|
||||||
return;
|
return;
|
||||||
|
@ -329,8 +329,7 @@ int
|
|||||||
pipeline_table_rule_add(const char *pipeline_name,
|
pipeline_table_rule_add(const char *pipeline_name,
|
||||||
uint32_t table_id,
|
uint32_t table_id,
|
||||||
struct table_rule_match *match,
|
struct table_rule_match *match,
|
||||||
struct table_rule_action *action,
|
struct table_rule_action *action);
|
||||||
void **data);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
pipeline_table_rule_add_bulk(const char *pipeline_name,
|
pipeline_table_rule_add_bulk(const char *pipeline_name,
|
||||||
|
@ -1210,19 +1210,19 @@ int
|
|||||||
pipeline_table_rule_add(const char *pipeline_name,
|
pipeline_table_rule_add(const char *pipeline_name,
|
||||||
uint32_t table_id,
|
uint32_t table_id,
|
||||||
struct table_rule_match *match,
|
struct table_rule_match *match,
|
||||||
struct table_rule_action *action,
|
struct table_rule_action *action)
|
||||||
void **data)
|
|
||||||
{
|
{
|
||||||
struct pipeline *p;
|
struct pipeline *p;
|
||||||
|
struct table *table;
|
||||||
struct pipeline_msg_req *req;
|
struct pipeline_msg_req *req;
|
||||||
struct pipeline_msg_rsp *rsp;
|
struct pipeline_msg_rsp *rsp;
|
||||||
|
struct table_rule *rule;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
/* Check input params */
|
/* Check input params */
|
||||||
if ((pipeline_name == NULL) ||
|
if ((pipeline_name == NULL) ||
|
||||||
(match == NULL) ||
|
(match == NULL) ||
|
||||||
(action == NULL) ||
|
(action == NULL))
|
||||||
(data == NULL))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
p = pipeline_find(pipeline_name);
|
p = pipeline_find(pipeline_name);
|
||||||
@ -1232,16 +1232,26 @@ pipeline_table_rule_add(const char *pipeline_name,
|
|||||||
action_check(action, p, table_id))
|
action_check(action, p, table_id))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
table = &p->table[table_id];
|
||||||
|
|
||||||
|
rule = calloc(1, sizeof(struct table_rule));
|
||||||
|
if (rule == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(&rule->match, match, sizeof(*match));
|
||||||
|
memcpy(&rule->action, action, sizeof(*action));
|
||||||
|
|
||||||
if (!pipeline_is_running(p)) {
|
if (!pipeline_is_running(p)) {
|
||||||
struct rte_table_action *a = p->table[table_id].a;
|
|
||||||
union table_rule_match_low_level match_ll;
|
union table_rule_match_low_level match_ll;
|
||||||
struct rte_pipeline_table_entry *data_in, *data_out;
|
struct rte_pipeline_table_entry *data_in, *data_out;
|
||||||
int key_found;
|
int key_found;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
|
|
||||||
buffer = calloc(TABLE_RULE_ACTION_SIZE_MAX, sizeof(uint8_t));
|
buffer = calloc(TABLE_RULE_ACTION_SIZE_MAX, sizeof(uint8_t));
|
||||||
if (buffer == NULL)
|
if (buffer == NULL) {
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Table match-action rule conversion */
|
/* Table match-action rule conversion */
|
||||||
data_in = (struct rte_pipeline_table_entry *)buffer;
|
data_in = (struct rte_pipeline_table_entry *)buffer;
|
||||||
@ -1249,12 +1259,14 @@ pipeline_table_rule_add(const char *pipeline_name,
|
|||||||
status = match_convert(match, &match_ll, 1);
|
status = match_convert(match, &match_ll, 1);
|
||||||
if (status) {
|
if (status) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = action_convert(a, action, data_in);
|
status = action_convert(table->a, action, data_in);
|
||||||
if (status) {
|
if (status) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1267,11 +1279,13 @@ pipeline_table_rule_add(const char *pipeline_name,
|
|||||||
&data_out);
|
&data_out);
|
||||||
if (status) {
|
if (status) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write Response */
|
/* Write Response */
|
||||||
*data = data_out;
|
rule->data = data_out;
|
||||||
|
table_rule_add(table, rule);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1279,8 +1293,10 @@ pipeline_table_rule_add(const char *pipeline_name,
|
|||||||
|
|
||||||
/* Allocate request */
|
/* Allocate request */
|
||||||
req = pipeline_msg_alloc();
|
req = pipeline_msg_alloc();
|
||||||
if (req == NULL)
|
if (req == NULL) {
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Write request */
|
/* Write request */
|
||||||
req->type = PIPELINE_REQ_TABLE_RULE_ADD;
|
req->type = PIPELINE_REQ_TABLE_RULE_ADD;
|
||||||
@ -1290,13 +1306,18 @@ pipeline_table_rule_add(const char *pipeline_name,
|
|||||||
|
|
||||||
/* Send request and wait for response */
|
/* Send request and wait for response */
|
||||||
rsp = pipeline_msg_send_recv(p, req);
|
rsp = pipeline_msg_send_recv(p, req);
|
||||||
if (rsp == NULL)
|
if (rsp == NULL) {
|
||||||
|
free(rule);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read response */
|
/* Read response */
|
||||||
status = rsp->status;
|
status = rsp->status;
|
||||||
if (status == 0)
|
if (status == 0) {
|
||||||
*data = rsp->table_rule_add.data;
|
rule->data = rsp->table_rule_add.data;
|
||||||
|
table_rule_add(table, rule);
|
||||||
|
} else
|
||||||
|
free(rule);
|
||||||
|
|
||||||
/* Free response */
|
/* Free response */
|
||||||
pipeline_msg_free(rsp);
|
pipeline_msg_free(rsp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user