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