Skip to content

Commit 3ca530c

Browse files
Addressed review comments
Signed-off-by: Akhilesh Samineni <[email protected]>
1 parent e4b7724 commit 3ca530c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

natsyncd/natsync.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ NatSync::NatSync(RedisPipeline *pipelineAppDB, DBConnector *appDb, DBConnector *
6161
}
6262
}
6363

64+
/* To check the port init is done or not */
65+
bool NatSync::isPortInitDone(DBConnector *app_db)
66+
{
67+
bool portInit = 0;
68+
long cnt = 0;
69+
70+
while(!portInit) {
71+
Table portTable(app_db, APP_PORT_TABLE_NAME);
72+
std::vector<FieldValueTuple> tuples;
73+
portInit = portTable.get("PortInitDone", tuples);
74+
75+
if(portInit)
76+
break;
77+
sleep(1);
78+
cnt++;
79+
}
80+
sleep(5);
81+
SWSS_LOG_NOTICE("PORT_INIT_DONE : %d %ld", portInit, cnt);
82+
return portInit;
83+
}
84+
6485
// Check if nat conntrack entries are restored in kernel
6586
bool NatSync::isNatRestoreDone()
6687
{

natsyncd/natsync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "nfnetlink.h"
2626
#include <linux/netfilter/nfnetlink_conntrack.h>
2727
#include <linux/netfilter/nf_conntrack_common.h>
28+
#include <unistd.h>
2829

2930
// The timeout value (in seconds) for natsyncd reconcilation logic
3031
#define DEFAULT_NATSYNC_WARMSTART_TIMER 30
@@ -46,6 +47,7 @@ class NatSync : public NetMsg
4647
virtual void onMsg(int nlmsg_type, struct nl_object *obj);
4748

4849
bool isNatRestoreDone();
50+
bool isPortInitDone(DBConnector *app_db);
4951

5052
AppRestartAssist *getRestartAssist()
5153
{

natsyncd/natsyncd.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int main(int argc, char **argv)
2323
nfnl.registerRecvCallbacks();
2424
NatSync sync(&pipelineAppDB, &appDb, &stateDb, &nfnl);
2525

26+
sync.isPortInitDone(&appDb);
27+
2628
NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_NEW), &sync);
2729
NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_DELETE), &sync);
2830

@@ -65,7 +67,7 @@ int main(int argc, char **argv)
6567
nfnl.registerGroup(NFNLGRP_CONNTRACK_UPDATE);
6668
nfnl.registerGroup(NFNLGRP_CONNTRACK_DESTROY);
6769

68-
cout << "Listens to conntrack messages..." << endl;
70+
SWSS_LOG_INFO("Listens to conntrack messages...");
6971
nfnl.dumpRequest(IPCTNL_MSG_CT_GET);
7072

7173
s.addSelectable(&nfnl);
@@ -89,7 +91,7 @@ int main(int argc, char **argv)
8991
}
9092
catch (const std::exception& e)
9193
{
92-
cout << "Exception \"" << e.what() << "\" had been thrown in daemon" << endl;
94+
SWSS_LOG_ERROR("Runtime error: %s", e.what());
9395
return 0;
9496
}
9597
}

0 commit comments

Comments
 (0)