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

userspace/snmp: update wrsPtpInstanceTable to have two indexes

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 275086c0
...@@ -2627,22 +2627,28 @@ wrsPtpInstanceEntry OBJECT-TYPE ...@@ -2627,22 +2627,28 @@ wrsPtpInstanceEntry OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"An entry containing pstats counters" "An entry containing pstats counters"
INDEX { wrsPtpInstanceIndex } INDEX { wrsPtpInstancePortIndex, wrsPtpInstanceOnPortIndex }
::= { wrsPtpInstanceTable 1 } ::= { wrsPtpInstanceTable 1 }
WrsPtpInstanceEntry ::= WrsPtpInstanceEntry ::=
SEQUENCE { SEQUENCE {
wrsPtpInstanceIndex Unsigned32, wrsPtpInstancePortIndex Unsigned32,
wrsPtpInstancePort Integer, wrsPtpInstanceOnPortIndex Unsigned32,
wrsPtpInstancePort INTEGER,
wrsPtpInstancePortInstance INTEGER,
wrsPtpInstancePortName DisplayString,
wrsPtpInstanceName DisplayString, wrsPtpInstanceName DisplayString,
wrsPtpInstanceState INTEGER, wrsPtpInstanceState INTEGER,
wrsPtpInstanceStateNext INTEGER, wrsPtpInstanceStateNext INTEGER,
wrsPtpInstanceRole INTEGER, wrsPtpInstanceRole INTEGER,
wrsPtpInstanceMechanism INTEGER, wrsPtpInstanceMechanism INTEGER,
wrsPtpInstanceProto INTEGER wrsPtpInstanceProto INTEGER,
wrsPtpInstanceExt INTEGER,
wrsPtpInstancePeerMac PhysAddress,
wrsPtpInstancePeerVid INTEGER,
} }
wrsPtpInstanceIndex OBJECT-TYPE wrsPtpInstancePortIndex OBJECT-TYPE
SYNTAX Unsigned32 SYNTAX Unsigned32
MAX-ACCESS not-accessible MAX-ACCESS not-accessible
STATUS current STATUS current
...@@ -2650,13 +2656,29 @@ wrsPtpInstanceIndex OBJECT-TYPE ...@@ -2650,13 +2656,29 @@ wrsPtpInstanceIndex OBJECT-TYPE
"Index for wrsPtpInstanceTable" "Index for wrsPtpInstanceTable"
::= { wrsPtpInstanceEntry 1 } ::= { wrsPtpInstanceEntry 1 }
wrsPtpInstanceOnPortIndex OBJECT-TYPE
SYNTAX Unsigned32
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"Index for wrsPtpInstanceTable"
::= { wrsPtpInstanceEntry 2 }
wrsPtpInstancePort OBJECT-TYPE wrsPtpInstancePort OBJECT-TYPE
SYNTAX Integer SYNTAX INTEGER
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Port number on which an instance is running" "Port number on which an instance is running"
::= { wrsPtpInstanceEntry 2 } ::= { wrsPtpInstanceEntry 3 }
wrsPtpInstancePortInstance OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Index of an instance running on a port"
::= { wrsPtpInstanceEntry 4 }
wrsPtpInstancePortName OBJECT-TYPE wrsPtpInstancePortName OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..12)) SYNTAX DisplayString (SIZE (0..12))
...@@ -2664,7 +2686,7 @@ wrsPtpInstancePortName OBJECT-TYPE ...@@ -2664,7 +2686,7 @@ wrsPtpInstancePortName OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Port name of port" "Port name of port"
::= { wrsPtpInstanceEntry 3 } ::= { wrsPtpInstanceEntry 5 }
wrsPtpInstanceName OBJECT-TYPE wrsPtpInstanceName OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..12)) SYNTAX DisplayString (SIZE (0..12))
...@@ -2672,7 +2694,7 @@ wrsPtpInstanceName OBJECT-TYPE ...@@ -2672,7 +2694,7 @@ wrsPtpInstanceName OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Name of an instance" "Name of an instance"
::= { wrsPtpInstanceEntry 4 } ::= { wrsPtpInstanceEntry 6 }
wrsPtpInstanceState OBJECT-TYPE wrsPtpInstanceState OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2709,7 +2731,7 @@ wrsPtpInstanceState OBJECT-TYPE ...@@ -2709,7 +2731,7 @@ wrsPtpInstanceState OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Name of instance" "Name of instance"
::= { wrsPtpInstanceEntry 5 } ::= { wrsPtpInstanceEntry 7 }
wrsPtpInstanceStateNext OBJECT-TYPE wrsPtpInstanceStateNext OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2746,7 +2768,7 @@ wrsPtpInstanceStateNext OBJECT-TYPE ...@@ -2746,7 +2768,7 @@ wrsPtpInstanceStateNext OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Name of instance" "Name of instance"
::= { wrsPtpInstanceEntry 6 } ::= { wrsPtpInstanceEntry 8 }
wrsPtpInstanceRole OBJECT-TYPE wrsPtpInstanceRole OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2759,7 +2781,7 @@ wrsPtpInstanceRole OBJECT-TYPE ...@@ -2759,7 +2781,7 @@ wrsPtpInstanceRole OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Role of instance" "Role of instance"
::= { wrsPtpInstanceEntry 7 } ::= { wrsPtpInstanceEntry 9 }
wrsPtpInstanceMechanism OBJECT-TYPE wrsPtpInstanceMechanism OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2771,7 +2793,7 @@ wrsPtpInstanceMechanism OBJECT-TYPE ...@@ -2771,7 +2793,7 @@ wrsPtpInstanceMechanism OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Mechanism used by an instance" "Mechanism used by an instance"
::= { wrsPtpInstanceEntry 8 } ::= { wrsPtpInstanceEntry 10 }
wrsPtpInstanceProto OBJECT-TYPE wrsPtpInstanceProto OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2784,7 +2806,7 @@ wrsPtpInstanceProto OBJECT-TYPE ...@@ -2784,7 +2806,7 @@ wrsPtpInstanceProto OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Protocol used by an instance" "Protocol used by an instance"
::= { wrsPtpInstanceEntry 9 } ::= { wrsPtpInstanceEntry 11 }
wrsPtpInstanceExt OBJECT-TYPE wrsPtpInstanceExt OBJECT-TYPE
SYNTAX INTEGER { SYNTAX INTEGER {
...@@ -2796,7 +2818,7 @@ wrsPtpInstanceExt OBJECT-TYPE ...@@ -2796,7 +2818,7 @@ wrsPtpInstanceExt OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Extension used by an instance" "Extension used by an instance"
::= { wrsPtpInstanceEntry 10 } ::= { wrsPtpInstanceEntry 12 }
wrsPtpInstancePeerMac OBJECT-TYPE wrsPtpInstancePeerMac OBJECT-TYPE
SYNTAX PhysAddress SYNTAX PhysAddress
...@@ -2804,7 +2826,7 @@ wrsPtpInstancePeerMac OBJECT-TYPE ...@@ -2804,7 +2826,7 @@ wrsPtpInstancePeerMac OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"VID used by an instance" "VID used by an instance"
::= { wrsPtpInstanceEntry 11 } ::= { wrsPtpInstanceEntry 13 }
wrsPtpInstancePeerVid OBJECT-TYPE wrsPtpInstancePeerVid OBJECT-TYPE
SYNTAX Integer SYNTAX Integer
...@@ -2812,7 +2834,7 @@ wrsPtpInstancePeerVid OBJECT-TYPE ...@@ -2812,7 +2834,7 @@ wrsPtpInstancePeerVid OBJECT-TYPE
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"VID used by an instance" "VID used by an instance"
::= { wrsPtpInstanceEntry 12 } ::= { wrsPtpInstanceEntry 14 }
--wrsNetworking --wrsNetworking
--Configuration --Configuration
......
...@@ -6,8 +6,10 @@ struct wrsPtpInstanceTable_s wrsPtpInstanceTable_array[PP_MAX_LINKS]; ...@@ -6,8 +6,10 @@ struct wrsPtpInstanceTable_s wrsPtpInstanceTable_array[PP_MAX_LINKS];
static struct pickinfo wrsPtpInstanceTable_pickinfo[] = { static struct pickinfo wrsPtpInstanceTable_pickinfo[] = {
/* Warning: strings are a special case for snmp format */ /* Warning: strings are a special case for snmp format */
FIELD(wrsPtpInstanceTable_s, ASN_UNSIGNED, wrsPtpInstanceIndex), /* not reported */ FIELD(wrsPtpInstanceTable_s, ASN_UNSIGNED, wrsPtpInstancePortIndex), /* not reported */
FIELD(wrsPtpInstanceTable_s, ASN_UNSIGNED, wrsPtpInstanceOnPortIndex), /* not reported */
FIELD(wrsPtpInstanceTable_s, ASN_INTEGER, wrsPtpInstancePort), FIELD(wrsPtpInstanceTable_s, ASN_INTEGER, wrsPtpInstancePort),
FIELD(wrsPtpInstanceTable_s, ASN_INTEGER, wrsPtpInstancePortInstance),
FIELD(wrsPtpInstanceTable_s, ASN_OCTET_STR, wrsPtpInstancePortName), FIELD(wrsPtpInstanceTable_s, ASN_OCTET_STR, wrsPtpInstancePortName),
FIELD(wrsPtpInstanceTable_s, ASN_OCTET_STR, wrsPtpInstanceName), FIELD(wrsPtpInstanceTable_s, ASN_OCTET_STR, wrsPtpInstanceName),
FIELD(wrsPtpInstanceTable_s, ASN_INTEGER, wrsPtpInstanceState), FIELD(wrsPtpInstanceTable_s, ASN_INTEGER, wrsPtpInstanceState),
...@@ -41,6 +43,9 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows) ...@@ -41,6 +43,9 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows)
struct pp_instance *ppsi_i; struct pp_instance *ppsi_i;
char *tmp_name; char *tmp_name;
struct hal_port_state *p; struct hal_port_state *p;
int phys_port;
int last_port = 0;
int instance_on_port = 0;
/* number of rows does not change for wrsPortStatusTable */ /* number of rows does not change for wrsPortStatusTable */
if (n_rows) if (n_rows)
...@@ -84,17 +89,28 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows) ...@@ -84,17 +89,28 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows)
tmp_name = (char *) wrs_shm_follow(ppsi_head, tmp_name = (char *) wrs_shm_follow(ppsi_head,
ppsi_i->port_name); ppsi_i->port_name);
strncpy(i_a[i].wrsPtpInstanceName, tmp_name, 12); strncpy(i_a[i].wrsPtpInstanceName, tmp_name, 16);
i_a[i].wrsPtpInstanceName[11] = '\0'; i_a[i].wrsPtpInstanceName[15] = '\0';
tmp_name = (char *) wrs_shm_follow(ppsi_head, tmp_name = (char *) wrs_shm_follow(ppsi_head,
ppsi_i->iface_name); ppsi_i->iface_name);
strncpy(i_a[i].wrsPtpInstancePortName, tmp_name, 12); strncpy(i_a[i].wrsPtpInstancePortName, tmp_name, 16);
i_a[i].wrsPtpInstancePortName[11] = '\0'; i_a[i].wrsPtpInstancePortName[15] = '\0';
p = pp_wrs_lookup_port(tmp_name); p = pp_wrs_lookup_port(tmp_name);
if (p) if (p) {
i_a[i].wrsPtpInstancePort = p->hw_index + 1; phys_port = p->hw_index + 1;
i_a[i].wrsPtpInstancePort = phys_port;
if (last_port == phys_port)
instance_on_port++;
else
instance_on_port = 1;
last_port = phys_port;
}
i_a[i].wrsPtpInstancePortInstance = instance_on_port;
i_a[i].wrsPtpInstanceState = ppsi_i->state; i_a[i].wrsPtpInstanceState = ppsi_i->state;
i_a[i].wrsPtpInstanceStateNext = ppsi_i->next_state; i_a[i].wrsPtpInstanceStateNext = ppsi_i->next_state;
...@@ -127,57 +143,49 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows) ...@@ -127,57 +143,49 @@ time_t wrsPtpInstanceTable_data_fill(unsigned int *n_rows)
* one for each table */ * one for each table */
static unsigned int t_n_rows; /* template n_rows */ static unsigned int t_n_rows; /* template n_rows */
struct coordinates_s {
int port;
int inst;
};
struct coordinates_s inst_c;
static netsnmp_variable_list * static netsnmp_variable_list *
table_next_entry(void **loop_context, table_next_entry(void **loop_context,
void **data_context, void **data_context,
netsnmp_variable_list *index, netsnmp_variable_list *index,
netsnmp_iterator_info *data) netsnmp_iterator_info *data)
{ {
int i = (int)(intptr_t)(*loop_context);
inst_c.inst++;
if (inst_c.inst > 1){ netsnmp_variable_list *idx = index;
inst_c.inst = 0; // snmp_log(LOG_ERR, "%s: loop_context %d\n", __func__, i);
inst_c.port++; if (i >= t_n_rows) {
} return NULL; /* no more */
if (inst_c.port > 5){ snmp_log(LOG_ERR, "%s: no more\n", __func__);
return NULL;
} }
/* create the line ID from counter number */
// i = (intptr_t)*loop_context; /* Embed into index part of OID a port number */
// if (i >= t_n_rows) snmp_set_var_typed_value(idx, ASN_INTEGER,
// return NULL; /* no more */ (u_char *)&wrsPtpInstanceTable_array[i].wrsPtpInstancePort,
// i++; sizeof(uint32_t));
/* Create the row OID: only the counter index */
snmp_set_var_value(index, (u_char *)&inst_c.port, sizeof(inst_c.port)); /* Embed into index part of OID an instance index on port */
snmp_set_var_value(index->next_variable, (u_char *)&inst_c.inst, sizeof(inst_c.inst)); idx = idx->next_variable;
snmp_set_var_typed_value(idx, ASN_INTEGER,
/* Set the data context (1..4) (u_char *)&wrsPtpInstanceTable_array[i].wrsPtpInstancePortInstance,
* Cannot be set to 0, because netsnmp_extract_iterator_context returns sizeof(uint32_t));
* NULL in function wrsPstats_handler when table is over */
*data_context = (void *)&inst_c; *data_context = &wrsPtpInstanceTable_array[i];
/* and set the loop context for the next iteration */ *loop_context = (void *)(intptr_t)(++i);
*loop_context = (void *)&inst_c;
return index; return index;
} }
static netsnmp_variable_list * static netsnmp_variable_list *
table_first_entry(void **loop_context, table_first_entry(void **loop_context,
void **data_context, void **data_context,
netsnmp_variable_list *index, netsnmp_variable_list *index,
netsnmp_iterator_info *data) netsnmp_iterator_info *data)
{ {
inst_c.port = 0; *loop_context = 0;
inst_c.inst = 0; *data_context = 0;
// snmp_log(LOG_ERR, "%s\n", __func__);
/* reset internal position, so "next" is "first" */ /* reset internal position, so "next" is "first" */
*loop_context = &inst_c; /* first counter */
return table_next_entry(loop_context, data_context, index, data); return table_next_entry(loop_context, data_context, index, data);
} }
...@@ -190,13 +198,15 @@ table_handler(netsnmp_mib_handler *handler, ...@@ -190,13 +198,15 @@ table_handler(netsnmp_mib_handler *handler,
netsnmp_request_info *request; netsnmp_request_info *request;
netsnmp_variable_list *requestvb; netsnmp_variable_list *requestvb;
netsnmp_table_request_info *table_info; netsnmp_table_request_info *table_info;
struct wrsPtpInstanceTable_s *entry;
struct pickinfo *pi; struct pickinfo *pi;
int row, subid; int subid;
int len; int len;
void *ptr; void *ptr;
struct counter64 tmp_counter64; struct counter64 tmp_counter64;
// snmp_log(LOG_ERR, "%s: before mode check\n", __func__);
switch (reqinfo->mode) { switch (reqinfo->mode) {
case MODE_GET: case MODE_GET:
/* "break;" so read code is not indented too much */ /* "break;" so read code is not indented too much */
...@@ -219,24 +229,23 @@ table_handler(netsnmp_mib_handler *handler, ...@@ -219,24 +229,23 @@ table_handler(netsnmp_mib_handler *handler,
for (request = requests; request; request = request->next) { for (request = requests; request; request = request->next) {
struct coordinates_s *xxx;
requestvb = request->requestvb; requestvb = request->requestvb;
/* "context" is the row number */ /* "context" is the row number */
xxx = (struct coordinates_s*)netsnmp_extract_iterator_context(request); entry = (struct wrsPtpInstanceTable_s *)netsnmp_extract_iterator_context(request);
if (!xxx) if (!entry) {
/* NULL returned from /* NULL returned from
* netsnmp_extract_iterator_context shuld be * netsnmp_extract_iterator_context shuld be
* interpreted as end of table */ * interpreted as end of table */
break; continue;
/* change range of row (1..X (snmp is 1 based) -> }
* 0..X (wrs_t_table_array/data array is 0 based)) */
row = 5;
table_info = netsnmp_extract_table_info(request); table_info = netsnmp_extract_table_info(request);
subid = table_info->colnum - 1; subid = table_info->colnum - 1;
// snmp_log(LOG_ERR, "%s: %d\n", __func__, subid);
pi = wrsPtpInstanceTable_pickinfo + subid; pi = wrsPtpInstanceTable_pickinfo + subid;
ptr = (void *)(wrsPtpInstanceTable_array + row) + pi->offset; ptr = (void *)(entry) + pi->offset;
/* snmp_set_var_typed_value function does not support counter64 /* snmp_set_var_typed_value function does not support counter64
* as a uint64_t, but as a struct counter64. Their binary * as a uint64_t, but as a struct counter64. Their binary
* representation differs by order of 32bit words. We fill * representation differs by order of 32bit words. We fill
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
struct wrsPtpInstanceTable_s { struct wrsPtpInstanceTable_s {
uint32_t wrsPtpInstanceIndex; /* not reported, index fields has t o be marked uint32_t wrsPtpInstancePortIndex; /* not reported, index fields has t o be marked
* as not-accessible in MIB */ * as not-accessible in MIB */
uint32_t wrsPtpInstanceOnPortIndex; /* port on which ptp instance is running (index+1) */
int wrsPtpInstancePort; /* port on which ptp instance is running (index+1) */ int wrsPtpInstancePort; /* port on which ptp instance is running (index+1) */
char wrsPtpInstancePortName[12];/* port name on which ptp instance is running (wriX) */ int wrsPtpInstancePortInstance; /* serial of instance running on a given port */
char wrsPtpInstanceName[12]; /* Instance name */ char wrsPtpInstancePortName[16];/* port name on which ptp instance is running (wriX) */
char wrsPtpInstanceName[16]; /* Instance name */
int wrsPtpInstanceState; int wrsPtpInstanceState;
int wrsPtpInstanceStateNext; int wrsPtpInstanceStateNext;
int wrsPtpInstanceRole; int wrsPtpInstanceRole;
......
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