blob: 650b497b8de72856c64b18447151f17882c374af [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
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050028extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
29extern dev_log_id openolt_log_id;
30extern bcmos_fastlock alloc_cfg_wait_lock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050031
Amit Ghoshfcad4d32019-11-13 10:24:55 +000032class TestOltEnable : public Test {
33 protected:
34 virtual void SetUp() {
35 }
36
37 virtual void TearDown() {
38 // Code here will be called immediately after each test
39 // (right before the destructor).
40 }
41};
42
43// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
44// bcmolt_cfg_get__bal_state_stub.
45ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
46
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050047// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
48// bcmolt_cfg_get__onu_state_stub.
49ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
50
51// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
52// bcmolt_cfg_get__tm_sched_stub.
53ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
54
55// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
56// bcmolt_cfg_get__pon_intf_stub.
57ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
58
59// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
60// bcmolt_cfg_get__nni_intf_stub.
61ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000062
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050063// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
64// bcmolt_cfg_get__flow_stub.
65ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
66
Amit Ghoshfcad4d32019-11-13 10:24:55 +000067// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050069MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
70MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
71MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
72MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050073MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000074
Amit Ghoshfcad4d32019-11-13 10:24:55 +000075// Test Fixture for OltEnable
76
77// Test 1: OltEnableSuccess case
78TEST_F(TestOltEnable, OltEnableSuccess){
79 // NiceMock is used to suppress 'WillByDefault' return errors.
80 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
81 NiceMock<BalMocker> balMock;
82 bcmos_errno host_init_res = BCM_ERR_OK;
83 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
84 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
85 bcmos_errno olt_oper_res = BCM_ERR_OK;
86
87 bcmolt_olt_cfg olt_cfg = { };
88 bcmolt_olt_key olt_key = { };
89 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
90 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
91
92 Status olt_enable_res;
93
94 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
95 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
96 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
97 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
98 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
99 .WillRepeatedly(Return(bal_cfg_get_res));
100 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
101
102 olt_enable_res = Enable_(1, NULL);
103 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
104}
105
106// Test 2: OltEnableFail_host_init_fail
107TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
108 // NiceMock is used to suppress 'WillByDefault' return errors.
109 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
110 NiceMock<BalMocker> balMock;
111 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
112
113 Status olt_enable_res;
114
115 // Ensure that the state of the OLT is in deactivated to start with..
116 state.deactivate();
117
118 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
119
120 olt_enable_res = Enable_(1, NULL);
121 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
122}
123
124// Test 3: OltEnableSuccess_PON_Device_Connected
125TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
126
127 // NiceMock is used to suppress 'WillByDefault' return errors.
128 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
129 NiceMock<BalMocker> balMock;
130 bcmos_errno host_init_res = BCM_ERR_OK;
131 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
132 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
133 bcmos_errno olt_oper_res = BCM_ERR_OK;
134
135 bcmolt_olt_cfg olt_cfg = { };
136 bcmolt_olt_key olt_key = { };
137 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
138 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
139
140 Status olt_enable_res;
141
142 // Ensure that the state of the OLT is in deactivated to start with..
143 state.deactivate();
144
145 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
146 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
147 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
148 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
149 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
150 .WillRepeatedly(Return(bal_cfg_get_res));
151
152 olt_enable_res = Enable_(1, NULL);
153 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
154
155}
156
157// Test 4: OltEnableFail_All_PON_Enable_Fail
158TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
159
160 // NiceMock is used to suppress 'WillByDefault' return errors.
161 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
162 NiceMock<BalMocker> balMock;
163 bcmos_errno host_init_res = BCM_ERR_OK;
164 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
165 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
166 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
167
168 bcmolt_olt_cfg olt_cfg = { };
169 bcmolt_olt_key olt_key = { };
170 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
171 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
172
173 Status olt_enable_res;
174
175 // Ensure that the state of the OLT is in deactivated to start with..
176 state.deactivate();
177
178 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
179 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
180 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
181 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
182 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
183 .WillRepeatedly(Return(bal_cfg_get_res));
184 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
185
186 olt_enable_res = Enable_(1, NULL);
187
188 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
189}
190
191// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
192TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
193
194 // NiceMock is used to suppress 'WillByDefault' return errors.
195 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
196 NiceMock<BalMocker> balMock;
197 bcmos_errno host_init_res = BCM_ERR_OK;
198 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
199 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
200 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
201 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
202
203 bcmolt_olt_cfg olt_cfg = { };
204 bcmolt_olt_key olt_key = { };
205 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
206 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
207
208 Status olt_enable_res;
209
210 // Ensure that the state of the OLT is in deactivated to start with..
211 state.deactivate();
212
213 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
214 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
215 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
216 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
217 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
218 .WillRepeatedly(Return(bal_cfg_get_res));
219 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
220 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
221 .WillOnce(Return(olt_oper_res_fail))
222 .WillRepeatedly(Return(olt_oper_res_success));
223 olt_enable_res = Enable_(1, NULL);
224
225 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
226}
227
228////////////////////////////////////////////////////////////////////////
229// For testing Enable/Disable functionality
230////////////////////////////////////////////////////////////////////////
231
Girish Gowdraddf9a162020-01-27 12:56:27 +0530232int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000233
234// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
235MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
236
237class TestOltDisableReenable : public Test {
238 protected:
239 virtual void SetUp() {
240 NiceMock<BalMocker> balMock;
241 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
242
243 bcmolt_olt_cfg olt_cfg = { };
244 bcmolt_olt_key olt_key = { };
245
246 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
247
Girish Gowdraddf9a162020-01-27 12:56:27 +0530248 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000249 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
250 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
251
252 ProbeDeviceCapabilities_();
253
254 }
255
256 virtual void TearDown() {
257 // Code here will be called immediately after each test
258 // (right before the destructor).
259 }
260};
261
262
263// Test Fixture for OltDisable
264
265// Test 1: OltDisableSuccess case
266TEST_F(TestOltDisableReenable, OltDisableSuccess){
267 // NiceMock is used to suppress 'WillByDefault' return errors.
268 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
269 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500270 bcmos_errno olt_oper_res = BCM_ERR_OK;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700271 bcmos_errno olt_get_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000272
273 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500274 state.deactivate();
275 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Girish Gowdrae1db2952021-05-04 00:16:54 -0700276 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_get_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000277 olt_disable_res = Disable_();
278 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
279
280}
281
282// Test 2: OltDisableAllPonFailed case
283TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
284 // NiceMock is used to suppress 'WillByDefault' return errors.
285 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
286 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500287 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700288 bcmos_errno pon_cfg_get_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000289
290 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500291 state.deactivate();
Girish Gowdrae1db2952021-05-04 00:16:54 -0700292 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(pon_cfg_get_res));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500293 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000294 olt_disable_res = Disable_();
295 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
296}
297
298
299// Test Fixture for OltReenable
300
301// Test 1: OltReenableSuccess case
302TEST_F(TestOltDisableReenable, OltReenableSuccess){
303 // NiceMock is used to suppress 'WillByDefault' return errors.
304 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
305 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500306 uint32_t pon_id = 0;
307 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
308 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000309 Status olt_reenable_res;
310
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500311 bcmolt_pon_interface_key pon_key;
312 bcmolt_pon_interface_cfg pon_cfg;
313 pon_key.pon_ni = pon_id;
314 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
315 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
316
317 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530318 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500319 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
320
321 bcmolt_tm_sched_cfg tm_sched_cfg;
322 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
323 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
324 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
325
326 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530327 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500328 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000329
330 olt_reenable_res = Reenable_();
331 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
332
333}
334
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500335// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000336TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
337 // NiceMock is used to suppress 'WillByDefault' return errors.
338 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
339 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500340 uint32_t pon_id = 0;
341 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000342 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000343 Status olt_reenable_res;
344
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500345 bcmolt_pon_interface_key pon_key;
346 bcmolt_pon_interface_cfg pon_cfg;
347 pon_key.pon_ni = pon_id;
348 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
349 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
350
351 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530352 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500353 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000354 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530355 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000356 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500357
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000358 olt_reenable_res = Reenable_();
359 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
360}
361
362////////////////////////////////////////////////////////////////////////////
363// For testing ProbeDeviceCapabilities functionality
364////////////////////////////////////////////////////////////////////////////
365class TestProbeDevCapabilities : public Test {
366 protected:
367 NiceMock<BalMocker> balMock;
368 bcmos_errno olt_res_success = BCM_ERR_OK;
369 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
370 bcmos_errno dev_res_success = BCM_ERR_OK;
371 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
372
373 virtual void SetUp() {
374 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
375
376 bcmolt_olt_cfg olt_cfg = { };
377 bcmolt_olt_key olt_key = { };
378
379 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
380
Girish Gowdraddf9a162020-01-27 12:56:27 +0530381 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000382 }
383
384 virtual void TearDown() {
385 }
386};
387
388// Test 1 - If querying the OLT fails, the method must return error
389TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
390
391 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
392 .WillOnce(Return(olt_res_fail));
393
394 Status query_status = ProbeDeviceCapabilities_();
395 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
396}
397
398// Test 2 - If all devices are queried successfully, the method must return Status::OK
399TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
400
401 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
402 .WillOnce(Return(olt_res_success));
403
404 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
405 .WillRepeatedly(Return(dev_res_success));
406
407 Status query_status = ProbeDeviceCapabilities_();
408
409 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
410}
411
412// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
413TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
414
415 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
416 .WillOnce(Return(olt_res_success));
417
418 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
419 .WillRepeatedly(Return(dev_res_fail));
420
421 Status query_status = ProbeDeviceCapabilities_();
422
423 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
424}
425
426// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
427TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
428
429 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
430 .WillOnce(Return(olt_res_success));
431
432 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
433 .WillOnce(Return(olt_res_success))
434 .WillRepeatedly(Return(dev_res_fail));
435
436 Status query_status = ProbeDeviceCapabilities_();
437
438 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
439}
440
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500441////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500442// For testing EnablePonIf functionality
443////////////////////////////////////////////////////////////////////////////
444
445class TestEnablePonIf : public Test {
446 protected:
447 uint32_t pon_id = 0;
448 NiceMock<BalMocker> balMock;
449
450 virtual void SetUp() {
451 }
452
453 virtual void TearDown() {
454 }
455};
456
457// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
458TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
459 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
460 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
461 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
462 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
463
464 bcmolt_pon_interface_key pon_key;
465 bcmolt_pon_interface_cfg pon_cfg;
466 pon_key.pon_ni = pon_id;
467 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
468 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
469 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
470 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
471
472 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
473 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
474
475 bcmolt_tm_sched_cfg tm_sched_cfg;
476 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
477 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
478 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
479 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
480 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
481
482 Status status = EnablePonIf_(pon_id);
483 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
484}
485
486// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
487TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
488 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
489 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
490 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
491 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
492
493 bcmolt_pon_interface_key pon_key;
494 bcmolt_pon_interface_cfg pon_cfg;
495 pon_key.pon_ni = pon_id;
496 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
497 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
498 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
499 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
500
501 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
502 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
503
504 bcmolt_tm_sched_cfg tm_sched_cfg;
505 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
506 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
507 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
508 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
509 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
510
511 Status status = EnablePonIf_(pon_id);
512 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
513}
514
515// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
516TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
517 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
518 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
519 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
520 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
521 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
522
523 bcmolt_pon_interface_key pon_key;
524 bcmolt_pon_interface_cfg pon_cfg;
525 pon_key.pon_ni = pon_id;
526 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
527 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
528 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
529 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
530
531 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
532 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
533 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
534
535 bcmolt_tm_sched_cfg tm_sched_cfg;
536 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
537 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
538 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
539 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
540 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
541
542 Status status = EnablePonIf_(pon_id);
543 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
544}
545
546// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
547TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
548 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
549 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
550 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
551 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
552 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
553 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
554
555 bcmolt_pon_interface_key pon_key;
556 bcmolt_pon_interface_cfg pon_cfg;
557 pon_key.pon_ni = pon_id;
558 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
559 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
560 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
561 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
562
563 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
564 .WillOnce(Return(olt_cfg_set_res))
565 .WillRepeatedly(Return(olt_cfg_set_err));
566 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
567 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
568
569 bcmolt_tm_sched_cfg tm_sched_cfg;
570 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
571 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
572 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
573 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
574 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
575
576 Status status = EnablePonIf_(pon_id);
577 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
578}
579
580// Test 5 - EnablePonIf already enabled success
581TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
582 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
583
584 bcmolt_pon_interface_key pon_key;
585 bcmolt_pon_interface_cfg pon_cfg;
586 pon_key.pon_ni = pon_id;
587 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
588 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
589 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
590 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
591
592 Status status = EnablePonIf_(pon_id);
593 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
594}
595
596// Test 6 - EnablePonIf - enable onu discovery failure case
597TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
598 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
599 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
600
601 bcmolt_pon_interface_key pon_key;
602 bcmolt_pon_interface_cfg pon_cfg;
603 pon_key.pon_ni = pon_id;
604 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
605 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
606 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
607 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
608 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
609
610 Status status = EnablePonIf_(pon_id);
611 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
612}
613
614// Test 7 - EnablePonIf failure case
615TEST_F(TestEnablePonIf, EnablePonIfFailed) {
616 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
617 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
618 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
619
620 bcmolt_pon_interface_key pon_key;
621 bcmolt_pon_interface_cfg pon_cfg;
622 pon_key.pon_ni = pon_id;
623 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
624 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
625 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
626 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
627 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
628 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
629
630 Status status = EnablePonIf_(pon_id);
631 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
632}
633
634////////////////////////////////////////////////////////////////////////////
635// For testing SetStateUplinkIf functionality
636////////////////////////////////////////////////////////////////////////////
637
638class TestSetStateUplinkIf : public Test {
639 protected:
640 uint32_t intf_id = 0;
641 NiceMock<BalMocker> balMock;
642
643 virtual void SetUp() {
644 }
645
646 virtual void TearDown() {
647 }
648};
649
650// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
651TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
652 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
653 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
654 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
655
656 bcmolt_nni_interface_key nni_key;
657 bcmolt_nni_interface_cfg nni_cfg;
658 nni_key.id = intf_id;
659 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
660 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
661 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
662 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
663
664 bcmolt_tm_sched_cfg tm_sched_cfg;
665 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
666 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
667 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
668 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
669 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
670 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
671
672 Status status = SetStateUplinkIf_(intf_id, true);
673 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
674}
675
676// Test 2 - SetStateUplinkIf, NNI interface already disabled case
677TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
678 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
679
680 bcmolt_nni_interface_key nni_key;
681 bcmolt_nni_interface_cfg nni_cfg;
682 nni_key.id = intf_id;
683 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
684 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
685 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
686 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
687
688 Status status = SetStateUplinkIf_(intf_id, false);
689 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
690}
691
692// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
693TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
694 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
695 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
696 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
697 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
698
699 bcmolt_nni_interface_key nni_key;
700 bcmolt_nni_interface_cfg nni_cfg;
701 nni_key.id = intf_id;
702 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
703 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
704 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
705 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
706
707 bcmolt_tm_sched_cfg tm_sched_cfg;
708 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
709 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
710 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
711 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
712 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
713 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
714 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
715
716 Status status = SetStateUplinkIf_(intf_id, true);
717 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
718}
719
720// Test 4 - SetStateUplinkIf Enable failure case
721TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
722 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
723 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
724
725 bcmolt_nni_interface_key nni_key;
726 bcmolt_nni_interface_cfg nni_cfg;
727 nni_key.id = intf_id;
728 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
729 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
730 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
731 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
732 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
733
734 Status status = SetStateUplinkIf_(intf_id, true);
735 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
736}
737
738// Test 5 - SetStateUplinkIf Disable success case
739TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
740 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
741 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
742
743 bcmolt_nni_interface_key nni_key;
744 bcmolt_nni_interface_cfg nni_cfg;
745 nni_key.id = intf_id;
746 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
747 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
748 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
749 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
750 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
751
752 Status status = SetStateUplinkIf_(intf_id, false);
753 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
754}
755
756// Test 6 - SetStateUplinkIf Disable failure case
757TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
758 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
759 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
760
761 bcmolt_nni_interface_key nni_key;
762 bcmolt_nni_interface_cfg nni_cfg;
763 nni_key.id = intf_id;
764 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
765 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
766 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
767 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
768 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
769
770 Status status = SetStateUplinkIf_(intf_id, false);
771 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
772}
773
774////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500775// For testing DisablePonIf functionality
776////////////////////////////////////////////////////////////////////////////
777
778class TestDisablePonIf : public Test {
779 protected:
780 virtual void SetUp() {
781 }
782
783 virtual void TearDown() {
784 }
785};
786
Girish Gowdrae1db2952021-05-04 00:16:54 -0700787// Test 1 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_ACTIVE_WORKING state
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500788TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
789 bcmos_errno olt_oper_res = BCM_ERR_OK;
790 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
791 NiceMock<BalMocker> balMock;
792 uint32_t pon_id=1;
793
Girish Gowdrae1db2952021-05-04 00:16:54 -0700794 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
795 bcmolt_pon_interface_cfg interface_obj;
796
797 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
798 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
799
800 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
801 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
802 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
803 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
804 return pon_intf_get_res;
805 }
806 ));
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500807 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
808 state.deactivate();
809 Status status = DisablePonIf_(pon_id);
810
811 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
812}
813
Girish Gowdrae1db2952021-05-04 00:16:54 -0700814// Test 2 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
815TEST_F(TestDisablePonIf, DisablePonIf_OperSubmitErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500816 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
817 NiceMock<BalMocker> balMock;
818 uint32_t pon_id=1;
819
Girish Gowdrae1db2952021-05-04 00:16:54 -0700820 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
821 bcmolt_pon_interface_cfg interface_obj;
822
823 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
824 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
825
826 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
827 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
828 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
829 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
830 return pon_intf_get_res;
831 }
832 ));
833
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500834 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
835 state.deactivate();
836 Status status = DisablePonIf_(pon_id);
837
838 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
839}
840
Girish Gowdrae1db2952021-05-04 00:16:54 -0700841// Test 3 - DisablePonIf Failure case - bcmolt_oper_submit returns BCM_ERR_INTERNAL
842TEST_F(TestDisablePonIf, DisablePonIf_CfgSetErrInternal) {
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500843 NiceMock<BalMocker> balMock;
844 uint32_t pon_id=1;
845 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
Girish Gowdrae1db2952021-05-04 00:16:54 -0700846
847 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
848 bcmolt_pon_interface_cfg interface_obj;
849
850 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
851 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
852
853 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
854 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
855 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
856 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
857 return pon_intf_get_res;
858 }
859 ));
860
861
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500862 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
863 state.deactivate();
864 Status status = DisablePonIf_(pon_id);
865
866 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
867}
868
Girish Gowdrae1db2952021-05-04 00:16:54 -0700869// Test 4 - DisablePonIf success case - PON port in BCMOLT_INTERFACE_STATE_INACTIVE state
870TEST_F(TestDisablePonIf, DisablePonIfSuccess_PonIntfInactive) {
871 bcmos_errno olt_oper_res = BCM_ERR_OK;
872 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
873 NiceMock<BalMocker> balMock;
874 uint32_t pon_id=1;
875
876 bcmos_errno pon_intf_get_res = BCM_ERR_OK;
877 bcmolt_pon_interface_cfg interface_obj;
878
879 bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)pon_id};
880 BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
881
882 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([pon_intf_get_res, &interface_obj] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
883 bcmolt_pon_interface_cfg* pon_cfg = (bcmolt_pon_interface_cfg*)cfg;
884 pon_cfg->data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
885 memcpy(&interface_obj, pon_cfg, sizeof(bcmolt_pon_interface_cfg));
886 return pon_intf_get_res;
887 }
888 ));
889 state.deactivate();
890 Status status = DisablePonIf_(pon_id);
891
892 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
893}
894
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500895////////////////////////////////////////////////////////////////////////////
896// For testing ActivateOnu functionality
897////////////////////////////////////////////////////////////////////////////
898
899class TestActivateOnu : public Test {
900 protected:
901 uint32_t pon_id = 0;
902 uint32_t onu_id = 1;
903 std::string vendor_id = "TWSH";
904 std::string vendor_specific = "80808080";
905 uint32_t pir = 1000000;
906 NiceMock<BalMocker> balMock;
907
908 virtual void SetUp() {
909 }
910
911 virtual void TearDown() {
912 }
913};
914
Girish Gowdra24297032020-03-23 12:32:37 -0700915// Test 1 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_NOT_CONFIGURED state
916TEST_F(TestActivateOnu, ActivateOnuSuccessOnuNotConfigured) {
917 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
918 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500919 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
Girish Gowdra24297032020-03-23 12:32:37 -0700920 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500921
922 bcmolt_onu_cfg onu_cfg;
923 bcmolt_onu_key onu_key;
924 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
Girish Gowdra24297032020-03-23 12:32:37 -0700925 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500926 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
927 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
928
929 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
930 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
Girish Gowdra24297032020-03-23 12:32:37 -0700931 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500932
kesavandc1f2db92020-08-31 15:32:06 +0530933 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500934 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
935}
936
Girish Gowdra24297032020-03-23 12:32:37 -0700937// Test 2 - ActivateOnu success case - ONU already in BCMOLT_ONU_STATE_ACTIVE state
938TEST_F(TestActivateOnu, ActivateOnuSuccessOnuAlreadyActive) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500939 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
940 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
941
942 bcmolt_onu_cfg onu_cfg;
943 bcmolt_onu_key onu_key;
944 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
945 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
946 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
947 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra24297032020-03-23 12:32:37 -0700948
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500949 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
950
kesavandc1f2db92020-08-31 15:32:06 +0530951 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500952 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
953}
954
Girish Gowdra24297032020-03-23 12:32:37 -0700955// Test 3 - ActivateOnu success case - ONU in BCMOLT_ONU_STATE_INACTIVE state
956TEST_F(TestActivateOnu, ActivateOnuSuccessOnuInactive) {
957 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
958 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
959 bcmos_errno onu_oper_submit_res = BCM_ERR_OK;
960
961 bcmolt_onu_cfg onu_cfg;
962 bcmolt_onu_key onu_key;
963 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
964 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
965 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
966 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
967
968 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
969 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
970
971
kesavandc1f2db92020-08-31 15:32:06 +0530972 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700973 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
974}
975
976// Test 4 - ActivateOnu failure case - ONU in invalid state (for this ex: BCMOLT_ONU_STATE_LOW_POWER_DOZE)
977TEST_F(TestActivateOnu, ActivateOnuFailOnuInvalidState) {
978 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
979 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
980
981 bcmolt_onu_cfg onu_cfg;
982 bcmolt_onu_key onu_key;
983 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
984 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_LOW_POWER_DOZE; // some invalid state which we dont recognize or process
985 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
986 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
987
988 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
989
kesavandc1f2db92020-08-31 15:32:06 +0530990 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -0700991 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
992}
993
994// Test 5 - ActivateOnu failure case - cfg_get failure
995TEST_F(TestActivateOnu, ActivateOnuFailCfgGetFail) {
996 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;// return cfg_get failure
997
998 bcmolt_onu_cfg onu_cfg;
999 bcmolt_onu_key onu_key;
1000 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1001 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1002 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1003 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1004
kesavandc1f2db92020-08-31 15:32:06 +05301005 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001006 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1007}
1008
1009// Test 6 - ActivateOnu failure case - oper_submit failure
1010TEST_F(TestActivateOnu, ActivateOnuFailOperSubmitFail) {
1011 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
1012 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1013 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
1014 bcmos_errno onu_oper_submit_res = BCM_ERR_INTERNAL; // return oper_submit failure
1015
1016 bcmolt_onu_cfg onu_cfg;
1017 bcmolt_onu_key onu_key;
1018 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1019 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_NOT_CONFIGURED;
1020 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1021 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1022
1023 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
1024 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
1025 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_submit_res));
1026
kesavandc1f2db92020-08-31 15:32:06 +05301027 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir, true);
Girish Gowdra24297032020-03-23 12:32:37 -07001028 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1029}
1030
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001031////////////////////////////////////////////////////////////////////////////
1032// For testing DeactivateOnu functionality
1033////////////////////////////////////////////////////////////////////////////
1034
1035class TestDeactivateOnu : public Test {
1036 protected:
1037 uint32_t pon_id = 0;
1038 uint32_t onu_id = 1;
1039 std::string vendor_id = "TWSH";
1040 std::string vendor_specific = "80808080";
1041 NiceMock<BalMocker> balMock;
1042
1043 virtual void SetUp() {
1044 }
1045
1046 virtual void TearDown() {
1047 }
1048};
1049
1050// Test 1 - DeactivateOnu success case
1051TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
1052 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1053 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1054
1055 bcmolt_onu_cfg onu_cfg;
1056 bcmolt_onu_key onu_key;
1057 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1058 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1059 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1060 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1061
1062 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1063
1064 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1065 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1066}
1067
1068// Test 2 - DeactivateOnu failure case
1069TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
1070 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1071 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1072
1073 bcmolt_onu_cfg onu_cfg;
1074 bcmolt_onu_key onu_key;
1075 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1076 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1077 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1078 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1079
1080 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1081
1082 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1083 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1084}
1085
1086////////////////////////////////////////////////////////////////////////////
1087// For testing DeleteOnu functionality
1088////////////////////////////////////////////////////////////////////////////
1089
1090class TestDeleteOnu : public Test {
1091 protected:
1092 uint32_t pon_id = 0;
1093 uint32_t onu_id = 1;
1094 std::string vendor_id = "TWSH";
1095 std::string vendor_specific = "80808080";
1096 NiceMock<BalMocker> balMock;
1097
1098 virtual void SetUp() {
1099 }
1100
1101 virtual void TearDown() {
1102 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301103 public:
1104 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
1105 onu_deactivate_complete_result res;
1106 res.pon_intf_id = 0;
1107 res.onu_id = 1;
1108 res.result = result;
1109 res.reason = reason;
1110 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
1111 // before we push the result.
1112 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1113 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
1114 onu_deact_compltd_key k(0, 1);
1115 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
1116 if (it == onu_deact_compltd_map.end()) {
1117 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
1118 } else {
1119 it->second->push(res);
1120 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
1121 }
1122 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
1123 return 0;
1124 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001125};
1126
1127// Test 1 - DeleteOnu success case
1128TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
1129 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1130 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1131 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1132
1133 bcmolt_onu_cfg onu_cfg;
1134 bcmolt_onu_key onu_key;
1135 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1136 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1137 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301138 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001139
1140 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1141 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1142
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301143 future<int> push_onu_deact_complt_res = \
1144 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1145 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1146 Status status = future_res.get();
1147 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001148 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1149}
1150
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301151// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1152TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001153 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1154 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1155 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1156
1157 bcmolt_onu_cfg onu_cfg;
1158 bcmolt_onu_key onu_key;
1159 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1160 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1161 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301162 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001163
1164 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1165 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1166
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301167 future<int> push_onu_deact_complt_res = \
1168 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1169 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1170
1171 Status status = future_res.get();
1172 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001173 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1174}
1175
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301176// Test 3 - DeleteOnu failure case - onu deactivation fails
1177TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
1178 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1179 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1180
1181 bcmolt_onu_cfg onu_cfg;
1182 bcmolt_onu_key onu_key;
1183 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1184 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1185 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301186 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301187
1188 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1189
1190 future<int> push_onu_deact_complt_res = \
1191 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1192 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1193
1194 Status status = future_res.get();
1195 int res = push_onu_deact_complt_res.get();
1196 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1197}
1198
1199// Test 4 - DeleteOnu failure case - onu deactivation timesout
1200TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
1201 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1202 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1203
1204 bcmolt_onu_cfg onu_cfg;
1205 bcmolt_onu_key onu_key;
1206 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1207 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1208 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301209 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301210
1211 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1212
1213 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1214
1215 Status status = future_res.get();
1216 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1217}
1218
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +05301219// Test 5 - DeleteOnu success case - Onu is Inactive so won't wait for onu deactivation response
1220TEST_F(TestDeleteOnu, DeleteOnuSuccessDontwaitforDeactivationResp) {
1221 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1222 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1223 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
1224
1225 bcmolt_onu_cfg onu_cfg;
1226 bcmolt_onu_key onu_key;
1227 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1228 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1229 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1230 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1231
1232 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1233 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1234
1235 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1236
1237 Status status = future_res.get();
1238 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1239}
1240
1241// Test 6 - DeleteOnu failure case - Failed to fetch Onu status
1242TEST_F(TestDeleteOnu, DeleteOnuFailureFetchOnuStatusFailed) {
1243 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
1244
1245 bcmolt_onu_cfg onu_cfg;
1246 bcmolt_onu_key onu_key;
1247 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1248 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
1249 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1250 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1251
1252 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1253
1254 Status status = future_res.get();
1255 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1256}
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301257
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001258////////////////////////////////////////////////////////////////////////////
1259// For testing OmciMsgOut functionality
1260////////////////////////////////////////////////////////////////////////////
1261
1262class TestOmciMsgOut : public Test {
1263 protected:
1264 uint32_t pon_id = 0;
1265 uint32_t onu_id = 1;
1266 std::string pkt = "omci-pkt";
1267 NiceMock<BalMocker> balMock;
1268
1269 virtual void SetUp() {
1270 }
1271
1272 virtual void TearDown() {
1273 }
1274};
1275
1276// Test 1 - OmciMsgOut success case
1277TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1278 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1279
1280 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1281
1282 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1283 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1284}
1285
1286// Test 1 - OmciMsgOut failure case
1287TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1288 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1289
1290 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1291
1292 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1293 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1294}
1295
1296////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001297// For testing FlowAdd functionality
1298////////////////////////////////////////////////////////////////////////////
1299
1300class TestFlowAdd : public Test {
1301 protected:
1302 int32_t access_intf_id = 0;
1303 int32_t onu_id = 1;
1304 int32_t uni_id = 0;
1305 uint32_t port_no = 16;
1306 uint32_t flow_id = 1;
1307 std::string flow_type = "upstream";
1308 int32_t alloc_id = 1024;
1309 int32_t network_intf_id = 0;
1310 int32_t gemport_id = 1024;
1311 int32_t priority_value = 0;
1312 uint64_t cookie = 0;
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301313 int32_t group_id = -1;
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001314 uint32_t tech_profile_id = 64;
Burak Gurdaga0523592021-02-24 15:17:47 +00001315 bool enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001316
1317 NiceMock<BalMocker> balMock;
1318 openolt::Flow* flow;
1319 openolt::Classifier* classifier;
1320 openolt::Action* action;
1321 openolt::ActionCmd* cmd;
1322
1323 bcmolt_flow_key flow_key;
1324 bcmolt_flow_cfg flow_cfg;
1325
1326 tech_profile::TrafficQueues* traffic_queues;
1327 tech_profile::TrafficQueue* traffic_queue_1;
1328 tech_profile::TrafficQueue* traffic_queue_2;
1329 tech_profile::DiscardConfig* discard_config_1;
1330 tech_profile::DiscardConfig* discard_config_2;
1331 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1332 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1333
1334
1335 virtual void SetUp() {
1336 classifier = new openolt::Classifier;
1337 action = new openolt::Action;
1338 cmd = new openolt::ActionCmd;
1339
1340 classifier->set_o_tpid(0);
1341 classifier->set_o_vid(7);
1342 classifier->set_i_tpid(0);
1343 classifier->set_i_vid(0);
1344 classifier->set_o_pbits(0);
1345 classifier->set_i_pbits(0);
1346 classifier->set_eth_type(0);
1347 classifier->set_ip_proto(0);
1348 classifier->set_src_port(0);
1349 classifier->set_dst_port(0);
1350 classifier->set_pkt_tag_type("single_tag");
1351
1352 action->set_o_vid(12);
1353 action->set_o_pbits(0);
1354 action->set_o_tpid(0);
1355 action->set_i_vid(0);
1356 action->set_i_pbits(0);
1357 action->set_i_tpid(0);
1358
1359 cmd->set_add_outer_tag(true);
1360 cmd->set_remove_outer_tag(false);
1361 cmd->set_trap_to_host(false);
1362 action->set_allocated_cmd(cmd);
1363
1364 flow_key.flow_id = 1;
1365 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1366 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1367 flow_cfg.data.onu_id=1;
1368 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1369 flow_cfg.data.svc_port_id=1024;
1370 flow_cfg.data.priority=0;
1371 flow_cfg.data.cookie=0;
1372 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1373 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1374 flow_cfg.data.ingress_intf.intf_id=0;
1375 flow_cfg.data.egress_intf.intf_id=0;
1376 flow_cfg.data.classifier.o_vid=7;
1377 flow_cfg.data.classifier.o_pbits=0;
1378 flow_cfg.data.classifier.i_vid=0;
1379 flow_cfg.data.classifier.i_pbits=0;
1380 flow_cfg.data.classifier.ether_type=0;
1381 flow_cfg.data.classifier.ip_proto=0;
1382 flow_cfg.data.classifier.src_port=0;
1383 flow_cfg.data.classifier.dst_port=0;
1384 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1385 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1386 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1387 flow_cfg.data.egress_qos.tm_sched.id=1020;
1388 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1389 flow_cfg.data.action.o_vid=12;
1390 flow_cfg.data.action.o_pbits=0;
1391 flow_cfg.data.action.i_vid=0;
1392 flow_cfg.data.action.i_pbits=0;
1393 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1394
1395 traffic_queues = new tech_profile::TrafficQueues;
1396 traffic_queues->set_intf_id(0);
1397 traffic_queues->set_onu_id(2);
1398 traffic_queue_1 = traffic_queues->add_traffic_queues();
1399 traffic_queue_1->set_gemport_id(1024);
1400 traffic_queue_1->set_pbit_map("0b00000101");
1401 traffic_queue_1->set_aes_encryption(true);
1402 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1403 traffic_queue_1->set_priority(0);
1404 traffic_queue_1->set_weight(0);
1405 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1406 discard_config_1 = new tech_profile::DiscardConfig;
1407 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1408 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1409 tail_drop_discard_config_1->set_queue_size(8);
1410 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1411 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1412
1413 traffic_queues->set_uni_id(0);
1414 traffic_queues->set_port_no(16);
1415
1416 traffic_queue_2 = traffic_queues->add_traffic_queues();
1417 traffic_queue_2->set_gemport_id(1025);
1418 traffic_queue_2->set_pbit_map("0b00001010");
1419 traffic_queue_2->set_aes_encryption(true);
1420 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1421 traffic_queue_2->set_priority(1);
1422 traffic_queue_2->set_weight(0);
1423 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1424 discard_config_2 = new tech_profile::DiscardConfig;
1425 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1426 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1427 tail_drop_discard_config_2->set_queue_size(8);
1428 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1429 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1430 }
1431
1432 virtual void TearDown() {
1433 }
1434};
1435
1436// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1437TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1438 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1439 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1440
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301441 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type,
Burak Gurdag2f2618c2020-04-23 13:20:30 +00001442 alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001443 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1444}
1445
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301446#ifdef FLOW_CHECKER
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001447// Test 2 - FlowAdd - Duplicate Flow case
1448TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1449 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1450 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1451 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1452
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301453 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 +00001454 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001455 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1456}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301457#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001458
1459// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1460TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1461 gemport_id = 1025;
1462
1463 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1464 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1465
1466 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1467 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1468 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1469
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301470 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 +00001471 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001472 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1473}
1474
1475// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1476TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1477 flow_type = "bidirectional";
1478
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301479 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 +00001480 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001481 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1482}
1483
1484// Test 5 - FlowAdd - Failure case(Invalid network setting)
1485TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1486 network_intf_id = -1;
1487
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301488 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 +00001489 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001490 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1491}
1492
1493// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1494TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1495 flow_id = 2;
1496
1497 classifier->set_eth_type(34958);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301498 action = new openolt::Action;
1499 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001500 cmd->set_trap_to_host(true);
1501 action->set_allocated_cmd(cmd);
1502
1503 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1504 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1505 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1506 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1507 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1508
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301509 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 +00001510 network_intf_id, gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001511 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1512}
1513
1514// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1515TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1516 flow_id = 3;
1517 gemport_id = 1025;
1518
1519 classifier->set_ip_proto(17);
1520 classifier->set_src_port(68);
1521 classifier->set_dst_port(67);
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301522 action = new openolt::Action;
1523 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001524 cmd->set_trap_to_host(true);
1525 action->set_allocated_cmd(cmd);
1526
1527 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1528 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1529 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1530 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1531 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1532
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301533 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 +00001534 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001535 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1536}
1537
1538// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1539TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1540 flow_id = 4;
1541 flow_type = "downstream";
1542
1543 classifier->set_o_vid(12);
1544 classifier->set_i_vid(7);
1545 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301546 action = new openolt::Action;
1547 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001548 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001549 cmd->set_remove_outer_tag(true);
1550 action->set_allocated_cmd(cmd);
1551
1552 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1553 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1554 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1555 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1556 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1557
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301558 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 +00001559 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001560 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1561}
1562
1563// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1564TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1565 onu_id = 2;
1566 flow_id = 5;
1567 alloc_id = 1025;
1568
1569 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1570 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1571
1572 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1573 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1574 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1575 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1576 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1577 CreateTrafficQueues_(traffic_queues);
1578
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301579 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 +00001580 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001581 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1582}
1583
1584// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1585TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1586 onu_id = 2;
1587 flow_id = 6;
1588 flow_type = "downstream";
1589 alloc_id = 1025;
1590
1591 classifier->set_o_vid(12);
1592 classifier->set_i_vid(7);
1593 classifier->set_pkt_tag_type("double_tag");
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301594 action = new openolt::Action;
1595 cmd = new openolt::ActionCmd;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001596 action->set_o_vid(0);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001597 cmd->set_remove_outer_tag(true);
1598 action->set_allocated_cmd(cmd);
1599
1600 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1601 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1602
1603 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1604 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1605 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1606 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1607 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1608 CreateTrafficQueues_(traffic_queues);
1609
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301610 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 +00001611 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id);
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001612 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1613}
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05301614
Burak Gurdaga0523592021-02-24 15:17:47 +00001615// Test 11 - FlowAdd - success case (Downstream-Encrypted GEM)
1616TEST_F(TestFlowAdd, FlowAddDownstreamEncryptedGemSuccess) {
1617 onu_id = 2;
1618 flow_id = 7;
1619 flow_type = "downstream";
1620 alloc_id = 1025;
1621 enable_encryption = true;
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001622
Burak Gurdaga0523592021-02-24 15:17:47 +00001623 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1624 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1625 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1626 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1627 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1628
1629 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1630 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1631 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1632}
1633
1634// Test 12 - FlowAdd - success case (Downstream-Unencrypted GEM - prints warning that encryption will not applied)
1635TEST_F(TestFlowAdd, FlowAddDownstreamUnencryptedGemWarning) {
1636 onu_id = 2;
1637 flow_id = 8;
1638 flow_type = "downstream";
1639 alloc_id = 1025;
1640 enable_encryption = false;
1641
1642 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1643 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1644 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1645 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1646 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1647
1648 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1649 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1650 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1651}
1652
1653// Test 13 - FlowAdd - success case (Upstream-Encrypted GEM - prints warning that encryption will not applied)
1654TEST_F(TestFlowAdd, FlowAddUpstreamEncryptedGemWarning) {
1655 onu_id = 2;
1656 flow_id = 9;
1657 flow_type = "upstream";
1658 alloc_id = 1025;
1659 enable_encryption = true;
1660
1661 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1662 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1663 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1664 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1665 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1666
1667 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1668 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1669 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1670}
1671
1672// Test 14 - FlowAdd - success case (Multicast-Encrypted GEM - prints warning that encryption will not applied)
1673TEST_F(TestFlowAdd, FlowAddMulticastEncryptedGemWarning) {
1674 onu_id = 2;
1675 flow_id = 10;
1676 flow_type = "multicast";
1677 alloc_id = 1025;
1678 enable_encryption = true;
1679
1680 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1681 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1682 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1683 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1684 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1685
1686 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id,
1687 gemport_id, *classifier, *action, priority_value, cookie, group_id, tech_profile_id, enable_encryption);
1688 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1689}
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001690////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001691// For testing OnuPacketOut functionality
1692////////////////////////////////////////////////////////////////////////////
1693
1694class TestOnuPacketOut : public Test {
1695 protected:
1696 uint32_t pon_id = 0;
1697 uint32_t onu_id = 1;
1698 std::string pkt = "omci-pkt";
1699 NiceMock<BalMocker> balMock;
1700
1701 virtual void SetUp() {
1702 }
1703
1704 virtual void TearDown() {
1705 }
1706};
1707
1708// Test 1 - OnuPacketOut success case
1709TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1710 uint32_t port_no = 16;
1711 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001712
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001713 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001714 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1715
1716 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1717 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1718}
1719
1720// Test 2 - OnuPacketOut Port number as 0 case
1721TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1722 uint32_t port_no = 0;
1723 uint32_t gemport_id = 1024;
1724
1725 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1726 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1727}
1728
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001729// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1730TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1731 uint32_t port_no = 16;
1732 uint32_t gemport_id = 0;
1733
1734 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1735 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1736
1737 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1738 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1739}
1740
1741// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1742TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1743 uint32_t port_no = 64;
1744 uint32_t gemport_id = 0;
1745
1746 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1747 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1748
1749 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1750 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1751}
1752
1753////////////////////////////////////////////////////////////////////////////
1754// For testing FlowRemove functionality
1755////////////////////////////////////////////////////////////////////////////
1756
1757class TestFlowRemove : public Test {
1758 protected:
1759 NiceMock<BalMocker> balMock;
1760
1761 virtual void SetUp() {
1762 }
1763
1764 virtual void TearDown() {
1765 }
1766};
1767
1768// Test 1 - FlowRemove - Failure case
1769TEST_F(TestFlowRemove, FlowRemoveFailure) {
1770 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1771 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1772
1773 Status status = FlowRemove_(1, "upstream");
1774 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1775}
1776
1777// Test 2 - FlowRemove - success case
1778TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1779 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1780 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1781
1782 Status status = FlowRemove_(1, "upstream");
1783 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1784}
1785
1786////////////////////////////////////////////////////////////////////////////
1787// For testing UplinkPacketOut functionality
1788////////////////////////////////////////////////////////////////////////////
1789
1790class TestUplinkPacketOut : public Test {
1791 protected:
1792 uint32_t pon_id = 0;
1793 std::string pkt = "omci-pkt";
1794 NiceMock<BalMocker> balMock;
1795
1796 bcmolt_flow_key flow_key;
1797 bcmolt_flow_cfg flow_cfg;
1798
1799 virtual void SetUp() {
1800 flow_key.flow_id = 1;
1801 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1802 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1803 flow_cfg.data.onu_id=1;
1804 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1805 flow_cfg.data.svc_port_id=1024;
1806 flow_cfg.data.priority=0;
1807 flow_cfg.data.cookie=0;
1808 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1809 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1810 flow_cfg.data.ingress_intf.intf_id=0;
1811 flow_cfg.data.egress_intf.intf_id=0;
1812 flow_cfg.data.classifier.o_vid=7;
1813 flow_cfg.data.classifier.o_pbits=0;
1814 flow_cfg.data.classifier.i_vid=0;
1815 flow_cfg.data.classifier.i_pbits=0;
1816 flow_cfg.data.classifier.ether_type=0;
1817 flow_cfg.data.classifier.ip_proto=0;
1818 flow_cfg.data.classifier.src_port=0;
1819 flow_cfg.data.classifier.dst_port=0;
1820 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1821 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1822 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1823 flow_cfg.data.egress_qos.tm_sched.id=1020;
1824 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1825 flow_cfg.data.action.o_vid=12;
1826 flow_cfg.data.action.o_pbits=0;
1827 flow_cfg.data.action.i_vid=0;
1828 flow_cfg.data.action.i_pbits=0;
1829 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1830 }
1831
1832 virtual void TearDown() {
1833 }
1834};
1835
1836// Test 1 - UplinkPacketOut success case
1837TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1838 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1839 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1840 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1841 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1842 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1843
1844 Status status = UplinkPacketOut_(pon_id, pkt);
1845 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1846}
1847
1848// Test 2 - UplinkPacketOut Failure case
1849TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1850 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1851 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1852 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1853 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1854 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1855
1856 Status status = UplinkPacketOut_(pon_id, pkt);
1857 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1858}
1859
1860// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1861TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1862 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1863
1864 FlowRemove_(2, "upstream");
1865 FlowRemove_(3, "upstream");
1866 FlowRemove_(4, "downstream");
1867 FlowRemove_(5, "upstream");
1868 FlowRemove_(6, "downstream");
Burak Gurdaga0523592021-02-24 15:17:47 +00001869 FlowRemove_(7, "downstream");
1870 FlowRemove_(8, "downstream");
1871 FlowRemove_(9, "upstream");
1872 FlowRemove_(10, "multicast");
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001873
1874 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1875 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1876 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1877
1878 Status status = UplinkPacketOut_(pon_id, pkt);
1879 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1880}
1881
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001882////////////////////////////////////////////////////////////////////////////
1883// For testing CreateTrafficSchedulers functionality
1884////////////////////////////////////////////////////////////////////////////
1885
1886class TestCreateTrafficSchedulers : public Test {
1887 protected:
1888 NiceMock<BalMocker> balMock;
1889 tech_profile::TrafficSchedulers* traffic_scheds;
1890 tech_profile::TrafficScheduler* traffic_sched;
1891 tech_profile::SchedulerConfig* scheduler;
1892 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1893
1894 virtual void SetUp() {
1895 traffic_scheds = new tech_profile::TrafficSchedulers;
1896 traffic_scheds->set_intf_id(0);
1897 traffic_scheds->set_onu_id(1);
1898 traffic_scheds->set_uni_id(0);
1899 traffic_scheds->set_port_no(16);
1900 traffic_sched = traffic_scheds->add_traffic_scheds();
1901 traffic_sched->set_alloc_id(1024);
1902 scheduler = new tech_profile::SchedulerConfig;
1903 scheduler->set_priority(0);
1904 scheduler->set_weight(0);
1905 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1906 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1907 traffic_shaping_info->set_cbs(60536);
1908 traffic_shaping_info->set_pbs(65536);
1909 traffic_shaping_info->set_gir(10000);
1910 }
1911
1912 virtual void TearDown() {
1913 }
1914
1915 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301916 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1917 alloc_cfg_compltd_key k(0, 1024);
1918 alloc_cfg_complete_result res;
1919 res.pon_intf_id = 0;
1920 res.alloc_id = 1024;
1921 res.state = state;
1922 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001923
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301924 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1925 // before we push the result.
1926 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1927 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1928 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1929 if (it == alloc_cfg_compltd_map.end()) {
1930 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 -05001931 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301932 it->second->push(res);
1933 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001934 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301935 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1936 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001937 }
1938};
1939
1940// Test 1 - CreateTrafficSchedulers-Upstream success case
1941TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1942 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1943 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1944 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1945 traffic_sched->set_allocated_scheduler(scheduler);
1946 traffic_shaping_info->set_cir(64000);
1947 traffic_shaping_info->set_pir(128000);
1948 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1949
1950 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1951 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1952
1953 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301954 future<int> push_alloc_cfg_complt = \
1955 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001956
1957 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301958 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001959 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1960}
1961
1962// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1963TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1964 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1965 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1966 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1967 traffic_sched->set_allocated_scheduler(scheduler);
1968 traffic_shaping_info->set_cir(64000);
1969 traffic_shaping_info->set_pir(128000);
1970 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1971
1972 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1973 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1974
1975 Status status = CreateTrafficSchedulers_(traffic_scheds);
1976 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1977}
1978
1979// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1980TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1981 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1982 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1983 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1984 traffic_sched->set_allocated_scheduler(scheduler);
1985 traffic_shaping_info->set_cir(64000);
1986 traffic_shaping_info->set_pir(128000);
1987 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1988
1989 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1990 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1991
1992 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301993 future<int> push_alloc_cfg_complt = \
1994 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001995
1996 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301997 int res = push_alloc_cfg_complt.get();
1998
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001999 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2000}
2001
2002// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
2003TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
2004 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2005 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2006 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2007 traffic_sched->set_allocated_scheduler(scheduler);
2008 traffic_shaping_info->set_cir(64000);
2009 traffic_shaping_info->set_pir(128000);
2010 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2011
2012 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2013 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2014
2015 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302016 future<int> push_alloc_cfg_complt = \
2017 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002018
2019 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302020 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002021 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2022}
2023
2024// Test 5 - CreateTrafficSchedulers-Upstream Failure case
2025TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
2026 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2027 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2028 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2029 traffic_sched->set_allocated_scheduler(scheduler);
2030 traffic_shaping_info->set_cir(64000);
2031 traffic_shaping_info->set_pir(128000);
2032 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2033
2034 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2035 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2036
2037 Status status = CreateTrafficSchedulers_(traffic_scheds);
2038 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2039}
2040
2041// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
2042TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
2043 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2044 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2045 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2046 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002047 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002048 traffic_shaping_info->set_cir(64000);
2049 traffic_shaping_info->set_pir(0);
2050 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2051
2052 Status status = CreateTrafficSchedulers_(traffic_scheds);
2053 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2054}
2055
2056// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
2057TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
2058 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2059 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2060 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2061 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002062 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002063 traffic_shaping_info->set_cir(64000);
2064 traffic_shaping_info->set_pir(32000);
2065 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2066
2067 Status status = CreateTrafficSchedulers_(traffic_scheds);
2068 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2069}
2070
2071// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
2072TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
2073 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2074 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2075 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2076 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002077 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002078 traffic_shaping_info->set_cir(64000);
2079 traffic_shaping_info->set_pir(64000);
2080 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2081
2082 Status status = CreateTrafficSchedulers_(traffic_scheds);
2083 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2084}
2085
2086// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
2087TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
2088 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2089 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2090 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2091 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002092 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002093 traffic_shaping_info->set_cir(64000);
2094 traffic_shaping_info->set_pir(0);
2095 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2096
2097 Status status = CreateTrafficSchedulers_(traffic_scheds);
2098 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2099}
2100
2101// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
2102TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
2103 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2104 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2105 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2106 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002107 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002108 traffic_shaping_info->set_cir(0);
2109 traffic_shaping_info->set_pir(32000);
2110 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2111
2112 Status status = CreateTrafficSchedulers_(traffic_scheds);
2113 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2114}
2115
2116// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
2117TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
2118 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2119 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2120 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2121 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002122 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002123 traffic_shaping_info->set_cir(64000);
2124 traffic_shaping_info->set_pir(32000);
2125 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2126
2127 Status status = CreateTrafficSchedulers_(traffic_scheds);
2128 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2129}
2130
2131// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
2132TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
2133 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2134 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
2135 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2136 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002137 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002138 traffic_shaping_info->set_cir(64000);
2139 traffic_shaping_info->set_pir(64000);
2140 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2141
2142 Status status = CreateTrafficSchedulers_(traffic_scheds);
2143 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2144}
2145
2146// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
2147TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
2148 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2149 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2150 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2151 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002152 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002153 traffic_shaping_info->set_cir(64000);
2154 traffic_shaping_info->set_pir(0);
2155 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2156
2157 Status status = CreateTrafficSchedulers_(traffic_scheds);
2158 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2159}
2160
2161// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
2162TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
2163 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2164 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2165 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2166 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002167 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002168 traffic_shaping_info->set_cir(0);
2169 traffic_shaping_info->set_pir(32000);
2170 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2171
2172 Status status = CreateTrafficSchedulers_(traffic_scheds);
2173 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2174}
2175
Burak Gurdag623fada2021-04-20 22:02:36 +00002176// Test 15 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW > Guaranteed BW) case
2177TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002178 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2179 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2180 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2181 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002182 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002183 traffic_shaping_info->set_cir(64000);
2184 traffic_shaping_info->set_pir(128000);
2185 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2186
Burak Gurdag623fada2021-04-20 22:02:36 +00002187 Status status = CreateTrafficSchedulers_(traffic_scheds);
2188 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002189}
2190
Burak Gurdag623fada2021-04-20 22:02:36 +00002191// Test 16 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW < Guaranteed BW) case
2192TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwFailure) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002193 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2194 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2195 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2196 traffic_sched->set_allocated_scheduler(scheduler);
Burak Gurdag623fada2021-04-20 22:02:36 +00002197 traffic_shaping_info->set_gir(0);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002198 traffic_shaping_info->set_cir(64000);
2199 traffic_shaping_info->set_pir(32000);
2200 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2201
Burak Gurdag623fada2021-04-20 22:02:36 +00002202 Status status = CreateTrafficSchedulers_(traffic_scheds);
2203 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2204}
2205
2206// Test 17 - CreateTrafficSchedulers-Upstream Failure (Invalid AdditionalBW value) case
2207TEST_F(TestCreateTrafficSchedulers, AdditionalBW_InvalidValueFailure) {
2208 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2209 scheduler->set_additional_bw(9);
2210 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2211 traffic_sched->set_allocated_scheduler(scheduler);
2212 traffic_shaping_info->set_gir(0);
2213 traffic_shaping_info->set_cir(64000);
2214 traffic_shaping_info->set_pir(128000);
2215 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2216
2217 Status status = CreateTrafficSchedulers_(traffic_scheds);
2218 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2219}
2220
2221// Test 18 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW = Fixed BW) case
2222TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWEqFixedBwSuccess) {
2223 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
2224 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
2225 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2226 traffic_sched->set_allocated_scheduler(scheduler);
2227 traffic_shaping_info->set_gir(64000);
2228 traffic_shaping_info->set_cir(0);
2229 traffic_shaping_info->set_pir(64000);
2230 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2231
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002232 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2233 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2234
2235 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302236 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002237 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2238
2239 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302240 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002241 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2242}
2243
Burak Gurdag623fada2021-04-20 22:02:36 +00002244// Test 19 - CreateTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002245TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
2246 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2247 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2248 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2249 traffic_sched->set_allocated_scheduler(scheduler);
2250 traffic_shaping_info->set_cir(64000);
2251 traffic_shaping_info->set_pir(128000);
2252 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2253
2254 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2255 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2256
2257 Status status = CreateTrafficSchedulers_(traffic_scheds);
2258 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2259}
2260
Burak Gurdag623fada2021-04-20 22:02:36 +00002261// Test 20 - CreateTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002262TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
2263 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2264 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2265 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2266 traffic_sched->set_allocated_scheduler(scheduler);
2267 traffic_shaping_info->set_cir(64000);
2268 traffic_shaping_info->set_pir(128000);
2269 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2270
2271 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2272 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2273
2274 Status status = CreateTrafficSchedulers_(traffic_scheds);
2275 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2276}
2277
Burak Gurdag623fada2021-04-20 22:02:36 +00002278// Test 21 - CreateTrafficSchedulers-Invalid direction Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002279TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
2280 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2281 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2282 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
2283 traffic_sched->set_allocated_scheduler(scheduler);
2284 traffic_shaping_info->set_cir(64000);
2285 traffic_shaping_info->set_pir(128000);
2286 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2287
2288 Status status = CreateTrafficSchedulers_(traffic_scheds);
2289 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2290}
2291
2292////////////////////////////////////////////////////////////////////////////
2293// For testing RemoveTrafficSchedulers functionality
2294////////////////////////////////////////////////////////////////////////////
2295
2296class TestRemoveTrafficSchedulers : public Test {
2297 protected:
2298 NiceMock<BalMocker> balMock;
2299 tech_profile::TrafficSchedulers* traffic_scheds;
2300 tech_profile::TrafficScheduler* traffic_sched;
2301 tech_profile::SchedulerConfig* scheduler;
2302 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2303 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302304 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002305
2306 virtual void SetUp() {
2307 traffic_scheds = new tech_profile::TrafficSchedulers;
2308 traffic_scheds->set_intf_id(0);
2309 traffic_scheds->set_onu_id(1);
2310 traffic_scheds->set_uni_id(0);
2311 traffic_scheds->set_port_no(16);
2312 traffic_sched = traffic_scheds->add_traffic_scheds();
2313 traffic_sched->set_alloc_id(1025);
2314 scheduler = new tech_profile::SchedulerConfig;
2315 scheduler->set_priority(0);
2316 scheduler->set_weight(0);
2317 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2318 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2319 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2320 traffic_shaping_info->set_cir(64000);
2321 traffic_shaping_info->set_pir(128000);
2322 traffic_shaping_info->set_cbs(60536);
2323 traffic_shaping_info->set_pbs(65536);
2324 traffic_shaping_info->set_gir(10000);
2325 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2326 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2327 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2328 }
2329
2330 virtual void TearDown() {
2331 }
2332
2333 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302334 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2335 alloc_cfg_compltd_key k(0, 1025);
2336 alloc_cfg_complete_result res;
2337 res.pon_intf_id = 0;
2338 res.alloc_id = 1025;
2339 res.state = state;
2340 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002341
Thiyagarajan Subramani1744c922020-02-16 18:55:02 +05302342 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
2343 // before we push the result.
2344 std::this_thread::sleep_for(std::chrono::milliseconds(100));
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302345 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2346 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2347 if (it == alloc_cfg_compltd_map.end()) {
2348 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 -05002349 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302350 it->second->push(res);
2351 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002352 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302353 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2354 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002355 }
2356};
2357
2358// Test 1 - RemoveTrafficSchedulers-Upstream success case
2359TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2360 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2361 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2362 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2363
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302364 bcmolt_pon_interface_key pon_key;
2365 bcmolt_pon_interface_cfg pon_cfg;
2366 pon_key.pon_ni = pon_id;
2367 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2368 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2369 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2370 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2371 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2372
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002373 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302374 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002375 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2376
2377 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302378 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002379 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2380}
2381
2382// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2383TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2384 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2385 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2386 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2387
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302388 bcmolt_pon_interface_key pon_key;
2389 bcmolt_pon_interface_cfg pon_cfg;
2390 pon_key.pon_ni = pon_id;
2391 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2392 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2393 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2394 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2395 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2396
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002397 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302398 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002399 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2400
2401 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302402 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002403 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2404}
2405
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302406// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2407TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2408 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2409 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2410 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2411
2412 bcmolt_pon_interface_key pon_key;
2413 bcmolt_pon_interface_cfg pon_cfg;
2414 pon_key.pon_ni = pon_id;
2415 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2416 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2417 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2418 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2419 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2420
2421 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2422
2423 Status status = future_res.get();
2424 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2425}
2426
2427// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2428TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2429 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2430 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2431 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2432
2433 bcmolt_pon_interface_key pon_key;
2434 bcmolt_pon_interface_cfg pon_cfg;
2435 pon_key.pon_ni = pon_id;
2436 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2437 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2438 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2439 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2440 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2441
2442 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2443
2444 Status status = future_res.get();
2445 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2446}
2447
2448// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002449TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2450 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2451
2452 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2453 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2454
2455 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2456 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2457}
2458
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302459// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002460TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2461 //Create Scheduler
2462 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2463 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2464 traffic_sched->set_allocated_scheduler(scheduler);
2465 CreateTrafficSchedulers_(traffic_scheds);
2466
2467 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2468 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2469
2470 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2471 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2472}
2473
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302474// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002475TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2476 //Create Scheduler
2477 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2478 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2479 traffic_sched->set_allocated_scheduler(scheduler);
2480 CreateTrafficSchedulers_(traffic_scheds);
2481
2482 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2483 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2484
2485 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2486 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2487}
2488
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302489// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002490TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2491 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2492
2493 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2494 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2495}
2496
2497////////////////////////////////////////////////////////////////////////////
2498// For testing CreateTrafficQueues functionality
2499////////////////////////////////////////////////////////////////////////////
2500
2501class TestCreateTrafficQueues : public Test {
2502 protected:
2503 NiceMock<BalMocker> balMock;
2504 tech_profile::TrafficQueues* traffic_queues;
2505 tech_profile::TrafficQueue* traffic_queue_1;
2506 tech_profile::TrafficQueue* traffic_queue_2;
2507 tech_profile::DiscardConfig* discard_config_1;
2508 tech_profile::DiscardConfig* discard_config_2;
2509 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2510 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2511
2512 virtual void SetUp() {
2513 traffic_queues = new tech_profile::TrafficQueues;
2514 traffic_queues->set_intf_id(0);
2515 traffic_queues->set_onu_id(1);
2516 traffic_queue_1 = traffic_queues->add_traffic_queues();
2517 traffic_queue_1->set_gemport_id(1024);
2518 traffic_queue_1->set_pbit_map("0b00000101");
2519 traffic_queue_1->set_aes_encryption(true);
2520 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2521 traffic_queue_1->set_priority(0);
2522 traffic_queue_1->set_weight(0);
2523 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2524 discard_config_1 = new tech_profile::DiscardConfig;
2525 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2526 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2527 tail_drop_discard_config_1->set_queue_size(8);
2528 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2529 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2530 }
2531
2532 virtual void TearDown() {
2533 }
2534};
2535
2536// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2537TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2538 Status status;
2539 traffic_queues->set_uni_id(0);
2540 traffic_queues->set_port_no(16);
2541 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2542
2543 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2544 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2545
2546 status = CreateTrafficQueues_(traffic_queues);
2547 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2548
2549 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2550 status = CreateTrafficQueues_(traffic_queues);
2551 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2552}
2553
2554// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2555TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2556 traffic_queues->set_uni_id(1);
2557 traffic_queues->set_port_no(32);
2558 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2559
2560 traffic_queue_2 = traffic_queues->add_traffic_queues();
2561 traffic_queue_2->set_gemport_id(1025);
2562 traffic_queue_2->set_pbit_map("0b00001010");
2563 traffic_queue_2->set_aes_encryption(true);
2564 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2565 traffic_queue_2->set_priority(1);
2566 traffic_queue_2->set_weight(0);
2567 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2568 discard_config_2 = new tech_profile::DiscardConfig;
2569 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2570 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2571 tail_drop_discard_config_2->set_queue_size(8);
2572 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2573 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2574 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2575
2576 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2577 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2578
2579 Status status = CreateTrafficQueues_(traffic_queues);
2580 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2581}
2582
2583// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2584TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2585 traffic_queues->set_uni_id(2);
2586 traffic_queues->set_port_no(16);
2587 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2588
2589 traffic_queue_2 = traffic_queues->add_traffic_queues();
2590 traffic_queue_2->set_gemport_id(1025);
2591 traffic_queue_2->set_pbit_map("0b10001010");
2592 traffic_queue_2->set_aes_encryption(true);
2593 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2594 traffic_queue_2->set_priority(1);
2595 traffic_queue_2->set_weight(0);
2596 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2597 discard_config_2 = new tech_profile::DiscardConfig;
2598 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2599 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2600 tail_drop_discard_config_2->set_queue_size(8);
2601 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2602 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2603 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2604
2605 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2606 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2607
2608 Status status = CreateTrafficQueues_(traffic_queues);
2609 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2610}
2611
2612// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2613TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2614 traffic_queues->set_uni_id(3);
2615 traffic_queues->set_port_no(16);
2616 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2617
2618 traffic_queue_2 = traffic_queues->add_traffic_queues();
2619 traffic_queue_2->set_gemport_id(1025);
2620 traffic_queue_2->set_pbit_map("0b00001010");
2621 traffic_queue_2->set_aes_encryption(true);
2622 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2623 traffic_queue_2->set_priority(1);
2624 traffic_queue_2->set_weight(0);
2625 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2626 discard_config_2 = new tech_profile::DiscardConfig;
2627 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2628 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2629 tail_drop_discard_config_2->set_queue_size(8);
2630 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2631 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2632 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2633
2634 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2635 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2636
2637 Status status = CreateTrafficQueues_(traffic_queues);
2638 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2639}
2640
2641// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2642TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2643 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2644 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2645 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2646
2647 traffic_queue_2 = traffic_queues->add_traffic_queues();
2648 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2649 traffic_queues->set_uni_id(uni_ids[i]);
2650 traffic_queues->set_port_no(port_nos[i]);
2651 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2652
2653 traffic_queue_2->set_gemport_id(1025);
2654 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2655 traffic_queue_2->set_aes_encryption(true);
2656 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2657 traffic_queue_2->set_priority(1);
2658 traffic_queue_2->set_weight(0);
2659 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2660 discard_config_2 = new tech_profile::DiscardConfig;
2661 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2662 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2663 tail_drop_discard_config_2->set_queue_size(8);
2664 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2665 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2666 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2667
2668 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2669 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2670
2671 Status status = CreateTrafficQueues_(traffic_queues);
2672 if(i==16)
2673 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2674 else
2675 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2676 }
2677}
2678
2679// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2680TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2681 traffic_queues->set_uni_id(0);
2682 traffic_queues->set_port_no(16);
2683 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2684
2685 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2686 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2687
2688 Status status = CreateTrafficQueues_(traffic_queues);
2689 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2690}
2691
2692////////////////////////////////////////////////////////////////////////////
2693// For testing RemoveTrafficQueues functionality
2694////////////////////////////////////////////////////////////////////////////
2695
2696class TestRemoveTrafficQueues : public Test {
2697 protected:
2698 NiceMock<BalMocker> balMock;
2699 tech_profile::TrafficQueues* traffic_queues;
2700 tech_profile::TrafficQueue* traffic_queue_1;
2701 tech_profile::TrafficQueue* traffic_queue_2;
2702
2703 virtual void SetUp() {
2704 traffic_queues = new tech_profile::TrafficQueues;
2705 traffic_queues->set_intf_id(0);
2706 traffic_queues->set_onu_id(1);
2707 traffic_queue_1 = traffic_queues->add_traffic_queues();
2708 traffic_queue_1->set_gemport_id(1024);
2709 traffic_queue_1->set_priority(0);
2710 }
2711
2712 virtual void TearDown() {
2713 }
2714};
2715
2716// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2717TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2718 Status status;
2719 traffic_queues->set_uni_id(0);
2720 traffic_queues->set_port_no(16);
2721 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2722
2723 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2724 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2725
2726 status = RemoveTrafficQueues_(traffic_queues);
2727 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2728
2729 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2730 status = RemoveTrafficQueues_(traffic_queues);
2731 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2732}
2733
2734// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2735TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2736 Status status;
2737 traffic_queues->set_uni_id(0);
2738 traffic_queues->set_port_no(16);
2739 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2740
2741 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2742 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2743
2744 status = RemoveTrafficQueues_(traffic_queues);
2745 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2746}
2747
2748// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2749TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2750 //Remove scheduler so that is_tm_sched_id_present api call will return false
2751 tech_profile::TrafficSchedulers* traffic_scheds;
2752 tech_profile::TrafficScheduler* traffic_sched;
2753 traffic_scheds = new tech_profile::TrafficSchedulers;
2754 traffic_scheds->set_intf_id(0);
2755 traffic_scheds->set_onu_id(1);
2756 traffic_scheds->set_uni_id(0);
2757 traffic_scheds->set_port_no(16);
2758 traffic_sched = traffic_scheds->add_traffic_scheds();
2759 traffic_sched->set_alloc_id(1024);
2760 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2761
2762 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2763 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2764 RemoveTrafficSchedulers_(traffic_scheds);
2765
2766 traffic_queues->set_uni_id(0);
2767 traffic_queues->set_port_no(16);
2768 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2769
2770 Status status = RemoveTrafficQueues_(traffic_queues);
2771 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2772}
2773
2774/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2775as it is getting referred by some other queues case */
2776TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2777 traffic_queues->set_uni_id(3);
2778 traffic_queues->set_port_no(16);
2779 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2780 traffic_queue_2 = traffic_queues->add_traffic_queues();
2781 traffic_queue_2->set_gemport_id(1025);
2782 traffic_queue_2->set_priority(1);
2783 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2784
2785 Status status = RemoveTrafficQueues_(traffic_queues);
2786 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2787}
2788
2789/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2790is not getting referred by any other queues case */
2791TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2792 traffic_queues->set_uni_id(1);
2793 traffic_queues->set_port_no(32);
2794 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2795 traffic_queue_2 = traffic_queues->add_traffic_queues();
2796 traffic_queue_2->set_gemport_id(1025);
2797 traffic_queue_2->set_priority(1);
2798
2799 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2800 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2801
2802 Status status = RemoveTrafficQueues_(traffic_queues);
2803 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2804}
2805
2806/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2807having no reference to any other queues case */
2808TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2809 traffic_queues->set_uni_id(4);
2810 traffic_queues->set_port_no(64);
2811 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2812 traffic_queue_2 = traffic_queues->add_traffic_queues();
2813 traffic_queue_2->set_gemport_id(1025);
2814 traffic_queue_2->set_priority(1);
2815
2816 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2817 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2818
2819 Status status = RemoveTrafficQueues_(traffic_queues);
2820 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2821}
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002822
2823////////////////////////////////////////////////////////////////////////////
2824// For testing OnuItuPonAlarmSet functionality
2825////////////////////////////////////////////////////////////////////////////
2826
2827class TestOnuItuPonAlarmSet : public Test {
2828 protected:
2829 bcmolt_pon_ni pon_ni = 0;
2830 bcmolt_onu_id onu_id = 1;
2831
kesavandc1f2db92020-08-31 15:32:06 +05302832 config::OnuItuPonAlarm *onu_itu_pon_alarm_rt;
2833 config::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config;
2834 config::OnuItuPonAlarm::SoakTime *soak_time_rt;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002835
kesavandc1f2db92020-08-31 15:32:06 +05302836 config::OnuItuPonAlarm *onu_itu_pon_alarm_rr;
2837 config::OnuItuPonAlarm::RateRangeConfig *rate_range_config;
2838 config::OnuItuPonAlarm::SoakTime *soak_time_rr;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002839
kesavandc1f2db92020-08-31 15:32:06 +05302840 config::OnuItuPonAlarm *onu_itu_pon_alarm_tc;
2841 config::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config;
2842 config::OnuItuPonAlarm::SoakTime *soak_time_tc;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002843
2844 NiceMock<BalMocker> balMock;
2845
2846 virtual void SetUp() {
kesavandc1f2db92020-08-31 15:32:06 +05302847 onu_itu_pon_alarm_rt = new config::OnuItuPonAlarm;
2848 rate_threshold_config = new config::OnuItuPonAlarm::RateThresholdConfig;
2849 soak_time_rt = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002850 onu_itu_pon_alarm_rt->set_pon_ni(0);
2851 onu_itu_pon_alarm_rt->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05302852 onu_itu_pon_alarm_rt->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
2853 onu_itu_pon_alarm_rt->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002854 rate_threshold_config->set_rate_threshold_rising(1);
2855 rate_threshold_config->set_rate_threshold_falling(4);
2856 soak_time_rt->set_active_soak_time(2);
2857 soak_time_rt->set_clear_soak_time(2);
2858 rate_threshold_config->set_allocated_soak_time(soak_time_rt);
2859 onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config);
2860
kesavandc1f2db92020-08-31 15:32:06 +05302861 onu_itu_pon_alarm_rr = new config::OnuItuPonAlarm;
2862 rate_range_config = new config::OnuItuPonAlarm::RateRangeConfig;
2863 soak_time_rr = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002864 onu_itu_pon_alarm_rr->set_pon_ni(0);
2865 onu_itu_pon_alarm_rr->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05302866 onu_itu_pon_alarm_rr->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
2867 onu_itu_pon_alarm_rr->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002868 rate_range_config->set_rate_range_lower(1);
2869 rate_range_config->set_rate_range_upper(4);
2870 soak_time_rr->set_active_soak_time(2);
2871 soak_time_rr->set_clear_soak_time(2);
2872 rate_range_config->set_allocated_soak_time(soak_time_rr);
2873 onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config);
2874
kesavandc1f2db92020-08-31 15:32:06 +05302875 onu_itu_pon_alarm_tc = new config::OnuItuPonAlarm;
2876 value_threshold_config = new config::OnuItuPonAlarm::ValueThresholdConfig;
2877 soak_time_tc = new config::OnuItuPonAlarm::SoakTime;
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002878 onu_itu_pon_alarm_tc->set_pon_ni(0);
2879 onu_itu_pon_alarm_tc->set_onu_id(1);
kesavandc1f2db92020-08-31 15:32:06 +05302880 onu_itu_pon_alarm_tc->set_alarm_id(config::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
2881 onu_itu_pon_alarm_tc->set_alarm_reporting_condition(config::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD);
Jason Huang5d9ab1a2020-04-15 16:53:49 +08002882 value_threshold_config->set_threshold_limit(6);
2883 soak_time_tc->set_active_soak_time(2);
2884 soak_time_tc->set_clear_soak_time(2);
2885 value_threshold_config->set_allocated_soak_time(soak_time_tc);
2886 onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config);
2887 }
2888
2889 virtual void TearDown() {
2890 }
2891};
2892
2893// Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case
2894// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
2895// the configured threshold boundary.
2896TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) {
2897 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2898 bcmolt_onu_key key = {};
2899 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2900 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
2901 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
2902 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
2903 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2904
2905 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2906
2907 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
2908 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2909}
2910
2911// Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case
2912// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
2913// the configured threshold boundary.
2914TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) {
2915 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2916 bcmolt_onu_key key = {};
2917 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2918 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
2919 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
2920 stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
2921 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2922
2923 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2924
2925 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
2926 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2927}
2928
2929// Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case
2930// rate_range: The alarm is triggered if the stats delta value between samples deviates
2931// from the configured range.
2932TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) {
2933 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2934 bcmolt_onu_key key = {};
2935 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2936 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
2937 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100;
2938 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50;
2939 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2940
2941 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2942
2943 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
2944 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2945}
2946
2947// Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case
2948// rate_range: The alarm is triggered if the stats delta value between samples deviates
2949// from the configured range.
2950TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) {
2951 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2952 bcmolt_onu_key key = {};
2953 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2954 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
2955 stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50;
2956 stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100;
2957 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2958
2959 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2960
2961 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
2962 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2963}
2964
2965// Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case
2966// value_threshold: The alarm is raised if the stats sample value becomes greater than this
2967// level. The alarm is cleared when the host read the stats.
2968TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) {
2969 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2970 bcmolt_onu_key key = {};
2971 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2972 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
2973 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100;
2974 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2975
2976 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2977
2978 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
2979 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2980}
2981
2982// Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case
2983// value_threshold: The alarm is raised if the stats sample value becomes greater than this
2984// level. The alarm is cleared when the host read the stats.
2985TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) {
2986 bcmolt_onu_itu_pon_stats_cfg stat_cfg;
2987 bcmolt_onu_key key = {};
2988 BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
2989 stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
2990 stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1;
2991 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2992
2993 ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2994
2995 Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
2996 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2997}
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00002998
2999////////////////////////////////////////////////////////////////////////////
3000// For testing DeleteGroup functionality
3001////////////////////////////////////////////////////////////////////////////
3002
3003class TestDeleteGroup : public Test {
3004 protected:
3005 uint32_t group_id = 1;
3006 NiceMock<BalMocker> balMock;
3007
3008 virtual void SetUp() {
3009 }
Burak Gurdageb4ca2e2020-06-15 07:48:26 +00003010};
3011
3012// Test 1 - DeleteGroup success case
3013TEST_F(TestDeleteGroup, DeleteGroupSuccess) {
3014 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3015 bcmos_errno group_cfg_clear_res = BCM_ERR_OK;
3016 bcmolt_group_cfg grp_cfg_out;
3017 bcmolt_group_key grp_key = {};
3018
3019 grp_key.id = group_id;
3020 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3021
3022 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3023 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3024 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3025 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3026 return group_cfg_get_res;
3027 }
3028 ));
3029
3030 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3031
3032 Status status = DeleteGroup_(group_id);
3033 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3034}
3035
3036// Test 2 - DeleteGroup failure case: Group does not exist
3037TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) {
3038 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3039 bcmolt_group_cfg grp_cfg_out;
3040 bcmolt_group_key grp_key = {};
3041
3042 grp_key.id = group_id;
3043 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3044
3045 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3046 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3047 grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED;
3048 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3049 return group_cfg_get_res;
3050 }
3051 ));
3052
3053 Status status = DeleteGroup_(group_id);
3054 ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND );
3055}
3056
3057// Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.)
3058TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) {
3059 bcmos_errno group_cfg_get_res = BCM_ERR_OK;
3060 bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL;
3061 bcmolt_group_cfg grp_cfg_out;
3062 bcmolt_group_key grp_key = {};
3063
3064 grp_key.id = group_id;
3065 BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
3066
3067 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
3068 bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
3069 grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
3070 memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
3071 return group_cfg_get_res;
3072 }
3073 ));
3074
3075 EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
3076
3077 Status status = DeleteGroup_(group_id);
3078 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3079}
Jason Huang1d9cfce2020-05-20 22:58:47 +08003080
3081////////////////////////////////////////////////////////////////////////////
3082// For testing OnuLogicalDistanceZero functionality
3083////////////////////////////////////////////////////////////////////////////
3084class TestOnuLogicalDistanceZero : public Test {
3085 protected:
3086 NiceMock<BalMocker> balMock;
3087 bcmolt_pon_ni pon_ni = 0;
3088 openolt::OnuLogicalDistance *onu_logical_distance_zero;
3089
3090 virtual void SetUp() {
3091 onu_logical_distance_zero = new openolt::OnuLogicalDistance;
3092 onu_logical_distance_zero->set_intf_id(pon_ni);
3093 }
3094 virtual void TearDown() {
3095 }
3096};
3097
3098//
3099// Test 1 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance success case
3100//
3101TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroSuccess) {
3102 bcmolt_pon_distance pon_distance = {};
3103 bcmolt_pon_interface_cfg pon_cfg;
3104 bcmolt_pon_interface_key key = {};
3105
3106 key.pon_ni = pon_ni;
3107 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3108 state.activate();
3109 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3110
3111 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3112 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3113
3114 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3115 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3116}
3117
3118// Test 2 - GetLogicalOnuDistanceZero-Get 0KM logical ONU distance failure case
3119// The PON state is not ready for failure case
3120//
3121TEST_F(TestOnuLogicalDistanceZero, OnuLogicalDistanceZeroPonStateFailure) {
3122 bcmolt_pon_distance pon_distance = {};
3123 bcmolt_pon_interface_cfg pon_cfg;
3124 bcmolt_pon_interface_key key = {};
3125
3126 key.pon_ni = pon_ni;
3127 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3128 state.deactivate();
3129 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
3130
3131 Status status = GetLogicalOnuDistanceZero_(pon_ni, onu_logical_distance_zero);
3132 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3133}
3134
3135class TestOnuLogicalDistance : public Test {
3136 protected:
3137 NiceMock<BalMocker> balMock;
3138 bcmolt_pon_ni pon_ni = 0;
3139 bcmolt_onu_id onu_id = 1;
3140 openolt::OnuLogicalDistance *onu_logical_distance;
3141
3142 virtual void SetUp() {
3143 onu_logical_distance = new openolt::OnuLogicalDistance;
3144 onu_logical_distance->set_intf_id(pon_ni);
3145 onu_logical_distance->set_onu_id(onu_id);
3146 }
3147 virtual void TearDown() {
3148 }
3149};
3150
3151//
3152// Test 1 - GetLogicalOnuDistance-Get logical ONU distance success case
3153//
3154TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceSuccess) {
3155 bcmolt_pon_distance pon_distance = {};
3156 bcmolt_pon_interface_cfg pon_cfg;
3157 bcmolt_pon_interface_key key = {};
3158 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3159
3160 key.pon_ni = pon_ni;
3161 state.activate();
3162 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3163
3164 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3165 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3166
3167 bcmolt_onu_cfg onu_cfg;
3168 bcmolt_onu_key onu_key = {};
3169 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3170
3171 onu_key.pon_ni = pon_ni;
3172 onu_key.onu_id = onu_id;
3173 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3174 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
3175
3176 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3177 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3178
3179 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3180 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
3181}
3182
3183// Test 2 - GetLogicalOnuDistance-Get logical ONU distance failure case
3184// The failure case is for retrieving ONU ranging time
3185//
3186TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceRetrieveOnuRangingTimeFailure) {
3187 bcmolt_pon_distance pon_distance = {};
3188 bcmolt_pon_interface_cfg pon_cfg;
3189 bcmolt_pon_interface_key key = {};
3190 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3191
3192 key.pon_ni = pon_ni;
3193 state.activate();
3194 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3195
3196 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3197 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3198
3199 bcmolt_onu_cfg onu_cfg;
3200 bcmolt_onu_key onu_key = {};
3201 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
3202
3203 onu_key.pon_ni = pon_ni;
3204 onu_key.onu_id = onu_id;
3205 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3206
3207 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3208 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3209
3210 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3211 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3212}
3213
3214// Test 3 - GetLogicalOnuDistance-Get logical ONU distance failure case
3215// The failure case is for ONU is not yet activated
3216//
3217TEST_F(TestOnuLogicalDistance, OnuLogicalDistanceOnuNotActivatedFailure) {
3218 bcmolt_pon_distance pon_distance = {};
3219 bcmolt_pon_interface_cfg pon_cfg;
3220 bcmolt_pon_interface_key key = {};
3221 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
3222
3223 key.pon_ni = pon_ni;
3224 state.activate();
3225 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, key);
3226
3227 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
3228 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
3229
3230 bcmolt_onu_cfg onu_cfg;
3231 bcmolt_onu_key onu_key = {};
3232 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
3233
3234 onu_key.pon_ni = pon_ni;
3235 onu_key.onu_id = onu_id;
3236 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
3237
3238 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
3239 .WillRepeatedly(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
3240
3241 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_INACTIVE;
3242 Status status = GetLogicalOnuDistance_(pon_ni, onu_id, onu_logical_distance);
3243 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
3244}
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -07003245
3246////////////////////////////////////////////////////////////////////////////
3247// For testing Secure Server functionality
3248////////////////////////////////////////////////////////////////////////////
3249
3250class TestSecureServer : public Test {
3251 protected:
3252 virtual void SetUp() {}
3253 virtual void TearDown() {}
3254};
3255
3256TEST_F(TestSecureServer, StartInsecureServer) {
3257 // const to prevent the following warning:
3258 // warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
3259 const char *args[] = {"./openolt"};
3260 int argc = sizeof(args) / sizeof(args[0]);
3261 char **argv = const_cast<char**>(args);
3262
3263 bool ok = RunServer(argc, argv);
3264
3265 ASSERT_TRUE(ok);
3266
3267 OPENOLT_LOG(INFO, openolt_log_id, "insecure gRPC server has been started and shut down successfully\n");
3268}
3269
3270TEST_F(TestSecureServer, StartWithInvalidTLSOption) {
3271 const char *args[] = {"./openolt", "--enable-tls", "DUMMY_GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3272 int argc = sizeof(args) / sizeof(args[0]);
3273 char **argv = const_cast<char**>(args);
3274
3275 bool ok = RunServer(argc, argv);
3276
3277 ASSERT_FALSE(ok);
3278
3279 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to invalid TLS option\n");
3280}
3281
3282TEST_F(TestSecureServer, CertificatesAreMissing) {
3283 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3284 int argc = sizeof(args) / sizeof(args[0]);
3285 char **argv = const_cast<char**>(args);
3286 const std::string cmd = "exec [ -d './keystore' ] && rm -rf './keystore'";
3287
3288 int res = std::system(cmd.c_str());
3289 if (res == 0) {
3290 std::cout << "directory ./keystore is deleted\n";
3291 } else {
3292 std::cout << "directory ./keystore is not existing\n";
3293 }
3294
3295 bool ok = RunServer(argc, argv);
3296
3297 ASSERT_FALSE(ok);
3298
3299 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server could not be started due to missing certificates\n");
3300}
3301
3302TEST_F(TestSecureServer, StartWithValidTLSOption) {
3303 const char *args[] = {"./openolt", "--enable-tls", "GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE"};
3304 int argc = sizeof(args) / sizeof(args[0]);
3305 char **argv = const_cast<char**>(args);
3306 const std::string cmd_1 = "exec cp -r ./keystore-test ./keystore";
3307 const std::string cmd_2 = "exec rm -rf './keystore'";
3308
3309 int res = std::system(cmd_1.c_str());
3310 if (res == 0) {
3311 std::cout << "directory ./keystore is copied from ./keystore-test\n";
3312
3313 bool ok = RunServer(argc, argv);
3314 ASSERT_TRUE(ok);
3315
3316 OPENOLT_LOG(INFO, openolt_log_id, "secure gRPC server has been started with the given certificates and TLS options, and shut down successfully\n");
3317
3318 res = std::system(cmd_2.c_str());
3319 if (res == 0) {
3320 std::cout << "directory ./keystore is deleted\n";
3321 } else {
3322 std::cerr << "directory ./keystore could not be deleted\n";
3323 }
3324 } else {
3325 std::cerr << "directory ./keystore could not be prepared, err: " << res << '\n';
3326 FAIL();
3327 }
3328}
Orhan Kupusogluec57af02021-05-12 12:38:17 +00003329
3330////////////////////////////////////////////////////////////////////////////
3331// For testing RxTx Power Read functionality
3332////////////////////////////////////////////////////////////////////////////
3333
3334class TestPowerRead : public Test {
3335 protected:
3336 virtual void SetUp() {
3337 std::array<char, 600> content = {};
3338 content.fill(0x00); // not required for 0x00
3339
3340 // for asfvolt16
3341 content[102] = 0x5D;
3342 content[103] = 0x38;
3343 content[104] = 0x1A;
3344 content[105] = 0xB5;
3345
3346 // for asgvolt64
3347 content[358] = 0x5C;
3348 content[359] = 0x82;
3349 content[360] = 0x04;
3350 content[361] = 0xBE;
3351
3352 std::ofstream test_file;
3353 test_file.open(file_name, std::ios::binary | std::ios::out);
3354 test_file.write(content.data(), content.size());
3355 test_file.close();
3356
3357 const std::string cmd = "exec hexdump -C " + file_name + " > " + hex_dump;
3358
3359 int res = std::system(cmd.c_str());
3360 if (res == 0) {
3361 std::ifstream dump_file(hex_dump) ;
3362 std::string hexdump = { std::istreambuf_iterator<char>(dump_file), std::istreambuf_iterator<char>() };
3363 std::cout << cmd << '\n';
3364 std::cout << hexdump << '\n';
3365 } else {
3366 std::cerr << "hexdump capture failed\n";
3367 }
3368 }
3369 virtual void TearDown() {
3370 std::remove(file_name.c_str());
3371 std::remove(hex_dump.c_str());
3372 }
3373
3374 const std::string file_name = "eeprom.bin";
3375 const std::string hex_dump = file_name + ".hexdump";
3376};
3377
3378TEST_F(TestPowerRead, TestAsfvolt16) {
3379 std::cout << "Test Power Reads on XGS-PON OLT:\n";
3380
3381 int port = 20;
3382 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3383
3384 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3385
3386 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3387
3388 port = 0;
3389 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_XGSPON, TrxEepromReader::RX_AND_TX_POWER, port};
3390
3391 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3392 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3393 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3394 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3395 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3396
3397 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3398
3399 ASSERT_TRUE(rxtx_power_raw.second);
3400
3401 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3402 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3403 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3404 << 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";
3405 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3406 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3407 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3408 << 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";
3409 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3410
3411 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3412 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 256);
3413 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 104);
3414 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3415 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 20);
3416 ASSERT_EQ(rxtx_power_raw.first.first, 0x1AB5); // 6837
3417 ASSERT_EQ(rxtx_power_raw.first.second, 0x5D38); // 23864
3418 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/47-0050/sfp_eeprom");
3419}
3420
3421TEST_F(TestPowerRead, TestAsgvolt64) {
3422 std::cout << "Test Power Reads on GPON OLT:\n";
3423
3424 int port = 80;
3425 auto trx_eeprom_reader1 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3426
3427 std::cout << "\tis port #" << port << " valid? " << std::boolalpha << trx_eeprom_reader1.is_valid_port() << '\n';
3428
3429 ASSERT_FALSE(trx_eeprom_reader1.is_valid_port());
3430
3431 port = 0;
3432 auto trx_eeprom_reader2 = TrxEepromReader{TrxEepromReader::DEVICE_GPON, TrxEepromReader::RX_AND_TX_POWER, port};
3433
3434 std::cout << "\tis port #" << port << " valid? " << trx_eeprom_reader2.is_valid_port() << '\n';
3435 std::cout << "\tbuffer size: " << trx_eeprom_reader2.get_buf_size() << '\n';
3436 std::cout << "\tread offset: " << trx_eeprom_reader2.get_read_offset() << '\n';
3437 std::cout << "\tread num bytes: " << trx_eeprom_reader2.get_read_num_bytes() << '\n';
3438 std::cout << "\tmax ports: " << trx_eeprom_reader2.get_max_ports() << '\n';
3439
3440 auto rxtx_power_raw = trx_eeprom_reader2.read_power_raw();
3441
3442 ASSERT_TRUE(rxtx_power_raw.second);
3443
3444 std::cout << "\tRx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.first
3445 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.first
3446 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_rx_to_mw(rxtx_power_raw.first.first) << " mW, "
3447 << 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";
3448 std::cout << "\tTx power - raw: (hex) " << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << rxtx_power_raw.first.second
3449 << ", (dec) " << std::dec << std::setfill(' ') << std::setw(5) << rxtx_power_raw.first.second
3450 << " | " << std::dec << std::fixed << std::setprecision(5) << std::setw(8) << trx_eeprom_reader2.raw_tx_to_mw(rxtx_power_raw.first.second) << " mW, "
3451 << 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";
3452 std::cout << "\tnode path: " << trx_eeprom_reader2.get_node_path() << '\n';
3453
3454 ASSERT_TRUE(trx_eeprom_reader2.is_valid_port());
3455 ASSERT_EQ(trx_eeprom_reader2.get_buf_size(), 600);
3456 ASSERT_EQ(trx_eeprom_reader2.get_read_offset(), 360);
3457 ASSERT_EQ(trx_eeprom_reader2.get_read_num_bytes(), 2);
3458 ASSERT_EQ(trx_eeprom_reader2.get_max_ports(), 74);
3459 ASSERT_EQ(rxtx_power_raw.first.first, 0x04BE); // 1214
3460 ASSERT_EQ(rxtx_power_raw.first.second, 0x5C82); // 23682
3461 ASSERT_STREQ(trx_eeprom_reader2.get_node_path(), "/sys/bus/i2c/devices/41-0050/eeprom");
3462}