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