参考了王斌的文档:http://down.51cto.com/data/621454

TIP:笔者使用的版本是0.99.20

需求:在接口模式下添加一条"ip ospf enable"的命令,什么也不做,只输出一些字符;

Quagga内的视图是在vtysh.h定义的,位置:“vtysh/vtysh.c”,我常接触的主要有以下:

/* Vty node structures. */
static struct cmd_node bgp_node =
{
BGP_NODE,
"%s(config-router)# ",
}; static struct cmd_node interface_node =
{
INTERFACE_NODE,
"%s(config-if)# ",
}; static struct cmd_node zebra_node =
{
ZEBRA_NODE,
"%s(config-router)# "
}; static struct cmd_node bgp_ipv4_node =
{
BGP_IPV4_NODE,
"%s(config-router-af)# "
}; static struct cmd_node ospf_node =
{
OSPF_NODE,
"%s(config-router)# "
};

我主要用接口视图和OSPF视图,每个模式下会绑定该模式下可以使用的命令,比如,只有接口模式下才有“ip ospf hello-interval”,而ospf模式下没有,这就是视图和命令的关系。需要添加自己的视图可以在这里定义,这里了解下即可,无需修改;

定义“ip ospf enable”命令:

具体说明见王斌的笔记,这里我就直接加代码了,首先是在"ospfd/osfp_vty.c"加DEFUN,具体如下:

DEFUN (interface_ospf_enable,
interface_ospf_enable_cmd,
"ip ospf enable",
"IP Information\n"
"OSPF interface commands\n"
"enable ip ospf router in this Interface\n")
{
vty_out(vty,"%% GO GO Sven%s", VTY_NEWLINE);
return CMD_SUCCESS;
}

这里和王斌笔记有点不同,如果按照作者的来,可能会看不到最后的提示信息,这里需要加上另外两串字符串,ip和ospf的提示信息,如果只加上enable的提示信息的话,那么你看在敲上“ip ospf ?”的时候可能看到的就是空荡荡的,没提示信息。

将"ip ospf enable"和Interface视图关联起来:

需要在"ospf_vty.c"的ospf_vty_if_init函数内添加以下内容:

 /*My commands*/
install_element(INTERFACE_NODE,&interface_ospf_enable_cmd);


表示该命令关联的是Interface视图,这样就修改完毕了,先不和ospf交互,该命令啥事也不干,只输出一个字符串


至此代码就修改完毕了,按照上一篇的提示编译安装,然后重启服务即可telnet 2609来查看效果了:

[root@sven siwen.xwd]# netstat -nta|grep 260.
tcp 0 0 0.0.0.0:2601 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:2609 0.0.0.0:* LISTEN
[root@ siwen.xwd]# telnet localhost 2609
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'. Hello, this is Quagga (version 0.99.20).
Copyright 1996-2005 Kunihiro Ishiguro, et al. User Access Verification Password:
ospfd> en
ospfd> enable
ospfd# con
ospfd# configure
% Command incomplete.
ospfd# configure te
ospfd# configure terminal
ospfd(config)# int
ospfd(config)# interface eth1
ospfd(config-if)# ip os
ospfd(config-if)# ip ospf
authentication Enable authentication on this interface
authentication-key Authentication password (key)
cost Interface cost
dead-interval Interval after which a neighbor is declared dead
enable enable ip ospf router in this Interface
hello-interval Time between HELLO packets
message-digest-key Message digest authentication password (key)
mtu-ignore Disable mtu mismatch detection
network Network type
priority Router priority
retransmit-interval Time between retransmitting lost link state advertisements
transmit-delay Link state transmit delay
ospfd(config-if)# ip ospf en
ospfd(config-if)# ip ospf enable
% GO GO Sven
ospfd(config-if)#

可以看到"ip ospf enable"命令已经加入进去,并且有提示信息,执行完毕后,会输出字符串。

Quagga添加自己的命令的更多相关文章

  1. nodejs 编写(添加时间戳)命令行工具 timestamp

    Nodejs除了编写服务器端程序还可以编写命令行工具,如gulp.js就是Nodejs编写的. 接下来我们来实现一个添加时间戳的命令: $ timestamp action https://www.n ...

  2. 添加右键菜单命令 在此处打开命令窗口(E)(带图标)

    @color 0A @title 添加右键菜单命令 在此处打开命令窗口(^&E)(带图标) by wjshan0808 @echo off reg add HKCR\Directory\Bac ...

  3. win7下给右键菜单添加启动cmd命令

    win7下给右键菜单添加启动cmd命令 (2013-07-20 19:20:56) 转载▼ 标签: it 右键 cmd 分类: 小软件操作技巧     最近编辑器在用windows下的gvim,但进入 ...

  4. 给Linux添加google搜索命令

    一次面试时,面试官问怎么在终端直接做到在百度搜索自己的名字,当时没回答出来,面试官给了提示,问http协议.答案是说telnet连接www.baidu.com之后GET 昨天偶然看到一篇博客,http ...

  5. uboot中添加自己的命令【转】

    本文转载自:http://blog.csdn.net/huanghai381/article/details/51206646 每个命令都是通过U_BOOT_CMD宏来定义的.这个宏定义了一个相关的结 ...

  6. Linux添加开机启动命令

    1.vi /etc/rc.d/rc.local 添加要启动的命令 如: service php-fpm start  //这样,开机就自动启动了php扩展 2. crontab -e   //是写定时 ...

  7. windows系统添加删除用户命令!

    参考:net   help   usernet   help   group Net   user添加或修改用户帐户或者显示用户帐户信息. 语法net   user   [UserName   [Pa ...

  8. 为自己的git添加alias,命令缩写

    在多人协作开发时,一般用git来进行代码管理.git有一些命令如:git pull . git push等等,这些命令可以设置alias,也就是缩写.如:git pull 是 git pl, git ...

  9. CentOS -- 添加开机自启动 命令 脚本

    如果只是添加一条开机启动的命令: 1. chmod +x /etc/rc.d/rc.local 2. 将命令写到 /etc/rc.d/rc.local 这个文件中 3. reboot

随机推荐

  1. Ubuntu 14.04 关机键无效解决方法

         这几天開始研究ubuntu 14.04软件,安装Cairo-Dock后发现右上角的关机.重新启动.注销菜单点击都没了反应仅仅能通过命令实现,后来经过研究,发现仅仅要设置了 Cairo-Doc ...

  2. Webservice中使用Session、Application

    原文:Webservice中使用Session.Application 在Asp.Net 2.0里,已经能够在WebMethod里使用 Session . Application 这种服务器变量了.一 ...

  3. javascirpt怎样模仿块级作用域(js高程笔记)

    因为javascript没有块级作用域的概念,所以在块语句中定义的变量,实际上是在包括函数中而非语句中创建的. 如: function outputNumbers(count){ for(var i= ...

  4. Java 实现迭代器(Iterator)模式

    类图 /** * 自己定义集合接口, 相似java.util.Collection * 用于数据存储 * @author stone * */ public interface ICollection ...

  5. Serv-U执行CMD命令

    site exec + 命令.比如关机: site exec shutdown -r -t 0 注意,网上很多教程在前面加了一个“quote”,实测根本无效,不知道那些教材是怎么回事. 执行方式有很多 ...

  6. Premiere Pro CC问题集,不断更新

    1.Premiere Pro CC不好用? 是的.原因如下: 1.1 Adobe公司不注重用户体验,不注重工作流程,导致这款软件的用户体验很差,设计也很烂.对比Adobe公司当年用户体验最好的软件 F ...

  7. selenium2入门 用selenium安装、加载、启用插件(一)

    一:下载 下载地址是:http://docs.seleniumhq.org/download/

  8. openwrt固件支持3G和4G上网卡

    http://wiki.openwrt.org/doc/howtobuild/wireless-router-with-a-3g-dongle Building image with support ...

  9. android微信付费

    原文地址:http://blog.csdn.net/intbird 微信官方文档地址:t=resource/res_main_tmpl&verify=1&lang=zh_CN" ...

  10. 在C#中Color结构的各属性颜色对照表(转)

    转自:http://blog.sina.com.cn/s/blog_454dc49501016q2p.html Color.AliceBlue 240,248,255 Color.LightSalmo ...