wiki:Packages/SNMP

Version 7 (modified by Tan Gemicioglu, on Dec 19, 2015 at 11:52:49 PM) (diff)

Fixed broken link.

SNMP

NetSNMP

The NetSNMP package can be used with RTEMS to provide a full agent implementation. The NetSNMP project can be found at the following link

http://net-snmp.sourceforge.net/

NetSNMP implements the V1, V2 and V3 versions of the protocol which can be accessed through the SNMP library API. The package also implements a full agent and included in the agent is a MIB-II standard mib. RTEMS used the FreeBSD networking stack and part of this is the sysctl interface. NetSNMP can use this interface to obtain data about interfaces and networking stack.

Building NetSNMP

You can build NetSNMP using the RTEMS Source Builder (RSB). Get the RSB to build your tools and RTEMS then:

  $ cd rtems
  $ ../source-builder/sb-set-builder --log=log_net_snmp_zynq \
         --prefix=$HOME/development/rtems/bsps/4.11 \
         --with-tools=/Users/chris/development/rtems/4.11 \
         --host=arm-rtems4.11 --with-rtems-bsp=xilinx_zynq_zc706 \
                      4.11/net-mgmt/net-snmp

This will build the latest NetSNMP (5.7.2.1) build for the Xilinx Zynq ZC702 BSP.

The version is yet to be tested.

Starting NetSNMP

The NetSNMP agent runs as a single task under RTEMS. The agents main is compiled specifically for RTEMS and is involked by calling the function:

  int snmpd_init (rtems_task_priority priority, char* cmdline);

The command line is the documented in the snmpd man page (http://net-snmp.sourceforge.net/docs/man/snmpd.html). Select the priority that suites your application. SNMP will use your processing resources and as it is typically used for monitoring a priority lower than your important real-time tasks as well as the networking stack is recommended.

This document will refer to snmpd as the NetSNMP agent running as an RTEMS task.

The NetSNMP uses a number of files. The most important of these is the /etc/snmpd.conf. You need to arrange to have this file created before you start snmpd. Many ways exist in RTEMS to create this file. For example code to write the file, coping directly from non-volatile storage to the IFMS, reading from a disk drive, or using the untar call.

The standard NetSNMP configure script creates a list of modules that the agent supports. The modules active when snmpd is running is controlled by command line options. This makes sense on a Unix or Windows host. Here you build into the agent all that is supported by the host and the system administrator enables what is needed. On an embedded system this approach results in an executable that is much larger than required. To keep the image size to what you need a function called by the agent that specifies the list of agent modules you require needs to be provided. An RTEMS application may look like:

 #include <stdio.h>
 #include <rtems.h>
 #include <rtems/untar.h>
 /**
  * NetSNMP MIBS.
  */
 void init_system_mib();
 void init_sysORTable();
 void init_at(); 
 void init_interfaces(); 
 void init_snmp_mib(); 
 void init_tcp(); 
 void init_icmp(); 
 void init_ip(); 
 void init_udp(); 
 void init_vacm_vars(); 
 void init_setSerialNo(); 
 void init_snmpEngine(); 
 void init_snmpMPDStats(); 
 void init_usmStats();
 void init_usmUser(); 
 void init_snmpNotifyTable(); 
 void init_snmpNotifyFilterTable(); 
 void init_snmpNotifyFilterProfileTable(); 
 void init_snmpTargetAddrEntry(); 
 void init_snmpTargetParamsEntry(); 
 void init_target_counters(); 
 void init_nsTransactionTable(); 
 void init_nsModuleTable(); 
 void init_override(); 
 void init_var_route(); 
 void init_vacm_context();
 void init_mib_modules (); 
 int  snmpd_init (rtems_task_priority priority, char* cmdline);
 /*  
  * These are created by the linker when linking a binary file. 
  */
 extern int _binary_net_snmp_files_tar_start; 
 extern int _binary_net_snmp_files_tar_size;
 /*
  * We need to supply this function. It is call by the
  * the snmpd agent. List the modules we need. They will
  * be linked from the NetSNMP library.
  */
 void init_mib_modules () 
 {   
   init_system_mib(); 
   init_sysORTable(); 
   init_at(); 
   init_interfaces(); 
   init_snmp_mib(); 
   init_tcp(); 
   init_icmp(); 
   init_ip(); 
   init_udp(); 
 #if FOR_V3_ENABLE_THESE
   init_vacm_vars(); 
   init_setSerialNo(); 
   init_snmpEngine(); 
   init_snmpMPDStats(); 
   init_usmStats(); 
   init_usmUser(); 
   init_snmpNotifyTable(); 
   init_snmpNotifyFilterTable(); 
   init_snmpNotifyFilterProfileTable(); 
   init_snmpTargetAddrEntry(); 
   init_snmpTargetParamsEntry(); 
   init_target_counters(); 
   init_nsTransactionTable(); 
   init_nsModuleTable(); 
   init_override(); 
   init_var_route(); 
   init_vacm_context(); 
 #endif
 }
 /** 
  * Main line. 
  */ 
 int Init () 
 {
   /*
    * Place the snmpd files into the IMFS.
    */
   Untar_FromMemory ((unsigned char *) (&_binary_net_snmp_files_tar_start), 
                     (int) &_binary_net_snmp_files_tar_size);
   /* 
    * Start the BSD TCP/IP stack. 
    */ 
   rtems_bsdnet_initialize_network ();
   /* 
    * Start the Net SNMP server. 
    */ 
   if (!snmpd_init (150, "-f -L")) 
   { 
     printf ("Net SNMP did not start\n") 
    return 1; 
   }  
   rtems_task_delete (RTEMS_SELF);
 }