Skip to content

Commit

Permalink
Remove the port_config.ini dependency from portsyncd
Browse files Browse the repository at this point in the history
portsyncd will rely on configDB port table, not from port_config.ini

port_config.ini is used when we convert minigraph to configDB, then
everything should come from configDB.

Also for the DPB feature, we are going to deprecate port_config.ini

Signed-off-by: Zhenggen Xu <zxu@linkedin.com>
  • Loading branch information
zhenggen-xu committed Oct 24, 2019
1 parent 731a8f5 commit 3796a9a
Showing 1 changed file with 7 additions and 104 deletions.
111 changes: 7 additions & 104 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ bool g_init = false;

void usage()
{
cout << "Usage: portsyncd [-p port_config.ini]" << endl;
cout << " -p port_config.ini: import port lane mapping" << endl;
cout << " use configDB data if not specified" << endl;
cout << "Usage: portsyncd" << endl;
cout << " port lane mapping is from configDB" << endl;
cout << " this program will exit if configDB does not contain that info" << endl;
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm);
Expand All @@ -50,16 +50,12 @@ int main(int argc, char **argv)
{
Logger::linkToDbNative("portsyncd");
int opt;
string port_config_file;
map<string, KeyOpFieldsValuesTuple> port_cfg_map;

while ((opt = getopt(argc, argv, "p:v:h")) != -1 )
while ((opt = getopt(argc, argv, "v:h")) != -1 )
{
switch (opt)
{
case 'p':
port_config_file.assign(optarg);
break;
case 'h':
usage();
return 1;
Expand Down Expand Up @@ -91,11 +87,9 @@ int main(int argc, char **argv)
if (!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);
}
// program will exit with failure
SWSS_LOG_THROW("ConfigDB does not have port information, existing...");
return EXIT_FAILURE;
}

LinkSync sync(&appl_db, &state_db);
Expand Down Expand Up @@ -222,97 +216,6 @@ bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo
return true;
}

void handlePortConfigFile(ProducerStateTable &p, string file, bool warm)
{
cout << "Read port configuration file..." << endl;

ifstream infile(file);
if (!infile.is_open())
{
usage();
throw runtime_error("Port configuration file not found!");
}

list<string> header = {"name", "lanes", "alias", "speed", "autoneg", "fec"};
string line;
while (getline(infile, line))
{
if (line.at(0) == '#')
{
// Take this line as column header line
istringstream iss_hdr(line.substr(1));
string hdr;

header.clear();
while (! iss_hdr.eof()) {
iss_hdr >> hdr;
cout << "Adding column header '" << hdr << "'" << endl;
header.push_back(hdr);
}

continue;
}

istringstream iss(line);
map<string, string> entry;

/* Read port configuration entry */
for (auto column : header)
{
iss >> entry[column];
}

if (!warm)
{
/* If port has no alias, then use its name as alias */
string alias;
if ((entry.find("alias") != entry.end()) && (entry["alias"] != ""))
{
alias = entry["alias"];
}
else
{
alias = entry["name"];
}

FieldValueTuple lanes_attr("lanes", entry["lanes"]);
FieldValueTuple alias_attr("alias", alias);

vector<FieldValueTuple> attrs;
attrs.push_back(lanes_attr);
attrs.push_back(alias_attr);

if ((entry.find("speed") != entry.end()) && (entry["speed"] != ""))
{
FieldValueTuple speed_attr("speed", entry["speed"]);
attrs.push_back(speed_attr);
}

if ((entry.find("autoneg") != entry.end()) && (entry["autoneg"] != ""))
{
FieldValueTuple autoneg_attr("autoneg", entry["autoneg"]);
attrs.push_back(autoneg_attr);
}

if ((entry.find("fec") != entry.end()) && (entry["fec"] != ""))
{
FieldValueTuple fec_attr("fec", entry["fec"]);
attrs.push_back(fec_attr);
}

p.set(entry["name"], attrs);
}

g_portSet.insert(entry["name"]);
}

infile.close();
if (!warm)
{
notifyPortConfigDone(p);
}
}

void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map)
{

Expand Down

0 comments on commit 3796a9a

Please sign in to comment.