examples/ip_pipeline: add table entry delete command
[dpdk.git] / examples / ip_pipeline / thread.c
index 0291883..2532e09 100644 (file)
@@ -490,6 +490,8 @@ enum pipeline_req_type {
        PIPELINE_REQ_TABLE_STATS_READ,
        PIPELINE_REQ_TABLE_RULE_ADD,
        PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT,
+       PIPELINE_REQ_TABLE_RULE_DELETE,
+       PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT,
 
        PIPELINE_REQ_MAX
 };
@@ -515,6 +517,10 @@ struct pipeline_msg_req_table_rule_add_default {
        struct table_rule_action action;
 };
 
+struct pipeline_msg_req_table_rule_delete {
+       struct table_rule_match match;
+};
+
 struct pipeline_msg_req {
        enum pipeline_req_type type;
        uint32_t id; /* Port IN, port OUT or table ID */
@@ -526,6 +532,7 @@ struct pipeline_msg_req {
                struct pipeline_msg_req_table_stats_read table_stats_read;
                struct pipeline_msg_req_table_rule_add table_rule_add;
                struct pipeline_msg_req_table_rule_add_default table_rule_add_default;
+               struct pipeline_msg_req_table_rule_delete table_rule_delete;
        };
 };
 
@@ -1096,6 +1103,94 @@ pipeline_table_rule_add_default(const char *pipeline_name,
        return status;
 }
 
+int
+pipeline_table_rule_delete(const char *pipeline_name,
+       uint32_t table_id,
+       struct table_rule_match *match)
+{
+       struct pipeline *p;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       int status;
+
+       /* Check input params */
+       if ((pipeline_name == NULL) ||
+               (match == NULL))
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (p->enabled == 0) ||
+               (table_id >= p->n_tables) ||
+               match_check(match, p, table_id))
+               return -1;
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_TABLE_RULE_DELETE;
+       req->id = table_id;
+       memcpy(&req->table_rule_delete.match, match, sizeof(*match));
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+       if (rsp == NULL)
+               return -1;
+
+       /* Read response */
+       status = rsp->status;
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
+
+int
+pipeline_table_rule_delete_default(const char *pipeline_name,
+       uint32_t table_id)
+{
+       struct pipeline *p;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       int status;
+
+       /* Check input params */
+       if (pipeline_name == NULL)
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (p->enabled == 0) ||
+               (table_id >= p->n_tables))
+               return -1;
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT;
+       req->id = table_id;
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+       if (rsp == NULL)
+               return -1;
+
+       /* Read response */
+       status = rsp->status;
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
+
 /**
  * Data plane threads: message handling
  */
@@ -1652,6 +1747,45 @@ pipeline_msg_handle_table_rule_add_default(struct pipeline_data *p,
        return rsp;
 }
 
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_table_rule_delete(struct pipeline_data *p,
+       struct pipeline_msg_req *req)
+{
+       union table_rule_match_low_level match_ll;
+       struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
+       struct table_rule_match *match = &req->table_rule_delete.match;
+       uint32_t table_id = req->id;
+       int key_found, status;
+
+       status = match_convert(match, &match_ll, 0);
+       if (status) {
+               rsp->status = -1;
+               return rsp;
+       }
+
+       rsp->status = rte_pipeline_table_entry_delete(p->p,
+               table_id,
+               &match_ll,
+               &key_found,
+               NULL);
+
+       return rsp;
+}
+
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_table_rule_delete_default(struct pipeline_data *p,
+       struct pipeline_msg_req *req)
+{
+       struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
+       uint32_t table_id = req->id;
+
+       rsp->status = rte_pipeline_table_default_entry_delete(p->p,
+               table_id,
+               NULL);
+
+       return rsp;
+}
+
 static void
 pipeline_msg_handle(struct pipeline_data *p)
 {
@@ -1692,6 +1826,14 @@ pipeline_msg_handle(struct pipeline_data *p)
                        rsp = pipeline_msg_handle_table_rule_add_default(p,     req);
                        break;
 
+               case PIPELINE_REQ_TABLE_RULE_DELETE:
+                       rsp = pipeline_msg_handle_table_rule_delete(p, req);
+                       break;
+
+               case PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT:
+                       rsp = pipeline_msg_handle_table_rule_delete_default(p, req);
+                       break;
+
                default:
                        rsp = (struct pipeline_msg_rsp *) req;
                        rsp->status = -1;