mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
- Improve ONIE TLV processing. Still WIP.
- Read ONIE data from the platform's onie-syseeprom contents.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
name: onlplib
|
||||
depends: cjson
|
||||
depends: cjson_util
|
||||
|
||||
@@ -70,4 +70,23 @@ definitions:
|
||||
- vsnprintf
|
||||
- snprintf
|
||||
- strlen
|
||||
- atoi
|
||||
- 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
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/************************************************************
|
||||
* <bsn.cl fy=2014 v=onl>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* </bsn.cl>
|
||||
************************************************************
|
||||
*
|
||||
@@ -23,9 +23,25 @@
|
||||
*
|
||||
***********************************************************/
|
||||
|
||||
#include <onlplib/onlplib_config.h>
|
||||
|
||||
/* <--auto.start.xmacro(ALL).define> */
|
||||
/* <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.end.xmacro(ALL).define> */
|
||||
|
||||
/* <--auto.start.xenum(ALL).define> */
|
||||
|
||||
@@ -396,6 +396,7 @@ onlp_onie_show(onlp_onie_info_t* info, aim_pvs_t* pvs)
|
||||
}
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson_util/cjson_util.h>
|
||||
|
||||
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 <onlplib/onlplib.x>
|
||||
|
||||
|
||||
cJSON_Delete(cj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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))))
|
||||
|
||||
Reference in New Issue
Block a user