Using SNMP

Files In This Example

The source code for this example in the following locations:

Overview of SNMP

The JUNOS SDK includes (initially limited) support for Net-SNMP. The SNMP documentation is at

The sample application, jnx-ifinfod, is intended to provide the basis for your use of SNMP. The application creates an SNMP subagent for communicating with SNMP clients to poll and display system interface information through the command-line interface (CLI). This topic provides an introduction to the sample code.

An SNMP client initiates a get() or getnext() operation to send a request to an snmpd agent on the router. The agent for the SNMP daemon on the router (snmpd) communicates through the Net-SNMP library with the corresponding SNMP subagent in the application, resolves the request for the relevant object identifiers (OIDs), and returns a response to the client through snmpd.

Limitations of Current Support

SNMP support has the following current limitations:

Applications that use SNMP need to include two more libraries (binaries only): libjsnmp and libverify. Any application that links with libnet-snmp and libjnet-snmp must also link with both these libraries.

How the Sample Application Uses SNMP

The sample application creates the MIBs jnxIfinfoInterfaceTable, jnxIfinfoInterfaceAliasTable, and jnxIfinfoNetSnmpVersion. The code can be easily extended to support other tables or scalar MIBs in the future. For details about how the sample MIBs are defined, see Definitions for Application-Specific MIBs.

The sample application's subagent is initialized at daemon startup. The subagent is initialized using a JUNOS function, netsnmp_set_evcontext(event_context). This function sets the event context used in the Net-SNMP library, and then calls the Net-SNMP functions netsnmp_ds_set_init() and init_agent(). It then initializes MIB modules and implements them using the Net-SNMP functions netsnmp_register_scalar(), netsnmp_create_handler_registration(), and netsnmp_register_table_iterator().

Displaying a Message

Sample output from the application:

jnxIfinfoInterfaceAliasTable : OID: 1,3,6,1,4,1,2636,3,48,1,1

An snmpwalk on this OID returns the alias ID and alias name configured under
"edit jnx-ifinfod" configuration hierarchy:

  	snmpwalk bart public .
	enterprises.juniperMIB.jnxMibs. = 128
	enterprises.juniperMIB.jnxMibs. = 129
	enterprises.juniperMIB.jnxMibs. = 132
	enterprises.juniperMIB.jnxMibs. = "myt3"
	enterprises.juniperMIB.jnxMibs. = "vbns"
	enterprises.juniperMIB.jnxMibs. = "vbns"

Using SNMP in Your SDK Application

The following code shows these steps that your application should follow to set up SNMP:

  1. The application calls netsnmp_set_evcontext(), netsnmp_ds_set_init(), and init_agent().

  2. The application registers the MIB modules and implements their functions using the Net-SNMP APIs.

  3. The application calls init_snmp()to start the library.


      /* set up isc context */

    /* set Net-SNMP parameters */

    /* initialize agent */

    /* register MIB  modules */

     * start library


Adding MIB Methods

Use one of the following to add MIB methods:

While you can use other Net-SNMP functions, Juniper Networks does not support them.

You should specify your MIB file locations through the SDK-MIBS and SDK-MIBDIRS environment variables. SDK-MIBS indicates the names of all SDK MIB files, and SDK-MIBSDIRS indicates the files' locations.

Using SNMP Traps

The SNMP traps APIs are located in the directory src/junos/lib/libjnet-snmp, separately from the other Juniper SNMP extensions, which are in src/junos/lib/libnet-snmp.

Follow these steps to add a trap to your SDK application:

  1. Call the function netsnmp_trap_sdk_request_header(), passing a v2 OID.

  2. Call the function snmp_varlist_add_variable() to add a varbind list to the trap packet. You must add at least one variable object.

  3. Call the function netsnmp_trap_request_send() to send the trap.

Creating an SNMP Trap from the Multiservices PIC

The jnx-ifinfo example also contains an additional control component, jnx-ifinfo-ctrl, that runs on the Multiservices PIC. This component demonstrates how to generate an SNMP trap from the Multiservices PIC.

Communication takes place as follows:

In this example, the SNMP trap is sent only once, during jnx-ifinfod-ctrl startup.

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5