examples/ip_pipeline: remove check of null response
[dpdk.git] / examples / ip_pipeline / thread.c
index e1142d9..adb8316 100644 (file)
@@ -325,8 +325,6 @@ thread_pipeline_enable(uint32_t thread_id,
 
        /* Send request and wait for response */
        rsp = thread_msg_send_recv(thread_id, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -412,8 +410,6 @@ thread_pipeline_disable(uint32_t thread_id,
 
        /* Send request and wait for response */
        rsp = thread_msg_send_recv(thread_id, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -584,6 +580,7 @@ enum pipeline_req_type {
        PIPELINE_REQ_TABLE_RULE_MTR_READ,
        PIPELINE_REQ_TABLE_DSCP_TABLE_UPDATE,
        PIPELINE_REQ_TABLE_RULE_TTL_READ,
+       PIPELINE_REQ_TABLE_RULE_TIME_READ,
        PIPELINE_REQ_MAX
 };
 
@@ -647,6 +644,10 @@ struct pipeline_msg_req_table_rule_ttl_read {
        int clear;
 };
 
+struct pipeline_msg_req_table_rule_time_read {
+       void *data;
+};
+
 struct pipeline_msg_req {
        enum pipeline_req_type type;
        uint32_t id; /* Port IN, port OUT or table ID */
@@ -666,6 +667,7 @@ struct pipeline_msg_req {
                struct pipeline_msg_req_table_rule_mtr_read table_rule_mtr_read;
                struct pipeline_msg_req_table_dscp_table_update table_dscp_table_update;
                struct pipeline_msg_req_table_rule_ttl_read table_rule_ttl_read;
+               struct pipeline_msg_req_table_rule_time_read table_rule_time_read;
        };
 };
 
@@ -705,6 +707,10 @@ struct pipeline_msg_rsp_table_rule_ttl_read {
        struct rte_table_action_ttl_counters stats;
 };
 
+struct pipeline_msg_rsp_table_rule_time_read {
+       uint64_t timestamp;
+};
+
 struct pipeline_msg_rsp {
        int status;
 
@@ -719,6 +725,7 @@ struct pipeline_msg_rsp {
                struct pipeline_msg_rsp_table_rule_stats_read table_rule_stats_read;
                struct pipeline_msg_rsp_table_rule_mtr_read table_rule_mtr_read;
                struct pipeline_msg_rsp_table_rule_ttl_read table_rule_ttl_read;
+               struct pipeline_msg_rsp_table_rule_time_read table_rule_time_read;
        };
 };
 
@@ -804,12 +811,10 @@ pipeline_port_in_stats_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
-       if (status)
+       if (status == 0)
                memcpy(stats, &rsp->port_in_stats_read.stats, sizeof(*stats));
 
        /* Free response */
@@ -852,8 +857,6 @@ pipeline_port_in_enable(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -898,8 +901,6 @@ pipeline_port_in_disable(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -952,12 +953,10 @@ pipeline_port_out_stats_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
-       if (status)
+       if (status == 0)
                memcpy(stats, &rsp->port_out_stats_read.stats, sizeof(*stats));
 
        /* Free response */
@@ -1008,12 +1007,10 @@ pipeline_table_stats_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
-       if (status)
+       if (status == 0)
                memcpy(stats, &rsp->table_stats_read.stats, sizeof(*stats));
 
        /* Free response */
@@ -1425,10 +1422,6 @@ pipeline_table_rule_add(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL) {
-               free(rule);
-               return -1;
-       }
 
        /* Read response */
        status = rsp->status;
@@ -1527,10 +1520,6 @@ pipeline_table_rule_add_default(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL) {
-               free(rule);
-               return -1;
-       }
 
        /* Read response */
        status = rsp->status;
@@ -1644,10 +1633,6 @@ pipeline_table_rule_add_bulk(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL) {
-               table_rule_list_free(list);
-               return -ENOMEM;
-       }
 
        /* Read response */
        status = rsp->status;
@@ -1722,8 +1707,6 @@ pipeline_table_rule_delete(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -1779,8 +1762,6 @@ pipeline_table_rule_delete_default(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -1846,8 +1827,6 @@ pipeline_table_rule_stats_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -1904,8 +1883,6 @@ pipeline_table_mtr_profile_add(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -1956,8 +1933,6 @@ pipeline_table_mtr_profile_delete(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -2026,8 +2001,6 @@ pipeline_table_rule_mtr_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -2085,8 +2058,6 @@ pipeline_table_dscp_table_update(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -2153,8 +2124,6 @@ pipeline_table_rule_ttl_read(const char *pipeline_name,
 
        /* Send request and wait for response */
        rsp = pipeline_msg_send_recv(p, req);
-       if (rsp == NULL)
-               return -1;
 
        /* Read response */
        status = rsp->status;
@@ -2167,6 +2136,69 @@ pipeline_table_rule_ttl_read(const char *pipeline_name,
        return status;
 }
 
+int
+pipeline_table_rule_time_read(const char *pipeline_name,
+       uint32_t table_id,
+       struct table_rule_match *match,
+       uint64_t *timestamp)
+{
+       struct pipeline *p;
+       struct table *table;
+       struct pipeline_msg_req *req;
+       struct pipeline_msg_rsp *rsp;
+       struct table_rule *rule;
+       int status;
+
+       /* Check input params */
+       if ((pipeline_name == NULL) ||
+               (match == NULL) ||
+               (timestamp == NULL))
+               return -1;
+
+       p = pipeline_find(pipeline_name);
+       if ((p == NULL) ||
+               (table_id >= p->n_tables) ||
+               match_check(match, p, table_id))
+               return -1;
+
+       table = &p->table[table_id];
+
+       rule = table_rule_find(table, match);
+       if (rule == NULL)
+               return -1;
+
+       if (!pipeline_is_running(p)) {
+               status = rte_table_action_time_read(table->a,
+                               rule->data,
+                               timestamp);
+
+               return status;
+       }
+
+       /* Allocate request */
+       req = pipeline_msg_alloc();
+       if (req == NULL)
+               return -1;
+
+       /* Write request */
+       req->type = PIPELINE_REQ_TABLE_RULE_TIME_READ;
+       req->id = table_id;
+       req->table_rule_time_read.data = rule->data;
+
+       /* Send request and wait for response */
+       rsp = pipeline_msg_send_recv(p, req);
+
+       /* Read response */
+       status = rsp->status;
+       if (status == 0)
+               *timestamp = rsp->table_rule_time_read.timestamp;
+
+       /* Free response */
+       pipeline_msg_free(rsp);
+
+       return status;
+}
+
 /**
  * Data plane threads: message handling
  */
@@ -2942,6 +2974,22 @@ pipeline_msg_handle_table_rule_ttl_read(struct pipeline_data *p,
        return rsp;
 }
 
+static struct pipeline_msg_rsp *
+pipeline_msg_handle_table_rule_time_read(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;
+       void *data = req->table_rule_time_read.data;
+       struct rte_table_action *a = p->table_data[table_id].a;
+
+       rsp->status = rte_table_action_time_read(a,
+               data,
+               &rsp->table_rule_time_read.timestamp);
+
+       return rsp;
+}
+
 static void
 pipeline_msg_handle(struct pipeline_data *p)
 {
@@ -3018,6 +3066,10 @@ pipeline_msg_handle(struct pipeline_data *p)
                        rsp = pipeline_msg_handle_table_rule_ttl_read(p, req);
                        break;
 
+               case PIPELINE_REQ_TABLE_RULE_TIME_READ:
+                       rsp = pipeline_msg_handle_table_rule_time_read(p, req);
+                       break;
+
                default:
                        rsp = (struct pipeline_msg_rsp *) req;
                        rsp->status = -1;