diff --git a/meta/AttrKeyMap.cpp b/meta/AttrKeyMap.cpp index 7d74aa1f49ce..e4e3412e0ed1 100644 --- a/meta/AttrKeyMap.cpp +++ b/meta/AttrKeyMap.cpp @@ -53,12 +53,19 @@ bool AttrKeyMap::attrKeyExists( } std::string AttrKeyMap::constructKey( + _In_ sai_object_id_t switchId, _In_ const sai_object_meta_key_t& metaKey, _In_ uint32_t attrCount, _In_ const sai_attribute_t* attrList) { SWSS_LOG_ENTER(); + if (switchId == SAI_NULL_OBJECT_ID) + { + SWSS_LOG_THROW("switchId is NULL for %s", + sai_serialize_object_meta_key(metaKey).c_str()); + } + // Use map to make sure that keys will be always sorted by attr id. std::map keys; @@ -133,7 +140,9 @@ std::string AttrKeyMap::constructKey( keys[md->attrid] = name; } - std::string key; + // switch ID is added, since same key pattern is allowed on different switch objects + + std::string key = sai_serialize_object_id(switchId) + ";"; for (auto& k: keys) { diff --git a/meta/AttrKeyMap.h b/meta/AttrKeyMap.h index 4b60eff672c3..35775de183e6 100644 --- a/meta/AttrKeyMap.h +++ b/meta/AttrKeyMap.h @@ -36,6 +36,7 @@ namespace saimeta * @brief Construct key based on attributes marked as keys. */ static std::string constructKey( + _In_ sai_object_id_t switchId, _In_ const sai_object_meta_key_t& metaKey, _In_ uint32_t attrCount, _In_ const sai_attribute_t* attrList); diff --git a/meta/Meta.cpp b/meta/Meta.cpp index 8cc5afd669af..f84e4391111e 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -5052,7 +5052,7 @@ sai_status_t Meta::meta_generic_validation_create( if (haskeys) { - std::string key = AttrKeyMap::constructKey(meta_key, attr_count, attr_list); + std::string key = AttrKeyMap::constructKey(switch_id, meta_key, attr_count, attr_list); // since we didn't created oid yet, we don't know if attribute key exists, check all if (m_attrKeys.attrKeyExists(key)) @@ -6951,7 +6951,7 @@ void Meta::meta_generic_validation_post_create( { auto mKey = sai_serialize_object_meta_key(meta_key); - auto attrKey = AttrKeyMap::constructKey(meta_key, attr_count, attr_list); + auto attrKey = AttrKeyMap::constructKey(switch_id, meta_key, attr_count, attr_list); m_attrKeys.insert(mKey, attrKey); } @@ -7914,7 +7914,9 @@ void Meta::populate( { auto mKey = sai_serialize_object_meta_key(mk); - auto attrKey = AttrKeyMap::constructKey(mk, attr_count, attr_list); + auto switchId = switchIdQuery(mk.objectkey.key.object_id); + + auto attrKey = AttrKeyMap::constructKey(switchId, mk, attr_count, attr_list); m_attrKeys.insert(mKey, attrKey); } diff --git a/meta/tests.cpp b/meta/tests.cpp index 6ed3fe77836f..432fe1219281 100644 --- a/meta/tests.cpp +++ b/meta/tests.cpp @@ -2956,11 +2956,13 @@ void test_construct_key() meta_key.objecttype = SAI_OBJECT_TYPE_PORT; - std::string key = AttrKeyMap::constructKey(meta_key, 1, &attr); + sai_object_id_t switchId = 0x21000000000000; + + std::string key = AttrKeyMap::constructKey(switchId, meta_key, 1, &attr); SWSS_LOG_NOTICE("constructed key: %s", key.c_str()); - META_ASSERT_TRUE(key == "SAI_PORT_ATTR_HW_LANE_LIST:1,2,3,4;"); + META_ASSERT_TRUE(key == "oid:0x21000000000000;SAI_PORT_ATTR_HW_LANE_LIST:1,2,3,4;"); } static sai_object_id_t create_scheduler_group( diff --git a/tests/BCM56850.pl b/tests/BCM56850.pl index c541891c2c0d..34941ddd4965 100755 --- a/tests/BCM56850.pl +++ b/tests/BCM56850.pl @@ -688,8 +688,16 @@ sub test_ignore_attributes play "ignore_attributes.rec"; } +sub test_multi_switch_key +{ + fresh_start("-p", "$utils::DIR/vsprofile_ctx_multi.ini", "-g", "0", "-x", "$utils::DIR/ctx_multi.json"); + + play("-p", "$utils::DIR/vsprofile_ctx_multi.ini", "multi_switch_key.rec"); +} + # RUN TESTS +test_multi_switch_key; test_ignore_attributes; test_sairedis_client; test_macsec_p2p_establishment; diff --git a/tests/BCM56850/ctx_multi.json b/tests/BCM56850/ctx_multi.json new file mode 100644 index 000000000000..fcbfdab385b4 --- /dev/null +++ b/tests/BCM56850/ctx_multi.json @@ -0,0 +1,25 @@ +{ + "CONTEXTS": [ + { + "guid" : 0, + "name" : "syncd", + "dbAsic" : "ASIC_DB", + "dbCounters" : "COUNTERS_DB", + "dbFlex": "FLEX_COUNTER_DB", + "dbState" : "STATE_DB", + "zmq_enable": false, + "zmq_endpoint": "tcp://127.0.0.1:5555", + "zmq_ntf_endpoint": "tcp://127.0.0.1:5556", + "switches": [ + { + "index" : 0, + "hwinfo" : "" + }, + { + "index" : 1, + "hwinfo" : "1" + } + ] + } + ] +} diff --git a/tests/BCM56850/lanemap_multi.ini b/tests/BCM56850/lanemap_multi.ini new file mode 100644 index 000000000000..6762b7ac8ba4 --- /dev/null +++ b/tests/BCM56850/lanemap_multi.ini @@ -0,0 +1,66 @@ +; comment +# comment +eth0:29,30,31,32 +eth1:25,26,27,28 +eth2:37,38,39,40 +eth3:33,34,35,36 +eth4:41,42,43,44 +eth5:45,46,47,48 +eth6:5,6,7,8 +eth7:1,2,3,4 +eth8:9,10,11,12 +eth9:13,14,15,16 +eth10:21,22,23,24 +eth11:17,18,19,20 +eth12:249,50,51,52 +eth13:353,54,55,56 +eth14:461,62,63,64 +eth15:557,58,59,60 +eth16:665,66,67,68 +eth17:769,70,71,72 +eth18:877,78,79,80 +eth19:973,74,75,76 +eth20:105,106,107,108 +eth21:109,110,111,112 +eth22:117,118,119,120 +eth23:113,114,115,116 +eth24:121,122,123,124 +eth25:125,126,127,128 +eth26:85,86,87,88 +eth27:81,82,83,84 +eth28:89,90,91,92 +eth29:93,94,95,96 +eth30:97,98,99,100 +eth31:101,102,103,104 +1:ethx0:29,30,31,32 +1:ethx1:25,26,27,28 +1:ethx2:37,38,39,40 +1:ethx3:33,34,35,36 +1:ethx4:41,42,43,44 +1:ethx5:45,46,47,48 +1:ethx6:5,6,7,8 +1:ethx7:1,2,3,4 +1:ethx8:9,10,11,12 +1:ethx9:13,14,15,16 +1:ethx10:21,22,23,24 +1:ethx11:17,18,19,20 +1:ethx12:249,50,51,52 +1:ethx13:353,54,55,56 +1:ethx14:461,62,63,64 +1:ethx15:557,58,59,60 +1:ethx16:665,66,67,68 +1:ethx17:769,70,71,72 +1:ethx18:877,78,79,80 +1:ethx19:973,74,75,76 +1:ethx20:105,106,107,108 +1:ethx21:109,110,111,112 +1:ethx22:117,118,119,120 +1:ethx23:113,114,115,116 +1:ethx24:121,122,123,124 +1:ethx25:125,126,127,128 +1:ethx26:85,86,87,88 +1:ethx27:81,82,83,84 +1:ethx28:89,90,91,92 +1:ethx29:93,94,95,96 +1:ethx30:97,98,99,100 +1:ethx31:101,102,103,104 diff --git a/tests/BCM56850/multi_switch_key.rec b/tests/BCM56850/multi_switch_key.rec new file mode 100644 index 000000000000..6593e8ecdc5e --- /dev/null +++ b/tests/BCM56850/multi_switch_key.rec @@ -0,0 +1,10 @@ +2020-06-08.18:03:22.457728|a|INIT_VIEW +2020-06-08.18:03:22.459307|A|SAI_STATUS_SUCCESS +2020-06-08.18:03:22.481256|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true +2020-06-08.18:03:22.485235|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x0 +2020-06-08.18:03:24.753799|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x3000000000022 +2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_SWITCH:oid:0x121000000000001|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO=1:49 +2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2 +2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x1260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2 +2020-06-08.18:03:22.461844|a|APPLY_VIEW +2020-06-08.18:03:22.463034|A|SAI_STATUS_SUCCESS diff --git a/tests/BCM56850/vsprofile_ctx_multi.ini b/tests/BCM56850/vsprofile_ctx_multi.ini new file mode 100644 index 000000000000..6387f130b706 --- /dev/null +++ b/tests/BCM56850/vsprofile_ctx_multi.ini @@ -0,0 +1,5 @@ +SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin +SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin +SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850 +SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap_multi.ini +SAI_REDIS_CONTEXT_CONFIG=BCM56850/ctx_multi.json diff --git a/vslib/src/Sai.cpp b/vslib/src/Sai.cpp index 605991172b78..855938a3ff92 100644 --- a/vslib/src/Sai.cpp +++ b/vslib/src/Sai.cpp @@ -218,6 +218,13 @@ sai_status_t Sai::initialize( sc->m_useTapDevice = useTapDevice; sc->m_laneMap = m_laneMapContainer->getLaneMap(sc->m_switchIndex); + if (sc->m_laneMap == nullptr) + { + SWSS_LOG_WARN("lane map for switch index %u is empty, loading default map (may have ifname conflict)", sc->m_switchIndex); + + sc->m_laneMap = LaneMap::getDefaultLaneMap(sc->m_switchIndex); + } + if (m_fabricLaneMapContainer) { sc->m_fabricLaneMap = m_fabricLaneMapContainer->getLaneMap(sc->m_switchIndex);