-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg4c_cl.h
112 lines (92 loc) · 2.94 KB
/
g4c_cl.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
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
#ifndef __G4C_CLASSIFIER_H__
#define __G4C_CLASSIFIER_H__
#ifdef __cplusplus
extern "C" {
#endif
#define G4C_CL_VERBOSE 'v'
#define G4C_IPA_STATE_SIZE 256
#define G4C_IPA_STATE_BITS 8
#ifndef PORT_BITS
#define PORT_BITS 8
#endif
#define PORT_STATE_SIZE (1<<PORT_BITS)
#define PORT_MASK (((uint32_t)0xffff)>>(16-PORT_BITS))
#define get_eport(_p) ((int)((_p)&PORT_MASK))
#ifndef PROTO_BITS
#define PROTO_BITS 7
#endif
#define PROTO_STATE_SIZE (1<<PROTO_BITS)
#define PROTO_MASK (((uint16_t)0xffff)>>(16-PROTO_BITS))
#define get_eproto(_p) ((int)((_p)&PROTO_MASK))
typedef int g4c_cl_sid_t;
// All fields in network order
typedef struct _g4c_pattern_t {
uint32_t src_addr;
int nr_src_netbits;
uint32_t dst_addr;
int nr_dst_netbits;
int32_t src_port; // negative means no such field. lower two bytes in network order
int32_t dst_port;
int16_t proto; // negative means no such field.
int idx;
int action;
} g4c_pattern_t;
#define G4C_CL_RES_SZ_ALIGN 4
#define cl_ipa_trans_tbl(bp, id) ((bp)+((id)<<G4C_IPA_STATE_BITS))
#define cl_ipa_trans(bp, id, v) (cl_ipa_trans_tbl((bp), (id))+(v))
#define cl_res(bp, id, stride) ((bp)+(id)*(stride))
#define cl_trans_tbl(bp, id, stsz) ((bp)+((id)*stsz))
typedef struct _g4c_classifier_t {
void *mem;
void *devmem;
size_t memsz;
int nrules;
int res_sz;
uint32_t res_stride; // unit in uint32_t, not bytes size, should be res_sz/sizeof(res_sz)
int nr_saddr_sts;
int *saddr_trs;
uint32_t *saddr_ress;
int nr_daddr_sts;
int *daddr_trs;
uint32_t *daddr_ress;
int nr_sp_sts;
int *sp_trs;
uint32_t *sp_ress;
int nr_dp_sts;
int *dp_trs;
uint32_t *dp_ress;
int nr_pt_sts;
int *pt_trs;
uint32_t *pt_ress;
int *dev_saddr_trs;
int *dev_daddr_trs;
int *dev_sp_trs;
int *dev_dp_trs;
int *dev_pt_trs;
uint32_t *dev_saddr_ress;
uint32_t *dev_daddr_ress;
uint32_t *dev_sp_ress;
uint32_t *dev_dp_ress;
uint32_t *dev_pt_ress;
int *actions;
int *dev_actions;
} g4c_classifier_t;
void g4c_cl_init(int n, char *keys, int *values);
g4c_classifier_t *g4c_create_classifier(g4c_pattern_t *ptn, int nptn, int create_dev, int stream);
int g4c_cpu_classify_pkt(g4c_classifier_t *gcl, uint8_t *ttlptr);
// res_stride is for int*, not byte ptr, res_ofs the same.
// Must be 4B aligned at ttl, otherwise GPU can't read 4B data.
int g4c_gpu_classify_pkts(g4c_classifier_t *dgcl,
int npkts,
uint8_t *data,
uint32_t stride,
uint32_t ttl_ofs,
uint32_t l3hdr_ofs,
int *ress,
uint32_t res_stride,
uint32_t res_ofs,
int s);
#ifdef __cplusplus
}
#endif
#endif