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