Skip to content
Merged
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
39 changes: 39 additions & 0 deletions lib/ff_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,48 @@ int ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag,
typedef int (*dispatch_func_t)(void *data, uint16_t *len,
uint16_t queue_id, uint16_t nb_queues);

/*
* Packet dispatcher context structure.
* Contains additional context information for packet dispatching.
*/
struct ff_dispatcher_context {
struct {
uint8_t stripped;
uint16_t vlan_tci; /**< Priority (3) + CFI (1) + Identifier Code (12) */
} vlan;
};

/*
* Enhanced packet dispatch callback function with context.
* Implemented by user.
*
* @param data
* The data pointer of this packet.
* @param len
* The length of this packet.
* @param queue_id
* Current queue of this packet.
* @param nb_queues
* Number of queues to be dispatched.
* @param context
* Additional context information for packet dispatching.
*
* @return 0 to (nb_queues - 1)
* The queue id that the packet will be dispatched to.
* @return FF_DISPATCH_ERROR (-1)
* Error occurs or packet is handled by user, packet will be freed.
* @return FF_DISPATCH_RESPONSE (-2)
* Packet is handled by user, packet will be responsed.
*/
typedef int (*dispatch_func_context_t)(void *data, uint16_t *len,
uint16_t queue_id, uint16_t nb_queues, struct ff_dispatcher_context context);

/* regist a packet dispath function */
void ff_regist_packet_dispatcher(dispatch_func_t func);

/* Register a packet dispatch function with context support */
void ff_regist_packet_dispatcher_context(dispatch_func_context_t func);

/*
* RAW packet send direty with DPDK by user APP.
*
Expand Down
32 changes: 28 additions & 4 deletions lib/ff_dpdk_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ static pcblddr_func_t pcblddr_fun;

static struct rte_ring **dispatch_ring[RTE_MAX_ETHPORTS];
static dispatch_func_t packet_dispatcher;
static dispatch_func_context_t packet_dispatcher_with_context;

static uint16_t rss_reta_size[RTE_MAX_ETHPORTS];

Expand Down Expand Up @@ -1614,10 +1615,27 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
ff_traffic.rx_bytes += rte_pktmbuf_pkt_len(rtem);
}

if (!pkts_from_ring && packet_dispatcher) {
uint64_t cur_tsc = rte_rdtsc();
int ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
usr_cb_tsc += rte_rdtsc() - cur_tsc;
if (!pkts_from_ring && (packet_dispatcher || packet_dispatcher_with_context)) {
uint64_t cur_tsc;
int ret;
if (packet_dispatcher) {
cur_tsc = rte_rdtsc();
ret = (*packet_dispatcher)(data, &len, queue_id, nb_queues);
usr_cb_tsc += rte_rdtsc() - cur_tsc;
} else if (packet_dispatcher_with_context) {
struct ff_dispatcher_context ctx;
if (rtem->ol_flags & RTE_MBUF_F_RX_VLAN_STRIPPED) {
ctx.vlan.stripped = 1;
ctx.vlan.vlan_tci = rte_cpu_to_be_16(rtem->vlan_tci);
} else {
ctx.vlan.stripped = 0;
ctx.vlan.vlan_tci = 0;
}
cur_tsc = rte_rdtsc();
ret = (*packet_dispatcher_with_context)(data, &len, queue_id, nb_queues, ctx);
usr_cb_tsc += rte_rdtsc() - cur_tsc;
}

if (ret == FF_DISPATCH_RESPONSE) {
rte_pktmbuf_pkt_len(rtem) = rte_pktmbuf_data_len(rtem) = len;
/*
Expand Down Expand Up @@ -2772,6 +2790,12 @@ ff_regist_packet_dispatcher(dispatch_func_t func)
packet_dispatcher = func;
}

void
ff_regist_packet_dispatcher_context(dispatch_func_context_t func)
{
packet_dispatcher_with_context = func;
}

uint64_t
ff_get_tsc_ns()
{
Expand Down