Commit 8c75e089 authored by Alessandro Rubini's avatar Alessandro Rubini

snmp library: add version items to MIB and code (now fake)

Version items are now fake strings, as I still miss the code
that reads if from the device.  But they work, and the mib is
updated:

   tornado% snmpwalk -c public -v 2c -m +`pwd`/WR-SWITCH-MIB.txt wrs \
            .1.3.6.1.4.1.96.100.4
   WR-SWITCH-MIB::wrsVersionSw.0 = STRING:  fake-v4.0-rc1
   WR-SWITCH-MIB::wrsVersionGw1.0 = STRING: fake-7cce708
   WR-SWITCH-MIB::wrsVersionGw2.0 = STRING: fake-5118070
   WR-SWITCH-MIB::wrsVersionGw3.0 = STRING: fake-7efeb16
   WR-SWITCH-MIB::wrsVersionHw1.0 = STRING: fake-3.30
   WR-SWITCH-MIB::wrsVersionHw2.0 = STRING: fake-LX240T
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d49c43a2
#!/bin/sh
# Log to syslog at daemon level. Amd log source address (-a)
snmpd -Lsd -p /var/run/snmpd.pid -a -c /wr/etc/snmpd.conf
\ No newline at end of file
snmpd -Lsd -p /var/run/snmpd.pid -a -c /wr/etc/snmpd.conf
......@@ -13,7 +13,7 @@ LDFLAGS = -shared $$($(NET_SNMP_CONFIG) --ldflags)
CFLAGS += -Iinclude -DWRS_WITH_SNMP_HACKISH_LOG=0
SHLIB = wrsSnmp.so
SOURCES = init.c wrsScalar.c wrsPstats.c
SOURCES = init.c wrsScalar.c wrsPstats.c wrsVersion.c
OBJECTS = $(SOURCES:.c=.o)
all: $(SHLIB)
......
......@@ -32,6 +32,7 @@ wrSwitchMIB MODULE-IDENTITY
wrsScalar OBJECT IDENTIFIER ::= { wrSwitchMIB 1 }
wrsPstats OBJECT IDENTIFIER ::= { wrSwitchMIB 2 }
wrsPpsi OBJECT IDENTIFIER ::= { wrSwitchMIB 3 }
wrsVersion OBJECT IDENTIFIER ::= { wrSwitchMIB 4 }
-- define one stupid object for a start
......@@ -243,4 +244,57 @@ pstatsWR17 OBJECT-TYPE
"The value of this counter for interface wr17."
::= {pstatsEntry 19 }
-- FIXME: wrsPpsi (3)
-- Versions (4) are all just strings, 6 of them
wrsVersionSw OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..64))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The software version, as returned from 'git describe' at build time"
::= { wrsVersion 1 }
wrsVersionGw1 OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The gateware version: commit of wr_switch_hdl"
::= { wrsVersion 2 }
wrsVersionGw2 OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The gateware version: commit of general-cores"
::= { wrsVersion 3 }
wrsVersionGw3 OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The gateware version: commit of wr-cores"
::= { wrsVersion 4 }
wrsVersionHw1 OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The hardware version: PCB"
::= { wrsVersion 5 }
wrsVersionHw2 OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The hardware version: FPGA"
::= { wrsVersion 6 }
END
......@@ -8,10 +8,12 @@
/* The sub-init functions */
#include "wrsScalar.h"
#include "wrsPstats.h"
#include "wrsVersion.h"
void
init_wrsSnmp(void)
{
init_wrsScalar();
init_wrsPstats();
init_wrsVersion();
}
/*
* White Rabbit Switch versions. This is a series of scalars,
* so I used the approach of disman/expr/expScalars.c
*
* Alessandro Rubini for CERN, 2014
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/auto_nlist.h>
#include "wrsVersion.h"
/* Our structure for caching data */
#define VERSION_N_STRINGS 6 /* sw, 3 gw, 2 hw */
static struct wrs_version {
char *value[VERSION_N_STRINGS];
} wrs_version;
static int version_group(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
oid obj; /* actually, an integer, i.e. the final index */
char *s;
switch (reqinfo->mode) {
case MODE_GET:
/* "- 2" because last is 0 for all scalars, I suppose */
obj = requests->requestvb->name[
requests->requestvb->name_length - 2
];
s = wrs_version.value[obj - 1];
snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR, s, strlen(s));
break;
default:
snmp_log(LOG_ERR, "unknown mode (%d) in wrs version group\n",
reqinfo->mode);
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
void
init_wrsVersion(void)
{
const oid wrsVersion_oid[] = { WRS_VERSION_OID };
netsnmp_handler_registration *hreg;
/* FIXME.... */
wrs_version.value[0] = "fake-v4.0-rc1";
wrs_version.value[1] = "fake-7cce708";
wrs_version.value[2] = "fake-5118070";
wrs_version.value[3] = "fake-7efeb16";
wrs_version.value[4] = "fake-3.30";
wrs_version.value[5] = "fake-LX240T";
/* do the registration */
hreg = netsnmp_create_handler_registration(
"wrsVersion", version_group,
wrsVersion_oid, OID_LENGTH(wrsVersion_oid),
HANDLER_CAN_RONLY);
netsnmp_register_scalar_group(
hreg, 1 /* min */, VERSION_N_STRINGS /* max */);
}
#ifndef _PSTATSTABLE_H
#define _PSTATSTABLE_H
#define WRS_VERSION_OID 1, 3, 6, 1, 4, 1, 96, 100, 4
extern void init_wrsVersion(void);
#endif /* _PSTATSTABLE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment