diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_main.c b/packages/base/any/onlp/src/onlp/module/src/onlp_main.c
index 51cbb36d..6dd5ccfe 100644
--- a/packages/base/any/onlp/src/onlp/module/src/onlp_main.c
+++ b/packages/base/any/onlp/src/onlp/module/src/onlp_main.c
@@ -184,6 +184,7 @@ onlpdump_main(int argc, char* argv[])
char* pidfile = NULL;
const char* O = NULL;
const char* t = NULL;
+ const char* J = NULL;
/**
* debug trap
@@ -198,7 +199,7 @@ onlpdump_main(int argc, char* argv[])
}
}
- while( (c = getopt(argc, argv, "srehdojmyM:ipxlSt:O:b")) != -1) {
+ while( (c = getopt(argc, argv, "srehdojmyM:ipxlSt:O:bJ:")) != -1) {
switch(c)
{
case 's': show=1; break;
@@ -218,6 +219,7 @@ onlpdump_main(int argc, char* argv[])
case 'S': S=1; break;
case 'l': l=1; break;
case 'b': b=1; break;
+ case 'J': J = optarg; break;
case 'y': show=1; showflags |= ONLP_OID_SHOW_F_YAML; break;
default: help=1; rv = 1; break;
}
@@ -242,9 +244,24 @@ onlpdump_main(int argc, char* argv[])
printf(" -S Decode SFP Inventory\n");
printf(" -b Decode SFP Inventory into SFF database entries.\n");
printf(" -l API Lock test.\n");
+ printf(" -J Decode ONIE JSON data.\n");
return rv;
}
+ if(J) {
+ int rv;
+ onlp_onie_info_t onie;
+ rv = onlp_onie_read_json(&onie, J);
+ if(rv < 0) {
+ fprintf(stderr, "onie read json failed: %d\n", rv);
+ return 1;
+ }
+ else {
+ onlp_onie_show(&onie, &aim_pvs_stdout);
+ onlp_onie_info_free(&onie);
+ return 0;
+ }
+ }
if(t) {
int rv;
diff --git a/packages/base/any/onlp/src/onlplib/.module b/packages/base/any/onlp/src/onlplib/.module
index 7cf3968c..f3d0bc49 100644
--- a/packages/base/any/onlp/src/onlplib/.module
+++ b/packages/base/any/onlp/src/onlplib/.module
@@ -1,2 +1,2 @@
name: onlplib
-depends: cjson
+depends: cjson_util
diff --git a/packages/base/any/onlp/src/onlplib/module/auto/onlplib.yml b/packages/base/any/onlp/src/onlplib/module/auto/onlplib.yml
index b13f63ab..bec06562 100644
--- a/packages/base/any/onlp/src/onlplib/module/auto/onlplib.yml
+++ b/packages/base/any/onlp/src/onlplib/module/auto/onlplib.yml
@@ -70,4 +70,23 @@ definitions:
- vsnprintf
- snprintf
- strlen
- - atoi
\ No newline at end of file
+ - atoi
+
+ xmacro:
+ ONIE_TLV_ENTRY:
+ members:
+ - product_name, Product Name, 0x21, str
+ - part_number, Part Number, 0x22, str
+ - serial_number, Serial Number, 0x23, str
+ - mac, MAC, 0x24, mac
+ - manufacture_date, Manufacture Date, 0x25, str
+ - device_version, Device Version, 0x26, byte
+ - label_revision, Label Revision, 0x27, str
+ - platform_name, Platform Name, 0x28, str
+ - onie_version, ONIE Version, 0x29, str
+ - mac_range, MAC Range, 0x2A, int16
+ - manufacturer, Manufacturer, 0x2B, str
+ - country_code, Country Code, 0x2C, str
+ - vendor, Vendor, 0x2D, str
+ - diag_version, Diag Version, 0x2E, str
+ - service_tag, Service Tag, 0x2F, str
diff --git a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onie.h b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onie.h
index 89e9255a..e1b50894 100644
--- a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onie.h
+++ b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onie.h
@@ -100,4 +100,9 @@ void onlp_onie_show(onlp_onie_info_t* info, aim_pvs_t* pvs);
*/
void onlp_onie_show_json(onlp_onie_info_t* info, aim_pvs_t* pvs);
+/**
+ * Read ONIE fields from a JSON file.
+ */
+int onlp_onie_read_json(onlp_onie_info_t* info, const char* fname);
+
#endif /* __ONLP_ONIE_H__ */
diff --git a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onlplib.x b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onlplib.x
index f8b4ac4d..cd729e23 100644
--- a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onlplib.x
+++ b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/onlplib.x
@@ -1,21 +1,21 @@
/************************************************************
*
- *
- * Copyright 2014, 2015 Big Switch Networks, Inc.
- *
+ *
+ * Copyright 2014, 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.
- *
+ *
*
************************************************************
*
@@ -23,9 +23,25 @@
*
***********************************************************/
-#include
-
-/* <--auto.start.xmacro(ALL).define> */
+/* */
+#ifdef ONIE_TLV_ENTRY
+ONIE_TLV_ENTRY(product_name, Product Name, 0x21, str)
+ONIE_TLV_ENTRY(part_number, Part Number, 0x22, str)
+ONIE_TLV_ENTRY(serial_number, Serial Number, 0x23, str)
+ONIE_TLV_ENTRY(mac, MAC, 0x24, mac)
+ONIE_TLV_ENTRY(manufacture_date, Manufacture Date, 0x25, str)
+ONIE_TLV_ENTRY(device_version, Device Version, 0x26, byte)
+ONIE_TLV_ENTRY(label_revision, Label Revision, 0x27, str)
+ONIE_TLV_ENTRY(platform_name, Platform Name, 0x28, str)
+ONIE_TLV_ENTRY(onie_version, ONIE Version, 0x29, str)
+ONIE_TLV_ENTRY(mac_range, MAC Range, 0x2A, int16)
+ONIE_TLV_ENTRY(manufacturer, Manufacturer, 0x2B, str)
+ONIE_TLV_ENTRY(country_code, Country Code, 0x2C, str)
+ONIE_TLV_ENTRY(vendor, Vendor, 0x2D, str)
+ONIE_TLV_ENTRY(diag_version, Diag Version, 0x2E, str)
+ONIE_TLV_ENTRY(service_tag, Service Tag, 0x2F, str)
+#undef ONIE_TLV_ENTRY
+#endif
/* */
/* <--auto.start.xenum(ALL).define> */
diff --git a/packages/base/any/onlp/src/onlplib/module/src/onie.c b/packages/base/any/onlp/src/onlplib/module/src/onie.c
index eecd5feb..2060e2e3 100644
--- a/packages/base/any/onlp/src/onlplib/module/src/onie.c
+++ b/packages/base/any/onlp/src/onlplib/module/src/onie.c
@@ -396,6 +396,7 @@ onlp_onie_show(onlp_onie_info_t* info, aim_pvs_t* pvs)
}
#include
+#include
void
onlp_onie_show_json(onlp_onie_info_t* info, aim_pvs_t* pvs)
@@ -444,4 +445,85 @@ onlp_onie_show_json(onlp_onie_info_t* info, aim_pvs_t* pvs)
cJSON_Delete(cj);
}
+static char*
+lookup_entry__(cJSON* cj, const char* name, int code)
+{
+ char* str = NULL;
+ int rv = cjson_util_lookup_string(cj, &str, "0x%x", code);
+ if(rv < 0) {
+ rv = cjson_util_lookup_string(cj, &str, name);
+ }
+ if(rv < 0) {
+ return NULL;
+ }
+ else {
+ return aim_strdup(str);
+ }
+}
+
+int
+onlp_onie_read_json(onlp_onie_info_t* info, const char* fname)
+{
+ cJSON* cj;
+
+ memset(info, 0, sizeof(*info));
+
+ list_init(&info->vx_list);
+
+ int rv = cjson_util_parse_file(fname, &cj);
+ if(rv < 0) {
+ AIM_LOG_ERROR("Could not parse ONIE JSON file '%s' rv=%{aim_error}",
+ fname, rv);
+ return rv;
+ }
+
+#define ONIE_TLV_ENTRY_str(_member, _name, _code) \
+ do { \
+ info->_member = lookup_entry__(cj, #_name, _code); \
+ } while(0)
+
+#define ONIE_TLV_ENTRY_mac(_member, _name, _code) \
+ do { \
+ char* str = lookup_entry__(cj, #_name, _code); \
+ int mac[6] = {0}; \
+ if(str) { \
+ int i; \
+ sscanf(str, "%x:%x:%x:%x:%x:%x", \
+ mac+0, mac+1, mac+2, mac+3, mac+4, mac+5); \
+ for(i = 0; i < 6; i++) info->mac[i] = mac[i]; \
+ aim_free(str); \
+ } \
+ } while(0)
+
+#define ONIE_TLV_ENTRY_byte(_member, _name, _code) \
+ do { \
+ char* v = lookup_entry__(cj, #_name, _code); \
+ if(v) { \
+ info->_member = atoi(v); \
+ aim_free(v); \
+ } \
+ } while(0)
+
+#define ONIE_TLV_ENTRY_int16(_member, _name, _code) \
+ do { \
+ char* v = lookup_entry__(cj, #_name, _code); \
+ if(v) { \
+ info->_member = atoi(v); \
+ aim_free(v); \
+ } \
+ } while(0)
+
+#define ONIE_TLV_ENTRY(_member, _name, _code, _type) \
+ ONIE_TLV_ENTRY_##_type(_member, _name, _code);
+
+ #include
+
+
+ cJSON_Delete(cj);
+ return 0;
+}
+
+
+
+
diff --git a/packages/base/any/onlp/src/onlplib/onlplib.mk b/packages/base/any/onlp/src/onlplib/onlplib.mk
index c33c4de3..0f69b303 100644
--- a/packages/base/any/onlp/src/onlplib/onlplib.mk
+++ b/packages/base/any/onlp/src/onlplib/onlplib.mk
@@ -3,7 +3,7 @@
#
# Inclusive Makefile for the onlplib module.
#
-# Autogenerated 2016-05-17 17:43:05.779760
+# Autogenerated 2016-12-15 17:09:12.738344
#
###############################################################################
onlplib_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))