blob: 9fb98621ffb4e22cc97f4b338251e96bb4a4339e [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
1050////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001051// For testing FlowAdd functionality
1052////////////////////////////////////////////////////////////////////////////
1053
1054class TestFlowAdd : public Test {
1055 protected:
1056 int32_t access_intf_id = 0;
1057 int32_t onu_id = 1;
1058 int32_t uni_id = 0;
1059 uint32_t port_no = 16;
1060 uint32_t flow_id = 1;
1061 std::string flow_type = "upstream";
1062 int32_t alloc_id = 1024;
1063 int32_t network_intf_id = 0;
1064 int32_t gemport_id = 1024;
1065 int32_t priority_value = 0;
1066 uint64_t cookie = 0;
1067
1068 NiceMock<BalMocker> balMock;
1069 openolt::Flow* flow;
1070 openolt::Classifier* classifier;
1071 openolt::Action* action;
1072 openolt::ActionCmd* cmd;
1073
1074 bcmolt_flow_key flow_key;
1075 bcmolt_flow_cfg flow_cfg;
1076
1077 tech_profile::TrafficQueues* traffic_queues;
1078 tech_profile::TrafficQueue* traffic_queue_1;
1079 tech_profile::TrafficQueue* traffic_queue_2;
1080 tech_profile::DiscardConfig* discard_config_1;
1081 tech_profile::DiscardConfig* discard_config_2;
1082 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1083 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1084
1085
1086 virtual void SetUp() {
1087 classifier = new openolt::Classifier;
1088 action = new openolt::Action;
1089 cmd = new openolt::ActionCmd;
1090
1091 classifier->set_o_tpid(0);
1092 classifier->set_o_vid(7);
1093 classifier->set_i_tpid(0);
1094 classifier->set_i_vid(0);
1095 classifier->set_o_pbits(0);
1096 classifier->set_i_pbits(0);
1097 classifier->set_eth_type(0);
1098 classifier->set_ip_proto(0);
1099 classifier->set_src_port(0);
1100 classifier->set_dst_port(0);
1101 classifier->set_pkt_tag_type("single_tag");
1102
1103 action->set_o_vid(12);
1104 action->set_o_pbits(0);
1105 action->set_o_tpid(0);
1106 action->set_i_vid(0);
1107 action->set_i_pbits(0);
1108 action->set_i_tpid(0);
1109
1110 cmd->set_add_outer_tag(true);
1111 cmd->set_remove_outer_tag(false);
1112 cmd->set_trap_to_host(false);
1113 action->set_allocated_cmd(cmd);
1114
1115 flow_key.flow_id = 1;
1116 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1117 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1118 flow_cfg.data.onu_id=1;
1119 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1120 flow_cfg.data.svc_port_id=1024;
1121 flow_cfg.data.priority=0;
1122 flow_cfg.data.cookie=0;
1123 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1124 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1125 flow_cfg.data.ingress_intf.intf_id=0;
1126 flow_cfg.data.egress_intf.intf_id=0;
1127 flow_cfg.data.classifier.o_vid=7;
1128 flow_cfg.data.classifier.o_pbits=0;
1129 flow_cfg.data.classifier.i_vid=0;
1130 flow_cfg.data.classifier.i_pbits=0;
1131 flow_cfg.data.classifier.ether_type=0;
1132 flow_cfg.data.classifier.ip_proto=0;
1133 flow_cfg.data.classifier.src_port=0;
1134 flow_cfg.data.classifier.dst_port=0;
1135 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1136 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1137 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1138 flow_cfg.data.egress_qos.tm_sched.id=1020;
1139 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1140 flow_cfg.data.action.o_vid=12;
1141 flow_cfg.data.action.o_pbits=0;
1142 flow_cfg.data.action.i_vid=0;
1143 flow_cfg.data.action.i_pbits=0;
1144 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1145
1146 traffic_queues = new tech_profile::TrafficQueues;
1147 traffic_queues->set_intf_id(0);
1148 traffic_queues->set_onu_id(2);
1149 traffic_queue_1 = traffic_queues->add_traffic_queues();
1150 traffic_queue_1->set_gemport_id(1024);
1151 traffic_queue_1->set_pbit_map("0b00000101");
1152 traffic_queue_1->set_aes_encryption(true);
1153 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1154 traffic_queue_1->set_priority(0);
1155 traffic_queue_1->set_weight(0);
1156 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1157 discard_config_1 = new tech_profile::DiscardConfig;
1158 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1159 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1160 tail_drop_discard_config_1->set_queue_size(8);
1161 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1162 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1163
1164 traffic_queues->set_uni_id(0);
1165 traffic_queues->set_port_no(16);
1166
1167 traffic_queue_2 = traffic_queues->add_traffic_queues();
1168 traffic_queue_2->set_gemport_id(1025);
1169 traffic_queue_2->set_pbit_map("0b00001010");
1170 traffic_queue_2->set_aes_encryption(true);
1171 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1172 traffic_queue_2->set_priority(1);
1173 traffic_queue_2->set_weight(0);
1174 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1175 discard_config_2 = new tech_profile::DiscardConfig;
1176 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1177 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1178 tail_drop_discard_config_2->set_queue_size(8);
1179 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1180 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1181 }
1182
1183 virtual void TearDown() {
1184 }
1185};
1186
1187// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1188TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1189 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1190 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1191
1192 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);
1193 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1194}
1195
1196// Test 2 - FlowAdd - Duplicate Flow case
1197TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1198 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1199 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1200 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1201
1202 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);
1203 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1204}
1205
1206// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1207TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1208 gemport_id = 1025;
1209
1210 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1211 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1212
1213 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1214 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1215 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1216
1217 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);
1218 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1219}
1220
1221// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1222TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1223 flow_type = "bidirectional";
1224
1225 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);
1226 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1227}
1228
1229// Test 5 - FlowAdd - Failure case(Invalid network setting)
1230TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1231 network_intf_id = -1;
1232
1233 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);
1234 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1235}
1236
1237// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1238TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1239 flow_id = 2;
1240
1241 classifier->set_eth_type(34958);
1242 cmd->set_add_outer_tag(false);
1243 cmd->set_trap_to_host(true);
1244 action->set_allocated_cmd(cmd);
1245
1246 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1247 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1248 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1249 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1250 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1251
1252 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);
1253 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1254}
1255
1256// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1257TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1258 flow_id = 3;
1259 gemport_id = 1025;
1260
1261 classifier->set_ip_proto(17);
1262 classifier->set_src_port(68);
1263 classifier->set_dst_port(67);
1264 cmd->set_add_outer_tag(false);
1265 cmd->set_trap_to_host(true);
1266 action->set_allocated_cmd(cmd);
1267
1268 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1269 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1270 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1271 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1272 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1273
1274 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);
1275 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1276}
1277
1278// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1279TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1280 flow_id = 4;
1281 flow_type = "downstream";
1282
1283 classifier->set_o_vid(12);
1284 classifier->set_i_vid(7);
1285 classifier->set_pkt_tag_type("double_tag");
1286 action->set_o_vid(0);
1287 cmd->set_add_outer_tag(false);
1288 cmd->set_remove_outer_tag(true);
1289 action->set_allocated_cmd(cmd);
1290
1291 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1292 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1293 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1294 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1295 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1296
1297 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);
1298 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1299}
1300
1301// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1302TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1303 onu_id = 2;
1304 flow_id = 5;
1305 alloc_id = 1025;
1306
1307 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1308 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1309
1310 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1311 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1312 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1313 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1314 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1315 CreateTrafficQueues_(traffic_queues);
1316
1317 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);
1318 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1319}
1320
1321// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1322TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1323 onu_id = 2;
1324 flow_id = 6;
1325 flow_type = "downstream";
1326 alloc_id = 1025;
1327
1328 classifier->set_o_vid(12);
1329 classifier->set_i_vid(7);
1330 classifier->set_pkt_tag_type("double_tag");
1331 action->set_o_vid(0);
1332 cmd->set_add_outer_tag(false);
1333 cmd->set_remove_outer_tag(true);
1334 action->set_allocated_cmd(cmd);
1335
1336 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1337 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1338
1339 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1340 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1341 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1342 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1343 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1344 CreateTrafficQueues_(traffic_queues);
1345
1346 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);
1347 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1348}
1349
1350////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001351// For testing OnuPacketOut functionality
1352////////////////////////////////////////////////////////////////////////////
1353
1354class TestOnuPacketOut : public Test {
1355 protected:
1356 uint32_t pon_id = 0;
1357 uint32_t onu_id = 1;
1358 std::string pkt = "omci-pkt";
1359 NiceMock<BalMocker> balMock;
1360
1361 virtual void SetUp() {
1362 }
1363
1364 virtual void TearDown() {
1365 }
1366};
1367
1368// Test 1 - OnuPacketOut success case
1369TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1370 uint32_t port_no = 16;
1371 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001372
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001373 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001374 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1375
1376 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1377 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1378}
1379
1380// Test 2 - OnuPacketOut Port number as 0 case
1381TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1382 uint32_t port_no = 0;
1383 uint32_t gemport_id = 1024;
1384
1385 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1386 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1387}
1388
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001389// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1390TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1391 uint32_t port_no = 16;
1392 uint32_t gemport_id = 0;
1393
1394 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1395 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1396
1397 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1398 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1399}
1400
1401// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1402TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1403 uint32_t port_no = 64;
1404 uint32_t gemport_id = 0;
1405
1406 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1407 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1408
1409 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1410 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1411}
1412
1413////////////////////////////////////////////////////////////////////////////
1414// For testing FlowRemove functionality
1415////////////////////////////////////////////////////////////////////////////
1416
1417class TestFlowRemove : public Test {
1418 protected:
1419 NiceMock<BalMocker> balMock;
1420
1421 virtual void SetUp() {
1422 }
1423
1424 virtual void TearDown() {
1425 }
1426};
1427
1428// Test 1 - FlowRemove - Failure case
1429TEST_F(TestFlowRemove, FlowRemoveFailure) {
1430 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1431 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1432
1433 Status status = FlowRemove_(1, "upstream");
1434 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1435}
1436
1437// Test 2 - FlowRemove - success case
1438TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1439 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1440 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1441
1442 Status status = FlowRemove_(1, "upstream");
1443 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1444}
1445
1446////////////////////////////////////////////////////////////////////////////
1447// For testing UplinkPacketOut functionality
1448////////////////////////////////////////////////////////////////////////////
1449
1450class TestUplinkPacketOut : public Test {
1451 protected:
1452 uint32_t pon_id = 0;
1453 std::string pkt = "omci-pkt";
1454 NiceMock<BalMocker> balMock;
1455
1456 bcmolt_flow_key flow_key;
1457 bcmolt_flow_cfg flow_cfg;
1458
1459 virtual void SetUp() {
1460 flow_key.flow_id = 1;
1461 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1462 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1463 flow_cfg.data.onu_id=1;
1464 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1465 flow_cfg.data.svc_port_id=1024;
1466 flow_cfg.data.priority=0;
1467 flow_cfg.data.cookie=0;
1468 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1469 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1470 flow_cfg.data.ingress_intf.intf_id=0;
1471 flow_cfg.data.egress_intf.intf_id=0;
1472 flow_cfg.data.classifier.o_vid=7;
1473 flow_cfg.data.classifier.o_pbits=0;
1474 flow_cfg.data.classifier.i_vid=0;
1475 flow_cfg.data.classifier.i_pbits=0;
1476 flow_cfg.data.classifier.ether_type=0;
1477 flow_cfg.data.classifier.ip_proto=0;
1478 flow_cfg.data.classifier.src_port=0;
1479 flow_cfg.data.classifier.dst_port=0;
1480 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1481 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1482 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1483 flow_cfg.data.egress_qos.tm_sched.id=1020;
1484 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1485 flow_cfg.data.action.o_vid=12;
1486 flow_cfg.data.action.o_pbits=0;
1487 flow_cfg.data.action.i_vid=0;
1488 flow_cfg.data.action.i_pbits=0;
1489 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1490 }
1491
1492 virtual void TearDown() {
1493 }
1494};
1495
1496// Test 1 - UplinkPacketOut success case
1497TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1498 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1499 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1500 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1501 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1502 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1503
1504 Status status = UplinkPacketOut_(pon_id, pkt);
1505 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1506}
1507
1508// Test 2 - UplinkPacketOut Failure case
1509TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1510 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1511 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1512 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1513 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1514 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1515
1516 Status status = UplinkPacketOut_(pon_id, pkt);
1517 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1518}
1519
1520// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1521TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1522 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1523
1524 FlowRemove_(2, "upstream");
1525 FlowRemove_(3, "upstream");
1526 FlowRemove_(4, "downstream");
1527 FlowRemove_(5, "upstream");
1528 FlowRemove_(6, "downstream");
1529
1530 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1531 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1532 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1533
1534 Status status = UplinkPacketOut_(pon_id, pkt);
1535 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1536}
1537
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001538////////////////////////////////////////////////////////////////////////////
1539// For testing CreateTrafficSchedulers functionality
1540////////////////////////////////////////////////////////////////////////////
1541
1542class TestCreateTrafficSchedulers : public Test {
1543 protected:
1544 NiceMock<BalMocker> balMock;
1545 tech_profile::TrafficSchedulers* traffic_scheds;
1546 tech_profile::TrafficScheduler* traffic_sched;
1547 tech_profile::SchedulerConfig* scheduler;
1548 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1549
1550 virtual void SetUp() {
1551 traffic_scheds = new tech_profile::TrafficSchedulers;
1552 traffic_scheds->set_intf_id(0);
1553 traffic_scheds->set_onu_id(1);
1554 traffic_scheds->set_uni_id(0);
1555 traffic_scheds->set_port_no(16);
1556 traffic_sched = traffic_scheds->add_traffic_scheds();
1557 traffic_sched->set_alloc_id(1024);
1558 scheduler = new tech_profile::SchedulerConfig;
1559 scheduler->set_priority(0);
1560 scheduler->set_weight(0);
1561 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1562 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1563 traffic_shaping_info->set_cbs(60536);
1564 traffic_shaping_info->set_pbs(65536);
1565 traffic_shaping_info->set_gir(10000);
1566 }
1567
1568 virtual void TearDown() {
1569 }
1570
1571 public:
1572 static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1573 if(ALLOC_CFG_FLAG) {
1574 alloc_cfg_compltd_key k(0, 1024);
1575 alloc_cfg_complete_result res;
1576 res.pon_intf_id = 0;
1577 res.alloc_id = 1024;
1578 res.state = state;
1579 res.status = status;
1580
1581 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1582 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1583 if (it == alloc_cfg_compltd_map.end()) {
1584 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0);
1585 } else {
1586 it->second->push(res);
1587 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
1588 }
1589 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1590 } else {
1591 PushAllocCfgResult(state, status);
1592 }
1593 }
1594};
1595
1596// Test 1 - CreateTrafficSchedulers-Upstream success case
1597TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1598 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1599 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1600 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1601 traffic_sched->set_allocated_scheduler(scheduler);
1602 traffic_shaping_info->set_cir(64000);
1603 traffic_shaping_info->set_pir(128000);
1604 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1605
1606 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1607 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1608
1609 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1610 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1611
1612 Status status = future_res.get();
1613 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1614}
1615
1616// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1617TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1618 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1619 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1620 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1621 traffic_sched->set_allocated_scheduler(scheduler);
1622 traffic_shaping_info->set_cir(64000);
1623 traffic_shaping_info->set_pir(128000);
1624 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1625
1626 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1627 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1628
1629 Status status = CreateTrafficSchedulers_(traffic_scheds);
1630 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1631}
1632
1633// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1634TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1635 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1636 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1637 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1638 traffic_sched->set_allocated_scheduler(scheduler);
1639 traffic_shaping_info->set_cir(64000);
1640 traffic_shaping_info->set_pir(128000);
1641 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1642
1643 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1644 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1645
1646 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1647 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
1648
1649 Status status = future_res.get();
1650 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1651}
1652
1653// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1654TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1655 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1656 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1657 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1658 traffic_sched->set_allocated_scheduler(scheduler);
1659 traffic_shaping_info->set_cir(64000);
1660 traffic_shaping_info->set_pir(128000);
1661 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1662
1663 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1664 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1665
1666 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1667 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1668
1669 Status status = future_res.get();
1670 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1671}
1672
1673// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1674TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1675 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1676 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1677 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1678 traffic_sched->set_allocated_scheduler(scheduler);
1679 traffic_shaping_info->set_cir(64000);
1680 traffic_shaping_info->set_pir(128000);
1681 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1682
1683 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1684 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1685
1686 Status status = CreateTrafficSchedulers_(traffic_scheds);
1687 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1688}
1689
1690// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1691TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1692 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1693 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1694 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1695 traffic_sched->set_allocated_scheduler(scheduler);
1696 traffic_shaping_info->set_cir(64000);
1697 traffic_shaping_info->set_pir(0);
1698 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1699
1700 Status status = CreateTrafficSchedulers_(traffic_scheds);
1701 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1702}
1703
1704// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1705TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1706 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1707 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1708 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1709 traffic_sched->set_allocated_scheduler(scheduler);
1710 traffic_shaping_info->set_cir(64000);
1711 traffic_shaping_info->set_pir(32000);
1712 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1713
1714 Status status = CreateTrafficSchedulers_(traffic_scheds);
1715 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1716}
1717
1718// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1719TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1720 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1721 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1722 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1723 traffic_sched->set_allocated_scheduler(scheduler);
1724 traffic_shaping_info->set_cir(64000);
1725 traffic_shaping_info->set_pir(64000);
1726 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1727
1728 Status status = CreateTrafficSchedulers_(traffic_scheds);
1729 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1730}
1731
1732// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1733TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1734 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1735 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1736 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1737 traffic_sched->set_allocated_scheduler(scheduler);
1738 traffic_shaping_info->set_cir(64000);
1739 traffic_shaping_info->set_pir(0);
1740 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1741
1742 Status status = CreateTrafficSchedulers_(traffic_scheds);
1743 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1744}
1745
1746// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1747TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1748 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1749 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1750 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1751 traffic_sched->set_allocated_scheduler(scheduler);
1752 traffic_shaping_info->set_cir(0);
1753 traffic_shaping_info->set_pir(32000);
1754 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1755
1756 Status status = CreateTrafficSchedulers_(traffic_scheds);
1757 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1758}
1759
1760// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1761TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1762 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1763 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1764 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1765 traffic_sched->set_allocated_scheduler(scheduler);
1766 traffic_shaping_info->set_cir(64000);
1767 traffic_shaping_info->set_pir(32000);
1768 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1769
1770 Status status = CreateTrafficSchedulers_(traffic_scheds);
1771 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1772}
1773
1774// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1775TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1776 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1777 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1778 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1779 traffic_sched->set_allocated_scheduler(scheduler);
1780 traffic_shaping_info->set_cir(64000);
1781 traffic_shaping_info->set_pir(64000);
1782 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1783
1784 Status status = CreateTrafficSchedulers_(traffic_scheds);
1785 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1786}
1787
1788// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1789TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1790 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1791 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1792 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1793 traffic_sched->set_allocated_scheduler(scheduler);
1794 traffic_shaping_info->set_cir(64000);
1795 traffic_shaping_info->set_pir(0);
1796 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1797
1798 Status status = CreateTrafficSchedulers_(traffic_scheds);
1799 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1800}
1801
1802// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1803TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1804 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1805 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1806 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1807 traffic_sched->set_allocated_scheduler(scheduler);
1808 traffic_shaping_info->set_cir(0);
1809 traffic_shaping_info->set_pir(32000);
1810 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1811
1812 Status status = CreateTrafficSchedulers_(traffic_scheds);
1813 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1814}
1815
1816// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1817TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1818 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1819 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1820 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1821 traffic_sched->set_allocated_scheduler(scheduler);
1822 traffic_shaping_info->set_cir(64000);
1823 traffic_shaping_info->set_pir(128000);
1824 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1825
1826 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1827 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1828
1829 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1830 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1831
1832 Status status = future_res.get();
1833 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1834}
1835
1836// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1837TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1838 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1839 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1840 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1841 traffic_sched->set_allocated_scheduler(scheduler);
1842 traffic_shaping_info->set_cir(64000);
1843 traffic_shaping_info->set_pir(32000);
1844 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1845
1846 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1847 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1848
1849 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
1850 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1851
1852 Status status = future_res.get();
1853 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1854}
1855
1856// Test 17 - CreateTrafficSchedulers-Downstream success case
1857TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
1858 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1859 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1860 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1861 traffic_sched->set_allocated_scheduler(scheduler);
1862 traffic_shaping_info->set_cir(64000);
1863 traffic_shaping_info->set_pir(128000);
1864 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1865
1866 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1867 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1868
1869 Status status = CreateTrafficSchedulers_(traffic_scheds);
1870 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1871}
1872
1873// Test 18 - CreateTrafficSchedulers-Downstream Failure case
1874TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
1875 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1876 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1877 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1878 traffic_sched->set_allocated_scheduler(scheduler);
1879 traffic_shaping_info->set_cir(64000);
1880 traffic_shaping_info->set_pir(128000);
1881 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1882
1883 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1884 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1885
1886 Status status = CreateTrafficSchedulers_(traffic_scheds);
1887 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1888}
1889
1890// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
1891TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
1892 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1893 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1894 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1895 traffic_sched->set_allocated_scheduler(scheduler);
1896 traffic_shaping_info->set_cir(64000);
1897 traffic_shaping_info->set_pir(128000);
1898 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1899
1900 Status status = CreateTrafficSchedulers_(traffic_scheds);
1901 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1902}
1903
1904////////////////////////////////////////////////////////////////////////////
1905// For testing RemoveTrafficSchedulers functionality
1906////////////////////////////////////////////////////////////////////////////
1907
1908class TestRemoveTrafficSchedulers : public Test {
1909 protected:
1910 NiceMock<BalMocker> balMock;
1911 tech_profile::TrafficSchedulers* traffic_scheds;
1912 tech_profile::TrafficScheduler* traffic_sched;
1913 tech_profile::SchedulerConfig* scheduler;
1914 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1915 alloc_cfg_complete_result res;
1916
1917 virtual void SetUp() {
1918 traffic_scheds = new tech_profile::TrafficSchedulers;
1919 traffic_scheds->set_intf_id(0);
1920 traffic_scheds->set_onu_id(1);
1921 traffic_scheds->set_uni_id(0);
1922 traffic_scheds->set_port_no(16);
1923 traffic_sched = traffic_scheds->add_traffic_scheds();
1924 traffic_sched->set_alloc_id(1025);
1925 scheduler = new tech_profile::SchedulerConfig;
1926 scheduler->set_priority(0);
1927 scheduler->set_weight(0);
1928 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1929 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1930 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1931 traffic_shaping_info->set_cir(64000);
1932 traffic_shaping_info->set_pir(128000);
1933 traffic_shaping_info->set_cbs(60536);
1934 traffic_shaping_info->set_pbs(65536);
1935 traffic_shaping_info->set_gir(10000);
1936 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1937 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1938 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1939 }
1940
1941 virtual void TearDown() {
1942 }
1943
1944 public:
1945 static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1946 if(ALLOC_CFG_FLAG) {
1947 alloc_cfg_compltd_key k(0, 1025);
1948 alloc_cfg_complete_result res;
1949 res.pon_intf_id = 0;
1950 res.alloc_id = 1025;
1951 res.state = state;
1952 res.status = status;
1953
1954 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1955 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1956 if (it == alloc_cfg_compltd_map.end()) {
1957 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0);
1958 } else {
1959 it->second->push(res);
1960 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
1961 }
1962 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1963 } else {
1964 PushAllocCfgResult(state, status);
1965 }
1966 }
1967};
1968
1969// Test 1 - RemoveTrafficSchedulers-Upstream success case
1970TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
1971 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1972 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1973 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1974
1975 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
1976 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
1977
1978 Status status = future_res.get();
1979 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1980}
1981
1982// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
1983TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
1984 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1985 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1986 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1987
1988 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
1989 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1990
1991 Status status = future_res.get();
1992 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1993}
1994
1995// Test 3 - RemoveTrafficSchedulers-Upstream Failure case
1996TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
1997 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1998
1999 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2000 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2001
2002 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2003 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2004}
2005
2006// Test 4 - RemoveTrafficSchedulers-Downstream Failure case
2007TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2008 //Create Scheduler
2009 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2010 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2011 traffic_sched->set_allocated_scheduler(scheduler);
2012 CreateTrafficSchedulers_(traffic_scheds);
2013
2014 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2015 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2016
2017 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2018 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2019}
2020
2021// Test 5 - RemoveTrafficSchedulers-Downstream success case
2022TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2023 //Create Scheduler
2024 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2025 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2026 traffic_sched->set_allocated_scheduler(scheduler);
2027 CreateTrafficSchedulers_(traffic_scheds);
2028
2029 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2030 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2031
2032 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2033 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2034}
2035
2036// Test 6 - RemoveTrafficSchedulers-Downstream Scheduler not present case
2037TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2038 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2039
2040 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2041 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2042}
2043
2044////////////////////////////////////////////////////////////////////////////
2045// For testing CreateTrafficQueues functionality
2046////////////////////////////////////////////////////////////////////////////
2047
2048class TestCreateTrafficQueues : public Test {
2049 protected:
2050 NiceMock<BalMocker> balMock;
2051 tech_profile::TrafficQueues* traffic_queues;
2052 tech_profile::TrafficQueue* traffic_queue_1;
2053 tech_profile::TrafficQueue* traffic_queue_2;
2054 tech_profile::DiscardConfig* discard_config_1;
2055 tech_profile::DiscardConfig* discard_config_2;
2056 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2057 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2058
2059 virtual void SetUp() {
2060 traffic_queues = new tech_profile::TrafficQueues;
2061 traffic_queues->set_intf_id(0);
2062 traffic_queues->set_onu_id(1);
2063 traffic_queue_1 = traffic_queues->add_traffic_queues();
2064 traffic_queue_1->set_gemport_id(1024);
2065 traffic_queue_1->set_pbit_map("0b00000101");
2066 traffic_queue_1->set_aes_encryption(true);
2067 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2068 traffic_queue_1->set_priority(0);
2069 traffic_queue_1->set_weight(0);
2070 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2071 discard_config_1 = new tech_profile::DiscardConfig;
2072 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2073 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2074 tail_drop_discard_config_1->set_queue_size(8);
2075 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2076 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2077 }
2078
2079 virtual void TearDown() {
2080 }
2081};
2082
2083// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2084TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2085 Status status;
2086 traffic_queues->set_uni_id(0);
2087 traffic_queues->set_port_no(16);
2088 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2089
2090 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2091 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2092
2093 status = CreateTrafficQueues_(traffic_queues);
2094 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2095
2096 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2097 status = CreateTrafficQueues_(traffic_queues);
2098 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2099}
2100
2101// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2102TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2103 traffic_queues->set_uni_id(1);
2104 traffic_queues->set_port_no(32);
2105 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2106
2107 traffic_queue_2 = traffic_queues->add_traffic_queues();
2108 traffic_queue_2->set_gemport_id(1025);
2109 traffic_queue_2->set_pbit_map("0b00001010");
2110 traffic_queue_2->set_aes_encryption(true);
2111 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2112 traffic_queue_2->set_priority(1);
2113 traffic_queue_2->set_weight(0);
2114 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2115 discard_config_2 = new tech_profile::DiscardConfig;
2116 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2117 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2118 tail_drop_discard_config_2->set_queue_size(8);
2119 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2120 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2121 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2122
2123 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2124 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2125
2126 Status status = CreateTrafficQueues_(traffic_queues);
2127 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2128}
2129
2130// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2131TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2132 traffic_queues->set_uni_id(2);
2133 traffic_queues->set_port_no(16);
2134 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2135
2136 traffic_queue_2 = traffic_queues->add_traffic_queues();
2137 traffic_queue_2->set_gemport_id(1025);
2138 traffic_queue_2->set_pbit_map("0b10001010");
2139 traffic_queue_2->set_aes_encryption(true);
2140 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2141 traffic_queue_2->set_priority(1);
2142 traffic_queue_2->set_weight(0);
2143 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2144 discard_config_2 = new tech_profile::DiscardConfig;
2145 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2146 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2147 tail_drop_discard_config_2->set_queue_size(8);
2148 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2149 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2150 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2151
2152 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2153 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2154
2155 Status status = CreateTrafficQueues_(traffic_queues);
2156 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2157}
2158
2159// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2160TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2161 traffic_queues->set_uni_id(3);
2162 traffic_queues->set_port_no(16);
2163 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2164
2165 traffic_queue_2 = traffic_queues->add_traffic_queues();
2166 traffic_queue_2->set_gemport_id(1025);
2167 traffic_queue_2->set_pbit_map("0b00001010");
2168 traffic_queue_2->set_aes_encryption(true);
2169 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2170 traffic_queue_2->set_priority(1);
2171 traffic_queue_2->set_weight(0);
2172 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2173 discard_config_2 = new tech_profile::DiscardConfig;
2174 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2175 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2176 tail_drop_discard_config_2->set_queue_size(8);
2177 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2178 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2179 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2180
2181 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2182 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2183
2184 Status status = CreateTrafficQueues_(traffic_queues);
2185 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2186}
2187
2188// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2189TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2190 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2191 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2192 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2193
2194 traffic_queue_2 = traffic_queues->add_traffic_queues();
2195 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2196 traffic_queues->set_uni_id(uni_ids[i]);
2197 traffic_queues->set_port_no(port_nos[i]);
2198 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2199
2200 traffic_queue_2->set_gemport_id(1025);
2201 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2202 traffic_queue_2->set_aes_encryption(true);
2203 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2204 traffic_queue_2->set_priority(1);
2205 traffic_queue_2->set_weight(0);
2206 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2207 discard_config_2 = new tech_profile::DiscardConfig;
2208 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2209 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2210 tail_drop_discard_config_2->set_queue_size(8);
2211 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2212 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2213 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2214
2215 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2216 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2217
2218 Status status = CreateTrafficQueues_(traffic_queues);
2219 if(i==16)
2220 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2221 else
2222 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2223 }
2224}
2225
2226// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2227TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2228 traffic_queues->set_uni_id(0);
2229 traffic_queues->set_port_no(16);
2230 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2231
2232 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2233 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2234
2235 Status status = CreateTrafficQueues_(traffic_queues);
2236 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2237}
2238
2239////////////////////////////////////////////////////////////////////////////
2240// For testing RemoveTrafficQueues functionality
2241////////////////////////////////////////////////////////////////////////////
2242
2243class TestRemoveTrafficQueues : public Test {
2244 protected:
2245 NiceMock<BalMocker> balMock;
2246 tech_profile::TrafficQueues* traffic_queues;
2247 tech_profile::TrafficQueue* traffic_queue_1;
2248 tech_profile::TrafficQueue* traffic_queue_2;
2249
2250 virtual void SetUp() {
2251 traffic_queues = new tech_profile::TrafficQueues;
2252 traffic_queues->set_intf_id(0);
2253 traffic_queues->set_onu_id(1);
2254 traffic_queue_1 = traffic_queues->add_traffic_queues();
2255 traffic_queue_1->set_gemport_id(1024);
2256 traffic_queue_1->set_priority(0);
2257 }
2258
2259 virtual void TearDown() {
2260 }
2261};
2262
2263// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2264TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2265 Status status;
2266 traffic_queues->set_uni_id(0);
2267 traffic_queues->set_port_no(16);
2268 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2269
2270 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2271 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2272
2273 status = RemoveTrafficQueues_(traffic_queues);
2274 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2275
2276 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2277 status = RemoveTrafficQueues_(traffic_queues);
2278 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2279}
2280
2281// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2282TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2283 Status status;
2284 traffic_queues->set_uni_id(0);
2285 traffic_queues->set_port_no(16);
2286 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2287
2288 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2289 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2290
2291 status = RemoveTrafficQueues_(traffic_queues);
2292 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2293}
2294
2295// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2296TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2297 //Remove scheduler so that is_tm_sched_id_present api call will return false
2298 tech_profile::TrafficSchedulers* traffic_scheds;
2299 tech_profile::TrafficScheduler* traffic_sched;
2300 traffic_scheds = new tech_profile::TrafficSchedulers;
2301 traffic_scheds->set_intf_id(0);
2302 traffic_scheds->set_onu_id(1);
2303 traffic_scheds->set_uni_id(0);
2304 traffic_scheds->set_port_no(16);
2305 traffic_sched = traffic_scheds->add_traffic_scheds();
2306 traffic_sched->set_alloc_id(1024);
2307 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2308
2309 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2310 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2311 RemoveTrafficSchedulers_(traffic_scheds);
2312
2313 traffic_queues->set_uni_id(0);
2314 traffic_queues->set_port_no(16);
2315 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2316
2317 Status status = RemoveTrafficQueues_(traffic_queues);
2318 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2319}
2320
2321/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2322as it is getting referred by some other queues case */
2323TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2324 traffic_queues->set_uni_id(3);
2325 traffic_queues->set_port_no(16);
2326 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2327 traffic_queue_2 = traffic_queues->add_traffic_queues();
2328 traffic_queue_2->set_gemport_id(1025);
2329 traffic_queue_2->set_priority(1);
2330 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2331
2332 Status status = RemoveTrafficQueues_(traffic_queues);
2333 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2334}
2335
2336/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2337is not getting referred by any other queues case */
2338TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2339 traffic_queues->set_uni_id(1);
2340 traffic_queues->set_port_no(32);
2341 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2342 traffic_queue_2 = traffic_queues->add_traffic_queues();
2343 traffic_queue_2->set_gemport_id(1025);
2344 traffic_queue_2->set_priority(1);
2345
2346 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2347 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2348
2349 Status status = RemoveTrafficQueues_(traffic_queues);
2350 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2351}
2352
2353/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2354having no reference to any other queues case */
2355TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2356 traffic_queues->set_uni_id(4);
2357 traffic_queues->set_port_no(64);
2358 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2359 traffic_queue_2 = traffic_queues->add_traffic_queues();
2360 traffic_queue_2->set_gemport_id(1025);
2361 traffic_queue_2->set_priority(1);
2362
2363 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2364 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2365
2366 Status status = RemoveTrafficQueues_(traffic_queues);
2367 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2368}