Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions portsyncd/linksync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ extern set<string> g_portSet;
extern map<string, set<string>> g_vlanMap;
extern bool g_init;

LinkSync::LinkSync(DBConnector *db) :
m_portTableProducer(db, APP_PORT_TABLE_NAME),
m_vlanTableProducer(db, APP_VLAN_TABLE_NAME),
m_vlanMemberTableProducer(db, APP_VLAN_MEMBER_TABLE_NAME),
m_portTableConsumer(db, APP_PORT_TABLE_NAME),
m_vlanMemberTableConsumer(db, APP_VLAN_MEMBER_TABLE_NAME)
LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
m_portTableProducer(appl_db, APP_PORT_TABLE_NAME),
m_vlanTableProducer(appl_db, APP_VLAN_TABLE_NAME),
m_vlanMemberTableProducer(appl_db, APP_VLAN_MEMBER_TABLE_NAME),
m_portTable(appl_db, APP_PORT_TABLE_NAME),
m_vlanMemberTable(appl_db, APP_VLAN_MEMBER_TABLE_NAME),
m_statePortTable(state_db, STATE_PORT_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR)
{
/* See the comments for g_portSet in portsyncd.cpp */
for (string port : g_portSet)
{
vector<FieldValueTuple> temp;
if (m_portTableConsumer.get(port, temp))
if (m_portTable.get(port, temp))
{
for (auto it : temp)
{
Expand All @@ -55,7 +56,7 @@ LinkSync::LinkSync(DBConnector *db) :
}

vector<KeyOpFieldsValuesTuple> tuples;
m_vlanMemberTableConsumer.getTableContent(tuples);
m_vlanMemberTable.getTableContent(tuples);

for (auto tuple : tuples)
{
Expand Down Expand Up @@ -183,7 +184,7 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
* non-front panel interfaces such as eth0, lo which are not in the
* PORT_TABLE are ignored. */
vector<FieldValueTuple> temp;
if (m_portTableConsumer.get(key, temp))
if (m_portTable.get(key, temp))
{
/* TODO: When port is removed from the kernel */
if (nlmsg_type == RTM_DELLINK)
Expand All @@ -195,6 +196,10 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
if (!g_init && g_portSet.find(key) != g_portSet.end())
{
g_portSet.erase(key);
FieldValueTuple tuple("state", "ok");
vector<FieldValueTuple> vector;
vector.push_back(tuple);
m_statePortTable.set(key, vector);
}

m_portTableProducer.set(key, fvVector);
Expand Down
4 changes: 2 additions & 2 deletions portsyncd/linksync.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class LinkSync : public NetMsg
public:
enum { MAX_ADDR_SIZE = 64 };

LinkSync(DBConnector *db);
LinkSync(DBConnector *appl_db, DBConnector *state_db);

virtual void onMsg(int nlmsg_type, struct nl_object *obj);

private:
ProducerStateTable m_portTableProducer, m_vlanTableProducer, m_vlanMemberTableProducer;
Table m_portTableConsumer, m_vlanMemberTableConsumer;
Table m_portTable, m_vlanMemberTable, m_statePortTable;

std::map<unsigned int, std::string> m_ifindexNameMap;
};
Expand Down
7 changes: 4 additions & 3 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ int main(int argc, char **argv)
}
}

DBConnector db(0, DBConnector::DEFAULT_UNIXSOCKET, 0);
ProducerStateTable p(&db, APP_PORT_TABLE_NAME);
DBConnector appl_db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector state_db(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
ProducerStateTable p(&appl_db, APP_PORT_TABLE_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Table instead of producer state table.


LinkSync sync(&db);
LinkSync sync(&appl_db, &state_db);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);

Expand Down