NetBurner 3.5.7
PDF Version
Simple SNMP

Simple SNMP Example

Overview

This example demonstrates how to implement SNMP (Simple Network Management Protocol) functionality on a NetBurner device. SNMP is a standard protocol for monitoring and managing network devices. This example shows how to:

  • Enable and initialize the SNMP agent
  • Configure system description and enterprise OID
  • Send SNMP traps with custom variable bindings
  • Integrate SNMP with a command processor for interactive control

Features

  • SNMP agent with configurable system description
  • Enterprise-specific trap generation with custom data
  • Telnet command interface (port 23) for SNMP operations
  • Serial console command interface
  • User authentication for command sessions
  • HTTP web server for device access

How It Works

+-------------------+ +------------------+ +------------------+
| SNMP Manager | | NetBurner | | Serial Console |
| (Network) | | SNMP Agent | | or Telnet |
+-------------------+ +------------------+ +------------------+
| | |
| SNMP Get/Set | |
| <---------------------> | |
| | |
| SNMP Trap | 'T' Command |
| <---------------------- | <----------------------- |
| | |
| | 'D' Command |
| | <----------------------- |
| | | |
| | v |
| | Dump SNMP Tree |
| | | |
| | v |
| | -----------------------> |
| | (Tree Output) |
+-------------------+ +------------------+ +------------------+

Application Architecture

+------------------------------------------------------------------+
| UserMain() |
+------------------------------------------------------------------+
| | |
v v v
+------------------+ +------------------+ +------------------+
| init() | | StartHttp() | | SNMP Agent |
| Network Stack | | Web Server | | (SnmpServlet) |
+------------------+ +------------------+ +------------------+
|
v
+------------------+
| Command |
| Processor |
| (Port 23/Serial) |
+------------------+
|
+-------------------+-------------------+
| | |
v v v
+------------------+ +------------------+ +------------------+
| ProcessAuth() | | ProcessCommand() | | ProcessConnect() |
| Authentication | | D: Dump Tree | | Session Setup |
| | | T: Send Trap | | |
+------------------+ +------------------+ +------------------+
SNMP agent servlet that listens for and processes SNMP requests.
Definition snmp.h:195
void StartHttp(uint16_t port, bool RunConfigMirror)
Start the HTTP web server. Further documentation in the Initialization section Initialization - Syste...
void init()
System initialization. Ideally called at the beginning of all applications, since the easiest Recover...

SNMP Trap Flow

When a user sends the 'T' command, the following sequence occurs:

User Input: 'T'
|
v
+------------------+
| ProcessCommand() |
+------------------+
|
v
+------------------+
| SendTestTrap() |
+------------------+
|
v
+------------------------+
| - Destination: All |
| - Community: "public" |
| - Type: Enterprise |
| - Specific: 1 |
+------------------------+
|
v
+------------------------+
| TrapVarFunction() |
| (Callback) |
+------------------------+
|
+---------------------------+
| |
v v
+----------------+ +----------------+
| Varbind 1 | | Varbind 2 |
| OID: 8174.1 | | OID: 8174.2 |
| "Test msg 1" | | "Test msg 2" |
+----------------+ +----------------+
| |
+-------------+-------------+
|
v
+------------------+
| SNMP Trap Packet |
| Sent to Network |
+------------------+
void SnmpTrapWithData(IPADDR dest, const char *community_name, int generic_trap, int specific_trap, PutTrapVarBindsFunc *pDataCallbackFunction)
Send an SNMP trap with custom variable bindings.

Command Interface

The example provides a command processor accessible via:

  • Telnet on port 23
  • Serial console (Serial0 or Serial1)

Available Commands

Command Description
D or d Dump the SNMP MIB tree to the console
T or t Send a test SNMP enterprise trap
logout Close the current session

Authentication

The example includes a simple authentication callback that rejects login attempts where the username and password are identical.

SNMP Configuration

The example configures the following SNMP parameters:

  • System Description: "NetBurner SNMP Test Application"
  • Enterprise OID: 1.3.6.1.4.1.8174.2.40

The OID structure follows:

1.3.6.1.4.1.8174.2.40
| | | | | | | | |
| | | | | | | | +-- Application-specific ID (40)
| | | | | | | +----- Product category (2)
| | | | | | +------- NetBurner Enterprise Number (8174)
| | | | | +------------ Private enterprises
| | | | +-------------- Private
| | | +---------------- Internet
| | +------------------ DOD
| +--------------------- ISO/ORG
+----------------------- ISO

File Structure

simplesnmp/
|
+-- src/
| |
| +-- main.cpp Main application source code
|
+-- mib/
| |
| +-- .index MIB index file
| +-- RFC-1215.TXT Trap conventions
| +-- RFC1155-SMI.txt Structure of Management Information
| +-- RFC1213-MIB.txt MIB-II definitions
|
+-- overload/
| |
| +-- nbrtos/
| |
| +-- include/
| |
| +-- predef-overload.h Enables SNMP
|
+-- makefile Build configuration
+-- readme.txt This file

Key Source Code Components

SNMP Initialization

SNMP is enabled through the predef-overload.h file:

#define ENABLE_SNMP (1)

The SNMP server object is declared globally:

SnmpServlet TheSnmpServer;

Trap Variable Callback

The TrapVarFunction callback populates custom varbind data in traps:

void TrapVarFunction(ASN *put_asn)
{
put_asn->PutHeader(0x30); // Varbind sequence
put_asn->PutOidFromString("1.3.6.1.4.1.8174.1");
put_asn->PutOctetString("This is test message number 1");
put_asn->FixUpHeader();
put_asn->PutHeader(0x30); // Second varbind
put_asn->PutOidFromString("1.3.6.1.4.1.8174.2");
put_asn->PutOctetString("This is test message number 2");
put_asn->FixUpHeader();
}

Sending Traps

Traps are sent using SnmpTrapWithData():

IPADDR::NullIP(), // Destination (NullIP = broadcast/configured)
"public", // Community string
SNMP_ENTERPRISE_TRAP, // Trap type
1, // Specific trap code
TrapVarFunction // Callback for varbind data
);
static IPADDR6 NullIP()
Static function to return a null IPADDR6 object.

Command Processor Callbacks

The command processor uses several callback functions:

+--------------------+----------------------------------------+
| Callback | Purpose |
+--------------------+----------------------------------------+
| ProcessAuth | Validate username/password |
| ProcessCommand | Handle user commands (D, T, logout) |
| ProcessConnect | Initialize new sessions |
| ProcessPrompt | Display command prompt |
| ProcessDisconnect | Handle session termination |
+--------------------+----------------------------------------+

Runtime Output

When running, the application displays periodic tick messages:

Web Application: Simple SNMP Example
NNDK Revision: x.x.x
Were here
Tick 1
Tick 2
Tick 3
...

Testing with SNMP Tools

You can test this example using standard SNMP tools:

Using snmpwalk (Linux/macOS)

snmpwalk -v 2c -c public <device_ip> 1.3.6.1.2.1.1

Using snmpget

snmpget -v 2c -c public <device_ip> 1.3.6.1.2.1.1.1.0

Receiving Traps

Configure an SNMP trap receiver to listen on UDP port 162 and send the 'T' command via Telnet to trigger a test trap.

MIB Files

The mib/ directory contains standard MIB definitions:

File Description
RFC1155-SMI.txt Structure and Identification of
Management Information (SMI)
RFC1213-MIB.txt Management Information Base for Network
Management (MIB-II)
RFC-1215.TXT Convention for Defining Traps

These files define the standard OIDs and data types used by SNMP.

Network Ports

Port Protocol Service
80 TCP HTTP web server
23 TCP Telnet command interface
161 UDP SNMP agent (queries)
162 UDP SNMP trap destination (outbound)

See Also

  • NetBurner SNMP API documentation
  • RFC 1157 - Simple Network Management Protocol (SNMP)
  • RFC 1155 - Structure and Identification of Management Information
  • RFC 1213 - Management Information Base (MIB-II)