Simulation data#

SNMP agent simulation revolves around the contents of .snmprec files.

File format#

The .snmprec file format is optimised to be compact, human-readable and inexpensive to parse. It’s also important to store full and exact response information in a most intact form. Here’s an example data file content:|4|Linux SMP Tue Jun 19 14:58:11 CDT 2007 i686|6||67|233425120|4x|00127962f940|64x|c3dafe61

There is a pipe-separated triplet of OID|tag|value items where:

  • OID is a dot-separated set of numbers

  • Tag is a BER-encoded ASN.1 tag. A modifier can be appended to the tag number. The following modifiers are known:

    • x when the value is hexified (e.g. ‘0102’)

    • e when the value is a Python string literal (e.g. ‘x01x02hello’)

    • Colon-separated reference to a variation module

  • The value is either a printable string or a hexified string or a raw Python string. Unless it’s a number.

Valid tag values and their corresponding ASN.1/SNMP types are:

  • 2 - Integer32


  • 5 - NULL


  • 64 - IpAddress

  • 65 - Counter32

  • 66 - Gauge32

  • 67 - TimeTicks

  • 68 - Opaque

  • 70 - Counter64

Besides plain-text form, compressed .snmprec.bz2 files are also supported.

Managing data files#

The snmpsim-manage-records tool is designed to perform a few handy operations on the data files.

If you possess .snmpwalk or .sapwalk snapshots and wish to convert them into Simulator’s native .snmprec data file format (what can be required for using variation modules), run the snmpsim-manage-records tool like this:

$ snmpsim-manage-records --input-file=linux.snmpwalk \
    --source-record-type=snmpwalk|4|Linux cray #2 SMP Sat Apr 9 23:39:07 CDT 2011 i686|6||67|121722922|4|Root <root@cray> (configure /etc/snmp/snmp.local.conf)|4|new system name|4|KK12 (edit /etc/snmp/snmpd.conf)|67|0|6||6||6|
# Records: written 3711, filtered out 0, deduplicated 0, broken 0, variated 0

SNMP Simulator requires data files to be sorted (by OID) and containing no duplicate OIDs. In case your data file does not comply with these requirements for some reason, you could pass it through the snmpsim-manage-records tool to fix data file:

$ snmpsim-manage-records --input-file=tcp-mib.snmprec --sort-records
  --ignore-broken-records --deduplicate-records|2|1|2|4|2|2|2|4
# Records: written 33, filtered out 0, deduplicated 0, broken 0, variated 0

If you have a huge data file and wish to use just a part of it for simulation purposes, snmpsim-manage-records tool could cut a slice form a data file and store records in a new one:

$ snmpsim-manage-records --input-file=tcp-mib.snmprec \
    --start-oid= --stop-oid=|2|1|64x|8b896863|2|3|64x|4f1182fe|2|3
# Records: written 5, filtered out 28, deduplicated 0, broken 0, variated 0

Merge of multiple data files into a single data file is also supported:

$ snmpsim-manage-records --input-file=tcp-mib.snmprec \
    --input-file=udp-mib.snmprec --sort-records \
# Records: written 49, filtered out 0, deduplicated 0, broken 0, variated 0

Having string values more human-readable may be more convenient in the course of adjusting simulation data, debugging etc. By default, strings in simulation data are hexified. By passing such .snmprec file through the snmpsim-manage-records –escaped-strings call, you can convert your .snmprec data into Python string literal representation:

$ head data/sample.snmprec|4x|00127962f940
$ snmpsim-manage-records --source-record-type=snmprec  \
    --input-file=data/sample.snmprec --escaped-strings|4e|\x00\x12yb\xf9@
# Records: written 1, filtered out 0, deduplicated 0, broken 0, variated 0