blob: dd8265ed501ba9902b232982b2453a0d2907d66a [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"
Girish Gowdrab0337eb2022-03-25 16:44:21 -070021#include "core_utils.h"
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070022#include "server.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050023#include <future>
Orhan Kupusogluec57af02021-05-12 12:38:17 +000024#include <fstream>
25#include "trx_eeprom_reader.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000026using namespace testing;
27using namespace std;
28
29class TestOltEnable : public Test {
30 protected:
31 virtual void SetUp() {
32 }
33
34 virtual void TearDown() {
35 // Code here will be called immediately after each test
36 // (right before the destructor).
37 }
38};
39
40// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
41// bcmolt_cfg_get__bal_state_stub.
42ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
43
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050044// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
45// bcmolt_cfg_get__onu_state_stub.
46ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
47
48// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
49// bcmolt_cfg_get__tm_sched_stub.
50ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
51
52// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
53// bcmolt_cfg_get__pon_intf_stub.
54ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
55
56// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
57// bcmolt_cfg_get__nni_intf_stub.
58ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000059
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050060// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
61// bcmolt_cfg_get__flow_stub.
62ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
63
Amit Ghoshfcad4d32019-11-13 10:24:55 +000064// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
65MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050066MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
67MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
69MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050070MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000071
Amit Ghoshfcad4d32019-11-13 10:24:55 +000072// Test Fixture for OltEnable
73
74// Test 1: OltEnableSuccess case
75TEST_F(TestOltEnable, OltEnableSuccess){
76 // NiceMock is used to suppress 'WillByDefault' return errors.
77 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
78 NiceMock<BalMocker> balMock;
79 bcmos_errno host_init_res = BCM_ERR_OK;
80 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
81 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
82 bcmos_errno olt_oper_res = BCM_ERR_OK;
83
84 bcmolt_olt_cfg olt_cfg = { };
85 bcmolt_olt_key olt_key = { };
86 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
87 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
88
89 Status olt_enable_res;
90
91 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
92 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
93 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
94 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
95 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
96 .WillRepeatedly(Return(bal_cfg_get_res));
97 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
98
99 olt_enable_res = Enable_(1, NULL);
100 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
101}
102
103// Test 2: OltEnableFail_host_init_fail
104TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
105 // NiceMock is used to suppress 'WillByDefault' return errors.
106 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
107 NiceMock<BalMocker> balMock;
108 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
109
110 Status olt_enable_res;
111
112 // Ensure that the state of the OLT is in deactivated to start with..
113 state.deactivate();
114
115 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
116
117 olt_enable_res = Enable_(1, NULL);
118 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
119}
120
121// Test 3: OltEnableSuccess_PON_Device_Connected
122TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
123
124 // NiceMock is used to suppress 'WillByDefault' return errors.
125 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
126 NiceMock<BalMocker> balMock;
127 bcmos_errno host_init_res = BCM_ERR_OK;
128 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
129 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
130 bcmos_errno olt_oper_res = BCM_ERR_OK;
131
132 bcmolt_olt_cfg olt_cfg = { };
133 bcmolt_olt_key olt_key = { };
134 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
135 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
136
137 Status olt_enable_res;
138
139 // Ensure that the state of the OLT is in deactivated to start with..
140 state.deactivate();
141
142 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
143 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
144 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
145 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
146 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
147 .WillRepeatedly(Return(bal_cfg_get_res));
148
149 olt_enable_res = Enable_(1, NULL);
150 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
151
152}
153
154// Test 4: OltEnableFail_All_PON_Enable_Fail
155TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
156
157 // NiceMock is used to suppress 'WillByDefault' return errors.
158 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
159 NiceMock<BalMocker> balMock;
160 bcmos_errno host_init_res = BCM_ERR_OK;
161 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
162 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
163 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
164
165 bcmolt_olt_cfg olt_cfg = { };
166 bcmolt_olt_key olt_key = { };
167 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
168 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
169
170 Status olt_enable_res;
171
172 // Ensure that the state of the OLT is in deactivated to start with..
173 state.deactivate();
174
175 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
176 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
177 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
178 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
179 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
180 .WillRepeatedly(Return(bal_cfg_get_res));
181 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
182
183 olt_enable_res = Enable_(1, NULL);
184
185 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
186}
187
188// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
189TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
190
191 // NiceMock is used to suppress 'WillByDefault' return errors.
192 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
193 NiceMock<BalMocker> balMock;
194 bcmos_errno host_init_res = BCM_ERR_OK;
195 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
196 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
197 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
198 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
199
200 bcmolt_olt_cfg olt_cfg = { };
201 bcmolt_olt_key olt_key = { };
202 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
203 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
204
205 Status olt_enable_res;
206
207 // Ensure that the state of the OLT is in deactivated to start with..
208 state.deactivate();
209
210 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
211 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
212 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
213 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
214 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
215 .WillRepeatedly(Return(bal_cfg_get_res));
216 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
217 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
218 .WillOnce(Return(olt_oper_res_fail))
219 .WillRepeatedly(Return(olt_oper_res_success));
220 olt_enable_res = Enable_(1, NULL);
221
222 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
223}
224
225////////////////////////////////////////////////////////////////////////
226// For testing Enable/Disable functionality
227////////////////////////////////////////////////////////////////////////
228
Girish Gowdraddf9a162020-01-27 12:56:27 +0530229int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000230
231// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
232MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
233
234class TestOltDisableReenable : public Test {
235 protected:
236 virtual void SetUp() {
237 NiceMock<BalMocker> balMock;
238 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
239
240 bcmolt_olt_cfg olt_cfg = { };
241 bcmolt_olt_key olt_key = { };
242
243 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
244
Girish Gowdraddf9a162020-01-27 12:56:27 +0530245 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000246 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
247 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
248
249 ProbeDeviceCapabilities_();
250
251 }
252
253 virtual void TearDown() {
254 // Code here will be called immediately after each test
255 // (right before the destructor).
256 }
257};
258
259
260// Test Fixture for OltDisable
261
262// Test 1: OltDisableSuccess case
263TEST_F(TestOltDisableReenable, OltDisableSuccess){
264 // NiceMock is used to suppress 'WillByDefault' return errors.
265 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
266 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500267 bcmos_errno olt_oper_res = BCM_ERR_OK;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700268 bcmos_errno olt_get_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000269
270 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500271 state.deactivate();
272 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Girish Gowdrae1db2952021-05-04 00:16:54 -0700273 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_get_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000274 olt_disable_res = Disable_();
275 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
276
277}
278
279// Test 2: OltDisableAllPonFailed case
280TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
281 // NiceMock is used to suppress 'WillByDefault' return errors.
282 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
283 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500284 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700285 bcmos_errno pon_cfg_get_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000286
287 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500288 state.deactivate();
Girish Gowdrae1db2952021-05-04 00:16:54 -0700289 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(pon_cfg_get_res));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500290 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000291 olt_disable_res = Disable_();
292 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
293}
294
295
296// Test Fixture for OltReenable
297
298// Test 1: OltReenableSuccess case
299TEST_F(TestOltDisableReenable, OltReenableSuccess){
300 // NiceMock is used to suppress 'WillByDefault' return errors.
301 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
302 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500303 uint32_t pon_id = 0;
304 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
305 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000306 Status olt_reenable_res;
307
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500308 bcmolt_pon_interface_key pon_key;
309 bcmolt_pon_interface_cfg pon_cfg;
310 pon_key.pon_ni = pon_id;
311 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
312 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
313
314 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530315 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500316 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
317
318 bcmolt_tm_sched_cfg tm_sched_cfg;
319 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
320 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
321 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
322
323 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530324 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500325 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000326
327 olt_reenable_res = Reenable_();
328 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
329
330}
331
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500332// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000333TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
334 // NiceMock is used to suppress 'WillByDefault' return errors.
335 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
336 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500337 uint32_t pon_id = 0;
338 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000339 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000340 Status olt_reenable_res;
341
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500342 bcmolt_pon_interface_key pon_key;
343 bcmolt_pon_interface_cfg pon_cfg;
344 pon_key.pon_ni = pon_id;
345 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
346 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
347
348 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530349 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500350 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000351 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530352 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000353 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500354
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000355 olt_reenable_res = Reenable_();
356 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
357}
358
359////////////////////////////////////////////////////////////////////////////
360// For testing ProbeDeviceCapabilities functionality
361////////////////////////////////////////////////////////////////////////////
362class TestProbeDevCapabilities : public Test {
363 protected:
364 NiceMock<BalMocker> balMock;
365 bcmos_errno olt_res_success = BCM_ERR_OK;
366 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
367 bcmos_errno dev_res_success = BCM_ERR_OK;
368 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
369
370 virtual void SetUp() {
371 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
372
373 bcmolt_olt_cfg olt_cfg = { };
374 bcmolt_olt_key olt_key = { };
375
376 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
377
Girish Gowdraddf9a162020-01-27 12:56:27 +0530378 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000379 }
380
381 virtual void TearDown() {
382 }
383};
384
385// Test 1 - If querying the OLT fails, the method must return error
386TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
387
388 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
389 .WillOnce(Return(olt_res_fail));
390
391 Status query_status = ProbeDeviceCapabilities_();
392 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
393}
394
395// Test 2 - If all devices are queried successfully, the method must return Status::OK
396TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
397
398 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
399 .WillOnce(Return(olt_res_success));
400
401 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
402 .WillRepeatedly(Return(dev_res_success));
403
404 Status query_status = ProbeDeviceCapabilities_();
405
406 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
407}
408
409// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
410TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
411
412 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
413 .WillOnce(Return(olt_res_success));
414
415 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
416 .WillRepeatedly(Return(dev_res_fail));
417
418 Status query_status = ProbeDeviceCapabilities_();
419
420 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
421}
422
423// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
424TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
425
426 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
427 .WillOnce(Return(olt_res_success));
428
429 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
430 .WillOnce(Return(olt_res_success))
431 .WillRepeatedly(Return(dev_res_fail));
432
433 Status query_status = ProbeDeviceCapabilities_();
434
435 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
436}
437
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500438////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500439// For testing EnablePonIf functionality
440////////////////////////////////////////////////////////////////////////////
441
442class TestEnablePonIf : public Test {
443 protected:
444 uint32_t pon_id = 0;
445 NiceMock<BalMocker> balMock;
446
447 virtual void SetUp() {
448 }
449
450 virtual void TearDown() {
451 }
452};
453
454// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
455TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
456 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
457 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
458 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
459 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
460
461 bcmolt_pon_interface_key pon_key;
462 bcmolt_pon_interface_cfg pon_cfg;
463 pon_key.pon_ni = pon_id;
464 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
465 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
466 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
467 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
468
469 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
470 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
471
472 bcmolt_tm_sched_cfg tm_sched_cfg;
473 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
474 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
475 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
476 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
477 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
478
479 Status status = EnablePonIf_(pon_id);
480 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
481}
482
483// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
484TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
485 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
486 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
487 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
488 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
489
490 bcmolt_pon_interface_key pon_key;
491 bcmolt_pon_interface_cfg pon_cfg;
492 pon_key.pon_ni = pon_id;
493 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
494 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
495 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
496 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
497
498 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
499 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
500
501 bcmolt_tm_sched_cfg tm_sched_cfg;
502 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
503 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
504 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
505 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
506 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
507
508 Status status = EnablePonIf_(pon_id);
509 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
510}
511
512// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
513TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
514 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
515 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
516 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
517 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
518 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
519
520 bcmolt_pon_interface_key pon_key;
521 bcmolt_pon_interface_cfg pon_cfg;
522 pon_key.pon_ni = pon_id;
523 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
524 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
525 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
526 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
527
528 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
529 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
530 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
531
532 bcmolt_tm_sched_cfg tm_sched_cfg;
533 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
534 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
535 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
536 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
537 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
538
539 Status status = EnablePonIf_(pon_id);
540 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
541}
542
543// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
544TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
545 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
546 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
547 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
548 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
549 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
550 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
551
552 bcmolt_pon_interface_key pon_key;
553 bcmolt_pon_interface_cfg pon_cfg;
554 pon_key.pon_ni = pon_id;
555 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
556 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
557 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
558 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
559
560 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
561 .WillOnce(Return(olt_cfg_set_res))
562 .WillRepeatedly(Return(olt_cfg_set_err));
563 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
564 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
565
566 bcmolt_tm_sched_cfg tm_sched_cfg;
567 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
568 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
569 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
570 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
571 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
572
573 Status status = EnablePonIf_(pon_id);
574 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
575}
576
577// Test 5 - EnablePonIf already enabled success
578TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
579 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
580
581 bcmolt_pon_interface_key pon_key;
582 bcmolt_pon_interface_cfg pon_cfg;
583 pon_key.pon_ni = pon_id;
584 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
585 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
586 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
587 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
588
589 Status status = EnablePonIf_(pon_id);
590 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
591}
592
593// Test 6 - EnablePonIf - enable onu discovery failure case
594TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
595 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
596 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
597
598 bcmolt_pon_interface_key pon_key;
599 bcmolt_pon_interface_cfg pon_cfg;
600 pon_key.pon_ni = pon_id;
601 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
602 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
603 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
604 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
605 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
606
607 Status status = EnablePonIf_(pon_id);
608 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
609}
610
611// Test 7 - EnablePonIf failure case
612TEST_F(TestEnablePonIf, EnablePonIfFailed) {
613 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
614 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
615 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
616
617 bcmolt_pon_interface_key pon_key;
618 bcmolt_pon_interface_cfg pon_cfg;
619 pon_key.pon_ni = pon_id;
620 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
621 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
622 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
623 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
624 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
625 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
626
627 Status status = EnablePonIf_(pon_id);
628 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
629}
630
631////////////////////////////////////////////////////////////////////////////
632// For testing SetStateUplinkIf functionality
633////////////////////////////////////////////////////////////////////////////
634
635class TestSetStateUplinkIf : public Test {
636 protected:
637 uint32_t intf_id = 0;
638 NiceMock<BalMocker> balMock;
639
640 virtual void SetUp() {
641 }
642
643 virtual void TearDown() {
644 }
645};
646
647// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
648TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
649 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
650 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
651 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
652
653 bcmolt_nni_interface_key nni_key;
654 bcmolt_nni_interface_cfg nni_cfg;
655 nni_key.id = intf_id;
656 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
657 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
658 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
659 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
660
661 bcmolt_tm_sched_cfg tm_sched_cfg;
662 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
663 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
664 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
665 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
666 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
667 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
668
669 Status status = SetStateUplinkIf_(intf_id, true);
670 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
671}
672
673// Test 2 - SetStateUplinkIf, NNI interface already disabled case
674TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
675 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
676
677 bcmolt_nni_interface_key nni_key;
678 bcmolt_nni_interface_cfg nni_cfg;
679 nni_key.id = intf_id;
680 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
681 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
682 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
683 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
684
685 Status status = SetStateUplinkIf_(intf_id, false);
686 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
687}
688
689// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
690TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
691 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
692 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
693 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
694 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
695
696 bcmolt_nni_interface_key nni_key;
697 bcmolt_nni_interface_cfg nni_cfg;
698 nni_key.id = intf_id;
699 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
700 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
701 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
702 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
703
704 bcmolt_tm_sched_cfg tm_sched_cfg;
705 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
706 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
707 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
708 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
709 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
710 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
711 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
712
713 Status status = SetStateUplinkIf_(intf_id, true);
714 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
715}
716
717// Test 4 - SetStateUplinkIf Enable failure case
718TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
719 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
720 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
721
722 bcmolt_nni_interface_key nni_key;
723 bcmolt_nni_interface_cfg nni_cfg;
724 nni_key.id = intf_id;
725 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
726 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
727 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
728 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
729 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
730
731 Status status = SetStateUplinkIf_(intf_id, true);
732 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
733}
734
735// Test 5 - SetStateUplinkIf Disable success case
736TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
737 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
738 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
739
740 bcmolt_nni_interface_key nni_key;
741 bcmolt_nni_interface_cfg nni_cfg;
742 nni_key.id = intf_id;
743 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
744 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
745 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
746 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
747 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
748
749 Status status = SetStateUplinkIf_(intf_id, false);
750 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
751}
752
753// Test 6 - SetStateUplinkIf Disable failure case
754TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
755 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
756 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
757
758 bcmolt_nni_interface_key nni_key;
759 bcmolt_nni_interface_cfg nni_cfg;
760 nni_key.id = intf_id;
761 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
762 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
763 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
764 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
765 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
766
767 Status status = SetStateUplinkIf_(intf_id, false);
768 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
769}
770
771////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500772// For testing DisablePonIf functionality
773////////////////////////////////////////////////////////////////////////////
774
775class TestDisablePonIf : public Test {
776 protected:
777 virtual void SetUp() {
778 }
779
780 virtual void TearDown() {
781 }
782};
783
Girish Gowdrae1db2952021-05-04 00:16:54 -0700784// Test 1 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_ACTIVE_WORKING state
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500785TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
786 bcmos_errno olt_oper_res = BCM_ERR_OK;
787 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
788 NiceMock<BalMocker> balMock;
789 uint32_t pon_id=1;
790
Girish Gowdrae1db2952021-05-04 00:16:54 -0700791 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
792 bcmolt_pon_interface_cfg interface_obj;
793
794 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
795 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
796
797 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
798 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
799 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
800 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
801 return pon_intf_get_res;
802 }
803 ));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500804 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
805 state.deactivate();
806 Status status = DisablePonIf_(pon_id);
807
808 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
809}
810
Girish Gowdrae1db2952021-05-04 00:16:54 -0700811// Test 2 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
812TEST_F(TestDisablePonIf, DisablePonIf_OperSubmitErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500813 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
814 NiceMock<BalMocker> balMock;
815 uint32_t pon_id=1;
816
Girish Gowdrae1db2952021-05-04 00:16:54 -0700817 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
818 bcmolt_pon_interface_cfg interface_obj;
819
820 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
821 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
822
823 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
824 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
825 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
826 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
827 return pon_intf_get_res;
828 }
829 ));
830
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500831 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
832 state.deactivate();
833 Status status = DisablePonIf_(pon_id);
834
835 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
836}
837
Girish Gowdrae1db2952021-05-04 00:16:54 -0700838// Test 3 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
839TEST_F(TestDisablePonIf, DisablePonIf_CfgSetErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500840 NiceMock<BalMocker> balMock;
841 uint32_t pon_id=1;
842 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700843
844 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
845 bcmolt_pon_interface_cfg interface_obj;
846
847 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
848 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
849
850 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
851 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
852 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
853 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
854 return pon_intf_get_res;
855 }
856 ));
857
858
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500859 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
860 state.deactivate();
861 Status status = DisablePonIf_(pon_id);
862
863 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
864}
865
Girish Gowdrae1db2952021-05-04 00:16:54 -0700866// Test 4 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_INACTIVE state
867TEST_F(TestDisablePonIf, DisablePonIfSuccess_PonIntfInactive) {
868 bcmos_errno olt_oper_res = BCM_ERR_OK;
869 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
870 NiceMock<BalMocker> balMock;
871 uint32_t pon_id=1;
872
873 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
874 bcmolt_pon_interface_cfg interface_obj;
875
876 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
877 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
878
879 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
880 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
881 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
882 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
883 return pon_intf_get_res;
884 }
885 ));
886 state.deactivate();
887 Status status = DisablePonIf_(pon_id);
888
889 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
890}
891
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500892////////////////////////////////////////////////////////////////////////////
893// For testing ActivateOnu functionality
894////////////////////////////////////////////////////////////////////////////
895
896class TestActivateOnu : public Test {
897 protected:
898 uint32_t pon_id = 0;
899 uint32_t onu_id = 1;
900 std::string vendor_id = "TWSH";
901 std::string vendor_specific = "80808080";
902 uint32_t pir = 1000000;
903 NiceMock<BalMocker> balMock;
904
905 virtual void SetUp() {
906 }
907
908 virtual void TearDown() {
909 }
910};
911
Girish Gowdra24297032020-03-23 12:32:37 -0700912// Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state
913TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) {
914 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
915 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500916 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
Girish Gowdra24297032020-03-23 12:32:37 -0700917 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500918
919 bcmolt_onu_cfg onu_cfg;
920 bcmolt_onu_key onu_key;
921 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
Girish Gowdra24297032020-03-23 12:32:37 -0700922 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500923 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
924 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
925
926 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
927 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
Girish Gowdra24297032020-03-23 12:32:37 -0700928 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500929
kesavandc1f2db92020-08-31 15:32:06 +0530930 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500931 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
932}
933
Girish Gowdra24297032020-03-23 12:32:37 -0700934// Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state
935TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500936 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
937 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
938
939 bcmolt_onu_cfg onu_cfg;
940 bcmolt_onu_key onu_key;
941 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
942 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
943 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
944 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra24297032020-03-23 12:32:37 -0700945
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500946 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
947
kesavandc1f2db92020-08-31 15:32:06 +0530948 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500949 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
950}
951
Girish Gowdra24297032020-03-23 12:32:37 -0700952// Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state
953TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) {
954 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
955 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
956 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
957
958 bcmolt_onu_cfg onu_cfg;
959 bcmolt_onu_key onu_key;
960 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
961 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
962 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
963 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
964
965 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
966 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
967
968
kesavandc1f2db92020-08-31 15:32:06 +0530969 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700970 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
971}
972
973// Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE)
974TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) {
975 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
976 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
977
978 bcmolt_onu_cfg onu_cfg;
979 bcmolt_onu_key onu_key;
980 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
981 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process
982 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
983 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
984
985 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
986
kesavandc1f2db92020-08-31 15:32:06 +0530987 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700988 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
989}
990
991// Test 5 - ActivateOnu failure case - cfg_get failure
992TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) {
993 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure
994
995 bcmolt_onu_cfg onu_cfg;
996 bcmolt_onu_key onu_key;
997 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
998 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
999 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1000 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1001
kesavandc1f2db92020-08-31 15:32:06 +05301002 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001003 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1004}
1005
1006// Test 6 - ActivateOnu failure case - oper_submit failure
1007TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) {
1008 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1009 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1010 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
1011 bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure
1012
1013 bcmolt_onu_cfg onu_cfg;
1014 bcmolt_onu_key onu_key;
1015 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1016 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
1017 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1018 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1019
1020 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
1021 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
1022 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
1023
kesavandc1f2db92020-08-31 15:32:06 +05301024 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001025 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1026}
1027
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001028////////////////////////////////////////////////////////////////////////////
1029// For testing DeactivateOnu functionality
1030////////////////////////////////////////////////////////////////////////////
1031
1032class TestDeactivateOnu : public Test {
1033 protected:
1034 uint32_t pon_id = 0;
1035 uint32_t onu_id = 1;
1036 std::string vendor_id = "TWSH";
1037 std::string vendor_specific = "80808080";
1038 NiceMock<BalMocker> balMock;
1039
1040 virtual void SetUp() {
1041 }
1042
1043 virtual void TearDown() {
1044 }
1045};
1046
1047// Test 1 - DeactivateOnu success case
1048TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001049 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1050
Girish Gowdra72cbee92021-11-05 15:16:18 -07001051 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1052 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001053 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001054 onu_key.pon_ni = 0;
1055 onu_key.onu_id = 1;
1056
1057 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1058
1059 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1060 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1061 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1062 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1063 return onu_cfg_get_res;
1064 }
1065 ));
1066
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001067
1068 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1069
1070 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1071 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1072}
1073
1074// Test 2 - DeactivateOnu failure case
1075TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001076 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1077
Girish Gowdra72cbee92021-11-05 15:16:18 -07001078 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1079 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001080 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001081 onu_key.pon_ni = 0;
1082 onu_key.onu_id = 1;
1083
1084 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1085
1086 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1087 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1088 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1089 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1090 return onu_cfg_get_res;
1091 }
1092 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001093
1094 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1095
1096 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1097 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1098}
1099
1100////////////////////////////////////////////////////////////////////////////
1101// For testing DeleteOnu functionality
1102////////////////////////////////////////////////////////////////////////////
1103
1104class TestDeleteOnu : public Test {
1105 protected:
1106 uint32_t pon_id = 0;
1107 uint32_t onu_id = 1;
1108 std::string vendor_id = "TWSH";
1109 std::string vendor_specific = "80808080";
1110 NiceMock<BalMocker> balMock;
1111
1112 virtual void SetUp() {
1113 }
1114
1115 virtual void TearDown() {
1116 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301117 public:
1118 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
1119 onu_deactivate_complete_result res;
1120 res.pon_intf_id = 0;
1121 res.onu_id = 1;
1122 res.result = result;
1123 res.reason = reason;
1124 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
1125 // before we push the result.
1126 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1127 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
1128 onu_deact_compltd_key k(0, 1);
1129 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
1130 if (it == onu_deact_compltd_map.end()) {
1131 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
1132 } else {
1133 it->second->push(res);
1134 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
1135 }
1136 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
1137 return 0;
1138 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001139};
1140
1141// Test 1 - DeleteOnu success case
1142TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001143 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1144 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1145
Girish Gowdra72cbee92021-11-05 15:16:18 -07001146 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1147 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001148 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001149 onu_key.pon_ni = 0;
1150 onu_key.onu_id = 1;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001151
Girish Gowdra72cbee92021-11-05 15:16:18 -07001152 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1153
1154 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1155 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1156 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1157 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1158 return onu_cfg_get_res;
1159 }
1160 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001161 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1162 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1163
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301164 future<int> push_onu_deact_complt_res = \
1165 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1166 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1167 Status status = future_res.get();
1168 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001169 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1170}
1171
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301172// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1173TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001174 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1175 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1176
Girish Gowdra72cbee92021-11-05 15:16:18 -07001177 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1178 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001179 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001180 onu_key.pon_ni = 0;
1181 onu_key.onu_id = 1;
1182
1183 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1184
1185 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1186 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1187 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1188 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1189 return onu_cfg_get_res;
1190 }
1191 ));
1192
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001193
1194 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1195 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1196
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301197 future<int> push_onu_deact_complt_res = \
1198 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1199 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1200
1201 Status status = future_res.get();
1202 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001203 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1204}
1205
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301206// Test 3 - DeleteOnu failure case - onu deactivation fails
1207TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301208 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1209
Girish Gowdra72cbee92021-11-05 15:16:18 -07001210 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1211 bcmolt_onu_cfg onu_cfg_out;
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301212 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001213 onu_key.pon_ni = 0;
1214 onu_key.onu_id = 1;
1215
1216 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1217
1218 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1219 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1220 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1221 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1222 return onu_cfg_get_res;
1223 }
1224 ));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301225
1226 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1227
1228 future<int> push_onu_deact_complt_res = \
1229 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1230 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1231
1232 Status status = future_res.get();
1233 int res = push_onu_deact_complt_res.get();
1234 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1235}
1236
1237// Test 4 - DeleteOnu failure case - onu deactivation timesout
1238TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301239 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1240
Girish Gowdra72cbee92021-11-05 15:16:18 -07001241 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1242 bcmolt_onu_cfg onu_cfg_out;
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301243 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001244 onu_key.pon_ni = 0;
1245 onu_key.onu_id = 1;
1246
1247 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1248
1249 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1250 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1251 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1252 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1253 return onu_cfg_get_res;
1254 }
1255 ));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301256
1257 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1258
1259 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1260
1261 Status status = future_res.get();
1262 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1263}
1264
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301265// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1266TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301267 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1268 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1269
Girish Gowdra72cbee92021-11-05 15:16:18 -07001270 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1271 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301272 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001273 onu_key.pon_ni = 0;
1274 onu_key.onu_id = 1;
1275
1276 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1277
1278 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1279 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1280 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1281 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1282 return onu_cfg_get_res;
1283 }
1284 ));
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301285
1286 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1287 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1288
1289 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1290
1291 Status status = future_res.get();
1292 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1293}
1294
1295// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1296TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1297 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1298
Girish Gowdra72cbee92021-11-05 15:16:18 -07001299 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
1300 bcmolt_onu_cfg onu_cfg_out;
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301301 bcmolt_onu_key onu_key;
Girish Gowdra72cbee92021-11-05 15:16:18 -07001302 onu_key.pon_ni = 0;
1303 onu_key.onu_id = 1;
1304
1305 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
1306
1307 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
1308 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
1309 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1310 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
1311 return onu_cfg_get_res;
1312 }
1313 ));
1314
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301315
1316 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1317
1318 Status status = future_res.get();
1319 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1320}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301321
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001322////////////////////////////////////////////////////////////////////////////
1323// For testing OmciMsgOut functionality
1324////////////////////////////////////////////////////////////////////////////
1325
1326class TestOmciMsgOut : public Test {
1327 protected:
1328 uint32_t pon_id = 0;
1329 uint32_t onu_id = 1;
1330 std::string pkt = "omci-pkt";
1331 NiceMock<BalMocker> balMock;
1332
1333 virtual void SetUp() {
1334 }
1335
1336 virtual void TearDown() {
1337 }
1338};
1339
1340// Test 1 - OmciMsgOut success case
1341TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1342 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1343
1344 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1345
1346 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1347 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1348}
1349
1350// Test 1 - OmciMsgOut failure case
1351TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1352 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1353
1354 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1355
1356 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1357 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1358}
1359
1360////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001361// For testing FlowAdd functionality
1362////////////////////////////////////////////////////////////////////////////
1363
1364class TestFlowAdd : public Test {
1365 protected:
1366 int32_t access_intf_id = 0;
1367 int32_t onu_id = 1;
1368 int32_t uni_id = 0;
1369 uint32_t port_no = 16;
1370 uint32_t flow_id = 1;
1371 std::string flow_type = "upstream";
1372 int32_t alloc_id = 1024;
1373 int32_t network_intf_id = 0;
1374 int32_t gemport_id = 1024;
1375 int32_t priority_value = 0;
1376 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301377 int32_t group_id = -1;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001378 uint32_t tech_profile_id = 64;
Burak Gurdaga0523592021-02-24 15:17:47 +00001379 bool enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001380
1381 NiceMock<BalMocker> balMock;
1382 openolt::Flow* flow;
1383 openolt::Classifier* classifier;
1384 openolt::Action* action;
1385 openolt::ActionCmd* cmd;
1386
1387 bcmolt_flow_key flow_key;
1388 bcmolt_flow_cfg flow_cfg;
1389
1390 tech_profile::TrafficQueues* traffic_queues;
1391 tech_profile::TrafficQueue* traffic_queue_1;
1392 tech_profile::TrafficQueue* traffic_queue_2;
1393 tech_profile::DiscardConfig* discard_config_1;
1394 tech_profile::DiscardConfig* discard_config_2;
1395 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1396 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1397
1398
1399 virtual void SetUp() {
1400 classifier = new openolt::Classifier;
1401 action = new openolt::Action;
1402 cmd = new openolt::ActionCmd;
1403
1404 classifier->set_o_tpid(0);
1405 classifier->set_o_vid(7);
1406 classifier->set_i_tpid(0);
1407 classifier->set_i_vid(0);
1408 classifier->set_o_pbits(0);
1409 classifier->set_i_pbits(0);
1410 classifier->set_eth_type(0);
1411 classifier->set_ip_proto(0);
1412 classifier->set_src_port(0);
1413 classifier->set_dst_port(0);
1414 classifier->set_pkt_tag_type("single_tag");
Girish Gowdraf83e17a2022-02-16 16:27:00 -08001415 classifier->set_src_mac("aabbccddeeff");
1416 classifier->set_dst_mac("112233445566");
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001417
1418 action->set_o_vid(12);
1419 action->set_o_pbits(0);
1420 action->set_o_tpid(0);
1421 action->set_i_vid(0);
1422 action->set_i_pbits(0);
1423 action->set_i_tpid(0);
1424
1425 cmd->set_add_outer_tag(true);
1426 cmd->set_remove_outer_tag(false);
1427 cmd->set_trap_to_host(false);
1428 action->set_allocated_cmd(cmd);
1429
1430 flow_key.flow_id = 1;
1431 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1432 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1433 flow_cfg.data.onu_id=1;
1434 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1435 flow_cfg.data.svc_port_id=1024;
1436 flow_cfg.data.priority=0;
1437 flow_cfg.data.cookie=0;
1438 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1439 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1440 flow_cfg.data.ingress_intf.intf_id=0;
1441 flow_cfg.data.egress_intf.intf_id=0;
1442 flow_cfg.data.classifier.o_vid=7;
1443 flow_cfg.data.classifier.o_pbits=0;
1444 flow_cfg.data.classifier.i_vid=0;
1445 flow_cfg.data.classifier.i_pbits=0;
1446 flow_cfg.data.classifier.ether_type=0;
1447 flow_cfg.data.classifier.ip_proto=0;
1448 flow_cfg.data.classifier.src_port=0;
1449 flow_cfg.data.classifier.dst_port=0;
1450 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1451 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1452 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1453 flow_cfg.data.egress_qos.tm_sched.id=1020;
1454 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1455 flow_cfg.data.action.o_vid=12;
1456 flow_cfg.data.action.o_pbits=0;
1457 flow_cfg.data.action.i_vid=0;
1458 flow_cfg.data.action.i_pbits=0;
1459 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1460
1461 traffic_queues = new tech_profile::TrafficQueues;
1462 traffic_queues->set_intf_id(0);
1463 traffic_queues->set_onu_id(2);
1464 traffic_queue_1 = traffic_queues->add_traffic_queues();
1465 traffic_queue_1->set_gemport_id(1024);
1466 traffic_queue_1->set_pbit_map("0b00000101");
1467 traffic_queue_1->set_aes_encryption(true);
1468 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1469 traffic_queue_1->set_priority(0);
1470 traffic_queue_1->set_weight(0);
1471 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1472 discard_config_1 = new tech_profile::DiscardConfig;
1473 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1474 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1475 tail_drop_discard_config_1->set_queue_size(8);
1476 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1477 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1478
1479 traffic_queues->set_uni_id(0);
1480 traffic_queues->set_port_no(16);
1481
1482 traffic_queue_2 = traffic_queues->add_traffic_queues();
1483 traffic_queue_2->set_gemport_id(1025);
1484 traffic_queue_2->set_pbit_map("0b00001010");
1485 traffic_queue_2->set_aes_encryption(true);
1486 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1487 traffic_queue_2->set_priority(1);
1488 traffic_queue_2->set_weight(0);
1489 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1490 discard_config_2 = new tech_profile::DiscardConfig;
1491 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1492 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1493 tail_drop_discard_config_2->set_queue_size(8);
1494 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1495 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1496 }
1497
1498 virtual void TearDown() {
1499 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301500
1501 public:
1502 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
1503 gem_cfg_compltd_key k(0, gem_port_id);
1504 gem_cfg_complete_result res;
1505 res.pon_intf_id = 0;
1506 res.gem_port_id = gem_port_id;
1507 res.state = state;
1508 res.status = status;
1509
1510 uint32_t gem_cfg_key_check_counter = 1;
1511 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
1512 while(true) {
1513 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1514 it = gem_cfg_compltd_map.find(k);
1515
1516 if (it != gem_cfg_compltd_map.end()) {
1517 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1518 break;
1519 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
1520 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1521
1522 // We need to wait for some time to allow the Gem Cfg Request to be triggered
1523 // before we push the result.
1524 bcmos_usleep(6000);
1525 } else {
1526 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
1527 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1528 return 0;
1529 }
1530 gem_cfg_key_check_counter++;
1531 }
1532
1533 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1534 if (it->second) {
1535 it->second->push(res);
1536 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
1537 }
1538 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1539 return 0;
1540 }
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001541};
1542
1543// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1544TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1545 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1546 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1547
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301548 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001549 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001550 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1551}
1552
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301553#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001554// Test 2 - FlowAdd - Duplicate Flow case
1555TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1556 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1557 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1558 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1559
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301560 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 +00001561 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001562 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1563}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301564#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001565
1566// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1567TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1568 gemport_id = 1025;
1569
1570 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1571 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1572
1573 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1574 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1575 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1576
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301577 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 +00001578 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001579 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1580}
1581
1582// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1583TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1584 flow_type = "bidirectional";
1585
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301586 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 +00001587 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001588 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1589}
1590
1591// Test 5 - FlowAdd - Failure case(Invalid network setting)
1592TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1593 network_intf_id = -1;
1594
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301595 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 +00001596 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001597 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1598}
1599
1600// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1601TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1602 flow_id = 2;
1603
1604 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301605 action = new openolt::Action;
1606 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001607 cmd->set_trap_to_host(true);
1608 action->set_allocated_cmd(cmd);
1609
1610 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1611 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1612 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1613 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1614 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1615
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301616 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 +00001617 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001618 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1619}
1620
1621// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1622TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1623 flow_id = 3;
1624 gemport_id = 1025;
1625
1626 classifier->set_ip_proto(17);
1627 classifier->set_src_port(68);
1628 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301629 action = new openolt::Action;
1630 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001631 cmd->set_trap_to_host(true);
1632 action->set_allocated_cmd(cmd);
1633
1634 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1635 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1636 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1637 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1638 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1639
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301640 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 +00001641 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001642 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1643}
1644
1645// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1646TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1647 flow_id = 4;
1648 flow_type = "downstream";
1649
1650 classifier->set_o_vid(12);
1651 classifier->set_i_vid(7);
1652 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301653 action = new openolt::Action;
1654 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001655 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001656 cmd->set_remove_outer_tag(true);
1657 action->set_allocated_cmd(cmd);
1658
1659 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1660 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1661 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1662 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1663 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1664
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301665 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 +00001666 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001667 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1668}
1669
1670// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1671TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1672 onu_id = 2;
1673 flow_id = 5;
1674 alloc_id = 1025;
1675
1676 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1677 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1678
1679 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1680 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1681 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1682 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1683 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001684
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301685 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
1686 future<int> push_gem_cfg_complt = \
1687 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1688 push_gem_cfg_complt = \
1689 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
1690 Status status = future_res.get();
1691 int res = push_gem_cfg_complt.get();
1692
1693 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 +00001694 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001695 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1696}
1697
1698// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1699TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1700 onu_id = 2;
1701 flow_id = 6;
1702 flow_type = "downstream";
1703 alloc_id = 1025;
1704
1705 classifier->set_o_vid(12);
1706 classifier->set_i_vid(7);
1707 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301708 action = new openolt::Action;
1709 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001710 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001711 cmd->set_remove_outer_tag(true);
1712 action->set_allocated_cmd(cmd);
1713
1714 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1715 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1716
1717 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1718 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1719 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1720 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1721 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1722 CreateTrafficQueues_(traffic_queues);
1723
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301724 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 +00001725 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001726 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1727}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301728
Burak Gurdaga0523592021-02-24 15:17:47 +00001729// Test 11 - FlowAdd - success case (Downstream-Encrypted GEM)
1730TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) {
1731 onu_id = 2;
1732 flow_id = 7;
1733 flow_type = "downstream";
1734 alloc_id = 1025;
1735 enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001736
Burak Gurdaga0523592021-02-24 15:17:47 +00001737 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1738 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1739 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1740 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1741 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1742
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301743 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 +00001744 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301745
1746 future<int> push_gem_cfg_complt = \
1747 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1748 Status status = future_res.get();
1749 int res = push_gem_cfg_complt.get();
Burak Gurdaga0523592021-02-24 15:17:47 +00001750 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1751}
1752
1753// Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied)
1754TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) {
1755 onu_id = 2;
1756 flow_id = 8;
1757 flow_type = "downstream";
1758 alloc_id = 1025;
1759 enable_encryption = false;
1760
1761 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1762 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1763 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1764 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1765 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1766
1767 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1768 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1769 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1770}
1771
1772// Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied)
1773TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) {
1774 onu_id = 2;
1775 flow_id = 9;
1776 flow_type = "upstream";
1777 alloc_id = 1025;
1778 enable_encryption = true;
1779
1780 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1781 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1782 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1783 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1784 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1785
1786 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1787 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1788 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1789}
1790
1791// Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied)
1792TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) {
1793 onu_id = 2;
1794 flow_id = 10;
1795 flow_type = "multicast";
1796 alloc_id = 1025;
1797 enable_encryption = true;
1798
1799 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1800 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1801 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1802 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1803 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1804
1805 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1806 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1807 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1808}
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001809////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001810// For testing OnuPacketOut functionality
1811////////////////////////////////////////////////////////////////////////////
1812
1813class TestOnuPacketOut : public Test {
1814 protected:
1815 uint32_t pon_id = 0;
1816 uint32_t onu_id = 1;
1817 std::string pkt = "omci-pkt";
1818 NiceMock<BalMocker> balMock;
1819
1820 virtual void SetUp() {
1821 }
1822
1823 virtual void TearDown() {
1824 }
1825};
1826
1827// Test 1 - OnuPacketOut success case
1828TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1829 uint32_t port_no = 16;
1830 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001831
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001832 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001833 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1834
1835 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1836 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1837}
1838
1839// Test 2 - OnuPacketOut Port number as 0 case
1840TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1841 uint32_t port_no = 0;
1842 uint32_t gemport_id = 1024;
1843
1844 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1845 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1846}
1847
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001848// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1849TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1850 uint32_t port_no = 16;
1851 uint32_t gemport_id = 0;
1852
1853 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1854 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1855
1856 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1857 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1858}
1859
1860// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1861TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1862 uint32_t port_no = 64;
1863 uint32_t gemport_id = 0;
1864
1865 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1866 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1867
1868 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1869 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1870}
1871
1872////////////////////////////////////////////////////////////////////////////
1873// For testing FlowRemove functionality
1874////////////////////////////////////////////////////////////////////////////
1875
1876class TestFlowRemove : public Test {
1877 protected:
1878 NiceMock<BalMocker> balMock;
1879
1880 virtual void SetUp() {
1881 }
1882
1883 virtual void TearDown() {
1884 }
1885};
1886
1887// Test 1 - FlowRemove - Failure case
1888TEST_F(TestFlowRemove, FlowRemoveFailure) {
1889 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1890 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1891
1892 Status status = FlowRemove_(1, "upstream");
1893 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1894}
1895
1896// Test 2 - FlowRemove - success case
1897TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1898 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1899 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1900
1901 Status status = FlowRemove_(1, "upstream");
1902 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1903}
1904
1905////////////////////////////////////////////////////////////////////////////
1906// For testing UplinkPacketOut functionality
1907////////////////////////////////////////////////////////////////////////////
1908
1909class TestUplinkPacketOut : public Test {
1910 protected:
1911 uint32_t pon_id = 0;
1912 std::string pkt = "omci-pkt";
1913 NiceMock<BalMocker> balMock;
1914
1915 bcmolt_flow_key flow_key;
1916 bcmolt_flow_cfg flow_cfg;
1917
1918 virtual void SetUp() {
1919 flow_key.flow_id = 1;
1920 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1921 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1922 flow_cfg.data.onu_id=1;
1923 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1924 flow_cfg.data.svc_port_id=1024;
1925 flow_cfg.data.priority=0;
1926 flow_cfg.data.cookie=0;
1927 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1928 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1929 flow_cfg.data.ingress_intf.intf_id=0;
1930 flow_cfg.data.egress_intf.intf_id=0;
1931 flow_cfg.data.classifier.o_vid=7;
1932 flow_cfg.data.classifier.o_pbits=0;
1933 flow_cfg.data.classifier.i_vid=0;
1934 flow_cfg.data.classifier.i_pbits=0;
1935 flow_cfg.data.classifier.ether_type=0;
1936 flow_cfg.data.classifier.ip_proto=0;
1937 flow_cfg.data.classifier.src_port=0;
1938 flow_cfg.data.classifier.dst_port=0;
1939 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1940 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1941 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1942 flow_cfg.data.egress_qos.tm_sched.id=1020;
1943 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1944 flow_cfg.data.action.o_vid=12;
1945 flow_cfg.data.action.o_pbits=0;
1946 flow_cfg.data.action.i_vid=0;
1947 flow_cfg.data.action.i_pbits=0;
1948 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1949 }
1950
1951 virtual void TearDown() {
1952 }
1953};
1954
1955// Test 1 - UplinkPacketOut success case
1956TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1957 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1958 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1959 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1960 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1961 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1962
1963 Status status = UplinkPacketOut_(pon_id, pkt);
1964 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1965}
1966
1967// Test 2 - UplinkPacketOut Failure case
1968TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1969 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1970 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1971 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1972 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1973 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1974
1975 Status status = UplinkPacketOut_(pon_id, pkt);
1976 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1977}
1978
1979// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1980TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1981 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1982
1983 FlowRemove_(2, "upstream");
1984 FlowRemove_(3, "upstream");
1985 FlowRemove_(4, "downstream");
1986 FlowRemove_(5, "upstream");
1987 FlowRemove_(6, "downstream");
Burak Gurdaga0523592021-02-24 15:17:47 +00001988 FlowRemove_(7, "downstream");
1989 FlowRemove_(8, "downstream");
1990 FlowRemove_(9, "upstream");
1991 FlowRemove_(10, "multicast");
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001992
1993 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1994 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1995 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1996
1997 Status status = UplinkPacketOut_(pon_id, pkt);
1998 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1999}
2000
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002001////////////////////////////////////////////////////////////////////////////
2002// For testing CreateTrafficSchedulers functionality
2003////////////////////////////////////////////////////////////////////////////
2004
2005class TestCreateTrafficSchedulers : public Test {
2006 protected:
2007 NiceMock<BalMocker> balMock;
2008 tech_profile::TrafficSchedulers* traffic_scheds;
2009 tech_profile::TrafficScheduler* traffic_sched;
2010 tech_profile::SchedulerConfig* scheduler;
2011 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2012
2013 virtual void SetUp() {
2014 traffic_scheds = new tech_profile::TrafficSchedulers;
2015 traffic_scheds->set_intf_id(0);
2016 traffic_scheds->set_onu_id(1);
2017 traffic_scheds->set_uni_id(0);
2018 traffic_scheds->set_port_no(16);
2019 traffic_sched = traffic_scheds->add_traffic_scheds();
2020 traffic_sched->set_alloc_id(1024);
2021 scheduler = new tech_profile::SchedulerConfig;
2022 scheduler->set_priority(0);
2023 scheduler->set_weight(0);
2024 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2025 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2026 traffic_shaping_info->set_cbs(60536);
2027 traffic_shaping_info->set_pbs(65536);
2028 traffic_shaping_info->set_gir(10000);
2029 }
2030
2031 virtual void TearDown() {
2032 }
2033
2034 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302035 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2036 alloc_cfg_compltd_key k(0, 1024);
2037 alloc_cfg_complete_result res;
2038 res.pon_intf_id = 0;
2039 res.alloc_id = 1024;
2040 res.state = state;
2041 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002042
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302043 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2044 // before we push the result.
2045 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2046 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2047 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2048 if (it == alloc_cfg_compltd_map.end()) {
2049 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 -05002050 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302051 it->second->push(res);
2052 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002053 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302054 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2055 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002056 }
2057};
2058
2059// Test 1 - CreateTrafficSchedulers-Upstream success case
2060TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
2061 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2062 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2063 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2064 traffic_sched->set_allocated_scheduler(scheduler);
2065 traffic_shaping_info->set_cir(64000);
2066 traffic_shaping_info->set_pir(128000);
2067 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2068
2069 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2070 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2071
Girish Gowdra72cbee92021-11-05 15:16:18 -07002072 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2073 bcmolt_onu_cfg onu_cfg_out;
2074 bcmolt_onu_key onu_key;
2075 onu_key.pon_ni = 0;
2076 onu_key.onu_id = 1;
2077 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2078 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2079 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2080 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2081 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2082 return onu_cfg_get_res;
2083 }
2084 ));
2085
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002086 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302087 future<int> push_alloc_cfg_complt = \
2088 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002089
2090 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302091 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002092 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2093}
2094
2095// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
2096TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
2097 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2098 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2099 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2100 traffic_sched->set_allocated_scheduler(scheduler);
2101 traffic_shaping_info->set_cir(64000);
2102 traffic_shaping_info->set_pir(128000);
2103 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2104
2105 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2106 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2107
Girish Gowdra72cbee92021-11-05 15:16:18 -07002108 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2109 bcmolt_onu_cfg onu_cfg_out;
2110 bcmolt_onu_key onu_key;
2111 onu_key.pon_ni = 0;
2112 onu_key.onu_id = 1;
2113 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302114
2115 bcmos_errno alloc_cfg_get_res = BCM_ERR_OK;
2116 bcmolt_itupon_alloc_cfg alloc_cfg;
2117 bcmolt_itupon_alloc_key alloc_key;
2118 alloc_key.pon_ni = 0;
2119 alloc_key.alloc_id = 1024;
2120 BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key);
2121
2122 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2)
2123 .WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
Girish Gowdra72cbee92021-11-05 15:16:18 -07002124 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2125 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2126 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2127 return onu_cfg_get_res;
2128 }
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302129 ))
2130 .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2131 bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg;
2132 o_cfg->data.state = BCMOLT_ACTIVATION_STATE_PROCESSING;
2133 memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg));
2134 return alloc_cfg_get_res;
2135 }
Girish Gowdra72cbee92021-11-05 15:16:18 -07002136 ));
2137
2138 Status status = CreateTrafficSchedulers_(traffic_scheds);
2139 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2140}
2141
2142// Test 2A - CreateTrafficSchedulers-Upstream success case(ONU not in ACTIVE state)
2143TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccessOnuNotInActive) {
2144 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2145 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2146 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2147 traffic_sched->set_allocated_scheduler(scheduler);
2148 traffic_shaping_info->set_cir(64000);
2149 traffic_shaping_info->set_pir(128000);
2150 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2151
2152 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2153 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2154
2155 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2156 bcmolt_onu_cfg onu_cfg_out;
2157 bcmolt_onu_key onu_key;
2158 onu_key.pon_ni = 0;
2159 onu_key.onu_id = 1;
2160 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2161 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2162 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2163 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2164 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2165 return onu_cfg_get_res;
2166 }
2167 ));
2168
2169 Status status = CreateTrafficSchedulers_(traffic_scheds);
2170 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2171}
2172
2173// Test 2B - CreateTrafficSchedulers-Upstream failure case. cfg-get failure
2174TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamCfgGetFailure) {
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 bcmos_errno olt_cfg_get_res = BCM_ERR_INTERNAL;
2185 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2186 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
2187
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002188 Status status = CreateTrafficSchedulers_(traffic_scheds);
2189 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2190}
2191
Girish Gowdracdd5e5f2021-12-05 16:48:08 +05302192// Test 2C - CreateTrafficSchedulers-Upstream Succes case(timeout waiting for alloc cfg indication, but itupon-alloc object is ACTIVE)
2193TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeoutSuccess) {
2194 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2195 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2196 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2197 traffic_sched->set_allocated_scheduler(scheduler);
2198 traffic_shaping_info->set_cir(64000);
2199 traffic_shaping_info->set_pir(128000);
2200 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2201
2202 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2203 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2204
2205 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2206 bcmolt_onu_cfg onu_cfg_out;
2207 bcmolt_onu_key onu_key;
2208 onu_key.pon_ni = 0;
2209 onu_key.onu_id = 1;
2210 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2211
2212 bcmos_errno alloc_cfg_get_res = BCM_ERR_OK;
2213 bcmolt_itupon_alloc_cfg alloc_cfg;
2214 bcmolt_itupon_alloc_key alloc_key;
2215 alloc_key.pon_ni = 0;
2216 alloc_key.alloc_id = 1024;
2217 BCMOLT_CFG_INIT(&alloc_cfg, itupon_alloc, alloc_key);
2218
2219 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).Times(2)
2220 .WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2221 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2222 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2223 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2224 return onu_cfg_get_res;
2225 }
2226 ))
2227 .WillOnce(Invoke([alloc_cfg_get_res, &alloc_cfg] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2228 bcmolt_itupon_alloc_cfg* o_cfg = (bcmolt_itupon_alloc_cfg*)cfg;
2229 o_cfg->data.state = BCMOLT_ACTIVATION_STATE_ACTIVE;
2230 memcpy(&alloc_cfg, o_cfg, sizeof(bcmolt_itupon_alloc_cfg));
2231 return alloc_cfg_get_res;
2232 }
2233 ));
2234
2235 Status status = CreateTrafficSchedulers_(traffic_scheds);
2236 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2237}
2238
2239
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002240// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
2241TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
2242 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2243 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2244 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2245 traffic_sched->set_allocated_scheduler(scheduler);
2246 traffic_shaping_info->set_cir(64000);
2247 traffic_shaping_info->set_pir(128000);
2248 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2249
2250 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2251 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2252
Girish Gowdra72cbee92021-11-05 15:16:18 -07002253 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2254 bcmolt_onu_cfg onu_cfg_out;
2255 bcmolt_onu_key onu_key;
2256 onu_key.pon_ni = 0;
2257 onu_key.onu_id = 1;
2258 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2259 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2260 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2261 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2262 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2263 return onu_cfg_get_res;
2264 }
2265 ));
2266
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002267 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302268 future<int> push_alloc_cfg_complt = \
2269 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002270
2271 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302272 int res = push_alloc_cfg_complt.get();
2273
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002274 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2275}
2276
2277// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
2278TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
2279 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2280 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2281 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2282 traffic_sched->set_allocated_scheduler(scheduler);
2283 traffic_shaping_info->set_cir(64000);
2284 traffic_shaping_info->set_pir(128000);
2285 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2286
2287 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2288 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2289
Girish Gowdra72cbee92021-11-05 15:16:18 -07002290 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2291 bcmolt_onu_cfg onu_cfg_out;
2292 bcmolt_onu_key onu_key;
2293 onu_key.pon_ni = 0;
2294 onu_key.onu_id = 1;
2295 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2296 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2297 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2298 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2299 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2300 return onu_cfg_get_res;
2301 }
2302 ));
2303
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002304 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302305 future<int> push_alloc_cfg_complt = \
2306 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002307
2308 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302309 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002310 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2311}
2312
2313// Test 5 - CreateTrafficSchedulers-Upstream Failure case
2314TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
2315 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2316 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2317 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2318 traffic_sched->set_allocated_scheduler(scheduler);
2319 traffic_shaping_info->set_cir(64000);
2320 traffic_shaping_info->set_pir(128000);
2321 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2322
2323 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2324 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2325
2326 Status status = CreateTrafficSchedulers_(traffic_scheds);
2327 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2328}
2329
2330// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
2331TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
2332 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2333 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2334 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2335 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002336 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002337 traffic_shaping_info->set_cir(64000);
2338 traffic_shaping_info->set_pir(0);
2339 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2340
2341 Status status = CreateTrafficSchedulers_(traffic_scheds);
2342 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2343}
2344
2345// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
2346TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
2347 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2348 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2349 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2350 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002351 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002352 traffic_shaping_info->set_cir(64000);
2353 traffic_shaping_info->set_pir(32000);
2354 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2355
2356 Status status = CreateTrafficSchedulers_(traffic_scheds);
2357 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2358}
2359
2360// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
2361TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
2362 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2363 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2364 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2365 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002366 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002367 traffic_shaping_info->set_cir(64000);
2368 traffic_shaping_info->set_pir(64000);
2369 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2370
2371 Status status = CreateTrafficSchedulers_(traffic_scheds);
2372 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2373}
2374
2375// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
2376TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
2377 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2378 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2379 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2380 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002381 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002382 traffic_shaping_info->set_cir(64000);
2383 traffic_shaping_info->set_pir(0);
2384 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2385
2386 Status status = CreateTrafficSchedulers_(traffic_scheds);
2387 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2388}
2389
2390// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
2391TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
2392 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2393 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2394 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2395 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002396 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002397 traffic_shaping_info->set_cir(0);
2398 traffic_shaping_info->set_pir(32000);
2399 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2400
2401 Status status = CreateTrafficSchedulers_(traffic_scheds);
2402 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2403}
2404
2405// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
2406TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
2407 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2408 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2409 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2410 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002411 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002412 traffic_shaping_info->set_cir(64000);
2413 traffic_shaping_info->set_pir(32000);
2414 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2415
2416 Status status = CreateTrafficSchedulers_(traffic_scheds);
2417 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2418}
2419
2420// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
2421TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
2422 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2423 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2424 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2425 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002426 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002427 traffic_shaping_info->set_cir(64000);
2428 traffic_shaping_info->set_pir(64000);
2429 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2430
2431 Status status = CreateTrafficSchedulers_(traffic_scheds);
2432 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2433}
2434
2435// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
2436TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
2437 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2438 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2439 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2440 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002441 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002442 traffic_shaping_info->set_cir(64000);
2443 traffic_shaping_info->set_pir(0);
2444 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2445
2446 Status status = CreateTrafficSchedulers_(traffic_scheds);
2447 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2448}
2449
2450// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
2451TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
2452 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2453 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2454 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2455 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002456 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002457 traffic_shaping_info->set_cir(0);
2458 traffic_shaping_info->set_pir(32000);
2459 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2460
2461 Status status = CreateTrafficSchedulers_(traffic_scheds);
2462 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2463}
2464
Burak Gurdag623fada2021-04-20 22:02:36 +00002465// Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case
2466TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002467 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2468 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2469 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2470 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002471 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002472 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
Burak Gurdag623fada2021-04-20 22:02:36 +00002476 Status status = CreateTrafficSchedulers_(traffic_scheds);
2477 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002478}
2479
Burak Gurdag623fada2021-04-20 22:02:36 +00002480// Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case
2481TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002482 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2483 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2484 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2485 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002486 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002487 traffic_shaping_info->set_cir(64000);
2488 traffic_shaping_info->set_pir(32000);
2489 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2490
Burak Gurdag623fada2021-04-20 22:02:36 +00002491 Status status = CreateTrafficSchedulers_(traffic_scheds);
2492 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2493}
2494
2495// Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case
2496TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) {
2497 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2498 scheduler->set_additional_bw(9);
2499 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2500 traffic_sched->set_allocated_scheduler(scheduler);
2501 traffic_shaping_info->set_gir(0);
2502 traffic_shaping_info->set_cir(64000);
2503 traffic_shaping_info->set_pir(128000);
2504 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2505
2506 Status status = CreateTrafficSchedulers_(traffic_scheds);
2507 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2508}
2509
2510// Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case
2511TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) {
2512 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2513 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2514 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2515 traffic_sched->set_allocated_scheduler(scheduler);
2516 traffic_shaping_info->set_gir(64000);
2517 traffic_shaping_info->set_cir(0);
2518 traffic_shaping_info->set_pir(64000);
2519 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2520
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002521 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2522 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2523
2524 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302525 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002526 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2527
2528 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302529 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002530 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2531}
2532
Burak Gurdag623fada2021-04-20 22:02:36 +00002533// Test 19 - CreateTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002534TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2535 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2536 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2537 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2538 traffic_sched->set_allocated_scheduler(scheduler);
2539 traffic_shaping_info->set_cir(64000);
2540 traffic_shaping_info->set_pir(128000);
2541 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2542
2543 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2544 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2545
2546 Status status = CreateTrafficSchedulers_(traffic_scheds);
2547 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2548}
2549
Burak Gurdag623fada2021-04-20 22:02:36 +00002550// Test 20 - CreateTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002551TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2552 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2553 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2554 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2555 traffic_sched->set_allocated_scheduler(scheduler);
2556 traffic_shaping_info->set_cir(64000);
2557 traffic_shaping_info->set_pir(128000);
2558 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2559
2560 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2561 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2562
2563 Status status = CreateTrafficSchedulers_(traffic_scheds);
2564 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2565}
2566
Burak Gurdag623fada2021-04-20 22:02:36 +00002567// Test 21 - CreateTrafficSchedulers-Invalid direction Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002568TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2569 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2570 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2571 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2572 traffic_sched->set_allocated_scheduler(scheduler);
2573 traffic_shaping_info->set_cir(64000);
2574 traffic_shaping_info->set_pir(128000);
2575 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2576
2577 Status status = CreateTrafficSchedulers_(traffic_scheds);
2578 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2579}
2580
2581////////////////////////////////////////////////////////////////////////////
2582// For testing RemoveTrafficSchedulers functionality
2583////////////////////////////////////////////////////////////////////////////
2584
2585class TestRemoveTrafficSchedulers : public Test {
2586 protected:
2587 NiceMock<BalMocker> balMock;
2588 tech_profile::TrafficSchedulers* traffic_scheds;
2589 tech_profile::TrafficScheduler* traffic_sched;
2590 tech_profile::SchedulerConfig* scheduler;
2591 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2592 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302593 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002594
2595 virtual void SetUp() {
2596 traffic_scheds = new tech_profile::TrafficSchedulers;
2597 traffic_scheds->set_intf_id(0);
2598 traffic_scheds->set_onu_id(1);
2599 traffic_scheds->set_uni_id(0);
2600 traffic_scheds->set_port_no(16);
2601 traffic_sched = traffic_scheds->add_traffic_scheds();
2602 traffic_sched->set_alloc_id(1025);
2603 scheduler = new tech_profile::SchedulerConfig;
2604 scheduler->set_priority(0);
2605 scheduler->set_weight(0);
2606 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2607 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2608 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2609 traffic_shaping_info->set_cir(64000);
2610 traffic_shaping_info->set_pir(128000);
2611 traffic_shaping_info->set_cbs(60536);
2612 traffic_shaping_info->set_pbs(65536);
2613 traffic_shaping_info->set_gir(10000);
2614 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2615 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2616 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2617 }
2618
2619 virtual void TearDown() {
2620 }
2621
2622 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302623 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2624 alloc_cfg_compltd_key k(0, 1025);
2625 alloc_cfg_complete_result res;
2626 res.pon_intf_id = 0;
2627 res.alloc_id = 1025;
2628 res.state = state;
2629 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002630
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302631 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2632 // before we push the result.
2633 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302634 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2635 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2636 if (it == alloc_cfg_compltd_map.end()) {
2637 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 -05002638 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302639 it->second->push(res);
2640 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002641 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302642 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2643 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002644 }
2645};
2646
2647// Test 1 - RemoveTrafficSchedulers-Upstream success case
2648TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2649 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2650 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2651 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2652
Girish Gowdra72cbee92021-11-05 15:16:18 -07002653 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2654 bcmolt_onu_cfg onu_cfg_out;
2655 bcmolt_onu_key onu_key;
2656 onu_key.pon_ni = 0;
2657 onu_key.onu_id = 1;
2658
2659 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2660
2661 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2662 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2663 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2664 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2665 return onu_cfg_get_res;
2666 }
2667 ));
2668
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302669
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002670 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302671 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002672 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2673
2674 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302675 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002676 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2677}
2678
2679// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2680TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2681 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2682 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2683 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2684
Girish Gowdra72cbee92021-11-05 15:16:18 -07002685 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2686 bcmolt_onu_cfg onu_cfg_out;
2687 bcmolt_onu_key onu_key;
2688 onu_key.pon_ni = 0;
2689 onu_key.onu_id = 1;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302690
Girish Gowdra72cbee92021-11-05 15:16:18 -07002691 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2692
2693 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2694 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2695 o_cfg->data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
2696 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2697 return onu_cfg_get_res;
2698 }
2699 ));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002700 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302701 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002702 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2703
2704 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302705 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002706 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2707}
2708
Girish Gowdra72cbee92021-11-05 15:16:18 -07002709// Test 3 - RemoveTrafficSchedulers-Upstream success case(ONU case - Don't wait for alloc object delete response)
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302710TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2711 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2712 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2713 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2714
Girish Gowdra72cbee92021-11-05 15:16:18 -07002715 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
2716 bcmolt_onu_cfg onu_cfg_out;
2717 bcmolt_onu_key onu_key;
2718 onu_key.pon_ni = 0;
2719 onu_key.onu_id = 1;
2720
2721 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2722
2723 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2724 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2725 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2726 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2727 return onu_cfg_get_res;
2728 }
2729 ));
2730
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302731
2732 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2733
2734 Status status = future_res.get();
2735 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2736}
2737
2738// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2739TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2740 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2741 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2742 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2743
Girish Gowdra72cbee92021-11-05 15:16:18 -07002744 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
2745 bcmolt_onu_cfg onu_cfg_out;
2746 bcmolt_onu_key onu_key;
2747 onu_key.pon_ni = 0;
2748 onu_key.onu_id = 1;
2749
2750 BCMOLT_CFG_INIT(&onu_cfg_out, onu, onu_key);
2751
2752 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([onu_cfg_get_res, &onu_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
2753 bcmolt_onu_cfg* o_cfg = (bcmolt_onu_cfg*)cfg;
2754 o_cfg->data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
2755 memcpy(&onu_cfg_out, o_cfg, sizeof(bcmolt_onu_cfg));
2756 return onu_cfg_get_res;
2757 }
2758 ));
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302759
2760 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2761
2762 Status status = future_res.get();
2763 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2764}
2765
2766// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002767TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2768 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2769
2770 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2771 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2772
2773 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2774 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2775}
2776
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302777// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002778TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2779 //Create Scheduler
2780 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2781 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2782 traffic_sched->set_allocated_scheduler(scheduler);
2783 CreateTrafficSchedulers_(traffic_scheds);
2784
2785 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2786 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2787
2788 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2789 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2790}
2791
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302792// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002793TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2794 //Create Scheduler
2795 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2796 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2797 traffic_sched->set_allocated_scheduler(scheduler);
2798 CreateTrafficSchedulers_(traffic_scheds);
2799
2800 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2801 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2802
2803 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2804 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2805}
2806
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302807// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002808TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2809 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2810
2811 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2812 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2813}
2814
2815////////////////////////////////////////////////////////////////////////////
2816// For testing CreateTrafficQueues functionality
2817////////////////////////////////////////////////////////////////////////////
2818
2819class TestCreateTrafficQueues : public Test {
2820 protected:
2821 NiceMock<BalMocker> balMock;
2822 tech_profile::TrafficQueues* traffic_queues;
2823 tech_profile::TrafficQueue* traffic_queue_1;
2824 tech_profile::TrafficQueue* traffic_queue_2;
2825 tech_profile::DiscardConfig* discard_config_1;
2826 tech_profile::DiscardConfig* discard_config_2;
2827 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2828 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2829
2830 virtual void SetUp() {
2831 traffic_queues = new tech_profile::TrafficQueues;
2832 traffic_queues->set_intf_id(0);
2833 traffic_queues->set_onu_id(1);
2834 traffic_queue_1 = traffic_queues->add_traffic_queues();
2835 traffic_queue_1->set_gemport_id(1024);
2836 traffic_queue_1->set_pbit_map("0b00000101");
2837 traffic_queue_1->set_aes_encryption(true);
2838 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2839 traffic_queue_1->set_priority(0);
2840 traffic_queue_1->set_weight(0);
2841 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2842 discard_config_1 = new tech_profile::DiscardConfig;
2843 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2844 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2845 tail_drop_discard_config_1->set_queue_size(8);
2846 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2847 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2848 }
2849
2850 virtual void TearDown() {
2851 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302852
2853 public:
2854 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
2855 gem_cfg_compltd_key k(0, gem_port_id);
2856 gem_cfg_complete_result res;
2857 res.pon_intf_id = 0;
2858 res.gem_port_id = gem_port_id;
2859 res.state = state;
2860 res.status = status;
2861
2862 uint32_t gem_cfg_key_check_counter = 1;
2863 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
2864 while(true) {
2865 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2866 it = gem_cfg_compltd_map.find(k);
2867
2868 if (it != gem_cfg_compltd_map.end()) {
2869 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2870 break;
2871 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
2872 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2873
2874 // We need to wait for some time to allow the Gem Cfg Request to be triggered
2875 // before we push the result.
2876 bcmos_usleep(6000);
2877 } else {
2878 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
2879 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2880 return 0;
2881 }
2882 gem_cfg_key_check_counter++;
2883 }
2884
2885 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2886 if (it->second) {
2887 it->second->push(res);
2888 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
2889 }
2890 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2891 return 0;
2892 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002893};
2894
2895// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2896TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002897 traffic_queues->set_uni_id(0);
2898 traffic_queues->set_port_no(16);
2899 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2900
2901 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2902 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2903
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302904 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2905 future<int> push_gem_cfg_complt = \
2906 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2907 Status status = future_res.get();
2908 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002909 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2910
2911 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2912 status = CreateTrafficQueues_(traffic_queues);
2913 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2914}
2915
2916// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2917TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2918 traffic_queues->set_uni_id(1);
2919 traffic_queues->set_port_no(32);
2920 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2921
2922 traffic_queue_2 = traffic_queues->add_traffic_queues();
2923 traffic_queue_2->set_gemport_id(1025);
2924 traffic_queue_2->set_pbit_map("0b00001010");
2925 traffic_queue_2->set_aes_encryption(true);
2926 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2927 traffic_queue_2->set_priority(1);
2928 traffic_queue_2->set_weight(0);
2929 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2930 discard_config_2 = new tech_profile::DiscardConfig;
2931 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2932 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2933 tail_drop_discard_config_2->set_queue_size(8);
2934 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2935 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2936 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2937
2938 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2939 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2940
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302941 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2942 future<int> push_gem_cfg_complt = \
2943 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2944 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2945 push_gem_cfg_complt = \
2946 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2947 Status status = future_res.get();
2948 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002949 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2950}
2951
2952// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2953TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2954 traffic_queues->set_uni_id(2);
2955 traffic_queues->set_port_no(16);
2956 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2957
2958 traffic_queue_2 = traffic_queues->add_traffic_queues();
2959 traffic_queue_2->set_gemport_id(1025);
2960 traffic_queue_2->set_pbit_map("0b10001010");
2961 traffic_queue_2->set_aes_encryption(true);
2962 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2963 traffic_queue_2->set_priority(1);
2964 traffic_queue_2->set_weight(0);
2965 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2966 discard_config_2 = new tech_profile::DiscardConfig;
2967 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2968 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2969 tail_drop_discard_config_2->set_queue_size(8);
2970 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2971 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2972 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2973
2974 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2975 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2976
2977 Status status = CreateTrafficQueues_(traffic_queues);
2978 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2979}
2980
2981// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2982TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2983 traffic_queues->set_uni_id(3);
2984 traffic_queues->set_port_no(16);
2985 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2986
2987 traffic_queue_2 = traffic_queues->add_traffic_queues();
2988 traffic_queue_2->set_gemport_id(1025);
2989 traffic_queue_2->set_pbit_map("0b00001010");
2990 traffic_queue_2->set_aes_encryption(true);
2991 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2992 traffic_queue_2->set_priority(1);
2993 traffic_queue_2->set_weight(0);
2994 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2995 discard_config_2 = new tech_profile::DiscardConfig;
2996 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2997 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2998 tail_drop_discard_config_2->set_queue_size(8);
2999 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
3000 traffic_queue_2->set_allocated_discard_config(discard_config_2);
3001 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
3002
3003 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3004 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3005
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303006 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
3007 future<int> push_gem_cfg_complt = \
3008 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
3009 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3010 push_gem_cfg_complt = \
3011 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
3012 Status status = future_res.get();
3013 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003014 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3015}
3016
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303017// Test 5 - CreateTrafficQueues-Downstream PRIORITY_TO_QUEUE TM QMP Max count reached case
3018TEST_F(TestCreateTrafficQueues, CreateDownstreamPriorityQueueReachedMaxTMQMPCount) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003019 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
3020 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
3021 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
3022
3023 traffic_queue_2 = traffic_queues->add_traffic_queues();
3024 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
3025 traffic_queues->set_uni_id(uni_ids[i]);
3026 traffic_queues->set_port_no(port_nos[i]);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303027 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003028
3029 traffic_queue_2->set_gemport_id(1025);
3030 traffic_queue_2->set_pbit_map(pbit_maps[i]);
3031 traffic_queue_2->set_aes_encryption(true);
3032 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
3033 traffic_queue_2->set_priority(1);
3034 traffic_queue_2->set_weight(0);
3035 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
3036 discard_config_2 = new tech_profile::DiscardConfig;
3037 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
3038 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
3039 tail_drop_discard_config_2->set_queue_size(8);
3040 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
3041 traffic_queue_2->set_allocated_discard_config(discard_config_2);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303042 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003043
3044 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3045 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3046
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303047 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
3048 future<int> push_gem_cfg_complt = \
3049 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
3050 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3051 push_gem_cfg_complt = \
3052 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
3053 Status status = future_res.get();
3054 int res = push_gem_cfg_complt.get();
3055
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003056 if(i==16)
3057 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3058 else
3059 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3060 }
3061}
3062
3063// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
3064TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
3065 traffic_queues->set_uni_id(0);
3066 traffic_queues->set_port_no(16);
3067 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3068
3069 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3070 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3071
3072 Status status = CreateTrafficQueues_(traffic_queues);
3073 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3074}
3075
3076////////////////////////////////////////////////////////////////////////////
3077// For testing RemoveTrafficQueues functionality
3078////////////////////////////////////////////////////////////////////////////
3079
3080class TestRemoveTrafficQueues : public Test {
3081 protected:
3082 NiceMock<BalMocker> balMock;
3083 tech_profile::TrafficQueues* traffic_queues;
3084 tech_profile::TrafficQueue* traffic_queue_1;
3085 tech_profile::TrafficQueue* traffic_queue_2;
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303086 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003087
3088 virtual void SetUp() {
3089 traffic_queues = new tech_profile::TrafficQueues;
3090 traffic_queues->set_intf_id(0);
3091 traffic_queues->set_onu_id(1);
3092 traffic_queue_1 = traffic_queues->add_traffic_queues();
3093 traffic_queue_1->set_gemport_id(1024);
3094 traffic_queue_1->set_priority(0);
3095 }
3096
3097 virtual void TearDown() {
3098 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303099
3100 public:
3101 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
3102 gem_cfg_compltd_key k(0, gem_port_id);
3103 gem_cfg_complete_result res;
3104 res.pon_intf_id = 0;
3105 res.gem_port_id = gem_port_id;
3106 res.state = state;
3107 res.status = status;
3108
3109 uint32_t gem_cfg_key_check_counter = 1;
3110 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
3111 while(true) {
3112 bcmos_fastlock_lock(&gem_cfg_wait_lock);
3113 it = gem_cfg_compltd_map.find(k);
3114
3115 if (it != gem_cfg_compltd_map.end()) {
3116 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3117 break;
3118 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
3119 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3120
3121 // We need to wait for some time to allow the Gem Cfg Request to be triggered
3122 // before we push the result.
3123 bcmos_usleep(6000);
3124 } else {
3125 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
3126 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3127 return 0;
3128 }
3129 gem_cfg_key_check_counter++;
3130 }
3131
3132 bcmos_fastlock_lock(&gem_cfg_wait_lock);
3133 if (it->second) {
3134 it->second->push(res);
3135 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
3136 }
3137 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
3138 return 0;
3139 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003140};
3141
3142// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
3143TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003144 traffic_queues->set_uni_id(0);
3145 traffic_queues->set_port_no(16);
3146 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3147
3148 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3149 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3150
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303151 bcmolt_pon_interface_key pon_key;
3152 bcmolt_pon_interface_cfg pon_cfg;
3153 pon_key.pon_ni = pon_id;
3154 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3155 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3156 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3157 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05303158 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303159
3160 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3161 future<int> push_gem_cfg_complt = \
3162 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3163
3164 Status status = future_res.get();
3165 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003166 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3167
3168 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3169 status = RemoveTrafficQueues_(traffic_queues);
3170 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3171}
3172
3173// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
3174TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003175 traffic_queues->set_uni_id(0);
3176 traffic_queues->set_port_no(16);
3177 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3178
3179 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
3180 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3181
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303182 Status status = RemoveTrafficQueues_(traffic_queues);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003183 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3184}
3185
3186// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
3187TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
3188 //Remove scheduler so that is_tm_sched_id_present api call will return false
3189 tech_profile::TrafficSchedulers* traffic_scheds;
3190 tech_profile::TrafficScheduler* traffic_sched;
3191 traffic_scheds = new tech_profile::TrafficSchedulers;
3192 traffic_scheds->set_intf_id(0);
3193 traffic_scheds->set_onu_id(1);
3194 traffic_scheds->set_uni_id(0);
3195 traffic_scheds->set_port_no(16);
3196 traffic_sched = traffic_scheds->add_traffic_scheds();
3197 traffic_sched->set_alloc_id(1024);
3198 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
3199
3200 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3201 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3202 RemoveTrafficSchedulers_(traffic_scheds);
3203
3204 traffic_queues->set_uni_id(0);
3205 traffic_queues->set_port_no(16);
3206 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
3207
3208 Status status = RemoveTrafficQueues_(traffic_queues);
3209 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3210}
3211
3212/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
3213as it is getting referred by some other queues case */
3214TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
3215 traffic_queues->set_uni_id(3);
3216 traffic_queues->set_port_no(16);
3217 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
3218 traffic_queue_2 = traffic_queues->add_traffic_queues();
3219 traffic_queue_2->set_gemport_id(1025);
3220 traffic_queue_2->set_priority(1);
3221 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
3222
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)));
3231
3232 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3233 future<int> push_gem_cfg_complt = \
3234 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3235 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3236 push_gem_cfg_complt = \
3237 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3238
3239 Status status = future_res.get();
3240 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003241 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3242}
3243
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303244/* Test 5 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, removing TM QMP as it
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003245is not getting referred by any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303246TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueRemovingTMQMP) {
3247 traffic_queues->set_uni_id(5);
3248 traffic_queues->set_port_no(80);
3249 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003250 traffic_queue_2 = traffic_queues->add_traffic_queues();
3251 traffic_queue_2->set_gemport_id(1025);
3252 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303253 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
3254
3255 bcmolt_pon_interface_key pon_key;
3256 bcmolt_pon_interface_cfg pon_cfg;
3257 pon_key.pon_ni = pon_id;
3258 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3259 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3260 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3261 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3262 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003263
3264 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
3265 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
3266
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303267 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3268 future<int> push_gem_cfg_complt = \
3269 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3270 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3271 push_gem_cfg_complt = \
3272 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3273
3274 Status status = future_res.get();
3275 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003276 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3277}
3278
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303279/* Test 6 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, error while removing TM QMP
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003280having no reference to any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303281TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueErrorRemovingTMQMP) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003282 traffic_queues->set_uni_id(4);
3283 traffic_queues->set_port_no(64);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303284 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003285 traffic_queue_2 = traffic_queues->add_traffic_queues();
3286 traffic_queue_2->set_gemport_id(1025);
3287 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303288 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003289
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303290 bcmolt_pon_interface_key pon_key;
3291 bcmolt_pon_interface_cfg pon_cfg;
3292 pon_key.pon_ni = pon_id;
3293 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3294 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3295 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3296 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3297 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003298
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303299 bcmos_errno olt_cfg_clear_res_success = BCM_ERR_OK;
3300 bcmos_errno olt_cfg_clear_res_failure = BCM_ERR_INTERNAL;
3301 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _))
3302 .WillOnce(Return(olt_cfg_clear_res_success))
3303 .WillOnce(Return(olt_cfg_clear_res_success))
3304 .WillOnce(Return(olt_cfg_clear_res_success))
3305 .WillOnce(Return(olt_cfg_clear_res_success))
3306 .WillRepeatedly(Return(olt_cfg_clear_res_failure));
3307
3308 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3309 future<int> push_gem_cfg_complt = \
3310 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3311 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3312 push_gem_cfg_complt = \
3313 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3314
3315 Status status = future_res.get();
3316 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003317 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3318}
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003319
3320////////////////////////////////////////////////////////////////////////////
3321// For testing OnuItuPonAlarmSet functionality
3322////////////////////////////////////////////////////////////////////////////
3323
3324class TestOnuItuPonAlarmSet : public Test {
3325 protected:
3326 bcmolt_pon_ni pon_ni = 0;
3327 bcmolt_onu_id onu_id = 1;
3328
kesavandc1f2db92020-08-31 15:32:06 +05303329 config::OnuItuPonAlarm *onu_itu_pon_alarm_rt;
3330 config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config;
3331 config::OnuItuPonAlarm::SoakTime *soak_time_rt;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003332
kesavandc1f2db92020-08-31 15:32:06 +05303333 config::OnuItuPonAlarm *onu_itu_pon_alarm_rr;
3334 config::OnuItuPonAlarm::RateRangeConfig *rate_range_config;
3335 config::OnuItuPonAlarm::SoakTime *soak_time_rr;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003336
kesavandc1f2db92020-08-31 15:32:06 +05303337 config::OnuItuPonAlarm *onu_itu_pon_alarm_tc;
3338 config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config;
3339 config::OnuItuPonAlarm::SoakTime *soak_time_tc;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003340
3341 NiceMock<BalMocker> balMock;
3342
3343 virtual void SetUp() {
kesavandc1f2db92020-08-31 15:32:06 +05303344 onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm;
3345 rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig;
3346 soak_time_rt = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003347 onu_itu_pon_alarm_rt->set_pon_ni(0);
3348 onu_itu_pon_alarm_rt->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303349 onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3350 onu_itu_pon_alarm_rt->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003351 rate_threshold_config->set_rate_threshold_rising(1);
3352 rate_threshold_config->set_rate_threshold_falling(4);
3353 soak_time_rt->set_active_soak_time(2);
3354 soak_time_rt->set_clear_soak_time(2);
3355 rate_threshold_config->set_allocated_soak_time(soak_time_rt);
3356 onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config);
3357
kesavandc1f2db92020-08-31 15:32:06 +05303358 onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm;
3359 rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig;
3360 soak_time_rr = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003361 onu_itu_pon_alarm_rr->set_pon_ni(0);
3362 onu_itu_pon_alarm_rr->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303363 onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3364 onu_itu_pon_alarm_rr->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003365 rate_range_config->set_rate_range_lower(1);
3366 rate_range_config->set_rate_range_upper(4);
3367 soak_time_rr->set_active_soak_time(2);
3368 soak_time_rr->set_clear_soak_time(2);
3369 rate_range_config->set_allocated_soak_time(soak_time_rr);
3370 onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config);
3371
kesavandc1f2db92020-08-31 15:32:06 +05303372 onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm;
3373 value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig;
3374 soak_time_tc = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003375 onu_itu_pon_alarm_tc->set_pon_ni(0);
3376 onu_itu_pon_alarm_tc->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303377 onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3378 onu_itu_pon_alarm_tc->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003379 value_threshold_config->set_threshold_limit(6);
3380 soak_time_tc->set_active_soak_time(2);
3381 soak_time_tc->set_clear_soak_time(2);
3382 value_threshold_config->set_allocated_soak_time(soak_time_tc);
3383 onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config);
3384 }
3385
3386 virtual void TearDown() {
3387 }
3388};
3389
3390// Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case
3391// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3392// the configured threshold boundary.
3393TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) {
3394 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3395 bcmolt_onu_key key = {};
3396 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3397 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3398 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3399 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3400 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3401
3402 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3403
3404 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3405 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3406}
3407
3408// Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case
3409// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3410// the configured threshold boundary.
3411TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) {
3412 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3413 bcmolt_onu_key key = {};
3414 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3415 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3416 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3417 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3418 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3419
3420 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3421
3422 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3423 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3424}
3425
3426// Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case
3427// rate_range: The alarm is triggered if the stats delta value between samples deviates
3428// from the configured range.
3429TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) {
3430 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3431 bcmolt_onu_key key = {};
3432 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3433 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3434 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100;
3435 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50;
3436 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3437
3438 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3439
3440 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3441 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3442}
3443
3444// Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case
3445// rate_range: The alarm is triggered if the stats delta value between samples deviates
3446// from the configured range.
3447TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) {
3448 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3449 bcmolt_onu_key key = {};
3450 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3451 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3452 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50;
3453 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100;
3454 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3455
3456 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3457
3458 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3459 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3460}
3461
3462// Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case
3463// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3464// level. The alarm is cleared when the host read the stats.
3465TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) {
3466 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3467 bcmolt_onu_key key = {};
3468 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3469 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3470 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100;
3471 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3472
3473 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3474
3475 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3476 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3477}
3478
3479// Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case
3480// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3481// level. The alarm is cleared when the host read the stats.
3482TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) {
3483 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3484 bcmolt_onu_key key = {};
3485 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3486 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3487 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1;
3488 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3489
3490 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3491
3492 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3493 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3494}
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003495
3496////////////////////////////////////////////////////////////////////////////
3497// For testing DeleteGroup functionality
3498////////////////////////////////////////////////////////////////////////////
3499
3500class TestDeleteGroup : public Test {
3501 protected:
3502 uint32_t group_id = 1;
3503 NiceMock<BalMocker> balMock;
3504
3505 virtual void SetUp() {
3506 }
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003507};
3508
3509// Test 1 - DeleteGroup success case
3510TEST_F(TestDeleteGroup, DeleteGroupSuccess) {
3511 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3512 bcmos_errno group_cfg_clear_res = BCM_ERR_OK;
3513 bcmolt_group_cfg grp_cfg_out;
3514 bcmolt_group_key grp_key = {};
3515
3516 grp_key.id = group_id;
3517 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3518
3519 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3520 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3521 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3522 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3523 return group_cfg_get_res;
3524 }
3525 ));
3526
3527 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3528
3529 Status status = DeleteGroup_(group_id);
3530 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3531}
3532
3533// Test 2 - DeleteGroup failure case: Group does not exist
3534TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) {
3535 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3536 bcmolt_group_cfg grp_cfg_out;
3537 bcmolt_group_key grp_key = {};
3538
3539 grp_key.id = group_id;
3540 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3541
3542 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3543 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3544 grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED;
3545 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3546 return group_cfg_get_res;
3547 }
3548 ));
3549
3550 Status status = DeleteGroup_(group_id);
3551 ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND );
3552}
3553
3554// Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.)
3555TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) {
3556 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3557 bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL;
3558 bcmolt_group_cfg grp_cfg_out;
3559 bcmolt_group_key grp_key = {};
3560
3561 grp_key.id = group_id;
3562 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3563
3564 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3565 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3566 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3567 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3568 return group_cfg_get_res;
3569 }
3570 ));
3571
3572 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3573
3574 Status status = DeleteGroup_(group_id);
3575 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3576}
Jason Huang1d9cfce2020-05-20 22:58:47 +08003577
3578////////////////////////////////////////////////////////////////////////////
3579// For testing OnuLogicalDistanceZero functionality
3580////////////////////////////////////////////////////////////////////////////
3581class TestOnuLogicalDistanceZero : public Test {
3582 protected:
3583 NiceMock<BalMocker> balMock;
3584 bcmolt_pon_ni pon_ni = 0;
3585 openolt::OnuLogicalDistance *onu_logical_distance_zero;
3586
3587 virtual void SetUp() {
3588 onu_logical_distance_zero = new openolt::OnuLogicalDistance;
3589 onu_logical_distance_zero->set_intf_id(pon_ni);
3590 }
3591 virtual void TearDown() {
3592 }
3593};
3594
3595//
3596// Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case
3597//
3598TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) {
3599 bcmolt_pon_distance pon_distance = {};
3600 bcmolt_pon_interface_cfg pon_cfg;
3601 bcmolt_pon_interface_key key = {};
3602
3603 key.pon_ni = pon_ni;
3604 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3605 state.activate();
3606 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3607
3608 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3609 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3610
3611 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3612 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3613}
3614
3615// Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case
3616// The PON state is not ready for failure case
3617//
3618TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) {
3619 bcmolt_pon_distance pon_distance = {};
3620 bcmolt_pon_interface_cfg pon_cfg;
3621 bcmolt_pon_interface_key key = {};
3622
3623 key.pon_ni = pon_ni;
3624 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3625 state.deactivate();
3626 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
3627
3628 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3629 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3630}
3631
3632class TestOnuLogicalDistance : public Test {
3633 protected:
3634 NiceMock<BalMocker> balMock;
3635 bcmolt_pon_ni pon_ni = 0;
3636 bcmolt_onu_id onu_id = 1;
3637 openolt::OnuLogicalDistance *onu_logical_distance;
3638
3639 virtual void SetUp() {
3640 onu_logical_distance = new openolt::OnuLogicalDistance;
3641 onu_logical_distance->set_intf_id(pon_ni);
3642 onu_logical_distance->set_onu_id(onu_id);
3643 }
3644 virtual void TearDown() {
3645 }
3646};
3647
3648//
3649// Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case
3650//
3651TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) {
3652 bcmolt_pon_distance pon_distance = {};
3653 bcmolt_pon_interface_cfg pon_cfg;
3654 bcmolt_pon_interface_key key = {};
3655 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3656
3657 key.pon_ni = pon_ni;
3658 state.activate();
3659 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3660
3661 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3662 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3663
3664 bcmolt_onu_cfg onu_cfg;
3665 bcmolt_onu_key onu_key = {};
3666 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3667
3668 onu_key.pon_ni = pon_ni;
3669 onu_key.onu_id = onu_id;
3670 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3671 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
3672
3673 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3674 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3675
3676 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3677 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3678}
3679
3680// Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case
3681// The failure case is for retrieving ONU ranging time
3682//
3683TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) {
3684 bcmolt_pon_distance pon_distance = {};
3685 bcmolt_pon_interface_cfg pon_cfg;
3686 bcmolt_pon_interface_key key = {};
3687 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3688
3689 key.pon_ni = pon_ni;
3690 state.activate();
3691 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3692
3693 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3694 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3695
3696 bcmolt_onu_cfg onu_cfg;
3697 bcmolt_onu_key onu_key = {};
3698 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
3699
3700 onu_key.pon_ni = pon_ni;
3701 onu_key.onu_id = onu_id;
3702 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3703
3704 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3705 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3706
3707 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3708 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3709}
3710
3711// Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case
3712// The failure case is for ONU is not yet activated
3713//
3714TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) {
3715 bcmolt_pon_distance pon_distance = {};
3716 bcmolt_pon_interface_cfg pon_cfg;
3717 bcmolt_pon_interface_key key = {};
3718 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3719
3720 key.pon_ni = pon_ni;
3721 state.activate();
3722 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3723
3724 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3725 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3726
3727 bcmolt_onu_cfg onu_cfg;
3728 bcmolt_onu_key onu_key = {};
3729 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3730
3731 onu_key.pon_ni = pon_ni;
3732 onu_key.onu_id = onu_id;
3733 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3734
3735 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3736 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3737
3738 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
3739 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3740 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3741}
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -07003742
3743////////////////////////////////////////////////////////////////////////////
3744// For testing Secure Server functionality
3745////////////////////////////////////////////////////////////////////////////
3746
3747class TestSecureServer : public Test {
3748 protected:
3749 virtual void SetUp() {}
3750 virtual void TearDown() {}
3751};
3752
3753TEST_F(TestSecureServer, StartInsecureServer) {
3754 // const to prevent the following warning:
3755 // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
3756 const char *args[] = {"./openolt"};
3757 int argc = sizeof(args) / sizeof(args[0]);
3758 char **argv = const_cast<char**>(args);
3759
3760 bool ok = RunServer(argc, argv);
3761
3762 ASSERT_TRUE(ok);
3763
3764 OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n");
3765}
3766
3767TEST_F(TestSecureServer, StartWithInvalidTLSOption) {
3768 const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3769 int argc = sizeof(args) / sizeof(args[0]);
3770 char **argv = const_cast<char**>(args);
3771
3772 bool ok = RunServer(argc, argv);
3773
3774 ASSERT_FALSE(ok);
3775
3776 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n");
3777}
3778
3779TEST_F(TestSecureServer, CertificatesAreMissing) {
3780 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3781 int argc = sizeof(args) / sizeof(args[0]);
3782 char **argv = const_cast<char**>(args);
3783 const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'";
3784
3785 int res = std::system(cmd.c_str());
3786 if (res == 0) {
3787 std::cout << "directory ./keystore is deleted\n";
3788 } else {
3789 std::cout << "directory ./keystore is not existing\n";
3790 }
3791
3792 bool ok = RunServer(argc, argv);
3793
3794 ASSERT_FALSE(ok);
3795
3796 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n");
3797}
3798
3799TEST_F(TestSecureServer, StartWithValidTLSOption) {
3800 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3801 int argc = sizeof(args) / sizeof(args[0]);
3802 char **argv = const_cast<char**>(args);
3803 const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore";
3804 const std::string cmd_2 = "exec rm -rf './keystore'";
3805
3806 int res = std::system(cmd_1.c_str());
3807 if (res == 0) {
3808 std::cout << "directory ./keystore is copied from ./keystore-test\n";
3809
3810 bool ok = RunServer(argc, argv);
3811 ASSERT_TRUE(ok);
3812
3813 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n");
3814
3815 res = std::system(cmd_2.c_str());
3816 if (res == 0) {
3817 std::cout << "directory ./keystore is deleted\n";
3818 } else {
3819 std::cerr << "directory ./keystore could not be deleted\n";
3820 }
3821 } else {
3822 std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n';
3823 FAIL();
3824 }
3825}
Orhan Kupusogluec57af02021-05-12 12:38:17 +00003826
3827////////////////////////////////////////////////////////////////////////////
3828// For testing RxTx Power Read functionality
3829////////////////////////////////////////////////////////////////////////////
3830
3831class TestPowerRead : public Test {
3832 protected:
3833 virtual void SetUp() {
3834 std::array<char, 600> content = {};
3835 content.fill(0x00); // not required for 0x00
3836
3837 // for asfvolt16
3838 content[102] = 0x5D;
3839 content[103] = 0x38;
3840 content[104] = 0x1A;
3841 content[105] = 0xB5;
3842
3843 // for asgvolt64
3844 content[358] = 0x5C;
3845 content[359] = 0x82;
3846 content[360] = 0x04;
3847 content[361] = 0xBE;
3848
3849 std::ofstream test_file;
3850 test_file.open(file_name, std::ios::binary | std::ios::out);
3851 test_file.write(content.data(), content.size());
3852 test_file.close();
3853
3854 const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump;
3855
3856 int res = std::system(cmd.c_str());
3857 if (res == 0) {
3858 std::ifstream dump_file(hex_dump) ;
3859 std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() };
3860 std::cout << cmd << '\n';
3861 std::cout << hexdump << '\n';
3862 } else {
3863 std::cerr << "hexdump capture failed\n";
3864 }
3865 }
3866 virtual void TearDown() {
3867 std::remove(file_name.c_str());
3868 std::remove(hex_dump.c_str());
3869 }
3870
3871 const std::string file_name = "eeprom.bin";
3872 const std::string hex_dump = file_name + ".hexdump";
3873};
3874
3875TEST_F(TestPowerRead, TestAsfvolt16) {
3876 std::cout << "Test Power Reads on XGS-PON OLT:\n";
3877
3878 int port = 20;
3879 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3880
3881 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3882
3883 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3884
3885 port = 0;
3886 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3887
3888 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3889 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3890 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3891 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3892 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3893
3894 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3895
3896 ASSERT_TRUE(rxtx_power_raw.second);
3897
3898 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3899 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3900 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3901 << 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";
3902 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3903 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3904 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3905 << 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";
3906 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3907
3908 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3909 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256);
3910 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104);
3911 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3912 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20);
3913 ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837
3914 ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864
3915 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom");
3916}
3917
3918TEST_F(TestPowerRead, TestAsgvolt64) {
3919 std::cout << "Test Power Reads on GPON OLT:\n";
3920
3921 int port = 80;
3922 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3923
3924 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3925
3926 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3927
3928 port = 0;
3929 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3930
3931 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3932 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3933 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3934 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3935 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3936
3937 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3938
3939 ASSERT_TRUE(rxtx_power_raw.second);
3940
3941 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3942 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3943 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3944 << 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";
3945 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3946 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3947 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3948 << 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";
3949 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3950
3951 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3952 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600);
3953 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360);
3954 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3955 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74);
3956 ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214
3957 ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682
3958 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom");
3959}
Girish Gowdrab0337eb2022-03-25 16:44:21 -07003960
3961////////////////////////////////////////////////////////////////////////////
3962// For testing SFP eeprom read and decode capabilities
3963////////////////////////////////////////////////////////////////////////////
3964
3965class TestEEPROMReadDecode : public Test {
3966 protected:
3967 virtual void SetUp() {
3968 }
3969 virtual void TearDown() {
3970 }
3971
3972};
3973
3974// This test reads and decodes EEPROM data confirming to SFP8436 specification.
3975// The XFP used on ASFVOLT16 OLTs confirm to this specification.
3976TEST_F(TestEEPROMReadDecode, TestSFF8436Decode) {
3977 bool res;
3978 res = ponTrx.read_eeprom_data_for_sfp(0);
3979 ASSERT_TRUE(res);
3980 res = ponTrx.decode_eeprom_data(0);
3981 ASSERT_TRUE(res);
3982 trx_data* t = ponTrx.get_trx_data(0);
3983 ASSERT_NE(t, NULL);
3984 ASSERT_EQ(t->sfp_index, 0);
3985 ASSERT_STREQ(t->vendor_name.c_str(), "Hisense ");
3986 ASSERT_STREQ(t->vendor_part_no.c_str(), "LTH7226-PC+ ");
3987 ASSERT_STREQ(t->vendor_rev.c_str(), "01");
3988 ASSERT_EQ(t->p_data[0].wavelength, 1577);
3989
3990}
3991
3992TEST_F(TestEEPROMReadDecode, TestHexToAsciiSuccess) {
3993 std::string vn_ascii("SUPERXON LTD. ");
3994 std::string oui_ascii("");
3995 std::string pn_ascii("SOGP4321-PSGB ");
3996 std::string rev_ascii("10");
3997 pair<string, bool> res;
3998 unsigned char vn_hex[EEPROM_VENDOR_NAME_LENGTH] = {0x53, 0x55, 0x50, 0x45, 0x52, 0x58, 0x4F, 0x4E,
3999 0x20, 0x4C, 0x54, 0x44, 0x2E, 0x20, 0x20, 0x20};
4000 unsigned char oui_hex[EEPROM_VENDOR_OUI_LENGTH] = {0x00, 0x00, 0x00};
4001 unsigned char pn_hex[EEPROM_VENDOR_PART_NUMBER_LENGTH] = {0x53, 0x4F, 0x47, 0x50, 0x34, 0x33, 0x32, 0x31,
4002 0x2D, 0x50, 0x53, 0x47, 0x42, 0x20, 0x20, 0x20};
4003 unsigned char rev_hex[EEPROM_VENDOR_REVISION_LENGTH] = {0x31, 0x30};
4004 res = hex_to_ascii_string(vn_hex, EEPROM_VENDOR_NAME_LENGTH);
4005 ASSERT_TRUE(res.second);
4006 ASSERT_STREQ(res.first.c_str(), vn_ascii.c_str());
4007
4008 res = hex_to_ascii_string(oui_hex, EEPROM_VENDOR_OUI_LENGTH);
4009 ASSERT_TRUE(res.second);
4010 ASSERT_STREQ(res.first.c_str(), oui_ascii.c_str());
4011
4012 res = hex_to_ascii_string(pn_hex, EEPROM_VENDOR_PART_NUMBER_LENGTH);
4013 ASSERT_TRUE(res.second);
4014 ASSERT_STREQ(res.first.c_str(), pn_ascii.c_str());
4015
4016 res = hex_to_ascii_string(rev_hex, EEPROM_VENDOR_REVISION_LENGTH);
4017 ASSERT_TRUE(res.second);
4018 ASSERT_STREQ(res.first.c_str(), rev_ascii.c_str());
4019
4020}
4021
4022TEST_F(TestEEPROMReadDecode, TestHexToUintSuccess) {
4023 uint32_t wl_uint = 1490;
4024 pair<uint32_t, bool> res;
4025 unsigned char vn_hex[EEPROM_DOWNSTREAM_WAVELENGTH_LENGTH] = {0x05, 0xD2};
4026 res = hex_to_uinteger(vn_hex, EEPROM_DOWNSTREAM_WAVELENGTH_LENGTH);
4027 ASSERT_TRUE(res.second);
4028 ASSERT_EQ(res.first, wl_uint);
4029}