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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#pragma once
#include <stdint.h>
#include <assert.h>
// 负载分担方式
enum e_dist_mode
{
/* 软件二元组哈希 */
LDBC_DIST_OUTER_TUPLE2 = 0,
/* 软件四元组哈希 */
LDBC_DIST_OUTER_TUPLE4 = 1,
/* 软件二元组哈希(解析到隧道内层)*/
LDBC_DIST_INNER_TUPLE2 = 2,
/* 软件四元组哈希(解析到隧道内层)*/
LDBC_DIST_INNER_TUPLE4 = 3,
/* 使用硬件计算结果 */
LDBC_DIST_HARDWARE = 4,
/* MAX */
LDBC_DIST_MAX
};
enum e_hash_mode
{
/* 对称CRC算法 */
LDBC_HASH_SYM_CRC = 0,
/* 非对称CRC算法 */
LDBC_HASH_ASYM_CRC = 1,
/* JANUS使用的哈希算法 */
LDBC_HASH_JANUS = 2,
/* 对称RSS */
LDBC_HASH_SYM_RSS = 3,
/* 非对称RSS */
LDBC_HASH_ASYM_RSS = 4,
/* MAX */
LDBC_HASH_MAX
};
enum complex_layer
{
/* 数据链路层 */
LAYER_TYPE_ETHER = 1 << 0,
LAYER_TYPE_PPP = 1 << 1,
LAYER_TYPE_HDLC = 1 << 2,
LAYER_TYPE_L2 = (LAYER_TYPE_ETHER | LAYER_TYPE_PPP | LAYER_TYPE_HDLC),
/* 数据链路层 -- 隧道 */
LAYER_TYPE_VLAN = 1 << 2,
LAYER_TYPE_PPPOE = 1 << 3,
LAYER_TYPE_MPLS = 1 << 4,
LAYER_TYPE_L2_TUN = (LAYER_TYPE_VLAN | LAYER_TYPE_PPPOE | LAYER_TYPE_MPLS),
/* 网络层 */
LAYER_TYPE_IPV4 = 1 << 5,
LAYER_TYPE_IPV6 = 1 << 6,
LAYER_TYPE_L3 = (LAYER_TYPE_IPV4 | LAYER_TYPE_IPV6),
/* 网络层 -- 隧道 */
/* 传输层 */
LAYER_TYPE_UDP = 1 << 7,
LAYER_TYPE_TCP = 1 << 8,
LAYER_TYPE_L4 = (LAYER_TYPE_UDP | LAYER_TYPE_TCP),
/* 传输层 -- 隧道 */
LAYER_TYPE_G_VXLAN = 1 << 9,
LAYER_TYPE_GTPV1_U = 1 << 10
};
#define MR_PKT_PARSE_RESULT_MAX 8
enum
{
PARSE_CONTINUE,
PARSE_STOP
};
struct pkt_parser_result
{
const char * data;
enum complex_layer this_layer_type;
};
struct pkt_parser
{
enum complex_layer expect_layer_type;
unsigned int nr_expect_results;
struct pkt_parser_result results[MR_PKT_PARSE_RESULT_MAX];
unsigned int nr_results;
};
struct distributer
{
enum e_dist_mode distmode;
enum e_hash_mode hashmode;
uint32_t orin_hash;
int (*fn_distributer)(struct distributer *, struct rte_mbuf * mbufs[], unsigned int nr_mbufs);
uint32_t (*fn_hash_0)(struct distributer *, const void * data, int layer_type, uint32_t orin_hash);
uint32_t (*fn_hash_1)(struct distributer *, const void * data, int layer_type, uint32_t orin_hash);
uint8_t rss_key[40];
};
struct distributer * distributer_create(enum e_dist_mode distmode,
enum e_hash_mode hashmode, uint32_t orin_hash);
int distributer_rss_key_setup(struct distributer * dist_object, const uint8_t * key);
static inline int distributer_caculate(struct distributer * dist_object,
struct rte_mbuf * mbufs[], unsigned int nr_mbufs)
{
return dist_object->fn_distributer(dist_object, mbufs, nr_mbufs);
}
/* 复杂报文格式解析 */
const void * complex_parser_ether(struct pkt_parser * handler, const void * data);
static inline void pkt_parser_init(struct pkt_parser * pkt_parser,
enum complex_layer expect_layer_type, unsigned int nr_expect_results)
{
pkt_parser->expect_layer_type = expect_layer_type;
pkt_parser->nr_expect_results = nr_expect_results;
pkt_parser->nr_results = 0;
}
static inline int pkt_parser_push(struct pkt_parser * pkt_parser,
enum complex_layer this_layer_type, const char * data)
{
assert(pkt_parser->nr_results < pkt_parser->nr_expect_results);
assert(pkt_parser->nr_results < RTE_DIM(pkt_parser->results));
pkt_parser->results[pkt_parser->nr_results].data = data;
pkt_parser->results[pkt_parser->nr_results].this_layer_type = this_layer_type;
pkt_parser->nr_results++;
if (pkt_parser->nr_results >= pkt_parser->nr_expect_results)
return -ENOMEM;
return 0;
}
const char * ldbc_str_dist_mode(struct distributer * dist_object);
const char * ldbc_str_hash_mode(struct distributer * dist_object);
|