blob: b08b92e9c6ac08fb0f49f204b5ca383e3dba5ba4 [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
1163////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001164// For testing FlowAdd functionality
1165////////////////////////////////////////////////////////////////////////////
1166
1167class TestFlowAdd : public Test {
1168 protected:
1169 int32_t access_intf_id = 0;
1170 int32_t onu_id = 1;
1171 int32_t uni_id = 0;
1172 uint32_t port_no = 16;
1173 uint32_t flow_id = 1;
1174 std::string flow_type = "upstream";
1175 int32_t alloc_id = 1024;
1176 int32_t network_intf_id = 0;
1177 int32_t gemport_id = 1024;
1178 int32_t priority_value = 0;
1179 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301180 int32_t group_id = -1;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001181
1182 NiceMock<BalMocker> balMock;
1183 openolt::Flow* flow;
1184 openolt::Classifier* classifier;
1185 openolt::Action* action;
1186 openolt::ActionCmd* cmd;
1187
1188 bcmolt_flow_key flow_key;
1189 bcmolt_flow_cfg flow_cfg;
1190
1191 tech_profile::TrafficQueues* traffic_queues;
1192 tech_profile::TrafficQueue* traffic_queue_1;
1193 tech_profile::TrafficQueue* traffic_queue_2;
1194 tech_profile::DiscardConfig* discard_config_1;
1195 tech_profile::DiscardConfig* discard_config_2;
1196 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1197 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1198
1199
1200 virtual void SetUp() {
1201 classifier = new openolt::Classifier;
1202 action = new openolt::Action;
1203 cmd = new openolt::ActionCmd;
1204
1205 classifier->set_o_tpid(0);
1206 classifier->set_o_vid(7);
1207 classifier->set_i_tpid(0);
1208 classifier->set_i_vid(0);
1209 classifier->set_o_pbits(0);
1210 classifier->set_i_pbits(0);
1211 classifier->set_eth_type(0);
1212 classifier->set_ip_proto(0);
1213 classifier->set_src_port(0);
1214 classifier->set_dst_port(0);
1215 classifier->set_pkt_tag_type("single_tag");
1216
1217 action->set_o_vid(12);
1218 action->set_o_pbits(0);
1219 action->set_o_tpid(0);
1220 action->set_i_vid(0);
1221 action->set_i_pbits(0);
1222 action->set_i_tpid(0);
1223
1224 cmd->set_add_outer_tag(true);
1225 cmd->set_remove_outer_tag(false);
1226 cmd->set_trap_to_host(false);
1227 action->set_allocated_cmd(cmd);
1228
1229 flow_key.flow_id = 1;
1230 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1231 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1232 flow_cfg.data.onu_id=1;
1233 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1234 flow_cfg.data.svc_port_id=1024;
1235 flow_cfg.data.priority=0;
1236 flow_cfg.data.cookie=0;
1237 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1238 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1239 flow_cfg.data.ingress_intf.intf_id=0;
1240 flow_cfg.data.egress_intf.intf_id=0;
1241 flow_cfg.data.classifier.o_vid=7;
1242 flow_cfg.data.classifier.o_pbits=0;
1243 flow_cfg.data.classifier.i_vid=0;
1244 flow_cfg.data.classifier.i_pbits=0;
1245 flow_cfg.data.classifier.ether_type=0;
1246 flow_cfg.data.classifier.ip_proto=0;
1247 flow_cfg.data.classifier.src_port=0;
1248 flow_cfg.data.classifier.dst_port=0;
1249 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1250 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1251 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1252 flow_cfg.data.egress_qos.tm_sched.id=1020;
1253 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1254 flow_cfg.data.action.o_vid=12;
1255 flow_cfg.data.action.o_pbits=0;
1256 flow_cfg.data.action.i_vid=0;
1257 flow_cfg.data.action.i_pbits=0;
1258 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1259
1260 traffic_queues = new tech_profile::TrafficQueues;
1261 traffic_queues->set_intf_id(0);
1262 traffic_queues->set_onu_id(2);
1263 traffic_queue_1 = traffic_queues->add_traffic_queues();
1264 traffic_queue_1->set_gemport_id(1024);
1265 traffic_queue_1->set_pbit_map("0b00000101");
1266 traffic_queue_1->set_aes_encryption(true);
1267 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1268 traffic_queue_1->set_priority(0);
1269 traffic_queue_1->set_weight(0);
1270 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1271 discard_config_1 = new tech_profile::DiscardConfig;
1272 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1273 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1274 tail_drop_discard_config_1->set_queue_size(8);
1275 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1276 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1277
1278 traffic_queues->set_uni_id(0);
1279 traffic_queues->set_port_no(16);
1280
1281 traffic_queue_2 = traffic_queues->add_traffic_queues();
1282 traffic_queue_2->set_gemport_id(1025);
1283 traffic_queue_2->set_pbit_map("0b00001010");
1284 traffic_queue_2->set_aes_encryption(true);
1285 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1286 traffic_queue_2->set_priority(1);
1287 traffic_queue_2->set_weight(0);
1288 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1289 discard_config_2 = new tech_profile::DiscardConfig;
1290 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1291 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1292 tail_drop_discard_config_2->set_queue_size(8);
1293 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1294 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1295 }
1296
1297 virtual void TearDown() {
1298 }
1299};
1300
1301// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1302TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1303 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1304 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1305
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301306 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
1307 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001308 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1309}
1310
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301311#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001312// Test 2 - FlowAdd - Duplicate Flow case
1313TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1314 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1315 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1316 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1317
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301318 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1319 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001320 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1321}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301322#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001323
1324// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1325TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1326 gemport_id = 1025;
1327
1328 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1329 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1330
1331 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1332 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1333 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1334
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301335 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1336 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001337 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1338}
1339
1340// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1341TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1342 flow_type = "bidirectional";
1343
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301344 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1345 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001346 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1347}
1348
1349// Test 5 - FlowAdd - Failure case(Invalid network setting)
1350TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1351 network_intf_id = -1;
1352
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301353 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1354 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001355 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1356}
1357
1358// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1359TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1360 flow_id = 2;
1361
1362 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301363 action = new openolt::Action;
1364 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001365 cmd->set_trap_to_host(true);
1366 action->set_allocated_cmd(cmd);
1367
1368 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1369 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1370 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1371 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1372 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1373
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301374 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id,
1375 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001376 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1377}
1378
1379// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1380TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1381 flow_id = 3;
1382 gemport_id = 1025;
1383
1384 classifier->set_ip_proto(17);
1385 classifier->set_src_port(68);
1386 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301387 action = new openolt::Action;
1388 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001389 cmd->set_trap_to_host(true);
1390 action->set_allocated_cmd(cmd);
1391
1392 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1393 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1394 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1395 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1396 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1397
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301398 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1399 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001400 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1401}
1402
1403// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1404TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1405 flow_id = 4;
1406 flow_type = "downstream";
1407
1408 classifier->set_o_vid(12);
1409 classifier->set_i_vid(7);
1410 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301411 action = new openolt::Action;
1412 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001413 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001414 cmd->set_remove_outer_tag(true);
1415 action->set_allocated_cmd(cmd);
1416
1417 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1418 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1419 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1420 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1421 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1422
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301423 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1424 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001425 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1426}
1427
1428// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1429TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1430 onu_id = 2;
1431 flow_id = 5;
1432 alloc_id = 1025;
1433
1434 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1435 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1436
1437 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1438 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1439 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1440 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1441 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1442 CreateTrafficQueues_(traffic_queues);
1443
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301444 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1445 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001446 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1447}
1448
1449// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1450TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1451 onu_id = 2;
1452 flow_id = 6;
1453 flow_type = "downstream";
1454 alloc_id = 1025;
1455
1456 classifier->set_o_vid(12);
1457 classifier->set_i_vid(7);
1458 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301459 action = new openolt::Action;
1460 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001461 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001462 cmd->set_remove_outer_tag(true);
1463 action->set_allocated_cmd(cmd);
1464
1465 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1466 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1467
1468 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1469 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1470 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1471 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1472 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1473 CreateTrafficQueues_(traffic_queues);
1474
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301475 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1476 gemport_id, *classifier, *action, priority_value, cookie, group_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001477 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1478}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301479
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001480
1481////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001482// For testing OnuPacketOut functionality
1483////////////////////////////////////////////////////////////////////////////
1484
1485class TestOnuPacketOut : public Test {
1486 protected:
1487 uint32_t pon_id = 0;
1488 uint32_t onu_id = 1;
1489 std::string pkt = "omci-pkt";
1490 NiceMock<BalMocker> balMock;
1491
1492 virtual void SetUp() {
1493 }
1494
1495 virtual void TearDown() {
1496 }
1497};
1498
1499// Test 1 - OnuPacketOut success case
1500TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1501 uint32_t port_no = 16;
1502 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001503
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001504 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001505 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1506
1507 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1508 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1509}
1510
1511// Test 2 - OnuPacketOut Port number as 0 case
1512TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1513 uint32_t port_no = 0;
1514 uint32_t gemport_id = 1024;
1515
1516 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1517 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1518}
1519
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001520// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1521TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1522 uint32_t port_no = 16;
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
1532// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1533TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1534 uint32_t port_no = 64;
1535 uint32_t gemport_id = 0;
1536
1537 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1538 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1539
1540 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1541 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1542}
1543
1544////////////////////////////////////////////////////////////////////////////
1545// For testing FlowRemove functionality
1546////////////////////////////////////////////////////////////////////////////
1547
1548class TestFlowRemove : public Test {
1549 protected:
1550 NiceMock<BalMocker> balMock;
1551
1552 virtual void SetUp() {
1553 }
1554
1555 virtual void TearDown() {
1556 }
1557};
1558
1559// Test 1 - FlowRemove - Failure case
1560TEST_F(TestFlowRemove, FlowRemoveFailure) {
1561 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1562 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1563
1564 Status status = FlowRemove_(1, "upstream");
1565 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1566}
1567
1568// Test 2 - FlowRemove - success case
1569TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1570 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1571 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1572
1573 Status status = FlowRemove_(1, "upstream");
1574 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1575}
1576
1577////////////////////////////////////////////////////////////////////////////
1578// For testing UplinkPacketOut functionality
1579////////////////////////////////////////////////////////////////////////////
1580
1581class TestUplinkPacketOut : public Test {
1582 protected:
1583 uint32_t pon_id = 0;
1584 std::string pkt = "omci-pkt";
1585 NiceMock<BalMocker> balMock;
1586
1587 bcmolt_flow_key flow_key;
1588 bcmolt_flow_cfg flow_cfg;
1589
1590 virtual void SetUp() {
1591 flow_key.flow_id = 1;
1592 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1593 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1594 flow_cfg.data.onu_id=1;
1595 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1596 flow_cfg.data.svc_port_id=1024;
1597 flow_cfg.data.priority=0;
1598 flow_cfg.data.cookie=0;
1599 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1600 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1601 flow_cfg.data.ingress_intf.intf_id=0;
1602 flow_cfg.data.egress_intf.intf_id=0;
1603 flow_cfg.data.classifier.o_vid=7;
1604 flow_cfg.data.classifier.o_pbits=0;
1605 flow_cfg.data.classifier.i_vid=0;
1606 flow_cfg.data.classifier.i_pbits=0;
1607 flow_cfg.data.classifier.ether_type=0;
1608 flow_cfg.data.classifier.ip_proto=0;
1609 flow_cfg.data.classifier.src_port=0;
1610 flow_cfg.data.classifier.dst_port=0;
1611 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1612 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1613 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1614 flow_cfg.data.egress_qos.tm_sched.id=1020;
1615 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1616 flow_cfg.data.action.o_vid=12;
1617 flow_cfg.data.action.o_pbits=0;
1618 flow_cfg.data.action.i_vid=0;
1619 flow_cfg.data.action.i_pbits=0;
1620 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1621 }
1622
1623 virtual void TearDown() {
1624 }
1625};
1626
1627// Test 1 - UplinkPacketOut success case
1628TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1629 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1630 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1631 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1632 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1633 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1634
1635 Status status = UplinkPacketOut_(pon_id, pkt);
1636 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1637}
1638
1639// Test 2 - UplinkPacketOut Failure case
1640TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1641 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1642 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1643 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1644 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1645 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1646
1647 Status status = UplinkPacketOut_(pon_id, pkt);
1648 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1649}
1650
1651// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1652TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1653 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1654
1655 FlowRemove_(2, "upstream");
1656 FlowRemove_(3, "upstream");
1657 FlowRemove_(4, "downstream");
1658 FlowRemove_(5, "upstream");
1659 FlowRemove_(6, "downstream");
1660
1661 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1662 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1663 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1664
1665 Status status = UplinkPacketOut_(pon_id, pkt);
1666 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1667}
1668
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001669////////////////////////////////////////////////////////////////////////////
1670// For testing CreateTrafficSchedulers functionality
1671////////////////////////////////////////////////////////////////////////////
1672
1673class TestCreateTrafficSchedulers : public Test {
1674 protected:
1675 NiceMock<BalMocker> balMock;
1676 tech_profile::TrafficSchedulers* traffic_scheds;
1677 tech_profile::TrafficScheduler* traffic_sched;
1678 tech_profile::SchedulerConfig* scheduler;
1679 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1680
1681 virtual void SetUp() {
1682 traffic_scheds = new tech_profile::TrafficSchedulers;
1683 traffic_scheds->set_intf_id(0);
1684 traffic_scheds->set_onu_id(1);
1685 traffic_scheds->set_uni_id(0);
1686 traffic_scheds->set_port_no(16);
1687 traffic_sched = traffic_scheds->add_traffic_scheds();
1688 traffic_sched->set_alloc_id(1024);
1689 scheduler = new tech_profile::SchedulerConfig;
1690 scheduler->set_priority(0);
1691 scheduler->set_weight(0);
1692 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1693 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1694 traffic_shaping_info->set_cbs(60536);
1695 traffic_shaping_info->set_pbs(65536);
1696 traffic_shaping_info->set_gir(10000);
1697 }
1698
1699 virtual void TearDown() {
1700 }
1701
1702 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301703 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1704 alloc_cfg_compltd_key k(0, 1024);
1705 alloc_cfg_complete_result res;
1706 res.pon_intf_id = 0;
1707 res.alloc_id = 1024;
1708 res.state = state;
1709 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001710
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301711 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1712 // before we push the result.
1713 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1714 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1715 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1716 if (it == alloc_cfg_compltd_map.end()) {
1717 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 -05001718 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301719 it->second->push(res);
1720 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001721 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301722 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1723 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001724 }
1725};
1726
1727// Test 1 - CreateTrafficSchedulers-Upstream success case
1728TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1729 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1730 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1731 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1732 traffic_sched->set_allocated_scheduler(scheduler);
1733 traffic_shaping_info->set_cir(64000);
1734 traffic_shaping_info->set_pir(128000);
1735 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1736
1737 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1738 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1739
1740 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301741 future<int> push_alloc_cfg_complt = \
1742 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001743
1744 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301745 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001746 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1747}
1748
1749// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1750TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1751 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1752 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1753 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1754 traffic_sched->set_allocated_scheduler(scheduler);
1755 traffic_shaping_info->set_cir(64000);
1756 traffic_shaping_info->set_pir(128000);
1757 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1758
1759 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1760 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1761
1762 Status status = CreateTrafficSchedulers_(traffic_scheds);
1763 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1764}
1765
1766// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1767TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1768 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1769 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1770 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1771 traffic_sched->set_allocated_scheduler(scheduler);
1772 traffic_shaping_info->set_cir(64000);
1773 traffic_shaping_info->set_pir(128000);
1774 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1775
1776 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1777 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1778
1779 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301780 future<int> push_alloc_cfg_complt = \
1781 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001782
1783 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301784 int res = push_alloc_cfg_complt.get();
1785
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001786 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1787}
1788
1789// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1790TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1791 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1792 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1793 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1794 traffic_sched->set_allocated_scheduler(scheduler);
1795 traffic_shaping_info->set_cir(64000);
1796 traffic_shaping_info->set_pir(128000);
1797 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1798
1799 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1800 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1801
1802 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301803 future<int> push_alloc_cfg_complt = \
1804 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001805
1806 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301807 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001808 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1809}
1810
1811// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1812TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1813 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1814 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1815 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1816 traffic_sched->set_allocated_scheduler(scheduler);
1817 traffic_shaping_info->set_cir(64000);
1818 traffic_shaping_info->set_pir(128000);
1819 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1820
1821 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1822 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1823
1824 Status status = CreateTrafficSchedulers_(traffic_scheds);
1825 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1826}
1827
1828// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1829TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1830 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1831 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1832 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1833 traffic_sched->set_allocated_scheduler(scheduler);
1834 traffic_shaping_info->set_cir(64000);
1835 traffic_shaping_info->set_pir(0);
1836 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1837
1838 Status status = CreateTrafficSchedulers_(traffic_scheds);
1839 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1840}
1841
1842// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1843TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1844 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1845 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1846 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1847 traffic_sched->set_allocated_scheduler(scheduler);
1848 traffic_shaping_info->set_cir(64000);
1849 traffic_shaping_info->set_pir(32000);
1850 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1851
1852 Status status = CreateTrafficSchedulers_(traffic_scheds);
1853 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1854}
1855
1856// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1857TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1858 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1859 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1860 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1861 traffic_sched->set_allocated_scheduler(scheduler);
1862 traffic_shaping_info->set_cir(64000);
1863 traffic_shaping_info->set_pir(64000);
1864 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1865
1866 Status status = CreateTrafficSchedulers_(traffic_scheds);
1867 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1868}
1869
1870// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1871TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1872 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1873 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1874 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1875 traffic_sched->set_allocated_scheduler(scheduler);
1876 traffic_shaping_info->set_cir(64000);
1877 traffic_shaping_info->set_pir(0);
1878 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1879
1880 Status status = CreateTrafficSchedulers_(traffic_scheds);
1881 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1882}
1883
1884// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1885TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1886 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1887 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1888 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1889 traffic_sched->set_allocated_scheduler(scheduler);
1890 traffic_shaping_info->set_cir(0);
1891 traffic_shaping_info->set_pir(32000);
1892 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1893
1894 Status status = CreateTrafficSchedulers_(traffic_scheds);
1895 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1896}
1897
1898// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1899TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1900 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1901 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1902 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1903 traffic_sched->set_allocated_scheduler(scheduler);
1904 traffic_shaping_info->set_cir(64000);
1905 traffic_shaping_info->set_pir(32000);
1906 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1907
1908 Status status = CreateTrafficSchedulers_(traffic_scheds);
1909 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1910}
1911
1912// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1913TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1914 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1915 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1916 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1917 traffic_sched->set_allocated_scheduler(scheduler);
1918 traffic_shaping_info->set_cir(64000);
1919 traffic_shaping_info->set_pir(64000);
1920 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1921
1922 Status status = CreateTrafficSchedulers_(traffic_scheds);
1923 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1924}
1925
1926// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1927TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1928 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1929 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1930 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1931 traffic_sched->set_allocated_scheduler(scheduler);
1932 traffic_shaping_info->set_cir(64000);
1933 traffic_shaping_info->set_pir(0);
1934 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1935
1936 Status status = CreateTrafficSchedulers_(traffic_scheds);
1937 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1938}
1939
1940// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1941TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1942 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1943 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1944 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1945 traffic_sched->set_allocated_scheduler(scheduler);
1946 traffic_shaping_info->set_cir(0);
1947 traffic_shaping_info->set_pir(32000);
1948 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1949
1950 Status status = CreateTrafficSchedulers_(traffic_scheds);
1951 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1952}
1953
1954// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1955TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1956 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1957 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1958 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1959 traffic_sched->set_allocated_scheduler(scheduler);
1960 traffic_shaping_info->set_cir(64000);
1961 traffic_shaping_info->set_pir(128000);
1962 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1963
1964 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1965 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1966
1967 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301968 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001969 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1970
1971 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301972 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001973 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1974}
1975
1976// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1977TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1978 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1979 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1980 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1981 traffic_sched->set_allocated_scheduler(scheduler);
1982 traffic_shaping_info->set_cir(64000);
1983 traffic_shaping_info->set_pir(32000);
1984 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1985
1986 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1987 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1988
1989 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301990 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001991 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1992
1993 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301994 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001995 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1996}
1997
1998// Test 17 - CreateTrafficSchedulers-Downstream success case
1999TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2000 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2001 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2002 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2003 traffic_sched->set_allocated_scheduler(scheduler);
2004 traffic_shaping_info->set_cir(64000);
2005 traffic_shaping_info->set_pir(128000);
2006 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2007
2008 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2009 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2010
2011 Status status = CreateTrafficSchedulers_(traffic_scheds);
2012 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2013}
2014
2015// Test 18 - CreateTrafficSchedulers-Downstream Failure case
2016TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2017 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2018 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2019 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2020 traffic_sched->set_allocated_scheduler(scheduler);
2021 traffic_shaping_info->set_cir(64000);
2022 traffic_shaping_info->set_pir(128000);
2023 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2024
2025 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2026 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2027
2028 Status status = CreateTrafficSchedulers_(traffic_scheds);
2029 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2030}
2031
2032// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
2033TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2034 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2035 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2036 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2037 traffic_sched->set_allocated_scheduler(scheduler);
2038 traffic_shaping_info->set_cir(64000);
2039 traffic_shaping_info->set_pir(128000);
2040 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2041
2042 Status status = CreateTrafficSchedulers_(traffic_scheds);
2043 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2044}
2045
2046////////////////////////////////////////////////////////////////////////////
2047// For testing RemoveTrafficSchedulers functionality
2048////////////////////////////////////////////////////////////////////////////
2049
2050class TestRemoveTrafficSchedulers : public Test {
2051 protected:
2052 NiceMock<BalMocker> balMock;
2053 tech_profile::TrafficSchedulers* traffic_scheds;
2054 tech_profile::TrafficScheduler* traffic_sched;
2055 tech_profile::SchedulerConfig* scheduler;
2056 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2057 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302058 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002059
2060 virtual void SetUp() {
2061 traffic_scheds = new tech_profile::TrafficSchedulers;
2062 traffic_scheds->set_intf_id(0);
2063 traffic_scheds->set_onu_id(1);
2064 traffic_scheds->set_uni_id(0);
2065 traffic_scheds->set_port_no(16);
2066 traffic_sched = traffic_scheds->add_traffic_scheds();
2067 traffic_sched->set_alloc_id(1025);
2068 scheduler = new tech_profile::SchedulerConfig;
2069 scheduler->set_priority(0);
2070 scheduler->set_weight(0);
2071 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2072 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2073 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2074 traffic_shaping_info->set_cir(64000);
2075 traffic_shaping_info->set_pir(128000);
2076 traffic_shaping_info->set_cbs(60536);
2077 traffic_shaping_info->set_pbs(65536);
2078 traffic_shaping_info->set_gir(10000);
2079 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2080 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2081 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2082 }
2083
2084 virtual void TearDown() {
2085 }
2086
2087 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302088 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2089 alloc_cfg_compltd_key k(0, 1025);
2090 alloc_cfg_complete_result res;
2091 res.pon_intf_id = 0;
2092 res.alloc_id = 1025;
2093 res.state = state;
2094 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002095
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302096 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2097 // before we push the result.
2098 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302099 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2100 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2101 if (it == alloc_cfg_compltd_map.end()) {
2102 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 -05002103 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302104 it->second->push(res);
2105 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002106 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302107 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2108 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002109 }
2110};
2111
2112// Test 1 - RemoveTrafficSchedulers-Upstream success case
2113TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2114 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2115 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2116 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2117
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302118 bcmolt_pon_interface_key pon_key;
2119 bcmolt_pon_interface_cfg pon_cfg;
2120 pon_key.pon_ni = pon_id;
2121 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2122 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2123 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2124 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2125 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2126
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002127 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302128 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002129 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2130
2131 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302132 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002133 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2134}
2135
2136// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2137TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2138 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2139 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2140 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2141
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302142 bcmolt_pon_interface_key pon_key;
2143 bcmolt_pon_interface_cfg pon_cfg;
2144 pon_key.pon_ni = pon_id;
2145 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2146 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2147 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2148 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2149 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2150
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002151 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302152 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002153 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2154
2155 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302156 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002157 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2158}
2159
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302160// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2161TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2162 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2163 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2164 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2165
2166 bcmolt_pon_interface_key pon_key;
2167 bcmolt_pon_interface_cfg pon_cfg;
2168 pon_key.pon_ni = pon_id;
2169 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2170 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2171 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2172 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2173 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2174
2175 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2176
2177 Status status = future_res.get();
2178 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2179}
2180
2181// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2182TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2183 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2184 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2185 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2186
2187 bcmolt_pon_interface_key pon_key;
2188 bcmolt_pon_interface_cfg pon_cfg;
2189 pon_key.pon_ni = pon_id;
2190 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2191 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2192 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2193 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2194 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2195
2196 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2197
2198 Status status = future_res.get();
2199 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2200}
2201
2202// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002203TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2204 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2205
2206 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2207 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2208
2209 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2210 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2211}
2212
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302213// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002214TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2215 //Create Scheduler
2216 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2217 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2218 traffic_sched->set_allocated_scheduler(scheduler);
2219 CreateTrafficSchedulers_(traffic_scheds);
2220
2221 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2222 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2223
2224 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2225 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2226}
2227
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302228// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002229TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2230 //Create Scheduler
2231 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2232 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2233 traffic_sched->set_allocated_scheduler(scheduler);
2234 CreateTrafficSchedulers_(traffic_scheds);
2235
2236 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2237 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2238
2239 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2240 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2241}
2242
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302243// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002244TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2245 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2246
2247 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2248 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2249}
2250
2251////////////////////////////////////////////////////////////////////////////
2252// For testing CreateTrafficQueues functionality
2253////////////////////////////////////////////////////////////////////////////
2254
2255class TestCreateTrafficQueues : public Test {
2256 protected:
2257 NiceMock<BalMocker> balMock;
2258 tech_profile::TrafficQueues* traffic_queues;
2259 tech_profile::TrafficQueue* traffic_queue_1;
2260 tech_profile::TrafficQueue* traffic_queue_2;
2261 tech_profile::DiscardConfig* discard_config_1;
2262 tech_profile::DiscardConfig* discard_config_2;
2263 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2264 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2265
2266 virtual void SetUp() {
2267 traffic_queues = new tech_profile::TrafficQueues;
2268 traffic_queues->set_intf_id(0);
2269 traffic_queues->set_onu_id(1);
2270 traffic_queue_1 = traffic_queues->add_traffic_queues();
2271 traffic_queue_1->set_gemport_id(1024);
2272 traffic_queue_1->set_pbit_map("0b00000101");
2273 traffic_queue_1->set_aes_encryption(true);
2274 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2275 traffic_queue_1->set_priority(0);
2276 traffic_queue_1->set_weight(0);
2277 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2278 discard_config_1 = new tech_profile::DiscardConfig;
2279 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2280 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2281 tail_drop_discard_config_1->set_queue_size(8);
2282 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2283 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2284 }
2285
2286 virtual void TearDown() {
2287 }
2288};
2289
2290// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2291TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2292 Status status;
2293 traffic_queues->set_uni_id(0);
2294 traffic_queues->set_port_no(16);
2295 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2296
2297 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2298 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2299
2300 status = CreateTrafficQueues_(traffic_queues);
2301 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2302
2303 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2304 status = CreateTrafficQueues_(traffic_queues);
2305 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2306}
2307
2308// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2309TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2310 traffic_queues->set_uni_id(1);
2311 traffic_queues->set_port_no(32);
2312 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2313
2314 traffic_queue_2 = traffic_queues->add_traffic_queues();
2315 traffic_queue_2->set_gemport_id(1025);
2316 traffic_queue_2->set_pbit_map("0b00001010");
2317 traffic_queue_2->set_aes_encryption(true);
2318 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2319 traffic_queue_2->set_priority(1);
2320 traffic_queue_2->set_weight(0);
2321 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2322 discard_config_2 = new tech_profile::DiscardConfig;
2323 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2324 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2325 tail_drop_discard_config_2->set_queue_size(8);
2326 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2327 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2328 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2329
2330 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2331 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2332
2333 Status status = CreateTrafficQueues_(traffic_queues);
2334 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2335}
2336
2337// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2338TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2339 traffic_queues->set_uni_id(2);
2340 traffic_queues->set_port_no(16);
2341 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2342
2343 traffic_queue_2 = traffic_queues->add_traffic_queues();
2344 traffic_queue_2->set_gemport_id(1025);
2345 traffic_queue_2->set_pbit_map("0b10001010");
2346 traffic_queue_2->set_aes_encryption(true);
2347 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2348 traffic_queue_2->set_priority(1);
2349 traffic_queue_2->set_weight(0);
2350 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2351 discard_config_2 = new tech_profile::DiscardConfig;
2352 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2353 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2354 tail_drop_discard_config_2->set_queue_size(8);
2355 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2356 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2357 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2358
2359 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2360 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2361
2362 Status status = CreateTrafficQueues_(traffic_queues);
2363 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2364}
2365
2366// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2367TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2368 traffic_queues->set_uni_id(3);
2369 traffic_queues->set_port_no(16);
2370 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2371
2372 traffic_queue_2 = traffic_queues->add_traffic_queues();
2373 traffic_queue_2->set_gemport_id(1025);
2374 traffic_queue_2->set_pbit_map("0b00001010");
2375 traffic_queue_2->set_aes_encryption(true);
2376 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2377 traffic_queue_2->set_priority(1);
2378 traffic_queue_2->set_weight(0);
2379 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2380 discard_config_2 = new tech_profile::DiscardConfig;
2381 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2382 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2383 tail_drop_discard_config_2->set_queue_size(8);
2384 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2385 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2386 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2387
2388 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2389 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2390
2391 Status status = CreateTrafficQueues_(traffic_queues);
2392 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2393}
2394
2395// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2396TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2397 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2398 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2399 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2400
2401 traffic_queue_2 = traffic_queues->add_traffic_queues();
2402 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2403 traffic_queues->set_uni_id(uni_ids[i]);
2404 traffic_queues->set_port_no(port_nos[i]);
2405 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2406
2407 traffic_queue_2->set_gemport_id(1025);
2408 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2409 traffic_queue_2->set_aes_encryption(true);
2410 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2411 traffic_queue_2->set_priority(1);
2412 traffic_queue_2->set_weight(0);
2413 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2414 discard_config_2 = new tech_profile::DiscardConfig;
2415 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2416 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2417 tail_drop_discard_config_2->set_queue_size(8);
2418 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2419 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2420 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2421
2422 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2423 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2424
2425 Status status = CreateTrafficQueues_(traffic_queues);
2426 if(i==16)
2427 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2428 else
2429 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2430 }
2431}
2432
2433// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2434TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2435 traffic_queues->set_uni_id(0);
2436 traffic_queues->set_port_no(16);
2437 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2438
2439 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2440 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2441
2442 Status status = CreateTrafficQueues_(traffic_queues);
2443 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2444}
2445
2446////////////////////////////////////////////////////////////////////////////
2447// For testing RemoveTrafficQueues functionality
2448////////////////////////////////////////////////////////////////////////////
2449
2450class TestRemoveTrafficQueues : public Test {
2451 protected:
2452 NiceMock<BalMocker> balMock;
2453 tech_profile::TrafficQueues* traffic_queues;
2454 tech_profile::TrafficQueue* traffic_queue_1;
2455 tech_profile::TrafficQueue* traffic_queue_2;
2456
2457 virtual void SetUp() {
2458 traffic_queues = new tech_profile::TrafficQueues;
2459 traffic_queues->set_intf_id(0);
2460 traffic_queues->set_onu_id(1);
2461 traffic_queue_1 = traffic_queues->add_traffic_queues();
2462 traffic_queue_1->set_gemport_id(1024);
2463 traffic_queue_1->set_priority(0);
2464 }
2465
2466 virtual void TearDown() {
2467 }
2468};
2469
2470// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2471TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2472 Status status;
2473 traffic_queues->set_uni_id(0);
2474 traffic_queues->set_port_no(16);
2475 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2476
2477 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2478 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2479
2480 status = RemoveTrafficQueues_(traffic_queues);
2481 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2482
2483 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2484 status = RemoveTrafficQueues_(traffic_queues);
2485 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2486}
2487
2488// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2489TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2490 Status status;
2491 traffic_queues->set_uni_id(0);
2492 traffic_queues->set_port_no(16);
2493 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2494
2495 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2496 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2497
2498 status = RemoveTrafficQueues_(traffic_queues);
2499 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2500}
2501
2502// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2503TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2504 //Remove scheduler so that is_tm_sched_id_present api call will return false
2505 tech_profile::TrafficSchedulers* traffic_scheds;
2506 tech_profile::TrafficScheduler* traffic_sched;
2507 traffic_scheds = new tech_profile::TrafficSchedulers;
2508 traffic_scheds->set_intf_id(0);
2509 traffic_scheds->set_onu_id(1);
2510 traffic_scheds->set_uni_id(0);
2511 traffic_scheds->set_port_no(16);
2512 traffic_sched = traffic_scheds->add_traffic_scheds();
2513 traffic_sched->set_alloc_id(1024);
2514 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2515
2516 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2517 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2518 RemoveTrafficSchedulers_(traffic_scheds);
2519
2520 traffic_queues->set_uni_id(0);
2521 traffic_queues->set_port_no(16);
2522 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2523
2524 Status status = RemoveTrafficQueues_(traffic_queues);
2525 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2526}
2527
2528/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2529as it is getting referred by some other queues case */
2530TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2531 traffic_queues->set_uni_id(3);
2532 traffic_queues->set_port_no(16);
2533 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2534 traffic_queue_2 = traffic_queues->add_traffic_queues();
2535 traffic_queue_2->set_gemport_id(1025);
2536 traffic_queue_2->set_priority(1);
2537 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2538
2539 Status status = RemoveTrafficQueues_(traffic_queues);
2540 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2541}
2542
2543/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2544is not getting referred by any other queues case */
2545TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2546 traffic_queues->set_uni_id(1);
2547 traffic_queues->set_port_no(32);
2548 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2549 traffic_queue_2 = traffic_queues->add_traffic_queues();
2550 traffic_queue_2->set_gemport_id(1025);
2551 traffic_queue_2->set_priority(1);
2552
2553 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2554 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2555
2556 Status status = RemoveTrafficQueues_(traffic_queues);
2557 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2558}
2559
2560/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2561having no reference to any other queues case */
2562TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2563 traffic_queues->set_uni_id(4);
2564 traffic_queues->set_port_no(64);
2565 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2566 traffic_queue_2 = traffic_queues->add_traffic_queues();
2567 traffic_queue_2->set_gemport_id(1025);
2568 traffic_queue_2->set_priority(1);
2569
2570 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2571 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2572
2573 Status status = RemoveTrafficQueues_(traffic_queues);
2574 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2575}