#pragma once #include #include #include 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);