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
146
147
148
149
150
151
152
153
154
|
#pragma once
#include <common.h>
#include <rte_ether.h>
#include <vdev_define.h>
TAILQ_HEAD(vdev_instance_list, vdev_instance);
/* 虚设备管理器 */
struct vdev_main
{
/* 虚设备列表 */
struct _vdev * _vdev_array[MR_VDEV_MAX];
unsigned int vdev_max_idx;
/* 用户配置默认值 */
unsigned int sz_tunnel;
unsigned int sz_buffer;
};
/* 保存在APP管理中的上下文指针结构,每个APP一个 */
struct vdev_main_pme
{
struct vdev_instance_list vdi_list;
};
/* 虚拟设备信息,服务进程使用 */
struct _vdev
{
struct vdev vdev;
/* Stream */
unsigned int nr_rxstream;
unsigned int nr_txstream;
unsigned int sz_tunnel;
unsigned int sz_buffer;
/* VNODE */
struct vnode * vnode_rx;
struct vnode * vnode_tx;
struct vnode * vnode_ftx;
struct vnode * vnode_ltx;
/* VNODE CONS/PROD */
struct vnode_prod * vnode_rx_prod;
struct vnode_cons * vnode_tx_cons;
struct vnode_cons * vnode_ftx_cons;
struct vnode_cons * vnode_ltx_cons;
/* LOOP Buffer*/
struct rte_ring ** rx_loop_buffers;
struct rte_ring ** tx_loop_buffers;
/* Mempool */
struct rte_mempool * direct_pool;
struct rte_mempool * indirect_pool;
/* Datapath Function Pointers
* Dispatch : Send data from physical devices to virtual devices
* Collect : Recv data from virtual devices and send to physical devices
* idle_pool : Call when dataplane thread is not busy, eg. flush buffers
* stats_get : Get stats information
* flush : flush packet buffer
*/
int(*dispatch)(struct _vdev * _vdev, queue_id_t qid, struct rte_mbuf * pkts[],
unsigned int nr_pkts, int flags);
int(*collect)(struct _vdev * _vdev, queue_id_t qid, struct rte_mbuf * pkts[],
unsigned int nr_pkts, int flags);
int(*idle_pool)(struct _vdev * _vdev, queue_id_t qid);
int(*stats_get)(struct _vdev * _vdev, struct vdev_stat_info * stat_info);
/* 销毁函数 */
int(*destory)(struct _vdev * _vdev);
/* VDI创建 */
struct vdev_instance * (*vdi_create)(struct _vdev * _vdev, const char * appsym,
unsigned int nr_rxstream, unsigned int nr_txstream);
/* VDI销毁 */
int(*vdi_destory)(struct vdev_instance * vdi);
/* 统计信息暂存,通过外部接口设置,用于计算速度 */
struct vdev_stat_info stat_info_last;
};
// 虚设备查询
struct vdev * vdev_lookup(struct vdev_main * v_main, const char * symbol);
// 虚设备迭代查询
int vdev_iterate(struct vdev_main * v_main, struct vdev ** vdev_result, unsigned int * next);
// 设置虚设备的IP地址
int vdev_set_inaddr(struct vdev * vdev, struct in_addr in_addr, struct in_addr in_mask,
struct in_addr gateway);
// 读取虚设备的IP地址
int vdev_get_inaddr(struct vdev * vdev, struct in_addr * in_addr, struct in_addr * in_mask,
struct in_addr * gateway);
// 设置虚设备的MAC地址
int vdev_set_ether_addr(struct vdev * vdev, struct ether_addr * ether_addr);
// 设置虚设备的MTU
int vdev_set_mtu(struct vdev * vdev, unsigned int mtu);
// 读取虚设备的MTU
int vdev_get_mtu(struct vdev * vdev);
// 启动设备
int vdev_enable(struct vdev * vdev);
// 禁用设备
int vdev_disable(struct vdev * vdev);
// 分发数据
int vdev_dispatch(struct vdev * vdev, queue_id_t qid, struct rte_mbuf * pkts[],
unsigned int nr_pkts, int flags);
// 收集数据
int vdev_collect(struct vdev * vdev, queue_id_t qid, struct rte_mbuf * pkts[],
unsigned int nr_pkts, int flags);
// 空闲轮询
int vdev_idle_poll(struct vdev * vdev, queue_id_t qid);
int vdev_stats_get(struct vdev * vdev, struct vdev_stat_info * stat_info);
void vdev_stats_last_save(struct vdev * vdev, struct vdev_stat_info * stat_info_last);
void vdev_stats_last_get(struct vdev * vdev, struct vdev_stat_info * stat_info_last);
int vdev_data_create(struct vdev_main* v_main, const char * symbol,
unsigned int nr_rxstream, unsigned int nr_txstream,
unsigned int sz_tunnel, unsigned int sz_buffer,
struct rte_mempool * direct_pool,
struct rte_mempool * indirect_pool);
int vdev_loop_create(struct vdev_main* v_main, const char * symbol,
unsigned int sz_tunnel, unsigned int sz_buffer,
struct rte_mempool * direct_pool,
struct rte_mempool * indirect_pool);
int vdev_main_init(struct sc_main * sc);
int vdev_usercfg_query_vdev_list(struct sc_main * sc, const char * str_vdev_type,
char vdevsyms[MR_SYMBOL_MAX][MR_VDEV_MAX], unsigned int * nr_vdevsyms);
int vdev_usercfg_query_vdev_setup(struct sc_main * sc, const char * devsym,
unsigned int * sz_tunnel, unsigned int * sz_buffer);
int vdev_usercfg_query_vdev_in_addr(struct sc_main * sc, const char * devsym,
struct in_addr * addr, struct in_addr * mask, struct in_addr * gateway);
|