Skip to content

Commit

Permalink
portsyncd: Adding ConfigDone notification in portsyncd (#17)
Browse files Browse the repository at this point in the history
As most of the applications depend on port initialization, we add
a 'ConfigDone' notification in portsyncd after finishing reading
the file 'port_config.ini'. Before orchagent receives this notification,
all other tasks from other applications are stored without actually
being executed. Only when the orchagent get this notification will all
other tasks been executed.

Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
  • Loading branch information
stcheng committed Apr 29, 2016
1 parent ffc8a6a commit f191703
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
3 changes: 3 additions & 0 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ void IntfsOrch::doTask(Consumer &consumer)
if (consumer.m_toSync.empty())
return;

if (!m_portsOrch->isInitDone())
return;

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand Down
3 changes: 3 additions & 0 deletions orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ void NeighOrch::doTask(Consumer &consumer)
if (consumer.m_toSync.empty())
return;

if (!m_portsOrch->isInitDone())
return;

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand Down
24 changes: 24 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ PortsOrch::PortsOrch(DBConnector *db, string tableName) :
}
}

bool PortsOrch::isInitDone()
{
return m_initDone;
}

bool PortsOrch::getPort(string alias, Port &p)
{
if (m_portList.find(alias) == m_portList.end())
Expand Down Expand Up @@ -182,6 +187,25 @@ void PortsOrch::doTask(Consumer &consumer)
string alias = kfvKey(t);
string op = kfvOp(t);

/* Get notification from application */
/* portsyncd application:
* When portsorch receives 'ConfigDone' message, it indicates port initialization
* procedure is done. Before port initialization procedure, none of other tasks
* are executed.
*/
if (alias == "ConfigDone")
{
/* portsyncd restarting case:
* When portsyncd restarts, duplicate notifications may be received.
*/
if (m_initDone)
return;

m_initDone = true;
SWSS_LOG_INFO("Get ConfigDone notification from portsyncd.\n");
return;
}

if (op == "SET")
{
set<int> lane_set;
Expand Down
3 changes: 3 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ class PortsOrch : public Orch
public:
PortsOrch(DBConnector *db, string tableName);

bool isInitDone();

bool getPort(string alias, Port &p);

bool setPortAdminStatus(sai_object_id_t id, bool up);

private:
bool m_initDone = false;
sai_object_id_t m_cpuPort;

sai_uint32_t m_portCount;
Expand Down
3 changes: 3 additions & 0 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ void RouteOrch::doTask(Consumer& consumer)
if (consumer.m_toSync.empty())
return;

if (!m_portsOrch->isInitDone())
return;

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand Down
17 changes: 15 additions & 2 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(int argc, char **argv)
int opt;
string port_config_file = DEFAULT_PORT_CONFIG_FILE;

while ((opt = getopt(argc, argv, "f:")) != -1 )
while ((opt = getopt(argc, argv, "f:h")) != -1 )
{
switch (opt)
{
Expand All @@ -56,6 +56,8 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}

cout << "Read port configuration file..." << endl;

string line;
while (getline(infile, line))
{
Expand All @@ -73,6 +75,17 @@ int main(int argc, char **argv)
p.set(alias, attrs);
}

infile.close();

/*
* After finishing reading port configuration file, this daemon shall send
* out a signal to orchagent indicating port initialization procedure is
* done and other application could start syncing.
*/
FieldValueTuple finish_notice("lanes", "0");
vector<FieldValueTuple> attrs = { finish_notice };
p.set("ConfigDone", attrs);

LinkSync sync(&db);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);
Expand All @@ -85,7 +98,7 @@ int main(int argc, char **argv)
Select s;

netlink.registerGroup(RTNLGRP_LINK);
cout << "Listens to link messages..." << endl;
cout << "Listen to link messages..." << endl;
netlink.dumpRequest(RTM_GETLINK);

s.addSelectable(&netlink);
Expand Down

0 comments on commit f191703

Please sign in to comment.