DPDK基本数据包转发

DPDK实例

Basic Forwarding Sample Application(基本数据转发)
说明:此文章是本人从dpdk文档中翻译以及自己的一点理解,如果错误,请大佬指正,勿喷!勿骂!

1,基本转发示例应用
       基本准发示例是dpdk进行数据转发的一个简单框架,从中可以简单了解到dpdk如何进行收发数据包的。
2,编译及运行
		首先设置环境变量,
		export RTE_SDK=/path/to/rte_sdk     注:该路径为sdk的源码
		export RTE_TARGET=x86_64-native-linuxapp-gcc  
		make 编译
		运行  :  ./build/basicfwd -l 1 -n 4
3,代码说明
3.1 main()函数
main()函数执行初始化,并为每个lcore调用执行线程。
/*argc argv提供给rte_eal_init(),该函数的返回值是解析的参数*/
int main(int argc, char *argv[])
{

	struct rte_mempool *mbuf_pool;
	unsigned nb_ports;
	uint16_t portid;
	/* Initialize the Environment Abstraction Layer (EAL). */
	int ret = rte_eal_init(argc, argv);   
	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");

	argc -= ret;
	argv += ret;

	/* Check that there is an even number of ports to send/receive on. 
	确定网口是偶数个,以用来收发*/
	nb_ports = rte_eth_dev_count_avail();   //获取可用网口数量
	if (nb_ports < 2 || (nb_ports & 1))
		rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

	/* Creates a new mempool
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值