如何在以太网芯片W5200中实现SNMP?

今天给大家介绍W5200应用笔记之如何在W5200中实现SNMP。首先简单介绍下SNMP。简单网络管理协议(SNMP)是一个“管理IP网络上的设备的网络标准协议”,通常支持SNMP的设备包括路由器、交换机、服务器、工作站、打印机、调制解调器等等。

 

SNMP对于任何程序员来说都是容易理解的。简而言之可以使系统更加简化。网络设备以后台程序的形式运行SNMP代理,该后台程序响应来自网络的请求。代理提供大量的对象标识符 (Object Identifiers ,OIDs)。一个OID是唯一的键值对。代理填充这些值并且使它们有效。SNMP管理(客户端)能够查询代理的键值对的具体信息。从编程的角度来看这与引进一堆的全局变量没什么区别。SNMP OIDs能够被读或写。向一个SNMP设备写信息是相当罕见的,这是一些管理应用程序控制设备(如交换机的管理GUI)的常用方法。在SNMP中存在一个基本的认证方法,允许管理者发送一个通用名称(认为明文密码)去认证OIDs的读或写。大多数设备使用不安全的通用名称“public”。SNMP使用UDP端口161和162通信。

 

该应用笔记展示了w5200E01-M3中的<SNMP代理>与PC中的<SNMP管理>如何进行通信。

该笔记的所有代码和文件都可在中文网站进行下载。

1. SNMP协议

SNMP消息格式指定在消息里包括哪些字段并按什么顺序。最终,该消息是由几层嵌套的字段组成。在最外面的一层,SNMP消息是Sequence类型的单独字段。完整的消息是一个序列的三个小的字段:SNMP Version(整型),SNMP Community String(8位字符串),和SNMP PDU(GetRequest,或SetRequest)。

SNMP Version和SNMP Community String是原始数据类型,他们不是从小的字段得到的(没有更多的层)。但是,PDU是一个复杂的数据类型,由一些小的字段组成(更多层次)。PDU由一个Request ID (整型)、Error (整型)、Error Index (整型)和一个Varbind List组成。Varbind或 Variable Binding是两个特定字段序列。第一个字段是一个OID,存放指定的参数。第二个字段包括该指定参数的值。在SetRequest中,参数值的数据类型必须与MIB中设置的参数类型一致。 在GetRequest中,参数值是空,长度是0×00。该空数据是Value数据的占位符,该Value数据是SNMP代理使用GetResponse PDU返回得到的。此外,顾名思义, Varbind List就是一个Varbinds Sequence。最后,当一个消息设置或获取一个单独的参数,Varbind List只允许有一个Varbind 。SNMP里每个字段的解释请看下表。

MIB树的SNMP相关分支在网络分支中,包括以下两种主要分支类型:

n 公共分支(mgmt=2),由互联网工程任务组(Internet Engineering Task Force ,IETF) RFCs定义,与所有的SNMP管理设备一样。

n 私有分支(private=4),由互联网号码分配局(IANA)分配,这些分支的分配由一些公司和组织定义。

下图展示了SNMP MIB树的结构。MIB树的深度和宽度没有限制。

MIB树的树根是国际标准化组织(iso),它的下面是组织(org)分支,再下面是国防部(dod),再下面是互联网(internet)。管理(mgmt),主要的公共分支,定义所有供应商设备通用的网络管理参数。在管理分支的下面是MIB-II (mib-2),在其下面是通用管理功能分支,如系统管理,打印机,主机资源和接口。

MIB的私有分支包括一些大的组织,这些组织在企业分支的下面。每个组织在该对象下面都有一个根分支节点。每个组织创建它自己的MIB分支和对象子网,这必须符合称为结构管理信息(SMI)的定义。SMI定义了MIB对象允许的数据类型。

2. SNMP Get/Set/Trap演示

[net-snmp version 5.7 package for windows]用来演示。

(Net-SNMP是一套使用和调度SNMP协议的软件。它包括一个通用的客户端程序库、一套命令行代码、一个高度可扩展的SNMP代理、perl模块和python模块)。

 

在用Microsoft Visual Studio建立工程后,可以获取所有的net-snmp示例可执行文件。在所有的net-snmp示例可执行文件中,使用snmpget.ex,snmpset.exe,snmpwalk.exe和snmptrapd.exe。

2.1 Trap 演示

首先,如下所示启动net-snmp包中的<snmptrapd.exe>。

 

重启[w5200E01-M3]模块。

 

然后,可以看见PC中的snmp trap数据包,如下所示。

2.2 Get Request演示(系统MIB)

2.3 Set Request演示(私有MIB), LED On/Off测试

如果发出以下命令,[w5200E01-M3]的LED将会熄灭。

snmpset -v 1 -c public 192.168.11.251 .1.3.6.1.4.1.0.2.0 i 0

如果发出以下命令,[w5200E01-M3]的LED将会点亮。

snmpset -v 1 -c public 192.168.11.251 .1.3.6.1.4.1.0.2.0 i 1

2.4 Walk演示

3. 使用SNMP Library示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
INTRODUCTION lwIP is a small independent implementation of the TCP/IP protocol suite. The focus of the lwIP TCP/IP implementation is to reduce the RAM usage while still having a full scale TCP. This making lwIP suitable for use in embedded systems with tens of kilobytes of free RAM and room for around 40 kilobytes of code ROM. lwIP was originally developed by Adam Dunkels at the Computer and Networks Architectures (CNA) lab at the Swedish Institute of Computer Science (SICS) and is now developed and maintained by a worldwide network of developers. FEATURES * IP (Internet Protocol, IPv4 and IPv6) including packet forwarding over multiple network interfaces * ICMP (Internet Control Message Protocol) for network maintenance and debugging * IGMP (Internet Group Management Protocol) for multicast traffic management * MLD (Multicast listener discovery for IPv6). Aims to be compliant with RFC 2710. No support for MLDv2 * ND (Neighbor discovery and stateless address autoconfiguration for IPv6). Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 (Address autoconfiguration) * DHCP, AutoIP/APIPA (Zeroconf), ACD (Address Conflict Detection) and (stateless) DHCPv6 * UDP (User Datagram Protocol) including experimental UDP-lite extensions * TCP (Transmission Control Protocol) with congestion control, RTT estimation fast recovery/fast retransmit and sending SACKs * raw/native API for enhanced performance * Optional Berkeley-like socket API * TLS: optional layered TCP ("altcp") for nearly transparent TLS for any TCP-based protocol (ported to mbedTLS) (see changelog for more info) * PPPoS and PPPoE (Point-to-point protocol over Serial/Ethernet) * DNS (Domain name resolver incl. mDNS) * 6LoWPAN (via IEEE 802.15.4, BLE or ZEP) APPLICATIONS * HTTP server with SSI and CGI (HTTPS via altcp) * SNMPv2c agent with MIB compiler (Simple Network Management Protocol), v3 via altcp * SNTP (Simple network time protocol) * NetBIOS name service responder * MDNS (Multicast DNS) responder * iPerf server implementation * MQTT client (TLS support via altcp) LICENSE lwIP is freely available under a BSD license. DEVELOPMENT lwIP has grown into an excellent TCP/IP stack for embedded devices, and developers using the stack often submit bug fixes, improvements, and additions to the stack to further increase its usefulness. Development of lwIP is hosted on Savannah, a central point for software development, maintenance and distribution. Everyone can help improve lwIP by use of Savannah's interface, Git and the mailing list. A core team of developers will commit changes to the Git source tree. The lwIP TCP/IP stack is maintained in the 'lwip' Git module and contributions (such as platform ports) are in the 'contrib' Git module. See doc/savannah.txt for details on Git server access for users and developers. The current Git trees are web-browsable: http://git.savannah.gnu.org/cgit/lwip.git http://git.savannah.gnu.org/cgit/lwip/lwip-contrib.git Submit patches and bugs via the lwIP project page: http://savannah.nongnu.org/projects/lwip/ Continuous integration builds (GCC, clang): https://travis-ci.org/lwip-tcpip/lwip DOCUMENTATION Self documentation of the source code is regularly extracted from the current Git sources and is available from this web page: http://www.nongnu.org/lwip/ Also, there are mailing lists you can subscribe at http://savannah.nongnu.org/mail/?group=lwip plus searchable archives: http://lists.nongnu.org/archive/html/lwip-users/ http://lists.nongnu.org/archive/html/lwip-devel/ There is a wiki about lwIP at http://lwip.wikia.com/wiki/LwIP_Wiki You might get questions answered there, but unfortunately, it is not as well maintained as it should be. lwIP was originally written by Adam Dunkels: http://dunkels.com/adam/ Reading Adam's papers, the files in docs/, browsing the source code documentation and browsing the mailing list archives is a good way to become familiar with the design of lwIP. Adam Dunkels Leon Woestenberg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值