blob: 1d3c2eff3d55e8e2c2727634bea7c2e3c546d6da [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"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050020#include <future>
Amit Ghoshfcad4d32019-11-13 10:24:55 +000021using namespace testing;
22using namespace std;
23
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050024extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
25extern dev_log_id openolt_log_id;
26extern bcmos_fastlock alloc_cfg_wait_lock;
27extern bool ALLOC_CFG_FLAG;
28
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
72
73// Test Fixture for OltEnable
74
75// Test 1: OltEnableSuccess case
76TEST_F(TestOltEnable, OltEnableSuccess){
77 // NiceMock is used to suppress 'WillByDefault' return errors.
78 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
79 NiceMock<BalMocker> balMock;
80 bcmos_errno host_init_res = BCM_ERR_OK;
81 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
82 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
83 bcmos_errno olt_oper_res = BCM_ERR_OK;
84
85 bcmolt_olt_cfg olt_cfg = { };
86 bcmolt_olt_key olt_key = { };
87 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
88 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
89
90 Status olt_enable_res;
91
92 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
93 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
94 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
95 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
96 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
97 .WillRepeatedly(Return(bal_cfg_get_res));
98 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
99
100 olt_enable_res = Enable_(1, NULL);
101 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
102}
103
104// Test 2: OltEnableFail_host_init_fail
105TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
106 // NiceMock is used to suppress 'WillByDefault' return errors.
107 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
108 NiceMock<BalMocker> balMock;
109 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
110
111 Status olt_enable_res;
112
113 // Ensure that the state of the OLT is in deactivated to start with..
114 state.deactivate();
115
116 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
117
118 olt_enable_res = Enable_(1, NULL);
119 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
120}
121
122// Test 3: OltEnableSuccess_PON_Device_Connected
123TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
124
125 // NiceMock is used to suppress 'WillByDefault' return errors.
126 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
127 NiceMock<BalMocker> balMock;
128 bcmos_errno host_init_res = BCM_ERR_OK;
129 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
130 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
131 bcmos_errno olt_oper_res = BCM_ERR_OK;
132
133 bcmolt_olt_cfg olt_cfg = { };
134 bcmolt_olt_key olt_key = { };
135 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
136 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
137
138 Status olt_enable_res;
139
140 // Ensure that the state of the OLT is in deactivated to start with..
141 state.deactivate();
142
143 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
144 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
145 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
146 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
147 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
148 .WillRepeatedly(Return(bal_cfg_get_res));
149
150 olt_enable_res = Enable_(1, NULL);
151 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
152
153}
154
155// Test 4: OltEnableFail_All_PON_Enable_Fail
156TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
157
158 // NiceMock is used to suppress 'WillByDefault' return errors.
159 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
160 NiceMock<BalMocker> balMock;
161 bcmos_errno host_init_res = BCM_ERR_OK;
162 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
163 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
164 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
165
166 bcmolt_olt_cfg olt_cfg = { };
167 bcmolt_olt_key olt_key = { };
168 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
169 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
170
171 Status olt_enable_res;
172
173 // Ensure that the state of the OLT is in deactivated to start with..
174 state.deactivate();
175
176 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
177 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
178 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
179 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
180 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
181 .WillRepeatedly(Return(bal_cfg_get_res));
182 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
183
184 olt_enable_res = Enable_(1, NULL);
185
186 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
187}
188
189// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
190TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
191
192 // NiceMock is used to suppress 'WillByDefault' return errors.
193 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
194 NiceMock<BalMocker> balMock;
195 bcmos_errno host_init_res = BCM_ERR_OK;
196 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
197 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
198 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
199 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
200
201 bcmolt_olt_cfg olt_cfg = { };
202 bcmolt_olt_key olt_key = { };
203 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
204 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
205
206 Status olt_enable_res;
207
208 // Ensure that the state of the OLT is in deactivated to start with..
209 state.deactivate();
210
211 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
212 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
213 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
214 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
215 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
216 .WillRepeatedly(Return(bal_cfg_get_res));
217 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
218 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
219 .WillOnce(Return(olt_oper_res_fail))
220 .WillRepeatedly(Return(olt_oper_res_success));
221 olt_enable_res = Enable_(1, NULL);
222
223 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
224}
225
226////////////////////////////////////////////////////////////////////////
227// For testing Enable/Disable functionality
228////////////////////////////////////////////////////////////////////////
229
230int num_of_pon_ports = 16;
231
232// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
233MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
234
235class TestOltDisableReenable : public Test {
236 protected:
237 virtual void SetUp() {
238 NiceMock<BalMocker> balMock;
239 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
240
241 bcmolt_olt_cfg olt_cfg = { };
242 bcmolt_olt_key olt_key = { };
243
244 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
245
246 olt_cfg.data.topology.topology_maps.len = num_of_pon_ports;
247 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
248 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
249
250 ProbeDeviceCapabilities_();
251
252 }
253
254 virtual void TearDown() {
255 // Code here will be called immediately after each test
256 // (right before the destructor).
257 }
258};
259
260
261// Test Fixture for OltDisable
262
263// Test 1: OltDisableSuccess case
264TEST_F(TestOltDisableReenable, OltDisableSuccess){
265 // NiceMock is used to suppress 'WillByDefault' return errors.
266 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
267 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500268 bcmos_errno olt_oper_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000269
270 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500271 state.deactivate();
272 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000273 olt_disable_res = Disable_();
274 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
275
276}
277
278// Test 2: OltDisableAllPonFailed case
279TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
280 // NiceMock is used to suppress 'WillByDefault' return errors.
281 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
282 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500283 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000284
285 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500286 state.deactivate();
287 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000288 olt_disable_res = Disable_();
289 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
290}
291
292
293// Test Fixture for OltReenable
294
295// Test 1: OltReenableSuccess case
296TEST_F(TestOltDisableReenable, OltReenableSuccess){
297 // NiceMock is used to suppress 'WillByDefault' return errors.
298 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
299 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500300 uint32_t pon_id = 0;
301 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
302 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000303 Status olt_reenable_res;
304
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500305 bcmolt_pon_interface_key pon_key;
306 bcmolt_pon_interface_cfg pon_cfg;
307 pon_key.pon_ni = pon_id;
308 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
309 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
310
311 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
312 .Times(num_of_pon_ports)
313 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
314
315 bcmolt_tm_sched_cfg tm_sched_cfg;
316 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
317 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
318 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
319
320 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
321 .Times(num_of_pon_ports)
322 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000323
324 olt_reenable_res = Reenable_();
325 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
326
327}
328
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500329// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000330TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
331 // NiceMock is used to suppress 'WillByDefault' return errors.
332 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
333 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500334 uint32_t pon_id = 0;
335 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000336 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000337 Status olt_reenable_res;
338
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500339 bcmolt_pon_interface_key pon_key;
340 bcmolt_pon_interface_cfg pon_cfg;
341 pon_key.pon_ni = pon_id;
342 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
343 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
344
345 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
346 .Times(num_of_pon_ports)
347 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000348 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
349 .Times(num_of_pon_ports)
350 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500351
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000352 olt_reenable_res = Reenable_();
353 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
354}
355
356////////////////////////////////////////////////////////////////////////////
357// For testing ProbeDeviceCapabilities functionality
358////////////////////////////////////////////////////////////////////////////
359class TestProbeDevCapabilities : public Test {
360 protected:
361 NiceMock<BalMocker> balMock;
362 bcmos_errno olt_res_success = BCM_ERR_OK;
363 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
364 bcmos_errno dev_res_success = BCM_ERR_OK;
365 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
366
367 virtual void SetUp() {
368 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
369
370 bcmolt_olt_cfg olt_cfg = { };
371 bcmolt_olt_key olt_key = { };
372
373 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
374
375 olt_cfg.data.topology.topology_maps.len = num_of_pon_ports;
376 }
377
378 virtual void TearDown() {
379 }
380};
381
382// Test 1 - If querying the OLT fails, the method must return error
383TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
384
385 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
386 .WillOnce(Return(olt_res_fail));
387
388 Status query_status = ProbeDeviceCapabilities_();
389 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
390}
391
392// Test 2 - If all devices are queried successfully, the method must return Status::OK
393TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
394
395 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
396 .WillOnce(Return(olt_res_success));
397
398 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
399 .WillRepeatedly(Return(dev_res_success));
400
401 Status query_status = ProbeDeviceCapabilities_();
402
403 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
404}
405
406// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
407TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
408
409 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
410 .WillOnce(Return(olt_res_success));
411
412 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
413 .WillRepeatedly(Return(dev_res_fail));
414
415 Status query_status = ProbeDeviceCapabilities_();
416
417 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
418}
419
420// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
421TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
422
423 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
424 .WillOnce(Return(olt_res_success));
425
426 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
427 .WillOnce(Return(olt_res_success))
428 .WillRepeatedly(Return(dev_res_fail));
429
430 Status query_status = ProbeDeviceCapabilities_();
431
432 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
433}
434
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500435////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500436// For testing EnablePonIf functionality
437////////////////////////////////////////////////////////////////////////////
438
439class TestEnablePonIf : public Test {
440 protected:
441 uint32_t pon_id = 0;
442 NiceMock<BalMocker> balMock;
443
444 virtual void SetUp() {
445 }
446
447 virtual void TearDown() {
448 }
449};
450
451// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
452TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
453 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
454 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
455 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
456 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
457
458 bcmolt_pon_interface_key pon_key;
459 bcmolt_pon_interface_cfg pon_cfg;
460 pon_key.pon_ni = pon_id;
461 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
462 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
463 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
464 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
465
466 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
467 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
468
469 bcmolt_tm_sched_cfg tm_sched_cfg;
470 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
471 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
472 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
473 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
474 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
475
476 Status status = EnablePonIf_(pon_id);
477 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
478}
479
480// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
481TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
482 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
483 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
484 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
485 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
486
487 bcmolt_pon_interface_key pon_key;
488 bcmolt_pon_interface_cfg pon_cfg;
489 pon_key.pon_ni = pon_id;
490 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
491 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
492 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
493 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
494
495 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
496 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
497
498 bcmolt_tm_sched_cfg tm_sched_cfg;
499 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
500 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
501 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
502 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
503 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
504
505 Status status = EnablePonIf_(pon_id);
506 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
507}
508
509// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
510TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
511 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
512 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
513 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
514 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
515 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
516
517 bcmolt_pon_interface_key pon_key;
518 bcmolt_pon_interface_cfg pon_cfg;
519 pon_key.pon_ni = pon_id;
520 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
521 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
522 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
523 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
524
525 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
526 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
527 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
528
529 bcmolt_tm_sched_cfg tm_sched_cfg;
530 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
531 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
532 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
533 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
534 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
535
536 Status status = EnablePonIf_(pon_id);
537 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
538}
539
540// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
541TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
542 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
543 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
544 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
545 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
546 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
547 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
548
549 bcmolt_pon_interface_key pon_key;
550 bcmolt_pon_interface_cfg pon_cfg;
551 pon_key.pon_ni = pon_id;
552 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
553 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
554 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
555 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
556
557 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
558 .WillOnce(Return(olt_cfg_set_res))
559 .WillRepeatedly(Return(olt_cfg_set_err));
560 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
561 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
562
563 bcmolt_tm_sched_cfg tm_sched_cfg;
564 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
565 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
566 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
567 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
568 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
569
570 Status status = EnablePonIf_(pon_id);
571 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
572}
573
574// Test 5 - EnablePonIf already enabled success
575TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
576 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
577
578 bcmolt_pon_interface_key pon_key;
579 bcmolt_pon_interface_cfg pon_cfg;
580 pon_key.pon_ni = pon_id;
581 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
582 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
583 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
584 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
585
586 Status status = EnablePonIf_(pon_id);
587 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
588}
589
590// Test 6 - EnablePonIf - enable onu discovery failure case
591TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
592 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
593 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
594
595 bcmolt_pon_interface_key pon_key;
596 bcmolt_pon_interface_cfg pon_cfg;
597 pon_key.pon_ni = pon_id;
598 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
599 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
600 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
601 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
602 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
603
604 Status status = EnablePonIf_(pon_id);
605 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
606}
607
608// Test 7 - EnablePonIf failure case
609TEST_F(TestEnablePonIf, EnablePonIfFailed) {
610 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
611 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
612 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
613
614 bcmolt_pon_interface_key pon_key;
615 bcmolt_pon_interface_cfg pon_cfg;
616 pon_key.pon_ni = pon_id;
617 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
618 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
619 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
620 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
621 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
622 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
623
624 Status status = EnablePonIf_(pon_id);
625 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
626}
627
628////////////////////////////////////////////////////////////////////////////
629// For testing SetStateUplinkIf functionality
630////////////////////////////////////////////////////////////////////////////
631
632class TestSetStateUplinkIf : public Test {
633 protected:
634 uint32_t intf_id = 0;
635 NiceMock<BalMocker> balMock;
636
637 virtual void SetUp() {
638 }
639
640 virtual void TearDown() {
641 }
642};
643
644// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
645TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
646 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
647 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
648 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
649
650 bcmolt_nni_interface_key nni_key;
651 bcmolt_nni_interface_cfg nni_cfg;
652 nni_key.id = intf_id;
653 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
654 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
655 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
656 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
657
658 bcmolt_tm_sched_cfg tm_sched_cfg;
659 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
660 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
661 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
662 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
663 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
664 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
665
666 Status status = SetStateUplinkIf_(intf_id, true);
667 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
668}
669
670// Test 2 - SetStateUplinkIf, NNI interface already disabled case
671TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
672 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
673
674 bcmolt_nni_interface_key nni_key;
675 bcmolt_nni_interface_cfg nni_cfg;
676 nni_key.id = intf_id;
677 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
678 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
679 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
680 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
681
682 Status status = SetStateUplinkIf_(intf_id, false);
683 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
684}
685
686// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
687TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
688 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
689 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
690 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
691 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
692
693 bcmolt_nni_interface_key nni_key;
694 bcmolt_nni_interface_cfg nni_cfg;
695 nni_key.id = intf_id;
696 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
697 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
698 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
699 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
700
701 bcmolt_tm_sched_cfg tm_sched_cfg;
702 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
703 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
704 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
705 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
706 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
707 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
708 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
709
710 Status status = SetStateUplinkIf_(intf_id, true);
711 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
712}
713
714// Test 4 - SetStateUplinkIf Enable failure case
715TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
716 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
717 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
718
719 bcmolt_nni_interface_key nni_key;
720 bcmolt_nni_interface_cfg nni_cfg;
721 nni_key.id = intf_id;
722 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
723 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
724 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
725 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
726 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
727
728 Status status = SetStateUplinkIf_(intf_id, true);
729 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
730}
731
732// Test 5 - SetStateUplinkIf Disable success case
733TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
734 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
735 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
736
737 bcmolt_nni_interface_key nni_key;
738 bcmolt_nni_interface_cfg nni_cfg;
739 nni_key.id = intf_id;
740 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
741 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
742 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
743 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
744 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
745
746 Status status = SetStateUplinkIf_(intf_id, false);
747 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
748}
749
750// Test 6 - SetStateUplinkIf Disable failure case
751TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
752 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
753 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
754
755 bcmolt_nni_interface_key nni_key;
756 bcmolt_nni_interface_cfg nni_cfg;
757 nni_key.id = intf_id;
758 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
759 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
760 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
761 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
762 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
763
764 Status status = SetStateUplinkIf_(intf_id, false);
765 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
766}
767
768////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500769// For testing DisablePonIf functionality
770////////////////////////////////////////////////////////////////////////////
771
772class TestDisablePonIf : public Test {
773 protected:
774 virtual void SetUp() {
775 }
776
777 virtual void TearDown() {
778 }
779};
780
781// Test 1 - DisablePonIf success case
782TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
783 bcmos_errno olt_oper_res = BCM_ERR_OK;
784 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
785 NiceMock<BalMocker> balMock;
786 uint32_t pon_id=1;
787
788 //ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
789 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
790 state.deactivate();
791 Status status = DisablePonIf_(pon_id);
792
793 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
794}
795
796// Test 2 - DisablePonIf Failure case
797TEST_F(TestDisablePonIf, DisablePonIfFailed) {
798 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
799 NiceMock<BalMocker> balMock;
800 uint32_t pon_id=1;
801
802 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
803 state.deactivate();
804 Status status = DisablePonIf_(pon_id);
805
806 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
807}
808
809// Test 3 - DisablePonIf ONU discovery failure case
810TEST_F(TestDisablePonIf, DisablePonIfOnuDiscoveryFail) {
811 NiceMock<BalMocker> balMock;
812 uint32_t pon_id=1;
813 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
814 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
815 state.deactivate();
816 Status status = DisablePonIf_(pon_id);
817
818 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
819}
820
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500821////////////////////////////////////////////////////////////////////////////
822// For testing ActivateOnu functionality
823////////////////////////////////////////////////////////////////////////////
824
825class TestActivateOnu : public Test {
826 protected:
827 uint32_t pon_id = 0;
828 uint32_t onu_id = 1;
829 std::string vendor_id = "TWSH";
830 std::string vendor_specific = "80808080";
831 uint32_t pir = 1000000;
832 NiceMock<BalMocker> balMock;
833
834 virtual void SetUp() {
835 }
836
837 virtual void TearDown() {
838 }
839};
840
841// Test 1 - ActivateOnu success case
842TEST_F(TestActivateOnu, ActivateOnuSuccess) {
843 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
844 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
845 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
846
847 bcmolt_onu_cfg onu_cfg;
848 bcmolt_onu_key onu_key;
849 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
850 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
851 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
852 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
853
854 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
855 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
856
857 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
858 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
859}
860
861// Test 2 - ActivateOnu failure case
862TEST_F(TestActivateOnu, ActivateOnuFailure) {
863 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
864 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
865 bcmos_errno onu_cfg_set_res = BCM_ERR_INTERNAL;
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)));
873
874 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
875 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
876
877 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
878 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
879}
880
881// Test 3 - ActivateOnu - Onu already under processing case
882TEST_F(TestActivateOnu, ActivateOnuProcessing) {
883 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
884 bcmos_errno onu_cfg_get_stub_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_ACTIVE;
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 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
893
894 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
895 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
896}
897
898////////////////////////////////////////////////////////////////////////////
899// For testing DeactivateOnu functionality
900////////////////////////////////////////////////////////////////////////////
901
902class TestDeactivateOnu : public Test {
903 protected:
904 uint32_t pon_id = 0;
905 uint32_t onu_id = 1;
906 std::string vendor_id = "TWSH";
907 std::string vendor_specific = "80808080";
908 NiceMock<BalMocker> balMock;
909
910 virtual void SetUp() {
911 }
912
913 virtual void TearDown() {
914 }
915};
916
917// Test 1 - DeactivateOnu success case
918TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
919 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
920 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
921
922 bcmolt_onu_cfg onu_cfg;
923 bcmolt_onu_key onu_key;
924 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
925 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
926 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
927 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
928
929 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
930
931 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
932 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
933}
934
935// Test 2 - DeactivateOnu failure case
936TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
937 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
938 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
939
940 bcmolt_onu_cfg onu_cfg;
941 bcmolt_onu_key onu_key;
942 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
943 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
944 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
945 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
946
947 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
948
949 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
950 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
951}
952
953////////////////////////////////////////////////////////////////////////////
954// For testing DeleteOnu functionality
955////////////////////////////////////////////////////////////////////////////
956
957class TestDeleteOnu : public Test {
958 protected:
959 uint32_t pon_id = 0;
960 uint32_t onu_id = 1;
961 std::string vendor_id = "TWSH";
962 std::string vendor_specific = "80808080";
963 NiceMock<BalMocker> balMock;
964
965 virtual void SetUp() {
966 }
967
968 virtual void TearDown() {
969 }
970};
971
972// Test 1 - DeleteOnu success case
973TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
974 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
975 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
976 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
977
978 bcmolt_onu_cfg onu_cfg;
979 bcmolt_onu_key onu_key;
980 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
981 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
982 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
983 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
984
985 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
986 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
987
988 Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
989 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
990}
991
992// Test 2 - DeleteOnu failure case
993TEST_F(TestDeleteOnu, DeleteOnuFailure) {
994 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
995 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
996 bcmos_errno onu_cfg_clear_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 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1007
1008 Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1009 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1010}
1011
1012////////////////////////////////////////////////////////////////////////////
1013// For testing OmciMsgOut functionality
1014////////////////////////////////////////////////////////////////////////////
1015
1016class TestOmciMsgOut : public Test {
1017 protected:
1018 uint32_t pon_id = 0;
1019 uint32_t onu_id = 1;
1020 std::string pkt = "omci-pkt";
1021 NiceMock<BalMocker> balMock;
1022
1023 virtual void SetUp() {
1024 }
1025
1026 virtual void TearDown() {
1027 }
1028};
1029
1030// Test 1 - OmciMsgOut success case
1031TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1032 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1033
1034 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1035
1036 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1037 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1038}
1039
1040// Test 1 - OmciMsgOut failure case
1041TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1042 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1043
1044 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1045
1046 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1047 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1048}
1049
Jason Huang09b73ea2020-01-08 17:52:05 +08001050#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001051////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001052// For testing FlowAdd functionality
1053////////////////////////////////////////////////////////////////////////////
1054
1055class TestFlowAdd : public Test {
1056 protected:
1057 int32_t access_intf_id = 0;
1058 int32_t onu_id = 1;
1059 int32_t uni_id = 0;
1060 uint32_t port_no = 16;
1061 uint32_t flow_id = 1;
1062 std::string flow_type = "upstream";
1063 int32_t alloc_id = 1024;
1064 int32_t network_intf_id = 0;
1065 int32_t gemport_id = 1024;
1066 int32_t priority_value = 0;
1067 uint64_t cookie = 0;
1068
1069 NiceMock<BalMocker> balMock;
1070 openolt::Flow* flow;
1071 openolt::Classifier* classifier;
1072 openolt::Action* action;
1073 openolt::ActionCmd* cmd;
1074
1075 bcmolt_flow_key flow_key;
1076 bcmolt_flow_cfg flow_cfg;
1077
1078 tech_profile::TrafficQueues* traffic_queues;
1079 tech_profile::TrafficQueue* traffic_queue_1;
1080 tech_profile::TrafficQueue* traffic_queue_2;
1081 tech_profile::DiscardConfig* discard_config_1;
1082 tech_profile::DiscardConfig* discard_config_2;
1083 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1084 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1085
1086
1087 virtual void SetUp() {
1088 classifier = new openolt::Classifier;
1089 action = new openolt::Action;
1090 cmd = new openolt::ActionCmd;
1091
1092 classifier->set_o_tpid(0);
1093 classifier->set_o_vid(7);
1094 classifier->set_i_tpid(0);
1095 classifier->set_i_vid(0);
1096 classifier->set_o_pbits(0);
1097 classifier->set_i_pbits(0);
1098 classifier->set_eth_type(0);
1099 classifier->set_ip_proto(0);
1100 classifier->set_src_port(0);
1101 classifier->set_dst_port(0);
1102 classifier->set_pkt_tag_type("single_tag");
1103
1104 action->set_o_vid(12);
1105 action->set_o_pbits(0);
1106 action->set_o_tpid(0);
1107 action->set_i_vid(0);
1108 action->set_i_pbits(0);
1109 action->set_i_tpid(0);
1110
1111 cmd->set_add_outer_tag(true);
1112 cmd->set_remove_outer_tag(false);
1113 cmd->set_trap_to_host(false);
1114 action->set_allocated_cmd(cmd);
1115
1116 flow_key.flow_id = 1;
1117 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1118 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1119 flow_cfg.data.onu_id=1;
1120 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1121 flow_cfg.data.svc_port_id=1024;
1122 flow_cfg.data.priority=0;
1123 flow_cfg.data.cookie=0;
1124 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1125 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1126 flow_cfg.data.ingress_intf.intf_id=0;
1127 flow_cfg.data.egress_intf.intf_id=0;
1128 flow_cfg.data.classifier.o_vid=7;
1129 flow_cfg.data.classifier.o_pbits=0;
1130 flow_cfg.data.classifier.i_vid=0;
1131 flow_cfg.data.classifier.i_pbits=0;
1132 flow_cfg.data.classifier.ether_type=0;
1133 flow_cfg.data.classifier.ip_proto=0;
1134 flow_cfg.data.classifier.src_port=0;
1135 flow_cfg.data.classifier.dst_port=0;
1136 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1137 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1138 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1139 flow_cfg.data.egress_qos.tm_sched.id=1020;
1140 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1141 flow_cfg.data.action.o_vid=12;
1142 flow_cfg.data.action.o_pbits=0;
1143 flow_cfg.data.action.i_vid=0;
1144 flow_cfg.data.action.i_pbits=0;
1145 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1146
1147 traffic_queues = new tech_profile::TrafficQueues;
1148 traffic_queues->set_intf_id(0);
1149 traffic_queues->set_onu_id(2);
1150 traffic_queue_1 = traffic_queues->add_traffic_queues();
1151 traffic_queue_1->set_gemport_id(1024);
1152 traffic_queue_1->set_pbit_map("0b00000101");
1153 traffic_queue_1->set_aes_encryption(true);
1154 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1155 traffic_queue_1->set_priority(0);
1156 traffic_queue_1->set_weight(0);
1157 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1158 discard_config_1 = new tech_profile::DiscardConfig;
1159 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1160 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1161 tail_drop_discard_config_1->set_queue_size(8);
1162 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1163 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1164
1165 traffic_queues->set_uni_id(0);
1166 traffic_queues->set_port_no(16);
1167
1168 traffic_queue_2 = traffic_queues->add_traffic_queues();
1169 traffic_queue_2->set_gemport_id(1025);
1170 traffic_queue_2->set_pbit_map("0b00001010");
1171 traffic_queue_2->set_aes_encryption(true);
1172 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1173 traffic_queue_2->set_priority(1);
1174 traffic_queue_2->set_weight(0);
1175 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1176 discard_config_2 = new tech_profile::DiscardConfig;
1177 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1178 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1179 tail_drop_discard_config_2->set_queue_size(8);
1180 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1181 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1182 }
1183
1184 virtual void TearDown() {
1185 }
1186};
1187
1188// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1189TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1190 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1191 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1192
1193 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1194 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1195}
1196
1197// Test 2 - FlowAdd - Duplicate Flow case
1198TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1199 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1200 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1201 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1202
1203 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1204 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1205}
1206
1207// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1208TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1209 gemport_id = 1025;
1210
1211 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1212 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1213
1214 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1215 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1216 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1217
1218 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1219 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1220}
1221
1222// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1223TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1224 flow_type = "bidirectional";
1225
1226 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1227 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1228}
1229
1230// Test 5 - FlowAdd - Failure case(Invalid network setting)
1231TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1232 network_intf_id = -1;
1233
1234 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1235 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1236}
1237
1238// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1239TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1240 flow_id = 2;
1241
1242 classifier->set_eth_type(34958);
1243 cmd->set_add_outer_tag(false);
1244 cmd->set_trap_to_host(true);
1245 action->set_allocated_cmd(cmd);
1246
1247 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1248 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1249 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1250 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1251 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1252
1253 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1254 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1255}
1256
1257// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1258TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1259 flow_id = 3;
1260 gemport_id = 1025;
1261
1262 classifier->set_ip_proto(17);
1263 classifier->set_src_port(68);
1264 classifier->set_dst_port(67);
1265 cmd->set_add_outer_tag(false);
1266 cmd->set_trap_to_host(true);
1267 action->set_allocated_cmd(cmd);
1268
1269 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1270 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1271 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1272 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1273 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1274
1275 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1276 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1277}
1278
1279// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1280TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1281 flow_id = 4;
1282 flow_type = "downstream";
1283
1284 classifier->set_o_vid(12);
1285 classifier->set_i_vid(7);
1286 classifier->set_pkt_tag_type("double_tag");
1287 action->set_o_vid(0);
1288 cmd->set_add_outer_tag(false);
1289 cmd->set_remove_outer_tag(true);
1290 action->set_allocated_cmd(cmd);
1291
1292 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1293 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1294 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1295 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1296 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1297
1298 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1299 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1300}
1301
1302// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1303TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1304 onu_id = 2;
1305 flow_id = 5;
1306 alloc_id = 1025;
1307
1308 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1309 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1310
1311 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1312 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1313 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1314 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1315 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1316 CreateTrafficQueues_(traffic_queues);
1317
1318 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1319 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1320}
1321
1322// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1323TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1324 onu_id = 2;
1325 flow_id = 6;
1326 flow_type = "downstream";
1327 alloc_id = 1025;
1328
1329 classifier->set_o_vid(12);
1330 classifier->set_i_vid(7);
1331 classifier->set_pkt_tag_type("double_tag");
1332 action->set_o_vid(0);
1333 cmd->set_add_outer_tag(false);
1334 cmd->set_remove_outer_tag(true);
1335 action->set_allocated_cmd(cmd);
1336
1337 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1338 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1339
1340 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1341 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1342 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1343 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1344 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1345 CreateTrafficQueues_(traffic_queues);
1346
1347 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1348 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1349}
Jason Huang09b73ea2020-01-08 17:52:05 +08001350#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001351
1352////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001353// For testing OnuPacketOut functionality
1354////////////////////////////////////////////////////////////////////////////
1355
1356class TestOnuPacketOut : public Test {
1357 protected:
1358 uint32_t pon_id = 0;
1359 uint32_t onu_id = 1;
1360 std::string pkt = "omci-pkt";
1361 NiceMock<BalMocker> balMock;
1362
1363 virtual void SetUp() {
1364 }
1365
1366 virtual void TearDown() {
1367 }
1368};
1369
1370// Test 1 - OnuPacketOut success case
1371TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1372 uint32_t port_no = 16;
1373 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001374
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001375 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001376 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1377
1378 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1379 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1380}
1381
1382// Test 2 - OnuPacketOut Port number as 0 case
1383TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1384 uint32_t port_no = 0;
1385 uint32_t gemport_id = 1024;
1386
1387 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1388 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1389}
1390
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001391// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1392TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1393 uint32_t port_no = 16;
1394 uint32_t gemport_id = 0;
1395
1396 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1397 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1398
1399 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1400 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1401}
1402
1403// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1404TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1405 uint32_t port_no = 64;
1406 uint32_t gemport_id = 0;
1407
1408 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1409 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1410
1411 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1412 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1413}
1414
Jason Huang09b73ea2020-01-08 17:52:05 +08001415#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001416////////////////////////////////////////////////////////////////////////////
1417// For testing FlowRemove functionality
1418////////////////////////////////////////////////////////////////////////////
1419
1420class TestFlowRemove : public Test {
1421 protected:
1422 NiceMock<BalMocker> balMock;
1423
1424 virtual void SetUp() {
1425 }
1426
1427 virtual void TearDown() {
1428 }
1429};
1430
1431// Test 1 - FlowRemove - Failure case
1432TEST_F(TestFlowRemove, FlowRemoveFailure) {
1433 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1434 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1435
1436 Status status = FlowRemove_(1, "upstream");
1437 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1438}
1439
1440// Test 2 - FlowRemove - success case
1441TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1442 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1443 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1444
1445 Status status = FlowRemove_(1, "upstream");
1446 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1447}
1448
1449////////////////////////////////////////////////////////////////////////////
1450// For testing UplinkPacketOut functionality
1451////////////////////////////////////////////////////////////////////////////
1452
1453class TestUplinkPacketOut : public Test {
1454 protected:
1455 uint32_t pon_id = 0;
1456 std::string pkt = "omci-pkt";
1457 NiceMock<BalMocker> balMock;
1458
1459 bcmolt_flow_key flow_key;
1460 bcmolt_flow_cfg flow_cfg;
1461
1462 virtual void SetUp() {
1463 flow_key.flow_id = 1;
1464 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1465 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1466 flow_cfg.data.onu_id=1;
1467 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1468 flow_cfg.data.svc_port_id=1024;
1469 flow_cfg.data.priority=0;
1470 flow_cfg.data.cookie=0;
1471 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1472 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1473 flow_cfg.data.ingress_intf.intf_id=0;
1474 flow_cfg.data.egress_intf.intf_id=0;
1475 flow_cfg.data.classifier.o_vid=7;
1476 flow_cfg.data.classifier.o_pbits=0;
1477 flow_cfg.data.classifier.i_vid=0;
1478 flow_cfg.data.classifier.i_pbits=0;
1479 flow_cfg.data.classifier.ether_type=0;
1480 flow_cfg.data.classifier.ip_proto=0;
1481 flow_cfg.data.classifier.src_port=0;
1482 flow_cfg.data.classifier.dst_port=0;
1483 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1484 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1485 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1486 flow_cfg.data.egress_qos.tm_sched.id=1020;
1487 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1488 flow_cfg.data.action.o_vid=12;
1489 flow_cfg.data.action.o_pbits=0;
1490 flow_cfg.data.action.i_vid=0;
1491 flow_cfg.data.action.i_pbits=0;
1492 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1493 }
1494
1495 virtual void TearDown() {
1496 }
1497};
1498
1499// Test 1 - UplinkPacketOut success case
1500TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1501 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1502 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1503 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1504 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1505 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1506
1507 Status status = UplinkPacketOut_(pon_id, pkt);
1508 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1509}
1510
1511// Test 2 - UplinkPacketOut Failure case
1512TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1513 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1514 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1515 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1516 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1517 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1518
1519 Status status = UplinkPacketOut_(pon_id, pkt);
1520 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1521}
1522
1523// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1524TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1525 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1526
1527 FlowRemove_(2, "upstream");
1528 FlowRemove_(3, "upstream");
1529 FlowRemove_(4, "downstream");
1530 FlowRemove_(5, "upstream");
1531 FlowRemove_(6, "downstream");
1532
1533 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1534 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1535 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1536
1537 Status status = UplinkPacketOut_(pon_id, pkt);
1538 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1539}
Jason Huang09b73ea2020-01-08 17:52:05 +08001540#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001541
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001542////////////////////////////////////////////////////////////////////////////
1543// For testing CreateTrafficSchedulers functionality
1544////////////////////////////////////////////////////////////////////////////
1545
1546class TestCreateTrafficSchedulers : public Test {
1547 protected:
1548 NiceMock<BalMocker> balMock;
1549 tech_profile::TrafficSchedulers* traffic_scheds;
1550 tech_profile::TrafficScheduler* traffic_sched;
1551 tech_profile::SchedulerConfig* scheduler;
1552 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1553
1554 virtual void SetUp() {
1555 traffic_scheds = new tech_profile::TrafficSchedulers;
1556 traffic_scheds->set_intf_id(0);
1557 traffic_scheds->set_onu_id(1);
1558 traffic_scheds->set_uni_id(0);
1559 traffic_scheds->set_port_no(16);
1560 traffic_sched = traffic_scheds->add_traffic_scheds();
1561 traffic_sched->set_alloc_id(1024);
1562 scheduler = new tech_profile::SchedulerConfig;
1563 scheduler->set_priority(0);
1564 scheduler->set_weight(0);
1565 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1566 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1567 traffic_shaping_info->set_cbs(60536);
1568 traffic_shaping_info->set_pbs(65536);
1569 traffic_shaping_info->set_gir(10000);
1570 }
1571
1572 virtual void TearDown() {
1573 }
1574
1575 public:
1576 static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1577 if(ALLOC_CFG_FLAG) {
1578 alloc_cfg_compltd_key k(0, 1024);
1579 alloc_cfg_complete_result res;
1580 res.pon_intf_id = 0;
1581 res.alloc_id = 1024;
1582 res.state = state;
1583 res.status = status;
1584
1585 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1586 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1587 if (it == alloc_cfg_compltd_map.end()) {
1588 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0);
1589 } else {
1590 it->second->push(res);
1591 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
1592 }
1593 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1594 } else {
1595 PushAllocCfgResult(state, status);
1596 }
1597 }
1598};
1599
1600// Test 1 - CreateTrafficSchedulers-Upstream success case
1601TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1602 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1603 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1604 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1605 traffic_sched->set_allocated_scheduler(scheduler);
1606 traffic_shaping_info->set_cir(64000);
1607 traffic_shaping_info->set_pir(128000);
1608 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1609
1610 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1611 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1612
1613 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1614 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1615
1616 Status status = future_res.get();
1617 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1618}
1619
1620// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1621TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1622 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1623 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1624 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1625 traffic_sched->set_allocated_scheduler(scheduler);
1626 traffic_shaping_info->set_cir(64000);
1627 traffic_shaping_info->set_pir(128000);
1628 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1629
1630 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1631 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1632
1633 Status status = CreateTrafficSchedulers_(traffic_scheds);
1634 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1635}
1636
1637// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1638TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1639 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1640 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1641 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1642 traffic_sched->set_allocated_scheduler(scheduler);
1643 traffic_shaping_info->set_cir(64000);
1644 traffic_shaping_info->set_pir(128000);
1645 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1646
1647 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1648 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1649
1650 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1651 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
1652
1653 Status status = future_res.get();
1654 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1655}
1656
1657// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1658TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1659 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1660 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1661 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1662 traffic_sched->set_allocated_scheduler(scheduler);
1663 traffic_shaping_info->set_cir(64000);
1664 traffic_shaping_info->set_pir(128000);
1665 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1666
1667 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1668 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1669
1670 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1671 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1672
1673 Status status = future_res.get();
1674 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1675}
1676
1677// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1678TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1679 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1680 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1681 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1682 traffic_sched->set_allocated_scheduler(scheduler);
1683 traffic_shaping_info->set_cir(64000);
1684 traffic_shaping_info->set_pir(128000);
1685 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1686
1687 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1688 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1689
1690 Status status = CreateTrafficSchedulers_(traffic_scheds);
1691 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1692}
1693
1694// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1695TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1696 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1697 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1698 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1699 traffic_sched->set_allocated_scheduler(scheduler);
1700 traffic_shaping_info->set_cir(64000);
1701 traffic_shaping_info->set_pir(0);
1702 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1703
1704 Status status = CreateTrafficSchedulers_(traffic_scheds);
1705 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1706}
1707
1708// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1709TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1710 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1711 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1712 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1713 traffic_sched->set_allocated_scheduler(scheduler);
1714 traffic_shaping_info->set_cir(64000);
1715 traffic_shaping_info->set_pir(32000);
1716 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1717
1718 Status status = CreateTrafficSchedulers_(traffic_scheds);
1719 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1720}
1721
1722// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1723TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1724 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1725 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1726 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1727 traffic_sched->set_allocated_scheduler(scheduler);
1728 traffic_shaping_info->set_cir(64000);
1729 traffic_shaping_info->set_pir(64000);
1730 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1731
1732 Status status = CreateTrafficSchedulers_(traffic_scheds);
1733 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1734}
1735
1736// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1737TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1738 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1739 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1740 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1741 traffic_sched->set_allocated_scheduler(scheduler);
1742 traffic_shaping_info->set_cir(64000);
1743 traffic_shaping_info->set_pir(0);
1744 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1745
1746 Status status = CreateTrafficSchedulers_(traffic_scheds);
1747 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1748}
1749
1750// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1751TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1752 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1753 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1754 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1755 traffic_sched->set_allocated_scheduler(scheduler);
1756 traffic_shaping_info->set_cir(0);
1757 traffic_shaping_info->set_pir(32000);
1758 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1759
1760 Status status = CreateTrafficSchedulers_(traffic_scheds);
1761 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1762}
1763
1764// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1765TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1766 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1767 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1768 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1769 traffic_sched->set_allocated_scheduler(scheduler);
1770 traffic_shaping_info->set_cir(64000);
1771 traffic_shaping_info->set_pir(32000);
1772 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1773
1774 Status status = CreateTrafficSchedulers_(traffic_scheds);
1775 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1776}
1777
1778// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1779TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1780 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1781 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1782 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1783 traffic_sched->set_allocated_scheduler(scheduler);
1784 traffic_shaping_info->set_cir(64000);
1785 traffic_shaping_info->set_pir(64000);
1786 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1787
1788 Status status = CreateTrafficSchedulers_(traffic_scheds);
1789 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1790}
1791
1792// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1793TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1794 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1795 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1796 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1797 traffic_sched->set_allocated_scheduler(scheduler);
1798 traffic_shaping_info->set_cir(64000);
1799 traffic_shaping_info->set_pir(0);
1800 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1801
1802 Status status = CreateTrafficSchedulers_(traffic_scheds);
1803 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1804}
1805
1806// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1807TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1808 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1809 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1810 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1811 traffic_sched->set_allocated_scheduler(scheduler);
1812 traffic_shaping_info->set_cir(0);
1813 traffic_shaping_info->set_pir(32000);
1814 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1815
1816 Status status = CreateTrafficSchedulers_(traffic_scheds);
1817 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1818}
1819
1820// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1821TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1822 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1823 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1824 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1825 traffic_sched->set_allocated_scheduler(scheduler);
1826 traffic_shaping_info->set_cir(64000);
1827 traffic_shaping_info->set_pir(128000);
1828 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1829
1830 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1831 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1832
1833 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1834 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1835
1836 Status status = future_res.get();
1837 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1838}
1839
1840// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1841TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1842 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1843 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1844 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1845 traffic_sched->set_allocated_scheduler(scheduler);
1846 traffic_shaping_info->set_cir(64000);
1847 traffic_shaping_info->set_pir(32000);
1848 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1849
1850 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1851 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1852
1853 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1854 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1855
1856 Status status = future_res.get();
1857 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1858}
1859
1860// Test 17 - CreateTrafficSchedulers-Downstream success case
1861TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
1862 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1863 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1864 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1865 traffic_sched->set_allocated_scheduler(scheduler);
1866 traffic_shaping_info->set_cir(64000);
1867 traffic_shaping_info->set_pir(128000);
1868 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1869
1870 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1871 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1872
1873 Status status = CreateTrafficSchedulers_(traffic_scheds);
1874 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1875}
1876
1877// Test 18 - CreateTrafficSchedulers-Downstream Failure case
1878TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
1879 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1880 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1881 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1882 traffic_sched->set_allocated_scheduler(scheduler);
1883 traffic_shaping_info->set_cir(64000);
1884 traffic_shaping_info->set_pir(128000);
1885 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1886
1887 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1888 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1889
1890 Status status = CreateTrafficSchedulers_(traffic_scheds);
1891 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1892}
1893
1894// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
1895TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
1896 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1897 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1898 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1899 traffic_sched->set_allocated_scheduler(scheduler);
1900 traffic_shaping_info->set_cir(64000);
1901 traffic_shaping_info->set_pir(128000);
1902 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1903
1904 Status status = CreateTrafficSchedulers_(traffic_scheds);
1905 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1906}
1907
1908////////////////////////////////////////////////////////////////////////////
1909// For testing RemoveTrafficSchedulers functionality
1910////////////////////////////////////////////////////////////////////////////
1911
1912class TestRemoveTrafficSchedulers : public Test {
1913 protected:
1914 NiceMock<BalMocker> balMock;
1915 tech_profile::TrafficSchedulers* traffic_scheds;
1916 tech_profile::TrafficScheduler* traffic_sched;
1917 tech_profile::SchedulerConfig* scheduler;
1918 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1919 alloc_cfg_complete_result res;
1920
1921 virtual void SetUp() {
1922 traffic_scheds = new tech_profile::TrafficSchedulers;
1923 traffic_scheds->set_intf_id(0);
1924 traffic_scheds->set_onu_id(1);
1925 traffic_scheds->set_uni_id(0);
1926 traffic_scheds->set_port_no(16);
1927 traffic_sched = traffic_scheds->add_traffic_scheds();
1928 traffic_sched->set_alloc_id(1025);
1929 scheduler = new tech_profile::SchedulerConfig;
1930 scheduler->set_priority(0);
1931 scheduler->set_weight(0);
1932 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1933 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1934 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1935 traffic_shaping_info->set_cir(64000);
1936 traffic_shaping_info->set_pir(128000);
1937 traffic_shaping_info->set_cbs(60536);
1938 traffic_shaping_info->set_pbs(65536);
1939 traffic_shaping_info->set_gir(10000);
1940 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1941 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1942 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1943 }
1944
1945 virtual void TearDown() {
1946 }
1947
1948 public:
1949 static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1950 if(ALLOC_CFG_FLAG) {
1951 alloc_cfg_compltd_key k(0, 1025);
1952 alloc_cfg_complete_result res;
1953 res.pon_intf_id = 0;
1954 res.alloc_id = 1025;
1955 res.state = state;
1956 res.status = status;
1957
1958 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1959 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1960 if (it == alloc_cfg_compltd_map.end()) {
1961 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0);
1962 } else {
1963 it->second->push(res);
1964 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
1965 }
1966 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1967 } else {
1968 PushAllocCfgResult(state, status);
1969 }
1970 }
1971};
1972
1973// Test 1 - RemoveTrafficSchedulers-Upstream success case
1974TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
1975 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1976 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1977 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1978
1979 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
1980 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
1981
1982 Status status = future_res.get();
1983 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1984}
1985
1986// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
1987TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
1988 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1989 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1990 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1991
1992 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
1993 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1994
1995 Status status = future_res.get();
1996 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1997}
1998
1999// Test 3 - RemoveTrafficSchedulers-Upstream Failure case
2000TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2001 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2002
2003 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2004 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2005
2006 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2007 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2008}
2009
2010// Test 4 - RemoveTrafficSchedulers-Downstream Failure case
2011TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2012 //Create Scheduler
2013 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2014 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2015 traffic_sched->set_allocated_scheduler(scheduler);
2016 CreateTrafficSchedulers_(traffic_scheds);
2017
2018 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2019 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2020
2021 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2022 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2023}
2024
2025// Test 5 - RemoveTrafficSchedulers-Downstream success case
2026TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2027 //Create Scheduler
2028 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2029 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2030 traffic_sched->set_allocated_scheduler(scheduler);
2031 CreateTrafficSchedulers_(traffic_scheds);
2032
2033 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2034 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2035
2036 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2037 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2038}
2039
2040// Test 6 - RemoveTrafficSchedulers-Downstream Scheduler not present case
2041TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2042 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2043
2044 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2045 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2046}
2047
2048////////////////////////////////////////////////////////////////////////////
2049// For testing CreateTrafficQueues functionality
2050////////////////////////////////////////////////////////////////////////////
2051
2052class TestCreateTrafficQueues : public Test {
2053 protected:
2054 NiceMock<BalMocker> balMock;
2055 tech_profile::TrafficQueues* traffic_queues;
2056 tech_profile::TrafficQueue* traffic_queue_1;
2057 tech_profile::TrafficQueue* traffic_queue_2;
2058 tech_profile::DiscardConfig* discard_config_1;
2059 tech_profile::DiscardConfig* discard_config_2;
2060 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2061 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2062
2063 virtual void SetUp() {
2064 traffic_queues = new tech_profile::TrafficQueues;
2065 traffic_queues->set_intf_id(0);
2066 traffic_queues->set_onu_id(1);
2067 traffic_queue_1 = traffic_queues->add_traffic_queues();
2068 traffic_queue_1->set_gemport_id(1024);
2069 traffic_queue_1->set_pbit_map("0b00000101");
2070 traffic_queue_1->set_aes_encryption(true);
2071 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2072 traffic_queue_1->set_priority(0);
2073 traffic_queue_1->set_weight(0);
2074 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2075 discard_config_1 = new tech_profile::DiscardConfig;
2076 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2077 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2078 tail_drop_discard_config_1->set_queue_size(8);
2079 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2080 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2081 }
2082
2083 virtual void TearDown() {
2084 }
2085};
2086
2087// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2088TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2089 Status status;
2090 traffic_queues->set_uni_id(0);
2091 traffic_queues->set_port_no(16);
2092 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2093
2094 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2095 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2096
2097 status = CreateTrafficQueues_(traffic_queues);
2098 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2099
2100 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2101 status = CreateTrafficQueues_(traffic_queues);
2102 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2103}
2104
2105// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2106TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2107 traffic_queues->set_uni_id(1);
2108 traffic_queues->set_port_no(32);
2109 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2110
2111 traffic_queue_2 = traffic_queues->add_traffic_queues();
2112 traffic_queue_2->set_gemport_id(1025);
2113 traffic_queue_2->set_pbit_map("0b00001010");
2114 traffic_queue_2->set_aes_encryption(true);
2115 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2116 traffic_queue_2->set_priority(1);
2117 traffic_queue_2->set_weight(0);
2118 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2119 discard_config_2 = new tech_profile::DiscardConfig;
2120 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2121 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2122 tail_drop_discard_config_2->set_queue_size(8);
2123 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2124 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2125 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2126
2127 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2128 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2129
2130 Status status = CreateTrafficQueues_(traffic_queues);
2131 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2132}
2133
2134// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2135TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2136 traffic_queues->set_uni_id(2);
2137 traffic_queues->set_port_no(16);
2138 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2139
2140 traffic_queue_2 = traffic_queues->add_traffic_queues();
2141 traffic_queue_2->set_gemport_id(1025);
2142 traffic_queue_2->set_pbit_map("0b10001010");
2143 traffic_queue_2->set_aes_encryption(true);
2144 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2145 traffic_queue_2->set_priority(1);
2146 traffic_queue_2->set_weight(0);
2147 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2148 discard_config_2 = new tech_profile::DiscardConfig;
2149 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2150 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2151 tail_drop_discard_config_2->set_queue_size(8);
2152 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2153 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2154 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2155
2156 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2157 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2158
2159 Status status = CreateTrafficQueues_(traffic_queues);
2160 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2161}
2162
2163// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2164TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2165 traffic_queues->set_uni_id(3);
2166 traffic_queues->set_port_no(16);
2167 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2168
2169 traffic_queue_2 = traffic_queues->add_traffic_queues();
2170 traffic_queue_2->set_gemport_id(1025);
2171 traffic_queue_2->set_pbit_map("0b00001010");
2172 traffic_queue_2->set_aes_encryption(true);
2173 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2174 traffic_queue_2->set_priority(1);
2175 traffic_queue_2->set_weight(0);
2176 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2177 discard_config_2 = new tech_profile::DiscardConfig;
2178 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2179 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2180 tail_drop_discard_config_2->set_queue_size(8);
2181 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2182 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2183 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2184
2185 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2186 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2187
2188 Status status = CreateTrafficQueues_(traffic_queues);
2189 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2190}
2191
2192// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2193TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2194 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2195 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2196 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2197
2198 traffic_queue_2 = traffic_queues->add_traffic_queues();
2199 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2200 traffic_queues->set_uni_id(uni_ids[i]);
2201 traffic_queues->set_port_no(port_nos[i]);
2202 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2203
2204 traffic_queue_2->set_gemport_id(1025);
2205 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2206 traffic_queue_2->set_aes_encryption(true);
2207 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2208 traffic_queue_2->set_priority(1);
2209 traffic_queue_2->set_weight(0);
2210 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2211 discard_config_2 = new tech_profile::DiscardConfig;
2212 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2213 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2214 tail_drop_discard_config_2->set_queue_size(8);
2215 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2216 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2217 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2218
2219 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2220 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2221
2222 Status status = CreateTrafficQueues_(traffic_queues);
2223 if(i==16)
2224 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2225 else
2226 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2227 }
2228}
2229
2230// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2231TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2232 traffic_queues->set_uni_id(0);
2233 traffic_queues->set_port_no(16);
2234 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2235
2236 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2237 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2238
2239 Status status = CreateTrafficQueues_(traffic_queues);
2240 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2241}
2242
2243////////////////////////////////////////////////////////////////////////////
2244// For testing RemoveTrafficQueues functionality
2245////////////////////////////////////////////////////////////////////////////
2246
2247class TestRemoveTrafficQueues : public Test {
2248 protected:
2249 NiceMock<BalMocker> balMock;
2250 tech_profile::TrafficQueues* traffic_queues;
2251 tech_profile::TrafficQueue* traffic_queue_1;
2252 tech_profile::TrafficQueue* traffic_queue_2;
2253
2254 virtual void SetUp() {
2255 traffic_queues = new tech_profile::TrafficQueues;
2256 traffic_queues->set_intf_id(0);
2257 traffic_queues->set_onu_id(1);
2258 traffic_queue_1 = traffic_queues->add_traffic_queues();
2259 traffic_queue_1->set_gemport_id(1024);
2260 traffic_queue_1->set_priority(0);
2261 }
2262
2263 virtual void TearDown() {
2264 }
2265};
2266
2267// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2268TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2269 Status status;
2270 traffic_queues->set_uni_id(0);
2271 traffic_queues->set_port_no(16);
2272 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2273
2274 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2275 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2276
2277 status = RemoveTrafficQueues_(traffic_queues);
2278 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2279
2280 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2281 status = RemoveTrafficQueues_(traffic_queues);
2282 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2283}
2284
2285// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2286TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2287 Status status;
2288 traffic_queues->set_uni_id(0);
2289 traffic_queues->set_port_no(16);
2290 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2291
2292 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2293 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2294
2295 status = RemoveTrafficQueues_(traffic_queues);
2296 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2297}
2298
2299// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2300TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2301 //Remove scheduler so that is_tm_sched_id_present api call will return false
2302 tech_profile::TrafficSchedulers* traffic_scheds;
2303 tech_profile::TrafficScheduler* traffic_sched;
2304 traffic_scheds = new tech_profile::TrafficSchedulers;
2305 traffic_scheds->set_intf_id(0);
2306 traffic_scheds->set_onu_id(1);
2307 traffic_scheds->set_uni_id(0);
2308 traffic_scheds->set_port_no(16);
2309 traffic_sched = traffic_scheds->add_traffic_scheds();
2310 traffic_sched->set_alloc_id(1024);
2311 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2312
2313 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2314 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2315 RemoveTrafficSchedulers_(traffic_scheds);
2316
2317 traffic_queues->set_uni_id(0);
2318 traffic_queues->set_port_no(16);
2319 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2320
2321 Status status = RemoveTrafficQueues_(traffic_queues);
2322 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2323}
2324
2325/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2326as it is getting referred by some other queues case */
2327TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2328 traffic_queues->set_uni_id(3);
2329 traffic_queues->set_port_no(16);
2330 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2331 traffic_queue_2 = traffic_queues->add_traffic_queues();
2332 traffic_queue_2->set_gemport_id(1025);
2333 traffic_queue_2->set_priority(1);
2334 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2335
2336 Status status = RemoveTrafficQueues_(traffic_queues);
2337 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2338}
2339
2340/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2341is not getting referred by any other queues case */
2342TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2343 traffic_queues->set_uni_id(1);
2344 traffic_queues->set_port_no(32);
2345 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2346 traffic_queue_2 = traffic_queues->add_traffic_queues();
2347 traffic_queue_2->set_gemport_id(1025);
2348 traffic_queue_2->set_priority(1);
2349
2350 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2351 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2352
2353 Status status = RemoveTrafficQueues_(traffic_queues);
2354 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2355}
2356
2357/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2358having no reference to any other queues case */
2359TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2360 traffic_queues->set_uni_id(4);
2361 traffic_queues->set_port_no(64);
2362 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2363 traffic_queue_2 = traffic_queues->add_traffic_queues();
2364 traffic_queue_2->set_gemport_id(1025);
2365 traffic_queue_2->set_priority(1);
2366
2367 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2368 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2369
2370 Status status = RemoveTrafficQueues_(traffic_queues);
2371 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2372}