Skip to content

Commit

Permalink
portsyncd: Adding ConfigDone notification in portsyncd
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
Shuotian Cheng committed Apr 25, 2016
1 parent 46fa3d1 commit 769761d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
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
19 changes: 19 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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);

inline bool isInitDone() { return m_initDone; }

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
15 changes: 14 additions & 1 deletion portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 769761d

Please sign in to comment.