#include <string.h>
#include "pipeline_actions_common.h"
#include "pipeline_flow_actions_be.h"
#include "parser.h"
#include "hash_func.h"
int
pipeline_fa_flow_params_set_default(struct pipeline_fa_flow_params *params)
{
uint32_t i;
if (params == NULL)
return -1;
for (i = 0; i < PIPELINE_FA_N_TC_MAX; i++) {
}
for (i = 0; i < PIPELINE_FA_N_TC_MAX; i++) {
struct pipeline_fa_policer_params *p = ¶ms->p[i];
uint32_t j;
struct pipeline_fa_policer_action *a = &p->action[j];
a->drop = 0;
}
}
params->port_id = 0;
return 0;
}
struct dscp_entry {
uint32_t traffic_class;
};
struct pipeline_flow_actions {
struct pipeline p;
struct pipeline_fa_params params;
pipeline_msg_req_handler custom_handlers[PIPELINE_FA_MSG_REQS];
struct dscp_entry dscp[PIPELINE_FA_N_DSCP];
static void *
pipeline_fa_msg_req_custom_handler(struct pipeline *p, void *msg);
static pipeline_msg_req_handler handlers[] = {
[PIPELINE_MSG_REQ_PING] =
pipeline_msg_req_ping_handler,
[PIPELINE_MSG_REQ_STATS_PORT_IN] =
pipeline_msg_req_stats_port_in_handler,
[PIPELINE_MSG_REQ_STATS_PORT_OUT] =
pipeline_msg_req_stats_port_out_handler,
[PIPELINE_MSG_REQ_STATS_TABLE] =
pipeline_msg_req_stats_table_handler,
[PIPELINE_MSG_REQ_PORT_IN_ENABLE] =
pipeline_msg_req_port_in_enable_handler,
[PIPELINE_MSG_REQ_PORT_IN_DISABLE] =
pipeline_msg_req_port_in_disable_handler,
[PIPELINE_MSG_REQ_CUSTOM] =
pipeline_fa_msg_req_custom_handler,
};
static void *
pipeline_fa_msg_req_flow_config_handler(struct pipeline *p, void *msg);
static void *
pipeline_fa_msg_req_flow_config_bulk_handler(struct pipeline *p, void *msg);
static void *
pipeline_fa_msg_req_dscp_config_handler(struct pipeline *p, void *msg);
static void *
pipeline_fa_msg_req_policer_stats_read_handler(struct pipeline *p, void *msg);
static pipeline_msg_req_handler custom_handlers[] = {
[PIPELINE_FA_MSG_REQ_FLOW_CONFIG] =
pipeline_fa_msg_req_flow_config_handler,
[PIPELINE_FA_MSG_REQ_FLOW_CONFIG_BULK] =
pipeline_fa_msg_req_flow_config_bulk_handler,
[PIPELINE_FA_MSG_REQ_DSCP_CONFIG] =
pipeline_fa_msg_req_dscp_config_handler,
[PIPELINE_FA_MSG_REQ_POLICER_STATS_READ] =
pipeline_fa_msg_req_policer_stats_read_handler,
};
struct meter_policer {
struct rte_meter_trtcm meter;
struct pipeline_fa_policer_params policer;
struct pipeline_fa_policer_stats stats;
};
struct flow_table_entry {
struct meter_policer
mp[PIPELINE_FA_N_TC_MAX];
};
static int
flow_table_entry_set_meter(struct flow_table_entry *entry,
uint32_t meter_id,
struct pipeline_fa_flow_params *params)
{
struct rte_meter_trtcm *meter = &entry->mp[meter_id].meter;
}
static void
flow_table_entry_set_policer(struct flow_table_entry *entry,
uint32_t policer_id,
struct pipeline_fa_flow_params *params)
{
struct pipeline_fa_policer_params *p0 = &entry->mp[policer_id].policer;
struct pipeline_fa_policer_params *p1 = ¶ms->p[policer_id];
memcpy(p0, p1, sizeof(*p0));
}
static void
flow_table_entry_set_port_id(struct pipeline_flow_actions *p,
struct flow_table_entry *entry,
struct pipeline_fa_flow_params *params)
{
entry->head.port_id = p->p.port_out_id[params->port_id];
}
static int
flow_table_entry_set_default(struct pipeline_flow_actions *p,
struct flow_table_entry *entry)
{
struct pipeline_fa_flow_params params;
uint32_t i;
pipeline_fa_flow_params_set_default(¶ms);
memset(entry, 0, sizeof(*entry));
flow_table_entry_set_port_id(p, entry, ¶ms);
for (i = 0; i < PIPELINE_FA_N_TC_MAX; i++) {
int status;
status = flow_table_entry_set_meter(entry, i, ¶ms);
if (status)
return status;
}
for (i = 0; i < PIPELINE_FA_N_TC_MAX; i++)
flow_table_entry_set_policer(entry, i, ¶ms);
return 0;
}
static inline uint64_t
pkt_work(
void *arg,
uint64_t time)
{
struct pipeline_flow_actions *p = arg;
struct flow_table_entry *entry =
(struct flow_table_entry *) table_entry;
uint32_t tc = p->dscp[dscp].traffic_class;
struct rte_meter_trtcm *meter = &entry->mp[tc].meter;
struct pipeline_fa_policer_params *policer = &entry->mp[tc].policer;
struct pipeline_fa_policer_stats *stats = &entry->mp[tc].stats;
time,
total_length,
color);
uint64_t drop = policer->action[color2].drop;
stats->n_pkts[color3] += drop ^ 1LLU;
stats->n_pkts_drop += drop;
*pkt_color = color3;
return drop;
}
static inline uint64_t
pkt4_work(
void *arg,
uint64_t time)
{
struct pipeline_flow_actions *p = arg;
struct flow_table_entry *entry0 =
(struct flow_table_entry *) table_entries[0];
struct flow_table_entry *entry1 =
(struct flow_table_entry *) table_entries[1];
struct flow_table_entry *entry2 =
(struct flow_table_entry *) table_entries[2];
struct flow_table_entry *entry3 =
(struct flow_table_entry *) table_entries[3];
uint32_t tc0 = p->dscp[dscp0].traffic_class;
uint32_t tc1 = p->dscp[dscp1].traffic_class;
uint32_t tc2 = p->dscp[dscp2].traffic_class;
uint32_t tc3 = p->dscp[dscp3].traffic_class;
struct rte_meter_trtcm *meter0 = &entry0->mp[tc0].meter;
struct pipeline_fa_policer_params *policer0 = &entry0->mp[tc0].policer;
struct pipeline_fa_policer_stats *stats0 = &entry0->mp[tc0].stats;
struct rte_meter_trtcm *meter1 = &entry1->mp[tc1].meter;
struct pipeline_fa_policer_params *policer1 = &entry1->mp[tc1].policer;
struct pipeline_fa_policer_stats *stats1 = &entry1->mp[tc1].stats;
struct rte_meter_trtcm *meter2 = &entry2->mp[tc2].meter;
struct pipeline_fa_policer_params *policer2 = &entry2->mp[tc2].policer;
struct pipeline_fa_policer_stats *stats2 = &entry2->mp[tc2].stats;
struct rte_meter_trtcm *meter3 = &entry3->mp[tc3].meter;
struct pipeline_fa_policer_params *policer3 = &entry3->mp[tc3].policer;
struct pipeline_fa_policer_stats *stats3 = &entry3->mp[tc3].stats;
meter0,
time,
total_length0,
color0);
meter1,
time,
total_length1,
color1);
meter2,
time,
total_length2,
color2);
meter3,
time,
total_length3,
color3);
uint64_t drop0 = policer0->action[color2_0].drop;
uint64_t drop1 = policer1->action[color2_1].drop;
uint64_t drop2 = policer2->action[color2_2].drop;
uint64_t drop3 = policer3->action[color2_3].drop;
stats0->n_pkts[color3_0] += drop0 ^ 1LLU;
stats0->n_pkts_drop += drop0;
stats1->n_pkts[color3_1] += drop1 ^ 1LLU;
stats1->n_pkts_drop += drop1;
stats2->n_pkts[color3_2] += drop2 ^ 1LLU;
stats2->n_pkts_drop += drop2;
stats3->n_pkts[color3_3] += drop3 ^ 1LLU;
stats3->n_pkts_drop += drop3;
*pkt0_color = color3_0;
*pkt1_color = color3_1;
*pkt2_color = color3_2;
*pkt3_color = color3_3;
return drop0 | (drop1 << 1) | (drop2 << 2) | (drop3 << 3);
}
PIPELINE_TABLE_AH_HIT_DROP_TIME(fa_table_ah_hit, pkt_work, pkt4_work);
get_fa_table_ah_hit(
__rte_unused struct pipeline_flow_actions *p)
{
return fa_table_ah_hit;
}
int
pipeline_fa_parse_args(struct pipeline_fa_params *p,
struct pipeline_params *params)
{
uint32_t n_flows_present = 0;
uint32_t n_meters_per_flow_present = 0;
uint32_t flow_id_offset_present = 0;
uint32_t ip_hdr_offset_present = 0;
uint32_t color_offset_present = 0;
uint32_t i;
p->n_meters_per_flow = 1;
p->dscp_enabled = 0;
for (i = 0; i < params->n_args; i++) {
char *arg_name = params->args_name[i];
char *arg_value = params->args_value[i];
if (strcmp(arg_name, "n_flows") == 0) {
int status;
PIPELINE_PARSE_ERR_DUPLICATE(
n_flows_present == 0, params->name,
arg_name);
n_flows_present = 1;
status = parser_read_uint32(&p->n_flows,
arg_value);
PIPELINE_PARSE_ERR_INV_VAL(((status != -EINVAL) &&
(p->n_flows != 0)), params->name,
arg_name, arg_value);
PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
params->name, arg_name, arg_value);
continue;
}
if (strcmp(arg_name, "n_meters_per_flow") == 0) {
int status;
PIPELINE_PARSE_ERR_DUPLICATE(
n_meters_per_flow_present == 0,
params->name, arg_name);
n_meters_per_flow_present = 1;
status = parser_read_uint32(&p->n_meters_per_flow,
arg_value);
PIPELINE_PARSE_ERR_INV_VAL(((status != -EINVAL) &&
(p->n_meters_per_flow != 0)),
params->name, arg_name, arg_value);
PIPELINE_PARSE_ERR_OUT_RNG(((status != -ERANGE) &&
(p->n_meters_per_flow <=
PIPELINE_FA_N_TC_MAX)), params->name,
arg_name, arg_value);
continue;
}
if (strcmp(arg_name, "flow_id_offset") == 0) {
int status;
PIPELINE_PARSE_ERR_DUPLICATE(
flow_id_offset_present == 0,
params->name, arg_name);
flow_id_offset_present = 1;
status = parser_read_uint32(&p->flow_id_offset,
arg_value);
PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
params->name, arg_name, arg_value);
PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
params->name, arg_name, arg_value);
continue;
}
if (strcmp(arg_name, "ip_hdr_offset") == 0) {
int status;
PIPELINE_PARSE_ERR_DUPLICATE(
ip_hdr_offset_present == 0,
params->name, arg_name);
ip_hdr_offset_present = 1;
status = parser_read_uint32(&p->ip_hdr_offset,
arg_value);
PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
params->name, arg_name, arg_value);
PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
params->name, arg_name, arg_value);
continue;
}
if (strcmp(arg_name, "color_offset") == 0) {
int status;
PIPELINE_PARSE_ERR_DUPLICATE(
color_offset_present == 0, params->name,
arg_name);
color_offset_present = 1;
status = parser_read_uint32(&p->color_offset,
arg_value);
PIPELINE_PARSE_ERR_INV_VAL((status != -EINVAL),
params->name, arg_name, arg_value);
PIPELINE_PARSE_ERR_OUT_RNG((status != -ERANGE),
params->name, arg_name, arg_value);
p->dscp_enabled = 1;
continue;
}
PIPELINE_PARSE_ERR_INV_ENT(0, params->name, arg_name);
}
PIPELINE_PARSE_ERR_MANDATORY((n_flows_present), params->name,
"n_flows");
PIPELINE_PARSE_ERR_MANDATORY((flow_id_offset_present),
params->name, "flow_id_offset");
PIPELINE_PARSE_ERR_MANDATORY((ip_hdr_offset_present),
params->name, "ip_hdr_offset");
PIPELINE_PARSE_ERR_MANDATORY((color_offset_present), params->name,
"color_offset");
return 0;
}
static void
dscp_init(struct pipeline_flow_actions *p)
{
uint32_t i;
for (i = 0; i < PIPELINE_FA_N_DSCP; i++) {
p->dscp[i].traffic_class = 0;
}
}
static void *pipeline_fa_init(struct pipeline_params *params,
{
struct pipeline *p;
struct pipeline_flow_actions *p_fa;
uint32_t size, i;
if (params == NULL)
return NULL;
if (params->n_ports_in != params->n_ports_out)
return NULL;
sizeof(struct pipeline_flow_actions));
if (p == NULL)
return NULL;
p_fa = (struct pipeline_flow_actions *) p;
strcpy(p->name, params->name);
p->log_level = params->log_level;
PLOG(p, HIGH, "Flow actions");
if (pipeline_fa_parse_args(&p_fa->params, params))
return NULL;
dscp_init(p_fa);
{
.socket_id = params->socket_id,
.offset_port_id = 0,
};
if (p->p == NULL) {
return NULL;
}
}
p->n_ports_in = params->n_ports_in;
for (i = 0; i < p->n_ports_in; i++) {
.
ops = pipeline_port_in_params_get_ops(
¶ms->port_in[i]),
.arg_create = pipeline_port_in_params_convert(
¶ms->port_in[i]),
.f_action = NULL,
.arg_ah = NULL,
.burst_size = params->port_in[i].burst_size,
};
&port_params,
&p->port_in_id[i]);
if (status) {
return NULL;
}
}
p->n_ports_out = params->n_ports_out;
for (i = 0; i < p->n_ports_out; i++) {
.
ops = pipeline_port_out_params_get_ops(
¶ms->port_out[i]),
.arg_create = pipeline_port_out_params_convert(
¶ms->port_out[i]),
.f_action = NULL,
.arg_ah = NULL,
};
&port_params,
&p->port_out_id[i]);
if (status) {
return NULL;
}
}
p->n_tables = 1;
{
.offset = p_fa->params.flow_id_offset,
};
.arg_create = &table_array_params,
.f_action_hit = get_fa_table_ah_hit(p_fa),
.f_action_miss = NULL,
.arg_ah = p_fa,
.action_data_size =
sizeof(struct flow_table_entry) -
};
int status;
&table_params,
&p->table_id[0]);
if (status) {
return NULL;
}
}
for (i = 0; i < p->n_ports_in; i++) {
p->port_in_id[i],
p->table_id[0]);
if (status) {
return NULL;
}
}
for (i = 0; i < p->n_ports_in; i++) {
p->port_in_id[i]);
if (status) {
return NULL;
}
}
for (i = 0; i < p_fa->params.n_flows; i++) {
};
struct flow_table_entry entry;
int key_found, status;
flow_table_entry_set_default(p_fa, &entry);
p->table_id[0],
&key,
&key_found,
&entry_ptr);
if (status) {
return NULL;
}
}
return NULL;
}
p->n_msgq = params->n_msgq;
for (i = 0; i < p->n_msgq; i++)
p->msgq_in[i] = params->msgq_in[i];
for (i = 0; i < p->n_msgq; i++)
p->msgq_out[i] = params->msgq_out[i];
memcpy(p->handlers, handlers, sizeof(p->handlers));
memcpy(p_fa->custom_handlers,
custom_handlers,
sizeof(p_fa->custom_handlers));
return p;
}
static int
pipeline_fa_free(void *pipeline)
{
struct pipeline *p = (struct pipeline *) pipeline;
if (p == NULL)
return -1;
return 0;
}
static int
pipeline_fa_track(void *pipeline,
uint32_t *port_out)
{
struct pipeline *p = (struct pipeline *) pipeline;
if ((p == NULL) ||
(port_in >= p->n_ports_in) ||
(port_out == NULL))
return -1;
if (p->n_ports_in == 1) {
*port_out = 0;
return 0;
}
return -1;
}
static int
pipeline_fa_timer(void *pipeline)
{
struct pipeline *p = (struct pipeline *) pipeline;
pipeline_msg_req_handle(p);
return 0;
}
void *
pipeline_fa_msg_req_custom_handler(struct pipeline *p, void *msg)
{
struct pipeline_flow_actions *p_fa =
(struct pipeline_flow_actions *) p;
struct pipeline_custom_msg_req *req = msg;
pipeline_msg_req_handler f_handle;
f_handle = (req->subtype < PIPELINE_FA_MSG_REQS) ?
p_fa->custom_handlers[req->subtype] :
pipeline_msg_req_invalid_handler;
if (f_handle == NULL)
f_handle = pipeline_msg_req_invalid_handler;
return f_handle(p, req);
}
void *
pipeline_fa_msg_req_flow_config_handler(struct pipeline *p, void *msg)
{
struct pipeline_flow_actions *p_fa = (struct pipeline_flow_actions *) p;
struct pipeline_fa_flow_config_msg_req *req = msg;
struct pipeline_fa_flow_config_msg_rsp *rsp = msg;
struct flow_table_entry *entry;
uint32_t mask, i;
if (req->entry_ptr == NULL) {
.
pos = req->flow_id % p_fa->params.n_flows,
};
struct flow_table_entry default_entry;
int key_found, status;
flow_table_entry_set_default(p_fa, &default_entry);
p->table_id[0],
&key,
&key_found,
if (status) {
rsp->status = -1;
return rsp;
}
} else
entry = (struct flow_table_entry *) req->entry_ptr;
for (i = 0, mask = 1; i < PIPELINE_FA_N_TC_MAX; i++, mask <<= 1) {
int status;
if ((mask & req->meter_update_mask) == 0)
continue;
status = flow_table_entry_set_meter(entry, i, &req->params);
if (status) {
rsp->status = -1;
return rsp;
}
}
for (i = 0, mask = 1; i < PIPELINE_FA_N_TC_MAX; i++, mask <<= 1) {
if ((mask & req->policer_update_mask) == 0)
continue;
flow_table_entry_set_policer(entry, i, &req->params);
}
if (req->port_update)
flow_table_entry_set_port_id(p_fa, entry, &req->params);
rsp->status = 0;
rsp->entry_ptr = (void *) entry;
return rsp;
}
void *
pipeline_fa_msg_req_flow_config_bulk_handler(struct pipeline *p, void *msg)
{
struct pipeline_flow_actions *p_fa = (struct pipeline_flow_actions *) p;
struct pipeline_fa_flow_config_bulk_msg_req *req = msg;
struct pipeline_fa_flow_config_bulk_msg_rsp *rsp = msg;
uint32_t i;
for (i = 0; i < req->n_flows; i++) {
struct flow_table_entry *entry;
uint32_t j, mask;
if (req->entry_ptr[i] == NULL) {
.
pos = req->flow_id[i] % p_fa->params.n_flows,
};
struct flow_table_entry entry_to_add;
int key_found, status;
flow_table_entry_set_default(p_fa, &entry_to_add);
p->table_id[0],
&key,
&key_found,
if (status) {
rsp->n_flows = i;
return rsp;
}
req->entry_ptr[i] = (void *) entry;
} else
entry = (struct flow_table_entry *) req->entry_ptr[i];
for (j = 0, mask = 1;
j < PIPELINE_FA_N_TC_MAX;
j++, mask <<= 1) {
int status;
if ((mask & req->meter_update_mask) == 0)
continue;
status = flow_table_entry_set_meter(entry,
j, &req->params[i]);
if (status) {
rsp->n_flows = i;
return rsp;
}
}
for (j = 0, mask = 1;
j < PIPELINE_FA_N_TC_MAX;
j++, mask <<= 1) {
if ((mask & req->policer_update_mask) == 0)
continue;
flow_table_entry_set_policer(entry,
j, &req->params[i]);
}
if (req->port_update)
flow_table_entry_set_port_id(p_fa,
entry, &req->params[i]);
}
rsp->n_flows = i;
return rsp;
}
void *
pipeline_fa_msg_req_dscp_config_handler(struct pipeline *p, void *msg)
{
struct pipeline_flow_actions *p_fa = (struct pipeline_flow_actions *) p;
struct pipeline_fa_dscp_config_msg_req *req = msg;
struct pipeline_fa_dscp_config_msg_rsp *rsp = msg;
if ((req->dscp >= PIPELINE_FA_N_DSCP) ||
(req->traffic_class >= PIPELINE_FA_N_TC_MAX) ||
rsp->status = -1;
return rsp;
}
p_fa->dscp[req->dscp].traffic_class = req->traffic_class;
p_fa->dscp[req->dscp].color = req->color;
rsp->status = 0;
return rsp;
}
void *
pipeline_fa_msg_req_policer_stats_read_handler(
__rte_unused struct pipeline *p,
void *msg)
{
struct pipeline_fa_policer_stats_msg_req *req = msg;
struct pipeline_fa_policer_stats_msg_rsp *rsp = msg;
struct flow_table_entry *entry = req->entry_ptr;
uint32_t policer_id = req->policer_id;
int clear = req->clear;
if ((req->entry_ptr == NULL) ||
(req->policer_id >= PIPELINE_FA_N_TC_MAX)) {
rsp->status = -1;
return rsp;
}
memcpy(&rsp->stats,
&entry->mp[policer_id].stats,
sizeof(rsp->stats));
if (clear)
memset(&entry->mp[policer_id].stats,
0, sizeof(entry->mp[policer_id].stats));
rsp->status = 0;
return rsp;
}
struct pipeline_be_ops pipeline_flow_actions_be_ops = {
.f_init = pipeline_fa_init,
.f_free = pipeline_fa_free,
.f_run = NULL,
.f_timer = pipeline_fa_timer,
.f_track = pipeline_fa_track,
};