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