quagga中cli命令分析
来源:互联网 发布:单倍型分析软件 编辑:程序博客网 时间:2024/06/05 15:43
在已有的命令视图中新增加命令
定义命令并处理
- 定义命令,
DEFUN(处理函数,命令名称,命令字符串,帮助信息)
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \ DEFUN_CMD_FUNC_DECL(funcname) \ DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \ DEFUN_CMD_FUNC_TEXT(funcname)
DEFUN (vpnv4_route_target_import, vpnv4_route_target_import_cmd, "rt-import ASN:nn", "Route target import\n" "ASN:nn, e.g., 100:1\n"){ return bgp_vpn_rt_import (SAFI_MPLS_VPN, vty, argv[0]);}
处理函数声明: Static int bgp_vpn_rt_import (safi_t safi, struct vty *vty, const char *rt_str);
- 处理函数实现;
int bgp_vpn_rt_import (safi_t safi, struct vty *vty, const char *rt_str){ return CMD_SUCCESS;}
- 安装该命令到对应的命令视图下,
Install_element(命令视图,命令名称)
voidbgp_mplsvpn_init (void){ install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd); install_element (BGP_VPNV4_NODE, &vpnv4_network_route_map_cmd); install_element (BGP_VPNV4_NODE, &vpnv4_route_target_import_cmd); install_element (BGP_VPNV4_NODE, &vpnv4_route_target_export_cmd); ...}
show running显示命令
- show running读取命令的位置
/* Write current configuration into the terminal. */ALIAS (config_write_terminal, show_running_config_cmd, "show running-config", SHOW_STR "running configuration\n")
可以看到show running使用的是config_write_terminal这个函数体,它的实现在:
/* Write current configuration into the terminal. */DEFUN (config_write_terminal, config_write_terminal_cmd, "write terminal", "Write running configuration to memory, network, or terminal\n" "Write to terminal\n"){ unsigned int i; struct cmd_node *node; if (vty->type == VTY_SHELL_SERV) { for (i = 0; i < vector_active (cmdvec); i++) if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh) { if ((*node->func) (vty)) vty_out (vty, "!%s", VTY_NEWLINE); } } else { vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, VTY_NEWLINE); vty_out (vty, "!%s", VTY_NEWLINE); for (i = 0; i < vector_active (cmdvec); i++) if ((node = vector_slot (cmdvec, i)) && node->func) { if ((*node->func) (vty)) vty_out (vty, "!%s", VTY_NEWLINE); } vty_out (vty, "end%s",VTY_NEWLINE); } return CMD_SUCCESS;}
执行show running时调用了node->func函数,install_node时会给node->func赋值:
/* Install top node of command vector. */voidinstall_node (struct cmd_node *node, int (*func) (struct vty *)){ vector_set_index (cmdvec, node->node, node); node->func = func; node->cmd_vector = vector_init (VECTOR_MIN_SIZE);}
只要func不为null,调用show running就会执行此函数。以BGP为例,install_node定义的位置如下:
voidbgp_vty_init (void){ /* Install bgp top node. */ install_node (&bgp_node, bgp_config_write); install_node (&bgp_ipv4_unicast_node, NULL); install_node (&bgp_ipv4_multicast_node, NULL); install_node (&bgp_ipv6_unicast_node, NULL); install_node (&bgp_ipv6_multicast_node, NULL); install_node (&bgp_vpnv4_node, NULL); install_node (&bgp_vpnv6_node, NULL); install_node (&bgp_encap_node, NULL); install_node (&bgp_encapv6_node, NULL); /* Install default VTY commands to new nodes. */ install_default (BGP_NODE); install_default (BGP_IPV4_NODE); ... }
可以看到执行的是bgp_config_write函数,可以把需要显示的命令及数值添加到函数里,以配置的bgp vpn rt为例,需要在对应的node视图下添加:
vty_out (vty, " rt-export %s", rt_export_buf); vty_out (vty, "%s", VTY_NEWLINE);
在quagga的基础上新增加命令视图(转)
- 定义命令视图类型,enum node_type ;
- 定义命令视图结构,struct cmd_node;
Static struct cmd_node 视图名称={
命令视图类型,
该视图下的提示符字符串,
}; - 安装命令视图,install_node(),install_default();
Install_node(视图名称,回调函数)
Install_default(视图类型)
1 0
- quagga中cli命令分析
- quagga中cli命令分析
- quagga 中 命令框架
- quagga 命令定义的代码分析
- quagga 中 rip运行流程具体分析
- quagga 命令定义的代码分析--从定义到实现
- quagga 命令定义的代码分析(DEFUN)
- 基于quagga开源包的嵌入式CLI开发
- quagga代码分析一
- docker中安装quagga
- Quagga添加自己的命令
- 设置redis-cli命令到PATH中
- quagga
- quagga
- dce quagga中增加netanim
- 在容器中使用quagga
- (1) quagga源码分析--大内总管zebra
- Linux中实现redis-cli命令在任意目录执行
- 现学现卖微信小程序开发(二)
- Android将系统emoji表情转换成十进制字符串
- 函数对象
- ReactNative实战系列 组件封装之Dialog(iOS和Android通用)
- 性能指标之资源指标-CPU-配置(1)
- quagga中cli命令分析
- hive参数
- 几段PHP 数组操作代码
- spring applicationContext.xml文件移到resources目录下,需要做哪些事情
- 现学现卖微信小程序开发(三):引入“Rx”,为小程序插上翅膀
- CSS预处理器-Less
- 把java工程打包成为一个可执行的jar包
- 未能加载文件或程序集 WPFToolkit
- SpringBoot启动时报错