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" |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 20 | #include <future> |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 21 | using namespace testing; |
| 22 | using namespace std; |
| 23 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 24 | extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map; |
| 25 | extern dev_log_id openolt_log_id; |
| 26 | extern bcmos_fastlock alloc_cfg_wait_lock; |
| 27 | extern bool ALLOC_CFG_FLAG; |
| 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 | |
| 60 | // Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function |
| 61 | 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] | 62 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 63 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 64 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 65 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 66 | |
| 67 | |
| 68 | // Test Fixture for OltEnable |
| 69 | |
| 70 | // Test 1: OltEnableSuccess case |
| 71 | TEST_F(TestOltEnable, OltEnableSuccess){ |
| 72 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 73 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 74 | NiceMock<BalMocker> balMock; |
| 75 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 76 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 77 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 78 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 79 | |
| 80 | bcmolt_olt_cfg olt_cfg = { }; |
| 81 | bcmolt_olt_key olt_key = { }; |
| 82 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 83 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 84 | |
| 85 | Status olt_enable_res; |
| 86 | |
| 87 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 88 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 89 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 90 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 91 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 92 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 93 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 94 | |
| 95 | olt_enable_res = Enable_(1, NULL); |
| 96 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 97 | } |
| 98 | |
| 99 | // Test 2: OltEnableFail_host_init_fail |
| 100 | TEST_F(TestOltEnable, OltEnableFail_host_init_fail) { |
| 101 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 102 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 103 | NiceMock<BalMocker> balMock; |
| 104 | bcmos_errno host_init_res = BCM_ERR_INTERNAL; |
| 105 | |
| 106 | Status olt_enable_res; |
| 107 | |
| 108 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 109 | state.deactivate(); |
| 110 | |
| 111 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 112 | |
| 113 | olt_enable_res = Enable_(1, NULL); |
| 114 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 115 | } |
| 116 | |
| 117 | // Test 3: OltEnableSuccess_PON_Device_Connected |
| 118 | TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) { |
| 119 | |
| 120 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 121 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 122 | NiceMock<BalMocker> balMock; |
| 123 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 124 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 125 | bcmos_errno bal_cfg_get_res = BCM_ERR_OK; |
| 126 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 127 | |
| 128 | bcmolt_olt_cfg olt_cfg = { }; |
| 129 | bcmolt_olt_key olt_key = { }; |
| 130 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 131 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 132 | |
| 133 | Status olt_enable_res; |
| 134 | |
| 135 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 136 | state.deactivate(); |
| 137 | |
| 138 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 139 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 140 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 141 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 142 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 143 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 144 | |
| 145 | olt_enable_res = Enable_(1, NULL); |
| 146 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | // Test 4: OltEnableFail_All_PON_Enable_Fail |
| 151 | TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) { |
| 152 | |
| 153 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 154 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 155 | NiceMock<BalMocker> balMock; |
| 156 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 157 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 158 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 159 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 160 | |
| 161 | bcmolt_olt_cfg olt_cfg = { }; |
| 162 | bcmolt_olt_key olt_key = { }; |
| 163 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 164 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 165 | |
| 166 | Status olt_enable_res; |
| 167 | |
| 168 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 169 | state.deactivate(); |
| 170 | |
| 171 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 172 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 173 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 174 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 175 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 176 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 177 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 178 | |
| 179 | olt_enable_res = Enable_(1, NULL); |
| 180 | |
| 181 | ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() ); |
| 182 | } |
| 183 | |
| 184 | // Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed. |
| 185 | TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) { |
| 186 | |
| 187 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 188 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 189 | NiceMock<BalMocker> balMock; |
| 190 | bcmos_errno host_init_res = BCM_ERR_OK; |
| 191 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 192 | bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED; |
| 193 | bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL; |
| 194 | bcmos_errno olt_oper_res_success = BCM_ERR_OK; |
| 195 | |
| 196 | bcmolt_olt_cfg olt_cfg = { }; |
| 197 | bcmolt_olt_key olt_key = { }; |
| 198 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 199 | olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY; |
| 200 | |
| 201 | Status olt_enable_res; |
| 202 | |
| 203 | // Ensure that the state of the OLT is in deactivated to start with.. |
| 204 | state.deactivate(); |
| 205 | |
| 206 | ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res)); |
| 207 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _)) |
| 208 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 209 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 210 | .Times(BCM_MAX_DEVS_PER_LINE_CARD) |
| 211 | .WillRepeatedly(Return(bal_cfg_get_res)); |
| 212 | // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices. |
| 213 | EXPECT_CALL(balMock, bcmolt_oper_submit(_, _)) |
| 214 | .WillOnce(Return(olt_oper_res_fail)) |
| 215 | .WillRepeatedly(Return(olt_oper_res_success)); |
| 216 | olt_enable_res = Enable_(1, NULL); |
| 217 | |
| 218 | ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() ); |
| 219 | } |
| 220 | |
| 221 | //////////////////////////////////////////////////////////////////////// |
| 222 | // For testing Enable/Disable functionality |
| 223 | //////////////////////////////////////////////////////////////////////// |
| 224 | |
| 225 | int num_of_pon_ports = 16; |
| 226 | |
| 227 | // Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function |
| 228 | MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*)); |
| 229 | |
| 230 | class TestOltDisableReenable : public Test { |
| 231 | protected: |
| 232 | virtual void SetUp() { |
| 233 | NiceMock<BalMocker> balMock; |
| 234 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 235 | |
| 236 | bcmolt_olt_cfg olt_cfg = { }; |
| 237 | bcmolt_olt_key olt_key = { }; |
| 238 | |
| 239 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 240 | |
| 241 | olt_cfg.data.topology.topology_maps.len = num_of_pon_ports; |
| 242 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _)) |
| 243 | .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res))); |
| 244 | |
| 245 | ProbeDeviceCapabilities_(); |
| 246 | |
| 247 | } |
| 248 | |
| 249 | virtual void TearDown() { |
| 250 | // Code here will be called immediately after each test |
| 251 | // (right before the destructor). |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | // Test Fixture for OltDisable |
| 257 | |
| 258 | // Test 1: OltDisableSuccess case |
| 259 | TEST_F(TestOltDisableReenable, OltDisableSuccess){ |
| 260 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 261 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 262 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 263 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 264 | |
| 265 | Status olt_disable_res; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 266 | state.deactivate(); |
| 267 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 268 | olt_disable_res = Disable_(); |
| 269 | ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() ); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | // Test 2: OltDisableAllPonFailed case |
| 274 | TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){ |
| 275 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 276 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 277 | NiceMock<BalMocker> balMock; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 278 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 279 | |
| 280 | Status olt_disable_res; |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 281 | state.deactivate(); |
| 282 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 283 | olt_disable_res = Disable_(); |
| 284 | ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | // Test Fixture for OltReenable |
| 289 | |
| 290 | // Test 1: OltReenableSuccess case |
| 291 | TEST_F(TestOltDisableReenable, OltReenableSuccess){ |
| 292 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 293 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 294 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 295 | uint32_t pon_id = 0; |
| 296 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 297 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 298 | Status olt_reenable_res; |
| 299 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 300 | bcmolt_pon_interface_key pon_key; |
| 301 | bcmolt_pon_interface_cfg pon_cfg; |
| 302 | pon_key.pon_ni = pon_id; |
| 303 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 304 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 305 | |
| 306 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 307 | .Times(num_of_pon_ports) |
| 308 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 309 | |
| 310 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 311 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 312 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 313 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 314 | |
| 315 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 316 | .Times(num_of_pon_ports) |
| 317 | .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 318 | |
| 319 | olt_reenable_res = Reenable_(); |
| 320 | ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() ); |
| 321 | |
| 322 | } |
| 323 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 324 | // Test 2: OltReenableAllPonFailed case |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 325 | TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){ |
| 326 | // NiceMock is used to suppress 'WillByDefault' return errors. |
| 327 | // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md |
| 328 | NiceMock<BalMocker> balMock; |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 329 | uint32_t pon_id = 0; |
| 330 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 331 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 332 | Status olt_reenable_res; |
| 333 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 334 | bcmolt_pon_interface_key pon_key; |
| 335 | bcmolt_pon_interface_cfg pon_cfg; |
| 336 | pon_key.pon_ni = pon_id; |
| 337 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 338 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 339 | |
| 340 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 341 | .Times(num_of_pon_ports) |
| 342 | .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 343 | EXPECT_CALL(balMock,bcmolt_oper_submit(_, _)) |
| 344 | .Times(num_of_pon_ports) |
| 345 | .WillRepeatedly(Return(olt_oper_res)); |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 346 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 347 | olt_reenable_res = Reenable_(); |
| 348 | ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL); |
| 349 | } |
| 350 | |
| 351 | //////////////////////////////////////////////////////////////////////////// |
| 352 | // For testing ProbeDeviceCapabilities functionality |
| 353 | //////////////////////////////////////////////////////////////////////////// |
| 354 | class TestProbeDevCapabilities : public Test { |
| 355 | protected: |
| 356 | NiceMock<BalMocker> balMock; |
| 357 | bcmos_errno olt_res_success = BCM_ERR_OK; |
| 358 | bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL; |
| 359 | bcmos_errno dev_res_success = BCM_ERR_OK; |
| 360 | bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL; |
| 361 | |
| 362 | virtual void SetUp() { |
| 363 | bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK; |
| 364 | |
| 365 | bcmolt_olt_cfg olt_cfg = { }; |
| 366 | bcmolt_olt_key olt_key = { }; |
| 367 | |
| 368 | BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key); |
| 369 | |
| 370 | olt_cfg.data.topology.topology_maps.len = num_of_pon_ports; |
| 371 | } |
| 372 | |
| 373 | virtual void TearDown() { |
| 374 | } |
| 375 | }; |
| 376 | |
| 377 | // Test 1 - If querying the OLT fails, the method must return error |
| 378 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) { |
| 379 | |
| 380 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 381 | .WillOnce(Return(olt_res_fail)); |
| 382 | |
| 383 | Status query_status = ProbeDeviceCapabilities_(); |
| 384 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 385 | } |
| 386 | |
| 387 | // Test 2 - If all devices are queried successfully, the method must return Status::OK |
| 388 | TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) { |
| 389 | |
| 390 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 391 | .WillOnce(Return(olt_res_success)); |
| 392 | |
| 393 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 394 | .WillRepeatedly(Return(dev_res_success)); |
| 395 | |
| 396 | Status query_status = ProbeDeviceCapabilities_(); |
| 397 | |
| 398 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 399 | } |
| 400 | |
| 401 | // Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error |
| 402 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) { |
| 403 | |
| 404 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 405 | .WillOnce(Return(olt_res_success)); |
| 406 | |
| 407 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 408 | .WillRepeatedly(Return(dev_res_fail)); |
| 409 | |
| 410 | Status query_status = ProbeDeviceCapabilities_(); |
| 411 | |
| 412 | ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() ); |
| 413 | } |
| 414 | |
| 415 | // Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success |
| 416 | TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) { |
| 417 | |
| 418 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_)) |
| 419 | .WillOnce(Return(olt_res_success)); |
| 420 | |
| 421 | EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)) |
| 422 | .WillOnce(Return(olt_res_success)) |
| 423 | .WillRepeatedly(Return(dev_res_fail)); |
| 424 | |
| 425 | Status query_status = ProbeDeviceCapabilities_(); |
| 426 | |
| 427 | ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() ); |
| 428 | } |
| 429 | |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 430 | //////////////////////////////////////////////////////////////////////////// |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 431 | // For testing EnablePonIf functionality |
| 432 | //////////////////////////////////////////////////////////////////////////// |
| 433 | |
| 434 | class TestEnablePonIf : public Test { |
| 435 | protected: |
| 436 | uint32_t pon_id = 0; |
| 437 | NiceMock<BalMocker> balMock; |
| 438 | |
| 439 | virtual void SetUp() { |
| 440 | } |
| 441 | |
| 442 | virtual void TearDown() { |
| 443 | } |
| 444 | }; |
| 445 | |
| 446 | // Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case |
| 447 | TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) { |
| 448 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 449 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 450 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 451 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 452 | |
| 453 | bcmolt_pon_interface_key pon_key; |
| 454 | bcmolt_pon_interface_cfg pon_cfg; |
| 455 | pon_key.pon_ni = pon_id; |
| 456 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 457 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 458 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 459 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 460 | |
| 461 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 462 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 463 | |
| 464 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 465 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 466 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 467 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 468 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 469 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 470 | |
| 471 | Status status = EnablePonIf_(pon_id); |
| 472 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 473 | } |
| 474 | |
| 475 | // Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case |
| 476 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) { |
| 477 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 478 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 479 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL; |
| 480 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 481 | |
| 482 | bcmolt_pon_interface_key pon_key; |
| 483 | bcmolt_pon_interface_cfg pon_cfg; |
| 484 | pon_key.pon_ni = pon_id; |
| 485 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 486 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 487 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 488 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 489 | |
| 490 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 491 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 492 | |
| 493 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 494 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 495 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 496 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 497 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 498 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 499 | |
| 500 | Status status = EnablePonIf_(pon_id); |
| 501 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 502 | } |
| 503 | |
| 504 | // Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state |
| 505 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) { |
| 506 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 507 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 508 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 509 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 510 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 511 | |
| 512 | bcmolt_pon_interface_key pon_key; |
| 513 | bcmolt_pon_interface_cfg pon_cfg; |
| 514 | pon_key.pon_ni = pon_id; |
| 515 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 516 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 517 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 518 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 519 | |
| 520 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 521 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 522 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 523 | |
| 524 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 525 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 526 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 527 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED; |
| 528 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 529 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 530 | |
| 531 | Status status = EnablePonIf_(pon_id); |
| 532 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 533 | } |
| 534 | |
| 535 | // Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed |
| 536 | TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) { |
| 537 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 538 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 539 | bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL; |
| 540 | bcmos_errno olt_cfg_get_res = BCM_ERR_OK; |
| 541 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 542 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 543 | |
| 544 | bcmolt_pon_interface_key pon_key; |
| 545 | bcmolt_pon_interface_cfg pon_cfg; |
| 546 | pon_key.pon_ni = pon_id; |
| 547 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 548 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 549 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 550 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 551 | |
| 552 | EXPECT_CALL(balMock, bcmolt_cfg_set(_, _)) |
| 553 | .WillOnce(Return(olt_cfg_set_res)) |
| 554 | .WillRepeatedly(Return(olt_cfg_set_err)); |
| 555 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 556 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res)); |
| 557 | |
| 558 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 559 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 560 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 561 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 562 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 563 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 564 | |
| 565 | Status status = EnablePonIf_(pon_id); |
| 566 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 567 | } |
| 568 | |
| 569 | // Test 5 - EnablePonIf already enabled success |
| 570 | TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) { |
| 571 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 572 | |
| 573 | bcmolt_pon_interface_key pon_key; |
| 574 | bcmolt_pon_interface_cfg pon_cfg; |
| 575 | pon_key.pon_ni = pon_id; |
| 576 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 577 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 578 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 579 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 580 | |
| 581 | Status status = EnablePonIf_(pon_id); |
| 582 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 583 | } |
| 584 | |
| 585 | // Test 6 - EnablePonIf - enable onu discovery failure case |
| 586 | TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) { |
| 587 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 588 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 589 | |
| 590 | bcmolt_pon_interface_key pon_key; |
| 591 | bcmolt_pon_interface_cfg pon_cfg; |
| 592 | pon_key.pon_ni = pon_id; |
| 593 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 594 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 595 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 596 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 597 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 598 | |
| 599 | Status status = EnablePonIf_(pon_id); |
| 600 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 601 | } |
| 602 | |
| 603 | // Test 7 - EnablePonIf failure case |
| 604 | TEST_F(TestEnablePonIf, EnablePonIfFailed) { |
| 605 | bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK; |
| 606 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 607 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 608 | |
| 609 | bcmolt_pon_interface_key pon_key; |
| 610 | bcmolt_pon_interface_cfg pon_cfg; |
| 611 | pon_key.pon_ni = pon_id; |
| 612 | BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key); |
| 613 | pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 614 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _)) |
| 615 | .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res))); |
| 616 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 617 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 618 | |
| 619 | Status status = EnablePonIf_(pon_id); |
| 620 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 621 | } |
| 622 | |
| 623 | //////////////////////////////////////////////////////////////////////////// |
| 624 | // For testing SetStateUplinkIf functionality |
| 625 | //////////////////////////////////////////////////////////////////////////// |
| 626 | |
| 627 | class TestSetStateUplinkIf : public Test { |
| 628 | protected: |
| 629 | uint32_t intf_id = 0; |
| 630 | NiceMock<BalMocker> balMock; |
| 631 | |
| 632 | virtual void SetUp() { |
| 633 | } |
| 634 | |
| 635 | virtual void TearDown() { |
| 636 | } |
| 637 | }; |
| 638 | |
| 639 | // Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case |
| 640 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) { |
| 641 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 642 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 643 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 644 | |
| 645 | bcmolt_nni_interface_key nni_key; |
| 646 | bcmolt_nni_interface_cfg nni_cfg; |
| 647 | nni_key.id = intf_id; |
| 648 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 649 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 650 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 651 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 652 | |
| 653 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 654 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 655 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 656 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 657 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 658 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 659 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 660 | |
| 661 | Status status = SetStateUplinkIf_(intf_id, true); |
| 662 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 663 | } |
| 664 | |
| 665 | // Test 2 - SetStateUplinkIf, NNI interface already disabled case |
| 666 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) { |
| 667 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 668 | |
| 669 | bcmolt_nni_interface_key nni_key; |
| 670 | bcmolt_nni_interface_cfg nni_cfg; |
| 671 | nni_key.id = intf_id; |
| 672 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 673 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE; |
| 674 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 675 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 676 | |
| 677 | Status status = SetStateUplinkIf_(intf_id, false); |
| 678 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 679 | } |
| 680 | |
| 681 | // Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case |
| 682 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) { |
| 683 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 684 | bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK; |
| 685 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 686 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 687 | |
| 688 | bcmolt_nni_interface_key nni_key; |
| 689 | bcmolt_nni_interface_cfg nni_cfg; |
| 690 | nni_key.id = intf_id; |
| 691 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 692 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 693 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 694 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 695 | |
| 696 | bcmolt_tm_sched_cfg tm_sched_cfg; |
| 697 | bcmolt_tm_sched_key tm_sched_key = {.id = 1004}; |
| 698 | BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key); |
| 699 | tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED; |
| 700 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _)) |
| 701 | .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res))); |
| 702 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 703 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 704 | |
| 705 | Status status = SetStateUplinkIf_(intf_id, true); |
| 706 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 707 | } |
| 708 | |
| 709 | // Test 4 - SetStateUplinkIf Enable failure case |
| 710 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) { |
| 711 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 712 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 713 | |
| 714 | bcmolt_nni_interface_key nni_key; |
| 715 | bcmolt_nni_interface_cfg nni_cfg; |
| 716 | nni_key.id = intf_id; |
| 717 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 718 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN; |
| 719 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 720 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 721 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 722 | |
| 723 | Status status = SetStateUplinkIf_(intf_id, true); |
| 724 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 725 | } |
| 726 | |
| 727 | // Test 5 - SetStateUplinkIf Disable success case |
| 728 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) { |
| 729 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 730 | bcmos_errno olt_oper_sub_res = BCM_ERR_OK; |
| 731 | |
| 732 | bcmolt_nni_interface_key nni_key; |
| 733 | bcmolt_nni_interface_cfg nni_cfg; |
| 734 | nni_key.id = intf_id; |
| 735 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 736 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 737 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 738 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 739 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 740 | |
| 741 | Status status = SetStateUplinkIf_(intf_id, false); |
| 742 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 743 | } |
| 744 | |
| 745 | // Test 6 - SetStateUplinkIf Disable failure case |
| 746 | TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) { |
| 747 | bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK; |
| 748 | bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL; |
| 749 | |
| 750 | bcmolt_nni_interface_key nni_key; |
| 751 | bcmolt_nni_interface_cfg nni_cfg; |
| 752 | nni_key.id = intf_id; |
| 753 | BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key); |
| 754 | nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING; |
| 755 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _)) |
| 756 | .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res))); |
| 757 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res)); |
| 758 | |
| 759 | Status status = SetStateUplinkIf_(intf_id, false); |
| 760 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 761 | } |
| 762 | |
| 763 | //////////////////////////////////////////////////////////////////////////// |
Chaitrashree G S | 73e084d | 2019-11-20 16:18:59 -0500 | [diff] [blame] | 764 | // For testing DisablePonIf functionality |
| 765 | //////////////////////////////////////////////////////////////////////////// |
| 766 | |
| 767 | class TestDisablePonIf : public Test { |
| 768 | protected: |
| 769 | virtual void SetUp() { |
| 770 | } |
| 771 | |
| 772 | virtual void TearDown() { |
| 773 | } |
| 774 | }; |
| 775 | |
| 776 | // Test 1 - DisablePonIf success case |
| 777 | TEST_F(TestDisablePonIf, DisablePonIfSuccess) { |
| 778 | bcmos_errno olt_oper_res = BCM_ERR_OK; |
| 779 | bcmos_errno bal_cfg_set_res = BCM_ERR_OK; |
| 780 | NiceMock<BalMocker> balMock; |
| 781 | uint32_t pon_id=1; |
| 782 | |
| 783 | //ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res)); |
| 784 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 785 | state.deactivate(); |
| 786 | Status status = DisablePonIf_(pon_id); |
| 787 | |
| 788 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 789 | } |
| 790 | |
| 791 | // Test 2 - DisablePonIf Failure case |
| 792 | TEST_F(TestDisablePonIf, DisablePonIfFailed) { |
| 793 | bcmos_errno olt_oper_res = BCM_ERR_INTERNAL; |
| 794 | NiceMock<BalMocker> balMock; |
| 795 | uint32_t pon_id=1; |
| 796 | |
| 797 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res)); |
| 798 | state.deactivate(); |
| 799 | Status status = DisablePonIf_(pon_id); |
| 800 | |
| 801 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 802 | } |
| 803 | |
| 804 | // Test 3 - DisablePonIf ONU discovery failure case |
| 805 | TEST_F(TestDisablePonIf, DisablePonIfOnuDiscoveryFail) { |
| 806 | NiceMock<BalMocker> balMock; |
| 807 | uint32_t pon_id=1; |
| 808 | bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL; |
| 809 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res)); |
| 810 | state.deactivate(); |
| 811 | Status status = DisablePonIf_(pon_id); |
| 812 | |
| 813 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 814 | } |
| 815 | |
Thiyagarajan Subramani | 6dc2005 | 2019-12-05 09:06:36 -0500 | [diff] [blame] | 816 | //////////////////////////////////////////////////////////////////////////// |
| 817 | // For testing ActivateOnu functionality |
| 818 | //////////////////////////////////////////////////////////////////////////// |
| 819 | |
| 820 | class TestActivateOnu : public Test { |
| 821 | protected: |
| 822 | uint32_t pon_id = 0; |
| 823 | uint32_t onu_id = 1; |
| 824 | std::string vendor_id = "TWSH"; |
| 825 | std::string vendor_specific = "80808080"; |
| 826 | uint32_t pir = 1000000; |
| 827 | NiceMock<BalMocker> balMock; |
| 828 | |
| 829 | virtual void SetUp() { |
| 830 | } |
| 831 | |
| 832 | virtual void TearDown() { |
| 833 | } |
| 834 | }; |
| 835 | |
| 836 | // Test 1 - ActivateOnu success case |
| 837 | TEST_F(TestActivateOnu, ActivateOnuSuccess) { |
| 838 | bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL; |
| 839 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 840 | bcmos_errno onu_cfg_set_res = BCM_ERR_OK; |
| 841 | |
| 842 | bcmolt_onu_cfg onu_cfg; |
| 843 | bcmolt_onu_key onu_key; |
| 844 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 845 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 846 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 847 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 848 | |
| 849 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 850 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
| 851 | |
| 852 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir); |
| 853 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 854 | } |
| 855 | |
| 856 | // Test 2 - ActivateOnu failure case |
| 857 | TEST_F(TestActivateOnu, ActivateOnuFailure) { |
| 858 | bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL; |
| 859 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL; |
| 860 | bcmos_errno onu_cfg_set_res = BCM_ERR_INTERNAL; |
| 861 | |
| 862 | bcmolt_onu_cfg onu_cfg; |
| 863 | bcmolt_onu_key onu_key; |
| 864 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 865 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 866 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 867 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 868 | |
| 869 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 870 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res)); |
| 871 | |
| 872 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir); |
| 873 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 874 | } |
| 875 | |
| 876 | // Test 3 - ActivateOnu - Onu already under processing case |
| 877 | TEST_F(TestActivateOnu, ActivateOnuProcessing) { |
| 878 | bcmos_errno onu_cfg_get_res = BCM_ERR_OK; |
| 879 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 880 | |
| 881 | bcmolt_onu_cfg onu_cfg; |
| 882 | bcmolt_onu_key onu_key; |
| 883 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 884 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 885 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 886 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 887 | ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res)); |
| 888 | |
| 889 | Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir); |
| 890 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 891 | } |
| 892 | |
| 893 | //////////////////////////////////////////////////////////////////////////// |
| 894 | // For testing DeactivateOnu functionality |
| 895 | //////////////////////////////////////////////////////////////////////////// |
| 896 | |
| 897 | class TestDeactivateOnu : public Test { |
| 898 | protected: |
| 899 | uint32_t pon_id = 0; |
| 900 | uint32_t onu_id = 1; |
| 901 | std::string vendor_id = "TWSH"; |
| 902 | std::string vendor_specific = "80808080"; |
| 903 | NiceMock<BalMocker> balMock; |
| 904 | |
| 905 | virtual void SetUp() { |
| 906 | } |
| 907 | |
| 908 | virtual void TearDown() { |
| 909 | } |
| 910 | }; |
| 911 | |
| 912 | // Test 1 - DeactivateOnu success case |
| 913 | TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) { |
| 914 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 915 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 916 | |
| 917 | bcmolt_onu_cfg onu_cfg; |
| 918 | bcmolt_onu_key onu_key; |
| 919 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 920 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 921 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 922 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 923 | |
| 924 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 925 | |
| 926 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 927 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 928 | } |
| 929 | |
| 930 | // Test 2 - DeactivateOnu failure case |
| 931 | TEST_F(TestDeactivateOnu, DeactivateOnuFailure) { |
| 932 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 933 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 934 | |
| 935 | bcmolt_onu_cfg onu_cfg; |
| 936 | bcmolt_onu_key onu_key; |
| 937 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 938 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 939 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 940 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 941 | |
| 942 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 943 | |
| 944 | Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 945 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 946 | } |
| 947 | |
| 948 | //////////////////////////////////////////////////////////////////////////// |
| 949 | // For testing DeleteOnu functionality |
| 950 | //////////////////////////////////////////////////////////////////////////// |
| 951 | |
| 952 | class TestDeleteOnu : public Test { |
| 953 | protected: |
| 954 | uint32_t pon_id = 0; |
| 955 | uint32_t onu_id = 1; |
| 956 | std::string vendor_id = "TWSH"; |
| 957 | std::string vendor_specific = "80808080"; |
| 958 | NiceMock<BalMocker> balMock; |
| 959 | |
| 960 | virtual void SetUp() { |
| 961 | } |
| 962 | |
| 963 | virtual void TearDown() { |
| 964 | } |
| 965 | }; |
| 966 | |
| 967 | // Test 1 - DeleteOnu success case |
| 968 | TEST_F(TestDeleteOnu, DeleteOnuSuccess) { |
| 969 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 970 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 971 | bcmos_errno onu_cfg_clear_res = BCM_ERR_OK; |
| 972 | |
| 973 | bcmolt_onu_cfg onu_cfg; |
| 974 | bcmolt_onu_key onu_key; |
| 975 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 976 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 977 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 978 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 979 | |
| 980 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 981 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 982 | |
| 983 | Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 984 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 985 | } |
| 986 | |
| 987 | // Test 2 - DeleteOnu failure case |
| 988 | TEST_F(TestDeleteOnu, DeleteOnuFailure) { |
| 989 | bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK; |
| 990 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 991 | bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL; |
| 992 | |
| 993 | bcmolt_onu_cfg onu_cfg; |
| 994 | bcmolt_onu_key onu_key; |
| 995 | BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key); |
| 996 | onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE; |
| 997 | EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _)) |
| 998 | .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res))); |
| 999 | |
| 1000 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1001 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res)); |
| 1002 | |
| 1003 | Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str()); |
| 1004 | ASSERT_FALSE( status.error_message() == Status::OK.error_message() ); |
| 1005 | } |
| 1006 | |
| 1007 | //////////////////////////////////////////////////////////////////////////// |
| 1008 | // For testing OmciMsgOut functionality |
| 1009 | //////////////////////////////////////////////////////////////////////////// |
| 1010 | |
| 1011 | class TestOmciMsgOut : public Test { |
| 1012 | protected: |
| 1013 | uint32_t pon_id = 0; |
| 1014 | uint32_t onu_id = 1; |
| 1015 | std::string pkt = "omci-pkt"; |
| 1016 | NiceMock<BalMocker> balMock; |
| 1017 | |
| 1018 | virtual void SetUp() { |
| 1019 | } |
| 1020 | |
| 1021 | virtual void TearDown() { |
| 1022 | } |
| 1023 | }; |
| 1024 | |
| 1025 | // Test 1 - OmciMsgOut success case |
| 1026 | TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) { |
| 1027 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1028 | |
| 1029 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1030 | |
| 1031 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1032 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1033 | } |
| 1034 | |
| 1035 | // Test 1 - OmciMsgOut failure case |
| 1036 | TEST_F(TestOmciMsgOut, OmciMsgOutFailure) { |
| 1037 | bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL; |
| 1038 | |
| 1039 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1040 | |
| 1041 | Status status = OmciMsgOut_(pon_id, onu_id, pkt); |
| 1042 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1043 | } |
| 1044 | |
| 1045 | //////////////////////////////////////////////////////////////////////////// |
| 1046 | // For testing OnuPacketOut functionality |
| 1047 | //////////////////////////////////////////////////////////////////////////// |
| 1048 | |
| 1049 | class TestOnuPacketOut : public Test { |
| 1050 | protected: |
| 1051 | uint32_t pon_id = 0; |
| 1052 | uint32_t onu_id = 1; |
| 1053 | std::string pkt = "omci-pkt"; |
| 1054 | NiceMock<BalMocker> balMock; |
| 1055 | |
| 1056 | virtual void SetUp() { |
| 1057 | } |
| 1058 | |
| 1059 | virtual void TearDown() { |
| 1060 | } |
| 1061 | }; |
| 1062 | |
| 1063 | // Test 1 - OnuPacketOut success case |
| 1064 | TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) { |
| 1065 | uint32_t port_no = 16; |
| 1066 | uint32_t gemport_id = 1024; |
| 1067 | bcmos_errno onu_oper_sub_res = BCM_ERR_OK; |
| 1068 | |
| 1069 | ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res)); |
| 1070 | |
| 1071 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1072 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1073 | } |
| 1074 | |
| 1075 | // Test 2 - OnuPacketOut Port number as 0 case |
| 1076 | TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) { |
| 1077 | uint32_t port_no = 0; |
| 1078 | uint32_t gemport_id = 1024; |
| 1079 | |
| 1080 | Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt); |
| 1081 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1082 | } |
| 1083 | |
| 1084 | //////////////////////////////////////////////////////////////////////////// |
| 1085 | // For testing CreateTrafficSchedulers functionality |
| 1086 | //////////////////////////////////////////////////////////////////////////// |
| 1087 | |
| 1088 | class TestCreateTrafficSchedulers : public Test { |
| 1089 | protected: |
| 1090 | NiceMock<BalMocker> balMock; |
| 1091 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 1092 | tech_profile::TrafficScheduler* traffic_sched; |
| 1093 | tech_profile::SchedulerConfig* scheduler; |
| 1094 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 1095 | |
| 1096 | virtual void SetUp() { |
| 1097 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 1098 | traffic_scheds->set_intf_id(0); |
| 1099 | traffic_scheds->set_onu_id(1); |
| 1100 | traffic_scheds->set_uni_id(0); |
| 1101 | traffic_scheds->set_port_no(16); |
| 1102 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 1103 | traffic_sched->set_alloc_id(1024); |
| 1104 | scheduler = new tech_profile::SchedulerConfig; |
| 1105 | scheduler->set_priority(0); |
| 1106 | scheduler->set_weight(0); |
| 1107 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1108 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 1109 | traffic_shaping_info->set_cbs(60536); |
| 1110 | traffic_shaping_info->set_pbs(65536); |
| 1111 | traffic_shaping_info->set_gir(10000); |
| 1112 | } |
| 1113 | |
| 1114 | virtual void TearDown() { |
| 1115 | } |
| 1116 | |
| 1117 | public: |
| 1118 | static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 1119 | if(ALLOC_CFG_FLAG) { |
| 1120 | alloc_cfg_compltd_key k(0, 1024); |
| 1121 | alloc_cfg_complete_result res; |
| 1122 | res.pon_intf_id = 0; |
| 1123 | res.alloc_id = 1024; |
| 1124 | res.state = state; |
| 1125 | res.status = status; |
| 1126 | |
| 1127 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 1128 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 1129 | if (it == alloc_cfg_compltd_map.end()) { |
| 1130 | OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0); |
| 1131 | } else { |
| 1132 | it->second->push(res); |
| 1133 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
| 1134 | } |
| 1135 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 1136 | } else { |
| 1137 | PushAllocCfgResult(state, status); |
| 1138 | } |
| 1139 | } |
| 1140 | }; |
| 1141 | |
| 1142 | // Test 1 - CreateTrafficSchedulers-Upstream success case |
| 1143 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) { |
| 1144 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1145 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1146 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1147 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1148 | traffic_shaping_info->set_cir(64000); |
| 1149 | traffic_shaping_info->set_pir(128000); |
| 1150 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1151 | |
| 1152 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1153 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1154 | |
| 1155 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
| 1156 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 1157 | |
| 1158 | Status status = future_res.get(); |
| 1159 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1160 | } |
| 1161 | |
| 1162 | // Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication) |
| 1163 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) { |
| 1164 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1165 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1166 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1167 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1168 | traffic_shaping_info->set_cir(64000); |
| 1169 | traffic_shaping_info->set_pir(128000); |
| 1170 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1171 | |
| 1172 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1173 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1174 | |
| 1175 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1176 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1177 | } |
| 1178 | |
| 1179 | // Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request) |
| 1180 | TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) { |
| 1181 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1182 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1183 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1184 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1185 | traffic_shaping_info->set_cir(64000); |
| 1186 | traffic_shaping_info->set_pir(128000); |
| 1187 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1188 | |
| 1189 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1190 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1191 | |
| 1192 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
| 1193 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL); |
| 1194 | |
| 1195 | Status status = future_res.get(); |
| 1196 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1197 | } |
| 1198 | |
| 1199 | // Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state) |
| 1200 | TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) { |
| 1201 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1202 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1203 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1204 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1205 | traffic_shaping_info->set_cir(64000); |
| 1206 | traffic_shaping_info->set_pir(128000); |
| 1207 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1208 | |
| 1209 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1210 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1211 | |
| 1212 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
| 1213 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 1214 | |
| 1215 | Status status = future_res.get(); |
| 1216 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1217 | } |
| 1218 | |
| 1219 | // Test 5 - CreateTrafficSchedulers-Upstream Failure case |
| 1220 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) { |
| 1221 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1222 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1223 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1224 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1225 | traffic_shaping_info->set_cir(64000); |
| 1226 | traffic_shaping_info->set_pir(128000); |
| 1227 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1228 | |
| 1229 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1230 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1231 | |
| 1232 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1233 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1234 | } |
| 1235 | |
| 1236 | // Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case |
| 1237 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) { |
| 1238 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1239 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1240 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1241 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1242 | traffic_shaping_info->set_cir(64000); |
| 1243 | traffic_shaping_info->set_pir(0); |
| 1244 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1245 | |
| 1246 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1247 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1248 | } |
| 1249 | |
| 1250 | // Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case |
| 1251 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) { |
| 1252 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1253 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1254 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1255 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1256 | traffic_shaping_info->set_cir(64000); |
| 1257 | traffic_shaping_info->set_pir(32000); |
| 1258 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1259 | |
| 1260 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1261 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1262 | } |
| 1263 | |
| 1264 | // Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case |
| 1265 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) { |
| 1266 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1267 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1268 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1269 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1270 | traffic_shaping_info->set_cir(64000); |
| 1271 | traffic_shaping_info->set_pir(64000); |
| 1272 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1273 | |
| 1274 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1275 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1276 | } |
| 1277 | |
| 1278 | // Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case |
| 1279 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) { |
| 1280 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1281 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 1282 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1283 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1284 | traffic_shaping_info->set_cir(64000); |
| 1285 | traffic_shaping_info->set_pir(0); |
| 1286 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1287 | |
| 1288 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1289 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1290 | } |
| 1291 | |
| 1292 | // Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case |
| 1293 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) { |
| 1294 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1295 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 1296 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1297 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1298 | traffic_shaping_info->set_cir(0); |
| 1299 | traffic_shaping_info->set_pir(32000); |
| 1300 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1301 | |
| 1302 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1303 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1304 | } |
| 1305 | |
| 1306 | // Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case |
| 1307 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) { |
| 1308 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1309 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 1310 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1311 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1312 | traffic_shaping_info->set_cir(64000); |
| 1313 | traffic_shaping_info->set_pir(32000); |
| 1314 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1315 | |
| 1316 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1317 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1318 | } |
| 1319 | |
| 1320 | // Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case |
| 1321 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) { |
| 1322 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1323 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA); |
| 1324 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1325 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1326 | traffic_shaping_info->set_cir(64000); |
| 1327 | traffic_shaping_info->set_pir(64000); |
| 1328 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1329 | |
| 1330 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1331 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1332 | } |
| 1333 | |
| 1334 | // Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case |
| 1335 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) { |
| 1336 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1337 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 1338 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1339 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1340 | traffic_shaping_info->set_cir(64000); |
| 1341 | traffic_shaping_info->set_pir(0); |
| 1342 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1343 | |
| 1344 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1345 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1346 | } |
| 1347 | |
| 1348 | // Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case |
| 1349 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) { |
| 1350 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1351 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 1352 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1353 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1354 | traffic_shaping_info->set_cir(0); |
| 1355 | traffic_shaping_info->set_pir(32000); |
| 1356 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1357 | |
| 1358 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1359 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1360 | } |
| 1361 | |
| 1362 | // Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case |
| 1363 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) { |
| 1364 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1365 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 1366 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1367 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1368 | traffic_shaping_info->set_cir(64000); |
| 1369 | traffic_shaping_info->set_pir(128000); |
| 1370 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1371 | |
| 1372 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1373 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1374 | |
| 1375 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
| 1376 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 1377 | |
| 1378 | Status status = future_res.get(); |
| 1379 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1380 | } |
| 1381 | |
| 1382 | // Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case |
| 1383 | TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) { |
| 1384 | scheduler->set_direction(tech_profile::Direction::UPSTREAM); |
| 1385 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None); |
| 1386 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1387 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1388 | traffic_shaping_info->set_cir(64000); |
| 1389 | traffic_shaping_info->set_pir(32000); |
| 1390 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1391 | |
| 1392 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1393 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1394 | |
| 1395 | future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds); |
| 1396 | async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 1397 | |
| 1398 | Status status = future_res.get(); |
| 1399 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1400 | } |
| 1401 | |
| 1402 | // Test 17 - CreateTrafficSchedulers-Downstream success case |
| 1403 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) { |
| 1404 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1405 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1406 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1407 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1408 | traffic_shaping_info->set_cir(64000); |
| 1409 | traffic_shaping_info->set_pir(128000); |
| 1410 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1411 | |
| 1412 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1413 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1414 | |
| 1415 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1416 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1417 | } |
| 1418 | |
| 1419 | // Test 18 - CreateTrafficSchedulers-Downstream Failure case |
| 1420 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) { |
| 1421 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1422 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1423 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1424 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1425 | traffic_shaping_info->set_cir(64000); |
| 1426 | traffic_shaping_info->set_pir(128000); |
| 1427 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1428 | |
| 1429 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1430 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1431 | |
| 1432 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1433 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1434 | } |
| 1435 | |
| 1436 | // Test 19 - CreateTrafficSchedulers-Invalid direction Failure case |
| 1437 | TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) { |
| 1438 | scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 1439 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1440 | traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL); |
| 1441 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1442 | traffic_shaping_info->set_cir(64000); |
| 1443 | traffic_shaping_info->set_pir(128000); |
| 1444 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1445 | |
| 1446 | Status status = CreateTrafficSchedulers_(traffic_scheds); |
| 1447 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1448 | } |
| 1449 | |
| 1450 | //////////////////////////////////////////////////////////////////////////// |
| 1451 | // For testing RemoveTrafficSchedulers functionality |
| 1452 | //////////////////////////////////////////////////////////////////////////// |
| 1453 | |
| 1454 | class TestRemoveTrafficSchedulers : public Test { |
| 1455 | protected: |
| 1456 | NiceMock<BalMocker> balMock; |
| 1457 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 1458 | tech_profile::TrafficScheduler* traffic_sched; |
| 1459 | tech_profile::SchedulerConfig* scheduler; |
| 1460 | tech_profile::TrafficShapingInfo* traffic_shaping_info; |
| 1461 | alloc_cfg_complete_result res; |
| 1462 | |
| 1463 | virtual void SetUp() { |
| 1464 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 1465 | traffic_scheds->set_intf_id(0); |
| 1466 | traffic_scheds->set_onu_id(1); |
| 1467 | traffic_scheds->set_uni_id(0); |
| 1468 | traffic_scheds->set_port_no(16); |
| 1469 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 1470 | traffic_sched->set_alloc_id(1025); |
| 1471 | scheduler = new tech_profile::SchedulerConfig; |
| 1472 | scheduler->set_priority(0); |
| 1473 | scheduler->set_weight(0); |
| 1474 | scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1475 | scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort); |
| 1476 | traffic_shaping_info = new tech_profile::TrafficShapingInfo; |
| 1477 | traffic_shaping_info->set_cir(64000); |
| 1478 | traffic_shaping_info->set_pir(128000); |
| 1479 | traffic_shaping_info->set_cbs(60536); |
| 1480 | traffic_shaping_info->set_pbs(65536); |
| 1481 | traffic_shaping_info->set_gir(10000); |
| 1482 | traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info); |
| 1483 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1484 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1485 | } |
| 1486 | |
| 1487 | virtual void TearDown() { |
| 1488 | } |
| 1489 | |
| 1490 | public: |
| 1491 | static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) { |
| 1492 | if(ALLOC_CFG_FLAG) { |
| 1493 | alloc_cfg_compltd_key k(0, 1025); |
| 1494 | alloc_cfg_complete_result res; |
| 1495 | res.pon_intf_id = 0; |
| 1496 | res.alloc_id = 1025; |
| 1497 | res.state = state; |
| 1498 | res.status = status; |
| 1499 | |
| 1500 | bcmos_fastlock_lock(&alloc_cfg_wait_lock); |
| 1501 | std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k); |
| 1502 | if (it == alloc_cfg_compltd_map.end()) { |
| 1503 | OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0); |
| 1504 | } else { |
| 1505 | it->second->push(res); |
| 1506 | OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n"); |
| 1507 | } |
| 1508 | bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0); |
| 1509 | } else { |
| 1510 | PushAllocCfgResult(state, status); |
| 1511 | } |
| 1512 | } |
| 1513 | }; |
| 1514 | |
| 1515 | // Test 1 - RemoveTrafficSchedulers-Upstream success case |
| 1516 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) { |
| 1517 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1518 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1519 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1520 | |
| 1521 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 1522 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS); |
| 1523 | |
| 1524 | Status status = future_res.get(); |
| 1525 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1526 | } |
| 1527 | |
| 1528 | // Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset) |
| 1529 | TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) { |
| 1530 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1531 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1532 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1533 | |
| 1534 | future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds); |
| 1535 | async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS); |
| 1536 | |
| 1537 | Status status = future_res.get(); |
| 1538 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1539 | } |
| 1540 | |
| 1541 | // Test 3 - RemoveTrafficSchedulers-Upstream Failure case |
| 1542 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) { |
| 1543 | traffic_sched->set_direction(tech_profile::Direction::UPSTREAM); |
| 1544 | |
| 1545 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1546 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1547 | |
| 1548 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 1549 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1550 | } |
| 1551 | |
| 1552 | // Test 4 - RemoveTrafficSchedulers-Downstream Failure case |
| 1553 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) { |
| 1554 | //Create Scheduler |
| 1555 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1556 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1557 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1558 | CreateTrafficSchedulers_(traffic_scheds); |
| 1559 | |
| 1560 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1561 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1562 | |
| 1563 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 1564 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1565 | } |
| 1566 | |
| 1567 | // Test 5 - RemoveTrafficSchedulers-Downstream success case |
| 1568 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) { |
| 1569 | //Create Scheduler |
| 1570 | scheduler->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1571 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1572 | traffic_sched->set_allocated_scheduler(scheduler); |
| 1573 | CreateTrafficSchedulers_(traffic_scheds); |
| 1574 | |
| 1575 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1576 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1577 | |
| 1578 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 1579 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1580 | } |
| 1581 | |
| 1582 | // Test 6 - RemoveTrafficSchedulers-Downstream Scheduler not present case |
| 1583 | TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) { |
| 1584 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1585 | |
| 1586 | Status status = RemoveTrafficSchedulers_(traffic_scheds); |
| 1587 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1588 | } |
| 1589 | |
| 1590 | //////////////////////////////////////////////////////////////////////////// |
| 1591 | // For testing CreateTrafficQueues functionality |
| 1592 | //////////////////////////////////////////////////////////////////////////// |
| 1593 | |
| 1594 | class TestCreateTrafficQueues : public Test { |
| 1595 | protected: |
| 1596 | NiceMock<BalMocker> balMock; |
| 1597 | tech_profile::TrafficQueues* traffic_queues; |
| 1598 | tech_profile::TrafficQueue* traffic_queue_1; |
| 1599 | tech_profile::TrafficQueue* traffic_queue_2; |
| 1600 | tech_profile::DiscardConfig* discard_config_1; |
| 1601 | tech_profile::DiscardConfig* discard_config_2; |
| 1602 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1; |
| 1603 | tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2; |
| 1604 | |
| 1605 | virtual void SetUp() { |
| 1606 | traffic_queues = new tech_profile::TrafficQueues; |
| 1607 | traffic_queues->set_intf_id(0); |
| 1608 | traffic_queues->set_onu_id(1); |
| 1609 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 1610 | traffic_queue_1->set_gemport_id(1024); |
| 1611 | traffic_queue_1->set_pbit_map("0b00000101"); |
| 1612 | traffic_queue_1->set_aes_encryption(true); |
| 1613 | traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1614 | traffic_queue_1->set_priority(0); |
| 1615 | traffic_queue_1->set_weight(0); |
| 1616 | traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1617 | discard_config_1 = new tech_profile::DiscardConfig; |
| 1618 | discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1619 | tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig; |
| 1620 | tail_drop_discard_config_1->set_queue_size(8); |
| 1621 | discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1); |
| 1622 | traffic_queue_1->set_allocated_discard_config(discard_config_1); |
| 1623 | } |
| 1624 | |
| 1625 | virtual void TearDown() { |
| 1626 | } |
| 1627 | }; |
| 1628 | |
| 1629 | // Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 1630 | TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) { |
| 1631 | Status status; |
| 1632 | traffic_queues->set_uni_id(0); |
| 1633 | traffic_queues->set_port_no(16); |
| 1634 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1635 | |
| 1636 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1637 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1638 | |
| 1639 | status = CreateTrafficQueues_(traffic_queues); |
| 1640 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1641 | |
| 1642 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1643 | status = CreateTrafficQueues_(traffic_queues); |
| 1644 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1645 | } |
| 1646 | |
| 1647 | // Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case |
| 1648 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) { |
| 1649 | traffic_queues->set_uni_id(1); |
| 1650 | traffic_queues->set_port_no(32); |
| 1651 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1652 | |
| 1653 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1654 | traffic_queue_2->set_gemport_id(1025); |
| 1655 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 1656 | traffic_queue_2->set_aes_encryption(true); |
| 1657 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1658 | traffic_queue_2->set_priority(1); |
| 1659 | traffic_queue_2->set_weight(0); |
| 1660 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1661 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1662 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1663 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1664 | tail_drop_discard_config_2->set_queue_size(8); |
| 1665 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1666 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1667 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1668 | |
| 1669 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1670 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1671 | |
| 1672 | Status status = CreateTrafficQueues_(traffic_queues); |
| 1673 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1674 | } |
| 1675 | |
| 1676 | // Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case |
| 1677 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) { |
| 1678 | traffic_queues->set_uni_id(2); |
| 1679 | traffic_queues->set_port_no(16); |
| 1680 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1681 | |
| 1682 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1683 | traffic_queue_2->set_gemport_id(1025); |
| 1684 | traffic_queue_2->set_pbit_map("0b10001010"); |
| 1685 | traffic_queue_2->set_aes_encryption(true); |
| 1686 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1687 | traffic_queue_2->set_priority(1); |
| 1688 | traffic_queue_2->set_weight(0); |
| 1689 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1690 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1691 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1692 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1693 | tail_drop_discard_config_2->set_queue_size(8); |
| 1694 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1695 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1696 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1697 | |
| 1698 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1699 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1700 | |
| 1701 | Status status = CreateTrafficQueues_(traffic_queues); |
| 1702 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1703 | } |
| 1704 | |
| 1705 | // Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case |
| 1706 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) { |
| 1707 | traffic_queues->set_uni_id(3); |
| 1708 | traffic_queues->set_port_no(16); |
| 1709 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1710 | |
| 1711 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1712 | traffic_queue_2->set_gemport_id(1025); |
| 1713 | traffic_queue_2->set_pbit_map("0b00001010"); |
| 1714 | traffic_queue_2->set_aes_encryption(true); |
| 1715 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1716 | traffic_queue_2->set_priority(1); |
| 1717 | traffic_queue_2->set_weight(0); |
| 1718 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1719 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1720 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1721 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1722 | tail_drop_discard_config_2->set_queue_size(8); |
| 1723 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1724 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1725 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1726 | |
| 1727 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1728 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1729 | |
| 1730 | Status status = CreateTrafficQueues_(traffic_queues); |
| 1731 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1732 | } |
| 1733 | |
| 1734 | // Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case |
| 1735 | TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) { |
| 1736 | int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; |
| 1737 | int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272}; |
| 1738 | std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"}; |
| 1739 | |
| 1740 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1741 | for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) { |
| 1742 | traffic_queues->set_uni_id(uni_ids[i]); |
| 1743 | traffic_queues->set_port_no(port_nos[i]); |
| 1744 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1745 | |
| 1746 | traffic_queue_2->set_gemport_id(1025); |
| 1747 | traffic_queue_2->set_pbit_map(pbit_maps[i]); |
| 1748 | traffic_queue_2->set_aes_encryption(true); |
| 1749 | traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority); |
| 1750 | traffic_queue_2->set_priority(1); |
| 1751 | traffic_queue_2->set_weight(0); |
| 1752 | traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1753 | discard_config_2 = new tech_profile::DiscardConfig; |
| 1754 | discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop); |
| 1755 | tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig; |
| 1756 | tail_drop_discard_config_2->set_queue_size(8); |
| 1757 | discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2); |
| 1758 | traffic_queue_2->set_allocated_discard_config(discard_config_2); |
| 1759 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1760 | |
| 1761 | bcmos_errno olt_cfg_set_res = BCM_ERR_OK; |
| 1762 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1763 | |
| 1764 | Status status = CreateTrafficQueues_(traffic_queues); |
| 1765 | if(i==16) |
| 1766 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1767 | else |
| 1768 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | // Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case |
| 1773 | TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) { |
| 1774 | traffic_queues->set_uni_id(0); |
| 1775 | traffic_queues->set_port_no(16); |
| 1776 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1777 | |
| 1778 | bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL; |
| 1779 | ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res)); |
| 1780 | |
| 1781 | Status status = CreateTrafficQueues_(traffic_queues); |
| 1782 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1783 | } |
| 1784 | |
| 1785 | //////////////////////////////////////////////////////////////////////////// |
| 1786 | // For testing RemoveTrafficQueues functionality |
| 1787 | //////////////////////////////////////////////////////////////////////////// |
| 1788 | |
| 1789 | class TestRemoveTrafficQueues : public Test { |
| 1790 | protected: |
| 1791 | NiceMock<BalMocker> balMock; |
| 1792 | tech_profile::TrafficQueues* traffic_queues; |
| 1793 | tech_profile::TrafficQueue* traffic_queue_1; |
| 1794 | tech_profile::TrafficQueue* traffic_queue_2; |
| 1795 | |
| 1796 | virtual void SetUp() { |
| 1797 | traffic_queues = new tech_profile::TrafficQueues; |
| 1798 | traffic_queues->set_intf_id(0); |
| 1799 | traffic_queues->set_onu_id(1); |
| 1800 | traffic_queue_1 = traffic_queues->add_traffic_queues(); |
| 1801 | traffic_queue_1->set_gemport_id(1024); |
| 1802 | traffic_queue_1->set_priority(0); |
| 1803 | } |
| 1804 | |
| 1805 | virtual void TearDown() { |
| 1806 | } |
| 1807 | }; |
| 1808 | |
| 1809 | // Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case |
| 1810 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) { |
| 1811 | Status status; |
| 1812 | traffic_queues->set_uni_id(0); |
| 1813 | traffic_queues->set_port_no(16); |
| 1814 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1815 | |
| 1816 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1817 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1818 | |
| 1819 | status = RemoveTrafficQueues_(traffic_queues); |
| 1820 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1821 | |
| 1822 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1823 | status = RemoveTrafficQueues_(traffic_queues); |
| 1824 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1825 | } |
| 1826 | |
| 1827 | // Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case |
| 1828 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) { |
| 1829 | Status status; |
| 1830 | traffic_queues->set_uni_id(0); |
| 1831 | traffic_queues->set_port_no(16); |
| 1832 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1833 | |
| 1834 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1835 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1836 | |
| 1837 | status = RemoveTrafficQueues_(traffic_queues); |
| 1838 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1839 | } |
| 1840 | |
| 1841 | // Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case |
| 1842 | TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) { |
| 1843 | //Remove scheduler so that is_tm_sched_id_present api call will return false |
| 1844 | tech_profile::TrafficSchedulers* traffic_scheds; |
| 1845 | tech_profile::TrafficScheduler* traffic_sched; |
| 1846 | traffic_scheds = new tech_profile::TrafficSchedulers; |
| 1847 | traffic_scheds->set_intf_id(0); |
| 1848 | traffic_scheds->set_onu_id(1); |
| 1849 | traffic_scheds->set_uni_id(0); |
| 1850 | traffic_scheds->set_port_no(16); |
| 1851 | traffic_sched = traffic_scheds->add_traffic_scheds(); |
| 1852 | traffic_sched->set_alloc_id(1024); |
| 1853 | traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1854 | |
| 1855 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1856 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1857 | RemoveTrafficSchedulers_(traffic_scheds); |
| 1858 | |
| 1859 | traffic_queues->set_uni_id(0); |
| 1860 | traffic_queues->set_port_no(16); |
| 1861 | traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM); |
| 1862 | |
| 1863 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 1864 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1865 | } |
| 1866 | |
| 1867 | /* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP |
| 1868 | as it is getting referred by some other queues case */ |
| 1869 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) { |
| 1870 | traffic_queues->set_uni_id(3); |
| 1871 | traffic_queues->set_port_no(16); |
| 1872 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1873 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1874 | traffic_queue_2->set_gemport_id(1025); |
| 1875 | traffic_queue_2->set_priority(1); |
| 1876 | traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM); |
| 1877 | |
| 1878 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 1879 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1880 | } |
| 1881 | |
| 1882 | /* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it |
| 1883 | is not getting referred by any other queues case */ |
| 1884 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) { |
| 1885 | traffic_queues->set_uni_id(1); |
| 1886 | traffic_queues->set_port_no(32); |
| 1887 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1888 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1889 | traffic_queue_2->set_gemport_id(1025); |
| 1890 | traffic_queue_2->set_priority(1); |
| 1891 | |
| 1892 | bcmos_errno olt_cfg_clear_res = BCM_ERR_OK; |
| 1893 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1894 | |
| 1895 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 1896 | ASSERT_TRUE( status.error_message() == Status::OK.error_message() ); |
| 1897 | } |
| 1898 | |
| 1899 | /* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP |
| 1900 | having no reference to any other queues case */ |
| 1901 | TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) { |
| 1902 | traffic_queues->set_uni_id(4); |
| 1903 | traffic_queues->set_port_no(64); |
| 1904 | traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM); |
| 1905 | traffic_queue_2 = traffic_queues->add_traffic_queues(); |
| 1906 | traffic_queue_2->set_gemport_id(1025); |
| 1907 | traffic_queue_2->set_priority(1); |
| 1908 | |
| 1909 | bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL; |
| 1910 | ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res)); |
| 1911 | |
| 1912 | Status status = RemoveTrafficQueues_(traffic_queues); |
| 1913 | ASSERT_TRUE( status.error_message() != Status::OK.error_message() ); |
| 1914 | } |