NetBurner 3.5.7
PDF Version
Simple SNMP

Example Path: examples/snmp/simplesnmp

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:196
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 Globals (AppName/SYSDESC/SYSOID/
| | TheSnmpServer) plus a ~10-line
| | UserMain that brings the stack up
| | and starts the command processor.
| +-- commands.h
| +-- commands.cpp Telnet/serial CLI: 5 file-scope
| | Process* callbacks plus the public
| | StartCommandLine() that wires them
| | up and starts the command-processor
| | task.
| +-- trap.h
| +-- trap.cpp SNMP trap PDU builder + SendTestTrap().
| Called from the 'T' command handler
| in commands.cpp.
|
+-- 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
const char * AppName
EFFS Multiple Partitions Example.
Definition aes/src/main.cpp:10
const char * SYSDESC
Application-defined system description string for MIB-II sysDescr.
Definition snmp/CustomMIB/src/main.cpp:44
const char * SYSOID
Application-defined system object identifier string for MIB-II sysObjectID.
Definition snmp/CustomMIB/src/main.cpp:45

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 the net-snmp Command-Line Tools

The NetBurner SDK ships a portable net-snmp 5.9.1 distribution at:

C:\nburn\snmp\net-snmp\

containing snmpget.exe, snmpset.exe, snmpwalk.exe, snmptable.exe, snmptranslate.exe, etc. The standard MIBs (RFC1155-SMI, RFC1213-MIB, SNMPv2-SMI, SNMPv2-TC, ...) live alongside the per-example MIBs at:

C:\nburn\snmp\mibs\

This example serves only the standard MIB-II tree (no custom enterprise OIDs), so the bundled MIBs are sufficient – no extra MIB files to copy.

All examples below use the example IP address 192.168.1.100. Substitute your NetBurner's actual IP (run nbdiscovery if you do not know it).

One-time setup so you can copy/paste cleanly

Windows cmd:

set PATH=C:\nburn\snmp\net-snmp;PATH% set MIBDIRS=C:\nburn\snmp\mibs set MIBS=ALL

PowerShell:

$env:PATH = "C:\nburn\snmp\net-snmp;$env:PATH" $env:MIBDIRS = "C:\nburn\snmp\mibs" $env:MIBS = "ALL"

Bash (Git Bash / MSYS):

export PATH="/c/nburn/snmp/net-snmp:$PATH" export MIBDIRS="/c/nburn/snmp/mibs" export MIBS="ALL"

After that the -M / -m flags below can be omitted. All examples include them explicitly so they work even without the env vars.

snmpget – read MIB-II values

snmpget -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 sysDescr.0 sysUpTime.0 sysObjectID.0 snmpget -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 sysName.0 sysContact.0 sysLocation.0

Expected output for sysDescr/sysUpTime/sysObjectID:

RFC1213-MIBsysDescr.0 = STRING: "NetBurner SNMP Test Application" RFC1213-MIBsysUpTime.0 = Timeticks: (12345) 0:02:03.45 RFC1213-MIBsysObjectID.0 = OID: SNMPv2-SMIenterprises.8174.2.40

By numeric OID (no MIB needed):

snmpget -v2c -c public 192.168.1.100 .1.3.6.1.2.1.1.1.0

snmpwalk – enumerate a subtree

Walk the entire system group:

snmpwalk -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 system

Walk the interfaces table (one Ethernet row, plus counters):

snmpwalk -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 interfaces

Walk the entire MIB tree the device exposes:

snmpwalk -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 .1

snmpset – writable MIB-II scalars

The standard sysContact.0, sysName.0, and sysLocation.0 leaves are read-write on most agents. Round-trip example:

snmpset -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 sysContact.0 s "[email protected]" snmpget -v2c -c public -M C:\nburn\snmp\mibs -m ALL 192.168.1.100 sysContact.0

snmptranslate – offline OID name/number lookup

snmptranslate -M C:\nburn\snmp\mibs -m ALL -On sysDescr.0 snmptranslate -M C:\nburn\snmp\mibs -m ALL .1.3.6.1.2.1.1.1.0

Receiving the test trap

The 'T' command sends an enterprise trap to whatever is configured as the device's trap destination. Run a trap receiver on a host on the same subnet and point the device at it:

snmptrapd -f -Lo -m ALL -M C:\nburn\snmp\mibs

Configure the device's trap destination via the web config page or by running the CustomMIB example to set TRAPDESTINATION.0 over SNMP. Then log into Telnet (port 23) on the NetBurner and press T.

Troubleshooting

Cannot find module (RFC1213-MIB) / (SNMPv2-SMI) Confirm -M C:\nburn\snmp\mibs -m ALL is on the command line and that those files exist in the mibs folder.

Timeout Verify with ping 192.168.1.100 and confirm the device is on the same subnet. SNMP listens on UDP/161; check Windows Firewall.

No Such Object available on this agent at this OID The OID is not registered, or the agent's access mask rejected the request under the community you used.

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)