- 在实习的时候就对dpdk中
cmdline的实现方式感兴趣,苦于待干的事情太多,一直没有空记录。 - 最近抽出时间准备进行一次较为深入的分析,来看一下dpdk是如何使用c语言来实现
cmdline的. - 本文中使用的dpdk库版本为:16.04
目录
一、分析
1. 从一段代码入手
本段代码摘自 app/test-pmd/cmdline.c,这是dpdk例程 testpmd 其中的一个命令实现。
/* *** SHOW PORT INFO *** */
struct cmd_showport_result {
cmdline_fixed_string_t show;
cmdline_fixed_string_t port;
cmdline_fixed_string_t what;
uint8_t portnum;
};
static void cmd_showport_parsed(void *parsed_result,
__attribute__((unused)) struct cmdline *cl,
__attribute__((unused)) void *data)
{
struct cmd_showport_result *res = parsed_result;
...若干实现
}
cmdline_parse_token_string_t cmd_showport_show =
TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
"show#clear");
cmdline_parse_token_string_t cmd_showport_port =
TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
cmdline_parse_token_string_t cmd_showport_what =
TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what

本文深入分析了DPDK中cmdline的实现,从cmdline_parse_inst_t出发,探讨了命令类型、令牌类型cmdline_parse_token_hdr_t及其结构体cmdline_token_ops,以及子令牌类型如cmdline_parse_token_num_t的创建过程。通过实例展示了新增命令的流程,包括新建命令结构体、命令参数结构体、生成相关令牌和编写回调函数。整个解析机制展示了C语言在实现类似多态和接口功能的巧妙之处。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



