DPDK examples cmdline完全注释(添加quit功能)

目录

main.c

添加的quit部分代码


DPDK版本:20.05

main.c

/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2014 Intel Corporation.
 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
 * All rights reserved.
 */

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <termios.h>
#include <sys/queue.h>

#include <cmdline_rdline.h>
#include <cmdline_parse.h>
#include <cmdline_socket.h>
#include <cmdline.h>

#include <rte_memory.h>
#include <rte_eal.h>
#include <rte_debug.h>

#include "commands.h"

//启动
//# ./build/cmdline 
//    EAL: Detected 40 lcore(s)
//    EAL: Detected 2 NUMA nodes
//    EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
//    EAL: Selected IOVA mode 'PA'
//    EAL: Probing VFIO support...
//    EAL: VFIO support initialized
//    EAL: PCI device 0000:3b:00.0 on NUMA socket 0
//    EAL:   probe driver: 8086:154d net_ixgbe
//    EAL: PCI device 0000:3b:00.1 on NUMA socket 0
//    EAL:   probe driver: 8086:154d net_ixgbe
//    example> help
//    Demo example of command line interface in RTE
//    
//    This is a readline-like interface that can be used to
//    debug your RTE application. It supports some features
//    of GNU readline like completion, cut/paste, and some
//    other special bindings.
//    
//    This demo shows how rte_cmdline library can be
//    extended to handle a list of objects. There are
//    3 commands:
//    - add obj_name IP
//    - del obj_name
//    - quit
//    - show obj_name
//    
//    example> quit
//    >>>>>>>>>>>>quit<<<<<<<<<<<
//    

int main(int argc, char **argv)
{
	int ret;
	struct cmdline *cl;

    /* 初始化 EAL */
	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_panic("Cannot init EAL\n");

    /* 创建命令行 */
    /* main_ctx: 命令行的全局变量 */
    /* "example> ": 提示符 */
	cl = cmdline_stdin_new(main_ctx, "example> ");
	if (cl == NULL)
		rte_panic("Cannot create cmdline instance\n");

    /*从标准输入读入数据  */
	cmdline_interact(cl);

    /* 释放资源和配置 */
	cmdline_stdin_exit(cl);

	return 0;
}

添加的quit部分代码


/**
 *  在原始的 cmdline 基础上添加 quit 命令
 *  作者: 荣涛 <rongtao@sylincom.com>
 *  时间:   2020年7月28日17:51:20
 */
struct cmd_quit_result {
    cmdline_fixed_string_t quit;
};

static void cmd_quit_parsed(__rte_unused void *parsed_result,
			    struct cmdline *cl,
			    __rte_unused void *data)
{
	cmdline_printf(cl,">>>>>>>>>>>>quit<<<<<<<<<<<\n\n");
    cmdline_stdin_exit(cl);
    exit(0);
}

cmdline_parse_token_string_t cmd_quit_quit =
	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");


cmdline_parse_inst_t cmd_quit = {
	.f = cmd_quit_parsed,  /* function to call */
	.data = NULL,      /* 2nd arg of func */
	.help_str = "quit",
	.tokens = {        /* token list, NULL terminated */
		(void *)&cmd_quit_quit,
		NULL,
	},
};


/**********************************************************/
/**********************************************************/
/****** CONTEXT (list of instruction) */

cmdline_parse_ctx_t main_ctx[] = {
	(cmdline_parse_inst_t *)&cmd_obj_del_show,
	(cmdline_parse_inst_t *)&cmd_obj_add,
	(cmdline_parse_inst_t *)&cmd_help,
	(cmdline_parse_inst_t *)&cmd_quit,
	NULL,
};

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页