Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
wr-switch-sw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
white-rabbit
wr-switch-sw
Commits
ebc6a893
Commit
ebc6a893
authored
Mar 19, 2015
by
Adam Wujek
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userspace/snmpd: add wrsPortStatusTable using table template
Signed-off-by:
Adam Wujek
<
adam.wujek@cern.ch
>
parent
dd080034
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
1 deletion
+170
-1
Makefile
userspace/snmpd/Makefile
+2
-1
init.c
userspace/snmpd/init.c
+2
-0
wrsPortStatusTable.c
userspace/snmpd/wrsPortStatusTable.c
+128
-0
wrsPortStatusTable.h
userspace/snmpd/wrsPortStatusTable.h
+29
-0
wrsSnmp.h
userspace/snmpd/wrsSnmp.h
+9
-0
No files found.
userspace/snmpd/Makefile
View file @
ebc6a893
...
...
@@ -34,7 +34,8 @@ SOURCES = \
shmem.c
\
wrsPtpData.c
\
wrsTemperature.c
\
wrsOSStatus.c
wrsOSStatus.c
\
wrsPortStatusTable.c
OBJECTS
=
$
(
SOURCES:.c
=
.o
)
...
...
userspace/snmpd/init.c
View file @
ebc6a893
...
...
@@ -9,6 +9,7 @@
#include "wrsSnmp.h"
#include "wrsTemperature.h"
#include "wrsOSStatus.h"
#include "wrsPortStatusTable.h"
FILE
*
wrs_logf
;
/* for the local-hack messages */
...
...
@@ -22,4 +23,5 @@ void init_wrsSnmp(void)
init_wrsPtpData
();
init_wrsTemperature
();
init_wrsOSStatus
();
init_wrsPortStatusTable
();
}
userspace/snmpd/wrsPortStatusTable.c
0 → 100644
View file @
ebc6a893
#include "wrsSnmp.h"
#include "wrsPortStatusTable.h"
/* Our data: per-port information */
struct
wrsPortStatusTable_s
wrsPortStatusTable_array
[
WRS_N_PORTS
];
static
struct
pickinfo
wrsPortStatusTable_pickinfo
[]
=
{
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
link_up
),
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
port_mode
),
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
port_locked
),
FIELD
(
wrsPortStatusTable_s
,
ASN_OCTET_STR
,
peer_id
),
FIELD
(
wrsPortStatusTable_s
,
ASN_OCTET_STR
,
sfp_vn
),
FIELD
(
wrsPortStatusTable_s
,
ASN_OCTET_STR
,
sfp_pn
),
FIELD
(
wrsPortStatusTable_s
,
ASN_OCTET_STR
,
sfp_vs
),
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
sfp_in_db
),
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
sfp_GbE
),
FIELD
(
wrsPortStatusTable_s
,
ASN_INTEGER
,
sfp_error
),
};
time_t
wrsPortStatusTable_data_fill
(
unsigned
int
*
n_rows
)
{
unsigned
ii
,
i
;
unsigned
retries
=
0
;
static
time_t
time_update
;
time_t
time_cur
;
/* number of rows does not change for wrsPortStatusTable */
if
(
n_rows
)
*
n_rows
=
WRS_N_PORTS
;
time_cur
=
time
(
NULL
);
if
(
time_update
&&
time_cur
-
time_update
<
WRSPORTSTATUSTABLE_CACHE_TIMEOUT
)
{
/* cache not updated, return last update time */
return
time_update
;
}
time_update
=
time_cur
;
/* read data, with the sequential lock to have all data consistent */
struct
hal_port_state
*
port_state
;
memset
(
wrsPortStatusTable_array
,
0
,
sizeof
(
wrsPortStatusTable_array
));
while
(
1
)
{
ii
=
wrs_shm_seqbegin
(
hal_head
);
for
(
i
=
0
;
i
<
hal_nports_local
;
++
i
)
{
/* Assume that number of ports does not change between
* reads */
char
if_name
[
10
];
snprintf
(
if_name
,
10
,
"wr%d"
,
i
);
port_state
=
hal_lookup_port
(
hal_ports
,
hal_nports_local
,
if_name
);
/* No need to copy all ports structures, only what
* we're interested in.
* Keep value 0 for Not available */
wrsPortStatusTable_array
[
i
].
link_up
=
1
+
state_up
(
port_state
->
state
);
wrsPortStatusTable_array
[
i
].
port_mode
=
port_state
->
mode
;
if
(
port_state
->
state
==
HAL_PORT_STATE_DISABLED
)
{
wrsPortStatusTable_array
[
i
].
sfp_error
=
WRS_PORT_STATUS_SFP_ERROR_PORT_DOWN
;
/* if port is disabled don't fill
* other fields */
continue
;
}
/* Keep value 0 for Not available */
wrsPortStatusTable_array
[
i
].
port_locked
=
1
+
port_state
->
locked
;
/* FIXME: get real peer_id */
memset
(
&
wrsPortStatusTable_array
[
i
].
peer_id
,
0xff
,
sizeof
(
ClockIdentity
));
wrsPortStatusTable_array
[
i
].
sfp_in_db
=
port_state
->
calib
.
sfp
.
flags
&
SFP_FLAG_IN_DB
?
2
:
1
;
wrsPortStatusTable_array
[
i
].
sfp_GbE
=
port_state
->
calib
.
sfp
.
flags
&
SFP_FLAG_1GbE
?
2
:
1
;
strncpy
(
wrsPortStatusTable_array
[
i
].
sfp_vn
,
port_state
->
calib
.
sfp
.
vendor_name
,
sizeof
(
wrsPortStatusTable_array
[
i
].
sfp_vn
));
strncpy
(
wrsPortStatusTable_array
[
i
].
sfp_pn
,
port_state
->
calib
.
sfp
.
part_num
,
sizeof
(
wrsPortStatusTable_array
[
i
].
sfp_pn
));
strncpy
(
wrsPortStatusTable_array
[
i
].
sfp_vs
,
port_state
->
calib
.
sfp
.
vendor_serial
,
sizeof
(
wrsPortStatusTable_array
[
i
].
sfp_vs
));
/* sfp error when SFP is not 1 GbE or
* (port is not wr-non mode and sfp not in data base)
* Keep value 0 for Not available
* sfp ok is 1 (WRS_PORT_STATUS_SFP_ERROR_SFP_OK)
* sfp error is 2 WRS_PORT_STATUS_SFP_ERROR_SFP_ERROR
* port down, set above, is 3
* (WRS_PORT_STATUS_SFP_ERROR_PORT_DOWN) */
wrsPortStatusTable_array
[
i
].
sfp_error
=
1
+
((
wrsPortStatusTable_array
[
i
].
sfp_GbE
==
1
)
||
((
port_state
->
mode
!=
HEXP_PORT_MODE_NON_WR
)
&&
(
wrsPortStatusTable_array
[
i
].
sfp_in_db
==
1
)));
logmsg
(
"reading ports name %s link %d, mode %d, "
"locked %d
\n
"
,
port_state
->
name
,
wrsPortStatusTable_array
[
i
].
link_up
,
wrsPortStatusTable_array
[
i
].
port_mode
,
wrsPortStatusTable_array
[
i
].
port_locked
);
}
retries
++
;
if
(
retries
>
100
)
{
snmp_log
(
LOG_ERR
,
"%s: too many retries to read HAL
\n
"
,
__func__
);
retries
=
0
;
}
if
(
!
wrs_shm_seqretry
(
hal_head
,
ii
))
break
;
/* consistent read */
usleep
(
1000
);
}
/* there was an update, return current time */
return
time_cur
;
}
#define TT_OID WRS_OID, 6, 4
#define TT_PICKINFO wrsPortStatusTable_pickinfo
#define TT_DATA_FILL_FUNC wrsPortStatusTable_data_fill
#define TT_DATA_ARRAY wrsPortStatusTable_array
#define TT_GROUP_NAME "wrsPortStatusTable"
#define TT_INIT_FUNC init_wrsPortStatusTable
#include "wrsTableTemplate.h"
userspace/snmpd/wrsPortStatusTable.h
0 → 100644
View file @
ebc6a893
#ifndef WRS_PORT_STATUS_TABLE_H
#define WRS_PORT_STATUS_TABLE_H
#define WRSPORTSTATUSTABLE_CACHE_TIMEOUT 5
#define WRS_PORT_STATUS_SFP_ERROR_SFP_OK 1
/* ok */
#define WRS_PORT_STATUS_SFP_ERROR_SFP_ERROR 2
/* error */
#define WRS_PORT_STATUS_SFP_ERROR_PORT_DOWN 3
/* ok */
struct
wrsPortStatusTable_s
{
ClockIdentity
peer_id
;
/* These can't be "unsigned char" because we scanf a %i in there */
unsigned
link_up
;
unsigned
port_mode
;
unsigned
port_locked
;
char
sfp_vn
[
16
];
/* vendor name */
char
sfp_pn
[
16
];
/* part name */
char
sfp_vs
[
16
];
/* vendor serial */
int
sfp_in_db
;
int
sfp_GbE
;
int
sfp_error
;
};
extern
struct
wrsPortStatusTable_s
wrsPortStatusTable_array
[
WRS_N_PORTS
];
time_t
wrsPortStatusTable_data_fill
(
unsigned
int
*
rows
);
void
init_wrsPortStatusTable
(
void
);
#endif
/* WRS_PORT_STATUS_TABLE_H */
userspace/snmpd/wrsSnmp.h
View file @
ebc6a893
...
...
@@ -5,6 +5,15 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/* Crap! -- everybody makes them different, and even ppsi::ieee wants them */
#undef FALSE
#undef TRUE
/* conflict between definition in net-snmp-agent-includes.h (which include
* snmp_vars.h) and ppsi.h where INST is defined as a inline function */
#undef INST
#include <ppsi/ieee1588_types.h>
/* for ClockIdentity */
#include <libwr/shmem.h>
#include <libwr/hal_shmem.h>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment