Myricom logo

Data Fields
snf_rss_mode_function Struct Reference

Data Fields

int(* rss_hash_fn )(struct snf_recv_req *r, void *context, uint32_t *hashval)
 
void * rss_context
 

Detailed Description

User-defined RSS hashing function parameters. Users that provide their own callbacks can generate their own hash based on the contents of a received packet. NOTE This feature is available only in the SNF kernel API

Field Documentation

void* snf_rss_mode_function::rss_context

User context that is reflected when the user-provided rss_hash_fn is called.

int(* snf_rss_mode_function::rss_hash_fn)(struct snf_recv_req *r, void *context, uint32_t *hashval)

User-provided hash function. The callback is provided with a valid snf_recv_req structure which contains a packet as received by Sniffer. It is up to the user to inspect and parse the packet to produce a unique 32-bit hash. The implementation will map the 32-bit into one of the rings allocated in snf_open. The function must return one of three values

  • 0 The packet is queued in the ring based on the 32-bit hash value that is provided, which is hashval % num_rings.
  • <0 The packet is dropped and accounted as a drop in the ring corresponding to the 32-bit hash value provided by the user.

In the example below, we replace the default hash function with a hash function that sends packets to different rings at every interval of 500 packets. This approach ignores the actual packet contents and the importance of flow affinity, we just want to spread the packet analysis to different rings and threads.

#define MAX_RINGS 32
#define PKT_INTERVAL 500
static uint32_t cnt[MAX_RINGS];
static uint32_t cur_ring = 0;
static int
custom_hash(struct snf_recv_req *r, void *context, uint32_t *hashval)
{
if (++cnt[cur_ring] == PKT_INTERVAL) {
cnt[cur_ring] = 0;
if (++cur_ring == MAX_RINGS)
cur_ring = 0;
}
// Return cur_ring as the hash value, since Sniffer will apply a
// modulo and the corresponding ring will receive the packet when
// calling snf_recv()
*hash_val = cur_ring;
return 0;
}
// At snf_open time, select a custom hash approach.
struct snf_rss_params rssp;
rssp.params.rss_function.rss_hash_fn = custom_hash;
rssp.params.rss_function.rss_context = NULL; // Don't need a context
// On port 0, we will open MAX_RINGS rings, use default flags,
// select an 800 MB data ring and chose our custom hashing function.
int rc = snf_open(0, MAX_RINGS, &rssp, 800, 0, &hsnf);
if (rc) {
perror("Error in snf_open");
exit(EXIT_FAILURE);
}
Myricom banner
Thu Jan 7 2021 14:20:25 - SNF 5.3.2.11.54430