Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support TRex callbacks #1122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CALLBACKS_H
#define CALLBACKS_H

#include <rte_mbuf.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
uint16_t (*tx_burst)(uint16_t port, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
} TrexCallbackFuncs;

extern TrexCallbackFuncs trex_callback_funcs;

inline void trex_callback_funcs_set(TrexCallbackFuncs* cbs) {
trex_callback_funcs = *cbs;
}

#ifdef __cplusplus
}
#endif

#endif
3 changes: 3 additions & 0 deletions src/main_dpdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extern "C" {
#include "astf/astf_db.h"
#include "utl_offloads.h"
#include "trex_defs.h"
#include "callbacks.h"

#define MAX_PKT_BURST 32
#define BP_MAX_CORES 48
Expand Down Expand Up @@ -1186,6 +1187,8 @@ COLD_FUNC void CPhyEthIgnoreStats::dump(FILE *fd) {
DP_A4(m_rx_arp);
}

TrexCallbackFuncs trex_callback_funcs{NULL};

// Clear the RX queue of an interface, dropping all packets
void CPhyEthIF::flush_rx_queue(void){

Expand Down
12 changes: 12 additions & 0 deletions src/main_dpdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "bp_sim.h"
#include "dpdk_port_map.h"
#include "trex_modes.h"
#include "callbacks.h"

// These are statistics for packets we send, and do not expect to get back (Like ARP)
// We reduce them from general statistics we report (and report them separately, so we can keep the assumption
Expand Down Expand Up @@ -201,6 +202,17 @@ class CPhyEthIF {
if (unlikely(m_dev_tx_offload_needed)) {
tx_burst_offload_csum(tx_pkts, nb_pkts, m_dev_tx_offload_needed);
}

if (trex_callback_funcs.tx_burst != NULL) {
uint16_t send_no_pkts = trex_callback_funcs.tx_burst(m_repid, tx_pkts, nb_pkts);
uint16_t dropped_pkts = nb_pkts - send_no_pkts;

if (send_no_pkts < 1) {
return dropped_pkts;
}
return rte_eth_tx_burst(m_repid, queue_id, tx_pkts, send_no_pkts) + dropped_pkts;
}

return rte_eth_tx_burst(m_repid, queue_id, tx_pkts, nb_pkts);
} else {
for (int i=0; i<nb_pkts;i++) {
Expand Down