Skip to content

Commit

Permalink
If available, read port settings from Config DB first (sonic-net#723)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Moroz <c_andriym@mellanox.com>
  • Loading branch information
andriymoroz-mlnx authored and yxieca committed Jan 23, 2019
1 parent 230086b commit 7375015
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void usage()
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm);
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm);
void handleVlanIntfFile(string file);
void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map);
void checkPortInitDone(DBConnector *appl_db);
Expand Down Expand Up @@ -92,11 +92,14 @@ int main(int argc, char **argv)
netlink.dumpRequest(RTM_GETLINK);
cout << "Listen to link messages..." << endl;

if (!port_config_file.empty())
if (!handlePortConfigFromConfigDB(p, cfgDb, warm))
{
handlePortConfigFile(p, port_config_file, warm);
} else {
handlePortConfigFromConfigDB(p, cfgDb, warm);
// if port config is missing in ConfigDB
// attempt to use port_config.ini
if (!port_config_file.empty())
{
handlePortConfigFile(p, port_config_file, warm);
}
}

s.addSelectable(&netlink);
Expand Down Expand Up @@ -175,14 +178,21 @@ static void notifyPortConfigDone(ProducerStateTable &p)
p.set("PortConfigDone", attrs);
}

void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm)
{
cout << "Get port configuration from ConfigDB..." << endl;

Table table(&cfgDb, CFG_PORT_TABLE_NAME);
std::vector<FieldValueTuple> ovalues;
std::vector<string> keys;
table.getKeys(keys);

if (keys.empty())
{
cout << "No port configuration in ConfigDB" << endl;
return false;
}

for ( auto &k : keys )
{
table.get(k, ovalues);
Expand All @@ -202,6 +212,8 @@ void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo
{
notifyPortConfigDone(p);
}

return true;
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm)
Expand Down

0 comments on commit 7375015

Please sign in to comment.