Commit 985a10d5 authored by Adam Wujek's avatar Adam Wujek

[FEATURE: #268] userspace/snmpd: improve reporting of offset between NTP and WR time

Add wrsSystemClockDriftUs (in microseconds) as int32. There is no need
to export this value as int64, with greater values of the offset
the exact information about the offset is not needed.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 4d778f25
...@@ -95,12 +95,17 @@ setCronConfig () ...@@ -95,12 +95,17 @@ setCronConfig ()
compareToThreshold () compareToThreshold ()
{ {
local __resultvar=$1 local __resultvar=$1
local __c_offset=$2 # $(( )) to remove leading "+"
local __c_offset=$(( $2 ))
local __c_threshold=$3 local __c_threshold=$3
if (( $__c_offset >= __c_threshold )) ; then if (( $__c_offset >= __c_threshold )) ; then
x=$(expr $__c_offset - $__c_threshold) x=$(( $__c_offset - $__c_threshold ))
debug "System clock drift is exceedind the threshold by ${x} sec" debug "X1System clock drift is exceeding the threshold by ${x} sec"
eval $__resultvar="1"
elif (( -$__c_offset >= __c_threshold )) ; then
x=$(( $__c_offset + $__c_threshold ))
debug "X2System clock drift is exceeding the threshold by ${x} sec"
eval $__resultvar="1" eval $__resultvar="1"
else else
debug "System clock drift is not exceeding the threshold" debug "System clock drift is not exceeding the threshold"
...@@ -109,27 +114,36 @@ compareToThreshold () ...@@ -109,27 +114,36 @@ compareToThreshold ()
} }
# #
# Decode NTPD deamon output to get the offset in ms # Decode NTPD deamon output to get the offset in seconds.useconds
# #
decodeOffsetMs () decodeOffset ()
{ {
local __resultvar=$1 local __resultvar=$1
local __str=$2 local __str=$2
local __offset=$(echo $__str | sed -n 's/.* offset:[+-]\?\([0-9]*\).*/\1/p') local __offset=$(echo $__str | sed -n 's/.* offset:\?\([+-][0-9]*\)\.\?\([0-9]*\) .*/\1.\2/p')
if [[ -z "$__offset" ]] ; then if [[ -z "$__offset" ]] ; then
# Empty string # Empty string
debug "Invalid Offset !!!" debug "Invalid Offset !!!"
debug "NTP msg=\"$__str\"" debug "NTP msg=\"$__str\""
eval $__resultvar="-1" return 1
else else
offset=$(expr $__offset + 0) # Change the sign of the offset. ntpd returns a positive
debug "NTP offset=$__offset ms" # offset when the ntp time is ahead of the local time, which is
# counter-intuitive.
if [ "${__offset:0:1}" = "-" ]; then
__offset=+${__offset:1}
elif [ "${__offset:0:1}" = "+" ]; then
__offset=-${__offset:1}
fi
debug "NTP offset=$__offset s"
eval $__resultvar="'$__offset'" eval $__resultvar="'$__offset'"
return 0
fi fi
} }
# #
# Kill the NTPD daemon in background after few seconds # Kill the NTPD daemon in background after few seconds
# #
...@@ -171,9 +185,9 @@ read_ntp_server() ...@@ -171,9 +185,9 @@ read_ntp_server()
killNTPD 10 killNTPD 10
ntpRes=$($ntpTool -n -w -q -d -p $server 2>&1) ntpRes=$($ntpTool -n -w -q -d -p $server 2>&1)
if [ -n "$ntpRes" ] ; then if [ -n "$ntpRes" ] ; then
decodeOffsetMs offset "$ntpRes" decodeOffset offset "$ntpRes"
if (( $offset >= 0 )) ; then if [ $? -eq 0 ] ; then
compareToThreshold alarmState $offset $ltThreshold compareToThreshold alarmState ${offset%.*} $ltThreshold
if (( $alarmState == 1 )) ; then if (( $alarmState == 1 )) ; then
# Exceeded Threshold # Exceeded Threshold
writeMsg "exceeded_threshold" $systemClockMonitoringStatus writeMsg "exceeded_threshold" $systemClockMonitoringStatus
......
...@@ -30,6 +30,7 @@ wrSwitchMIB MODULE-IDENTITY ...@@ -30,6 +30,7 @@ wrSwitchMIB MODULE-IDENTITY
DESCRIPTION DESCRIPTION
"Updates for v6.1 WRS firmware release "Updates for v6.1 WRS firmware release
Added objects: Added objects:
- wrsSystemClockDriftUs
- wrsVersionFeatures - wrsVersionFeatures
" "
...@@ -731,6 +732,15 @@ wrsLeapSecSourceURL OBJECT-TYPE ...@@ -731,6 +732,15 @@ wrsLeapSecSourceURL OBJECT-TYPE
"Url to the leap second file" "Url to the leap second file"
::= { wrsCurrentTimeGroup 11 } ::= { wrsCurrentTimeGroup 11 }
wrsSystemClockDriftUs OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Drift of system clock expressed in microseconds with saturation to
min/max integer values"
::= { wrsCurrentTimeGroup 12 }
--wrsBootStatusGroup (.7.1.2) --wrsBootStatusGroup (.7.1.2)
wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 } wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 }
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
"wrsLeapSecStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.9" "wrsLeapSecStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.9"
"wrsLeapSecSourceStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.10" "wrsLeapSecSourceStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.10"
"wrsLeapSecSourceURL" "1.3.6.1.4.1.96.100.7.1.1.11" "wrsLeapSecSourceURL" "1.3.6.1.4.1.96.100.7.1.1.11"
"wrsSystemClockDriftUs" "1.3.6.1.4.1.96.100.7.1.1.12"
"wrsBootStatusGroup" "1.3.6.1.4.1.96.100.7.1.2" "wrsBootStatusGroup" "1.3.6.1.4.1.96.100.7.1.2"
"wrsBootCnt" "1.3.6.1.4.1.96.100.7.1.2.1" "wrsBootCnt" "1.3.6.1.4.1.96.100.7.1.2.1"
"wrsRebootCnt" "1.3.6.1.4.1.96.100.7.1.2.2" "wrsRebootCnt" "1.3.6.1.4.1.96.100.7.1.2.2"
......
...@@ -54,6 +54,7 @@ static struct pickinfo wrsCurrentTime_pickinfo[] = { ...@@ -54,6 +54,7 @@ static struct pickinfo wrsCurrentTime_pickinfo[] = {
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecStatusDetails), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecStatusDetails),
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecSourceStatusDetails), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecSourceStatusDetails),
FIELD(wrsCurrentTime_s, ASN_OCTET_STR, wrsLeapSecSourceUrl), FIELD(wrsCurrentTime_s, ASN_OCTET_STR, wrsLeapSecSourceUrl),
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockDriftUs),
}; };
static service_exp_t services[]={ static service_exp_t services[]={
...@@ -176,7 +177,9 @@ static void get_wrsSystemClockStatusDetails(void){ ...@@ -176,7 +177,9 @@ static void get_wrsSystemClockStatusDetails(void){
static int first_run=1; static int first_run=1;
char buff[21]; /* 1 for null char */ char buff[21]; /* 1 for null char */
FILE *f; FILE *f;
int status=0, drift=0; int status = 0;
int drift = 0;
int drift_us = 0;
static int threshold=0, unit=0, checkInterval=0; static int threshold=0, unit=0, checkInterval=0;
update_expected_services(); update_expected_services();
...@@ -212,10 +215,11 @@ static void get_wrsSystemClockStatusDetails(void){ ...@@ -212,10 +215,11 @@ static void get_wrsSystemClockStatusDetails(void){
if ((f=fopen(SYSTEMCLOCK_DRIFT, "r"))!=NULL) { if ((f=fopen(SYSTEMCLOCK_DRIFT, "r"))!=NULL) {
/* readline without newline */ /* readline without newline */
if ( fscanf(f, "%d", &drift)!=1 ) { if (fscanf(f, "%d.%d", &drift, &drift_us) != 2) {
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: invalid " snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: invalid "
"drift value in file " SYSTEMCLOCK_DRIFT "\n",slog_obj_name); "drift value in file " SYSTEMCLOCK_DRIFT "\n",slog_obj_name);
drift=0; drift = 0;
drift_us = 0;
} }
fclose(f); fclose(f);
} else { } else {
...@@ -270,6 +274,7 @@ static void get_wrsSystemClockStatusDetails(void){ ...@@ -270,6 +274,7 @@ static void get_wrsSystemClockStatusDetails(void){
} }
wrsCurrentTime_s.wrsSystemClockStatusDetails = status; wrsCurrentTime_s.wrsSystemClockStatusDetails = status;
wrsCurrentTime_s.wrsSystemClockDrift = drift; wrsCurrentTime_s.wrsSystemClockDrift = drift;
wrsCurrentTime_s.wrsSystemClockDriftUs = int_saturate((int64_t)drift * 1000000 + (int64_t)drift_us);
wrsCurrentTime_s.wrsSystemClockDriftThreshold=threshold; wrsCurrentTime_s.wrsSystemClockDriftThreshold=threshold;
wrsCurrentTime_s.wrsSystemClockCheckInterval=checkInterval; wrsCurrentTime_s.wrsSystemClockCheckInterval=checkInterval;
wrsCurrentTime_s.wrsSystemClockCheckIntervalUnit=unit; wrsCurrentTime_s.wrsSystemClockCheckIntervalUnit=unit;
......
...@@ -55,6 +55,7 @@ struct wrsCurrentTime_s { ...@@ -55,6 +55,7 @@ struct wrsCurrentTime_s {
int wrsLeapSecSourceStatusDetails; /* Leap second source status details*/ int wrsLeapSecSourceStatusDetails; /* Leap second source status details*/
int wrsLeapSecSource; /* Source of the leap seconds file */ int wrsLeapSecSource; /* Source of the leap seconds file */
char wrsLeapSecSourceUrl[WRS_LEAP_SECOND_SOURCE_URL_LEN + 1]; /* URL to download leap second file */ char wrsLeapSecSourceUrl[WRS_LEAP_SECOND_SOURCE_URL_LEN + 1]; /* URL to download leap second file */
int wrsSystemClockDriftUs; /* Current system clock drift value in us */
}; };
extern struct wrsCurrentTime_s wrsCurrentTime_s; extern struct wrsCurrentTime_s wrsCurrentTime_s;
......
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