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