blob: 58e7073ae679ddc111eaf147bf1e323267233e1e [file] [log] [blame]
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "gtest/gtest.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050017#include "Queue.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000018#include "bal_mocker.h"
19#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053020#include "core_data.h"
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070021#include "server.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050022#include <future>
Orhan Kupusogluec57af02021-05-12 12:38:17 +000023#include <fstream>
24#include "trx_eeprom_reader.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000025using namespace testing;
26using namespace std;
27
28class TestOltEnable : public Test {
29 protected:
30 virtual void SetUp() {
31 }
32
33 virtual void TearDown() {
34 // Code here will be called immediately after each test
35 // (right before the destructor).
36 }
37};
38
39// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
40// bcmolt_cfg_get__bal_state_stub.
41ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
42
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050043// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
44// bcmolt_cfg_get__onu_state_stub.
45ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
46
47// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
48// bcmolt_cfg_get__tm_sched_stub.
49ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
50
51// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
52// bcmolt_cfg_get__pon_intf_stub.
53ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
54
55// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
56// bcmolt_cfg_get__nni_intf_stub.
57ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000058
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050059// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
60// bcmolt_cfg_get__flow_stub.
61ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
62
Amit Ghoshfcad4d32019-11-13 10:24:55 +000063// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
64MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050065MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
66MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
67MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050069MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000070
Amit Ghoshfcad4d32019-11-13 10:24:55 +000071// Test Fixture for OltEnable
72
73// Test 1: OltEnableSuccess case
74TEST_F(TestOltEnable, OltEnableSuccess){
75 // NiceMock is used to suppress 'WillByDefault' return errors.
76 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
77 NiceMock<BalMocker> balMock;
78 bcmos_errno host_init_res = BCM_ERR_OK;
79 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
80 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
81 bcmos_errno olt_oper_res = BCM_ERR_OK;
82
83 bcmolt_olt_cfg olt_cfg = { };
84 bcmolt_olt_key olt_key = { };
85 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
86 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
87
88 Status olt_enable_res;
89
90 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
91 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
92 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
93 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
94 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
95 .WillRepeatedly(Return(bal_cfg_get_res));
96 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
97
98 olt_enable_res = Enable_(1, NULL);
99 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
100}
101
102// Test 2: OltEnableFail_host_init_fail
103TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
104 // NiceMock is used to suppress 'WillByDefault' return errors.
105 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
106 NiceMock<BalMocker> balMock;
107 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
108
109 Status olt_enable_res;
110
111 // Ensure that the state of the OLT is in deactivated to start with..
112 state.deactivate();
113
114 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
115
116 olt_enable_res = Enable_(1, NULL);
117 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
118}
119
120// Test 3: OltEnableSuccess_PON_Device_Connected
121TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
122
123 // NiceMock is used to suppress 'WillByDefault' return errors.
124 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
125 NiceMock<BalMocker> balMock;
126 bcmos_errno host_init_res = BCM_ERR_OK;
127 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
128 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
129 bcmos_errno olt_oper_res = BCM_ERR_OK;
130
131 bcmolt_olt_cfg olt_cfg = { };
132 bcmolt_olt_key olt_key = { };
133 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
134 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
135
136 Status olt_enable_res;
137
138 // Ensure that the state of the OLT is in deactivated to start with..
139 state.deactivate();
140
141 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
142 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
143 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
144 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
145 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
146 .WillRepeatedly(Return(bal_cfg_get_res));
147
148 olt_enable_res = Enable_(1, NULL);
149 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
150
151}
152
153// Test 4: OltEnableFail_All_PON_Enable_Fail
154TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
155
156 // NiceMock is used to suppress 'WillByDefault' return errors.
157 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
158 NiceMock<BalMocker> balMock;
159 bcmos_errno host_init_res = BCM_ERR_OK;
160 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
161 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
162 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
163
164 bcmolt_olt_cfg olt_cfg = { };
165 bcmolt_olt_key olt_key = { };
166 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
167 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
168
169 Status olt_enable_res;
170
171 // Ensure that the state of the OLT is in deactivated to start with..
172 state.deactivate();
173
174 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
175 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
176 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
177 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
178 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
179 .WillRepeatedly(Return(bal_cfg_get_res));
180 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
181
182 olt_enable_res = Enable_(1, NULL);
183
184 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
185}
186
187// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
188TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
189
190 // NiceMock is used to suppress 'WillByDefault' return errors.
191 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
192 NiceMock<BalMocker> balMock;
193 bcmos_errno host_init_res = BCM_ERR_OK;
194 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
195 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
196 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
197 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
198
199 bcmolt_olt_cfg olt_cfg = { };
200 bcmolt_olt_key olt_key = { };
201 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
202 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
203
204 Status olt_enable_res;
205
206 // Ensure that the state of the OLT is in deactivated to start with..
207 state.deactivate();
208
209 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
210 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
211 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
212 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
213 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
214 .WillRepeatedly(Return(bal_cfg_get_res));
215 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
216 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
217 .WillOnce(Return(olt_oper_res_fail))
218 .WillRepeatedly(Return(olt_oper_res_success));
219 olt_enable_res = Enable_(1, NULL);
220
221 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
222}
223
224////////////////////////////////////////////////////////////////////////
225// For testing Enable/Disable functionality
226////////////////////////////////////////////////////////////////////////
227
Girish Gowdraddf9a162020-01-27 12:56:27 +0530228int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000229
230// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
231MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
232
233class TestOltDisableReenable : public Test {
234 protected:
235 virtual void SetUp() {
236 NiceMock<BalMocker> balMock;
237 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
238
239 bcmolt_olt_cfg olt_cfg = { };
240 bcmolt_olt_key olt_key = { };
241
242 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
243
Girish Gowdraddf9a162020-01-27 12:56:27 +0530244 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000245 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
246 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
247
248 ProbeDeviceCapabilities_();
249
250 }
251
252 virtual void TearDown() {
253 // Code here will be called immediately after each test
254 // (right before the destructor).
255 }
256};
257
258
259// Test Fixture for OltDisable
260
261// Test 1: OltDisableSuccess case
262TEST_F(TestOltDisableReenable, OltDisableSuccess){
263 // NiceMock is used to suppress 'WillByDefault' return errors.
264 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
265 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500266 bcmos_errno olt_oper_res = BCM_ERR_OK;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700267 bcmos_errno olt_get_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000268
269 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500270 state.deactivate();
271 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Girish Gowdrae1db2952021-05-04 00:16:54 -0700272 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_get_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000273 olt_disable_res = Disable_();
274 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
275
276}
277
278// Test 2: OltDisableAllPonFailed case
279TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
280 // NiceMock is used to suppress 'WillByDefault' return errors.
281 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
282 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500283 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700284 bcmos_errno pon_cfg_get_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000285
286 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500287 state.deactivate();
Girish Gowdrae1db2952021-05-04 00:16:54 -0700288 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(pon_cfg_get_res));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500289 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000290 olt_disable_res = Disable_();
291 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
292}
293
294
295// Test Fixture for OltReenable
296
297// Test 1: OltReenableSuccess case
298TEST_F(TestOltDisableReenable, OltReenableSuccess){
299 // NiceMock is used to suppress 'WillByDefault' return errors.
300 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
301 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500302 uint32_t pon_id = 0;
303 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
304 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000305 Status olt_reenable_res;
306
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500307 bcmolt_pon_interface_key pon_key;
308 bcmolt_pon_interface_cfg pon_cfg;
309 pon_key.pon_ni = pon_id;
310 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
311 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
312
313 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530314 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500315 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
316
317 bcmolt_tm_sched_cfg tm_sched_cfg;
318 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
319 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
320 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
321
322 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530323 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500324 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000325
326 olt_reenable_res = Reenable_();
327 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
328
329}
330
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500331// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000332TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
333 // NiceMock is used to suppress 'WillByDefault' return errors.
334 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
335 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500336 uint32_t pon_id = 0;
337 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000338 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000339 Status olt_reenable_res;
340
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500341 bcmolt_pon_interface_key pon_key;
342 bcmolt_pon_interface_cfg pon_cfg;
343 pon_key.pon_ni = pon_id;
344 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
345 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
346
347 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530348 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500349 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000350 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530351 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000352 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500353
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000354 olt_reenable_res = Reenable_();
355 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
356}
357
358////////////////////////////////////////////////////////////////////////////
359// For testing ProbeDeviceCapabilities functionality
360////////////////////////////////////////////////////////////////////////////
361class TestProbeDevCapabilities : public Test {
362 protected:
363 NiceMock<BalMocker> balMock;
364 bcmos_errno olt_res_success = BCM_ERR_OK;
365 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
366 bcmos_errno dev_res_success = BCM_ERR_OK;
367 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
368
369 virtual void SetUp() {
370 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
371
372 bcmolt_olt_cfg olt_cfg = { };
373 bcmolt_olt_key olt_key = { };
374
375 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
376
Girish Gowdraddf9a162020-01-27 12:56:27 +0530377 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000378 }
379
380 virtual void TearDown() {
381 }
382};
383
384// Test 1 - If querying the OLT fails, the method must return error
385TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
386
387 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
388 .WillOnce(Return(olt_res_fail));
389
390 Status query_status = ProbeDeviceCapabilities_();
391 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
392}
393
394// Test 2 - If all devices are queried successfully, the method must return Status::OK
395TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
396
397 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
398 .WillOnce(Return(olt_res_success));
399
400 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
401 .WillRepeatedly(Return(dev_res_success));
402
403 Status query_status = ProbeDeviceCapabilities_();
404
405 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
406}
407
408// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
409TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
410
411 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
412 .WillOnce(Return(olt_res_success));
413
414 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
415 .WillRepeatedly(Return(dev_res_fail));
416
417 Status query_status = ProbeDeviceCapabilities_();
418
419 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
420}
421
422// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
423TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
424
425 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
426 .WillOnce(Return(olt_res_success));
427
428 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
429 .WillOnce(Return(olt_res_success))
430 .WillRepeatedly(Return(dev_res_fail));
431
432 Status query_status = ProbeDeviceCapabilities_();
433
434 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
435}
436
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500437////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500438// For testing EnablePonIf functionality
439////////////////////////////////////////////////////////////////////////////
440
441class TestEnablePonIf : public Test {
442 protected:
443 uint32_t pon_id = 0;
444 NiceMock<BalMocker> balMock;
445
446 virtual void SetUp() {
447 }
448
449 virtual void TearDown() {
450 }
451};
452
453// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
454TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
455 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
456 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
457 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
458 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
459
460 bcmolt_pon_interface_key pon_key;
461 bcmolt_pon_interface_cfg pon_cfg;
462 pon_key.pon_ni = pon_id;
463 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
464 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
465 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
466 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
467
468 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
469 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
470
471 bcmolt_tm_sched_cfg tm_sched_cfg;
472 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
473 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
474 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
475 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
476 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
477
478 Status status = EnablePonIf_(pon_id);
479 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
480}
481
482// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
483TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
484 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
485 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
486 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
487 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
488
489 bcmolt_pon_interface_key pon_key;
490 bcmolt_pon_interface_cfg pon_cfg;
491 pon_key.pon_ni = pon_id;
492 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
493 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
494 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
495 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
496
497 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
498 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
499
500 bcmolt_tm_sched_cfg tm_sched_cfg;
501 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
502 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
503 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
504 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
505 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
506
507 Status status = EnablePonIf_(pon_id);
508 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
509}
510
511// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
512TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
513 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
514 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
515 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
516 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
517 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
518
519 bcmolt_pon_interface_key pon_key;
520 bcmolt_pon_interface_cfg pon_cfg;
521 pon_key.pon_ni = pon_id;
522 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
523 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
524 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
525 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
526
527 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
528 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
529 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
530
531 bcmolt_tm_sched_cfg tm_sched_cfg;
532 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
533 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
534 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
535 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
536 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
537
538 Status status = EnablePonIf_(pon_id);
539 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
540}
541
542// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
543TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
544 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
545 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
546 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
547 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
548 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
549 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
550
551 bcmolt_pon_interface_key pon_key;
552 bcmolt_pon_interface_cfg pon_cfg;
553 pon_key.pon_ni = pon_id;
554 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
555 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
556 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
557 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
558
559 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
560 .WillOnce(Return(olt_cfg_set_res))
561 .WillRepeatedly(Return(olt_cfg_set_err));
562 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
563 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
564
565 bcmolt_tm_sched_cfg tm_sched_cfg;
566 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
567 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
568 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
569 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
570 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
571
572 Status status = EnablePonIf_(pon_id);
573 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
574}
575
576// Test 5 - EnablePonIf already enabled success
577TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
578 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
579
580 bcmolt_pon_interface_key pon_key;
581 bcmolt_pon_interface_cfg pon_cfg;
582 pon_key.pon_ni = pon_id;
583 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
584 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
585 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
586 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
587
588 Status status = EnablePonIf_(pon_id);
589 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
590}
591
592// Test 6 - EnablePonIf - enable onu discovery failure case
593TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
594 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
595 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
596
597 bcmolt_pon_interface_key pon_key;
598 bcmolt_pon_interface_cfg pon_cfg;
599 pon_key.pon_ni = pon_id;
600 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
601 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
602 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
603 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
604 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
605
606 Status status = EnablePonIf_(pon_id);
607 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
608}
609
610// Test 7 - EnablePonIf failure case
611TEST_F(TestEnablePonIf, EnablePonIfFailed) {
612 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
613 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
614 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
615
616 bcmolt_pon_interface_key pon_key;
617 bcmolt_pon_interface_cfg pon_cfg;
618 pon_key.pon_ni = pon_id;
619 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
620 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
621 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
622 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
623 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
624 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
625
626 Status status = EnablePonIf_(pon_id);
627 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
628}
629
630////////////////////////////////////////////////////////////////////////////
631// For testing SetStateUplinkIf functionality
632////////////////////////////////////////////////////////////////////////////
633
634class TestSetStateUplinkIf : public Test {
635 protected:
636 uint32_t intf_id = 0;
637 NiceMock<BalMocker> balMock;
638
639 virtual void SetUp() {
640 }
641
642 virtual void TearDown() {
643 }
644};
645
646// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
647TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
648 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
649 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
650 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
651
652 bcmolt_nni_interface_key nni_key;
653 bcmolt_nni_interface_cfg nni_cfg;
654 nni_key.id = intf_id;
655 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
656 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
657 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
658 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
659
660 bcmolt_tm_sched_cfg tm_sched_cfg;
661 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
662 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
663 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
664 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
665 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
666 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
667
668 Status status = SetStateUplinkIf_(intf_id, true);
669 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
670}
671
672// Test 2 - SetStateUplinkIf, NNI interface already disabled case
673TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
674 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
675
676 bcmolt_nni_interface_key nni_key;
677 bcmolt_nni_interface_cfg nni_cfg;
678 nni_key.id = intf_id;
679 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
680 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
681 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
682 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
683
684 Status status = SetStateUplinkIf_(intf_id, false);
685 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
686}
687
688// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
689TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
690 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
691 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
692 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
693 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
694
695 bcmolt_nni_interface_key nni_key;
696 bcmolt_nni_interface_cfg nni_cfg;
697 nni_key.id = intf_id;
698 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
699 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
700 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
701 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
702
703 bcmolt_tm_sched_cfg tm_sched_cfg;
704 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
705 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
706 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
707 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
708 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
709 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
710 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
711
712 Status status = SetStateUplinkIf_(intf_id, true);
713 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
714}
715
716// Test 4 - SetStateUplinkIf Enable failure case
717TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
718 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
719 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
720
721 bcmolt_nni_interface_key nni_key;
722 bcmolt_nni_interface_cfg nni_cfg;
723 nni_key.id = intf_id;
724 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
725 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
726 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
727 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
728 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
729
730 Status status = SetStateUplinkIf_(intf_id, true);
731 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
732}
733
734// Test 5 - SetStateUplinkIf Disable success case
735TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
736 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
737 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
738
739 bcmolt_nni_interface_key nni_key;
740 bcmolt_nni_interface_cfg nni_cfg;
741 nni_key.id = intf_id;
742 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
743 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
744 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
745 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
746 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
747
748 Status status = SetStateUplinkIf_(intf_id, false);
749 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
750}
751
752// Test 6 - SetStateUplinkIf Disable failure case
753TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
754 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
755 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
756
757 bcmolt_nni_interface_key nni_key;
758 bcmolt_nni_interface_cfg nni_cfg;
759 nni_key.id = intf_id;
760 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
761 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
762 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
763 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
764 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
765
766 Status status = SetStateUplinkIf_(intf_id, false);
767 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
768}
769
770////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500771// For testing DisablePonIf functionality
772////////////////////////////////////////////////////////////////////////////
773
774class TestDisablePonIf : public Test {
775 protected:
776 virtual void SetUp() {
777 }
778
779 virtual void TearDown() {
780 }
781};
782
Girish Gowdrae1db2952021-05-04 00:16:54 -0700783// Test 1 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_ACTIVE_WORKING state
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500784TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
785 bcmos_errno olt_oper_res = BCM_ERR_OK;
786 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
787 NiceMock<BalMocker> balMock;
788 uint32_t pon_id=1;
789
Girish Gowdrae1db2952021-05-04 00:16:54 -0700790 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
791 bcmolt_pon_interface_cfg interface_obj;
792
793 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
794 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
795
796 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
797 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
798 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
799 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
800 return pon_intf_get_res;
801 }
802 ));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500803 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
804 state.deactivate();
805 Status status = DisablePonIf_(pon_id);
806
807 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
808}
809
Girish Gowdrae1db2952021-05-04 00:16:54 -0700810// Test 2 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
811TEST_F(TestDisablePonIf, DisablePonIf_OperSubmitErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500812 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
813 NiceMock<BalMocker> balMock;
814 uint32_t pon_id=1;
815
Girish Gowdrae1db2952021-05-04 00:16:54 -0700816 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
817 bcmolt_pon_interface_cfg interface_obj;
818
819 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
820 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
821
822 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
823 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
824 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
825 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
826 return pon_intf_get_res;
827 }
828 ));
829
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500830 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
831 state.deactivate();
832 Status status = DisablePonIf_(pon_id);
833
834 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
835}
836
Girish Gowdrae1db2952021-05-04 00:16:54 -0700837// Test 3 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
838TEST_F(TestDisablePonIf, DisablePonIf_CfgSetErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500839 NiceMock<BalMocker> balMock;
840 uint32_t pon_id=1;
841 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700842
843 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
844 bcmolt_pon_interface_cfg interface_obj;
845
846 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
847 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
848
849 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
850 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
851 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
852 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
853 return pon_intf_get_res;
854 }
855 ));
856
857
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500858 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
859 state.deactivate();
860 Status status = DisablePonIf_(pon_id);
861
862 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
863}
864
Girish Gowdrae1db2952021-05-04 00:16:54 -0700865// Test 4 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_INACTIVE state
866TEST_F(TestDisablePonIf, DisablePonIfSuccess_PonIntfInactive) {
867 bcmos_errno olt_oper_res = BCM_ERR_OK;
868 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
869 NiceMock<BalMocker> balMock;
870 uint32_t pon_id=1;
871
872 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
873 bcmolt_pon_interface_cfg interface_obj;
874
875 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
876 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
877
878 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
879 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
880 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
881 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
882 return pon_intf_get_res;
883 }
884 ));
885 state.deactivate();
886 Status status = DisablePonIf_(pon_id);
887
888 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
889}
890
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500891////////////////////////////////////////////////////////////////////////////
892// For testing ActivateOnu functionality
893////////////////////////////////////////////////////////////////////////////
894
895class TestActivateOnu : public Test {
896 protected:
897 uint32_t pon_id = 0;
898 uint32_t onu_id = 1;
899 std::string vendor_id = "TWSH";
900 std::string vendor_specific = "80808080";
901 uint32_t pir = 1000000;
902 NiceMock<BalMocker> balMock;
903
904 virtual void SetUp() {
905 }
906
907 virtual void TearDown() {
908 }
909};
910
Girish Gowdra24297032020-03-23 12:32:37 -0700911// Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state
912TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) {
913 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
914 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500915 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
Girish Gowdra24297032020-03-23 12:32:37 -0700916 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500917
918 bcmolt_onu_cfg onu_cfg;
919 bcmolt_onu_key onu_key;
920 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
Girish Gowdra24297032020-03-23 12:32:37 -0700921 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500922 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
923 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
924
925 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
926 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
Girish Gowdra24297032020-03-23 12:32:37 -0700927 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500928
kesavandc1f2db92020-08-31 15:32:06 +0530929 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500930 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
931}
932
Girish Gowdra24297032020-03-23 12:32:37 -0700933// Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state
934TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500935 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
936 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
937
938 bcmolt_onu_cfg onu_cfg;
939 bcmolt_onu_key onu_key;
940 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
941 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
942 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
943 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra24297032020-03-23 12:32:37 -0700944
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500945 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
946
kesavandc1f2db92020-08-31 15:32:06 +0530947 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500948 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
949}
950
Girish Gowdra24297032020-03-23 12:32:37 -0700951// Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state
952TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) {
953 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
954 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
955 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
956
957 bcmolt_onu_cfg onu_cfg;
958 bcmolt_onu_key onu_key;
959 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
960 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
961 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
962 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
963
964 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
965 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
966
967
kesavandc1f2db92020-08-31 15:32:06 +0530968 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700969 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
970}
971
972// Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE)
973TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) {
974 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
975 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
976
977 bcmolt_onu_cfg onu_cfg;
978 bcmolt_onu_key onu_key;
979 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
980 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process
981 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
982 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
983
984 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
985
kesavandc1f2db92020-08-31 15:32:06 +0530986 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700987 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
988}
989
990// Test 5 - ActivateOnu failure case - cfg_get failure
991TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) {
992 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure
993
994 bcmolt_onu_cfg onu_cfg;
995 bcmolt_onu_key onu_key;
996 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
997 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
998 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
999 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1000
kesavandc1f2db92020-08-31 15:32:06 +05301001 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001002 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1003}
1004
1005// Test 6 - ActivateOnu failure case - oper_submit failure
1006TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) {
1007 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1008 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1009 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
1010 bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure
1011
1012 bcmolt_onu_cfg onu_cfg;
1013 bcmolt_onu_key onu_key;
1014 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1015 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
1016 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1017 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1018
1019 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
1020 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
1021 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
1022
kesavandc1f2db92020-08-31 15:32:06 +05301023 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001024 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1025}
1026
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001027////////////////////////////////////////////////////////////////////////////
1028// For testing DeactivateOnu functionality
1029////////////////////////////////////////////////////////////////////////////
1030
1031class TestDeactivateOnu : public Test {
1032 protected:
1033 uint32_t pon_id = 0;
1034 uint32_t onu_id = 1;
1035 std::string vendor_id = "TWSH";
1036 std::string vendor_specific = "80808080";
1037 NiceMock<BalMocker> balMock;
1038
1039 virtual void SetUp() {
1040 }
1041
1042 virtual void TearDown() {
1043 }
1044};
1045
1046// Test 1 - DeactivateOnu success case
1047TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
1048 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1049 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1050
1051 bcmolt_onu_cfg onu_cfg;
1052 bcmolt_onu_key onu_key;
1053 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1054 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1055 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1056 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1057
1058 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1059
1060 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1061 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1062}
1063
1064// Test 2 - DeactivateOnu failure case
1065TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
1066 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1067 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1068
1069 bcmolt_onu_cfg onu_cfg;
1070 bcmolt_onu_key onu_key;
1071 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1072 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1073 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1074 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1075
1076 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1077
1078 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1079 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1080}
1081
1082////////////////////////////////////////////////////////////////////////////
1083// For testing DeleteOnu functionality
1084////////////////////////////////////////////////////////////////////////////
1085
1086class TestDeleteOnu : public Test {
1087 protected:
1088 uint32_t pon_id = 0;
1089 uint32_t onu_id = 1;
1090 std::string vendor_id = "TWSH";
1091 std::string vendor_specific = "80808080";
1092 NiceMock<BalMocker> balMock;
1093
1094 virtual void SetUp() {
1095 }
1096
1097 virtual void TearDown() {
1098 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301099 public:
1100 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
1101 onu_deactivate_complete_result res;
1102 res.pon_intf_id = 0;
1103 res.onu_id = 1;
1104 res.result = result;
1105 res.reason = reason;
1106 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
1107 // before we push the result.
1108 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1109 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
1110 onu_deact_compltd_key k(0, 1);
1111 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
1112 if (it == onu_deact_compltd_map.end()) {
1113 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
1114 } else {
1115 it->second->push(res);
1116 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
1117 }
1118 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
1119 return 0;
1120 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001121};
1122
1123// Test 1 - DeleteOnu success case
1124TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
1125 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1126 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1127 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1128
1129 bcmolt_onu_cfg onu_cfg;
1130 bcmolt_onu_key onu_key;
1131 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1132 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1133 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301134 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001135
1136 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1137 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1138
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301139 future<int> push_onu_deact_complt_res = \
1140 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1141 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1142 Status status = future_res.get();
1143 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001144 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1145}
1146
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301147// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1148TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001149 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1150 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1151 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1152
1153 bcmolt_onu_cfg onu_cfg;
1154 bcmolt_onu_key onu_key;
1155 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1156 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1157 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301158 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001159
1160 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1161 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1162
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301163 future<int> push_onu_deact_complt_res = \
1164 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1165 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1166
1167 Status status = future_res.get();
1168 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001169 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1170}
1171
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301172// Test 3 - DeleteOnu failure case - onu deactivation fails
1173TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
1174 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1175 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1176
1177 bcmolt_onu_cfg onu_cfg;
1178 bcmolt_onu_key onu_key;
1179 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1180 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1181 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301182 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301183
1184 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1185
1186 future<int> push_onu_deact_complt_res = \
1187 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1188 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1189
1190 Status status = future_res.get();
1191 int res = push_onu_deact_complt_res.get();
1192 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1193}
1194
1195// Test 4 - DeleteOnu failure case - onu deactivation timesout
1196TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
1197 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1198 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1199
1200 bcmolt_onu_cfg onu_cfg;
1201 bcmolt_onu_key onu_key;
1202 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1203 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1204 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301205 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301206
1207 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1208
1209 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1210
1211 Status status = future_res.get();
1212 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1213}
1214
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301215// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1216TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
1217 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1218 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1219 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1220
1221 bcmolt_onu_cfg onu_cfg;
1222 bcmolt_onu_key onu_key;
1223 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1224 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1225 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1226 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1227
1228 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1229 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1230
1231 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1232
1233 Status status = future_res.get();
1234 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1235}
1236
1237// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1238TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1239 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1240
1241 bcmolt_onu_cfg onu_cfg;
1242 bcmolt_onu_key onu_key;
1243 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1244 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1245 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1246 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1247
1248 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1249
1250 Status status = future_res.get();
1251 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1252}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301253
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001254////////////////////////////////////////////////////////////////////////////
1255// For testing OmciMsgOut functionality
1256////////////////////////////////////////////////////////////////////////////
1257
1258class TestOmciMsgOut : public Test {
1259 protected:
1260 uint32_t pon_id = 0;
1261 uint32_t onu_id = 1;
1262 std::string pkt = "omci-pkt";
1263 NiceMock<BalMocker> balMock;
1264
1265 virtual void SetUp() {
1266 }
1267
1268 virtual void TearDown() {
1269 }
1270};
1271
1272// Test 1 - OmciMsgOut success case
1273TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1274 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1275
1276 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1277
1278 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1279 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1280}
1281
1282// Test 1 - OmciMsgOut failure case
1283TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1284 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1285
1286 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1287
1288 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1289 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1290}
1291
1292////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001293// For testing FlowAdd functionality
1294////////////////////////////////////////////////////////////////////////////
1295
1296class TestFlowAdd : public Test {
1297 protected:
1298 int32_t access_intf_id = 0;
1299 int32_t onu_id = 1;
1300 int32_t uni_id = 0;
1301 uint32_t port_no = 16;
1302 uint32_t flow_id = 1;
1303 std::string flow_type = "upstream";
1304 int32_t alloc_id = 1024;
1305 int32_t network_intf_id = 0;
1306 int32_t gemport_id = 1024;
1307 int32_t priority_value = 0;
1308 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301309 int32_t group_id = -1;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001310 uint32_t tech_profile_id = 64;
Burak Gurdaga0523592021-02-24 15:17:47 +00001311 bool enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001312
1313 NiceMock<BalMocker> balMock;
1314 openolt::Flow* flow;
1315 openolt::Classifier* classifier;
1316 openolt::Action* action;
1317 openolt::ActionCmd* cmd;
1318
1319 bcmolt_flow_key flow_key;
1320 bcmolt_flow_cfg flow_cfg;
1321
1322 tech_profile::TrafficQueues* traffic_queues;
1323 tech_profile::TrafficQueue* traffic_queue_1;
1324 tech_profile::TrafficQueue* traffic_queue_2;
1325 tech_profile::DiscardConfig* discard_config_1;
1326 tech_profile::DiscardConfig* discard_config_2;
1327 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1328 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1329
1330
1331 virtual void SetUp() {
1332 classifier = new openolt::Classifier;
1333 action = new openolt::Action;
1334 cmd = new openolt::ActionCmd;
1335
1336 classifier->set_o_tpid(0);
1337 classifier->set_o_vid(7);
1338 classifier->set_i_tpid(0);
1339 classifier->set_i_vid(0);
1340 classifier->set_o_pbits(0);
1341 classifier->set_i_pbits(0);
1342 classifier->set_eth_type(0);
1343 classifier->set_ip_proto(0);
1344 classifier->set_src_port(0);
1345 classifier->set_dst_port(0);
1346 classifier->set_pkt_tag_type("single_tag");
1347
1348 action->set_o_vid(12);
1349 action->set_o_pbits(0);
1350 action->set_o_tpid(0);
1351 action->set_i_vid(0);
1352 action->set_i_pbits(0);
1353 action->set_i_tpid(0);
1354
1355 cmd->set_add_outer_tag(true);
1356 cmd->set_remove_outer_tag(false);
1357 cmd->set_trap_to_host(false);
1358 action->set_allocated_cmd(cmd);
1359
1360 flow_key.flow_id = 1;
1361 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1362 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1363 flow_cfg.data.onu_id=1;
1364 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1365 flow_cfg.data.svc_port_id=1024;
1366 flow_cfg.data.priority=0;
1367 flow_cfg.data.cookie=0;
1368 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1369 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1370 flow_cfg.data.ingress_intf.intf_id=0;
1371 flow_cfg.data.egress_intf.intf_id=0;
1372 flow_cfg.data.classifier.o_vid=7;
1373 flow_cfg.data.classifier.o_pbits=0;
1374 flow_cfg.data.classifier.i_vid=0;
1375 flow_cfg.data.classifier.i_pbits=0;
1376 flow_cfg.data.classifier.ether_type=0;
1377 flow_cfg.data.classifier.ip_proto=0;
1378 flow_cfg.data.classifier.src_port=0;
1379 flow_cfg.data.classifier.dst_port=0;
1380 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1381 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1382 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1383 flow_cfg.data.egress_qos.tm_sched.id=1020;
1384 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1385 flow_cfg.data.action.o_vid=12;
1386 flow_cfg.data.action.o_pbits=0;
1387 flow_cfg.data.action.i_vid=0;
1388 flow_cfg.data.action.i_pbits=0;
1389 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1390
1391 traffic_queues = new tech_profile::TrafficQueues;
1392 traffic_queues->set_intf_id(0);
1393 traffic_queues->set_onu_id(2);
1394 traffic_queue_1 = traffic_queues->add_traffic_queues();
1395 traffic_queue_1->set_gemport_id(1024);
1396 traffic_queue_1->set_pbit_map("0b00000101");
1397 traffic_queue_1->set_aes_encryption(true);
1398 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1399 traffic_queue_1->set_priority(0);
1400 traffic_queue_1->set_weight(0);
1401 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1402 discard_config_1 = new tech_profile::DiscardConfig;
1403 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1404 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1405 tail_drop_discard_config_1->set_queue_size(8);
1406 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1407 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1408
1409 traffic_queues->set_uni_id(0);
1410 traffic_queues->set_port_no(16);
1411
1412 traffic_queue_2 = traffic_queues->add_traffic_queues();
1413 traffic_queue_2->set_gemport_id(1025);
1414 traffic_queue_2->set_pbit_map("0b00001010");
1415 traffic_queue_2->set_aes_encryption(true);
1416 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1417 traffic_queue_2->set_priority(1);
1418 traffic_queue_2->set_weight(0);
1419 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1420 discard_config_2 = new tech_profile::DiscardConfig;
1421 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1422 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1423 tail_drop_discard_config_2->set_queue_size(8);
1424 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1425 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1426 }
1427
1428 virtual void TearDown() {
1429 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301430
1431 public:
1432 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
1433 gem_cfg_compltd_key k(0, gem_port_id);
1434 gem_cfg_complete_result res;
1435 res.pon_intf_id = 0;
1436 res.gem_port_id = gem_port_id;
1437 res.state = state;
1438 res.status = status;
1439
1440 uint32_t gem_cfg_key_check_counter = 1;
1441 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
1442 while(true) {
1443 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1444 it = gem_cfg_compltd_map.find(k);
1445
1446 if (it != gem_cfg_compltd_map.end()) {
1447 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1448 break;
1449 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
1450 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1451
1452 // We need to wait for some time to allow the Gem Cfg Request to be triggered
1453 // before we push the result.
1454 bcmos_usleep(6000);
1455 } else {
1456 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
1457 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1458 return 0;
1459 }
1460 gem_cfg_key_check_counter++;
1461 }
1462
1463 bcmos_fastlock_lock(&gem_cfg_wait_lock);
1464 if (it->second) {
1465 it->second->push(res);
1466 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
1467 }
1468 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
1469 return 0;
1470 }
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001471};
1472
1473// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1474TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1475 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1476 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1477
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301478 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001479 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001480 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1481}
1482
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301483#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001484// Test 2 - FlowAdd - Duplicate Flow case
1485TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1486 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1487 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1488 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1489
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301490 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 +00001491 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001492 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1493}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301494#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001495
1496// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1497TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1498 gemport_id = 1025;
1499
1500 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1501 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1502
1503 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1504 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1505 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1506
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301507 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 +00001508 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001509 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1510}
1511
1512// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1513TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1514 flow_type = "bidirectional";
1515
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301516 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 +00001517 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001518 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1519}
1520
1521// Test 5 - FlowAdd - Failure case(Invalid network setting)
1522TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1523 network_intf_id = -1;
1524
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301525 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 +00001526 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001527 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1528}
1529
1530// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1531TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1532 flow_id = 2;
1533
1534 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301535 action = new openolt::Action;
1536 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001537 cmd->set_trap_to_host(true);
1538 action->set_allocated_cmd(cmd);
1539
1540 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1541 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1542 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1543 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1544 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1545
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301546 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 +00001547 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001548 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1549}
1550
1551// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1552TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1553 flow_id = 3;
1554 gemport_id = 1025;
1555
1556 classifier->set_ip_proto(17);
1557 classifier->set_src_port(68);
1558 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301559 action = new openolt::Action;
1560 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001561 cmd->set_trap_to_host(true);
1562 action->set_allocated_cmd(cmd);
1563
1564 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1565 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1566 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1567 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1568 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1569
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301570 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 +00001571 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001572 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1573}
1574
1575// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1576TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1577 flow_id = 4;
1578 flow_type = "downstream";
1579
1580 classifier->set_o_vid(12);
1581 classifier->set_i_vid(7);
1582 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301583 action = new openolt::Action;
1584 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001585 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001586 cmd->set_remove_outer_tag(true);
1587 action->set_allocated_cmd(cmd);
1588
1589 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1590 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1591 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1592 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1593 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
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 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1601TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1602 onu_id = 2;
1603 flow_id = 5;
1604 alloc_id = 1025;
1605
1606 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1607 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1608
1609 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1610 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1611 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1612 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1613 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001614
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301615 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
1616 future<int> push_gem_cfg_complt = \
1617 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1618 push_gem_cfg_complt = \
1619 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
1620 Status status = future_res.get();
1621 int res = push_gem_cfg_complt.get();
1622
1623 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 +00001624 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001625 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1626}
1627
1628// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1629TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1630 onu_id = 2;
1631 flow_id = 6;
1632 flow_type = "downstream";
1633 alloc_id = 1025;
1634
1635 classifier->set_o_vid(12);
1636 classifier->set_i_vid(7);
1637 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301638 action = new openolt::Action;
1639 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001640 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001641 cmd->set_remove_outer_tag(true);
1642 action->set_allocated_cmd(cmd);
1643
1644 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1645 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1646
1647 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1648 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1649 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1650 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1651 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1652 CreateTrafficQueues_(traffic_queues);
1653
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301654 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 +00001655 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001656 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1657}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301658
Burak Gurdaga0523592021-02-24 15:17:47 +00001659// Test 11 - FlowAdd - success case (Downstream-Encrypted GEM)
1660TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) {
1661 onu_id = 2;
1662 flow_id = 7;
1663 flow_type = "downstream";
1664 alloc_id = 1025;
1665 enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001666
Burak Gurdaga0523592021-02-24 15:17:47 +00001667 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1668 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1669 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1670 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1671 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1672
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301673 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 +00001674 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05301675
1676 future<int> push_gem_cfg_complt = \
1677 async(launch::async, TestFlowAdd::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
1678 Status status = future_res.get();
1679 int res = push_gem_cfg_complt.get();
Burak Gurdaga0523592021-02-24 15:17:47 +00001680 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1681}
1682
1683// Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied)
1684TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) {
1685 onu_id = 2;
1686 flow_id = 8;
1687 flow_type = "downstream";
1688 alloc_id = 1025;
1689 enable_encryption = false;
1690
1691 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1692 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1693 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1694 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1695 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1696
1697 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1698 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1699 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1700}
1701
1702// Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied)
1703TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) {
1704 onu_id = 2;
1705 flow_id = 9;
1706 flow_type = "upstream";
1707 alloc_id = 1025;
1708 enable_encryption = true;
1709
1710 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1711 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1712 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1713 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1714 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1715
1716 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1717 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1718 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1719}
1720
1721// Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied)
1722TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) {
1723 onu_id = 2;
1724 flow_id = 10;
1725 flow_type = "multicast";
1726 alloc_id = 1025;
1727 enable_encryption = true;
1728
1729 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1730 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1731 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1732 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1733 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1734
1735 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1736 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1737 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1738}
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001739////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001740// For testing OnuPacketOut functionality
1741////////////////////////////////////////////////////////////////////////////
1742
1743class TestOnuPacketOut : public Test {
1744 protected:
1745 uint32_t pon_id = 0;
1746 uint32_t onu_id = 1;
1747 std::string pkt = "omci-pkt";
1748 NiceMock<BalMocker> balMock;
1749
1750 virtual void SetUp() {
1751 }
1752
1753 virtual void TearDown() {
1754 }
1755};
1756
1757// Test 1 - OnuPacketOut success case
1758TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1759 uint32_t port_no = 16;
1760 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001761
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001762 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001763 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1764
1765 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1766 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1767}
1768
1769// Test 2 - OnuPacketOut Port number as 0 case
1770TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1771 uint32_t port_no = 0;
1772 uint32_t gemport_id = 1024;
1773
1774 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1775 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1776}
1777
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001778// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1779TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1780 uint32_t port_no = 16;
1781 uint32_t gemport_id = 0;
1782
1783 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1784 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1785
1786 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1787 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1788}
1789
1790// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1791TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1792 uint32_t port_no = 64;
1793 uint32_t gemport_id = 0;
1794
1795 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1796 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1797
1798 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1799 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1800}
1801
1802////////////////////////////////////////////////////////////////////////////
1803// For testing FlowRemove functionality
1804////////////////////////////////////////////////////////////////////////////
1805
1806class TestFlowRemove : public Test {
1807 protected:
1808 NiceMock<BalMocker> balMock;
1809
1810 virtual void SetUp() {
1811 }
1812
1813 virtual void TearDown() {
1814 }
1815};
1816
1817// Test 1 - FlowRemove - Failure case
1818TEST_F(TestFlowRemove, FlowRemoveFailure) {
1819 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1820 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1821
1822 Status status = FlowRemove_(1, "upstream");
1823 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1824}
1825
1826// Test 2 - FlowRemove - success case
1827TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1828 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1829 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1830
1831 Status status = FlowRemove_(1, "upstream");
1832 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1833}
1834
1835////////////////////////////////////////////////////////////////////////////
1836// For testing UplinkPacketOut functionality
1837////////////////////////////////////////////////////////////////////////////
1838
1839class TestUplinkPacketOut : public Test {
1840 protected:
1841 uint32_t pon_id = 0;
1842 std::string pkt = "omci-pkt";
1843 NiceMock<BalMocker> balMock;
1844
1845 bcmolt_flow_key flow_key;
1846 bcmolt_flow_cfg flow_cfg;
1847
1848 virtual void SetUp() {
1849 flow_key.flow_id = 1;
1850 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1851 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1852 flow_cfg.data.onu_id=1;
1853 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1854 flow_cfg.data.svc_port_id=1024;
1855 flow_cfg.data.priority=0;
1856 flow_cfg.data.cookie=0;
1857 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1858 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1859 flow_cfg.data.ingress_intf.intf_id=0;
1860 flow_cfg.data.egress_intf.intf_id=0;
1861 flow_cfg.data.classifier.o_vid=7;
1862 flow_cfg.data.classifier.o_pbits=0;
1863 flow_cfg.data.classifier.i_vid=0;
1864 flow_cfg.data.classifier.i_pbits=0;
1865 flow_cfg.data.classifier.ether_type=0;
1866 flow_cfg.data.classifier.ip_proto=0;
1867 flow_cfg.data.classifier.src_port=0;
1868 flow_cfg.data.classifier.dst_port=0;
1869 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1870 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1871 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1872 flow_cfg.data.egress_qos.tm_sched.id=1020;
1873 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1874 flow_cfg.data.action.o_vid=12;
1875 flow_cfg.data.action.o_pbits=0;
1876 flow_cfg.data.action.i_vid=0;
1877 flow_cfg.data.action.i_pbits=0;
1878 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1879 }
1880
1881 virtual void TearDown() {
1882 }
1883};
1884
1885// Test 1 - UplinkPacketOut success case
1886TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1887 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1888 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1889 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1890 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1891 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1892
1893 Status status = UplinkPacketOut_(pon_id, pkt);
1894 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1895}
1896
1897// Test 2 - UplinkPacketOut Failure case
1898TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1899 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1900 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1901 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1902 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1903 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1904
1905 Status status = UplinkPacketOut_(pon_id, pkt);
1906 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1907}
1908
1909// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1910TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1911 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1912
1913 FlowRemove_(2, "upstream");
1914 FlowRemove_(3, "upstream");
1915 FlowRemove_(4, "downstream");
1916 FlowRemove_(5, "upstream");
1917 FlowRemove_(6, "downstream");
Burak Gurdaga0523592021-02-24 15:17:47 +00001918 FlowRemove_(7, "downstream");
1919 FlowRemove_(8, "downstream");
1920 FlowRemove_(9, "upstream");
1921 FlowRemove_(10, "multicast");
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001922
1923 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1924 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1925 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1926
1927 Status status = UplinkPacketOut_(pon_id, pkt);
1928 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1929}
1930
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001931////////////////////////////////////////////////////////////////////////////
1932// For testing CreateTrafficSchedulers functionality
1933////////////////////////////////////////////////////////////////////////////
1934
1935class TestCreateTrafficSchedulers : public Test {
1936 protected:
1937 NiceMock<BalMocker> balMock;
1938 tech_profile::TrafficSchedulers* traffic_scheds;
1939 tech_profile::TrafficScheduler* traffic_sched;
1940 tech_profile::SchedulerConfig* scheduler;
1941 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1942
1943 virtual void SetUp() {
1944 traffic_scheds = new tech_profile::TrafficSchedulers;
1945 traffic_scheds->set_intf_id(0);
1946 traffic_scheds->set_onu_id(1);
1947 traffic_scheds->set_uni_id(0);
1948 traffic_scheds->set_port_no(16);
1949 traffic_sched = traffic_scheds->add_traffic_scheds();
1950 traffic_sched->set_alloc_id(1024);
1951 scheduler = new tech_profile::SchedulerConfig;
1952 scheduler->set_priority(0);
1953 scheduler->set_weight(0);
1954 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1955 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1956 traffic_shaping_info->set_cbs(60536);
1957 traffic_shaping_info->set_pbs(65536);
1958 traffic_shaping_info->set_gir(10000);
1959 }
1960
1961 virtual void TearDown() {
1962 }
1963
1964 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301965 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1966 alloc_cfg_compltd_key k(0, 1024);
1967 alloc_cfg_complete_result res;
1968 res.pon_intf_id = 0;
1969 res.alloc_id = 1024;
1970 res.state = state;
1971 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001972
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301973 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1974 // before we push the result.
1975 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1976 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1977 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1978 if (it == alloc_cfg_compltd_map.end()) {
1979 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 -05001980 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301981 it->second->push(res);
1982 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001983 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301984 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1985 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001986 }
1987};
1988
1989// Test 1 - CreateTrafficSchedulers-Upstream success case
1990TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1991 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1992 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1993 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1994 traffic_sched->set_allocated_scheduler(scheduler);
1995 traffic_shaping_info->set_cir(64000);
1996 traffic_shaping_info->set_pir(128000);
1997 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1998
1999 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2000 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2001
2002 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302003 future<int> push_alloc_cfg_complt = \
2004 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002005
2006 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302007 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002008 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2009}
2010
2011// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
2012TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
2013 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2014 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2015 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2016 traffic_sched->set_allocated_scheduler(scheduler);
2017 traffic_shaping_info->set_cir(64000);
2018 traffic_shaping_info->set_pir(128000);
2019 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2020
2021 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2022 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2023
2024 Status status = CreateTrafficSchedulers_(traffic_scheds);
2025 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2026}
2027
2028// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
2029TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
2030 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2031 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2032 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2033 traffic_sched->set_allocated_scheduler(scheduler);
2034 traffic_shaping_info->set_cir(64000);
2035 traffic_shaping_info->set_pir(128000);
2036 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2037
2038 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2039 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2040
2041 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302042 future<int> push_alloc_cfg_complt = \
2043 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002044
2045 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302046 int res = push_alloc_cfg_complt.get();
2047
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002048 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2049}
2050
2051// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
2052TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
2053 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2054 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2055 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2056 traffic_sched->set_allocated_scheduler(scheduler);
2057 traffic_shaping_info->set_cir(64000);
2058 traffic_shaping_info->set_pir(128000);
2059 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2060
2061 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2062 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2063
2064 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302065 future<int> push_alloc_cfg_complt = \
2066 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002067
2068 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302069 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002070 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2071}
2072
2073// Test 5 - CreateTrafficSchedulers-Upstream Failure case
2074TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
2075 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2076 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2077 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2078 traffic_sched->set_allocated_scheduler(scheduler);
2079 traffic_shaping_info->set_cir(64000);
2080 traffic_shaping_info->set_pir(128000);
2081 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2082
2083 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2084 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2085
2086 Status status = CreateTrafficSchedulers_(traffic_scheds);
2087 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2088}
2089
2090// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
2091TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
2092 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2093 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2094 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2095 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002096 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002097 traffic_shaping_info->set_cir(64000);
2098 traffic_shaping_info->set_pir(0);
2099 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2100
2101 Status status = CreateTrafficSchedulers_(traffic_scheds);
2102 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2103}
2104
2105// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
2106TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
2107 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2108 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2109 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2110 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002111 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002112 traffic_shaping_info->set_cir(64000);
2113 traffic_shaping_info->set_pir(32000);
2114 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2115
2116 Status status = CreateTrafficSchedulers_(traffic_scheds);
2117 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2118}
2119
2120// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
2121TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
2122 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2123 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2124 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2125 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002126 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002127 traffic_shaping_info->set_cir(64000);
2128 traffic_shaping_info->set_pir(64000);
2129 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2130
2131 Status status = CreateTrafficSchedulers_(traffic_scheds);
2132 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2133}
2134
2135// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
2136TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
2137 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2138 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2139 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2140 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002141 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002142 traffic_shaping_info->set_cir(64000);
2143 traffic_shaping_info->set_pir(0);
2144 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2145
2146 Status status = CreateTrafficSchedulers_(traffic_scheds);
2147 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2148}
2149
2150// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
2151TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
2152 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2153 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2154 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2155 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002156 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002157 traffic_shaping_info->set_cir(0);
2158 traffic_shaping_info->set_pir(32000);
2159 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2160
2161 Status status = CreateTrafficSchedulers_(traffic_scheds);
2162 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2163}
2164
2165// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
2166TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
2167 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2168 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2169 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2170 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002171 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002172 traffic_shaping_info->set_cir(64000);
2173 traffic_shaping_info->set_pir(32000);
2174 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2175
2176 Status status = CreateTrafficSchedulers_(traffic_scheds);
2177 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2178}
2179
2180// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
2181TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
2182 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2183 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2184 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2185 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002186 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002187 traffic_shaping_info->set_cir(64000);
2188 traffic_shaping_info->set_pir(64000);
2189 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2190
2191 Status status = CreateTrafficSchedulers_(traffic_scheds);
2192 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2193}
2194
2195// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
2196TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
2197 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2198 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2199 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2200 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002201 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002202 traffic_shaping_info->set_cir(64000);
2203 traffic_shaping_info->set_pir(0);
2204 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2205
2206 Status status = CreateTrafficSchedulers_(traffic_scheds);
2207 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2208}
2209
2210// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
2211TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
2212 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2213 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2214 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2215 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002216 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002217 traffic_shaping_info->set_cir(0);
2218 traffic_shaping_info->set_pir(32000);
2219 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2220
2221 Status status = CreateTrafficSchedulers_(traffic_scheds);
2222 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2223}
2224
Burak Gurdag623fada2021-04-20 22:02:36 +00002225// Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case
2226TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002227 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2228 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2229 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2230 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002231 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002232 traffic_shaping_info->set_cir(64000);
2233 traffic_shaping_info->set_pir(128000);
2234 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2235
Burak Gurdag623fada2021-04-20 22:02:36 +00002236 Status status = CreateTrafficSchedulers_(traffic_scheds);
2237 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002238}
2239
Burak Gurdag623fada2021-04-20 22:02:36 +00002240// Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case
2241TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002242 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2243 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2244 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2245 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002246 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002247 traffic_shaping_info->set_cir(64000);
2248 traffic_shaping_info->set_pir(32000);
2249 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2250
Burak Gurdag623fada2021-04-20 22:02:36 +00002251 Status status = CreateTrafficSchedulers_(traffic_scheds);
2252 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2253}
2254
2255// Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case
2256TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) {
2257 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2258 scheduler->set_additional_bw(9);
2259 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2260 traffic_sched->set_allocated_scheduler(scheduler);
2261 traffic_shaping_info->set_gir(0);
2262 traffic_shaping_info->set_cir(64000);
2263 traffic_shaping_info->set_pir(128000);
2264 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2265
2266 Status status = CreateTrafficSchedulers_(traffic_scheds);
2267 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2268}
2269
2270// Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case
2271TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) {
2272 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2273 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2274 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2275 traffic_sched->set_allocated_scheduler(scheduler);
2276 traffic_shaping_info->set_gir(64000);
2277 traffic_shaping_info->set_cir(0);
2278 traffic_shaping_info->set_pir(64000);
2279 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2280
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002281 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2282 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2283
2284 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302285 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002286 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2287
2288 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302289 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002290 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2291}
2292
Burak Gurdag623fada2021-04-20 22:02:36 +00002293// Test 19 - CreateTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002294TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2295 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2296 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2297 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2298 traffic_sched->set_allocated_scheduler(scheduler);
2299 traffic_shaping_info->set_cir(64000);
2300 traffic_shaping_info->set_pir(128000);
2301 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2302
2303 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2304 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2305
2306 Status status = CreateTrafficSchedulers_(traffic_scheds);
2307 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2308}
2309
Burak Gurdag623fada2021-04-20 22:02:36 +00002310// Test 20 - CreateTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002311TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2312 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2313 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2314 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2315 traffic_sched->set_allocated_scheduler(scheduler);
2316 traffic_shaping_info->set_cir(64000);
2317 traffic_shaping_info->set_pir(128000);
2318 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2319
2320 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2321 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2322
2323 Status status = CreateTrafficSchedulers_(traffic_scheds);
2324 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2325}
2326
Burak Gurdag623fada2021-04-20 22:02:36 +00002327// Test 21 - CreateTrafficSchedulers-Invalid direction Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002328TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2329 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2330 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2331 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2332 traffic_sched->set_allocated_scheduler(scheduler);
2333 traffic_shaping_info->set_cir(64000);
2334 traffic_shaping_info->set_pir(128000);
2335 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2336
2337 Status status = CreateTrafficSchedulers_(traffic_scheds);
2338 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2339}
2340
2341////////////////////////////////////////////////////////////////////////////
2342// For testing RemoveTrafficSchedulers functionality
2343////////////////////////////////////////////////////////////////////////////
2344
2345class TestRemoveTrafficSchedulers : public Test {
2346 protected:
2347 NiceMock<BalMocker> balMock;
2348 tech_profile::TrafficSchedulers* traffic_scheds;
2349 tech_profile::TrafficScheduler* traffic_sched;
2350 tech_profile::SchedulerConfig* scheduler;
2351 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2352 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302353 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002354
2355 virtual void SetUp() {
2356 traffic_scheds = new tech_profile::TrafficSchedulers;
2357 traffic_scheds->set_intf_id(0);
2358 traffic_scheds->set_onu_id(1);
2359 traffic_scheds->set_uni_id(0);
2360 traffic_scheds->set_port_no(16);
2361 traffic_sched = traffic_scheds->add_traffic_scheds();
2362 traffic_sched->set_alloc_id(1025);
2363 scheduler = new tech_profile::SchedulerConfig;
2364 scheduler->set_priority(0);
2365 scheduler->set_weight(0);
2366 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2367 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2368 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2369 traffic_shaping_info->set_cir(64000);
2370 traffic_shaping_info->set_pir(128000);
2371 traffic_shaping_info->set_cbs(60536);
2372 traffic_shaping_info->set_pbs(65536);
2373 traffic_shaping_info->set_gir(10000);
2374 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2375 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2376 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2377 }
2378
2379 virtual void TearDown() {
2380 }
2381
2382 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302383 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2384 alloc_cfg_compltd_key k(0, 1025);
2385 alloc_cfg_complete_result res;
2386 res.pon_intf_id = 0;
2387 res.alloc_id = 1025;
2388 res.state = state;
2389 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002390
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302391 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2392 // before we push the result.
2393 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302394 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2395 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2396 if (it == alloc_cfg_compltd_map.end()) {
2397 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 -05002398 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302399 it->second->push(res);
2400 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002401 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302402 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2403 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002404 }
2405};
2406
2407// Test 1 - RemoveTrafficSchedulers-Upstream success case
2408TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2409 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2410 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2411 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2412
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302413 bcmolt_pon_interface_key pon_key;
2414 bcmolt_pon_interface_cfg pon_cfg;
2415 pon_key.pon_ni = pon_id;
2416 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2417 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2418 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2419 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2420 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2421
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002422 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302423 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002424 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2425
2426 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302427 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002428 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2429}
2430
2431// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2432TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2433 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2434 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2435 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2436
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302437 bcmolt_pon_interface_key pon_key;
2438 bcmolt_pon_interface_cfg pon_cfg;
2439 pon_key.pon_ni = pon_id;
2440 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2441 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2442 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2443 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2444 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2445
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002446 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302447 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002448 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2449
2450 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302451 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002452 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2453}
2454
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302455// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2456TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2457 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2458 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2459 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2460
2461 bcmolt_pon_interface_key pon_key;
2462 bcmolt_pon_interface_cfg pon_cfg;
2463 pon_key.pon_ni = pon_id;
2464 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2465 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2466 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2467 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2468 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2469
2470 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2471
2472 Status status = future_res.get();
2473 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2474}
2475
2476// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2477TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2478 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2479 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2480 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2481
2482 bcmolt_pon_interface_key pon_key;
2483 bcmolt_pon_interface_cfg pon_cfg;
2484 pon_key.pon_ni = pon_id;
2485 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2486 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2487 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2488 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2489 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2490
2491 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2492
2493 Status status = future_res.get();
2494 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2495}
2496
2497// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002498TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2499 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2500
2501 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2502 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2503
2504 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2505 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2506}
2507
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302508// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002509TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2510 //Create Scheduler
2511 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2512 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2513 traffic_sched->set_allocated_scheduler(scheduler);
2514 CreateTrafficSchedulers_(traffic_scheds);
2515
2516 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2517 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2518
2519 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2520 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2521}
2522
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302523// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002524TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2525 //Create Scheduler
2526 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2527 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2528 traffic_sched->set_allocated_scheduler(scheduler);
2529 CreateTrafficSchedulers_(traffic_scheds);
2530
2531 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2532 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2533
2534 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2535 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2536}
2537
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302538// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002539TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2540 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2541
2542 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2543 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2544}
2545
2546////////////////////////////////////////////////////////////////////////////
2547// For testing CreateTrafficQueues functionality
2548////////////////////////////////////////////////////////////////////////////
2549
2550class TestCreateTrafficQueues : public Test {
2551 protected:
2552 NiceMock<BalMocker> balMock;
2553 tech_profile::TrafficQueues* traffic_queues;
2554 tech_profile::TrafficQueue* traffic_queue_1;
2555 tech_profile::TrafficQueue* traffic_queue_2;
2556 tech_profile::DiscardConfig* discard_config_1;
2557 tech_profile::DiscardConfig* discard_config_2;
2558 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2559 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2560
2561 virtual void SetUp() {
2562 traffic_queues = new tech_profile::TrafficQueues;
2563 traffic_queues->set_intf_id(0);
2564 traffic_queues->set_onu_id(1);
2565 traffic_queue_1 = traffic_queues->add_traffic_queues();
2566 traffic_queue_1->set_gemport_id(1024);
2567 traffic_queue_1->set_pbit_map("0b00000101");
2568 traffic_queue_1->set_aes_encryption(true);
2569 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2570 traffic_queue_1->set_priority(0);
2571 traffic_queue_1->set_weight(0);
2572 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2573 discard_config_1 = new tech_profile::DiscardConfig;
2574 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2575 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2576 tail_drop_discard_config_1->set_queue_size(8);
2577 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2578 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2579 }
2580
2581 virtual void TearDown() {
2582 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302583
2584 public:
2585 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
2586 gem_cfg_compltd_key k(0, gem_port_id);
2587 gem_cfg_complete_result res;
2588 res.pon_intf_id = 0;
2589 res.gem_port_id = gem_port_id;
2590 res.state = state;
2591 res.status = status;
2592
2593 uint32_t gem_cfg_key_check_counter = 1;
2594 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
2595 while(true) {
2596 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2597 it = gem_cfg_compltd_map.find(k);
2598
2599 if (it != gem_cfg_compltd_map.end()) {
2600 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2601 break;
2602 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
2603 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2604
2605 // We need to wait for some time to allow the Gem Cfg Request to be triggered
2606 // before we push the result.
2607 bcmos_usleep(6000);
2608 } else {
2609 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
2610 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2611 return 0;
2612 }
2613 gem_cfg_key_check_counter++;
2614 }
2615
2616 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2617 if (it->second) {
2618 it->second->push(res);
2619 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
2620 }
2621 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2622 return 0;
2623 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002624};
2625
2626// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2627TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002628 traffic_queues->set_uni_id(0);
2629 traffic_queues->set_port_no(16);
2630 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2631
2632 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2633 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2634
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302635 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2636 future<int> push_gem_cfg_complt = \
2637 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2638 Status status = future_res.get();
2639 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002640 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2641
2642 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2643 status = CreateTrafficQueues_(traffic_queues);
2644 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2645}
2646
2647// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2648TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2649 traffic_queues->set_uni_id(1);
2650 traffic_queues->set_port_no(32);
2651 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2652
2653 traffic_queue_2 = traffic_queues->add_traffic_queues();
2654 traffic_queue_2->set_gemport_id(1025);
2655 traffic_queue_2->set_pbit_map("0b00001010");
2656 traffic_queue_2->set_aes_encryption(true);
2657 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2658 traffic_queue_2->set_priority(1);
2659 traffic_queue_2->set_weight(0);
2660 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2661 discard_config_2 = new tech_profile::DiscardConfig;
2662 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2663 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2664 tail_drop_discard_config_2->set_queue_size(8);
2665 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2666 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2667 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2668
2669 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2670 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2671
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302672 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2673 future<int> push_gem_cfg_complt = \
2674 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2675 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2676 push_gem_cfg_complt = \
2677 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2678 Status status = future_res.get();
2679 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002680 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2681}
2682
2683// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2684TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2685 traffic_queues->set_uni_id(2);
2686 traffic_queues->set_port_no(16);
2687 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2688
2689 traffic_queue_2 = traffic_queues->add_traffic_queues();
2690 traffic_queue_2->set_gemport_id(1025);
2691 traffic_queue_2->set_pbit_map("0b10001010");
2692 traffic_queue_2->set_aes_encryption(true);
2693 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2694 traffic_queue_2->set_priority(1);
2695 traffic_queue_2->set_weight(0);
2696 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2697 discard_config_2 = new tech_profile::DiscardConfig;
2698 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2699 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2700 tail_drop_discard_config_2->set_queue_size(8);
2701 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2702 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2703 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2704
2705 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2706 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2707
2708 Status status = CreateTrafficQueues_(traffic_queues);
2709 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2710}
2711
2712// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2713TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2714 traffic_queues->set_uni_id(3);
2715 traffic_queues->set_port_no(16);
2716 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2717
2718 traffic_queue_2 = traffic_queues->add_traffic_queues();
2719 traffic_queue_2->set_gemport_id(1025);
2720 traffic_queue_2->set_pbit_map("0b00001010");
2721 traffic_queue_2->set_aes_encryption(true);
2722 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2723 traffic_queue_2->set_priority(1);
2724 traffic_queue_2->set_weight(0);
2725 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2726 discard_config_2 = new tech_profile::DiscardConfig;
2727 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2728 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2729 tail_drop_discard_config_2->set_queue_size(8);
2730 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2731 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2732 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2733
2734 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2735 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2736
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302737 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2738 future<int> push_gem_cfg_complt = \
2739 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2740 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2741 push_gem_cfg_complt = \
2742 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2743 Status status = future_res.get();
2744 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002745 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2746}
2747
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302748// Test 5 - CreateTrafficQueues-Downstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2749TEST_F(TestCreateTrafficQueues, CreateDownstreamPriorityQueueReachedMaxTMQMPCount) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002750 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2751 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2752 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2753
2754 traffic_queue_2 = traffic_queues->add_traffic_queues();
2755 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2756 traffic_queues->set_uni_id(uni_ids[i]);
2757 traffic_queues->set_port_no(port_nos[i]);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302758 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002759
2760 traffic_queue_2->set_gemport_id(1025);
2761 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2762 traffic_queue_2->set_aes_encryption(true);
2763 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2764 traffic_queue_2->set_priority(1);
2765 traffic_queue_2->set_weight(0);
2766 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2767 discard_config_2 = new tech_profile::DiscardConfig;
2768 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2769 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2770 tail_drop_discard_config_2->set_queue_size(8);
2771 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2772 traffic_queue_2->set_allocated_discard_config(discard_config_2);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302773 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002774
2775 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2776 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2777
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302778 future<Status> future_res = async(launch::async, CreateTrafficQueues_, traffic_queues);
2779 future<int> push_gem_cfg_complt = \
2780 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1024);
2781 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2782 push_gem_cfg_complt = \
2783 async(launch::async, TestCreateTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_ACTIVE, GEM_CFG_STATUS_SUCCESS, 1025);
2784 Status status = future_res.get();
2785 int res = push_gem_cfg_complt.get();
2786
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002787 if(i==16)
2788 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2789 else
2790 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2791 }
2792}
2793
2794// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2795TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2796 traffic_queues->set_uni_id(0);
2797 traffic_queues->set_port_no(16);
2798 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2799
2800 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2801 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2802
2803 Status status = CreateTrafficQueues_(traffic_queues);
2804 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2805}
2806
2807////////////////////////////////////////////////////////////////////////////
2808// For testing RemoveTrafficQueues functionality
2809////////////////////////////////////////////////////////////////////////////
2810
2811class TestRemoveTrafficQueues : public Test {
2812 protected:
2813 NiceMock<BalMocker> balMock;
2814 tech_profile::TrafficQueues* traffic_queues;
2815 tech_profile::TrafficQueue* traffic_queue_1;
2816 tech_profile::TrafficQueue* traffic_queue_2;
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302817 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002818
2819 virtual void SetUp() {
2820 traffic_queues = new tech_profile::TrafficQueues;
2821 traffic_queues->set_intf_id(0);
2822 traffic_queues->set_onu_id(1);
2823 traffic_queue_1 = traffic_queues->add_traffic_queues();
2824 traffic_queue_1->set_gemport_id(1024);
2825 traffic_queue_1->set_priority(0);
2826 }
2827
2828 virtual void TearDown() {
2829 }
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302830
2831 public:
2832 static int PushGemCfgResult(GemObjectState state, GemCfgStatus status, uint32_t gem_port_id) {
2833 gem_cfg_compltd_key k(0, gem_port_id);
2834 gem_cfg_complete_result res;
2835 res.pon_intf_id = 0;
2836 res.gem_port_id = gem_port_id;
2837 res.state = state;
2838 res.status = status;
2839
2840 uint32_t gem_cfg_key_check_counter = 1;
2841 std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *>::iterator it;
2842 while(true) {
2843 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2844 it = gem_cfg_compltd_map.find(k);
2845
2846 if (it != gem_cfg_compltd_map.end()) {
2847 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2848 break;
2849 } else if (it == gem_cfg_compltd_map.end() && gem_cfg_key_check_counter < MAX_GEM_CFG_KEY_CHECK) {
2850 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2851
2852 // We need to wait for some time to allow the Gem Cfg Request to be triggered
2853 // before we push the result.
2854 bcmos_usleep(6000);
2855 } else {
2856 OPENOLT_LOG(ERROR, openolt_log_id, "gem config key not found for gem_port_id = %u, pon_intf = %u\n", gem_port_id, 0);
2857 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2858 return 0;
2859 }
2860 gem_cfg_key_check_counter++;
2861 }
2862
2863 bcmos_fastlock_lock(&gem_cfg_wait_lock);
2864 if (it->second) {
2865 it->second->push(res);
2866 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked gem cfg result\n");
2867 }
2868 bcmos_fastlock_unlock(&gem_cfg_wait_lock, 0);
2869 return 0;
2870 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002871};
2872
2873// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2874TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002875 traffic_queues->set_uni_id(0);
2876 traffic_queues->set_port_no(16);
2877 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2878
2879 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2880 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2881
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302882 bcmolt_pon_interface_key pon_key;
2883 bcmolt_pon_interface_cfg pon_cfg;
2884 pon_key.pon_ni = pon_id;
2885 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2886 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2887 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2888 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +05302889 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302890
2891 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
2892 future<int> push_gem_cfg_complt = \
2893 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
2894
2895 Status status = future_res.get();
2896 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002897 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2898
2899 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2900 status = RemoveTrafficQueues_(traffic_queues);
2901 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2902}
2903
2904// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2905TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002906 traffic_queues->set_uni_id(0);
2907 traffic_queues->set_port_no(16);
2908 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2909
2910 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2911 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2912
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302913 Status status = RemoveTrafficQueues_(traffic_queues);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002914 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2915}
2916
2917// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2918TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2919 //Remove scheduler so that is_tm_sched_id_present api call will return false
2920 tech_profile::TrafficSchedulers* traffic_scheds;
2921 tech_profile::TrafficScheduler* traffic_sched;
2922 traffic_scheds = new tech_profile::TrafficSchedulers;
2923 traffic_scheds->set_intf_id(0);
2924 traffic_scheds->set_onu_id(1);
2925 traffic_scheds->set_uni_id(0);
2926 traffic_scheds->set_port_no(16);
2927 traffic_sched = traffic_scheds->add_traffic_scheds();
2928 traffic_sched->set_alloc_id(1024);
2929 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2930
2931 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2932 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2933 RemoveTrafficSchedulers_(traffic_scheds);
2934
2935 traffic_queues->set_uni_id(0);
2936 traffic_queues->set_port_no(16);
2937 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2938
2939 Status status = RemoveTrafficQueues_(traffic_queues);
2940 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2941}
2942
2943/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2944as it is getting referred by some other queues case */
2945TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2946 traffic_queues->set_uni_id(3);
2947 traffic_queues->set_port_no(16);
2948 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2949 traffic_queue_2 = traffic_queues->add_traffic_queues();
2950 traffic_queue_2->set_gemport_id(1025);
2951 traffic_queue_2->set_priority(1);
2952 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2953
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302954 bcmolt_pon_interface_key pon_key;
2955 bcmolt_pon_interface_cfg pon_cfg;
2956 pon_key.pon_ni = pon_id;
2957 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2958 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2959 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2960 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2961 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2962
2963 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
2964 future<int> push_gem_cfg_complt = \
2965 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
2966 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2967 push_gem_cfg_complt = \
2968 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
2969
2970 Status status = future_res.get();
2971 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002972 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2973}
2974
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302975/* Test 5 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, removing TM QMP as it
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002976is not getting referred by any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302977TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueRemovingTMQMP) {
2978 traffic_queues->set_uni_id(5);
2979 traffic_queues->set_port_no(80);
2980 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002981 traffic_queue_2 = traffic_queues->add_traffic_queues();
2982 traffic_queue_2->set_gemport_id(1025);
2983 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302984 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
2985
2986 bcmolt_pon_interface_key pon_key;
2987 bcmolt_pon_interface_cfg pon_cfg;
2988 pon_key.pon_ni = pon_id;
2989 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2990 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2991 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2992 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2993 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002994
2995 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2996 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2997
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05302998 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
2999 future<int> push_gem_cfg_complt = \
3000 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3001 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3002 push_gem_cfg_complt = \
3003 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3004
3005 Status status = future_res.get();
3006 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003007 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3008}
3009
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303010/* Test 6 - RemoveTrafficQueues-Downstream PRIORITY_TO_QUEUE, error while removing TM QMP
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003011having no reference to any other queues case */
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303012TEST_F(TestRemoveTrafficQueues, RemoveDownstreamPriorityQueueErrorRemovingTMQMP) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003013 traffic_queues->set_uni_id(4);
3014 traffic_queues->set_port_no(64);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303015 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003016 traffic_queue_2 = traffic_queues->add_traffic_queues();
3017 traffic_queue_2->set_gemport_id(1025);
3018 traffic_queue_2->set_priority(1);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303019 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003020
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303021 bcmolt_pon_interface_key pon_key;
3022 bcmolt_pon_interface_cfg pon_cfg;
3023 pon_key.pon_ni = pon_id;
3024 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
3025 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
3026 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3027 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3028 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003029
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +05303030 bcmos_errno olt_cfg_clear_res_success = BCM_ERR_OK;
3031 bcmos_errno olt_cfg_clear_res_failure = BCM_ERR_INTERNAL;
3032 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _))
3033 .WillOnce(Return(olt_cfg_clear_res_success))
3034 .WillOnce(Return(olt_cfg_clear_res_success))
3035 .WillOnce(Return(olt_cfg_clear_res_success))
3036 .WillOnce(Return(olt_cfg_clear_res_success))
3037 .WillRepeatedly(Return(olt_cfg_clear_res_failure));
3038
3039 future<Status> future_res = async(launch::async, RemoveTrafficQueues_, traffic_queues);
3040 future<int> push_gem_cfg_complt = \
3041 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1024);
3042 std::this_thread::sleep_for(std::chrono::milliseconds(100));
3043 push_gem_cfg_complt = \
3044 async(launch::async, TestRemoveTrafficQueues::PushGemCfgResult, GEM_OBJECT_STATE_NOT_CONFIGURED, GEM_CFG_STATUS_SUCCESS, 1025);
3045
3046 Status status = future_res.get();
3047 int res = push_gem_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05003048 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3049}
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003050
3051////////////////////////////////////////////////////////////////////////////
3052// For testing OnuItuPonAlarmSet functionality
3053////////////////////////////////////////////////////////////////////////////
3054
3055class TestOnuItuPonAlarmSet : public Test {
3056 protected:
3057 bcmolt_pon_ni pon_ni = 0;
3058 bcmolt_onu_id onu_id = 1;
3059
kesavandc1f2db92020-08-31 15:32:06 +05303060 config::OnuItuPonAlarm *onu_itu_pon_alarm_rt;
3061 config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config;
3062 config::OnuItuPonAlarm::SoakTime *soak_time_rt;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003063
kesavandc1f2db92020-08-31 15:32:06 +05303064 config::OnuItuPonAlarm *onu_itu_pon_alarm_rr;
3065 config::OnuItuPonAlarm::RateRangeConfig *rate_range_config;
3066 config::OnuItuPonAlarm::SoakTime *soak_time_rr;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003067
kesavandc1f2db92020-08-31 15:32:06 +05303068 config::OnuItuPonAlarm *onu_itu_pon_alarm_tc;
3069 config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config;
3070 config::OnuItuPonAlarm::SoakTime *soak_time_tc;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003071
3072 NiceMock<BalMocker> balMock;
3073
3074 virtual void SetUp() {
kesavandc1f2db92020-08-31 15:32:06 +05303075 onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm;
3076 rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig;
3077 soak_time_rt = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003078 onu_itu_pon_alarm_rt->set_pon_ni(0);
3079 onu_itu_pon_alarm_rt->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303080 onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3081 onu_itu_pon_alarm_rt->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003082 rate_threshold_config->set_rate_threshold_rising(1);
3083 rate_threshold_config->set_rate_threshold_falling(4);
3084 soak_time_rt->set_active_soak_time(2);
3085 soak_time_rt->set_clear_soak_time(2);
3086 rate_threshold_config->set_allocated_soak_time(soak_time_rt);
3087 onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config);
3088
kesavandc1f2db92020-08-31 15:32:06 +05303089 onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm;
3090 rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig;
3091 soak_time_rr = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003092 onu_itu_pon_alarm_rr->set_pon_ni(0);
3093 onu_itu_pon_alarm_rr->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303094 onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3095 onu_itu_pon_alarm_rr->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003096 rate_range_config->set_rate_range_lower(1);
3097 rate_range_config->set_rate_range_upper(4);
3098 soak_time_rr->set_active_soak_time(2);
3099 soak_time_rr->set_clear_soak_time(2);
3100 rate_range_config->set_allocated_soak_time(soak_time_rr);
3101 onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config);
3102
kesavandc1f2db92020-08-31 15:32:06 +05303103 onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm;
3104 value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig;
3105 soak_time_tc = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003106 onu_itu_pon_alarm_tc->set_pon_ni(0);
3107 onu_itu_pon_alarm_tc->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05303108 onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
3109 onu_itu_pon_alarm_tc->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08003110 value_threshold_config->set_threshold_limit(6);
3111 soak_time_tc->set_active_soak_time(2);
3112 soak_time_tc->set_clear_soak_time(2);
3113 value_threshold_config->set_allocated_soak_time(soak_time_tc);
3114 onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config);
3115 }
3116
3117 virtual void TearDown() {
3118 }
3119};
3120
3121// Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case
3122// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3123// the configured threshold boundary.
3124TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) {
3125 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3126 bcmolt_onu_key key = {};
3127 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3128 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3129 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3130 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3131 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3132
3133 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3134
3135 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3136 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3137}
3138
3139// Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case
3140// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
3141// the configured threshold boundary.
3142TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) {
3143 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3144 bcmolt_onu_key key = {};
3145 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3146 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
3147 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
3148 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
3149 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3150
3151 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3152
3153 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
3154 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3155}
3156
3157// Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case
3158// rate_range: The alarm is triggered if the stats delta value between samples deviates
3159// from the configured range.
3160TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) {
3161 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3162 bcmolt_onu_key key = {};
3163 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3164 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3165 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100;
3166 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50;
3167 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3168
3169 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3170
3171 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3172 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3173}
3174
3175// Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case
3176// rate_range: The alarm is triggered if the stats delta value between samples deviates
3177// from the configured range.
3178TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) {
3179 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3180 bcmolt_onu_key key = {};
3181 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3182 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
3183 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50;
3184 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100;
3185 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3186
3187 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3188
3189 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
3190 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3191}
3192
3193// Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case
3194// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3195// level. The alarm is cleared when the host read the stats.
3196TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) {
3197 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3198 bcmolt_onu_key key = {};
3199 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3200 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3201 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100;
3202 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
3203
3204 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3205
3206 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3207 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3208}
3209
3210// Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case
3211// value_threshold: The alarm is raised if the stats sample value becomes greater than this
3212// level. The alarm is cleared when the host read the stats.
3213TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) {
3214 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
3215 bcmolt_onu_key key = {};
3216 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
3217 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
3218 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1;
3219 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
3220
3221 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
3222
3223 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
3224 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3225}
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003226
3227////////////////////////////////////////////////////////////////////////////
3228// For testing DeleteGroup functionality
3229////////////////////////////////////////////////////////////////////////////
3230
3231class TestDeleteGroup : public Test {
3232 protected:
3233 uint32_t group_id = 1;
3234 NiceMock<BalMocker> balMock;
3235
3236 virtual void SetUp() {
3237 }
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003238};
3239
3240// Test 1 - DeleteGroup success case
3241TEST_F(TestDeleteGroup, DeleteGroupSuccess) {
3242 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3243 bcmos_errno group_cfg_clear_res = BCM_ERR_OK;
3244 bcmolt_group_cfg grp_cfg_out;
3245 bcmolt_group_key grp_key = {};
3246
3247 grp_key.id = group_id;
3248 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3249
3250 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3251 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3252 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3253 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3254 return group_cfg_get_res;
3255 }
3256 ));
3257
3258 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3259
3260 Status status = DeleteGroup_(group_id);
3261 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3262}
3263
3264// Test 2 - DeleteGroup failure case: Group does not exist
3265TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) {
3266 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3267 bcmolt_group_cfg grp_cfg_out;
3268 bcmolt_group_key grp_key = {};
3269
3270 grp_key.id = group_id;
3271 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3272
3273 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3274 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3275 grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED;
3276 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3277 return group_cfg_get_res;
3278 }
3279 ));
3280
3281 Status status = DeleteGroup_(group_id);
3282 ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND );
3283}
3284
3285// Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.)
3286TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) {
3287 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3288 bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL;
3289 bcmolt_group_cfg grp_cfg_out;
3290 bcmolt_group_key grp_key = {};
3291
3292 grp_key.id = group_id;
3293 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3294
3295 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3296 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3297 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3298 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3299 return group_cfg_get_res;
3300 }
3301 ));
3302
3303 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3304
3305 Status status = DeleteGroup_(group_id);
3306 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3307}
Jason Huang1d9cfce2020-05-20 22:58:47 +08003308
3309////////////////////////////////////////////////////////////////////////////
3310// For testing OnuLogicalDistanceZero functionality
3311////////////////////////////////////////////////////////////////////////////
3312class TestOnuLogicalDistanceZero : public Test {
3313 protected:
3314 NiceMock<BalMocker> balMock;
3315 bcmolt_pon_ni pon_ni = 0;
3316 openolt::OnuLogicalDistance *onu_logical_distance_zero;
3317
3318 virtual void SetUp() {
3319 onu_logical_distance_zero = new openolt::OnuLogicalDistance;
3320 onu_logical_distance_zero->set_intf_id(pon_ni);
3321 }
3322 virtual void TearDown() {
3323 }
3324};
3325
3326//
3327// Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case
3328//
3329TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) {
3330 bcmolt_pon_distance pon_distance = {};
3331 bcmolt_pon_interface_cfg pon_cfg;
3332 bcmolt_pon_interface_key key = {};
3333
3334 key.pon_ni = pon_ni;
3335 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3336 state.activate();
3337 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3338
3339 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3340 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3341
3342 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3343 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3344}
3345
3346// Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case
3347// The PON state is not ready for failure case
3348//
3349TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) {
3350 bcmolt_pon_distance pon_distance = {};
3351 bcmolt_pon_interface_cfg pon_cfg;
3352 bcmolt_pon_interface_key key = {};
3353
3354 key.pon_ni = pon_ni;
3355 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3356 state.deactivate();
3357 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
3358
3359 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3360 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3361}
3362
3363class TestOnuLogicalDistance : public Test {
3364 protected:
3365 NiceMock<BalMocker> balMock;
3366 bcmolt_pon_ni pon_ni = 0;
3367 bcmolt_onu_id onu_id = 1;
3368 openolt::OnuLogicalDistance *onu_logical_distance;
3369
3370 virtual void SetUp() {
3371 onu_logical_distance = new openolt::OnuLogicalDistance;
3372 onu_logical_distance->set_intf_id(pon_ni);
3373 onu_logical_distance->set_onu_id(onu_id);
3374 }
3375 virtual void TearDown() {
3376 }
3377};
3378
3379//
3380// Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case
3381//
3382TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) {
3383 bcmolt_pon_distance pon_distance = {};
3384 bcmolt_pon_interface_cfg pon_cfg;
3385 bcmolt_pon_interface_key key = {};
3386 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3387
3388 key.pon_ni = pon_ni;
3389 state.activate();
3390 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3391
3392 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3393 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3394
3395 bcmolt_onu_cfg onu_cfg;
3396 bcmolt_onu_key onu_key = {};
3397 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3398
3399 onu_key.pon_ni = pon_ni;
3400 onu_key.onu_id = onu_id;
3401 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3402 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
3403
3404 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3405 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3406
3407 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3408 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3409}
3410
3411// Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case
3412// The failure case is for retrieving ONU ranging time
3413//
3414TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) {
3415 bcmolt_pon_distance pon_distance = {};
3416 bcmolt_pon_interface_cfg pon_cfg;
3417 bcmolt_pon_interface_key key = {};
3418 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3419
3420 key.pon_ni = pon_ni;
3421 state.activate();
3422 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3423
3424 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3425 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3426
3427 bcmolt_onu_cfg onu_cfg;
3428 bcmolt_onu_key onu_key = {};
3429 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
3430
3431 onu_key.pon_ni = pon_ni;
3432 onu_key.onu_id = onu_id;
3433 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3434
3435 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3436 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3437
3438 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3439 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3440}
3441
3442// Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case
3443// The failure case is for ONU is not yet activated
3444//
3445TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) {
3446 bcmolt_pon_distance pon_distance = {};
3447 bcmolt_pon_interface_cfg pon_cfg;
3448 bcmolt_pon_interface_key key = {};
3449 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3450
3451 key.pon_ni = pon_ni;
3452 state.activate();
3453 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3454
3455 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3456 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3457
3458 bcmolt_onu_cfg onu_cfg;
3459 bcmolt_onu_key onu_key = {};
3460 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3461
3462 onu_key.pon_ni = pon_ni;
3463 onu_key.onu_id = onu_id;
3464 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3465
3466 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3467 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3468
3469 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
3470 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3471 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3472}
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -07003473
3474////////////////////////////////////////////////////////////////////////////
3475// For testing Secure Server functionality
3476////////////////////////////////////////////////////////////////////////////
3477
3478class TestSecureServer : public Test {
3479 protected:
3480 virtual void SetUp() {}
3481 virtual void TearDown() {}
3482};
3483
3484TEST_F(TestSecureServer, StartInsecureServer) {
3485 // const to prevent the following warning:
3486 // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
3487 const char *args[] = {"./openolt"};
3488 int argc = sizeof(args) / sizeof(args[0]);
3489 char **argv = const_cast<char**>(args);
3490
3491 bool ok = RunServer(argc, argv);
3492
3493 ASSERT_TRUE(ok);
3494
3495 OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n");
3496}
3497
3498TEST_F(TestSecureServer, StartWithInvalidTLSOption) {
3499 const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3500 int argc = sizeof(args) / sizeof(args[0]);
3501 char **argv = const_cast<char**>(args);
3502
3503 bool ok = RunServer(argc, argv);
3504
3505 ASSERT_FALSE(ok);
3506
3507 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n");
3508}
3509
3510TEST_F(TestSecureServer, CertificatesAreMissing) {
3511 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3512 int argc = sizeof(args) / sizeof(args[0]);
3513 char **argv = const_cast<char**>(args);
3514 const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'";
3515
3516 int res = std::system(cmd.c_str());
3517 if (res == 0) {
3518 std::cout << "directory ./keystore is deleted\n";
3519 } else {
3520 std::cout << "directory ./keystore is not existing\n";
3521 }
3522
3523 bool ok = RunServer(argc, argv);
3524
3525 ASSERT_FALSE(ok);
3526
3527 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n");
3528}
3529
3530TEST_F(TestSecureServer, StartWithValidTLSOption) {
3531 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3532 int argc = sizeof(args) / sizeof(args[0]);
3533 char **argv = const_cast<char**>(args);
3534 const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore";
3535 const std::string cmd_2 = "exec rm -rf './keystore'";
3536
3537 int res = std::system(cmd_1.c_str());
3538 if (res == 0) {
3539 std::cout << "directory ./keystore is copied from ./keystore-test\n";
3540
3541 bool ok = RunServer(argc, argv);
3542 ASSERT_TRUE(ok);
3543
3544 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n");
3545
3546 res = std::system(cmd_2.c_str());
3547 if (res == 0) {
3548 std::cout << "directory ./keystore is deleted\n";
3549 } else {
3550 std::cerr << "directory ./keystore could not be deleted\n";
3551 }
3552 } else {
3553 std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n';
3554 FAIL();
3555 }
3556}
Orhan Kupusogluec57af02021-05-12 12:38:17 +00003557
3558////////////////////////////////////////////////////////////////////////////
3559// For testing RxTx Power Read functionality
3560////////////////////////////////////////////////////////////////////////////
3561
3562class TestPowerRead : public Test {
3563 protected:
3564 virtual void SetUp() {
3565 std::array<char, 600> content = {};
3566 content.fill(0x00); // not required for 0x00
3567
3568 // for asfvolt16
3569 content[102] = 0x5D;
3570 content[103] = 0x38;
3571 content[104] = 0x1A;
3572 content[105] = 0xB5;
3573
3574 // for asgvolt64
3575 content[358] = 0x5C;
3576 content[359] = 0x82;
3577 content[360] = 0x04;
3578 content[361] = 0xBE;
3579
3580 std::ofstream test_file;
3581 test_file.open(file_name, std::ios::binary | std::ios::out);
3582 test_file.write(content.data(), content.size());
3583 test_file.close();
3584
3585 const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump;
3586
3587 int res = std::system(cmd.c_str());
3588 if (res == 0) {
3589 std::ifstream dump_file(hex_dump) ;
3590 std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() };
3591 std::cout << cmd << '\n';
3592 std::cout << hexdump << '\n';
3593 } else {
3594 std::cerr << "hexdump capture failed\n";
3595 }
3596 }
3597 virtual void TearDown() {
3598 std::remove(file_name.c_str());
3599 std::remove(hex_dump.c_str());
3600 }
3601
3602 const std::string file_name = "eeprom.bin";
3603 const std::string hex_dump = file_name + ".hexdump";
3604};
3605
3606TEST_F(TestPowerRead, TestAsfvolt16) {
3607 std::cout << "Test Power Reads on XGS-PON OLT:\n";
3608
3609 int port = 20;
3610 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3611
3612 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3613
3614 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3615
3616 port = 0;
3617 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3618
3619 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3620 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3621 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3622 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3623 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3624
3625 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3626
3627 ASSERT_TRUE(rxtx_power_raw.second);
3628
3629 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3630 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3631 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3632 << 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";
3633 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3634 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3635 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3636 << 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";
3637 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3638
3639 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3640 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256);
3641 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104);
3642 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3643 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20);
3644 ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837
3645 ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864
3646 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom");
3647}
3648
3649TEST_F(TestPowerRead, TestAsgvolt64) {
3650 std::cout << "Test Power Reads on GPON OLT:\n";
3651
3652 int port = 80;
3653 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3654
3655 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3656
3657 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3658
3659 port = 0;
3660 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3661
3662 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3663 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3664 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3665 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3666 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3667
3668 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3669
3670 ASSERT_TRUE(rxtx_power_raw.second);
3671
3672 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3673 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3674 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3675 << 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";
3676 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3677 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3678 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3679 << 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";
3680 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3681
3682 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3683 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600);
3684 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360);
3685 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3686 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74);
3687 ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214
3688 ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682
3689 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom");
3690}