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"); |
| 1414 | |
| 1415 | action->set_o_vid(12); |
| 1416 | action->set_o_pbits(0); |
| 1417 | action->set_o_tpid(0); |
| 1418 | action->set_i_vid(0); |
| 1419 | action->set_i_pbits(0); |
| 1420 | action->set_i_tpid(0); |
| 1421 | |
| 1422 | cmd->set_add_outer_tag(true); |
| 1423 | cmd->set_remove_outer_tag(false); |
| 1424 | cmd->set_trap_to_host(false); |
| 1425 | action->set_allocated_cmd(cmd); |
| 1426 | |
| 1427 | flow_key.flow_id = 1; |
| 1428 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1429 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1430 | flow_cfg.data.onu_id=1; |
| 1431 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1432 | flow_cfg.data.svc_port_id=1024; |
| 1433 | flow_cfg.data.priority=0; |
| 1434 | flow_cfg.data.cookie=0; |
| 1435 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1436 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1437 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1438 | flow_cfg.data.egress_intf.intf_id=0; |
| 1439 | flow_cfg.data.classifier.o_vid=7; |
| 1440 | flow_cfg.data.classifier.o_pbits=0; |
| 1441 | flow_cfg.data.classifier.i_vid=0; |
| 1442 | flow_cfg.data.classifier.i_pbits=0; |
| 1443 | flow_cfg.data.classifier.ether_type=0; |
| 1444 | flow_cfg.data.classifier.ip_proto=0; |
| 1445 | flow_cfg.data.classifier.src_port=0; |
| 1446 | flow_cfg.data.classifier.dst_port=0; |
| 1447 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1448 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1449 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1450 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1451 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1452 | flow_cfg.data.action.o_vid=12; |
| 1453 | flow_cfg.data.action.o_pbits=0; |
| 1454 | flow_cfg.data.action.i_vid=0; |
| 1455 | flow_cfg.data.action.i_pbits=0; |
| 1456 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1457 | |
| 1458 | traffic_queues = new tech_profile::TrafficQueues; |
| 1459 | traffic_queues->set_intf_id(0); |
| 1460 | traffic_queues->set_onu_id(2); |
| 1461 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 1462 | traffic_queue_1->set_gemport_id(1024); |
| 1463 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 1464 | traffic_queue_1->set_aes_encryption(true); |
| 1465 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1466 | traffic_queue_1->set_priority(0); |
| 1467 | traffic_queue_1->set_weight(0); |
| 1468 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1469 | discard_config_1 = new tech_profile::DiscardConfig; |
| 1470 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1471 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 1472 | tail_drop_discard_config_1->set_queue_size(8); |
| 1473 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 1474 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 1475 | |
| 1476 | traffic_queues->set_uni_id(0); |
| 1477 | traffic_queues->set_port_no(16); |
| 1478 | |
| 1479 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1480 | traffic_queue_2->set_gemport_id(1025); |
| 1481 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 1482 | traffic_queue_2->set_aes_encryption(true); |
| 1483 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1484 | traffic_queue_2->set_priority(1); |
| 1485 | traffic_queue_2->set_weight(0); |
| 1486 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1487 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1488 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1489 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1490 | tail_drop_discard_config_2->set_queue_size(8); |
| 1491 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1492 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1493 | } |
| 1494 | |
| 1495 | virtual void TearDown() { |
| 1496 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1497 | |
| 1498 | public: |
| 1499 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 1500 | gem_cfg_compltd_key k(0, gem_port_id); |
| 1501 | gem_cfg_complete_result res; |
| 1502 | res.pon_intf_id = 0; |
| 1503 | res.gem_port_id = gem_port_id; |
| 1504 | res.state = state; |
| 1505 | res.status = status; |
| 1506 | |
| 1507 | uint32_t gem_cfg_key_check_counter = 1; |
| 1508 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 1509 | while(true) { |
| 1510 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 1511 | it = gem_cfg_compltd_map.find(k); |
| 1512 | |
| 1513 | if (it != gem_cfg_compltd_map.end()) { |
| 1514 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1515 | break; |
| 1516 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 1517 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1518 | |
| 1519 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 1520 | // before we push the result. |
| 1521 | bcmos_usleep(6000); |
| 1522 | } else { |
| 1523 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 1524 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1525 | return 0; |
| 1526 | } |
| 1527 | gem_cfg_key_check_counter++; |
| 1528 | } |
| 1529 | |
| 1530 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 1531 | if (it->second) { |
| 1532 | it->second->push(res); |
| 1533 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 1534 | } |
| 1535 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 1536 | return 0; |
| 1537 | } |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1538 | }; |
| 1539 | |
| 1540 | // Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue) |
| 1541 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) { |
| 1542 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1543 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1544 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1545 | 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] | 1546 | 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] | 1547 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1548 | } |
| 1549 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1550 | #ifdef FLOW_CHECKER |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1551 | // Test 2 - FlowAdd - Duplicate Flow case |
| 1552 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) { |
| 1553 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1554 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1555 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1556 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1557 | 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] | 1558 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1559 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1560 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1561 | #endif |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1562 | |
| 1563 | // Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error) |
| 1564 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) { |
| 1565 | gemport_id = 1025; |
| 1566 | |
| 1567 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1568 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1569 | |
| 1570 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1571 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1572 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1573 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1574 | 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] | 1575 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1576 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1577 | } |
| 1578 | |
| 1579 | // Test 4 - FlowAdd - Failure case(Invalid flow direction) |
| 1580 | TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) { |
| 1581 | flow_type = "bidirectional"; |
| 1582 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1583 | 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] | 1584 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1585 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1586 | } |
| 1587 | |
| 1588 | // Test 5 - FlowAdd - Failure case(Invalid network setting) |
| 1589 | TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) { |
| 1590 | network_intf_id = -1; |
| 1591 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1592 | 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] | 1593 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1594 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1595 | } |
| 1596 | |
| 1597 | // Test 6 - FlowAdd - Success case(Single tag & EAP Ether type) |
| 1598 | TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) { |
| 1599 | flow_id = 2; |
| 1600 | |
| 1601 | classifier->set_eth_type(34958); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1602 | action = new openolt::Action; |
| 1603 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1604 | cmd->set_trap_to_host(true); |
| 1605 | action->set_allocated_cmd(cmd); |
| 1606 | |
| 1607 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1608 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1609 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1610 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1611 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1612 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1613 | 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] | 1614 | 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] | 1615 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1616 | } |
| 1617 | |
| 1618 | // Test 7 - FlowAdd - Success case(Single tag & DHCP flow) |
| 1619 | TEST_F(TestFlowAdd, FlowAddDhcpSuccess) { |
| 1620 | flow_id = 3; |
| 1621 | gemport_id = 1025; |
| 1622 | |
| 1623 | classifier->set_ip_proto(17); |
| 1624 | classifier->set_src_port(68); |
| 1625 | classifier->set_dst_port(67); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1626 | action = new openolt::Action; |
| 1627 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1628 | cmd->set_trap_to_host(true); |
| 1629 | action->set_allocated_cmd(cmd); |
| 1630 | |
| 1631 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1632 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1633 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1634 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1635 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1636 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1637 | 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] | 1638 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1639 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1640 | } |
| 1641 | |
| 1642 | // Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue) |
| 1643 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) { |
| 1644 | flow_id = 4; |
| 1645 | flow_type = "downstream"; |
| 1646 | |
| 1647 | classifier->set_o_vid(12); |
| 1648 | classifier->set_i_vid(7); |
| 1649 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1650 | action = new openolt::Action; |
| 1651 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1652 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1653 | cmd->set_remove_outer_tag(true); |
| 1654 | action->set_allocated_cmd(cmd); |
| 1655 | |
| 1656 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1657 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1658 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1659 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1660 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1661 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1662 | 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] | 1663 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1664 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1665 | } |
| 1666 | |
| 1667 | // Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue) |
| 1668 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) { |
| 1669 | onu_id = 2; |
| 1670 | flow_id = 5; |
| 1671 | alloc_id = 1025; |
| 1672 | |
| 1673 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1674 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1675 | |
| 1676 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1677 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1678 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1679 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1680 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1681 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1682 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 1683 | future<int> push_gem_cfg_complt = \ |
| 1684 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 1685 | push_gem_cfg_complt = \ |
| 1686 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 1687 | Status status = future_res.get(); |
| 1688 | int res = push_gem_cfg_complt.get(); |
| 1689 | |
| 1690 | 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] | 1691 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1692 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1693 | } |
| 1694 | |
| 1695 | // Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue) |
| 1696 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) { |
| 1697 | onu_id = 2; |
| 1698 | flow_id = 6; |
| 1699 | flow_type = "downstream"; |
| 1700 | alloc_id = 1025; |
| 1701 | |
| 1702 | classifier->set_o_vid(12); |
| 1703 | classifier->set_i_vid(7); |
| 1704 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1705 | action = new openolt::Action; |
| 1706 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1707 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1708 | cmd->set_remove_outer_tag(true); |
| 1709 | action->set_allocated_cmd(cmd); |
| 1710 | |
| 1711 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1712 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1713 | |
| 1714 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1715 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1716 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1717 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1718 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1719 | CreateTrafficQueues_(traffic_queues); |
| 1720 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1721 | 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] | 1722 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1723 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1724 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1725 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1726 | // Test 11 - FlowAdd - success case (Downstream-Encrypted GEM) |
| 1727 | TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) { |
| 1728 | onu_id = 2; |
| 1729 | flow_id = 7; |
| 1730 | flow_type = "downstream"; |
| 1731 | alloc_id = 1025; |
| 1732 | enable_encryption = true; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1733 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1734 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1735 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1736 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1737 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1738 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1739 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 1740 | 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] | 1741 | 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] | 1742 | |
| 1743 | future<int> push_gem_cfg_complt = \ |
| 1744 | async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 1745 | Status status = future_res.get(); |
| 1746 | int res = push_gem_cfg_complt.get(); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1747 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1748 | } |
| 1749 | |
| 1750 | // Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied) |
| 1751 | TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) { |
| 1752 | onu_id = 2; |
| 1753 | flow_id = 8; |
| 1754 | flow_type = "downstream"; |
| 1755 | alloc_id = 1025; |
| 1756 | enable_encryption = false; |
| 1757 | |
| 1758 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1759 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1760 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1761 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1762 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1763 | |
| 1764 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1765 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1766 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1767 | } |
| 1768 | |
| 1769 | // Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied) |
| 1770 | TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) { |
| 1771 | onu_id = 2; |
| 1772 | flow_id = 9; |
| 1773 | flow_type = "upstream"; |
| 1774 | alloc_id = 1025; |
| 1775 | enable_encryption = true; |
| 1776 | |
| 1777 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1778 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1779 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1780 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1781 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1782 | |
| 1783 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1784 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1785 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1786 | } |
| 1787 | |
| 1788 | // Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied) |
| 1789 | TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) { |
| 1790 | onu_id = 2; |
| 1791 | flow_id = 10; |
| 1792 | flow_type = "multicast"; |
| 1793 | alloc_id = 1025; |
| 1794 | enable_encryption = true; |
| 1795 | |
| 1796 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1797 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1798 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1799 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1800 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1801 | |
| 1802 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1803 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1804 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1805 | } |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1806 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1807 | // For testing OnuPacketOut functionality |
| 1808 | //////////////////////////////////////////////////////////////////////////// |
| 1809 | |
| 1810 | class TestOnuPacketOut : public Test { |
| 1811 | protected: |
| 1812 | uint32_t pon_id = 0; |
| 1813 | uint32_t onu_id = 1; |
| 1814 | std::string pkt = "omci-pkt"; |
| 1815 | NiceMock<BalMocker> balMock; |
| 1816 | |
| 1817 | virtual void SetUp() { |
| 1818 | } |
| 1819 | |
| 1820 | virtual void TearDown() { |
| 1821 | } |
| 1822 | }; |
| 1823 | |
| 1824 | // Test 1 - OnuPacketOut success case |
| 1825 | TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) { |
| 1826 | uint32_t port_no = 16; |
| 1827 | uint32_t gemport_id = 1024; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1828 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1829 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1830 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1831 | |
| 1832 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1833 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1834 | } |
| 1835 | |
| 1836 | // Test 2 - OnuPacketOut Port number as 0 case |
| 1837 | TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) { |
| 1838 | uint32_t port_no = 0; |
| 1839 | uint32_t gemport_id = 1024; |
| 1840 | |
| 1841 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1842 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1843 | } |
| 1844 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1845 | // Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case |
| 1846 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) { |
| 1847 | uint32_t port_no = 16; |
| 1848 | uint32_t gemport_id = 0; |
| 1849 | |
| 1850 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1851 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1852 | |
| 1853 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1854 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1855 | } |
| 1856 | |
| 1857 | // Test 4 - OnuPacketOut success, Failure in finding Gem port case |
| 1858 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) { |
| 1859 | uint32_t port_no = 64; |
| 1860 | uint32_t gemport_id = 0; |
| 1861 | |
| 1862 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1863 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1864 | |
| 1865 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1866 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1867 | } |
| 1868 | |
| 1869 | //////////////////////////////////////////////////////////////////////////// |
| 1870 | // For testing FlowRemove functionality |
| 1871 | //////////////////////////////////////////////////////////////////////////// |
| 1872 | |
| 1873 | class TestFlowRemove : public Test { |
| 1874 | protected: |
| 1875 | NiceMock<BalMocker> balMock; |
| 1876 | |
| 1877 | virtual void SetUp() { |
| 1878 | } |
| 1879 | |
| 1880 | virtual void TearDown() { |
| 1881 | } |
| 1882 | }; |
| 1883 | |
| 1884 | // Test 1 - FlowRemove - Failure case |
| 1885 | TEST_F(TestFlowRemove, FlowRemoveFailure) { |
| 1886 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1887 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1888 | |
| 1889 | Status status = FlowRemove_(1, "upstream"); |
| 1890 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1891 | } |
| 1892 | |
| 1893 | // Test 2 - FlowRemove - success case |
| 1894 | TEST_F(TestFlowRemove, FlowRemoveSuccess) { |
| 1895 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1896 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1897 | |
| 1898 | Status status = FlowRemove_(1, "upstream"); |
| 1899 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1900 | } |
| 1901 | |
| 1902 | //////////////////////////////////////////////////////////////////////////// |
| 1903 | // For testing UplinkPacketOut functionality |
| 1904 | //////////////////////////////////////////////////////////////////////////// |
| 1905 | |
| 1906 | class TestUplinkPacketOut : public Test { |
| 1907 | protected: |
| 1908 | uint32_t pon_id = 0; |
| 1909 | std::string pkt = "omci-pkt"; |
| 1910 | NiceMock<BalMocker> balMock; |
| 1911 | |
| 1912 | bcmolt_flow_key flow_key; |
| 1913 | bcmolt_flow_cfg flow_cfg; |
| 1914 | |
| 1915 | virtual void SetUp() { |
| 1916 | flow_key.flow_id = 1; |
| 1917 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1918 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1919 | flow_cfg.data.onu_id=1; |
| 1920 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1921 | flow_cfg.data.svc_port_id=1024; |
| 1922 | flow_cfg.data.priority=0; |
| 1923 | flow_cfg.data.cookie=0; |
| 1924 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1925 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1926 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1927 | flow_cfg.data.egress_intf.intf_id=0; |
| 1928 | flow_cfg.data.classifier.o_vid=7; |
| 1929 | flow_cfg.data.classifier.o_pbits=0; |
| 1930 | flow_cfg.data.classifier.i_vid=0; |
| 1931 | flow_cfg.data.classifier.i_pbits=0; |
| 1932 | flow_cfg.data.classifier.ether_type=0; |
| 1933 | flow_cfg.data.classifier.ip_proto=0; |
| 1934 | flow_cfg.data.classifier.src_port=0; |
| 1935 | flow_cfg.data.classifier.dst_port=0; |
| 1936 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1937 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1938 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1939 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1940 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1941 | flow_cfg.data.action.o_vid=12; |
| 1942 | flow_cfg.data.action.o_pbits=0; |
| 1943 | flow_cfg.data.action.i_vid=0; |
| 1944 | flow_cfg.data.action.i_pbits=0; |
| 1945 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1946 | } |
| 1947 | |
| 1948 | virtual void TearDown() { |
| 1949 | } |
| 1950 | }; |
| 1951 | |
| 1952 | // Test 1 - UplinkPacketOut success case |
| 1953 | TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) { |
| 1954 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK; |
| 1955 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1956 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1957 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1958 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1959 | |
| 1960 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1961 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1962 | } |
| 1963 | |
| 1964 | // Test 2 - UplinkPacketOut Failure case |
| 1965 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) { |
| 1966 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL; |
| 1967 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1968 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1969 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1970 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1971 | |
| 1972 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1973 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1974 | } |
| 1975 | |
| 1976 | // Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case |
| 1977 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) { |
| 1978 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
| 1979 | |
| 1980 | FlowRemove_(2, "upstream"); |
| 1981 | FlowRemove_(3, "upstream"); |
| 1982 | FlowRemove_(4, "downstream"); |
| 1983 | FlowRemove_(5, "upstream"); |
| 1984 | FlowRemove_(6, "downstream"); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1985 | FlowRemove_(7, "downstream"); |
| 1986 | FlowRemove_(8, "downstream"); |
| 1987 | FlowRemove_(9, "upstream"); |
| 1988 | FlowRemove_(10, "multicast"); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1989 | |
| 1990 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1991 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1992 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1993 | |
| 1994 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1995 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1996 | } |
| 1997 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1998 | //////////////////////////////////////////////////////////////////////////// |
| 1999 | // For testing CreateTrafficSchedulers functionality |
| 2000 | //////////////////////////////////////////////////////////////////////////// |
| 2001 | |
| 2002 | class TestCreateTrafficSchedulers : public Test { |
| 2003 | protected: |
| 2004 | NiceMock<BalMocker> balMock; |
| 2005 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2006 | tech_profile::TrafficScheduler* traffic_sched; |
| 2007 | tech_profile::SchedulerConfig* scheduler; |
| 2008 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 2009 | |
| 2010 | virtual void SetUp() { |
| 2011 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2012 | traffic_scheds->set_intf_id(0); |
| 2013 | traffic_scheds->set_onu_id(1); |
| 2014 | traffic_scheds->set_uni_id(0); |
| 2015 | traffic_scheds->set_port_no(16); |
| 2016 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2017 | traffic_sched->set_alloc_id(1024); |
| 2018 | scheduler = new tech_profile::SchedulerConfig; |
| 2019 | scheduler->set_priority(0); |
| 2020 | scheduler->set_weight(0); |
| 2021 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2022 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 2023 | traffic_shaping_info->set_cbs(60536); |
| 2024 | traffic_shaping_info->set_pbs(65536); |
| 2025 | traffic_shaping_info->set_gir(10000); |
| 2026 | } |
| 2027 | |
| 2028 | virtual void TearDown() { |
| 2029 | } |
| 2030 | |
| 2031 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2032 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 2033 | alloc_cfg_compltd_key k(0, 1024); |
| 2034 | alloc_cfg_complete_result res; |
| 2035 | res.pon_intf_id = 0; |
| 2036 | res.alloc_id = 1024; |
| 2037 | res.state = state; |
| 2038 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2039 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2040 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 2041 | // before we push the result. |
| 2042 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 2043 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 2044 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 2045 | if (it == alloc_cfg_compltd_map.end()) { |
| 2046 | 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] | 2047 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2048 | it->second->push(res); |
| 2049 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2050 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2051 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 2052 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2053 | } |
| 2054 | }; |
| 2055 | |
| 2056 | // Test 1 - CreateTrafficSchedulers-Upstream success case |
| 2057 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) { |
| 2058 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2059 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2060 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2061 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2062 | traffic_shaping_info->set_cir(64000); |
| 2063 | traffic_shaping_info->set_pir(128000); |
| 2064 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2065 | |
| 2066 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2067 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2068 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2069 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2070 | bcmolt_onu_cfg onu_cfg_out; |
| 2071 | bcmolt_onu_key onu_key; |
| 2072 | onu_key.pon_ni = 0; |
| 2073 | onu_key.onu_id = 1; |
| 2074 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2075 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2076 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2077 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2078 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2079 | return onu_cfg_get_res; |
| 2080 | } |
| 2081 | )); |
| 2082 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2083 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2084 | future<int> push_alloc_cfg_complt = \ |
| 2085 | 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] | 2086 | |
| 2087 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2088 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2089 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2090 | } |
| 2091 | |
| 2092 | // Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication) |
| 2093 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) { |
| 2094 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2095 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2096 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2097 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2098 | traffic_shaping_info->set_cir(64000); |
| 2099 | traffic_shaping_info->set_pir(128000); |
| 2100 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2101 | |
| 2102 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2103 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2104 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2105 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2106 | bcmolt_onu_cfg onu_cfg_out; |
| 2107 | bcmolt_onu_key onu_key; |
| 2108 | onu_key.pon_ni = 0; |
| 2109 | onu_key.onu_id = 1; |
| 2110 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2111 | |
| 2112 | bcmos_errno alloc_cfg_get_res = BCM_ERR_OK; |
| 2113 | bcmolt_itupon_alloc_cfg alloc_cfg; |
| 2114 | bcmolt_itupon_alloc_key alloc_key; |
| 2115 | alloc_key.pon_ni = 0; |
| 2116 | alloc_key.alloc_id = 1024; |
| 2117 | BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key); |
| 2118 | |
| 2119 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2) |
| 2120 | .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] | 2121 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2122 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2123 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2124 | return onu_cfg_get_res; |
| 2125 | } |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2126 | )) |
| 2127 | .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2128 | bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg; |
| 2129 | o_cfg->data.state = BCMOLT_ACTIVATION_STATE_PROCESSING; |
| 2130 | memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg)); |
| 2131 | return alloc_cfg_get_res; |
| 2132 | } |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2133 | )); |
| 2134 | |
| 2135 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2136 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2137 | } |
| 2138 | |
| 2139 | // Test 2A - CreateTrafficSchedulers-Upstream success case(ONU not in ACTIVE state) |
| 2140 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccessOnuNotInActive) { |
| 2141 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2142 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2143 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2144 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2145 | traffic_shaping_info->set_cir(64000); |
| 2146 | traffic_shaping_info->set_pir(128000); |
| 2147 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2148 | |
| 2149 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2150 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2151 | |
| 2152 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2153 | bcmolt_onu_cfg onu_cfg_out; |
| 2154 | bcmolt_onu_key onu_key; |
| 2155 | onu_key.pon_ni = 0; |
| 2156 | onu_key.onu_id = 1; |
| 2157 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2158 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2159 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2160 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2161 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2162 | return onu_cfg_get_res; |
| 2163 | } |
| 2164 | )); |
| 2165 | |
| 2166 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2167 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2168 | } |
| 2169 | |
| 2170 | // Test 2B - CreateTrafficSchedulers-Upstream failure case. cfg-get failure |
| 2171 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamCfgGetFailure) { |
| 2172 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2173 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2174 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2175 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2176 | traffic_shaping_info->set_cir(64000); |
| 2177 | traffic_shaping_info->set_pir(128000); |
| 2178 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2179 | |
| 2180 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2181 | bcmos_errno olt_cfg_get_res = BCM_ERR_INTERNAL; |
| 2182 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2183 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 2184 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2185 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2186 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2187 | } |
| 2188 | |
Girish Gowdra | cdd5e5f | 2021-12-05 16:48:08 +0530 | [diff] [blame] | 2189 | // Test 2C - CreateTrafficSchedulers-Upstream Succes case(timeout waiting for alloc cfg indication, but itupon-alloc object is ACTIVE) |
| 2190 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeoutSuccess) { |
| 2191 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2192 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2193 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2194 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2195 | traffic_shaping_info->set_cir(64000); |
| 2196 | traffic_shaping_info->set_pir(128000); |
| 2197 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2198 | |
| 2199 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2200 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2201 | |
| 2202 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2203 | bcmolt_onu_cfg onu_cfg_out; |
| 2204 | bcmolt_onu_key onu_key; |
| 2205 | onu_key.pon_ni = 0; |
| 2206 | onu_key.onu_id = 1; |
| 2207 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2208 | |
| 2209 | bcmos_errno alloc_cfg_get_res = BCM_ERR_OK; |
| 2210 | bcmolt_itupon_alloc_cfg alloc_cfg; |
| 2211 | bcmolt_itupon_alloc_key alloc_key; |
| 2212 | alloc_key.pon_ni = 0; |
| 2213 | alloc_key.alloc_id = 1024; |
| 2214 | BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key); |
| 2215 | |
| 2216 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2) |
| 2217 | .WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2218 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2219 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2220 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2221 | return onu_cfg_get_res; |
| 2222 | } |
| 2223 | )) |
| 2224 | .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2225 | bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg; |
| 2226 | o_cfg->data.state = BCMOLT_ACTIVATION_STATE_ACTIVE; |
| 2227 | memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg)); |
| 2228 | return alloc_cfg_get_res; |
| 2229 | } |
| 2230 | )); |
| 2231 | |
| 2232 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2233 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2234 | } |
| 2235 | |
| 2236 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2237 | // Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request) |
| 2238 | TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) { |
| 2239 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2240 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2241 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2242 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2243 | traffic_shaping_info->set_cir(64000); |
| 2244 | traffic_shaping_info->set_pir(128000); |
| 2245 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2246 | |
| 2247 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2248 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2249 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2250 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2251 | bcmolt_onu_cfg onu_cfg_out; |
| 2252 | bcmolt_onu_key onu_key; |
| 2253 | onu_key.pon_ni = 0; |
| 2254 | onu_key.onu_id = 1; |
| 2255 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2256 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2257 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2258 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2259 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2260 | return onu_cfg_get_res; |
| 2261 | } |
| 2262 | )); |
| 2263 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2264 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2265 | future<int> push_alloc_cfg_complt = \ |
| 2266 | 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] | 2267 | |
| 2268 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2269 | int res = push_alloc_cfg_complt.get(); |
| 2270 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2271 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2272 | } |
| 2273 | |
| 2274 | // Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state) |
| 2275 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) { |
| 2276 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2277 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2278 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2279 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2280 | traffic_shaping_info->set_cir(64000); |
| 2281 | traffic_shaping_info->set_pir(128000); |
| 2282 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2283 | |
| 2284 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2285 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2286 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2287 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2288 | bcmolt_onu_cfg onu_cfg_out; |
| 2289 | bcmolt_onu_key onu_key; |
| 2290 | onu_key.pon_ni = 0; |
| 2291 | onu_key.onu_id = 1; |
| 2292 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2293 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2294 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2295 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2296 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2297 | return onu_cfg_get_res; |
| 2298 | } |
| 2299 | )); |
| 2300 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2301 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2302 | future<int> push_alloc_cfg_complt = \ |
| 2303 | 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] | 2304 | |
| 2305 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2306 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2307 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2308 | } |
| 2309 | |
| 2310 | // Test 5 - CreateTrafficSchedulers-Upstream Failure case |
| 2311 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) { |
| 2312 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2313 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2314 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2315 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2316 | traffic_shaping_info->set_cir(64000); |
| 2317 | traffic_shaping_info->set_pir(128000); |
| 2318 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2319 | |
| 2320 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2321 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2322 | |
| 2323 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2324 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2325 | } |
| 2326 | |
| 2327 | // Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case |
| 2328 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) { |
| 2329 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2330 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2331 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2332 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2333 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2334 | traffic_shaping_info->set_cir(64000); |
| 2335 | traffic_shaping_info->set_pir(0); |
| 2336 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2337 | |
| 2338 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2339 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2340 | } |
| 2341 | |
| 2342 | // Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case |
| 2343 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) { |
| 2344 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2345 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2346 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2347 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2348 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2349 | traffic_shaping_info->set_cir(64000); |
| 2350 | traffic_shaping_info->set_pir(32000); |
| 2351 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2352 | |
| 2353 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2354 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2355 | } |
| 2356 | |
| 2357 | // Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case |
| 2358 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) { |
| 2359 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2360 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2361 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2362 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2363 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2364 | traffic_shaping_info->set_cir(64000); |
| 2365 | traffic_shaping_info->set_pir(64000); |
| 2366 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2367 | |
| 2368 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2369 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2370 | } |
| 2371 | |
| 2372 | // Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case |
| 2373 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) { |
| 2374 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2375 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2376 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2377 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2378 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2379 | traffic_shaping_info->set_cir(64000); |
| 2380 | traffic_shaping_info->set_pir(0); |
| 2381 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2382 | |
| 2383 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2384 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2385 | } |
| 2386 | |
| 2387 | // Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case |
| 2388 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) { |
| 2389 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2390 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2391 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2392 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2393 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2394 | traffic_shaping_info->set_cir(0); |
| 2395 | traffic_shaping_info->set_pir(32000); |
| 2396 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2397 | |
| 2398 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2399 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2400 | } |
| 2401 | |
| 2402 | // Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case |
| 2403 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) { |
| 2404 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2405 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2406 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2407 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2408 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2409 | traffic_shaping_info->set_cir(64000); |
| 2410 | traffic_shaping_info->set_pir(32000); |
| 2411 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2412 | |
| 2413 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2414 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2415 | } |
| 2416 | |
| 2417 | // Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case |
| 2418 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) { |
| 2419 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2420 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2421 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2422 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2423 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2424 | traffic_shaping_info->set_cir(64000); |
| 2425 | traffic_shaping_info->set_pir(64000); |
| 2426 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2427 | |
| 2428 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2429 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2430 | } |
| 2431 | |
| 2432 | // Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case |
| 2433 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) { |
| 2434 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2435 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2436 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2437 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2438 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2439 | traffic_shaping_info->set_cir(64000); |
| 2440 | traffic_shaping_info->set_pir(0); |
| 2441 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2442 | |
| 2443 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2444 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2445 | } |
| 2446 | |
| 2447 | // Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case |
| 2448 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) { |
| 2449 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2450 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2451 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2452 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2453 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2454 | traffic_shaping_info->set_cir(0); |
| 2455 | traffic_shaping_info->set_pir(32000); |
| 2456 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2457 | |
| 2458 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2459 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2460 | } |
| 2461 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2462 | // Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case |
| 2463 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2464 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2465 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2466 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2467 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2468 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2469 | traffic_shaping_info->set_cir(64000); |
| 2470 | traffic_shaping_info->set_pir(128000); |
| 2471 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2472 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2473 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2474 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2475 | } |
| 2476 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2477 | // Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case |
| 2478 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2479 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2480 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2481 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2482 | traffic_sched->set_allocated_scheduler(scheduler); |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2483 | traffic_shaping_info->set_gir(0); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2484 | traffic_shaping_info->set_cir(64000); |
| 2485 | traffic_shaping_info->set_pir(32000); |
| 2486 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2487 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2488 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2489 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2490 | } |
| 2491 | |
| 2492 | // Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case |
| 2493 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) { |
| 2494 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2495 | scheduler->set_additional_bw(9); |
| 2496 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2497 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2498 | traffic_shaping_info->set_gir(0); |
| 2499 | traffic_shaping_info->set_cir(64000); |
| 2500 | traffic_shaping_info->set_pir(128000); |
| 2501 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2502 | |
| 2503 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2504 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2505 | } |
| 2506 | |
| 2507 | // Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case |
| 2508 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) { |
| 2509 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2510 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2511 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2512 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2513 | traffic_shaping_info->set_gir(64000); |
| 2514 | traffic_shaping_info->set_cir(0); |
| 2515 | traffic_shaping_info->set_pir(64000); |
| 2516 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2517 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2518 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2519 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2520 | |
| 2521 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2522 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2523 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2524 | |
| 2525 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2526 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2527 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2528 | } |
| 2529 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2530 | // Test 19 - CreateTrafficSchedulers-Downstream success case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2531 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) { |
| 2532 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2533 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2534 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2535 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2536 | traffic_shaping_info->set_cir(64000); |
| 2537 | traffic_shaping_info->set_pir(128000); |
| 2538 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2539 | |
| 2540 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2541 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2542 | |
| 2543 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2544 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2545 | } |
| 2546 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2547 | // Test 20 - CreateTrafficSchedulers-Downstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2548 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) { |
| 2549 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2550 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2551 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2552 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2553 | traffic_shaping_info->set_cir(64000); |
| 2554 | traffic_shaping_info->set_pir(128000); |
| 2555 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2556 | |
| 2557 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2558 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2559 | |
| 2560 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2561 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2562 | } |
| 2563 | |
Burak Gurdag | 623fada | 2021-04-20 22:02:36 +0000 | [diff] [blame] | 2564 | // Test 21 - CreateTrafficSchedulers-Invalid direction Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2565 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) { |
| 2566 | scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 2567 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2568 | traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 2569 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2570 | traffic_shaping_info->set_cir(64000); |
| 2571 | traffic_shaping_info->set_pir(128000); |
| 2572 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2573 | |
| 2574 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2575 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2576 | } |
| 2577 | |
| 2578 | //////////////////////////////////////////////////////////////////////////// |
| 2579 | // For testing RemoveTrafficSchedulers functionality |
| 2580 | //////////////////////////////////////////////////////////////////////////// |
| 2581 | |
| 2582 | class TestRemoveTrafficSchedulers : public Test { |
| 2583 | protected: |
| 2584 | NiceMock<BalMocker> balMock; |
| 2585 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2586 | tech_profile::TrafficScheduler* traffic_sched; |
| 2587 | tech_profile::SchedulerConfig* scheduler; |
| 2588 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 2589 | alloc_cfg_complete_result res; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2590 | uint32_t pon_id = 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2591 | |
| 2592 | virtual void SetUp() { |
| 2593 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2594 | traffic_scheds->set_intf_id(0); |
| 2595 | traffic_scheds->set_onu_id(1); |
| 2596 | traffic_scheds->set_uni_id(0); |
| 2597 | traffic_scheds->set_port_no(16); |
| 2598 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2599 | traffic_sched->set_alloc_id(1025); |
| 2600 | scheduler = new tech_profile::SchedulerConfig; |
| 2601 | scheduler->set_priority(0); |
| 2602 | scheduler->set_weight(0); |
| 2603 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2604 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2605 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 2606 | traffic_shaping_info->set_cir(64000); |
| 2607 | traffic_shaping_info->set_pir(128000); |
| 2608 | traffic_shaping_info->set_cbs(60536); |
| 2609 | traffic_shaping_info->set_pbs(65536); |
| 2610 | traffic_shaping_info->set_gir(10000); |
| 2611 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2612 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2613 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2614 | } |
| 2615 | |
| 2616 | virtual void TearDown() { |
| 2617 | } |
| 2618 | |
| 2619 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2620 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 2621 | alloc_cfg_compltd_key k(0, 1025); |
| 2622 | alloc_cfg_complete_result res; |
| 2623 | res.pon_intf_id = 0; |
| 2624 | res.alloc_id = 1025; |
| 2625 | res.state = state; |
| 2626 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2627 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 2628 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 2629 | // before we push the result. |
| 2630 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2631 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 2632 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 2633 | if (it == alloc_cfg_compltd_map.end()) { |
| 2634 | 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] | 2635 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2636 | it->second->push(res); |
| 2637 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2638 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2639 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 2640 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2641 | } |
| 2642 | }; |
| 2643 | |
| 2644 | // Test 1 - RemoveTrafficSchedulers-Upstream success case |
| 2645 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) { |
| 2646 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2647 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2648 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2649 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2650 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2651 | bcmolt_onu_cfg onu_cfg_out; |
| 2652 | bcmolt_onu_key onu_key; |
| 2653 | onu_key.pon_ni = 0; |
| 2654 | onu_key.onu_id = 1; |
| 2655 | |
| 2656 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2657 | |
| 2658 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2659 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2660 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2661 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2662 | return onu_cfg_get_res; |
| 2663 | } |
| 2664 | )); |
| 2665 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2666 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2667 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2668 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2669 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS); |
| 2670 | |
| 2671 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2672 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2673 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2674 | } |
| 2675 | |
| 2676 | // Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset) |
| 2677 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) { |
| 2678 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2679 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2680 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2681 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2682 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2683 | bcmolt_onu_cfg onu_cfg_out; |
| 2684 | bcmolt_onu_key onu_key; |
| 2685 | onu_key.pon_ni = 0; |
| 2686 | onu_key.onu_id = 1; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2687 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2688 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2689 | |
| 2690 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2691 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2692 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 2693 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2694 | return onu_cfg_get_res; |
| 2695 | } |
| 2696 | )); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2697 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2698 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2699 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2700 | |
| 2701 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2702 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2703 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2704 | } |
| 2705 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2706 | // 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] | 2707 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) { |
| 2708 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2709 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2710 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2711 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2712 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 2713 | bcmolt_onu_cfg onu_cfg_out; |
| 2714 | bcmolt_onu_key onu_key; |
| 2715 | onu_key.pon_ni = 0; |
| 2716 | onu_key.onu_id = 1; |
| 2717 | |
| 2718 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2719 | |
| 2720 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2721 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2722 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2723 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2724 | return onu_cfg_get_res; |
| 2725 | } |
| 2726 | )); |
| 2727 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2728 | |
| 2729 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2730 | |
| 2731 | Status status = future_res.get(); |
| 2732 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2733 | } |
| 2734 | |
| 2735 | // Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case) |
| 2736 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) { |
| 2737 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2738 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2739 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2740 | |
Girish Gowdra | 72cbee9 | 2021-11-05 15:16:18 -0700 | [diff] [blame] | 2741 | bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL; |
| 2742 | bcmolt_onu_cfg onu_cfg_out; |
| 2743 | bcmolt_onu_key onu_key; |
| 2744 | onu_key.pon_ni = 0; |
| 2745 | onu_key.onu_id = 1; |
| 2746 | |
| 2747 | BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key); |
| 2748 | |
| 2749 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2750 | bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg; |
| 2751 | o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 2752 | memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg)); |
| 2753 | return onu_cfg_get_res; |
| 2754 | } |
| 2755 | )); |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2756 | |
| 2757 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2758 | |
| 2759 | Status status = future_res.get(); |
| 2760 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2761 | } |
| 2762 | |
| 2763 | // Test 5 - RemoveTrafficSchedulers-Upstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2764 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) { |
| 2765 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2766 | |
| 2767 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2768 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2769 | |
| 2770 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2771 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2772 | } |
| 2773 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2774 | // Test 6 - RemoveTrafficSchedulers-Downstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2775 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) { |
| 2776 | //Create Scheduler |
| 2777 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2778 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2779 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2780 | CreateTrafficSchedulers_(traffic_scheds); |
| 2781 | |
| 2782 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2783 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2784 | |
| 2785 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2786 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2787 | } |
| 2788 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2789 | // Test 7 - RemoveTrafficSchedulers-Downstream success case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2790 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) { |
| 2791 | //Create Scheduler |
| 2792 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2793 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2794 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2795 | CreateTrafficSchedulers_(traffic_scheds); |
| 2796 | |
| 2797 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2798 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2799 | |
| 2800 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2801 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2802 | } |
| 2803 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2804 | // Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2805 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) { |
| 2806 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2807 | |
| 2808 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2809 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2810 | } |
| 2811 | |
| 2812 | //////////////////////////////////////////////////////////////////////////// |
| 2813 | // For testing CreateTrafficQueues functionality |
| 2814 | //////////////////////////////////////////////////////////////////////////// |
| 2815 | |
| 2816 | class TestCreateTrafficQueues : public Test { |
| 2817 | protected: |
| 2818 | NiceMock<BalMocker> balMock; |
| 2819 | tech_profile::TrafficQueues* traffic_queues; |
| 2820 | tech_profile::TrafficQueue* traffic_queue_1; |
| 2821 | tech_profile::TrafficQueue* traffic_queue_2; |
| 2822 | tech_profile::DiscardConfig* discard_config_1; |
| 2823 | tech_profile::DiscardConfig* discard_config_2; |
| 2824 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 2825 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 2826 | |
| 2827 | virtual void SetUp() { |
| 2828 | traffic_queues = new tech_profile::TrafficQueues; |
| 2829 | traffic_queues->set_intf_id(0); |
| 2830 | traffic_queues->set_onu_id(1); |
| 2831 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 2832 | traffic_queue_1->set_gemport_id(1024); |
| 2833 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 2834 | traffic_queue_1->set_aes_encryption(true); |
| 2835 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2836 | traffic_queue_1->set_priority(0); |
| 2837 | traffic_queue_1->set_weight(0); |
| 2838 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2839 | discard_config_1 = new tech_profile::DiscardConfig; |
| 2840 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2841 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 2842 | tail_drop_discard_config_1->set_queue_size(8); |
| 2843 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 2844 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 2845 | } |
| 2846 | |
| 2847 | virtual void TearDown() { |
| 2848 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2849 | |
| 2850 | public: |
| 2851 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 2852 | gem_cfg_compltd_key k(0, gem_port_id); |
| 2853 | gem_cfg_complete_result res; |
| 2854 | res.pon_intf_id = 0; |
| 2855 | res.gem_port_id = gem_port_id; |
| 2856 | res.state = state; |
| 2857 | res.status = status; |
| 2858 | |
| 2859 | uint32_t gem_cfg_key_check_counter = 1; |
| 2860 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 2861 | while(true) { |
| 2862 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 2863 | it = gem_cfg_compltd_map.find(k); |
| 2864 | |
| 2865 | if (it != gem_cfg_compltd_map.end()) { |
| 2866 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2867 | break; |
| 2868 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 2869 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2870 | |
| 2871 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 2872 | // before we push the result. |
| 2873 | bcmos_usleep(6000); |
| 2874 | } else { |
| 2875 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 2876 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2877 | return 0; |
| 2878 | } |
| 2879 | gem_cfg_key_check_counter++; |
| 2880 | } |
| 2881 | |
| 2882 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 2883 | if (it->second) { |
| 2884 | it->second->push(res); |
| 2885 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 2886 | } |
| 2887 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 2888 | return 0; |
| 2889 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2890 | }; |
| 2891 | |
| 2892 | // Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 2893 | TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2894 | traffic_queues->set_uni_id(0); |
| 2895 | traffic_queues->set_port_no(16); |
| 2896 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2897 | |
| 2898 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2899 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2900 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2901 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 2902 | future<int> push_gem_cfg_complt = \ |
| 2903 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 2904 | Status status = future_res.get(); |
| 2905 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2906 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2907 | |
| 2908 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2909 | status = CreateTrafficQueues_(traffic_queues); |
| 2910 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2911 | } |
| 2912 | |
| 2913 | // Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case |
| 2914 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) { |
| 2915 | traffic_queues->set_uni_id(1); |
| 2916 | traffic_queues->set_port_no(32); |
| 2917 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2918 | |
| 2919 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2920 | traffic_queue_2->set_gemport_id(1025); |
| 2921 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2922 | traffic_queue_2->set_aes_encryption(true); |
| 2923 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2924 | traffic_queue_2->set_priority(1); |
| 2925 | traffic_queue_2->set_weight(0); |
| 2926 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2927 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2928 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2929 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2930 | tail_drop_discard_config_2->set_queue_size(8); |
| 2931 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2932 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2933 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2934 | |
| 2935 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2936 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2937 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 2938 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 2939 | future<int> push_gem_cfg_complt = \ |
| 2940 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 2941 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 2942 | push_gem_cfg_complt = \ |
| 2943 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 2944 | Status status = future_res.get(); |
| 2945 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2946 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2947 | } |
| 2948 | |
| 2949 | // Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case |
| 2950 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) { |
| 2951 | traffic_queues->set_uni_id(2); |
| 2952 | traffic_queues->set_port_no(16); |
| 2953 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2954 | |
| 2955 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2956 | traffic_queue_2->set_gemport_id(1025); |
| 2957 | traffic_queue_2->set_pbit_map("0b10001010"); |
| 2958 | traffic_queue_2->set_aes_encryption(true); |
| 2959 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2960 | traffic_queue_2->set_priority(1); |
| 2961 | traffic_queue_2->set_weight(0); |
| 2962 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2963 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2964 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2965 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2966 | tail_drop_discard_config_2->set_queue_size(8); |
| 2967 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2968 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2969 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2970 | |
| 2971 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2972 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2973 | |
| 2974 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2975 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2976 | } |
| 2977 | |
| 2978 | // Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case |
| 2979 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) { |
| 2980 | traffic_queues->set_uni_id(3); |
| 2981 | traffic_queues->set_port_no(16); |
| 2982 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2983 | |
| 2984 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2985 | traffic_queue_2->set_gemport_id(1025); |
| 2986 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2987 | traffic_queue_2->set_aes_encryption(true); |
| 2988 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2989 | traffic_queue_2->set_priority(1); |
| 2990 | traffic_queue_2->set_weight(0); |
| 2991 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2992 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2993 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2994 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2995 | tail_drop_discard_config_2->set_queue_size(8); |
| 2996 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2997 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2998 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2999 | |
| 3000 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3001 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3002 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3003 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 3004 | future<int> push_gem_cfg_complt = \ |
| 3005 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3006 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3007 | push_gem_cfg_complt = \ |
| 3008 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3009 | Status status = future_res.get(); |
| 3010 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3011 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3012 | } |
| 3013 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3014 | // Test 5 - CreateTrafficQueues-Downstream PRIORITY_TO_QUEUE TM QMP Max count reached case |
| 3015 | TEST_F(TestCreateTrafficQueues, CreateDownstreamPriorityQueueReachedMaxTMQMPCount) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3016 | int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; |
| 3017 | int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272}; |
| 3018 | std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"}; |
| 3019 | |
| 3020 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3021 | for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) { |
| 3022 | traffic_queues->set_uni_id(uni_ids[i]); |
| 3023 | traffic_queues->set_port_no(port_nos[i]); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3024 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3025 | |
| 3026 | traffic_queue_2->set_gemport_id(1025); |
| 3027 | traffic_queue_2->set_pbit_map(pbit_maps[i]); |
| 3028 | traffic_queue_2->set_aes_encryption(true); |
| 3029 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 3030 | traffic_queue_2->set_priority(1); |
| 3031 | traffic_queue_2->set_weight(0); |
| 3032 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 3033 | discard_config_2 = new tech_profile::DiscardConfig; |
| 3034 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 3035 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 3036 | tail_drop_discard_config_2->set_queue_size(8); |
| 3037 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 3038 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3039 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3040 | |
| 3041 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3042 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3043 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3044 | future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues); |
| 3045 | future<int> push_gem_cfg_complt = \ |
| 3046 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3047 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3048 | push_gem_cfg_complt = \ |
| 3049 | async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3050 | Status status = future_res.get(); |
| 3051 | int res = push_gem_cfg_complt.get(); |
| 3052 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3053 | if(i==16) |
| 3054 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3055 | else |
| 3056 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | // Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case |
| 3061 | TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) { |
| 3062 | traffic_queues->set_uni_id(0); |
| 3063 | traffic_queues->set_port_no(16); |
| 3064 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3065 | |
| 3066 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3067 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3068 | |
| 3069 | Status status = CreateTrafficQueues_(traffic_queues); |
| 3070 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3071 | } |
| 3072 | |
| 3073 | //////////////////////////////////////////////////////////////////////////// |
| 3074 | // For testing RemoveTrafficQueues functionality |
| 3075 | //////////////////////////////////////////////////////////////////////////// |
| 3076 | |
| 3077 | class TestRemoveTrafficQueues : public Test { |
| 3078 | protected: |
| 3079 | NiceMock<BalMocker> balMock; |
| 3080 | tech_profile::TrafficQueues* traffic_queues; |
| 3081 | tech_profile::TrafficQueue* traffic_queue_1; |
| 3082 | tech_profile::TrafficQueue* traffic_queue_2; |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3083 | uint32_t pon_id = 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3084 | |
| 3085 | virtual void SetUp() { |
| 3086 | traffic_queues = new tech_profile::TrafficQueues; |
| 3087 | traffic_queues->set_intf_id(0); |
| 3088 | traffic_queues->set_onu_id(1); |
| 3089 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 3090 | traffic_queue_1->set_gemport_id(1024); |
| 3091 | traffic_queue_1->set_priority(0); |
| 3092 | } |
| 3093 | |
| 3094 | virtual void TearDown() { |
| 3095 | } |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3096 | |
| 3097 | public: |
| 3098 | static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) { |
| 3099 | gem_cfg_compltd_key k(0, gem_port_id); |
| 3100 | gem_cfg_complete_result res; |
| 3101 | res.pon_intf_id = 0; |
| 3102 | res.gem_port_id = gem_port_id; |
| 3103 | res.state = state; |
| 3104 | res.status = status; |
| 3105 | |
| 3106 | uint32_t gem_cfg_key_check_counter = 1; |
| 3107 | std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it; |
| 3108 | while(true) { |
| 3109 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 3110 | it = gem_cfg_compltd_map.find(k); |
| 3111 | |
| 3112 | if (it != gem_cfg_compltd_map.end()) { |
| 3113 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3114 | break; |
| 3115 | } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) { |
| 3116 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3117 | |
| 3118 | // We need to wait for some time to allow the Gem Cfg Request to be triggered |
| 3119 | // before we push the result. |
| 3120 | bcmos_usleep(6000); |
| 3121 | } else { |
| 3122 | OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0); |
| 3123 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3124 | return 0; |
| 3125 | } |
| 3126 | gem_cfg_key_check_counter++; |
| 3127 | } |
| 3128 | |
| 3129 | bcmos_fastlock_lock(&gem_cfg_wait_lock); |
| 3130 | if (it->second) { |
| 3131 | it->second->push(res); |
| 3132 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n"); |
| 3133 | } |
| 3134 | bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0); |
| 3135 | return 0; |
| 3136 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3137 | }; |
| 3138 | |
| 3139 | // Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 3140 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3141 | traffic_queues->set_uni_id(0); |
| 3142 | traffic_queues->set_port_no(16); |
| 3143 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3144 | |
| 3145 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3146 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3147 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3148 | bcmolt_pon_interface_key pon_key; |
| 3149 | bcmolt_pon_interface_cfg pon_cfg; |
| 3150 | pon_key.pon_ni = pon_id; |
| 3151 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3152 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3153 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3154 | 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] | 3155 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3156 | |
| 3157 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3158 | future<int> push_gem_cfg_complt = \ |
| 3159 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3160 | |
| 3161 | Status status = future_res.get(); |
| 3162 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3163 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3164 | |
| 3165 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3166 | status = RemoveTrafficQueues_(traffic_queues); |
| 3167 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3168 | } |
| 3169 | |
| 3170 | // Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case |
| 3171 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3172 | traffic_queues->set_uni_id(0); |
| 3173 | traffic_queues->set_port_no(16); |
| 3174 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3175 | |
| 3176 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 3177 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3178 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3179 | Status status = RemoveTrafficQueues_(traffic_queues); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3180 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3181 | } |
| 3182 | |
| 3183 | // Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case |
| 3184 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) { |
| 3185 | //Remove scheduler so that is_tm_sched_id_present api call will return false |
| 3186 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 3187 | tech_profile::TrafficScheduler* traffic_sched; |
| 3188 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 3189 | traffic_scheds->set_intf_id(0); |
| 3190 | traffic_scheds->set_onu_id(1); |
| 3191 | traffic_scheds->set_uni_id(0); |
| 3192 | traffic_scheds->set_port_no(16); |
| 3193 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 3194 | traffic_sched->set_alloc_id(1024); |
| 3195 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3196 | |
| 3197 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3198 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3199 | RemoveTrafficSchedulers_(traffic_scheds); |
| 3200 | |
| 3201 | traffic_queues->set_uni_id(0); |
| 3202 | traffic_queues->set_port_no(16); |
| 3203 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3204 | |
| 3205 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 3206 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3207 | } |
| 3208 | |
| 3209 | /* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP |
| 3210 | as it is getting referred by some other queues case */ |
| 3211 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) { |
| 3212 | traffic_queues->set_uni_id(3); |
| 3213 | traffic_queues->set_port_no(16); |
| 3214 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 3215 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3216 | traffic_queue_2->set_gemport_id(1025); |
| 3217 | traffic_queue_2->set_priority(1); |
| 3218 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 3219 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3220 | bcmolt_pon_interface_key pon_key; |
| 3221 | bcmolt_pon_interface_cfg pon_cfg; |
| 3222 | pon_key.pon_ni = pon_id; |
| 3223 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3224 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3225 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3226 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3227 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3228 | |
| 3229 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3230 | future<int> push_gem_cfg_complt = \ |
| 3231 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3232 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3233 | push_gem_cfg_complt = \ |
| 3234 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3235 | |
| 3236 | Status status = future_res.get(); |
| 3237 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3238 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3239 | } |
| 3240 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3241 | /* Test 5 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, removing TM QMP as it |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3242 | is not getting referred by any other queues case */ |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3243 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueRemovingTMQMP) { |
| 3244 | traffic_queues->set_uni_id(5); |
| 3245 | traffic_queues->set_port_no(80); |
| 3246 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3247 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3248 | traffic_queue_2->set_gemport_id(1025); |
| 3249 | traffic_queue_2->set_priority(1); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3250 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 3251 | |
| 3252 | bcmolt_pon_interface_key pon_key; |
| 3253 | bcmolt_pon_interface_cfg pon_cfg; |
| 3254 | pon_key.pon_ni = pon_id; |
| 3255 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3256 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3257 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3258 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3259 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3260 | |
| 3261 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 3262 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 3263 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3264 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3265 | future<int> push_gem_cfg_complt = \ |
| 3266 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3267 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3268 | push_gem_cfg_complt = \ |
| 3269 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3270 | |
| 3271 | Status status = future_res.get(); |
| 3272 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3273 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3274 | } |
| 3275 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3276 | /* Test 6 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, error while removing TM QMP |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3277 | having no reference to any other queues case */ |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3278 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueErrorRemovingTMQMP) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3279 | traffic_queues->set_uni_id(4); |
| 3280 | traffic_queues->set_port_no(64); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3281 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3282 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 3283 | traffic_queue_2->set_gemport_id(1025); |
| 3284 | traffic_queue_2->set_priority(1); |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3285 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3286 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3287 | bcmolt_pon_interface_key pon_key; |
| 3288 | bcmolt_pon_interface_cfg pon_cfg; |
| 3289 | pon_key.pon_ni = pon_id; |
| 3290 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 3291 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 3292 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3293 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3294 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3295 | |
Thiyagarajan Subramani | e976fcf | 2021-05-07 22:46:57 +0530 | [diff] [blame] | 3296 | bcmos_errno olt_cfg_clear_res_success = BCM_ERR_OK; |
| 3297 | bcmos_errno olt_cfg_clear_res_failure = BCM_ERR_INTERNAL; |
| 3298 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)) |
| 3299 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3300 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3301 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3302 | .WillOnce(Return(olt_cfg_clear_res_success)) |
| 3303 | .WillRepeatedly(Return(olt_cfg_clear_res_failure)); |
| 3304 | |
| 3305 | future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues); |
| 3306 | future<int> push_gem_cfg_complt = \ |
| 3307 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024); |
| 3308 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 3309 | push_gem_cfg_complt = \ |
| 3310 | async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025); |
| 3311 | |
| 3312 | Status status = future_res.get(); |
| 3313 | int res = push_gem_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 3314 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3315 | } |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3316 | |
| 3317 | //////////////////////////////////////////////////////////////////////////// |
| 3318 | // For testing OnuItuPonAlarmSet functionality |
| 3319 | //////////////////////////////////////////////////////////////////////////// |
| 3320 | |
| 3321 | class TestOnuItuPonAlarmSet : public Test { |
| 3322 | protected: |
| 3323 | bcmolt_pon_ni pon_ni = 0; |
| 3324 | bcmolt_onu_id onu_id = 1; |
| 3325 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3326 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rt; |
| 3327 | config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config; |
| 3328 | config::OnuItuPonAlarm::SoakTime *soak_time_rt; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3329 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3330 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rr; |
| 3331 | config::OnuItuPonAlarm::RateRangeConfig *rate_range_config; |
| 3332 | config::OnuItuPonAlarm::SoakTime *soak_time_rr; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3333 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3334 | config::OnuItuPonAlarm *onu_itu_pon_alarm_tc; |
| 3335 | config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config; |
| 3336 | config::OnuItuPonAlarm::SoakTime *soak_time_tc; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3337 | |
| 3338 | NiceMock<BalMocker> balMock; |
| 3339 | |
| 3340 | virtual void SetUp() { |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3341 | onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm; |
| 3342 | rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig; |
| 3343 | soak_time_rt = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3344 | onu_itu_pon_alarm_rt->set_pon_ni(0); |
| 3345 | onu_itu_pon_alarm_rt->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3346 | onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3347 | 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] | 3348 | rate_threshold_config->set_rate_threshold_rising(1); |
| 3349 | rate_threshold_config->set_rate_threshold_falling(4); |
| 3350 | soak_time_rt->set_active_soak_time(2); |
| 3351 | soak_time_rt->set_clear_soak_time(2); |
| 3352 | rate_threshold_config->set_allocated_soak_time(soak_time_rt); |
| 3353 | onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config); |
| 3354 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3355 | onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm; |
| 3356 | rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig; |
| 3357 | soak_time_rr = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3358 | onu_itu_pon_alarm_rr->set_pon_ni(0); |
| 3359 | onu_itu_pon_alarm_rr->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3360 | onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3361 | 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] | 3362 | rate_range_config->set_rate_range_lower(1); |
| 3363 | rate_range_config->set_rate_range_upper(4); |
| 3364 | soak_time_rr->set_active_soak_time(2); |
| 3365 | soak_time_rr->set_clear_soak_time(2); |
| 3366 | rate_range_config->set_allocated_soak_time(soak_time_rr); |
| 3367 | onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config); |
| 3368 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3369 | onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm; |
| 3370 | value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig; |
| 3371 | soak_time_tc = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 3372 | onu_itu_pon_alarm_tc->set_pon_ni(0); |
| 3373 | onu_itu_pon_alarm_tc->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 3374 | onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 3375 | 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] | 3376 | value_threshold_config->set_threshold_limit(6); |
| 3377 | soak_time_tc->set_active_soak_time(2); |
| 3378 | soak_time_tc->set_clear_soak_time(2); |
| 3379 | value_threshold_config->set_allocated_soak_time(soak_time_tc); |
| 3380 | onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config); |
| 3381 | } |
| 3382 | |
| 3383 | virtual void TearDown() { |
| 3384 | } |
| 3385 | }; |
| 3386 | |
| 3387 | // Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case |
| 3388 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 3389 | // the configured threshold boundary. |
| 3390 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) { |
| 3391 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3392 | bcmolt_onu_key key = {}; |
| 3393 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3394 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 3395 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 3396 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 3397 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3398 | |
| 3399 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3400 | |
| 3401 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 3402 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3403 | } |
| 3404 | |
| 3405 | // Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case |
| 3406 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 3407 | // the configured threshold boundary. |
| 3408 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) { |
| 3409 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3410 | bcmolt_onu_key key = {}; |
| 3411 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3412 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 3413 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 3414 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 3415 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3416 | |
| 3417 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3418 | |
| 3419 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 3420 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3421 | } |
| 3422 | |
| 3423 | // Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case |
| 3424 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 3425 | // from the configured range. |
| 3426 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) { |
| 3427 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3428 | bcmolt_onu_key key = {}; |
| 3429 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3430 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 3431 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100; |
| 3432 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50; |
| 3433 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3434 | |
| 3435 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3436 | |
| 3437 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 3438 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3439 | } |
| 3440 | |
| 3441 | // Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case |
| 3442 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 3443 | // from the configured range. |
| 3444 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) { |
| 3445 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3446 | bcmolt_onu_key key = {}; |
| 3447 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3448 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 3449 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50; |
| 3450 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100; |
| 3451 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3452 | |
| 3453 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3454 | |
| 3455 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 3456 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3457 | } |
| 3458 | |
| 3459 | // Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case |
| 3460 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 3461 | // level. The alarm is cleared when the host read the stats. |
| 3462 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) { |
| 3463 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3464 | bcmolt_onu_key key = {}; |
| 3465 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3466 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 3467 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100; |
| 3468 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 3469 | |
| 3470 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3471 | |
| 3472 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 3473 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3474 | } |
| 3475 | |
| 3476 | // Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case |
| 3477 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 3478 | // level. The alarm is cleared when the host read the stats. |
| 3479 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) { |
| 3480 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 3481 | bcmolt_onu_key key = {}; |
| 3482 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 3483 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 3484 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1; |
| 3485 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 3486 | |
| 3487 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 3488 | |
| 3489 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 3490 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3491 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 3492 | |
| 3493 | //////////////////////////////////////////////////////////////////////////// |
| 3494 | // For testing DeleteGroup functionality |
| 3495 | //////////////////////////////////////////////////////////////////////////// |
| 3496 | |
| 3497 | class TestDeleteGroup : public Test { |
| 3498 | protected: |
| 3499 | uint32_t group_id = 1; |
| 3500 | NiceMock<BalMocker> balMock; |
| 3501 | |
| 3502 | virtual void SetUp() { |
| 3503 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 3504 | }; |
| 3505 | |
| 3506 | // Test 1 - DeleteGroup success case |
| 3507 | TEST_F(TestDeleteGroup, DeleteGroupSuccess) { |
| 3508 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3509 | bcmos_errno group_cfg_clear_res = BCM_ERR_OK; |
| 3510 | bcmolt_group_cfg grp_cfg_out; |
| 3511 | bcmolt_group_key grp_key = {}; |
| 3512 | |
| 3513 | grp_key.id = group_id; |
| 3514 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3515 | |
| 3516 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3517 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3518 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 3519 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3520 | return group_cfg_get_res; |
| 3521 | } |
| 3522 | )); |
| 3523 | |
| 3524 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 3525 | |
| 3526 | Status status = DeleteGroup_(group_id); |
| 3527 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3528 | } |
| 3529 | |
| 3530 | // Test 2 - DeleteGroup failure case: Group does not exist |
| 3531 | TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) { |
| 3532 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3533 | bcmolt_group_cfg grp_cfg_out; |
| 3534 | bcmolt_group_key grp_key = {}; |
| 3535 | |
| 3536 | grp_key.id = group_id; |
| 3537 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3538 | |
| 3539 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3540 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3541 | grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED; |
| 3542 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3543 | return group_cfg_get_res; |
| 3544 | } |
| 3545 | )); |
| 3546 | |
| 3547 | Status status = DeleteGroup_(group_id); |
| 3548 | ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND ); |
| 3549 | } |
| 3550 | |
| 3551 | // Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.) |
| 3552 | TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) { |
| 3553 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 3554 | bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL; |
| 3555 | bcmolt_group_cfg grp_cfg_out; |
| 3556 | bcmolt_group_key grp_key = {}; |
| 3557 | |
| 3558 | grp_key.id = group_id; |
| 3559 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 3560 | |
| 3561 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 3562 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 3563 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 3564 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 3565 | return group_cfg_get_res; |
| 3566 | } |
| 3567 | )); |
| 3568 | |
| 3569 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 3570 | |
| 3571 | Status status = DeleteGroup_(group_id); |
| 3572 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3573 | } |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 3574 | |
| 3575 | //////////////////////////////////////////////////////////////////////////// |
| 3576 | // For testing OnuLogicalDistanceZero functionality |
| 3577 | //////////////////////////////////////////////////////////////////////////// |
| 3578 | class TestOnuLogicalDistanceZero : public Test { |
| 3579 | protected: |
| 3580 | NiceMock<BalMocker> balMock; |
| 3581 | bcmolt_pon_ni pon_ni = 0; |
| 3582 | openolt::OnuLogicalDistance *onu_logical_distance_zero; |
| 3583 | |
| 3584 | virtual void SetUp() { |
| 3585 | onu_logical_distance_zero = new openolt::OnuLogicalDistance; |
| 3586 | onu_logical_distance_zero->set_intf_id(pon_ni); |
| 3587 | } |
| 3588 | virtual void TearDown() { |
| 3589 | } |
| 3590 | }; |
| 3591 | |
| 3592 | // |
| 3593 | // Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case |
| 3594 | // |
| 3595 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) { |
| 3596 | bcmolt_pon_distance pon_distance = {}; |
| 3597 | bcmolt_pon_interface_cfg pon_cfg; |
| 3598 | bcmolt_pon_interface_key key = {}; |
| 3599 | |
| 3600 | key.pon_ni = pon_ni; |
| 3601 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3602 | state.activate(); |
| 3603 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3604 | |
| 3605 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3606 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3607 | |
| 3608 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3609 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3610 | } |
| 3611 | |
| 3612 | // Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case |
| 3613 | // The PON state is not ready for failure case |
| 3614 | // |
| 3615 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) { |
| 3616 | bcmolt_pon_distance pon_distance = {}; |
| 3617 | bcmolt_pon_interface_cfg pon_cfg; |
| 3618 | bcmolt_pon_interface_key key = {}; |
| 3619 | |
| 3620 | key.pon_ni = pon_ni; |
| 3621 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3622 | state.deactivate(); |
| 3623 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL; |
| 3624 | |
| 3625 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3626 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3627 | } |
| 3628 | |
| 3629 | class TestOnuLogicalDistance : public Test { |
| 3630 | protected: |
| 3631 | NiceMock<BalMocker> balMock; |
| 3632 | bcmolt_pon_ni pon_ni = 0; |
| 3633 | bcmolt_onu_id onu_id = 1; |
| 3634 | openolt::OnuLogicalDistance *onu_logical_distance; |
| 3635 | |
| 3636 | virtual void SetUp() { |
| 3637 | onu_logical_distance = new openolt::OnuLogicalDistance; |
| 3638 | onu_logical_distance->set_intf_id(pon_ni); |
| 3639 | onu_logical_distance->set_onu_id(onu_id); |
| 3640 | } |
| 3641 | virtual void TearDown() { |
| 3642 | } |
| 3643 | }; |
| 3644 | |
| 3645 | // |
| 3646 | // Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case |
| 3647 | // |
| 3648 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) { |
| 3649 | bcmolt_pon_distance pon_distance = {}; |
| 3650 | bcmolt_pon_interface_cfg pon_cfg; |
| 3651 | bcmolt_pon_interface_key key = {}; |
| 3652 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3653 | |
| 3654 | key.pon_ni = pon_ni; |
| 3655 | state.activate(); |
| 3656 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3657 | |
| 3658 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3659 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3660 | |
| 3661 | bcmolt_onu_cfg onu_cfg; |
| 3662 | bcmolt_onu_key onu_key = {}; |
| 3663 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3664 | |
| 3665 | onu_key.pon_ni = pon_ni; |
| 3666 | onu_key.onu_id = onu_id; |
| 3667 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3668 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 3669 | |
| 3670 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3671 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3672 | |
| 3673 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3674 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3675 | } |
| 3676 | |
| 3677 | // Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3678 | // The failure case is for retrieving ONU ranging time |
| 3679 | // |
| 3680 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) { |
| 3681 | bcmolt_pon_distance pon_distance = {}; |
| 3682 | bcmolt_pon_interface_cfg pon_cfg; |
| 3683 | bcmolt_pon_interface_key key = {}; |
| 3684 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3685 | |
| 3686 | key.pon_ni = pon_ni; |
| 3687 | state.activate(); |
| 3688 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3689 | |
| 3690 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3691 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3692 | |
| 3693 | bcmolt_onu_cfg onu_cfg; |
| 3694 | bcmolt_onu_key onu_key = {}; |
| 3695 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 3696 | |
| 3697 | onu_key.pon_ni = pon_ni; |
| 3698 | onu_key.onu_id = onu_id; |
| 3699 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3700 | |
| 3701 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3702 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3703 | |
| 3704 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3705 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3706 | } |
| 3707 | |
| 3708 | // Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3709 | // The failure case is for ONU is not yet activated |
| 3710 | // |
| 3711 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) { |
| 3712 | bcmolt_pon_distance pon_distance = {}; |
| 3713 | bcmolt_pon_interface_cfg pon_cfg; |
| 3714 | bcmolt_pon_interface_key key = {}; |
| 3715 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3716 | |
| 3717 | key.pon_ni = pon_ni; |
| 3718 | state.activate(); |
| 3719 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3720 | |
| 3721 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3722 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3723 | |
| 3724 | bcmolt_onu_cfg onu_cfg; |
| 3725 | bcmolt_onu_key onu_key = {}; |
| 3726 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3727 | |
| 3728 | onu_key.pon_ni = pon_ni; |
| 3729 | onu_key.onu_id = onu_id; |
| 3730 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3731 | |
| 3732 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3733 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3734 | |
| 3735 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 3736 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3737 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3738 | } |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 3739 | |
| 3740 | //////////////////////////////////////////////////////////////////////////// |
| 3741 | // For testing Secure Server functionality |
| 3742 | //////////////////////////////////////////////////////////////////////////// |
| 3743 | |
| 3744 | class TestSecureServer : public Test { |
| 3745 | protected: |
| 3746 | virtual void SetUp() {} |
| 3747 | virtual void TearDown() {} |
| 3748 | }; |
| 3749 | |
| 3750 | TEST_F(TestSecureServer, StartInsecureServer) { |
| 3751 | // const to prevent the following warning: |
| 3752 | // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] |
| 3753 | const char *args[] = {"./openolt"}; |
| 3754 | int argc = sizeof(args) / sizeof(args[0]); |
| 3755 | char **argv = const_cast<char**>(args); |
| 3756 | |
| 3757 | bool ok = RunServer(argc, argv); |
| 3758 | |
| 3759 | ASSERT_TRUE(ok); |
| 3760 | |
| 3761 | OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n"); |
| 3762 | } |
| 3763 | |
| 3764 | TEST_F(TestSecureServer, StartWithInvalidTLSOption) { |
| 3765 | const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3766 | int argc = sizeof(args) / sizeof(args[0]); |
| 3767 | char **argv = const_cast<char**>(args); |
| 3768 | |
| 3769 | bool ok = RunServer(argc, argv); |
| 3770 | |
| 3771 | ASSERT_FALSE(ok); |
| 3772 | |
| 3773 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n"); |
| 3774 | } |
| 3775 | |
| 3776 | TEST_F(TestSecureServer, CertificatesAreMissing) { |
| 3777 | const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3778 | int argc = sizeof(args) / sizeof(args[0]); |
| 3779 | char **argv = const_cast<char**>(args); |
| 3780 | const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'"; |
| 3781 | |
| 3782 | int res = std::system(cmd.c_str()); |
| 3783 | if (res == 0) { |
| 3784 | std::cout << "directory ./keystore is deleted\n"; |
| 3785 | } else { |
| 3786 | std::cout << "directory ./keystore is not existing\n"; |
| 3787 | } |
| 3788 | |
| 3789 | bool ok = RunServer(argc, argv); |
| 3790 | |
| 3791 | ASSERT_FALSE(ok); |
| 3792 | |
| 3793 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n"); |
| 3794 | } |
| 3795 | |
| 3796 | TEST_F(TestSecureServer, StartWithValidTLSOption) { |
| 3797 | const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"}; |
| 3798 | int argc = sizeof(args) / sizeof(args[0]); |
| 3799 | char **argv = const_cast<char**>(args); |
| 3800 | const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore"; |
| 3801 | const std::string cmd_2 = "exec rm -rf './keystore'"; |
| 3802 | |
| 3803 | int res = std::system(cmd_1.c_str()); |
| 3804 | if (res == 0) { |
| 3805 | std::cout << "directory ./keystore is copied from ./keystore-test\n"; |
| 3806 | |
| 3807 | bool ok = RunServer(argc, argv); |
| 3808 | ASSERT_TRUE(ok); |
| 3809 | |
| 3810 | OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n"); |
| 3811 | |
| 3812 | res = std::system(cmd_2.c_str()); |
| 3813 | if (res == 0) { |
| 3814 | std::cout << "directory ./keystore is deleted\n"; |
| 3815 | } else { |
| 3816 | std::cerr << "directory ./keystore could not be deleted\n"; |
| 3817 | } |
| 3818 | } else { |
| 3819 | std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n'; |
| 3820 | FAIL(); |
| 3821 | } |
| 3822 | } |
Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 3823 | |
| 3824 | //////////////////////////////////////////////////////////////////////////// |
| 3825 | // For testing RxTx Power Read functionality |
| 3826 | //////////////////////////////////////////////////////////////////////////// |
| 3827 | |
| 3828 | class TestPowerRead : public Test { |
| 3829 | protected: |
| 3830 | virtual void SetUp() { |
| 3831 | std::array<char, 600> content = {}; |
| 3832 | content.fill(0x00); // not required for 0x00 |
| 3833 | |
| 3834 | // for asfvolt16 |
| 3835 | content[102] = 0x5D; |
| 3836 | content[103] = 0x38; |
| 3837 | content[104] = 0x1A; |
| 3838 | content[105] = 0xB5; |
| 3839 | |
| 3840 | // for asgvolt64 |
| 3841 | content[358] = 0x5C; |
| 3842 | content[359] = 0x82; |
| 3843 | content[360] = 0x04; |
| 3844 | content[361] = 0xBE; |
| 3845 | |
| 3846 | std::ofstream test_file; |
| 3847 | test_file.open(file_name, std::ios::binary | std::ios::out); |
| 3848 | test_file.write(content.data(), content.size()); |
| 3849 | test_file.close(); |
| 3850 | |
| 3851 | const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump; |
| 3852 | |
| 3853 | int res = std::system(cmd.c_str()); |
| 3854 | if (res == 0) { |
| 3855 | std::ifstream dump_file(hex_dump) ; |
| 3856 | std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() }; |
| 3857 | std::cout << cmd << '\n'; |
| 3858 | std::cout << hexdump << '\n'; |
| 3859 | } else { |
| 3860 | std::cerr << "hexdump capture failed\n"; |
| 3861 | } |
| 3862 | } |
| 3863 | virtual void TearDown() { |
| 3864 | std::remove(file_name.c_str()); |
| 3865 | std::remove(hex_dump.c_str()); |
| 3866 | } |
| 3867 | |
| 3868 | const std::string file_name = "eeprom.bin"; |
| 3869 | const std::string hex_dump = file_name + ".hexdump"; |
| 3870 | }; |
| 3871 | |
| 3872 | TEST_F(TestPowerRead, TestAsfvolt16) { |
| 3873 | std::cout << "Test Power Reads on XGS-PON OLT:\n"; |
| 3874 | |
| 3875 | int port = 20; |
| 3876 | auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3877 | |
| 3878 | std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n'; |
| 3879 | |
| 3880 | ASSERT_FALSE(trx_eeprom_reader1.is_valid_port()); |
| 3881 | |
| 3882 | port = 0; |
| 3883 | auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3884 | |
| 3885 | std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n'; |
| 3886 | std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n'; |
| 3887 | std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n'; |
| 3888 | std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n'; |
| 3889 | std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n'; |
| 3890 | |
| 3891 | auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw(); |
| 3892 | |
| 3893 | ASSERT_TRUE(rxtx_power_raw.second); |
| 3894 | |
| 3895 | std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first |
| 3896 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first |
| 3897 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, " |
| 3898 | << 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"; |
| 3899 | std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second |
| 3900 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second |
| 3901 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, " |
| 3902 | << 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"; |
| 3903 | std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n'; |
| 3904 | |
| 3905 | ASSERT_TRUE(trx_eeprom_reader2.is_valid_port()); |
| 3906 | ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256); |
| 3907 | ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104); |
| 3908 | ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2); |
| 3909 | ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20); |
| 3910 | ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837 |
| 3911 | ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864 |
| 3912 | ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom"); |
| 3913 | } |
| 3914 | |
| 3915 | TEST_F(TestPowerRead, TestAsgvolt64) { |
| 3916 | std::cout << "Test Power Reads on GPON OLT:\n"; |
| 3917 | |
| 3918 | int port = 80; |
| 3919 | auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3920 | |
| 3921 | std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n'; |
| 3922 | |
| 3923 | ASSERT_FALSE(trx_eeprom_reader1.is_valid_port()); |
| 3924 | |
| 3925 | port = 0; |
| 3926 | auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port}; |
| 3927 | |
| 3928 | std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n'; |
| 3929 | std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n'; |
| 3930 | std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n'; |
| 3931 | std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n'; |
| 3932 | std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n'; |
| 3933 | |
| 3934 | auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw(); |
| 3935 | |
| 3936 | ASSERT_TRUE(rxtx_power_raw.second); |
| 3937 | |
| 3938 | std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first |
| 3939 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first |
| 3940 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, " |
| 3941 | << 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"; |
| 3942 | std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second |
| 3943 | << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second |
| 3944 | << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, " |
| 3945 | << 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"; |
| 3946 | std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n'; |
| 3947 | |
| 3948 | ASSERT_TRUE(trx_eeprom_reader2.is_valid_port()); |
| 3949 | ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600); |
| 3950 | ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360); |
| 3951 | ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2); |
| 3952 | ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74); |
| 3953 | ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214 |
| 3954 | ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682 |
| 3955 | ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom"); |
| 3956 | } |