-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhash_lkup.h
63 lines (54 loc) · 1.38 KB
/
hash_lkup.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef HASH_LOOK_UP_H
#define HASH_LOOK_UP_H
#include <rte_hash.h>
#include <rte_hash.h>
#include <rte_eal.h>
#include <rte_malloc.h>
#include <rte_memory.h>
#include <rte_jhash.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#define MAX_HASH_ENTRIES 1000000
#define FIVE_TUPLE_LEN (sizeof(uint32_t) * 5)
void hash_table_init(char *hash_file);
int hash_table_lkup(const void *key);
static struct rte_hash* create_hash_table(char *hash_file)
{
struct rte_hash *hdl;
struct rte_hash_parameters param;
memset(¶m, 0, sizeof(param));
param.name = "L2FWD";
param.entries = MAX_HASH_ENTRIES;
param.key_len = FIVE_TUPLE_LEN;
param.hash_func = rte_jhash;
param.hash_func_init_val = 0x1234;
hdl = rte_hash_create(¶m);
if(hdl == NULL)
{
rte_exit(EINVAL, "create hash table failed!\n");
}
uint32_t i;
uint32_t ft[5];
int ret;
FILE *fp = fopen(hash_file, "r");
if(fp == NULL)
{
rte_exit(EINVAL, "hash file not exist!\n");
}
i = 0;
while(fscanf(fp, "%u%u%u%u%u", &ft[0], &ft[1], &ft[2], &ft[3], &ft[4]) != EOF)
{
ret = rte_hash_add_key(hdl, (void*)ft);
if(ret == -EINVAL)
{
rte_exit(EINVAL, "add key %u failure!\n", i);
}
i++;
}
printf("load %u hash entries!\n", i);
fclose(fp);
return hdl;
}
#endif