Skip to content

Commit

Permalink
orchagent: Replacing ConsumerTable/ProducerTable with ConsumerStateTa…
Browse files Browse the repository at this point in the history
…ble/ProducerStateTable (sonic-net#127)

* Replace ConsumerTable/ProducerTable with ConsumerStateTable/ProducerStateTable

* Fix bug: ConsumerStateTable may pop nothing
  • Loading branch information
qiluo-msft authored and Shuotian Cheng committed Nov 8, 2016
1 parent 3b9fe12 commit 374f1a1
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "netmsg.h"
#include "ipprefix.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "fpmsyncd/fpmlink.h"
#include "fpmsyncd/routesync.h"

Expand Down
4 changes: 2 additions & 2 deletions fpmsyncd/routesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __ROUTESYNC__

#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "netmsg.h"

namespace swss {
Expand All @@ -17,7 +17,7 @@ class RouteSync : public NetMsg
virtual void onMsg(int nlmsg_type, struct nl_object *obj);

private:
ProducerTable m_routeTable;
ProducerStateTable m_routeTable;
struct nl_cache *m_link_cache;
struct nl_sock *m_nl_sock;
};
Expand Down
2 changes: 1 addition & 1 deletion intfsyncd/intfsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "logger.h"
#include "netmsg.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "linkcache.h"
#include "intfsyncd/intfsync.h"

Expand Down
4 changes: 2 additions & 2 deletions intfsyncd/intfsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __INTFSYNC__

#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "netmsg.h"

namespace swss {
Expand All @@ -17,7 +17,7 @@ class IntfSync : public NetMsg
virtual void onMsg(int nlmsg_type, struct nl_object *obj);

private:
ProducerTable m_intfTable;
ProducerStateTable m_intfTable;
};

}
Expand Down
2 changes: 1 addition & 1 deletion neighsyncd/neighsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "logger.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "ipaddress.h"
#include "netmsg.h"
#include "linkcache.h"
Expand Down
4 changes: 2 additions & 2 deletions neighsyncd/neighsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __NEIGHSYNC__

#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "netmsg.h"

namespace swss {
Expand All @@ -17,7 +17,7 @@ class NeighSync : public NetMsg
virtual void onMsg(int nlmsg_type, struct nl_object *obj);

private:
ProducerTable m_neighTable;
ProducerStateTable m_neighTable;
};

}
Expand Down
11 changes: 8 additions & 3 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern PortsOrch *gPortsOrch;
Orch::Orch(DBConnector *db, string tableName) :
m_db(db)
{
Consumer consumer(new ConsumerTable(m_db, tableName));
Consumer consumer(new ConsumerStateTable(m_db, tableName));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
}

Expand All @@ -23,7 +23,7 @@ Orch::Orch(DBConnector *db, vector<string> &tableNames) :
{
for(auto it : tableNames)
{
Consumer consumer(new ConsumerTable(m_db, it));
Consumer consumer(new ConsumerStateTable(m_db, it));
m_consumerMap.insert(ConsumerMapPair(it, consumer));
}
}
Expand All @@ -44,7 +44,7 @@ vector<Selectable *> Orch::getSelectables()
return selectables;
}

bool Orch::hasSelectable(ConsumerTable *selectable) const
bool Orch::hasSelectable(ConsumerStateTable *selectable) const
{
for(auto it : m_consumerMap) {
if (it.second.m_consumer == selectable) {
Expand Down Expand Up @@ -73,6 +73,11 @@ bool Orch::execute(string tableName)

string key = kfvKey(new_data);
string op = kfvOp(new_data);
// Possible nothing popped, ie. the oparation is already merged with other operations
if (op.empty())
{
return true;
}

dumpTuple(consumer, new_data);

Expand Down
10 changes: 5 additions & 5 deletions orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ extern "C" {
}

#include "dbconnector.h"
#include "consumertable.h"
#include "producertable.h"
#include "consumerstatetable.h"
#include "producerstatetable.h"

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -40,8 +40,8 @@ typedef pair<string, object_map*> type_map_pair;

typedef map<string, KeyOpFieldsValuesTuple> SyncMap;
struct Consumer {
Consumer(ConsumerTable* consumer) :m_consumer(consumer) { }
ConsumerTable* m_consumer;
Consumer(ConsumerStateTable* consumer) :m_consumer(consumer) { }
ConsumerStateTable* m_consumer;
/* Store the latest 'golden' status */
SyncMap m_toSync;
};
Expand All @@ -65,7 +65,7 @@ class Orch
virtual ~Orch();

vector<Selectable*> getSelectables();
bool hasSelectable(ConsumerTable* s) const;
bool hasSelectable(ConsumerStateTable* s) const;

bool execute(string tableName);
/* Iterate all consumers in m_consumerMap and run doTask(Consumer) */
Expand Down
6 changes: 3 additions & 3 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ void OrchDaemon::start()
continue;
}

Orch *o = getOrchByConsumer((ConsumerTable *)s);
o->execute(((ConsumerTable *)s)->getTableName());
Orch *o = getOrchByConsumer((ConsumerStateTable *)s);
o->execute(((ConsumerStateTable *)s)->getTableName());
}
}

Orch *OrchDaemon::getOrchByConsumer(ConsumerTable *c)
Orch *OrchDaemon::getOrchByConsumer(ConsumerStateTable *c)
{
SWSS_LOG_ENTER();

Expand Down
4 changes: 2 additions & 2 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SWSS_ORCHDAEMON_H

#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "consumertable.h"
#include "select.h"

Expand Down Expand Up @@ -31,7 +31,7 @@ class OrchDaemon
std::vector<Orch *> m_orchList;
Select *m_select;

Orch *getOrchByConsumer(ConsumerTable *c);
Orch *getOrchByConsumer(ConsumerStateTable *c);
};

#endif /* SWSS_ORCHDAEMON_H */
4 changes: 2 additions & 2 deletions orchagent/routeresync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <iostream>
#include <vector>
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "logger.h"

using namespace std;
Expand All @@ -20,7 +20,7 @@ int main(int argc, char **argv)
SWSS_LOG_ENTER();

DBConnector db(APPL_DB, "localhost", 6379, 0);
ProducerTable r(&db, APP_ROUTE_TABLE_NAME);
ProducerStateTable r(&db, APP_ROUTE_TABLE_NAME);

if (argc != 2)
{
Expand Down
2 changes: 1 addition & 1 deletion portsyncd/linksync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "logger.h"
#include "netmsg.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "tokenize.h"

#include "linkcache.h"
Expand Down
4 changes: 2 additions & 2 deletions portsyncd/linksync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __LINKSYNC__

#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "netmsg.h"

#include <map>
Expand All @@ -19,7 +19,7 @@ class LinkSync : public NetMsg
virtual void onMsg(int nlmsg_type, struct nl_object *obj);

private:
ProducerTable m_portTableProducer, m_vlanTableProducer, m_lagTableProducer;
ProducerStateTable m_portTableProducer, m_vlanTableProducer, m_lagTableProducer;
Table m_portTableConsumer, m_vlanTableConsumer, m_lagTableConsumer;

std::map<unsigned int, std::string> m_ifindexNameMap;
Expand Down
8 changes: 4 additions & 4 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "select.h"
#include "netdispatcher.h"
#include "netlink.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "portsyncd/linksync.h"

#include <getopt.h>
Expand Down Expand Up @@ -44,7 +44,7 @@ void usage()
cout << " default: /etc/network/interfaces.d/vlan_interfaces" << endl;
}

void handlePortConfigFile(ProducerTable &p, string file);
void handlePortConfigFile(ProducerStateTable &p, string file);
void handleVlanIntfFile(string file);

int main(int argc, char **argv)
Expand Down Expand Up @@ -73,7 +73,7 @@ int main(int argc, char **argv)
}

DBConnector db(0, "localhost", 6379, 0);
ProducerTable p(&db, APP_PORT_TABLE_NAME);
ProducerStateTable p(&db, APP_PORT_TABLE_NAME);

LinkSync sync(&db);
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
Expand Down Expand Up @@ -134,7 +134,7 @@ int main(int argc, char **argv)
return 1;
}

void handlePortConfigFile(ProducerTable &p, string file)
void handlePortConfigFile(ProducerStateTable &p, string file)
{
cout << "Read port configuration file..." << endl;

Expand Down
4 changes: 2 additions & 2 deletions swssconfig/swssconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "logger.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "json.hpp"

using namespace std;
Expand Down Expand Up @@ -57,7 +57,7 @@ bool write_db_data(vector<KeyOpFieldsValuesTuple> &db_items)
}
string table_name = key.substr(0, pos);
string key_name = key.substr(pos + 1);
ProducerTable producer(&db, table_name);
ProducerStateTable producer(&db, table_name);

if (kfvOp(db_item) == SET_COMMAND)
producer.set(key_name, kfvFieldsValues(db_item), SET_COMMAND);
Expand Down
4 changes: 2 additions & 2 deletions teamsyncd/teamsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "logger.h"
#include "netmsg.h"
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "teamsync.h"

using namespace std;
Expand Down Expand Up @@ -88,7 +88,7 @@ const struct team_change_handler TeamSync::TeamPortSync::gPortChangeHandler = {
};

TeamSync::TeamPortSync::TeamPortSync(const string &lagName, int ifindex,
ProducerTable *lagTable) :
ProducerStateTable *lagTable) :
m_lagTable(lagTable),
m_lagName(lagName),
m_ifindex(ifindex)
Expand Down
8 changes: 4 additions & 4 deletions teamsyncd/teamsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <memory>
#include "dbconnector.h"
#include "producertable.h"
#include "producerstatetable.h"
#include "selectable.h"
#include "select.h"
#include "netmsg.h"
Expand All @@ -29,7 +29,7 @@ class TeamSync : public NetMsg
public:
enum { MAX_IFNAME = 64 };
TeamPortSync(const std::string &lagName, int ifindex,
ProducerTable *lagTable);
ProducerStateTable *lagTable);
~TeamPortSync();

virtual void addFd(fd_set *fd);
Expand All @@ -43,7 +43,7 @@ class TeamSync : public NetMsg
team_change_type_mask_t type_mask);
static const struct team_change_handler gPortChangeHandler;
private:
ProducerTable *m_lagTable;
ProducerStateTable *m_lagTable;
struct team_handle *m_team;
std::string m_lagName;
int m_ifindex;
Expand All @@ -56,7 +56,7 @@ class TeamSync : public NetMsg

private:
Select *m_select;
ProducerTable m_lagTable;
ProducerStateTable m_lagTable;
std::map<std::string, std::shared_ptr<TeamPortSync> > m_teamPorts;
};

Expand Down

0 comments on commit 374f1a1

Please sign in to comment.