From f1fab494a7cad81e9a29dd8ce19dcbfa170e2e58 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Fri, 10 May 2024 11:16:42 -0700 Subject: [PATCH 01/26] Vlanmgr and Fdborch changes for PAC Added Vlanmgr and Fdborch changes to support PAC. --- cfgmgr/vlanmgr.cpp | 322 +++++++++++++++++++++++++++++++++++++++++- cfgmgr/vlanmgr.h | 10 +- cfgmgr/vlanmgrd.cpp | 8 +- orchagent/fdborch.cpp | 10 +- orchagent/fdborch.h | 1 + orchagent/orch.cpp | 14 ++ orchagent/orch.h | 2 + 7 files changed, 361 insertions(+), 6 deletions(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index e74582ce29..2c1ba04d0b 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -21,8 +21,9 @@ using namespace swss; extern MacAddress gMacAddress; -VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector &tableNames) : - Orch(cfgDb, tableNames), +VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector &tableNames, + const vector &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), @@ -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(); @@ -642,6 +645,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 if (op == DEL_COMMAND) @@ -654,6 +658,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 { @@ -680,6 +685,307 @@ 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 fvVector; + FieldValueTuple portLearnMode("learn_mode", learn_mode); + fvVector.push_back(portLearnMode); + m_appPortTableProducer.set(alias, fvVector); + } + } + else if (op == DEL_COMMAND) + { + if (isMemberStateOk(alias)) + { + vector fvVector; + FieldValueTuple portLearnMode("learn_mode", "hardware"); + fvVector.push_back(portLearnMode); + m_appPortTableProducer.set(alias, fvVector); + } + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + + 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: | */ + vector 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()); + + /* Ensure the key starts with "Vlan" otherwise ignore */ + if (strncmp(keys[0].c_str(), VLAN_PREFIX, 4)) + { + SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", keys[0].c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + int vlan_id; + vlan_id = stoi(keys[0].substr(4)); + + if ((vlan_id <= 0) || (vlan_id > 4095)) + { + SWSS_LOG_ERROR("Invalid key format. Vlan is out of range: %s", keys[0].c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + 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 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); + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + 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); + + /* Ensure the key starts with "Vlan" otherwise ignore */ + if (strncmp(key.c_str(), VLAN_PREFIX, 4)) + { + SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + key = key.substr(4); + size_t found = key.find(CONFIGDB_KEY_SEPARATOR); + int vlan_id; + string vlan_alias, port_alias; + if (found != string::npos) + { + vlan_id = stoi(key.substr(0, found)); + port_alias = key.substr(found+1); + } + else + { + SWSS_LOG_ERROR("Invalid key format. No member port is presented: %s", + kfvKey(t).c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + 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 fvVector = kfvFieldsValues(t); + FieldValueTuple s("dynamic", "yes"); + fvVector.push_back(s); + m_appVlanMemberTableProducer.set(key, fvVector); + + vector fvVector1; + FieldValueTuple s1("state", "ok"); + fvVector.push_back(s1); + m_stateVlanMemberTable.set(kfvKey(t), fvVector); + } + else + { + it++; + continue; + } + } + 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)); + } + else + { + SWSS_LOG_DEBUG("%s doesn't exist", kfvKey(t).c_str()); + } + 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); + } + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + /* 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 fvVector; + FieldValueTuple s("tagging_mode", tagging_mode); + fvVector.push_back(s); + FieldValueTuple s1("dynamic", "no"); + fvVector.push_back(s1); + SWSS_LOG_INFO("key: %s\n", key.c_str()); + m_appVlanMemberTableProducer.set(key, fvVector); + + vector 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(); @@ -694,6 +1000,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()); diff --git a/cfgmgr/vlanmgr.h b/cfgmgr/vlanmgr.h index 8cf467f41c..7fce59ce65 100644 --- a/cfgmgr/vlanmgr.h +++ b/cfgmgr/vlanmgr.h @@ -14,11 +14,13 @@ namespace swss { class VlanMgr : public Orch { public: - VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector &tableNames); + VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector &tableNames, + const std::vector &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; @@ -26,6 +28,7 @@ class VlanMgr : public Orch std::set m_vlanReplay; std::set m_vlanMemberReplay; bool replayDone; + std::unordered_map> m_PortVlanMember; void doTask(Consumer &consumer); void doVlanTask(Consumer &consumer); @@ -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); }; } diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index b69dc78122..383f40c99c 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -56,7 +56,11 @@ int main(int argc, char **argv) CFG_VLAN_TABLE_NAME, CFG_VLAN_MEMBER_TABLE_NAME, }; - + vector 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); @@ -78,7 +82,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 cfgOrchList = {&vlanmgr}; diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index 4c12ad363c..5163b40ab9 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -734,6 +734,7 @@ void FdbOrch::doTask(Consumer& consumer) string esi = ""; unsigned int vni = 0; string sticky = ""; + string discard = "false"; for (auto i : kfvFieldsValues(t)) { @@ -746,6 +747,10 @@ void FdbOrch::doTask(Consumer& consumer) { type = fvValue(i); } + if (fvField(i) == "discard") + { + discard = fvValue(i); + } if(origin == FDB_ORIGIN_VXLAN_ADVERTIZED) { @@ -821,6 +826,7 @@ void FdbOrch::doTask(Consumer& consumer) fdbData.esi = esi; fdbData.vni = vni; fdbData.is_flush_pending = false; + fdbData.discard = discard; if (addFdbEntry(entry, port, fdbData)) { if (origin == FDB_ORIGIN_MCLAG_ADVERTIZED) @@ -1410,7 +1416,9 @@ bool FdbOrch::addFdbEntry(const FdbEntry& entry, const string& port_name, attrs.push_back(attr); } } - + attr.id = SAI_FDB_ENTRY_ATTR_PACKET_ACTION; + attr.value.s32 = (fdbData.discard == "true") ? SAI_PACKET_ACTION_DROP: SAI_PACKET_ACTION_FORWARD; + attrs.push_back(attr); if (macUpdate) { SWSS_LOG_INFO("MAC-Update FDB %s in %s on from-%s:to-%s from-%s:to-%s origin-%d-to-%d", diff --git a/orchagent/fdborch.h b/orchagent/fdborch.h index 09bc6dcc69..3df6685265 100644 --- a/orchagent/fdborch.h +++ b/orchagent/fdborch.h @@ -65,6 +65,7 @@ struct FdbData string esi; unsigned int vni; sai_fdb_entry_type_t sai_fdb_type; + string discard; }; struct SavedFdbEntry diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index 5607d5c027..5b691b9c86 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -36,6 +36,20 @@ Orch::Orch(DBConnector *db, const vector &tableNames) } } +Orch::Orch(swss::DBConnector *db1, swss::DBConnector *db2, + const std::vector &tableNames_1, const std::vector &tableNames_2) +{ + for(auto it : tableNames_1) + { + addConsumer(db1, it, default_orch_pri); + } + + for(auto it : tableNames_2) + { + addConsumer(db2, it, default_orch_pri); + } +} + Orch::Orch(DBConnector *db, const vector &tableNames_with_pri) { for (const auto& it : tableNames_with_pri) diff --git a/orchagent/orch.h b/orchagent/orch.h index bb39d34589..627775d579 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -214,6 +214,8 @@ class Orch public: Orch(swss::DBConnector *db, const std::string tableName, int pri = default_orch_pri); Orch(swss::DBConnector *db, const std::vector &tableNames); + Orch(swss::DBConnector *db1, swss::DBConnector *db2, + const std::vector &tableNames_1, const std::vector &tableNames_2); Orch(swss::DBConnector *db, const std::vector &tableNameWithPri); Orch(const std::vector& tables); virtual ~Orch(); From 878a10d898e53831dd0a7f2c4f6979c3b061ea03 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 24 Sep 2024 14:09:20 -0700 Subject: [PATCH 02/26] Create settings.json --- .vscode/settings.json | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..68667a878c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,65 @@ +{ + "files.associations": { + "vector": "cpp", + "__bit_reference": "cpp", + "__config": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "execution": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "variant": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file From 6edba6cf40b26f24773f35267bdbb33b41ea6912 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 24 Sep 2024 14:13:11 -0700 Subject: [PATCH 03/26] Delete settings.json --- .vscode/settings.json | 65 ------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 68667a878c..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "files.associations": { - "vector": "cpp", - "__bit_reference": "cpp", - "__config": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "execution": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "map": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "regex": "cpp", - "set": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "variant": "cpp", - "algorithm": "cpp" - } -} \ No newline at end of file From 31d2ce47d2fa8028a20dcf51f0d7ba47d68d203c Mon Sep 17 00:00:00 2001 From: anilkpan Date: Fri, 10 May 2024 11:16:42 -0700 Subject: [PATCH 04/26] Vlanmgr and Fdborch changes for PAC Added Vlanmgr and Fdborch changes to support PAC. --- cfgmgr/vlanmgr.cpp | 322 +++++++++++++++++++++++++++++++++++++++++- cfgmgr/vlanmgr.h | 10 +- cfgmgr/vlanmgrd.cpp | 8 +- orchagent/fdborch.cpp | 10 +- orchagent/fdborch.h | 1 + orchagent/orch.cpp | 14 ++ orchagent/orch.h | 2 + 7 files changed, 361 insertions(+), 6 deletions(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index c23a23cf14..2f0fdc5e92 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -21,8 +21,9 @@ using namespace swss; extern MacAddress gMacAddress; -VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector &tableNames) : - Orch(cfgDb, tableNames), +VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector &tableNames, + const vector &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), @@ -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(); @@ -631,6 +634,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 if (op == DEL_COMMAND) @@ -643,6 +647,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 { @@ -669,6 +674,307 @@ 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 fvVector; + FieldValueTuple portLearnMode("learn_mode", learn_mode); + fvVector.push_back(portLearnMode); + m_appPortTableProducer.set(alias, fvVector); + } + } + else if (op == DEL_COMMAND) + { + if (isMemberStateOk(alias)) + { + vector fvVector; + FieldValueTuple portLearnMode("learn_mode", "hardware"); + fvVector.push_back(portLearnMode); + m_appPortTableProducer.set(alias, fvVector); + } + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + + 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: | */ + vector 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()); + + /* Ensure the key starts with "Vlan" otherwise ignore */ + if (strncmp(keys[0].c_str(), VLAN_PREFIX, 4)) + { + SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", keys[0].c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + int vlan_id; + vlan_id = stoi(keys[0].substr(4)); + + if ((vlan_id <= 0) || (vlan_id > 4095)) + { + SWSS_LOG_ERROR("Invalid key format. Vlan is out of range: %s", keys[0].c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + 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 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); + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + 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); + + /* Ensure the key starts with "Vlan" otherwise ignore */ + if (strncmp(key.c_str(), VLAN_PREFIX, 4)) + { + SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + key = key.substr(4); + size_t found = key.find(CONFIGDB_KEY_SEPARATOR); + int vlan_id; + string vlan_alias, port_alias; + if (found != string::npos) + { + vlan_id = stoi(key.substr(0, found)); + port_alias = key.substr(found+1); + } + else + { + SWSS_LOG_ERROR("Invalid key format. No member port is presented: %s", + kfvKey(t).c_str()); + it = consumer.m_toSync.erase(it); + continue; + } + + 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 fvVector = kfvFieldsValues(t); + FieldValueTuple s("dynamic", "yes"); + fvVector.push_back(s); + m_appVlanMemberTableProducer.set(key, fvVector); + + vector fvVector1; + FieldValueTuple s1("state", "ok"); + fvVector.push_back(s1); + m_stateVlanMemberTable.set(kfvKey(t), fvVector); + } + else + { + it++; + continue; + } + } + 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)); + } + else + { + SWSS_LOG_DEBUG("%s doesn't exist", kfvKey(t).c_str()); + } + 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); + } + } + else + { + SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); + } + /* 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 fvVector; + FieldValueTuple s("tagging_mode", tagging_mode); + fvVector.push_back(s); + FieldValueTuple s1("dynamic", "no"); + fvVector.push_back(s1); + SWSS_LOG_INFO("key: %s\n", key.c_str()); + m_appVlanMemberTableProducer.set(key, fvVector); + + vector 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(); @@ -683,6 +989,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()); diff --git a/cfgmgr/vlanmgr.h b/cfgmgr/vlanmgr.h index 8cf467f41c..7fce59ce65 100644 --- a/cfgmgr/vlanmgr.h +++ b/cfgmgr/vlanmgr.h @@ -14,11 +14,13 @@ namespace swss { class VlanMgr : public Orch { public: - VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector &tableNames); + VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector &tableNames, + const std::vector &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; @@ -26,6 +28,7 @@ class VlanMgr : public Orch std::set m_vlanReplay; std::set m_vlanMemberReplay; bool replayDone; + std::unordered_map> m_PortVlanMember; void doTask(Consumer &consumer); void doVlanTask(Consumer &consumer); @@ -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); }; } diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index 84bc19cf08..d430063247 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -36,7 +36,11 @@ int main(int argc, char **argv) CFG_VLAN_TABLE_NAME, CFG_VLAN_MEMBER_TABLE_NAME, }; - + vector 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); @@ -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 cfgOrchList = {&vlanmgr}; diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index 03c854fee3..aa1051ed06 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -772,6 +772,7 @@ void FdbOrch::doTask(Consumer& consumer) string esi = ""; unsigned int vni = 0; string sticky = ""; + string discard = "false"; for (auto i : kfvFieldsValues(t)) { @@ -784,6 +785,10 @@ void FdbOrch::doTask(Consumer& consumer) { type = fvValue(i); } + if (fvField(i) == "discard") + { + discard = fvValue(i); + } if(origin == FDB_ORIGIN_VXLAN_ADVERTIZED) { @@ -859,6 +864,7 @@ void FdbOrch::doTask(Consumer& consumer) fdbData.esi = esi; fdbData.vni = vni; fdbData.is_flush_pending = false; + fdbData.discard = discard; if (addFdbEntry(entry, port, fdbData)) { if (origin == FDB_ORIGIN_MCLAG_ADVERTIZED) @@ -1451,7 +1457,9 @@ bool FdbOrch::addFdbEntry(const FdbEntry& entry, const string& port_name, attrs.push_back(attr); } } - + attr.id = SAI_FDB_ENTRY_ATTR_PACKET_ACTION; + attr.value.s32 = (fdbData.discard == "true") ? SAI_PACKET_ACTION_DROP: SAI_PACKET_ACTION_FORWARD; + attrs.push_back(attr); if (macUpdate) { SWSS_LOG_INFO("MAC-Update FDB %s in %s on from-%s:to-%s from-%s:to-%s origin-%d-to-%d", diff --git a/orchagent/fdborch.h b/orchagent/fdborch.h index 9e71bc8c6b..c909218f21 100644 --- a/orchagent/fdborch.h +++ b/orchagent/fdborch.h @@ -65,6 +65,7 @@ struct FdbData string esi; unsigned int vni; sai_fdb_entry_type_t sai_fdb_type; + string discard; }; struct SavedFdbEntry diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index d1cbdb89c8..41a42a0ded 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -30,6 +30,20 @@ Orch::Orch(DBConnector *db, const vector &tableNames) } } +Orch::Orch(swss::DBConnector *db1, swss::DBConnector *db2, + const std::vector &tableNames_1, const std::vector &tableNames_2) +{ + for(auto it : tableNames_1) + { + addConsumer(db1, it, default_orch_pri); + } + + for(auto it : tableNames_2) + { + addConsumer(db2, it, default_orch_pri); + } +} + Orch::Orch(DBConnector *db, const vector &tableNames_with_pri) { for (const auto& it : tableNames_with_pri) diff --git a/orchagent/orch.h b/orchagent/orch.h index bdbecf5f5f..ca3a004f33 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -221,6 +221,8 @@ class Orch public: Orch(swss::DBConnector *db, const std::string tableName, int pri = default_orch_pri); Orch(swss::DBConnector *db, const std::vector &tableNames); + Orch(swss::DBConnector *db1, swss::DBConnector *db2, + const std::vector &tableNames_1, const std::vector &tableNames_2); Orch(swss::DBConnector *db, const std::vector &tableNameWithPri); Orch(const std::vector& tables); virtual ~Orch() = default; From 21c452c2b103309b182e8c6b418405708bec104f Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 24 Sep 2024 14:09:20 -0700 Subject: [PATCH 05/26] Create settings.json --- .vscode/settings.json | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..68667a878c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,65 @@ +{ + "files.associations": { + "vector": "cpp", + "__bit_reference": "cpp", + "__config": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "execution": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "variant": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file From e3b9c5cfbad77b230e39bfde8944991ba4ee0578 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 24 Sep 2024 14:13:11 -0700 Subject: [PATCH 06/26] Delete settings.json --- .vscode/settings.json | 65 ------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 68667a878c..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "files.associations": { - "vector": "cpp", - "__bit_reference": "cpp", - "__config": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "execution": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "map": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "regex": "cpp", - "set": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "variant": "cpp", - "algorithm": "cpp" - } -} \ No newline at end of file From 14edf8501590a7b3966b26de9be8c42b3fb1d1a2 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Mon, 4 Nov 2024 11:27:05 -0800 Subject: [PATCH 07/26] Create test_pac.py Added pytest for PAC --- tests/test_pac.py | 202 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 tests/test_pac.py diff --git a/tests/test_pac.py b/tests/test_pac.py new file mode 100644 index 0000000000..1a8fdf7ad2 --- /dev/null +++ b/tests/test_pac.py @@ -0,0 +1,202 @@ +import os +import sys +import time +import json +import pytest + +from swsscommon import swsscommon +from distutils.version import StrictVersion + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + + # FIXME: better to wait until DB create them + time.sleep(1) + +def remove_entry(tbl, key): + tbl._del(key) + time.sleep(1) + +def create_entry_tbl(db, table, key, pairs): + tbl = swsscommon.Table(db, table) + create_entry(tbl, key, pairs) + +def remove_entry_tbl(db, table, key): + tbl = swsscommon.Table(db, table) + remove_entry(tbl, key) + +def create_entry_pst(db, table, key, pairs): + tbl = swsscommon.ProducerStateTable(db, table) + create_entry(tbl, key, pairs) + +def how_many_entries_exist(db, table): + tbl = swsscommon.Table(db, table) + return len(tbl.getKeys()) + +def get_port_oid(self, port_name): + port_map_tbl = swsscommon.Table(self.cntdb, 'COUNTERS_PORT_NAME_MAP') + for k in port_map_tbl.get('')[1]: + if k[0] == port_name: + return k[1] + return None + +def get_bridge_port_oid(self, port_oid): + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + for key in tbl.getKeys(): + status, data = tbl.get(key) + assert status + values = dict(data) + if port_oid == values["SAI_BRIDGE_PORT_ATTR_PORT_ID"]: + return key + return None + +def check_learn_mode_in_asicdb(self, interface_oid, learn_mode): + # Get bridge port oid + bridge_port_oid = self.get_bridge_port_oid(interface_oid) + assert bridge_port_oid is not None + + tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + (status, fvs) = tbl.get(bridge_port_oid) + assert status == True + values = dict(fvs) + if values["SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE"] == learn_mode: + return True + else: + return False + +class TestPac(object): + def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): + dvs.setup_db() + time.sleep(2) + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + # create vlan + dvs.create_vlan("2") + time.sleep(1) + + # Get bvid from vlanid + ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") + assert ok, bvid + + # create a Vlan member entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0", + [ + ("tagging_mode", "untagged"), + ] + ) + + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + + # Add FDB entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) + + assert ok, str(extra) + + # Remove FDB entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01" + ) + + # check that the FDB entry was removed from ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) + assert ok == False, "The fdb entry still exists in ASIC" + + # remove Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" + ) + dvs.remove_vlan("2") + + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 0, "The Vlan2 wasn't removed" + assert bp_after - bp_before == 0, "The bridge port wasn't removed" + assert vm_after - vm_before == 0, "The vlan member wasn't removed" + + def test_PacPortLearnMode(self, dvs, testlog): + dvs.setup_db() + time.sleep(2) + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + # create vlan + dvs.create_vlan("2") + time.sleep(1) + + # create vlan member + dvs.create_vlan_member("2", "Ethernet0") + time.sleep(1) + + # get port oid + port_oid = self.get_port_oid("Ethernet0") + assert port_oid is not None + + # check asicdb before setting mac learn mode; The default learn_mode value is SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW. + status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") + assert status == True + + # Set port learn mode to CPU + create_entry_tbl( + dvs.sdb, + "OPER_PORT", "Ethernet0", + [ + ("learn_mode", "cpu_trap"), + ] + ) + status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_CPU_TRAP") + assert status == True + + # Set port learn mode back to default + create_entry_tbl( + dvs.sdb, + "OPER_PORT", "Ethernet0", + [ + ("learn_mode", "hardware"), + ] + ) + status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") + assert status == True + dvs.remove_vlan_member("2", "Ethernet0") + dvs.remove_vlan("2") + +# Add Dummy always-pass test at end as workaroud +# for issue when Flaky fail on final test it invokes module tear-down before retrying +def test_nonflaky_dummy(): + pass From c5f3e36c5f3780dbc13d9d900cbf05043bce7f73 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Mon, 4 Nov 2024 14:42:58 -0800 Subject: [PATCH 08/26] Update test_pac.py --- tests/test_pac.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 1a8fdf7ad2..175fbe7deb 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -34,15 +34,15 @@ def how_many_entries_exist(db, table): tbl = swsscommon.Table(db, table) return len(tbl.getKeys()) -def get_port_oid(self, port_name): - port_map_tbl = swsscommon.Table(self.cntdb, 'COUNTERS_PORT_NAME_MAP') +def get_port_oid(db, port_name): + port_map_tbl = swsscommon.Table(db, 'COUNTERS_PORT_NAME_MAP') for k in port_map_tbl.get('')[1]: if k[0] == port_name: return k[1] return None -def get_bridge_port_oid(self, port_oid): - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") +def get_bridge_port_oid(db, port_oid): + tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") for key in tbl.getKeys(): status, data = tbl.get(key) assert status @@ -51,12 +51,12 @@ def get_bridge_port_oid(self, port_oid): return key return None -def check_learn_mode_in_asicdb(self, interface_oid, learn_mode): +def check_learn_mode_in_asicdb(db, interface_oid, learn_mode): # Get bridge port oid - bridge_port_oid = self.get_bridge_port_oid(interface_oid) + bridge_port_oid = get_bridge_port_oid(db, interface_oid) assert bridge_port_oid is not None - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") (status, fvs) = tbl.get(bridge_port_oid) assert status == True values = dict(fvs) @@ -164,12 +164,13 @@ def test_PacPortLearnMode(self, dvs, testlog): dvs.create_vlan_member("2", "Ethernet0") time.sleep(1) + cntdb = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) # get port oid - port_oid = self.get_port_oid("Ethernet0") + port_oid = get_port_oid(cntdb, "Ethernet0") assert port_oid is not None # check asicdb before setting mac learn mode; The default learn_mode value is SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW. - status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") + status = check_learn_mode_in_asicdb(dvs.adb, port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") assert status == True # Set port learn mode to CPU @@ -180,7 +181,7 @@ def test_PacPortLearnMode(self, dvs, testlog): ("learn_mode", "cpu_trap"), ] ) - status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_CPU_TRAP") + status = check_learn_mode_in_asicdb(dvs.adb, port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_CPU_TRAP") assert status == True # Set port learn mode back to default @@ -191,7 +192,7 @@ def test_PacPortLearnMode(self, dvs, testlog): ("learn_mode", "hardware"), ] ) - status = self.check_learn_mode_in_asicdb(port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") + status = check_learn_mode_in_asicdb(dvs.adb, port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") assert status == True dvs.remove_vlan_member("2", "Ethernet0") dvs.remove_vlan("2") From 7f8fbebd78b2c8e1dfb058c2e15e50d636368e97 Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 5 Nov 2024 15:34:35 -0800 Subject: [PATCH 09/26] Fix code coverage issue --- cfgmgr/vlanmgr.cpp | 18 ------------ tests/test_pac.py | 72 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index 2f0fdc5e92..7546933fd7 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -717,11 +717,6 @@ void VlanMgr::doVlanPacPortTask(Consumer &consumer) m_appPortTableProducer.set(alias, fvVector); } } - else - { - SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - } - it = consumer.m_toSync.erase(it); } } @@ -805,10 +800,6 @@ void VlanMgr::doVlanPacFdbTask(Consumer &consumer) { m_appFdbTableProducer.del(key); } - else - { - SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - } it = consumer.m_toSync.erase(it); } } @@ -882,11 +873,6 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) fvVector.push_back(s1); m_stateVlanMemberTable.set(kfvKey(t), fvVector); } - else - { - it++; - continue; - } } else if (op == DEL_COMMAND) { @@ -914,10 +900,6 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) addPortToVlan(port_alias, vlan_alias, tagging_mode); } } - else - { - SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - } /* Other than the case of member port/lag is not ready, no retry will be performed */ it = consumer.m_toSync.erase(it); } diff --git a/tests/test_pac.py b/tests/test_pac.py index 175fbe7deb..5d26f40e8d 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -78,10 +78,39 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.create_vlan("2") time.sleep(1) + dvs.create_vlan("3") + time.sleep(1) + + # create vlan member + dvs.create_vlan_member("3", "Ethernet0") + time.sleep(1) + # Get bvid from vlanid ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid + # Negative tests for adding Vlan member entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "lan2|Ethernet0", + [ + ("tagging_mode", "untagged"), + ] + ) + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2", + [ + ("tagging_mode", "untagged"), + ] + ) + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000", + [ + ("tagging_mode", "untagged"), + ] + ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -100,6 +129,34 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" + # Negative tests for adding FDb entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "lan2|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan5000|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan20|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) # Add FDB entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -133,12 +190,20 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) assert ok == False, "The fdb entry still exists in ASIC" + # Negative test for removing Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" + ) + # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" ) dvs.remove_vlan("2") + dvs.remove_vlan_member("3", "Ethernet0") + dvs.remove_vlan("3") vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") @@ -185,12 +250,9 @@ def test_PacPortLearnMode(self, dvs, testlog): assert status == True # Set port learn mode back to default - create_entry_tbl( + remove_entry_tbl( dvs.sdb, - "OPER_PORT", "Ethernet0", - [ - ("learn_mode", "hardware"), - ] + "OPER_PORT", "Ethernet0" ) status = check_learn_mode_in_asicdb(dvs.adb, port_oid, "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW") assert status == True From 90f4074ca26c161b230154b10e0cbf8471f648ba Mon Sep 17 00:00:00 2001 From: anilkpan Date: Tue, 5 Nov 2024 22:06:54 -0800 Subject: [PATCH 10/26] Update test_pac.py --- tests/test_pac.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 5d26f40e8d..d7192283d1 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -73,6 +73,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + fdb_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") # create vlan dvs.create_vlan("2") @@ -97,6 +98,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("tagging_mode", "untagged"), ] ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "lan2|Ethernet0" + ) create_entry_tbl( dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2", @@ -104,6 +111,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("tagging_mode", "untagged"), ] ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2" + ) create_entry_tbl( dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000", @@ -111,6 +124,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("tagging_mode", "untagged"), ] ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000" + ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -125,11 +144,11 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" - # Negative tests for adding FDb entry in Oper State DB + # Negative tests for adding FDB entry in Oper State DB create_entry_tbl( dvs.sdb, "OPER_FDB", "lan2|00:00:00:00:00:01", @@ -139,6 +158,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("discard", "false"), ] ) + fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") + assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "lan2|00:00:00:00:00:01" + ) create_entry_tbl( dvs.sdb, "OPER_FDB", "Vlan5000|00:00:00:00:00:01", @@ -148,6 +173,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("discard", "false"), ] ) + fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") + assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan5000|00:00:00:00:00:01" + ) create_entry_tbl( dvs.sdb, "OPER_FDB", "Vlan20|00:00:00:00:00:01", @@ -157,6 +188,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ("discard", "false"), ] ) + fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") + assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan20|00:00:00:00:00:01" + ) # Add FDB entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -195,7 +232,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" ) - + # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, From 9d0e8b4e15e3823034cdc554e7b2e07bf9b8c52b Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:55:20 -0800 Subject: [PATCH 11/26] update test_pac.py --- tests/test_pac.py | 184 ---------------------------------------------- 1 file changed, 184 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index d7192283d1..49ce28ba33 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -66,190 +66,6 @@ def check_learn_mode_in_asicdb(db, interface_oid, learn_mode): return False class TestPac(object): - def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): - dvs.setup_db() - time.sleep(2) - - vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - fdb_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") - - # create vlan - dvs.create_vlan("2") - time.sleep(1) - - dvs.create_vlan("3") - time.sleep(1) - - # create vlan member - dvs.create_vlan_member("3", "Ethernet0") - time.sleep(1) - - # Get bvid from vlanid - ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") - assert ok, bvid - - # Negative tests for adding Vlan member entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "lan2|Ethernet0", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "lan2|Ethernet0" - ) - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2" - ) - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000" - ) - # create a Vlan member entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet0", - [ - ("tagging_mode", "untagged"), - ] - ) - - # check that the vlan information was propagated - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" - assert bp_after - bp_before == 1, "The bridge port wasn't created" - assert vm_after - vm_before == 1, "The vlan member wasn't added" - - # Negative tests for adding FDB entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "lan2|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") - assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "lan2|00:00:00:00:00:01" - ) - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan5000|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") - assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan5000|00:00:00:00:00:01" - ) - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan20|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - fdb_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") - assert fdb_after - fdb_before == 0, "The FDB entry shouldn't have been created" - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan20|00:00:00:00:00:01" - ) - # Add FDB entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - # Get mapping between interface name and its bridge port_id - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entry was inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) - - assert ok, str(extra) - - # Remove FDB entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01" - ) - - # check that the FDB entry was removed from ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) - assert ok == False, "The fdb entry still exists in ASIC" - - # Negative test for removing Vlan member entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" - ) - - # remove Vlan member entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" - ) - dvs.remove_vlan("2") - dvs.remove_vlan_member("3", "Ethernet0") - dvs.remove_vlan("3") - - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 0, "The Vlan2 wasn't removed" - assert bp_after - bp_before == 0, "The bridge port wasn't removed" - assert vm_after - vm_before == 0, "The vlan member wasn't removed" - def test_PacPortLearnMode(self, dvs, testlog): dvs.setup_db() time.sleep(2) From 70758a6a72872fbbfa595c73173b1370b1004e3f Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:36:39 -0800 Subject: [PATCH 12/26] Update test_pac.py --- tests/test_pac.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/test_pac.py b/tests/test_pac.py index 49ce28ba33..8f0a0180ff 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -66,6 +66,89 @@ def check_learn_mode_in_asicdb(db, interface_oid, learn_mode): return False class TestPac(object): + def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): + dvs.setup_db() + time.sleep(2) + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + fdb_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") + + # create vlan + dvs.create_vlan("2") + time.sleep(1) + + # Get bvid from vlanid + ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") + assert ok, bvid + + # create a Vlan member entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0", + [ + ("tagging_mode", "untagged"), + ] + ) + + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + + # Add FDB entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) + + assert ok, str(extra) + + # Remove FDB entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01" + ) + + # check that the FDB entry was removed from ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) + assert ok == False, "The fdb entry still exists in ASIC" + + # remove Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" + ) + dvs.remove_vlan("2") + + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 0, "The Vlan2 wasn't removed" + assert bp_after - bp_before == 0, "The bridge port wasn't removed" + assert vm_after - vm_before == 0, "The vlan member wasn't removed" + def test_PacPortLearnMode(self, dvs, testlog): dvs.setup_db() time.sleep(2) From fcaa14e7cc0347dafd34829b96b652bd5a3fe962 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:27:03 -0800 Subject: [PATCH 13/26] Update test_pac.py --- tests/test_pac.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_pac.py b/tests/test_pac.py index 8f0a0180ff..be1d02a2a1 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -83,6 +83,47 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid + # Negative tests for adding Vlan member entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "lan2|Ethernet0", + [ + ("tagging_mode", "untagged"), + ] + + ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "lan2|Ethernet0" + ) + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2", + [ + ("tagging_mode", "untagged"), + ] + ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2" + ) + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000", + [ + ("tagging_mode", "untagged"), + ] + ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000" + ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -134,6 +175,12 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) assert ok == False, "The fdb entry still exists in ASIC" + # Negative test for removing Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" + ) + # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, From 3a8802a149c7c0a6d393a10c2c938cc127bd87c0 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:46:27 -0800 Subject: [PATCH 14/26] Update test_pac.py --- tests/test_pac.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index be1d02a2a1..82a61f2520 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -113,7 +113,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ) create_entry_tbl( dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000", + "OPER_VLAN_MEMBER", "Vlan5000|Ethernet0", [ ("tagging_mode", "untagged"), ] @@ -122,7 +122,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" remove_entry_tbl( dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet1000" + "OPER_VLAN_MEMBER", "Vlan5000|Ethernet0" ) # create a Vlan member entry in Oper State DB create_entry_tbl( From b353612709671eca21aa88d25874bc1ed45da8f8 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:03:17 -0800 Subject: [PATCH 15/26] Update test_pac.py --- tests/test_pac.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 82a61f2520..85ba3bbc9c 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -111,19 +111,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2" ) - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan5000|Ethernet0", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan5000|Ethernet0" - ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, From f1b8f77f99111b87471991c27be93e2b0a6669c7 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:29:35 -0800 Subject: [PATCH 16/26] Update test_pac.py --- tests/test_pac.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 85ba3bbc9c..543ab46e2e 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -98,19 +98,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.sdb, "OPER_VLAN_MEMBER", "lan2|Ethernet0" ) - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2" - ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, From 64dbe646be2234cc56bec73901d572d6b5887e15 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:47:02 -0800 Subject: [PATCH 17/26] Update test_pac.py --- tests/test_pac.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 543ab46e2e..307f97d3bf 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -83,21 +83,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid - # Negative tests for adding Vlan member entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "lan2|Ethernet0", - [ - ("tagging_mode", "untagged"), - ] - - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "lan2|Ethernet0" - ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, From 7a2eb97fa7248ec0a3bb5a811a631a0ece4bec20 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:20:21 -0800 Subject: [PATCH 18/26] Update test_pac.py --- tests/test_pac.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_pac.py b/tests/test_pac.py index 307f97d3bf..b5e6aaaa3b 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -83,6 +83,19 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2", + [ + ("tagging_mode", "untagged"), + ] + ) + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2" + ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, From 6196f63df578711bf62e6cf4af976a506ed0c6be Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:57:40 -0800 Subject: [PATCH 19/26] Update test_pac.py --- tests/test_pac.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index b5e6aaaa3b..7872f0caa6 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -79,23 +79,17 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.create_vlan("2") time.sleep(1) + dvs.create_vlan("3") + time.sleep(1) + + # create vlan member + dvs.create_vlan_member("3", "Ethernet0") + time.sleep(1) + # Get bvid from vlanid ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2", - [ - ("tagging_mode", "untagged"), - ] - ) - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vm_after - vm_before == 1, "The vlan member shouldn't have been added" - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2" - ) # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -110,7 +104,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" @@ -147,18 +141,14 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) assert ok == False, "The fdb entry still exists in ASIC" - # Negative test for removing Vlan member entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" - ) - # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" ) dvs.remove_vlan("2") + dvs.remove_vlan_member("3", "Ethernet0") + dvs.remove_vlan("3") vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") From 484e536eca019cc78e8e6b46e51a4ff292c3e56c Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:16:37 -0800 Subject: [PATCH 20/26] update to fix test failures --- cfgmgr/vlanmgr.cpp | 34 +--------------------------------- tests/test_pac.py | 17 +++++++---------- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index 7546933fd7..ce2f810c7c 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -736,23 +736,9 @@ void VlanMgr::doVlanPacFdbTask(Consumer &consumer) SWSS_LOG_NOTICE("VlanMgr process static MAC vlan: %s mac: %s ", keys[0].c_str(), keys[1].c_str()); - /* Ensure the key starts with "Vlan" otherwise ignore */ - if (strncmp(keys[0].c_str(), VLAN_PREFIX, 4)) - { - SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", keys[0].c_str()); - it = consumer.m_toSync.erase(it); - continue; - } - int vlan_id; vlan_id = stoi(keys[0].substr(4)); - if ((vlan_id <= 0) || (vlan_id > 4095)) - { - SWSS_LOG_ERROR("Invalid key format. Vlan is out of range: %s", keys[0].c_str()); - it = consumer.m_toSync.erase(it); - continue; - } if (!m_vlans.count(keys[0])) { SWSS_LOG_NOTICE("Vlan %s not available yet, mac %s", keys[0].c_str(), keys[1].c_str()); @@ -813,14 +799,6 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) string key = kfvKey(t); - /* Ensure the key starts with "Vlan" otherwise ignore */ - if (strncmp(key.c_str(), VLAN_PREFIX, 4)) - { - SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str()); - it = consumer.m_toSync.erase(it); - continue; - } - key = key.substr(4); size_t found = key.find(CONFIGDB_KEY_SEPARATOR); int vlan_id; @@ -830,13 +808,6 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) vlan_id = stoi(key.substr(0, found)); port_alias = key.substr(found+1); } - else - { - SWSS_LOG_ERROR("Invalid key format. No member port is presented: %s", - kfvKey(t).c_str()); - it = consumer.m_toSync.erase(it); - continue; - } vlan_alias = VLAN_PREFIX + to_string(vlan_id); string op = kfvOp(t); @@ -886,10 +857,7 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) m_appVlanMemberTableProducer.del(key); m_stateVlanMemberTable.del(kfvKey(t)); } - else - { - SWSS_LOG_DEBUG("%s doesn't exist", kfvKey(t).c_str()); - } + auto vlans = m_PortVlanMember[port_alias]; for (const auto& vlan : vlans) { diff --git a/tests/test_pac.py b/tests/test_pac.py index 7872f0caa6..307f97d3bf 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -79,13 +79,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.create_vlan("2") time.sleep(1) - dvs.create_vlan("3") - time.sleep(1) - - # create vlan member - dvs.create_vlan_member("3", "Ethernet0") - time.sleep(1) - # Get bvid from vlanid ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid @@ -104,7 +97,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" @@ -141,14 +134,18 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) assert ok == False, "The fdb entry still exists in ASIC" + # Negative test for removing Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" + ) + # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" ) dvs.remove_vlan("2") - dvs.remove_vlan_member("3", "Ethernet0") - dvs.remove_vlan("3") vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") From 7341d6170bbea5b42aed77b350d810b43afa7ac4 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:37:50 -0800 Subject: [PATCH 21/26] updated for vstest fix --- cfgmgr/vlanmgr.cpp | 2 +- tests/test_pac.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index ce2f810c7c..7f236f2a81 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -801,7 +801,7 @@ void VlanMgr::doVlanPacVlanMemberTask(Consumer &consumer) key = key.substr(4); size_t found = key.find(CONFIGDB_KEY_SEPARATOR); - int vlan_id; + int vlan_id = 0; string vlan_alias, port_alias; if (found != string::npos) { diff --git a/tests/test_pac.py b/tests/test_pac.py index 307f97d3bf..8f0a0180ff 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -134,12 +134,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) assert ok == False, "The fdb entry still exists in ASIC" - # Negative test for removing Vlan member entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet10" - ) - # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, From 2c251fca895ccc40beb9a1b8d616cc9a0bde6316 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:46:02 -0800 Subject: [PATCH 22/26] Update test_pac.py --- tests/test_pac.py | 83 ----------------------------------------------- 1 file changed, 83 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 8f0a0180ff..49ce28ba33 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -66,89 +66,6 @@ def check_learn_mode_in_asicdb(db, interface_oid, learn_mode): return False class TestPac(object): - def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): - dvs.setup_db() - time.sleep(2) - - vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - fdb_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") - - # create vlan - dvs.create_vlan("2") - time.sleep(1) - - # Get bvid from vlanid - ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") - assert ok, bvid - - # create a Vlan member entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet0", - [ - ("tagging_mode", "untagged"), - ] - ) - - # check that the vlan information was propagated - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" - assert bp_after - bp_before == 1, "The bridge port wasn't created" - assert vm_after - vm_before == 1, "The vlan member wasn't added" - - # Add FDB entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - # Get mapping between interface name and its bridge port_id - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entry was inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) - - assert ok, str(extra) - - # Remove FDB entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01" - ) - - # check that the FDB entry was removed from ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) - assert ok == False, "The fdb entry still exists in ASIC" - - # remove Vlan member entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" - ) - dvs.remove_vlan("2") - - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 0, "The Vlan2 wasn't removed" - assert bp_after - bp_before == 0, "The bridge port wasn't removed" - assert vm_after - vm_before == 0, "The vlan member wasn't removed" - def test_PacPortLearnMode(self, dvs, testlog): dvs.setup_db() time.sleep(2) From 85b9dac647df9e26f33ef7d6287c2c4b6c32a25c Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:17:31 -0800 Subject: [PATCH 23/26] Update test_pac.py --- tests/test_pac.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/test_pac.py b/tests/test_pac.py index 49ce28ba33..8f0a0180ff 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -66,6 +66,89 @@ def check_learn_mode_in_asicdb(db, interface_oid, learn_mode): return False class TestPac(object): + def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): + dvs.setup_db() + time.sleep(2) + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + fdb_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB") + + # create vlan + dvs.create_vlan("2") + time.sleep(1) + + # Get bvid from vlanid + ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") + assert ok, bvid + + # create a Vlan member entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0", + [ + ("tagging_mode", "untagged"), + ] + ) + + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + + # Add FDB entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) + + assert ok, str(extra) + + # Remove FDB entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01" + ) + + # check that the FDB entry was removed from ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) + assert ok == False, "The fdb entry still exists in ASIC" + + # remove Vlan member entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" + ) + dvs.remove_vlan("2") + + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 0, "The Vlan2 wasn't removed" + assert bp_after - bp_before == 0, "The bridge port wasn't removed" + assert vm_after - vm_before == 0, "The vlan member wasn't removed" + def test_PacPortLearnMode(self, dvs, testlog): dvs.setup_db() time.sleep(2) From 361796b1a19c3ac481aa7d970d237023e7900222 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:01:28 -0800 Subject: [PATCH 24/26] Update test_pac.py --- tests/test_pac.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 8f0a0180ff..0bcaaaf048 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -101,39 +101,6 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" - # Add FDB entry in Oper State DB - create_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ("discard", "false"), - ] - ) - # Get mapping between interface name and its bridge port_id - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entry was inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) - - assert ok, str(extra) - - # Remove FDB entry in Oper State DB - remove_entry_tbl( - dvs.sdb, - "OPER_FDB", "Vlan2|00:00:00:00:00:01" - ) - - # check that the FDB entry was removed from ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) - assert ok == False, "The fdb entry still exists in ASIC" - # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb, From 05d2b81ee5ffc4c2b25729884170ed9a9dbeecb6 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:23:21 -0800 Subject: [PATCH 25/26] Update test_pac.py --- tests/test_pac.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_pac.py b/tests/test_pac.py index 0bcaaaf048..65c9bfa2a2 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -83,6 +83,13 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") assert ok, bvid + dvs.create_vlan("3") + time.sleep(1) + + # create vlan member + dvs.create_vlan_member("3", "Ethernet0") + time.sleep(1) + # create a Vlan member entry in Oper State DB create_entry_tbl( dvs.sdb, @@ -97,7 +104,7 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" @@ -106,7 +113,18 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): dvs.sdb, "OPER_VLAN_MEMBER", "Vlan2|Ethernet0" ) + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 2, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + dvs.remove_vlan("2") + dvs.remove_vlan_member("3", "Ethernet0") + dvs.remove_vlan("3") vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") From bbb2ee7104bf842433e43942175911c6ea159278 Mon Sep 17 00:00:00 2001 From: anilkpan <64167306+anilkpan@users.noreply.github.com> Date: Fri, 15 Nov 2024 21:48:46 -0800 Subject: [PATCH 26/26] Update test_pac.py --- tests/test_pac.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_pac.py b/tests/test_pac.py index 65c9bfa2a2..54d98f4bc8 100644 --- a/tests/test_pac.py +++ b/tests/test_pac.py @@ -108,6 +108,39 @@ def test_PacvlanMemberAndFDBAddRemove(self, dvs, testlog): assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" + # Add FDB entry in Oper State DB + create_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ("discard", "false"), + ] + ) + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_PACKET_ACTION", "SAI_PACKET_ACTION_FORWARD"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"])]) + + assert ok, str(extra) + + # Remove FDB entry in Oper State DB + remove_entry_tbl( + dvs.sdb, + "OPER_FDB", "Vlan2|00:00:00:00:00:01" + ) + + # check that the FDB entry was removed from ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "00:00:00:00:00:01"), ("bvid", bvid)], []) + assert ok == False, "The fdb entry still exists in ASIC" + # remove Vlan member entry in Oper State DB remove_entry_tbl( dvs.sdb,