Skip to content
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

[swss] Add support for gearbox phys #1321

Merged
merged 9 commits into from
Jul 2, 2020
Merged
3 changes: 1 addition & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd orchagent swssconfig cfgmgr tests
SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd orchagent swssconfig cfgmgr tests gearsyncd gearsyncd/tests

if HAVE_LIBTEAM
SUBDIRS += teamsyncd
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart -I $(top_srcdir)/orchagent/flex_counter
INCLUDES = -I$(top_srcdir)/lib -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart -I $(top_srcdir)/orchagent/flex_counter
CFLAGS_SAI = -I /usr/include/sai
LIBNL_CFLAGS = -I/usr/include/libnl3
LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ AC_CONFIG_FILES([
orchagent/Makefile
fpmsyncd/Makefile
neighsyncd/Makefile
gearsyncd/Makefile
gearsyncd/tests/Makefile
natsyncd/Makefile
portsyncd/Makefile
teamsyncd/Makefile
Expand Down
15 changes: 15 additions & 0 deletions gearsyncd/Makefile.am
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)
285 changes: 285 additions & 0 deletions gearsyncd/gearboxparser.cpp
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;
}
sydlogan marked this conversation as resolved.
Show resolved Hide resolved
}
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.
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;
}
29 changes: 29 additions & 0 deletions gearsyncd/gearboxparser.h
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.
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__ */
Loading