Commit d1f8f7b9 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: move wrsDate.c to wrsCurrentTimeGroup.c

--Functionality is the same as in wrsDate.c, but it uses wrsGroupTemplate.h
--update MIB
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4ca59177
......@@ -30,9 +30,9 @@ SOURCES = \
wrsScalar.c \
wrsPstatsTable.c \
wrsVersion.c \
wrsDate.c \
shmem.c \
wrsPtpDataTable.c \
wrsCurrentTimeGroup.c \
wrsTemperature.c \
wrsOSStatus.c \
wrsPortStatusTable.c
......
......@@ -35,7 +35,7 @@ wrsScalar OBJECT IDENTIFIER ::= { wrSwitchMIB 1 }
--wrsPstatsTable OBJECT IDENTIFIER ::= { wrSwitchMIB 2 } == obsolete
--wrsPpsi OBJECT IDENTIFIER ::= { wrSwitchMIB 3 } == obsolete
wrsVersion OBJECT IDENTIFIER ::= { wrSwitchMIB 4 } -- going to be obsolete
wrsDate OBJECT IDENTIFIER ::= { wrSwitchMIB 5 } -- going to be obsolete
--wrsDate OBJECT IDENTIFIER ::= { wrSwitchMIB 5 } == obsolete
wrsExpertStatus OBJECT IDENTIFIER ::= { wrSwitchMIB 6 }
wrsStatus OBJECT IDENTIFIER ::= { wrSwitchMIB 254 }
......@@ -123,7 +123,10 @@ wrsScbVersion OBJECT-TYPE
"The version of the SCB (motherboard)"
::= { wrsVersion 9 }
-- Date (5), to quickly check wr status
wrsOperationStatus OBJECT IDENTIFIER ::= { wrsExpertStatus 1 }
-- wrsCurrentTimeGroup (.6.1.1)
wrsCurrentTimeGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 1 }
wrsDateTAI OBJECT-TYPE
SYNTAX Counter64 -- actually integer, but it is unsigned so ok
......@@ -131,19 +134,16 @@ wrsDateTAI OBJECT-TYPE
STATUS current
DESCRIPTION
"The current time, in TAI seconds"
::= { wrsDate 1 }
::= { wrsCurrentTimeGroup 1 }
wrsDateString OBJECT-TYPE
wrsDateTAIString OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..32))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The current TAI time, printed as %y-%m-%d-%H:%M:%S (no time zone)"
::= { wrsDate 2 }
wrsOperationStatus OBJECT IDENTIFIER ::= { wrsExpertStatus 1 }
::= { wrsCurrentTimeGroup 2 }
--wrsCurrentTimeGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 1 }
--wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 }
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
......
......@@ -10,6 +10,7 @@
#include "snmp_shmem.h"
#include "wrsPstatsTable.h"
#include "wrsPtpDataTable.h"
#include "wrsCurrentTimeGroup.h"
#include "wrsTemperature.h"
#include "wrsOSStatus.h"
#include "wrsPortStatusTable.h"
......@@ -22,8 +23,8 @@ void init_wrsSnmp(void)
init_wrsScalar();
init_wrsPstatsTable();
init_wrsVersion();
init_wrsDate();
init_wrsPtpDataTable();
init_wrsCurrentTimeGroup();
init_wrsTemperature();
init_wrsOSStatus();
init_wrsPortStatusTable();
......
/*
* White Rabbit Switch date. This is two changing values
*
* 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 "wrsSnmp.h"
#include "wrsCurrentTimeGroup.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "wrsSnmp.h"
/* defines for nic-hardware.h */
#define WR_SWITCH
#define WR_IS_NODE 0
......@@ -22,11 +15,16 @@
#include "../../kernel/wbgen-regs/ppsg-regs.h"
static struct PPSG_WB *pps;
static uint64_t wrs_d_current_64;
static char wrs_d_current_string[32];
static struct pickinfo wrsCurrentTime_pickinfo[] = {
FIELD(wrsCurrentTime_s, ASN_COUNTER64, wrsDateTAI),
FIELD(wrsCurrentTime_s, ASN_OCTET_STR, wrsDateTAIString),
};
struct wrsCurrentTime_s wrsCurrentTime_s;
/* FIXME: this is copied from wr_date, should be librarized */
void *create_map(unsigned long address, unsigned long size)
static void *create_map(unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
......@@ -49,18 +47,34 @@ void *create_map(unsigned long address, unsigned long size)
return mapaddr + fragment;
}
static void wrs_d_get(void)
time_t wrsCurrentTime_data_fill(void)
{
static time_t time_update;
time_t time_cur;
unsigned long utch, utcl, tmp1, tmp2;
time_t t;
struct tm tm;
uint64_t wrs_d_current_64;
time_cur = time(NULL);
if (time_update
&& time_cur - time_update < WRSCURRENTTIME_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
return time_update;
}
time_update = time_cur;
memset(&wrsCurrentTime_s, 0, sizeof(wrsCurrentTime_s));
/* get TAI time from FPGA */
if (!pps) /* first time, map the fpga space */
pps = create_map(FPGA_BASE_PPSG, sizeof(*pps));
if (!pps) {
wrs_d_current_64 = 0;
strcpy(wrs_d_current_string, "0000-00-00-00:00:00 (failed)");
return;
strcpy(wrsCurrentTime_s.wrsDateTAIString,
"0000-00-00-00:00:00 (failed)");
return time_update;
}
do {
......@@ -71,69 +85,29 @@ static void wrs_d_get(void)
} while ((tmp1 != utch) || (tmp2 != utcl));
wrs_d_current_64 = (uint64_t)(utch) << 32 | utcl;
/*
* WARNING: the current snmpd is bugged: it has
* endianness problems with 64 bit, and the two
* halves are swapped. So pre-swap them here
*/
wrsCurrentTime_s.wrsDateTAI =
(wrs_d_current_64 << 32) | (wrs_d_current_64 >> 32);
t = wrs_d_current_64;
localtime_r(&t, &tm);
strftime(wrs_d_current_string,
sizeof(wrs_d_current_string), "%Y-%m-%d-%H:%M:%S", &tm);
}
strftime(wrsCurrentTime_s.wrsDateTAIString,
sizeof(wrsCurrentTime_s.wrsDateTAIString),
"%Y-%m-%d-%H:%M:%S", &tm);
static int date_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 */
switch (reqinfo->mode) {
case MODE_GET:
wrs_d_get();
/*
* WARNING: the current snmpd is bugged: it has
* endianness problems with 64 bit, and the two
* halves are swapped. So pre-swap them here
*/
wrs_d_current_64 =
(wrs_d_current_64 << 32) | (wrs_d_current_64 >> 32);
/* "- 2" because last is 0 for all scalars, I suppose */
obj = requests->requestvb->name[
requests->requestvb->name_length - 2
];
if (obj == 1) /* number */
snmp_set_var_typed_value(requests->requestvb,
ASN_COUNTER64,
&wrs_d_current_64,
sizeof(wrs_d_current_64));
else /* string */
snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR,
wrs_d_current_string,
strlen(wrs_d_current_string));
break;
default:
snmp_log(LOG_ERR, "unknown mode (%d) in wrs date group\n",
reqinfo->mode);
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRSCURRENTTIME_OID
#define GT_PICKINFO wrsCurrentTime_pickinfo
#define GT_DATA_FILL_FUNC wrsCurrentTime_data_fill
#define GT_DATA_STRUCT wrsCurrentTime_s
#define GT_GROUP_NAME "wrsCurrentTime"
#define GT_INIT_FUNC init_wrsCurrentTimeGroup
void
init_wrsDate(void)
{
const oid wrsDate_oid[] = { WRS_OID, 5 };
netsnmp_handler_registration *hreg;
/* do the registration */
hreg = netsnmp_create_handler_registration(
"wrsDate", date_group,
wrsDate_oid, OID_LENGTH(wrsDate_oid),
HANDLER_CAN_RONLY);
netsnmp_register_scalar_group(
hreg, 1 /* min */, 2 /* max */);
}
#include "wrsGroupTemplate.h"
#ifndef WRS_CURRENT_TIME_GROUP_H
#define WRS_CURRENT_TIME_GROUP_H
#define WRSCURRENTTIME_CACHE_TIMEOUT 5
#define WRSCURRENTTIME_OID WRS_OID, 6, 1, 1
struct wrsCurrentTime_s {
uint64_t wrsDateTAI; /* current time in TAI */
char wrsDateTAIString[32]; /* current time in TAI as string */
};
extern struct wrsCurrentTime_s wrsCurrentTime_s;
time_t wrsCurrentTime_data_fill(void);
void init_wrsCurrentTimeGroup(void);
#endif /* WRS_CURRENT_TIME_GROUP_H */
......@@ -103,7 +103,6 @@ extern void init_wrsScalar(void);
/* Real stuff follows */
extern void init_wrsVersion(void);
extern void init_wrsDate(void);
#define WRS_OID 1, 3, 6, 1, 4, 1, 96, 100
......
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