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" |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 21 | #include <future> |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 22 | using namespace testing; |
| 23 | using namespace std; |
| 24 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 25 | extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map; |
| 26 | extern dev_log_id openolt_log_id; |
| 27 | extern bcmos_fastlock alloc_cfg_wait_lock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 28 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 29 | class TestOltEnable : public Test { |
| 30 | protected: |
| 31 | virtual void SetUp() { |
| 32 | } |
| 33 | |
| 34 | virtual void TearDown() { |
| 35 | // Code here will be called immediately after each test |
| 36 | // (right before the destructor). |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | // This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in |
| 41 | // bcmolt_cfg_get__bal_state_stub. |
| 42 | ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; }; |
| 43 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 44 | // This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in |
| 45 | // bcmolt_cfg_get__onu_state_stub. |
| 46 | ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; }; |
| 47 | |
| 48 | // This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in |
| 49 | // bcmolt_cfg_get__tm_sched_stub. |
| 50 | ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; }; |
| 51 | |
| 52 | // This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in |
| 53 | // bcmolt_cfg_get__pon_intf_stub. |
| 54 | ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; }; |
| 55 | |
| 56 | // This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in |
| 57 | // bcmolt_cfg_get__nni_intf_stub. |
| 58 | ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; }; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 59 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 60 | // This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in |
| 61 | // bcmolt_cfg_get__flow_stub. |
| 62 | ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; }; |
| 63 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 64 | // Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function |
| 65 | 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] | 66 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 67 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 68 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 69 | 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] | 70 | 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] | 71 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 72 | // Test Fixture for OltEnable |
| 73 | |
| 74 | // Test 1: OltEnableSuccess case |
| 75 | TEST_F(TestOltEnable, OltEnableSuccess){ |
| 76 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 77 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 78 | NiceMock<BalMocker> balMock; |
| 79 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 80 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 81 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 82 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 83 | |
| 84 | bcmolt_olt_cfg olt_cfg = { }; |
| 85 | bcmolt_olt_key olt_key = { }; |
| 86 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 87 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 88 | |
| 89 | Status olt_enable_res; |
| 90 | |
| 91 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 92 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 93 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 94 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 95 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 96 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 97 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 98 | |
| 99 | olt_enable_res = Enable_(1, NULL); |
| 100 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 101 | } |
| 102 | |
| 103 | // Test 2: OltEnableFail_host_init_fail |
| 104 | TEST_F(TestOltEnable, OltEnableFail_host_init_fail) { |
| 105 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 106 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 107 | NiceMock<BalMocker> balMock; |
| 108 | bcmos_errno host_init_res = BCM_ERR_INTERNAL; |
| 109 | |
| 110 | Status olt_enable_res; |
| 111 | |
| 112 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 113 | state.deactivate(); |
| 114 | |
| 115 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 116 | |
| 117 | olt_enable_res = Enable_(1, NULL); |
| 118 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 119 | } |
| 120 | |
| 121 | // Test 3: OltEnableSuccess_PON_Device_Connected |
| 122 | TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) { |
| 123 | |
| 124 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 125 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 126 | NiceMock<BalMocker> balMock; |
| 127 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 128 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 129 | bcmos_errno bal_cfg_get_res = BCM_ERR_OK; |
| 130 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 131 | |
| 132 | bcmolt_olt_cfg olt_cfg = { }; |
| 133 | bcmolt_olt_key olt_key = { }; |
| 134 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 135 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 136 | |
| 137 | Status olt_enable_res; |
| 138 | |
| 139 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 140 | state.deactivate(); |
| 141 | |
| 142 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 143 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 144 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 145 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 146 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 147 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 148 | |
| 149 | olt_enable_res = Enable_(1, NULL); |
| 150 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 151 | |
| 152 | } |
| 153 | |
| 154 | // Test 4: OltEnableFail_All_PON_Enable_Fail |
| 155 | TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) { |
| 156 | |
| 157 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 158 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 159 | NiceMock<BalMocker> balMock; |
| 160 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 161 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 162 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 163 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 164 | |
| 165 | bcmolt_olt_cfg olt_cfg = { }; |
| 166 | bcmolt_olt_key olt_key = { }; |
| 167 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 168 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 169 | |
| 170 | Status olt_enable_res; |
| 171 | |
| 172 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 173 | state.deactivate(); |
| 174 | |
| 175 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 176 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 177 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 178 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 179 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 180 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 181 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 182 | |
| 183 | olt_enable_res = Enable_(1, NULL); |
| 184 | |
| 185 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 186 | } |
| 187 | |
| 188 | // Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed. |
| 189 | TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) { |
| 190 | |
| 191 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 192 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 193 | NiceMock<BalMocker> balMock; |
| 194 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 195 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 196 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 197 | bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL; |
| 198 | bcmos_errno olt_oper_res_success = BCM_ERR_OK; |
| 199 | |
| 200 | bcmolt_olt_cfg olt_cfg = { }; |
| 201 | bcmolt_olt_key olt_key = { }; |
| 202 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 203 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 204 | |
| 205 | Status olt_enable_res; |
| 206 | |
| 207 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 208 | state.deactivate(); |
| 209 | |
| 210 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 211 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 212 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 213 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 214 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 215 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 216 | // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices. |
| 217 | EXPECT_CALL(balMock, bcmolt_oper_submit(_, _)) |
| 218 | .WillOnce(Return(olt_oper_res_fail)) |
| 219 | .WillRepeatedly(Return(olt_oper_res_success)); |
| 220 | olt_enable_res = Enable_(1, NULL); |
| 221 | |
| 222 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 223 | } |
| 224 | |
| 225 | //////////////////////////////////////////////////////////////////////// |
| 226 | // For testing Enable/Disable functionality |
| 227 | //////////////////////////////////////////////////////////////////////// |
| 228 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 229 | int num_of_pon_port = 16; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 230 | |
| 231 | // Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function |
| 232 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 233 | |
| 234 | class TestOltDisableReenable : public Test { |
| 235 | protected: |
| 236 | virtual void SetUp() { |
| 237 | NiceMock<BalMocker> balMock; |
| 238 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 239 | |
| 240 | bcmolt_olt_cfg olt_cfg = { }; |
| 241 | bcmolt_olt_key olt_key = { }; |
| 242 | |
| 243 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 244 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 245 | olt_cfg.data.topology.topology_maps.len = num_of_pon_port; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 246 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _)) |
| 247 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 248 | |
| 249 | ProbeDeviceCapabilities_(); |
| 250 | |
| 251 | } |
| 252 | |
| 253 | virtual void TearDown() { |
| 254 | // Code here will be called immediately after each test |
| 255 | // (right before the destructor). |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | |
| 260 | // Test Fixture for OltDisable |
| 261 | |
| 262 | // Test 1: OltDisableSuccess case |
| 263 | TEST_F(TestOltDisableReenable, OltDisableSuccess){ |
| 264 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 265 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 266 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 267 | bcmos_errno olt_oper_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)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 272 | olt_disable_res = Disable_(); |
| 273 | ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() ); |
| 274 | |
| 275 | } |
| 276 | |
| 277 | // Test 2: OltDisableAllPonFailed case |
| 278 | TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){ |
| 279 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 280 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 281 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 282 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 283 | |
| 284 | Status olt_disable_res; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 285 | state.deactivate(); |
| 286 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 287 | olt_disable_res = Disable_(); |
| 288 | ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | // Test Fixture for OltReenable |
| 293 | |
| 294 | // Test 1: OltReenableSuccess case |
| 295 | TEST_F(TestOltDisableReenable, OltReenableSuccess){ |
| 296 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 297 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 298 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 299 | uint32_t pon_id = 0; |
| 300 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 301 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 302 | Status olt_reenable_res; |
| 303 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 304 | bcmolt_pon_interface_key pon_key; |
| 305 | bcmolt_pon_interface_cfg pon_cfg; |
| 306 | pon_key.pon_ni = pon_id; |
| 307 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 308 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 309 | |
| 310 | 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] | 311 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 312 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 313 | |
| 314 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 315 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 316 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 317 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 318 | |
| 319 | 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] | 320 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 321 | .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 322 | |
| 323 | olt_reenable_res = Reenable_(); |
| 324 | ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() ); |
| 325 | |
| 326 | } |
| 327 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 328 | // Test 2: OltReenableAllPonFailed case |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 329 | TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){ |
| 330 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 331 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 332 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 333 | uint32_t pon_id = 0; |
| 334 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 335 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 336 | Status olt_reenable_res; |
| 337 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 338 | bcmolt_pon_interface_key pon_key; |
| 339 | bcmolt_pon_interface_cfg pon_cfg; |
| 340 | pon_key.pon_ni = pon_id; |
| 341 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 342 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 343 | |
| 344 | 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] | 345 | .Times(num_of_pon_port) |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 346 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 347 | EXPECT_CALL(balMock,bcmolt_oper_submit(_, _)) |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 348 | .Times(num_of_pon_port) |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 349 | .WillRepeatedly(Return(olt_oper_res)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 350 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 351 | olt_reenable_res = Reenable_(); |
| 352 | ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 353 | } |
| 354 | |
| 355 | //////////////////////////////////////////////////////////////////////////// |
| 356 | // For testing ProbeDeviceCapabilities functionality |
| 357 | //////////////////////////////////////////////////////////////////////////// |
| 358 | class TestProbeDevCapabilities : public Test { |
| 359 | protected: |
| 360 | NiceMock<BalMocker> balMock; |
| 361 | bcmos_errno olt_res_success = BCM_ERR_OK; |
| 362 | bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL; |
| 363 | bcmos_errno dev_res_success = BCM_ERR_OK; |
| 364 | bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL; |
| 365 | |
| 366 | virtual void SetUp() { |
| 367 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 368 | |
| 369 | bcmolt_olt_cfg olt_cfg = { }; |
| 370 | bcmolt_olt_key olt_key = { }; |
| 371 | |
| 372 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 373 | |
Girish Gowdra | ddf9a16 | 2020-01-27 12:56:27 +0530 | [diff] [blame] | 374 | olt_cfg.data.topology.topology_maps.len = num_of_pon_port; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | virtual void TearDown() { |
| 378 | } |
| 379 | }; |
| 380 | |
| 381 | // Test 1 - If querying the OLT fails, the method must return error |
| 382 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) { |
| 383 | |
| 384 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 385 | .WillOnce(Return(olt_res_fail)); |
| 386 | |
| 387 | Status query_status = ProbeDeviceCapabilities_(); |
| 388 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 389 | } |
| 390 | |
| 391 | // Test 2 - If all devices are queried successfully, the method must return Status::OK |
| 392 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) { |
| 393 | |
| 394 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 395 | .WillOnce(Return(olt_res_success)); |
| 396 | |
| 397 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 398 | .WillRepeatedly(Return(dev_res_success)); |
| 399 | |
| 400 | Status query_status = ProbeDeviceCapabilities_(); |
| 401 | |
| 402 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 403 | } |
| 404 | |
| 405 | // Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error |
| 406 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) { |
| 407 | |
| 408 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 409 | .WillOnce(Return(olt_res_success)); |
| 410 | |
| 411 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 412 | .WillRepeatedly(Return(dev_res_fail)); |
| 413 | |
| 414 | Status query_status = ProbeDeviceCapabilities_(); |
| 415 | |
| 416 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 417 | } |
| 418 | |
| 419 | // Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success |
| 420 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) { |
| 421 | |
| 422 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 423 | .WillOnce(Return(olt_res_success)); |
| 424 | |
| 425 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 426 | .WillOnce(Return(olt_res_success)) |
| 427 | .WillRepeatedly(Return(dev_res_fail)); |
| 428 | |
| 429 | Status query_status = ProbeDeviceCapabilities_(); |
| 430 | |
| 431 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 432 | } |
| 433 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 434 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 435 | // For testing EnablePonIf functionality |
| 436 | //////////////////////////////////////////////////////////////////////////// |
| 437 | |
| 438 | class TestEnablePonIf : public Test { |
| 439 | protected: |
| 440 | uint32_t pon_id = 0; |
| 441 | NiceMock<BalMocker> balMock; |
| 442 | |
| 443 | virtual void SetUp() { |
| 444 | } |
| 445 | |
| 446 | virtual void TearDown() { |
| 447 | } |
| 448 | }; |
| 449 | |
| 450 | // Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case |
| 451 | TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) { |
| 452 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 453 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 454 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 455 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 456 | |
| 457 | bcmolt_pon_interface_key pon_key; |
| 458 | bcmolt_pon_interface_cfg pon_cfg; |
| 459 | pon_key.pon_ni = pon_id; |
| 460 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 461 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 462 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 463 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 464 | |
| 465 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 466 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 467 | |
| 468 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 469 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 470 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 471 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 472 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 473 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 474 | |
| 475 | Status status = EnablePonIf_(pon_id); |
| 476 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 477 | } |
| 478 | |
| 479 | // Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case |
| 480 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) { |
| 481 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 482 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 483 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL; |
| 484 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 485 | |
| 486 | bcmolt_pon_interface_key pon_key; |
| 487 | bcmolt_pon_interface_cfg pon_cfg; |
| 488 | pon_key.pon_ni = pon_id; |
| 489 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 490 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 491 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 492 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 493 | |
| 494 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 495 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 496 | |
| 497 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 498 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 499 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 500 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 501 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 502 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 503 | |
| 504 | Status status = EnablePonIf_(pon_id); |
| 505 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 506 | } |
| 507 | |
| 508 | // Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state |
| 509 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) { |
| 510 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 511 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 512 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 513 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 514 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 515 | |
| 516 | bcmolt_pon_interface_key pon_key; |
| 517 | bcmolt_pon_interface_cfg pon_cfg; |
| 518 | pon_key.pon_ni = pon_id; |
| 519 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 520 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 521 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 522 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 523 | |
| 524 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 525 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 526 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 527 | |
| 528 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 529 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 530 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 531 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 532 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 533 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 534 | |
| 535 | Status status = EnablePonIf_(pon_id); |
| 536 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 537 | } |
| 538 | |
| 539 | // Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed |
| 540 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) { |
| 541 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 542 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 543 | bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL; |
| 544 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 545 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 546 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 547 | |
| 548 | bcmolt_pon_interface_key pon_key; |
| 549 | bcmolt_pon_interface_cfg pon_cfg; |
| 550 | pon_key.pon_ni = pon_id; |
| 551 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 552 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 553 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 554 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 555 | |
| 556 | EXPECT_CALL(balMock, bcmolt_cfg_set(_, _)) |
| 557 | .WillOnce(Return(olt_cfg_set_res)) |
| 558 | .WillRepeatedly(Return(olt_cfg_set_err)); |
| 559 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 560 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 561 | |
| 562 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 563 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 564 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 565 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 566 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 567 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 568 | |
| 569 | Status status = EnablePonIf_(pon_id); |
| 570 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 571 | } |
| 572 | |
| 573 | // Test 5 - EnablePonIf already enabled success |
| 574 | TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) { |
| 575 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 576 | |
| 577 | bcmolt_pon_interface_key pon_key; |
| 578 | bcmolt_pon_interface_cfg pon_cfg; |
| 579 | pon_key.pon_ni = pon_id; |
| 580 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 581 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 582 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 583 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 584 | |
| 585 | Status status = EnablePonIf_(pon_id); |
| 586 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 587 | } |
| 588 | |
| 589 | // Test 6 - EnablePonIf - enable onu discovery failure case |
| 590 | TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) { |
| 591 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 592 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 593 | |
| 594 | bcmolt_pon_interface_key pon_key; |
| 595 | bcmolt_pon_interface_cfg pon_cfg; |
| 596 | pon_key.pon_ni = pon_id; |
| 597 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 598 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 599 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 600 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 601 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 602 | |
| 603 | Status status = EnablePonIf_(pon_id); |
| 604 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 605 | } |
| 606 | |
| 607 | // Test 7 - EnablePonIf failure case |
| 608 | TEST_F(TestEnablePonIf, EnablePonIfFailed) { |
| 609 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 610 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 611 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 612 | |
| 613 | bcmolt_pon_interface_key pon_key; |
| 614 | bcmolt_pon_interface_cfg pon_cfg; |
| 615 | pon_key.pon_ni = pon_id; |
| 616 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 617 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 618 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 619 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 620 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 621 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 622 | |
| 623 | Status status = EnablePonIf_(pon_id); |
| 624 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 625 | } |
| 626 | |
| 627 | //////////////////////////////////////////////////////////////////////////// |
| 628 | // For testing SetStateUplinkIf functionality |
| 629 | //////////////////////////////////////////////////////////////////////////// |
| 630 | |
| 631 | class TestSetStateUplinkIf : public Test { |
| 632 | protected: |
| 633 | uint32_t intf_id = 0; |
| 634 | NiceMock<BalMocker> balMock; |
| 635 | |
| 636 | virtual void SetUp() { |
| 637 | } |
| 638 | |
| 639 | virtual void TearDown() { |
| 640 | } |
| 641 | }; |
| 642 | |
| 643 | // Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case |
| 644 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) { |
| 645 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 646 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 647 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 648 | |
| 649 | bcmolt_nni_interface_key nni_key; |
| 650 | bcmolt_nni_interface_cfg nni_cfg; |
| 651 | nni_key.id = intf_id; |
| 652 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 653 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 654 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 655 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 656 | |
| 657 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 658 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 659 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 660 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 661 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 662 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 663 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 664 | |
| 665 | Status status = SetStateUplinkIf_(intf_id, true); |
| 666 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 667 | } |
| 668 | |
| 669 | // Test 2 - SetStateUplinkIf, NNI interface already disabled case |
| 670 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) { |
| 671 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 672 | |
| 673 | bcmolt_nni_interface_key nni_key; |
| 674 | bcmolt_nni_interface_cfg nni_cfg; |
| 675 | nni_key.id = intf_id; |
| 676 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 677 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 678 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 679 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 680 | |
| 681 | Status status = SetStateUplinkIf_(intf_id, false); |
| 682 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 683 | } |
| 684 | |
| 685 | // Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case |
| 686 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) { |
| 687 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 688 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 689 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 690 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 691 | |
| 692 | bcmolt_nni_interface_key nni_key; |
| 693 | bcmolt_nni_interface_cfg nni_cfg; |
| 694 | nni_key.id = intf_id; |
| 695 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 696 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 697 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 698 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 699 | |
| 700 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 701 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 702 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 703 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 704 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 705 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 706 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 707 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 708 | |
| 709 | Status status = SetStateUplinkIf_(intf_id, true); |
| 710 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 711 | } |
| 712 | |
| 713 | // Test 4 - SetStateUplinkIf Enable failure case |
| 714 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) { |
| 715 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 716 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 717 | |
| 718 | bcmolt_nni_interface_key nni_key; |
| 719 | bcmolt_nni_interface_cfg nni_cfg; |
| 720 | nni_key.id = intf_id; |
| 721 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 722 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 723 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 724 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 725 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 726 | |
| 727 | Status status = SetStateUplinkIf_(intf_id, true); |
| 728 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 729 | } |
| 730 | |
| 731 | // Test 5 - SetStateUplinkIf Disable success case |
| 732 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) { |
| 733 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 734 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 735 | |
| 736 | bcmolt_nni_interface_key nni_key; |
| 737 | bcmolt_nni_interface_cfg nni_cfg; |
| 738 | nni_key.id = intf_id; |
| 739 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 740 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 741 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 742 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 743 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 744 | |
| 745 | Status status = SetStateUplinkIf_(intf_id, false); |
| 746 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 747 | } |
| 748 | |
| 749 | // Test 6 - SetStateUplinkIf Disable failure case |
| 750 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) { |
| 751 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 752 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 753 | |
| 754 | bcmolt_nni_interface_key nni_key; |
| 755 | bcmolt_nni_interface_cfg nni_cfg; |
| 756 | nni_key.id = intf_id; |
| 757 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 758 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 759 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 760 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 761 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 762 | |
| 763 | Status status = SetStateUplinkIf_(intf_id, false); |
| 764 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 765 | } |
| 766 | |
| 767 | //////////////////////////////////////////////////////////////////////////// |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 768 | // For testing DisablePonIf functionality |
| 769 | //////////////////////////////////////////////////////////////////////////// |
| 770 | |
| 771 | class TestDisablePonIf : public Test { |
| 772 | protected: |
| 773 | virtual void SetUp() { |
| 774 | } |
| 775 | |
| 776 | virtual void TearDown() { |
| 777 | } |
| 778 | }; |
| 779 | |
| 780 | // Test 1 - DisablePonIf success case |
| 781 | TEST_F(TestDisablePonIf, DisablePonIfSuccess) { |
| 782 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 783 | bcmos_errno bal_cfg_set_res = BCM_ERR_OK; |
| 784 | NiceMock<BalMocker> balMock; |
| 785 | uint32_t pon_id=1; |
| 786 | |
| 787 | //ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res)); |
| 788 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 789 | state.deactivate(); |
| 790 | Status status = DisablePonIf_(pon_id); |
| 791 | |
| 792 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 793 | } |
| 794 | |
| 795 | // Test 2 - DisablePonIf Failure case |
| 796 | TEST_F(TestDisablePonIf, DisablePonIfFailed) { |
| 797 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 798 | NiceMock<BalMocker> balMock; |
| 799 | uint32_t pon_id=1; |
| 800 | |
| 801 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 802 | state.deactivate(); |
| 803 | Status status = DisablePonIf_(pon_id); |
| 804 | |
| 805 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 806 | } |
| 807 | |
| 808 | // Test 3 - DisablePonIf ONU discovery failure case |
| 809 | TEST_F(TestDisablePonIf, DisablePonIfOnuDiscoveryFail) { |
| 810 | NiceMock<BalMocker> balMock; |
| 811 | uint32_t pon_id=1; |
| 812 | bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL; |
| 813 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res)); |
| 814 | state.deactivate(); |
| 815 | Status status = DisablePonIf_(pon_id); |
| 816 | |
| 817 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 818 | } |
| 819 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 820 | //////////////////////////////////////////////////////////////////////////// |
| 821 | // For testing ActivateOnu functionality |
| 822 | //////////////////////////////////////////////////////////////////////////// |
| 823 | |
| 824 | class TestActivateOnu : public Test { |
| 825 | protected: |
| 826 | uint32_t pon_id = 0; |
| 827 | uint32_t onu_id = 1; |
| 828 | std::string vendor_id = "TWSH"; |
| 829 | std::string vendor_specific = "80808080"; |
| 830 | uint32_t pir = 1000000; |
| 831 | NiceMock<BalMocker> balMock; |
| 832 | |
| 833 | virtual void SetUp() { |
| 834 | } |
| 835 | |
| 836 | virtual void TearDown() { |
| 837 | } |
| 838 | }; |
| 839 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 840 | // Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state |
| 841 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) { |
| 842 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 843 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 844 | bcmos_errno onu_cfg_set_res = BCM_ERR_OK; |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 845 | bcmos_errno onu_oper_submit_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 846 | |
| 847 | bcmolt_onu_cfg onu_cfg; |
| 848 | bcmolt_onu_key onu_key; |
| 849 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 850 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 851 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 852 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 853 | |
| 854 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 855 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 856 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 857 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 858 | 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] | 859 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 860 | } |
| 861 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 862 | // Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state |
| 863 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 864 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 865 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 866 | |
| 867 | bcmolt_onu_cfg onu_cfg; |
| 868 | bcmolt_onu_key onu_key; |
| 869 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 870 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 871 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 872 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 873 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 874 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 875 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 876 | 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] | 877 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 878 | } |
| 879 | |
Girish Gowdra | 2429703 | 2020-03-23 12:32:37 -0700 | [diff] [blame] | 880 | // Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state |
| 881 | TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) { |
| 882 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 883 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 884 | bcmos_errno onu_oper_submit_res = BCM_ERR_OK; |
| 885 | |
| 886 | bcmolt_onu_cfg onu_cfg; |
| 887 | bcmolt_onu_key onu_key; |
| 888 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 889 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 890 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 891 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 892 | |
| 893 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 894 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
| 895 | |
| 896 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 897 | 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] | 898 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 899 | } |
| 900 | |
| 901 | // Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE) |
| 902 | TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) { |
| 903 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 904 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 905 | |
| 906 | bcmolt_onu_cfg onu_cfg; |
| 907 | bcmolt_onu_key onu_key; |
| 908 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 909 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process |
| 910 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 911 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 912 | |
| 913 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 914 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 915 | 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] | 916 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 917 | } |
| 918 | |
| 919 | // Test 5 - ActivateOnu failure case - cfg_get failure |
| 920 | TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) { |
| 921 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure |
| 922 | |
| 923 | bcmolt_onu_cfg onu_cfg; |
| 924 | bcmolt_onu_key onu_key; |
| 925 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 926 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 927 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 928 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 929 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 930 | 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] | 931 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 932 | } |
| 933 | |
| 934 | // Test 6 - ActivateOnu failure case - oper_submit failure |
| 935 | TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) { |
| 936 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 937 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 938 | bcmos_errno onu_cfg_set_res = BCM_ERR_OK; |
| 939 | bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure |
| 940 | |
| 941 | bcmolt_onu_cfg onu_cfg; |
| 942 | bcmolt_onu_key onu_key; |
| 943 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 944 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED; |
| 945 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 946 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 947 | |
| 948 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 949 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
| 950 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res)); |
| 951 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 952 | 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] | 953 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 954 | } |
| 955 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 956 | //////////////////////////////////////////////////////////////////////////// |
| 957 | // For testing DeactivateOnu functionality |
| 958 | //////////////////////////////////////////////////////////////////////////// |
| 959 | |
| 960 | class TestDeactivateOnu : public Test { |
| 961 | protected: |
| 962 | uint32_t pon_id = 0; |
| 963 | uint32_t onu_id = 1; |
| 964 | std::string vendor_id = "TWSH"; |
| 965 | std::string vendor_specific = "80808080"; |
| 966 | NiceMock<BalMocker> balMock; |
| 967 | |
| 968 | virtual void SetUp() { |
| 969 | } |
| 970 | |
| 971 | virtual void TearDown() { |
| 972 | } |
| 973 | }; |
| 974 | |
| 975 | // Test 1 - DeactivateOnu success case |
| 976 | TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) { |
| 977 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 978 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 979 | |
| 980 | bcmolt_onu_cfg onu_cfg; |
| 981 | bcmolt_onu_key onu_key; |
| 982 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 983 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 984 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 985 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 986 | |
| 987 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 988 | |
| 989 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 990 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 991 | } |
| 992 | |
| 993 | // Test 2 - DeactivateOnu failure case |
| 994 | TEST_F(TestDeactivateOnu, DeactivateOnuFailure) { |
| 995 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 996 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 997 | |
| 998 | bcmolt_onu_cfg onu_cfg; |
| 999 | bcmolt_onu_key onu_key; |
| 1000 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1001 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1002 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 1003 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 1004 | |
| 1005 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1006 | |
| 1007 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1008 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1009 | } |
| 1010 | |
| 1011 | //////////////////////////////////////////////////////////////////////////// |
| 1012 | // For testing DeleteOnu functionality |
| 1013 | //////////////////////////////////////////////////////////////////////////// |
| 1014 | |
| 1015 | class TestDeleteOnu : public Test { |
| 1016 | protected: |
| 1017 | uint32_t pon_id = 0; |
| 1018 | uint32_t onu_id = 1; |
| 1019 | std::string vendor_id = "TWSH"; |
| 1020 | std::string vendor_specific = "80808080"; |
| 1021 | NiceMock<BalMocker> balMock; |
| 1022 | |
| 1023 | virtual void SetUp() { |
| 1024 | } |
| 1025 | |
| 1026 | virtual void TearDown() { |
| 1027 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1028 | public: |
| 1029 | static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) { |
| 1030 | onu_deactivate_complete_result res; |
| 1031 | res.pon_intf_id = 0; |
| 1032 | res.onu_id = 1; |
| 1033 | res.result = result; |
| 1034 | res.reason = reason; |
| 1035 | // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered |
| 1036 | // before we push the result. |
| 1037 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 1038 | bcmos_fastlock_lock(&onu_deactivate_wait_lock); |
| 1039 | onu_deact_compltd_key k(0, 1); |
| 1040 | std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k); |
| 1041 | if (it == onu_deact_compltd_map.end()) { |
| 1042 | OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1); |
| 1043 | } else { |
| 1044 | it->second->push(res); |
| 1045 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n"); |
| 1046 | } |
| 1047 | bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0); |
| 1048 | return 0; |
| 1049 | } |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1050 | }; |
| 1051 | |
| 1052 | // Test 1 - DeleteOnu success case |
| 1053 | TEST_F(TestDeleteOnu, DeleteOnuSuccess) { |
| 1054 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1055 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1056 | bcmos_errno onu_cfg_clear_res = BCM_ERR_OK; |
| 1057 | |
| 1058 | bcmolt_onu_cfg onu_cfg; |
| 1059 | bcmolt_onu_key onu_key; |
| 1060 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1061 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1062 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1063 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1064 | |
| 1065 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1066 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1067 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1068 | future<int> push_onu_deact_complt_res = \ |
| 1069 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE); |
| 1070 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1071 | Status status = future_res.get(); |
| 1072 | int res = push_onu_deact_complt_res.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1073 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1074 | } |
| 1075 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1076 | // Test 2 - DeleteOnu failure case - BAL Clear ONU fails |
| 1077 | TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) { |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1078 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1079 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1080 | bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1081 | |
| 1082 | bcmolt_onu_cfg onu_cfg; |
| 1083 | bcmolt_onu_key onu_key; |
| 1084 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1085 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1086 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1087 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1088 | |
| 1089 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1090 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1091 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1092 | future<int> push_onu_deact_complt_res = \ |
| 1093 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE); |
| 1094 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1095 | |
| 1096 | Status status = future_res.get(); |
| 1097 | int res = push_onu_deact_complt_res.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1098 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1099 | } |
| 1100 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1101 | // Test 3 - DeleteOnu failure case - onu deactivation fails |
| 1102 | TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) { |
| 1103 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1104 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1105 | |
| 1106 | bcmolt_onu_cfg onu_cfg; |
| 1107 | bcmolt_onu_key onu_key; |
| 1108 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1109 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1110 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1111 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1112 | |
| 1113 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1114 | |
| 1115 | future<int> push_onu_deact_complt_res = \ |
| 1116 | async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL); |
| 1117 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1118 | |
| 1119 | Status status = future_res.get(); |
| 1120 | int res = push_onu_deact_complt_res.get(); |
| 1121 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1122 | } |
| 1123 | |
| 1124 | // Test 4 - DeleteOnu failure case - onu deactivation timesout |
| 1125 | TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) { |
| 1126 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1127 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1128 | |
| 1129 | bcmolt_onu_cfg onu_cfg; |
| 1130 | bcmolt_onu_key onu_key; |
| 1131 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1132 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 1133 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1134 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1135 | |
| 1136 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1137 | |
| 1138 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1139 | |
| 1140 | Status status = future_res.get(); |
| 1141 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1142 | } |
| 1143 | |
Thiyagarajan Subramani | ad46323 | 2020-02-28 19:10:43 +0530 | [diff] [blame] | 1144 | // Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response |
| 1145 | TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) { |
| 1146 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 1147 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1148 | bcmos_errno onu_cfg_clear_res = BCM_ERR_OK; |
| 1149 | |
| 1150 | bcmolt_onu_cfg onu_cfg; |
| 1151 | bcmolt_onu_key onu_key; |
| 1152 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1153 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 1154 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 1155 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 1156 | |
| 1157 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1158 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1159 | |
| 1160 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1161 | |
| 1162 | Status status = future_res.get(); |
| 1163 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1164 | } |
| 1165 | |
| 1166 | // Test 6 - DeleteOnu failure case - Failed to fetch Onu status |
| 1167 | TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) { |
| 1168 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 1169 | |
| 1170 | bcmolt_onu_cfg onu_cfg; |
| 1171 | bcmolt_onu_key onu_key; |
| 1172 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 1173 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 1174 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 1175 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 1176 | |
| 1177 | future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1178 | |
| 1179 | Status status = future_res.get(); |
| 1180 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1181 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1182 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1183 | //////////////////////////////////////////////////////////////////////////// |
| 1184 | // For testing OmciMsgOut functionality |
| 1185 | //////////////////////////////////////////////////////////////////////////// |
| 1186 | |
| 1187 | class TestOmciMsgOut : public Test { |
| 1188 | protected: |
| 1189 | uint32_t pon_id = 0; |
| 1190 | uint32_t onu_id = 1; |
| 1191 | std::string pkt = "omci-pkt"; |
| 1192 | NiceMock<BalMocker> balMock; |
| 1193 | |
| 1194 | virtual void SetUp() { |
| 1195 | } |
| 1196 | |
| 1197 | virtual void TearDown() { |
| 1198 | } |
| 1199 | }; |
| 1200 | |
| 1201 | // Test 1 - OmciMsgOut success case |
| 1202 | TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) { |
| 1203 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1204 | |
| 1205 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1206 | |
| 1207 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1208 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1209 | } |
| 1210 | |
| 1211 | // Test 1 - OmciMsgOut failure case |
| 1212 | TEST_F(TestOmciMsgOut, OmciMsgOutFailure) { |
| 1213 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 1214 | |
| 1215 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1216 | |
| 1217 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1218 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1219 | } |
| 1220 | |
| 1221 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1222 | // For testing FlowAdd functionality |
| 1223 | //////////////////////////////////////////////////////////////////////////// |
| 1224 | |
| 1225 | class TestFlowAdd : public Test { |
| 1226 | protected: |
| 1227 | int32_t access_intf_id = 0; |
| 1228 | int32_t onu_id = 1; |
| 1229 | int32_t uni_id = 0; |
| 1230 | uint32_t port_no = 16; |
| 1231 | uint32_t flow_id = 1; |
| 1232 | std::string flow_type = "upstream"; |
| 1233 | int32_t alloc_id = 1024; |
| 1234 | int32_t network_intf_id = 0; |
| 1235 | int32_t gemport_id = 1024; |
| 1236 | int32_t priority_value = 0; |
| 1237 | uint64_t cookie = 0; |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1238 | int32_t group_id = -1; |
Burak Gurdag | 2f2618c | 2020-04-23 13:20:30 +0000 | [diff] [blame] | 1239 | uint32_t tech_profile_id = 64; |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1240 | bool enable_encryption = true; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1241 | |
| 1242 | NiceMock<BalMocker> balMock; |
| 1243 | openolt::Flow* flow; |
| 1244 | openolt::Classifier* classifier; |
| 1245 | openolt::Action* action; |
| 1246 | openolt::ActionCmd* cmd; |
| 1247 | |
| 1248 | bcmolt_flow_key flow_key; |
| 1249 | bcmolt_flow_cfg flow_cfg; |
| 1250 | |
| 1251 | tech_profile::TrafficQueues* traffic_queues; |
| 1252 | tech_profile::TrafficQueue* traffic_queue_1; |
| 1253 | tech_profile::TrafficQueue* traffic_queue_2; |
| 1254 | tech_profile::DiscardConfig* discard_config_1; |
| 1255 | tech_profile::DiscardConfig* discard_config_2; |
| 1256 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 1257 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 1258 | |
| 1259 | |
| 1260 | virtual void SetUp() { |
| 1261 | classifier = new openolt::Classifier; |
| 1262 | action = new openolt::Action; |
| 1263 | cmd = new openolt::ActionCmd; |
| 1264 | |
| 1265 | classifier->set_o_tpid(0); |
| 1266 | classifier->set_o_vid(7); |
| 1267 | classifier->set_i_tpid(0); |
| 1268 | classifier->set_i_vid(0); |
| 1269 | classifier->set_o_pbits(0); |
| 1270 | classifier->set_i_pbits(0); |
| 1271 | classifier->set_eth_type(0); |
| 1272 | classifier->set_ip_proto(0); |
| 1273 | classifier->set_src_port(0); |
| 1274 | classifier->set_dst_port(0); |
| 1275 | classifier->set_pkt_tag_type("single_tag"); |
| 1276 | |
| 1277 | action->set_o_vid(12); |
| 1278 | action->set_o_pbits(0); |
| 1279 | action->set_o_tpid(0); |
| 1280 | action->set_i_vid(0); |
| 1281 | action->set_i_pbits(0); |
| 1282 | action->set_i_tpid(0); |
| 1283 | |
| 1284 | cmd->set_add_outer_tag(true); |
| 1285 | cmd->set_remove_outer_tag(false); |
| 1286 | cmd->set_trap_to_host(false); |
| 1287 | action->set_allocated_cmd(cmd); |
| 1288 | |
| 1289 | flow_key.flow_id = 1; |
| 1290 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1291 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1292 | flow_cfg.data.onu_id=1; |
| 1293 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1294 | flow_cfg.data.svc_port_id=1024; |
| 1295 | flow_cfg.data.priority=0; |
| 1296 | flow_cfg.data.cookie=0; |
| 1297 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1298 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1299 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1300 | flow_cfg.data.egress_intf.intf_id=0; |
| 1301 | flow_cfg.data.classifier.o_vid=7; |
| 1302 | flow_cfg.data.classifier.o_pbits=0; |
| 1303 | flow_cfg.data.classifier.i_vid=0; |
| 1304 | flow_cfg.data.classifier.i_pbits=0; |
| 1305 | flow_cfg.data.classifier.ether_type=0; |
| 1306 | flow_cfg.data.classifier.ip_proto=0; |
| 1307 | flow_cfg.data.classifier.src_port=0; |
| 1308 | flow_cfg.data.classifier.dst_port=0; |
| 1309 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1310 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1311 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1312 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1313 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1314 | flow_cfg.data.action.o_vid=12; |
| 1315 | flow_cfg.data.action.o_pbits=0; |
| 1316 | flow_cfg.data.action.i_vid=0; |
| 1317 | flow_cfg.data.action.i_pbits=0; |
| 1318 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1319 | |
| 1320 | traffic_queues = new tech_profile::TrafficQueues; |
| 1321 | traffic_queues->set_intf_id(0); |
| 1322 | traffic_queues->set_onu_id(2); |
| 1323 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 1324 | traffic_queue_1->set_gemport_id(1024); |
| 1325 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 1326 | traffic_queue_1->set_aes_encryption(true); |
| 1327 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1328 | traffic_queue_1->set_priority(0); |
| 1329 | traffic_queue_1->set_weight(0); |
| 1330 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1331 | discard_config_1 = new tech_profile::DiscardConfig; |
| 1332 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1333 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 1334 | tail_drop_discard_config_1->set_queue_size(8); |
| 1335 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 1336 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 1337 | |
| 1338 | traffic_queues->set_uni_id(0); |
| 1339 | traffic_queues->set_port_no(16); |
| 1340 | |
| 1341 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1342 | traffic_queue_2->set_gemport_id(1025); |
| 1343 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 1344 | traffic_queue_2->set_aes_encryption(true); |
| 1345 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1346 | traffic_queue_2->set_priority(1); |
| 1347 | traffic_queue_2->set_weight(0); |
| 1348 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1349 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1350 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1351 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1352 | tail_drop_discard_config_2->set_queue_size(8); |
| 1353 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1354 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1355 | } |
| 1356 | |
| 1357 | virtual void TearDown() { |
| 1358 | } |
| 1359 | }; |
| 1360 | |
| 1361 | // Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue) |
| 1362 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) { |
| 1363 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1364 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1365 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1366 | 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] | 1367 | 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] | 1368 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1369 | } |
| 1370 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1371 | #ifdef FLOW_CHECKER |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1372 | // Test 2 - FlowAdd - Duplicate Flow case |
| 1373 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) { |
| 1374 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1375 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1376 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1377 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1378 | 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] | 1379 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1380 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1381 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1382 | #endif |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1383 | |
| 1384 | // Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error) |
| 1385 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) { |
| 1386 | gemport_id = 1025; |
| 1387 | |
| 1388 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1389 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1390 | |
| 1391 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1392 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1393 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1394 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1395 | 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] | 1396 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1397 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1398 | } |
| 1399 | |
| 1400 | // Test 4 - FlowAdd - Failure case(Invalid flow direction) |
| 1401 | TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) { |
| 1402 | flow_type = "bidirectional"; |
| 1403 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1404 | 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] | 1405 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1406 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1407 | } |
| 1408 | |
| 1409 | // Test 5 - FlowAdd - Failure case(Invalid network setting) |
| 1410 | TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) { |
| 1411 | network_intf_id = -1; |
| 1412 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1413 | 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] | 1414 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1415 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1416 | } |
| 1417 | |
| 1418 | // Test 6 - FlowAdd - Success case(Single tag & EAP Ether type) |
| 1419 | TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) { |
| 1420 | flow_id = 2; |
| 1421 | |
| 1422 | classifier->set_eth_type(34958); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1423 | action = new openolt::Action; |
| 1424 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1425 | cmd->set_trap_to_host(true); |
| 1426 | action->set_allocated_cmd(cmd); |
| 1427 | |
| 1428 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1429 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1430 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1431 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1432 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1433 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1434 | 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] | 1435 | 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] | 1436 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1437 | } |
| 1438 | |
| 1439 | // Test 7 - FlowAdd - Success case(Single tag & DHCP flow) |
| 1440 | TEST_F(TestFlowAdd, FlowAddDhcpSuccess) { |
| 1441 | flow_id = 3; |
| 1442 | gemport_id = 1025; |
| 1443 | |
| 1444 | classifier->set_ip_proto(17); |
| 1445 | classifier->set_src_port(68); |
| 1446 | classifier->set_dst_port(67); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1447 | action = new openolt::Action; |
| 1448 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1449 | cmd->set_trap_to_host(true); |
| 1450 | action->set_allocated_cmd(cmd); |
| 1451 | |
| 1452 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1453 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1454 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1455 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1456 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1457 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1458 | 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] | 1459 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1460 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1461 | } |
| 1462 | |
| 1463 | // Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue) |
| 1464 | TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) { |
| 1465 | flow_id = 4; |
| 1466 | flow_type = "downstream"; |
| 1467 | |
| 1468 | classifier->set_o_vid(12); |
| 1469 | classifier->set_i_vid(7); |
| 1470 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1471 | action = new openolt::Action; |
| 1472 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1473 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1474 | cmd->set_remove_outer_tag(true); |
| 1475 | action->set_allocated_cmd(cmd); |
| 1476 | |
| 1477 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1478 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1479 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1480 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1481 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1482 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1483 | 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] | 1484 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1485 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1486 | } |
| 1487 | |
| 1488 | // Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue) |
| 1489 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) { |
| 1490 | onu_id = 2; |
| 1491 | flow_id = 5; |
| 1492 | alloc_id = 1025; |
| 1493 | |
| 1494 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1495 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1496 | |
| 1497 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1498 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1499 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1500 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1501 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1502 | CreateTrafficQueues_(traffic_queues); |
| 1503 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1504 | 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] | 1505 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1506 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1507 | } |
| 1508 | |
| 1509 | // Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue) |
| 1510 | TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) { |
| 1511 | onu_id = 2; |
| 1512 | flow_id = 6; |
| 1513 | flow_type = "downstream"; |
| 1514 | alloc_id = 1025; |
| 1515 | |
| 1516 | classifier->set_o_vid(12); |
| 1517 | classifier->set_i_vid(7); |
| 1518 | classifier->set_pkt_tag_type("double_tag"); |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1519 | action = new openolt::Action; |
| 1520 | cmd = new openolt::ActionCmd; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1521 | action->set_o_vid(0); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1522 | cmd->set_remove_outer_tag(true); |
| 1523 | action->set_allocated_cmd(cmd); |
| 1524 | |
| 1525 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1526 | traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1527 | |
| 1528 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1529 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1530 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1531 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1532 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1533 | CreateTrafficQueues_(traffic_queues); |
| 1534 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1535 | 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] | 1536 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1537 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1538 | } |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 1539 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1540 | // Test 11 - FlowAdd - success case (Downstream-Encrypted GEM) |
| 1541 | TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) { |
| 1542 | onu_id = 2; |
| 1543 | flow_id = 7; |
| 1544 | flow_type = "downstream"; |
| 1545 | alloc_id = 1025; |
| 1546 | enable_encryption = true; |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1547 | |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1548 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1549 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1550 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1551 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1552 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1553 | |
| 1554 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1555 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1556 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1557 | } |
| 1558 | |
| 1559 | // Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied) |
| 1560 | TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) { |
| 1561 | onu_id = 2; |
| 1562 | flow_id = 8; |
| 1563 | flow_type = "downstream"; |
| 1564 | alloc_id = 1025; |
| 1565 | enable_encryption = false; |
| 1566 | |
| 1567 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1568 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1569 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1570 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1571 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1572 | |
| 1573 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1574 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1575 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1576 | } |
| 1577 | |
| 1578 | // Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied) |
| 1579 | TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) { |
| 1580 | onu_id = 2; |
| 1581 | flow_id = 9; |
| 1582 | flow_type = "upstream"; |
| 1583 | alloc_id = 1025; |
| 1584 | enable_encryption = true; |
| 1585 | |
| 1586 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1587 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1588 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1589 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1590 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1591 | |
| 1592 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1593 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1594 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1595 | } |
| 1596 | |
| 1597 | // Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied) |
| 1598 | TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) { |
| 1599 | onu_id = 2; |
| 1600 | flow_id = 10; |
| 1601 | flow_type = "multicast"; |
| 1602 | alloc_id = 1025; |
| 1603 | enable_encryption = true; |
| 1604 | |
| 1605 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1606 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1607 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1608 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1609 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1610 | |
| 1611 | Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, |
| 1612 | gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption); |
| 1613 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1614 | } |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1615 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1616 | // For testing OnuPacketOut functionality |
| 1617 | //////////////////////////////////////////////////////////////////////////// |
| 1618 | |
| 1619 | class TestOnuPacketOut : public Test { |
| 1620 | protected: |
| 1621 | uint32_t pon_id = 0; |
| 1622 | uint32_t onu_id = 1; |
| 1623 | std::string pkt = "omci-pkt"; |
| 1624 | NiceMock<BalMocker> balMock; |
| 1625 | |
| 1626 | virtual void SetUp() { |
| 1627 | } |
| 1628 | |
| 1629 | virtual void TearDown() { |
| 1630 | } |
| 1631 | }; |
| 1632 | |
| 1633 | // Test 1 - OnuPacketOut success case |
| 1634 | TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) { |
| 1635 | uint32_t port_no = 16; |
| 1636 | uint32_t gemport_id = 1024; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1637 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1638 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1639 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1640 | |
| 1641 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1642 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1643 | } |
| 1644 | |
| 1645 | // Test 2 - OnuPacketOut Port number as 0 case |
| 1646 | TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) { |
| 1647 | uint32_t port_no = 0; |
| 1648 | uint32_t gemport_id = 1024; |
| 1649 | |
| 1650 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1651 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1652 | } |
| 1653 | |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1654 | // Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case |
| 1655 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) { |
| 1656 | uint32_t port_no = 16; |
| 1657 | uint32_t gemport_id = 0; |
| 1658 | |
| 1659 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1660 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1661 | |
| 1662 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1663 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1664 | } |
| 1665 | |
| 1666 | // Test 4 - OnuPacketOut success, Failure in finding Gem port case |
| 1667 | TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) { |
| 1668 | uint32_t port_no = 64; |
| 1669 | uint32_t gemport_id = 0; |
| 1670 | |
| 1671 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1672 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1673 | |
| 1674 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1675 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1676 | } |
| 1677 | |
| 1678 | //////////////////////////////////////////////////////////////////////////// |
| 1679 | // For testing FlowRemove functionality |
| 1680 | //////////////////////////////////////////////////////////////////////////// |
| 1681 | |
| 1682 | class TestFlowRemove : public Test { |
| 1683 | protected: |
| 1684 | NiceMock<BalMocker> balMock; |
| 1685 | |
| 1686 | virtual void SetUp() { |
| 1687 | } |
| 1688 | |
| 1689 | virtual void TearDown() { |
| 1690 | } |
| 1691 | }; |
| 1692 | |
| 1693 | // Test 1 - FlowRemove - Failure case |
| 1694 | TEST_F(TestFlowRemove, FlowRemoveFailure) { |
| 1695 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1696 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1697 | |
| 1698 | Status status = FlowRemove_(1, "upstream"); |
| 1699 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1700 | } |
| 1701 | |
| 1702 | // Test 2 - FlowRemove - success case |
| 1703 | TEST_F(TestFlowRemove, FlowRemoveSuccess) { |
| 1704 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1705 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1706 | |
| 1707 | Status status = FlowRemove_(1, "upstream"); |
| 1708 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1709 | } |
| 1710 | |
| 1711 | //////////////////////////////////////////////////////////////////////////// |
| 1712 | // For testing UplinkPacketOut functionality |
| 1713 | //////////////////////////////////////////////////////////////////////////// |
| 1714 | |
| 1715 | class TestUplinkPacketOut : public Test { |
| 1716 | protected: |
| 1717 | uint32_t pon_id = 0; |
| 1718 | std::string pkt = "omci-pkt"; |
| 1719 | NiceMock<BalMocker> balMock; |
| 1720 | |
| 1721 | bcmolt_flow_key flow_key; |
| 1722 | bcmolt_flow_cfg flow_cfg; |
| 1723 | |
| 1724 | virtual void SetUp() { |
| 1725 | flow_key.flow_id = 1; |
| 1726 | flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1727 | BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key); |
| 1728 | flow_cfg.data.onu_id=1; |
| 1729 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM; |
| 1730 | flow_cfg.data.svc_port_id=1024; |
| 1731 | flow_cfg.data.priority=0; |
| 1732 | flow_cfg.data.cookie=0; |
| 1733 | flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON; |
| 1734 | flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI; |
| 1735 | flow_cfg.data.ingress_intf.intf_id=0; |
| 1736 | flow_cfg.data.egress_intf.intf_id=0; |
| 1737 | flow_cfg.data.classifier.o_vid=7; |
| 1738 | flow_cfg.data.classifier.o_pbits=0; |
| 1739 | flow_cfg.data.classifier.i_vid=0; |
| 1740 | flow_cfg.data.classifier.i_pbits=0; |
| 1741 | flow_cfg.data.classifier.ether_type=0; |
| 1742 | flow_cfg.data.classifier.ip_proto=0; |
| 1743 | flow_cfg.data.classifier.src_port=0; |
| 1744 | flow_cfg.data.classifier.dst_port=0; |
| 1745 | flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG; |
| 1746 | flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE; |
| 1747 | flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0; |
| 1748 | flow_cfg.data.egress_qos.tm_sched.id=1020; |
| 1749 | flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 1750 | flow_cfg.data.action.o_vid=12; |
| 1751 | flow_cfg.data.action.o_pbits=0; |
| 1752 | flow_cfg.data.action.i_vid=0; |
| 1753 | flow_cfg.data.action.i_pbits=0; |
| 1754 | flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE; |
| 1755 | } |
| 1756 | |
| 1757 | virtual void TearDown() { |
| 1758 | } |
| 1759 | }; |
| 1760 | |
| 1761 | // Test 1 - UplinkPacketOut success case |
| 1762 | TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) { |
| 1763 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK; |
| 1764 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1765 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1766 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1767 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1768 | |
| 1769 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1770 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1771 | } |
| 1772 | |
| 1773 | // Test 2 - UplinkPacketOut Failure case |
| 1774 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) { |
| 1775 | bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL; |
| 1776 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res)); |
| 1777 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1778 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1779 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1780 | |
| 1781 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1782 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1783 | } |
| 1784 | |
| 1785 | // Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case |
| 1786 | TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) { |
| 1787 | flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM; |
| 1788 | |
| 1789 | FlowRemove_(2, "upstream"); |
| 1790 | FlowRemove_(3, "upstream"); |
| 1791 | FlowRemove_(4, "downstream"); |
| 1792 | FlowRemove_(5, "upstream"); |
| 1793 | FlowRemove_(6, "downstream"); |
Burak Gurdag | a052359 | 2021-02-24 15:17:47 +0000 | [diff] [blame] | 1794 | FlowRemove_(7, "downstream"); |
| 1795 | FlowRemove_(8, "downstream"); |
| 1796 | FlowRemove_(9, "upstream"); |
| 1797 | FlowRemove_(10, "multicast"); |
Thiyagarajan Subramani | 81c5611 | 2019-12-19 08:29:55 -0500 | [diff] [blame] | 1798 | |
| 1799 | bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK; |
| 1800 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _)) |
| 1801 | .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res))); |
| 1802 | |
| 1803 | Status status = UplinkPacketOut_(pon_id, pkt); |
| 1804 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1805 | } |
| 1806 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1807 | //////////////////////////////////////////////////////////////////////////// |
| 1808 | // For testing CreateTrafficSchedulers functionality |
| 1809 | //////////////////////////////////////////////////////////////////////////// |
| 1810 | |
| 1811 | class TestCreateTrafficSchedulers : public Test { |
| 1812 | protected: |
| 1813 | NiceMock<BalMocker> balMock; |
| 1814 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 1815 | tech_profile::TrafficScheduler* traffic_sched; |
| 1816 | tech_profile::SchedulerConfig* scheduler; |
| 1817 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 1818 | |
| 1819 | virtual void SetUp() { |
| 1820 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 1821 | traffic_scheds->set_intf_id(0); |
| 1822 | traffic_scheds->set_onu_id(1); |
| 1823 | traffic_scheds->set_uni_id(0); |
| 1824 | traffic_scheds->set_port_no(16); |
| 1825 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 1826 | traffic_sched->set_alloc_id(1024); |
| 1827 | scheduler = new tech_profile::SchedulerConfig; |
| 1828 | scheduler->set_priority(0); |
| 1829 | scheduler->set_weight(0); |
| 1830 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1831 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 1832 | traffic_shaping_info->set_cbs(60536); |
| 1833 | traffic_shaping_info->set_pbs(65536); |
| 1834 | traffic_shaping_info->set_gir(10000); |
| 1835 | } |
| 1836 | |
| 1837 | virtual void TearDown() { |
| 1838 | } |
| 1839 | |
| 1840 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1841 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 1842 | alloc_cfg_compltd_key k(0, 1024); |
| 1843 | alloc_cfg_complete_result res; |
| 1844 | res.pon_intf_id = 0; |
| 1845 | res.alloc_id = 1024; |
| 1846 | res.state = state; |
| 1847 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1848 | |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1849 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 1850 | // before we push the result. |
| 1851 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 1852 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 1853 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 1854 | if (it == alloc_cfg_compltd_map.end()) { |
| 1855 | 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] | 1856 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1857 | it->second->push(res); |
| 1858 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1859 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1860 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 1861 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1862 | } |
| 1863 | }; |
| 1864 | |
| 1865 | // Test 1 - CreateTrafficSchedulers-Upstream success case |
| 1866 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) { |
| 1867 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1868 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1869 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1870 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1871 | traffic_shaping_info->set_cir(64000); |
| 1872 | traffic_shaping_info->set_pir(128000); |
| 1873 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1874 | |
| 1875 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1876 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1877 | |
| 1878 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1879 | future<int> push_alloc_cfg_complt = \ |
| 1880 | 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] | 1881 | |
| 1882 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1883 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1884 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1885 | } |
| 1886 | |
| 1887 | // Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication) |
| 1888 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) { |
| 1889 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1890 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1891 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1892 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1893 | traffic_shaping_info->set_cir(64000); |
| 1894 | traffic_shaping_info->set_pir(128000); |
| 1895 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1896 | |
| 1897 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1898 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1899 | |
| 1900 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1901 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1902 | } |
| 1903 | |
| 1904 | // Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request) |
| 1905 | TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) { |
| 1906 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1907 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1908 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1909 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1910 | traffic_shaping_info->set_cir(64000); |
| 1911 | traffic_shaping_info->set_pir(128000); |
| 1912 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1913 | |
| 1914 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1915 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1916 | |
| 1917 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1918 | future<int> push_alloc_cfg_complt = \ |
| 1919 | 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] | 1920 | |
| 1921 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1922 | int res = push_alloc_cfg_complt.get(); |
| 1923 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1924 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1925 | } |
| 1926 | |
| 1927 | // Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state) |
| 1928 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) { |
| 1929 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1930 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1931 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1932 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1933 | traffic_shaping_info->set_cir(64000); |
| 1934 | traffic_shaping_info->set_pir(128000); |
| 1935 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1936 | |
| 1937 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1938 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1939 | |
| 1940 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1941 | future<int> push_alloc_cfg_complt = \ |
| 1942 | 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] | 1943 | |
| 1944 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 1945 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 1946 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1947 | } |
| 1948 | |
| 1949 | // Test 5 - CreateTrafficSchedulers-Upstream Failure case |
| 1950 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) { |
| 1951 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1952 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1953 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1954 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1955 | traffic_shaping_info->set_cir(64000); |
| 1956 | traffic_shaping_info->set_pir(128000); |
| 1957 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1958 | |
| 1959 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1960 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1961 | |
| 1962 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1963 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1964 | } |
| 1965 | |
| 1966 | // Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case |
| 1967 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) { |
| 1968 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1969 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1970 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1971 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1972 | traffic_shaping_info->set_cir(64000); |
| 1973 | traffic_shaping_info->set_pir(0); |
| 1974 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1975 | |
| 1976 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1977 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1978 | } |
| 1979 | |
| 1980 | // Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case |
| 1981 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) { |
| 1982 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1983 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1984 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1985 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1986 | traffic_shaping_info->set_cir(64000); |
| 1987 | traffic_shaping_info->set_pir(32000); |
| 1988 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1989 | |
| 1990 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1991 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1992 | } |
| 1993 | |
| 1994 | // Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case |
| 1995 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) { |
| 1996 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1997 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1998 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1999 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2000 | traffic_shaping_info->set_cir(64000); |
| 2001 | traffic_shaping_info->set_pir(64000); |
| 2002 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2003 | |
| 2004 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2005 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2006 | } |
| 2007 | |
| 2008 | // Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case |
| 2009 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) { |
| 2010 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2011 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2012 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2013 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2014 | traffic_shaping_info->set_cir(64000); |
| 2015 | traffic_shaping_info->set_pir(0); |
| 2016 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2017 | |
| 2018 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2019 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2020 | } |
| 2021 | |
| 2022 | // Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case |
| 2023 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) { |
| 2024 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2025 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2026 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2027 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2028 | traffic_shaping_info->set_cir(0); |
| 2029 | traffic_shaping_info->set_pir(32000); |
| 2030 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2031 | |
| 2032 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2033 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2034 | } |
| 2035 | |
| 2036 | // Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case |
| 2037 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) { |
| 2038 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2039 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2040 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2041 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2042 | traffic_shaping_info->set_cir(64000); |
| 2043 | traffic_shaping_info->set_pir(32000); |
| 2044 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2045 | |
| 2046 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2047 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2048 | } |
| 2049 | |
| 2050 | // Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case |
| 2051 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) { |
| 2052 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2053 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 2054 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2055 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2056 | traffic_shaping_info->set_cir(64000); |
| 2057 | traffic_shaping_info->set_pir(64000); |
| 2058 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2059 | |
| 2060 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2061 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2062 | } |
| 2063 | |
| 2064 | // Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case |
| 2065 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) { |
| 2066 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2067 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2068 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2069 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2070 | traffic_shaping_info->set_cir(64000); |
| 2071 | traffic_shaping_info->set_pir(0); |
| 2072 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2073 | |
| 2074 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2075 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2076 | } |
| 2077 | |
| 2078 | // Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case |
| 2079 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) { |
| 2080 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2081 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2082 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2083 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2084 | traffic_shaping_info->set_cir(0); |
| 2085 | traffic_shaping_info->set_pir(32000); |
| 2086 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2087 | |
| 2088 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2089 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2090 | } |
| 2091 | |
| 2092 | // Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case |
| 2093 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) { |
| 2094 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2095 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 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 | |
| 2105 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2106 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2107 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2108 | |
| 2109 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2110 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2111 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2112 | } |
| 2113 | |
| 2114 | // Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case |
| 2115 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) { |
| 2116 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 2117 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 2118 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2119 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2120 | traffic_shaping_info->set_cir(64000); |
| 2121 | traffic_shaping_info->set_pir(32000); |
| 2122 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2123 | |
| 2124 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2125 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2126 | |
| 2127 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2128 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2129 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2130 | |
| 2131 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2132 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2133 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2134 | } |
| 2135 | |
| 2136 | // Test 17 - CreateTrafficSchedulers-Downstream success case |
| 2137 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) { |
| 2138 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2139 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2140 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2141 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2142 | traffic_shaping_info->set_cir(64000); |
| 2143 | traffic_shaping_info->set_pir(128000); |
| 2144 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2145 | |
| 2146 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2147 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2148 | |
| 2149 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2150 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2151 | } |
| 2152 | |
| 2153 | // Test 18 - CreateTrafficSchedulers-Downstream Failure case |
| 2154 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) { |
| 2155 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2156 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2157 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2158 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2159 | traffic_shaping_info->set_cir(64000); |
| 2160 | traffic_shaping_info->set_pir(128000); |
| 2161 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2162 | |
| 2163 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2164 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2165 | |
| 2166 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2167 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2168 | } |
| 2169 | |
| 2170 | // Test 19 - CreateTrafficSchedulers-Invalid direction Failure case |
| 2171 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) { |
| 2172 | scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 2173 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2174 | traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 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 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 2181 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2182 | } |
| 2183 | |
| 2184 | //////////////////////////////////////////////////////////////////////////// |
| 2185 | // For testing RemoveTrafficSchedulers functionality |
| 2186 | //////////////////////////////////////////////////////////////////////////// |
| 2187 | |
| 2188 | class TestRemoveTrafficSchedulers : public Test { |
| 2189 | protected: |
| 2190 | NiceMock<BalMocker> balMock; |
| 2191 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2192 | tech_profile::TrafficScheduler* traffic_sched; |
| 2193 | tech_profile::SchedulerConfig* scheduler; |
| 2194 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 2195 | alloc_cfg_complete_result res; |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2196 | uint32_t pon_id = 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2197 | |
| 2198 | virtual void SetUp() { |
| 2199 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2200 | traffic_scheds->set_intf_id(0); |
| 2201 | traffic_scheds->set_onu_id(1); |
| 2202 | traffic_scheds->set_uni_id(0); |
| 2203 | traffic_scheds->set_port_no(16); |
| 2204 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2205 | traffic_sched->set_alloc_id(1025); |
| 2206 | scheduler = new tech_profile::SchedulerConfig; |
| 2207 | scheduler->set_priority(0); |
| 2208 | scheduler->set_weight(0); |
| 2209 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2210 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 2211 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 2212 | traffic_shaping_info->set_cir(64000); |
| 2213 | traffic_shaping_info->set_pir(128000); |
| 2214 | traffic_shaping_info->set_cbs(60536); |
| 2215 | traffic_shaping_info->set_pbs(65536); |
| 2216 | traffic_shaping_info->set_gir(10000); |
| 2217 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 2218 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2219 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2220 | } |
| 2221 | |
| 2222 | virtual void TearDown() { |
| 2223 | } |
| 2224 | |
| 2225 | public: |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2226 | static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 2227 | alloc_cfg_compltd_key k(0, 1025); |
| 2228 | alloc_cfg_complete_result res; |
| 2229 | res.pon_intf_id = 0; |
| 2230 | res.alloc_id = 1025; |
| 2231 | res.state = state; |
| 2232 | res.status = status; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2233 | |
Thiyagarajan Subramani | 1744c92 | 2020-02-16 18:55:02 +0530 | [diff] [blame] | 2234 | // We need to wait for some time to allow the Alloc Cfg Request to be triggered |
| 2235 | // before we push the result. |
| 2236 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2237 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 2238 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 2239 | if (it == alloc_cfg_compltd_map.end()) { |
| 2240 | 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] | 2241 | } else { |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2242 | it->second->push(res); |
| 2243 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2244 | } |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2245 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 2246 | return 0; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2247 | } |
| 2248 | }; |
| 2249 | |
| 2250 | // Test 1 - RemoveTrafficSchedulers-Upstream success case |
| 2251 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) { |
| 2252 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2253 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2254 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2255 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2256 | bcmolt_pon_interface_key pon_key; |
| 2257 | bcmolt_pon_interface_cfg pon_cfg; |
| 2258 | pon_key.pon_ni = pon_id; |
| 2259 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 2260 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 2261 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 2262 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 2263 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 2264 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2265 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2266 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2267 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS); |
| 2268 | |
| 2269 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2270 | int res = push_alloc_cfg_complt.get(); |
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 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset) |
| 2275 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) { |
| 2276 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2277 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2278 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2279 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2280 | bcmolt_pon_interface_key pon_key; |
| 2281 | bcmolt_pon_interface_cfg pon_cfg; |
| 2282 | pon_key.pon_ni = pon_id; |
| 2283 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 2284 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 2285 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 2286 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 2287 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 2288 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2289 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2290 | future<int> push_alloc_cfg_complt = \ |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2291 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 2292 | |
| 2293 | Status status = future_res.get(); |
Girish Gowdra | 7a79dae | 2020-02-10 18:22:11 +0530 | [diff] [blame] | 2294 | int res = push_alloc_cfg_complt.get(); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2295 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2296 | } |
| 2297 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2298 | // Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response) |
| 2299 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) { |
| 2300 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2301 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2302 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2303 | |
| 2304 | bcmolt_pon_interface_key pon_key; |
| 2305 | bcmolt_pon_interface_cfg pon_cfg; |
| 2306 | pon_key.pon_ni = pon_id; |
| 2307 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 2308 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 2309 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 2310 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 2311 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 2312 | |
| 2313 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2314 | |
| 2315 | Status status = future_res.get(); |
| 2316 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2317 | } |
| 2318 | |
| 2319 | // Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case) |
| 2320 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) { |
| 2321 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2322 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2323 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2324 | |
| 2325 | bcmolt_pon_interface_key pon_key; |
| 2326 | bcmolt_pon_interface_cfg pon_cfg; |
| 2327 | pon_key.pon_ni = pon_id; |
| 2328 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 2329 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 2330 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL; |
| 2331 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 2332 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 2333 | |
| 2334 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 2335 | |
| 2336 | Status status = future_res.get(); |
| 2337 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2338 | } |
| 2339 | |
| 2340 | // Test 5 - RemoveTrafficSchedulers-Upstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2341 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) { |
| 2342 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 2343 | |
| 2344 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2345 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2346 | |
| 2347 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2348 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2349 | } |
| 2350 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2351 | // Test 6 - RemoveTrafficSchedulers-Downstream Failure case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2352 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) { |
| 2353 | //Create Scheduler |
| 2354 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2355 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2356 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2357 | CreateTrafficSchedulers_(traffic_scheds); |
| 2358 | |
| 2359 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2360 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2361 | |
| 2362 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2363 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2364 | } |
| 2365 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2366 | // Test 7 - RemoveTrafficSchedulers-Downstream success case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2367 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) { |
| 2368 | //Create Scheduler |
| 2369 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2370 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2371 | traffic_sched->set_allocated_scheduler(scheduler); |
| 2372 | CreateTrafficSchedulers_(traffic_scheds); |
| 2373 | |
| 2374 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2375 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2376 | |
| 2377 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2378 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2379 | } |
| 2380 | |
Thiyagarajan Subramani | 8305c28 | 2020-02-04 20:07:42 +0530 | [diff] [blame] | 2381 | // Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 2382 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) { |
| 2383 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2384 | |
| 2385 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 2386 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2387 | } |
| 2388 | |
| 2389 | //////////////////////////////////////////////////////////////////////////// |
| 2390 | // For testing CreateTrafficQueues functionality |
| 2391 | //////////////////////////////////////////////////////////////////////////// |
| 2392 | |
| 2393 | class TestCreateTrafficQueues : public Test { |
| 2394 | protected: |
| 2395 | NiceMock<BalMocker> balMock; |
| 2396 | tech_profile::TrafficQueues* traffic_queues; |
| 2397 | tech_profile::TrafficQueue* traffic_queue_1; |
| 2398 | tech_profile::TrafficQueue* traffic_queue_2; |
| 2399 | tech_profile::DiscardConfig* discard_config_1; |
| 2400 | tech_profile::DiscardConfig* discard_config_2; |
| 2401 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 2402 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 2403 | |
| 2404 | virtual void SetUp() { |
| 2405 | traffic_queues = new tech_profile::TrafficQueues; |
| 2406 | traffic_queues->set_intf_id(0); |
| 2407 | traffic_queues->set_onu_id(1); |
| 2408 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 2409 | traffic_queue_1->set_gemport_id(1024); |
| 2410 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 2411 | traffic_queue_1->set_aes_encryption(true); |
| 2412 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2413 | traffic_queue_1->set_priority(0); |
| 2414 | traffic_queue_1->set_weight(0); |
| 2415 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2416 | discard_config_1 = new tech_profile::DiscardConfig; |
| 2417 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2418 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 2419 | tail_drop_discard_config_1->set_queue_size(8); |
| 2420 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 2421 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 2422 | } |
| 2423 | |
| 2424 | virtual void TearDown() { |
| 2425 | } |
| 2426 | }; |
| 2427 | |
| 2428 | // Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 2429 | TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) { |
| 2430 | Status status; |
| 2431 | traffic_queues->set_uni_id(0); |
| 2432 | traffic_queues->set_port_no(16); |
| 2433 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2434 | |
| 2435 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2436 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2437 | |
| 2438 | status = CreateTrafficQueues_(traffic_queues); |
| 2439 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2440 | |
| 2441 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2442 | status = CreateTrafficQueues_(traffic_queues); |
| 2443 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2444 | } |
| 2445 | |
| 2446 | // Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case |
| 2447 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) { |
| 2448 | traffic_queues->set_uni_id(1); |
| 2449 | traffic_queues->set_port_no(32); |
| 2450 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2451 | |
| 2452 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2453 | traffic_queue_2->set_gemport_id(1025); |
| 2454 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2455 | traffic_queue_2->set_aes_encryption(true); |
| 2456 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2457 | traffic_queue_2->set_priority(1); |
| 2458 | traffic_queue_2->set_weight(0); |
| 2459 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2460 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2461 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2462 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2463 | tail_drop_discard_config_2->set_queue_size(8); |
| 2464 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2465 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2466 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2467 | |
| 2468 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2469 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2470 | |
| 2471 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2472 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2473 | } |
| 2474 | |
| 2475 | // Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case |
| 2476 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) { |
| 2477 | traffic_queues->set_uni_id(2); |
| 2478 | traffic_queues->set_port_no(16); |
| 2479 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2480 | |
| 2481 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2482 | traffic_queue_2->set_gemport_id(1025); |
| 2483 | traffic_queue_2->set_pbit_map("0b10001010"); |
| 2484 | traffic_queue_2->set_aes_encryption(true); |
| 2485 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2486 | traffic_queue_2->set_priority(1); |
| 2487 | traffic_queue_2->set_weight(0); |
| 2488 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2489 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2490 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2491 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2492 | tail_drop_discard_config_2->set_queue_size(8); |
| 2493 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2494 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2495 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2496 | |
| 2497 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2498 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2499 | |
| 2500 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2501 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2502 | } |
| 2503 | |
| 2504 | // Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case |
| 2505 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) { |
| 2506 | traffic_queues->set_uni_id(3); |
| 2507 | traffic_queues->set_port_no(16); |
| 2508 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2509 | |
| 2510 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2511 | traffic_queue_2->set_gemport_id(1025); |
| 2512 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 2513 | traffic_queue_2->set_aes_encryption(true); |
| 2514 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2515 | traffic_queue_2->set_priority(1); |
| 2516 | traffic_queue_2->set_weight(0); |
| 2517 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2518 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2519 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2520 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2521 | tail_drop_discard_config_2->set_queue_size(8); |
| 2522 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2523 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2524 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2525 | |
| 2526 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2527 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2528 | |
| 2529 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2530 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2531 | } |
| 2532 | |
| 2533 | // Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case |
| 2534 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) { |
| 2535 | int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; |
| 2536 | int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272}; |
| 2537 | std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"}; |
| 2538 | |
| 2539 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2540 | for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) { |
| 2541 | traffic_queues->set_uni_id(uni_ids[i]); |
| 2542 | traffic_queues->set_port_no(port_nos[i]); |
| 2543 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2544 | |
| 2545 | traffic_queue_2->set_gemport_id(1025); |
| 2546 | traffic_queue_2->set_pbit_map(pbit_maps[i]); |
| 2547 | traffic_queue_2->set_aes_encryption(true); |
| 2548 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 2549 | traffic_queue_2->set_priority(1); |
| 2550 | traffic_queue_2->set_weight(0); |
| 2551 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2552 | discard_config_2 = new tech_profile::DiscardConfig; |
| 2553 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 2554 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 2555 | tail_drop_discard_config_2->set_queue_size(8); |
| 2556 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 2557 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 2558 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2559 | |
| 2560 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2561 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2562 | |
| 2563 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2564 | if(i==16) |
| 2565 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2566 | else |
| 2567 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | // Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case |
| 2572 | TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) { |
| 2573 | traffic_queues->set_uni_id(0); |
| 2574 | traffic_queues->set_port_no(16); |
| 2575 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2576 | |
| 2577 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2578 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2579 | |
| 2580 | Status status = CreateTrafficQueues_(traffic_queues); |
| 2581 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2582 | } |
| 2583 | |
| 2584 | //////////////////////////////////////////////////////////////////////////// |
| 2585 | // For testing RemoveTrafficQueues functionality |
| 2586 | //////////////////////////////////////////////////////////////////////////// |
| 2587 | |
| 2588 | class TestRemoveTrafficQueues : public Test { |
| 2589 | protected: |
| 2590 | NiceMock<BalMocker> balMock; |
| 2591 | tech_profile::TrafficQueues* traffic_queues; |
| 2592 | tech_profile::TrafficQueue* traffic_queue_1; |
| 2593 | tech_profile::TrafficQueue* traffic_queue_2; |
| 2594 | |
| 2595 | virtual void SetUp() { |
| 2596 | traffic_queues = new tech_profile::TrafficQueues; |
| 2597 | traffic_queues->set_intf_id(0); |
| 2598 | traffic_queues->set_onu_id(1); |
| 2599 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 2600 | traffic_queue_1->set_gemport_id(1024); |
| 2601 | traffic_queue_1->set_priority(0); |
| 2602 | } |
| 2603 | |
| 2604 | virtual void TearDown() { |
| 2605 | } |
| 2606 | }; |
| 2607 | |
| 2608 | // Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 2609 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) { |
| 2610 | Status status; |
| 2611 | traffic_queues->set_uni_id(0); |
| 2612 | traffic_queues->set_port_no(16); |
| 2613 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2614 | |
| 2615 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2616 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2617 | |
| 2618 | status = RemoveTrafficQueues_(traffic_queues); |
| 2619 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2620 | |
| 2621 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2622 | status = RemoveTrafficQueues_(traffic_queues); |
| 2623 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2624 | } |
| 2625 | |
| 2626 | // Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case |
| 2627 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) { |
| 2628 | Status status; |
| 2629 | traffic_queues->set_uni_id(0); |
| 2630 | traffic_queues->set_port_no(16); |
| 2631 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2632 | |
| 2633 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2634 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2635 | |
| 2636 | status = RemoveTrafficQueues_(traffic_queues); |
| 2637 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2638 | } |
| 2639 | |
| 2640 | // Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case |
| 2641 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) { |
| 2642 | //Remove scheduler so that is_tm_sched_id_present api call will return false |
| 2643 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 2644 | tech_profile::TrafficScheduler* traffic_sched; |
| 2645 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 2646 | traffic_scheds->set_intf_id(0); |
| 2647 | traffic_scheds->set_onu_id(1); |
| 2648 | traffic_scheds->set_uni_id(0); |
| 2649 | traffic_scheds->set_port_no(16); |
| 2650 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 2651 | traffic_sched->set_alloc_id(1024); |
| 2652 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2653 | |
| 2654 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2655 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2656 | RemoveTrafficSchedulers_(traffic_scheds); |
| 2657 | |
| 2658 | traffic_queues->set_uni_id(0); |
| 2659 | traffic_queues->set_port_no(16); |
| 2660 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 2661 | |
| 2662 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 2663 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2664 | } |
| 2665 | |
| 2666 | /* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP |
| 2667 | as it is getting referred by some other queues case */ |
| 2668 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) { |
| 2669 | traffic_queues->set_uni_id(3); |
| 2670 | traffic_queues->set_port_no(16); |
| 2671 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2672 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2673 | traffic_queue_2->set_gemport_id(1025); |
| 2674 | traffic_queue_2->set_priority(1); |
| 2675 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 2676 | |
| 2677 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 2678 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2679 | } |
| 2680 | |
| 2681 | /* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it |
| 2682 | is not getting referred by any other queues case */ |
| 2683 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) { |
| 2684 | traffic_queues->set_uni_id(1); |
| 2685 | traffic_queues->set_port_no(32); |
| 2686 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2687 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2688 | traffic_queue_2->set_gemport_id(1025); |
| 2689 | traffic_queue_2->set_priority(1); |
| 2690 | |
| 2691 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 2692 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2693 | |
| 2694 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 2695 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2696 | } |
| 2697 | |
| 2698 | /* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP |
| 2699 | having no reference to any other queues case */ |
| 2700 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) { |
| 2701 | traffic_queues->set_uni_id(4); |
| 2702 | traffic_queues->set_port_no(64); |
| 2703 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 2704 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 2705 | traffic_queue_2->set_gemport_id(1025); |
| 2706 | traffic_queue_2->set_priority(1); |
| 2707 | |
| 2708 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2709 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 2710 | |
| 2711 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 2712 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2713 | } |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2714 | |
| 2715 | //////////////////////////////////////////////////////////////////////////// |
| 2716 | // For testing OnuItuPonAlarmSet functionality |
| 2717 | //////////////////////////////////////////////////////////////////////////// |
| 2718 | |
| 2719 | class TestOnuItuPonAlarmSet : public Test { |
| 2720 | protected: |
| 2721 | bcmolt_pon_ni pon_ni = 0; |
| 2722 | bcmolt_onu_id onu_id = 1; |
| 2723 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2724 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rt; |
| 2725 | config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config; |
| 2726 | config::OnuItuPonAlarm::SoakTime *soak_time_rt; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2727 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2728 | config::OnuItuPonAlarm *onu_itu_pon_alarm_rr; |
| 2729 | config::OnuItuPonAlarm::RateRangeConfig *rate_range_config; |
| 2730 | config::OnuItuPonAlarm::SoakTime *soak_time_rr; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2731 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2732 | config::OnuItuPonAlarm *onu_itu_pon_alarm_tc; |
| 2733 | config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config; |
| 2734 | config::OnuItuPonAlarm::SoakTime *soak_time_tc; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2735 | |
| 2736 | NiceMock<BalMocker> balMock; |
| 2737 | |
| 2738 | virtual void SetUp() { |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2739 | onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm; |
| 2740 | rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig; |
| 2741 | soak_time_rt = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2742 | onu_itu_pon_alarm_rt->set_pon_ni(0); |
| 2743 | onu_itu_pon_alarm_rt->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2744 | onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 2745 | 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] | 2746 | rate_threshold_config->set_rate_threshold_rising(1); |
| 2747 | rate_threshold_config->set_rate_threshold_falling(4); |
| 2748 | soak_time_rt->set_active_soak_time(2); |
| 2749 | soak_time_rt->set_clear_soak_time(2); |
| 2750 | rate_threshold_config->set_allocated_soak_time(soak_time_rt); |
| 2751 | onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config); |
| 2752 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2753 | onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm; |
| 2754 | rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig; |
| 2755 | soak_time_rr = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2756 | onu_itu_pon_alarm_rr->set_pon_ni(0); |
| 2757 | onu_itu_pon_alarm_rr->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2758 | onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 2759 | 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] | 2760 | rate_range_config->set_rate_range_lower(1); |
| 2761 | rate_range_config->set_rate_range_upper(4); |
| 2762 | soak_time_rr->set_active_soak_time(2); |
| 2763 | soak_time_rr->set_clear_soak_time(2); |
| 2764 | rate_range_config->set_allocated_soak_time(soak_time_rr); |
| 2765 | onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config); |
| 2766 | |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2767 | onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm; |
| 2768 | value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig; |
| 2769 | soak_time_tc = new config::OnuItuPonAlarm::SoakTime; |
Jason Huang | 5d9ab1a | 2020-04-15 16:53:49 +0800 | [diff] [blame] | 2770 | onu_itu_pon_alarm_tc->set_pon_ni(0); |
| 2771 | onu_itu_pon_alarm_tc->set_onu_id(1); |
kesavand | c1f2db9 | 2020-08-31 15:32:06 +0530 | [diff] [blame] | 2772 | onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS); |
| 2773 | 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] | 2774 | value_threshold_config->set_threshold_limit(6); |
| 2775 | soak_time_tc->set_active_soak_time(2); |
| 2776 | soak_time_tc->set_clear_soak_time(2); |
| 2777 | value_threshold_config->set_allocated_soak_time(soak_time_tc); |
| 2778 | onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config); |
| 2779 | } |
| 2780 | |
| 2781 | virtual void TearDown() { |
| 2782 | } |
| 2783 | }; |
| 2784 | |
| 2785 | // Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case |
| 2786 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 2787 | // the configured threshold boundary. |
| 2788 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) { |
| 2789 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2790 | bcmolt_onu_key key = {}; |
| 2791 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2792 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 2793 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 2794 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 2795 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2796 | |
| 2797 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2798 | |
| 2799 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 2800 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2801 | } |
| 2802 | |
| 2803 | // Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case |
| 2804 | // rate_threshold: The alarm is triggered if the stats delta value between samples crosses |
| 2805 | // the configured threshold boundary. |
| 2806 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) { |
| 2807 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2808 | bcmolt_onu_key key = {}; |
| 2809 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2810 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD; |
| 2811 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50; |
| 2812 | stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100; |
| 2813 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2814 | |
| 2815 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2816 | |
| 2817 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt); |
| 2818 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2819 | } |
| 2820 | |
| 2821 | // Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case |
| 2822 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 2823 | // from the configured range. |
| 2824 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) { |
| 2825 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2826 | bcmolt_onu_key key = {}; |
| 2827 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2828 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 2829 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100; |
| 2830 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50; |
| 2831 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2832 | |
| 2833 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2834 | |
| 2835 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 2836 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2837 | } |
| 2838 | |
| 2839 | // Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case |
| 2840 | // rate_range: The alarm is triggered if the stats delta value between samples deviates |
| 2841 | // from the configured range. |
| 2842 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) { |
| 2843 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2844 | bcmolt_onu_key key = {}; |
| 2845 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2846 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE; |
| 2847 | stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50; |
| 2848 | stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100; |
| 2849 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2850 | |
| 2851 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2852 | |
| 2853 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr); |
| 2854 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2855 | } |
| 2856 | |
| 2857 | // Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case |
| 2858 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 2859 | // level. The alarm is cleared when the host read the stats. |
| 2860 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) { |
| 2861 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2862 | bcmolt_onu_key key = {}; |
| 2863 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2864 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 2865 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100; |
| 2866 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 2867 | |
| 2868 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2869 | |
| 2870 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 2871 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2872 | } |
| 2873 | |
| 2874 | // Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case |
| 2875 | // value_threshold: The alarm is raised if the stats sample value becomes greater than this |
| 2876 | // level. The alarm is cleared when the host read the stats. |
| 2877 | TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) { |
| 2878 | bcmolt_onu_itu_pon_stats_cfg stat_cfg; |
| 2879 | bcmolt_onu_key key = {}; |
| 2880 | BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key); |
| 2881 | stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD; |
| 2882 | stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1; |
| 2883 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 2884 | |
| 2885 | ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 2886 | |
| 2887 | Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc); |
| 2888 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2889 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 2890 | |
| 2891 | //////////////////////////////////////////////////////////////////////////// |
| 2892 | // For testing DeleteGroup functionality |
| 2893 | //////////////////////////////////////////////////////////////////////////// |
| 2894 | |
| 2895 | class TestDeleteGroup : public Test { |
| 2896 | protected: |
| 2897 | uint32_t group_id = 1; |
| 2898 | NiceMock<BalMocker> balMock; |
| 2899 | |
| 2900 | virtual void SetUp() { |
| 2901 | } |
Burak Gurdag | eb4ca2e | 2020-06-15 07:48:26 +0000 | [diff] [blame] | 2902 | }; |
| 2903 | |
| 2904 | // Test 1 - DeleteGroup success case |
| 2905 | TEST_F(TestDeleteGroup, DeleteGroupSuccess) { |
| 2906 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 2907 | bcmos_errno group_cfg_clear_res = BCM_ERR_OK; |
| 2908 | bcmolt_group_cfg grp_cfg_out; |
| 2909 | bcmolt_group_key grp_key = {}; |
| 2910 | |
| 2911 | grp_key.id = group_id; |
| 2912 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 2913 | |
| 2914 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2915 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 2916 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 2917 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 2918 | return group_cfg_get_res; |
| 2919 | } |
| 2920 | )); |
| 2921 | |
| 2922 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 2923 | |
| 2924 | Status status = DeleteGroup_(group_id); |
| 2925 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 2926 | } |
| 2927 | |
| 2928 | // Test 2 - DeleteGroup failure case: Group does not exist |
| 2929 | TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) { |
| 2930 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 2931 | bcmolt_group_cfg grp_cfg_out; |
| 2932 | bcmolt_group_key grp_key = {}; |
| 2933 | |
| 2934 | grp_key.id = group_id; |
| 2935 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 2936 | |
| 2937 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2938 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 2939 | grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED; |
| 2940 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 2941 | return group_cfg_get_res; |
| 2942 | } |
| 2943 | )); |
| 2944 | |
| 2945 | Status status = DeleteGroup_(group_id); |
| 2946 | ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND ); |
| 2947 | } |
| 2948 | |
| 2949 | // Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.) |
| 2950 | TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) { |
| 2951 | bcmos_errno group_cfg_get_res = BCM_ERR_OK; |
| 2952 | bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL; |
| 2953 | bcmolt_group_cfg grp_cfg_out; |
| 2954 | bcmolt_group_key grp_key = {}; |
| 2955 | |
| 2956 | grp_key.id = group_id; |
| 2957 | BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key); |
| 2958 | |
| 2959 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) { |
| 2960 | bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg; |
| 2961 | grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED; |
| 2962 | memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg)); |
| 2963 | return group_cfg_get_res; |
| 2964 | } |
| 2965 | )); |
| 2966 | |
| 2967 | EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res)); |
| 2968 | |
| 2969 | Status status = DeleteGroup_(group_id); |
| 2970 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 2971 | } |
Jason Huang | 1d9cfce | 2020-05-20 22:58:47 +0800 | [diff] [blame] | 2972 | |
| 2973 | //////////////////////////////////////////////////////////////////////////// |
| 2974 | // For testing OnuLogicalDistanceZero functionality |
| 2975 | //////////////////////////////////////////////////////////////////////////// |
| 2976 | class TestOnuLogicalDistanceZero : public Test { |
| 2977 | protected: |
| 2978 | NiceMock<BalMocker> balMock; |
| 2979 | bcmolt_pon_ni pon_ni = 0; |
| 2980 | openolt::OnuLogicalDistance *onu_logical_distance_zero; |
| 2981 | |
| 2982 | virtual void SetUp() { |
| 2983 | onu_logical_distance_zero = new openolt::OnuLogicalDistance; |
| 2984 | onu_logical_distance_zero->set_intf_id(pon_ni); |
| 2985 | } |
| 2986 | virtual void TearDown() { |
| 2987 | } |
| 2988 | }; |
| 2989 | |
| 2990 | // |
| 2991 | // Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case |
| 2992 | // |
| 2993 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) { |
| 2994 | bcmolt_pon_distance pon_distance = {}; |
| 2995 | bcmolt_pon_interface_cfg pon_cfg; |
| 2996 | bcmolt_pon_interface_key key = {}; |
| 2997 | |
| 2998 | key.pon_ni = pon_ni; |
| 2999 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3000 | state.activate(); |
| 3001 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3002 | |
| 3003 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3004 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3005 | |
| 3006 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3007 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3008 | } |
| 3009 | |
| 3010 | // Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case |
| 3011 | // The PON state is not ready for failure case |
| 3012 | // |
| 3013 | TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) { |
| 3014 | bcmolt_pon_distance pon_distance = {}; |
| 3015 | bcmolt_pon_interface_cfg pon_cfg; |
| 3016 | bcmolt_pon_interface_key key = {}; |
| 3017 | |
| 3018 | key.pon_ni = pon_ni; |
| 3019 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3020 | state.deactivate(); |
| 3021 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL; |
| 3022 | |
| 3023 | Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero); |
| 3024 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3025 | } |
| 3026 | |
| 3027 | class TestOnuLogicalDistance : public Test { |
| 3028 | protected: |
| 3029 | NiceMock<BalMocker> balMock; |
| 3030 | bcmolt_pon_ni pon_ni = 0; |
| 3031 | bcmolt_onu_id onu_id = 1; |
| 3032 | openolt::OnuLogicalDistance *onu_logical_distance; |
| 3033 | |
| 3034 | virtual void SetUp() { |
| 3035 | onu_logical_distance = new openolt::OnuLogicalDistance; |
| 3036 | onu_logical_distance->set_intf_id(pon_ni); |
| 3037 | onu_logical_distance->set_onu_id(onu_id); |
| 3038 | } |
| 3039 | virtual void TearDown() { |
| 3040 | } |
| 3041 | }; |
| 3042 | |
| 3043 | // |
| 3044 | // Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case |
| 3045 | // |
| 3046 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) { |
| 3047 | bcmolt_pon_distance pon_distance = {}; |
| 3048 | bcmolt_pon_interface_cfg pon_cfg; |
| 3049 | bcmolt_pon_interface_key key = {}; |
| 3050 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3051 | |
| 3052 | key.pon_ni = pon_ni; |
| 3053 | state.activate(); |
| 3054 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3055 | |
| 3056 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3057 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3058 | |
| 3059 | bcmolt_onu_cfg onu_cfg; |
| 3060 | bcmolt_onu_key onu_key = {}; |
| 3061 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3062 | |
| 3063 | onu_key.pon_ni = pon_ni; |
| 3064 | onu_key.onu_id = onu_id; |
| 3065 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3066 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 3067 | |
| 3068 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3069 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3070 | |
| 3071 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3072 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 3073 | } |
| 3074 | |
| 3075 | // Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3076 | // The failure case is for retrieving ONU ranging time |
| 3077 | // |
| 3078 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) { |
| 3079 | bcmolt_pon_distance pon_distance = {}; |
| 3080 | bcmolt_pon_interface_cfg pon_cfg; |
| 3081 | bcmolt_pon_interface_key key = {}; |
| 3082 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3083 | |
| 3084 | key.pon_ni = pon_ni; |
| 3085 | state.activate(); |
| 3086 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3087 | |
| 3088 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3089 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3090 | |
| 3091 | bcmolt_onu_cfg onu_cfg; |
| 3092 | bcmolt_onu_key onu_key = {}; |
| 3093 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 3094 | |
| 3095 | onu_key.pon_ni = pon_ni; |
| 3096 | onu_key.onu_id = onu_id; |
| 3097 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3098 | |
| 3099 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3100 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3101 | |
| 3102 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3103 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3104 | } |
| 3105 | |
| 3106 | // Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case |
| 3107 | // The failure case is for ONU is not yet activated |
| 3108 | // |
| 3109 | TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) { |
| 3110 | bcmolt_pon_distance pon_distance = {}; |
| 3111 | bcmolt_pon_interface_cfg pon_cfg; |
| 3112 | bcmolt_pon_interface_key key = {}; |
| 3113 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 3114 | |
| 3115 | key.pon_ni = pon_ni; |
| 3116 | state.activate(); |
| 3117 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key); |
| 3118 | |
| 3119 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 3120 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 3121 | |
| 3122 | bcmolt_onu_cfg onu_cfg; |
| 3123 | bcmolt_onu_key onu_key = {}; |
| 3124 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 3125 | |
| 3126 | onu_key.pon_ni = pon_ni; |
| 3127 | onu_key.onu_id = onu_id; |
| 3128 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 3129 | |
| 3130 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 3131 | .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 3132 | |
| 3133 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE; |
| 3134 | Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance); |
| 3135 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 3136 | } |