X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Fhandle_police.c;h=0d46cc1658bd5ed0aee6f5fa4a8577fa8fbad57a;hb=9d1c6c3ff1f464fc2b99857f9113f5688f9b34f1;hp=125e8c0a87d2a79e778023192211fcbb9a791fc1;hpb=51759157a499326cfe69ec0eecb00b1c5879bf50;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/handle_police.c b/VNFs/DPPD-PROX/handle_police.c index 125e8c0a..0d46cc16 100644 --- a/VNFs/DPPD-PROX/handle_police.c +++ b/VNFs/DPPD-PROX/handle_police.c @@ -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,41 +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; - out_color = rte_meter_srtcm_color_aware_check(&task->sr_flows[user], tsc, pkt_len, in_color); +#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 = 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 = 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; @@ -100,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 = @@ -202,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"); @@ -214,10 +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, ¶ms) != 0, "Failed to rte_meter_srtcm_profile_config\n"); + for (uint32_t i = 0; i < targ->n_flows; ++i) { + PROX_PANIC(rte_meter_srtcm_config(&task->sr_flows[i], &task->sr_profile) != 0, "Failed to rte_meter_srtcm_config"); + } +#else for (uint32_t i = 0; i < targ->n_flows; ++i) { rte_meter_srtcm_config(&task->sr_flows[i], ¶ms); } +#endif } else { task->tr_flows = prox_zmalloc(targ->n_flows * sizeof(*task->tr_flows), socket_id); @@ -233,10 +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, ¶ms) != 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) { rte_meter_trtcm_config(&task->tr_flows[i], ¶ms); } +#endif } for (uint32_t i = 0; i < 3; ++i) { @@ -247,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, @@ -255,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,