Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "gtest/gtest.h" |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 17 | #include "Queue.h" |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 18 | #include "bal_mocker.h" |
| 19 | #include "core.h" |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 20 | #include "core_data.h" |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 21 | #include "server.h" |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 22 | #include <future> |
Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 23 | #include <fstream> |
| 24 | #include "trx_eeprom_reader.h" |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 25 | using namespace testing; |
| 26 | using namespace std; |
| 27 | |
| 28 | class TestOltEnable : public Test { |
| 29 | protected: |
| 30 | virtual void SetUp() { |
| 31 | } |
| 32 | |
| 33 | virtual void TearDown() { |
| 34 | // Code here will be called immediately after each test |
| 35 | // (right before the destructor). |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | // This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in |
| 40 | // bcmolt_cfg_get__bal_state_stub. |
| 41 | ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; }; |
| 42 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 43 | // This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in |
| 44 | // bcmolt_cfg_get__onu_state_stub. |
| 45 | ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; }; |
| 46 | |
| 47 | // This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in |
| 48 | // bcmolt_cfg_get__tm_sched_stub. |
| 49 | ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; }; |
| 50 | |
| 51 | // This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in |
| 52 | // bcmolt_cfg_get__pon_intf_stub. |
| 53 | ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; }; |
| 54 | |
| 55 | // This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in |
| 56 | // bcmolt_cfg_get__nni_intf_stub. |
| 57 | ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; }; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 58 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 59 | // This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in |
| 60 | // bcmolt_cfg_get__flow_stub. |
| 61 | ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; }; |
| 62 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 63 | // Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function |
| 64 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 65 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 66 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 67 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 68 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*)); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 69 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 70 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 71 | // Test Fixture for OltEnable |
| 72 | |
| 73 | // Test 1: OltEnableSuccess case |
| 74 | TEST_F(TestOltEnable, OltEnableSuccess){ |
| 75 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 76 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 77 | NiceMock<BalMocker> balMock; |
| 78 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 79 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 80 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 81 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 82 | |
| 83 | bcmolt_olt_cfg olt_cfg = { }; |
| 84 | bcmolt_olt_key olt_key = { }; |
| 85 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 86 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 87 | |
| 88 | Status olt_enable_res; |
| 89 | |
| 90 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 91 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 92 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 93 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 94 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 95 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 96 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 97 | |
| 98 | olt_enable_res = Enable_(1, NULL); |
| 99 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 100 | } |
| 101 | |
| 102 | // Test 2: OltEnableFail_host_init_fail |
| 103 | TEST_F(TestOltEnable, OltEnableFail_host_init_fail) { |
| 104 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 105 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 106 | NiceMock<BalMocker> balMock; |
| 107 | bcmos_errno host_init_res = BCM_ERR_INTERNAL; |
| 108 | |
| 109 | Status olt_enable_res; |
| 110 | |
| 111 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 112 | state.deactivate(); |
| 113 | |
| 114 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 115 | |
| 116 | olt_enable_res = Enable_(1, NULL); |
| 117 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 118 | } |
| 119 | |
| 120 | // Test 3: OltEnableSuccess_PON_Device_Connected |
| 121 | TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) { |
| 122 | |
| 123 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 124 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 125 | NiceMock<BalMocker> balMock; |
| 126 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 127 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 128 | bcmos_errno bal_cfg_get_res = BCM_ERR_OK; |
| 129 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 130 | |
| 131 | bcmolt_olt_cfg olt_cfg = { }; |
| 132 | bcmolt_olt_key olt_key = { }; |
| 133 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 134 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 135 | |
| 136 | Status olt_enable_res; |
| 137 | |
| 138 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 139 | state.deactivate(); |
| 140 | |
| 141 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 142 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 143 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 144 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 145 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 146 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 147 | |
| 148 | olt_enable_res = Enable_(1, NULL); |
| 149 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 150 | |
| 151 | } |
| 152 | |
| 153 | // Test 4: OltEnableFail_All_PON_Enable_Fail |
| 154 | TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) { |
| 155 | |
| 156 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 157 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 158 | NiceMock<BalMocker> balMock; |
| 159 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 160 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 161 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 162 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 163 | |
| 164 | bcmolt_olt_cfg olt_cfg = { }; |
| 165 | bcmolt_olt_key olt_key = { }; |
| 166 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 167 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 168 | |
| 169 | Status olt_enable_res; |
| 170 | |
| 171 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 172 | state.deactivate(); |
| 173 | |
| 174 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 175 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 176 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 177 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 178 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 179 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 180 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 181 | |
| 182 | olt_enable_res = Enable_(1, NULL); |
| 183 | |
| 184 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 185 | } |
| 186 | |
| 187 | // Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed. |
| 188 | TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) { |
| 189 | |
| 190 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 191 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 192 | NiceMock<BalMocker> balMock; |
| 193 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 194 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 195 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 196 | bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL; |
| 197 | bcmos_errno olt_oper_res_success = BCM_ERR_OK; |
| 198 | |
| 199 | bcmolt_olt_cfg olt_cfg = { }; |
| 200 | bcmolt_olt_key olt_key = { }; |
| 201 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 202 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 203 | |
| 204 | Status olt_enable_res; |
| 205 | |
| 206 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 207 | state.deactivate(); |
| 208 | |
| 209 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 210 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 211 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 212 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 213 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 214 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 215 | // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices. |
| 216 | EXPECT_CALL(balMock, bcmolt_oper_submit(_, _)) |
| 217 | .WillOnce(Return(olt_oper_res_fail)) |
| 218 | .WillRepeatedly(Return(olt_oper_res_success)); |
| 219 | olt_enable_res = Enable_(1, NULL); |
| 220 | |
| 221 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 222 | } |
| 223 | |
| 224 | //////////////////////////////////////////////////////////////////////// |
| 225 | // For testing Enable/Disable functionality |
| 226 | //////////////////////////////////////////////////////////////////////// |
| 227 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 228 | int num_of_pon_port = 16; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 229 | |
| 230 | // Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function |
| 231 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 232 | |
| 233 | class TestOltDisableReenable : public Test { |
| 234 | protected: |
| 235 | virtual void SetUp() { |
| 236 | NiceMock<BalMocker> balMock; |
| 237 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 238 | |
| 239 | bcmolt_olt_cfg olt_cfg = { }; |
| 240 | bcmolt_olt_key olt_key = { }; |
| 241 | |
| 242 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 243 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 244 | olt_cfg.data.topology.topology_maps.len = num_of_pon_port; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 245 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _)) |
| 246 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 247 | |
| 248 | ProbeDeviceCapabilities_(); |
| 249 | |
| 250 | } |
| 251 | |
| 252 | virtual void TearDown() { |
| 253 | // Code here will be called immediately after each test |
| 254 | // (right before the destructor). |
| 255 | } |
| 256 | }; |
| 257 | |
| 258 | |
| 259 | // Test Fixture for OltDisable |
| 260 | |
| 261 | // Test 1: OltDisableSuccess case |
| 262 | TEST_F(TestOltDisableReenable, OltDisableSuccess){ |
| 263 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 264 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 265 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 266 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 267 | bcmos_errno olt_get_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 268 | |
| 269 | Status olt_disable_res; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 270 | state.deactivate(); |
| 271 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 272 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_get_res)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 273 | olt_disable_res = Disable_(); |
| 274 | ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() ); |
| 275 | |
| 276 | } |
| 277 | |
| 278 | // Test 2: OltDisableAllPonFailed case |
| 279 | TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){ |
| 280 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 281 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 282 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 283 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 284 | bcmos_errno pon_cfg_get_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 285 | |
| 286 | Status olt_disable_res; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 287 | state.deactivate(); |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 288 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(pon_cfg_get_res)); |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 289 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 290 | olt_disable_res = Disable_(); |
| 291 | ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | // Test Fixture for OltReenable |
| 296 | |
| 297 | // Test 1: OltReenableSuccess case |
| 298 | TEST_F(TestOltDisableReenable, OltReenableSuccess){ |
| 299 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 300 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 301 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 302 | uint32_t pon_id = 0; |
| 303 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 304 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 305 | Status olt_reenable_res; |
| 306 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 307 | bcmolt_pon_interface_key pon_key; |
| 308 | bcmolt_pon_interface_cfg pon_cfg; |
| 309 | pon_key.pon_ni = pon_id; |
| 310 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 311 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 312 | |
| 313 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 314 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 315 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 316 | |
| 317 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 318 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 319 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 320 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 321 | |
| 322 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 323 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 324 | .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 325 | |
| 326 | olt_reenable_res = Reenable_(); |
| 327 | ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() ); |
| 328 | |
| 329 | } |
| 330 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 331 | // Test 2: OltReenableAllPonFailed case |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 332 | TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){ |
| 333 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 334 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 335 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 336 | uint32_t pon_id = 0; |
| 337 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 338 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 339 | Status olt_reenable_res; |
| 340 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 341 | bcmolt_pon_interface_key pon_key; |
| 342 | bcmolt_pon_interface_cfg pon_cfg; |
| 343 | pon_key.pon_ni = pon_id; |
| 344 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 345 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 346 | |
| 347 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 348 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 349 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 350 | EXPECT_CALL(balMock,bcmolt_oper_submit(_, _)) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 351 | .Times(num_of_pon_port) |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 352 | .WillRepeatedly(Return(olt_oper_res)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 353 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 354 | olt_reenable_res = Reenable_(); |
| 355 | ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 356 | } |
| 357 | |
| 358 | //////////////////////////////////////////////////////////////////////////// |
| 359 | // For testing ProbeDeviceCapabilities functionality |
| 360 | //////////////////////////////////////////////////////////////////////////// |
| 361 | class TestProbeDevCapabilities : public Test { |
| 362 | protected: |
| 363 | NiceMock<BalMocker> balMock; |
| 364 | bcmos_errno olt_res_success = BCM_ERR_OK; |
| 365 | bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL; |
| 366 | bcmos_errno dev_res_success = BCM_ERR_OK; |
| 367 | bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL; |
| 368 | |
| 369 | virtual void SetUp() { |
| 370 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 371 | |
| 372 | bcmolt_olt_cfg olt_cfg = { }; |
| 373 | bcmolt_olt_key olt_key = { }; |
| 374 | |
| 375 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 376 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 377 | olt_cfg.data.topology.topology_maps.len = num_of_pon_port; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | virtual void TearDown() { |
| 381 | } |
| 382 | }; |
| 383 | |
| 384 | // Test 1 - If querying the OLT fails, the method must return error |
| 385 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) { |
| 386 | |
| 387 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 388 | .WillOnce(Return(olt_res_fail)); |
| 389 | |
| 390 | Status query_status = ProbeDeviceCapabilities_(); |
| 391 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 392 | } |
| 393 | |
| 394 | // Test 2 - If all devices are queried successfully, the method must return Status::OK |
| 395 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) { |
| 396 | |
| 397 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 398 | .WillOnce(Return(olt_res_success)); |
| 399 | |
| 400 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 401 | .WillRepeatedly(Return(dev_res_success)); |
| 402 | |
| 403 | Status query_status = ProbeDeviceCapabilities_(); |
| 404 | |
| 405 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 406 | } |
| 407 | |
| 408 | // Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error |
| 409 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) { |
| 410 | |
| 411 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 412 | .WillOnce(Return(olt_res_success)); |
| 413 | |
| 414 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 415 | .WillRepeatedly(Return(dev_res_fail)); |
| 416 | |
| 417 | Status query_status = ProbeDeviceCapabilities_(); |
| 418 | |
| 419 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 420 | } |
| 421 | |
| 422 | // Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success |
| 423 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) { |
| 424 | |
| 425 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 426 | .WillOnce(Return(olt_res_success)); |
| 427 | |
| 428 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 429 | .WillOnce(Return(olt_res_success)) |
| 430 | .WillRepeatedly(Return(dev_res_fail)); |
| 431 | |
| 432 | Status query_status = ProbeDeviceCapabilities_(); |
| 433 | |
| 434 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 435 | } |
| 436 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 437 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 438 | // For testing EnablePonIf functionality |
| 439 | //////////////////////////////////////////////////////////////////////////// |
| 440 | |
| 441 | class TestEnablePonIf : public Test { |
| 442 | protected: |
| 443 | uint32_t pon_id = 0; |
| 444 | NiceMock<BalMocker> balMock; |
| 445 | |
| 446 | virtual void SetUp() { |
| 447 | } |
| 448 | |
| 449 | virtual void TearDown() { |
| 450 | } |
| 451 | }; |
| 452 | |
| 453 | // Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case |
| 454 | TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) { |
| 455 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 456 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 457 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 458 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 459 | |
| 460 | bcmolt_pon_interface_key pon_key; |
| 461 | bcmolt_pon_interface_cfg pon_cfg; |
| 462 | pon_key.pon_ni = pon_id; |
| 463 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 464 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 465 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 466 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 467 | |
| 468 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 469 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 470 | |
| 471 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 472 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 473 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 474 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 475 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 476 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 477 | |
| 478 | Status status = EnablePonIf_(pon_id); |
| 479 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 480 | } |
| 481 | |
| 482 | // Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case |
| 483 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) { |
| 484 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 485 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 486 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL; |
| 487 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 488 | |
| 489 | bcmolt_pon_interface_key pon_key; |
| 490 | bcmolt_pon_interface_cfg pon_cfg; |
| 491 | pon_key.pon_ni = pon_id; |
| 492 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 493 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 494 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 495 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 496 | |
| 497 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 498 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 499 | |
| 500 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 501 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 502 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 503 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 504 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 505 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 506 | |
| 507 | Status status = EnablePonIf_(pon_id); |
| 508 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 509 | } |
| 510 | |
| 511 | // Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state |
| 512 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) { |
| 513 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 514 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 515 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 516 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 517 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 518 | |
| 519 | bcmolt_pon_interface_key pon_key; |
| 520 | bcmolt_pon_interface_cfg pon_cfg; |
| 521 | pon_key.pon_ni = pon_id; |
| 522 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 523 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 524 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 525 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 526 | |
| 527 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 528 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 529 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 530 | |
| 531 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 532 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 533 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 534 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 535 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 536 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 537 | |
| 538 | Status status = EnablePonIf_(pon_id); |
| 539 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 540 | } |
| 541 | |
| 542 | // Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed |
| 543 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) { |
| 544 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 545 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 546 | bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL; |
| 547 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 548 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 549 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 550 | |
| 551 | bcmolt_pon_interface_key pon_key; |
| 552 | bcmolt_pon_interface_cfg pon_cfg; |
| 553 | pon_key.pon_ni = pon_id; |
| 554 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 555 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 556 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 557 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 558 | |
| 559 | EXPECT_CALL(balMock, bcmolt_cfg_set(_, _)) |
| 560 | .WillOnce(Return(olt_cfg_set_res)) |
| 561 | .WillRepeatedly(Return(olt_cfg_set_err)); |
| 562 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 563 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 564 | |
| 565 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 566 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 567 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 568 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 569 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 570 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 571 | |
| 572 | Status status = EnablePonIf_(pon_id); |
| 573 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 574 | } |
| 575 | |
| 576 | // Test 5 - EnablePonIf already enabled success |
| 577 | TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) { |
| 578 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 579 | |
| 580 | bcmolt_pon_interface_key pon_key; |
| 581 | bcmolt_pon_interface_cfg pon_cfg; |
| 582 | pon_key.pon_ni = pon_id; |
| 583 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 584 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 585 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 586 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 587 | |
| 588 | Status status = EnablePonIf_(pon_id); |
| 589 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 590 | } |
| 591 | |
| 592 | // Test 6 - EnablePonIf - enable onu discovery failure case |
| 593 | TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) { |
| 594 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 595 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 596 | |
| 597 | bcmolt_pon_interface_key pon_key; |
| 598 | bcmolt_pon_interface_cfg pon_cfg; |
| 599 | pon_key.pon_ni = pon_id; |
| 600 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 601 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 602 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 603 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 604 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 605 | |
| 606 | Status status = EnablePonIf_(pon_id); |
| 607 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 608 | } |
| 609 | |
| 610 | // Test 7 - EnablePonIf failure case |
| 611 | TEST_F(TestEnablePonIf, EnablePonIfFailed) { |
| 612 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 613 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 614 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 615 | |
| 616 | bcmolt_pon_interface_key pon_key; |
| 617 | bcmolt_pon_interface_cfg pon_cfg; |
| 618 | pon_key.pon_ni = pon_id; |
| 619 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 620 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 621 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 622 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 623 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 624 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 625 | |
| 626 | Status status = EnablePonIf_(pon_id); |
| 627 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 628 | } |
| 629 | |
| 630 | //////////////////////////////////////////////////////////////////////////// |
| 631 | // For testing SetStateUplinkIf functionality |
| 632 | //////////////////////////////////////////////////////////////////////////// |
| 633 | |
| 634 | class TestSetStateUplinkIf : public Test { |
| 635 | protected: |
| 636 | uint32_t intf_id = 0; |
| 637 | NiceMock<BalMocker> balMock; |
| 638 | |
| 639 | virtual void SetUp() { |
| 640 | } |
| 641 | |
| 642 | virtual void TearDown() { |
| 643 | } |
| 644 | }; |
| 645 | |
| 646 | // Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case |
| 647 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) { |
| 648 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 649 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 650 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 651 | |
| 652 | bcmolt_nni_interface_key nni_key; |
| 653 | bcmolt_nni_interface_cfg nni_cfg; |
| 654 | nni_key.id = intf_id; |
| 655 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 656 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 657 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 658 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 659 | |
| 660 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 661 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 662 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 663 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 664 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 665 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 666 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 667 | |
| 668 | Status status = SetStateUplinkIf_(intf_id, true); |
| 669 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 670 | } |
| 671 | |
| 672 | // Test 2 - SetStateUplinkIf, NNI interface already disabled case |
| 673 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) { |
| 674 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 675 | |
| 676 | bcmolt_nni_interface_key nni_key; |
| 677 | bcmolt_nni_interface_cfg nni_cfg; |
| 678 | nni_key.id = intf_id; |
| 679 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 680 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 681 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 682 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 683 | |
| 684 | Status status = SetStateUplinkIf_(intf_id, false); |
| 685 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 686 | } |
| 687 | |
| 688 | // Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case |
| 689 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) { |
| 690 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 691 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 692 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 693 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 694 | |
| 695 | bcmolt_nni_interface_key nni_key; |
| 696 | bcmolt_nni_interface_cfg nni_cfg; |
| 697 | nni_key.id = intf_id; |
| 698 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 699 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 700 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 701 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 702 | |
| 703 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 704 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 705 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 706 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 707 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 708 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 709 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 710 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 711 | |
| 712 | Status status = SetStateUplinkIf_(intf_id, true); |
| 713 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 714 | } |
| 715 | |
| 716 | // Test 4 - SetStateUplinkIf Enable failure case |
| 717 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) { |
| 718 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 719 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 720 | |
| 721 | bcmolt_nni_interface_key nni_key; |
| 722 | bcmolt_nni_interface_cfg nni_cfg; |
| 723 | nni_key.id = intf_id; |
| 724 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 725 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 726 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 727 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 728 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 729 | |
| 730 | Status status = SetStateUplinkIf_(intf_id, true); |
| 731 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 732 | } |
| 733 | |
| 734 | // Test 5 - SetStateUplinkIf Disable success case |
| 735 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) { |
| 736 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 737 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 738 | |
| 739 | bcmolt_nni_interface_key nni_key; |
| 740 | bcmolt_nni_interface_cfg nni_cfg; |
| 741 | nni_key.id = intf_id; |
| 742 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 743 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 744 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 745 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 746 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 747 | |
| 748 | Status status = SetStateUplinkIf_(intf_id, false); |
| 749 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 750 | } |
| 751 | |
| 752 | // Test 6 - SetStateUplinkIf Disable failure case |
| 753 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) { |
| 754 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 755 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 756 | |
| 757 | bcmolt_nni_interface_key nni_key; |
| 758 | bcmolt_nni_interface_cfg nni_cfg; |
| 759 | nni_key.id = intf_id; |
| 760 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 761 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 762 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 763 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 764 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 765 | |
| 766 | Status status = SetStateUplinkIf_(intf_id, false); |
| 767 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 768 | } |
| 769 | |
| 770 | //////////////////////////////////////////////////////////////////////////// |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 771 | // For testing DisablePonIf functionality |
| 772 | //////////////////////////////////////////////////////////////////////////// |
| 773 | |
| 774 | class TestDisablePonIf : public Test { |
| 775 | protected: |
| 776 | virtual void SetUp() { |
| 777 | } |
| 778 | |
| 779 | virtual void TearDown() { |
| 780 | } |
| 781 | }; |
| 782 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 783 | // Test 1 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_ACTIVE_WORKING state |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 784 | TEST_F(TestDisablePonIf, DisablePonIfSuccess) { |
| 785 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 786 | bcmos_errno bal_cfg_set_res = BCM_ERR_OK; |
| 787 | NiceMock<BalMocker> balMock; |
| 788 | uint32_t pon_id=1; |
| 789 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 790 | bcmos_errno pon_intf_get_res = BCM_ERR_OK; |
| 791 | bcmolt_pon_interface_cfg interface_obj; |
| 792 | |
| 793 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id}; |
| 794 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 795 | |
| 796 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 797 | bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg; |
| 798 | pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 799 | memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg)); |
| 800 | return pon_intf_get_res; |
| 801 | } |
| 802 | )); |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 803 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 804 | state.deactivate(); |
| 805 | Status status = DisablePonIf_(pon_id); |
| 806 | |
| 807 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 808 | } |
| 809 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 810 | // Test 2 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL |
| 811 | TEST_F(TestDisablePonIf, DisablePonIf_OperSubmitErrInternal) { |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 812 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 813 | NiceMock<BalMocker> balMock; |
| 814 | uint32_t pon_id=1; |
| 815 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 816 | bcmos_errno pon_intf_get_res = BCM_ERR_OK; |
| 817 | bcmolt_pon_interface_cfg interface_obj; |
| 818 | |
| 819 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id}; |
| 820 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 821 | |
| 822 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 823 | bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg; |
| 824 | pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 825 | memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg)); |
| 826 | return pon_intf_get_res; |
| 827 | } |
| 828 | )); |
| 829 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 830 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 831 | state.deactivate(); |
| 832 | Status status = DisablePonIf_(pon_id); |
| 833 | |
| 834 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 835 | } |
| 836 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 837 | // Test 3 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL |
| 838 | TEST_F(TestDisablePonIf, DisablePonIf_CfgSetErrInternal) { |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 839 | NiceMock<BalMocker> balMock; |
| 840 | uint32_t pon_id=1; |
| 841 | bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL; |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 842 | |
| 843 | bcmos_errno pon_intf_get_res = BCM_ERR_OK; |
| 844 | bcmolt_pon_interface_cfg interface_obj; |
| 845 | |
| 846 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id}; |
| 847 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 848 | |
| 849 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 850 | bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg; |
| 851 | pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 852 | memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg)); |
| 853 | return pon_intf_get_res; |
| 854 | } |
| 855 | )); |
| 856 | |
| 857 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 858 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res)); |
| 859 | state.deactivate(); |
| 860 | Status status = DisablePonIf_(pon_id); |
| 861 | |
| 862 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 863 | } |
| 864 | |
Girish Gowdra | e1db295 | 2021-05-04 00:16:54 -0700 | [diff] [blame] | 865 | // Test 4 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_INACTIVE state |
| 866 | TEST_F(TestDisablePonIf, DisablePonIfSuccess_PonIntfInactive) { |
| 867 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 868 | bcmos_errno bal_cfg_set_res = BCM_ERR_OK; |
| 869 | NiceMock<BalMocker> balMock; |
| 870 | uint32_t pon_id=1; |
| 871 | |
| 872 | bcmos_errno pon_intf_get_res = BCM_ERR_OK; |
| 873 | bcmolt_pon_interface_cfg interface_obj; |
| 874 | |
| 875 | bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id}; |
| 876 | BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key); |
| 877 | |
| 878 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 879 | bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg; |
| 880 | pon_cfg->data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 881 | memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg)); |
| 882 | return pon_intf_get_res; |
| 883 | } |
| 884 | )); |
| 885 | state.deactivate(); |
| 886 | Status status = DisablePonIf_(pon_id); |
| 887 | |
| 888 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 889 | } |
| 890 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 891 | //////////////////////////////////////////////////////////////////////////// |
| 892 | // For testing ActivateOnu functionality |
| 893 | //////////////////////////////////////////////////////////////////////////// |
| 894 | |
| 895 | class TestActivateOnu : public Test { |
| 896 | protected: |
| 897 | uint32_t pon_id = 0; |
| 898 | uint32_t onu_id = 1; |
| 899 | std::string vendor_id = "TWSH"; |
| 900 | std::string vendor_specific = "80808080"; |
| 901 | uint32_t pir = 1000000; |
| 902 | NiceMock<BalMocker> balMock; |
| 903 | |
| 904 | virtual void SetUp() { |
| 905 | } |
| 906 | |
| 907 | virtual void TearDown() { |
| 908 | } |
| 909 | }; |
| 910 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 911 | // Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state |
| 912 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) { |
| 913 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 914 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 915 | bcmos_errno onu_cfg_set_res = BCM_ERR_OK; |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 916 | bcmos_errno onu_oper_submit_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 917 | |
| 918 | bcmolt_onu_cfg onu_cfg; |
| 919 | bcmolt_onu_key onu_key; |
| 920 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 921 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 922 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 923 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 924 | |
| 925 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 926 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 927 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 928 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 929 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 930 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 931 | } |
| 932 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 933 | // Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state |
| 934 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 935 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 936 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 937 | |
| 938 | bcmolt_onu_cfg onu_cfg; |
| 939 | bcmolt_onu_key onu_key; |
| 940 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 941 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 942 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 943 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 944 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 945 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 946 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 947 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 948 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 949 | } |
| 950 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 951 | // Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state |
| 952 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) { |
| 953 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 954 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 955 | bcmos_errno onu_oper_submit_res = BCM_ERR_OK; |
| 956 | |
| 957 | bcmolt_onu_cfg onu_cfg; |
| 958 | bcmolt_onu_key onu_key; |
| 959 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 960 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 961 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 962 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 963 | |
| 964 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 965 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
| 966 | |
| 967 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 968 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 969 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 970 | } |
| 971 | |
| 972 | // Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE) |
| 973 | TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) { |
| 974 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 975 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 976 | |
| 977 | bcmolt_onu_cfg onu_cfg; |
| 978 | bcmolt_onu_key onu_key; |
| 979 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 980 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process |
| 981 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 982 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 983 | |
| 984 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 985 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 986 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 987 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 988 | } |
| 989 | |
| 990 | // Test 5 - ActivateOnu failure case - cfg_get failure |
| 991 | TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) { |
| 992 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure |
| 993 | |
| 994 | bcmolt_onu_cfg onu_cfg; |
| 995 | bcmolt_onu_key onu_key; |
| 996 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 997 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 998 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 999 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 1000 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 1001 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1002 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1003 | } |
| 1004 | |
| 1005 | // Test 6 - ActivateOnu failure case - oper_submit failure |
| 1006 | TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) { |
| 1007 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1008 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1009 | bcmos_errno onu_cfg_set_res = BCM_ERR_OK; |
| 1010 | bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure |
| 1011 | |
| 1012 | bcmolt_onu_cfg onu_cfg; |
| 1013 | bcmolt_onu_key onu_key; |
| 1014 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1015 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED; |
| 1016 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 1017 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 1018 | |
| 1019 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 1020 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
| 1021 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
| 1022 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 1023 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 1024 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1025 | } |
| 1026 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1027 | //////////////////////////////////////////////////////////////////////////// |
| 1028 | // For testing DeactivateOnu functionality |
| 1029 | //////////////////////////////////////////////////////////////////////////// |
| 1030 | |
| 1031 | class TestDeactivateOnu : public Test { |
| 1032 | protected: |
| 1033 | uint32_t pon_id = 0; |
| 1034 | uint32_t onu_id = 1; |
| 1035 | std::string vendor_id = "TWSH"; |
| 1036 | std::string vendor_specific = "80808080"; |
| 1037 | NiceMock<BalMocker> balMock; |
| 1038 | |
| 1039 | virtual void SetUp() { |
| 1040 | } |
| 1041 | |
| 1042 | virtual void TearDown() { |
| 1043 | } |
| 1044 | }; |
| 1045 | |
| 1046 | // Test 1 - DeactivateOnu success case |
| 1047 | TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1048 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1049 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1050 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1051 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1052 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1053 | onu_key.pon_ni = 0; |
| 1054 | onu_key.onu_id = 1; |
| 1055 | |
| 1056 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1057 | |
| 1058 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1059 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1060 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1061 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1062 | return onu_cfg_get_res; |
| 1063 | } |
| 1064 | )); |
| 1065 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1066 | |
| 1067 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1068 | |
| 1069 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1070 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1071 | } |
| 1072 | |
| 1073 | // Test 2 - DeactivateOnu failure case |
| 1074 | TEST_F(TestDeactivateOnu, DeactivateOnuFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1075 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 1076 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1077 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1078 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1079 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1080 | onu_key.pon_ni = 0; |
| 1081 | onu_key.onu_id = 1; |
| 1082 | |
| 1083 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1084 | |
| 1085 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1086 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1087 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1088 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1089 | return onu_cfg_get_res; |
| 1090 | } |
| 1091 | )); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1092 | |
| 1093 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1094 | |
| 1095 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1096 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1097 | } |
| 1098 | |
| 1099 | //////////////////////////////////////////////////////////////////////////// |
| 1100 | // For testing DeleteOnu functionality |
| 1101 | //////////////////////////////////////////////////////////////////////////// |
| 1102 | |
| 1103 | class TestDeleteOnu : public Test { |
| 1104 | protected: |
| 1105 | uint32_t pon_id = 0; |
| 1106 | uint32_t onu_id = 1; |
| 1107 | std::string vendor_id = "TWSH"; |
| 1108 | std::string vendor_specific = "80808080"; |
| 1109 | NiceMock<BalMocker> balMock; |
| 1110 | |
| 1111 | virtual void SetUp() { |
| 1112 | } |
| 1113 | |
| 1114 | virtual void TearDown() { |
| 1115 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1116 | public: |
| 1117 | static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) { |
| 1118 | onu_deactivate_complete_result res; |
| 1119 | res.pon_intf_id = 0; |
| 1120 | res.onu_id = 1; |
| 1121 | res.result = result; |
| 1122 | res.reason = reason; |
| 1123 | // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered |
| 1124 | // before we push the result. |
| 1125 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 1126 | bcmos_fastlock_lock(&onu_deactivate_wait_lock); |
| 1127 | onu_deact_compltd_key k(0, 1); |
| 1128 | std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k); |
| 1129 | if (it == onu_deact_compltd_map.end()) { |
| 1130 | OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1); |
| 1131 | } else { |
| 1132 | it->second->push(res); |
| 1133 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n"); |
| 1134 | } |
| 1135 | bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0); |
| 1136 | return 0; |
| 1137 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1138 | }; |
| 1139 | |
| 1140 | // Test 1 - DeleteOnu success case |
| 1141 | TEST_F(TestDeleteOnu, DeleteOnuSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1142 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1143 | bcmos_errno onu_cfg_clear_res = BCM_ERR_OK; |
| 1144 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1145 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1146 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1147 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1148 | onu_key.pon_ni = 0; |
| 1149 | onu_key.onu_id = 1; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1150 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1151 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1152 | |
| 1153 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1154 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1155 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1156 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1157 | return onu_cfg_get_res; |
| 1158 | } |
| 1159 | )); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1160 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1161 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1162 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1163 | future<int> push_onu_deact_complt_res = \ |
| 1164 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE); |
| 1165 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1166 | Status status = future_res.get(); |
| 1167 | int res = push_onu_deact_complt_res.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1168 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1169 | } |
| 1170 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1171 | // Test 2 - DeleteOnu failure case - BAL Clear ONU fails |
| 1172 | TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1173 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1174 | bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1175 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1176 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1177 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1178 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1179 | onu_key.pon_ni = 0; |
| 1180 | onu_key.onu_id = 1; |
| 1181 | |
| 1182 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1183 | |
| 1184 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1185 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1186 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1187 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1188 | return onu_cfg_get_res; |
| 1189 | } |
| 1190 | )); |
| 1191 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1192 | |
| 1193 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1194 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1195 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1196 | future<int> push_onu_deact_complt_res = \ |
| 1197 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE); |
| 1198 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1199 | |
| 1200 | Status status = future_res.get(); |
| 1201 | int res = push_onu_deact_complt_res.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1202 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1203 | } |
| 1204 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1205 | // Test 3 - DeleteOnu failure case - onu deactivation fails |
| 1206 | TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1207 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1208 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1209 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1210 | bcmolt_onu_cfg onu_cfg_out; |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1211 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1212 | onu_key.pon_ni = 0; |
| 1213 | onu_key.onu_id = 1; |
| 1214 | |
| 1215 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1216 | |
| 1217 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1218 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1219 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1220 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1221 | return onu_cfg_get_res; |
| 1222 | } |
| 1223 | )); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1224 | |
| 1225 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1226 | |
| 1227 | future<int> push_onu_deact_complt_res = \ |
| 1228 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL); |
| 1229 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1230 | |
| 1231 | Status status = future_res.get(); |
| 1232 | int res = push_onu_deact_complt_res.get(); |
| 1233 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1234 | } |
| 1235 | |
| 1236 | // Test 4 - DeleteOnu failure case - onu deactivation timesout |
| 1237 | TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1238 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1239 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1240 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1241 | bcmolt_onu_cfg onu_cfg_out; |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1242 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1243 | onu_key.pon_ni = 0; |
| 1244 | onu_key.onu_id = 1; |
| 1245 | |
| 1246 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1247 | |
| 1248 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1249 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1250 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1251 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1252 | return onu_cfg_get_res; |
| 1253 | } |
| 1254 | )); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1255 | |
| 1256 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1257 | |
| 1258 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1259 | |
| 1260 | Status status = future_res.get(); |
| 1261 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1262 | } |
| 1263 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1264 | // Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response |
| 1265 | TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) { |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1266 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1267 | bcmos_errno onu_cfg_clear_res = BCM_ERR_OK; |
| 1268 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1269 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 1270 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1271 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1272 | onu_key.pon_ni = 0; |
| 1273 | onu_key.onu_id = 1; |
| 1274 | |
| 1275 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1276 | |
| 1277 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1278 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1279 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 1280 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1281 | return onu_cfg_get_res; |
| 1282 | } |
| 1283 | )); |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1284 | |
| 1285 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1286 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1287 | |
| 1288 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1289 | |
| 1290 | Status status = future_res.get(); |
| 1291 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1292 | } |
| 1293 | |
| 1294 | // Test 6 - DeleteOnu failure case - Failed to fetch Onu status |
| 1295 | TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) { |
| 1296 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 1297 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1298 | bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL; |
| 1299 | bcmolt_onu_cfg onu_cfg_out; |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1300 | bcmolt_onu_key onu_key; |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 1301 | onu_key.pon_ni = 0; |
| 1302 | onu_key.onu_id = 1; |
| 1303 | |
| 1304 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 1305 | |
| 1306 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 1307 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 1308 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 1309 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 1310 | return onu_cfg_get_res; |
| 1311 | } |
| 1312 | )); |
| 1313 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1314 | |
| 1315 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1316 | |
| 1317 | Status status = future_res.get(); |
| 1318 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1319 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1320 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1321 | //////////////////////////////////////////////////////////////////////////// |
| 1322 | // For testing OmciMsgOut functionality |
| 1323 | //////////////////////////////////////////////////////////////////////////// |
| 1324 | |
| 1325 | class TestOmciMsgOut : public Test { |
| 1326 | protected: |
| 1327 | uint32_t pon_id = 0; |
| 1328 | uint32_t onu_id = 1; |
| 1329 | std::string pkt = "omci-pkt"; |
| 1330 | NiceMock<BalMocker> balMock; |
| 1331 | |
| 1332 | virtual void SetUp() { |
| 1333 | } |
| 1334 | |
| 1335 | virtual void TearDown() { |
| 1336 | } |
| 1337 | }; |
| 1338 | |
| 1339 | // Test 1 - OmciMsgOut success case |
| 1340 | TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) { |
| 1341 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1342 | |
| 1343 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1344 | |
| 1345 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1346 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1347 | } |
| 1348 | |
| 1349 | // Test 1 - OmciMsgOut failure case |
| 1350 | TEST_F(TestOmciMsgOut, OmciMsgOutFailure) { |
| 1351 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 1352 | |
| 1353 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1354 | |
| 1355 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1356 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1357 | } |
| 1358 | |
| 1359 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1360 | // For testing FlowAdd functionality |
| 1361 | //////////////////////////////////////////////////////////////////////////// |
| 1362 | |
| 1363 | class TestFlowAdd : public Test { |
| 1364 | protected: |
| 1365 | int32_t access_intf_id = 0; |
| 1366 | int32_t onu_id = 1; |
| 1367 | int32_t uni_id = 0; |
| 1368 | uint32_t port_no = 16; |
| 1369 | uint32_t flow_id = 1; |
| 1370 | std::string flow_type = "upstream"; |
| 1371 | int32_t alloc_id = 1024; |
| 1372 | int32_t network_intf_id = 0; |
| 1373 | int32_t gemport_id = 1024; |
| 1374 | int32_t priority_value = 0; |
| 1375 | uint64_t cookie = 0; |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1376 | int32_t group_id = -1; |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1377 | uint32_t tech_profile_id = 64; |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1378 | bool enable_encryption = true; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1379 | |
| 1380 | NiceMock<BalMocker> balMock; |
| 1381 | openolt::Flow* flow; |
| 1382 | openolt::Classifier* classifier; |
| 1383 | openolt::Action* action; |
| 1384 | openolt::ActionCmd* cmd; |
| 1385 | |
| 1386 | bcmolt_flow_key flow_key; |
| 1387 | bcmolt_flow_cfg flow_cfg; |
| 1388 | |
| 1389 | tech_profile::TrafficQueues* traffic_queues; |
| 1390 | tech_profile::TrafficQueue* traffic_queue_1; |
| 1391 | tech_profile::TrafficQueue* traffic_queue_2; |
| 1392 | tech_profile::DiscardConfig* discard_config_1; |
| 1393 | tech_profile::DiscardConfig* discard_config_2; |
| 1394 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 1395 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 1396 | |
| 1397 | |
| 1398 | virtual void SetUp() { |
| 1399 | classifier = new openolt::Classifier; |
| 1400 | action = new openolt::Action; |
| 1401 | cmd = new openolt::ActionCmd; |
| 1402 | |
| 1403 | classifier->set_o_tpid(0); |
| 1404 | classifier->set_o_vid(7); |
| 1405 | classifier->set_i_tpid(0); |
| 1406 | classifier->set_i_vid(0); |
| 1407 | classifier->set_o_pbits(0); |
| 1408 | classifier->set_i_pbits(0); |
| 1409 | classifier->set_eth_type(0); |
| 1410 | classifier->set_ip_proto(0); |
| 1411 | classifier->set_src_port(0); |
| 1412 | classifier->set_dst_port(0); |
| 1413 | classifier->set_pkt_tag_type("single_tag"); |
Girish Gowdra | f83e17a | 2022-02-16 16:27:00 -0800 | [diff] [blame^] | 1414 | classifier->set_src_mac("aabbccddeeff"); |
| 1415 | classifier->set_dst_mac("112233445566"); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1416 | |
| 1417 | action->set_o_vid(12); |
| 1418 | action->set_o_pbits(0); |
| 1419 | action->set_o_tpid(0); |
| 1420 | action->set_i_vid(0); |
| 1421 | action->set_i_pbits(0); |
| 1422 | action->set_i_tpid(0); |
| 1423 | |
| 1424 | cmd->set_add_outer_tag(true); |
| 1425 | cmd->set_remove_outer_tag(false); |
| 1426 | cmd->set_trap_to_host(false); |
| 1427 | action->set_allocated_cmd(cmd); |
| 1428 | |
| 1429 | flow_key.flow_id = 1; |
| 1430 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1431 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1432 | flow_cfg.data.onu_id=1; |
| 1433 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1434 | flow_cfg.data.svc_port_id=1024; |
| 1435 | flow_cfg.data.priority=0; |
| 1436 | flow_cfg.data.cookie=0; |
| 1437 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1438 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1439 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1440 | flow_cfg.data.egress_intf.intf_id=0; |
| 1441 | flow_cfg.data.classifier.o_vid=7; |
| 1442 | flow_cfg.data.classifier.o_pbits=0; |
| 1443 | flow_cfg.data.classifier.i_vid=0; |
| 1444 | flow_cfg.data.classifier.i_pbits=0; |
| 1445 | flow_cfg.data.classifier.ether_type=0; |
| 1446 | flow_cfg.data.classifier.ip_proto=0; |
| 1447 | flow_cfg.data.classifier.src_port=0; |
| 1448 | flow_cfg.data.classifier.dst_port=0; |
| 1449 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1450 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1451 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1452 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1453 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1454 | flow_cfg.data.action.o_vid=12; |
| 1455 | flow_cfg.data.action.o_pbits=0; |
| 1456 | flow_cfg.data.action.i_vid=0; |
| 1457 | flow_cfg.data.action.i_pbits=0; |
| 1458 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1459 | |
| 1460 | traffic_queues = new tech_profile::TrafficQueues; |
| 1461 | traffic_queues->set_intf_id(0); |
| 1462 | traffic_queues->set_onu_id(2); |
| 1463 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 1464 | traffic_queue_1->set_gemport_id(1024); |
| 1465 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 1466 | traffic_queue_1->set_aes_encryption(true); |
| 1467 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1468 | traffic_queue_1->set_priority(0); |
| 1469 | traffic_queue_1->set_weight(0); |
| 1470 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1471 | discard_config_1 = new tech_profile::DiscardConfig; |
| 1472 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1473 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 1474 | tail_drop_discard_config_1->set_queue_size(8); |
| 1475 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 1476 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 1477 | |
| 1478 | traffic_queues->set_uni_id(0); |
| 1479 | traffic_queues->set_port_no(16); |
| 1480 | |
| 1481 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1482 | traffic_queue_2->set_gemport_id(1025); |
| 1483 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 1484 | traffic_queue_2->set_aes_encryption(true); |
| 1485 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1486 | traffic_queue_2->set_priority(1); |
| 1487 | traffic_queue_2->set_weight(0); |
| 1488 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1489 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1490 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1491 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1492 | tail_drop_discard_config_2->set_queue_size(8); |
| 1493 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1494 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1495 | } |
| 1496 | |
| 1497 | virtual void TearDown() { |
| 1498 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1499 | |
| 1500 | public: |
| 1501 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 1502 | gem_cfg_compltd_key k(0, gem_port_id); |
| 1503 | gem_cfg_complete_result res; |
| 1504 | res.pon_intf_id = 0; |
| 1505 | res.gem_port_id = gem_port_id; |
| 1506 | res.state = state; |
| 1507 | res.status = status; |
| 1508 | |
| 1509 | uint32_t gem_cfg_key_check_counter = 1; |
| 1510 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 1511 | while(true) { |
| 1512 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 1513 | it = gem_cfg_compltd_map.find(k); |
| 1514 | |
| 1515 | if (it != gem_cfg_compltd_map.end()) { |
| 1516 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1517 | break; |
| 1518 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 1519 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1520 | |
| 1521 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 1522 | // before we push the result. |
| 1523 | bcmos_usleep(6000); |
| 1524 | } else { |
| 1525 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 1526 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1527 | return 0; |
| 1528 | } |
| 1529 | gem_cfg_key_check_counter++; |
| 1530 | } |
| 1531 | |
| 1532 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 1533 | if (it->second) { |
| 1534 | it->second->push(res); |
| 1535 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 1536 | } |
| 1537 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1538 | return 0; |
| 1539 | } |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1540 | }; |
| 1541 | |
| 1542 | // Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue) |
| 1543 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) { |
| 1544 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1545 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1546 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1547 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1548 | alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1549 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1550 | } |
| 1551 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1552 | #ifdef FLOW_CHECKER |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1553 | // Test 2 - FlowAdd - Duplicate Flow case |
| 1554 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) { |
| 1555 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1556 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1557 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1558 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1559 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1560 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1561 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1562 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1563 | #endif |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1564 | |
| 1565 | // Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error) |
| 1566 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) { |
| 1567 | gemport_id = 1025; |
| 1568 | |
| 1569 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1570 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1571 | |
| 1572 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1573 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1574 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1575 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1576 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1577 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1578 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1579 | } |
| 1580 | |
| 1581 | // Test 4 - FlowAdd - Failure case(Invalid flow direction) |
| 1582 | TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) { |
| 1583 | flow_type = "bidirectional"; |
| 1584 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1585 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1586 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1587 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1588 | } |
| 1589 | |
| 1590 | // Test 5 - FlowAdd - Failure case(Invalid network setting) |
| 1591 | TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) { |
| 1592 | network_intf_id = -1; |
| 1593 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1594 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1595 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1596 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1597 | } |
| 1598 | |
| 1599 | // Test 6 - FlowAdd - Success case(Single tag & EAP Ether type) |
| 1600 | TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) { |
| 1601 | flow_id = 2; |
| 1602 | |
| 1603 | classifier->set_eth_type(34958); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1604 | action = new openolt::Action; |
| 1605 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1606 | cmd->set_trap_to_host(true); |
| 1607 | action->set_allocated_cmd(cmd); |
| 1608 | |
| 1609 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1610 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1611 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1612 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1613 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1614 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1615 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1616 | network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1617 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1618 | } |
| 1619 | |
| 1620 | // Test 7 - FlowAdd - Success case(Single tag & DHCP flow) |
| 1621 | TEST_F(TestFlowAdd, FlowAddDhcpSuccess) { |
| 1622 | flow_id = 3; |
| 1623 | gemport_id = 1025; |
| 1624 | |
| 1625 | classifier->set_ip_proto(17); |
| 1626 | classifier->set_src_port(68); |
| 1627 | classifier->set_dst_port(67); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1628 | action = new openolt::Action; |
| 1629 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1630 | cmd->set_trap_to_host(true); |
| 1631 | action->set_allocated_cmd(cmd); |
| 1632 | |
| 1633 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1634 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1635 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1636 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1637 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1638 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1639 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1640 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1641 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1642 | } |
| 1643 | |
| 1644 | // Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue) |
| 1645 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) { |
| 1646 | flow_id = 4; |
| 1647 | flow_type = "downstream"; |
| 1648 | |
| 1649 | classifier->set_o_vid(12); |
| 1650 | classifier->set_i_vid(7); |
| 1651 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1652 | action = new openolt::Action; |
| 1653 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1654 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1655 | cmd->set_remove_outer_tag(true); |
| 1656 | action->set_allocated_cmd(cmd); |
| 1657 | |
| 1658 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1659 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1660 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1661 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1662 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1663 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1664 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1665 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1666 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1667 | } |
| 1668 | |
| 1669 | // Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue) |
| 1670 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) { |
| 1671 | onu_id = 2; |
| 1672 | flow_id = 5; |
| 1673 | alloc_id = 1025; |
| 1674 | |
| 1675 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1676 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1677 | |
| 1678 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1679 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1680 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1681 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1682 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1683 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1684 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 1685 | future<int> push_gem_cfg_complt = \ |
| 1686 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 1687 | push_gem_cfg_complt = \ |
| 1688 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 1689 | Status status = future_res.get(); |
| 1690 | int res = push_gem_cfg_complt.get(); |
| 1691 | |
| 1692 | status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1693 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1694 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1695 | } |
| 1696 | |
| 1697 | // Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue) |
| 1698 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) { |
| 1699 | onu_id = 2; |
| 1700 | flow_id = 6; |
| 1701 | flow_type = "downstream"; |
| 1702 | alloc_id = 1025; |
| 1703 | |
| 1704 | classifier->set_o_vid(12); |
| 1705 | classifier->set_i_vid(7); |
| 1706 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1707 | action = new openolt::Action; |
| 1708 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1709 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1710 | cmd->set_remove_outer_tag(true); |
| 1711 | action->set_allocated_cmd(cmd); |
| 1712 | |
| 1713 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1714 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1715 | |
| 1716 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1717 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1718 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1719 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1720 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1721 | CreateTrafficQueues_(traffic_queues); |
| 1722 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1723 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1724 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1725 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1726 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1727 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1728 | // Test 11 - FlowAdd - success case (Downstream-Encrypted GEM) |
| 1729 | TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) { |
| 1730 | onu_id = 2; |
| 1731 | flow_id = 7; |
| 1732 | flow_type = "downstream"; |
| 1733 | alloc_id = 1025; |
| 1734 | enable_encryption = true; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1735 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1736 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1737 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1738 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1739 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1740 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1741 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1742 | future<Status> future_res = async(launch::async, FlowAdd_, access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1743 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1744 | |
| 1745 | future<int> push_gem_cfg_complt = \ |
| 1746 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 1747 | Status status = future_res.get(); |
| 1748 | int res = push_gem_cfg_complt.get(); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1749 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1750 | } |
| 1751 | |
| 1752 | // Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied) |
| 1753 | TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) { |
| 1754 | onu_id = 2; |
| 1755 | flow_id = 8; |
| 1756 | flow_type = "downstream"; |
| 1757 | alloc_id = 1025; |
| 1758 | enable_encryption = false; |
| 1759 | |
| 1760 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1761 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1762 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1763 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1764 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1765 | |
| 1766 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1767 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1768 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1769 | } |
| 1770 | |
| 1771 | // Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied) |
| 1772 | TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) { |
| 1773 | onu_id = 2; |
| 1774 | flow_id = 9; |
| 1775 | flow_type = "upstream"; |
| 1776 | alloc_id = 1025; |
| 1777 | enable_encryption = true; |
| 1778 | |
| 1779 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1780 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1781 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1782 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1783 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1784 | |
| 1785 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1786 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1787 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1788 | } |
| 1789 | |
| 1790 | // Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied) |
| 1791 | TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) { |
| 1792 | onu_id = 2; |
| 1793 | flow_id = 10; |
| 1794 | flow_type = "multicast"; |
| 1795 | alloc_id = 1025; |
| 1796 | enable_encryption = true; |
| 1797 | |
| 1798 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1799 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1800 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1801 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1802 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1803 | |
| 1804 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1805 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1806 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1807 | } |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1808 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1809 | // For testing OnuPacketOut functionality |
| 1810 | //////////////////////////////////////////////////////////////////////////// |
| 1811 | |
| 1812 | class TestOnuPacketOut : public Test { |
| 1813 | protected: |
| 1814 | uint32_t pon_id = 0; |
| 1815 | uint32_t onu_id = 1; |
| 1816 | std::string pkt = "omci-pkt"; |
| 1817 | NiceMock<BalMocker> balMock; |
| 1818 | |
| 1819 | virtual void SetUp() { |
| 1820 | } |
| 1821 | |
| 1822 | virtual void TearDown() { |
| 1823 | } |
| 1824 | }; |
| 1825 | |
| 1826 | // Test 1 - OnuPacketOut success case |
| 1827 | TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) { |
| 1828 | uint32_t port_no = 16; |
| 1829 | uint32_t gemport_id = 1024; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1830 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1831 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1832 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1833 | |
| 1834 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1835 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1836 | } |
| 1837 | |
| 1838 | // Test 2 - OnuPacketOut Port number as 0 case |
| 1839 | TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) { |
| 1840 | uint32_t port_no = 0; |
| 1841 | uint32_t gemport_id = 1024; |
| 1842 | |
| 1843 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1844 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1845 | } |
| 1846 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1847 | // Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case |
| 1848 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) { |
| 1849 | uint32_t port_no = 16; |
| 1850 | uint32_t gemport_id = 0; |
| 1851 | |
| 1852 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1853 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1854 | |
| 1855 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1856 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1857 | } |
| 1858 | |
| 1859 | // Test 4 - OnuPacketOut success, Failure in finding Gem port case |
| 1860 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) { |
| 1861 | uint32_t port_no = 64; |
| 1862 | uint32_t gemport_id = 0; |
| 1863 | |
| 1864 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1865 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1866 | |
| 1867 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1868 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1869 | } |
| 1870 | |
| 1871 | //////////////////////////////////////////////////////////////////////////// |
| 1872 | // For testing FlowRemove functionality |
| 1873 | //////////////////////////////////////////////////////////////////////////// |
| 1874 | |
| 1875 | class TestFlowRemove : public Test { |
| 1876 | protected: |
| 1877 | NiceMock<BalMocker> balMock; |
| 1878 | |
| 1879 | virtual void SetUp() { |
| 1880 | } |
| 1881 | |
| 1882 | virtual void TearDown() { |
| 1883 | } |
| 1884 | }; |
| 1885 | |
| 1886 | // Test 1 - FlowRemove - Failure case |
| 1887 | TEST_F(TestFlowRemove, FlowRemoveFailure) { |
| 1888 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1889 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1890 | |
| 1891 | Status status = FlowRemove_(1, "upstream"); |
| 1892 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1893 | } |
| 1894 | |
| 1895 | // Test 2 - FlowRemove - success case |
| 1896 | TEST_F(TestFlowRemove, FlowRemoveSuccess) { |
| 1897 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1898 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1899 | |
| 1900 | Status status = FlowRemove_(1, "upstream"); |
| 1901 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1902 | } |
| 1903 | |
| 1904 | //////////////////////////////////////////////////////////////////////////// |
| 1905 | // For testing UplinkPacketOut functionality |
| 1906 | //////////////////////////////////////////////////////////////////////////// |
| 1907 | |
| 1908 | class TestUplinkPacketOut : public Test { |
| 1909 | protected: |
| 1910 | uint32_t pon_id = 0; |
| 1911 | std::string pkt = "omci-pkt"; |
| 1912 | NiceMock<BalMocker> balMock; |
| 1913 | |
| 1914 | bcmolt_flow_key flow_key; |
| 1915 | bcmolt_flow_cfg flow_cfg; |
| 1916 | |
| 1917 | virtual void SetUp() { |
| 1918 | flow_key.flow_id = 1; |
| 1919 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1920 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1921 | flow_cfg.data.onu_id=1; |
| 1922 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1923 | flow_cfg.data.svc_port_id=1024; |
| 1924 | flow_cfg.data.priority=0; |
| 1925 | flow_cfg.data.cookie=0; |
| 1926 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1927 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1928 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1929 | flow_cfg.data.egress_intf.intf_id=0; |
| 1930 | flow_cfg.data.classifier.o_vid=7; |
| 1931 | flow_cfg.data.classifier.o_pbits=0; |
| 1932 | flow_cfg.data.classifier.i_vid=0; |
| 1933 | flow_cfg.data.classifier.i_pbits=0; |
| 1934 | flow_cfg.data.classifier.ether_type=0; |
| 1935 | flow_cfg.data.classifier.ip_proto=0; |
| 1936 | flow_cfg.data.classifier.src_port=0; |
| 1937 | flow_cfg.data.classifier.dst_port=0; |
| 1938 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1939 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1940 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1941 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1942 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1943 | flow_cfg.data.action.o_vid=12; |
| 1944 | flow_cfg.data.action.o_pbits=0; |
| 1945 | flow_cfg.data.action.i_vid=0; |
| 1946 | flow_cfg.data.action.i_pbits=0; |
| 1947 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1948 | } |
| 1949 | |
| 1950 | virtual void TearDown() { |
| 1951 | } |
| 1952 | }; |
| 1953 | |
| 1954 | // Test 1 - UplinkPacketOut success case |
| 1955 | TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) { |
| 1956 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK; |
| 1957 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1958 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1959 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1960 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1961 | |
| 1962 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1963 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1964 | } |
| 1965 | |
| 1966 | // Test 2 - UplinkPacketOut Failure case |
| 1967 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) { |
| 1968 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL; |
| 1969 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1970 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1971 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1972 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1973 | |
| 1974 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1975 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1976 | } |
| 1977 | |
| 1978 | // Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case |
| 1979 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) { |
| 1980 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
| 1981 | |
| 1982 | FlowRemove_(2, "upstream"); |
| 1983 | FlowRemove_(3, "upstream"); |
| 1984 | FlowRemove_(4, "downstream"); |
| 1985 | FlowRemove_(5, "upstream"); |
| 1986 | FlowRemove_(6, "downstream"); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1987 | FlowRemove_(7, "downstream"); |
| 1988 | FlowRemove_(8, "downstream"); |
| 1989 | FlowRemove_(9, "upstream"); |
| 1990 | FlowRemove_(10, "multicast"); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1991 | |
| 1992 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1993 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1994 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1995 | |
| 1996 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1997 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1998 | } |
| 1999 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2000 | //////////////////////////////////////////////////////////////////////////// |
| 2001 | // For testing CreateTrafficSchedulers functionality |
| 2002 | //////////////////////////////////////////////////////////////////////////// |
| 2003 | |
| 2004 | class TestCreateTrafficSchedulers : public Test { |
| 2005 | protected: |
| 2006 | NiceMock<BalMocker> balMock; |
| 2007 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2008 | tech_profile::TrafficScheduler* traffic_sched; |
| 2009 | tech_profile::SchedulerConfig* scheduler; |
| 2010 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 2011 | |
| 2012 | virtual void SetUp() { |
| 2013 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2014 | traffic_scheds->set_intf_id(0); |
| 2015 | traffic_scheds->set_onu_id(1); |
| 2016 | traffic_scheds->set_uni_id(0); |
| 2017 | traffic_scheds->set_port_no(16); |
| 2018 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2019 | traffic_sched->set_alloc_id(1024); |
| 2020 | scheduler = new tech_profile::SchedulerConfig; |
| 2021 | scheduler->set_priority(0); |
| 2022 | scheduler->set_weight(0); |
| 2023 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2024 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 2025 | traffic_shaping_info->set_cbs(60536); |
| 2026 | traffic_shaping_info->set_pbs(65536); |
| 2027 | traffic_shaping_info->set_gir(10000); |
| 2028 | } |
| 2029 | |
| 2030 | virtual void TearDown() { |
| 2031 | } |
| 2032 | |
| 2033 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2034 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 2035 | alloc_cfg_compltd_key k(0, 1024); |
| 2036 | alloc_cfg_complete_result res; |
| 2037 | res.pon_intf_id = 0; |
| 2038 | res.alloc_id = 1024; |
| 2039 | res.state = state; |
| 2040 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2041 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2042 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 2043 | // before we push the result. |
| 2044 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 2045 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 2046 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 2047 | if (it == alloc_cfg_compltd_map.end()) { |
| 2048 | OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2049 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2050 | it->second->push(res); |
| 2051 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2052 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2053 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 2054 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2055 | } |
| 2056 | }; |
| 2057 | |
| 2058 | // Test 1 - CreateTrafficSchedulers-Upstream success case |
| 2059 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) { |
| 2060 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2061 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2062 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2063 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2064 | traffic_shaping_info->set_cir(64000); |
| 2065 | traffic_shaping_info->set_pir(128000); |
| 2066 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2067 | |
| 2068 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2069 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2070 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2071 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2072 | bcmolt_onu_cfg onu_cfg_out; |
| 2073 | bcmolt_onu_key onu_key; |
| 2074 | onu_key.pon_ni = 0; |
| 2075 | onu_key.onu_id = 1; |
| 2076 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2077 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2078 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2079 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2080 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2081 | return onu_cfg_get_res; |
| 2082 | } |
| 2083 | )); |
| 2084 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2085 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2086 | future<int> push_alloc_cfg_complt = \ |
| 2087 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2088 | |
| 2089 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2090 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2091 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2092 | } |
| 2093 | |
| 2094 | // Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication) |
| 2095 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) { |
| 2096 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2097 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2098 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2099 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2100 | traffic_shaping_info->set_cir(64000); |
| 2101 | traffic_shaping_info->set_pir(128000); |
| 2102 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2103 | |
| 2104 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2105 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2106 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2107 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2108 | bcmolt_onu_cfg onu_cfg_out; |
| 2109 | bcmolt_onu_key onu_key; |
| 2110 | onu_key.pon_ni = 0; |
| 2111 | onu_key.onu_id = 1; |
| 2112 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2113 | |
| 2114 | bcmos_errno alloc_cfg_get_res = BCM_ERR_OK; |
| 2115 | bcmolt_itupon_alloc_cfg alloc_cfg; |
| 2116 | bcmolt_itupon_alloc_key alloc_key; |
| 2117 | alloc_key.pon_ni = 0; |
| 2118 | alloc_key.alloc_id = 1024; |
| 2119 | BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key); |
| 2120 | |
| 2121 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2) |
| 2122 | .WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2123 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2124 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2125 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2126 | return onu_cfg_get_res; |
| 2127 | } |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2128 | )) |
| 2129 | .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2130 | bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg; |
| 2131 | o_cfg->data.state = BCMOLT_ACTIVATION_STATE_PROCESSING; |
| 2132 | memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg)); |
| 2133 | return alloc_cfg_get_res; |
| 2134 | } |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2135 | )); |
| 2136 | |
| 2137 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2138 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2139 | } |
| 2140 | |
| 2141 | // Test 2A - CreateTrafficSchedulers-Upstream success case(ONU not in ACTIVE state) |
| 2142 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccessOnuNotInActive) { |
| 2143 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2144 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2145 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2146 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2147 | traffic_shaping_info->set_cir(64000); |
| 2148 | traffic_shaping_info->set_pir(128000); |
| 2149 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2150 | |
| 2151 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2152 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2153 | |
| 2154 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2155 | bcmolt_onu_cfg onu_cfg_out; |
| 2156 | bcmolt_onu_key onu_key; |
| 2157 | onu_key.pon_ni = 0; |
| 2158 | onu_key.onu_id = 1; |
| 2159 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2160 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2161 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2162 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2163 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2164 | return onu_cfg_get_res; |
| 2165 | } |
| 2166 | )); |
| 2167 | |
| 2168 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2169 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2170 | } |
| 2171 | |
| 2172 | // Test 2B - CreateTrafficSchedulers-Upstream failure case. cfg-get failure |
| 2173 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamCfgGetFailure) { |
| 2174 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2175 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2176 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2177 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2178 | traffic_shaping_info->set_cir(64000); |
| 2179 | traffic_shaping_info->set_pir(128000); |
| 2180 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2181 | |
| 2182 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2183 | bcmos_errno olt_cfg_get_res = BCM_ERR_INTERNAL; |
| 2184 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2185 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 2186 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2187 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2188 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2189 | } |
| 2190 | |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2191 | // Test 2C - CreateTrafficSchedulers-Upstream Succes case(timeout waiting for alloc cfg indication, but itupon-alloc object is ACTIVE) |
| 2192 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeoutSuccess) { |
| 2193 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2194 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2195 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2196 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2197 | traffic_shaping_info->set_cir(64000); |
| 2198 | traffic_shaping_info->set_pir(128000); |
| 2199 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2200 | |
| 2201 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2202 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2203 | |
| 2204 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2205 | bcmolt_onu_cfg onu_cfg_out; |
| 2206 | bcmolt_onu_key onu_key; |
| 2207 | onu_key.pon_ni = 0; |
| 2208 | onu_key.onu_id = 1; |
| 2209 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2210 | |
| 2211 | bcmos_errno alloc_cfg_get_res = BCM_ERR_OK; |
| 2212 | bcmolt_itupon_alloc_cfg alloc_cfg; |
| 2213 | bcmolt_itupon_alloc_key alloc_key; |
| 2214 | alloc_key.pon_ni = 0; |
| 2215 | alloc_key.alloc_id = 1024; |
| 2216 | BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key); |
| 2217 | |
| 2218 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2) |
| 2219 | .WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2220 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2221 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2222 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2223 | return onu_cfg_get_res; |
| 2224 | } |
| 2225 | )) |
| 2226 | .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2227 | bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg; |
| 2228 | o_cfg->data.state = BCMOLT_ACTIVATION_STATE_ACTIVE; |
| 2229 | memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg)); |
| 2230 | return alloc_cfg_get_res; |
| 2231 | } |
| 2232 | )); |
| 2233 | |
| 2234 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2235 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2236 | } |
| 2237 | |
| 2238 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2239 | // Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request) |
| 2240 | TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) { |
| 2241 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2242 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2243 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2244 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2245 | traffic_shaping_info->set_cir(64000); |
| 2246 | traffic_shaping_info->set_pir(128000); |
| 2247 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2248 | |
| 2249 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2250 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2251 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2252 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2253 | bcmolt_onu_cfg onu_cfg_out; |
| 2254 | bcmolt_onu_key onu_key; |
| 2255 | onu_key.pon_ni = 0; |
| 2256 | onu_key.onu_id = 1; |
| 2257 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2258 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2259 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2260 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2261 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2262 | return onu_cfg_get_res; |
| 2263 | } |
| 2264 | )); |
| 2265 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2266 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2267 | future<int> push_alloc_cfg_complt = \ |
| 2268 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2269 | |
| 2270 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2271 | int res = push_alloc_cfg_complt.get(); |
| 2272 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2273 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2274 | } |
| 2275 | |
| 2276 | // Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state) |
| 2277 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) { |
| 2278 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2279 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2280 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2281 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2282 | traffic_shaping_info->set_cir(64000); |
| 2283 | traffic_shaping_info->set_pir(128000); |
| 2284 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2285 | |
| 2286 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2287 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2288 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2289 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2290 | bcmolt_onu_cfg onu_cfg_out; |
| 2291 | bcmolt_onu_key onu_key; |
| 2292 | onu_key.pon_ni = 0; |
| 2293 | onu_key.onu_id = 1; |
| 2294 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2295 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2296 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2297 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2298 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2299 | return onu_cfg_get_res; |
| 2300 | } |
| 2301 | )); |
| 2302 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2303 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2304 | future<int> push_alloc_cfg_complt = \ |
| 2305 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2306 | |
| 2307 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2308 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2309 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2310 | } |
| 2311 | |
| 2312 | // Test 5 - CreateTrafficSchedulers-Upstream Failure case |
| 2313 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) { |
| 2314 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2315 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2316 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2317 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2318 | traffic_shaping_info->set_cir(64000); |
| 2319 | traffic_shaping_info->set_pir(128000); |
| 2320 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2321 | |
| 2322 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2323 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2324 | |
| 2325 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2326 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2327 | } |
| 2328 | |
| 2329 | // Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case |
| 2330 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) { |
| 2331 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2332 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2333 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2334 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2335 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2336 | traffic_shaping_info->set_cir(64000); |
| 2337 | traffic_shaping_info->set_pir(0); |
| 2338 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2339 | |
| 2340 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2341 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2342 | } |
| 2343 | |
| 2344 | // Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case |
| 2345 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) { |
| 2346 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2347 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2348 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2349 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2350 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2351 | traffic_shaping_info->set_cir(64000); |
| 2352 | traffic_shaping_info->set_pir(32000); |
| 2353 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2354 | |
| 2355 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2356 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2357 | } |
| 2358 | |
| 2359 | // Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case |
| 2360 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) { |
| 2361 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2362 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2363 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2364 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2365 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2366 | traffic_shaping_info->set_cir(64000); |
| 2367 | traffic_shaping_info->set_pir(64000); |
| 2368 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2369 | |
| 2370 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2371 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2372 | } |
| 2373 | |
| 2374 | // Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case |
| 2375 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) { |
| 2376 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2377 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2378 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2379 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2380 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2381 | traffic_shaping_info->set_cir(64000); |
| 2382 | traffic_shaping_info->set_pir(0); |
| 2383 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2384 | |
| 2385 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2386 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2387 | } |
| 2388 | |
| 2389 | // Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case |
| 2390 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) { |
| 2391 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2392 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2393 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2394 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2395 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2396 | traffic_shaping_info->set_cir(0); |
| 2397 | traffic_shaping_info->set_pir(32000); |
| 2398 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2399 | |
| 2400 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2401 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2402 | } |
| 2403 | |
| 2404 | // Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case |
| 2405 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) { |
| 2406 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2407 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2408 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2409 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2410 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2411 | traffic_shaping_info->set_cir(64000); |
| 2412 | traffic_shaping_info->set_pir(32000); |
| 2413 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2414 | |
| 2415 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2416 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2417 | } |
| 2418 | |
| 2419 | // Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case |
| 2420 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) { |
| 2421 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2422 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2423 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2424 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2425 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2426 | traffic_shaping_info->set_cir(64000); |
| 2427 | traffic_shaping_info->set_pir(64000); |
| 2428 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2429 | |
| 2430 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2431 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2432 | } |
| 2433 | |
| 2434 | // Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case |
| 2435 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) { |
| 2436 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2437 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2438 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2439 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2440 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2441 | traffic_shaping_info->set_cir(64000); |
| 2442 | traffic_shaping_info->set_pir(0); |
| 2443 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2444 | |
| 2445 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2446 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2447 | } |
| 2448 | |
| 2449 | // Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case |
| 2450 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) { |
| 2451 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2452 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2453 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2454 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2455 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2456 | traffic_shaping_info->set_cir(0); |
| 2457 | traffic_shaping_info->set_pir(32000); |
| 2458 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2459 | |
| 2460 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2461 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2462 | } |
| 2463 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2464 | // Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case |
| 2465 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2466 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2467 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2468 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2469 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2470 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2471 | traffic_shaping_info->set_cir(64000); |
| 2472 | traffic_shaping_info->set_pir(128000); |
| 2473 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2474 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2475 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2476 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2477 | } |
| 2478 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2479 | // Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case |
| 2480 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2481 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2482 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2483 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2484 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2485 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2486 | traffic_shaping_info->set_cir(64000); |
| 2487 | traffic_shaping_info->set_pir(32000); |
| 2488 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2489 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2490 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2491 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2492 | } |
| 2493 | |
| 2494 | // Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case |
| 2495 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) { |
| 2496 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2497 | scheduler->set_additional_bw(9); |
| 2498 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2499 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2500 | traffic_shaping_info->set_gir(0); |
| 2501 | traffic_shaping_info->set_cir(64000); |
| 2502 | traffic_shaping_info->set_pir(128000); |
| 2503 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2504 | |
| 2505 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2506 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2507 | } |
| 2508 | |
| 2509 | // Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case |
| 2510 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) { |
| 2511 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2512 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2513 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2514 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2515 | traffic_shaping_info->set_gir(64000); |
| 2516 | traffic_shaping_info->set_cir(0); |
| 2517 | traffic_shaping_info->set_pir(64000); |
| 2518 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2519 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2520 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2521 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2522 | |
| 2523 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2524 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2525 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2526 | |
| 2527 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2528 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2529 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2530 | } |
| 2531 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2532 | // Test 19 - CreateTrafficSchedulers-Downstream success case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2533 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) { |
| 2534 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2535 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2536 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2537 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2538 | traffic_shaping_info->set_cir(64000); |
| 2539 | traffic_shaping_info->set_pir(128000); |
| 2540 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2541 | |
| 2542 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2543 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2544 | |
| 2545 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2546 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2547 | } |
| 2548 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2549 | // Test 20 - CreateTrafficSchedulers-Downstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2550 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) { |
| 2551 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2552 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2553 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2554 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2555 | traffic_shaping_info->set_cir(64000); |
| 2556 | traffic_shaping_info->set_pir(128000); |
| 2557 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2558 | |
| 2559 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2560 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2561 | |
| 2562 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2563 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2564 | } |
| 2565 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2566 | // Test 21 - CreateTrafficSchedulers-Invalid direction Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2567 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) { |
| 2568 | scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 2569 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2570 | traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 2571 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2572 | traffic_shaping_info->set_cir(64000); |
| 2573 | traffic_shaping_info->set_pir(128000); |
| 2574 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2575 | |
| 2576 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2577 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2578 | } |
| 2579 | |
| 2580 | //////////////////////////////////////////////////////////////////////////// |
| 2581 | // For testing RemoveTrafficSchedulers functionality |
| 2582 | //////////////////////////////////////////////////////////////////////////// |
| 2583 | |
| 2584 | class TestRemoveTrafficSchedulers : public Test { |
| 2585 | protected: |
| 2586 | NiceMock<BalMocker> balMock; |
| 2587 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2588 | tech_profile::TrafficScheduler* traffic_sched; |
| 2589 | tech_profile::SchedulerConfig* scheduler; |
| 2590 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 2591 | alloc_cfg_complete_result res; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2592 | uint32_t pon_id = 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2593 | |
| 2594 | virtual void SetUp() { |
| 2595 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2596 | traffic_scheds->set_intf_id(0); |
| 2597 | traffic_scheds->set_onu_id(1); |
| 2598 | traffic_scheds->set_uni_id(0); |
| 2599 | traffic_scheds->set_port_no(16); |
| 2600 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2601 | traffic_sched->set_alloc_id(1025); |
| 2602 | scheduler = new tech_profile::SchedulerConfig; |
| 2603 | scheduler->set_priority(0); |
| 2604 | scheduler->set_weight(0); |
| 2605 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2606 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2607 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 2608 | traffic_shaping_info->set_cir(64000); |
| 2609 | traffic_shaping_info->set_pir(128000); |
| 2610 | traffic_shaping_info->set_cbs(60536); |
| 2611 | traffic_shaping_info->set_pbs(65536); |
| 2612 | traffic_shaping_info->set_gir(10000); |
| 2613 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2614 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2615 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2616 | } |
| 2617 | |
| 2618 | virtual void TearDown() { |
| 2619 | } |
| 2620 | |
| 2621 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2622 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 2623 | alloc_cfg_compltd_key k(0, 1025); |
| 2624 | alloc_cfg_complete_result res; |
| 2625 | res.pon_intf_id = 0; |
| 2626 | res.alloc_id = 1025; |
| 2627 | res.state = state; |
| 2628 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2629 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 2630 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 2631 | // before we push the result. |
| 2632 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2633 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 2634 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 2635 | if (it == alloc_cfg_compltd_map.end()) { |
| 2636 | OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2637 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2638 | it->second->push(res); |
| 2639 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2640 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2641 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 2642 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2643 | } |
| 2644 | }; |
| 2645 | |
| 2646 | // Test 1 - RemoveTrafficSchedulers-Upstream success case |
| 2647 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) { |
| 2648 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2649 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2650 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2651 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2652 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2653 | bcmolt_onu_cfg onu_cfg_out; |
| 2654 | bcmolt_onu_key onu_key; |
| 2655 | onu_key.pon_ni = 0; |
| 2656 | onu_key.onu_id = 1; |
| 2657 | |
| 2658 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2659 | |
| 2660 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2661 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2662 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2663 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2664 | return onu_cfg_get_res; |
| 2665 | } |
| 2666 | )); |
| 2667 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2668 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2669 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2670 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2671 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS); |
| 2672 | |
| 2673 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2674 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2675 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2676 | } |
| 2677 | |
| 2678 | // Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset) |
| 2679 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) { |
| 2680 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2681 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2682 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2683 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2684 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2685 | bcmolt_onu_cfg onu_cfg_out; |
| 2686 | bcmolt_onu_key onu_key; |
| 2687 | onu_key.pon_ni = 0; |
| 2688 | onu_key.onu_id = 1; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2689 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2690 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2691 | |
| 2692 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2693 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2694 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2695 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2696 | return onu_cfg_get_res; |
| 2697 | } |
| 2698 | )); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2699 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2700 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2701 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2702 | |
| 2703 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2704 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2705 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2706 | } |
| 2707 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2708 | // Test 3 - RemoveTrafficSchedulers-Upstream success case(ONU case - Don't wait for alloc object delete response) |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2709 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) { |
| 2710 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2711 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2712 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2713 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2714 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2715 | bcmolt_onu_cfg onu_cfg_out; |
| 2716 | bcmolt_onu_key onu_key; |
| 2717 | onu_key.pon_ni = 0; |
| 2718 | onu_key.onu_id = 1; |
| 2719 | |
| 2720 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2721 | |
| 2722 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2723 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2724 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2725 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2726 | return onu_cfg_get_res; |
| 2727 | } |
| 2728 | )); |
| 2729 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2730 | |
| 2731 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2732 | |
| 2733 | Status status = future_res.get(); |
| 2734 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2735 | } |
| 2736 | |
| 2737 | // Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case) |
| 2738 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) { |
| 2739 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2740 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2741 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2742 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2743 | bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL; |
| 2744 | bcmolt_onu_cfg onu_cfg_out; |
| 2745 | bcmolt_onu_key onu_key; |
| 2746 | onu_key.pon_ni = 0; |
| 2747 | onu_key.onu_id = 1; |
| 2748 | |
| 2749 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2750 | |
| 2751 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2752 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2753 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2754 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2755 | return onu_cfg_get_res; |
| 2756 | } |
| 2757 | )); |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2758 | |
| 2759 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2760 | |
| 2761 | Status status = future_res.get(); |
| 2762 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2763 | } |
| 2764 | |
| 2765 | // Test 5 - RemoveTrafficSchedulers-Upstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2766 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) { |
| 2767 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2768 | |
| 2769 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2770 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2771 | |
| 2772 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2773 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2774 | } |
| 2775 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2776 | // Test 6 - RemoveTrafficSchedulers-Downstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2777 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) { |
| 2778 | //Create Scheduler |
| 2779 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2780 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2781 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2782 | CreateTrafficSchedulers_(traffic_scheds); |
| 2783 | |
| 2784 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2785 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2786 | |
| 2787 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2788 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2789 | } |
| 2790 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2791 | // Test 7 - RemoveTrafficSchedulers-Downstream success case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2792 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) { |
| 2793 | //Create Scheduler |
| 2794 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2795 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2796 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2797 | CreateTrafficSchedulers_(traffic_scheds); |
| 2798 | |
| 2799 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2800 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2801 | |
| 2802 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2803 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2804 | } |
| 2805 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2806 | // Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2807 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) { |
| 2808 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2809 | |
| 2810 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2811 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2812 | } |
| 2813 | |
| 2814 | //////////////////////////////////////////////////////////////////////////// |
| 2815 | // For testing CreateTrafficQueues functionality |
| 2816 | //////////////////////////////////////////////////////////////////////////// |
| 2817 | |
| 2818 | class TestCreateTrafficQueues : public Test { |
| 2819 | protected: |
| 2820 | NiceMock<BalMocker> balMock; |
| 2821 | tech_profile::TrafficQueues* traffic_queues; |
| 2822 | tech_profile::TrafficQueue* traffic_queue_1; |
| 2823 | tech_profile::TrafficQueue* traffic_queue_2; |
| 2824 | tech_profile::DiscardConfig* discard_config_1; |
| 2825 | tech_profile::DiscardConfig* discard_config_2; |
| 2826 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 2827 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 2828 | |
| 2829 | virtual void SetUp() { |
| 2830 | traffic_queues = new tech_profile::TrafficQueues; |
| 2831 | traffic_queues->set_intf_id(0); |
| 2832 | traffic_queues->set_onu_id(1); |
| 2833 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 2834 | traffic_queue_1->set_gemport_id(1024); |
| 2835 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 2836 | traffic_queue_1->set_aes_encryption(true); |
| 2837 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2838 | traffic_queue_1->set_priority(0); |
| 2839 | traffic_queue_1->set_weight(0); |
| 2840 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2841 | discard_config_1 = new tech_profile::DiscardConfig; |
| 2842 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2843 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 2844 | tail_drop_discard_config_1->set_queue_size(8); |
| 2845 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 2846 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 2847 | } |
| 2848 | |
| 2849 | virtual void TearDown() { |
| 2850 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2851 | |
| 2852 | public: |
| 2853 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 2854 | gem_cfg_compltd_key k(0, gem_port_id); |
| 2855 | gem_cfg_complete_result res; |
| 2856 | res.pon_intf_id = 0; |
| 2857 | res.gem_port_id = gem_port_id; |
| 2858 | res.state = state; |
| 2859 | res.status = status; |
| 2860 | |
| 2861 | uint32_t gem_cfg_key_check_counter = 1; |
| 2862 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 2863 | while(true) { |
| 2864 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 2865 | it = gem_cfg_compltd_map.find(k); |
| 2866 | |
| 2867 | if (it != gem_cfg_compltd_map.end()) { |
| 2868 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2869 | break; |
| 2870 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 2871 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2872 | |
| 2873 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 2874 | // before we push the result. |
| 2875 | bcmos_usleep(6000); |
| 2876 | } else { |
| 2877 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 2878 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2879 | return 0; |
| 2880 | } |
| 2881 | gem_cfg_key_check_counter++; |
| 2882 | } |
| 2883 | |
| 2884 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 2885 | if (it->second) { |
| 2886 | it->second->push(res); |
| 2887 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 2888 | } |
| 2889 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2890 | return 0; |
| 2891 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2892 | }; |
| 2893 | |
| 2894 | // Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 2895 | TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2896 | traffic_queues->set_uni_id(0); |
| 2897 | traffic_queues->set_port_no(16); |
| 2898 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2899 | |
| 2900 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2901 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2902 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2903 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 2904 | future<int> push_gem_cfg_complt = \ |
| 2905 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 2906 | Status status = future_res.get(); |
| 2907 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2908 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2909 | |
| 2910 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2911 | status = CreateTrafficQueues_(traffic_queues); |
| 2912 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2913 | } |
| 2914 | |
| 2915 | // Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case |
| 2916 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) { |
| 2917 | traffic_queues->set_uni_id(1); |
| 2918 | traffic_queues->set_port_no(32); |
| 2919 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2920 | |
| 2921 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2922 | traffic_queue_2->set_gemport_id(1025); |
| 2923 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2924 | traffic_queue_2->set_aes_encryption(true); |
| 2925 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2926 | traffic_queue_2->set_priority(1); |
| 2927 | traffic_queue_2->set_weight(0); |
| 2928 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2929 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2930 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2931 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2932 | tail_drop_discard_config_2->set_queue_size(8); |
| 2933 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2934 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2935 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2936 | |
| 2937 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2938 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2939 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2940 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 2941 | future<int> push_gem_cfg_complt = \ |
| 2942 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 2943 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 2944 | push_gem_cfg_complt = \ |
| 2945 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 2946 | Status status = future_res.get(); |
| 2947 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2948 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2949 | } |
| 2950 | |
| 2951 | // Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case |
| 2952 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) { |
| 2953 | traffic_queues->set_uni_id(2); |
| 2954 | traffic_queues->set_port_no(16); |
| 2955 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2956 | |
| 2957 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2958 | traffic_queue_2->set_gemport_id(1025); |
| 2959 | traffic_queue_2->set_pbit_map("0b10001010"); |
| 2960 | traffic_queue_2->set_aes_encryption(true); |
| 2961 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2962 | traffic_queue_2->set_priority(1); |
| 2963 | traffic_queue_2->set_weight(0); |
| 2964 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2965 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2966 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2967 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2968 | tail_drop_discard_config_2->set_queue_size(8); |
| 2969 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2970 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2971 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2972 | |
| 2973 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2974 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2975 | |
| 2976 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2977 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2978 | } |
| 2979 | |
| 2980 | // Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case |
| 2981 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) { |
| 2982 | traffic_queues->set_uni_id(3); |
| 2983 | traffic_queues->set_port_no(16); |
| 2984 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2985 | |
| 2986 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2987 | traffic_queue_2->set_gemport_id(1025); |
| 2988 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2989 | traffic_queue_2->set_aes_encryption(true); |
| 2990 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2991 | traffic_queue_2->set_priority(1); |
| 2992 | traffic_queue_2->set_weight(0); |
| 2993 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2994 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2995 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2996 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2997 | tail_drop_discard_config_2->set_queue_size(8); |
| 2998 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2999 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 3000 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 3001 | |
| 3002 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3003 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3004 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3005 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 3006 | future<int> push_gem_cfg_complt = \ |
| 3007 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3008 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3009 | push_gem_cfg_complt = \ |
| 3010 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3011 | Status status = future_res.get(); |
| 3012 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3013 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3014 | } |
| 3015 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3016 | // Test 5 - CreateTrafficQueues-Downstream PRIORITY_TO_QUEUE TM QMP Max count reached case |
| 3017 | TEST_F(TestCreateTrafficQueues, CreateDownstreamPriorityQueueReachedMaxTMQMPCount) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3018 | int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; |
| 3019 | int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272}; |
| 3020 | std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"}; |
| 3021 | |
| 3022 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3023 | for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) { |
| 3024 | traffic_queues->set_uni_id(uni_ids[i]); |
| 3025 | traffic_queues->set_port_no(port_nos[i]); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3026 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3027 | |
| 3028 | traffic_queue_2->set_gemport_id(1025); |
| 3029 | traffic_queue_2->set_pbit_map(pbit_maps[i]); |
| 3030 | traffic_queue_2->set_aes_encryption(true); |
| 3031 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 3032 | traffic_queue_2->set_priority(1); |
| 3033 | traffic_queue_2->set_weight(0); |
| 3034 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 3035 | discard_config_2 = new tech_profile::DiscardConfig; |
| 3036 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 3037 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 3038 | tail_drop_discard_config_2->set_queue_size(8); |
| 3039 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 3040 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3041 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3042 | |
| 3043 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3044 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3045 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3046 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 3047 | future<int> push_gem_cfg_complt = \ |
| 3048 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3049 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3050 | push_gem_cfg_complt = \ |
| 3051 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3052 | Status status = future_res.get(); |
| 3053 | int res = push_gem_cfg_complt.get(); |
| 3054 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3055 | if(i==16) |
| 3056 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3057 | else |
| 3058 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | // Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case |
| 3063 | TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) { |
| 3064 | traffic_queues->set_uni_id(0); |
| 3065 | traffic_queues->set_port_no(16); |
| 3066 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3067 | |
| 3068 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3069 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3070 | |
| 3071 | Status status = CreateTrafficQueues_(traffic_queues); |
| 3072 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3073 | } |
| 3074 | |
| 3075 | //////////////////////////////////////////////////////////////////////////// |
| 3076 | // For testing RemoveTrafficQueues functionality |
| 3077 | //////////////////////////////////////////////////////////////////////////// |
| 3078 | |
| 3079 | class TestRemoveTrafficQueues : public Test { |
| 3080 | protected: |
| 3081 | NiceMock<BalMocker> balMock; |
| 3082 | tech_profile::TrafficQueues* traffic_queues; |
| 3083 | tech_profile::TrafficQueue* traffic_queue_1; |
| 3084 | tech_profile::TrafficQueue* traffic_queue_2; |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3085 | uint32_t pon_id = 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3086 | |
| 3087 | virtual void SetUp() { |
| 3088 | traffic_queues = new tech_profile::TrafficQueues; |
| 3089 | traffic_queues->set_intf_id(0); |
| 3090 | traffic_queues->set_onu_id(1); |
| 3091 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 3092 | traffic_queue_1->set_gemport_id(1024); |
| 3093 | traffic_queue_1->set_priority(0); |
| 3094 | } |
| 3095 | |
| 3096 | virtual void TearDown() { |
| 3097 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3098 | |
| 3099 | public: |
| 3100 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 3101 | gem_cfg_compltd_key k(0, gem_port_id); |
| 3102 | gem_cfg_complete_result res; |
| 3103 | res.pon_intf_id = 0; |
| 3104 | res.gem_port_id = gem_port_id; |
| 3105 | res.state = state; |
| 3106 | res.status = status; |
| 3107 | |
| 3108 | uint32_t gem_cfg_key_check_counter = 1; |
| 3109 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 3110 | while(true) { |
| 3111 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 3112 | it = gem_cfg_compltd_map.find(k); |
| 3113 | |
| 3114 | if (it != gem_cfg_compltd_map.end()) { |
| 3115 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3116 | break; |
| 3117 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 3118 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3119 | |
| 3120 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 3121 | // before we push the result. |
| 3122 | bcmos_usleep(6000); |
| 3123 | } else { |
| 3124 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 3125 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3126 | return 0; |
| 3127 | } |
| 3128 | gem_cfg_key_check_counter++; |
| 3129 | } |
| 3130 | |
| 3131 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 3132 | if (it->second) { |
| 3133 | it->second->push(res); |
| 3134 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 3135 | } |
| 3136 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3137 | return 0; |
| 3138 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3139 | }; |
| 3140 | |
| 3141 | // Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 3142 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3143 | traffic_queues->set_uni_id(0); |
| 3144 | traffic_queues->set_port_no(16); |
| 3145 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3146 | |
| 3147 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3148 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3149 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3150 | bcmolt_pon_interface_key pon_key; |
| 3151 | bcmolt_pon_interface_cfg pon_cfg; |
| 3152 | pon_key.pon_ni = pon_id; |
| 3153 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3154 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3155 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3156 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
Thiyagarajan Subramani | 19168f5 | 2021-05-25 23:26:41 +0530 | [diff] [blame] | 3157 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3158 | |
| 3159 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3160 | future<int> push_gem_cfg_complt = \ |
| 3161 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3162 | |
| 3163 | Status status = future_res.get(); |
| 3164 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3165 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3166 | |
| 3167 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3168 | status = RemoveTrafficQueues_(traffic_queues); |
| 3169 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3170 | } |
| 3171 | |
| 3172 | // Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case |
| 3173 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3174 | traffic_queues->set_uni_id(0); |
| 3175 | traffic_queues->set_port_no(16); |
| 3176 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3177 | |
| 3178 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 3179 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3180 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3181 | Status status = RemoveTrafficQueues_(traffic_queues); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3182 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3183 | } |
| 3184 | |
| 3185 | // Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case |
| 3186 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) { |
| 3187 | //Remove scheduler so that is_tm_sched_id_present api call will return false |
| 3188 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 3189 | tech_profile::TrafficScheduler* traffic_sched; |
| 3190 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 3191 | traffic_scheds->set_intf_id(0); |
| 3192 | traffic_scheds->set_onu_id(1); |
| 3193 | traffic_scheds->set_uni_id(0); |
| 3194 | traffic_scheds->set_port_no(16); |
| 3195 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 3196 | traffic_sched->set_alloc_id(1024); |
| 3197 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3198 | |
| 3199 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3200 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3201 | RemoveTrafficSchedulers_(traffic_scheds); |
| 3202 | |
| 3203 | traffic_queues->set_uni_id(0); |
| 3204 | traffic_queues->set_port_no(16); |
| 3205 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3206 | |
| 3207 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 3208 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3209 | } |
| 3210 | |
| 3211 | /* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP |
| 3212 | as it is getting referred by some other queues case */ |
| 3213 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) { |
| 3214 | traffic_queues->set_uni_id(3); |
| 3215 | traffic_queues->set_port_no(16); |
| 3216 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3217 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3218 | traffic_queue_2->set_gemport_id(1025); |
| 3219 | traffic_queue_2->set_priority(1); |
| 3220 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 3221 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3222 | bcmolt_pon_interface_key pon_key; |
| 3223 | bcmolt_pon_interface_cfg pon_cfg; |
| 3224 | pon_key.pon_ni = pon_id; |
| 3225 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3226 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3227 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3228 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3229 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3230 | |
| 3231 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3232 | future<int> push_gem_cfg_complt = \ |
| 3233 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3234 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3235 | push_gem_cfg_complt = \ |
| 3236 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3237 | |
| 3238 | Status status = future_res.get(); |
| 3239 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3240 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3241 | } |
| 3242 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3243 | /* Test 5 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, removing TM QMP as it |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3244 | is not getting referred by any other queues case */ |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3245 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueRemovingTMQMP) { |
| 3246 | traffic_queues->set_uni_id(5); |
| 3247 | traffic_queues->set_port_no(80); |
| 3248 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3249 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3250 | traffic_queue_2->set_gemport_id(1025); |
| 3251 | traffic_queue_2->set_priority(1); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3252 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3253 | |
| 3254 | bcmolt_pon_interface_key pon_key; |
| 3255 | bcmolt_pon_interface_cfg pon_cfg; |
| 3256 | pon_key.pon_ni = pon_id; |
| 3257 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3258 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3259 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3260 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3261 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3262 | |
| 3263 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3264 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3265 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3266 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3267 | future<int> push_gem_cfg_complt = \ |
| 3268 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3269 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3270 | push_gem_cfg_complt = \ |
| 3271 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3272 | |
| 3273 | Status status = future_res.get(); |
| 3274 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3275 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3276 | } |
| 3277 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3278 | /* Test 6 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, error while removing TM QMP |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3279 | having no reference to any other queues case */ |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3280 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueErrorRemovingTMQMP) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3281 | traffic_queues->set_uni_id(4); |
| 3282 | traffic_queues->set_port_no(64); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3283 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3284 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3285 | traffic_queue_2->set_gemport_id(1025); |
| 3286 | traffic_queue_2->set_priority(1); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3287 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3288 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3289 | bcmolt_pon_interface_key pon_key; |
| 3290 | bcmolt_pon_interface_cfg pon_cfg; |
| 3291 | pon_key.pon_ni = pon_id; |
| 3292 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3293 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3294 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3295 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3296 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3297 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3298 | bcmos_errno olt_cfg_clear_res_success = BCM_ERR_OK; |
| 3299 | bcmos_errno olt_cfg_clear_res_failure = BCM_ERR_INTERNAL; |
| 3300 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)) |
| 3301 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3302 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3303 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3304 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3305 | .WillRepeatedly(Return(olt_cfg_clear_res_failure)); |
| 3306 | |
| 3307 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3308 | future<int> push_gem_cfg_complt = \ |
| 3309 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3310 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3311 | push_gem_cfg_complt = \ |
| 3312 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3313 | |
| 3314 | Status status = future_res.get(); |
| 3315 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3316 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3317 | } |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3318 | |
| 3319 | //////////////////////////////////////////////////////////////////////////// |
| 3320 | // For testing OnuItuPonAlarmSet functionality |
| 3321 | //////////////////////////////////////////////////////////////////////////// |
| 3322 | |
| 3323 | class TestOnuItuPonAlarmSet : public Test { |
| 3324 | protected: |
| 3325 | bcmolt_pon_ni pon_ni = 0; |
| 3326 | bcmolt_onu_id onu_id = 1; |
| 3327 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3328 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rt; |
| 3329 | config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config; |
| 3330 | config::OnuItuPonAlarm::SoakTime *soak_time_rt; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3331 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3332 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rr; |
| 3333 | config::OnuItuPonAlarm::RateRangeConfig *rate_range_config; |
| 3334 | config::OnuItuPonAlarm::SoakTime *soak_time_rr; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3335 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3336 | config::OnuItuPonAlarm *onu_itu_pon_alarm_tc; |
| 3337 | config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config; |
| 3338 | config::OnuItuPonAlarm::SoakTime *soak_time_tc; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3339 | |
| 3340 | NiceMock<BalMocker> balMock; |
| 3341 | |
| 3342 | virtual void SetUp() { |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3343 | onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm; |
| 3344 | rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig; |
| 3345 | soak_time_rt = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3346 | onu_itu_pon_alarm_rt->set_pon_ni(0); |
| 3347 | onu_itu_pon_alarm_rt->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3348 | onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3349 | onu_itu_pon_alarm_rt->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD); |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3350 | rate_threshold_config->set_rate_threshold_rising(1); |
| 3351 | rate_threshold_config->set_rate_threshold_falling(4); |
| 3352 | soak_time_rt->set_active_soak_time(2); |
| 3353 | soak_time_rt->set_clear_soak_time(2); |
| 3354 | rate_threshold_config->set_allocated_soak_time(soak_time_rt); |
| 3355 | onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config); |
| 3356 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3357 | onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm; |
| 3358 | rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig; |
| 3359 | soak_time_rr = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3360 | onu_itu_pon_alarm_rr->set_pon_ni(0); |
| 3361 | onu_itu_pon_alarm_rr->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3362 | onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3363 | onu_itu_pon_alarm_rr->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE); |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3364 | rate_range_config->set_rate_range_lower(1); |
| 3365 | rate_range_config->set_rate_range_upper(4); |
| 3366 | soak_time_rr->set_active_soak_time(2); |
| 3367 | soak_time_rr->set_clear_soak_time(2); |
| 3368 | rate_range_config->set_allocated_soak_time(soak_time_rr); |
| 3369 | onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config); |
| 3370 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3371 | onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm; |
| 3372 | value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig; |
| 3373 | soak_time_tc = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3374 | onu_itu_pon_alarm_tc->set_pon_ni(0); |
| 3375 | onu_itu_pon_alarm_tc->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3376 | onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3377 | onu_itu_pon_alarm_tc->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD); |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3378 | value_threshold_config->set_threshold_limit(6); |
| 3379 | soak_time_tc->set_active_soak_time(2); |
| 3380 | soak_time_tc->set_clear_soak_time(2); |
| 3381 | value_threshold_config->set_allocated_soak_time(soak_time_tc); |
| 3382 | onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config); |
| 3383 | } |
| 3384 | |
| 3385 | virtual void TearDown() { |
| 3386 | } |
| 3387 | }; |
| 3388 | |
| 3389 | // Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case |
| 3390 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 3391 | // the configured threshold boundary. |
| 3392 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) { |
| 3393 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3394 | bcmolt_onu_key key = {}; |
| 3395 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3396 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 3397 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 3398 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 3399 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3400 | |
| 3401 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3402 | |
| 3403 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 3404 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3405 | } |
| 3406 | |
| 3407 | // Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case |
| 3408 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 3409 | // the configured threshold boundary. |
| 3410 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) { |
| 3411 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3412 | bcmolt_onu_key key = {}; |
| 3413 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3414 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 3415 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 3416 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 3417 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3418 | |
| 3419 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3420 | |
| 3421 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 3422 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3423 | } |
| 3424 | |
| 3425 | // Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case |
| 3426 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 3427 | // from the configured range. |
| 3428 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) { |
| 3429 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3430 | bcmolt_onu_key key = {}; |
| 3431 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3432 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 3433 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100; |
| 3434 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50; |
| 3435 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3436 | |
| 3437 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3438 | |
| 3439 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 3440 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3441 | } |
| 3442 | |
| 3443 | // Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case |
| 3444 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 3445 | // from the configured range. |
| 3446 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) { |
| 3447 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3448 | bcmolt_onu_key key = {}; |
| 3449 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3450 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 3451 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50; |
| 3452 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100; |
| 3453 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3454 | |
| 3455 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3456 | |
| 3457 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 3458 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3459 | } |
| 3460 | |
| 3461 | // Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case |
| 3462 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 3463 | // level. The alarm is cleared when the host read the stats. |
| 3464 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) { |
| 3465 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3466 | bcmolt_onu_key key = {}; |
| 3467 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3468 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 3469 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100; |
| 3470 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3471 | |
| 3472 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3473 | |
| 3474 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 3475 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3476 | } |
| 3477 | |
| 3478 | // Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case |
| 3479 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 3480 | // level. The alarm is cleared when the host read the stats. |
| 3481 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) { |
| 3482 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3483 | bcmolt_onu_key key = {}; |
| 3484 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3485 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 3486 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1; |
| 3487 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3488 | |
| 3489 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3490 | |
| 3491 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 3492 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3493 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 3494 | |
| 3495 | //////////////////////////////////////////////////////////////////////////// |
| 3496 | // For testing DeleteGroup functionality |
| 3497 | //////////////////////////////////////////////////////////////////////////// |
| 3498 | |
| 3499 | class TestDeleteGroup : public Test { |
| 3500 | protected: |
| 3501 | uint32_t group_id = 1; |
| 3502 | NiceMock<BalMocker> balMock; |
| 3503 | |
| 3504 | virtual void SetUp() { |
| 3505 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 3506 | }; |
| 3507 | |
| 3508 | // Test 1 - DeleteGroup success case |
| 3509 | TEST_F(TestDeleteGroup, DeleteGroupSuccess) { |
| 3510 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3511 | bcmos_errno group_cfg_clear_res = BCM_ERR_OK; |
| 3512 | bcmolt_group_cfg grp_cfg_out; |
| 3513 | bcmolt_group_key grp_key = {}; |
| 3514 | |
| 3515 | grp_key.id = group_id; |
| 3516 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3517 | |
| 3518 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3519 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3520 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 3521 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3522 | return group_cfg_get_res; |
| 3523 | } |
| 3524 | )); |
| 3525 | |
| 3526 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 3527 | |
| 3528 | Status status = DeleteGroup_(group_id); |
| 3529 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3530 | } |
| 3531 | |
| 3532 | // Test 2 - DeleteGroup failure case: Group does not exist |
| 3533 | TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) { |
| 3534 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3535 | bcmolt_group_cfg grp_cfg_out; |
| 3536 | bcmolt_group_key grp_key = {}; |
| 3537 | |
| 3538 | grp_key.id = group_id; |
| 3539 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3540 | |
| 3541 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3542 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3543 | grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED; |
| 3544 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3545 | return group_cfg_get_res; |
| 3546 | } |
| 3547 | )); |
| 3548 | |
| 3549 | Status status = DeleteGroup_(group_id); |
| 3550 | ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND ); |
| 3551 | } |
| 3552 | |
| 3553 | // Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.) |
| 3554 | TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) { |
| 3555 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3556 | bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL; |
| 3557 | bcmolt_group_cfg grp_cfg_out; |
| 3558 | bcmolt_group_key grp_key = {}; |
| 3559 | |
| 3560 | grp_key.id = group_id; |
| 3561 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3562 | |
| 3563 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3564 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3565 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 3566 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3567 | return group_cfg_get_res; |
| 3568 | } |
| 3569 | )); |
| 3570 | |
| 3571 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 3572 | |
| 3573 | Status status = DeleteGroup_(group_id); |
| 3574 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3575 | } |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 3576 | |
| 3577 | //////////////////////////////////////////////////////////////////////////// |
| 3578 | // For testing OnuLogicalDistanceZero functionality |
| 3579 | //////////////////////////////////////////////////////////////////////////// |
| 3580 | class TestOnuLogicalDistanceZero : public Test { |
| 3581 | protected: |
| 3582 | NiceMock<BalMocker> balMock; |
| 3583 | bcmolt_pon_ni pon_ni = 0; |
| 3584 | openolt::OnuLogicalDistance *onu_logical_distance_zero; |
| 3585 | |
| 3586 | virtual void SetUp() { |
| 3587 | onu_logical_distance_zero = new openolt::OnuLogicalDistance; |
| 3588 | onu_logical_distance_zero->set_intf_id(pon_ni); |
| 3589 | } |
| 3590 | virtual void TearDown() { |
| 3591 | } |
| 3592 | }; |
| 3593 | |
| 3594 | // |
| 3595 | // Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case |
| 3596 | // |
| 3597 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) { |
| 3598 | bcmolt_pon_distance pon_distance = {}; |
| 3599 | bcmolt_pon_interface_cfg pon_cfg; |
| 3600 | bcmolt_pon_interface_key key = {}; |
| 3601 | |
| 3602 | key.pon_ni = pon_ni; |
| 3603 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3604 | state.activate(); |
| 3605 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3606 | |
| 3607 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3608 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3609 | |
| 3610 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3611 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3612 | } |
| 3613 | |
| 3614 | // Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case |
| 3615 | // The PON state is not ready for failure case |
| 3616 | // |
| 3617 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) { |
| 3618 | bcmolt_pon_distance pon_distance = {}; |
| 3619 | bcmolt_pon_interface_cfg pon_cfg; |
| 3620 | bcmolt_pon_interface_key key = {}; |
| 3621 | |
| 3622 | key.pon_ni = pon_ni; |
| 3623 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3624 | state.deactivate(); |
| 3625 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL; |
| 3626 | |
| 3627 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3628 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3629 | } |
| 3630 | |
| 3631 | class TestOnuLogicalDistance : public Test { |
| 3632 | protected: |
| 3633 | NiceMock<BalMocker> balMock; |
| 3634 | bcmolt_pon_ni pon_ni = 0; |
| 3635 | bcmolt_onu_id onu_id = 1; |
| 3636 | openolt::OnuLogicalDistance *onu_logical_distance; |
| 3637 | |
| 3638 | virtual void SetUp() { |
| 3639 | onu_logical_distance = new openolt::OnuLogicalDistance; |
| 3640 | onu_logical_distance->set_intf_id(pon_ni); |
| 3641 | onu_logical_distance->set_onu_id(onu_id); |
| 3642 | } |
| 3643 | virtual void TearDown() { |
| 3644 | } |
| 3645 | }; |
| 3646 | |
| 3647 | // |
| 3648 | // Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case |
| 3649 | // |
| 3650 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) { |
| 3651 | bcmolt_pon_distance pon_distance = {}; |
| 3652 | bcmolt_pon_interface_cfg pon_cfg; |
| 3653 | bcmolt_pon_interface_key key = {}; |
| 3654 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3655 | |
| 3656 | key.pon_ni = pon_ni; |
| 3657 | state.activate(); |
| 3658 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3659 | |
| 3660 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3661 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3662 | |
| 3663 | bcmolt_onu_cfg onu_cfg; |
| 3664 | bcmolt_onu_key onu_key = {}; |
| 3665 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3666 | |
| 3667 | onu_key.pon_ni = pon_ni; |
| 3668 | onu_key.onu_id = onu_id; |
| 3669 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3670 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 3671 | |
| 3672 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3673 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3674 | |
| 3675 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3676 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3677 | } |
| 3678 | |
| 3679 | // Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3680 | // The failure case is for retrieving ONU ranging time |
| 3681 | // |
| 3682 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) { |
| 3683 | bcmolt_pon_distance pon_distance = {}; |
| 3684 | bcmolt_pon_interface_cfg pon_cfg; |
| 3685 | bcmolt_pon_interface_key key = {}; |
| 3686 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3687 | |
| 3688 | key.pon_ni = pon_ni; |
| 3689 | state.activate(); |
| 3690 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3691 | |
| 3692 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3693 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3694 | |
| 3695 | bcmolt_onu_cfg onu_cfg; |
| 3696 | bcmolt_onu_key onu_key = {}; |
| 3697 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 3698 | |
| 3699 | onu_key.pon_ni = pon_ni; |
| 3700 | onu_key.onu_id = onu_id; |
| 3701 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3702 | |
| 3703 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3704 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3705 | |
| 3706 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3707 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3708 | } |
| 3709 | |
| 3710 | // Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3711 | // The failure case is for ONU is not yet activated |
| 3712 | // |
| 3713 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) { |
| 3714 | bcmolt_pon_distance pon_distance = {}; |
| 3715 | bcmolt_pon_interface_cfg pon_cfg; |
| 3716 | bcmolt_pon_interface_key key = {}; |
| 3717 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3718 | |
| 3719 | key.pon_ni = pon_ni; |
| 3720 | state.activate(); |
| 3721 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3722 | |
| 3723 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3724 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3725 | |
| 3726 | bcmolt_onu_cfg onu_cfg; |
| 3727 | bcmolt_onu_key onu_key = {}; |
| 3728 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3729 | |
| 3730 | onu_key.pon_ni = pon_ni; |
| 3731 | onu_key.onu_id = onu_id; |
| 3732 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3733 | |
| 3734 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3735 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3736 | |
| 3737 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 3738 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3739 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3740 | } |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 3741 | |
| 3742 | //////////////////////////////////////////////////////////////////////////// |
| 3743 | // For testing Secure Server functionality |
| 3744 | //////////////////////////////////////////////////////////////////////////// |
| 3745 | |
| 3746 | class TestSecureServer : public Test { |
| 3747 | protected: |
| 3748 | virtual void SetUp() {} |
| 3749 | virtual void TearDown() {} |
| 3750 | }; |
| 3751 | |
| 3752 | TEST_F(TestSecureServer, StartInsecureServer) { |
| 3753 | // const to prevent the following warning: |
| 3754 | // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] |
| 3755 | const char *args[] = {"./openolt"}; |
| 3756 | int argc = sizeof(args) / sizeof(args[0]); |
| 3757 | char **argv = const_cast<char**>(args); |
| 3758 | |
| 3759 | bool ok = RunServer(argc, argv); |
| 3760 | |
| 3761 | ASSERT_TRUE(ok); |
| 3762 | |
| 3763 | OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n"); |
| 3764 | } |
| 3765 | |
| 3766 | TEST_F(TestSecureServer, StartWithInvalidTLSOption) { |
| 3767 | const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3768 | int argc = sizeof(args) / sizeof(args[0]); |
| 3769 | char **argv = const_cast<char**>(args); |
| 3770 | |
| 3771 | bool ok = RunServer(argc, argv); |
| 3772 | |
| 3773 | ASSERT_FALSE(ok); |
| 3774 | |
| 3775 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n"); |
| 3776 | } |
| 3777 | |
| 3778 | TEST_F(TestSecureServer, CertificatesAreMissing) { |
| 3779 | const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3780 | int argc = sizeof(args) / sizeof(args[0]); |
| 3781 | char **argv = const_cast<char**>(args); |
| 3782 | const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'"; |
| 3783 | |
| 3784 | int res = std::system(cmd.c_str()); |
| 3785 | if (res == 0) { |
| 3786 | std::cout << "directory ./keystore is deleted\n"; |
| 3787 | } else { |
| 3788 | std::cout << "directory ./keystore is not existing\n"; |
| 3789 | } |
| 3790 | |
| 3791 | bool ok = RunServer(argc, argv); |
| 3792 | |
| 3793 | ASSERT_FALSE(ok); |
| 3794 | |
| 3795 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n"); |
| 3796 | } |
| 3797 | |
| 3798 | TEST_F(TestSecureServer, StartWithValidTLSOption) { |
| 3799 | const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3800 | int argc = sizeof(args) / sizeof(args[0]); |
| 3801 | char **argv = const_cast<char**>(args); |
| 3802 | const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore"; |
| 3803 | const std::string cmd_2 = "exec rm -rf './keystore'"; |
| 3804 | |
| 3805 | int res = std::system(cmd_1.c_str()); |
| 3806 | if (res == 0) { |
| 3807 | std::cout << "directory ./keystore is copied from ./keystore-test\n"; |
| 3808 | |
| 3809 | bool ok = RunServer(argc, argv); |
| 3810 | ASSERT_TRUE(ok); |
| 3811 | |
| 3812 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n"); |
| 3813 | |
| 3814 | res = std::system(cmd_2.c_str()); |
| 3815 | if (res == 0) { |
| 3816 | std::cout << "directory ./keystore is deleted\n"; |
| 3817 | } else { |
| 3818 | std::cerr << "directory ./keystore could not be deleted\n"; |
| 3819 | } |
| 3820 | } else { |
| 3821 | std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n'; |
| 3822 | FAIL(); |
| 3823 | } |
| 3824 | } |
Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 3825 | |
| 3826 | //////////////////////////////////////////////////////////////////////////// |
| 3827 | // For testing RxTx Power Read functionality |
| 3828 | //////////////////////////////////////////////////////////////////////////// |
| 3829 | |
| 3830 | class TestPowerRead : public Test { |
| 3831 | protected: |
| 3832 | virtual void SetUp() { |
| 3833 | std::array<char, 600> content = {}; |
| 3834 | content.fill(0x00); // not required for 0x00 |
| 3835 | |
| 3836 | // for asfvolt16 |
| 3837 | content[102] = 0x5D; |
| 3838 | content[103] = 0x38; |
| 3839 | content[104] = 0x1A; |
| 3840 | content[105] = 0xB5; |
| 3841 | |
| 3842 | // for asgvolt64 |
| 3843 | content[358] = 0x5C; |
| 3844 | content[359] = 0x82; |
| 3845 | content[360] = 0x04; |
| 3846 | content[361] = 0xBE; |
| 3847 | |
| 3848 | std::ofstream test_file; |
| 3849 | test_file.open(file_name, std::ios::binary | std::ios::out); |
| 3850 | test_file.write(content.data(), content.size()); |
| 3851 | test_file.close(); |
| 3852 | |
| 3853 | const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump; |
| 3854 | |
| 3855 | int res = std::system(cmd.c_str()); |
| 3856 | if (res == 0) { |
| 3857 | std::ifstream dump_file(hex_dump) ; |
| 3858 | std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() }; |
| 3859 | std::cout << cmd << '\n'; |
| 3860 | std::cout << hexdump << '\n'; |
| 3861 | } else { |
| 3862 | std::cerr << "hexdump capture failed\n"; |
| 3863 | } |
| 3864 | } |
| 3865 | virtual void TearDown() { |
| 3866 | std::remove(file_name.c_str()); |
| 3867 | std::remove(hex_dump.c_str()); |
| 3868 | } |
| 3869 | |
| 3870 | const std::string file_name = "eeprom.bin"; |
| 3871 | const std::string hex_dump = file_name + ".hexdump"; |
| 3872 | }; |
| 3873 | |
| 3874 | TEST_F(TestPowerRead, TestAsfvolt16) { |
| 3875 | std::cout << "Test Power Reads on XGS-PON OLT:\n"; |
| 3876 | |
| 3877 | int port = 20; |
| 3878 | auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3879 | |
| 3880 | std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n'; |
| 3881 | |
| 3882 | ASSERT_FALSE(trx_eeprom_reader1.is_valid_port()); |
| 3883 | |
| 3884 | port = 0; |
| 3885 | auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3886 | |
| 3887 | std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n'; |
| 3888 | std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n'; |
| 3889 | std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n'; |
| 3890 | std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n'; |
| 3891 | std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n'; |
| 3892 | |
| 3893 | auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw(); |
| 3894 | |
| 3895 | ASSERT_TRUE(rxtx_power_raw.second); |
| 3896 | |
| 3897 | std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first |
| 3898 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first |
| 3899 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, " |
| 3900 | << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first)) << " dBm\n"; |
| 3901 | std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second |
| 3902 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second |
| 3903 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, " |
| 3904 | << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second)) << " dBm\n"; |
| 3905 | std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n'; |
| 3906 | |
| 3907 | ASSERT_TRUE(trx_eeprom_reader2.is_valid_port()); |
| 3908 | ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256); |
| 3909 | ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104); |
| 3910 | ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2); |
| 3911 | ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20); |
| 3912 | ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837 |
| 3913 | ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864 |
| 3914 | ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom"); |
| 3915 | } |
| 3916 | |
| 3917 | TEST_F(TestPowerRead, TestAsgvolt64) { |
| 3918 | std::cout << "Test Power Reads on GPON OLT:\n"; |
| 3919 | |
| 3920 | int port = 80; |
| 3921 | auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3922 | |
| 3923 | std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n'; |
| 3924 | |
| 3925 | ASSERT_FALSE(trx_eeprom_reader1.is_valid_port()); |
| 3926 | |
| 3927 | port = 0; |
| 3928 | auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3929 | |
| 3930 | std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n'; |
| 3931 | std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n'; |
| 3932 | std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n'; |
| 3933 | std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n'; |
| 3934 | std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n'; |
| 3935 | |
| 3936 | auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw(); |
| 3937 | |
| 3938 | ASSERT_TRUE(rxtx_power_raw.second); |
| 3939 | |
| 3940 | std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first |
| 3941 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first |
| 3942 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, " |
| 3943 | << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first)) << " dBm\n"; |
| 3944 | std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second |
| 3945 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second |
| 3946 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, " |
| 3947 | << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second)) << " dBm\n"; |
| 3948 | std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n'; |
| 3949 | |
| 3950 | ASSERT_TRUE(trx_eeprom_reader2.is_valid_port()); |
| 3951 | ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600); |
| 3952 | ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360); |
| 3953 | ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2); |
| 3954 | ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74); |
| 3955 | ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214 |
| 3956 | ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682 |
| 3957 | ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom"); |
| 3958 | } |