blob: 3d9ec414cde9fcdd1117dfaba0039da19fe71441 [file] [log] [blame]
Amit Ghoshfcad4d32019-11-13 10:24:55 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "gtest/gtest.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050017#include "Queue.h"
Amit Ghoshfcad4d32019-11-13 10:24:55 +000018#include "bal_mocker.h"
19#include "core.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053020#include "core_data.h"
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050021#include <future>
Amit Ghoshfcad4d32019-11-13 10:24:55 +000022using namespace testing;
23using namespace std;
24
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050025extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
26extern dev_log_id openolt_log_id;
27extern bcmos_fastlock alloc_cfg_wait_lock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050028
Amit Ghoshfcad4d32019-11-13 10:24:55 +000029class TestOltEnable : public Test {
30 protected:
31 virtual void SetUp() {
32 }
33
34 virtual void TearDown() {
35 // Code here will be called immediately after each test
36 // (right before the destructor).
37 }
38};
39
40// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
41// bcmolt_cfg_get__bal_state_stub.
42ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
43
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050044// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
45// bcmolt_cfg_get__onu_state_stub.
46ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
47
48// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
49// bcmolt_cfg_get__tm_sched_stub.
50ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
51
52// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
53// bcmolt_cfg_get__pon_intf_stub.
54ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
55
56// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
57// bcmolt_cfg_get__nni_intf_stub.
58ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
Amit Ghoshfcad4d32019-11-13 10:24:55 +000059
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050060// This is used to set custom bcmolt_flow_cfg value to bcmolt_flow_cfg pointer coming in
61// bcmolt_cfg_get__flow_stub.
62ACTION_P(SetArg1ToBcmOltFlowCfg, value) { *static_cast<bcmolt_flow_cfg*>(arg1) = value; };
63
Amit Ghoshfcad4d32019-11-13 10:24:55 +000064// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
65MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -050066MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
67MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
68MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
69MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -050070MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__flow_stub, bcmos_errno(bcmolt_oltid, void*));
Amit Ghoshfcad4d32019-11-13 10:24:55 +000071
72
73// Test Fixture for OltEnable
74
75// Test 1: OltEnableSuccess case
76TEST_F(TestOltEnable, OltEnableSuccess){
77 // NiceMock is used to suppress 'WillByDefault' return errors.
78 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
79 NiceMock<BalMocker> balMock;
80 bcmos_errno host_init_res = BCM_ERR_OK;
81 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
82 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
83 bcmos_errno olt_oper_res = BCM_ERR_OK;
84
85 bcmolt_olt_cfg olt_cfg = { };
86 bcmolt_olt_key olt_key = { };
87 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
88 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
89
90 Status olt_enable_res;
91
92 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
93 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
94 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
95 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
96 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
97 .WillRepeatedly(Return(bal_cfg_get_res));
98 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
99
100 olt_enable_res = Enable_(1, NULL);
101 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
102}
103
104// Test 2: OltEnableFail_host_init_fail
105TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
106 // NiceMock is used to suppress 'WillByDefault' return errors.
107 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
108 NiceMock<BalMocker> balMock;
109 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
110
111 Status olt_enable_res;
112
113 // Ensure that the state of the OLT is in deactivated to start with..
114 state.deactivate();
115
116 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
117
118 olt_enable_res = Enable_(1, NULL);
119 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
120}
121
122// Test 3: OltEnableSuccess_PON_Device_Connected
123TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
124
125 // NiceMock is used to suppress 'WillByDefault' return errors.
126 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
127 NiceMock<BalMocker> balMock;
128 bcmos_errno host_init_res = BCM_ERR_OK;
129 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
130 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
131 bcmos_errno olt_oper_res = BCM_ERR_OK;
132
133 bcmolt_olt_cfg olt_cfg = { };
134 bcmolt_olt_key olt_key = { };
135 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
136 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
137
138 Status olt_enable_res;
139
140 // Ensure that the state of the OLT is in deactivated to start with..
141 state.deactivate();
142
143 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
144 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
145 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
146 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
147 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
148 .WillRepeatedly(Return(bal_cfg_get_res));
149
150 olt_enable_res = Enable_(1, NULL);
151 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
152
153}
154
155// Test 4: OltEnableFail_All_PON_Enable_Fail
156TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
157
158 // NiceMock is used to suppress 'WillByDefault' return errors.
159 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
160 NiceMock<BalMocker> balMock;
161 bcmos_errno host_init_res = BCM_ERR_OK;
162 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
163 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
164 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
165
166 bcmolt_olt_cfg olt_cfg = { };
167 bcmolt_olt_key olt_key = { };
168 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
169 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
170
171 Status olt_enable_res;
172
173 // Ensure that the state of the OLT is in deactivated to start with..
174 state.deactivate();
175
176 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
177 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
178 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
179 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
180 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
181 .WillRepeatedly(Return(bal_cfg_get_res));
182 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
183
184 olt_enable_res = Enable_(1, NULL);
185
186 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
187}
188
189// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
190TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
191
192 // NiceMock is used to suppress 'WillByDefault' return errors.
193 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
194 NiceMock<BalMocker> balMock;
195 bcmos_errno host_init_res = BCM_ERR_OK;
196 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
197 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
198 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
199 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
200
201 bcmolt_olt_cfg olt_cfg = { };
202 bcmolt_olt_key olt_key = { };
203 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
204 olt_cfg.data.bal_state = BCMOLT_BAL_STATE_BAL_AND_SWITCH_READY;
205
206 Status olt_enable_res;
207
208 // Ensure that the state of the OLT is in deactivated to start with..
209 state.deactivate();
210
211 ON_CALL(balMock, bcmolt_host_init(_)).WillByDefault(Return(host_init_res));
212 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__bal_state_stub, bcmolt_cfg_get__bal_state_stub(_, _))
213 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
214 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
215 .Times(BCM_MAX_DEVS_PER_LINE_CARD)
216 .WillRepeatedly(Return(bal_cfg_get_res));
217 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
218 EXPECT_CALL(balMock, bcmolt_oper_submit(_, _))
219 .WillOnce(Return(olt_oper_res_fail))
220 .WillRepeatedly(Return(olt_oper_res_success));
221 olt_enable_res = Enable_(1, NULL);
222
223 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
224}
225
226////////////////////////////////////////////////////////////////////////
227// For testing Enable/Disable functionality
228////////////////////////////////////////////////////////////////////////
229
Girish Gowdraddf9a162020-01-27 12:56:27 +0530230int num_of_pon_port = 16;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000231
232// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
233MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
234
235class TestOltDisableReenable : public Test {
236 protected:
237 virtual void SetUp() {
238 NiceMock<BalMocker> balMock;
239 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
240
241 bcmolt_olt_cfg olt_cfg = { };
242 bcmolt_olt_key olt_key = { };
243
244 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
245
Girish Gowdraddf9a162020-01-27 12:56:27 +0530246 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000247 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
248 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
249
250 ProbeDeviceCapabilities_();
251
252 }
253
254 virtual void TearDown() {
255 // Code here will be called immediately after each test
256 // (right before the destructor).
257 }
258};
259
260
261// Test Fixture for OltDisable
262
263// Test 1: OltDisableSuccess case
264TEST_F(TestOltDisableReenable, OltDisableSuccess){
265 // NiceMock is used to suppress 'WillByDefault' return errors.
266 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
267 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500268 bcmos_errno olt_oper_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000269
270 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500271 state.deactivate();
272 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000273 olt_disable_res = Disable_();
274 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
275
276}
277
278// Test 2: OltDisableAllPonFailed case
279TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
280 // NiceMock is used to suppress 'WillByDefault' return errors.
281 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
282 NiceMock<BalMocker> balMock;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500283 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000284
285 Status olt_disable_res;
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500286 state.deactivate();
287 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000288 olt_disable_res = Disable_();
289 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
290}
291
292
293// Test Fixture for OltReenable
294
295// Test 1: OltReenableSuccess case
296TEST_F(TestOltDisableReenable, OltReenableSuccess){
297 // NiceMock is used to suppress 'WillByDefault' return errors.
298 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
299 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500300 uint32_t pon_id = 0;
301 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
302 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000303 Status olt_reenable_res;
304
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500305 bcmolt_pon_interface_key pon_key;
306 bcmolt_pon_interface_cfg pon_cfg;
307 pon_key.pon_ni = pon_id;
308 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
309 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
310
311 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530312 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500313 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
314
315 bcmolt_tm_sched_cfg tm_sched_cfg;
316 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
317 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
318 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
319
320 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530321 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500322 .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000323
324 olt_reenable_res = Reenable_();
325 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
326
327}
328
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500329// Test 2: OltReenableAllPonFailed case
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000330TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
331 // NiceMock is used to suppress 'WillByDefault' return errors.
332 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
333 NiceMock<BalMocker> balMock;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500334 uint32_t pon_id = 0;
335 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000336 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000337 Status olt_reenable_res;
338
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500339 bcmolt_pon_interface_key pon_key;
340 bcmolt_pon_interface_cfg pon_cfg;
341 pon_key.pon_ni = pon_id;
342 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
343 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
344
345 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530346 .Times(num_of_pon_port)
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500347 .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000348 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
Girish Gowdraddf9a162020-01-27 12:56:27 +0530349 .Times(num_of_pon_port)
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000350 .WillRepeatedly(Return(olt_oper_res));
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500351
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000352 olt_reenable_res = Reenable_();
353 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
354}
355
356////////////////////////////////////////////////////////////////////////////
357// For testing ProbeDeviceCapabilities functionality
358////////////////////////////////////////////////////////////////////////////
359class TestProbeDevCapabilities : public Test {
360 protected:
361 NiceMock<BalMocker> balMock;
362 bcmos_errno olt_res_success = BCM_ERR_OK;
363 bcmos_errno olt_res_fail = BCM_ERR_COMM_FAIL;
364 bcmos_errno dev_res_success = BCM_ERR_OK;
365 bcmos_errno dev_res_fail = BCM_ERR_COMM_FAIL;
366
367 virtual void SetUp() {
368 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
369
370 bcmolt_olt_cfg olt_cfg = { };
371 bcmolt_olt_key olt_key = { };
372
373 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
374
Girish Gowdraddf9a162020-01-27 12:56:27 +0530375 olt_cfg.data.topology.topology_maps.len = num_of_pon_port;
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000376 }
377
378 virtual void TearDown() {
379 }
380};
381
382// Test 1 - If querying the OLT fails, the method must return error
383TEST_F(TestProbeDevCapabilities, ProbeDev_OltQueryFailed) {
384
385 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
386 .WillOnce(Return(olt_res_fail));
387
388 Status query_status = ProbeDeviceCapabilities_();
389 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
390}
391
392// Test 2 - If all devices are queried successfully, the method must return Status::OK
393TEST_F(TestProbeDevCapabilities, ProbeDev_OltQuerySucceeded_DevQueriesSucceeded) {
394
395 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
396 .WillOnce(Return(olt_res_success));
397
398 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
399 .WillRepeatedly(Return(dev_res_success));
400
401 Status query_status = ProbeDeviceCapabilities_();
402
403 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
404}
405
406// Test 3 - After successfully probing the OLT, even if probing all devices failed, the method must return error
407TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_AllDevQueriesFailed) {
408
409 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
410 .WillOnce(Return(olt_res_success));
411
412 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
413 .WillRepeatedly(Return(dev_res_fail));
414
415 Status query_status = ProbeDeviceCapabilities_();
416
417 ASSERT_TRUE( query_status.error_message() != Status::OK.error_message() );
418}
419
420// Test 4 - After successfully probing the OLT, if probing some devices fail, the method returns success
421TEST_F(TestProbeDevCapabilities, ProbedDev_OltQuerySucceeded_SomeDevQueriesFailed) {
422
423 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_,_))
424 .WillOnce(Return(olt_res_success));
425
426 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
427 .WillOnce(Return(olt_res_success))
428 .WillRepeatedly(Return(dev_res_fail));
429
430 Status query_status = ProbeDeviceCapabilities_();
431
432 ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
433}
434
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500435////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500436// For testing EnablePonIf functionality
437////////////////////////////////////////////////////////////////////////////
438
439class TestEnablePonIf : public Test {
440 protected:
441 uint32_t pon_id = 0;
442 NiceMock<BalMocker> balMock;
443
444 virtual void SetUp() {
445 }
446
447 virtual void TearDown() {
448 }
449};
450
451// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
452TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
453 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
454 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
455 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
456 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
457
458 bcmolt_pon_interface_key pon_key;
459 bcmolt_pon_interface_cfg pon_cfg;
460 pon_key.pon_ni = pon_id;
461 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
462 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
463 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
464 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
465
466 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
467 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
468
469 bcmolt_tm_sched_cfg tm_sched_cfg;
470 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
471 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
472 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
473 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
474 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
475
476 Status status = EnablePonIf_(pon_id);
477 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
478}
479
480// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
481TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
482 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
483 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
484 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
485 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
486
487 bcmolt_pon_interface_key pon_key;
488 bcmolt_pon_interface_cfg pon_cfg;
489 pon_key.pon_ni = pon_id;
490 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
491 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
492 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
493 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
494
495 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
496 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
497
498 bcmolt_tm_sched_cfg tm_sched_cfg;
499 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
500 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
501 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
502 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
503 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
504
505 Status status = EnablePonIf_(pon_id);
506 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
507}
508
509// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
510TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
511 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
512 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
513 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
514 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
515 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
516
517 bcmolt_pon_interface_key pon_key;
518 bcmolt_pon_interface_cfg pon_cfg;
519 pon_key.pon_ni = pon_id;
520 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
521 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
522 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
523 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
524
525 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
526 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
527 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
528
529 bcmolt_tm_sched_cfg tm_sched_cfg;
530 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
531 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
532 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
533 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
534 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
535
536 Status status = EnablePonIf_(pon_id);
537 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
538}
539
540// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
541TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
542 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
543 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
544 bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
545 bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
546 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
547 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
548
549 bcmolt_pon_interface_key pon_key;
550 bcmolt_pon_interface_cfg pon_cfg;
551 pon_key.pon_ni = pon_id;
552 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
553 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
554 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
555 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
556
557 EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
558 .WillOnce(Return(olt_cfg_set_res))
559 .WillRepeatedly(Return(olt_cfg_set_err));
560 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
561 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
562
563 bcmolt_tm_sched_cfg tm_sched_cfg;
564 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
565 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
566 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
567 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
568 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
569
570 Status status = EnablePonIf_(pon_id);
571 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
572}
573
574// Test 5 - EnablePonIf already enabled success
575TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
576 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
577
578 bcmolt_pon_interface_key pon_key;
579 bcmolt_pon_interface_cfg pon_cfg;
580 pon_key.pon_ni = pon_id;
581 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
582 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
583 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
584 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
585
586 Status status = EnablePonIf_(pon_id);
587 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
588}
589
590// Test 6 - EnablePonIf - enable onu discovery failure case
591TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
592 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
593 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
594
595 bcmolt_pon_interface_key pon_key;
596 bcmolt_pon_interface_cfg pon_cfg;
597 pon_key.pon_ni = pon_id;
598 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
599 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
600 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
601 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
602 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
603
604 Status status = EnablePonIf_(pon_id);
605 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
606}
607
608// Test 7 - EnablePonIf failure case
609TEST_F(TestEnablePonIf, EnablePonIfFailed) {
610 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
611 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
612 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
613
614 bcmolt_pon_interface_key pon_key;
615 bcmolt_pon_interface_cfg pon_cfg;
616 pon_key.pon_ni = pon_id;
617 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
618 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
619 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
620 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
621 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
622 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
623
624 Status status = EnablePonIf_(pon_id);
625 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
626}
627
628////////////////////////////////////////////////////////////////////////////
629// For testing SetStateUplinkIf functionality
630////////////////////////////////////////////////////////////////////////////
631
632class TestSetStateUplinkIf : public Test {
633 protected:
634 uint32_t intf_id = 0;
635 NiceMock<BalMocker> balMock;
636
637 virtual void SetUp() {
638 }
639
640 virtual void TearDown() {
641 }
642};
643
644// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
645TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
646 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
647 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
648 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
649
650 bcmolt_nni_interface_key nni_key;
651 bcmolt_nni_interface_cfg nni_cfg;
652 nni_key.id = intf_id;
653 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
654 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
655 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
656 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
657
658 bcmolt_tm_sched_cfg tm_sched_cfg;
659 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
660 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
661 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
662 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
663 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
664 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
665
666 Status status = SetStateUplinkIf_(intf_id, true);
667 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
668}
669
670// Test 2 - SetStateUplinkIf, NNI interface already disabled case
671TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
672 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
673
674 bcmolt_nni_interface_key nni_key;
675 bcmolt_nni_interface_cfg nni_cfg;
676 nni_key.id = intf_id;
677 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
678 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
679 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
680 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
681
682 Status status = SetStateUplinkIf_(intf_id, false);
683 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
684}
685
686// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
687TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
688 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
689 bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
690 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
691 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
692
693 bcmolt_nni_interface_key nni_key;
694 bcmolt_nni_interface_cfg nni_cfg;
695 nni_key.id = intf_id;
696 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
697 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
698 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
699 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
700
701 bcmolt_tm_sched_cfg tm_sched_cfg;
702 bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
703 BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
704 tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
705 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
706 .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
707 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
708 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
709
710 Status status = SetStateUplinkIf_(intf_id, true);
711 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
712}
713
714// Test 4 - SetStateUplinkIf Enable failure case
715TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
716 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
717 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
718
719 bcmolt_nni_interface_key nni_key;
720 bcmolt_nni_interface_cfg nni_cfg;
721 nni_key.id = intf_id;
722 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
723 nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
724 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
725 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
726 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
727
728 Status status = SetStateUplinkIf_(intf_id, true);
729 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
730}
731
732// Test 5 - SetStateUplinkIf Disable success case
733TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
734 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
735 bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
736
737 bcmolt_nni_interface_key nni_key;
738 bcmolt_nni_interface_cfg nni_cfg;
739 nni_key.id = intf_id;
740 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
741 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
742 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
743 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
744 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
745
746 Status status = SetStateUplinkIf_(intf_id, false);
747 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
748}
749
750// Test 6 - SetStateUplinkIf Disable failure case
751TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
752 bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
753 bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
754
755 bcmolt_nni_interface_key nni_key;
756 bcmolt_nni_interface_cfg nni_cfg;
757 nni_key.id = intf_id;
758 BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
759 nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
760 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
761 .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
762 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
763
764 Status status = SetStateUplinkIf_(intf_id, false);
765 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
766}
767
768////////////////////////////////////////////////////////////////////////////
Chaitrashree G S73e084d2019-11-20 16:18:59 -0500769// For testing DisablePonIf functionality
770////////////////////////////////////////////////////////////////////////////
771
772class TestDisablePonIf : public Test {
773 protected:
774 virtual void SetUp() {
775 }
776
777 virtual void TearDown() {
778 }
779};
780
781// Test 1 - DisablePonIf success case
782TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
783 bcmos_errno olt_oper_res = BCM_ERR_OK;
784 bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
785 NiceMock<BalMocker> balMock;
786 uint32_t pon_id=1;
787
788 //ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
789 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
790 state.deactivate();
791 Status status = DisablePonIf_(pon_id);
792
793 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
794}
795
796// Test 2 - DisablePonIf Failure case
797TEST_F(TestDisablePonIf, DisablePonIfFailed) {
798 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
799 NiceMock<BalMocker> balMock;
800 uint32_t pon_id=1;
801
802 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
803 state.deactivate();
804 Status status = DisablePonIf_(pon_id);
805
806 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
807}
808
809// Test 3 - DisablePonIf ONU discovery failure case
810TEST_F(TestDisablePonIf, DisablePonIfOnuDiscoveryFail) {
811 NiceMock<BalMocker> balMock;
812 uint32_t pon_id=1;
813 bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
814 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
815 state.deactivate();
816 Status status = DisablePonIf_(pon_id);
817
818 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
819}
820
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500821////////////////////////////////////////////////////////////////////////////
822// For testing ActivateOnu functionality
823////////////////////////////////////////////////////////////////////////////
824
825class TestActivateOnu : public Test {
826 protected:
827 uint32_t pon_id = 0;
828 uint32_t onu_id = 1;
829 std::string vendor_id = "TWSH";
830 std::string vendor_specific = "80808080";
831 uint32_t pir = 1000000;
832 NiceMock<BalMocker> balMock;
833
834 virtual void SetUp() {
835 }
836
837 virtual void TearDown() {
838 }
839};
840
841// Test 1 - ActivateOnu success case
842TEST_F(TestActivateOnu, ActivateOnuSuccess) {
843 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
844 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
845 bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
846
847 bcmolt_onu_cfg onu_cfg;
848 bcmolt_onu_key onu_key;
849 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
850 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
851 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
852 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
853
854 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
855 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
856
857 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
858 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
859}
860
861// Test 2 - ActivateOnu failure case
862TEST_F(TestActivateOnu, ActivateOnuFailure) {
863 bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
864 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
865 bcmos_errno onu_cfg_set_res = BCM_ERR_INTERNAL;
866
867 bcmolt_onu_cfg onu_cfg;
868 bcmolt_onu_key onu_key;
869 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
870 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
871 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
872 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
873
874 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
875 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
876
877 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
878 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
879}
880
881// Test 3 - ActivateOnu - Onu already under processing case
882TEST_F(TestActivateOnu, ActivateOnuProcessing) {
883 bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
884 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
885
886 bcmolt_onu_cfg onu_cfg;
887 bcmolt_onu_key onu_key;
888 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
889 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
890 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
891 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
892 ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
893
894 Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
895 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
896}
897
898////////////////////////////////////////////////////////////////////////////
899// For testing DeactivateOnu functionality
900////////////////////////////////////////////////////////////////////////////
901
902class TestDeactivateOnu : public Test {
903 protected:
904 uint32_t pon_id = 0;
905 uint32_t onu_id = 1;
906 std::string vendor_id = "TWSH";
907 std::string vendor_specific = "80808080";
908 NiceMock<BalMocker> balMock;
909
910 virtual void SetUp() {
911 }
912
913 virtual void TearDown() {
914 }
915};
916
917// Test 1 - DeactivateOnu success case
918TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
919 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
920 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
921
922 bcmolt_onu_cfg onu_cfg;
923 bcmolt_onu_key onu_key;
924 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
925 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
926 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
927 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
928
929 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
930
931 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
932 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
933}
934
935// Test 2 - DeactivateOnu failure case
936TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
937 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
938 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
939
940 bcmolt_onu_cfg onu_cfg;
941 bcmolt_onu_key onu_key;
942 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
943 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
944 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
945 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
946
947 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
948
949 Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
950 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
951}
952
953////////////////////////////////////////////////////////////////////////////
954// For testing DeleteOnu functionality
955////////////////////////////////////////////////////////////////////////////
956
957class TestDeleteOnu : public Test {
958 protected:
959 uint32_t pon_id = 0;
960 uint32_t onu_id = 1;
961 std::string vendor_id = "TWSH";
962 std::string vendor_specific = "80808080";
963 NiceMock<BalMocker> balMock;
964
965 virtual void SetUp() {
966 }
967
968 virtual void TearDown() {
969 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530970 public:
971 static int PushOnuDeactCompltResult(bcmolt_result result, bcmolt_deactivation_fail_reason reason) {
972 onu_deactivate_complete_result res;
973 res.pon_intf_id = 0;
974 res.onu_id = 1;
975 res.result = result;
976 res.reason = reason;
977 // We need to wait for some time to allow the Onu Deactivation Reqeuest to be triggered
978 // before we push the result.
979 std::this_thread::sleep_for(std::chrono::milliseconds(100));
980 bcmos_fastlock_lock(&onu_deactivate_wait_lock);
981 onu_deact_compltd_key k(0, 1);
982 std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *>::iterator it = onu_deact_compltd_map.find(k);
983 if (it == onu_deact_compltd_map.end()) {
984 OPENOLT_LOG(ERROR, openolt_log_id, "onu deact key not found for pon_intf=%d, onu_id=%d\n", 0, 1);
985 } else {
986 it->second->push(res);
987 OPENOLT_LOG(INFO, openolt_log_id, "Pushed ONU deact completed result\n");
988 }
989 bcmos_fastlock_unlock(&onu_deactivate_wait_lock, 0);
990 return 0;
991 }
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -0500992};
993
994// Test 1 - DeleteOnu success case
995TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
996 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
997 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
998 bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
999
1000 bcmolt_onu_cfg onu_cfg;
1001 bcmolt_onu_key onu_key;
1002 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1003 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1004 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1005 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1006
1007 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1008 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1009
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301010 future<int> push_onu_deact_complt_res = \
1011 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1012 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1013 Status status = future_res.get();
1014 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001015 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1016}
1017
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301018// Test 2 - DeleteOnu failure case - BAL Clear ONU fails
1019TEST_F(TestDeleteOnu, DeleteOnuFailureClearOnuFail) {
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001020 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1021 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1022 bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
1023
1024 bcmolt_onu_cfg onu_cfg;
1025 bcmolt_onu_key onu_key;
1026 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1027 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1028 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1029 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1030
1031 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1032 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
1033
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301034 future<int> push_onu_deact_complt_res = \
1035 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_SUCCESS, BCMOLT_DEACTIVATION_FAIL_REASON_NONE);
1036 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1037
1038 Status status = future_res.get();
1039 int res = push_onu_deact_complt_res.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001040 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1041}
1042
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301043// Test 3 - DeleteOnu failure case - onu deactivation fails
1044TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationFail) {
1045 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1046 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1047
1048 bcmolt_onu_cfg onu_cfg;
1049 bcmolt_onu_key onu_key;
1050 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1051 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1052 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1053 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1054
1055 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1056
1057 future<int> push_onu_deact_complt_res = \
1058 async(launch::async,TestDeleteOnu::PushOnuDeactCompltResult, BCMOLT_RESULT_FAIL, BCMOLT_DEACTIVATION_FAIL_REASON_FAIL);
1059 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1060
1061 Status status = future_res.get();
1062 int res = push_onu_deact_complt_res.get();
1063 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1064}
1065
1066// Test 4 - DeleteOnu failure case - onu deactivation timesout
1067TEST_F(TestDeleteOnu, DeleteOnuFailureDeactivationTimeout) {
1068 bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
1069 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1070
1071 bcmolt_onu_cfg onu_cfg;
1072 bcmolt_onu_key onu_key;
1073 BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
1074 onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
1075 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
1076 .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
1077
1078 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1079
1080 future<Status> future_res = async(launch::async, DeleteOnu_, pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
1081
1082 Status status = future_res.get();
1083 ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
1084}
1085
1086
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001087////////////////////////////////////////////////////////////////////////////
1088// For testing OmciMsgOut functionality
1089////////////////////////////////////////////////////////////////////////////
1090
1091class TestOmciMsgOut : public Test {
1092 protected:
1093 uint32_t pon_id = 0;
1094 uint32_t onu_id = 1;
1095 std::string pkt = "omci-pkt";
1096 NiceMock<BalMocker> balMock;
1097
1098 virtual void SetUp() {
1099 }
1100
1101 virtual void TearDown() {
1102 }
1103};
1104
1105// Test 1 - OmciMsgOut success case
1106TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
1107 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1108
1109 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1110
1111 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1112 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1113}
1114
1115// Test 1 - OmciMsgOut failure case
1116TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
1117 bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
1118
1119 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1120
1121 Status status = OmciMsgOut_(pon_id, onu_id, pkt);
1122 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1123}
1124
Jason Huang09b73ea2020-01-08 17:52:05 +08001125#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001126////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001127// For testing FlowAdd functionality
1128////////////////////////////////////////////////////////////////////////////
1129
1130class TestFlowAdd : public Test {
1131 protected:
1132 int32_t access_intf_id = 0;
1133 int32_t onu_id = 1;
1134 int32_t uni_id = 0;
1135 uint32_t port_no = 16;
1136 uint32_t flow_id = 1;
1137 std::string flow_type = "upstream";
1138 int32_t alloc_id = 1024;
1139 int32_t network_intf_id = 0;
1140 int32_t gemport_id = 1024;
1141 int32_t priority_value = 0;
1142 uint64_t cookie = 0;
1143
1144 NiceMock<BalMocker> balMock;
1145 openolt::Flow* flow;
1146 openolt::Classifier* classifier;
1147 openolt::Action* action;
1148 openolt::ActionCmd* cmd;
1149
1150 bcmolt_flow_key flow_key;
1151 bcmolt_flow_cfg flow_cfg;
1152
1153 tech_profile::TrafficQueues* traffic_queues;
1154 tech_profile::TrafficQueue* traffic_queue_1;
1155 tech_profile::TrafficQueue* traffic_queue_2;
1156 tech_profile::DiscardConfig* discard_config_1;
1157 tech_profile::DiscardConfig* discard_config_2;
1158 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1159 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1160
1161
1162 virtual void SetUp() {
1163 classifier = new openolt::Classifier;
1164 action = new openolt::Action;
1165 cmd = new openolt::ActionCmd;
1166
1167 classifier->set_o_tpid(0);
1168 classifier->set_o_vid(7);
1169 classifier->set_i_tpid(0);
1170 classifier->set_i_vid(0);
1171 classifier->set_o_pbits(0);
1172 classifier->set_i_pbits(0);
1173 classifier->set_eth_type(0);
1174 classifier->set_ip_proto(0);
1175 classifier->set_src_port(0);
1176 classifier->set_dst_port(0);
1177 classifier->set_pkt_tag_type("single_tag");
1178
1179 action->set_o_vid(12);
1180 action->set_o_pbits(0);
1181 action->set_o_tpid(0);
1182 action->set_i_vid(0);
1183 action->set_i_pbits(0);
1184 action->set_i_tpid(0);
1185
1186 cmd->set_add_outer_tag(true);
1187 cmd->set_remove_outer_tag(false);
1188 cmd->set_trap_to_host(false);
1189 action->set_allocated_cmd(cmd);
1190
1191 flow_key.flow_id = 1;
1192 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1193 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1194 flow_cfg.data.onu_id=1;
1195 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1196 flow_cfg.data.svc_port_id=1024;
1197 flow_cfg.data.priority=0;
1198 flow_cfg.data.cookie=0;
1199 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1200 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1201 flow_cfg.data.ingress_intf.intf_id=0;
1202 flow_cfg.data.egress_intf.intf_id=0;
1203 flow_cfg.data.classifier.o_vid=7;
1204 flow_cfg.data.classifier.o_pbits=0;
1205 flow_cfg.data.classifier.i_vid=0;
1206 flow_cfg.data.classifier.i_pbits=0;
1207 flow_cfg.data.classifier.ether_type=0;
1208 flow_cfg.data.classifier.ip_proto=0;
1209 flow_cfg.data.classifier.src_port=0;
1210 flow_cfg.data.classifier.dst_port=0;
1211 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1212 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1213 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1214 flow_cfg.data.egress_qos.tm_sched.id=1020;
1215 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1216 flow_cfg.data.action.o_vid=12;
1217 flow_cfg.data.action.o_pbits=0;
1218 flow_cfg.data.action.i_vid=0;
1219 flow_cfg.data.action.i_pbits=0;
1220 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1221
1222 traffic_queues = new tech_profile::TrafficQueues;
1223 traffic_queues->set_intf_id(0);
1224 traffic_queues->set_onu_id(2);
1225 traffic_queue_1 = traffic_queues->add_traffic_queues();
1226 traffic_queue_1->set_gemport_id(1024);
1227 traffic_queue_1->set_pbit_map("0b00000101");
1228 traffic_queue_1->set_aes_encryption(true);
1229 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1230 traffic_queue_1->set_priority(0);
1231 traffic_queue_1->set_weight(0);
1232 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1233 discard_config_1 = new tech_profile::DiscardConfig;
1234 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1235 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1236 tail_drop_discard_config_1->set_queue_size(8);
1237 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1238 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1239
1240 traffic_queues->set_uni_id(0);
1241 traffic_queues->set_port_no(16);
1242
1243 traffic_queue_2 = traffic_queues->add_traffic_queues();
1244 traffic_queue_2->set_gemport_id(1025);
1245 traffic_queue_2->set_pbit_map("0b00001010");
1246 traffic_queue_2->set_aes_encryption(true);
1247 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1248 traffic_queue_2->set_priority(1);
1249 traffic_queue_2->set_weight(0);
1250 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1251 discard_config_2 = new tech_profile::DiscardConfig;
1252 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1253 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1254 tail_drop_discard_config_2->set_queue_size(8);
1255 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1256 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1257 }
1258
1259 virtual void TearDown() {
1260 }
1261};
1262
1263// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1264TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1265 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1266 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1267
1268 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1269 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1270}
1271
1272// Test 2 - FlowAdd - Duplicate Flow case
1273TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1274 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1275 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1276 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1277
1278 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1279 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1280}
1281
1282// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1283TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1284 gemport_id = 1025;
1285
1286 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1287 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1288
1289 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1290 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1291 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1292
1293 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1294 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1295}
1296
1297// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1298TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1299 flow_type = "bidirectional";
1300
1301 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1302 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1303}
1304
1305// Test 5 - FlowAdd - Failure case(Invalid network setting)
1306TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1307 network_intf_id = -1;
1308
1309 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1310 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1311}
1312
1313// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1314TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1315 flow_id = 2;
1316
1317 classifier->set_eth_type(34958);
1318 cmd->set_add_outer_tag(false);
1319 cmd->set_trap_to_host(true);
1320 action->set_allocated_cmd(cmd);
1321
1322 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1323 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1324 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1325 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1326 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1327
1328 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1329 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1330}
1331
1332// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1333TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1334 flow_id = 3;
1335 gemport_id = 1025;
1336
1337 classifier->set_ip_proto(17);
1338 classifier->set_src_port(68);
1339 classifier->set_dst_port(67);
1340 cmd->set_add_outer_tag(false);
1341 cmd->set_trap_to_host(true);
1342 action->set_allocated_cmd(cmd);
1343
1344 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1345 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1346 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1347 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1348 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1349
1350 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1351 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1352}
1353
1354// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1355TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1356 flow_id = 4;
1357 flow_type = "downstream";
1358
1359 classifier->set_o_vid(12);
1360 classifier->set_i_vid(7);
1361 classifier->set_pkt_tag_type("double_tag");
1362 action->set_o_vid(0);
1363 cmd->set_add_outer_tag(false);
1364 cmd->set_remove_outer_tag(true);
1365 action->set_allocated_cmd(cmd);
1366
1367 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1368 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1369 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1370 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1371 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1372
1373 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1374 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1375}
1376
1377// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1378TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1379 onu_id = 2;
1380 flow_id = 5;
1381 alloc_id = 1025;
1382
1383 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1384 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1385
1386 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1387 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1388 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1389 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1390 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1391 CreateTrafficQueues_(traffic_queues);
1392
1393 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1394 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1395}
1396
1397// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1398TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1399 onu_id = 2;
1400 flow_id = 6;
1401 flow_type = "downstream";
1402 alloc_id = 1025;
1403
1404 classifier->set_o_vid(12);
1405 classifier->set_i_vid(7);
1406 classifier->set_pkt_tag_type("double_tag");
1407 action->set_o_vid(0);
1408 cmd->set_add_outer_tag(false);
1409 cmd->set_remove_outer_tag(true);
1410 action->set_allocated_cmd(cmd);
1411
1412 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1413 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1414
1415 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1416 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1417 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1418 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1419 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1420 CreateTrafficQueues_(traffic_queues);
1421
1422 Status status = FlowAdd_(access_intf_id, onu_id, uni_id, port_no, flow_id, flow_type, alloc_id, network_intf_id, gemport_id, *classifier, *action, priority_value, cookie);
1423 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1424}
Jason Huang09b73ea2020-01-08 17:52:05 +08001425#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001426
1427////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001428// For testing OnuPacketOut functionality
1429////////////////////////////////////////////////////////////////////////////
1430
1431class TestOnuPacketOut : public Test {
1432 protected:
1433 uint32_t pon_id = 0;
1434 uint32_t onu_id = 1;
1435 std::string pkt = "omci-pkt";
1436 NiceMock<BalMocker> balMock;
1437
1438 virtual void SetUp() {
1439 }
1440
1441 virtual void TearDown() {
1442 }
1443};
1444
1445// Test 1 - OnuPacketOut success case
1446TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1447 uint32_t port_no = 16;
1448 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001449
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001450 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001451 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1452
1453 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1454 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1455}
1456
1457// Test 2 - OnuPacketOut Port number as 0 case
1458TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1459 uint32_t port_no = 0;
1460 uint32_t gemport_id = 1024;
1461
1462 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1463 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1464}
1465
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001466// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1467TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1468 uint32_t port_no = 16;
1469 uint32_t gemport_id = 0;
1470
1471 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1472 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1473
1474 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1475 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1476}
1477
1478// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1479TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1480 uint32_t port_no = 64;
1481 uint32_t gemport_id = 0;
1482
1483 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1484 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1485
1486 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1487 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1488}
1489
Jason Huang09b73ea2020-01-08 17:52:05 +08001490#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001491////////////////////////////////////////////////////////////////////////////
1492// For testing FlowRemove functionality
1493////////////////////////////////////////////////////////////////////////////
1494
1495class TestFlowRemove : public Test {
1496 protected:
1497 NiceMock<BalMocker> balMock;
1498
1499 virtual void SetUp() {
1500 }
1501
1502 virtual void TearDown() {
1503 }
1504};
1505
1506// Test 1 - FlowRemove - Failure case
1507TEST_F(TestFlowRemove, FlowRemoveFailure) {
1508 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1509 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1510
1511 Status status = FlowRemove_(1, "upstream");
1512 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1513}
1514
1515// Test 2 - FlowRemove - success case
1516TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1517 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1518 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1519
1520 Status status = FlowRemove_(1, "upstream");
1521 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1522}
1523
1524////////////////////////////////////////////////////////////////////////////
1525// For testing UplinkPacketOut functionality
1526////////////////////////////////////////////////////////////////////////////
1527
1528class TestUplinkPacketOut : public Test {
1529 protected:
1530 uint32_t pon_id = 0;
1531 std::string pkt = "omci-pkt";
1532 NiceMock<BalMocker> balMock;
1533
1534 bcmolt_flow_key flow_key;
1535 bcmolt_flow_cfg flow_cfg;
1536
1537 virtual void SetUp() {
1538 flow_key.flow_id = 1;
1539 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1540 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1541 flow_cfg.data.onu_id=1;
1542 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1543 flow_cfg.data.svc_port_id=1024;
1544 flow_cfg.data.priority=0;
1545 flow_cfg.data.cookie=0;
1546 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1547 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1548 flow_cfg.data.ingress_intf.intf_id=0;
1549 flow_cfg.data.egress_intf.intf_id=0;
1550 flow_cfg.data.classifier.o_vid=7;
1551 flow_cfg.data.classifier.o_pbits=0;
1552 flow_cfg.data.classifier.i_vid=0;
1553 flow_cfg.data.classifier.i_pbits=0;
1554 flow_cfg.data.classifier.ether_type=0;
1555 flow_cfg.data.classifier.ip_proto=0;
1556 flow_cfg.data.classifier.src_port=0;
1557 flow_cfg.data.classifier.dst_port=0;
1558 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1559 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1560 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1561 flow_cfg.data.egress_qos.tm_sched.id=1020;
1562 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1563 flow_cfg.data.action.o_vid=12;
1564 flow_cfg.data.action.o_pbits=0;
1565 flow_cfg.data.action.i_vid=0;
1566 flow_cfg.data.action.i_pbits=0;
1567 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1568 }
1569
1570 virtual void TearDown() {
1571 }
1572};
1573
1574// Test 1 - UplinkPacketOut success case
1575TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1576 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1577 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1578 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1579 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1580 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1581
1582 Status status = UplinkPacketOut_(pon_id, pkt);
1583 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1584}
1585
1586// Test 2 - UplinkPacketOut Failure case
1587TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1588 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1589 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1590 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1591 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1592 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1593
1594 Status status = UplinkPacketOut_(pon_id, pkt);
1595 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1596}
1597
1598// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1599TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1600 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1601
1602 FlowRemove_(2, "upstream");
1603 FlowRemove_(3, "upstream");
1604 FlowRemove_(4, "downstream");
1605 FlowRemove_(5, "upstream");
1606 FlowRemove_(6, "downstream");
1607
1608 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1609 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1610 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1611
1612 Status status = UplinkPacketOut_(pon_id, pkt);
1613 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1614}
Jason Huang09b73ea2020-01-08 17:52:05 +08001615#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001616
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001617////////////////////////////////////////////////////////////////////////////
1618// For testing CreateTrafficSchedulers functionality
1619////////////////////////////////////////////////////////////////////////////
1620
1621class TestCreateTrafficSchedulers : public Test {
1622 protected:
1623 NiceMock<BalMocker> balMock;
1624 tech_profile::TrafficSchedulers* traffic_scheds;
1625 tech_profile::TrafficScheduler* traffic_sched;
1626 tech_profile::SchedulerConfig* scheduler;
1627 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1628
1629 virtual void SetUp() {
1630 traffic_scheds = new tech_profile::TrafficSchedulers;
1631 traffic_scheds->set_intf_id(0);
1632 traffic_scheds->set_onu_id(1);
1633 traffic_scheds->set_uni_id(0);
1634 traffic_scheds->set_port_no(16);
1635 traffic_sched = traffic_scheds->add_traffic_scheds();
1636 traffic_sched->set_alloc_id(1024);
1637 scheduler = new tech_profile::SchedulerConfig;
1638 scheduler->set_priority(0);
1639 scheduler->set_weight(0);
1640 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1641 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1642 traffic_shaping_info->set_cbs(60536);
1643 traffic_shaping_info->set_pbs(65536);
1644 traffic_shaping_info->set_gir(10000);
1645 }
1646
1647 virtual void TearDown() {
1648 }
1649
1650 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301651 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1652 alloc_cfg_compltd_key k(0, 1024);
1653 alloc_cfg_complete_result res;
1654 res.pon_intf_id = 0;
1655 res.alloc_id = 1024;
1656 res.state = state;
1657 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001658
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301659 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1660 // before we push the result.
1661 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1662 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1663 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1664 if (it == alloc_cfg_compltd_map.end()) {
1665 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 -05001666 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301667 it->second->push(res);
1668 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001669 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301670 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1671 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001672 }
1673};
1674
1675// Test 1 - CreateTrafficSchedulers-Upstream success case
1676TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1677 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1678 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1679 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1680 traffic_sched->set_allocated_scheduler(scheduler);
1681 traffic_shaping_info->set_cir(64000);
1682 traffic_shaping_info->set_pir(128000);
1683 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1684
1685 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1686 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1687
1688 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301689 future<int> push_alloc_cfg_complt = \
1690 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001691
1692 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301693 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001694 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1695}
1696
1697// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1698TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1699 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1700 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1701 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1702 traffic_sched->set_allocated_scheduler(scheduler);
1703 traffic_shaping_info->set_cir(64000);
1704 traffic_shaping_info->set_pir(128000);
1705 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1706
1707 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1708 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1709
1710 Status status = CreateTrafficSchedulers_(traffic_scheds);
1711 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1712}
1713
1714// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1715TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1716 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1717 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1718 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1719 traffic_sched->set_allocated_scheduler(scheduler);
1720 traffic_shaping_info->set_cir(64000);
1721 traffic_shaping_info->set_pir(128000);
1722 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1723
1724 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1725 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1726
1727 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301728 future<int> push_alloc_cfg_complt = \
1729 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001730
1731 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301732 int res = push_alloc_cfg_complt.get();
1733
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001734 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1735}
1736
1737// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1738TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1739 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1740 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1741 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1742 traffic_sched->set_allocated_scheduler(scheduler);
1743 traffic_shaping_info->set_cir(64000);
1744 traffic_shaping_info->set_pir(128000);
1745 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1746
1747 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1748 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1749
1750 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301751 future<int> push_alloc_cfg_complt = \
1752 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001753
1754 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301755 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001756 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1757}
1758
1759// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1760TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1761 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1762 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1763 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1764 traffic_sched->set_allocated_scheduler(scheduler);
1765 traffic_shaping_info->set_cir(64000);
1766 traffic_shaping_info->set_pir(128000);
1767 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1768
1769 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1770 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1771
1772 Status status = CreateTrafficSchedulers_(traffic_scheds);
1773 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1774}
1775
1776// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1777TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1778 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1779 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1780 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1781 traffic_sched->set_allocated_scheduler(scheduler);
1782 traffic_shaping_info->set_cir(64000);
1783 traffic_shaping_info->set_pir(0);
1784 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1785
1786 Status status = CreateTrafficSchedulers_(traffic_scheds);
1787 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1788}
1789
1790// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1791TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1792 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1793 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1794 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1795 traffic_sched->set_allocated_scheduler(scheduler);
1796 traffic_shaping_info->set_cir(64000);
1797 traffic_shaping_info->set_pir(32000);
1798 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1799
1800 Status status = CreateTrafficSchedulers_(traffic_scheds);
1801 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1802}
1803
1804// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1805TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1806 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1807 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1808 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1809 traffic_sched->set_allocated_scheduler(scheduler);
1810 traffic_shaping_info->set_cir(64000);
1811 traffic_shaping_info->set_pir(64000);
1812 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1813
1814 Status status = CreateTrafficSchedulers_(traffic_scheds);
1815 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1816}
1817
1818// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1819TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1820 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1821 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1822 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1823 traffic_sched->set_allocated_scheduler(scheduler);
1824 traffic_shaping_info->set_cir(64000);
1825 traffic_shaping_info->set_pir(0);
1826 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1827
1828 Status status = CreateTrafficSchedulers_(traffic_scheds);
1829 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1830}
1831
1832// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1833TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1834 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1835 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1836 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1837 traffic_sched->set_allocated_scheduler(scheduler);
1838 traffic_shaping_info->set_cir(0);
1839 traffic_shaping_info->set_pir(32000);
1840 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1841
1842 Status status = CreateTrafficSchedulers_(traffic_scheds);
1843 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1844}
1845
1846// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1847TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1848 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1849 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1850 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1851 traffic_sched->set_allocated_scheduler(scheduler);
1852 traffic_shaping_info->set_cir(64000);
1853 traffic_shaping_info->set_pir(32000);
1854 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1855
1856 Status status = CreateTrafficSchedulers_(traffic_scheds);
1857 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1858}
1859
1860// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1861TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1862 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1863 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1864 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1865 traffic_sched->set_allocated_scheduler(scheduler);
1866 traffic_shaping_info->set_cir(64000);
1867 traffic_shaping_info->set_pir(64000);
1868 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1869
1870 Status status = CreateTrafficSchedulers_(traffic_scheds);
1871 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1872}
1873
1874// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1875TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1876 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1877 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1878 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1879 traffic_sched->set_allocated_scheduler(scheduler);
1880 traffic_shaping_info->set_cir(64000);
1881 traffic_shaping_info->set_pir(0);
1882 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1883
1884 Status status = CreateTrafficSchedulers_(traffic_scheds);
1885 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1886}
1887
1888// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1889TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1890 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1891 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1892 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1893 traffic_sched->set_allocated_scheduler(scheduler);
1894 traffic_shaping_info->set_cir(0);
1895 traffic_shaping_info->set_pir(32000);
1896 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1897
1898 Status status = CreateTrafficSchedulers_(traffic_scheds);
1899 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1900}
1901
1902// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1903TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1904 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1905 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1906 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1907 traffic_sched->set_allocated_scheduler(scheduler);
1908 traffic_shaping_info->set_cir(64000);
1909 traffic_shaping_info->set_pir(128000);
1910 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1911
1912 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1913 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1914
1915 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301916 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001917 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1918
1919 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301920 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001921 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1922}
1923
1924// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1925TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1926 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1927 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1928 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1929 traffic_sched->set_allocated_scheduler(scheduler);
1930 traffic_shaping_info->set_cir(64000);
1931 traffic_shaping_info->set_pir(32000);
1932 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1933
1934 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1935 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1936
1937 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301938 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001939 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1940
1941 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301942 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001943 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1944}
1945
1946// Test 17 - CreateTrafficSchedulers-Downstream success case
1947TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
1948 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1949 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1950 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1951 traffic_sched->set_allocated_scheduler(scheduler);
1952 traffic_shaping_info->set_cir(64000);
1953 traffic_shaping_info->set_pir(128000);
1954 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1955
1956 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1957 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1958
1959 Status status = CreateTrafficSchedulers_(traffic_scheds);
1960 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1961}
1962
1963// Test 18 - CreateTrafficSchedulers-Downstream Failure case
1964TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
1965 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1966 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1967 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1968 traffic_sched->set_allocated_scheduler(scheduler);
1969 traffic_shaping_info->set_cir(64000);
1970 traffic_shaping_info->set_pir(128000);
1971 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1972
1973 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1974 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1975
1976 Status status = CreateTrafficSchedulers_(traffic_scheds);
1977 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1978}
1979
1980// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
1981TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
1982 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1983 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1984 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1985 traffic_sched->set_allocated_scheduler(scheduler);
1986 traffic_shaping_info->set_cir(64000);
1987 traffic_shaping_info->set_pir(128000);
1988 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1989
1990 Status status = CreateTrafficSchedulers_(traffic_scheds);
1991 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1992}
1993
1994////////////////////////////////////////////////////////////////////////////
1995// For testing RemoveTrafficSchedulers functionality
1996////////////////////////////////////////////////////////////////////////////
1997
1998class TestRemoveTrafficSchedulers : public Test {
1999 protected:
2000 NiceMock<BalMocker> balMock;
2001 tech_profile::TrafficSchedulers* traffic_scheds;
2002 tech_profile::TrafficScheduler* traffic_sched;
2003 tech_profile::SchedulerConfig* scheduler;
2004 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2005 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302006 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002007
2008 virtual void SetUp() {
2009 traffic_scheds = new tech_profile::TrafficSchedulers;
2010 traffic_scheds->set_intf_id(0);
2011 traffic_scheds->set_onu_id(1);
2012 traffic_scheds->set_uni_id(0);
2013 traffic_scheds->set_port_no(16);
2014 traffic_sched = traffic_scheds->add_traffic_scheds();
2015 traffic_sched->set_alloc_id(1025);
2016 scheduler = new tech_profile::SchedulerConfig;
2017 scheduler->set_priority(0);
2018 scheduler->set_weight(0);
2019 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2020 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2021 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2022 traffic_shaping_info->set_cir(64000);
2023 traffic_shaping_info->set_pir(128000);
2024 traffic_shaping_info->set_cbs(60536);
2025 traffic_shaping_info->set_pbs(65536);
2026 traffic_shaping_info->set_gir(10000);
2027 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2028 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2029 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2030 }
2031
2032 virtual void TearDown() {
2033 }
2034
2035 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302036 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2037 alloc_cfg_compltd_key k(0, 1025);
2038 alloc_cfg_complete_result res;
2039 res.pon_intf_id = 0;
2040 res.alloc_id = 1025;
2041 res.state = state;
2042 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002043
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302044 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2045 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2046 if (it == alloc_cfg_compltd_map.end()) {
2047 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 -05002048 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302049 it->second->push(res);
2050 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002051 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302052 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2053 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002054 }
2055};
2056
2057// Test 1 - RemoveTrafficSchedulers-Upstream success case
2058TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2059 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2060 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2061 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2062
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302063 bcmolt_pon_interface_key pon_key;
2064 bcmolt_pon_interface_cfg pon_cfg;
2065 pon_key.pon_ni = pon_id;
2066 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2067 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2068 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2069 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2070 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2071
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002072 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302073 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002074 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2075
2076 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302077 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002078 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2079}
2080
2081// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2082TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2083 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2084 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2085 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2086
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302087 bcmolt_pon_interface_key pon_key;
2088 bcmolt_pon_interface_cfg pon_cfg;
2089 pon_key.pon_ni = pon_id;
2090 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2091 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2092 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2093 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2094 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2095
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002096 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302097 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002098 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2099
2100 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302101 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002102 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2103}
2104
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302105// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2106TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2107 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2108 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2109 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2110
2111 bcmolt_pon_interface_key pon_key;
2112 bcmolt_pon_interface_cfg pon_cfg;
2113 pon_key.pon_ni = pon_id;
2114 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2115 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2116 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2117 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2118 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2119
2120 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2121
2122 Status status = future_res.get();
2123 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2124}
2125
2126// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2127TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2128 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2129 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2130 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2131
2132 bcmolt_pon_interface_key pon_key;
2133 bcmolt_pon_interface_cfg pon_cfg;
2134 pon_key.pon_ni = pon_id;
2135 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2136 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2137 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2138 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2139 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2140
2141 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2142
2143 Status status = future_res.get();
2144 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2145}
2146
2147// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002148TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2149 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2150
2151 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2152 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2153
2154 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2155 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2156}
2157
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302158// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002159TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2160 //Create Scheduler
2161 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2162 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2163 traffic_sched->set_allocated_scheduler(scheduler);
2164 CreateTrafficSchedulers_(traffic_scheds);
2165
2166 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2167 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2168
2169 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2170 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2171}
2172
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302173// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002174TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2175 //Create Scheduler
2176 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2177 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2178 traffic_sched->set_allocated_scheduler(scheduler);
2179 CreateTrafficSchedulers_(traffic_scheds);
2180
2181 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2182 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2183
2184 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2185 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2186}
2187
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302188// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002189TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2190 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2191
2192 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2193 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2194}
2195
2196////////////////////////////////////////////////////////////////////////////
2197// For testing CreateTrafficQueues functionality
2198////////////////////////////////////////////////////////////////////////////
2199
2200class TestCreateTrafficQueues : public Test {
2201 protected:
2202 NiceMock<BalMocker> balMock;
2203 tech_profile::TrafficQueues* traffic_queues;
2204 tech_profile::TrafficQueue* traffic_queue_1;
2205 tech_profile::TrafficQueue* traffic_queue_2;
2206 tech_profile::DiscardConfig* discard_config_1;
2207 tech_profile::DiscardConfig* discard_config_2;
2208 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2209 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2210
2211 virtual void SetUp() {
2212 traffic_queues = new tech_profile::TrafficQueues;
2213 traffic_queues->set_intf_id(0);
2214 traffic_queues->set_onu_id(1);
2215 traffic_queue_1 = traffic_queues->add_traffic_queues();
2216 traffic_queue_1->set_gemport_id(1024);
2217 traffic_queue_1->set_pbit_map("0b00000101");
2218 traffic_queue_1->set_aes_encryption(true);
2219 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2220 traffic_queue_1->set_priority(0);
2221 traffic_queue_1->set_weight(0);
2222 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2223 discard_config_1 = new tech_profile::DiscardConfig;
2224 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2225 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2226 tail_drop_discard_config_1->set_queue_size(8);
2227 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2228 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2229 }
2230
2231 virtual void TearDown() {
2232 }
2233};
2234
2235// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2236TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2237 Status status;
2238 traffic_queues->set_uni_id(0);
2239 traffic_queues->set_port_no(16);
2240 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2241
2242 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2243 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2244
2245 status = CreateTrafficQueues_(traffic_queues);
2246 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2247
2248 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2249 status = CreateTrafficQueues_(traffic_queues);
2250 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2251}
2252
2253// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2254TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2255 traffic_queues->set_uni_id(1);
2256 traffic_queues->set_port_no(32);
2257 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2258
2259 traffic_queue_2 = traffic_queues->add_traffic_queues();
2260 traffic_queue_2->set_gemport_id(1025);
2261 traffic_queue_2->set_pbit_map("0b00001010");
2262 traffic_queue_2->set_aes_encryption(true);
2263 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2264 traffic_queue_2->set_priority(1);
2265 traffic_queue_2->set_weight(0);
2266 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2267 discard_config_2 = new tech_profile::DiscardConfig;
2268 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2269 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2270 tail_drop_discard_config_2->set_queue_size(8);
2271 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2272 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2273 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2274
2275 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2276 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2277
2278 Status status = CreateTrafficQueues_(traffic_queues);
2279 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2280}
2281
2282// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2283TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2284 traffic_queues->set_uni_id(2);
2285 traffic_queues->set_port_no(16);
2286 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2287
2288 traffic_queue_2 = traffic_queues->add_traffic_queues();
2289 traffic_queue_2->set_gemport_id(1025);
2290 traffic_queue_2->set_pbit_map("0b10001010");
2291 traffic_queue_2->set_aes_encryption(true);
2292 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2293 traffic_queue_2->set_priority(1);
2294 traffic_queue_2->set_weight(0);
2295 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2296 discard_config_2 = new tech_profile::DiscardConfig;
2297 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2298 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2299 tail_drop_discard_config_2->set_queue_size(8);
2300 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2301 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2302 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2303
2304 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2305 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2306
2307 Status status = CreateTrafficQueues_(traffic_queues);
2308 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2309}
2310
2311// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2312TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2313 traffic_queues->set_uni_id(3);
2314 traffic_queues->set_port_no(16);
2315 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2316
2317 traffic_queue_2 = traffic_queues->add_traffic_queues();
2318 traffic_queue_2->set_gemport_id(1025);
2319 traffic_queue_2->set_pbit_map("0b00001010");
2320 traffic_queue_2->set_aes_encryption(true);
2321 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2322 traffic_queue_2->set_priority(1);
2323 traffic_queue_2->set_weight(0);
2324 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2325 discard_config_2 = new tech_profile::DiscardConfig;
2326 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2327 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2328 tail_drop_discard_config_2->set_queue_size(8);
2329 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2330 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2331 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2332
2333 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2334 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2335
2336 Status status = CreateTrafficQueues_(traffic_queues);
2337 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2338}
2339
2340// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2341TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2342 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2343 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2344 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2345
2346 traffic_queue_2 = traffic_queues->add_traffic_queues();
2347 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2348 traffic_queues->set_uni_id(uni_ids[i]);
2349 traffic_queues->set_port_no(port_nos[i]);
2350 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2351
2352 traffic_queue_2->set_gemport_id(1025);
2353 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2354 traffic_queue_2->set_aes_encryption(true);
2355 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2356 traffic_queue_2->set_priority(1);
2357 traffic_queue_2->set_weight(0);
2358 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2359 discard_config_2 = new tech_profile::DiscardConfig;
2360 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2361 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2362 tail_drop_discard_config_2->set_queue_size(8);
2363 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2364 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2365 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2366
2367 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2368 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2369
2370 Status status = CreateTrafficQueues_(traffic_queues);
2371 if(i==16)
2372 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2373 else
2374 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2375 }
2376}
2377
2378// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2379TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2380 traffic_queues->set_uni_id(0);
2381 traffic_queues->set_port_no(16);
2382 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2383
2384 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2385 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2386
2387 Status status = CreateTrafficQueues_(traffic_queues);
2388 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2389}
2390
2391////////////////////////////////////////////////////////////////////////////
2392// For testing RemoveTrafficQueues functionality
2393////////////////////////////////////////////////////////////////////////////
2394
2395class TestRemoveTrafficQueues : public Test {
2396 protected:
2397 NiceMock<BalMocker> balMock;
2398 tech_profile::TrafficQueues* traffic_queues;
2399 tech_profile::TrafficQueue* traffic_queue_1;
2400 tech_profile::TrafficQueue* traffic_queue_2;
2401
2402 virtual void SetUp() {
2403 traffic_queues = new tech_profile::TrafficQueues;
2404 traffic_queues->set_intf_id(0);
2405 traffic_queues->set_onu_id(1);
2406 traffic_queue_1 = traffic_queues->add_traffic_queues();
2407 traffic_queue_1->set_gemport_id(1024);
2408 traffic_queue_1->set_priority(0);
2409 }
2410
2411 virtual void TearDown() {
2412 }
2413};
2414
2415// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2416TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2417 Status status;
2418 traffic_queues->set_uni_id(0);
2419 traffic_queues->set_port_no(16);
2420 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2421
2422 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2423 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2424
2425 status = RemoveTrafficQueues_(traffic_queues);
2426 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2427
2428 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2429 status = RemoveTrafficQueues_(traffic_queues);
2430 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2431}
2432
2433// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2434TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2435 Status status;
2436 traffic_queues->set_uni_id(0);
2437 traffic_queues->set_port_no(16);
2438 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2439
2440 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2441 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2442
2443 status = RemoveTrafficQueues_(traffic_queues);
2444 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2445}
2446
2447// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2448TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2449 //Remove scheduler so that is_tm_sched_id_present api call will return false
2450 tech_profile::TrafficSchedulers* traffic_scheds;
2451 tech_profile::TrafficScheduler* traffic_sched;
2452 traffic_scheds = new tech_profile::TrafficSchedulers;
2453 traffic_scheds->set_intf_id(0);
2454 traffic_scheds->set_onu_id(1);
2455 traffic_scheds->set_uni_id(0);
2456 traffic_scheds->set_port_no(16);
2457 traffic_sched = traffic_scheds->add_traffic_scheds();
2458 traffic_sched->set_alloc_id(1024);
2459 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2460
2461 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2462 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2463 RemoveTrafficSchedulers_(traffic_scheds);
2464
2465 traffic_queues->set_uni_id(0);
2466 traffic_queues->set_port_no(16);
2467 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2468
2469 Status status = RemoveTrafficQueues_(traffic_queues);
2470 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2471}
2472
2473/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2474as it is getting referred by some other queues case */
2475TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2476 traffic_queues->set_uni_id(3);
2477 traffic_queues->set_port_no(16);
2478 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2479 traffic_queue_2 = traffic_queues->add_traffic_queues();
2480 traffic_queue_2->set_gemport_id(1025);
2481 traffic_queue_2->set_priority(1);
2482 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2483
2484 Status status = RemoveTrafficQueues_(traffic_queues);
2485 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2486}
2487
2488/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2489is not getting referred by any other queues case */
2490TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2491 traffic_queues->set_uni_id(1);
2492 traffic_queues->set_port_no(32);
2493 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2494 traffic_queue_2 = traffic_queues->add_traffic_queues();
2495 traffic_queue_2->set_gemport_id(1025);
2496 traffic_queue_2->set_priority(1);
2497
2498 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2499 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2500
2501 Status status = RemoveTrafficQueues_(traffic_queues);
2502 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2503}
2504
2505/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2506having no reference to any other queues case */
2507TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2508 traffic_queues->set_uni_id(4);
2509 traffic_queues->set_port_no(64);
2510 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2511 traffic_queue_2 = traffic_queues->add_traffic_queues();
2512 traffic_queue_2->set_gemport_id(1025);
2513 traffic_queue_2->set_priority(1);
2514
2515 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2516 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2517
2518 Status status = RemoveTrafficQueues_(traffic_queues);
2519 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2520}