Skip to content

Commit 9ff7cc7

Browse files
oleksandrivantsivlguohan
authored andcommitted
Move ACL and Everflow configuration to Config DB. (sonic-net#325)
- Add possibility to subscribe *Orch to both APP DB and Config DB - Rename ACL and Everflow tables. - Fix issue with DBConnector object multiple deletions.
1 parent c44567b commit 9ff7cc7

10 files changed

+103
-53
lines changed

orchagent/aclorch.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -1049,14 +1049,20 @@ void AclOrch::doTask(Consumer &consumer)
10491049
{
10501050
SWSS_LOG_ENTER();
10511051

1052+
if (!m_portOrch->isInitDone())
1053+
{
1054+
/* Wait for ports initialization */
1055+
return;
1056+
}
1057+
10521058
string table_name = consumer.m_consumer->getTableName();
10531059

1054-
if (table_name == APP_ACL_TABLE_NAME)
1060+
if (table_name == CFG_ACL_TABLE_NAME)
10551061
{
10561062
unique_lock<mutex> lock(m_countersMutex);
10571063
doAclTableTask(consumer);
10581064
}
1059-
else if (table_name == APP_ACL_RULE_TABLE_NAME)
1065+
else if (table_name == CFG_ACL_RULE_TABLE_NAME)
10601066
{
10611067
unique_lock<mutex> lock(m_countersMutex);
10621068
doAclRuleTask(consumer);
@@ -1200,7 +1206,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
12001206
{
12011207
KeyOpFieldsValuesTuple t = it->second;
12021208
string key = kfvKey(t);
1203-
size_t found = key.find(':');
1209+
size_t found = key.find('|');
12041210
string table_id = key.substr(0, found);
12051211
string op = kfvOp(t);
12061212

@@ -1283,7 +1289,7 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
12831289
{
12841290
KeyOpFieldsValuesTuple t = it->second;
12851291
string key = kfvKey(t);
1286-
size_t found = key.find(':');
1292+
size_t found = key.find('|');
12871293
string table_id = key.substr(0, found);
12881294
string rule_id = key.substr(found + 1);
12891295
string op = kfvOp(t);

orchagent/fdborch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FdbOrch: public Orch, public Subject
2929
FdbOrch(DBConnector *db, string tableName, PortsOrch *port) :
3030
Orch(db, tableName),
3131
m_portsOrch(port),
32-
m_table(Table(m_db, tableName))
32+
m_table(Table(db, tableName))
3333
{
3434
}
3535

orchagent/main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ int main(int argc, char **argv)
247247

248248
/* Initialize orchestration components */
249249
DBConnector *appl_db = new DBConnector(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
250-
OrchDaemon *orchDaemon = new OrchDaemon(appl_db);
250+
DBConnector *config_db = new DBConnector(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
251+
252+
OrchDaemon *orchDaemon = new OrchDaemon(appl_db, config_db);
251253
if (!orchDaemon->init())
252254
{
253255
SWSS_LOG_ERROR("Failed to initialize orchstration daemon");

orchagent/mirrororch.cpp

+37-13
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,49 @@
2525
#define MIRROR_SESSION_DSCP_MIN 0
2626
#define MIRROR_SESSION_DSCP_MAX 63
2727

28+
#define MLNX_PLATFORM "mlnx"
29+
2830
extern sai_mirror_api_t *sai_mirror_api;
2931
extern sai_object_id_t gSwitchId;
3032

3133
using namespace std::rel_ops;
3234

33-
MirrorOrch::MirrorOrch(DBConnector *db, string tableName,
35+
MirrorEntry::MirrorEntry(const string& platform) :
36+
status(false),
37+
greType(0),
38+
dscp(0),
39+
ttl(0),
40+
queue(0),
41+
addVLanTag(false),
42+
sessionId(0),
43+
refCount(0)
44+
{
45+
nexthopInfo.resolved = false;
46+
neighborInfo.resolved = false;
47+
48+
if (platform == MLNX_PLATFORM)
49+
{
50+
greType = 0x6558;
51+
queue = 1;
52+
}
53+
else
54+
{
55+
greType = 0x88be;
56+
queue = 0;
57+
}
58+
59+
dscp = 8;
60+
ttl = 255;
61+
}
62+
63+
MirrorOrch::MirrorOrch(TableConnector appDbConnector, TableConnector confDbConnector,
3464
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch) :
35-
Orch(db, tableName),
65+
Orch(confDbConnector.first, confDbConnector.second),
3666
m_portsOrch(portOrch),
3767
m_routeOrch(routeOrch),
3868
m_neighOrch(neighOrch),
3969
m_fdbOrch(fdbOrch),
40-
m_mirrorTableProducer(db, tableName)
70+
m_mirrorTableProducer(appDbConnector.first, appDbConnector.second)
4171
{
4272
m_portsOrch->attach(this);
4373
m_neighOrch->attach(this);
@@ -104,7 +134,7 @@ bool MirrorOrch::getSessionState(const string& name, bool& state)
104134
return false;
105135
}
106136

107-
state = m_syncdMirrors[name].status;
137+
state = m_syncdMirrors.find(name)->second.status;
108138

109139
return true;
110140
}
@@ -118,7 +148,7 @@ bool MirrorOrch::getSessionOid(const string& name, sai_object_id_t& oid)
118148
return false;
119149
}
120150

121-
oid = m_syncdMirrors[name].sessionId;
151+
oid = m_syncdMirrors.find(name)->second.sessionId;
122152

123153
return true;
124154
}
@@ -132,7 +162,7 @@ bool MirrorOrch::increaseRefCount(const string& name)
132162
return false;
133163
}
134164

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

137167
return true;
138168
}
@@ -162,7 +192,7 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
162192
{
163193
SWSS_LOG_ENTER();
164194

165-
MirrorEntry entry = { };
195+
MirrorEntry entry(getenv("platform"));
166196

167197
for (auto i : data)
168198
{
@@ -201,12 +231,6 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
201231
{
202232
entry.queue = to_uint<uint8_t>(fvValue(i));
203233
}
204-
else if (fvField(i) == MIRROR_SESSION_STATUS)
205-
{
206-
// Status update always caused by MirrorOrch and should
207-
// not be changed by users. Ignore it.
208-
return;
209-
}
210234
else
211235
{
212236
SWSS_LOG_ERROR("Failed to parse session %s configuration. Unknown attribute %s.\n", key.c_str(), fvField(i).c_str());

orchagent/mirrororch.h

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "ipaddresses.h"
1313
#include "ipprefix.h"
1414

15-
#include "producerstatetable.h"
15+
#include "table.h"
1616

1717
#include <map>
1818
#include <inttypes.h>
@@ -52,19 +52,7 @@ struct MirrorEntry
5252
sai_object_id_t sessionId;
5353
int64_t refCount;
5454

55-
MirrorEntry() :
56-
status(false),
57-
greType(0),
58-
dscp(0),
59-
ttl(0),
60-
queue(0),
61-
addVLanTag(false),
62-
sessionId(0),
63-
refCount(0)
64-
{
65-
nexthopInfo.resolved = false;
66-
neighborInfo.resolved = false;
67-
}
55+
MirrorEntry(const string& platform);
6856
};
6957

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

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

98-
ProducerStateTable m_mirrorTableProducer;
86+
Table m_mirrorTableProducer;
9987

10088
MirrorTable m_syncdMirrors;
10189

orchagent/orch.cpp

+27-9
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include <sys/time.h>
55

66
#include "orch.h"
7+
8+
#include "subscriberstatetable.h"
79
#include "portsorch.h"
810
#include "tokenize.h"
911
#include "logger.h"
12+
#include "consumerstatetable.h"
1013

1114
using namespace swss;
1215

@@ -21,26 +24,29 @@ extern bool gLogRotate;
2124
extern string gRecordFile;
2225
extern string getTimestamp();
2326

24-
Orch::Orch(DBConnector *db, string tableName) :
25-
m_db(db)
27+
Orch::Orch(DBConnector *db, string tableName)
2628
{
27-
Consumer consumer(new ConsumerStateTable(m_db, tableName, gBatchSize));
28-
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
29+
addConsumer(db, tableName);
2930
}
3031

31-
Orch::Orch(DBConnector *db, vector<string> &tableNames) :
32-
m_db(db)
32+
Orch::Orch(DBConnector *db, vector<string> &tableNames)
3333
{
3434
for(auto it : tableNames)
3535
{
36-
Consumer consumer(new ConsumerStateTable(m_db, it, gBatchSize));
37-
m_consumerMap.insert(ConsumerMapPair(it, consumer));
36+
addConsumer(db, it);
37+
}
38+
}
39+
40+
Orch::Orch(const vector<TableConnector>& tables)
41+
{
42+
for (auto it : tables)
43+
{
44+
addConsumer(it.first, it.second);
3845
}
3946
}
4047

4148
Orch::~Orch()
4249
{
43-
delete(m_db);
4450
for(auto &it : m_consumerMap)
4551
delete it.second.m_consumer;
4652

@@ -355,3 +361,15 @@ bool Orch::parseIndexRange(const string &input, sai_uint32_t &range_low, sai_uin
355361
SWSS_LOG_DEBUG("resulting range:%d-%d", range_low, range_high);
356362
return true;
357363
}
364+
365+
void Orch::addConsumer(DBConnector *db, string tableName)
366+
{
367+
if (db->getDB() == CONFIG_DB)
368+
{
369+
Consumer consumer(new SubscriberStateTable(db, tableName));
370+
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
371+
} else {
372+
Consumer consumer(new ConsumerStateTable(db, tableName, gBatchSize));
373+
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
374+
}
375+
}

orchagent/orch.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ typedef enum
6161
failure
6262
} ref_resolve_status;
6363

64+
typedef pair<DBConnector *, string> TableConnector;
65+
typedef pair<DBConnector *, vector<string>> TablesConnector;
66+
6467
class Orch
6568
{
6669
public:
6770
Orch(DBConnector *db, string tableName);
6871
Orch(DBConnector *db, vector<string> &tableNames);
72+
Orch(const vector<TableConnector>& tables);
6973
virtual ~Orch();
7074

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

7882
protected:
79-
DBConnector *m_db;
8083
ConsumerMap m_consumerMap;
8184

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

9296
#endif /* SWSS_ORCH_H */

orchagent/orchdaemon.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ PortsOrch *gPortsOrch;
2020
/* Global variable gFdbOrch declared */
2121
FdbOrch *gFdbOrch;
2222

23-
OrchDaemon::OrchDaemon(DBConnector *applDb) :
24-
m_applDb(applDb)
23+
OrchDaemon::OrchDaemon(DBConnector *applDb, DBConnector *configDb) :
24+
m_applDb(applDb),
25+
m_configDb(configDb)
26+
2527
{
2628
SWSS_LOG_ENTER();
2729
}
@@ -31,6 +33,9 @@ OrchDaemon::~OrchDaemon()
3133
SWSS_LOG_ENTER();
3234
for (Orch *o : m_orchList)
3335
delete(o);
36+
37+
delete(m_configDb);
38+
delete(m_applDb);
3439
}
3540

3641
bool OrchDaemon::init()
@@ -80,13 +85,15 @@ bool OrchDaemon::init()
8085
};
8186
BufferOrch *buffer_orch = new BufferOrch(m_applDb, buffer_tables);
8287

83-
MirrorOrch *mirror_orch = new MirrorOrch(m_applDb, APP_MIRROR_SESSION_TABLE_NAME, gPortsOrch, route_orch, neigh_orch, gFdbOrch);
88+
TableConnector appDbMirrorSession(m_applDb, APP_MIRROR_SESSION_TABLE_NAME);
89+
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
90+
MirrorOrch *mirror_orch = new MirrorOrch(appDbMirrorSession, confDbMirrorSession, gPortsOrch, route_orch, neigh_orch, gFdbOrch);
8491

8592
vector<string> acl_tables = {
86-
APP_ACL_TABLE_NAME,
87-
APP_ACL_RULE_TABLE_NAME
93+
CFG_ACL_TABLE_NAME,
94+
CFG_ACL_RULE_TABLE_NAME
8895
};
89-
AclOrch *acl_orch = new AclOrch(m_applDb, acl_tables, gPortsOrch, mirror_orch, neigh_orch, route_orch);
96+
AclOrch *acl_orch = new AclOrch(m_configDb, acl_tables, gPortsOrch, mirror_orch, neigh_orch, route_orch);
9097

9198
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};
9299
m_select = new Select();

orchagent/orchdaemon.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ using namespace swss;
2525
class OrchDaemon
2626
{
2727
public:
28-
OrchDaemon(DBConnector *);
28+
OrchDaemon(DBConnector *, DBConnector *);
2929
~OrchDaemon();
3030

3131
bool init();
3232
void start();
3333
private:
3434
DBConnector *m_applDb;
35+
DBConnector *m_configDb;
3536

3637
std::vector<Orch *> m_orchList;
3738
Select *m_select;

orchagent/portsorch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
5353
m_counterTable = unique_ptr<Table>(new Table(counter_db, COUNTERS_PORT_NAME_MAP));
5454

5555
/* Initialize port table */
56-
m_portTable = unique_ptr<Table>(new Table(m_db, APP_PORT_TABLE_NAME));
56+
m_portTable = unique_ptr<Table>(new Table(db, APP_PORT_TABLE_NAME));
5757

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

0 commit comments

Comments
 (0)