Skip to content

Commit c20321c

Browse files
authored
[meta] Allow objects with the same key exist on different switches (#865)
Signed-off-by: kcudnik <[email protected]>
1 parent 216e549 commit c20321c

10 files changed

+141
-6
lines changed

meta/AttrKeyMap.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ bool AttrKeyMap::attrKeyExists(
5353
}
5454

5555
std::string AttrKeyMap::constructKey(
56+
_In_ sai_object_id_t switchId,
5657
_In_ const sai_object_meta_key_t& metaKey,
5758
_In_ uint32_t attrCount,
5859
_In_ const sai_attribute_t* attrList)
5960
{
6061
SWSS_LOG_ENTER();
6162

63+
if (switchId == SAI_NULL_OBJECT_ID)
64+
{
65+
SWSS_LOG_THROW("switchId is NULL for %s",
66+
sai_serialize_object_meta_key(metaKey).c_str());
67+
}
68+
6269
// Use map to make sure that keys will be always sorted by attr id.
6370

6471
std::map<int32_t, std::string> keys;
@@ -133,7 +140,9 @@ std::string AttrKeyMap::constructKey(
133140
keys[md->attrid] = name;
134141
}
135142

136-
std::string key;
143+
// switch ID is added, since same key pattern is allowed on different switch objects
144+
145+
std::string key = sai_serialize_object_id(switchId) + ";";
137146

138147
for (auto& k: keys)
139148
{

meta/AttrKeyMap.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace saimeta
3636
* @brief Construct key based on attributes marked as keys.
3737
*/
3838
static std::string constructKey(
39+
_In_ sai_object_id_t switchId,
3940
_In_ const sai_object_meta_key_t& metaKey,
4041
_In_ uint32_t attrCount,
4142
_In_ const sai_attribute_t* attrList);

meta/Meta.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -5052,7 +5052,7 @@ sai_status_t Meta::meta_generic_validation_create(
50525052

50535053
if (haskeys)
50545054
{
5055-
std::string key = AttrKeyMap::constructKey(meta_key, attr_count, attr_list);
5055+
std::string key = AttrKeyMap::constructKey(switch_id, meta_key, attr_count, attr_list);
50565056

50575057
// since we didn't created oid yet, we don't know if attribute key exists, check all
50585058
if (m_attrKeys.attrKeyExists(key))
@@ -6951,7 +6951,7 @@ void Meta::meta_generic_validation_post_create(
69516951
{
69526952
auto mKey = sai_serialize_object_meta_key(meta_key);
69536953

6954-
auto attrKey = AttrKeyMap::constructKey(meta_key, attr_count, attr_list);
6954+
auto attrKey = AttrKeyMap::constructKey(switch_id, meta_key, attr_count, attr_list);
69556955

69566956
m_attrKeys.insert(mKey, attrKey);
69576957
}
@@ -7914,7 +7914,9 @@ void Meta::populate(
79147914
{
79157915
auto mKey = sai_serialize_object_meta_key(mk);
79167916

7917-
auto attrKey = AttrKeyMap::constructKey(mk, attr_count, attr_list);
7917+
auto switchId = switchIdQuery(mk.objectkey.key.object_id);
7918+
7919+
auto attrKey = AttrKeyMap::constructKey(switchId, mk, attr_count, attr_list);
79187920

79197921
m_attrKeys.insert(mKey, attrKey);
79207922
}

meta/tests.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2956,11 +2956,13 @@ void test_construct_key()
29562956

29572957
meta_key.objecttype = SAI_OBJECT_TYPE_PORT;
29582958

2959-
std::string key = AttrKeyMap::constructKey(meta_key, 1, &attr);
2959+
sai_object_id_t switchId = 0x21000000000000;
2960+
2961+
std::string key = AttrKeyMap::constructKey(switchId, meta_key, 1, &attr);
29602962

29612963
SWSS_LOG_NOTICE("constructed key: %s", key.c_str());
29622964

2963-
META_ASSERT_TRUE(key == "SAI_PORT_ATTR_HW_LANE_LIST:1,2,3,4;");
2965+
META_ASSERT_TRUE(key == "oid:0x21000000000000;SAI_PORT_ATTR_HW_LANE_LIST:1,2,3,4;");
29642966
}
29652967

29662968
static sai_object_id_t create_scheduler_group(

tests/BCM56850.pl

+8
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,16 @@ sub test_ignore_attributes
688688
play "ignore_attributes.rec";
689689
}
690690

691+
sub test_multi_switch_key
692+
{
693+
fresh_start("-p", "$utils::DIR/vsprofile_ctx_multi.ini", "-g", "0", "-x", "$utils::DIR/ctx_multi.json");
694+
695+
play("-p", "$utils::DIR/vsprofile_ctx_multi.ini", "multi_switch_key.rec");
696+
}
697+
691698
# RUN TESTS
692699

700+
test_multi_switch_key;
693701
test_ignore_attributes;
694702
test_sairedis_client;
695703
test_macsec_p2p_establishment;

tests/BCM56850/ctx_multi.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"CONTEXTS": [
3+
{
4+
"guid" : 0,
5+
"name" : "syncd",
6+
"dbAsic" : "ASIC_DB",
7+
"dbCounters" : "COUNTERS_DB",
8+
"dbFlex": "FLEX_COUNTER_DB",
9+
"dbState" : "STATE_DB",
10+
"zmq_enable": false,
11+
"zmq_endpoint": "tcp://127.0.0.1:5555",
12+
"zmq_ntf_endpoint": "tcp://127.0.0.1:5556",
13+
"switches": [
14+
{
15+
"index" : 0,
16+
"hwinfo" : ""
17+
},
18+
{
19+
"index" : 1,
20+
"hwinfo" : "1"
21+
}
22+
]
23+
}
24+
]
25+
}

tests/BCM56850/lanemap_multi.ini

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
; comment
2+
# comment
3+
eth0:29,30,31,32
4+
eth1:25,26,27,28
5+
eth2:37,38,39,40
6+
eth3:33,34,35,36
7+
eth4:41,42,43,44
8+
eth5:45,46,47,48
9+
eth6:5,6,7,8
10+
eth7:1,2,3,4
11+
eth8:9,10,11,12
12+
eth9:13,14,15,16
13+
eth10:21,22,23,24
14+
eth11:17,18,19,20
15+
eth12:249,50,51,52
16+
eth13:353,54,55,56
17+
eth14:461,62,63,64
18+
eth15:557,58,59,60
19+
eth16:665,66,67,68
20+
eth17:769,70,71,72
21+
eth18:877,78,79,80
22+
eth19:973,74,75,76
23+
eth20:105,106,107,108
24+
eth21:109,110,111,112
25+
eth22:117,118,119,120
26+
eth23:113,114,115,116
27+
eth24:121,122,123,124
28+
eth25:125,126,127,128
29+
eth26:85,86,87,88
30+
eth27:81,82,83,84
31+
eth28:89,90,91,92
32+
eth29:93,94,95,96
33+
eth30:97,98,99,100
34+
eth31:101,102,103,104
35+
1:ethx0:29,30,31,32
36+
1:ethx1:25,26,27,28
37+
1:ethx2:37,38,39,40
38+
1:ethx3:33,34,35,36
39+
1:ethx4:41,42,43,44
40+
1:ethx5:45,46,47,48
41+
1:ethx6:5,6,7,8
42+
1:ethx7:1,2,3,4
43+
1:ethx8:9,10,11,12
44+
1:ethx9:13,14,15,16
45+
1:ethx10:21,22,23,24
46+
1:ethx11:17,18,19,20
47+
1:ethx12:249,50,51,52
48+
1:ethx13:353,54,55,56
49+
1:ethx14:461,62,63,64
50+
1:ethx15:557,58,59,60
51+
1:ethx16:665,66,67,68
52+
1:ethx17:769,70,71,72
53+
1:ethx18:877,78,79,80
54+
1:ethx19:973,74,75,76
55+
1:ethx20:105,106,107,108
56+
1:ethx21:109,110,111,112
57+
1:ethx22:117,118,119,120
58+
1:ethx23:113,114,115,116
59+
1:ethx24:121,122,123,124
60+
1:ethx25:125,126,127,128
61+
1:ethx26:85,86,87,88
62+
1:ethx27:81,82,83,84
63+
1:ethx28:89,90,91,92
64+
1:ethx29:93,94,95,96
65+
1:ethx30:97,98,99,100
66+
1:ethx31:101,102,103,104

tests/BCM56850/multi_switch_key.rec

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2020-06-08.18:03:22.457728|a|INIT_VIEW
2+
2020-06-08.18:03:22.459307|A|SAI_STATUS_SUCCESS
3+
2020-06-08.18:03:22.481256|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true
4+
2020-06-08.18:03:22.485235|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x0
5+
2020-06-08.18:03:24.753799|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x3000000000022
6+
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
7+
2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2
8+
2020-06-08.18:03:33.803112|c|SAI_OBJECT_TYPE_VLAN:oid:0x1260000000005d2|SAI_VLAN_ATTR_VLAN_ID=2
9+
2020-06-08.18:03:22.461844|a|APPLY_VIEW
10+
2020-06-08.18:03:22.463034|A|SAI_STATUS_SUCCESS
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SAI_WARM_BOOT_READ_FILE=./sai_warmboot.bin
2+
SAI_WARM_BOOT_WRITE_FILE=./sai_warmboot.bin
3+
SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850
4+
SAI_VS_INTERFACE_LANE_MAP_FILE=BCM56850/lanemap_multi.ini
5+
SAI_REDIS_CONTEXT_CONFIG=BCM56850/ctx_multi.json

vslib/src/Sai.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ sai_status_t Sai::initialize(
218218
sc->m_useTapDevice = useTapDevice;
219219
sc->m_laneMap = m_laneMapContainer->getLaneMap(sc->m_switchIndex);
220220

221+
if (sc->m_laneMap == nullptr)
222+
{
223+
SWSS_LOG_WARN("lane map for switch index %u is empty, loading default map (may have ifname conflict)", sc->m_switchIndex);
224+
225+
sc->m_laneMap = LaneMap::getDefaultLaneMap(sc->m_switchIndex);
226+
}
227+
221228
if (m_fabricLaneMapContainer)
222229
{
223230
sc->m_fabricLaneMap = m_fabricLaneMapContainer->getLaneMap(sc->m_switchIndex);

0 commit comments

Comments
 (0)