Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
  • Loading branch information
AkhileshSamineni committed Dec 10, 2019
1 parent e4b7724 commit 3ca530c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions natsyncd/natsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ NatSync::NatSync(RedisPipeline *pipelineAppDB, DBConnector *appDb, DBConnector *
}
}

/* To check the port init is done or not */
bool NatSync::isPortInitDone(DBConnector *app_db)
{
bool portInit = 0;
long cnt = 0;

while(!portInit) {
Table portTable(app_db, APP_PORT_TABLE_NAME);
std::vector<FieldValueTuple> tuples;
portInit = portTable.get("PortInitDone", tuples);

if(portInit)
break;
sleep(1);
cnt++;
}
sleep(5);
SWSS_LOG_NOTICE("PORT_INIT_DONE : %d %ld", portInit, cnt);
return portInit;
}

// Check if nat conntrack entries are restored in kernel
bool NatSync::isNatRestoreDone()
{
Expand Down
2 changes: 2 additions & 0 deletions natsyncd/natsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "nfnetlink.h"
#include <linux/netfilter/nfnetlink_conntrack.h>
#include <linux/netfilter/nf_conntrack_common.h>
#include <unistd.h>

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

bool isNatRestoreDone();
bool isPortInitDone(DBConnector *app_db);

AppRestartAssist *getRestartAssist()
{
Expand Down
6 changes: 4 additions & 2 deletions natsyncd/natsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ int main(int argc, char **argv)
nfnl.registerRecvCallbacks();
NatSync sync(&pipelineAppDB, &appDb, &stateDb, &nfnl);

sync.isPortInitDone(&appDb);

NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_NEW), &sync);
NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_DELETE), &sync);

Expand Down Expand Up @@ -65,7 +67,7 @@ int main(int argc, char **argv)
nfnl.registerGroup(NFNLGRP_CONNTRACK_UPDATE);
nfnl.registerGroup(NFNLGRP_CONNTRACK_DESTROY);

cout << "Listens to conntrack messages..." << endl;
SWSS_LOG_INFO("Listens to conntrack messages...");
nfnl.dumpRequest(IPCTNL_MSG_CT_GET);

s.addSelectable(&nfnl);
Expand All @@ -89,7 +91,7 @@ int main(int argc, char **argv)
}
catch (const std::exception& e)
{
cout << "Exception \"" << e.what() << "\" had been thrown in daemon" << endl;
SWSS_LOG_ERROR("Runtime error: %s", e.what());
return 0;
}
}
Expand Down

0 comments on commit 3ca530c

Please sign in to comment.