Skip to content

Commit

Permalink
Move ACL and Everflow configuration to Config DB. (sonic-net#325)
Browse files Browse the repository at this point in the history
- Add possibility to subscribe *Orch to both APP DB and Config DB
- Rename ACL and Everflow tables.
- Fix issue with DBConnector object multiple deletions.
  • Loading branch information
oleksandrivantsiv authored and lguohan committed Oct 25, 2017
1 parent c44567b commit 9ff7cc7
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 53 deletions.
14 changes: 10 additions & 4 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,14 +1049,20 @@ void AclOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

if (!m_portOrch->isInitDone())
{
/* Wait for ports initialization */
return;
}

string table_name = consumer.m_consumer->getTableName();

if (table_name == APP_ACL_TABLE_NAME)
if (table_name == CFG_ACL_TABLE_NAME)
{
unique_lock<mutex> lock(m_countersMutex);
doAclTableTask(consumer);
}
else if (table_name == APP_ACL_RULE_TABLE_NAME)
else if (table_name == CFG_ACL_RULE_TABLE_NAME)
{
unique_lock<mutex> lock(m_countersMutex);
doAclRuleTask(consumer);
Expand Down Expand Up @@ -1200,7 +1206,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
{
KeyOpFieldsValuesTuple t = it->second;
string key = kfvKey(t);
size_t found = key.find(':');
size_t found = key.find('|');
string table_id = key.substr(0, found);
string op = kfvOp(t);

Expand Down Expand Up @@ -1283,7 +1289,7 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
{
KeyOpFieldsValuesTuple t = it->second;
string key = kfvKey(t);
size_t found = key.find(':');
size_t found = key.find('|');
string table_id = key.substr(0, found);
string rule_id = key.substr(found + 1);
string op = kfvOp(t);
Expand Down
2 changes: 1 addition & 1 deletion orchagent/fdborch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FdbOrch: public Orch, public Subject
FdbOrch(DBConnector *db, string tableName, PortsOrch *port) :
Orch(db, tableName),
m_portsOrch(port),
m_table(Table(m_db, tableName))
m_table(Table(db, tableName))
{
}

Expand Down
4 changes: 3 additions & 1 deletion orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ int main(int argc, char **argv)

/* Initialize orchestration components */
DBConnector *appl_db = new DBConnector(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
OrchDaemon *orchDaemon = new OrchDaemon(appl_db);
DBConnector *config_db = new DBConnector(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

OrchDaemon *orchDaemon = new OrchDaemon(appl_db, config_db);
if (!orchDaemon->init())
{
SWSS_LOG_ERROR("Failed to initialize orchstration daemon");
Expand Down
50 changes: 37 additions & 13 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,49 @@
#define MIRROR_SESSION_DSCP_MIN 0
#define MIRROR_SESSION_DSCP_MAX 63

#define MLNX_PLATFORM "mlnx"

extern sai_mirror_api_t *sai_mirror_api;
extern sai_object_id_t gSwitchId;

using namespace std::rel_ops;

MirrorOrch::MirrorOrch(DBConnector *db, string tableName,
MirrorEntry::MirrorEntry(const string& platform) :
status(false),
greType(0),
dscp(0),
ttl(0),
queue(0),
addVLanTag(false),
sessionId(0),
refCount(0)
{
nexthopInfo.resolved = false;
neighborInfo.resolved = false;

if (platform == MLNX_PLATFORM)
{
greType = 0x6558;
queue = 1;
}
else
{
greType = 0x88be;
queue = 0;
}

dscp = 8;
ttl = 255;
}

MirrorOrch::MirrorOrch(TableConnector appDbConnector, TableConnector confDbConnector,
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch) :
Orch(db, tableName),
Orch(confDbConnector.first, confDbConnector.second),
m_portsOrch(portOrch),
m_routeOrch(routeOrch),
m_neighOrch(neighOrch),
m_fdbOrch(fdbOrch),
m_mirrorTableProducer(db, tableName)
m_mirrorTableProducer(appDbConnector.first, appDbConnector.second)
{
m_portsOrch->attach(this);
m_neighOrch->attach(this);
Expand Down Expand Up @@ -104,7 +134,7 @@ bool MirrorOrch::getSessionState(const string& name, bool& state)
return false;
}

state = m_syncdMirrors[name].status;
state = m_syncdMirrors.find(name)->second.status;

return true;
}
Expand All @@ -118,7 +148,7 @@ bool MirrorOrch::getSessionOid(const string& name, sai_object_id_t& oid)
return false;
}

oid = m_syncdMirrors[name].sessionId;
oid = m_syncdMirrors.find(name)->second.sessionId;

return true;
}
Expand All @@ -132,7 +162,7 @@ bool MirrorOrch::increaseRefCount(const string& name)
return false;
}

++m_syncdMirrors[name].refCount;
++m_syncdMirrors.find(name)->second.refCount;

return true;
}
Expand Down Expand Up @@ -162,7 +192,7 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
{
SWSS_LOG_ENTER();

MirrorEntry entry = { };
MirrorEntry entry(getenv("platform"));

for (auto i : data)
{
Expand Down Expand Up @@ -201,12 +231,6 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
{
entry.queue = to_uint<uint8_t>(fvValue(i));
}
else if (fvField(i) == MIRROR_SESSION_STATUS)
{
// Status update always caused by MirrorOrch and should
// not be changed by users. Ignore it.
return;
}
else
{
SWSS_LOG_ERROR("Failed to parse session %s configuration. Unknown attribute %s.\n", key.c_str(), fvField(i).c_str());
Expand Down
20 changes: 4 additions & 16 deletions orchagent/mirrororch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ipaddresses.h"
#include "ipprefix.h"

#include "producerstatetable.h"
#include "table.h"

#include <map>
#include <inttypes.h>
Expand Down Expand Up @@ -52,19 +52,7 @@ struct MirrorEntry
sai_object_id_t sessionId;
int64_t refCount;

MirrorEntry() :
status(false),
greType(0),
dscp(0),
ttl(0),
queue(0),
addVLanTag(false),
sessionId(0),
refCount(0)
{
nexthopInfo.resolved = false;
neighborInfo.resolved = false;
}
MirrorEntry(const string& platform);
};

struct MirrorSessionUpdate
Expand All @@ -79,7 +67,7 @@ typedef map<string, MirrorEntry> MirrorTable;
class MirrorOrch : public Orch, public Observer, public Subject
{
public:
MirrorOrch(DBConnector *db, string tableName,
MirrorOrch(TableConnector appDbConnector, TableConnector confDbConnector,
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch);

void update(SubjectType, void *);
Expand All @@ -95,7 +83,7 @@ class MirrorOrch : public Orch, public Observer, public Subject
NeighOrch *m_neighOrch;
FdbOrch *m_fdbOrch;

ProducerStateTable m_mirrorTableProducer;
Table m_mirrorTableProducer;

MirrorTable m_syncdMirrors;

Expand Down
36 changes: 27 additions & 9 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <sys/time.h>

#include "orch.h"

#include "subscriberstatetable.h"
#include "portsorch.h"
#include "tokenize.h"
#include "logger.h"
#include "consumerstatetable.h"

using namespace swss;

Expand All @@ -21,26 +24,29 @@ extern bool gLogRotate;
extern string gRecordFile;
extern string getTimestamp();

Orch::Orch(DBConnector *db, string tableName) :
m_db(db)
Orch::Orch(DBConnector *db, string tableName)
{
Consumer consumer(new ConsumerStateTable(m_db, tableName, gBatchSize));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
addConsumer(db, tableName);
}

Orch::Orch(DBConnector *db, vector<string> &tableNames) :
m_db(db)
Orch::Orch(DBConnector *db, vector<string> &tableNames)
{
for(auto it : tableNames)
{
Consumer consumer(new ConsumerStateTable(m_db, it, gBatchSize));
m_consumerMap.insert(ConsumerMapPair(it, consumer));
addConsumer(db, it);
}
}

Orch::Orch(const vector<TableConnector>& tables)
{
for (auto it : tables)
{
addConsumer(it.first, it.second);
}
}

Orch::~Orch()
{
delete(m_db);
for(auto &it : m_consumerMap)
delete it.second.m_consumer;

Expand Down Expand Up @@ -355,3 +361,15 @@ bool Orch::parseIndexRange(const string &input, sai_uint32_t &range_low, sai_uin
SWSS_LOG_DEBUG("resulting range:%d-%d", range_low, range_high);
return true;
}

void Orch::addConsumer(DBConnector *db, string tableName)
{
if (db->getDB() == CONFIG_DB)
{
Consumer consumer(new SubscriberStateTable(db, tableName));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
} else {
Consumer consumer(new ConsumerStateTable(db, tableName, gBatchSize));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
}
}
6 changes: 5 additions & 1 deletion orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ typedef enum
failure
} ref_resolve_status;

typedef pair<DBConnector *, string> TableConnector;
typedef pair<DBConnector *, vector<string>> TablesConnector;

class Orch
{
public:
Orch(DBConnector *db, string tableName);
Orch(DBConnector *db, vector<string> &tableNames);
Orch(const vector<TableConnector>& tables);
virtual ~Orch();

vector<Selectable*> getSelectables();
Expand All @@ -76,7 +80,6 @@ class Orch
void doTask();

protected:
DBConnector *m_db;
ConsumerMap m_consumerMap;

/* Run doTask against a specific consumer */
Expand All @@ -87,6 +90,7 @@ class Orch
bool parseIndexRange(const string &input, sai_uint32_t &range_low, sai_uint32_t &range_high);
bool parseReference(type_map &type_maps, string &ref, string &table_name, string &object_name);
ref_resolve_status resolveFieldRefArray(type_map&, const string&, KeyOpFieldsValuesTuple&, vector<sai_object_id_t>&);
void addConsumer(DBConnector *db, string tableName);
};

#endif /* SWSS_ORCH_H */
19 changes: 13 additions & 6 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ PortsOrch *gPortsOrch;
/* Global variable gFdbOrch declared */
FdbOrch *gFdbOrch;

OrchDaemon::OrchDaemon(DBConnector *applDb) :
m_applDb(applDb)
OrchDaemon::OrchDaemon(DBConnector *applDb, DBConnector *configDb) :
m_applDb(applDb),
m_configDb(configDb)

{
SWSS_LOG_ENTER();
}
Expand All @@ -31,6 +33,9 @@ OrchDaemon::~OrchDaemon()
SWSS_LOG_ENTER();
for (Orch *o : m_orchList)
delete(o);

delete(m_configDb);
delete(m_applDb);
}

bool OrchDaemon::init()
Expand Down Expand Up @@ -80,13 +85,15 @@ bool OrchDaemon::init()
};
BufferOrch *buffer_orch = new BufferOrch(m_applDb, buffer_tables);

MirrorOrch *mirror_orch = new MirrorOrch(m_applDb, APP_MIRROR_SESSION_TABLE_NAME, gPortsOrch, route_orch, neigh_orch, gFdbOrch);
TableConnector appDbMirrorSession(m_applDb, APP_MIRROR_SESSION_TABLE_NAME);
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
MirrorOrch *mirror_orch = new MirrorOrch(appDbMirrorSession, confDbMirrorSession, gPortsOrch, route_orch, neigh_orch, gFdbOrch);

vector<string> acl_tables = {
APP_ACL_TABLE_NAME,
APP_ACL_RULE_TABLE_NAME
CFG_ACL_TABLE_NAME,
CFG_ACL_RULE_TABLE_NAME
};
AclOrch *acl_orch = new AclOrch(m_applDb, acl_tables, gPortsOrch, mirror_orch, neigh_orch, route_orch);
AclOrch *acl_orch = new AclOrch(m_configDb, acl_tables, gPortsOrch, mirror_orch, neigh_orch, route_orch);

m_orchList = { switch_orch, gPortsOrch, intfs_orch, neigh_orch, route_orch, copp_orch, tunnel_decap_orch, qos_orch, buffer_orch, mirror_orch, acl_orch, gFdbOrch};
m_select = new Select();
Expand Down
3 changes: 2 additions & 1 deletion orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ using namespace swss;
class OrchDaemon
{
public:
OrchDaemon(DBConnector *);
OrchDaemon(DBConnector *, DBConnector *);
~OrchDaemon();

bool init();
void start();
private:
DBConnector *m_applDb;
DBConnector *m_configDb;

std::vector<Orch *> m_orchList;
Select *m_select;
Expand Down
2 changes: 1 addition & 1 deletion orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
m_counterTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_PORT_NAME_MAP));

/* Initialize port table */
m_portTable = unique_ptr<Table>(new Table(m_db, APP_PORT_TABLE_NAME));
m_portTable = unique_ptr<Table>(new Table(db, APP_PORT_TABLE_NAME));

/* Initialize queue tables */
m_queueTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_QUEUE_NAME_MAP));
Expand Down

0 comments on commit 9ff7cc7

Please sign in to comment.