Skip to content

Commit

Permalink
[meta] Allow objects with the same key exist on different switches (#865
Browse files Browse the repository at this point in the history
)

Signed-off-by: kcudnik <kcudnik@gmail.com>
  • Loading branch information
kcudnik authored Jul 21, 2021
1 parent 216e549 commit c20321c
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 6 deletions.
11 changes: 10 additions & 1 deletion meta/AttrKeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t, std::string> keys;
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions meta/AttrKeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions meta/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions tests/BCM56850.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions tests/BCM56850/ctx_multi.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
66 changes: 66 additions & 0 deletions tests/BCM56850/lanemap_multi.ini
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/BCM56850/multi_switch_key.rec
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/BCM56850/vsprofile_ctx_multi.ini
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions vslib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c20321c

Please sign in to comment.