blob: 393c31526266dd28f0fb08745e7a76af5dd6a199 [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"
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070021#include "server.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050022#include <future>
Orhan Kupusogluec57af02021-05-12 12:38:17 +000023#include <fstream>
24#include "trx_eeprom_reader.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000025using namespace testing;
26using namespace std;
27
28class TestOltEnable : public Test {
29 protected:
30 virtual void SetUp() {
31 }
32
33 virtual void TearDown() {
34 // Code here will be called immediately after each test
35 // (right before the destructor).
36 }
37};
38
39// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
40// bcmolt_cfg_get__bal_state_stub.
41ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
42
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050043// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
44// bcmolt_cfg_get__onu_state_stub.
45ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
46
47// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
48// bcmolt_cfg_get__tm_sched_stub.
49ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
50
51// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
52// bcmolt_cfg_get__pon_intf_stub.
53ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
54
55// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
56// bcmolt_cfg_get__nni_intf_stub.
57ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000058
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050059// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
60// bcmolt_cfg_get__flow_stub.
61ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
62
Amit Ghoshfcad4d32019-11-13 10:24:55 +000063// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
64MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050065MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
66MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
67MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050069MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000070
Amit Ghoshfcad4d32019-11-13 10:24:55 +000071// Test Fixture for OltEnable
72
73// Test 1: OltEnableSuccess case
74TEST_F(TestOltEnable, OltEnableSuccess){
75 // NiceMock is used to suppress 'WillByDefault' return errors.
76 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
77 NiceMock<BalMocker> balMock;
78 bcmos_errno host_init_res = BCM_ERR_OK;
79 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
80 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
81 bcmos_errno olt_oper_res = BCM_ERR_OK;
82
83 bcmolt_olt_cfg olt_cfg = { };
84 bcmolt_olt_key olt_key = { };
85 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
86 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
87
88 Status olt_enable_res;
89
90 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
91 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
92 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
93 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
94 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
95 .WillRepeatedly(Return(bal_cfg_get_res));
96 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
97
98 olt_enable_res = Enable_(1, NULL);
99 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
100}
101
102// Test 2: OltEnableFail_host_init_fail
103TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
104 // NiceMock is used to suppress 'WillByDefault' return errors.
105 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
106 NiceMock<BalMocker> balMock;
107 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
108
109 Status olt_enable_res;
110
111 // Ensure that the state of the OLT is in deactivated to start with..
112 state.deactivate();
113
114 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
115
116 olt_enable_res = Enable_(1, NULL);
117 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
118}
119
120// Test 3: OltEnableSuccess_PON_Device_Connected
121TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
122
123 // NiceMock is used to suppress 'WillByDefault' return errors.
124 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
125 NiceMock<BalMocker> balMock;
126 bcmos_errno host_init_res = BCM_ERR_OK;
127 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
128 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
129 bcmos_errno olt_oper_res = BCM_ERR_OK;
130
131 bcmolt_olt_cfg olt_cfg = { };
132 bcmolt_olt_key olt_key = { };
133 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
134 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
135
136 Status olt_enable_res;
137
138 // Ensure that the state of the OLT is in deactivated to start with..
139 state.deactivate();
140
141 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
142 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
143 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
144 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
145 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
146 .WillRepeatedly(Return(bal_cfg_get_res));
147
148 olt_enable_res = Enable_(1, NULL);
149 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
150
151}
152
153// Test 4: OltEnableFail_All_PON_Enable_Fail
154TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
155
156 // NiceMock is used to suppress 'WillByDefault' return errors.
157 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
158 NiceMock<BalMocker> balMock;
159 bcmos_errno host_init_res = BCM_ERR_OK;
160 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
161 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
162 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
163
164 bcmolt_olt_cfg olt_cfg = { };
165 bcmolt_olt_key olt_key = { };
166 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
167 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
168
169 Status olt_enable_res;
170
171 // Ensure that the state of the OLT is in deactivated to start with..
172 state.deactivate();
173
174 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
175 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
176 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
177 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
178 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
179 .WillRepeatedly(Return(bal_cfg_get_res));
180 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
181
182 olt_enable_res = Enable_(1, NULL);
183
184 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
185}
186
187// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
188TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
189
190 // NiceMock is used to suppress 'WillByDefault' return errors.
191 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
192 NiceMock<BalMocker> balMock;
193 bcmos_errno host_init_res = BCM_ERR_OK;
194 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
195 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
196 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
197 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
198
199 bcmolt_olt_cfg olt_cfg = { };
200 bcmolt_olt_key olt_key = { };
201 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
202 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
203
204 Status olt_enable_res;
205
206 // Ensure that the state of the OLT is in deactivated to start with..
207 state.deactivate();
208
209 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
210 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
211 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
212 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
213 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
214 .WillRepeatedly(Return(bal_cfg_get_res));
215 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
216 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
217 .WillOnce(Return(olt_oper_res_fail))
218 .WillRepeatedly(Return(olt_oper_res_success));
219 olt_enable_res = Enable_(1, NULL);
220
221 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
222}
223
224////////////////////////////////////////////////////////////////////////
225// For testing Enable/Disable functionality
226////////////////////////////////////////////////////////////////////////
227
Girish Gowdraddf9a162020-01-27 12:56:27 +0530228int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000229
230// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
231MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
232
233class TestOltDisableReenable : public Test {
234 protected:
235 virtual void SetUp() {
236 NiceMock<BalMocker> balMock;
237 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
238
239 bcmolt_olt_cfg olt_cfg = { };
240 bcmolt_olt_key olt_key = { };
241
242 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
243
Girish Gowdraddf9a162020-01-27 12:56:27 +0530244 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000245 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
246 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
247
248 ProbeDeviceCapabilities_();
249
250 }
251
252 virtual void TearDown() {
253 // Code here will be called immediately after each test
254 // (right before the destructor).
255 }
256};
257
258
259// Test Fixture for OltDisable
260
261// Test 1: OltDisableSuccess case
262TEST_F(TestOltDisableReenable, OltDisableSuccess){
263 // NiceMock is used to suppress 'WillByDefault' return errors.
264 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
265 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500266 bcmos_errno olt_oper_res = BCM_ERR_OK;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700267 bcmos_errno olt_get_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000268
269 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500270 state.deactivate();
271 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Girish Gowdrae1db2952021-05-04 00:16:54 -0700272 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_get_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;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700284 bcmos_errno pon_cfg_get_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000285
286 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500287 state.deactivate();
Girish Gowdrae1db2952021-05-04 00:16:54 -0700288 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(pon_cfg_get_res));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500289 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000290 olt_disable_res = Disable_();
291 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
292}
293
294
295// Test Fixture for OltReenable
296
297// Test 1: OltReenableSuccess case
298TEST_F(TestOltDisableReenable, OltReenableSuccess){
299 // NiceMock is used to suppress 'WillByDefault' return errors.
300 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
301 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500302 uint32_t pon_id = 0;
303 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
304 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000305 Status olt_reenable_res;
306
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500307 bcmolt_pon_interface_key pon_key;
308 bcmolt_pon_interface_cfg pon_cfg;
309 pon_key.pon_ni = pon_id;
310 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
311 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
312
313 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530314 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500315 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
316
317 bcmolt_tm_sched_cfg tm_sched_cfg;
318 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
319 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
320 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
321
322 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530323 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500324 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000325
326 olt_reenable_res = Reenable_();
327 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
328
329}
330
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500331// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000332TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
333 // NiceMock is used to suppress 'WillByDefault' return errors.
334 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
335 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500336 uint32_t pon_id = 0;
337 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000338 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000339 Status olt_reenable_res;
340
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500341 bcmolt_pon_interface_key pon_key;
342 bcmolt_pon_interface_cfg pon_cfg;
343 pon_key.pon_ni = pon_id;
344 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
345 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
346
347 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530348 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500349 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000350 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530351 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000352 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500353
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000354 olt_reenable_res = Reenable_();
355 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
356}
357
358////////////////////////////////////////////////////////////////////////////
359// For testing ProbeDeviceCapabilities functionality
360////////////////////////////////////////////////////////////////////////////
361class TestProbeDevCapabilities : public Test {
362 protected:
363 NiceMock<BalMocker> balMock;
364 bcmos_errno olt_res_success = BCM_ERR_OK;
365 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
366 bcmos_errno dev_res_success = BCM_ERR_OK;
367 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
368
369 virtual void SetUp() {
370 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
371
372 bcmolt_olt_cfg olt_cfg = { };
373 bcmolt_olt_key olt_key = { };
374
375 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
376
Girish Gowdraddf9a162020-01-27 12:56:27 +0530377 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000378 }
379
380 virtual void TearDown() {
381 }
382};
383
384// Test 1 - If querying the OLT fails, the method must return error
385TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
386
387 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
388 .WillOnce(Return(olt_res_fail));
389
390 Status query_status = ProbeDeviceCapabilities_();
391 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
392}
393
394// Test 2 - If all devices are queried successfully, the method must return Status::OK
395TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
396
397 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
398 .WillOnce(Return(olt_res_success));
399
400 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
401 .WillRepeatedly(Return(dev_res_success));
402
403 Status query_status = ProbeDeviceCapabilities_();
404
405 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
406}
407
408// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
409TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
410
411 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
412 .WillOnce(Return(olt_res_success));
413
414 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
415 .WillRepeatedly(Return(dev_res_fail));
416
417 Status query_status = ProbeDeviceCapabilities_();
418
419 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
420}
421
422// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
423TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
424
425 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
426 .WillOnce(Return(olt_res_success));
427
428 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
429 .WillOnce(Return(olt_res_success))
430 .WillRepeatedly(Return(dev_res_fail));
431
432 Status query_status = ProbeDeviceCapabilities_();
433
434 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
435}
436
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500437////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500438// For testing EnablePonIf functionality
439////////////////////////////////////////////////////////////////////////////
440
441class TestEnablePonIf : public Test {
442 protected:
443 uint32_t pon_id = 0;
444 NiceMock<BalMocker> balMock;
445
446 virtual void SetUp() {
447 }
448
449 virtual void TearDown() {
450 }
451};
452
453// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
454TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
455 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
456 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
457 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
458 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
459
460 bcmolt_pon_interface_key pon_key;
461 bcmolt_pon_interface_cfg pon_cfg;
462 pon_key.pon_ni = pon_id;
463 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
464 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
465 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
466 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
467
468 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
469 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
470
471 bcmolt_tm_sched_cfg tm_sched_cfg;
472 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
473 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
474 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
475 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
476 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
477
478 Status status = EnablePonIf_(pon_id);
479 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
480}
481
482// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
483TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
484 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
485 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
486 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
487 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
488
489 bcmolt_pon_interface_key pon_key;
490 bcmolt_pon_interface_cfg pon_cfg;
491 pon_key.pon_ni = pon_id;
492 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
493 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
494 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
495 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
496
497 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
498 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
499
500 bcmolt_tm_sched_cfg tm_sched_cfg;
501 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
502 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
503 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
504 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
505 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
506
507 Status status = EnablePonIf_(pon_id);
508 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
509}
510
511// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
512TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
513 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
514 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
515 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
516 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
517 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
518
519 bcmolt_pon_interface_key pon_key;
520 bcmolt_pon_interface_cfg pon_cfg;
521 pon_key.pon_ni = pon_id;
522 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
523 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
524 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
525 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
526
527 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
528 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
529 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
530
531 bcmolt_tm_sched_cfg tm_sched_cfg;
532 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
533 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
534 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
535 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
536 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
537
538 Status status = EnablePonIf_(pon_id);
539 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
540}
541
542// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
543TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
544 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
545 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
546 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
547 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
548 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
549 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
550
551 bcmolt_pon_interface_key pon_key;
552 bcmolt_pon_interface_cfg pon_cfg;
553 pon_key.pon_ni = pon_id;
554 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
555 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
556 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
557 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
558
559 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
560 .WillOnce(Return(olt_cfg_set_res))
561 .WillRepeatedly(Return(olt_cfg_set_err));
562 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
563 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
564
565 bcmolt_tm_sched_cfg tm_sched_cfg;
566 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
567 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
568 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
569 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
570 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
571
572 Status status = EnablePonIf_(pon_id);
573 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
574}
575
576// Test 5 - EnablePonIf already enabled success
577TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
578 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
579
580 bcmolt_pon_interface_key pon_key;
581 bcmolt_pon_interface_cfg pon_cfg;
582 pon_key.pon_ni = pon_id;
583 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
584 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
585 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
586 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
587
588 Status status = EnablePonIf_(pon_id);
589 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
590}
591
592// Test 6 - EnablePonIf - enable onu discovery failure case
593TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
594 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
595 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
596
597 bcmolt_pon_interface_key pon_key;
598 bcmolt_pon_interface_cfg pon_cfg;
599 pon_key.pon_ni = pon_id;
600 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
601 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
602 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
603 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
604 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
605
606 Status status = EnablePonIf_(pon_id);
607 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
608}
609
610// Test 7 - EnablePonIf failure case
611TEST_F(TestEnablePonIf, EnablePonIfFailed) {
612 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
613 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
614 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
615
616 bcmolt_pon_interface_key pon_key;
617 bcmolt_pon_interface_cfg pon_cfg;
618 pon_key.pon_ni = pon_id;
619 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
620 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
621 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
622 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
623 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
624 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
625
626 Status status = EnablePonIf_(pon_id);
627 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
628}
629
630////////////////////////////////////////////////////////////////////////////
631// For testing SetStateUplinkIf functionality
632////////////////////////////////////////////////////////////////////////////
633
634class TestSetStateUplinkIf : public Test {
635 protected:
636 uint32_t intf_id = 0;
637 NiceMock<BalMocker> balMock;
638
639 virtual void SetUp() {
640 }
641
642 virtual void TearDown() {
643 }
644};
645
646// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
647TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
648 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
649 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
650 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
651
652 bcmolt_nni_interface_key nni_key;
653 bcmolt_nni_interface_cfg nni_cfg;
654 nni_key.id = intf_id;
655 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
656 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
657 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
658 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
659
660 bcmolt_tm_sched_cfg tm_sched_cfg;
661 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
662 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
663 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
664 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
665 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
666 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
667
668 Status status = SetStateUplinkIf_(intf_id, true);
669 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
670}
671
672// Test 2 - SetStateUplinkIf, NNI interface already disabled case
673TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
674 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
675
676 bcmolt_nni_interface_key nni_key;
677 bcmolt_nni_interface_cfg nni_cfg;
678 nni_key.id = intf_id;
679 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
680 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
681 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
682 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
683
684 Status status = SetStateUplinkIf_(intf_id, false);
685 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
686}
687
688// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
689TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
690 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
691 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
692 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
693 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
694
695 bcmolt_nni_interface_key nni_key;
696 bcmolt_nni_interface_cfg nni_cfg;
697 nni_key.id = intf_id;
698 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
699 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
700 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
701 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
702
703 bcmolt_tm_sched_cfg tm_sched_cfg;
704 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
705 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
706 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
707 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
708 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
709 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
710 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
711
712 Status status = SetStateUplinkIf_(intf_id, true);
713 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
714}
715
716// Test 4 - SetStateUplinkIf Enable failure case
717TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
718 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
719 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
720
721 bcmolt_nni_interface_key nni_key;
722 bcmolt_nni_interface_cfg nni_cfg;
723 nni_key.id = intf_id;
724 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
725 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
726 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
727 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
728 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
729
730 Status status = SetStateUplinkIf_(intf_id, true);
731 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
732}
733
734// Test 5 - SetStateUplinkIf Disable success case
735TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
736 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
737 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
738
739 bcmolt_nni_interface_key nni_key;
740 bcmolt_nni_interface_cfg nni_cfg;
741 nni_key.id = intf_id;
742 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
743 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
744 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
745 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
746 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
747
748 Status status = SetStateUplinkIf_(intf_id, false);
749 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
750}
751
752// Test 6 - SetStateUplinkIf Disable failure case
753TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
754 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
755 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
756
757 bcmolt_nni_interface_key nni_key;
758 bcmolt_nni_interface_cfg nni_cfg;
759 nni_key.id = intf_id;
760 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
761 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
762 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
763 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
764 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
765
766 Status status = SetStateUplinkIf_(intf_id, false);
767 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
768}
769
770////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500771// For testing DisablePonIf functionality
772////////////////////////////////////////////////////////////////////////////
773
774class TestDisablePonIf : public Test {
775 protected:
776 virtual void SetUp() {
777 }
778
779 virtual void TearDown() {
780 }
781};
782
Girish Gowdrae1db2952021-05-04 00:16:54 -0700783// Test 1 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_ACTIVE_WORKING state
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500784TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
785 bcmos_errno olt_oper_res = BCM_ERR_OK;
786 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
787 NiceMock<BalMocker> balMock;
788 uint32_t pon_id=1;
789
Girish Gowdrae1db2952021-05-04 00:16:54 -0700790 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
791 bcmolt_pon_interface_cfg interface_obj;
792
793 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
794 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
795
796 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
797 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
798 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
799 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
800 return pon_intf_get_res;
801 }
802 ));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500803 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
804 state.deactivate();
805 Status status = DisablePonIf_(pon_id);
806
807 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
808}
809
Girish Gowdrae1db2952021-05-04 00:16:54 -0700810// Test 2 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
811TEST_F(TestDisablePonIf, DisablePonIf_OperSubmitErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500812 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
813 NiceMock<BalMocker> balMock;
814 uint32_t pon_id=1;
815
Girish Gowdrae1db2952021-05-04 00:16:54 -0700816 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
817 bcmolt_pon_interface_cfg interface_obj;
818
819 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
820 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
821
822 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
823 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
824 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
825 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
826 return pon_intf_get_res;
827 }
828 ));
829
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500830 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
831 state.deactivate();
832 Status status = DisablePonIf_(pon_id);
833
834 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
835}
836
Girish Gowdrae1db2952021-05-04 00:16:54 -0700837// Test 3 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
838TEST_F(TestDisablePonIf, DisablePonIf_CfgSetErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500839 NiceMock<BalMocker> balMock;
840 uint32_t pon_id=1;
841 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700842
843 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
844 bcmolt_pon_interface_cfg interface_obj;
845
846 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
847 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
848
849 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
850 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
851 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
852 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
853 return pon_intf_get_res;
854 }
855 ));
856
857
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500858 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
859 state.deactivate();
860 Status status = DisablePonIf_(pon_id);
861
862 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
863}
864
Girish Gowdrae1db2952021-05-04 00:16:54 -0700865// Test 4 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_INACTIVE state
866TEST_F(TestDisablePonIf, DisablePonIfSuccess_PonIntfInactive) {
867 bcmos_errno olt_oper_res = BCM_ERR_OK;
868 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
869 NiceMock<BalMocker> balMock;
870 uint32_t pon_id=1;
871
872 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
873 bcmolt_pon_interface_cfg interface_obj;
874
875 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
876 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
877
878 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
879 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
880 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
881 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
882 return pon_intf_get_res;
883 }
884 ));
885 state.deactivate();
886 Status status = DisablePonIf_(pon_id);
887
888 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
889}
890
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500891////////////////////////////////////////////////////////////////////////////
892// For testing ActivateOnu functionality
893////////////////////////////////////////////////////////////////////////////
894
895class TestActivateOnu : public Test {
896 protected:
897 uint32_t pon_id = 0;
898 uint32_t onu_id = 1;
899 std::string vendor_id = "TWSH";
900 std::string vendor_specific = "80808080";
901 uint32_t pir = 1000000;
902 NiceMock<BalMocker> balMock;
903
904 virtual void SetUp() {
905 }
906
907 virtual void TearDown() {
908 }
909};
910
Girish Gowdra24297032020-03-23 12:32:37 -0700911// Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state
912TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) {
913 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
914 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500915 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
Girish Gowdra24297032020-03-23 12:32:37 -0700916 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500917
918 bcmolt_onu_cfg onu_cfg;
919 bcmolt_onu_key onu_key;
920 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
Girish Gowdra24297032020-03-23 12:32:37 -0700921 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500922 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
923 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
924
925 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
926 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
Girish Gowdra24297032020-03-23 12:32:37 -0700927 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500928
kesavandc1f2db92020-08-31 15:32:06 +0530929 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500930 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
931}
932
Girish Gowdra24297032020-03-23 12:32:37 -0700933// Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state
934TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500935 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
936 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
937
938 bcmolt_onu_cfg onu_cfg;
939 bcmolt_onu_key onu_key;
940 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
941 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
942 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
943 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra24297032020-03-23 12:32:37 -0700944
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500945 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
946
kesavandc1f2db92020-08-31 15:32:06 +0530947 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500948 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
949}
950
Girish Gowdra24297032020-03-23 12:32:37 -0700951// Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state
952TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) {
953 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
954 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
955 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
956
957 bcmolt_onu_cfg onu_cfg;
958 bcmolt_onu_key onu_key;
959 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
960 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
961 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
962 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
963
964 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
965 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
966
967
kesavandc1f2db92020-08-31 15:32:06 +0530968 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700969 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
970}
971
972// Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE)
973TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) {
974 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
975 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
976
977 bcmolt_onu_cfg onu_cfg;
978 bcmolt_onu_key onu_key;
979 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
980 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process
981 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
982 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
983
984 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
985
kesavandc1f2db92020-08-31 15:32:06 +0530986 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700987 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
988}
989
990// Test 5 - ActivateOnu failure case - cfg_get failure
991TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) {
992 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure
993
994 bcmolt_onu_cfg onu_cfg;
995 bcmolt_onu_key onu_key;
996 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
997 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
998 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
999 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1000
kesavandc1f2db92020-08-31 15:32:06 +05301001 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001002 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1003}
1004
1005// Test 6 - ActivateOnu failure case - oper_submit failure
1006TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) {
1007 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1008 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1009 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
1010 bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure
1011
1012 bcmolt_onu_cfg onu_cfg;
1013 bcmolt_onu_key onu_key;
1014 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1015 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
1016 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1017 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1018
1019 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
1020 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
1021 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
1022
kesavandc1f2db92020-08-31 15:32:06 +05301023 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001024 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1025}
1026
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001027////////////////////////////////////////////////////////////////////////////
1028// For testing DeactivateOnu functionality
1029////////////////////////////////////////////////////////////////////////////
1030
1031class TestDeactivateOnu : public Test {
1032 protected:
1033 uint32_t pon_id = 0;
1034 uint32_t onu_id = 1;
1035 std::string vendor_id = "TWSH";
1036 std::string vendor_specific = "80808080";
1037 NiceMock<BalMocker> balMock;
1038
1039 virtual void SetUp() {
1040 }
1041
1042 virtual void TearDown() {
1043 }
1044};
1045
1046// Test 1 - DeactivateOnu success case
1047TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001048 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1049
Girish Gowdra72cbee92021-11-05 15:16:18 -07001050 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1051 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001052 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001053 onu_key.pon_ni = 0;
1054 onu_key.onu_id = 1;
1055
1056 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1057
1058 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1059 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1060 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1061 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1062 return onu_cfg_get_res;
1063 }
1064 ));
1065
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001066
1067 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1068
1069 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1070 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1071}
1072
1073// Test 2 - DeactivateOnu failure case
1074TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001075 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1076
Girish Gowdra72cbee92021-11-05 15:16:18 -07001077 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1078 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001079 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001080 onu_key.pon_ni = 0;
1081 onu_key.onu_id = 1;
1082
1083 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1084
1085 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1086 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1087 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1088 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1089 return onu_cfg_get_res;
1090 }
1091 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001092
1093 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1094
1095 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1096 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1097}
1098
1099////////////////////////////////////////////////////////////////////////////
1100// For testing DeleteOnu functionality
1101////////////////////////////////////////////////////////////////////////////
1102
1103class TestDeleteOnu : public Test {
1104 protected:
1105 uint32_t pon_id = 0;
1106 uint32_t onu_id = 1;
1107 std::string vendor_id = "TWSH";
1108 std::string vendor_specific = "80808080";
1109 NiceMock<BalMocker> balMock;
1110
1111 virtual void SetUp() {
1112 }
1113
1114 virtual void TearDown() {
1115 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301116 public:
1117 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
1118 onu_deactivate_complete_result res;
1119 res.pon_intf_id = 0;
1120 res.onu_id = 1;
1121 res.result = result;
1122 res.reason = reason;
1123 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
1124 // before we push the result.
1125 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1126 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
1127 onu_deact_compltd_key k(0, 1);
1128 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
1129 if (it == onu_deact_compltd_map.end()) {
1130 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
1131 } else {
1132 it->second->push(res);
1133 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
1134 }
1135 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
1136 return 0;
1137 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001138};
1139
1140// Test 1 - DeleteOnu success case
1141TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001142 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1143 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1144
Girish Gowdra72cbee92021-11-05 15:16:18 -07001145 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1146 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001147 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001148 onu_key.pon_ni = 0;
1149 onu_key.onu_id = 1;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001150
Girish Gowdra72cbee92021-11-05 15:16:18 -07001151 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1152
1153 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1154 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1155 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1156 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1157 return onu_cfg_get_res;
1158 }
1159 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001160 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1161 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1162
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301163 future<int> push_onu_deact_complt_res = \
1164 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1165 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1166 Status status = future_res.get();
1167 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001168 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1169}
1170
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301171// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1172TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001173 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1174 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1175
Girish Gowdra72cbee92021-11-05 15:16:18 -07001176 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1177 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001178 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001179 onu_key.pon_ni = 0;
1180 onu_key.onu_id = 1;
1181
1182 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1183
1184 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1185 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1186 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1187 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1188 return onu_cfg_get_res;
1189 }
1190 ));
1191
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001192
1193 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1194 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1195
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301196 future<int> push_onu_deact_complt_res = \
1197 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1198 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1199
1200 Status status = future_res.get();
1201 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001202 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1203}
1204
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301205// Test 3 - DeleteOnu failure case - onu deactivation fails
1206TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301207 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1208
Girish Gowdra72cbee92021-11-05 15:16:18 -07001209 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1210 bcmolt_onu_cfg onu_cfg_out;
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301211 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001212 onu_key.pon_ni = 0;
1213 onu_key.onu_id = 1;
1214
1215 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1216
1217 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1218 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1219 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1220 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1221 return onu_cfg_get_res;
1222 }
1223 ));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301224
1225 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1226
1227 future<int> push_onu_deact_complt_res = \
1228 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1229 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1230
1231 Status status = future_res.get();
1232 int res = push_onu_deact_complt_res.get();
1233 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1234}
1235
1236// Test 4 - DeleteOnu failure case - onu deactivation timesout
1237TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301238 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1239
Girish Gowdra72cbee92021-11-05 15:16:18 -07001240 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1241 bcmolt_onu_cfg onu_cfg_out;
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301242 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001243 onu_key.pon_ni = 0;
1244 onu_key.onu_id = 1;
1245
1246 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1247
1248 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1249 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1250 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1251 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1252 return onu_cfg_get_res;
1253 }
1254 ));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301255
1256 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1257
1258 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1259
1260 Status status = future_res.get();
1261 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1262}
1263
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301264// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1265TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301266 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1267 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1268
Girish Gowdra72cbee92021-11-05 15:16:18 -07001269 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1270 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301271 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001272 onu_key.pon_ni = 0;
1273 onu_key.onu_id = 1;
1274
1275 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1276
1277 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1278 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1279 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1280 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1281 return onu_cfg_get_res;
1282 }
1283 ));
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301284
1285 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1286 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1287
1288 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1289
1290 Status status = future_res.get();
1291 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1292}
1293
1294// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1295TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1296 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1297
Girish Gowdra72cbee92021-11-05 15:16:18 -07001298 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
1299 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301300 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001301 onu_key.pon_ni = 0;
1302 onu_key.onu_id = 1;
1303
1304 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1305
1306 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1307 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1308 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1309 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1310 return onu_cfg_get_res;
1311 }
1312 ));
1313
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301314
1315 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1316
1317 Status status = future_res.get();
1318 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1319}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301320
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001321////////////////////////////////////////////////////////////////////////////
1322// For testing OmciMsgOut functionality
1323////////////////////////////////////////////////////////////////////////////
1324
1325class TestOmciMsgOut : public Test {
1326 protected:
1327 uint32_t pon_id = 0;
1328 uint32_t onu_id = 1;
1329 std::string pkt = "omci-pkt";
1330 NiceMock<BalMocker> balMock;
1331
1332 virtual void SetUp() {
1333 }
1334
1335 virtual void TearDown() {
1336 }
1337};
1338
1339// Test 1 - OmciMsgOut success case
1340TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1341 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1342
1343 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1344
1345 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1346 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1347}
1348
1349// Test 1 - OmciMsgOut failure case
1350TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1351 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1352
1353 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1354
1355 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1356 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1357}
1358
1359////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001360// For testing FlowAdd functionality
1361////////////////////////////////////////////////////////////////////////////
1362
1363class TestFlowAdd : public Test {
1364 protected:
1365 int32_t access_intf_id = 0;
1366 int32_t onu_id = 1;
1367 int32_t uni_id = 0;
1368 uint32_t port_no = 16;
1369 uint32_t flow_id = 1;
1370 std::string flow_type = "upstream";
1371 int32_t alloc_id = 1024;
1372 int32_t network_intf_id = 0;
1373 int32_t gemport_id = 1024;
1374 int32_t priority_value = 0;
1375 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301376 int32_t group_id = -1;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001377 uint32_t tech_profile_id = 64;
Burak Gurdaga0523592021-02-24 15:17:47 +00001378 bool enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001379
1380 NiceMock<BalMocker> balMock;
1381 openolt::Flow* flow;
1382 openolt::Classifier* classifier;
1383 openolt::Action* action;
1384 openolt::ActionCmd* cmd;
1385
1386 bcmolt_flow_key flow_key;
1387 bcmolt_flow_cfg flow_cfg;
1388
1389 tech_profile::TrafficQueues* traffic_queues;
1390 tech_profile::TrafficQueue* traffic_queue_1;
1391 tech_profile::TrafficQueue* traffic_queue_2;
1392 tech_profile::DiscardConfig* discard_config_1;
1393 tech_profile::DiscardConfig* discard_config_2;
1394 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1395 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1396
1397
1398 virtual void SetUp() {
1399 classifier = new openolt::Classifier;
1400 action = new openolt::Action;
1401 cmd = new openolt::ActionCmd;
1402
1403 classifier->set_o_tpid(0);
1404 classifier->set_o_vid(7);
1405 classifier->set_i_tpid(0);
1406 classifier->set_i_vid(0);
1407 classifier->set_o_pbits(0);
1408 classifier->set_i_pbits(0);
1409 classifier->set_eth_type(0);
1410 classifier->set_ip_proto(0);
1411 classifier->set_src_port(0);
1412 classifier->set_dst_port(0);
1413 classifier->set_pkt_tag_type("single_tag");
1414
1415 action->set_o_vid(12);
1416 action->set_o_pbits(0);
1417 action->set_o_tpid(0);
1418 action->set_i_vid(0);
1419 action->set_i_pbits(0);
1420 action->set_i_tpid(0);
1421
1422 cmd->set_add_outer_tag(true);
1423 cmd->set_remove_outer_tag(false);
1424 cmd->set_trap_to_host(false);
1425 action->set_allocated_cmd(cmd);
1426
1427 flow_key.flow_id = 1;
1428 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1429 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1430 flow_cfg.data.onu_id=1;
1431 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1432 flow_cfg.data.svc_port_id=1024;
1433 flow_cfg.data.priority=0;
1434 flow_cfg.data.cookie=0;
1435 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1436 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1437 flow_cfg.data.ingress_intf.intf_id=0;
1438 flow_cfg.data.egress_intf.intf_id=0;
1439 flow_cfg.data.classifier.o_vid=7;
1440 flow_cfg.data.classifier.o_pbits=0;
1441 flow_cfg.data.classifier.i_vid=0;
1442 flow_cfg.data.classifier.i_pbits=0;
1443 flow_cfg.data.classifier.ether_type=0;
1444 flow_cfg.data.classifier.ip_proto=0;
1445 flow_cfg.data.classifier.src_port=0;
1446 flow_cfg.data.classifier.dst_port=0;
1447 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1448 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1449 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1450 flow_cfg.data.egress_qos.tm_sched.id=1020;
1451 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1452 flow_cfg.data.action.o_vid=12;
1453 flow_cfg.data.action.o_pbits=0;
1454 flow_cfg.data.action.i_vid=0;
1455 flow_cfg.data.action.i_pbits=0;
1456 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1457
1458 traffic_queues = new tech_profile::TrafficQueues;
1459 traffic_queues->set_intf_id(0);
1460 traffic_queues->set_onu_id(2);
1461 traffic_queue_1 = traffic_queues->add_traffic_queues();
1462 traffic_queue_1->set_gemport_id(1024);
1463 traffic_queue_1->set_pbit_map("0b00000101");
1464 traffic_queue_1->set_aes_encryption(true);
1465 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1466 traffic_queue_1->set_priority(0);
1467 traffic_queue_1->set_weight(0);
1468 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1469 discard_config_1 = new tech_profile::DiscardConfig;
1470 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1471 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1472 tail_drop_discard_config_1->set_queue_size(8);
1473 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1474 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1475
1476 traffic_queues->set_uni_id(0);
1477 traffic_queues->set_port_no(16);
1478
1479 traffic_queue_2 = traffic_queues->add_traffic_queues();
1480 traffic_queue_2->set_gemport_id(1025);
1481 traffic_queue_2->set_pbit_map("0b00001010");
1482 traffic_queue_2->set_aes_encryption(true);
1483 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1484 traffic_queue_2->set_priority(1);
1485 traffic_queue_2->set_weight(0);
1486 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1487 discard_config_2 = new tech_profile::DiscardConfig;
1488 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1489 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1490 tail_drop_discard_config_2->set_queue_size(8);
1491 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1492 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1493 }
1494
1495 virtual void TearDown() {
1496 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301497
1498 public:
1499 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
1500 gem_cfg_compltd_key k(0, gem_port_id);
1501 gem_cfg_complete_result res;
1502 res.pon_intf_id = 0;
1503 res.gem_port_id = gem_port_id;
1504 res.state = state;
1505 res.status = status;
1506
1507 uint32_t gem_cfg_key_check_counter = 1;
1508 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
1509 while(true) {
1510 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1511 it = gem_cfg_compltd_map.find(k);
1512
1513 if (it != gem_cfg_compltd_map.end()) {
1514 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1515 break;
1516 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
1517 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1518
1519 // We need to wait for some time to allow the Gem Cfg Request to be triggered
1520 // before we push the result.
1521 bcmos_usleep(6000);
1522 } else {
1523 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
1524 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1525 return 0;
1526 }
1527 gem_cfg_key_check_counter++;
1528 }
1529
1530 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1531 if (it->second) {
1532 it->second->push(res);
1533 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
1534 }
1535 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1536 return 0;
1537 }
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001538};
1539
1540// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1541TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1542 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1543 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1544
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301545 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001546 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001547 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1548}
1549
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301550#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001551// Test 2 - FlowAdd - Duplicate Flow case
1552TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1553 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1554 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1555 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1556
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301557 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001558 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001559 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1560}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301561#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001562
1563// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1564TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1565 gemport_id = 1025;
1566
1567 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1568 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1569
1570 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1571 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1572 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1573
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301574 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001575 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001576 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1577}
1578
1579// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1580TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1581 flow_type = "bidirectional";
1582
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301583 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001584 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001585 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1586}
1587
1588// Test 5 - FlowAdd - Failure case(Invalid network setting)
1589TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1590 network_intf_id = -1;
1591
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301592 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001593 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001594 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1595}
1596
1597// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1598TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1599 flow_id = 2;
1600
1601 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301602 action = new openolt::Action;
1603 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001604 cmd->set_trap_to_host(true);
1605 action->set_allocated_cmd(cmd);
1606
1607 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1608 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1609 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1610 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1611 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1612
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301613 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001614 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001615 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1616}
1617
1618// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1619TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1620 flow_id = 3;
1621 gemport_id = 1025;
1622
1623 classifier->set_ip_proto(17);
1624 classifier->set_src_port(68);
1625 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301626 action = new openolt::Action;
1627 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001628 cmd->set_trap_to_host(true);
1629 action->set_allocated_cmd(cmd);
1630
1631 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1632 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1633 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1634 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1635 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1636
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301637 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001638 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001639 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1640}
1641
1642// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1643TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1644 flow_id = 4;
1645 flow_type = "downstream";
1646
1647 classifier->set_o_vid(12);
1648 classifier->set_i_vid(7);
1649 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301650 action = new openolt::Action;
1651 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001652 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001653 cmd->set_remove_outer_tag(true);
1654 action->set_allocated_cmd(cmd);
1655
1656 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1657 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1658 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1659 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1660 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1661
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301662 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001663 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001664 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1665}
1666
1667// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1668TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1669 onu_id = 2;
1670 flow_id = 5;
1671 alloc_id = 1025;
1672
1673 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1674 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1675
1676 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1677 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1678 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1679 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1680 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001681
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301682 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
1683 future<int> push_gem_cfg_complt = \
1684 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1685 push_gem_cfg_complt = \
1686 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
1687 Status status = future_res.get();
1688 int res = push_gem_cfg_complt.get();
1689
1690 status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001691 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001692 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1693}
1694
1695// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1696TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1697 onu_id = 2;
1698 flow_id = 6;
1699 flow_type = "downstream";
1700 alloc_id = 1025;
1701
1702 classifier->set_o_vid(12);
1703 classifier->set_i_vid(7);
1704 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301705 action = new openolt::Action;
1706 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001707 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001708 cmd->set_remove_outer_tag(true);
1709 action->set_allocated_cmd(cmd);
1710
1711 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1712 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1713
1714 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1715 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1716 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1717 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1718 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1719 CreateTrafficQueues_(traffic_queues);
1720
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301721 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001722 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001723 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1724}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301725
Burak Gurdaga0523592021-02-24 15:17:47 +00001726// Test 11 - FlowAdd - success case (Downstream-Encrypted GEM)
1727TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) {
1728 onu_id = 2;
1729 flow_id = 7;
1730 flow_type = "downstream";
1731 alloc_id = 1025;
1732 enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001733
Burak Gurdaga0523592021-02-24 15:17:47 +00001734 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1735 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1736 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1737 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1738 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1739
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301740 future<Status> future_res = async(launch::async, FlowAdd_, access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
Burak Gurdaga0523592021-02-24 15:17:47 +00001741 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301742
1743 future<int> push_gem_cfg_complt = \
1744 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1745 Status status = future_res.get();
1746 int res = push_gem_cfg_complt.get();
Burak Gurdaga0523592021-02-24 15:17:47 +00001747 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1748}
1749
1750// Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied)
1751TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) {
1752 onu_id = 2;
1753 flow_id = 8;
1754 flow_type = "downstream";
1755 alloc_id = 1025;
1756 enable_encryption = false;
1757
1758 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1759 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1760 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1761 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1762 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1763
1764 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1765 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1766 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1767}
1768
1769// Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied)
1770TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) {
1771 onu_id = 2;
1772 flow_id = 9;
1773 flow_type = "upstream";
1774 alloc_id = 1025;
1775 enable_encryption = true;
1776
1777 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1778 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1779 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1780 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1781 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1782
1783 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1784 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1785 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1786}
1787
1788// Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied)
1789TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) {
1790 onu_id = 2;
1791 flow_id = 10;
1792 flow_type = "multicast";
1793 alloc_id = 1025;
1794 enable_encryption = true;
1795
1796 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1797 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1798 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1799 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1800 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1801
1802 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1803 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1804 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1805}
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001806////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001807// For testing OnuPacketOut functionality
1808////////////////////////////////////////////////////////////////////////////
1809
1810class TestOnuPacketOut : public Test {
1811 protected:
1812 uint32_t pon_id = 0;
1813 uint32_t onu_id = 1;
1814 std::string pkt = "omci-pkt";
1815 NiceMock<BalMocker> balMock;
1816
1817 virtual void SetUp() {
1818 }
1819
1820 virtual void TearDown() {
1821 }
1822};
1823
1824// Test 1 - OnuPacketOut success case
1825TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1826 uint32_t port_no = 16;
1827 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001828
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001829 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001830 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1831
1832 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1833 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1834}
1835
1836// Test 2 - OnuPacketOut Port number as 0 case
1837TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1838 uint32_t port_no = 0;
1839 uint32_t gemport_id = 1024;
1840
1841 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1842 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1843}
1844
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001845// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1846TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1847 uint32_t port_no = 16;
1848 uint32_t gemport_id = 0;
1849
1850 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1851 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1852
1853 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1854 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1855}
1856
1857// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1858TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1859 uint32_t port_no = 64;
1860 uint32_t gemport_id = 0;
1861
1862 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1863 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1864
1865 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1866 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1867}
1868
1869////////////////////////////////////////////////////////////////////////////
1870// For testing FlowRemove functionality
1871////////////////////////////////////////////////////////////////////////////
1872
1873class TestFlowRemove : public Test {
1874 protected:
1875 NiceMock<BalMocker> balMock;
1876
1877 virtual void SetUp() {
1878 }
1879
1880 virtual void TearDown() {
1881 }
1882};
1883
1884// Test 1 - FlowRemove - Failure case
1885TEST_F(TestFlowRemove, FlowRemoveFailure) {
1886 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1887 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1888
1889 Status status = FlowRemove_(1, "upstream");
1890 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1891}
1892
1893// Test 2 - FlowRemove - success case
1894TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1895 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1896 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1897
1898 Status status = FlowRemove_(1, "upstream");
1899 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1900}
1901
1902////////////////////////////////////////////////////////////////////////////
1903// For testing UplinkPacketOut functionality
1904////////////////////////////////////////////////////////////////////////////
1905
1906class TestUplinkPacketOut : public Test {
1907 protected:
1908 uint32_t pon_id = 0;
1909 std::string pkt = "omci-pkt";
1910 NiceMock<BalMocker> balMock;
1911
1912 bcmolt_flow_key flow_key;
1913 bcmolt_flow_cfg flow_cfg;
1914
1915 virtual void SetUp() {
1916 flow_key.flow_id = 1;
1917 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1918 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1919 flow_cfg.data.onu_id=1;
1920 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1921 flow_cfg.data.svc_port_id=1024;
1922 flow_cfg.data.priority=0;
1923 flow_cfg.data.cookie=0;
1924 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1925 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1926 flow_cfg.data.ingress_intf.intf_id=0;
1927 flow_cfg.data.egress_intf.intf_id=0;
1928 flow_cfg.data.classifier.o_vid=7;
1929 flow_cfg.data.classifier.o_pbits=0;
1930 flow_cfg.data.classifier.i_vid=0;
1931 flow_cfg.data.classifier.i_pbits=0;
1932 flow_cfg.data.classifier.ether_type=0;
1933 flow_cfg.data.classifier.ip_proto=0;
1934 flow_cfg.data.classifier.src_port=0;
1935 flow_cfg.data.classifier.dst_port=0;
1936 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1937 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1938 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1939 flow_cfg.data.egress_qos.tm_sched.id=1020;
1940 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1941 flow_cfg.data.action.o_vid=12;
1942 flow_cfg.data.action.o_pbits=0;
1943 flow_cfg.data.action.i_vid=0;
1944 flow_cfg.data.action.i_pbits=0;
1945 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1946 }
1947
1948 virtual void TearDown() {
1949 }
1950};
1951
1952// Test 1 - UplinkPacketOut success case
1953TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1954 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1955 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1956 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1957 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1958 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1959
1960 Status status = UplinkPacketOut_(pon_id, pkt);
1961 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1962}
1963
1964// Test 2 - UplinkPacketOut Failure case
1965TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1966 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1967 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1968 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1969 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1970 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1971
1972 Status status = UplinkPacketOut_(pon_id, pkt);
1973 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1974}
1975
1976// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1977TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1978 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1979
1980 FlowRemove_(2, "upstream");
1981 FlowRemove_(3, "upstream");
1982 FlowRemove_(4, "downstream");
1983 FlowRemove_(5, "upstream");
1984 FlowRemove_(6, "downstream");
Burak Gurdaga0523592021-02-24 15:17:47 +00001985 FlowRemove_(7, "downstream");
1986 FlowRemove_(8, "downstream");
1987 FlowRemove_(9, "upstream");
1988 FlowRemove_(10, "multicast");
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001989
1990 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1991 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1992 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1993
1994 Status status = UplinkPacketOut_(pon_id, pkt);
1995 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1996}
1997
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001998////////////////////////////////////////////////////////////////////////////
1999// For testing CreateTrafficSchedulers functionality
2000////////////////////////////////////////////////////////////////////////////
2001
2002class TestCreateTrafficSchedulers : public Test {
2003 protected:
2004 NiceMock<BalMocker> balMock;
2005 tech_profile::TrafficSchedulers* traffic_scheds;
2006 tech_profile::TrafficScheduler* traffic_sched;
2007 tech_profile::SchedulerConfig* scheduler;
2008 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2009
2010 virtual void SetUp() {
2011 traffic_scheds = new tech_profile::TrafficSchedulers;
2012 traffic_scheds->set_intf_id(0);
2013 traffic_scheds->set_onu_id(1);
2014 traffic_scheds->set_uni_id(0);
2015 traffic_scheds->set_port_no(16);
2016 traffic_sched = traffic_scheds->add_traffic_scheds();
2017 traffic_sched->set_alloc_id(1024);
2018 scheduler = new tech_profile::SchedulerConfig;
2019 scheduler->set_priority(0);
2020 scheduler->set_weight(0);
2021 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2022 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2023 traffic_shaping_info->set_cbs(60536);
2024 traffic_shaping_info->set_pbs(65536);
2025 traffic_shaping_info->set_gir(10000);
2026 }
2027
2028 virtual void TearDown() {
2029 }
2030
2031 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302032 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2033 alloc_cfg_compltd_key k(0, 1024);
2034 alloc_cfg_complete_result res;
2035 res.pon_intf_id = 0;
2036 res.alloc_id = 1024;
2037 res.state = state;
2038 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002039
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302040 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2041 // before we push the result.
2042 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2043 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2044 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2045 if (it == alloc_cfg_compltd_map.end()) {
2046 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 -05002047 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302048 it->second->push(res);
2049 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002050 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302051 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2052 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002053 }
2054};
2055
2056// Test 1 - CreateTrafficSchedulers-Upstream success case
2057TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
2058 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2059 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2060 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2061 traffic_sched->set_allocated_scheduler(scheduler);
2062 traffic_shaping_info->set_cir(64000);
2063 traffic_shaping_info->set_pir(128000);
2064 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2065
2066 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2067 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2068
Girish Gowdra72cbee92021-11-05 15:16:18 -07002069 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2070 bcmolt_onu_cfg onu_cfg_out;
2071 bcmolt_onu_key onu_key;
2072 onu_key.pon_ni = 0;
2073 onu_key.onu_id = 1;
2074 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2075 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2076 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2077 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2078 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2079 return onu_cfg_get_res;
2080 }
2081 ));
2082
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002083 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302084 future<int> push_alloc_cfg_complt = \
2085 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002086
2087 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302088 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002089 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2090}
2091
2092// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
2093TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
2094 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2095 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2096 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2097 traffic_sched->set_allocated_scheduler(scheduler);
2098 traffic_shaping_info->set_cir(64000);
2099 traffic_shaping_info->set_pir(128000);
2100 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2101
2102 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2103 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2104
Girish Gowdra72cbee92021-11-05 15:16:18 -07002105 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2106 bcmolt_onu_cfg onu_cfg_out;
2107 bcmolt_onu_key onu_key;
2108 onu_key.pon_ni = 0;
2109 onu_key.onu_id = 1;
2110 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2111 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2112 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2113 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2114 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2115 return onu_cfg_get_res;
2116 }
2117 ));
2118
2119 Status status = CreateTrafficSchedulers_(traffic_scheds);
2120 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2121}
2122
2123// Test 2A - CreateTrafficSchedulers-Upstream success case(ONU not in ACTIVE state)
2124TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccessOnuNotInActive) {
2125 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2126 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2127 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2128 traffic_sched->set_allocated_scheduler(scheduler);
2129 traffic_shaping_info->set_cir(64000);
2130 traffic_shaping_info->set_pir(128000);
2131 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2132
2133 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2134 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2135
2136 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2137 bcmolt_onu_cfg onu_cfg_out;
2138 bcmolt_onu_key onu_key;
2139 onu_key.pon_ni = 0;
2140 onu_key.onu_id = 1;
2141 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2142 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2143 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2144 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2145 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2146 return onu_cfg_get_res;
2147 }
2148 ));
2149
2150 Status status = CreateTrafficSchedulers_(traffic_scheds);
2151 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2152}
2153
2154// Test 2B - CreateTrafficSchedulers-Upstream failure case. cfg-get failure
2155TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamCfgGetFailure) {
2156 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2157 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2158 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2159 traffic_sched->set_allocated_scheduler(scheduler);
2160 traffic_shaping_info->set_cir(64000);
2161 traffic_shaping_info->set_pir(128000);
2162 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2163
2164 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2165 bcmos_errno olt_cfg_get_res = BCM_ERR_INTERNAL;
2166 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2167 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
2168
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002169 Status status = CreateTrafficSchedulers_(traffic_scheds);
2170 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2171}
2172
2173// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
2174TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
2175 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2176 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2177 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2178 traffic_sched->set_allocated_scheduler(scheduler);
2179 traffic_shaping_info->set_cir(64000);
2180 traffic_shaping_info->set_pir(128000);
2181 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2182
2183 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2184 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2185
Girish Gowdra72cbee92021-11-05 15:16:18 -07002186 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2187 bcmolt_onu_cfg onu_cfg_out;
2188 bcmolt_onu_key onu_key;
2189 onu_key.pon_ni = 0;
2190 onu_key.onu_id = 1;
2191 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2192 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2193 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2194 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2195 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2196 return onu_cfg_get_res;
2197 }
2198 ));
2199
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002200 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302201 future<int> push_alloc_cfg_complt = \
2202 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002203
2204 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302205 int res = push_alloc_cfg_complt.get();
2206
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002207 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2208}
2209
2210// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
2211TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
2212 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2213 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2214 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2215 traffic_sched->set_allocated_scheduler(scheduler);
2216 traffic_shaping_info->set_cir(64000);
2217 traffic_shaping_info->set_pir(128000);
2218 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2219
2220 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2221 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2222
Girish Gowdra72cbee92021-11-05 15:16:18 -07002223 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2224 bcmolt_onu_cfg onu_cfg_out;
2225 bcmolt_onu_key onu_key;
2226 onu_key.pon_ni = 0;
2227 onu_key.onu_id = 1;
2228 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2229 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2230 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2231 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2232 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2233 return onu_cfg_get_res;
2234 }
2235 ));
2236
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002237 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302238 future<int> push_alloc_cfg_complt = \
2239 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002240
2241 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302242 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002243 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2244}
2245
2246// Test 5 - CreateTrafficSchedulers-Upstream Failure case
2247TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
2248 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2249 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2250 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2251 traffic_sched->set_allocated_scheduler(scheduler);
2252 traffic_shaping_info->set_cir(64000);
2253 traffic_shaping_info->set_pir(128000);
2254 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2255
2256 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2257 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2258
2259 Status status = CreateTrafficSchedulers_(traffic_scheds);
2260 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2261}
2262
2263// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
2264TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
2265 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2266 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2267 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2268 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002269 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002270 traffic_shaping_info->set_cir(64000);
2271 traffic_shaping_info->set_pir(0);
2272 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2273
2274 Status status = CreateTrafficSchedulers_(traffic_scheds);
2275 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2276}
2277
2278// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
2279TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
2280 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2281 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2282 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2283 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002284 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002285 traffic_shaping_info->set_cir(64000);
2286 traffic_shaping_info->set_pir(32000);
2287 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2288
2289 Status status = CreateTrafficSchedulers_(traffic_scheds);
2290 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2291}
2292
2293// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
2294TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
2295 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2296 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2297 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2298 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002299 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002300 traffic_shaping_info->set_cir(64000);
2301 traffic_shaping_info->set_pir(64000);
2302 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2303
2304 Status status = CreateTrafficSchedulers_(traffic_scheds);
2305 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2306}
2307
2308// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
2309TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
2310 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2311 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2312 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2313 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002314 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002315 traffic_shaping_info->set_cir(64000);
2316 traffic_shaping_info->set_pir(0);
2317 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2318
2319 Status status = CreateTrafficSchedulers_(traffic_scheds);
2320 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2321}
2322
2323// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
2324TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
2325 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2326 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2327 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2328 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002329 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002330 traffic_shaping_info->set_cir(0);
2331 traffic_shaping_info->set_pir(32000);
2332 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2333
2334 Status status = CreateTrafficSchedulers_(traffic_scheds);
2335 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2336}
2337
2338// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
2339TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
2340 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2341 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2342 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2343 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002344 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002345 traffic_shaping_info->set_cir(64000);
2346 traffic_shaping_info->set_pir(32000);
2347 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2348
2349 Status status = CreateTrafficSchedulers_(traffic_scheds);
2350 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2351}
2352
2353// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
2354TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
2355 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2356 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2357 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2358 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002359 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002360 traffic_shaping_info->set_cir(64000);
2361 traffic_shaping_info->set_pir(64000);
2362 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2363
2364 Status status = CreateTrafficSchedulers_(traffic_scheds);
2365 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2366}
2367
2368// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
2369TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
2370 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2371 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2372 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2373 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002374 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002375 traffic_shaping_info->set_cir(64000);
2376 traffic_shaping_info->set_pir(0);
2377 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2378
2379 Status status = CreateTrafficSchedulers_(traffic_scheds);
2380 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2381}
2382
2383// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
2384TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
2385 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2386 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2387 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2388 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002389 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002390 traffic_shaping_info->set_cir(0);
2391 traffic_shaping_info->set_pir(32000);
2392 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2393
2394 Status status = CreateTrafficSchedulers_(traffic_scheds);
2395 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2396}
2397
Burak Gurdag623fada2021-04-20 22:02:36 +00002398// Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case
2399TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002400 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2401 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2402 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2403 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002404 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002405 traffic_shaping_info->set_cir(64000);
2406 traffic_shaping_info->set_pir(128000);
2407 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2408
Burak Gurdag623fada2021-04-20 22:02:36 +00002409 Status status = CreateTrafficSchedulers_(traffic_scheds);
2410 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002411}
2412
Burak Gurdag623fada2021-04-20 22:02:36 +00002413// Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case
2414TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002415 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2416 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2417 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2418 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002419 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002420 traffic_shaping_info->set_cir(64000);
2421 traffic_shaping_info->set_pir(32000);
2422 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2423
Burak Gurdag623fada2021-04-20 22:02:36 +00002424 Status status = CreateTrafficSchedulers_(traffic_scheds);
2425 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2426}
2427
2428// Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case
2429TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) {
2430 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2431 scheduler->set_additional_bw(9);
2432 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2433 traffic_sched->set_allocated_scheduler(scheduler);
2434 traffic_shaping_info->set_gir(0);
2435 traffic_shaping_info->set_cir(64000);
2436 traffic_shaping_info->set_pir(128000);
2437 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2438
2439 Status status = CreateTrafficSchedulers_(traffic_scheds);
2440 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2441}
2442
2443// Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case
2444TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) {
2445 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2446 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2447 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2448 traffic_sched->set_allocated_scheduler(scheduler);
2449 traffic_shaping_info->set_gir(64000);
2450 traffic_shaping_info->set_cir(0);
2451 traffic_shaping_info->set_pir(64000);
2452 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2453
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002454 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2455 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2456
2457 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302458 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002459 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2460
2461 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302462 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002463 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2464}
2465
Burak Gurdag623fada2021-04-20 22:02:36 +00002466// Test 19 - CreateTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002467TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2468 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2469 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2470 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2471 traffic_sched->set_allocated_scheduler(scheduler);
2472 traffic_shaping_info->set_cir(64000);
2473 traffic_shaping_info->set_pir(128000);
2474 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2475
2476 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2477 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2478
2479 Status status = CreateTrafficSchedulers_(traffic_scheds);
2480 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2481}
2482
Burak Gurdag623fada2021-04-20 22:02:36 +00002483// Test 20 - CreateTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002484TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2485 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2486 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2487 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2488 traffic_sched->set_allocated_scheduler(scheduler);
2489 traffic_shaping_info->set_cir(64000);
2490 traffic_shaping_info->set_pir(128000);
2491 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2492
2493 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2494 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2495
2496 Status status = CreateTrafficSchedulers_(traffic_scheds);
2497 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2498}
2499
Burak Gurdag623fada2021-04-20 22:02:36 +00002500// Test 21 - CreateTrafficSchedulers-Invalid direction Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002501TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2502 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2503 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2504 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2505 traffic_sched->set_allocated_scheduler(scheduler);
2506 traffic_shaping_info->set_cir(64000);
2507 traffic_shaping_info->set_pir(128000);
2508 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2509
2510 Status status = CreateTrafficSchedulers_(traffic_scheds);
2511 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2512}
2513
2514////////////////////////////////////////////////////////////////////////////
2515// For testing RemoveTrafficSchedulers functionality
2516////////////////////////////////////////////////////////////////////////////
2517
2518class TestRemoveTrafficSchedulers : public Test {
2519 protected:
2520 NiceMock<BalMocker> balMock;
2521 tech_profile::TrafficSchedulers* traffic_scheds;
2522 tech_profile::TrafficScheduler* traffic_sched;
2523 tech_profile::SchedulerConfig* scheduler;
2524 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2525 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302526 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002527
2528 virtual void SetUp() {
2529 traffic_scheds = new tech_profile::TrafficSchedulers;
2530 traffic_scheds->set_intf_id(0);
2531 traffic_scheds->set_onu_id(1);
2532 traffic_scheds->set_uni_id(0);
2533 traffic_scheds->set_port_no(16);
2534 traffic_sched = traffic_scheds->add_traffic_scheds();
2535 traffic_sched->set_alloc_id(1025);
2536 scheduler = new tech_profile::SchedulerConfig;
2537 scheduler->set_priority(0);
2538 scheduler->set_weight(0);
2539 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2540 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2541 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2542 traffic_shaping_info->set_cir(64000);
2543 traffic_shaping_info->set_pir(128000);
2544 traffic_shaping_info->set_cbs(60536);
2545 traffic_shaping_info->set_pbs(65536);
2546 traffic_shaping_info->set_gir(10000);
2547 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2548 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2549 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2550 }
2551
2552 virtual void TearDown() {
2553 }
2554
2555 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302556 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2557 alloc_cfg_compltd_key k(0, 1025);
2558 alloc_cfg_complete_result res;
2559 res.pon_intf_id = 0;
2560 res.alloc_id = 1025;
2561 res.state = state;
2562 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002563
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302564 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2565 // before we push the result.
2566 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302567 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2568 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2569 if (it == alloc_cfg_compltd_map.end()) {
2570 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 -05002571 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302572 it->second->push(res);
2573 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002574 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302575 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2576 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002577 }
2578};
2579
2580// Test 1 - RemoveTrafficSchedulers-Upstream success case
2581TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2582 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2583 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2584 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2585
Girish Gowdra72cbee92021-11-05 15:16:18 -07002586 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2587 bcmolt_onu_cfg onu_cfg_out;
2588 bcmolt_onu_key onu_key;
2589 onu_key.pon_ni = 0;
2590 onu_key.onu_id = 1;
2591
2592 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2593
2594 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2595 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2596 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2597 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2598 return onu_cfg_get_res;
2599 }
2600 ));
2601
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302602
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002603 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302604 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002605 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2606
2607 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302608 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002609 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2610}
2611
2612// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2613TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2614 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2615 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2616 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2617
Girish Gowdra72cbee92021-11-05 15:16:18 -07002618 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2619 bcmolt_onu_cfg onu_cfg_out;
2620 bcmolt_onu_key onu_key;
2621 onu_key.pon_ni = 0;
2622 onu_key.onu_id = 1;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302623
Girish Gowdra72cbee92021-11-05 15:16:18 -07002624 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2625
2626 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2627 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2628 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2629 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2630 return onu_cfg_get_res;
2631 }
2632 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002633 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302634 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002635 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2636
2637 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302638 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002639 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2640}
2641
Girish Gowdra72cbee92021-11-05 15:16:18 -07002642// Test 3 - RemoveTrafficSchedulers-Upstream success case(ONU case - Don't wait for alloc object delete response)
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302643TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2644 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2645 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2646 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2647
Girish Gowdra72cbee92021-11-05 15:16:18 -07002648 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2649 bcmolt_onu_cfg onu_cfg_out;
2650 bcmolt_onu_key onu_key;
2651 onu_key.pon_ni = 0;
2652 onu_key.onu_id = 1;
2653
2654 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2655
2656 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2657 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2658 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2659 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2660 return onu_cfg_get_res;
2661 }
2662 ));
2663
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302664
2665 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2666
2667 Status status = future_res.get();
2668 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2669}
2670
2671// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2672TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2673 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2674 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2675 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2676
Girish Gowdra72cbee92021-11-05 15:16:18 -07002677 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
2678 bcmolt_onu_cfg onu_cfg_out;
2679 bcmolt_onu_key onu_key;
2680 onu_key.pon_ni = 0;
2681 onu_key.onu_id = 1;
2682
2683 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2684
2685 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2686 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2687 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2688 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2689 return onu_cfg_get_res;
2690 }
2691 ));
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302692
2693 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2694
2695 Status status = future_res.get();
2696 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2697}
2698
2699// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002700TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2701 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2702
2703 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2704 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2705
2706 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2707 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2708}
2709
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302710// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002711TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2712 //Create Scheduler
2713 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2714 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2715 traffic_sched->set_allocated_scheduler(scheduler);
2716 CreateTrafficSchedulers_(traffic_scheds);
2717
2718 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2719 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2720
2721 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2722 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2723}
2724
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302725// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002726TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2727 //Create Scheduler
2728 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2729 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2730 traffic_sched->set_allocated_scheduler(scheduler);
2731 CreateTrafficSchedulers_(traffic_scheds);
2732
2733 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2734 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2735
2736 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2737 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2738}
2739
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302740// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002741TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2742 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2743
2744 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2745 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2746}
2747
2748////////////////////////////////////////////////////////////////////////////
2749// For testing CreateTrafficQueues functionality
2750////////////////////////////////////////////////////////////////////////////
2751
2752class TestCreateTrafficQueues : public Test {
2753 protected:
2754 NiceMock<BalMocker> balMock;
2755 tech_profile::TrafficQueues* traffic_queues;
2756 tech_profile::TrafficQueue* traffic_queue_1;
2757 tech_profile::TrafficQueue* traffic_queue_2;
2758 tech_profile::DiscardConfig* discard_config_1;
2759 tech_profile::DiscardConfig* discard_config_2;
2760 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2761 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2762
2763 virtual void SetUp() {
2764 traffic_queues = new tech_profile::TrafficQueues;
2765 traffic_queues->set_intf_id(0);
2766 traffic_queues->set_onu_id(1);
2767 traffic_queue_1 = traffic_queues->add_traffic_queues();
2768 traffic_queue_1->set_gemport_id(1024);
2769 traffic_queue_1->set_pbit_map("0b00000101");
2770 traffic_queue_1->set_aes_encryption(true);
2771 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2772 traffic_queue_1->set_priority(0);
2773 traffic_queue_1->set_weight(0);
2774 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2775 discard_config_1 = new tech_profile::DiscardConfig;
2776 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2777 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2778 tail_drop_discard_config_1->set_queue_size(8);
2779 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2780 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2781 }
2782
2783 virtual void TearDown() {
2784 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302785
2786 public:
2787 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
2788 gem_cfg_compltd_key k(0, gem_port_id);
2789 gem_cfg_complete_result res;
2790 res.pon_intf_id = 0;
2791 res.gem_port_id = gem_port_id;
2792 res.state = state;
2793 res.status = status;
2794
2795 uint32_t gem_cfg_key_check_counter = 1;
2796 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
2797 while(true) {
2798 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2799 it = gem_cfg_compltd_map.find(k);
2800
2801 if (it != gem_cfg_compltd_map.end()) {
2802 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2803 break;
2804 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
2805 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2806
2807 // We need to wait for some time to allow the Gem Cfg Request to be triggered
2808 // before we push the result.
2809 bcmos_usleep(6000);
2810 } else {
2811 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
2812 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2813 return 0;
2814 }
2815 gem_cfg_key_check_counter++;
2816 }
2817
2818 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2819 if (it->second) {
2820 it->second->push(res);
2821 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
2822 }
2823 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2824 return 0;
2825 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002826};
2827
2828// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2829TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002830 traffic_queues->set_uni_id(0);
2831 traffic_queues->set_port_no(16);
2832 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2833
2834 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2835 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2836
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302837 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2838 future<int> push_gem_cfg_complt = \
2839 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2840 Status status = future_res.get();
2841 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002842 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2843
2844 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2845 status = CreateTrafficQueues_(traffic_queues);
2846 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2847}
2848
2849// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2850TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2851 traffic_queues->set_uni_id(1);
2852 traffic_queues->set_port_no(32);
2853 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2854
2855 traffic_queue_2 = traffic_queues->add_traffic_queues();
2856 traffic_queue_2->set_gemport_id(1025);
2857 traffic_queue_2->set_pbit_map("0b00001010");
2858 traffic_queue_2->set_aes_encryption(true);
2859 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2860 traffic_queue_2->set_priority(1);
2861 traffic_queue_2->set_weight(0);
2862 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2863 discard_config_2 = new tech_profile::DiscardConfig;
2864 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2865 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2866 tail_drop_discard_config_2->set_queue_size(8);
2867 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2868 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2869 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2870
2871 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2872 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2873
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302874 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2875 future<int> push_gem_cfg_complt = \
2876 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2877 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2878 push_gem_cfg_complt = \
2879 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2880 Status status = future_res.get();
2881 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002882 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2883}
2884
2885// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2886TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2887 traffic_queues->set_uni_id(2);
2888 traffic_queues->set_port_no(16);
2889 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2890
2891 traffic_queue_2 = traffic_queues->add_traffic_queues();
2892 traffic_queue_2->set_gemport_id(1025);
2893 traffic_queue_2->set_pbit_map("0b10001010");
2894 traffic_queue_2->set_aes_encryption(true);
2895 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2896 traffic_queue_2->set_priority(1);
2897 traffic_queue_2->set_weight(0);
2898 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2899 discard_config_2 = new tech_profile::DiscardConfig;
2900 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2901 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2902 tail_drop_discard_config_2->set_queue_size(8);
2903 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2904 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2905 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2906
2907 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2908 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2909
2910 Status status = CreateTrafficQueues_(traffic_queues);
2911 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2912}
2913
2914// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2915TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2916 traffic_queues->set_uni_id(3);
2917 traffic_queues->set_port_no(16);
2918 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2919
2920 traffic_queue_2 = traffic_queues->add_traffic_queues();
2921 traffic_queue_2->set_gemport_id(1025);
2922 traffic_queue_2->set_pbit_map("0b00001010");
2923 traffic_queue_2->set_aes_encryption(true);
2924 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2925 traffic_queue_2->set_priority(1);
2926 traffic_queue_2->set_weight(0);
2927 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2928 discard_config_2 = new tech_profile::DiscardConfig;
2929 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2930 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2931 tail_drop_discard_config_2->set_queue_size(8);
2932 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2933 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2934 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2935
2936 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2937 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2938
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302939 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2940 future<int> push_gem_cfg_complt = \
2941 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2942 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2943 push_gem_cfg_complt = \
2944 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2945 Status status = future_res.get();
2946 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002947 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2948}
2949
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302950// Test 5 - CreateTrafficQueues-Downstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2951TEST_F(TestCreateTrafficQueues, CreateDownstreamPriorityQueueReachedMaxTMQMPCount) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002952 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2953 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2954 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2955
2956 traffic_queue_2 = traffic_queues->add_traffic_queues();
2957 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2958 traffic_queues->set_uni_id(uni_ids[i]);
2959 traffic_queues->set_port_no(port_nos[i]);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302960 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002961
2962 traffic_queue_2->set_gemport_id(1025);
2963 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2964 traffic_queue_2->set_aes_encryption(true);
2965 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2966 traffic_queue_2->set_priority(1);
2967 traffic_queue_2->set_weight(0);
2968 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2969 discard_config_2 = new tech_profile::DiscardConfig;
2970 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2971 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2972 tail_drop_discard_config_2->set_queue_size(8);
2973 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2974 traffic_queue_2->set_allocated_discard_config(discard_config_2);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302975 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002976
2977 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2978 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2979
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302980 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2981 future<int> push_gem_cfg_complt = \
2982 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2983 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2984 push_gem_cfg_complt = \
2985 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2986 Status status = future_res.get();
2987 int res = push_gem_cfg_complt.get();
2988
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002989 if(i==16)
2990 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2991 else
2992 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2993 }
2994}
2995
2996// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2997TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2998 traffic_queues->set_uni_id(0);
2999 traffic_queues->set_port_no(16);
3000 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3001
3002 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3003 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3004
3005 Status status = CreateTrafficQueues_(traffic_queues);
3006 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3007}
3008
3009////////////////////////////////////////////////////////////////////////////
3010// For testing RemoveTrafficQueues functionality
3011////////////////////////////////////////////////////////////////////////////
3012
3013class TestRemoveTrafficQueues : public Test {
3014 protected:
3015 NiceMock<BalMocker> balMock;
3016 tech_profile::TrafficQueues* traffic_queues;
3017 tech_profile::TrafficQueue* traffic_queue_1;
3018 tech_profile::TrafficQueue* traffic_queue_2;
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303019 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003020
3021 virtual void SetUp() {
3022 traffic_queues = new tech_profile::TrafficQueues;
3023 traffic_queues->set_intf_id(0);
3024 traffic_queues->set_onu_id(1);
3025 traffic_queue_1 = traffic_queues->add_traffic_queues();
3026 traffic_queue_1->set_gemport_id(1024);
3027 traffic_queue_1->set_priority(0);
3028 }
3029
3030 virtual void TearDown() {
3031 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303032
3033 public:
3034 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
3035 gem_cfg_compltd_key k(0, gem_port_id);
3036 gem_cfg_complete_result res;
3037 res.pon_intf_id = 0;
3038 res.gem_port_id = gem_port_id;
3039 res.state = state;
3040 res.status = status;
3041
3042 uint32_t gem_cfg_key_check_counter = 1;
3043 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
3044 while(true) {
3045 bcmos_fastlock_lock(&gem_cfg_wait_lock);
3046 it = gem_cfg_compltd_map.find(k);
3047
3048 if (it != gem_cfg_compltd_map.end()) {
3049 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3050 break;
3051 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
3052 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3053
3054 // We need to wait for some time to allow the Gem Cfg Request to be triggered
3055 // before we push the result.
3056 bcmos_usleep(6000);
3057 } else {
3058 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
3059 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3060 return 0;
3061 }
3062 gem_cfg_key_check_counter++;
3063 }
3064
3065 bcmos_fastlock_lock(&gem_cfg_wait_lock);
3066 if (it->second) {
3067 it->second->push(res);
3068 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
3069 }
3070 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3071 return 0;
3072 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003073};
3074
3075// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
3076TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003077 traffic_queues->set_uni_id(0);
3078 traffic_queues->set_port_no(16);
3079 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3080
3081 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3082 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3083
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303084 bcmolt_pon_interface_key pon_key;
3085 bcmolt_pon_interface_cfg pon_cfg;
3086 pon_key.pon_ni = pon_id;
3087 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3088 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3089 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3090 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05303091 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303092
3093 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3094 future<int> push_gem_cfg_complt = \
3095 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3096
3097 Status status = future_res.get();
3098 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003099 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3100
3101 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3102 status = RemoveTrafficQueues_(traffic_queues);
3103 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3104}
3105
3106// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
3107TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003108 traffic_queues->set_uni_id(0);
3109 traffic_queues->set_port_no(16);
3110 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3111
3112 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
3113 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3114
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303115 Status status = RemoveTrafficQueues_(traffic_queues);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003116 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3117}
3118
3119// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
3120TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
3121 //Remove scheduler so that is_tm_sched_id_present api call will return false
3122 tech_profile::TrafficSchedulers* traffic_scheds;
3123 tech_profile::TrafficScheduler* traffic_sched;
3124 traffic_scheds = new tech_profile::TrafficSchedulers;
3125 traffic_scheds->set_intf_id(0);
3126 traffic_scheds->set_onu_id(1);
3127 traffic_scheds->set_uni_id(0);
3128 traffic_scheds->set_port_no(16);
3129 traffic_sched = traffic_scheds->add_traffic_scheds();
3130 traffic_sched->set_alloc_id(1024);
3131 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
3132
3133 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3134 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3135 RemoveTrafficSchedulers_(traffic_scheds);
3136
3137 traffic_queues->set_uni_id(0);
3138 traffic_queues->set_port_no(16);
3139 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3140
3141 Status status = RemoveTrafficQueues_(traffic_queues);
3142 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3143}
3144
3145/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
3146as it is getting referred by some other queues case */
3147TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
3148 traffic_queues->set_uni_id(3);
3149 traffic_queues->set_port_no(16);
3150 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3151 traffic_queue_2 = traffic_queues->add_traffic_queues();
3152 traffic_queue_2->set_gemport_id(1025);
3153 traffic_queue_2->set_priority(1);
3154 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
3155
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303156 bcmolt_pon_interface_key pon_key;
3157 bcmolt_pon_interface_cfg pon_cfg;
3158 pon_key.pon_ni = pon_id;
3159 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3160 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3161 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3162 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3163 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3164
3165 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3166 future<int> push_gem_cfg_complt = \
3167 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3168 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3169 push_gem_cfg_complt = \
3170 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3171
3172 Status status = future_res.get();
3173 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003174 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3175}
3176
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303177/* Test 5 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, removing TM QMP as it
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003178is not getting referred by any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303179TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueRemovingTMQMP) {
3180 traffic_queues->set_uni_id(5);
3181 traffic_queues->set_port_no(80);
3182 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003183 traffic_queue_2 = traffic_queues->add_traffic_queues();
3184 traffic_queue_2->set_gemport_id(1025);
3185 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303186 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
3187
3188 bcmolt_pon_interface_key pon_key;
3189 bcmolt_pon_interface_cfg pon_cfg;
3190 pon_key.pon_ni = pon_id;
3191 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3192 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3193 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3194 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3195 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003196
3197 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3198 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3199
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303200 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3201 future<int> push_gem_cfg_complt = \
3202 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3203 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3204 push_gem_cfg_complt = \
3205 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3206
3207 Status status = future_res.get();
3208 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003209 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3210}
3211
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303212/* Test 6 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, error while removing TM QMP
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003213having no reference to any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303214TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueErrorRemovingTMQMP) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003215 traffic_queues->set_uni_id(4);
3216 traffic_queues->set_port_no(64);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303217 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003218 traffic_queue_2 = traffic_queues->add_traffic_queues();
3219 traffic_queue_2->set_gemport_id(1025);
3220 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303221 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003222
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303223 bcmolt_pon_interface_key pon_key;
3224 bcmolt_pon_interface_cfg pon_cfg;
3225 pon_key.pon_ni = pon_id;
3226 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3227 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3228 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3229 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3230 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003231
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303232 bcmos_errno olt_cfg_clear_res_success = BCM_ERR_OK;
3233 bcmos_errno olt_cfg_clear_res_failure = BCM_ERR_INTERNAL;
3234 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _))
3235 .WillOnce(Return(olt_cfg_clear_res_success))
3236 .WillOnce(Return(olt_cfg_clear_res_success))
3237 .WillOnce(Return(olt_cfg_clear_res_success))
3238 .WillOnce(Return(olt_cfg_clear_res_success))
3239 .WillRepeatedly(Return(olt_cfg_clear_res_failure));
3240
3241 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3242 future<int> push_gem_cfg_complt = \
3243 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3244 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3245 push_gem_cfg_complt = \
3246 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3247
3248 Status status = future_res.get();
3249 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003250 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3251}
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003252
3253////////////////////////////////////////////////////////////////////////////
3254// For testing OnuItuPonAlarmSet functionality
3255////////////////////////////////////////////////////////////////////////////
3256
3257class TestOnuItuPonAlarmSet : public Test {
3258 protected:
3259 bcmolt_pon_ni pon_ni = 0;
3260 bcmolt_onu_id onu_id = 1;
3261
kesavandc1f2db92020-08-31 15:32:06 +05303262 config::OnuItuPonAlarm *onu_itu_pon_alarm_rt;
3263 config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config;
3264 config::OnuItuPonAlarm::SoakTime *soak_time_rt;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003265
kesavandc1f2db92020-08-31 15:32:06 +05303266 config::OnuItuPonAlarm *onu_itu_pon_alarm_rr;
3267 config::OnuItuPonAlarm::RateRangeConfig *rate_range_config;
3268 config::OnuItuPonAlarm::SoakTime *soak_time_rr;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003269
kesavandc1f2db92020-08-31 15:32:06 +05303270 config::OnuItuPonAlarm *onu_itu_pon_alarm_tc;
3271 config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config;
3272 config::OnuItuPonAlarm::SoakTime *soak_time_tc;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003273
3274 NiceMock<BalMocker> balMock;
3275
3276 virtual void SetUp() {
kesavandc1f2db92020-08-31 15:32:06 +05303277 onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm;
3278 rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig;
3279 soak_time_rt = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003280 onu_itu_pon_alarm_rt->set_pon_ni(0);
3281 onu_itu_pon_alarm_rt->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303282 onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3283 onu_itu_pon_alarm_rt->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003284 rate_threshold_config->set_rate_threshold_rising(1);
3285 rate_threshold_config->set_rate_threshold_falling(4);
3286 soak_time_rt->set_active_soak_time(2);
3287 soak_time_rt->set_clear_soak_time(2);
3288 rate_threshold_config->set_allocated_soak_time(soak_time_rt);
3289 onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config);
3290
kesavandc1f2db92020-08-31 15:32:06 +05303291 onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm;
3292 rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig;
3293 soak_time_rr = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003294 onu_itu_pon_alarm_rr->set_pon_ni(0);
3295 onu_itu_pon_alarm_rr->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303296 onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3297 onu_itu_pon_alarm_rr->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003298 rate_range_config->set_rate_range_lower(1);
3299 rate_range_config->set_rate_range_upper(4);
3300 soak_time_rr->set_active_soak_time(2);
3301 soak_time_rr->set_clear_soak_time(2);
3302 rate_range_config->set_allocated_soak_time(soak_time_rr);
3303 onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config);
3304
kesavandc1f2db92020-08-31 15:32:06 +05303305 onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm;
3306 value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig;
3307 soak_time_tc = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003308 onu_itu_pon_alarm_tc->set_pon_ni(0);
3309 onu_itu_pon_alarm_tc->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303310 onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3311 onu_itu_pon_alarm_tc->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003312 value_threshold_config->set_threshold_limit(6);
3313 soak_time_tc->set_active_soak_time(2);
3314 soak_time_tc->set_clear_soak_time(2);
3315 value_threshold_config->set_allocated_soak_time(soak_time_tc);
3316 onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config);
3317 }
3318
3319 virtual void TearDown() {
3320 }
3321};
3322
3323// Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case
3324// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3325// the configured threshold boundary.
3326TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) {
3327 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3328 bcmolt_onu_key key = {};
3329 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3330 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3331 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3332 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3333 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3334
3335 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3336
3337 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3338 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3339}
3340
3341// Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case
3342// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3343// the configured threshold boundary.
3344TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) {
3345 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3346 bcmolt_onu_key key = {};
3347 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3348 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3349 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3350 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3351 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3352
3353 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3354
3355 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3356 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3357}
3358
3359// Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case
3360// rate_range: The alarm is triggered if the stats delta value between samples deviates
3361// from the configured range.
3362TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) {
3363 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3364 bcmolt_onu_key key = {};
3365 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3366 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3367 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100;
3368 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50;
3369 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3370
3371 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3372
3373 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3374 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3375}
3376
3377// Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case
3378// rate_range: The alarm is triggered if the stats delta value between samples deviates
3379// from the configured range.
3380TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) {
3381 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3382 bcmolt_onu_key key = {};
3383 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3384 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3385 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50;
3386 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100;
3387 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3388
3389 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3390
3391 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3392 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3393}
3394
3395// Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case
3396// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3397// level. The alarm is cleared when the host read the stats.
3398TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) {
3399 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3400 bcmolt_onu_key key = {};
3401 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3402 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3403 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100;
3404 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3405
3406 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3407
3408 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3409 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3410}
3411
3412// Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case
3413// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3414// level. The alarm is cleared when the host read the stats.
3415TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) {
3416 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3417 bcmolt_onu_key key = {};
3418 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3419 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3420 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1;
3421 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3422
3423 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3424
3425 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3426 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3427}
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003428
3429////////////////////////////////////////////////////////////////////////////
3430// For testing DeleteGroup functionality
3431////////////////////////////////////////////////////////////////////////////
3432
3433class TestDeleteGroup : public Test {
3434 protected:
3435 uint32_t group_id = 1;
3436 NiceMock<BalMocker> balMock;
3437
3438 virtual void SetUp() {
3439 }
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003440};
3441
3442// Test 1 - DeleteGroup success case
3443TEST_F(TestDeleteGroup, DeleteGroupSuccess) {
3444 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3445 bcmos_errno group_cfg_clear_res = BCM_ERR_OK;
3446 bcmolt_group_cfg grp_cfg_out;
3447 bcmolt_group_key grp_key = {};
3448
3449 grp_key.id = group_id;
3450 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3451
3452 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3453 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3454 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3455 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3456 return group_cfg_get_res;
3457 }
3458 ));
3459
3460 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3461
3462 Status status = DeleteGroup_(group_id);
3463 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3464}
3465
3466// Test 2 - DeleteGroup failure case: Group does not exist
3467TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) {
3468 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3469 bcmolt_group_cfg grp_cfg_out;
3470 bcmolt_group_key grp_key = {};
3471
3472 grp_key.id = group_id;
3473 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3474
3475 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3476 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3477 grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED;
3478 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3479 return group_cfg_get_res;
3480 }
3481 ));
3482
3483 Status status = DeleteGroup_(group_id);
3484 ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND );
3485}
3486
3487// Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.)
3488TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) {
3489 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3490 bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL;
3491 bcmolt_group_cfg grp_cfg_out;
3492 bcmolt_group_key grp_key = {};
3493
3494 grp_key.id = group_id;
3495 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3496
3497 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3498 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3499 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3500 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3501 return group_cfg_get_res;
3502 }
3503 ));
3504
3505 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3506
3507 Status status = DeleteGroup_(group_id);
3508 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3509}
Jason Huang1d9cfce2020-05-20 22:58:47 +08003510
3511////////////////////////////////////////////////////////////////////////////
3512// For testing OnuLogicalDistanceZero functionality
3513////////////////////////////////////////////////////////////////////////////
3514class TestOnuLogicalDistanceZero : public Test {
3515 protected:
3516 NiceMock<BalMocker> balMock;
3517 bcmolt_pon_ni pon_ni = 0;
3518 openolt::OnuLogicalDistance *onu_logical_distance_zero;
3519
3520 virtual void SetUp() {
3521 onu_logical_distance_zero = new openolt::OnuLogicalDistance;
3522 onu_logical_distance_zero->set_intf_id(pon_ni);
3523 }
3524 virtual void TearDown() {
3525 }
3526};
3527
3528//
3529// Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case
3530//
3531TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) {
3532 bcmolt_pon_distance pon_distance = {};
3533 bcmolt_pon_interface_cfg pon_cfg;
3534 bcmolt_pon_interface_key key = {};
3535
3536 key.pon_ni = pon_ni;
3537 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3538 state.activate();
3539 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3540
3541 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3542 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3543
3544 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3545 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3546}
3547
3548// Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case
3549// The PON state is not ready for failure case
3550//
3551TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) {
3552 bcmolt_pon_distance pon_distance = {};
3553 bcmolt_pon_interface_cfg pon_cfg;
3554 bcmolt_pon_interface_key key = {};
3555
3556 key.pon_ni = pon_ni;
3557 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3558 state.deactivate();
3559 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
3560
3561 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3562 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3563}
3564
3565class TestOnuLogicalDistance : public Test {
3566 protected:
3567 NiceMock<BalMocker> balMock;
3568 bcmolt_pon_ni pon_ni = 0;
3569 bcmolt_onu_id onu_id = 1;
3570 openolt::OnuLogicalDistance *onu_logical_distance;
3571
3572 virtual void SetUp() {
3573 onu_logical_distance = new openolt::OnuLogicalDistance;
3574 onu_logical_distance->set_intf_id(pon_ni);
3575 onu_logical_distance->set_onu_id(onu_id);
3576 }
3577 virtual void TearDown() {
3578 }
3579};
3580
3581//
3582// Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case
3583//
3584TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) {
3585 bcmolt_pon_distance pon_distance = {};
3586 bcmolt_pon_interface_cfg pon_cfg;
3587 bcmolt_pon_interface_key key = {};
3588 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3589
3590 key.pon_ni = pon_ni;
3591 state.activate();
3592 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3593
3594 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3595 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3596
3597 bcmolt_onu_cfg onu_cfg;
3598 bcmolt_onu_key onu_key = {};
3599 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3600
3601 onu_key.pon_ni = pon_ni;
3602 onu_key.onu_id = onu_id;
3603 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3604 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
3605
3606 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3607 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3608
3609 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3610 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3611}
3612
3613// Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case
3614// The failure case is for retrieving ONU ranging time
3615//
3616TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) {
3617 bcmolt_pon_distance pon_distance = {};
3618 bcmolt_pon_interface_cfg pon_cfg;
3619 bcmolt_pon_interface_key key = {};
3620 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3621
3622 key.pon_ni = pon_ni;
3623 state.activate();
3624 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3625
3626 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3627 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3628
3629 bcmolt_onu_cfg onu_cfg;
3630 bcmolt_onu_key onu_key = {};
3631 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
3632
3633 onu_key.pon_ni = pon_ni;
3634 onu_key.onu_id = onu_id;
3635 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3636
3637 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3638 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3639
3640 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3641 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3642}
3643
3644// Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case
3645// The failure case is for ONU is not yet activated
3646//
3647TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) {
3648 bcmolt_pon_distance pon_distance = {};
3649 bcmolt_pon_interface_cfg pon_cfg;
3650 bcmolt_pon_interface_key key = {};
3651 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3652
3653 key.pon_ni = pon_ni;
3654 state.activate();
3655 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3656
3657 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3658 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3659
3660 bcmolt_onu_cfg onu_cfg;
3661 bcmolt_onu_key onu_key = {};
3662 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3663
3664 onu_key.pon_ni = pon_ni;
3665 onu_key.onu_id = onu_id;
3666 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3667
3668 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3669 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3670
3671 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
3672 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3673 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3674}
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -07003675
3676////////////////////////////////////////////////////////////////////////////
3677// For testing Secure Server functionality
3678////////////////////////////////////////////////////////////////////////////
3679
3680class TestSecureServer : public Test {
3681 protected:
3682 virtual void SetUp() {}
3683 virtual void TearDown() {}
3684};
3685
3686TEST_F(TestSecureServer, StartInsecureServer) {
3687 // const to prevent the following warning:
3688 // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
3689 const char *args[] = {"./openolt"};
3690 int argc = sizeof(args) / sizeof(args[0]);
3691 char **argv = const_cast<char**>(args);
3692
3693 bool ok = RunServer(argc, argv);
3694
3695 ASSERT_TRUE(ok);
3696
3697 OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n");
3698}
3699
3700TEST_F(TestSecureServer, StartWithInvalidTLSOption) {
3701 const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3702 int argc = sizeof(args) / sizeof(args[0]);
3703 char **argv = const_cast<char**>(args);
3704
3705 bool ok = RunServer(argc, argv);
3706
3707 ASSERT_FALSE(ok);
3708
3709 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n");
3710}
3711
3712TEST_F(TestSecureServer, CertificatesAreMissing) {
3713 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3714 int argc = sizeof(args) / sizeof(args[0]);
3715 char **argv = const_cast<char**>(args);
3716 const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'";
3717
3718 int res = std::system(cmd.c_str());
3719 if (res == 0) {
3720 std::cout << "directory ./keystore is deleted\n";
3721 } else {
3722 std::cout << "directory ./keystore is not existing\n";
3723 }
3724
3725 bool ok = RunServer(argc, argv);
3726
3727 ASSERT_FALSE(ok);
3728
3729 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n");
3730}
3731
3732TEST_F(TestSecureServer, StartWithValidTLSOption) {
3733 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3734 int argc = sizeof(args) / sizeof(args[0]);
3735 char **argv = const_cast<char**>(args);
3736 const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore";
3737 const std::string cmd_2 = "exec rm -rf './keystore'";
3738
3739 int res = std::system(cmd_1.c_str());
3740 if (res == 0) {
3741 std::cout << "directory ./keystore is copied from ./keystore-test\n";
3742
3743 bool ok = RunServer(argc, argv);
3744 ASSERT_TRUE(ok);
3745
3746 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n");
3747
3748 res = std::system(cmd_2.c_str());
3749 if (res == 0) {
3750 std::cout << "directory ./keystore is deleted\n";
3751 } else {
3752 std::cerr << "directory ./keystore could not be deleted\n";
3753 }
3754 } else {
3755 std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n';
3756 FAIL();
3757 }
3758}
Orhan Kupusogluec57af02021-05-12 12:38:17 +00003759
3760////////////////////////////////////////////////////////////////////////////
3761// For testing RxTx Power Read functionality
3762////////////////////////////////////////////////////////////////////////////
3763
3764class TestPowerRead : public Test {
3765 protected:
3766 virtual void SetUp() {
3767 std::array<char, 600> content = {};
3768 content.fill(0x00); // not required for 0x00
3769
3770 // for asfvolt16
3771 content[102] = 0x5D;
3772 content[103] = 0x38;
3773 content[104] = 0x1A;
3774 content[105] = 0xB5;
3775
3776 // for asgvolt64
3777 content[358] = 0x5C;
3778 content[359] = 0x82;
3779 content[360] = 0x04;
3780 content[361] = 0xBE;
3781
3782 std::ofstream test_file;
3783 test_file.open(file_name, std::ios::binary | std::ios::out);
3784 test_file.write(content.data(), content.size());
3785 test_file.close();
3786
3787 const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump;
3788
3789 int res = std::system(cmd.c_str());
3790 if (res == 0) {
3791 std::ifstream dump_file(hex_dump) ;
3792 std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() };
3793 std::cout << cmd << '\n';
3794 std::cout << hexdump << '\n';
3795 } else {
3796 std::cerr << "hexdump capture failed\n";
3797 }
3798 }
3799 virtual void TearDown() {
3800 std::remove(file_name.c_str());
3801 std::remove(hex_dump.c_str());
3802 }
3803
3804 const std::string file_name = "eeprom.bin";
3805 const std::string hex_dump = file_name + ".hexdump";
3806};
3807
3808TEST_F(TestPowerRead, TestAsfvolt16) {
3809 std::cout << "Test Power Reads on XGS-PON OLT:\n";
3810
3811 int port = 20;
3812 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3813
3814 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3815
3816 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3817
3818 port = 0;
3819 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3820
3821 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3822 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3823 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3824 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3825 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3826
3827 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3828
3829 ASSERT_TRUE(rxtx_power_raw.second);
3830
3831 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3832 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3833 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3834 << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first)) << " dBm\n";
3835 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3836 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3837 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3838 << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second)) << " dBm\n";
3839 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3840
3841 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3842 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256);
3843 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104);
3844 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3845 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20);
3846 ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837
3847 ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864
3848 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom");
3849}
3850
3851TEST_F(TestPowerRead, TestAsgvolt64) {
3852 std::cout << "Test Power Reads on GPON OLT:\n";
3853
3854 int port = 80;
3855 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3856
3857 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3858
3859 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3860
3861 port = 0;
3862 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3863
3864 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3865 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3866 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3867 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3868 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3869
3870 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3871
3872 ASSERT_TRUE(rxtx_power_raw.second);
3873
3874 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3875 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3876 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3877 << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first)) << " dBm\n";
3878 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3879 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3880 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3881 << std::dec << std::setw(9) << trx_eeprom_reader2.mw_to_dbm(trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second)) << " dBm\n";
3882 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3883
3884 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3885 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600);
3886 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360);
3887 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3888 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74);
3889 ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214
3890 ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682
3891 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom");
3892}