-
Notifications
You must be signed in to change notification settings - Fork 689
[swss] Add support for gearbox phys #1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5102d3e
swss: Add support to swss for gearbox phys
slogan621 44b34de
bring in schema.h for table name definitions
slogan621 11b1e76
fixes to confirm to coding standard - braces, indentation
slogan621 782e685
fix a few braces/indents
slogan621 cd4d09e
replace ifdef guards with #pragma once
slogan621 f7b5939
remove placeholder while loop in gearsyncd
slogan621 a895347
remove cunit sources, Makefile.am for gearsyncd tests
slogan621 7fa6cb0
clean up tabs in a few files
slogan621 44da115
return SAI_STATUS_NOT_IMPLEMENTED for mdio_read/write
slogan621 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| INCLUDES = -I $(top_srcdir)/lib -I $(top_srcdir) -I $(top_srcdir)/warmrestart -I $(top_srcdir)/cfgmgr | ||
|
|
||
| bin_PROGRAMS = gearsyncd | ||
|
|
||
| if DEBUG | ||
| DBGFLAGS = -ggdb -DDEBUG | ||
| else | ||
| DBGFLAGS = -g | ||
| endif | ||
|
|
||
| gearsyncd_SOURCES = $(top_srcdir)/lib/gearboxutils.cpp gearsyncd.cpp gearparserbase.cpp gearboxparser.cpp phyparser.cpp $(top_srcdir)/cfgmgr/shellcmd.h | ||
|
|
||
| gearsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) $(ASAN_CFLAGS) | ||
|
|
||
| gearsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS) $(ASAN_LDFLAGS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,285 @@ | ||
| /* | ||
| * 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 "gearboxparser.h" | ||
| #include "phyparser.h" | ||
| #include <vector> | ||
|
|
||
| void GearboxParser::notifyGearboxConfigDone(bool success) | ||
| { | ||
| swss::ProducerStateTable *p = getProducerStateTable().get(); | ||
|
|
||
| swss::FieldValueTuple finish_notice("success", std::to_string(success)); | ||
| std::vector<swss::FieldValueTuple> attrs = { finish_notice }; | ||
|
|
||
| p->set("GearboxConfigDone", attrs); | ||
| } | ||
|
|
||
| bool GearboxParser::parse() | ||
| { | ||
| json root; | ||
|
|
||
| try | ||
| { | ||
| root = getJSONRoot(); | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| SWSS_LOG_ERROR("JSON root not parseable"); | ||
| return false; | ||
| } | ||
|
|
||
| json phys, phy, interfaces, interface, val, lanes; | ||
|
|
||
| std::vector<swss::FieldValueTuple> attrs; | ||
|
|
||
| try | ||
| { | ||
| phys = root["phys"]; | ||
| if (phys.size() == 0) | ||
| { | ||
| SWSS_LOG_ERROR("zero-sized 'phys' field in gearbox configuration"); | ||
| return false; | ||
| } | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| SWSS_LOG_ERROR("unable to read gearbox configuration (invalid format)"); | ||
| return false; | ||
| } | ||
|
|
||
| for (uint32_t iter = 0; iter < phys.size(); iter++) | ||
| { | ||
| phy = phys[iter]; | ||
| try { | ||
sydlogan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| attrs.clear(); | ||
| swss::FieldValueTuple attr; | ||
| if (phy.find("phy_id") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'phy_id' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["phy_id"]; | ||
| int phyId = val.get<int>(); | ||
| attr = std::make_pair("phy_id", std::to_string(phyId)); | ||
| attrs.push_back(attr); | ||
| if (phy.find("name") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'name' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["name"]; | ||
| std::string name(val.get<std::string>()); | ||
| attr = std::make_pair("name", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
| if (phy.find("address") == phy.end()) { | ||
| SWSS_LOG_ERROR("missing 'address' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["address"]; | ||
| attr = std::make_pair("address", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
| if (phy.find("lib_name") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'lib_name' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["lib_name"]; | ||
| attr = std::make_pair("lib_name", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
| if (phy.find("firmware_path") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'firmware_path' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["firmware_path"]; | ||
| attr = std::make_pair("firmware_path", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
| if (phy.find("config_file") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'config_file' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["config_file"]; | ||
| std::string cfgFile(val.get<std::string>()); | ||
| attr = std::make_pair("config_file", cfgFile); | ||
| attrs.push_back(attr); | ||
| if (phy.find("sai_init_config_file") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'sai_init_config_file' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["sai_init_config_file"]; | ||
| std::string bcmCfgFile(std::string(val.get<std::string>())); | ||
| attr = std::make_pair("sai_init_config_file", bcmCfgFile); | ||
| attrs.push_back(attr); | ||
| if (phy.find("phy_access") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'phy_access' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["phy_access"]; | ||
| attr = std::make_pair("phy_access", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
| if (phy.find("bus_id") == phy.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'bus_id' field in 'phys' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = phy["bus_id"]; | ||
| attr = std::make_pair("bus_id", std::to_string(val.get<int>())); | ||
| attrs.push_back(attr); | ||
| std::string key; | ||
| key = "phy:" + std::to_string(phyId); | ||
| if (getWriteToDb() == true) | ||
| { | ||
| writeToDb(key, attrs); | ||
| } | ||
| PhyParser p; | ||
| p.setPhyId(phyId); | ||
| p.setWriteToDb(getWriteToDb()); | ||
| p.setConfigPath(cfgFile); | ||
| if (p.parse() == false) | ||
| { | ||
| SWSS_LOG_ERROR("phy parser failed to parse item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| SWSS_LOG_ERROR("unable to read 'phys' item %d in gearbox configuration (invalid format)", iter); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (root.find("interfaces") != root.end()) | ||
| { | ||
| interfaces = root["interfaces"]; // vec | ||
| if (interfaces.size() == 0) | ||
| { | ||
| SWSS_LOG_ERROR("zero-sized 'interfaces' field in gearbox configuration"); | ||
| return false; | ||
| } | ||
| for (uint32_t iter = 0; iter < interfaces.size(); iter++) | ||
| { | ||
| attrs.clear(); | ||
| interface = interfaces[iter]; | ||
| try | ||
| { | ||
| swss::FieldValueTuple attr; | ||
|
|
||
| if (interface.find("name") == interface.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'name' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = interface["name"]; | ||
| attr = std::make_pair("name", std::string(val.get<std::string>())); | ||
| attrs.push_back(attr); | ||
|
|
||
| if (interface.find("index") == interface.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'index' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = interface["index"]; | ||
| int index = val.get<int>(); | ||
| attr = std::make_pair("index", std::to_string(index)); | ||
| attrs.push_back(attr); | ||
|
|
||
| if (interface.find("phy_id") == interface.end()) | ||
| { | ||
| SWSS_LOG_ERROR("missing 'phy_id' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| val = interface["phy_id"]; | ||
| attr = std::make_pair("phy_id", std::to_string(val.get<int>())); | ||
| attrs.push_back(attr); | ||
|
|
||
| if (interface.find("system_lanes") != interface.end()) | ||
| { | ||
| lanes = interface["system_lanes"]; // vec | ||
| std::string laneStr(""); | ||
| if (lanes.size() == 0) | ||
| { | ||
| SWSS_LOG_ERROR("zero-sized 'system_lanes' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| for (uint32_t iter2 = 0; iter2 < lanes.size(); iter2++) | ||
| { | ||
| val = lanes[iter2]; | ||
| if (laneStr.length() > 0) | ||
| { | ||
| laneStr += ","; | ||
| } | ||
| laneStr += std::to_string(val.get<int>()); | ||
| } | ||
| attr = std::make_pair("system_lanes", laneStr); | ||
| attrs.push_back(attr); | ||
| } | ||
| else | ||
| { | ||
| SWSS_LOG_ERROR("missing 'system_lanes' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
|
|
||
| if (interface.find("line_lanes") != interface.end()) | ||
| { | ||
| lanes = interface["line_lanes"]; // vec | ||
| std::string laneStr(""); | ||
| if (lanes.size() == 0) | ||
| { | ||
| SWSS_LOG_ERROR("zero-sized 'line_lanes' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| for (uint32_t iter2 = 0; iter2 < lanes.size(); iter2++) | ||
| { | ||
| val = lanes[iter2]; | ||
| if (laneStr.length() > 0) | ||
| { | ||
| laneStr += ","; | ||
| } | ||
| laneStr += std::to_string(val.get<int>()); | ||
| } | ||
| attr = std::make_pair("line_lanes", laneStr); | ||
| attrs.push_back(attr); | ||
| } | ||
| else | ||
| { | ||
| SWSS_LOG_ERROR("missing 'line_lanes' field in 'interfaces' item %d in gearbox configuration", iter); | ||
| return false; | ||
| } | ||
| std::string key; | ||
| key = "interface:" + std::to_string(index); | ||
| if (getWriteToDb() == true) | ||
| { | ||
| writeToDb(key, attrs); | ||
| } | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| SWSS_LOG_ERROR("unable to read 'interfaces' item %d in gearbox configuration (invalid format)", iter); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| SWSS_LOG_ERROR("unable to read 'interfaces' item in gearbox configuration"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2019 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. | ||
| */ | ||
|
|
||
| #if !defined(__GEARBOX_PARSER_H__) | ||
sydlogan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #define __GEARBOX_PARSER_H__ | ||
|
|
||
| #include "gearparserbase.h" | ||
|
|
||
| class GearboxParser: public GearParserBase | ||
| { | ||
| public: | ||
| bool parse(); | ||
| void notifyGearboxConfigDone(bool success); | ||
| }; | ||
|
|
||
| #endif /* __GEARBOX_PARSER_H__ */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.