Added support for DPDK 19.02 and 19.05
[samplevnf.git] / VNFs / DPPD-PROX / handle_police.c
index 564cf4b..0d46cc1 100644 (file)
@@ -33,6 +33,7 @@
 #include "qinq.h"
 #include "prox_cfg.h"
 #include "prox_shared.h"
+#include "prox_compat.h"
 
 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
 #define RTE_CACHE_LINE_SIZE CACHE_LINE_SIZE
@@ -44,48 +45,55 @@ struct task_police {
                struct rte_meter_srtcm *sr_flows;
                struct rte_meter_trtcm *tr_flows;
        };
-
+       union {
+#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0)
+               struct rte_meter_srtcm_profile sr_profile;
+               struct rte_meter_trtcm_profile tr_profile;
+#endif
+       };
        uint16_t           *user_table;
        enum police_action police_act[3][3];
        uint16_t overhead;
        uint8_t runtime_flags;
+       struct rte_sched_port *sched_port;
 };
 
 typedef uint8_t (*hp) (struct task_police *task, struct rte_mbuf *mbuf, uint64_t tsc, uint32_t user);
 
 static uint8_t handle_police(struct task_police *task, struct rte_mbuf *mbuf, uint64_t tsc, uint32_t user)
 {
-       enum rte_meter_color in_color = e_RTE_METER_GREEN;
-       enum rte_meter_color out_color;
+       enum prox_rte_color in_color = RTE_COLOR_GREEN;
+       enum prox_rte_color out_color;
        uint32_t pkt_len = rte_pktmbuf_pkt_len(mbuf) + task->overhead;
+
 #if RTE_VERSION < RTE_VERSION_NUM(18,5,0,0)
        out_color = rte_meter_srtcm_color_aware_check(&task->sr_flows[user], tsc, pkt_len, in_color);
 #else
-       out_color = 0;  // TODO DPDK1805
+       out_color = rte_meter_srtcm_color_aware_check(&task->sr_flows[user], &task->sr_profile, tsc, pkt_len, in_color);
 #endif
        return task->police_act[in_color][out_color] == ACT_DROP? OUT_DISCARD : 0;
 }
 
 static uint8_t handle_police_tr(struct task_police *task, struct rte_mbuf *mbuf, uint64_t tsc, uint32_t user)
 {
-       enum rte_meter_color in_color = e_RTE_METER_GREEN;
-       enum rte_meter_color out_color;
+       enum prox_rte_color in_color = RTE_COLOR_GREEN;
+       enum prox_rte_color out_color;
        uint32_t pkt_len = rte_pktmbuf_pkt_len(mbuf) + task->overhead;
 #if RTE_VERSION < RTE_VERSION_NUM(18,5,0,0)
        out_color = rte_meter_trtcm_color_aware_check(&task->tr_flows[user], tsc, pkt_len, in_color);
 #else
-       out_color = 0;// TODO DPDK1805
+       out_color = rte_meter_trtcm_color_aware_check(&task->tr_flows[user], &task->tr_profile, tsc, pkt_len, in_color);
 #endif
 
        if (task->runtime_flags  & TASK_MARK) {
 #if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
                uint32_t subport, pipe, traffic_class, queue;
-               enum rte_meter_color color;
+               enum prox_rte_color color;
 
-               rte_sched_port_pkt_read_tree_path(mbuf, &subport, &pipe, &traffic_class, &queue);
+               prox_rte_sched_port_pkt_read_tree_path(task->sched_port, mbuf, &subport, &pipe, &traffic_class, &queue);
                color = task->police_act[in_color][out_color];
 
-               rte_sched_port_pkt_write(mbuf, subport, pipe, traffic_class, queue, color);
+               prox_rte_sched_port_pkt_write(task->sched_port, mbuf, subport, pipe, traffic_class, queue, color);
 #else
                struct rte_sched_port_hierarchy *sched =
                        (struct rte_sched_port_hierarchy *) &mbuf->pkt.hash.sched;
@@ -107,7 +115,7 @@ static inline int get_user(struct task_police *task, struct rte_mbuf *mbuf)
        uint32_t dummy;
        uint32_t pipe;
 
-       rte_sched_port_pkt_read_tree_path(mbuf, &dummy, &pipe, &dummy, &dummy);
+       prox_rte_sched_port_pkt_read_tree_path(task->sched_port, mbuf, &dummy, &pipe, &dummy, &dummy);
        return pipe;
 #else
        struct rte_sched_port_hierarchy *sched =
@@ -198,10 +206,6 @@ static void init_task_police(struct task_base *tbase, struct task_args *targ)
        struct task_police *task = (struct task_police *)tbase;
        const int socket_id = rte_lcore_to_socket_id(targ->lconf->id);
 
-#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0)
-       plog_warn("mode police might not be supported in this prox/dpdk version\n"); // TODO DPDK1805
-#endif
-
        task->overhead = targ->overhead;
        task->runtime_flags = targ->runtime_flags;
 
@@ -213,6 +217,8 @@ static void init_task_police(struct task_base *tbase, struct task_args *targ)
                prox_sh_add_socket(socket_id, "user_table", task->user_table);
        }
 
+       task->sched_port = rte_sched_port_config(&targ->qos_conf.port_params);
+
        if (strcmp(targ->task_init->sub_mode_str, "trtcm")) {
                task->sr_flows = prox_zmalloc(targ->n_flows * sizeof(*task->sr_flows), socket_id);
                PROX_PANIC(task->sr_flows == NULL, "Failed to allocate flow contexts\n");
@@ -225,14 +231,16 @@ static void init_task_police(struct task_base *tbase, struct task_args *targ)
                        .cbs = targ->cbs,
                        .ebs = targ->ebs,
                };
-
+#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0)
+               PROX_PANIC(rte_meter_srtcm_profile_config(&task->sr_profile, &params) != 0, "Failed to rte_meter_srtcm_profile_config\n");
                for (uint32_t i = 0; i < targ->n_flows; ++i) {
-#if RTE_VERSION < RTE_VERSION_NUM(18,5,0,0)
-                       rte_meter_srtcm_config(&task->sr_flows[i], &params);
+                       PROX_PANIC(rte_meter_srtcm_config(&task->sr_flows[i], &task->sr_profile) != 0, "Failed to rte_meter_srtcm_config");
+               }
 #else
-       // TODO DPDK1805
-#endif
+               for (uint32_t i = 0; i < targ->n_flows; ++i) {
+                       rte_meter_srtcm_config(&task->sr_flows[i], &params);
                }
+#endif
        }
        else {
                task->tr_flows = prox_zmalloc(targ->n_flows * sizeof(*task->tr_flows), socket_id);
@@ -248,14 +256,17 @@ static void init_task_police(struct task_base *tbase, struct task_args *targ)
                        .cir = targ->cir,
                        .cbs = targ->cbs,
                };
+#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0)
+               PROX_PANIC(rte_meter_trtcm_profile_config(&task->tr_profile, &params) != 0, "Failed to rte_meter_srtcm_profile_config\n");
+               for (uint32_t i = 0; i < targ->n_flows; ++i) {
+                       PROX_PANIC(rte_meter_trtcm_config(&task->tr_flows[i], &task->tr_profile) != 0, "Failed to rte_meter_trtcm_config\n");
+               }
+#else
 
                for (uint32_t i = 0; i < targ->n_flows; ++i) {
-#if RTE_VERSION < RTE_VERSION_NUM(18,5,0,0)
                        rte_meter_trtcm_config(&task->tr_flows[i], &params);
-#else
-       // TODO DPDK1805
-#endif
                }
+#endif
        }
 
        for (uint32_t i = 0; i < 3; ++i) {
@@ -266,6 +277,7 @@ static void init_task_police(struct task_base *tbase, struct task_args *targ)
 }
 
 static struct task_init task_init_police = {
+       .mode = POLICE,
        .mode_str = "police",
        .init = init_task_police,
        .handle = handle_police_bulk,
@@ -274,6 +286,7 @@ static struct task_init task_init_police = {
 };
 
 static struct task_init task_init_police2 = {
+       .mode = POLICE,
        .mode_str = "police",
        .sub_mode_str = "trtcm",
        .init = init_task_police,