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
25 changes: 18 additions & 7 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ Orch::~Orch()
}
}

std::vector<Selectable*> Orch::getConsumers()
std::vector<Selectable *> Orch::getSelectables()
{
SWSS_LOG_ENTER();

std::vector<Selectable*> consumers;
std::vector<Selectable *> selectables;
for(auto it : m_consumerMap) {
consumers.push_back(it.second.m_consumer);
selectables.push_back(it.second.m_consumer);
}
return consumers;
return selectables;
}

bool Orch::hasConsumer(ConsumerTable *consumer) const
bool Orch::hasSelectable(ConsumerTable *selectable) const
{
for(auto it : m_consumerMap) {
if(it.second.m_consumer == consumer) {
if(it.second.m_consumer == selectable) {
return true;
}
}
Expand Down Expand Up @@ -103,6 +103,17 @@ bool Orch::execute(string tableName)
consumer.m_toSync[key] = KeyOpFieldsValuesTuple(key, op, existing_values);
}

doTask(consumer);
if (!consumer.m_toSync.empty())
doTask(consumer);

return true;
}

void Orch::doTask()
{
for(auto it : m_consumerMap)
{
if (!it.second.m_toSync.empty())
doTask(it.second);
}
}
11 changes: 7 additions & 4 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ class Orch
public:
Orch(DBConnector *db, string tableName);
Orch(DBConnector *db, vector<string> &tableNames);
~Orch();
virtual ~Orch();

std::vector<Selectable*> getConsumers();
bool hasConsumer(ConsumerTable* s)const;
std::vector<Selectable*> getSelectables();
bool hasSelectable(ConsumerTable* s) const;

bool execute(string tableName);

/* Iterate all consumers in m_consumerMap and run doTask(Consumer) */
void doTask();
protected:
/* Run doTask against a specific consumer */
virtual void doTask(Consumer &consumer) = 0;
private:

DBConnector *m_db;

protected:
Expand Down
46 changes: 27 additions & 19 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ OrchDaemon::~OrchDaemon()

if (m_asicDb)
delete(m_asicDb);

for (Orch *o : m_orchList)
delete(o);
}

bool OrchDaemon::init()
Expand All @@ -34,11 +37,12 @@ bool OrchDaemon::init()
APP_LAG_TABLE_NAME
};

m_portsO = new PortsOrch(m_applDb, ports_tables);
m_intfsO = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME, m_portsO);
m_neighO = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, m_portsO);
m_routeO = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, m_portsO, m_neighO);
PortsOrch *ports_orch = new PortsOrch(m_applDb, ports_tables);
IntfsOrch *intfs_orch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME, ports_orch);
NeighOrch *neigh_orch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, ports_orch);
RouteOrch *route_orch = new RouteOrch(m_applDb, APP_ROUTE_TABLE_NAME, ports_orch, neigh_orch);

m_orchList = { ports_orch, intfs_orch, neigh_orch, route_orch };
m_select = new Select();

return true;
Expand All @@ -48,16 +52,15 @@ void OrchDaemon::start()
{
SWSS_LOG_ENTER();

int ret;
m_select->addSelectables(m_portsO->getConsumers());
m_select->addSelectables(m_intfsO->getConsumers());
m_select->addSelectables(m_neighO->getConsumers());
m_select->addSelectables(m_routeO->getConsumers());
for (Orch *o : m_orchList)
{
m_select->addSelectables(o->getSelectables());
}

while (true)
{
Selectable *s;
int fd;
int fd, ret;

ret = m_select->select(&s, &fd, 1);
if (ret == Select::ERROR)
Expand All @@ -67,7 +70,14 @@ void OrchDaemon::start()
}

if (ret == Select::TIMEOUT)
continue;
{
/* After every TIMEOUT, periodically check all m_toSync map to
* execute all the remaining tasks that need to be retried. */
for (Orch *o : m_orchList)
{
o->doTask();
}
}

Orch *o = getOrchByConsumer((ConsumerTable *)s);
o->execute(((ConsumerTable *)s)->getTableName());
Expand All @@ -78,13 +88,11 @@ Orch *OrchDaemon::getOrchByConsumer(ConsumerTable *c)
{
SWSS_LOG_ENTER();

if (m_portsO->hasConsumer(c))
return m_portsO;
if (m_intfsO->hasConsumer(c))
return m_intfsO;
if (m_neighO->hasConsumer(c))
return m_neighO;
if (m_routeO->hasConsumer(c))
return m_routeO;
for (Orch *o : m_orchList)
{
if (o->hasSelectable(c))
return o;
}

return nullptr;
}
5 changes: 1 addition & 4 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class OrchDaemon
DBConnector *m_applDb;
DBConnector *m_asicDb;

PortsOrch *m_portsO;
IntfsOrch *m_intfsO;
NeighOrch *m_neighO;
RouteOrch *m_routeO;
std::vector<Orch *> m_orchList;

Select *m_select;

Expand Down