Skip to content

Commit

Permalink
auto start/stop vf offload pkt tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
byteocean committed Sep 5, 2023
1 parent 1b2c9e3 commit 797dd98
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 26 deletions.
1 change: 1 addition & 0 deletions include/dp_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct dp_port {
uint16_t peer_pf_port_id;
enum dp_vf_port_attach_status attach_status;
struct rte_pci_addr pci_addr;
struct rte_flow *default_flow;
};

struct dp_ports {
Expand Down
5 changes: 5 additions & 0 deletions include/monitoring/dp_graphtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ static __rte_always_inline void dp_graphtrace_disable(void)
_dp_graphtrace_enabled = false;
}

static __rte_always_inline bool dp_graphtrace_is_enabled(void)
{
return _dp_graphtrace_enabled;
}

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/rte_flow/dp_rte_flow_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ int dp_install_jump_rule_int_default_group(uint16_t port_id, uint32_t group_id);
int dp_install_default_rule_in_monitoring_group(uint16_t port_id);
int dp_install_default_capture_rule_in_vnet_group(uint16_t port_id);

int dp_change_all_vf_default_jump_rte_flow_group(uint32_t dst_group);

#ifdef ENABLE_VIRTSVC
int dp_install_isolated_mode_virtsvc(int port_id, uint8_t proto_id, uint8_t svc_ipv6[16], uint16_t svc_port);
#endif
Expand Down
3 changes: 0 additions & 3 deletions src/dp_cntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@ static __rte_always_inline void dp_cntrack_tcp_state(struct flow_value *flow_val

static __rte_always_inline int dp_capture_offloaded_pkts(struct rte_mbuf *m, struct flow_value *flow_val, struct dp_flow *df)
{

printf("flow_val->offload_flags.orig = %d, flow_val->offload_flags.reply = %d\n", flow_val->offload_flags.orig, flow_val->offload_flags.reply);
if (!offload_mode_enabled ||
flow_val->offload_flags.orig == DP_FLOW_NON_OFFLOAD || flow_val->offload_flags.reply == DP_FLOW_NON_OFFLOAD)
return 0;

dp_graphtrace_capture_offload_pkt(m);
df->flags.offload_mark = DP_PKT_OFFLOAD_MARK;
printf("offloaded pkt captured\n");
return 1;

}
Expand Down
7 changes: 6 additions & 1 deletion src/dp_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nodes/rx_node.h"
#include "rte_flow/dp_rte_flow_init.h"
#include "rte_flow/dp_rte_flow.h"
#include "monitoring/dp_graphtrace.h"

static const struct rte_eth_conf port_conf_default = {
.rxmode = {
Expand Down Expand Up @@ -451,6 +452,7 @@ int dp_port_start(uint16_t port_id)
{
struct dp_port *port;
int ret;
bool graphtrace_enabled = dp_graphtrace_is_enabled();

port = dp_port_get(port_id);
if (!port)
Expand Down Expand Up @@ -484,7 +486,10 @@ int dp_port_start(uint16_t port_id)


if (port->port_type == DP_PORT_VF) {
dp_install_jump_rule_int_default_group(port_id, DP_RTE_FLOW_MONITORING_GROUP);
if (graphtrace_enabled)
dp_install_jump_rule_int_default_group(port_id, DP_RTE_FLOW_MONITORING_GROUP);
else
dp_install_jump_rule_int_default_group(port_id, DP_RTE_FLOW_VNET_GROUP);
dp_install_default_rule_in_monitoring_group(port_id);
dp_install_default_capture_rule_in_vnet_group(port_id);
}
Expand Down
33 changes: 33 additions & 0 deletions src/monitoring/dp_graphtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "dp_log.h"
#include "dpdk_layer.h"
#include "monitoring/dp_graphtrace_shared.h"
#include "rte_flow/dp_rte_flow_init.h"
#include "rte_flow/dp_rte_flow.h"

#ifdef ENABLE_PYTEST
# include "dp_conf.h"
Expand All @@ -14,6 +16,7 @@ static enum dp_graphtrace_loglevel graphtrace_loglevel;

static struct dp_graphtrace graphtrace;
bool _dp_graphtrace_enabled = false;
static bool _offload_enabled;

static int dp_graphtrace_init_memzone(void)
{
Expand All @@ -37,6 +40,7 @@ static int dp_graphtrace_init_memzone(void)
return DP_ERROR;
}

_offload_enabled = dp_conf_is_offload_enabled();

return DP_OK;
}
Expand All @@ -49,10 +53,23 @@ static void dp_graphtrace_free_memzone(void)
graphtrace.mempool = NULL;
}

static __rte_always_inline
int dp_graphtrace_turn_on_vf_offload_tracing(void)
{
return dp_change_all_vf_default_jump_rte_flow_group(DP_RTE_FLOW_MONITORING_GROUP);
}

static __rte_always_inline
int dp_graphtrace_turn_off_vf_offload_tracing(void)
{
return dp_change_all_vf_default_jump_rte_flow_group(DP_RTE_FLOW_VNET_GROUP);
}

static __rte_always_inline
void dp_handle_graphtrace_request(const struct rte_mp_msg *mp_msg, struct dp_graphtrace_mp_reply *reply)
{
const struct dp_graphtrace_mp_request *request = (const struct dp_graphtrace_mp_request *)mp_msg->param;
int ret;

if (mp_msg->len_param != sizeof(struct dp_graphtrace_mp_request)) {
DPS_LOG_WARNING("Invalid graphtrace request message size", DP_LOG_VALUE(mp_msg->len_param));
Expand All @@ -63,11 +80,27 @@ void dp_handle_graphtrace_request(const struct rte_mp_msg *mp_msg, struct dp_gra
switch ((enum dp_graphtrace_action)request->action) {
case DP_GRAPHTRACE_ACTION_START:
dp_graphtrace_enable();
if (_offload_enabled) {
ret = dp_graphtrace_turn_on_vf_offload_tracing();
if (DP_FAILED(ret)) {
DPS_LOG_ERR("Cannot turn on offload tracing", DP_LOG_RET(ret));
reply->error_code = ret;
return;
}
}
reply->error_code = DP_OK;
DPS_LOG_INFO("Graphtrace enabled");
return;
case DP_GRAPHTRACE_ACTION_STOP:
dp_graphtrace_disable();
if (_offload_enabled) {
ret = dp_graphtrace_turn_off_vf_offload_tracing();
if (DP_FAILED(ret)) {
DPS_LOG_ERR("Cannot turn off offload tracing", DP_LOG_RET(ret));
reply->error_code = ret;
return;
}
}
reply->error_code = DP_OK;
DPS_LOG_INFO("Graphtrace disabled");
return;
Expand Down
39 changes: 37 additions & 2 deletions src/rte_flow/dp_rte_flow_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ int dp_install_jump_rule_int_default_group(uint16_t port_id, uint32_t dst_group)
int action_cnt = 0;

struct rte_flow *flow;
struct dp_port *port = dp_port_get_vf(port_id);

memset(pattern, 0, sizeof(pattern));
memset(action, 0, sizeof(action));
Expand All @@ -94,6 +95,8 @@ int dp_install_jump_rule_int_default_group(uint16_t port_id, uint32_t dst_group)
if (!flow)
return DP_ERROR;

port->default_flow = flow;

DPS_LOG_DEBUG("Installed the default jumping flow rule that destinated to group", DP_LOG_PORTID(port_id), DP_LOG_RTE_GROUP(dst_group));
return DP_OK;
}
Expand All @@ -109,18 +112,23 @@ int dp_install_default_rule_in_monitoring_group(uint16_t port_id)
struct rte_flow_action action[3]; // + end
int action_cnt = 0;

struct rte_flow *flow;
struct rte_flow_action sub_action[1];
int sub_action_cnt = 0;

struct rte_flow *flow;

memset(pattern, 0, sizeof(pattern));
memset(action, 0, sizeof(action));
memset(sub_action, 0, sizeof(sub_action));

// all ethernet packets
dp_set_eth_match_all_item(&pattern[pattern_cnt++]);
dp_set_end_flow_item(&pattern[pattern_cnt++]);

// create actions
// create sampling action
dp_set_sample_action(&action[action_cnt++], &sample_action, 1, NULL); // mirror all packets, without explicite sub sample action
dp_set_end_action(&sub_action[sub_action_cnt++]);
dp_set_sample_action(&action[action_cnt++], &sample_action, 1, sub_action); // mirror all packets, without explicite sub sample action

// create jump group action
dp_set_jump_group_action(&action[action_cnt++], &jump_action, DP_RTE_FLOW_VNET_GROUP); // jump to group DP_RTE_FLOW_VNET_GROUP
Expand Down Expand Up @@ -170,6 +178,33 @@ int dp_install_default_capture_rule_in_vnet_group(uint16_t port_id)
return DP_OK;
}

int dp_change_all_vf_default_jump_rte_flow_group(uint32_t dst_group)
{
struct dp_ports *ports = get_dp_ports();
struct dp_port *port;
struct rte_flow_error error;
int ret;

DP_FOREACH_PORT(ports, port) {
if (port->port_type == DP_PORT_VF && port->allocated) {
if(port->default_flow)
ret = rte_flow_destroy(port->port_id, port->default_flow, &error);

if (DP_FAILED(ret)) {
DPS_LOG_ERR("Failed to destroy default flow", DP_LOG_PORTID(port->port_id), DP_LOG_RET(ret));
return DP_ERROR;
}

if (DP_FAILED(dp_install_jump_rule_int_default_group(port->port_id, dst_group))) {
DPS_LOG_ERR("Failed to install default jump flow", DP_LOG_PORTID(port->port_id));
return DP_ERROR;
}
}
}

return DP_OK;
}

#ifdef ENABLE_VIRTSVC
int dp_install_isolated_mode_virtsvc(int port_id, uint8_t proto_id, uint8_t svc_ipv6[16], rte_be16_t svc_port)
{
Expand Down
6 changes: 3 additions & 3 deletions src/rte_flow/dp_rte_flow_traffic_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define DP_IPIP_ENCAP_HEADER_SIZE (sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr))

static const struct rte_flow_attr dp_flow_pf_attr_ingress = {
.group = 0,
.group = DP_RTE_FLOW_DEFAULT_GROUP,
.priority = 0,
.ingress = 1,
.egress = 0,
Expand All @@ -25,15 +25,15 @@ static const struct rte_flow_attr dp_flow_vf_attr_ingress = {
};

static const struct rte_flow_attr dp_flow_attr_egress = {
.group = 0,
.group = DP_RTE_FLOW_DEFAULT_GROUP,
.priority = 0,
.ingress = 0,
.egress = 1,
.transfer = 0,
};

static const struct rte_flow_attr dp_flow_pf_attr_transfer = {
.group = 0,
.group = DP_RTE_FLOW_DEFAULT_GROUP,
.priority = 0,
#ifdef ENABLE_DPDK_22_11
.ingress = 0,
Expand Down
38 changes: 21 additions & 17 deletions tools/dp_graphtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,27 @@ static void print_packet(struct rte_mbuf *pkt)

dp_graphtrace_sprint(pkt, printbuf, sizeof(printbuf));

if (pktinfo->pkt_type == DP_GRAPHTRACE_PKT_TYPE_SOFTWARE) {
dp_graphtrace_sprint(pkt, printbuf, sizeof(printbuf));
printf("%u: " NODENAME_FMT " %s " NODENAME_FMT ": %s\n",
pktinfo->pktid,
pktinfo->node->name,
pktinfo->next_node ? "->" : " ",
pktinfo->next_node ? pktinfo->next_node->name : "",
printbuf);
} else if (pktinfo->pkt_type == DP_GRAPHTRACE_PKT_TYPE_OFFLOAD) {
printf("%u: captured offload packet : %s\n",
pktinfo->pktid,
printbuf);
} else {
printf("%u: " NODENAME_FMT ": unknown packet type %u\n",
pktinfo->pktid,
pktinfo->node->name,
pktinfo->pkt_type);
switch (pktinfo->pkt_type) {
case DP_GRAPHTRACE_PKT_TYPE_SOFTWARE:
dp_graphtrace_sprint(pkt, printbuf, sizeof(printbuf));
printf("%u: " NODENAME_FMT " %s " NODENAME_FMT ": %s\n",
pktinfo->pktid,
pktinfo->node->name,
pktinfo->next_node ? "->" : " ",
pktinfo->next_node ? pktinfo->next_node->name : "",
printbuf);
break;
case DP_GRAPHTRACE_PKT_TYPE_OFFLOAD:
printf("%u: captured offload packet : %s\n",
pktinfo->pktid,
printbuf);
break;
default:
printf("%u: " NODENAME_FMT ": unknown packet type %u\n",
pktinfo->pktid,
pktinfo->node->name,
pktinfo->pkt_type);
break;
}
}

Expand Down

0 comments on commit 797dd98

Please sign in to comment.