Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vlanmgr and Fdborch changes for PAC #3143

Merged
merged 50 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f1fab49
Vlanmgr and Fdborch changes for PAC
anilkpan May 10, 2024
008db85
Merge remote-tracking branch 'upstream/master'
anilkpan Sep 24, 2024
878a10d
Create settings.json
anilkpan Sep 24, 2024
6edba6c
Delete settings.json
anilkpan Sep 24, 2024
31d2ce4
Vlanmgr and Fdborch changes for PAC
anilkpan May 10, 2024
21c452c
Create settings.json
anilkpan Sep 24, 2024
e3b9c5c
Delete settings.json
anilkpan Sep 24, 2024
73dbacb
Merge branch 'master' of https://github.com/anilkpan/sonic-swss
anilkpan Oct 14, 2024
894c4ca
Merge remote-tracking branch 'upstream/master'
anilkpan Oct 14, 2024
46a14fb
Merge remote-tracking branch 'upstream/master'
anilkpan Oct 22, 2024
e91a41d
Merge remote-tracking branch 'upstream/master'
anilkpan Oct 28, 2024
14edf85
Create test_pac.py
anilkpan Nov 4, 2024
1c2bbad
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 4, 2024
c5f3e36
Update test_pac.py
anilkpan Nov 4, 2024
7f8fbeb
Fix code coverage issue
anilkpan Nov 5, 2024
90f4074
Update test_pac.py
anilkpan Nov 6, 2024
8523bf6
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 6, 2024
e22aba0
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 11, 2024
9d0e8b4
update test_pac.py
anilkpan Nov 11, 2024
70758a6
Update test_pac.py
anilkpan Nov 11, 2024
fcaa14e
Update test_pac.py
anilkpan Nov 11, 2024
3a8802a
Update test_pac.py
anilkpan Nov 12, 2024
b353612
Update test_pac.py
anilkpan Nov 12, 2024
f1b8f77
Update test_pac.py
anilkpan Nov 12, 2024
64dbe64
Update test_pac.py
anilkpan Nov 12, 2024
7a2eb97
Update test_pac.py
anilkpan Nov 12, 2024
6196f63
Update test_pac.py
anilkpan Nov 12, 2024
7b6f678
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 13, 2024
484e536
update to fix test failures
anilkpan Nov 13, 2024
7341d61
updated for vstest fix
anilkpan Nov 13, 2024
2c251fc
Update test_pac.py
anilkpan Nov 13, 2024
b3832fd
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 15, 2024
85b9dac
Update test_pac.py
anilkpan Nov 15, 2024
361796b
Update test_pac.py
anilkpan Nov 15, 2024
94c3e7f
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 15, 2024
05d2b81
Update test_pac.py
anilkpan Nov 15, 2024
bbb2ee7
Update test_pac.py
anilkpan Nov 16, 2024
c601daf
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 18, 2024
6bbf558
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 20, 2024
d67bb1a
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 21, 2024
e12d545
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 23, 2024
ca15396
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 26, 2024
7844736
Merge remote-tracking branch 'upstream/master'
anilkpan Nov 27, 2024
19e7b15
Merge remote-tracking branch 'upstream/master'
anilkpan Dec 2, 2024
2d06bc4
Merge remote-tracking branch 'upstream/master'
anilkpan Dec 4, 2024
a50eadb
Merge remote-tracking branch 'upstream/master'
anilkpan Dec 6, 2024
b88757b
Fix CodeQL issues
anilkpan Dec 6, 2024
0a82207
Merge remote-tracking branch 'upstream/master'
anilkpan Dec 6, 2024
a49fa2f
Merge remote-tracking branch 'upstream/master'
anilkpan Dec 9, 2024
124c419
Merge branch 'master' into master
prsunny Dec 10, 2024
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
272 changes: 270 additions & 2 deletions cfgmgr/vlanmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ using namespace swss;

extern MacAddress gMacAddress;

VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
Orch(cfgDb, tableNames),
VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames,
const vector<string> &stateTableNames) :
Orch(cfgDb, stateDb, tableNames, stateTableNames),
m_cfgVlanTable(cfgDb, CFG_VLAN_TABLE_NAME),
m_cfgVlanMemberTable(cfgDb, CFG_VLAN_MEMBER_TABLE_NAME),
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
Expand All @@ -31,6 +32,8 @@ VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
m_stateVlanMemberTable(stateDb, STATE_VLAN_MEMBER_TABLE_NAME),
m_appVlanTableProducer(appDb, APP_VLAN_TABLE_NAME),
m_appVlanMemberTableProducer(appDb, APP_VLAN_MEMBER_TABLE_NAME),
m_appFdbTableProducer(appDb, APP_FDB_TABLE_NAME),
m_appPortTableProducer(appDb, APP_PORT_TABLE_NAME),
replayDone(false)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -643,6 +646,7 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer)
m_stateVlanMemberTable.set(kfvKey(t), fvVector);

m_vlanMemberReplay.erase(kfvKey(t));
m_PortVlanMember[port_alias][vlan_alias] = tagging_mode;
}
else
{
Expand All @@ -661,6 +665,7 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer)
key += port_alias;
m_appVlanMemberTableProducer.del(key);
m_stateVlanMemberTable.del(kfvKey(t));
m_PortVlanMember[port_alias].erase(vlan_alias);
}
else
{
Expand All @@ -687,6 +692,257 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer)
}
}

void VlanMgr::doVlanPacPortTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
auto &t = it->second;
string alias = kfvKey(t);
string op = kfvOp(t);

SWSS_LOG_DEBUG("processing %s operation %s", alias.c_str(),
op.empty() ? "none" : op.c_str());

if (op == SET_COMMAND)
{
string learn_mode;
for (auto i : kfvFieldsValues(t))
{
if (fvField(i) == "learn_mode")
{
learn_mode = fvValue(i);
}
}
if (!learn_mode.empty())
{
SWSS_LOG_NOTICE("set port learn mode port %s learn_mode %s\n", alias.c_str(), learn_mode.c_str());
vector<FieldValueTuple> fvVector;
FieldValueTuple portLearnMode("learn_mode", learn_mode);
fvVector.push_back(portLearnMode);
m_appPortTableProducer.set(alias, fvVector);
anilkpan marked this conversation as resolved.
Show resolved Hide resolved
}
}
else if (op == DEL_COMMAND)
{
if (isMemberStateOk(alias))
{
vector<FieldValueTuple> fvVector;
FieldValueTuple portLearnMode("learn_mode", "hardware");
fvVector.push_back(portLearnMode);
m_appPortTableProducer.set(alias, fvVector);
}
}
it = consumer.m_toSync.erase(it);
}
}

void VlanMgr::doVlanPacFdbTask(Consumer &consumer)
{
auto it = consumer.m_toSync.begin();

while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;

/* format: <VLAN_name>|<MAC_address> */
vector<string> keys = tokenize(kfvKey(t), config_db_key_delimiter, 1);
/* keys[0] is vlan as (Vlan10) and keys[1] is mac as (00-00-00-00-00-00) */
string op = kfvOp(t);

SWSS_LOG_NOTICE("VlanMgr process static MAC vlan: %s mac: %s ", keys[0].c_str(), keys[1].c_str());

int vlan_id;
vlan_id = stoi(keys[0].substr(4));

if (!m_vlans.count(keys[0]))
{
SWSS_LOG_NOTICE("Vlan %s not available yet, mac %s", keys[0].c_str(), keys[1].c_str());
it++;
continue;
}

MacAddress mac = MacAddress(keys[1]);

string key = VLAN_PREFIX + to_string(vlan_id);
key += DEFAULT_KEY_SEPARATOR;
key += mac.to_string();

if (op == SET_COMMAND)
{
string port, discard = "false", type = "static";
for (auto i : kfvFieldsValues(t))
{
if (fvField(i) == "port")
{
port = fvValue(i);
}
if (fvField(i) == "discard")
{
discard = fvValue(i);
}
if (fvField(i) == "type")
{
type = fvValue(i);
}
}
SWSS_LOG_NOTICE("PAC FDB SET %s port %s discard %s type %s\n",
key.c_str(), port.c_str(), discard.c_str(), type.c_str());
vector<FieldValueTuple> fvVector;
FieldValueTuple p("port", port);
fvVector.push_back(p);
FieldValueTuple t("type", type);
fvVector.push_back(t);
FieldValueTuple d("discard", discard);
fvVector.push_back(d);

m_appFdbTableProducer.set(key, fvVector);
}
else if (op == DEL_COMMAND)
{
m_appFdbTableProducer.del(key);
}
it = consumer.m_toSync.erase(it);
}
}

void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer)
{
auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
auto &t = it->second;

string key = kfvKey(t);

key = key.substr(4);
size_t found = key.find(CONFIGDB_KEY_SEPARATOR);
int vlan_id = 0;
string vlan_alias, port_alias;
if (found != string::npos)
{
vlan_id = stoi(key.substr(0, found));
port_alias = key.substr(found+1);
}

vlan_alias = VLAN_PREFIX + to_string(vlan_id);
string op = kfvOp(t);

if (op == SET_COMMAND)
{
/* Don't proceed if member port/lag is not ready yet */
if (!isMemberStateOk(port_alias) || !isVlanStateOk(vlan_alias))
{
SWSS_LOG_DEBUG("%s not ready, delaying", kfvKey(t).c_str());
it++;
continue;
}
string tagging_mode = "untagged";
auto vlans = m_PortVlanMember[port_alias];
for (const auto& vlan : vlans)
{
string vlan_alias = vlan.first;
removePortFromVlan(port_alias, vlan_alias);
}
SWSS_LOG_NOTICE("Add Vlan Member key: %s", kfvKey(t).c_str());
if (addHostVlanMember(vlan_id, port_alias, tagging_mode))
{
key = VLAN_PREFIX + to_string(vlan_id);
key += DEFAULT_KEY_SEPARATOR;
key += port_alias;
vector<FieldValueTuple> fvVector = kfvFieldsValues(t);
FieldValueTuple s("dynamic", "yes");
fvVector.push_back(s);
m_appVlanMemberTableProducer.set(key, fvVector);

vector<FieldValueTuple> fvVector1;
FieldValueTuple s1("state", "ok");
fvVector.push_back(s1);
m_stateVlanMemberTable.set(kfvKey(t), fvVector);
}
}
else if (op == DEL_COMMAND)
{
if (isVlanMemberStateOk(kfvKey(t)))
{
SWSS_LOG_NOTICE("Remove Vlan Member key: %s", kfvKey(t).c_str());
removeHostVlanMember(vlan_id, port_alias);
key = VLAN_PREFIX + to_string(vlan_id);
key += DEFAULT_KEY_SEPARATOR;
key += port_alias;
m_appVlanMemberTableProducer.del(key);
m_stateVlanMemberTable.del(kfvKey(t));
}

auto vlans = m_PortVlanMember[port_alias];
for (const auto& vlan : vlans)
{
string vlan_alias = vlan.first;
string tagging_mode = vlan.second;
SWSS_LOG_NOTICE("Add Vlan Member vlan: %s port %s tagging_mode %s",
vlan_alias.c_str(), port_alias.c_str(), tagging_mode.c_str());
addPortToVlan(port_alias, vlan_alias, tagging_mode);
}
}
/* Other than the case of member port/lag is not ready, no retry will be performed */
it = consumer.m_toSync.erase(it);
}
}

void VlanMgr::addPortToVlan(const std::string& membername, const std::string& vlan_alias,
const std::string& tagging_mode)
{
SWSS_LOG_NOTICE("member %s vlan %s tagging_mode %s",
membername.c_str(), vlan_alias.c_str(), tagging_mode.c_str());
int vlan_id = stoi(vlan_alias.substr(4));
if (addHostVlanMember(vlan_id, membername, tagging_mode))
{
std::string key = VLAN_PREFIX + to_string(vlan_id);
key += DEFAULT_KEY_SEPARATOR;
key += membername;
vector<FieldValueTuple> fvVector;
FieldValueTuple s("tagging_mode", tagging_mode);
fvVector.push_back(s);
FieldValueTuple s1("dynamic", "no");
anilkpan marked this conversation as resolved.
Show resolved Hide resolved
fvVector.push_back(s1);
SWSS_LOG_INFO("key: %s\n", key.c_str());
m_appVlanMemberTableProducer.set(key, fvVector);

vector<FieldValueTuple> fvVector1;
FieldValueTuple s2("state", "ok");
fvVector1.push_back(s2);
key = VLAN_PREFIX + to_string(vlan_id);
key += '|';
key += membername;
m_stateVlanMemberTable.set(key, fvVector1);
}
}

void VlanMgr::removePortFromVlan(const std::string& membername, const std::string& vlan_alias)
{
SWSS_LOG_NOTICE("member %s vlan %s",
membername.c_str(), vlan_alias.c_str());
int vlan_id = stoi(vlan_alias.substr(4));
std::string key = VLAN_PREFIX + to_string(vlan_id);
key += '|';
key += membername;
if (isVlanMemberStateOk(key))
{
key = VLAN_PREFIX + to_string(vlan_id);
key += ':';
key += membername;
SWSS_LOG_INFO("key: %s\n", key.c_str());
m_appVlanMemberTableProducer.del(key);

key = VLAN_PREFIX + to_string(vlan_id);
key += '|';
key += membername;
m_stateVlanMemberTable.del(key);
}
}

void VlanMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
Expand All @@ -701,6 +957,18 @@ void VlanMgr::doTask(Consumer &consumer)
{
doVlanMemberTask(consumer);
}
else if (table_name == STATE_OPER_PORT_TABLE_NAME)
{
doVlanPacPortTask(consumer);
}
else if (table_name == STATE_OPER_FDB_TABLE_NAME)
{
doVlanPacFdbTask(consumer);
}
else if (table_name == STATE_OPER_VLAN_MEMBER_TABLE_NAME)
{
doVlanPacVlanMemberTask(consumer);
}
else
{
SWSS_LOG_ERROR("Unknown config table %s ", table_name.c_str());
Expand Down
10 changes: 9 additions & 1 deletion cfgmgr/vlanmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ namespace swss {
class VlanMgr : public Orch
{
public:
VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector<std::string> &tableNames);
VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector<std::string> &tableNames,
const std::vector<std::string> &stateTableNames);
using Orch::doTask;

private:
ProducerStateTable m_appVlanTableProducer, m_appVlanMemberTableProducer;
ProducerStateTable m_appFdbTableProducer, m_appPortTableProducer;
Table m_cfgVlanTable, m_cfgVlanMemberTable;
Table m_statePortTable, m_stateLagTable;
Table m_stateVlanTable, m_stateVlanMemberTable;
std::set<std::string> m_vlans;
std::set<std::string> m_vlanReplay;
std::set<std::string> m_vlanMemberReplay;
bool replayDone;
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> m_PortVlanMember;

void doTask(Consumer &consumer);
void doVlanTask(Consumer &consumer);
Expand All @@ -43,6 +46,11 @@ class VlanMgr : public Orch
bool isVlanStateOk(const std::string &alias);
bool isVlanMacOk();
bool isVlanMemberStateOk(const std::string &vlanMemberKey);
void doVlanPacPortTask(Consumer &consumer);
void doVlanPacFdbTask(Consumer &consumer);
void doVlanPacVlanMemberTask(Consumer &consumer);
void addPortToVlan(const std::string& port_alias, const std::string& vlan_alias, const std::string& tagging_mode);
void removePortFromVlan(const std::string& port_alias, const std::string& vlan_alias);
};

}
Expand Down
8 changes: 6 additions & 2 deletions cfgmgr/vlanmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ int main(int argc, char **argv)
CFG_VLAN_TABLE_NAME,
CFG_VLAN_MEMBER_TABLE_NAME,
};

vector<string> state_vlan_tables = {
STATE_OPER_PORT_TABLE_NAME,
STATE_OPER_FDB_TABLE_NAME,
STATE_OPER_VLAN_MEMBER_TABLE_NAME
};
DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);
Expand All @@ -58,7 +62,7 @@ int main(int argc, char **argv)
}
gMacAddress = MacAddress(it->second);

VlanMgr vlanmgr(&cfgDb, &appDb, &stateDb, cfg_vlan_tables);
VlanMgr vlanmgr(&cfgDb, &appDb, &stateDb, cfg_vlan_tables, state_vlan_tables);

std::vector<Orch *> cfgOrchList = {&vlanmgr};

Expand Down
Loading
Loading