Commit 4f8af252 authored by Adam Wujek's avatar Adam Wujek 💬

lib/snmp: Add an object to restart PTP

Add an object to restart PTP via SNMP (wrpcPtpConfigRestart).
Also don't restart ppsi after SFP updates in the flash.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 650657cc
...@@ -543,6 +543,22 @@ wrpcPtpAlpha OBJECT-TYPE ...@@ -543,6 +543,22 @@ wrpcPtpAlpha OBJECT-TYPE
-- **************************************************************************** -- ****************************************************************************
wrpcPtpConfigGroup OBJECT IDENTIFIER ::= { wrpcCore 6 } wrpcPtpConfigGroup OBJECT IDENTIFIER ::= { wrpcCore 6 }
wrpcPtpConfigRestart OBJECT-TYPE
SYNTAX INTEGER {
na(0),
restartPtp(1)
restartPtpSuccessful(100)
restartPtpFailed(200)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"restart PTP
restartPtp - trigger the restart of PTP
restartPtpSuccessful - PTP restart triggered
restartPtpFailed - failed to trigger PTP restart"
::= { wrpcPtpConfigGroup 1 }
wrpcPtpConfigApply OBJECT-TYPE wrpcPtpConfigApply OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
na(0), na(0),
...@@ -571,7 +587,7 @@ wrpcPtpConfigApply OBJECT-TYPE ...@@ -571,7 +587,7 @@ wrpcPtpConfigApply OBJECT-TYPE
applyFailedI2CError - Failed to apply configuration due to communication error with the flash memory. applyFailedI2CError - Failed to apply configuration due to communication error with the flash memory.
applyFailedDBFull - Failed to apply configuration. Database is full. applyFailedDBFull - Failed to apply configuration. Database is full.
applyFailedInvalidPN - Invalid Product Number (PN) provided." applyFailedInvalidPN - Invalid Product Number (PN) provided."
::= { wrpcPtpConfigGroup 1 } ::= { wrpcPtpConfigGroup 2 }
wrpcPtpConfigSfpPn OBJECT-TYPE wrpcPtpConfigSfpPn OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(0..16)) SYNTAX OCTET STRING (SIZE(0..16))
...@@ -579,7 +595,7 @@ wrpcPtpConfigSfpPn OBJECT-TYPE ...@@ -579,7 +595,7 @@ wrpcPtpConfigSfpPn OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"SFP product number identifying which entry in the flash to update." "SFP product number identifying which entry in the flash to update."
::= { wrpcPtpConfigGroup 2 } ::= { wrpcPtpConfigGroup 3 }
wrpcPtpConfigDeltaTx OBJECT-TYPE wrpcPtpConfigDeltaTx OBJECT-TYPE
SYNTAX Integer32 SYNTAX Integer32
...@@ -587,7 +603,7 @@ wrpcPtpConfigDeltaTx OBJECT-TYPE ...@@ -587,7 +603,7 @@ wrpcPtpConfigDeltaTx OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Delta tx to be set" "Delta tx to be set"
::= { wrpcPtpConfigGroup 3 } ::= { wrpcPtpConfigGroup 4 }
wrpcPtpConfigDeltaRx OBJECT-TYPE wrpcPtpConfigDeltaRx OBJECT-TYPE
SYNTAX Integer32 SYNTAX Integer32
...@@ -595,7 +611,7 @@ wrpcPtpConfigDeltaRx OBJECT-TYPE ...@@ -595,7 +611,7 @@ wrpcPtpConfigDeltaRx OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Delta rx to be set" "Delta rx to be set"
::= { wrpcPtpConfigGroup 4 } ::= { wrpcPtpConfigGroup 5 }
wrpcPtpConfigAlpha OBJECT-TYPE wrpcPtpConfigAlpha OBJECT-TYPE
SYNTAX Integer32 SYNTAX Integer32
...@@ -603,7 +619,7 @@ wrpcPtpConfigAlpha OBJECT-TYPE ...@@ -603,7 +619,7 @@ wrpcPtpConfigAlpha OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Alpha to be set" "Alpha to be set"
::= { wrpcPtpConfigGroup 5 } ::= { wrpcPtpConfigGroup 6 }
-- **************************************************************************** -- ****************************************************************************
wrpcPortGroup OBJECT IDENTIFIER ::= { wrpcCore 7 } wrpcPortGroup OBJECT IDENTIFIER ::= { wrpcCore 7 }
......
...@@ -101,6 +101,11 @@ ...@@ -101,6 +101,11 @@
/* defines used by get_port function */ /* defines used by get_port function */
#define PORT_LINK_STATUS (void *) 1 #define PORT_LINK_STATUS (void *) 1
/* defines for wrpcPtpConfigRestart */
#define restartPtp 1
#define restartPtpSuccessful 100
#define restartPtpFailed 200
/* defines for wrpcPtpConfigApply */ /* defines for wrpcPtpConfigApply */
#define writeToFlashGivenSfp 1 #define writeToFlashGivenSfp 1
#define writeToFlashCurrentSfp 2 #define writeToFlashCurrentSfp 2
...@@ -188,6 +193,7 @@ struct snmp_oid_limb { ...@@ -188,6 +193,7 @@ struct snmp_oid_limb {
static struct s_sfpinfo snmp_ptp_config; static struct s_sfpinfo snmp_ptp_config;
static int ptp_config_apply_status; static int ptp_config_apply_status;
static int ptp_restart_status;
extern struct pp_instance ppi_static; extern struct pp_instance ppi_static;
static struct wr_servo_state *wr_s_state; static struct wr_servo_state *wr_s_state;
...@@ -227,6 +233,7 @@ static int get_sfp(uint8_t *buf, struct snmp_oid *obj); ...@@ -227,6 +233,7 @@ static int get_sfp(uint8_t *buf, struct snmp_oid *obj);
static int set_value(uint8_t *set_buff, struct snmp_oid *obj, void *p); static int set_value(uint8_t *set_buff, struct snmp_oid *obj, void *p);
static int set_pp(uint8_t *buf, struct snmp_oid *obj); static int set_pp(uint8_t *buf, struct snmp_oid *obj);
static int set_p(uint8_t *buf, struct snmp_oid *obj); static int set_p(uint8_t *buf, struct snmp_oid *obj);
static int set_ptp_restart(uint8_t *buf, struct snmp_oid *obj);
static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj); static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj);
static void print_oid_verbose(uint8_t *oid, int len); static void print_oid_verbose(uint8_t *oid, int len);
...@@ -287,11 +294,12 @@ static uint8_t oid_wrpcPtpRX[] = {24,0}; ...@@ -287,11 +294,12 @@ static uint8_t oid_wrpcPtpRX[] = {24,0};
static uint8_t oid_wrpcPtpAlpha[] = {26,0}; static uint8_t oid_wrpcPtpAlpha[] = {26,0};
/* wrpcPtpConfigGroup */ /* wrpcPtpConfigGroup */
static uint8_t oid_wrpcPtpConfigApply[] = {1,0}; static uint8_t oid_wrpcPtpConfigRestart[] = {1,0};
static uint8_t oid_wrpcPtpConfigSfpPn[] = {2,0}; static uint8_t oid_wrpcPtpConfigApply[] = {2,0};
static uint8_t oid_wrpcPtpConfigDeltaTx[] = {3,0}; static uint8_t oid_wrpcPtpConfigSfpPn[] = {3,0};
static uint8_t oid_wrpcPtpConfigDeltaRx[] = {4,0}; static uint8_t oid_wrpcPtpConfigDeltaTx[] = {4,0};
static uint8_t oid_wrpcPtpConfigAlpha[] = {5,0}; static uint8_t oid_wrpcPtpConfigDeltaRx[] = {5,0};
static uint8_t oid_wrpcPtpConfigAlpha[] = {6,0};
/* wrpcPortGroup */ /* wrpcPortGroup */
static uint8_t oid_wrpcPortLinkStatus[] = {1,0}; static uint8_t oid_wrpcPortLinkStatus[] = {1,0};
...@@ -370,7 +378,8 @@ static struct snmp_oid oid_array_wrpcPtpGroup[] = { ...@@ -370,7 +378,8 @@ static struct snmp_oid oid_array_wrpcPtpGroup[] = {
/* wrpcPtpConfigGroup */ /* wrpcPtpConfigGroup */
static struct snmp_oid oid_array_wrpcPtpConfigGroup[] = { static struct snmp_oid oid_array_wrpcPtpConfigGroup[] = {
OID_FIELD_VAR( oid_wrpcPtpConfigApply, get_p, set_ptp_config,ASN_INTEGER,&ptp_config_apply_status), OID_FIELD_VAR( oid_wrpcPtpConfigRestart, get_p, set_ptp_restart,ASN_INTEGER, &ptp_restart_status),
OID_FIELD_VAR( oid_wrpcPtpConfigApply, get_p, set_ptp_config, ASN_INTEGER, &ptp_config_apply_status),
OID_FIELD_VAR( oid_wrpcPtpConfigSfpPn, get_p, set_p, ASN_OCTET_STR, &snmp_ptp_config.pn), OID_FIELD_VAR( oid_wrpcPtpConfigSfpPn, get_p, set_p, ASN_OCTET_STR, &snmp_ptp_config.pn),
OID_FIELD_VAR( oid_wrpcPtpConfigDeltaTx, get_p, set_p, ASN_INTEGER, &snmp_ptp_config.dTx), OID_FIELD_VAR( oid_wrpcPtpConfigDeltaTx, get_p, set_p, ASN_INTEGER, &snmp_ptp_config.dTx),
OID_FIELD_VAR( oid_wrpcPtpConfigDeltaRx, get_p, set_p, ASN_INTEGER, &snmp_ptp_config.dRx), OID_FIELD_VAR( oid_wrpcPtpConfigDeltaRx, get_p, set_p, ASN_INTEGER, &snmp_ptp_config.dRx),
...@@ -971,6 +980,29 @@ static int set_p(uint8_t *buf, struct snmp_oid *obj) ...@@ -971,6 +980,29 @@ static int set_p(uint8_t *buf, struct snmp_oid *obj)
return set_value(buf, obj, obj->p + obj->offset); return set_value(buf, obj, obj->p + obj->offset);
} }
static int set_ptp_restart(uint8_t *buf, struct snmp_oid *obj)
{
int ret;
int32_t *restart_val;
restart_val = obj->p;
ret = set_value(buf, obj, restart_val);
if (ret < 0)
return ret;
switch (*restart_val) {
case restartPtp:
snmp_verbose("%s: restart PTP\n", __func__);
wrc_ptp_stop();
wrc_ptp_start();
*restart_val = restartPtpSuccessful;
break;
default:
*restart_val = restartPtpFailed;
}
return ret;
}
static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj) static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj)
{ {
int ret; int ret;
...@@ -986,8 +1018,10 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj) ...@@ -986,8 +1018,10 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj)
sfp_deltaTx = snmp_ptp_config.dTx; sfp_deltaTx = snmp_ptp_config.dTx;
sfp_deltaRx = snmp_ptp_config.dRx; sfp_deltaRx = snmp_ptp_config.dRx;
sfp_alpha = snmp_ptp_config.alpha; sfp_alpha = snmp_ptp_config.alpha;
/* Since ppsi does not support update of deltas in runtime, /* Since ppsi does not support update of deltas in runtime,
* we need to restart the ppsi */ * we need to restart the ppsi */
pp_printf("SNMP: SFP updated in memory, restart PTP\n");
wrc_ptp_stop(); wrc_ptp_stop();
wrc_ptp_start(); wrc_ptp_start();
...@@ -1026,10 +1060,6 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj) ...@@ -1026,10 +1060,6 @@ static int set_ptp_config(uint8_t *buf, struct snmp_oid *obj)
*apply_mode = applySuccessfulMatchFailed; *apply_mode = applySuccessfulMatchFailed;
break; break;
} }
/* Since ppsi does not support update of deltas in runtime,
* we need to restart the ppsi */
wrc_ptp_stop();
wrc_ptp_start();
*apply_mode = applySuccessful; *apply_mode = applySuccessful;
break; break;
...@@ -1208,12 +1238,13 @@ static int snmp_respond(uint8_t *buf) ...@@ -1208,12 +1238,13 @@ static int snmp_respond(uint8_t *buf)
uint8_t oid_branch_matching_len; uint8_t oid_branch_matching_len;
/* Hack to avoid compiler warnings "function defined but not used" for /* Hack to avoid compiler warnings "function defined but not used" for
* set_p and set_pp when SNMP compiled without SET support. * functions below when SNMP compiled without SET support.
* These functions will never be called here. */ * These functions will never be called here. */
if (0) { if (0) {
set_p(NULL, NULL); set_p(NULL, NULL);
set_pp(NULL, NULL); set_pp(NULL, NULL);
set_ptp_config(NULL, NULL); set_ptp_config(NULL, NULL);
set_ptp_restart(NULL, NULL);
} }
for (a_i = 0, h_i = 0; a_i < sizeof(match_array); a_i++, h_i++) { for (a_i = 0, h_i = 0; a_i < sizeof(match_array); a_i++, h_i++) {
......
...@@ -3,4 +3,4 @@ SNMP_OPTIONS_NO_M="-On -c public -v 2c " ...@@ -3,4 +3,4 @@ SNMP_OPTIONS_NO_M="-On -c public -v 2c "
SNMP_OPTIONS="$SNMP_OPTIONS_NO_M -m WR-WRPC-MIB -M +/var/lib/mibs/ietf:../../lib" SNMP_OPTIONS="$SNMP_OPTIONS_NO_M -m WR-WRPC-MIB -M +/var/lib/mibs/ietf:../../lib"
TOTAL_NUM_OIDS_EXPECT_TEXT="4 temperature sensors, 4 entries in the SFPs database" TOTAL_NUM_OIDS_EXPECT_TEXT="4 temperature sensors, 4 entries in the SFPs database"
# number of OIDs expected # number of OIDs expected
TOTAL_NUM_OIDS=68 TOTAL_NUM_OIDS=69
...@@ -58,7 +58,7 @@ load snmp_test_helpers ...@@ -58,7 +58,7 @@ load snmp_test_helpers
# set known value first # set known value first
helper_snmpset wrpcPtpConfigSfpPn.0 "TEST sfp2" helper_snmpset wrpcPtpConfigSfpPn.0 "TEST sfp2"
# set too long, bad length (erorr from target) # set too long, bad length (erorr from target)
run snmpset $SNMP_OPTIONS_NO_M $TARGET_IP .1.3.6.1.4.1.96.101.1.6.5.0 s "0123456789012345678" run snmpset $SNMP_OPTIONS_NO_M $TARGET_IP .1.3.6.1.4.1.96.101.1.6.3.0 s "0123456789012345678"
echo $status echo $status
[ "$status" -eq 2 ] [ "$status" -eq 2 ]
# expect value to be not changed # expect value to be not changed
...@@ -69,7 +69,7 @@ load snmp_test_helpers ...@@ -69,7 +69,7 @@ load snmp_test_helpers
# set known value first # set known value first
helper_snmpset wrpcPtpConfigSfpPn.0 "TEST sfp3" helper_snmpset wrpcPtpConfigSfpPn.0 "TEST sfp3"
# set too long, bad length (erorr from target) # set too long, bad length (erorr from target)
run snmpset $SNMP_OPTIONS_NO_M $TARGET_IP .1.3.6.1.4.1.96.101.1.6.2.0 i "012345678" run snmpset $SNMP_OPTIONS_NO_M $TARGET_IP .1.3.6.1.4.1.96.101.1.6.3.0 i "012345678"
echo $status echo $status
[ "$status" -eq 2 ] [ "$status" -eq 2 ]
# expect value to be not changed # expect value to be not changed
......
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