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