blob: 5082fac4eb8b6c34311164b582e2fe21757a70c4 [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
841// Test 1 - ActivateOnu success case
842TEST_F(TestActivateOnu, ActivateOnuSuccess) {
843 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
844 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
845 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
846
847 bcmolt_onu_cfg onu_cfg;
848 bcmolt_onu_key onu_key;
849 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
850 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
851 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
852 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
853
854 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
855 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
856
857 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
858 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
859}
860
861// Test 2 - ActivateOnu failure case
862TEST_F(TestActivateOnu, ActivateOnuFailure) {
863 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
864 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
865 bcmos_errno onu_cfg_set_res = BCM_ERR_INTERNAL;
866
867 bcmolt_onu_cfg onu_cfg;
868 bcmolt_onu_key onu_key;
869 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
870 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
871 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
872 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
873
874 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
875 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
876
877 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
878 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
879}
880
881// Test 3 - ActivateOnu - Onu already under processing case
882TEST_F(TestActivateOnu, ActivateOnuProcessing) {
883 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
884 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
885
886 bcmolt_onu_cfg onu_cfg;
887 bcmolt_onu_key onu_key;
888 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
889 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
890 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
891 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
892 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
893
894 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
895 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
896}
897
898////////////////////////////////////////////////////////////////////////////
899// For testing DeactivateOnu functionality
900////////////////////////////////////////////////////////////////////////////
901
902class TestDeactivateOnu : public Test {
903 protected:
904 uint32_t pon_id = 0;
905 uint32_t onu_id = 1;
906 std::string vendor_id = "TWSH";
907 std::string vendor_specific = "80808080";
908 NiceMock<BalMocker> balMock;
909
910 virtual void SetUp() {
911 }
912
913 virtual void TearDown() {
914 }
915};
916
917// Test 1 - DeactivateOnu success case
918TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
919 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
920 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
921
922 bcmolt_onu_cfg onu_cfg;
923 bcmolt_onu_key onu_key;
924 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
925 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
926 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
927 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
928
929 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
930
931 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
932 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
933}
934
935// Test 2 - DeactivateOnu failure case
936TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
937 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
938 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
939
940 bcmolt_onu_cfg onu_cfg;
941 bcmolt_onu_key onu_key;
942 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
943 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
944 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
945 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
946
947 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
948
949 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
950 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
951}
952
953////////////////////////////////////////////////////////////////////////////
954// For testing DeleteOnu functionality
955////////////////////////////////////////////////////////////////////////////
956
957class TestDeleteOnu : public Test {
958 protected:
959 uint32_t pon_id = 0;
960 uint32_t onu_id = 1;
961 std::string vendor_id = "TWSH";
962 std::string vendor_specific = "80808080";
963 NiceMock<BalMocker> balMock;
964
965 virtual void SetUp() {
966 }
967
968 virtual void TearDown() {
969 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530970 public:
971 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
972 onu_deactivate_complete_result res;
973 res.pon_intf_id = 0;
974 res.onu_id = 1;
975 res.result = result;
976 res.reason = reason;
977 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
978 // before we push the result.
979 std::this_thread::sleep_for(std::chrono::milliseconds(100));
980 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
981 onu_deact_compltd_key k(0, 1);
982 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
983 if (it == onu_deact_compltd_map.end()) {
984 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
985 } else {
986 it->second->push(res);
987 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
988 }
989 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
990 return 0;
991 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500992};
993
994// Test 1 - DeleteOnu success case
995TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
996 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
997 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
998 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
999
1000 bcmolt_onu_cfg onu_cfg;
1001 bcmolt_onu_key onu_key;
1002 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1003 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1004 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301005 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001006
1007 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1008 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1009
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301010 future<int> push_onu_deact_complt_res = \
1011 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1012 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1013 Status status = future_res.get();
1014 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001015 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1016}
1017
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301018// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1019TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001020 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1021 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1022 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1023
1024 bcmolt_onu_cfg onu_cfg;
1025 bcmolt_onu_key onu_key;
1026 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1027 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1028 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301029 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001030
1031 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1032 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1033
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301034 future<int> push_onu_deact_complt_res = \
1035 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1036 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1037
1038 Status status = future_res.get();
1039 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001040 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1041}
1042
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301043// Test 3 - DeleteOnu failure case - onu deactivation fails
1044TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
1045 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1046 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1047
1048 bcmolt_onu_cfg onu_cfg;
1049 bcmolt_onu_key onu_key;
1050 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1051 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1052 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301053 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301054
1055 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1056
1057 future<int> push_onu_deact_complt_res = \
1058 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1059 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1060
1061 Status status = future_res.get();
1062 int res = push_onu_deact_complt_res.get();
1063 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1064}
1065
1066// Test 4 - DeleteOnu failure case - onu deactivation timesout
1067TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
1068 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1069 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1070
1071 bcmolt_onu_cfg onu_cfg;
1072 bcmolt_onu_key onu_key;
1073 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1074 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1075 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301076 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301077
1078 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1079
1080 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1081
1082 Status status = future_res.get();
1083 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1084}
1085
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301086// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1087TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
1088 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1089 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1090 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1091
1092 bcmolt_onu_cfg onu_cfg;
1093 bcmolt_onu_key onu_key;
1094 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1095 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1096 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1097 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1098
1099 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1100 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1101
1102 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1103
1104 Status status = future_res.get();
1105 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1106}
1107
1108// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1109TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1110 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1111
1112 bcmolt_onu_cfg onu_cfg;
1113 bcmolt_onu_key onu_key;
1114 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1115 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1116 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1117 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1118
1119 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1120
1121 Status status = future_res.get();
1122 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1123}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301124
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001125////////////////////////////////////////////////////////////////////////////
1126// For testing OmciMsgOut functionality
1127////////////////////////////////////////////////////////////////////////////
1128
1129class TestOmciMsgOut : public Test {
1130 protected:
1131 uint32_t pon_id = 0;
1132 uint32_t onu_id = 1;
1133 std::string pkt = "omci-pkt";
1134 NiceMock<BalMocker> balMock;
1135
1136 virtual void SetUp() {
1137 }
1138
1139 virtual void TearDown() {
1140 }
1141};
1142
1143// Test 1 - OmciMsgOut success case
1144TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1145 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1146
1147 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1148
1149 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1150 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1151}
1152
1153// Test 1 - OmciMsgOut failure case
1154TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1155 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1156
1157 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1158
1159 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1160 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1161}
1162
Girish Gowdra489425a2020-02-22 13:07:42 +05301163// TODO: VOL-2494
Jason Huang09b73ea2020-01-08 17:52:05 +08001164#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001165////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001166// For testing FlowAdd functionality
1167////////////////////////////////////////////////////////////////////////////
1168
1169class TestFlowAdd : public Test {
1170 protected:
1171 int32_t access_intf_id = 0;
1172 int32_t onu_id = 1;
1173 int32_t uni_id = 0;
1174 uint32_t port_no = 16;
1175 uint32_t flow_id = 1;
1176 std::string flow_type = "upstream";
1177 int32_t alloc_id = 1024;
1178 int32_t network_intf_id = 0;
1179 int32_t gemport_id = 1024;
1180 int32_t priority_value = 0;
1181 uint64_t cookie = 0;
1182
1183 NiceMock<BalMocker> balMock;
1184 openolt::Flow* flow;
1185 openolt::Classifier* classifier;
1186 openolt::Action* action;
1187 openolt::ActionCmd* cmd;
1188
1189 bcmolt_flow_key flow_key;
1190 bcmolt_flow_cfg flow_cfg;
1191
1192 tech_profile::TrafficQueues* traffic_queues;
1193 tech_profile::TrafficQueue* traffic_queue_1;
1194 tech_profile::TrafficQueue* traffic_queue_2;
1195 tech_profile::DiscardConfig* discard_config_1;
1196 tech_profile::DiscardConfig* discard_config_2;
1197 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1198 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1199
1200
1201 virtual void SetUp() {
1202 classifier = new openolt::Classifier;
1203 action = new openolt::Action;
1204 cmd = new openolt::ActionCmd;
1205
1206 classifier->set_o_tpid(0);
1207 classifier->set_o_vid(7);
1208 classifier->set_i_tpid(0);
1209 classifier->set_i_vid(0);
1210 classifier->set_o_pbits(0);
1211 classifier->set_i_pbits(0);
1212 classifier->set_eth_type(0);
1213 classifier->set_ip_proto(0);
1214 classifier->set_src_port(0);
1215 classifier->set_dst_port(0);
1216 classifier->set_pkt_tag_type("single_tag");
1217
1218 action->set_o_vid(12);
1219 action->set_o_pbits(0);
1220 action->set_o_tpid(0);
1221 action->set_i_vid(0);
1222 action->set_i_pbits(0);
1223 action->set_i_tpid(0);
1224
1225 cmd->set_add_outer_tag(true);
1226 cmd->set_remove_outer_tag(false);
1227 cmd->set_trap_to_host(false);
1228 action->set_allocated_cmd(cmd);
1229
1230 flow_key.flow_id = 1;
1231 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1232 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1233 flow_cfg.data.onu_id=1;
1234 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1235 flow_cfg.data.svc_port_id=1024;
1236 flow_cfg.data.priority=0;
1237 flow_cfg.data.cookie=0;
1238 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1239 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1240 flow_cfg.data.ingress_intf.intf_id=0;
1241 flow_cfg.data.egress_intf.intf_id=0;
1242 flow_cfg.data.classifier.o_vid=7;
1243 flow_cfg.data.classifier.o_pbits=0;
1244 flow_cfg.data.classifier.i_vid=0;
1245 flow_cfg.data.classifier.i_pbits=0;
1246 flow_cfg.data.classifier.ether_type=0;
1247 flow_cfg.data.classifier.ip_proto=0;
1248 flow_cfg.data.classifier.src_port=0;
1249 flow_cfg.data.classifier.dst_port=0;
1250 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1251 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1252 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1253 flow_cfg.data.egress_qos.tm_sched.id=1020;
1254 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1255 flow_cfg.data.action.o_vid=12;
1256 flow_cfg.data.action.o_pbits=0;
1257 flow_cfg.data.action.i_vid=0;
1258 flow_cfg.data.action.i_pbits=0;
1259 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1260
1261 traffic_queues = new tech_profile::TrafficQueues;
1262 traffic_queues->set_intf_id(0);
1263 traffic_queues->set_onu_id(2);
1264 traffic_queue_1 = traffic_queues->add_traffic_queues();
1265 traffic_queue_1->set_gemport_id(1024);
1266 traffic_queue_1->set_pbit_map("0b00000101");
1267 traffic_queue_1->set_aes_encryption(true);
1268 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1269 traffic_queue_1->set_priority(0);
1270 traffic_queue_1->set_weight(0);
1271 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1272 discard_config_1 = new tech_profile::DiscardConfig;
1273 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1274 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1275 tail_drop_discard_config_1->set_queue_size(8);
1276 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1277 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1278
1279 traffic_queues->set_uni_id(0);
1280 traffic_queues->set_port_no(16);
1281
1282 traffic_queue_2 = traffic_queues->add_traffic_queues();
1283 traffic_queue_2->set_gemport_id(1025);
1284 traffic_queue_2->set_pbit_map("0b00001010");
1285 traffic_queue_2->set_aes_encryption(true);
1286 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1287 traffic_queue_2->set_priority(1);
1288 traffic_queue_2->set_weight(0);
1289 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1290 discard_config_2 = new tech_profile::DiscardConfig;
1291 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1292 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1293 tail_drop_discard_config_2->set_queue_size(8);
1294 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1295 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1296 }
1297
1298 virtual void TearDown() {
1299 }
1300};
1301
1302// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1303TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1304 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1305 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1306
1307 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1308 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1309}
1310
1311// Test 2 - FlowAdd - Duplicate Flow case
1312TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1313 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1314 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1315 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1316
1317 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1318 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1319}
1320
1321// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1322TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1323 gemport_id = 1025;
1324
1325 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1326 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1327
1328 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1329 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1330 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1331
1332 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1333 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1334}
1335
1336// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1337TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1338 flow_type = "bidirectional";
1339
1340 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1341 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1342}
1343
1344// Test 5 - FlowAdd - Failure case(Invalid network setting)
1345TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1346 network_intf_id = -1;
1347
1348 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1349 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1350}
1351
1352// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1353TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1354 flow_id = 2;
1355
1356 classifier->set_eth_type(34958);
1357 cmd->set_add_outer_tag(false);
1358 cmd->set_trap_to_host(true);
1359 action->set_allocated_cmd(cmd);
1360
1361 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1362 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1363 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1364 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1365 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1366
1367 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1368 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1369}
1370
1371// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1372TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1373 flow_id = 3;
1374 gemport_id = 1025;
1375
1376 classifier->set_ip_proto(17);
1377 classifier->set_src_port(68);
1378 classifier->set_dst_port(67);
1379 cmd->set_add_outer_tag(false);
1380 cmd->set_trap_to_host(true);
1381 action->set_allocated_cmd(cmd);
1382
1383 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1384 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1385 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1386 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1387 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1388
1389 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1390 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1391}
1392
1393// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1394TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1395 flow_id = 4;
1396 flow_type = "downstream";
1397
1398 classifier->set_o_vid(12);
1399 classifier->set_i_vid(7);
1400 classifier->set_pkt_tag_type("double_tag");
1401 action->set_o_vid(0);
1402 cmd->set_add_outer_tag(false);
1403 cmd->set_remove_outer_tag(true);
1404 action->set_allocated_cmd(cmd);
1405
1406 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1407 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1408 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1409 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1410 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1411
1412 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1413 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1414}
1415
1416// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1417TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1418 onu_id = 2;
1419 flow_id = 5;
1420 alloc_id = 1025;
1421
1422 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1423 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1424
1425 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1426 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1427 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1428 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1429 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1430 CreateTrafficQueues_(traffic_queues);
1431
1432 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1433 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1434}
1435
1436// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1437TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1438 onu_id = 2;
1439 flow_id = 6;
1440 flow_type = "downstream";
1441 alloc_id = 1025;
1442
1443 classifier->set_o_vid(12);
1444 classifier->set_i_vid(7);
1445 classifier->set_pkt_tag_type("double_tag");
1446 action->set_o_vid(0);
1447 cmd->set_add_outer_tag(false);
1448 cmd->set_remove_outer_tag(true);
1449 action->set_allocated_cmd(cmd);
1450
1451 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1452 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1453
1454 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1455 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1456 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1457 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1458 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1459 CreateTrafficQueues_(traffic_queues);
1460
1461 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1462 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1463}
Jason Huang09b73ea2020-01-08 17:52:05 +08001464#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001465
1466////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001467// For testing OnuPacketOut functionality
1468////////////////////////////////////////////////////////////////////////////
1469
1470class TestOnuPacketOut : public Test {
1471 protected:
1472 uint32_t pon_id = 0;
1473 uint32_t onu_id = 1;
1474 std::string pkt = "omci-pkt";
1475 NiceMock<BalMocker> balMock;
1476
1477 virtual void SetUp() {
1478 }
1479
1480 virtual void TearDown() {
1481 }
1482};
1483
1484// Test 1 - OnuPacketOut success case
1485TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1486 uint32_t port_no = 16;
1487 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001488
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001489 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001490 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1491
1492 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1493 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1494}
1495
1496// Test 2 - OnuPacketOut Port number as 0 case
1497TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1498 uint32_t port_no = 0;
1499 uint32_t gemport_id = 1024;
1500
1501 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1502 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1503}
1504
Girish Gowdra489425a2020-02-22 13:07:42 +05301505// TODO: VOL-2494
1506#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001507// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1508TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1509 uint32_t port_no = 16;
1510 uint32_t gemport_id = 0;
1511
1512 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1513 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1514
1515 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1516 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1517}
Girish Gowdra489425a2020-02-22 13:07:42 +05301518#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001519
1520// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1521TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1522 uint32_t port_no = 64;
1523 uint32_t gemport_id = 0;
1524
1525 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1526 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1527
1528 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1529 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1530}
1531
Girish Gowdra489425a2020-02-22 13:07:42 +05301532// TODO: VOL-2494
Jason Huang09b73ea2020-01-08 17:52:05 +08001533#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001534////////////////////////////////////////////////////////////////////////////
1535// For testing FlowRemove functionality
1536////////////////////////////////////////////////////////////////////////////
1537
1538class TestFlowRemove : public Test {
1539 protected:
1540 NiceMock<BalMocker> balMock;
1541
1542 virtual void SetUp() {
1543 }
1544
1545 virtual void TearDown() {
1546 }
1547};
1548
1549// Test 1 - FlowRemove - Failure case
1550TEST_F(TestFlowRemove, FlowRemoveFailure) {
1551 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1552 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1553
1554 Status status = FlowRemove_(1, "upstream");
1555 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1556}
1557
1558// Test 2 - FlowRemove - success case
1559TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1560 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1561 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1562
1563 Status status = FlowRemove_(1, "upstream");
1564 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1565}
1566
1567////////////////////////////////////////////////////////////////////////////
1568// For testing UplinkPacketOut functionality
1569////////////////////////////////////////////////////////////////////////////
1570
1571class TestUplinkPacketOut : public Test {
1572 protected:
1573 uint32_t pon_id = 0;
1574 std::string pkt = "omci-pkt";
1575 NiceMock<BalMocker> balMock;
1576
1577 bcmolt_flow_key flow_key;
1578 bcmolt_flow_cfg flow_cfg;
1579
1580 virtual void SetUp() {
1581 flow_key.flow_id = 1;
1582 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1583 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1584 flow_cfg.data.onu_id=1;
1585 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1586 flow_cfg.data.svc_port_id=1024;
1587 flow_cfg.data.priority=0;
1588 flow_cfg.data.cookie=0;
1589 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1590 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1591 flow_cfg.data.ingress_intf.intf_id=0;
1592 flow_cfg.data.egress_intf.intf_id=0;
1593 flow_cfg.data.classifier.o_vid=7;
1594 flow_cfg.data.classifier.o_pbits=0;
1595 flow_cfg.data.classifier.i_vid=0;
1596 flow_cfg.data.classifier.i_pbits=0;
1597 flow_cfg.data.classifier.ether_type=0;
1598 flow_cfg.data.classifier.ip_proto=0;
1599 flow_cfg.data.classifier.src_port=0;
1600 flow_cfg.data.classifier.dst_port=0;
1601 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1602 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1603 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1604 flow_cfg.data.egress_qos.tm_sched.id=1020;
1605 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1606 flow_cfg.data.action.o_vid=12;
1607 flow_cfg.data.action.o_pbits=0;
1608 flow_cfg.data.action.i_vid=0;
1609 flow_cfg.data.action.i_pbits=0;
1610 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1611 }
1612
1613 virtual void TearDown() {
1614 }
1615};
1616
1617// Test 1 - UplinkPacketOut success case
1618TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1619 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1620 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1621 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1622 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1623 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1624
1625 Status status = UplinkPacketOut_(pon_id, pkt);
1626 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1627}
1628
1629// Test 2 - UplinkPacketOut Failure case
1630TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1631 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1632 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1633 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1634 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1635 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1636
1637 Status status = UplinkPacketOut_(pon_id, pkt);
1638 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1639}
1640
1641// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1642TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1643 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1644
1645 FlowRemove_(2, "upstream");
1646 FlowRemove_(3, "upstream");
1647 FlowRemove_(4, "downstream");
1648 FlowRemove_(5, "upstream");
1649 FlowRemove_(6, "downstream");
1650
1651 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1652 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1653 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1654
1655 Status status = UplinkPacketOut_(pon_id, pkt);
1656 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1657}
Jason Huang09b73ea2020-01-08 17:52:05 +08001658#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001659
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001660////////////////////////////////////////////////////////////////////////////
1661// For testing CreateTrafficSchedulers functionality
1662////////////////////////////////////////////////////////////////////////////
1663
1664class TestCreateTrafficSchedulers : public Test {
1665 protected:
1666 NiceMock<BalMocker> balMock;
1667 tech_profile::TrafficSchedulers* traffic_scheds;
1668 tech_profile::TrafficScheduler* traffic_sched;
1669 tech_profile::SchedulerConfig* scheduler;
1670 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1671
1672 virtual void SetUp() {
1673 traffic_scheds = new tech_profile::TrafficSchedulers;
1674 traffic_scheds->set_intf_id(0);
1675 traffic_scheds->set_onu_id(1);
1676 traffic_scheds->set_uni_id(0);
1677 traffic_scheds->set_port_no(16);
1678 traffic_sched = traffic_scheds->add_traffic_scheds();
1679 traffic_sched->set_alloc_id(1024);
1680 scheduler = new tech_profile::SchedulerConfig;
1681 scheduler->set_priority(0);
1682 scheduler->set_weight(0);
1683 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1684 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1685 traffic_shaping_info->set_cbs(60536);
1686 traffic_shaping_info->set_pbs(65536);
1687 traffic_shaping_info->set_gir(10000);
1688 }
1689
1690 virtual void TearDown() {
1691 }
1692
1693 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301694 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1695 alloc_cfg_compltd_key k(0, 1024);
1696 alloc_cfg_complete_result res;
1697 res.pon_intf_id = 0;
1698 res.alloc_id = 1024;
1699 res.state = state;
1700 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001701
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301702 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1703 // before we push the result.
1704 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1705 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1706 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1707 if (it == alloc_cfg_compltd_map.end()) {
1708 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 -05001709 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301710 it->second->push(res);
1711 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001712 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301713 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1714 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001715 }
1716};
1717
1718// Test 1 - CreateTrafficSchedulers-Upstream success case
1719TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1720 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1721 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1722 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1723 traffic_sched->set_allocated_scheduler(scheduler);
1724 traffic_shaping_info->set_cir(64000);
1725 traffic_shaping_info->set_pir(128000);
1726 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1727
1728 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1729 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1730
1731 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301732 future<int> push_alloc_cfg_complt = \
1733 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001734
1735 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301736 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001737 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1738}
1739
1740// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1741TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1742 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1743 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1744 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1745 traffic_sched->set_allocated_scheduler(scheduler);
1746 traffic_shaping_info->set_cir(64000);
1747 traffic_shaping_info->set_pir(128000);
1748 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1749
1750 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1751 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1752
1753 Status status = CreateTrafficSchedulers_(traffic_scheds);
1754 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1755}
1756
1757// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1758TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1759 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1760 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1761 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1762 traffic_sched->set_allocated_scheduler(scheduler);
1763 traffic_shaping_info->set_cir(64000);
1764 traffic_shaping_info->set_pir(128000);
1765 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1766
1767 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1768 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1769
1770 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301771 future<int> push_alloc_cfg_complt = \
1772 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001773
1774 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301775 int res = push_alloc_cfg_complt.get();
1776
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001777 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1778}
1779
1780// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1781TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1782 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1783 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1784 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1785 traffic_sched->set_allocated_scheduler(scheduler);
1786 traffic_shaping_info->set_cir(64000);
1787 traffic_shaping_info->set_pir(128000);
1788 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1789
1790 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1791 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1792
1793 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301794 future<int> push_alloc_cfg_complt = \
1795 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001796
1797 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301798 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001799 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1800}
1801
1802// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1803TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1804 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1805 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1806 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1807 traffic_sched->set_allocated_scheduler(scheduler);
1808 traffic_shaping_info->set_cir(64000);
1809 traffic_shaping_info->set_pir(128000);
1810 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1811
1812 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1813 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1814
1815 Status status = CreateTrafficSchedulers_(traffic_scheds);
1816 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1817}
1818
1819// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1820TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1821 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1822 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1823 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1824 traffic_sched->set_allocated_scheduler(scheduler);
1825 traffic_shaping_info->set_cir(64000);
1826 traffic_shaping_info->set_pir(0);
1827 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1828
1829 Status status = CreateTrafficSchedulers_(traffic_scheds);
1830 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1831}
1832
1833// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1834TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1835 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1836 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1837 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1838 traffic_sched->set_allocated_scheduler(scheduler);
1839 traffic_shaping_info->set_cir(64000);
1840 traffic_shaping_info->set_pir(32000);
1841 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1842
1843 Status status = CreateTrafficSchedulers_(traffic_scheds);
1844 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1845}
1846
1847// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1848TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1849 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1850 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1851 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1852 traffic_sched->set_allocated_scheduler(scheduler);
1853 traffic_shaping_info->set_cir(64000);
1854 traffic_shaping_info->set_pir(64000);
1855 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1856
1857 Status status = CreateTrafficSchedulers_(traffic_scheds);
1858 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1859}
1860
1861// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1862TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1863 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1864 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1865 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1866 traffic_sched->set_allocated_scheduler(scheduler);
1867 traffic_shaping_info->set_cir(64000);
1868 traffic_shaping_info->set_pir(0);
1869 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1870
1871 Status status = CreateTrafficSchedulers_(traffic_scheds);
1872 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1873}
1874
1875// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1876TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1877 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1878 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1879 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1880 traffic_sched->set_allocated_scheduler(scheduler);
1881 traffic_shaping_info->set_cir(0);
1882 traffic_shaping_info->set_pir(32000);
1883 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1884
1885 Status status = CreateTrafficSchedulers_(traffic_scheds);
1886 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1887}
1888
1889// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1890TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1891 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1892 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1893 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1894 traffic_sched->set_allocated_scheduler(scheduler);
1895 traffic_shaping_info->set_cir(64000);
1896 traffic_shaping_info->set_pir(32000);
1897 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1898
1899 Status status = CreateTrafficSchedulers_(traffic_scheds);
1900 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1901}
1902
1903// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1904TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1905 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1906 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1907 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1908 traffic_sched->set_allocated_scheduler(scheduler);
1909 traffic_shaping_info->set_cir(64000);
1910 traffic_shaping_info->set_pir(64000);
1911 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1912
1913 Status status = CreateTrafficSchedulers_(traffic_scheds);
1914 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1915}
1916
1917// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1918TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1919 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1920 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1921 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1922 traffic_sched->set_allocated_scheduler(scheduler);
1923 traffic_shaping_info->set_cir(64000);
1924 traffic_shaping_info->set_pir(0);
1925 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1926
1927 Status status = CreateTrafficSchedulers_(traffic_scheds);
1928 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1929}
1930
1931// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1932TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1933 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1934 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1935 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1936 traffic_sched->set_allocated_scheduler(scheduler);
1937 traffic_shaping_info->set_cir(0);
1938 traffic_shaping_info->set_pir(32000);
1939 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1940
1941 Status status = CreateTrafficSchedulers_(traffic_scheds);
1942 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1943}
1944
1945// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1946TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1947 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1948 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1949 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1950 traffic_sched->set_allocated_scheduler(scheduler);
1951 traffic_shaping_info->set_cir(64000);
1952 traffic_shaping_info->set_pir(128000);
1953 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1954
1955 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1956 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1957
1958 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301959 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001960 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1961
1962 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301963 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001964 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1965}
1966
1967// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1968TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1969 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1970 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1971 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1972 traffic_sched->set_allocated_scheduler(scheduler);
1973 traffic_shaping_info->set_cir(64000);
1974 traffic_shaping_info->set_pir(32000);
1975 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1976
1977 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1978 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1979
1980 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301981 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001982 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1983
1984 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301985 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001986 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1987}
1988
1989// Test 17 - CreateTrafficSchedulers-Downstream success case
1990TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
1991 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1992 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1993 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1994 traffic_sched->set_allocated_scheduler(scheduler);
1995 traffic_shaping_info->set_cir(64000);
1996 traffic_shaping_info->set_pir(128000);
1997 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1998
1999 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2000 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2001
2002 Status status = CreateTrafficSchedulers_(traffic_scheds);
2003 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2004}
2005
2006// Test 18 - CreateTrafficSchedulers-Downstream Failure case
2007TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2008 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2009 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2010 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2011 traffic_sched->set_allocated_scheduler(scheduler);
2012 traffic_shaping_info->set_cir(64000);
2013 traffic_shaping_info->set_pir(128000);
2014 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2015
2016 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2017 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2018
2019 Status status = CreateTrafficSchedulers_(traffic_scheds);
2020 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2021}
2022
2023// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
2024TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2025 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2026 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2027 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2028 traffic_sched->set_allocated_scheduler(scheduler);
2029 traffic_shaping_info->set_cir(64000);
2030 traffic_shaping_info->set_pir(128000);
2031 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2032
2033 Status status = CreateTrafficSchedulers_(traffic_scheds);
2034 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2035}
2036
2037////////////////////////////////////////////////////////////////////////////
2038// For testing RemoveTrafficSchedulers functionality
2039////////////////////////////////////////////////////////////////////////////
2040
2041class TestRemoveTrafficSchedulers : public Test {
2042 protected:
2043 NiceMock<BalMocker> balMock;
2044 tech_profile::TrafficSchedulers* traffic_scheds;
2045 tech_profile::TrafficScheduler* traffic_sched;
2046 tech_profile::SchedulerConfig* scheduler;
2047 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2048 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302049 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002050
2051 virtual void SetUp() {
2052 traffic_scheds = new tech_profile::TrafficSchedulers;
2053 traffic_scheds->set_intf_id(0);
2054 traffic_scheds->set_onu_id(1);
2055 traffic_scheds->set_uni_id(0);
2056 traffic_scheds->set_port_no(16);
2057 traffic_sched = traffic_scheds->add_traffic_scheds();
2058 traffic_sched->set_alloc_id(1025);
2059 scheduler = new tech_profile::SchedulerConfig;
2060 scheduler->set_priority(0);
2061 scheduler->set_weight(0);
2062 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2063 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2064 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2065 traffic_shaping_info->set_cir(64000);
2066 traffic_shaping_info->set_pir(128000);
2067 traffic_shaping_info->set_cbs(60536);
2068 traffic_shaping_info->set_pbs(65536);
2069 traffic_shaping_info->set_gir(10000);
2070 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2071 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2072 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2073 }
2074
2075 virtual void TearDown() {
2076 }
2077
2078 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302079 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2080 alloc_cfg_compltd_key k(0, 1025);
2081 alloc_cfg_complete_result res;
2082 res.pon_intf_id = 0;
2083 res.alloc_id = 1025;
2084 res.state = state;
2085 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002086
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302087 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2088 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2089 if (it == alloc_cfg_compltd_map.end()) {
2090 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 -05002091 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302092 it->second->push(res);
2093 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002094 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302095 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2096 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002097 }
2098};
2099
Girish Gowdra489425a2020-02-22 13:07:42 +05302100// TODO: VOL-2494
2101#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002102// Test 1 - RemoveTrafficSchedulers-Upstream success case
2103TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2104 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2105 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2106 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2107
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302108 bcmolt_pon_interface_key pon_key;
2109 bcmolt_pon_interface_cfg pon_cfg;
2110 pon_key.pon_ni = pon_id;
2111 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2112 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2113 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2114 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2115 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2116
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002117 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302118 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002119 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2120
2121 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302122 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002123 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2124}
Girish Gowdra489425a2020-02-22 13:07:42 +05302125#endif
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002126
2127// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2128TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2129 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2130 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2131 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2132
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302133 bcmolt_pon_interface_key pon_key;
2134 bcmolt_pon_interface_cfg pon_cfg;
2135 pon_key.pon_ni = pon_id;
2136 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2137 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2138 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2139 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2140 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2141
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002142 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302143 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002144 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2145
2146 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302147 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002148 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2149}
2150
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302151// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2152TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2153 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2154 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2155 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2156
2157 bcmolt_pon_interface_key pon_key;
2158 bcmolt_pon_interface_cfg pon_cfg;
2159 pon_key.pon_ni = pon_id;
2160 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2161 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2162 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2163 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2164 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2165
2166 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2167
2168 Status status = future_res.get();
2169 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2170}
2171
2172// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2173TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2174 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2175 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2176 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2177
2178 bcmolt_pon_interface_key pon_key;
2179 bcmolt_pon_interface_cfg pon_cfg;
2180 pon_key.pon_ni = pon_id;
2181 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2182 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2183 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2184 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2185 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2186
2187 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2188
2189 Status status = future_res.get();
2190 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2191}
2192
2193// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002194TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2195 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2196
2197 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2198 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2199
2200 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2201 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2202}
2203
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302204// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002205TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2206 //Create Scheduler
2207 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2208 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2209 traffic_sched->set_allocated_scheduler(scheduler);
2210 CreateTrafficSchedulers_(traffic_scheds);
2211
2212 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2213 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2214
2215 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2216 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2217}
2218
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302219// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002220TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2221 //Create Scheduler
2222 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2223 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2224 traffic_sched->set_allocated_scheduler(scheduler);
2225 CreateTrafficSchedulers_(traffic_scheds);
2226
2227 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2228 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2229
2230 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2231 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2232}
2233
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302234// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002235TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2236 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2237
2238 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2239 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2240}
2241
2242////////////////////////////////////////////////////////////////////////////
2243// For testing CreateTrafficQueues functionality
2244////////////////////////////////////////////////////////////////////////////
2245
2246class TestCreateTrafficQueues : public Test {
2247 protected:
2248 NiceMock<BalMocker> balMock;
2249 tech_profile::TrafficQueues* traffic_queues;
2250 tech_profile::TrafficQueue* traffic_queue_1;
2251 tech_profile::TrafficQueue* traffic_queue_2;
2252 tech_profile::DiscardConfig* discard_config_1;
2253 tech_profile::DiscardConfig* discard_config_2;
2254 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2255 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2256
2257 virtual void SetUp() {
2258 traffic_queues = new tech_profile::TrafficQueues;
2259 traffic_queues->set_intf_id(0);
2260 traffic_queues->set_onu_id(1);
2261 traffic_queue_1 = traffic_queues->add_traffic_queues();
2262 traffic_queue_1->set_gemport_id(1024);
2263 traffic_queue_1->set_pbit_map("0b00000101");
2264 traffic_queue_1->set_aes_encryption(true);
2265 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2266 traffic_queue_1->set_priority(0);
2267 traffic_queue_1->set_weight(0);
2268 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2269 discard_config_1 = new tech_profile::DiscardConfig;
2270 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2271 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2272 tail_drop_discard_config_1->set_queue_size(8);
2273 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2274 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2275 }
2276
2277 virtual void TearDown() {
2278 }
2279};
2280
2281// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2282TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2283 Status status;
2284 traffic_queues->set_uni_id(0);
2285 traffic_queues->set_port_no(16);
2286 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2287
2288 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2289 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2290
2291 status = CreateTrafficQueues_(traffic_queues);
2292 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2293
2294 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2295 status = CreateTrafficQueues_(traffic_queues);
2296 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2297}
2298
2299// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2300TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2301 traffic_queues->set_uni_id(1);
2302 traffic_queues->set_port_no(32);
2303 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2304
2305 traffic_queue_2 = traffic_queues->add_traffic_queues();
2306 traffic_queue_2->set_gemport_id(1025);
2307 traffic_queue_2->set_pbit_map("0b00001010");
2308 traffic_queue_2->set_aes_encryption(true);
2309 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2310 traffic_queue_2->set_priority(1);
2311 traffic_queue_2->set_weight(0);
2312 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2313 discard_config_2 = new tech_profile::DiscardConfig;
2314 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2315 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2316 tail_drop_discard_config_2->set_queue_size(8);
2317 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2318 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2319 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2320
2321 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2322 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2323
2324 Status status = CreateTrafficQueues_(traffic_queues);
2325 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2326}
2327
2328// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2329TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2330 traffic_queues->set_uni_id(2);
2331 traffic_queues->set_port_no(16);
2332 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2333
2334 traffic_queue_2 = traffic_queues->add_traffic_queues();
2335 traffic_queue_2->set_gemport_id(1025);
2336 traffic_queue_2->set_pbit_map("0b10001010");
2337 traffic_queue_2->set_aes_encryption(true);
2338 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2339 traffic_queue_2->set_priority(1);
2340 traffic_queue_2->set_weight(0);
2341 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2342 discard_config_2 = new tech_profile::DiscardConfig;
2343 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2344 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2345 tail_drop_discard_config_2->set_queue_size(8);
2346 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2347 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2348 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2349
2350 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2351 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2352
2353 Status status = CreateTrafficQueues_(traffic_queues);
2354 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2355}
2356
2357// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2358TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2359 traffic_queues->set_uni_id(3);
2360 traffic_queues->set_port_no(16);
2361 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2362
2363 traffic_queue_2 = traffic_queues->add_traffic_queues();
2364 traffic_queue_2->set_gemport_id(1025);
2365 traffic_queue_2->set_pbit_map("0b00001010");
2366 traffic_queue_2->set_aes_encryption(true);
2367 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2368 traffic_queue_2->set_priority(1);
2369 traffic_queue_2->set_weight(0);
2370 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2371 discard_config_2 = new tech_profile::DiscardConfig;
2372 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2373 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2374 tail_drop_discard_config_2->set_queue_size(8);
2375 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2376 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2377 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2378
2379 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2380 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2381
2382 Status status = CreateTrafficQueues_(traffic_queues);
2383 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2384}
2385
2386// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2387TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2388 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2389 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2390 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2391
2392 traffic_queue_2 = traffic_queues->add_traffic_queues();
2393 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2394 traffic_queues->set_uni_id(uni_ids[i]);
2395 traffic_queues->set_port_no(port_nos[i]);
2396 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2397
2398 traffic_queue_2->set_gemport_id(1025);
2399 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2400 traffic_queue_2->set_aes_encryption(true);
2401 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2402 traffic_queue_2->set_priority(1);
2403 traffic_queue_2->set_weight(0);
2404 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2405 discard_config_2 = new tech_profile::DiscardConfig;
2406 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2407 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2408 tail_drop_discard_config_2->set_queue_size(8);
2409 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2410 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2411 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2412
2413 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2414 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2415
2416 Status status = CreateTrafficQueues_(traffic_queues);
2417 if(i==16)
2418 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2419 else
2420 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2421 }
2422}
2423
2424// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2425TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2426 traffic_queues->set_uni_id(0);
2427 traffic_queues->set_port_no(16);
2428 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2429
2430 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2431 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2432
2433 Status status = CreateTrafficQueues_(traffic_queues);
2434 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2435}
2436
2437////////////////////////////////////////////////////////////////////////////
2438// For testing RemoveTrafficQueues functionality
2439////////////////////////////////////////////////////////////////////////////
2440
2441class TestRemoveTrafficQueues : public Test {
2442 protected:
2443 NiceMock<BalMocker> balMock;
2444 tech_profile::TrafficQueues* traffic_queues;
2445 tech_profile::TrafficQueue* traffic_queue_1;
2446 tech_profile::TrafficQueue* traffic_queue_2;
2447
2448 virtual void SetUp() {
2449 traffic_queues = new tech_profile::TrafficQueues;
2450 traffic_queues->set_intf_id(0);
2451 traffic_queues->set_onu_id(1);
2452 traffic_queue_1 = traffic_queues->add_traffic_queues();
2453 traffic_queue_1->set_gemport_id(1024);
2454 traffic_queue_1->set_priority(0);
2455 }
2456
2457 virtual void TearDown() {
2458 }
2459};
2460
2461// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2462TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2463 Status status;
2464 traffic_queues->set_uni_id(0);
2465 traffic_queues->set_port_no(16);
2466 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2467
2468 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2469 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2470
2471 status = RemoveTrafficQueues_(traffic_queues);
2472 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2473
2474 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2475 status = RemoveTrafficQueues_(traffic_queues);
2476 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2477}
2478
2479// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2480TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2481 Status status;
2482 traffic_queues->set_uni_id(0);
2483 traffic_queues->set_port_no(16);
2484 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2485
2486 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2487 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2488
2489 status = RemoveTrafficQueues_(traffic_queues);
2490 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2491}
2492
2493// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2494TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2495 //Remove scheduler so that is_tm_sched_id_present api call will return false
2496 tech_profile::TrafficSchedulers* traffic_scheds;
2497 tech_profile::TrafficScheduler* traffic_sched;
2498 traffic_scheds = new tech_profile::TrafficSchedulers;
2499 traffic_scheds->set_intf_id(0);
2500 traffic_scheds->set_onu_id(1);
2501 traffic_scheds->set_uni_id(0);
2502 traffic_scheds->set_port_no(16);
2503 traffic_sched = traffic_scheds->add_traffic_scheds();
2504 traffic_sched->set_alloc_id(1024);
2505 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2506
2507 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2508 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2509 RemoveTrafficSchedulers_(traffic_scheds);
2510
2511 traffic_queues->set_uni_id(0);
2512 traffic_queues->set_port_no(16);
2513 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2514
2515 Status status = RemoveTrafficQueues_(traffic_queues);
2516 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2517}
2518
2519/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2520as it is getting referred by some other queues case */
2521TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2522 traffic_queues->set_uni_id(3);
2523 traffic_queues->set_port_no(16);
2524 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2525 traffic_queue_2 = traffic_queues->add_traffic_queues();
2526 traffic_queue_2->set_gemport_id(1025);
2527 traffic_queue_2->set_priority(1);
2528 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2529
2530 Status status = RemoveTrafficQueues_(traffic_queues);
2531 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2532}
2533
2534/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2535is not getting referred by any other queues case */
2536TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2537 traffic_queues->set_uni_id(1);
2538 traffic_queues->set_port_no(32);
2539 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2540 traffic_queue_2 = traffic_queues->add_traffic_queues();
2541 traffic_queue_2->set_gemport_id(1025);
2542 traffic_queue_2->set_priority(1);
2543
2544 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2545 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2546
2547 Status status = RemoveTrafficQueues_(traffic_queues);
2548 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2549}
2550
2551/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2552having no reference to any other queues case */
2553TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2554 traffic_queues->set_uni_id(4);
2555 traffic_queues->set_port_no(64);
2556 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2557 traffic_queue_2 = traffic_queues->add_traffic_queues();
2558 traffic_queue_2->set_gemport_id(1025);
2559 traffic_queue_2->set_priority(1);
2560
2561 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2562 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2563
2564 Status status = RemoveTrafficQueues_(traffic_queues);
2565 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2566}