From d9ce0e87b2656d562f5f5ada9158d0f4893bff6c Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Tue, 2 Jun 2020 09:55:35 -0700 Subject: [PATCH 1/6] swss-common: Changes to support SONiC Gearbox Manager * add class GearboxUtils, contains APIs useful for gearbox support across various submodules. * add additional REDIS tables to support second (PHY) syncd. Signed-off-by: syd.logan@broadcom.com --- common/Makefile.am | 1 + common/gearboxutils.cpp | 459 ++++++++++++++++++++++++++++++++++++++++ common/gearboxutils.h | 111 ++++++++++ common/schema.h | 7 + common/table.cpp | 20 +- 5 files changed, 590 insertions(+), 8 deletions(-) create mode 100644 common/gearboxutils.cpp create mode 100644 common/gearboxutils.h diff --git a/common/Makefile.am b/common/Makefile.am index a6231cb57..6e34b8b33 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -53,6 +53,7 @@ libswsscommon_la_SOURCES = \ notificationconsumer.cpp \ notificationproducer.cpp \ linkcache.cpp \ + gearboxutils.cpp \ portmap.cpp \ tokenize.cpp \ exec.cpp \ diff --git a/common/gearboxutils.cpp b/common/gearboxutils.cpp new file mode 100644 index 000000000..bcdd9e289 --- /dev/null +++ b/common/gearboxutils.cpp @@ -0,0 +1,459 @@ +/* + * Copyright 2019-2020 Broadcom Inc. + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +#include "gearboxutils.h" + +namespace swss { + +std::tuple GearboxUtils::parseGearboxKey(std::string key_str) +{ + /* + * The Gearbox key string has a few formats based on the number of tokens. + * Parse and return accordingly; + * phy::ports: rtn: ports + * phy::lanes: rtn: lanes + * phy: rtn: phy + * interface: rtn: interface + */ + + std::string str1, str2, str3; + std::vector token = tokenize(key_str, ':'); + + if (token.size() == 4) + { + str1 = token.at(2); + str2 = token.at(1); + str3 = token.at(3); + } + else if (token.size() == 2) + { + str1 = token.at(0); + str2 = token.at(1); + } + + SWSS_LOG_DEBUG("Parsed key:%s, Return:(%s)(%s)(%s)", key_str.c_str(), str1.c_str(), str2.c_str(), str3.c_str()); + + return make_tuple(str1, str2, str3); +} + +bool GearboxUtils::platformHasGearbox() +{ + bool ret = false; + + if (access("/usr/share/sonic/hwsku/gearbox_config.json", F_OK) != -1) + { + ret = true; + } + return ret; +} + +bool GearboxUtils::isGearboxConfigDone(Table &gearboxTable) +{ + std::vector tuples; + bool gearboxConfigDone = false; + + // this will return false if GearboxConfigDone is not set in the database + + gearboxConfigDone = gearboxTable.get("GearboxConfigDone", tuples); + return gearboxConfigDone; +} + +bool GearboxUtils::isGearboxConfigDone(Table *gearboxTable) +{ + std::vector tuples; + bool gearboxConfigDone = false; + + // this will return false if GearboxConfigDone is not set in the database + + gearboxConfigDone = gearboxTable->get("GearboxConfigDone", tuples); + return gearboxConfigDone; +} + +bool GearboxUtils::isGearboxEnabled(Table *gearboxTable) +{ + int count = 10; // 10 seconds is more than enough time + bool gearboxDone = false; + + SWSS_LOG_ENTER(); + + if (platformHasGearbox() != true) + { + return gearboxDone; + } + + // wait until gearbox table is ready + while (count > 0) + { + if (!isGearboxConfigDone(gearboxTable)) + { + sleep(1); + count--; + continue; + } + else + { + gearboxDone = true; + break; + } + } + + return gearboxDone; +} + +std::map GearboxUtils::loadPhyMap(Table *gearboxTable) +{ + std::vector ovalues; + std::tuple keyt; + std::vector keys; + + SWSS_LOG_ENTER(); + + gearboxTable->getKeys(keys); + + if (keys.empty()) + { + SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); + return gearboxPhyMap; + } + + for (auto &k : keys) + { + keyt = parseGearboxKey(k); + + if (std::get<0>(keyt).compare("phy") == 0) + { + gearbox_phy_t phy = {}; + + gearboxTable->get(k, ovalues); + for (auto &val : ovalues) + { + if (val.first == "phy_id") + { + phy.phy_id = std::stoi(val.second); + } + else if (val.first == "phy_oid") + { + // oid is from create_switch (not config) + phy.phy_oid = val.second; + } + else if (val.first == "name") + { + phy.name = val.second; + } + else if (val.first == "lib_name") + { + phy.lib_name = val.second; + } + else if (val.first == "firmware_path") + { + phy.firmware = val.second; + } + else if (val.first == "config_file") + { + phy.config_file = val.second; + } + else if (val.first == "sai_init_config_file") + { + phy.sai_init_config_file = val.second; + } + else if (val.first == "phy_access") + { + phy.access = val.second; + } + else if (val.first == "address") + { + phy.address = std::stoi(val.second); + } + else if (val.first == "bus_id") + { + phy.bus_id = std::stoi(val.second); + } + } + gearboxPhyMap[phy.phy_id] = phy; + } + } + + return gearboxPhyMap; +} + +std::map GearboxUtils::loadInterfaceMap(Table *gearboxTable) +{ + std::vector ovalues; + std::tuple keyt; + std::vector keys; + + SWSS_LOG_ENTER(); + + gearboxTable->getKeys(keys); + + if (keys.empty()) + { + SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); + return gearboxInterfaceMap; + } + + for (auto &k : keys) + { + keyt = parseGearboxKey(k); + + if (std::get<0>(keyt).compare("interface") == 0) + { + gearbox_interface_t interface = {}; + + gearboxTable->get(k, ovalues); + for (auto &val : ovalues) + { + if (val.first == "index") + { + interface.index = std::stoi(val.second); + SWSS_LOG_DEBUG("BOX interface = %d", interface.index); + } + else if (val.first == "phy_id") + { + interface.phy_id = std::stoi(val.second); + SWSS_LOG_DEBUG("BOX phy_id = %d", interface.phy_id); + } + else if (val.first == "line_lanes") + { + std::stringstream ss(val.second); + + for (int i; ss >> i;) + { + SWSS_LOG_DEBUG("Parsed key:%s, val:%s,inserted %d", val.first.c_str(), val.second.c_str(), i); + interface.line_lanes.insert(i); + if (ss.peek() == ',') + { + ss.ignore(); + } + } + } + else if (val.first == "system_lanes") + { + std::stringstream ss(val.second); + + for (int i; ss >> i;) + { + SWSS_LOG_DEBUG("Parsed key:%s, val:%s,inserted %d", val.first.c_str(), val.second.c_str(), i); + interface.system_lanes.insert(i); + if (ss.peek() == ',') + { + ss.ignore(); + } + } + } + } + gearboxInterfaceMap[interface.index] = interface; + } + } + + return gearboxInterfaceMap; +} + +std::map GearboxUtils::loadLaneMap(Table *gearboxTable) +{ + std::vector ovalues; + std::tuple keyt; + std::vector keys; + + SWSS_LOG_ENTER(); + + gearboxTable->getKeys(keys); + + if (keys.empty()) + { + SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); + return gearboxLaneMap; + } + + for (auto &k : keys) + { + keyt = parseGearboxKey(k); + + if (std::get<0>(keyt).compare("lanes") == 0) + { + gearbox_lane_t lane = {}; + + gearboxTable->get(k, ovalues); + for (auto &val : ovalues) + { + if (val.first == "index") + { + lane.index = std::stoi(val.second); + } + else if (val.first == "tx_polarity") + { + lane.tx_polarity = std::stoi(val.second); + } + else if (val.first == "rx_polarity") + { + lane.rx_polarity = std::stoi(val.second); + } + else if (val.first == "line_tx_lanemap") + { + lane.line_tx_lanemap = std::stoi(val.second); + } + else if (val.first == "line_rx_lanemap") + { + lane.line_rx_lanemap = std::stoi(val.second); + } + else if (val.first == "line_to_system_lanemap") + { + lane.line_to_system_lanemap = std::stoi(val.second); + } + else if (val.first == "mdio_addr") + { + lane.mdio_addr = val.second; + } + else if (val.first == "system_side") + { + lane.system_side = (val.second == "true") ? true : false; + } + } + gearboxLaneMap[lane.index] = lane; + } + } + + return gearboxLaneMap; +} + +std::map GearboxUtils::loadPortMap(Table *gearboxTable) +{ + std::vector ovalues; + std::tuple keyt; + std::vector keys; + + SWSS_LOG_ENTER(); + + gearboxTable->getKeys(keys); + + if (keys.empty()) + { + SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); + return gearboxPortMap; + } + + for (auto &k : keys) + { + keyt = parseGearboxKey(k); + + if (std::get<0>(keyt).compare("ports") == 0) + { + gearbox_port_t port = {}; + + gearboxTable->get(k, ovalues); + for (auto &val : ovalues) + { + if (val.first == "index") + { + port.index = std::stoi(val.second); + } + else if (val.first == "mdio_addr") + { + port.mdio_addr = val.second; + } + else if (val.first == "system_speed") + { + port.system_speed = std::stoi(val.second); + } + else if (val.first == "system_fec") + { + port.system_fec = val.second; + } + else if (val.first == "system_auto_neg") + { + port.system_auto_neg = (val.second == "true") ? true : false; + } + else if (val.first == "system_loopback") + { + port.system_loopback = val.second; + } + else if (val.first == "system_training") + { + port.system_training = (val.second == "true") ? true : false; + } + else if (val.first == "line_speed") + { + port.line_speed = std::stoi(val.second); + } + else if (val.first == "line_fec") + { + port.line_fec = val.second; + } + else if (val.first == "line_auto_neg") + { + port.line_auto_neg = (val.second == "true") ? true : false; + } + else if (val.first == "line_media_type") + { + port.line_media_type = val.second; + } + else if (val.first == "line_intf_type") + { + port.line_intf_type = val.second; + } + else if (val.first == "line_loopback") + { + port.line_loopback = val.second; + } + else if (val.first == "line_training") + { + port.line_training = (val.second == "true") ? true : false; + } + else if (val.first == "line_adver_speed") + { + std::stringstream ss(val.second); + for (int i; ss >> i;) + { + port.line_adver_speed.insert(i); + if (ss.peek() == ',') + { + ss.ignore(); + } + } + } + else if (val.first == "line_adver_fec") + { + std::stringstream ss(val.second); + for (int i; ss >> i;) + { + port.line_adver_fec.insert(i); + if (ss.peek() == ',') + { + ss.ignore(); + } + } + } + else if (val.first == "line_adver_auto_neg") + { + port.line_adver_auto_neg = (val.second == "true") ? true : false; + } + else if (val.first == "line_adver_asym_pause") + { + port.line_adver_asym_pause = (val.second == "true") ? true : false; + } + else if (val.first == "line_adver_media_type") + { + port.line_adver_media_type = val.second; + } + } + gearboxPortMap[port.index] = port; + } + } + + return gearboxPortMap; +} + +} diff --git a/common/gearboxutils.h b/common/gearboxutils.h new file mode 100644 index 000000000..99769be54 --- /dev/null +++ b/common/gearboxutils.h @@ -0,0 +1,111 @@ +/* + * Copyright 2019-2020 Broadcom Inc. + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +#ifndef SWSS_COMMON_GEARBOX_UTILS_H +#define SWSS_COMMON_GEARBOX_UTILS_H + +#include +#include +#include +#include +#include +#include +#include + +#include "tokenize.h" +#include "table.h" + +namespace swss { + +typedef struct +{ + int phy_id; + std::string phy_oid; + std::string name; + std::string lib_name; + std::string firmware; + std::string sai_init_config_file; + std::string config_file; + std::string access; + uint32_t address; + uint32_t bus_id; +} gearbox_phy_t; + +typedef struct +{ + int index; + int phy_id; + std::set line_lanes; + std::set system_lanes; +} gearbox_interface_t; + +typedef struct +{ + int index; + bool system_side; + int tx_polarity; + int rx_polarity; + int line_tx_lanemap; + int line_rx_lanemap; + int line_to_system_lanemap; + std::string mdio_addr; +} gearbox_lane_t; + +typedef struct +{ + int index; + std::string mdio_addr; + int system_speed; + std::string system_fec; + bool system_auto_neg; + std::string system_loopback; + bool system_training; + int line_speed; + std::string line_fec; + bool line_auto_neg; + std::string line_media_type; + std::string line_intf_type; + std::string line_loopback; + bool line_training; + std::set line_adver_speed; + std::set line_adver_fec; + bool line_adver_auto_neg; + bool line_adver_asym_pause; + std::string line_adver_media_type; +} gearbox_port_t; + +class GearboxUtils +{ + private: + std::map gearboxPhyMap; + std::map gearboxInterfaceMap; + std::map gearboxLaneMap; + std::map gearboxPortMap; + std::tuple parseGearboxKey(std::string key_str); + public: + bool platformHasGearbox(); + bool isGearboxConfigDone(Table &gearboxTable); + bool isGearboxConfigDone(Table *gearboxTable); + bool isGearboxEnabled(Table *gearboxTable); + std::map loadPhyMap(Table *gearboxTable); + std::map loadInterfaceMap(Table *gearboxTable); + std::map loadLaneMap(Table *gearboxTable); + std::map loadPortMap(Table *gearboxTable); +}; + +} + +#endif /* SWSS_COMMON_GEARBOX_UTILS_H */ diff --git a/common/schema.h b/common/schema.h index fde31c72e..c1ad4f306 100644 --- a/common/schema.h +++ b/common/schema.h @@ -14,10 +14,15 @@ namespace swss { #define FLEX_COUNTER_DB 5 #define STATE_DB 6 #define SNMP_OVERLAY_DB 7 +#define ASIC_DB2 8 +#define COUNTERS_DB2 9 +#define FLEX_COUNTER_DB2 10 +#define STATE_DB2 11 /***** APPLICATION DATABASE *****/ #define APP_PORT_TABLE_NAME "PORT_TABLE" +#define APP_GEARBOX_TABLE_NAME "GEARBOX_TABLE" #define APP_VLAN_TABLE_NAME "VLAN_TABLE" #define APP_VLAN_MEMBER_TABLE_NAME "VLAN_MEMBER_TABLE" #define APP_LAG_TABLE_NAME "LAG_TABLE" @@ -152,6 +157,8 @@ namespace swss { #define CFG_PORT_TABLE_NAME "PORT" #define CFG_PORT_CABLE_LEN_TABLE_NAME "CABLE_LENGTH" +#define CFG_GEARBOX_TABLE_NAME "GEARBOX" + #define CFG_INTF_TABLE_NAME "INTERFACE" #define CFG_LOOPBACK_INTERFACE_TABLE_NAME "LOOPBACK_INTERFACE" #define CFG_MGMT_INTERFACE_TABLE_NAME "MGMT_INTERFACE" diff --git a/common/table.cpp b/common/table.cpp index b8f5797f9..8eee0fbfa 100644 --- a/common/table.cpp +++ b/common/table.cpp @@ -19,14 +19,18 @@ const std::string TableBase::TABLE_NAME_SEPARATOR_COLON = ":"; const std::string TableBase::TABLE_NAME_SEPARATOR_VBAR = "|"; const TableNameSeparatorMap TableBase::tableNameSeparatorMap = { - { APPL_DB, TABLE_NAME_SEPARATOR_COLON }, - { ASIC_DB, TABLE_NAME_SEPARATOR_COLON }, - { COUNTERS_DB, TABLE_NAME_SEPARATOR_COLON }, - { LOGLEVEL_DB, TABLE_NAME_SEPARATOR_COLON }, - { CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR }, - { PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON }, - { FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON }, - { STATE_DB, TABLE_NAME_SEPARATOR_VBAR } + { APPL_DB, TABLE_NAME_SEPARATOR_COLON }, + { ASIC_DB, TABLE_NAME_SEPARATOR_COLON }, + { COUNTERS_DB, TABLE_NAME_SEPARATOR_COLON }, + { LOGLEVEL_DB, TABLE_NAME_SEPARATOR_COLON }, + { CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR }, + { PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON }, + { FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON }, + { STATE_DB, TABLE_NAME_SEPARATOR_VBAR }, + { ASIC_DB2, TABLE_NAME_SEPARATOR_VBAR }, + { COUNTERS_DB2, TABLE_NAME_SEPARATOR_VBAR }, + { FLEX_COUNTER_DB2, TABLE_NAME_SEPARATOR_VBAR }, + { STATE_DB2, TABLE_NAME_SEPARATOR_VBAR } }; Table::Table(const DBConnector *db, const string &tableName) From c7bec863713c0a8932adcbb5bb5e59cfca406f00 Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Thu, 4 Jun 2020 14:10:54 -0700 Subject: [PATCH 2/6] Add firmware_major_version to gearbox_phy_t --- common/gearboxutils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/gearboxutils.h b/common/gearboxutils.h index 99769be54..e8ffc85c9 100644 --- a/common/gearboxutils.h +++ b/common/gearboxutils.h @@ -37,6 +37,7 @@ typedef struct std::string name; std::string lib_name; std::string firmware; + std::string firmware_major_version; std::string sai_init_config_file; std::string config_file; std::string access; From 7ccec8b486580bbda4072ce2fd59fcf99a1cd8b4 Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Thu, 11 Jun 2020 10:21:10 -0700 Subject: [PATCH 3/6] remove gearboxutils, will be relocated into swss --- common/Makefile.am | 1 - common/gearboxutils.cpp | 459 ---------------------------------------- common/gearboxutils.h | 112 ---------- 3 files changed, 572 deletions(-) delete mode 100644 common/gearboxutils.cpp delete mode 100644 common/gearboxutils.h diff --git a/common/Makefile.am b/common/Makefile.am index 6e34b8b33..a6231cb57 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -53,7 +53,6 @@ libswsscommon_la_SOURCES = \ notificationconsumer.cpp \ notificationproducer.cpp \ linkcache.cpp \ - gearboxutils.cpp \ portmap.cpp \ tokenize.cpp \ exec.cpp \ diff --git a/common/gearboxutils.cpp b/common/gearboxutils.cpp deleted file mode 100644 index bcdd9e289..000000000 --- a/common/gearboxutils.cpp +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright 2019-2020 Broadcom Inc. - * - * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#include "gearboxutils.h" - -namespace swss { - -std::tuple GearboxUtils::parseGearboxKey(std::string key_str) -{ - /* - * The Gearbox key string has a few formats based on the number of tokens. - * Parse and return accordingly; - * phy::ports: rtn: ports - * phy::lanes: rtn: lanes - * phy: rtn: phy - * interface: rtn: interface - */ - - std::string str1, str2, str3; - std::vector token = tokenize(key_str, ':'); - - if (token.size() == 4) - { - str1 = token.at(2); - str2 = token.at(1); - str3 = token.at(3); - } - else if (token.size() == 2) - { - str1 = token.at(0); - str2 = token.at(1); - } - - SWSS_LOG_DEBUG("Parsed key:%s, Return:(%s)(%s)(%s)", key_str.c_str(), str1.c_str(), str2.c_str(), str3.c_str()); - - return make_tuple(str1, str2, str3); -} - -bool GearboxUtils::platformHasGearbox() -{ - bool ret = false; - - if (access("/usr/share/sonic/hwsku/gearbox_config.json", F_OK) != -1) - { - ret = true; - } - return ret; -} - -bool GearboxUtils::isGearboxConfigDone(Table &gearboxTable) -{ - std::vector tuples; - bool gearboxConfigDone = false; - - // this will return false if GearboxConfigDone is not set in the database - - gearboxConfigDone = gearboxTable.get("GearboxConfigDone", tuples); - return gearboxConfigDone; -} - -bool GearboxUtils::isGearboxConfigDone(Table *gearboxTable) -{ - std::vector tuples; - bool gearboxConfigDone = false; - - // this will return false if GearboxConfigDone is not set in the database - - gearboxConfigDone = gearboxTable->get("GearboxConfigDone", tuples); - return gearboxConfigDone; -} - -bool GearboxUtils::isGearboxEnabled(Table *gearboxTable) -{ - int count = 10; // 10 seconds is more than enough time - bool gearboxDone = false; - - SWSS_LOG_ENTER(); - - if (platformHasGearbox() != true) - { - return gearboxDone; - } - - // wait until gearbox table is ready - while (count > 0) - { - if (!isGearboxConfigDone(gearboxTable)) - { - sleep(1); - count--; - continue; - } - else - { - gearboxDone = true; - break; - } - } - - return gearboxDone; -} - -std::map GearboxUtils::loadPhyMap(Table *gearboxTable) -{ - std::vector ovalues; - std::tuple keyt; - std::vector keys; - - SWSS_LOG_ENTER(); - - gearboxTable->getKeys(keys); - - if (keys.empty()) - { - SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); - return gearboxPhyMap; - } - - for (auto &k : keys) - { - keyt = parseGearboxKey(k); - - if (std::get<0>(keyt).compare("phy") == 0) - { - gearbox_phy_t phy = {}; - - gearboxTable->get(k, ovalues); - for (auto &val : ovalues) - { - if (val.first == "phy_id") - { - phy.phy_id = std::stoi(val.second); - } - else if (val.first == "phy_oid") - { - // oid is from create_switch (not config) - phy.phy_oid = val.second; - } - else if (val.first == "name") - { - phy.name = val.second; - } - else if (val.first == "lib_name") - { - phy.lib_name = val.second; - } - else if (val.first == "firmware_path") - { - phy.firmware = val.second; - } - else if (val.first == "config_file") - { - phy.config_file = val.second; - } - else if (val.first == "sai_init_config_file") - { - phy.sai_init_config_file = val.second; - } - else if (val.first == "phy_access") - { - phy.access = val.second; - } - else if (val.first == "address") - { - phy.address = std::stoi(val.second); - } - else if (val.first == "bus_id") - { - phy.bus_id = std::stoi(val.second); - } - } - gearboxPhyMap[phy.phy_id] = phy; - } - } - - return gearboxPhyMap; -} - -std::map GearboxUtils::loadInterfaceMap(Table *gearboxTable) -{ - std::vector ovalues; - std::tuple keyt; - std::vector keys; - - SWSS_LOG_ENTER(); - - gearboxTable->getKeys(keys); - - if (keys.empty()) - { - SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); - return gearboxInterfaceMap; - } - - for (auto &k : keys) - { - keyt = parseGearboxKey(k); - - if (std::get<0>(keyt).compare("interface") == 0) - { - gearbox_interface_t interface = {}; - - gearboxTable->get(k, ovalues); - for (auto &val : ovalues) - { - if (val.first == "index") - { - interface.index = std::stoi(val.second); - SWSS_LOG_DEBUG("BOX interface = %d", interface.index); - } - else if (val.first == "phy_id") - { - interface.phy_id = std::stoi(val.second); - SWSS_LOG_DEBUG("BOX phy_id = %d", interface.phy_id); - } - else if (val.first == "line_lanes") - { - std::stringstream ss(val.second); - - for (int i; ss >> i;) - { - SWSS_LOG_DEBUG("Parsed key:%s, val:%s,inserted %d", val.first.c_str(), val.second.c_str(), i); - interface.line_lanes.insert(i); - if (ss.peek() == ',') - { - ss.ignore(); - } - } - } - else if (val.first == "system_lanes") - { - std::stringstream ss(val.second); - - for (int i; ss >> i;) - { - SWSS_LOG_DEBUG("Parsed key:%s, val:%s,inserted %d", val.first.c_str(), val.second.c_str(), i); - interface.system_lanes.insert(i); - if (ss.peek() == ',') - { - ss.ignore(); - } - } - } - } - gearboxInterfaceMap[interface.index] = interface; - } - } - - return gearboxInterfaceMap; -} - -std::map GearboxUtils::loadLaneMap(Table *gearboxTable) -{ - std::vector ovalues; - std::tuple keyt; - std::vector keys; - - SWSS_LOG_ENTER(); - - gearboxTable->getKeys(keys); - - if (keys.empty()) - { - SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); - return gearboxLaneMap; - } - - for (auto &k : keys) - { - keyt = parseGearboxKey(k); - - if (std::get<0>(keyt).compare("lanes") == 0) - { - gearbox_lane_t lane = {}; - - gearboxTable->get(k, ovalues); - for (auto &val : ovalues) - { - if (val.first == "index") - { - lane.index = std::stoi(val.second); - } - else if (val.first == "tx_polarity") - { - lane.tx_polarity = std::stoi(val.second); - } - else if (val.first == "rx_polarity") - { - lane.rx_polarity = std::stoi(val.second); - } - else if (val.first == "line_tx_lanemap") - { - lane.line_tx_lanemap = std::stoi(val.second); - } - else if (val.first == "line_rx_lanemap") - { - lane.line_rx_lanemap = std::stoi(val.second); - } - else if (val.first == "line_to_system_lanemap") - { - lane.line_to_system_lanemap = std::stoi(val.second); - } - else if (val.first == "mdio_addr") - { - lane.mdio_addr = val.second; - } - else if (val.first == "system_side") - { - lane.system_side = (val.second == "true") ? true : false; - } - } - gearboxLaneMap[lane.index] = lane; - } - } - - return gearboxLaneMap; -} - -std::map GearboxUtils::loadPortMap(Table *gearboxTable) -{ - std::vector ovalues; - std::tuple keyt; - std::vector keys; - - SWSS_LOG_ENTER(); - - gearboxTable->getKeys(keys); - - if (keys.empty()) - { - SWSS_LOG_ERROR("No Gearbox records in ApplDB!"); - return gearboxPortMap; - } - - for (auto &k : keys) - { - keyt = parseGearboxKey(k); - - if (std::get<0>(keyt).compare("ports") == 0) - { - gearbox_port_t port = {}; - - gearboxTable->get(k, ovalues); - for (auto &val : ovalues) - { - if (val.first == "index") - { - port.index = std::stoi(val.second); - } - else if (val.first == "mdio_addr") - { - port.mdio_addr = val.second; - } - else if (val.first == "system_speed") - { - port.system_speed = std::stoi(val.second); - } - else if (val.first == "system_fec") - { - port.system_fec = val.second; - } - else if (val.first == "system_auto_neg") - { - port.system_auto_neg = (val.second == "true") ? true : false; - } - else if (val.first == "system_loopback") - { - port.system_loopback = val.second; - } - else if (val.first == "system_training") - { - port.system_training = (val.second == "true") ? true : false; - } - else if (val.first == "line_speed") - { - port.line_speed = std::stoi(val.second); - } - else if (val.first == "line_fec") - { - port.line_fec = val.second; - } - else if (val.first == "line_auto_neg") - { - port.line_auto_neg = (val.second == "true") ? true : false; - } - else if (val.first == "line_media_type") - { - port.line_media_type = val.second; - } - else if (val.first == "line_intf_type") - { - port.line_intf_type = val.second; - } - else if (val.first == "line_loopback") - { - port.line_loopback = val.second; - } - else if (val.first == "line_training") - { - port.line_training = (val.second == "true") ? true : false; - } - else if (val.first == "line_adver_speed") - { - std::stringstream ss(val.second); - for (int i; ss >> i;) - { - port.line_adver_speed.insert(i); - if (ss.peek() == ',') - { - ss.ignore(); - } - } - } - else if (val.first == "line_adver_fec") - { - std::stringstream ss(val.second); - for (int i; ss >> i;) - { - port.line_adver_fec.insert(i); - if (ss.peek() == ',') - { - ss.ignore(); - } - } - } - else if (val.first == "line_adver_auto_neg") - { - port.line_adver_auto_neg = (val.second == "true") ? true : false; - } - else if (val.first == "line_adver_asym_pause") - { - port.line_adver_asym_pause = (val.second == "true") ? true : false; - } - else if (val.first == "line_adver_media_type") - { - port.line_adver_media_type = val.second; - } - } - gearboxPortMap[port.index] = port; - } - } - - return gearboxPortMap; -} - -} diff --git a/common/gearboxutils.h b/common/gearboxutils.h deleted file mode 100644 index e8ffc85c9..000000000 --- a/common/gearboxutils.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2019-2020 Broadcom Inc. - * - * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ - -#ifndef SWSS_COMMON_GEARBOX_UTILS_H -#define SWSS_COMMON_GEARBOX_UTILS_H - -#include -#include -#include -#include -#include -#include -#include - -#include "tokenize.h" -#include "table.h" - -namespace swss { - -typedef struct -{ - int phy_id; - std::string phy_oid; - std::string name; - std::string lib_name; - std::string firmware; - std::string firmware_major_version; - std::string sai_init_config_file; - std::string config_file; - std::string access; - uint32_t address; - uint32_t bus_id; -} gearbox_phy_t; - -typedef struct -{ - int index; - int phy_id; - std::set line_lanes; - std::set system_lanes; -} gearbox_interface_t; - -typedef struct -{ - int index; - bool system_side; - int tx_polarity; - int rx_polarity; - int line_tx_lanemap; - int line_rx_lanemap; - int line_to_system_lanemap; - std::string mdio_addr; -} gearbox_lane_t; - -typedef struct -{ - int index; - std::string mdio_addr; - int system_speed; - std::string system_fec; - bool system_auto_neg; - std::string system_loopback; - bool system_training; - int line_speed; - std::string line_fec; - bool line_auto_neg; - std::string line_media_type; - std::string line_intf_type; - std::string line_loopback; - bool line_training; - std::set line_adver_speed; - std::set line_adver_fec; - bool line_adver_auto_neg; - bool line_adver_asym_pause; - std::string line_adver_media_type; -} gearbox_port_t; - -class GearboxUtils -{ - private: - std::map gearboxPhyMap; - std::map gearboxInterfaceMap; - std::map gearboxLaneMap; - std::map gearboxPortMap; - std::tuple parseGearboxKey(std::string key_str); - public: - bool platformHasGearbox(); - bool isGearboxConfigDone(Table &gearboxTable); - bool isGearboxConfigDone(Table *gearboxTable); - bool isGearboxEnabled(Table *gearboxTable); - std::map loadPhyMap(Table *gearboxTable); - std::map loadInterfaceMap(Table *gearboxTable); - std::map loadLaneMap(Table *gearboxTable); - std::map loadPortMap(Table *gearboxTable); -}; - -} - -#endif /* SWSS_COMMON_GEARBOX_UTILS_H */ From ba5cfe38ec8eea7837176f906ade0f63d2e915e1 Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Fri, 12 Jun 2020 11:04:17 -0700 Subject: [PATCH 4/6] add entries, needed by sairedis tests --- common/database_config.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common/database_config.json b/common/database_config.json index b86ae11bb..3d8350a9f 100644 --- a/common/database_config.json +++ b/common/database_config.json @@ -51,6 +51,26 @@ "id" : 7, "separator": "|", "instance" : "redis" + }, + "ASIC_DB2" : { + "id" : 8, + "separator": "|", + "instance" : "redis" + }, + "COUNTERS_DB2" : { + "id" : 9, + "separator": "|", + "instance" : "redis" + }, + "FLEX_COUNTER_DB2" : { + "id" : 10, + "separator": "|", + "instance" : "redis" + }, + "STATE_DB2" : { + "id" : 11, + "separator": "|", + "instance" : "redis" } }, "VERSION" : "1.0" From a9d5f9fde28529ca88daad688e6d602e380d42ae Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Mon, 15 Jun 2020 21:07:29 -0700 Subject: [PATCH 5/6] rename Gearbox database tables, e,g. ASIC_DB2 --> GB_ASIC_TABLE, and remove STATE_DB2 --- common/database_config.json | 15 +++++++++++++++ common/schema.h | 7 +++---- common/table.cpp | 23 +++++++++++------------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/common/database_config.json b/common/database_config.json index 3d8350a9f..2a17c1a23 100644 --- a/common/database_config.json +++ b/common/database_config.json @@ -71,6 +71,21 @@ "id" : 11, "separator": "|", "instance" : "redis" + }, + "GB_ASIC_DB" : { + "id" : 8, + "separator": "|", + "instance" : "redis" + }, + "GB_COUNTERS_DB" : { + "id" : 9, + "separator": "|", + "instance" : "redis" + }, + "GB_FLEX_COUNTER_DB" : { + "id" : 10, + "separator": "|", + "instance" : "redis" } }, "VERSION" : "1.0" diff --git a/common/schema.h b/common/schema.h index c1ad4f306..7ce14e62e 100644 --- a/common/schema.h +++ b/common/schema.h @@ -14,10 +14,9 @@ namespace swss { #define FLEX_COUNTER_DB 5 #define STATE_DB 6 #define SNMP_OVERLAY_DB 7 -#define ASIC_DB2 8 -#define COUNTERS_DB2 9 -#define FLEX_COUNTER_DB2 10 -#define STATE_DB2 11 +#define GB_ASIC_DB 8 +#define GB_COUNTERS_DB 9 +#define GB_FLEX_COUNTER_DB 10 /***** APPLICATION DATABASE *****/ diff --git a/common/table.cpp b/common/table.cpp index 8eee0fbfa..7f4b11b7e 100644 --- a/common/table.cpp +++ b/common/table.cpp @@ -19,18 +19,17 @@ const std::string TableBase::TABLE_NAME_SEPARATOR_COLON = ":"; const std::string TableBase::TABLE_NAME_SEPARATOR_VBAR = "|"; const TableNameSeparatorMap TableBase::tableNameSeparatorMap = { - { APPL_DB, TABLE_NAME_SEPARATOR_COLON }, - { ASIC_DB, TABLE_NAME_SEPARATOR_COLON }, - { COUNTERS_DB, TABLE_NAME_SEPARATOR_COLON }, - { LOGLEVEL_DB, TABLE_NAME_SEPARATOR_COLON }, - { CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR }, - { PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON }, - { FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON }, - { STATE_DB, TABLE_NAME_SEPARATOR_VBAR }, - { ASIC_DB2, TABLE_NAME_SEPARATOR_VBAR }, - { COUNTERS_DB2, TABLE_NAME_SEPARATOR_VBAR }, - { FLEX_COUNTER_DB2, TABLE_NAME_SEPARATOR_VBAR }, - { STATE_DB2, TABLE_NAME_SEPARATOR_VBAR } + { APPL_DB, TABLE_NAME_SEPARATOR_COLON }, + { ASIC_DB, TABLE_NAME_SEPARATOR_COLON }, + { COUNTERS_DB, TABLE_NAME_SEPARATOR_COLON }, + { LOGLEVEL_DB, TABLE_NAME_SEPARATOR_COLON }, + { CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR }, + { PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON }, + { FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON }, + { STATE_DB, TABLE_NAME_SEPARATOR_VBAR }, + { GB_ASIC_DB, TABLE_NAME_SEPARATOR_VBAR }, + { GB_COUNTERS_DB, TABLE_NAME_SEPARATOR_VBAR }, + { GB_FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_VBAR } }; Table::Table(const DBConnector *db, const string &tableName) From 648b48faafdfecdbec3b80ea10c5191176fd1e4e Mon Sep 17 00:00:00 2001 From: Syd Logan Date: Mon, 15 Jun 2020 21:10:26 -0700 Subject: [PATCH 6/6] fix typo in database_config.js --- common/database_config.json | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/common/database_config.json b/common/database_config.json index 2a17c1a23..b65d0e794 100644 --- a/common/database_config.json +++ b/common/database_config.json @@ -52,26 +52,6 @@ "separator": "|", "instance" : "redis" }, - "ASIC_DB2" : { - "id" : 8, - "separator": "|", - "instance" : "redis" - }, - "COUNTERS_DB2" : { - "id" : 9, - "separator": "|", - "instance" : "redis" - }, - "FLEX_COUNTER_DB2" : { - "id" : 10, - "separator": "|", - "instance" : "redis" - }, - "STATE_DB2" : { - "id" : 11, - "separator": "|", - "instance" : "redis" - }, "GB_ASIC_DB" : { "id" : 8, "separator": "|",