blob: 7f9926f901144eea58f1b2109ba085b2e3f3bd3f [file] [log] [blame]
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "gtest/gtest.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050017#include "Queue.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000018#include "bal_mocker.h"
19#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053020#include "core_data.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050021#include <future>
Amit Ghoshfcad4d32019-11-13 10:24:55 +000022using namespace testing;
23using namespace std;
24
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050025extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
26extern dev_log_id openolt_log_id;
27extern bcmos_fastlock alloc_cfg_wait_lock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050028
Amit Ghoshfcad4d32019-11-13 10:24:55 +000029class TestOltEnable : public Test {
30 protected:
31 virtual void SetUp() {
32 }
33
34 virtual void TearDown() {
35 // Code here will be called immediately after each test
36 // (right before the destructor).
37 }
38};
39
40// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
41// bcmolt_cfg_get__bal_state_stub.
42ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
43
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050044// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
45// bcmolt_cfg_get__onu_state_stub.
46ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
47
48// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
49// bcmolt_cfg_get__tm_sched_stub.
50ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
51
52// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
53// bcmolt_cfg_get__pon_intf_stub.
54ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
55
56// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
57// bcmolt_cfg_get__nni_intf_stub.
58ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000059
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050060// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
61// bcmolt_cfg_get__flow_stub.
62ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
63
Amit Ghoshfcad4d32019-11-13 10:24:55 +000064// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
65MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050066MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
67MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
69MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050070MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000071
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
Girish Gowdraddf9a162020-01-27 12:56:27 +0530230int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000231
232// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
233MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
234
235class TestOltDisableReenable : public Test {
236 protected:
237 virtual void SetUp() {
238 NiceMock<BalMocker> balMock;
239 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
240
241 bcmolt_olt_cfg olt_cfg = { };
242 bcmolt_olt_key olt_key = { };
243
244 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
245
Girish Gowdraddf9a162020-01-27 12:56:27 +0530246 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000247 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
248 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
249
250 ProbeDeviceCapabilities_();
251
252 }
253
254 virtual void TearDown() {
255 // Code here will be called immediately after each test
256 // (right before the destructor).
257 }
258};
259
260
261// Test Fixture for OltDisable
262
263// Test 1: OltDisableSuccess case
264TEST_F(TestOltDisableReenable, OltDisableSuccess){
265 // NiceMock is used to suppress 'WillByDefault' return errors.
266 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
267 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500268 bcmos_errno olt_oper_res = BCM_ERR_OK;
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(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530312 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500313 .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(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530321 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500322 .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(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530346 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500347 .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(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530349 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000350 .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
Girish Gowdraddf9a162020-01-27 12:56:27 +0530375 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000376 }
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
Girish Gowdra24297032020-03-23 12:32:37 -0700841// Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state
842TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) {
843 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
844 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500845 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
Girish Gowdra24297032020-03-23 12:32:37 -0700846 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500847
848 bcmolt_onu_cfg onu_cfg;
849 bcmolt_onu_key onu_key;
850 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
Girish Gowdra24297032020-03-23 12:32:37 -0700851 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500852 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
853 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
854
855 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
856 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
Girish Gowdra24297032020-03-23 12:32:37 -0700857 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500858
859 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
860 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
861}
862
Girish Gowdra24297032020-03-23 12:32:37 -0700863// Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state
864TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500865 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
866 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
867
868 bcmolt_onu_cfg onu_cfg;
869 bcmolt_onu_key onu_key;
870 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
871 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
872 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
873 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra24297032020-03-23 12:32:37 -0700874
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500875 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
876
877 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
878 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
879}
880
Girish Gowdra24297032020-03-23 12:32:37 -0700881// Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state
882TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) {
883 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
884 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
885 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
886
887 bcmolt_onu_cfg onu_cfg;
888 bcmolt_onu_key onu_key;
889 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
890 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
891 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
892 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
893
894 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
895 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
896
897
898 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
899 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
900}
901
902// Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE)
903TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) {
904 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
905 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
906
907 bcmolt_onu_cfg onu_cfg;
908 bcmolt_onu_key onu_key;
909 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
910 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process
911 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
912 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
913
914 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
915
916 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
917 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
918}
919
920// Test 5 - ActivateOnu failure case - cfg_get failure
921TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) {
922 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure
923
924 bcmolt_onu_cfg onu_cfg;
925 bcmolt_onu_key onu_key;
926 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
927 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
928 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
929 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
930
931 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
932 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
933}
934
935// Test 6 - ActivateOnu failure case - oper_submit failure
936TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) {
937 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
938 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
939 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
940 bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure
941
942 bcmolt_onu_cfg onu_cfg;
943 bcmolt_onu_key onu_key;
944 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
945 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
946 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
947 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
948
949 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
950 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
951 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
952
953 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
954 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
955}
956
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500957////////////////////////////////////////////////////////////////////////////
958// For testing DeactivateOnu functionality
959////////////////////////////////////////////////////////////////////////////
960
961class TestDeactivateOnu : public Test {
962 protected:
963 uint32_t pon_id = 0;
964 uint32_t onu_id = 1;
965 std::string vendor_id = "TWSH";
966 std::string vendor_specific = "80808080";
967 NiceMock<BalMocker> balMock;
968
969 virtual void SetUp() {
970 }
971
972 virtual void TearDown() {
973 }
974};
975
976// Test 1 - DeactivateOnu success case
977TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
978 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
979 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
980
981 bcmolt_onu_cfg onu_cfg;
982 bcmolt_onu_key onu_key;
983 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
984 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
985 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
986 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
987
988 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
989
990 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
991 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
992}
993
994// Test 2 - DeactivateOnu failure case
995TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
996 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
997 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
998
999 bcmolt_onu_cfg onu_cfg;
1000 bcmolt_onu_key onu_key;
1001 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1002 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1003 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1004 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1005
1006 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1007
1008 Status status = DeactivateOnu_(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 DeleteOnu functionality
1014////////////////////////////////////////////////////////////////////////////
1015
1016class TestDeleteOnu : public Test {
1017 protected:
1018 uint32_t pon_id = 0;
1019 uint32_t onu_id = 1;
1020 std::string vendor_id = "TWSH";
1021 std::string vendor_specific = "80808080";
1022 NiceMock<BalMocker> balMock;
1023
1024 virtual void SetUp() {
1025 }
1026
1027 virtual void TearDown() {
1028 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301029 public:
1030 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
1031 onu_deactivate_complete_result res;
1032 res.pon_intf_id = 0;
1033 res.onu_id = 1;
1034 res.result = result;
1035 res.reason = reason;
1036 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
1037 // before we push the result.
1038 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1039 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
1040 onu_deact_compltd_key k(0, 1);
1041 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
1042 if (it == onu_deact_compltd_map.end()) {
1043 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
1044 } else {
1045 it->second->push(res);
1046 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
1047 }
1048 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
1049 return 0;
1050 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001051};
1052
1053// Test 1 - DeleteOnu success case
1054TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
1055 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1056 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1057 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1058
1059 bcmolt_onu_cfg onu_cfg;
1060 bcmolt_onu_key onu_key;
1061 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1062 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1063 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301064 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001065
1066 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1067 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1068
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301069 future<int> push_onu_deact_complt_res = \
1070 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1071 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1072 Status status = future_res.get();
1073 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001074 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1075}
1076
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301077// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1078TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001079 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1080 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1081 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1082
1083 bcmolt_onu_cfg onu_cfg;
1084 bcmolt_onu_key onu_key;
1085 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1086 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1087 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301088 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001089
1090 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1091 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1092
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301093 future<int> push_onu_deact_complt_res = \
1094 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1095 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1096
1097 Status status = future_res.get();
1098 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001099 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1100}
1101
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301102// Test 3 - DeleteOnu failure case - onu deactivation fails
1103TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
1104 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1105 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1106
1107 bcmolt_onu_cfg onu_cfg;
1108 bcmolt_onu_key onu_key;
1109 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1110 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1111 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301112 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301113
1114 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1115
1116 future<int> push_onu_deact_complt_res = \
1117 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1118 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1119
1120 Status status = future_res.get();
1121 int res = push_onu_deact_complt_res.get();
1122 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1123}
1124
1125// Test 4 - DeleteOnu failure case - onu deactivation timesout
1126TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
1127 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1128 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1129
1130 bcmolt_onu_cfg onu_cfg;
1131 bcmolt_onu_key onu_key;
1132 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1133 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1134 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301135 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301136
1137 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1138
1139 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1140
1141 Status status = future_res.get();
1142 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1143}
1144
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301145// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1146TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
1147 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1148 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1149 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1150
1151 bcmolt_onu_cfg onu_cfg;
1152 bcmolt_onu_key onu_key;
1153 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1154 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1155 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1156 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1157
1158 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1159 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1160
1161 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1162
1163 Status status = future_res.get();
1164 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1165}
1166
1167// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1168TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1169 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1170
1171 bcmolt_onu_cfg onu_cfg;
1172 bcmolt_onu_key onu_key;
1173 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1174 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1175 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1176 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1177
1178 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1179
1180 Status status = future_res.get();
1181 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1182}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301183
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001184////////////////////////////////////////////////////////////////////////////
1185// For testing OmciMsgOut functionality
1186////////////////////////////////////////////////////////////////////////////
1187
1188class TestOmciMsgOut : public Test {
1189 protected:
1190 uint32_t pon_id = 0;
1191 uint32_t onu_id = 1;
1192 std::string pkt = "omci-pkt";
1193 NiceMock<BalMocker> balMock;
1194
1195 virtual void SetUp() {
1196 }
1197
1198 virtual void TearDown() {
1199 }
1200};
1201
1202// Test 1 - OmciMsgOut success case
1203TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1204 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1205
1206 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1207
1208 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1209 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1210}
1211
1212// Test 1 - OmciMsgOut failure case
1213TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1214 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1215
1216 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1217
1218 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1219 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1220}
1221
1222////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001223// For testing FlowAdd functionality
1224////////////////////////////////////////////////////////////////////////////
1225
1226class TestFlowAdd : public Test {
1227 protected:
1228 int32_t access_intf_id = 0;
1229 int32_t onu_id = 1;
1230 int32_t uni_id = 0;
1231 uint32_t port_no = 16;
1232 uint32_t flow_id = 1;
1233 std::string flow_type = "upstream";
1234 int32_t alloc_id = 1024;
1235 int32_t network_intf_id = 0;
1236 int32_t gemport_id = 1024;
1237 int32_t priority_value = 0;
1238 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301239 int32_t group_id = -1;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001240
1241 NiceMock<BalMocker> balMock;
1242 openolt::Flow* flow;
1243 openolt::Classifier* classifier;
1244 openolt::Action* action;
1245 openolt::ActionCmd* cmd;
1246
1247 bcmolt_flow_key flow_key;
1248 bcmolt_flow_cfg flow_cfg;
1249
1250 tech_profile::TrafficQueues* traffic_queues;
1251 tech_profile::TrafficQueue* traffic_queue_1;
1252 tech_profile::TrafficQueue* traffic_queue_2;
1253 tech_profile::DiscardConfig* discard_config_1;
1254 tech_profile::DiscardConfig* discard_config_2;
1255 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1256 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1257
1258
1259 virtual void SetUp() {
1260 classifier = new openolt::Classifier;
1261 action = new openolt::Action;
1262 cmd = new openolt::ActionCmd;
1263
1264 classifier->set_o_tpid(0);
1265 classifier->set_o_vid(7);
1266 classifier->set_i_tpid(0);
1267 classifier->set_i_vid(0);
1268 classifier->set_o_pbits(0);
1269 classifier->set_i_pbits(0);
1270 classifier->set_eth_type(0);
1271 classifier->set_ip_proto(0);
1272 classifier->set_src_port(0);
1273 classifier->set_dst_port(0);
1274 classifier->set_pkt_tag_type("single_tag");
1275
1276 action->set_o_vid(12);
1277 action->set_o_pbits(0);
1278 action->set_o_tpid(0);
1279 action->set_i_vid(0);
1280 action->set_i_pbits(0);
1281 action->set_i_tpid(0);
1282
1283 cmd->set_add_outer_tag(true);
1284 cmd->set_remove_outer_tag(false);
1285 cmd->set_trap_to_host(false);
1286 action->set_allocated_cmd(cmd);
1287
1288 flow_key.flow_id = 1;
1289 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1290 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1291 flow_cfg.data.onu_id=1;
1292 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1293 flow_cfg.data.svc_port_id=1024;
1294 flow_cfg.data.priority=0;
1295 flow_cfg.data.cookie=0;
1296 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1297 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1298 flow_cfg.data.ingress_intf.intf_id=0;
1299 flow_cfg.data.egress_intf.intf_id=0;
1300 flow_cfg.data.classifier.o_vid=7;
1301 flow_cfg.data.classifier.o_pbits=0;
1302 flow_cfg.data.classifier.i_vid=0;
1303 flow_cfg.data.classifier.i_pbits=0;
1304 flow_cfg.data.classifier.ether_type=0;
1305 flow_cfg.data.classifier.ip_proto=0;
1306 flow_cfg.data.classifier.src_port=0;
1307 flow_cfg.data.classifier.dst_port=0;
1308 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1309 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1310 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1311 flow_cfg.data.egress_qos.tm_sched.id=1020;
1312 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1313 flow_cfg.data.action.o_vid=12;
1314 flow_cfg.data.action.o_pbits=0;
1315 flow_cfg.data.action.i_vid=0;
1316 flow_cfg.data.action.i_pbits=0;
1317 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1318
1319 traffic_queues = new tech_profile::TrafficQueues;
1320 traffic_queues->set_intf_id(0);
1321 traffic_queues->set_onu_id(2);
1322 traffic_queue_1 = traffic_queues->add_traffic_queues();
1323 traffic_queue_1->set_gemport_id(1024);
1324 traffic_queue_1->set_pbit_map("0b00000101");
1325 traffic_queue_1->set_aes_encryption(true);
1326 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1327 traffic_queue_1->set_priority(0);
1328 traffic_queue_1->set_weight(0);
1329 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1330 discard_config_1 = new tech_profile::DiscardConfig;
1331 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1332 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1333 tail_drop_discard_config_1->set_queue_size(8);
1334 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1335 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1336
1337 traffic_queues->set_uni_id(0);
1338 traffic_queues->set_port_no(16);
1339
1340 traffic_queue_2 = traffic_queues->add_traffic_queues();
1341 traffic_queue_2->set_gemport_id(1025);
1342 traffic_queue_2->set_pbit_map("0b00001010");
1343 traffic_queue_2->set_aes_encryption(true);
1344 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1345 traffic_queue_2->set_priority(1);
1346 traffic_queue_2->set_weight(0);
1347 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1348 discard_config_2 = new tech_profile::DiscardConfig;
1349 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1350 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1351 tail_drop_discard_config_2->set_queue_size(8);
1352 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1353 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1354 }
1355
1356 virtual void TearDown() {
1357 }
1358};
1359
1360// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1361TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1362 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1363 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1364
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301365 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
1366 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001367 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1368}
1369
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301370#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001371// Test 2 - FlowAdd - Duplicate Flow case
1372TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1373 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1374 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1375 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1376
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301377 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1378 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001379 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1380}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301381#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001382
1383// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1384TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1385 gemport_id = 1025;
1386
1387 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1388 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1389
1390 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1391 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1392 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1393
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301394 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1395 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001396 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1397}
1398
1399// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1400TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1401 flow_type = "bidirectional";
1402
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301403 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1404 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001405 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1406}
1407
1408// Test 5 - FlowAdd - Failure case(Invalid network setting)
1409TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1410 network_intf_id = -1;
1411
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301412 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1413 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001414 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1415}
1416
1417// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1418TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1419 flow_id = 2;
1420
1421 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301422 action = new openolt::Action;
1423 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001424 cmd->set_trap_to_host(true);
1425 action->set_allocated_cmd(cmd);
1426
1427 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1428 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1429 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1430 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1431 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1432
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301433 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id,
1434 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001435 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1436}
1437
1438// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1439TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1440 flow_id = 3;
1441 gemport_id = 1025;
1442
1443 classifier->set_ip_proto(17);
1444 classifier->set_src_port(68);
1445 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301446 action = new openolt::Action;
1447 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001448 cmd->set_trap_to_host(true);
1449 action->set_allocated_cmd(cmd);
1450
1451 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1452 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1453 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1454 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1455 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1456
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301457 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1458 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001459 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1460}
1461
1462// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1463TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1464 flow_id = 4;
1465 flow_type = "downstream";
1466
1467 classifier->set_o_vid(12);
1468 classifier->set_i_vid(7);
1469 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301470 action = new openolt::Action;
1471 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001472 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001473 cmd->set_remove_outer_tag(true);
1474 action->set_allocated_cmd(cmd);
1475
1476 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1477 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1478 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1479 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1480 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1481
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301482 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1483 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001484 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1485}
1486
1487// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1488TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1489 onu_id = 2;
1490 flow_id = 5;
1491 alloc_id = 1025;
1492
1493 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1494 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1495
1496 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1497 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1498 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1499 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1500 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1501 CreateTrafficQueues_(traffic_queues);
1502
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301503 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1504 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001505 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1506}
1507
1508// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1509TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1510 onu_id = 2;
1511 flow_id = 6;
1512 flow_type = "downstream";
1513 alloc_id = 1025;
1514
1515 classifier->set_o_vid(12);
1516 classifier->set_i_vid(7);
1517 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301518 action = new openolt::Action;
1519 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001520 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001521 cmd->set_remove_outer_tag(true);
1522 action->set_allocated_cmd(cmd);
1523
1524 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1525 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1526
1527 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1528 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1529 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1530 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1531 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1532 CreateTrafficQueues_(traffic_queues);
1533
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301534 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1535 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001536 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1537}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301538
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001539
1540////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001541// For testing OnuPacketOut functionality
1542////////////////////////////////////////////////////////////////////////////
1543
1544class TestOnuPacketOut : public Test {
1545 protected:
1546 uint32_t pon_id = 0;
1547 uint32_t onu_id = 1;
1548 std::string pkt = "omci-pkt";
1549 NiceMock<BalMocker> balMock;
1550
1551 virtual void SetUp() {
1552 }
1553
1554 virtual void TearDown() {
1555 }
1556};
1557
1558// Test 1 - OnuPacketOut success case
1559TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1560 uint32_t port_no = 16;
1561 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001562
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001563 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001564 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1565
1566 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1567 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1568}
1569
1570// Test 2 - OnuPacketOut Port number as 0 case
1571TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1572 uint32_t port_no = 0;
1573 uint32_t gemport_id = 1024;
1574
1575 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1576 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1577}
1578
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001579// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1580TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1581 uint32_t port_no = 16;
1582 uint32_t gemport_id = 0;
1583
1584 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1585 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1586
1587 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1588 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1589}
1590
1591// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1592TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1593 uint32_t port_no = 64;
1594 uint32_t gemport_id = 0;
1595
1596 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1597 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1598
1599 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1600 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1601}
1602
1603////////////////////////////////////////////////////////////////////////////
1604// For testing FlowRemove functionality
1605////////////////////////////////////////////////////////////////////////////
1606
1607class TestFlowRemove : public Test {
1608 protected:
1609 NiceMock<BalMocker> balMock;
1610
1611 virtual void SetUp() {
1612 }
1613
1614 virtual void TearDown() {
1615 }
1616};
1617
1618// Test 1 - FlowRemove - Failure case
1619TEST_F(TestFlowRemove, FlowRemoveFailure) {
1620 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1621 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1622
1623 Status status = FlowRemove_(1, "upstream");
1624 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1625}
1626
1627// Test 2 - FlowRemove - success case
1628TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1629 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1630 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1631
1632 Status status = FlowRemove_(1, "upstream");
1633 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1634}
1635
1636////////////////////////////////////////////////////////////////////////////
1637// For testing UplinkPacketOut functionality
1638////////////////////////////////////////////////////////////////////////////
1639
1640class TestUplinkPacketOut : public Test {
1641 protected:
1642 uint32_t pon_id = 0;
1643 std::string pkt = "omci-pkt";
1644 NiceMock<BalMocker> balMock;
1645
1646 bcmolt_flow_key flow_key;
1647 bcmolt_flow_cfg flow_cfg;
1648
1649 virtual void SetUp() {
1650 flow_key.flow_id = 1;
1651 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1652 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1653 flow_cfg.data.onu_id=1;
1654 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1655 flow_cfg.data.svc_port_id=1024;
1656 flow_cfg.data.priority=0;
1657 flow_cfg.data.cookie=0;
1658 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1659 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1660 flow_cfg.data.ingress_intf.intf_id=0;
1661 flow_cfg.data.egress_intf.intf_id=0;
1662 flow_cfg.data.classifier.o_vid=7;
1663 flow_cfg.data.classifier.o_pbits=0;
1664 flow_cfg.data.classifier.i_vid=0;
1665 flow_cfg.data.classifier.i_pbits=0;
1666 flow_cfg.data.classifier.ether_type=0;
1667 flow_cfg.data.classifier.ip_proto=0;
1668 flow_cfg.data.classifier.src_port=0;
1669 flow_cfg.data.classifier.dst_port=0;
1670 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1671 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1672 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1673 flow_cfg.data.egress_qos.tm_sched.id=1020;
1674 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1675 flow_cfg.data.action.o_vid=12;
1676 flow_cfg.data.action.o_pbits=0;
1677 flow_cfg.data.action.i_vid=0;
1678 flow_cfg.data.action.i_pbits=0;
1679 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1680 }
1681
1682 virtual void TearDown() {
1683 }
1684};
1685
1686// Test 1 - UplinkPacketOut success case
1687TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1688 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1689 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1690 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1691 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1692 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1693
1694 Status status = UplinkPacketOut_(pon_id, pkt);
1695 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1696}
1697
1698// Test 2 - UplinkPacketOut Failure case
1699TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1700 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1701 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1702 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1703 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1704 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1705
1706 Status status = UplinkPacketOut_(pon_id, pkt);
1707 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1708}
1709
1710// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1711TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1712 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1713
1714 FlowRemove_(2, "upstream");
1715 FlowRemove_(3, "upstream");
1716 FlowRemove_(4, "downstream");
1717 FlowRemove_(5, "upstream");
1718 FlowRemove_(6, "downstream");
1719
1720 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1721 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1722 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1723
1724 Status status = UplinkPacketOut_(pon_id, pkt);
1725 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1726}
1727
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001728////////////////////////////////////////////////////////////////////////////
1729// For testing CreateTrafficSchedulers functionality
1730////////////////////////////////////////////////////////////////////////////
1731
1732class TestCreateTrafficSchedulers : public Test {
1733 protected:
1734 NiceMock<BalMocker> balMock;
1735 tech_profile::TrafficSchedulers* traffic_scheds;
1736 tech_profile::TrafficScheduler* traffic_sched;
1737 tech_profile::SchedulerConfig* scheduler;
1738 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1739
1740 virtual void SetUp() {
1741 traffic_scheds = new tech_profile::TrafficSchedulers;
1742 traffic_scheds->set_intf_id(0);
1743 traffic_scheds->set_onu_id(1);
1744 traffic_scheds->set_uni_id(0);
1745 traffic_scheds->set_port_no(16);
1746 traffic_sched = traffic_scheds->add_traffic_scheds();
1747 traffic_sched->set_alloc_id(1024);
1748 scheduler = new tech_profile::SchedulerConfig;
1749 scheduler->set_priority(0);
1750 scheduler->set_weight(0);
1751 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1752 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1753 traffic_shaping_info->set_cbs(60536);
1754 traffic_shaping_info->set_pbs(65536);
1755 traffic_shaping_info->set_gir(10000);
1756 }
1757
1758 virtual void TearDown() {
1759 }
1760
1761 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301762 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1763 alloc_cfg_compltd_key k(0, 1024);
1764 alloc_cfg_complete_result res;
1765 res.pon_intf_id = 0;
1766 res.alloc_id = 1024;
1767 res.state = state;
1768 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001769
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301770 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1771 // before we push the result.
1772 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1773 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1774 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1775 if (it == alloc_cfg_compltd_map.end()) {
1776 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001777 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301778 it->second->push(res);
1779 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001780 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301781 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1782 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001783 }
1784};
1785
1786// Test 1 - CreateTrafficSchedulers-Upstream success case
1787TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1788 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1789 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1790 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1791 traffic_sched->set_allocated_scheduler(scheduler);
1792 traffic_shaping_info->set_cir(64000);
1793 traffic_shaping_info->set_pir(128000);
1794 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1795
1796 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1797 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1798
1799 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301800 future<int> push_alloc_cfg_complt = \
1801 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001802
1803 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301804 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001805 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1806}
1807
1808// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1809TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1810 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1811 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1812 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1813 traffic_sched->set_allocated_scheduler(scheduler);
1814 traffic_shaping_info->set_cir(64000);
1815 traffic_shaping_info->set_pir(128000);
1816 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1817
1818 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1819 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1820
1821 Status status = CreateTrafficSchedulers_(traffic_scheds);
1822 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1823}
1824
1825// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1826TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1827 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1828 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1829 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1830 traffic_sched->set_allocated_scheduler(scheduler);
1831 traffic_shaping_info->set_cir(64000);
1832 traffic_shaping_info->set_pir(128000);
1833 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1834
1835 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1836 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1837
1838 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301839 future<int> push_alloc_cfg_complt = \
1840 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001841
1842 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301843 int res = push_alloc_cfg_complt.get();
1844
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001845 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1846}
1847
1848// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1849TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1850 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1851 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1852 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1853 traffic_sched->set_allocated_scheduler(scheduler);
1854 traffic_shaping_info->set_cir(64000);
1855 traffic_shaping_info->set_pir(128000);
1856 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1857
1858 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1859 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1860
1861 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301862 future<int> push_alloc_cfg_complt = \
1863 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001864
1865 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301866 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001867 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1868}
1869
1870// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1871TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1872 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1873 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1874 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1875 traffic_sched->set_allocated_scheduler(scheduler);
1876 traffic_shaping_info->set_cir(64000);
1877 traffic_shaping_info->set_pir(128000);
1878 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1879
1880 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1881 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1882
1883 Status status = CreateTrafficSchedulers_(traffic_scheds);
1884 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1885}
1886
1887// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1888TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1889 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1890 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1891 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1892 traffic_sched->set_allocated_scheduler(scheduler);
1893 traffic_shaping_info->set_cir(64000);
1894 traffic_shaping_info->set_pir(0);
1895 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1896
1897 Status status = CreateTrafficSchedulers_(traffic_scheds);
1898 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1899}
1900
1901// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1902TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1903 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1904 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1905 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1906 traffic_sched->set_allocated_scheduler(scheduler);
1907 traffic_shaping_info->set_cir(64000);
1908 traffic_shaping_info->set_pir(32000);
1909 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1910
1911 Status status = CreateTrafficSchedulers_(traffic_scheds);
1912 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1913}
1914
1915// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1916TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1917 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1918 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1919 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1920 traffic_sched->set_allocated_scheduler(scheduler);
1921 traffic_shaping_info->set_cir(64000);
1922 traffic_shaping_info->set_pir(64000);
1923 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1924
1925 Status status = CreateTrafficSchedulers_(traffic_scheds);
1926 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1927}
1928
1929// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1930TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1931 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1932 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1933 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1934 traffic_sched->set_allocated_scheduler(scheduler);
1935 traffic_shaping_info->set_cir(64000);
1936 traffic_shaping_info->set_pir(0);
1937 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1938
1939 Status status = CreateTrafficSchedulers_(traffic_scheds);
1940 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1941}
1942
1943// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1944TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1945 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1946 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1947 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1948 traffic_sched->set_allocated_scheduler(scheduler);
1949 traffic_shaping_info->set_cir(0);
1950 traffic_shaping_info->set_pir(32000);
1951 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1952
1953 Status status = CreateTrafficSchedulers_(traffic_scheds);
1954 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1955}
1956
1957// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1958TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1959 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1960 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1961 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1962 traffic_sched->set_allocated_scheduler(scheduler);
1963 traffic_shaping_info->set_cir(64000);
1964 traffic_shaping_info->set_pir(32000);
1965 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1966
1967 Status status = CreateTrafficSchedulers_(traffic_scheds);
1968 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1969}
1970
1971// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1972TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1973 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1974 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1975 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1976 traffic_sched->set_allocated_scheduler(scheduler);
1977 traffic_shaping_info->set_cir(64000);
1978 traffic_shaping_info->set_pir(64000);
1979 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1980
1981 Status status = CreateTrafficSchedulers_(traffic_scheds);
1982 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1983}
1984
1985// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1986TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1987 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1988 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1989 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1990 traffic_sched->set_allocated_scheduler(scheduler);
1991 traffic_shaping_info->set_cir(64000);
1992 traffic_shaping_info->set_pir(0);
1993 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1994
1995 Status status = CreateTrafficSchedulers_(traffic_scheds);
1996 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1997}
1998
1999// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
2000TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
2001 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2002 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2003 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2004 traffic_sched->set_allocated_scheduler(scheduler);
2005 traffic_shaping_info->set_cir(0);
2006 traffic_shaping_info->set_pir(32000);
2007 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2008
2009 Status status = CreateTrafficSchedulers_(traffic_scheds);
2010 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2011}
2012
2013// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
2014TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
2015 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2016 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2017 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2018 traffic_sched->set_allocated_scheduler(scheduler);
2019 traffic_shaping_info->set_cir(64000);
2020 traffic_shaping_info->set_pir(128000);
2021 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2022
2023 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2024 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2025
2026 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302027 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002028 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2029
2030 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302031 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002032 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2033}
2034
2035// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
2036TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
2037 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2038 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2039 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2040 traffic_sched->set_allocated_scheduler(scheduler);
2041 traffic_shaping_info->set_cir(64000);
2042 traffic_shaping_info->set_pir(32000);
2043 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2044
2045 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2046 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2047
2048 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302049 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002050 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2051
2052 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302053 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002054 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2055}
2056
2057// Test 17 - CreateTrafficSchedulers-Downstream success case
2058TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2059 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2060 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2061 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2062 traffic_sched->set_allocated_scheduler(scheduler);
2063 traffic_shaping_info->set_cir(64000);
2064 traffic_shaping_info->set_pir(128000);
2065 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2066
2067 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2068 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2069
2070 Status status = CreateTrafficSchedulers_(traffic_scheds);
2071 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2072}
2073
2074// Test 18 - CreateTrafficSchedulers-Downstream Failure case
2075TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2076 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2077 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2078 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2079 traffic_sched->set_allocated_scheduler(scheduler);
2080 traffic_shaping_info->set_cir(64000);
2081 traffic_shaping_info->set_pir(128000);
2082 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2083
2084 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2085 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2086
2087 Status status = CreateTrafficSchedulers_(traffic_scheds);
2088 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2089}
2090
2091// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
2092TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2093 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2094 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2095 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2096 traffic_sched->set_allocated_scheduler(scheduler);
2097 traffic_shaping_info->set_cir(64000);
2098 traffic_shaping_info->set_pir(128000);
2099 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2100
2101 Status status = CreateTrafficSchedulers_(traffic_scheds);
2102 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2103}
2104
2105////////////////////////////////////////////////////////////////////////////
2106// For testing RemoveTrafficSchedulers functionality
2107////////////////////////////////////////////////////////////////////////////
2108
2109class TestRemoveTrafficSchedulers : public Test {
2110 protected:
2111 NiceMock<BalMocker> balMock;
2112 tech_profile::TrafficSchedulers* traffic_scheds;
2113 tech_profile::TrafficScheduler* traffic_sched;
2114 tech_profile::SchedulerConfig* scheduler;
2115 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2116 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302117 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002118
2119 virtual void SetUp() {
2120 traffic_scheds = new tech_profile::TrafficSchedulers;
2121 traffic_scheds->set_intf_id(0);
2122 traffic_scheds->set_onu_id(1);
2123 traffic_scheds->set_uni_id(0);
2124 traffic_scheds->set_port_no(16);
2125 traffic_sched = traffic_scheds->add_traffic_scheds();
2126 traffic_sched->set_alloc_id(1025);
2127 scheduler = new tech_profile::SchedulerConfig;
2128 scheduler->set_priority(0);
2129 scheduler->set_weight(0);
2130 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2131 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2132 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2133 traffic_shaping_info->set_cir(64000);
2134 traffic_shaping_info->set_pir(128000);
2135 traffic_shaping_info->set_cbs(60536);
2136 traffic_shaping_info->set_pbs(65536);
2137 traffic_shaping_info->set_gir(10000);
2138 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2139 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2140 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2141 }
2142
2143 virtual void TearDown() {
2144 }
2145
2146 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302147 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2148 alloc_cfg_compltd_key k(0, 1025);
2149 alloc_cfg_complete_result res;
2150 res.pon_intf_id = 0;
2151 res.alloc_id = 1025;
2152 res.state = state;
2153 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002154
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302155 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2156 // before we push the result.
2157 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302158 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2159 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2160 if (it == alloc_cfg_compltd_map.end()) {
2161 OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002162 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302163 it->second->push(res);
2164 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002165 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302166 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2167 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002168 }
2169};
2170
2171// Test 1 - RemoveTrafficSchedulers-Upstream success case
2172TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2173 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2174 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2175 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2176
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302177 bcmolt_pon_interface_key pon_key;
2178 bcmolt_pon_interface_cfg pon_cfg;
2179 pon_key.pon_ni = pon_id;
2180 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2181 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2182 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2183 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2184 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2185
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002186 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302187 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002188 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2189
2190 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302191 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002192 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2193}
2194
2195// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2196TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2197 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2198 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2199 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2200
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302201 bcmolt_pon_interface_key pon_key;
2202 bcmolt_pon_interface_cfg pon_cfg;
2203 pon_key.pon_ni = pon_id;
2204 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2205 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2206 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2207 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2208 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2209
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002210 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302211 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002212 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2213
2214 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302215 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002216 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2217}
2218
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302219// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2220TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2221 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2222 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2223 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2224
2225 bcmolt_pon_interface_key pon_key;
2226 bcmolt_pon_interface_cfg pon_cfg;
2227 pon_key.pon_ni = pon_id;
2228 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2229 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2230 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2231 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2232 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2233
2234 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2235
2236 Status status = future_res.get();
2237 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2238}
2239
2240// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2241TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2242 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2243 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2244 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2245
2246 bcmolt_pon_interface_key pon_key;
2247 bcmolt_pon_interface_cfg pon_cfg;
2248 pon_key.pon_ni = pon_id;
2249 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2250 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2251 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2252 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2253 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2254
2255 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2256
2257 Status status = future_res.get();
2258 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2259}
2260
2261// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002262TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2263 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2264
2265 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2266 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2267
2268 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2269 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2270}
2271
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302272// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002273TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2274 //Create Scheduler
2275 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2276 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2277 traffic_sched->set_allocated_scheduler(scheduler);
2278 CreateTrafficSchedulers_(traffic_scheds);
2279
2280 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2281 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2282
2283 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2284 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2285}
2286
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302287// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002288TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2289 //Create Scheduler
2290 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2291 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2292 traffic_sched->set_allocated_scheduler(scheduler);
2293 CreateTrafficSchedulers_(traffic_scheds);
2294
2295 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2296 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2297
2298 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2299 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2300}
2301
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302302// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002303TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2304 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2305
2306 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2307 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2308}
2309
2310////////////////////////////////////////////////////////////////////////////
2311// For testing CreateTrafficQueues functionality
2312////////////////////////////////////////////////////////////////////////////
2313
2314class TestCreateTrafficQueues : public Test {
2315 protected:
2316 NiceMock<BalMocker> balMock;
2317 tech_profile::TrafficQueues* traffic_queues;
2318 tech_profile::TrafficQueue* traffic_queue_1;
2319 tech_profile::TrafficQueue* traffic_queue_2;
2320 tech_profile::DiscardConfig* discard_config_1;
2321 tech_profile::DiscardConfig* discard_config_2;
2322 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2323 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2324
2325 virtual void SetUp() {
2326 traffic_queues = new tech_profile::TrafficQueues;
2327 traffic_queues->set_intf_id(0);
2328 traffic_queues->set_onu_id(1);
2329 traffic_queue_1 = traffic_queues->add_traffic_queues();
2330 traffic_queue_1->set_gemport_id(1024);
2331 traffic_queue_1->set_pbit_map("0b00000101");
2332 traffic_queue_1->set_aes_encryption(true);
2333 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2334 traffic_queue_1->set_priority(0);
2335 traffic_queue_1->set_weight(0);
2336 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2337 discard_config_1 = new tech_profile::DiscardConfig;
2338 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2339 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2340 tail_drop_discard_config_1->set_queue_size(8);
2341 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2342 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2343 }
2344
2345 virtual void TearDown() {
2346 }
2347};
2348
2349// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2350TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2351 Status status;
2352 traffic_queues->set_uni_id(0);
2353 traffic_queues->set_port_no(16);
2354 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2355
2356 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2357 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2358
2359 status = CreateTrafficQueues_(traffic_queues);
2360 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2361
2362 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2363 status = CreateTrafficQueues_(traffic_queues);
2364 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2365}
2366
2367// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2368TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2369 traffic_queues->set_uni_id(1);
2370 traffic_queues->set_port_no(32);
2371 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2372
2373 traffic_queue_2 = traffic_queues->add_traffic_queues();
2374 traffic_queue_2->set_gemport_id(1025);
2375 traffic_queue_2->set_pbit_map("0b00001010");
2376 traffic_queue_2->set_aes_encryption(true);
2377 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2378 traffic_queue_2->set_priority(1);
2379 traffic_queue_2->set_weight(0);
2380 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2381 discard_config_2 = new tech_profile::DiscardConfig;
2382 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2383 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2384 tail_drop_discard_config_2->set_queue_size(8);
2385 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2386 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2387 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2388
2389 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2390 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2391
2392 Status status = CreateTrafficQueues_(traffic_queues);
2393 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2394}
2395
2396// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2397TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2398 traffic_queues->set_uni_id(2);
2399 traffic_queues->set_port_no(16);
2400 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2401
2402 traffic_queue_2 = traffic_queues->add_traffic_queues();
2403 traffic_queue_2->set_gemport_id(1025);
2404 traffic_queue_2->set_pbit_map("0b10001010");
2405 traffic_queue_2->set_aes_encryption(true);
2406 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2407 traffic_queue_2->set_priority(1);
2408 traffic_queue_2->set_weight(0);
2409 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2410 discard_config_2 = new tech_profile::DiscardConfig;
2411 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2412 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2413 tail_drop_discard_config_2->set_queue_size(8);
2414 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2415 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2416 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2417
2418 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2419 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2420
2421 Status status = CreateTrafficQueues_(traffic_queues);
2422 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2423}
2424
2425// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2426TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2427 traffic_queues->set_uni_id(3);
2428 traffic_queues->set_port_no(16);
2429 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2430
2431 traffic_queue_2 = traffic_queues->add_traffic_queues();
2432 traffic_queue_2->set_gemport_id(1025);
2433 traffic_queue_2->set_pbit_map("0b00001010");
2434 traffic_queue_2->set_aes_encryption(true);
2435 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2436 traffic_queue_2->set_priority(1);
2437 traffic_queue_2->set_weight(0);
2438 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2439 discard_config_2 = new tech_profile::DiscardConfig;
2440 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2441 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2442 tail_drop_discard_config_2->set_queue_size(8);
2443 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2444 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2445 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2446
2447 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2448 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2449
2450 Status status = CreateTrafficQueues_(traffic_queues);
2451 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2452}
2453
2454// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2455TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2456 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2457 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2458 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2459
2460 traffic_queue_2 = traffic_queues->add_traffic_queues();
2461 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2462 traffic_queues->set_uni_id(uni_ids[i]);
2463 traffic_queues->set_port_no(port_nos[i]);
2464 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2465
2466 traffic_queue_2->set_gemport_id(1025);
2467 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2468 traffic_queue_2->set_aes_encryption(true);
2469 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2470 traffic_queue_2->set_priority(1);
2471 traffic_queue_2->set_weight(0);
2472 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2473 discard_config_2 = new tech_profile::DiscardConfig;
2474 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2475 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2476 tail_drop_discard_config_2->set_queue_size(8);
2477 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2478 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2479 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2480
2481 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2482 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2483
2484 Status status = CreateTrafficQueues_(traffic_queues);
2485 if(i==16)
2486 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2487 else
2488 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2489 }
2490}
2491
2492// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2493TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2494 traffic_queues->set_uni_id(0);
2495 traffic_queues->set_port_no(16);
2496 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2497
2498 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2499 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2500
2501 Status status = CreateTrafficQueues_(traffic_queues);
2502 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2503}
2504
2505////////////////////////////////////////////////////////////////////////////
2506// For testing RemoveTrafficQueues functionality
2507////////////////////////////////////////////////////////////////////////////
2508
2509class TestRemoveTrafficQueues : public Test {
2510 protected:
2511 NiceMock<BalMocker> balMock;
2512 tech_profile::TrafficQueues* traffic_queues;
2513 tech_profile::TrafficQueue* traffic_queue_1;
2514 tech_profile::TrafficQueue* traffic_queue_2;
2515
2516 virtual void SetUp() {
2517 traffic_queues = new tech_profile::TrafficQueues;
2518 traffic_queues->set_intf_id(0);
2519 traffic_queues->set_onu_id(1);
2520 traffic_queue_1 = traffic_queues->add_traffic_queues();
2521 traffic_queue_1->set_gemport_id(1024);
2522 traffic_queue_1->set_priority(0);
2523 }
2524
2525 virtual void TearDown() {
2526 }
2527};
2528
2529// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2530TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2531 Status status;
2532 traffic_queues->set_uni_id(0);
2533 traffic_queues->set_port_no(16);
2534 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2535
2536 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2537 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2538
2539 status = RemoveTrafficQueues_(traffic_queues);
2540 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2541
2542 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2543 status = RemoveTrafficQueues_(traffic_queues);
2544 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2545}
2546
2547// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2548TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2549 Status status;
2550 traffic_queues->set_uni_id(0);
2551 traffic_queues->set_port_no(16);
2552 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2553
2554 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2555 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2556
2557 status = RemoveTrafficQueues_(traffic_queues);
2558 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2559}
2560
2561// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2562TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2563 //Remove scheduler so that is_tm_sched_id_present api call will return false
2564 tech_profile::TrafficSchedulers* traffic_scheds;
2565 tech_profile::TrafficScheduler* traffic_sched;
2566 traffic_scheds = new tech_profile::TrafficSchedulers;
2567 traffic_scheds->set_intf_id(0);
2568 traffic_scheds->set_onu_id(1);
2569 traffic_scheds->set_uni_id(0);
2570 traffic_scheds->set_port_no(16);
2571 traffic_sched = traffic_scheds->add_traffic_scheds();
2572 traffic_sched->set_alloc_id(1024);
2573 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2574
2575 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2576 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2577 RemoveTrafficSchedulers_(traffic_scheds);
2578
2579 traffic_queues->set_uni_id(0);
2580 traffic_queues->set_port_no(16);
2581 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2582
2583 Status status = RemoveTrafficQueues_(traffic_queues);
2584 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2585}
2586
2587/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2588as it is getting referred by some other queues case */
2589TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2590 traffic_queues->set_uni_id(3);
2591 traffic_queues->set_port_no(16);
2592 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2593 traffic_queue_2 = traffic_queues->add_traffic_queues();
2594 traffic_queue_2->set_gemport_id(1025);
2595 traffic_queue_2->set_priority(1);
2596 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2597
2598 Status status = RemoveTrafficQueues_(traffic_queues);
2599 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2600}
2601
2602/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2603is not getting referred by any other queues case */
2604TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2605 traffic_queues->set_uni_id(1);
2606 traffic_queues->set_port_no(32);
2607 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2608 traffic_queue_2 = traffic_queues->add_traffic_queues();
2609 traffic_queue_2->set_gemport_id(1025);
2610 traffic_queue_2->set_priority(1);
2611
2612 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2613 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2614
2615 Status status = RemoveTrafficQueues_(traffic_queues);
2616 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2617}
2618
2619/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2620having no reference to any other queues case */
2621TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2622 traffic_queues->set_uni_id(4);
2623 traffic_queues->set_port_no(64);
2624 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2625 traffic_queue_2 = traffic_queues->add_traffic_queues();
2626 traffic_queue_2->set_gemport_id(1025);
2627 traffic_queue_2->set_priority(1);
2628
2629 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2630 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2631
2632 Status status = RemoveTrafficQueues_(traffic_queues);
2633 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2634}