diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index 4570374cb4..a79aa844f2 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -29,12 +29,34 @@ VlanMgr::VlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c m_stateVlanTable(stateDb, STATE_VLAN_TABLE_NAME), m_stateVlanMemberTable(stateDb, STATE_VLAN_MEMBER_TABLE_NAME), m_appVlanTableProducer(appDb, APP_VLAN_TABLE_NAME), - m_appVlanMemberTableProducer(appDb, APP_VLAN_MEMBER_TABLE_NAME) + m_appVlanMemberTableProducer(appDb, APP_VLAN_MEMBER_TABLE_NAME), + replayDone(false) { SWSS_LOG_ENTER(); if (WarmStart::isWarmStart()) { + vector vlanKeys, vlanMemberKeys; + + /* cache all vlan and vlan member config */ + m_cfgVlanTable.getKeys(vlanKeys); + m_cfgVlanMemberTable.getKeys(vlanMemberKeys); + for (auto k : vlanKeys) + { + m_vlanReplay.insert(k); + } + for (auto k : vlanMemberKeys) + { + m_vlanMemberReplay.insert(k); + } + if (m_vlanReplay.empty()) + { + replayDone = true; + WarmStart::setWarmStartState("vlanmgrd", WarmStart::REPLAYED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to REPLAYED"); + WarmStart::setWarmStartState("vlanmgrd", WarmStart::RECONCILED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to RECONCILED"); + } const std::string cmds = std::string("") + IP_CMD + " link show " + DOT1Q_BRIDGE_NAME + " 2>/dev/null"; @@ -298,6 +320,7 @@ void VlanMgr::doVlanTask(Consumer &consumer) if (isVlanStateOk(key) && m_vlans.find(key) == m_vlans.end()) { m_vlans.insert(key); + m_vlanReplay.erase(kfvKey(t)); it = consumer.m_toSync.erase(it); SWSS_LOG_DEBUG("%s already created", kfvKey(t).c_str()); continue; @@ -308,6 +331,7 @@ void VlanMgr::doVlanTask(Consumer &consumer) { addHostVlan(vlan_id); } + m_vlanReplay.erase(kfvKey(t)); /* set up host env .... */ for (auto i : kfvFieldsValues(t)) @@ -394,6 +418,16 @@ void VlanMgr::doVlanTask(Consumer &consumer) it = consumer.m_toSync.erase(it); } } + if (!replayDone && m_vlanReplay.empty() && + m_vlanMemberReplay.empty() && + WarmStart::isWarmStart()) + { + replayDone = true; + WarmStart::setWarmStartState("vlanmgrd", WarmStart::REPLAYED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to REPLAYED"); + WarmStart::setWarmStartState("vlanmgrd", WarmStart::RECONCILED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to RECONCILED"); + } } bool VlanMgr::isMemberStateOk(const string &alias) @@ -536,6 +570,7 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer) if (isVlanMemberStateOk(kfvKey(t))) { SWSS_LOG_DEBUG("%s already set", kfvKey(t).c_str()); + m_vlanMemberReplay.erase(kfvKey(t)); it = consumer.m_toSync.erase(it); continue; } @@ -577,6 +612,8 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer) FieldValueTuple s("state", "ok"); fvVector.push_back(s); m_stateVlanMemberTable.set(kfvKey(t), fvVector); + + m_vlanMemberReplay.erase(kfvKey(t)); } } else if (op == DEL_COMMAND) @@ -603,6 +640,16 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer) /* Other than the case of member port/lag is not ready, no retry will be performed */ it = consumer.m_toSync.erase(it); } + if (!replayDone && m_vlanMemberReplay.empty() && + WarmStart::isWarmStart()) + { + replayDone = true; + WarmStart::setWarmStartState("vlanmgrd", WarmStart::REPLAYED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to REPLAYED"); + WarmStart::setWarmStartState("vlanmgrd", WarmStart::RECONCILED); + SWSS_LOG_NOTICE("vlanmgr warmstart state set to RECONCILED"); + + } } void VlanMgr::doTask(Consumer &consumer) diff --git a/cfgmgr/vlanmgr.h b/cfgmgr/vlanmgr.h index 7c2f0c68b1..8cf467f41c 100644 --- a/cfgmgr/vlanmgr.h +++ b/cfgmgr/vlanmgr.h @@ -23,7 +23,10 @@ class VlanMgr : public Orch Table m_statePortTable, m_stateLagTable; Table m_stateVlanTable, m_stateVlanMemberTable; std::set m_vlans; - + std::set m_vlanReplay; + std::set m_vlanMemberReplay; + bool replayDone; + void doTask(Consumer &consumer); void doVlanTask(Consumer &consumer); void doVlanMemberTask(Consumer &consumer); diff --git a/doc/Configuration.md b/doc/Configuration.md index 3e4195011f..7a1941fc31 100644 --- a/doc/Configuration.md +++ b/doc/Configuration.md @@ -539,7 +539,16 @@ group name and IP ranges in **BGP_PEER_RANGE** table. "ipv4_neighbor_low_threshold": "70", "acl_group_threshold_type": "percentage", "ipv4_nexthop_high_threshold": "85", - "ipv6_route_threshold_type": "percentage" + "ipv6_route_threshold_type": "percentage", + "snat_entry_threshold_type": "percentage", + "snat_entry_high_threshold": "85", + "snat_entry_low_threshold": "70", + "dnat_entry_threshold_type": "percentage", + "dnat_entry_high_threshold": "85", + "dnat_entry_low_threshold": "70", + "ipmc_entry_threshold_type": "percentage", + "ipmc_entry_high_threshold": "85", + "ipmc_entry_low_threshold": "70" } } } diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 114dc99ee6..798a39fc99 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -124,7 +124,8 @@ static const acl_capabilities_t defaultAclActionsSupported = ACL_STAGE_INGRESS, { SAI_ACL_ACTION_TYPE_PACKET_ACTION, - SAI_ACL_ACTION_TYPE_MIRROR_INGRESS + SAI_ACL_ACTION_TYPE_MIRROR_INGRESS, + SAI_ACL_ACTION_TYPE_NO_NAT } }, { diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 0c02155d47..60c9e0a621 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -37,7 +37,10 @@ const map crmResTypeNameMap = { CrmResourceType::CRM_ACL_GROUP, "ACL_GROUP" }, { CrmResourceType::CRM_ACL_ENTRY, "ACL_ENTRY" }, { CrmResourceType::CRM_ACL_COUNTER, "ACL_COUNTER" }, - { CrmResourceType::CRM_FDB_ENTRY, "FDB_ENTRY" } + { CrmResourceType::CRM_FDB_ENTRY, "FDB_ENTRY" }, + { CrmResourceType::CRM_IPMC_ENTRY, "IPMC_ENTRY" }, + { CrmResourceType::CRM_SNAT_ENTRY, "SNAT_ENTRY" }, + { CrmResourceType::CRM_DNAT_ENTRY, "DNAT_ENTRY" } }; const map crmResSaiAvailAttrMap = @@ -54,7 +57,10 @@ const map crmResSaiAvailAttrMap = { CrmResourceType::CRM_ACL_GROUP, SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP }, { CrmResourceType::CRM_ACL_ENTRY, SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_ENTRY }, { CrmResourceType::CRM_ACL_COUNTER, SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER }, - { CrmResourceType::CRM_FDB_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY } + { CrmResourceType::CRM_FDB_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY }, + { CrmResourceType::CRM_IPMC_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY}, + { CrmResourceType::CRM_SNAT_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY }, + { CrmResourceType::CRM_DNAT_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY } }; const map crmThreshTypeResMap = @@ -71,7 +77,10 @@ const map crmThreshTypeResMap = { "acl_group_threshold_type", CrmResourceType::CRM_ACL_GROUP }, { "acl_entry_threshold_type", CrmResourceType::CRM_ACL_ENTRY }, { "acl_counter_threshold_type", CrmResourceType::CRM_ACL_COUNTER }, - { "fdb_entry_threshold_type", CrmResourceType::CRM_FDB_ENTRY } + { "fdb_entry_threshold_type", CrmResourceType::CRM_FDB_ENTRY }, + { "ipmc_entry_threshold_type", CrmResourceType::CRM_IPMC_ENTRY }, + { "snat_entry_threshold_type", CrmResourceType::CRM_SNAT_ENTRY }, + { "dnat_entry_threshold_type", CrmResourceType::CRM_DNAT_ENTRY } }; const map crmThreshLowResMap = @@ -89,6 +98,9 @@ const map crmThreshLowResMap = {"acl_entry_low_threshold", CrmResourceType::CRM_ACL_ENTRY }, {"acl_counter_low_threshold", CrmResourceType::CRM_ACL_COUNTER }, {"fdb_entry_low_threshold", CrmResourceType::CRM_FDB_ENTRY }, + {"ipmc_entry_low_threshold", CrmResourceType::CRM_IPMC_ENTRY }, + {"snat_entry_low_threshold", CrmResourceType::CRM_SNAT_ENTRY }, + {"dnat_entry_low_threshold", CrmResourceType::CRM_DNAT_ENTRY } }; const map crmThreshHighResMap = @@ -105,7 +117,10 @@ const map crmThreshHighResMap = {"acl_group_high_threshold", CrmResourceType::CRM_ACL_GROUP }, {"acl_entry_high_threshold", CrmResourceType::CRM_ACL_ENTRY }, {"acl_counter_high_threshold", CrmResourceType::CRM_ACL_COUNTER }, - {"fdb_entry_high_threshold", CrmResourceType::CRM_FDB_ENTRY } + {"fdb_entry_high_threshold", CrmResourceType::CRM_FDB_ENTRY }, + {"ipmc_entry_high_threshold", CrmResourceType::CRM_IPMC_ENTRY }, + {"snat_entry_high_threshold", CrmResourceType::CRM_SNAT_ENTRY }, + {"dnat_entry_high_threshold", CrmResourceType::CRM_DNAT_ENTRY } }; const map crmThreshTypeMap = @@ -129,7 +144,10 @@ const map crmAvailCntsTableMap = { "crm_stats_acl_group_available", CrmResourceType::CRM_ACL_GROUP }, { "crm_stats_acl_entry_available", CrmResourceType::CRM_ACL_ENTRY }, { "crm_stats_acl_counter_available", CrmResourceType::CRM_ACL_COUNTER }, - { "crm_stats_fdb_entry_available", CrmResourceType::CRM_FDB_ENTRY } + { "crm_stats_fdb_entry_available", CrmResourceType::CRM_FDB_ENTRY }, + { "crm_stats_ipmc_entry_available", CrmResourceType::CRM_IPMC_ENTRY }, + { "crm_stats_snat_entry_available", CrmResourceType::CRM_SNAT_ENTRY }, + { "crm_stats_dnat_entry_available", CrmResourceType::CRM_DNAT_ENTRY } }; const map crmUsedCntsTableMap = @@ -146,7 +164,10 @@ const map crmUsedCntsTableMap = { "crm_stats_acl_group_used", CrmResourceType::CRM_ACL_GROUP }, { "crm_stats_acl_entry_used", CrmResourceType::CRM_ACL_ENTRY }, { "crm_stats_acl_counter_used", CrmResourceType::CRM_ACL_COUNTER }, - { "crm_stats_fdb_entry_used", CrmResourceType::CRM_FDB_ENTRY } + { "crm_stats_fdb_entry_used", CrmResourceType::CRM_FDB_ENTRY }, + { "crm_stats_ipmc_entry_used", CrmResourceType::CRM_IPMC_ENTRY }, + { "crm_stats_snat_entry_used", CrmResourceType::CRM_SNAT_ENTRY }, + { "crm_stats_dnat_entry_used", CrmResourceType::CRM_DNAT_ENTRY } }; CrmOrch::CrmOrch(DBConnector *db, string tableName): @@ -429,10 +450,18 @@ void CrmOrch::getResAvailableCounters() case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY: case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY: case SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY: { sai_status_t status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr); if (status != SAI_STATUS_SUCCESS) { + if(status == SAI_STATUS_NOT_SUPPORTED) + { + // remove unsupported resources from map + m_resourcesMap.erase(res.first); + } SWSS_LOG_ERROR("Failed to get switch attribute %u , rv:%d", attr.id, status); break; } @@ -504,22 +533,36 @@ void CrmOrch::updateCrmCountersTable() // Update CRM used counters in COUNTERS_DB for (const auto &i : crmUsedCntsTableMap) { - for (const auto &cnt : m_resourcesMap.at(i.second).countersMap) + try + { + for (const auto &cnt : m_resourcesMap.at(i.second).countersMap) + { + FieldValueTuple attr(i.first, to_string(cnt.second.usedCounter)); + vector attrs = { attr }; + m_countersCrmTable->set(cnt.first, attrs); + } + } + catch(const out_of_range &e) { - FieldValueTuple attr(i.first, to_string(cnt.second.usedCounter)); - vector attrs = { attr }; - m_countersCrmTable->set(cnt.first, attrs); + // expected when a resource is unavailable } } // Update CRM available counters in COUNTERS_DB for (const auto &i : crmAvailCntsTableMap) { - for (const auto &cnt : m_resourcesMap.at(i.second).countersMap) + try { - FieldValueTuple attr(i.first, to_string(cnt.second.availableCounter)); - vector attrs = { attr }; - m_countersCrmTable->set(cnt.first, attrs); + for (const auto &cnt : m_resourcesMap.at(i.second).countersMap) + { + FieldValueTuple attr(i.first, to_string(cnt.second.availableCounter)); + vector attrs = { attr }; + m_countersCrmTable->set(cnt.first, attrs); + } + } + catch(const out_of_range &e) + { + // expected when a resource is unavailable } } } @@ -541,7 +584,16 @@ void CrmOrch::checkCrmThresholds() if (cnt.usedCounter != 0) { - percentageUtil = (uint32_t)((cnt.usedCounter * 100) / (uint64_t)(cnt.usedCounter + cnt.availableCounter)); + uint32_t dvsr = cnt.usedCounter + cnt.availableCounter; + if (dvsr != 0) + { + percentageUtil = (cnt.usedCounter * 100) / dvsr; + } + else + { + SWSS_LOG_WARN("%s Exception occured (div by Zero): Used count %u free count %u", + res.name.c_str(), cnt.usedCounter, cnt.availableCounter); + } } switch (res.thresholdType) diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index 488a18b3a7..21d039396c 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -25,6 +25,9 @@ enum class CrmResourceType CRM_ACL_ENTRY, CRM_ACL_COUNTER, CRM_FDB_ENTRY, + CRM_IPMC_ENTRY, + CRM_SNAT_ENTRY, + CRM_DNAT_ENTRY, }; enum class CrmThresholdType diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 8bfc31809e..c5f46d01d3 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -38,7 +38,6 @@ const int intfsorch_pri = 35; #define RIF_FLEX_STAT_COUNTER_POLL_MSECS "1000" #define UPDATE_MAPS_SEC 1 -#define LOOPBACK_PREFIX "Loopback" static const vector rifStatIds = { @@ -57,7 +56,7 @@ IntfsOrch::IntfsOrch(DBConnector *db, string tableName, VRFOrch *vrf_orch) : { SWSS_LOG_ENTER(); - /* Initialize DB connectors */ + /* Initialize DB connectors */ m_counter_db = shared_ptr(new DBConnector("COUNTERS_DB", 0)); m_flex_db = shared_ptr(new DBConnector("FLEX_COUNTER_DB", 0)); m_asic_db = shared_ptr(new DBConnector("ASIC_DB", 0)); @@ -576,7 +575,7 @@ void IntfsOrch::doTask(Consumer &consumer) SWSS_LOG_ERROR("Invalid mac argument %s to %s()", value.c_str(), e.what()); continue; } - } + } else if (field == "nat_zone") { try diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 86ee569fb6..d8ba2b4824 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -557,7 +557,13 @@ void RouteOrch::doTask(Consumer& consumer) for (auto alias : alsv) { - if (alias == "eth0" || alias == "lo" || alias == "docker0") + /* skip route to management, docker, loopback + * TODO: for route to loopback interface, the proper + * way is to create loopback interface and then create + * route pointing to it, so that we can traps packets to + * CPU */ + if (alias == "eth0" || alias == "docker0" || + alias == "lo" || !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX)) { excp_intfs_flag = true; break; @@ -1231,7 +1237,7 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) && vrf_id == gVirtualRouterId) { /* Only support the default vrf for Fine Grained ECMP */ - SWSS_LOG_INFO("Reroute %s:%s to fgNhgOrch", ipPrefix.to_string().c_str(), + SWSS_LOG_INFO("Reroute %s:%s to fgNhgOrch", ipPrefix.to_string().c_str(), nextHops.to_string().c_str()); return m_fgNhgOrch->addRoute(vrf_id, ipPrefix, nextHops); } diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index e57bcddde4..214c2bd4ae 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -21,6 +21,8 @@ /* Length of the Interface Id value in EUI64 format */ #define EUI64_INTF_ID_LEN 8 +#define LOOPBACK_PREFIX "Loopback" + typedef std::map NextHopGroupMembers; struct NextHopGroupEntry diff --git a/tests/dvslib/dvs_acl.py b/tests/dvslib/dvs_acl.py index 41c588e738..2b48c3b76c 100644 --- a/tests/dvslib/dvs_acl.py +++ b/tests/dvslib/dvs_acl.py @@ -389,6 +389,26 @@ def verify_redirect_acl_rule( self._check_acl_entry_base(fvs, sai_qualifiers, "REDIRECT", priority) self._check_acl_entry_redirect_action(fvs, expected_destination) + def verify_nat_acl_rule( + self, + sai_qualifiers: Dict[str, str], + priority: str = "2020", + acl_rule_id=None + ) -> None: + """Verify that an ACL nat rule has the correct ASIC DB representation. + + Args: + sai_qualifiers: The expected set of SAI qualifiers to be found in ASIC DB. + priority: The priority of the rule. + acl_rule_id: A specific OID to check in ASIC DB. If left empty, this method + assumes that only one rule exists in ASIC DB. + """ + if not acl_rule_id: + acl_rule_id = self._get_acl_rule_id() + + fvs = self.asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY", acl_rule_id) + self._check_acl_entry_base(fvs, sai_qualifiers, "DO_NOT_NAT", priority) + def verify_mirror_acl_rule( self, sai_qualifiers: Dict[str, str], @@ -527,6 +547,9 @@ def _check_acl_entry_base( assert action == "REDIRECT" elif "SAI_ACL_ENTRY_ATTR_ACTION_MIRROR" in k: assert action == "MIRROR" + elif "SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT" in k: + assert action == "DO_NOT_NAT" + assert v == "true" elif k in qualifiers: assert qualifiers[k](v) else: diff --git a/tests/test_crm.py b/tests/test_crm.py index 96bf56d4e3..38b0de7a0c 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -702,6 +702,31 @@ def test_CrmAclGroup(self, dvs, testlog): #table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') #assert table_used_counter == 0 + def test_CrmSnatEntry(self, dvs, testlog): + + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_snat_entry_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_snat_entry_available') + assert used_counter == 0 + assert avail_counter != 0 + + def test_CrmDnatEntry(self, dvs, testlog): + + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_dnat_entry_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_dnat_entry_available') + assert used_counter == 0 + assert avail_counter != 0 + +# commented ipmc test case till vslib is updated +# def test_CrmIpmcEntry(self, dvs, testlog): +# +# # get counters +# used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipmc_entry_used') +# avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipmc_entry_available') +# assert used_counter == 0 +# assert avail_counter != 0 + def test_Configure(self, dvs, testlog): #polling interval @@ -905,6 +930,50 @@ def test_Configure_fdb(self, dvs, testlog): threshold_type = getCrmConfigStr(dvs, 'Config', 'fdb_entry_threshold_type') assert threshold_type == 'percentage' + def test_Configure_snat(self, dvs, testlog): + + #thresholds snat low/high threshold/type + dvs.runcmd("crm config thresholds snat low 50") + dvs.runcmd("crm config thresholds snat high 90") + dvs.runcmd("crm config thresholds snat type percentage") + + time.sleep(2) + threshold_low = getCrmConfigValue(dvs, 'Config', 'snat_entry_low_threshold') + assert threshold_low == 50 + threshold_high = getCrmConfigValue(dvs, 'Config', 'snat_entry_high_threshold') + assert threshold_high == 90 + threshold_type = getCrmConfigStr(dvs, 'Config', 'snat_entry_threshold_type') + assert threshold_type == 'percentage' + + def test_Configure_dnat(self, dvs, testlog): + + #thresholds dnat low/high threshold/type + dvs.runcmd("crm config thresholds dnat low 50") + dvs.runcmd("crm config thresholds dnat high 90") + dvs.runcmd("crm config thresholds dnat type percentage") + + time.sleep(2) + threshold_low = getCrmConfigValue(dvs, 'Config', 'dnat_entry_low_threshold') + assert threshold_low == 50 + threshold_high = getCrmConfigValue(dvs, 'Config', 'dnat_entry_high_threshold') + assert threshold_high == 90 + threshold_type = getCrmConfigStr(dvs, 'Config', 'dnat_entry_threshold_type') + assert threshold_type == 'percentage' + + def test_Configure_ipmc(self, dvs, testlog): + + #thresholds ipmc low/high threshold/type + dvs.runcmd("crm config thresholds ipmc low 50") + dvs.runcmd("crm config thresholds ipmc high 90") + dvs.runcmd("crm config thresholds ipmc type percentage") + + time.sleep(2) + threshold_low = getCrmConfigValue(dvs, 'Config', 'ipmc_entry_low_threshold') + assert threshold_low == 50 + threshold_high = getCrmConfigValue(dvs, 'Config', 'ipmc_entry_high_threshold') + assert threshold_high == 90 + threshold_type = getCrmConfigStr(dvs, 'Config', 'ipmc_entry_threshold_type') + assert threshold_type == 'percentage' # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying diff --git a/tests/test_evpn_l3_vxlan.py b/tests/test_evpn_l3_vxlan.py new file mode 100644 index 0000000000..6f541b20a6 --- /dev/null +++ b/tests/test_evpn_l3_vxlan.py @@ -0,0 +1,1597 @@ +from swsscommon import swsscommon +import time +import json +import random +import pytest +from pprint import pprint + + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + time.sleep(1) + + +def create_entry_tbl(db, table, separator, key, pairs): + tbl = swsscommon.Table(db, table) + create_entry(tbl, key, pairs) + +def delete_entry_tbl(db, table, key): + tbl = swsscommon.Table(db, table) + tbl._del(key) + time.sleep(1) + +def create_entry_pst(db, table, separator, key, pairs): + tbl = swsscommon.ProducerStateTable(db, table) + create_entry(tbl, key, pairs) + +def delete_entry_pst(db, table, key): + tbl = swsscommon.ProducerStateTable(db, table) + tbl._del(key) + time.sleep(1) + +def how_many_entries_exist(db, table): + tbl = swsscommon.Table(db, table) + return len(tbl.getKeys()) + + +def entries(db, table): + tbl = swsscommon.Table(db, table) + return set(tbl.getKeys()) + + +def get_exist_entries(dvs, table): + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, table) + return set(tbl.getKeys()) + + +def get_created_entry(db, table, existed_entries): + tbl = swsscommon.Table(db, table) + entries = set(tbl.getKeys()) + new_entries = list(entries - existed_entries) + assert len(new_entries) == 1, "Wrong number of created entries." + return new_entries[0] + + +def get_created_entries(db, table, existed_entries, count): + tbl = swsscommon.Table(db, table) + entries = set(tbl.getKeys()) + new_entries = list(entries - existed_entries) + assert len(new_entries) == count, "Wrong number of created entries." + new_entries.sort() + return new_entries + +def get_deleted_entries(db, table, existed_entries, count): + tbl = swsscommon.Table(db, table) + entries = set(tbl.getKeys()) + old_entries = list(existed_entries - entries) + assert len(old_entries) == count, "Wrong number of deleted entries." + old_entries.sort() + return old_entries + +def get_default_vr_id(dvs): + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + table = 'ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER' + tbl = swsscommon.Table(db, table) + keys = tbl.getKeys() + assert len(keys) == 1, "Wrong number of virtual routers found" + + return keys[0] + +def check_object(db, table, key, expected_attributes): + tbl = swsscommon.Table(db, table) + keys = tbl.getKeys() + assert key in keys, "The desired key is not presented" + + status, fvs = tbl.get(key) + assert status, "Got an error when get a key" + + assert len(fvs) >= len(expected_attributes), "Incorrect attributes" + + attr_keys = {entry[0] for entry in fvs} + + for name, value in fvs: + if name in expected_attributes: + assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \ + (value, name, expected_attributes[name]) + +def check_deleted_object(db, table, key): + tbl = swsscommon.Table(db, table) + keys = tbl.getKeys() + assert key not in keys, "The desired key is not removed" + +def get_key_with_attr(db, table, expected_attributes ): + tbl = swsscommon.Table(db, table) + keys = tbl.getKeys() + retkey = list() + #assert key in keys, "The desired key is not presented" + + for key in keys: + status, fvs = tbl.get(key) + assert status, "Got an error when get a key" + + assert len(fvs) >= len(expected_attributes), "Incorrect attributes" + + attr_keys = {entry[0] for entry in fvs} + + num_match = 0 + for name, value in fvs: + if name in expected_attributes: + if expected_attributes[name] == value: + num_match += 1 + if num_match == len(expected_attributes): + retkey.append(key) + + return retkey + +def create_vrf_routes(dvs, prefix, vrf_name, endpoint, ifname, mac="", vni=0): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + attrs = [ + ("nexthop", endpoint), + ("ifname", ifname), + ] + + if vni: + attrs.append(('vni_label', vni)) + + if mac: + attrs.append(('router_mac', mac)) + + create_entry_pst( + app_db, + "ROUTE_TABLE", ':', "%s:%s" % (vrf_name, prefix), + attrs, + ) + + time.sleep(2) + +def delete_vrf_routes(dvs, prefix, vrf_name): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + delete_entry_pst(app_db, "ROUTE_TABLE", "%s:%s" % (vrf_name, prefix)) + + time.sleep(2) + +def create_vrf_routes_ecmp(dvs, prefix, vrf_name, ecmp_nexthop_attributes): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + create_entry_pst( + app_db, + "ROUTE_TABLE", ':', "%s:%s" % (vrf_name, prefix), + ecmp_nexthop_attributes, + ) + + time.sleep(2) + +def create_vlan(dvs, vlan_name, vlan_ids): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + vlan_id = vlan_name[4:] + + # create vlan + create_entry_tbl( + conf_db, + "VLAN", '|', vlan_name, + [ + ("vlanid", vlan_id), + ], + ) + + time.sleep(1) + + vlan_oid = get_created_entry(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN", vlan_ids) + + check_object(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN", vlan_oid, + { + "SAI_VLAN_ATTR_VLAN_ID": vlan_id, + } + ) + + return vlan_oid + +def remove_vlan(dvs, vlan): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(conf_db, "VLAN") + tbl._del("Vlan" + vlan) + time.sleep(1) + +def create_vlan_member(dvs, vlan, interface, tagging_mode="untagged"): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(conf_db, "VLAN_MEMBER") + fvs = swsscommon.FieldValuePairs([("tagging_mode", tagging_mode)]) + tbl.set("Vlan" + vlan + "|" + interface, fvs) + time.sleep(1) + +def remove_vlan_member(dvs, vlan, interface): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(conf_db, "VLAN_MEMBER") + tbl._del("Vlan" + vlan + "|" + interface) + time.sleep(1) + +def create_vlan_interface(dvs, vlan_name, ifname, vrf_name, ipaddr): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + # create a vlan member in config db + create_entry_tbl( + conf_db, + "VLAN_MEMBER", '|', "%s|%s" % (vlan_name, ifname), + [ + ("tagging_mode", "untagged"), + ], + ) + + time.sleep(1) + + # create vlan interface in config db + create_entry_tbl( + conf_db, + "VLAN_INTERFACE", '|', vlan_name, + [ + ("vrf_name", vrf_name), + ], + ) + + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + create_entry_pst( + app_db, + "INTF_TABLE", ':', vlan_name, + [ + ("vrf_name", vrf_name), + ], + ) + time.sleep(2) + + create_entry_tbl( + conf_db, + "VLAN_INTERFACE", '|', "%s|%s" % (vlan_name, ipaddr), + [ + ("family", "IPv4"), + ], + ) + + time.sleep(2) + + +def delete_vlan_interface(dvs, ifname, ipaddr): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + delete_entry_tbl(conf_db, "VLAN_INTERFACE", "%s|%s" % (ifname, ipaddr)) + time.sleep(2) + + delete_entry_tbl(conf_db, "VLAN_INTERFACE", ifname) + time.sleep(2) + +def create_evpn_nvo(dvs, nvoname, tnlname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("source_vtep", tnlname), + ] + + # create the VXLAN tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VXLAN_EVPN_NVO", '|', nvoname, + attrs, + ) + +def remove_evpn_nvo(dvs, nvoname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + delete_entry_tbl(conf_db,"VXLAN_EVPN_NVO", nvoname,) + +def create_vxlan_tunnel(dvs, name, src_ip): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("src_ip", src_ip), + ] + + # create the VXLAN tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VXLAN_TUNNEL", '|', name, + attrs, + ) + +def create_vxlan_tunnel_map(dvs, tnlname, mapname, vni_id, vlan_id): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("vni", vni_id), + ("vlan", vlan_id), + ] + + # create the VXLAN tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VXLAN_TUNNEL_MAP", '|', "%s|%s" % (tnlname, mapname), + attrs, + ) + + +def create_vxlan_vrf_tunnel_map(dvs, vrfname, vni_id): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("vni", vni_id), + ] + + # create the VXLAN VRF tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VRF", '|', vrfname, + attrs, + ) + +def remove_vxlan_vrf_tunnel_map(dvs, vrfname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("vni", "0"), + ] + + # remove the VXLAN VRF tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VRF", '|', vrfname, + attrs, + ) + +def create_evpn_remote_vni(dvs, vlan_id, remotevtep, vnid): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + create_entry_pst( + app_db, + "VXLAN_REMOTE_VNI_TABLE", ':', "%s:%s" % (vlan_id, remotevtep), + [ + ("vni", vnid), + ], + ) + time.sleep(2) + +def remove_vxlan_tunnel(dvs, tnlname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + # create the VXLAN tunnel Term entry in Config DB + delete_entry_tbl( + conf_db, + "VXLAN_TUNNEL", tnlname, + ) + +def remove_vxlan_tunnel_map(dvs, tnlname, mapname,vni_id, vlan_id): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("vni", vni_id), + ("vlan", vlan_id), + ] + + # create the VXLAN tunnel Term entry in Config DB + delete_entry_tbl( + conf_db, + "VXLAN_TUNNEL_MAP", "%s|%s" % (tnlname, mapname), + ) + +def remove_evpn_remote_vni(dvs, vlan_id, remotevtep ): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + delete_entry_pst( + app_db, + "VXLAN_REMOTE_VNI_TABLE", "%s:%s" % (vlan_id, remotevtep), + ) + time.sleep(2) + +def create_vlan1(dvs, vlan_name): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + vlan_id = vlan_name[4:] + + # create vlan + create_entry_tbl( + conf_db, + "VLAN", '|', vlan_name, + [ + ("vlanid", vlan_id), + ], + ) + +def get_switch_mac(dvs): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH') + + entries = tbl.getKeys() + mac = None + for entry in entries: + status, fvs = tbl.get(entry) + assert status, "Got an error when get a key" + for key, value in fvs: + if key == 'SAI_SWITCH_ATTR_SRC_MAC_ADDRESS': + mac = value + break + else: + assert False, 'Don\'t found switch mac' + + return mac + +loopback_id = 0 +def_vr_id = 0 +switch_mac = None + + +class VxlanTunnel(object): + + ASIC_TUNNEL_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL" + ASIC_TUNNEL_MAP = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP" + ASIC_TUNNEL_MAP_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_MAP_ENTRY" + ASIC_TUNNEL_TERM_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_TUNNEL_TERM_TABLE_ENTRY" + ASIC_BRIDGE_PORT = "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT" + ASIC_VRF_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER" + ASIC_RIF_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE" + ASIC_ROUTE_ENTRY = "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY" + ASIC_NEXT_HOP = "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP" + ASIC_NEXT_HOP_GRP = "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP" + ASIC_NEXT_HOP_GRP_MEMBERS = "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER" + + tunnel_map_ids = set() + tunnel_map_entry_ids = set() + tunnel_map_vrf_entry_ids = set() + tunnel_ids = set() + tunnel_term_ids = set() + bridgeport_ids = set() + tunnel_map_map = {} + tunnel = {} + tunnelterm = {} + mapentry_map = {} + diptunnel_map = {} + diptunterm_map = {} + diptunstate_map = {} + bridgeport_map = {} + vlan_id_map = {} + vlan_member_map = {} + vr_map = {} + vnet_vr_ids = set() + nh_ids = {} + nh_grp_id = set() + nh_grp_member_id = set() + route_id = {} + + def fetch_exist_entries(self, dvs): + self.tunnel_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_TABLE) + self.tunnel_map_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_MAP) + self.tunnel_map_entry_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_MAP_ENTRY) + self.tunnel_term_ids = get_exist_entries(dvs, self.ASIC_TUNNEL_TERM_ENTRY) + self.bridgeport_ids = get_exist_entries(dvs, self.ASIC_BRIDGE_PORT) + self.vnet_vr_ids = get_exist_entries(dvs, self.ASIC_VRF_TABLE) + self.rifs = get_exist_entries(dvs, self.ASIC_RIF_TABLE) + self.routes = get_exist_entries(dvs, self.ASIC_ROUTE_ENTRY) + self.nhops = get_exist_entries(dvs, self.ASIC_NEXT_HOP) + self.nhop_grp = get_exist_entries(dvs, self.ASIC_NEXT_HOP_GRP) + self.nhop_grp_members = get_exist_entries(dvs, self.ASIC_NEXT_HOP_GRP_MEMBERS) + + global switch_mac + + if switch_mac is None: + switch_mac = get_switch_mac(dvs) + + def check_vxlan_tunnel_map_entry_delete(self, dvs, tunnel_name, vidlist, vnilist): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) + + for x in range(1): + status, fvs = tbl.get(self.mapentry_map[tunnel_name + vidlist[x]]) + assert status == False, "SIP Tunnel Map entry not deleted" + + def check_vxlan_tunnel_vlan_map_entry(self, dvs, tunnel_name, vidlist, vnidlist): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) + + expected_attributes_1 = { + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID', + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': self.tunnel_map_map[tunnel_name][0], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE': vidlist[0], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY': vnidlist[0], + } + + for x in range(1): + expected_attributes_1['SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE'] = vidlist[x] + expected_attributes_1['SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY'] = vnidlist[x] + ret = get_key_with_attr(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, expected_attributes_1) + assert len(ret) > 0, "SIP TunnelMap entry not created" + assert len(ret) == 1, "More than 1 SIP TunnMapEntry created" + self.mapentry_map[tunnel_name + vidlist[x]] = ret[0] + + + def check_vxlan_sip_tunnel_delete(self, dvs, tunnel_name): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_TERM_ENTRY) + status, fvs = tbl.get(self.tunnelterm[tunnel_name]) + assert status == False, "SIP Tunnel Term entry not deleted" + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_TABLE) + status, fvs = tbl.get(self.tunnel[tunnel_name]) + assert status == False, "SIP Tunnel entry not deleted" + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_MAP) + status, fvs = tbl.get(self.tunnel_map_map[tunnel_name][0]) + assert status == False, "SIP Tunnel mapper0 not deleted" + status, fvs = tbl.get(self.tunnel_map_map[tunnel_name][1]) + assert status == False, "SIP Tunnel mapper1 not deleted" + status, fvs = tbl.get(self.tunnel_map_map[tunnel_name][2]) + assert status == False, "SIP Tunnel mapper2 not deleted" + status, fvs = tbl.get(self.tunnel_map_map[tunnel_name][3]) + assert status == False, "SIP Tunnel mapper3 not deleted" + + def check_vxlan_sip_tunnel(self, dvs, tunnel_name, src_ip, vidlist, vnidlist): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tunnel_map_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 4) + tunnel_id = get_created_entry(asic_db, self.ASIC_TUNNEL_TABLE, self.tunnel_ids) + tunnel_term_id = get_created_entry(asic_db, self.ASIC_TUNNEL_TERM_ENTRY, self.tunnel_term_ids) + tunnel_map_entry_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, self.tunnel_map_entry_ids, 3) + + # check that the vxlan tunnel termination are there + assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP) == (len(self.tunnel_map_ids) + 4), "The TUNNEL_MAP wasn't created" + assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) == (len(self.tunnel_map_entry_ids) + 3), "The TUNNEL_MAP_ENTRY is created" + assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_TABLE) == (len(self.tunnel_ids) + 1), "The TUNNEL wasn't created" + assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_TERM_ENTRY) == (len(self.tunnel_term_ids) + 1), "The TUNNEL_TERM_TABLE_ENTRY wasm't created" + + check_object(asic_db, self.ASIC_TUNNEL_MAP, tunnel_map_id[2], + { + 'SAI_TUNNEL_MAP_ATTR_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID', + } + ) + + check_object(asic_db, self.ASIC_TUNNEL_MAP, tunnel_map_id[3], + { + 'SAI_TUNNEL_MAP_ATTR_TYPE': 'SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI', + } + ) + + decapstr = '2:' + tunnel_map_id[0] + ',' + tunnel_map_id[2] + encapstr = '2:' + tunnel_map_id[1] + ',' + tunnel_map_id[3] + + check_object(asic_db, self.ASIC_TUNNEL_TABLE, tunnel_id, + { + 'SAI_TUNNEL_ATTR_TYPE': 'SAI_TUNNEL_TYPE_VXLAN', + 'SAI_TUNNEL_ATTR_DECAP_MAPPERS': decapstr, + 'SAI_TUNNEL_ATTR_ENCAP_MAPPERS': encapstr, + 'SAI_TUNNEL_ATTR_ENCAP_SRC_IP': src_ip, + } + ) + + expected_attributes = { + 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE': 'SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP', + 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP': src_ip, + 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE': 'SAI_TUNNEL_TYPE_VXLAN', + 'SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID': tunnel_id, + } + + check_object(asic_db, self.ASIC_TUNNEL_TERM_ENTRY, tunnel_term_id, expected_attributes) + + expected_attributes_1 = { + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_VLAN_ID', + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[0], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE': vidlist[0], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY': vnidlist[0], + } + + for x in range(1): + expected_attributes_1['SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE'] = vidlist[x] + expected_attributes_1['SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY'] = vnidlist[x] + check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[x], expected_attributes_1) + + self.tunnel_map_ids.update(tunnel_map_id) + self.tunnel_ids.add(tunnel_id) + self.tunnel_term_ids.add(tunnel_term_id) + self.tunnel_map_map[tunnel_name] = tunnel_map_id + self.tunnel[tunnel_name] = tunnel_id + self.tunnelterm[tunnel_name] = tunnel_term_id + + def check_vxlan_dip_tunnel_delete(self, dvs, dip): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(state_db, 'VXLAN_TUNNEL_TABLE') + status, fvs = tbl.get(self.diptunstate_map[dip]) + assert status == False, "State Table entry not deleted" + + tbl = swsscommon.Table(asic_db, self.ASIC_TUNNEL_TABLE) + status, fvs = tbl.get(self.diptunnel_map[dip]) + assert status == False, "Tunnel entry not deleted" + + tbl = swsscommon.Table(asic_db, self.ASIC_BRIDGE_PORT) + status, fvs = tbl.get(self.bridgeport_map[dip]) + assert status == False, "Tunnel bridgeport entry not deleted" + + def check_vxlan_dip_tunnel(self, dvs, vtep_name, src_ip, dip): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + expected_state_attributes = { + 'src_ip': src_ip, + 'dst_ip': dip, + 'tnl_src': 'EVPN', + } + + ret = get_key_with_attr(state_db, 'VXLAN_TUNNEL_TABLE', expected_state_attributes) + assert len(ret) > 0, "Tunnel Statetable entry not created" + assert len(ret) == 1, "More than 1 Tunn statetable entry created" + self.diptunstate_map[dip] = ret[0] + + tunnel_map_id = self.tunnel_map_map[vtep_name] + + decapstr = '2:' + tunnel_map_id[0] + ',' + tunnel_map_id[2] + encapstr = '2:' + tunnel_map_id[1] + ',' + tunnel_map_id[3] + + expected_tun_attributes = { + 'SAI_TUNNEL_ATTR_TYPE': 'SAI_TUNNEL_TYPE_VXLAN', + 'SAI_TUNNEL_ATTR_PEER_MODE': 'SAI_TUNNEL_PEER_MODE_P2P', + 'SAI_TUNNEL_ATTR_DECAP_MAPPERS': decapstr, + 'SAI_TUNNEL_ATTR_ENCAP_MAPPERS': encapstr, + 'SAI_TUNNEL_ATTR_ENCAP_SRC_IP': src_ip, + 'SAI_TUNNEL_ATTR_ENCAP_DST_IP': dip, + } + + ret = get_key_with_attr(asic_db, self.ASIC_TUNNEL_TABLE, expected_tun_attributes) + assert len(ret) > 0, "Tunnel entry not created" + assert len(ret) == 1, "More than 1 tunnel entry created" + + self.diptunnel_map[dip] = ret[0] + tunnel_id = ret[0] + + expected_bridgeport_attributes = { + 'SAI_BRIDGE_PORT_ATTR_TYPE': 'SAI_BRIDGE_PORT_TYPE_TUNNEL', + 'SAI_BRIDGE_PORT_ATTR_TUNNEL_ID': tunnel_id, + 'SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE': 'SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE', + 'SAI_BRIDGE_PORT_ATTR_ADMIN_STATE': 'true', + } + + ret = get_key_with_attr(asic_db, self.ASIC_BRIDGE_PORT, expected_bridgeport_attributes) + assert len(ret) > 0, "Bridgeport entry not created" + assert len(ret) == 1, "More than 1 bridgeport entry created" + + self.bridgeport_map[dip] = ret[0] + + def check_vlan_extension_delete(self, dvs, vlan_name, dip): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER') + status, fvs = tbl.get(self.vlan_member_map[dip+vlan_name]) + assert status == False, "VLAN Member entry not deleted" + + def check_vlan_extension(self, dvs, vlan_name, dip): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + expected_vlan_attributes = { + 'SAI_VLAN_ATTR_VLAN_ID': vlan_name, + } + ret = get_key_with_attr(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VLAN', expected_vlan_attributes) + assert len(ret) > 0, "VLAN entry not created" + assert len(ret) == 1, "More than 1 VLAN entry created" + + self.vlan_id_map[vlan_name] = ret[0] + + expected_vlan_member_attributes = { + 'SAI_VLAN_MEMBER_ATTR_VLAN_ID': self.vlan_id_map[vlan_name], + 'SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID': self.bridgeport_map[dip], + } + ret = get_key_with_attr(asic_db, 'ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER', expected_vlan_member_attributes) + assert len(ret) > 0, "VLAN Member not created" + assert len(ret) == 1, "More than 1 VLAN member created" + self.vlan_member_map[dip+vlan_name] = ret[0] + + def check_vxlan_tunnel_vrf_map_entry(self, dvs, tunnel_name, vrf_name, vni_id): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + if (self.tunnel_map_map.get(tunnel_name) is None): + tunnel_map_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 4) + else: + tunnel_map_id = self.tunnel_map_map[tunnel_name] + + tunnel_map_entry_id = get_created_entries(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, self.tunnel_map_entry_ids, 3) + + # check that the vxlan tunnel termination are there + assert how_many_entries_exist(asic_db, self.ASIC_TUNNEL_MAP_ENTRY) == (len(self.tunnel_map_entry_ids) + 3), "The TUNNEL_MAP_ENTRY is created too early" + + check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[1], + { + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VIRTUAL_ROUTER_ID_TO_VNI', + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[3], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY': self.vr_map[vrf_name].get('ing'), + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE': vni_id, + } + ) + + self.tunnel_map_vrf_entry_ids.update(tunnel_map_entry_id[1]) + + check_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[2], + { + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE': 'SAI_TUNNEL_MAP_TYPE_VNI_TO_VIRTUAL_ROUTER_ID', + 'SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP': tunnel_map_id[2], + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY': vni_id, + 'SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE': self.vr_map[vrf_name].get('egr'), + } + ) + + self.tunnel_map_vrf_entry_ids.update(tunnel_map_entry_id[2]) + self.tunnel_map_entry_ids.update(tunnel_map_entry_id) + + def check_vxlan_tunnel_vrf_map_entry_remove(self, dvs, tunnel_name, vrf_name, vni_id): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tunnel_map_entry_id = get_deleted_entries(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, self.tunnel_map_entry_ids, 2) + check_deleted_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[0]) + check_deleted_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, tunnel_map_entry_id[1]) + for vrf_map_id in self.tunnel_map_vrf_entry_ids: + check_deleted_object(asic_db, self.ASIC_TUNNEL_MAP_ENTRY, vrf_map_id) + + def check_router_interface(self, dvs, name, vlan_oid, route_count): + # Check RIF in ingress VRF + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + global switch_mac + + expected_attr = { + "SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": self.vr_map[name].get('ing'), + "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": switch_mac, + } + + if vlan_oid: + expected_attr.update({'SAI_ROUTER_INTERFACE_ATTR_TYPE': 'SAI_ROUTER_INTERFACE_TYPE_VLAN'}) + expected_attr.update({'SAI_ROUTER_INTERFACE_ATTR_VLAN_ID': vlan_oid}) + else: + expected_attr.update({'SAI_ROUTER_INTERFACE_ATTR_TYPE': 'SAI_ROUTER_INTERFACE_TYPE_PORT'}) + + new_rif = get_created_entry(asic_db, self.ASIC_RIF_TABLE, self.rifs) + check_object(asic_db, self.ASIC_RIF_TABLE, new_rif, expected_attr) + + #IP2ME route will be created with every router interface + new_route = get_created_entries(asic_db, self.ASIC_ROUTE_ENTRY, self.routes, route_count) + + self.rifs.add(new_rif) + self.routes.update(new_route) + + def check_del_router_interface(self, dvs, name): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + old_rif = get_deleted_entries(asic_db, self.ASIC_RIF_TABLE, self.rifs, 1) + check_deleted_object(asic_db, self.ASIC_RIF_TABLE, old_rif[0]) + + self.rifs.remove(old_rif[0]) + + def vrf_route_ids(self, dvs, vrf_name): + vr_set = set() + + vr_set.add(self.vr_map[vrf_name].get('ing')) + return vr_set + + def check_vrf_routes(self, dvs, prefix, vrf_name, endpoint, tunnel, mac="", vni=0, no_update=0): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + vr_ids = self.vrf_route_ids(dvs, vrf_name) + count = len(vr_ids) + + # Check routes in ingress VRF + expected_attr = { + "SAI_NEXT_HOP_ATTR_TYPE": "SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP", + "SAI_NEXT_HOP_ATTR_IP": endpoint, + "SAI_NEXT_HOP_ATTR_TUNNEL_ID": self.tunnel[tunnel], + } + + if vni: + expected_attr.update({'SAI_NEXT_HOP_ATTR_TUNNEL_VNI': vni}) + + if mac: + expected_attr.update({'SAI_NEXT_HOP_ATTR_TUNNEL_MAC': mac}) + + if endpoint in self.nh_ids: + new_nh = self.nh_ids[endpoint] + else: + new_nh = get_created_entry(asic_db, self.ASIC_NEXT_HOP, self.nhops) + self.nh_ids[endpoint] = new_nh + self.nhops.add(new_nh) + + check_object(asic_db, self.ASIC_NEXT_HOP, new_nh, expected_attr) + if no_update: + count = 0 + new_route = get_created_entries(asic_db, self.ASIC_ROUTE_ENTRY, self.routes, count) + + if count: + self.route_id[vrf_name + ":" + prefix] = new_route + + #Check if the route is in expected VRF + asic_vrs = set() + for idx in range(count): + check_object(asic_db, self.ASIC_ROUTE_ENTRY, new_route[idx], + { + "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": new_nh, + } + ) + rt_key = json.loads(new_route[idx]) + asic_vrs.add(rt_key['vr']) + found_route = False + if rt_key['dest'] == prefix: + found_route = True + + assert found_route + + if count: + assert asic_vrs == vr_ids + + self.routes.update(new_route) + + return True + + def check_vrf_routes_ecmp(self, dvs, prefix, vrf_name, tunnel, nh_count, no_update=0): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + vr_ids = self.vrf_route_ids(dvs, vrf_name) + count = len(vr_ids) + + new_nhg = get_created_entry(asic_db, self.ASIC_NEXT_HOP_GRP, self.nhop_grp) + self.nh_grp_id.add(new_nhg) + + if no_update: + count = 0 + + new_route = get_created_entries(asic_db, self.ASIC_ROUTE_ENTRY, self.routes, count) + if count: + self.route_id[vrf_name + ":" + prefix] = new_route + + #Check if the route is in expected VRF + asic_vrs = set() + for idx in range(count): + check_object(asic_db, self.ASIC_ROUTE_ENTRY, new_route[idx], + { + "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": new_nhg, + } + ) + rt_key = json.loads(new_route[idx]) + asic_vrs.add(rt_key['vr']) + + found_route = False + if rt_key['dest'] == prefix: + found_route = True + + assert found_route + + if count: + assert asic_vrs == vr_ids + + self.routes.update(new_route) + + new_nhg_members = get_created_entries(asic_db, self.ASIC_NEXT_HOP_GRP_MEMBERS, self.nhop_grp_members, nh_count) + + for idx in range(nh_count): + self.nh_grp_member_id.add(new_nhg_members[idx]) + check_object(asic_db, self.ASIC_NEXT_HOP_GRP_MEMBERS, new_nhg_members[idx], + { + "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": new_nhg, + } + ) + + nhid_list = list() + + nhg_member_tbl = swsscommon.Table(asic_db, self.ASIC_NEXT_HOP_GRP_MEMBERS) + + for k in new_nhg_members: + (status, fvs) = nhg_member_tbl.get(k) + assert status + + for v in fvs: + if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID": + nhid = v[1] + nhid_list.append(nhid) + + return nhid_list + + def check_add_tunnel_nexthop(self, dvs, nh_id, endpoint, tunnel, mac, vni): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + # Check routes in ingress VRF + expected_attr = { + "SAI_NEXT_HOP_ATTR_TYPE": "SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP", + "SAI_NEXT_HOP_ATTR_IP": endpoint, + "SAI_NEXT_HOP_ATTR_TUNNEL_ID": self.tunnel[tunnel], + "SAI_NEXT_HOP_ATTR_TUNNEL_VNI": vni, + "SAI_NEXT_HOP_ATTR_TUNNEL_MAC": mac, + } + + check_object(asic_db, self.ASIC_NEXT_HOP, nh_id, expected_attr) + + def check_del_tunnel_nexthop(self, dvs, vrf_name, endpoint, tunnel, mac="", vni=0): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + del_nh_ids = get_deleted_entries(asic_db, self.ASIC_NEXT_HOP, self.nhops, 1) + check_deleted_object(asic_db, self.ASIC_NEXT_HOP, del_nh_ids[0]) + check_deleted_object(asic_db, self.ASIC_NEXT_HOP, self.nh_ids[endpoint]) + assert del_nh_ids[0] == self.nh_ids[endpoint] + self.nh_ids.pop(endpoint) + return True + + def check_vrf_routes_ecmp_nexthop_grp_del(self, dvs, nh_count): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + nh_grp_id_len = len(self.nh_grp_id) + assert nh_grp_id_len == 1 + + for nh_grp_id in self.nh_grp_id: + check_deleted_object(asic_db, self.ASIC_NEXT_HOP_GRP, nh_grp_id) + self.nh_grp_id.clear() + + nh_grp_member_id_len = len(self.nh_grp_member_id) + assert nh_grp_member_id_len == nh_count + + for nh_grp_member_id in self.nh_grp_member_id: + check_deleted_object(asic_db, self.ASIC_NEXT_HOP_GRP_MEMBERS, nh_grp_member_id) + + self.nh_grp_member_id.clear() + + def check_del_vrf_routes(self, dvs, prefix, vrf_name): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + del_route = get_deleted_entries(asic_db, self.ASIC_ROUTE_ENTRY, self.routes, 1) + + for idx in range(1): + rt_key = json.loads(del_route[idx]) + found_route = False + if rt_key['dest'] == prefix: + found_route = True + + assert found_route + + check_deleted_object(asic_db, self.ASIC_ROUTE_ENTRY, self.route_id[vrf_name + ":" + prefix]) + self.route_id.clear() + + return True + + def create_vrf(self, dvs, vrf_name): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + + tbl = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER") + initial_entries = set(tbl.getKeys()) + + attrs = [ + ("vni", "0"), + ] + tbl = swsscommon.Table(conf_db, "VRF") + fvs = swsscommon.FieldValuePairs(attrs) + tbl.set(vrf_name, fvs) + time.sleep(2) + + tbl = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER") + current_entries = set(tbl.getKeys()) + assert len(current_entries - initial_entries) == 1 + + new_vr_ids = get_created_entries(asic_db, self.ASIC_VRF_TABLE, self.vnet_vr_ids, 1) + self.vnet_vr_ids.update(new_vr_ids) + self.vr_map[vrf_name] = { 'ing':new_vr_ids[0], 'egr':new_vr_ids[0]} + + return list(current_entries - initial_entries)[0] + + def remove_vrf(self, dvs, vrf_name): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(conf_db, "VRF") + tbl._del(vrf_name) + time.sleep(2) + + + def is_vrf_attributes_correct(self, db, table, key, expected_attributes): + tbl = swsscommon.Table(db, table) + keys = set(tbl.getKeys()) + assert key in keys, "The created key wasn't found" + + status, fvs = tbl.get(key) + assert status, "Got an error when get a key" + + # filter the fake 'NULL' attribute out + fvs = filter(lambda x : x != ('NULL', 'NULL'), fvs) + + attr_keys = {entry[0] for entry in fvs} + assert attr_keys == set(expected_attributes.keys()) + + for name, value in fvs: + assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \ + (value, name, expected_attributes[name]) + + +class TestL3Vxlan(object): + + def get_vxlan_obj(self): + return VxlanTunnel() + + def setup_db(self, dvs): + self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) + self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + +# Test 1 - Create and Delete SIP Tunnel and VRF VNI Map entries +# @pytest.mark.skip(reason="Starting Route Orch, VRF Orch to be merged") +# @pytest.mark.dev_sanity + def test_sip_tunnel_vrf_vni_map(self, dvs, testlog): + vxlan_obj = self.get_vxlan_obj() + + self.setup_db(dvs) + tunnel_name = 'tunnel_2' + map_name = 'map_1000_100' + vrf_map_name = 'evpn_map_1000_Vrf-RED' + + vxlan_obj.fetch_exist_entries(dvs) + + print ("\n\nTesting Create and Delete SIP Tunnel and VRF VNI Map entries") + print ("\tCreate SIP Tunnel") + create_vlan1(dvs,"Vlan100") + create_vxlan_tunnel(dvs, tunnel_name, '6.6.6.6') + create_evpn_nvo(dvs, 'nvo1', tunnel_name) + + print ("\tCreate Vlan-VNI map and VRF-VNI map") + create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + + vxlan_obj.create_vrf(dvs, "Vrf-RED") + create_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED', '1000') + + print ("\tTesting VRF-VNI map in APP DB") + vlanlist = ['100'] + vnilist = ['1000'] + + exp_attrs = [ + ("vni", "1000"), + ] + exp_attr = {} + for an in range(len(exp_attrs)): + exp_attr[exp_attrs[an][0]] = exp_attrs[an][1] + + check_object(self.pdb, "VRF_TABLE", 'Vrf-RED', exp_attr) + + exp_attrs1 = [ + ("vni", "1000"), + ("vlan", "Vlan100"), + ] + exp_attr1 = {} + for an in range(len(exp_attrs1)): + exp_attr1[exp_attrs1[an][0]] = exp_attrs1[an][1] + + check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) + + print ("\tTesting SIP Tunnel Creation") + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + + print ("\tTesting Tunnel Vlan VNI Map Entry") + vxlan_obj.check_vxlan_tunnel_vlan_map_entry(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting Tunnel VRF VNI Map Entry") + vxlan_obj.check_vxlan_tunnel_vrf_map_entry(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting Tunnel VRF VNI Map Entry removal") + remove_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED') + vxlan_obj.remove_vrf(dvs, "Vrf-RED") + vxlan_obj.check_vxlan_tunnel_vrf_map_entry_remove(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting Tunnel Vlan VNI Map entry removal") + remove_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + vxlan_obj.check_vxlan_tunnel_map_entry_delete(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting SIP Tunnel Deletion") + remove_vxlan_tunnel(dvs, tunnel_name) + remove_evpn_nvo(dvs, 'nvo1') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name) + remove_vlan(dvs, "100") + + +# Test 2 - Create and Delete DIP Tunnel on adding and removing prefix route +# @pytest.mark.skip(reason="Starting Route Orch, VRF Orch to be merged") +# @pytest.mark.dev_sanity + def test_prefix_route_create_dip_tunnel(self, dvs, testlog): + vxlan_obj = self.get_vxlan_obj() + + self.setup_db(dvs) + tunnel_name = 'tunnel_2' + map_name = 'map_1000_100' + vrf_map_name = 'evpn_map_1000_Vrf-RED' + vxlan_obj.fetch_exist_entries(dvs) + + print ("\n\nTesting Create and Delete DIP Tunnel on adding and removing prefix route") + print ("\tCreate SIP Tunnel") + vlan_ids = get_exist_entries(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + vlan_oid = create_vlan(dvs,"Vlan100", vlan_ids) + create_vxlan_tunnel(dvs, tunnel_name, '6.6.6.6') + create_evpn_nvo(dvs, 'nvo1', tunnel_name) + + print ("\tCreate Vlan-VNI map and VRF-VNI map") + create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + + print ("\tTesting VRF-VNI map in APP DB") + vxlan_obj.create_vrf(dvs, "Vrf-RED") + create_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED', '1000') + + vlanlist = ['100'] + vnilist = ['1000'] + + exp_attrs = [ + ("vni", "1000"), + ] + exp_attr = {} + for an in range(len(exp_attrs)): + exp_attr[exp_attrs[an][0]] = exp_attrs[an][1] + + check_object(self.pdb, "VRF_TABLE", 'Vrf-RED', exp_attr) + + exp_attrs1 = [ + ("vni", "1000"), + ("vlan", "Vlan100"), + ] + exp_attr1 = {} + for an in range(len(exp_attrs1)): + exp_attr1[exp_attrs1[an][0]] = exp_attrs1[an][1] + + check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) + + print ("\tTesting SIP Tunnel Creation") + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + + print ("\tTesting Tunnel Vlan Map Entry") + vxlan_obj.check_vxlan_tunnel_vlan_map_entry(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting Tunnel Vrf Map Entry") + vxlan_obj.check_vxlan_tunnel_vrf_map_entry(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting VLAN 100 interface creation") + create_vlan_interface(dvs, "Vlan100", "Ethernet24", "Vrf-RED", "100.100.3.1/24") + vxlan_obj.check_router_interface(dvs, 'Vrf-RED', vlan_oid, 2) + + print ("\tTest VRF IPv4 Route with Tunnel Nexthop Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTesting DIP tunnel 7.7.7.7 creation") + vxlan_obj.check_vxlan_dip_tunnel(dvs, tunnel_name, '6.6.6.6', '7.7.7.7') + + print ("\tTest VRF IPv4 Route with Tunnel Nexthop Delete") + delete_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + print ("\tTesting DIP tunnel 7.7.7.7 deletion") + vxlan_obj.check_vxlan_dip_tunnel_delete(dvs, '7.7.7.7') + + print ("\tTesting Tunnel Vrf Map Entry removal") + remove_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED') + vxlan_obj.check_vxlan_tunnel_vrf_map_entry_remove(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting Vlan 100 interface delete") + delete_vlan_interface(dvs, "Vlan100", "100.100.3.1/24") + vxlan_obj.check_del_router_interface(dvs, "Vlan100") + + print ("\tTesting Tunnel Map entry removal") + remove_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + vxlan_obj.check_vxlan_tunnel_map_entry_delete(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting SIP Tunnel Deletion") + remove_vxlan_tunnel(dvs, tunnel_name) + remove_evpn_nvo(dvs, 'nvo1') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name) + vxlan_obj.remove_vrf(dvs, "Vrf-RED") + remove_vlan_member(dvs, "100", "Ethernet24") + remove_vlan(dvs, "100") + + +# Test 3 - Create and Delete DIP Tunnel and Test IPv4 route and overlay nexthop add and delete +# @pytest.mark.skip(reason="Starting Route Orch, VRF Orch to be merged") +# @pytest.mark.dev_sanity + def test_dip_tunnel_ipv4_routes(self, dvs, testlog): + vxlan_obj = self.get_vxlan_obj() + + self.setup_db(dvs) + tunnel_name = 'tunnel_2' + map_name = 'map_1000_100' + vrf_map_name = 'evpn_map_1000_Vrf-RED' + vxlan_obj.fetch_exist_entries(dvs) + + print ("\n\nTesting IPv4 Route and Overlay Nexthop Add and Delete") + print ("\tCreate SIP Tunnel") + create_vlan1(dvs,"Vlan100") + create_vxlan_tunnel(dvs, tunnel_name, '6.6.6.6') + create_evpn_nvo(dvs, 'nvo1', tunnel_name) + + print ("\tCreate Vlan-VNI map and VRF-VNI map") + create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + + vxlan_obj.create_vrf(dvs, "Vrf-RED") + create_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED', '1000') + + print ("\tTesting VRF-VNI map in APP DB") + vlanlist = ['100'] + vnilist = ['1000'] + + exp_attrs = [ + ("vni", "1000"), + ] + exp_attr = {} + for an in range(len(exp_attrs)): + exp_attr[exp_attrs[an][0]] = exp_attrs[an][1] + + check_object(self.pdb, "VRF_TABLE", 'Vrf-RED', exp_attr) + + exp_attrs1 = [ + ("vni", "1000"), + ("vlan", "Vlan100"), + ] + exp_attr1 = {} + for an in range(len(exp_attrs1)): + exp_attr1[exp_attrs1[an][0]] = exp_attrs1[an][1] + + check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) + + print ("\tTesting SIP Tunnel Creation") + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + + print ("\tTesting Tunnel Vlan Map Entry") + vxlan_obj.check_vxlan_tunnel_vlan_map_entry(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting Tunnel Vrf Map Entry") + vxlan_obj.check_vxlan_tunnel_vrf_map_entry(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting First DIP tunnel creation to 7.7.7.7") + create_evpn_remote_vni(dvs, 'Vlan100', '7.7.7.7', '1000') + vxlan_obj.check_vxlan_dip_tunnel(dvs, tunnel_name, '6.6.6.6', '7.7.7.7') + + print ("\tTesting VLAN 100 extension") + vxlan_obj.check_vlan_extension(dvs, '100', '7.7.7.7') + + print ("\tTesting Second DIP tunnel creation to 8.8.8.8") + create_evpn_remote_vni(dvs, 'Vlan100', '8.8.8.8', '1000') + vxlan_obj.check_vxlan_dip_tunnel(dvs, tunnel_name, '6.6.6.6', '8.8.8.8') + + print ("\tTesting VLAN 100 extension to 8.8.8.8 and 7.7.7.7") + vxlan_obj.check_vlan_extension(dvs, '100', '8.8.8.8') + vxlan_obj.check_vlan_extension(dvs, '100', '7.7.7.7') + + print ("\tTesting VLAN 100 interface creation") + create_vlan_interface(dvs, "Vlan100", "Ethernet24", "Vrf-RED", "100.100.3.1/24") + vxlan_obj.check_router_interface(dvs, 'Vrf-RED', vxlan_obj.vlan_id_map['100'], 2) + + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 7.7.7.7 Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 7.7.7.7 Delete") + delete_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + print ("\n\nTesting IPv4 Route and Overlay Nexthop Update") + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 7.7.7.7 Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest Tunnel Nexthop change from 7.7.7.7 to 8.8.8.8") + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '8.8.8.8', "Vlan100", "00:22:22:22:22:22", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000', 1) + + print ("\tTest Previous Tunnel Nexthop 7.7.7.7 is removed") + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest VRF IPv4 Route and Tunnel Nexthop 8.8.8.8 Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + print ("\n\nTest VRF IPv4 Route with ECMP Tunnel Nexthop Add and Delete") + vxlan_obj.fetch_exist_entries(dvs) + + ecmp_nexthop_attr = [ + ("nexthop", "7.7.7.7,8.8.8.8"), + ("ifname", "Vlan100,Vlan100"), + ("vni_label", "1000,1000"), + ("router_mac", "00:11:11:11:11:11,00:22:22:22:22:22"), + ] + + print ("\tTest VRF IPv4 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Add") + create_vrf_routes_ecmp(dvs, "80.80.1.0/24", 'Vrf-RED', ecmp_nexthop_attr) + + nh_count = 2 + ecmp_nhid_list = vxlan_obj.check_vrf_routes_ecmp(dvs, "80.80.1.0/24", 'Vrf-RED', tunnel_name, nh_count) + assert nh_count == len(ecmp_nhid_list) + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[0], '7.7.7.7', tunnel_name, '00:11:11:11:11:11', '1000') + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[1], '8.8.8.8', tunnel_name, '00:22:22:22:22:22', '1000') + + print ("\tTest VRF IPv4 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + check_deleted_object(self.adb, vxlan_obj.ASIC_NEXT_HOP, ecmp_nhid_list[0]) + check_deleted_object(self.adb, vxlan_obj.ASIC_NEXT_HOP, ecmp_nhid_list[1]) + + vxlan_obj.check_vrf_routes_ecmp_nexthop_grp_del(dvs, 2) + vxlan_obj.check_del_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + print ("\n\nTest VRF IPv4 Route with Tunnel Nexthop update from non-ECMP to ECMP") + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 7.7.7.7 Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + ecmp_nexthop_attr = [ + ("nexthop", "7.7.7.7,8.8.8.8"), + ("ifname", "Vlan100,Vlan100"), + ("vni_label", "1000,1000"), + ("router_mac", "00:11:11:11:11:11,00:22:22:22:22:22"), + ] + + print ("\tTest VRF IPv4 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Udpate") + create_vrf_routes_ecmp(dvs, "80.80.1.0/24", 'Vrf-RED', ecmp_nexthop_attr) + + nh_count = 2 + ecmp_nhid_list = vxlan_obj.check_vrf_routes_ecmp(dvs, "80.80.1.0/24", 'Vrf-RED', tunnel_name, nh_count, 1) + assert nh_count == len(ecmp_nhid_list) + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[0], '7.7.7.7', tunnel_name, '00:11:11:11:11:11', '1000') + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[1], '8.8.8.8', tunnel_name, '00:22:22:22:22:22', '1000') + + print ("\n\nTest VRF IPv4 Route with Tunnel Nexthop update from ECMP to non-ECMP") + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 8.8.8.8 Update") + create_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '8.8.8.8', "Vlan100", "00:22:22:22:22:22", '1000') + vxlan_obj.check_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000', 1) + + print ("\tTest Tunnel Nexthop 7.7.7.7 is deleted") + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest Tunnel Nexthop ECMP Group is deleted") + vxlan_obj.check_vrf_routes_ecmp_nexthop_grp_del(dvs, 2) + + print ("\tTest VRF IPv4 Route with Tunnel Nexthop 8.8.8.8 Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "80.80.1.0/24", 'Vrf-RED') + + print ("\n\nTest DIP and SIP Tunnel Deletion ") + print ("\tTesting Tunnel Vrf VNI Map Entry removal") + remove_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED') + vxlan_obj.check_vxlan_tunnel_vrf_map_entry_remove(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting LastVlan removal and DIP tunnel delete for 7.7.7.7") + remove_evpn_remote_vni(dvs, 'Vlan100', '7.7.7.7') + vxlan_obj.check_vlan_extension_delete(dvs, '100', '7.7.7.7') + vxlan_obj.check_vxlan_dip_tunnel_delete(dvs, '7.7.7.7') + + print ("\tTesting LastVlan removal and DIP tunnel delete for 8.8.8.8") + remove_evpn_remote_vni(dvs, 'Vlan100', '8.8.8.8') + vxlan_obj.check_vlan_extension_delete(dvs, '100', '8.8.8.8') + vxlan_obj.check_vxlan_dip_tunnel_delete(dvs, '8.8.8.8') + + print ("\tTesting Vlan 100 interface delete") + delete_vlan_interface(dvs, "Vlan100", "100.100.3.1/24") + vxlan_obj.check_del_router_interface(dvs, "Vlan100") + + print ("\tTesting Tunnel Map entry removal") + remove_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + vxlan_obj.check_vxlan_tunnel_map_entry_delete(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting SIP Tunnel Deletion") + remove_vxlan_tunnel(dvs, tunnel_name) + remove_evpn_nvo(dvs, 'nvo1') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name) + vxlan_obj.remove_vrf(dvs, "Vrf-RED") + remove_vlan_member(dvs, "100", "Ethernet24") + remove_vlan(dvs, "100") + + +# Test 4 - Create and Delete DIP Tunnel and Test IPv6 route and overlay nexthop add and delete +# @pytest.mark.skip(reason="Starting Route Orch, VRF Orch to be merged") +# @pytest.mark.dev_sanity + def test_dip_tunnel_ipv6_routes(self, dvs, testlog): + vxlan_obj = self.get_vxlan_obj() + + self.setup_db(dvs) + tunnel_name = 'tunnel_2' + map_name = 'map_1000_100' + vrf_map_name = 'evpn_map_1000_Vrf-RED' + vxlan_obj.fetch_exist_entries(dvs) + + print ("\n\nTesting IPv6 Route and Overlay Nexthop Add and Delete") + print ("\tCreate SIP Tunnel") + create_vlan1(dvs,"Vlan100") + create_vxlan_tunnel(dvs, tunnel_name, '6.6.6.6') + create_evpn_nvo(dvs, 'nvo1', tunnel_name) + + print ("\tCreate Vlan-VNI map and VRF-VNI map") + create_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + + print ("\tTesting VRF-VNI map in APP DB") + vxlan_obj.create_vrf(dvs, "Vrf-RED") + create_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED', '1000') + + vlanlist = ['100'] + vnilist = ['1000'] + + exp_attrs = [ + ("vni", "1000"), + ] + exp_attr = {} + for an in range(len(exp_attrs)): + exp_attr[exp_attrs[an][0]] = exp_attrs[an][1] + + print ("\tCheck VRF Table in APP DB") + check_object(self.pdb, "VRF_TABLE", 'Vrf-RED', exp_attr) + + exp_attrs1 = [ + ("vni", "1000"), + ("vlan", "Vlan100"), + ] + exp_attr1 = {} + for an in range(len(exp_attrs1)): + exp_attr1[exp_attrs1[an][0]] = exp_attrs1[an][1] + + check_object(self.pdb, "VXLAN_VRF_TABLE", "%s:%s" % (tunnel_name, vrf_map_name), exp_attr1) + + print ("\tTesting SIP Tunnel Creation") + vxlan_obj.check_vxlan_sip_tunnel(dvs, tunnel_name, '6.6.6.6', vlanlist, vnilist) + + print ("\tTesting Tunnel Vlan Map Entry") + vxlan_obj.check_vxlan_tunnel_vlan_map_entry(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting Tunnel Vrf Map Entry") + vxlan_obj.check_vxlan_tunnel_vrf_map_entry(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting First DIP tunnel creation to 7.7.7.7") + create_evpn_remote_vni(dvs, 'Vlan100', '7.7.7.7', '1000') + vxlan_obj.check_vxlan_dip_tunnel(dvs, tunnel_name, '6.6.6.6', '7.7.7.7') + + print ("\tTesting VLAN 100 extension") + vxlan_obj.check_vlan_extension(dvs, '100', '7.7.7.7') + + print ("\tTesting Second DIP tunnel creation to 8.8.8.8") + create_evpn_remote_vni(dvs, 'Vlan100', '8.8.8.8', '1000') + vxlan_obj.check_vxlan_dip_tunnel(dvs, tunnel_name, '6.6.6.6', '8.8.8.8') + + print ("\tTesting VLAN 100 extension to 8.8.8.8 and 7.7.7.7") + vxlan_obj.check_vlan_extension(dvs, '100', '8.8.8.8') + vxlan_obj.check_vlan_extension(dvs, '100', '7.7.7.7') + + vxlan_obj.fetch_exist_entries(dvs) + print ("\tTesting VLAN 100 interface creation") + create_vlan_interface(dvs, "Vlan100", "Ethernet24", "Vrf-RED", "2001::8/64") + vxlan_obj.check_router_interface(dvs, 'Vrf-RED', vxlan_obj.vlan_id_map['100'], 2) + + print ("\tTest VRF IPv6 Route with Tunnel Nexthop Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest VRF IPv6 Route with Tunnel Nexthop Delete") + delete_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + + print ("\n\nTesting IPv6 Route and Overlay Nexthop Update") + print ("\tTest VRF IPv6 Route with Tunnel Nexthop 7.7.7.7 Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest Tunnel Nexthop change from 7.7.7.7 to 8.8.8.8") + create_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '8.8.8.8', "Vlan100", "00:22:22:22:22:22", '1000') + vxlan_obj.check_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000', 1) + + print ("\tTest Previous Tunnel Nexthop 7.7.7.7 is removed") + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest VRF IPv6 Route and Tunnel Nexthop 8.8.8.8 Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + + print ("\n\nTest VRF IPv6 Route with ECMP Tunnel Nexthop Add and delete") + vxlan_obj.fetch_exist_entries(dvs) + + ecmp_nexthop_attr = [ + ("nexthop", "7.7.7.7,8.8.8.8"), + ("ifname", "Vlan100,Vlan100"), + ("vni_label", "1000,1000"), + ("router_mac", "00:11:11:11:11:11,00:22:22:22:22:22"), + ] + + print ("\tTest VRF IPv6 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Add") + create_vrf_routes_ecmp(dvs, "2002::8/64", 'Vrf-RED', ecmp_nexthop_attr) + + nh_count = 2 + ecmp_nhid_list = vxlan_obj.check_vrf_routes_ecmp(dvs, "2002::8/64", 'Vrf-RED', tunnel_name, nh_count) + assert nh_count == len(ecmp_nhid_list) + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[0], '7.7.7.7', tunnel_name, '00:11:11:11:11:11', '1000') + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[1], '8.8.8.8', tunnel_name, '00:22:22:22:22:22', '1000') + + print ("\tTest VRF IPv6 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + check_deleted_object(self.adb, vxlan_obj.ASIC_NEXT_HOP, ecmp_nhid_list[0]) + check_deleted_object(self.adb, vxlan_obj.ASIC_NEXT_HOP, ecmp_nhid_list[1]) + + vxlan_obj.check_vrf_routes_ecmp_nexthop_grp_del(dvs, 2) + vxlan_obj.check_del_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + + print ("\n\nTest VRF IPv6 Route with Tunnel Nexthop update from non-ECMP to ECMP") + print ("\tTest VRF IPv6 Route with Tunnel Nexthop 7.7.7.7 Add") + vxlan_obj.fetch_exist_entries(dvs) + create_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', "Vlan100", "00:11:11:11:11:11", '1000') + vxlan_obj.check_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest VRF IPv4 Route with ECMP Tunnel Nexthop [7.7.7.7 , 8.8.8.8] Udpate") + ecmp_nexthop_attr = [ + ("nexthop", "7.7.7.7,8.8.8.8"), + ("ifname", "Vlan100,Vlan100"), + ("vni_label", "1000,1000"), + ("router_mac", "00:11:11:11:11:11,00:22:22:22:22:22"), + ] + + create_vrf_routes_ecmp(dvs, "2002::8/64", 'Vrf-RED', ecmp_nexthop_attr) + + nh_count = 2 + ecmp_nhid_list = vxlan_obj.check_vrf_routes_ecmp(dvs, "2002::8/64", 'Vrf-RED', tunnel_name, nh_count, 1) + assert nh_count == len(ecmp_nhid_list) + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[0], '7.7.7.7', tunnel_name, '00:11:11:11:11:11', '1000') + vxlan_obj.check_add_tunnel_nexthop(dvs, ecmp_nhid_list[1], '8.8.8.8', tunnel_name, '00:22:22:22:22:22', '1000') + + print ("\n\nTest VRF IPv6 Route with Tunnel Nexthop update from ECMP to non-ECMP") + print ("\tTest VRF IPv6 Route with Tunnel Nexthop 8.8.8.8 Update") + create_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '8.8.8.8', "Vlan100", "00:22:22:22:22:22", '1000') + vxlan_obj.check_vrf_routes(dvs, "2002::8/64", 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000', 1) + + print ("\tTest Tunnel Nexthop 7.7.7.7 is deleted") + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '7.7.7.7', tunnel_name, "00:11:11:11:11:11", '1000') + + print ("\tTest Tunnel Nexthop ECMP Group is deleted") + vxlan_obj.check_vrf_routes_ecmp_nexthop_grp_del(dvs, 2) + + print ("\tTest VRF IPv6 Route with Tunnel Nexthop 8.8.8.8 Delete") + vxlan_obj.fetch_exist_entries(dvs) + delete_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + + vxlan_obj.check_del_tunnel_nexthop(dvs, 'Vrf-RED', '8.8.8.8', tunnel_name, "00:22:22:22:22:22", '1000') + vxlan_obj.check_del_vrf_routes(dvs, "2002::8/64", 'Vrf-RED') + + print ("\n\nTest DIP and SIP Tunnel Deletion ") + print ("\tTesting Tunnel Vrf Map Entry removal") + remove_vxlan_vrf_tunnel_map(dvs, 'Vrf-RED') + vxlan_obj.check_vxlan_tunnel_vrf_map_entry_remove(dvs, tunnel_name, 'Vrf-RED', '1000') + + print ("\tTesting LastVlan removal and DIP tunnel delete for 7.7.7.7") + remove_evpn_remote_vni(dvs, 'Vlan100', '7.7.7.7') + vxlan_obj.check_vlan_extension_delete(dvs, '100', '7.7.7.7') + vxlan_obj.check_vxlan_dip_tunnel_delete(dvs, '7.7.7.7') + + print ("\tTesting LastVlan removal and DIP tunnel delete for 8.8.8.8") + remove_evpn_remote_vni(dvs, 'Vlan100', '8.8.8.8') + vxlan_obj.check_vlan_extension_delete(dvs, '100', '8.8.8.8') + vxlan_obj.check_vxlan_dip_tunnel_delete(dvs, '8.8.8.8') + + print ("\tTesting Vlan 100 interface delete") + delete_vlan_interface(dvs, "Vlan100", "2001::8/64") + vxlan_obj.check_del_router_interface(dvs, "Vlan100") + + print ("\tTesting Tunnel Map entry removal") + remove_vxlan_tunnel_map(dvs, tunnel_name, map_name, '1000', 'Vlan100') + vxlan_obj.check_vxlan_tunnel_map_entry_delete(dvs, tunnel_name, vlanlist, vnilist) + + print ("\tTesting SIP Tunnel Deletion") + remove_vxlan_tunnel(dvs, tunnel_name) + remove_evpn_nvo(dvs, 'nvo1') + vxlan_obj.check_vxlan_sip_tunnel_delete(dvs, tunnel_name) + vxlan_obj.remove_vrf(dvs, "Vrf-RED") + remove_vlan_member(dvs, "100", "Ethernet24") + remove_vlan(dvs, "100") + + +# 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 diff --git a/tests/test_fdbsync.py b/tests/test_fdbsync.py new file mode 100644 index 0000000000..ee86c8616d --- /dev/null +++ b/tests/test_fdbsync.py @@ -0,0 +1,420 @@ +import time +import json +import pytest +import pdb + +from swsscommon import swsscommon + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + time.sleep(1) + +def create_entry_tbl(db, table, separator, key, pairs): + tbl = swsscommon.Table(db, table) + create_entry(tbl, key, pairs) + +def delete_entry_tbl(db, table, key): + tbl = swsscommon.Table(db, table) + tbl._del(key) + time.sleep(1) + +def create_evpn_nvo(dvs, nvoname, tnlname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + + attrs = [ + ("source_vtep", tnlname), + ] + + # create the VXLAN tunnel Term entry in Config DB + create_entry_tbl( + conf_db, + "VXLAN_EVPN_NVO", '|', nvoname, + attrs, + ) + +def remove_evpn_nvo(dvs, nvoname): + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + delete_entry_tbl(conf_db, "VXLAN_EVPN_NVO", nvoname, ) + +def set_admin_status(dvs, interface, status): + tbl = swsscommon.Table(dvs.cdb, "PORT") + fvs = swsscommon.FieldValuePairs([("admin_status", status)]) + tbl.set(interface, fvs) + time.sleep(1) + +tunnel_name = 'vxlan' +tunnel_vlan = 'Vlan20' +tunnel_device = 'vxlan-20' +tunnel_vlan_id = '20' +tunnel_vni = '10020' +tunnel_src_ip = '12.1.1.1' +tunnel_remote_ip = '10.0.0.7' +tunnel_remote_fdb = '00:11:01:00:00:01' +tunnel_remote_fdb2 = '12:34:55:12:34:56' +tunnel_remote_fdb_type = 'dynamic' +tunnel_remote_fdb_type_static = 'static' +state_db_name = 'FDB_TABLE' +local_intf = 'Ethernet8' +local_intf2 = 'Ethernet12' +tunnel_name_nvo = 'nvo' +app_fdb_name = '_VXLAN_FDB_TABLE:' +tunnel_remote_imet = '00:00:00:00:00:00' +tunnel_remote_imet_type = 'permanent' +app_imet_name = 'VXLAN_REMOTE_VNI_TABLE:' + +class TestFdbsync(object): + + + def test_AddLocalFDB(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo , tunnel_name) + + set_admin_status(dvs, local_intf, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + # check that the FDB entries were inserted into State DB + ok, extra = dvs.is_table_entry_exists(dvs.sdb, state_db_name, + tunnel_vlan + ":.*", + [("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + assert ok, str(extra) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb + " | wc -l"]) + num = int(output.strip()) + assert num == 1 + + delete_entry_tbl( + dvs.sdb, + state_db_name, tunnel_vlan + ':' + tunnel_remote_fdb, + ) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert output == '' + remove_evpn_nvo(dvs, tunnel_name_nvo) + + def test_AddLocalFDBWithOutNVO(self, dvs, testlog): + dvs.setup_db() + set_admin_status(dvs, local_intf, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb ]) + assert output == '' + + delete_entry_tbl( + dvs.sdb, + state_db_name, tunnel_vlan + ':' + tunnel_remote_fdb, + ) + + def test_AddLocalFDBPortUpdate(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + set_admin_status(dvs, local_intf, "up") + set_admin_status(dvs, local_intf2, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + dvs.create_vlan_member(tunnel_vlan_id, local_intf2) + + #pdb.set_trace() + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb + " | wc -l"]) + num = int(output.strip()) + assert num == 1 + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert local_intf in output + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf2), + ("type", tunnel_remote_fdb_type), + ] + ) + # check that the FDB entries were inserted into State DB + ok, extra = dvs.is_table_entry_exists(dvs.sdb, state_db_name, + tunnel_vlan + ":.*", + [("port", local_intf2), + ("type", tunnel_remote_fdb_type), + ] + ) + assert ok, str(extra) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb + " | wc -l"]) + num = int(output.strip()) + assert num == 1 + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert local_intf2 in output + + + delete_entry_tbl( + dvs.sdb, + state_db_name, tunnel_vlan + ':' + tunnel_remote_fdb, + ) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert output == '' + remove_evpn_nvo(dvs, tunnel_name_nvo) + + def test_AddLocalStaticFDB(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + set_admin_status(dvs, local_intf, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type_static), + ] + ) + + # check that the FDB entries were inserted into State DB + ok, extra = dvs.is_table_entry_exists(dvs.sdb, state_db_name, + tunnel_vlan + ":.*", + [("port", local_intf), + ("type", tunnel_remote_fdb_type_static), + ] + ) + assert ok, str(extra) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb + " | wc -l"]) + num = int(output.strip()) + assert num == 1 + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert tunnel_remote_fdb_type_static in output + + delete_entry_tbl( + dvs.sdb, + state_db_name, tunnel_vlan + ':' + tunnel_remote_fdb, + ) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb]) + assert output == '' + remove_evpn_nvo(dvs, tunnel_name_nvo) + + def test_AddVxlanFDB(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + dvs.runcmd("ip link add {} type vxlan id {} local {}".format(tunnel_device, tunnel_vni, tunnel_src_ip)) + dvs.runcmd("ip link set up {}".format(tunnel_device)) + dvs.runcmd("bridge fdb add {} dev {} dst {} self {}".format(tunnel_remote_fdb2, tunnel_device, tunnel_remote_ip, tunnel_remote_fdb_type_static)) + + # Check in the APP DB for the FDB entry to be present APP_VXLAN_FDB_TABLE_NAME "APP_VXLAN_FDB_TABLE_NAME" + # check application database + tbl = swsscommon.Table(dvs.pdb, app_fdb_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == tunnel_remote_fdb2 + (status, fvs) = tbl.get(intf_entries[0]) + assert status == True + assert len(fvs) == 3 + for fv in fvs: + if fv[0] == "remote_vtep": + assert fv[1] == tunnel_remote_ip + elif fv[0] == "type": + assert fv[1] == tunnel_remote_fdb_type_static + elif fv[0] == "vni": + assert fv[1] == tunnel_vni + else: + assert False + + # Remove the fdb entry, and check the APP_DB + dvs.runcmd("bridge fdb del {} dev {} dst {} self {}".format(tunnel_remote_fdb2, tunnel_device, tunnel_remote_ip, tunnel_remote_fdb_type_static)) + ebl = swsscommon.Table(dvs.pdb, app_fdb_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + + def test_AddVxlanIMET(self, dvs, testlog): + + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + dvs.runcmd("ip link add {} type vxlan id {} local {}".format(tunnel_device, tunnel_vni, tunnel_src_ip)) + dvs.runcmd("ip link set up {}".format(tunnel_device)) + dvs.runcmd("bridge fdb add {} dev {} dst {} self {}".format(tunnel_remote_imet, tunnel_device, tunnel_remote_ip, tunnel_remote_imet_type)) + + # Check in the APP DB for the FDB entry to be present APP_VXLAN_FDB_TABLE_NAME "APP_VXLAN_FDB_TABLE_NAME" + # check application database + tbl = swsscommon.Table(dvs.pdb, app_imet_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == tunnel_remote_ip + (status, fvs) = tbl.get(intf_entries[0]) + assert status == True + assert len(fvs) == 1 + for fv in fvs: + if fv[0] == "vni": + assert fv[1] == tunnel_vni + else: + assert False + + # Remove the fdb entry, and check the APP_DB + dvs.runcmd("bridge fdb del {} dev {} dst {} self {}".format(tunnel_remote_imet, tunnel_device, tunnel_remote_ip, tunnel_remote_imet_type)) + tbl = swsscommon.Table(dvs.pdb, app_imet_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 0 + + def test_VxlanFDBToLocal(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + dvs.runcmd("ip link add {} type vxlan id {} local {}".format(tunnel_device, tunnel_vni, tunnel_src_ip)) + dvs.runcmd("ip link set up {}".format(tunnel_device)) + dvs.runcmd("bridge fdb add {} dev {} dst {} self {}".format(tunnel_remote_fdb2, tunnel_device, tunnel_remote_ip, tunnel_remote_fdb_type)) + + # Check in the APP DB for the FDB entry to be present APP_VXLAN_FDB_TABLE_NAME "APP_VXLAN_FDB_TABLE_NAME" + # check application database + tbl = swsscommon.Table(dvs.pdb, app_fdb_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == tunnel_remote_fdb2 + (status, fvs) = tbl.get(intf_entries[0]) + assert status == True + assert len(fvs) == 3 + for fv in fvs: + if fv[0] == "remote_vtep": + assert fv[1] == tunnel_remote_ip + elif fv[0] == "type": + assert fv[1] == tunnel_remote_fdb_type + elif fv[0] == "vni": + assert fv[1] == tunnel_vni + else: + assert False + + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + set_admin_status(dvs, local_intf, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb2, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + # check that the FDB entries were inserted into State DB + ok, extra = dvs.is_table_entry_exists(dvs.sdb, state_db_name, + tunnel_vlan + ":.*", + [("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + assert ok, str(extra) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb2 + " | grep Ethernet8 | wc -l"]) + num = int(output.strip()) + assert num == 1 + + delete_entry_tbl( + dvs.sdb, + state_db_name, tunnel_vlan + ':' + tunnel_remote_fdb2, + ) + + def test_LocalFDBToVxlan(self, dvs, testlog): + dvs.setup_db() + create_evpn_nvo(dvs, tunnel_name_nvo, tunnel_name) + + set_admin_status(dvs, local_intf, "up") + + # create vlan; create vlan member + dvs.create_vlan(tunnel_vlan_id) + dvs.create_vlan_member(tunnel_vlan_id, local_intf) + + create_entry_tbl( + dvs.sdb, + state_db_name, '|', tunnel_vlan + ':' + tunnel_remote_fdb, + [ + ("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + # check that the FDB entries were inserted into State DB + ok, extra = dvs.is_table_entry_exists(dvs.sdb, state_db_name, + tunnel_vlan + ":.*", + [("port", local_intf), + ("type", tunnel_remote_fdb_type), + ] + ) + assert ok, str(extra) + + (exitcode, output) = dvs.runcmd(['sh', '-c', "bridge fdb show | grep " + tunnel_remote_fdb + " | wc -l"]) + num = int(output.strip()) + assert num == 1 + + #pdb.set_trace() + dvs.runcmd("ip link add {} type vxlan id {} local {}".format(tunnel_device, tunnel_vni, tunnel_src_ip)) + dvs.runcmd("ip link set up {}".format(tunnel_device)) + dvs.runcmd("bridge fdb add {} dev {} dst {} self {}".format(tunnel_remote_fdb, tunnel_device, tunnel_remote_ip, tunnel_remote_fdb_type)) + + # Check in the APP DB for the FDB entry to be present APP_VXLAN_FDB_TABLE_NAME "APP_VXLAN_FDB_TABLE_NAME" + # check application database + tbl = swsscommon.Table(dvs.pdb, app_fdb_name+tunnel_vlan) + intf_entries = tbl.getKeys() + assert len(intf_entries) == 1 + assert intf_entries[0] == tunnel_remote_fdb + (status, fvs) = tbl.get(intf_entries[0]) + assert status == True + assert len(fvs) == 3 + for fv in fvs: + if fv[0] == "remote_vtep": + assert fv[1] == tunnel_remote_ip + elif fv[0] == "type": + assert fv[1] == tunnel_remote_fdb_type + elif fv[0] == "vni": + assert fv[1] == tunnel_vni + else: + assert False + diff --git a/tests/test_nat.py b/tests/test_nat.py index 6f8606d67b..2c76e153c5 100644 --- a/tests/test_nat.py +++ b/tests/test_nat.py @@ -2,6 +2,10 @@ from dvslib.dvs_common import wait_for_result +L3_TABLE_TYPE = "L3" +L3_TABLE_NAME = "L3_TEST" +L3_BIND_PORTS = ["Ethernet0"] +L3_RULE_NAME = "L3_TEST_RULE" class TestNat(object): def setup_db(self, dvs): @@ -320,6 +324,35 @@ def _check_conntrack_for_static_entry(): # delete a static nat entry dvs.runcmd("config nat remove static basic 67.66.65.1 18.18.18.2") + def test_DoNotNatAclAction(self, dvs_acl, testlog): + + # Creating the ACL Table + dvs_acl.create_acl_table(L3_TABLE_NAME, L3_TABLE_TYPE, L3_BIND_PORTS, stage="ingress") + + acl_table_id = dvs_acl.get_acl_table_ids(1)[0] + acl_table_group_ids = dvs_acl.get_acl_table_group_ids(len(L3_BIND_PORTS)) + + dvs_acl.verify_acl_table_group_members(acl_table_id, acl_table_group_ids, 1) + dvs_acl.verify_acl_table_port_binding(acl_table_id, L3_BIND_PORTS, 1) + + # Create a ACL Rule with "do_not_nat" packet action + config_qualifiers = {"SRC_IP": "14.1.0.1/32"} + dvs_acl.create_acl_rule(L3_TABLE_NAME, L3_RULE_NAME, config_qualifiers, action="DO_NOT_NAT", priority="97") + + expected_sai_qualifiers = { + "SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP": dvs_acl.get_simple_qualifier_comparator("14.1.0.1&mask:255.255.255.255") + } + + dvs_acl.verify_nat_acl_rule(expected_sai_qualifiers, priority="97") + + # Deleting the ACL Rule + dvs_acl.remove_acl_rule(L3_TABLE_NAME, L3_RULE_NAME) + dvs_acl.verify_no_acl_rules() + + # Deleting the ACL Table + dvs_acl.remove_acl_table(L3_TABLE_NAME) + dvs_acl.verify_acl_table_count(0) + # Add Dummy always-pass test at end as workaroud # for issue when Flaky fail on final test it invokes module tear-down before retrying