Skip to content

Commit

Permalink
datapath: add debug traces
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Jarry <[email protected]>
  • Loading branch information
rjarry committed Jun 7, 2024
1 parent 0778f88 commit fa1b197
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions modules/infra/datapath/br_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
void *br_datapath_loop(void *priv);

#ifdef TRACE_PACKETS
static inline void trace_packet(const char *node, const struct rte_mbuf *m) {
static inline void trace_packet(const char *prefix, const char *node, const struct rte_mbuf *m) {
char buf[BUFSIZ], src[64], dst[64];
const struct rte_ether_hdr *eth;
uint16_t ether_type;
Expand Down Expand Up @@ -149,7 +149,7 @@ static inline void trace_packet(const char *node, const struct rte_mbuf *m) {
}
n += snprintf(buf + n, sizeof(buf) - n, ", (pkt_len=%u)", m->pkt_len);

LOG(NOTICE, "[%s p%u] %s", node, m->port, buf);
LOG(NOTICE, "[%s%s p%u] %s", prefix ?: "", node, m->port, buf);
}
#else
#define trace_packet(node, mbuf)
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/datapath/drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ uint16_t br_node_drop_process(
(void)graph;

for (uint16_t i = 0; i < nb_objs; i++)
trace_packet(node->name, objs[i]);
trace_packet("DROP ", node->name, objs[i]);
rte_pktmbuf_free_bulk((struct rte_mbuf **)objs, nb_objs);

return nb_objs;
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/datapath/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t
struct rte_mbuf *m = node->objs[i];
struct eth_input_mbuf_data *if_in = eth_input_mbuf_data(m);
if_in->iface = port_get_iface(m->port);
trace_packet(node->name, m);
trace_packet("", "RX", m);
}

rte_node_enqueue(graph, node, ETH_IN, node->objs, count);
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/datapath/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tx_process(struct rte_graph *graph, struct rte_node *node, void **objs, uint16_t
for (i = 0; i < nb_objs; i++) {
struct rte_mbuf *mbuf = objs[i];

trace_packet(node->name, mbuf);
trace_packet("", "TX", mbuf);

if (mbuf->port != port_id) {
if (burst_start != i) {
Expand Down
54 changes: 52 additions & 2 deletions modules/ipip/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,52 @@ static struct rte_hash *ipip_hash;
struct iface *ipip_get_iface(ip4_addr_t local, ip4_addr_t remote, uint16_t vrf_id) {
struct ipip_key key = {local, remote, vrf_id};
void *data;
int ret;

if (rte_hash_lookup_data(ipip_hash, &key, &data) < 0)
return NULL;
if ((ret = rte_hash_lookup_data(ipip_hash, &key, &data)) < 0) {
char buf[256], l[64], r[64];
inet_ntop(AF_INET, &local, l, sizeof(l));
inet_ntop(AF_INET, &remote, r, sizeof(r));
snprintf(
buf,
sizeof(buf),
"rte_hash_lookup_data: (local=%s, remote=%s, vrf_id=%u)",
l,
r,
vrf_id
);
return errno_log_null(-ret, buf);
}

return data;
}

void list_ipip(void) {
char local[64], remote[64];
const struct iface *iface;
const struct ipip_key *k;
const void *key;
uint32_t iter;
int32_t idx;
void *data;

iter = 0;
while ((idx = rte_hash_iterate(ipip_hash, &key, &data, &iter)) >= 0) {
iface = data;
k = key;

inet_ntop(AF_INET, &k->local, local, sizeof(local));
inet_ntop(AF_INET, &k->remote, remote, sizeof(remote));

LOG(INFO,
"(local=%s remote=%s vrf_id=%u) -> iface=%s",
local,
remote,
k->vrf_id,
iface->name);
}
}

static int iface_ipip_reconfig(
struct iface *iface,
uint64_t set_attrs,
Expand Down Expand Up @@ -67,6 +106,17 @@ static int iface_ipip_reconfig(
if ((ret = rte_hash_add_key_data(ipip_hash, &next_key, iface)) < 0)
return errno_log(-ret, "rte_hash_add_key_data");

char local[64], remote[64];
inet_ntop(AF_INET, &next->local, local, sizeof(local));
inet_ntop(AF_INET, &next->remote, remote, sizeof(remote));

LOG(INFO,
"(local=%s remote=%s vrf_id=%u) -> iface=%s",
local,
remote,
vrf_id,
iface->name);

cur->local = next->local;
cur->remote = next->remote;
iface->vrf_id = vrf_id;
Expand Down
1 change: 1 addition & 0 deletions modules/ipip/datapath_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ipip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs,
ip_data = ip_local_mbuf_data(mbuf);
ipip = ipip_get_iface(ip_data->dst, ip_data->src, ip_data->vrf_id);
if (ipip == NULL) {
list_ipip();
next = NO_TUNNEL;
goto next;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/ipip/ipip_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ struct iface_info_ipip {

struct iface *ipip_get_iface(ip4_addr_t local, ip4_addr_t remote, uint16_t vrf_id);

void list_ipip(void);

#endif

0 comments on commit fa1b197

Please sign in to comment.