您的位置:首页 > 其它

使用AdventNet快速开发网管软件Agent端

2016-06-25 20:32 666 查看
       开发网管软件的工具和源码包有很多,如Java的SNMP4J,C++的SNMP++,C的Net-SNMP和AdventNet  Agent Toolkit C Edition工具包。这里我介绍一下使用AdventNet工具来开发Agent(代理端)的思路,并不注重具体实现的过程。
       首先我来介绍一下AdventNet  Agent Toolkit C Edition这款工具,当我们安装好后会出现如下图标



点击图标打开软件后看到如下界面,主要用到的有MibEditor(编辑mib)、MibBrowser(浏览mib节点)、Agent Complier(编译mib文件生成对应的h文件和c文件)。



我用MIbEditor编辑定义了一个Mib用MibBrowser打开如下:



然后将这个Mib用Agent Compiler生成对应的h和c文件,用Visual Studio 2013 生成对应的Agent工程,对于一个表会生成三个文件c文件,表名+ftov.c是对文本数据库的读写操作,表名+ hdlr.c用来初始化表和存储空间,表名+instru.c对Get和Set进行处理,我们对工具生成的源码以及Get、Set和Trap过程进行分析。
程序的主要函数调用关系如下图:



其中黄色部分为处理trap主要函数,绿色部分为处理接收SNMP PDU(协议数据单元)的主要函数,蓝色部分为处理发送SNMP PDU。下面对这个几个函数进行具体的解释。
1 BaseLoop()
This function will call an indefinite loop, inside that loop it will manage all protocols functionality.

这个函数将调用一个无限的循环,在这个循环中,它将管理所有的协议功能。
2 CheckReceiveAndProcessSnmpMessage()
This function will do the core functionality of the agent.
此方法将做代理的核心功能。

3 MakeAndSendMasterAgentsTrap()
It will create trap message by taking trapPdu from thetrapPduVector and will put the message in trapvector. PollTrapMessage method will send the trap then and there.

它将从thetrappduvector以trappdu创建陷阱消息并将消息存储在trapvector。polltrapmessage方法将陷阱立即发送。
4 SendTrapMessage()
Creates a trap SNMP message with given entries and add it to the trap list.

创建一个给定的条目陷阱SNMP报文,并将其添加到陷阱列表中。
5 PollTrapList()
Polls the trap list if any Entry is there then it will send trap to the appropriate managers who are registered in the manager list.

调查陷阱列表,如果有任何条目,那么它会发送陷阱到在管理器列表中注册了的适当的管理者。
6 CheckReceiveAndProcessUdpSnmpMessage()
This function will do the core functionality of the agent for Udp domain.

这个函数将UDP域做代理的核心功能。
7 PollAndReceiveSnmpMessage()
It will poll the SnmpSession periodically and return the received SNMP message if available.

它将定期调查snmpsession返回接收到的可用的SNMP报文。
8 ReadSnmpMessage()
It will read a SNMP message from the application. The application may be manager/subagent.
它将从应用程序读取一个SNMP报文。应用程序可能是管理端/副代理。
9 ReadUdpPacket()

It will read the data from the specified socket.
它将从指定的套接字读取数据。
10 ProcessAndSendSnmpPkt()
This function will create receivedInfo and add it in the queue.

这个函数会创建receivedinfo并加入队列中。

11 ProcessRcvdSnmpReq()
It will call processSnmpMessage method to process the received message.

这将调用processsnmpmessage方法处理接收到的消息的。
12 ProcessSnmpMessage()
This function will process the recevied SNMP message depending upon the version.
这个函数将根据SNMP的版本来进行处理接收到的SNMP报文。
13 ParseSnmpV1V2Message()
This function will parse the received Snmp Message and stored it in the Pdu for V1 and V2 parameters.
这个函数将解析接收到的SNMP报文存放在PDU为V1和V2的参数。
14 SendSnmpMessage()
It will send SNMP message to the remote application, the remote may be manager or subagent.
它将发送SNMP消息给远程应用程序,远程可以是管理端或副代理。

csdn源码:http://download.csdn.net/detail/davebobo/9559593
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: