|
| 1 | +#include "SwitchBCM56850.h" |
| 2 | + |
| 3 | +#include "meta/sai_serialize.h" |
| 4 | + |
| 5 | +#include <gtest/gtest.h> |
| 6 | + |
| 7 | +using namespace saivs; |
| 8 | + |
| 9 | +TEST(SwitchBCM56850, ctr) |
| 10 | +{ |
| 11 | + auto sc = std::make_shared<SwitchConfig>(0, ""); |
| 12 | + auto signal = std::make_shared<Signal>(); |
| 13 | + auto eventQueue = std::make_shared<EventQueue>(signal); |
| 14 | + |
| 15 | + sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU; |
| 16 | + sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850; |
| 17 | + sc->m_bootType = SAI_VS_BOOT_TYPE_COLD; |
| 18 | + sc->m_useTapDevice = false; |
| 19 | + sc->m_laneMap = LaneMap::getDefaultLaneMap(0); |
| 20 | + sc->m_eventQueue = eventQueue; |
| 21 | + |
| 22 | + auto scc = std::make_shared<SwitchConfigContainer>(); |
| 23 | + |
| 24 | + scc->insert(sc); |
| 25 | + |
| 26 | + SwitchBCM56850 sw( |
| 27 | + 0x2100000000, |
| 28 | + std::make_shared<RealObjectIdManager>(0, scc), |
| 29 | + sc); |
| 30 | + |
| 31 | + SwitchBCM56850 sw2( |
| 32 | + 0x2100000000, |
| 33 | + std::make_shared<RealObjectIdManager>(0, scc), |
| 34 | + sc, |
| 35 | + nullptr); |
| 36 | + |
| 37 | + sai_attribute_t attr; |
| 38 | + |
| 39 | + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; |
| 40 | + attr.value.booldata = true; |
| 41 | + |
| 42 | + EXPECT_EQ(sw.initialize_default_objects(1, &attr), SAI_STATUS_SUCCESS); |
| 43 | +} |
| 44 | + |
| 45 | +TEST(SwitchBCM56850, refresh_bridge_port_list) |
| 46 | +{ |
| 47 | + auto sc = std::make_shared<SwitchConfig>(0, ""); |
| 48 | + auto signal = std::make_shared<Signal>(); |
| 49 | + auto eventQueue = std::make_shared<EventQueue>(signal); |
| 50 | + |
| 51 | + sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU; |
| 52 | + sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850; |
| 53 | + sc->m_bootType = SAI_VS_BOOT_TYPE_COLD; |
| 54 | + sc->m_useTapDevice = false; |
| 55 | + sc->m_laneMap = LaneMap::getDefaultLaneMap(0); |
| 56 | + sc->m_eventQueue = eventQueue; |
| 57 | + |
| 58 | + auto scc = std::make_shared<SwitchConfigContainer>(); |
| 59 | + |
| 60 | + scc->insert(sc); |
| 61 | + |
| 62 | + SwitchBCM56850 sw( |
| 63 | + 0x2100000000, |
| 64 | + std::make_shared<RealObjectIdManager>(0, scc), |
| 65 | + sc); |
| 66 | + |
| 67 | + sai_attribute_t attr; |
| 68 | + |
| 69 | + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; |
| 70 | + attr.value.booldata = true; |
| 71 | + |
| 72 | + EXPECT_EQ(sw.initialize_default_objects(1, &attr), SAI_STATUS_SUCCESS); |
| 73 | + |
| 74 | + attr.id = SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID; |
| 75 | + attr.value.oid = SAI_NULL_OBJECT_ID; |
| 76 | + |
| 77 | + EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_SWITCH, "oid:0x2100000000", 1, &attr), SAI_STATUS_SUCCESS); |
| 78 | + |
| 79 | + EXPECT_NE(attr.value.oid, SAI_NULL_OBJECT_ID); |
| 80 | + |
| 81 | + auto boid = attr.value.oid; |
| 82 | + |
| 83 | + auto sboid = sai_serialize_object_id(boid); |
| 84 | + |
| 85 | + sai_object_id_t list[128]; |
| 86 | + |
| 87 | + attr.id = SAI_BRIDGE_ATTR_PORT_LIST; |
| 88 | + |
| 89 | + attr.value.objlist.count = 128; |
| 90 | + attr.value.objlist.list = list; |
| 91 | + |
| 92 | + EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_BRIDGE, sboid, 1, &attr), SAI_STATUS_SUCCESS); |
| 93 | + |
| 94 | + //std::cout << sw.dump_switch_database_for_warm_restart(); |
| 95 | +} |
| 96 | + |
| 97 | +static std::map<sai_object_id_t, WarmBootState> g_warmBootState; |
| 98 | +// TODO move to utils |
| 99 | +static bool getWarmBootState( |
| 100 | + _In_ const char* warmBootFile, |
| 101 | + _In_ std::shared_ptr<RealObjectIdManager> roidm) |
| 102 | +{ |
| 103 | + SWSS_LOG_ENTER(); |
| 104 | + |
| 105 | + std::ifstream ifs; |
| 106 | + |
| 107 | + ifs.open(warmBootFile); |
| 108 | + |
| 109 | + if (!ifs.is_open()) |
| 110 | + { |
| 111 | + SWSS_LOG_ERROR("failed to open: %s", warmBootFile); |
| 112 | + |
| 113 | + return false; |
| 114 | + } |
| 115 | + |
| 116 | + std::string line; |
| 117 | + |
| 118 | + while (std::getline(ifs, line)) |
| 119 | + { |
| 120 | + SWSS_LOG_DEBUG("line: %s", line.c_str()); |
| 121 | + |
| 122 | + // line format: OBJECT_TYPE OBJECT_ID ATTR_ID ATTR_VALUE |
| 123 | + std::istringstream iss(line); |
| 124 | + |
| 125 | + std::string strObjectType; |
| 126 | + std::string strObjectId; |
| 127 | + std::string strAttrId; |
| 128 | + std::string strAttrValue; |
| 129 | + |
| 130 | + iss >> strObjectType >> strObjectId; |
| 131 | + |
| 132 | + if (strObjectType == SAI_VS_FDB_INFO) |
| 133 | + { |
| 134 | + /* |
| 135 | + * If we read line from fdb info set and use tap device is enabled |
| 136 | + * just parse line and repopulate fdb info set. |
| 137 | + */ |
| 138 | + |
| 139 | + FdbInfo fi = FdbInfo::deserialize(strObjectId); |
| 140 | + |
| 141 | + auto switchId = roidm->switchIdQuery(fi.m_portId); |
| 142 | + |
| 143 | + if (switchId == SAI_NULL_OBJECT_ID) |
| 144 | + { |
| 145 | + SWSS_LOG_ERROR("switchIdQuery returned NULL on fi.m_port = %s", |
| 146 | + sai_serialize_object_id(fi.m_portId).c_str()); |
| 147 | + |
| 148 | + g_warmBootState.clear(); |
| 149 | + return false; |
| 150 | + } |
| 151 | + |
| 152 | + g_warmBootState[switchId].m_switchId = switchId; |
| 153 | + |
| 154 | + g_warmBootState[switchId].m_fdbInfoSet.insert(fi); |
| 155 | + |
| 156 | + continue; |
| 157 | + } |
| 158 | + |
| 159 | + iss >> strAttrId >> strAttrValue; |
| 160 | + |
| 161 | + sai_object_meta_key_t metaKey; |
| 162 | + sai_deserialize_object_meta_key(strObjectType + ":" + strObjectId, metaKey); |
| 163 | + |
| 164 | + /* |
| 165 | + * Since all objects we are creating, then during warm boot we need to |
| 166 | + * get the biggest object index, so after warm boot we can start |
| 167 | + * generating new objects with index value not colliding with objects |
| 168 | + * loaded from warm boot scenario. We only need to consider OID |
| 169 | + * objects. |
| 170 | + */ |
| 171 | + |
| 172 | + roidm->updateWarmBootObjectIndex(metaKey.objectkey.key.object_id); |
| 173 | + |
| 174 | + // query each object for switch id |
| 175 | + |
| 176 | + auto switchId = roidm->switchIdQuery(metaKey.objectkey.key.object_id); |
| 177 | + |
| 178 | + if (switchId == SAI_NULL_OBJECT_ID) |
| 179 | + { |
| 180 | + SWSS_LOG_ERROR("switchIdQuery returned NULL on oid = %s", |
| 181 | + sai_serialize_object_id(metaKey.objectkey.key.object_id).c_str()); |
| 182 | + |
| 183 | + g_warmBootState.clear(); |
| 184 | + return false; |
| 185 | + } |
| 186 | + |
| 187 | + g_warmBootState[switchId].m_switchId = switchId; |
| 188 | + |
| 189 | + auto &objectHash = g_warmBootState[switchId].m_objectHash[metaKey.objecttype]; // will create if not exist |
| 190 | + |
| 191 | + if (objectHash.find(strObjectId) == objectHash.end()) |
| 192 | + { |
| 193 | + objectHash[strObjectId] = {}; |
| 194 | + } |
| 195 | + |
| 196 | + if (strAttrId == "NULL") |
| 197 | + { |
| 198 | + // skip empty attributes |
| 199 | + continue; |
| 200 | + } |
| 201 | + |
| 202 | + objectHash[strObjectId][strAttrId] = |
| 203 | + std::make_shared<SaiAttrWrap>(strAttrId, strAttrValue); |
| 204 | + } |
| 205 | + |
| 206 | + // NOTE notification pointers should be restored by attr_list when creating switch |
| 207 | + |
| 208 | + ifs.close(); |
| 209 | + |
| 210 | + return true; |
| 211 | +} |
| 212 | + |
| 213 | +TEST(SwitchBCM56850, warm_update_queues) |
| 214 | +{ |
| 215 | + auto sc = std::make_shared<SwitchConfig>(0, ""); |
| 216 | + auto signal = std::make_shared<Signal>(); |
| 217 | + auto eventQueue = std::make_shared<EventQueue>(signal); |
| 218 | + |
| 219 | + sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU; |
| 220 | + sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850; |
| 221 | + sc->m_bootType = SAI_VS_BOOT_TYPE_COLD; |
| 222 | + sc->m_useTapDevice = false; |
| 223 | + sc->m_laneMap = LaneMap::getDefaultLaneMap(0); |
| 224 | + sc->m_eventQueue = eventQueue; |
| 225 | + |
| 226 | + auto scc = std::make_shared<SwitchConfigContainer>(); |
| 227 | + |
| 228 | + scc->insert(sc); |
| 229 | + |
| 230 | + auto roidm = std::make_shared<RealObjectIdManager>(0, scc); |
| 231 | + |
| 232 | + EXPECT_TRUE(getWarmBootState("files/mlnx2700.warm.bin", roidm)); |
| 233 | + |
| 234 | + auto warmBootState = std::make_shared<WarmBootState>(g_warmBootState.at(0x2100000000)); // copy ctr |
| 235 | + |
| 236 | + SwitchBCM56850 sw( |
| 237 | + 0x2100000000, |
| 238 | + roidm, |
| 239 | + sc, |
| 240 | + warmBootState); |
| 241 | + |
| 242 | + sai_attribute_t attr; |
| 243 | + |
| 244 | + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; |
| 245 | + attr.value.booldata = true; |
| 246 | + |
| 247 | + EXPECT_EQ(sw.warm_boot_initialize_objects(), SAI_STATUS_SUCCESS); |
| 248 | + |
| 249 | + attr.id = SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID; |
| 250 | + attr.value.oid = SAI_NULL_OBJECT_ID; |
| 251 | + |
| 252 | + EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_SWITCH, "oid:0x2100000000", 1, &attr), SAI_STATUS_SUCCESS); |
| 253 | + |
| 254 | + EXPECT_NE(attr.value.oid, SAI_NULL_OBJECT_ID); |
| 255 | + |
| 256 | + auto boid = attr.value.oid; |
| 257 | + |
| 258 | + auto sboid = sai_serialize_object_id(boid); |
| 259 | + |
| 260 | + sai_object_id_t list[128]; |
| 261 | + |
| 262 | + attr.id = SAI_BRIDGE_ATTR_PORT_LIST; |
| 263 | + |
| 264 | + attr.value.objlist.count = 128; |
| 265 | + attr.value.objlist.list = list; |
| 266 | + |
| 267 | + EXPECT_EQ(sw.get(SAI_OBJECT_TYPE_BRIDGE, sboid, 1, &attr), SAI_STATUS_SUCCESS); |
| 268 | +} |
0 commit comments