From 07afc973c01cd062c0c788cf65b6033aadf26c39 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Fri, 15 Apr 2016 01:48:48 +0000 Subject: [PATCH] - Use new official OCP ONL subtree. - Implement the ONL Platform information subtrees --- packages/base/any/onlp-snmpd/APKG.yml | 1 + packages/base/any/onlp-snmpd/bin/onl-snmpwalk | 34 +++++++ packages/base/any/onlp-snmpd/builds/Makefile | 2 +- .../inc/onlp_snmp/onlp_snmp_platform_oids.h | 27 ++---- .../inc/onlp_snmp/onlp_snmp_sensor_oids.h | 23 ++--- .../onlp_snmp/module/src/onlp_snmp_sensors.c | 96 +++++++++++++++++-- 6 files changed, 141 insertions(+), 42 deletions(-) create mode 100755 packages/base/any/onlp-snmpd/bin/onl-snmpwalk diff --git a/packages/base/any/onlp-snmpd/APKG.yml b/packages/base/any/onlp-snmpd/APKG.yml index d931723e..6d23b694 100644 --- a/packages/base/any/onlp-snmpd/APKG.yml +++ b/packages/base/any/onlp-snmpd/APKG.yml @@ -14,6 +14,7 @@ packages: files: builds/$BUILD_DIR/${TOOLCHAIN}/bin/onlp-snmpd: /usr/bin/onlp-snmpd + ${ONL}/packages/base/any/onlp-snmpd/bin/onl-snmpwalk : /usr/bin/onl-snmpwalk init: ${ONL}/packages/base/any/onlp-snmpd/onlp-snmpd.init diff --git a/packages/base/any/onlp-snmpd/bin/onl-snmpwalk b/packages/base/any/onlp-snmpd/bin/onl-snmpwalk new file mode 100755 index 00000000..c88e606f --- /dev/null +++ b/packages/base/any/onlp-snmpd/bin/onl-snmpwalk @@ -0,0 +1,34 @@ +#!/bin/sh +############################################################ +SERVER=localhost +ONL_TREE=.1.3.6.1.4.1.42623.1 +MIBS=OCP-ONL-PLATFORM-MIB:OCP-ONL-SENSOR-MIB +MIB_ARGS="-m $MIBS" +COMMUNITY=public +ECHO= + +while getopts "s:c:nvpd" opt; do + case $opt in + s) + SERVER=$OPTARG; + ;; + n) + MIB_ARGS= + ;; + c) + COMMUNITY=$OPTARG; + ;; + p) + ONL_TREE="${ONL_TREE}.1" + ;; + v) + set -x + ;; + d) + # Just echo the command + ECHO=echo + ;; + esac +done + +$ECHO snmpwalk $MIB_ARGS -v2c -c $COMMUNITY $SERVER $ONL_TREE diff --git a/packages/base/any/onlp-snmpd/builds/Makefile b/packages/base/any/onlp-snmpd/builds/Makefile index 638105f6..f423035f 100644 --- a/packages/base/any/onlp-snmpd/builds/Makefile +++ b/packages/base/any/onlp-snmpd/builds/Makefile @@ -3,7 +3,7 @@ include $(ONL)/make/any.mk MODULE := onlp-snmpd include $(BUILDER)/standardinit.mk -DEPENDMODULES := onlp_snmp AIM OS snmp_subagent IOF +DEPENDMODULES := onlp_snmp AIM OS snmp_subagent IOF onlplib DEPENDMODULE_HEADERS := onlp include $(BUILDER)/dependmodules.mk diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_platform_oids.h b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_platform_oids.h index a8a1c5b9..74a29190 100644 --- a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_platform_oids.h +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_platform_oids.h @@ -1,21 +1,21 @@ /************************************************************ * - * - * Copyright 2015 Big Switch Networks, Inc. - * + * + * Copyright 2015 Big Switch Networks, Inc. + * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.eclipse.org/legal/epl-v10.html - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. - * + * * ************************************************************ * @@ -30,23 +30,10 @@ * ONLP-PLATFORM-MIBS.txt */ -/** - * These are all currently defined as part of the Big Switch enterprise tree. - * - * In the future we should apply for an ONL Private Enterprise Number and - * redefine these appropriately. - */ - -#define ONLP_SNMP_PLATFORM_INFORMATION_OID 1,3,6,1,4,1,37538,2,1000 +#define ONLP_SNMP_PLATFORM_INFORMATION_OID 1,3,6,1,4,1,42623,1,1 #define ONLP_SNMP_PLATFORM_GENERAL_OID ONLP_SNMP_PLATFORM_INFORMATION_OID,1 #define ONLP_SNMP_PLATFORM_SYSTEM_OID ONLP_SNMP_PLATFORM_GENERAL_OID,1 - -/** - * TODO - */ - - #endif /* __ONLP_SNMP_PLATFORM_OIDS_H__ */ diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_sensor_oids.h b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_sensor_oids.h index e4a24888..79a40ba9 100644 --- a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_sensor_oids.h +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/inc/onlp_snmp/onlp_snmp_sensor_oids.h @@ -1,21 +1,21 @@ /************************************************************ * - * - * Copyright 2015 Big Switch Networks, Inc. - * + * + * Copyright 2015 Big Switch Networks, Inc. + * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.eclipse.org/legal/epl-v10.html - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. - * + * * ************************************************************ * @@ -27,17 +27,10 @@ /** * See: - * ONLP-SENSOR-MIBS.txt + * OCP-ONL-SENSOR-MIBS.txt */ -/** - * These are all currently defined as part of the Big Switch enterprise tree. - * - * In the future we should apply for an ONL Private Enterprise Number and - * redefine these appropriately. - */ - -#define ONLP_SNMP_SENSOR_OID 1,3,6,1,4,1,37538,2,3 +#define ONLP_SNMP_SENSOR_OID 1,3,6,1,4,1,42623,1,2 #define ONLP_SNMP_SENSOR_ENTRY 1 diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c index 03923cfc..4a0379a7 100644 --- a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c @@ -1,21 +1,21 @@ /************************************************************ * - * - * Copyright 2015 Big Switch Networks, Inc. - * + * + * Copyright 2015 Big Switch Networks, Inc. + * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.eclipse.org/legal/epl-v10.html - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. - * + * * ************************************************************ * @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -1291,9 +1292,92 @@ void onlp_snmp_sensors_init(void) } } +static void +platform_string_register(int index, const char* desc, char* value) +{ + oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1}; + tree[11] = index; + + if(!value || !value[0]) { + return; + } + + char* s = aim_strdup(value); + + netsnmp_handler_registration *reg = + netsnmp_create_handler_registration( + desc, NULL, + tree, OID_LENGTH(tree), + HANDLER_CAN_RONLY); + netsnmp_watcher_info *winfo = + netsnmp_create_watcher_info( + s, strlen(s), + ASN_OCTET_STR, WATCHER_FIXED_SIZE); + netsnmp_register_watched_scalar( reg, winfo ); +} + +void +platform_int_register(int index, char* desc, int value) +{ + oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1}; + tree[11] = index; + + int* v = aim_zmalloc(sizeof(value)); + *v = value; + + netsnmp_register_int_instance(desc, + tree, + OID_LENGTH(tree), + v, NULL); +} + + +void +onlp_snmp_platform_init(void) +{ + /** + * This is the base of the platform:general:system tree + */ + onlp_sys_info_t si; + if(onlp_sys_info_get(&si) >= 0) { + +#define REGISTER_STR(_index, _field) \ + do { \ + platform_string_register(_index, #_field, (char*)si.onie_info._field); \ + } while(0) + +#define REGISTER_INT(_index, _field) \ + do { \ + platform_int_register(_index, #_field, si.onie_info._field); \ + } while(0) + + REGISTER_STR(1, product_name); + REGISTER_STR(2, part_number); + REGISTER_STR(3, serial_number); + char* mstring = aim_fstrdup("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + si.onie_info.mac[0], si.onie_info.mac[2], si.onie_info.mac[3], + si.onie_info.mac[3], si.onie_info.mac[4], si.onie_info.mac[5]); + platform_string_register(4, "mac", mstring); + aim_free(mstring); + + REGISTER_INT(5, mac_range); + REGISTER_STR(6, manufacturer); + REGISTER_STR(7, manufacture_date); + REGISTER_STR(8, vendor); + REGISTER_STR(9, platform_name); + REGISTER_INT(10, device_version); + REGISTER_STR(11, label_revision); + REGISTER_STR(12, country_code); + REGISTER_STR(13, diag_version); + REGISTER_STR(14, service_tag); + REGISTER_STR(15, onie_version); + } +} + int onlp_snmp_sensors_client(int enable, void* cookie) { onlp_snmp_sensors_init(); + onlp_snmp_platform_init(); return 0; }