blob: d82a69785c36b54ee4b20c1b8743556c7604cb5b [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
Girish Gowdra489425a2020-02-22 13:07:42 +05301125// TODO: VOL-2494
Jason Huang09b73ea2020-01-08 17:52:05 +08001126#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001127////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001128// For testing FlowAdd functionality
1129////////////////////////////////////////////////////////////////////////////
1130
1131class TestFlowAdd : public Test {
1132 protected:
1133 int32_t access_intf_id = 0;
1134 int32_t onu_id = 1;
1135 int32_t uni_id = 0;
1136 uint32_t port_no = 16;
1137 uint32_t flow_id = 1;
1138 std::string flow_type = "upstream";
1139 int32_t alloc_id = 1024;
1140 int32_t network_intf_id = 0;
1141 int32_t gemport_id = 1024;
1142 int32_t priority_value = 0;
1143 uint64_t cookie = 0;
1144
1145 NiceMock<BalMocker> balMock;
1146 openolt::Flow* flow;
1147 openolt::Classifier* classifier;
1148 openolt::Action* action;
1149 openolt::ActionCmd* cmd;
1150
1151 bcmolt_flow_key flow_key;
1152 bcmolt_flow_cfg flow_cfg;
1153
1154 tech_profile::TrafficQueues* traffic_queues;
1155 tech_profile::TrafficQueue* traffic_queue_1;
1156 tech_profile::TrafficQueue* traffic_queue_2;
1157 tech_profile::DiscardConfig* discard_config_1;
1158 tech_profile::DiscardConfig* discard_config_2;
1159 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
1160 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
1161
1162
1163 virtual void SetUp() {
1164 classifier = new openolt::Classifier;
1165 action = new openolt::Action;
1166 cmd = new openolt::ActionCmd;
1167
1168 classifier->set_o_tpid(0);
1169 classifier->set_o_vid(7);
1170 classifier->set_i_tpid(0);
1171 classifier->set_i_vid(0);
1172 classifier->set_o_pbits(0);
1173 classifier->set_i_pbits(0);
1174 classifier->set_eth_type(0);
1175 classifier->set_ip_proto(0);
1176 classifier->set_src_port(0);
1177 classifier->set_dst_port(0);
1178 classifier->set_pkt_tag_type("single_tag");
1179
1180 action->set_o_vid(12);
1181 action->set_o_pbits(0);
1182 action->set_o_tpid(0);
1183 action->set_i_vid(0);
1184 action->set_i_pbits(0);
1185 action->set_i_tpid(0);
1186
1187 cmd->set_add_outer_tag(true);
1188 cmd->set_remove_outer_tag(false);
1189 cmd->set_trap_to_host(false);
1190 action->set_allocated_cmd(cmd);
1191
1192 flow_key.flow_id = 1;
1193 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1194 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1195 flow_cfg.data.onu_id=1;
1196 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1197 flow_cfg.data.svc_port_id=1024;
1198 flow_cfg.data.priority=0;
1199 flow_cfg.data.cookie=0;
1200 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1201 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1202 flow_cfg.data.ingress_intf.intf_id=0;
1203 flow_cfg.data.egress_intf.intf_id=0;
1204 flow_cfg.data.classifier.o_vid=7;
1205 flow_cfg.data.classifier.o_pbits=0;
1206 flow_cfg.data.classifier.i_vid=0;
1207 flow_cfg.data.classifier.i_pbits=0;
1208 flow_cfg.data.classifier.ether_type=0;
1209 flow_cfg.data.classifier.ip_proto=0;
1210 flow_cfg.data.classifier.src_port=0;
1211 flow_cfg.data.classifier.dst_port=0;
1212 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1213 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1214 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1215 flow_cfg.data.egress_qos.tm_sched.id=1020;
1216 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1217 flow_cfg.data.action.o_vid=12;
1218 flow_cfg.data.action.o_pbits=0;
1219 flow_cfg.data.action.i_vid=0;
1220 flow_cfg.data.action.i_pbits=0;
1221 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1222
1223 traffic_queues = new tech_profile::TrafficQueues;
1224 traffic_queues->set_intf_id(0);
1225 traffic_queues->set_onu_id(2);
1226 traffic_queue_1 = traffic_queues->add_traffic_queues();
1227 traffic_queue_1->set_gemport_id(1024);
1228 traffic_queue_1->set_pbit_map("0b00000101");
1229 traffic_queue_1->set_aes_encryption(true);
1230 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1231 traffic_queue_1->set_priority(0);
1232 traffic_queue_1->set_weight(0);
1233 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1234 discard_config_1 = new tech_profile::DiscardConfig;
1235 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1236 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
1237 tail_drop_discard_config_1->set_queue_size(8);
1238 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
1239 traffic_queue_1->set_allocated_discard_config(discard_config_1);
1240
1241 traffic_queues->set_uni_id(0);
1242 traffic_queues->set_port_no(16);
1243
1244 traffic_queue_2 = traffic_queues->add_traffic_queues();
1245 traffic_queue_2->set_gemport_id(1025);
1246 traffic_queue_2->set_pbit_map("0b00001010");
1247 traffic_queue_2->set_aes_encryption(true);
1248 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1249 traffic_queue_2->set_priority(1);
1250 traffic_queue_2->set_weight(0);
1251 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1252 discard_config_2 = new tech_profile::DiscardConfig;
1253 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
1254 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
1255 tail_drop_discard_config_2->set_queue_size(8);
1256 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
1257 traffic_queue_2->set_allocated_discard_config(discard_config_2);
1258 }
1259
1260 virtual void TearDown() {
1261 }
1262};
1263
1264// Test 1 - FlowAdd - success case(HSIA-upstream FixedQueue)
1265TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamSuccess) {
1266 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1267 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1268
1269 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);
1270 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1271}
1272
1273// Test 2 - FlowAdd - Duplicate Flow case
1274TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamDuplicate) {
1275 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1276 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1277 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1278
1279 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);
1280 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1281}
1282
1283// Test 3 - FlowAdd - Failure case(bcmolt_cfg_set returns error)
1284TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueUpstreamFailure) {
1285 gemport_id = 1025;
1286
1287 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1288 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1289
1290 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1291 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1292 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1293
1294 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);
1295 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1296}
1297
1298// Test 4 - FlowAdd - Failure case(Invalid flow direction)
1299TEST_F(TestFlowAdd, FlowAddFailureInvalidFlowDirection) {
1300 flow_type = "bidirectional";
1301
1302 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);
1303 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1304}
1305
1306// Test 5 - FlowAdd - Failure case(Invalid network setting)
1307TEST_F(TestFlowAdd, FlowAddFailureInvalidNWCfg) {
1308 network_intf_id = -1;
1309
1310 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);
1311 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1312}
1313
1314// Test 6 - FlowAdd - Success case(Single tag & EAP Ether type)
1315TEST_F(TestFlowAdd, FlowAddEapEtherTypeSuccess) {
1316 flow_id = 2;
1317
1318 classifier->set_eth_type(34958);
1319 cmd->set_add_outer_tag(false);
1320 cmd->set_trap_to_host(true);
1321 action->set_allocated_cmd(cmd);
1322
1323 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1324 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1325 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1326 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1327 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1328
1329 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);
1330 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1331}
1332
1333// Test 7 - FlowAdd - Success case(Single tag & DHCP flow)
1334TEST_F(TestFlowAdd, FlowAddDhcpSuccess) {
1335 flow_id = 3;
1336 gemport_id = 1025;
1337
1338 classifier->set_ip_proto(17);
1339 classifier->set_src_port(68);
1340 classifier->set_dst_port(67);
1341 cmd->set_add_outer_tag(false);
1342 cmd->set_trap_to_host(true);
1343 action->set_allocated_cmd(cmd);
1344
1345 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1346 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1347 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1348 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1349 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1350
1351 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);
1352 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1353}
1354
1355// Test 8 - FlowAdd - success case(HSIA-downstream FixedQueue)
1356TEST_F(TestFlowAdd, FlowAddHsiaFixedQueueDownstreamSuccess) {
1357 flow_id = 4;
1358 flow_type = "downstream";
1359
1360 classifier->set_o_vid(12);
1361 classifier->set_i_vid(7);
1362 classifier->set_pkt_tag_type("double_tag");
1363 action->set_o_vid(0);
1364 cmd->set_add_outer_tag(false);
1365 cmd->set_remove_outer_tag(true);
1366 action->set_allocated_cmd(cmd);
1367
1368 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1369 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1370 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1371 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1372 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1373
1374 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);
1375 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1376}
1377
1378// Test 9 - FlowAdd - success case(HSIA-upstream PriorityQueue)
1379TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueUpstreamSuccess) {
1380 onu_id = 2;
1381 flow_id = 5;
1382 alloc_id = 1025;
1383
1384 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
1385 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
1386
1387 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1388 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1389 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1390 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1391 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1392 CreateTrafficQueues_(traffic_queues);
1393
1394 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);
1395 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1396}
1397
1398// Test 10 - FlowAdd - success case(HSIA-downstream PriorityQueue)
1399TEST_F(TestFlowAdd, FlowAddHsiaPriorityQueueDownstreamSuccess) {
1400 onu_id = 2;
1401 flow_id = 6;
1402 flow_type = "downstream";
1403 alloc_id = 1025;
1404
1405 classifier->set_o_vid(12);
1406 classifier->set_i_vid(7);
1407 classifier->set_pkt_tag_type("double_tag");
1408 action->set_o_vid(0);
1409 cmd->set_add_outer_tag(false);
1410 cmd->set_remove_outer_tag(true);
1411 action->set_allocated_cmd(cmd);
1412
1413 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
1414 traffic_queue_2->set_direction(tech_profile::Direction::DOWNSTREAM);
1415
1416 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1417 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1418 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1419 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1420 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1421 CreateTrafficQueues_(traffic_queues);
1422
1423 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);
1424 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1425}
Jason Huang09b73ea2020-01-08 17:52:05 +08001426#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001427
1428////////////////////////////////////////////////////////////////////////////
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001429// For testing OnuPacketOut functionality
1430////////////////////////////////////////////////////////////////////////////
1431
1432class TestOnuPacketOut : public Test {
1433 protected:
1434 uint32_t pon_id = 0;
1435 uint32_t onu_id = 1;
1436 std::string pkt = "omci-pkt";
1437 NiceMock<BalMocker> balMock;
1438
1439 virtual void SetUp() {
1440 }
1441
1442 virtual void TearDown() {
1443 }
1444};
1445
1446// Test 1 - OnuPacketOut success case
1447TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
1448 uint32_t port_no = 16;
1449 uint32_t gemport_id = 1024;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001450
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001451 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001452 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1453
1454 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1455 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1456}
1457
1458// Test 2 - OnuPacketOut Port number as 0 case
1459TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
1460 uint32_t port_no = 0;
1461 uint32_t gemport_id = 1024;
1462
1463 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1464 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1465}
1466
Girish Gowdra489425a2020-02-22 13:07:42 +05301467// TODO: VOL-2494
1468#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001469// Test 3 - OnuPacketOut success, Finding Flow ID from port no and Gem from Flow ID case
1470TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowSuccess) {
1471 uint32_t port_no = 16;
1472 uint32_t gemport_id = 0;
1473
1474 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1475 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1476
1477 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1478 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1479}
Girish Gowdra489425a2020-02-22 13:07:42 +05301480#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001481
1482// Test 4 - OnuPacketOut success, Failure in finding Gem port case
1483TEST_F(TestOnuPacketOut, OnuPacketOutFindGemFromFlowFailure) {
1484 uint32_t port_no = 64;
1485 uint32_t gemport_id = 0;
1486
1487 bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
1488 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
1489
1490 Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
1491 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1492}
1493
Girish Gowdra489425a2020-02-22 13:07:42 +05301494// TODO: VOL-2494
Jason Huang09b73ea2020-01-08 17:52:05 +08001495#if 0
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001496////////////////////////////////////////////////////////////////////////////
1497// For testing FlowRemove functionality
1498////////////////////////////////////////////////////////////////////////////
1499
1500class TestFlowRemove : public Test {
1501 protected:
1502 NiceMock<BalMocker> balMock;
1503
1504 virtual void SetUp() {
1505 }
1506
1507 virtual void TearDown() {
1508 }
1509};
1510
1511// Test 1 - FlowRemove - Failure case
1512TEST_F(TestFlowRemove, FlowRemoveFailure) {
1513 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
1514 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1515
1516 Status status = FlowRemove_(1, "upstream");
1517 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1518}
1519
1520// Test 2 - FlowRemove - success case
1521TEST_F(TestFlowRemove, FlowRemoveSuccess) {
1522 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
1523 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
1524
1525 Status status = FlowRemove_(1, "upstream");
1526 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1527}
1528
1529////////////////////////////////////////////////////////////////////////////
1530// For testing UplinkPacketOut functionality
1531////////////////////////////////////////////////////////////////////////////
1532
1533class TestUplinkPacketOut : public Test {
1534 protected:
1535 uint32_t pon_id = 0;
1536 std::string pkt = "omci-pkt";
1537 NiceMock<BalMocker> balMock;
1538
1539 bcmolt_flow_key flow_key;
1540 bcmolt_flow_cfg flow_cfg;
1541
1542 virtual void SetUp() {
1543 flow_key.flow_id = 1;
1544 flow_key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1545 BCMOLT_CFG_INIT(&flow_cfg, flow, flow_key);
1546 flow_cfg.data.onu_id=1;
1547 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_UPSTREAM;
1548 flow_cfg.data.svc_port_id=1024;
1549 flow_cfg.data.priority=0;
1550 flow_cfg.data.cookie=0;
1551 flow_cfg.data.ingress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_PON;
1552 flow_cfg.data.egress_intf.intf_type=BCMOLT_FLOW_INTERFACE_TYPE_NNI;
1553 flow_cfg.data.ingress_intf.intf_id=0;
1554 flow_cfg.data.egress_intf.intf_id=0;
1555 flow_cfg.data.classifier.o_vid=7;
1556 flow_cfg.data.classifier.o_pbits=0;
1557 flow_cfg.data.classifier.i_vid=0;
1558 flow_cfg.data.classifier.i_pbits=0;
1559 flow_cfg.data.classifier.ether_type=0;
1560 flow_cfg.data.classifier.ip_proto=0;
1561 flow_cfg.data.classifier.src_port=0;
1562 flow_cfg.data.classifier.dst_port=0;
1563 flow_cfg.data.classifier.pkt_tag_type=BCMOLT_PKT_TAG_TYPE_SINGLE_TAG;
1564 flow_cfg.data.egress_qos.type=BCMOLT_EGRESS_QOS_TYPE_FIXED_QUEUE;
1565 flow_cfg.data.egress_qos.u.fixed_queue.queue_id=0;
1566 flow_cfg.data.egress_qos.tm_sched.id=1020;
1567 flow_cfg.data.action.cmds_bitmask=BCMOLT_ACTION_CMD_ID_ADD_OUTER_TAG;
1568 flow_cfg.data.action.o_vid=12;
1569 flow_cfg.data.action.o_pbits=0;
1570 flow_cfg.data.action.i_vid=0;
1571 flow_cfg.data.action.i_pbits=0;
1572 flow_cfg.data.state=BCMOLT_FLOW_STATE_ENABLE;
1573 }
1574
1575 virtual void TearDown() {
1576 }
1577};
1578
1579// Test 1 - UplinkPacketOut success case
1580TEST_F(TestUplinkPacketOut, UplinkPacketOutSuccess) {
1581 bcmos_errno send_eth_oper_sub_res = BCM_ERR_OK;
1582 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1583 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1584 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1585 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1586
1587 Status status = UplinkPacketOut_(pon_id, pkt);
1588 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1589}
1590
1591// Test 2 - UplinkPacketOut Failure case
1592TEST_F(TestUplinkPacketOut, UplinkPacketOutFailure) {
1593 bcmos_errno send_eth_oper_sub_res = BCM_ERR_INTERNAL;
1594 ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(send_eth_oper_sub_res));
1595 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1596 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1597 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1598
1599 Status status = UplinkPacketOut_(pon_id, pkt);
1600 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1601}
1602
1603// Test 3 - UplinkPacketOut No matching flow id found for Uplink Packetout case
1604TEST_F(TestUplinkPacketOut, UplinkPacketOutFailureNoFlowIdFound) {
1605 flow_cfg.key.flow_type = BCMOLT_FLOW_TYPE_DOWNSTREAM;
1606
1607 FlowRemove_(2, "upstream");
1608 FlowRemove_(3, "upstream");
1609 FlowRemove_(4, "downstream");
1610 FlowRemove_(5, "upstream");
1611 FlowRemove_(6, "downstream");
1612
1613 bcmos_errno flow_cfg_get_stub_res = BCM_ERR_OK;
1614 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__flow_stub, bcmolt_cfg_get__flow_stub(_, _))
1615 .WillRepeatedly(DoAll(SetArg1ToBcmOltFlowCfg(flow_cfg), Return(flow_cfg_get_stub_res)));
1616
1617 Status status = UplinkPacketOut_(pon_id, pkt);
1618 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1619}
Jason Huang09b73ea2020-01-08 17:52:05 +08001620#endif
Thiyagarajan Subramani81c56112019-12-19 08:29:55 -05001621
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001622////////////////////////////////////////////////////////////////////////////
1623// For testing CreateTrafficSchedulers functionality
1624////////////////////////////////////////////////////////////////////////////
1625
1626class TestCreateTrafficSchedulers : public Test {
1627 protected:
1628 NiceMock<BalMocker> balMock;
1629 tech_profile::TrafficSchedulers* traffic_scheds;
1630 tech_profile::TrafficScheduler* traffic_sched;
1631 tech_profile::SchedulerConfig* scheduler;
1632 tech_profile::TrafficShapingInfo* traffic_shaping_info;
1633
1634 virtual void SetUp() {
1635 traffic_scheds = new tech_profile::TrafficSchedulers;
1636 traffic_scheds->set_intf_id(0);
1637 traffic_scheds->set_onu_id(1);
1638 traffic_scheds->set_uni_id(0);
1639 traffic_scheds->set_port_no(16);
1640 traffic_sched = traffic_scheds->add_traffic_scheds();
1641 traffic_sched->set_alloc_id(1024);
1642 scheduler = new tech_profile::SchedulerConfig;
1643 scheduler->set_priority(0);
1644 scheduler->set_weight(0);
1645 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
1646 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
1647 traffic_shaping_info->set_cbs(60536);
1648 traffic_shaping_info->set_pbs(65536);
1649 traffic_shaping_info->set_gir(10000);
1650 }
1651
1652 virtual void TearDown() {
1653 }
1654
1655 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301656 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
1657 alloc_cfg_compltd_key k(0, 1024);
1658 alloc_cfg_complete_result res;
1659 res.pon_intf_id = 0;
1660 res.alloc_id = 1024;
1661 res.state = state;
1662 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001663
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301664 // We need to wait for some time to allow the Alloc Cfg Request to be triggered
1665 // before we push the result.
1666 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1667 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
1668 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
1669 if (it == alloc_cfg_compltd_map.end()) {
1670 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 -05001671 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301672 it->second->push(res);
1673 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001674 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301675 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
1676 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001677 }
1678};
1679
1680// Test 1 - CreateTrafficSchedulers-Upstream success case
1681TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
1682 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1683 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1684 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1685 traffic_sched->set_allocated_scheduler(scheduler);
1686 traffic_shaping_info->set_cir(64000);
1687 traffic_shaping_info->set_pir(128000);
1688 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1689
1690 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1691 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1692
1693 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301694 future<int> push_alloc_cfg_complt = \
1695 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001696
1697 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301698 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001699 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1700}
1701
1702// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
1703TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
1704 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1705 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1706 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1707 traffic_sched->set_allocated_scheduler(scheduler);
1708 traffic_shaping_info->set_cir(64000);
1709 traffic_shaping_info->set_pir(128000);
1710 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1711
1712 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1713 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1714
1715 Status status = CreateTrafficSchedulers_(traffic_scheds);
1716 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1717}
1718
1719// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
1720TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
1721 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1722 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1723 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1724 traffic_sched->set_allocated_scheduler(scheduler);
1725 traffic_shaping_info->set_cir(64000);
1726 traffic_shaping_info->set_pir(128000);
1727 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1728
1729 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1730 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1731
1732 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301733 future<int> push_alloc_cfg_complt = \
1734 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001735
1736 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301737 int res = push_alloc_cfg_complt.get();
1738
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001739 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1740}
1741
1742// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
1743TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
1744 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1745 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1746 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1747 traffic_sched->set_allocated_scheduler(scheduler);
1748 traffic_shaping_info->set_cir(64000);
1749 traffic_shaping_info->set_pir(128000);
1750 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1751
1752 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1753 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1754
1755 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301756 future<int> push_alloc_cfg_complt = \
1757 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001758
1759 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301760 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001761 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1762}
1763
1764// Test 5 - CreateTrafficSchedulers-Upstream Failure case
1765TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
1766 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1767 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1768 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1769 traffic_sched->set_allocated_scheduler(scheduler);
1770 traffic_shaping_info->set_cir(64000);
1771 traffic_shaping_info->set_pir(128000);
1772 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1773
1774 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1775 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1776
1777 Status status = CreateTrafficSchedulers_(traffic_scheds);
1778 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1779}
1780
1781// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
1782TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
1783 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1784 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1785 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1786 traffic_sched->set_allocated_scheduler(scheduler);
1787 traffic_shaping_info->set_cir(64000);
1788 traffic_shaping_info->set_pir(0);
1789 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1790
1791 Status status = CreateTrafficSchedulers_(traffic_scheds);
1792 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1793}
1794
1795// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
1796TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
1797 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1798 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1799 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1800 traffic_sched->set_allocated_scheduler(scheduler);
1801 traffic_shaping_info->set_cir(64000);
1802 traffic_shaping_info->set_pir(32000);
1803 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1804
1805 Status status = CreateTrafficSchedulers_(traffic_scheds);
1806 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1807}
1808
1809// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
1810TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
1811 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1812 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1813 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1814 traffic_sched->set_allocated_scheduler(scheduler);
1815 traffic_shaping_info->set_cir(64000);
1816 traffic_shaping_info->set_pir(64000);
1817 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1818
1819 Status status = CreateTrafficSchedulers_(traffic_scheds);
1820 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1821}
1822
1823// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
1824TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
1825 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1826 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1827 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1828 traffic_sched->set_allocated_scheduler(scheduler);
1829 traffic_shaping_info->set_cir(64000);
1830 traffic_shaping_info->set_pir(0);
1831 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1832
1833 Status status = CreateTrafficSchedulers_(traffic_scheds);
1834 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1835}
1836
1837// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
1838TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
1839 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1840 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1841 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1842 traffic_sched->set_allocated_scheduler(scheduler);
1843 traffic_shaping_info->set_cir(0);
1844 traffic_shaping_info->set_pir(32000);
1845 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1846
1847 Status status = CreateTrafficSchedulers_(traffic_scheds);
1848 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1849}
1850
1851// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
1852TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
1853 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1854 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1855 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1856 traffic_sched->set_allocated_scheduler(scheduler);
1857 traffic_shaping_info->set_cir(64000);
1858 traffic_shaping_info->set_pir(32000);
1859 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1860
1861 Status status = CreateTrafficSchedulers_(traffic_scheds);
1862 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1863}
1864
1865// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
1866TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
1867 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1868 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
1869 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1870 traffic_sched->set_allocated_scheduler(scheduler);
1871 traffic_shaping_info->set_cir(64000);
1872 traffic_shaping_info->set_pir(64000);
1873 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1874
1875 Status status = CreateTrafficSchedulers_(traffic_scheds);
1876 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1877}
1878
1879// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
1880TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
1881 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1882 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1883 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1884 traffic_sched->set_allocated_scheduler(scheduler);
1885 traffic_shaping_info->set_cir(64000);
1886 traffic_shaping_info->set_pir(0);
1887 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1888
1889 Status status = CreateTrafficSchedulers_(traffic_scheds);
1890 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1891}
1892
1893// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
1894TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
1895 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1896 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1897 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1898 traffic_sched->set_allocated_scheduler(scheduler);
1899 traffic_shaping_info->set_cir(0);
1900 traffic_shaping_info->set_pir(32000);
1901 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1902
1903 Status status = CreateTrafficSchedulers_(traffic_scheds);
1904 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1905}
1906
1907// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
1908TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
1909 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1910 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1911 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1912 traffic_sched->set_allocated_scheduler(scheduler);
1913 traffic_shaping_info->set_cir(64000);
1914 traffic_shaping_info->set_pir(128000);
1915 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1916
1917 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1918 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1919
1920 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301921 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001922 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1923
1924 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301925 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001926 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1927}
1928
1929// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
1930TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
1931 scheduler->set_direction(tech_profile::Direction::UPSTREAM);
1932 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
1933 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
1934 traffic_sched->set_allocated_scheduler(scheduler);
1935 traffic_shaping_info->set_cir(64000);
1936 traffic_shaping_info->set_pir(32000);
1937 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1938
1939 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1940 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1941
1942 future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301943 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001944 async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
1945
1946 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05301947 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05001948 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1949}
1950
1951// Test 17 - CreateTrafficSchedulers-Downstream success case
1952TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
1953 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1954 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1955 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1956 traffic_sched->set_allocated_scheduler(scheduler);
1957 traffic_shaping_info->set_cir(64000);
1958 traffic_shaping_info->set_pir(128000);
1959 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1960
1961 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
1962 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1963
1964 Status status = CreateTrafficSchedulers_(traffic_scheds);
1965 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
1966}
1967
1968// Test 18 - CreateTrafficSchedulers-Downstream Failure case
1969TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
1970 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
1971 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1972 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
1973 traffic_sched->set_allocated_scheduler(scheduler);
1974 traffic_shaping_info->set_cir(64000);
1975 traffic_shaping_info->set_pir(128000);
1976 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1977
1978 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
1979 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
1980
1981 Status status = CreateTrafficSchedulers_(traffic_scheds);
1982 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1983}
1984
1985// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
1986TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
1987 scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1988 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
1989 traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
1990 traffic_sched->set_allocated_scheduler(scheduler);
1991 traffic_shaping_info->set_cir(64000);
1992 traffic_shaping_info->set_pir(128000);
1993 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
1994
1995 Status status = CreateTrafficSchedulers_(traffic_scheds);
1996 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
1997}
1998
1999////////////////////////////////////////////////////////////////////////////
2000// For testing RemoveTrafficSchedulers functionality
2001////////////////////////////////////////////////////////////////////////////
2002
2003class TestRemoveTrafficSchedulers : public Test {
2004 protected:
2005 NiceMock<BalMocker> balMock;
2006 tech_profile::TrafficSchedulers* traffic_scheds;
2007 tech_profile::TrafficScheduler* traffic_sched;
2008 tech_profile::SchedulerConfig* scheduler;
2009 tech_profile::TrafficShapingInfo* traffic_shaping_info;
2010 alloc_cfg_complete_result res;
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302011 uint32_t pon_id = 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002012
2013 virtual void SetUp() {
2014 traffic_scheds = new tech_profile::TrafficSchedulers;
2015 traffic_scheds->set_intf_id(0);
2016 traffic_scheds->set_onu_id(1);
2017 traffic_scheds->set_uni_id(0);
2018 traffic_scheds->set_port_no(16);
2019 traffic_sched = traffic_scheds->add_traffic_scheds();
2020 traffic_sched->set_alloc_id(1025);
2021 scheduler = new tech_profile::SchedulerConfig;
2022 scheduler->set_priority(0);
2023 scheduler->set_weight(0);
2024 scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2025 scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
2026 traffic_shaping_info = new tech_profile::TrafficShapingInfo;
2027 traffic_shaping_info->set_cir(64000);
2028 traffic_shaping_info->set_pir(128000);
2029 traffic_shaping_info->set_cbs(60536);
2030 traffic_shaping_info->set_pbs(65536);
2031 traffic_shaping_info->set_gir(10000);
2032 traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
2033 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2034 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2035 }
2036
2037 virtual void TearDown() {
2038 }
2039
2040 public:
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302041 static int PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
2042 alloc_cfg_compltd_key k(0, 1025);
2043 alloc_cfg_complete_result res;
2044 res.pon_intf_id = 0;
2045 res.alloc_id = 1025;
2046 res.state = state;
2047 res.status = status;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002048
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302049 bcmos_fastlock_lock(&alloc_cfg_wait_lock);
2050 std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
2051 if (it == alloc_cfg_compltd_map.end()) {
2052 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 -05002053 } else {
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302054 it->second->push(res);
2055 OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002056 }
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302057 bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
2058 return 0;
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002059 }
2060};
2061
Girish Gowdra489425a2020-02-22 13:07:42 +05302062// TODO: VOL-2494
2063#if 0
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002064// Test 1 - RemoveTrafficSchedulers-Upstream success case
2065TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
2066 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2067 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2068 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2069
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302070 bcmolt_pon_interface_key pon_key;
2071 bcmolt_pon_interface_cfg pon_cfg;
2072 pon_key.pon_ni = pon_id;
2073 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2074 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2075 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2076 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2077 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2078
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002079 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302080 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002081 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
2082
2083 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302084 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002085 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2086}
Girish Gowdra489425a2020-02-22 13:07:42 +05302087#endif
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002088
2089// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
2090TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
2091 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2092 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2093 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2094
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302095 bcmolt_pon_interface_key pon_key;
2096 bcmolt_pon_interface_cfg pon_cfg;
2097 pon_key.pon_ni = pon_id;
2098 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2099 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
2100 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2101 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2102 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2103
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002104 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302105 future<int> push_alloc_cfg_complt = \
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002106 async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
2107
2108 Status status = future_res.get();
Girish Gowdra7a79dae2020-02-10 18:22:11 +05302109 int res = push_alloc_cfg_complt.get();
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002110 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2111}
2112
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302113// Test 3 - RemoveTrafficSchedulers-Upstream success case(PON disable case - Don't wait for alloc object delete response)
2114TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjPonDisable) {
2115 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2116 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2117 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2118
2119 bcmolt_pon_interface_key pon_key;
2120 bcmolt_pon_interface_cfg pon_cfg;
2121 pon_key.pon_ni = pon_id;
2122 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2123 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2124 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
2125 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2126 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2127
2128 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2129
2130 Status status = future_res.get();
2131 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2132}
2133
2134// Test 4 - RemoveTrafficSchedulers-Upstream success case(Get PON State failure case)
2135TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjGetPonStateFailure) {
2136 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2137 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2138 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2139
2140 bcmolt_pon_interface_key pon_key;
2141 bcmolt_pon_interface_cfg pon_cfg;
2142 pon_key.pon_ni = pon_id;
2143 BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
2144 pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
2145 bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_INTERNAL;
2146 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
2147 .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
2148
2149 future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
2150
2151 Status status = future_res.get();
2152 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2153}
2154
2155// Test 5 - RemoveTrafficSchedulers-Upstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002156TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
2157 traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
2158
2159 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2160 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2161
2162 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2163 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2164}
2165
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302166// Test 6 - RemoveTrafficSchedulers-Downstream Failure case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002167TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
2168 //Create Scheduler
2169 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2170 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2171 traffic_sched->set_allocated_scheduler(scheduler);
2172 CreateTrafficSchedulers_(traffic_scheds);
2173
2174 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2175 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2176
2177 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2178 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2179}
2180
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302181// Test 7 - RemoveTrafficSchedulers-Downstream success case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002182TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
2183 //Create Scheduler
2184 scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
2185 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2186 traffic_sched->set_allocated_scheduler(scheduler);
2187 CreateTrafficSchedulers_(traffic_scheds);
2188
2189 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2190 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2191
2192 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2193 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2194}
2195
Thiyagarajan Subramani8305c282020-02-04 20:07:42 +05302196// Test 8 - RemoveTrafficSchedulers-Downstream Scheduler not present case
Thiyagarajan Subramani6dc20052019-12-05 09:06:36 -05002197TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
2198 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2199
2200 Status status = RemoveTrafficSchedulers_(traffic_scheds);
2201 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2202}
2203
2204////////////////////////////////////////////////////////////////////////////
2205// For testing CreateTrafficQueues functionality
2206////////////////////////////////////////////////////////////////////////////
2207
2208class TestCreateTrafficQueues : public Test {
2209 protected:
2210 NiceMock<BalMocker> balMock;
2211 tech_profile::TrafficQueues* traffic_queues;
2212 tech_profile::TrafficQueue* traffic_queue_1;
2213 tech_profile::TrafficQueue* traffic_queue_2;
2214 tech_profile::DiscardConfig* discard_config_1;
2215 tech_profile::DiscardConfig* discard_config_2;
2216 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
2217 tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
2218
2219 virtual void SetUp() {
2220 traffic_queues = new tech_profile::TrafficQueues;
2221 traffic_queues->set_intf_id(0);
2222 traffic_queues->set_onu_id(1);
2223 traffic_queue_1 = traffic_queues->add_traffic_queues();
2224 traffic_queue_1->set_gemport_id(1024);
2225 traffic_queue_1->set_pbit_map("0b00000101");
2226 traffic_queue_1->set_aes_encryption(true);
2227 traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2228 traffic_queue_1->set_priority(0);
2229 traffic_queue_1->set_weight(0);
2230 traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2231 discard_config_1 = new tech_profile::DiscardConfig;
2232 discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2233 tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
2234 tail_drop_discard_config_1->set_queue_size(8);
2235 discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
2236 traffic_queue_1->set_allocated_discard_config(discard_config_1);
2237 }
2238
2239 virtual void TearDown() {
2240 }
2241};
2242
2243// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2244TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
2245 Status status;
2246 traffic_queues->set_uni_id(0);
2247 traffic_queues->set_port_no(16);
2248 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2249
2250 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2251 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2252
2253 status = CreateTrafficQueues_(traffic_queues);
2254 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2255
2256 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2257 status = CreateTrafficQueues_(traffic_queues);
2258 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2259}
2260
2261// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
2262TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
2263 traffic_queues->set_uni_id(1);
2264 traffic_queues->set_port_no(32);
2265 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2266
2267 traffic_queue_2 = traffic_queues->add_traffic_queues();
2268 traffic_queue_2->set_gemport_id(1025);
2269 traffic_queue_2->set_pbit_map("0b00001010");
2270 traffic_queue_2->set_aes_encryption(true);
2271 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2272 traffic_queue_2->set_priority(1);
2273 traffic_queue_2->set_weight(0);
2274 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2275 discard_config_2 = new tech_profile::DiscardConfig;
2276 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2277 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2278 tail_drop_discard_config_2->set_queue_size(8);
2279 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2280 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2281 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2282
2283 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2284 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2285
2286 Status status = CreateTrafficQueues_(traffic_queues);
2287 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2288}
2289
2290// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
2291TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
2292 traffic_queues->set_uni_id(2);
2293 traffic_queues->set_port_no(16);
2294 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2295
2296 traffic_queue_2 = traffic_queues->add_traffic_queues();
2297 traffic_queue_2->set_gemport_id(1025);
2298 traffic_queue_2->set_pbit_map("0b10001010");
2299 traffic_queue_2->set_aes_encryption(true);
2300 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2301 traffic_queue_2->set_priority(1);
2302 traffic_queue_2->set_weight(0);
2303 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2304 discard_config_2 = new tech_profile::DiscardConfig;
2305 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2306 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2307 tail_drop_discard_config_2->set_queue_size(8);
2308 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2309 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2310 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2311
2312 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2313 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2314
2315 Status status = CreateTrafficQueues_(traffic_queues);
2316 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2317}
2318
2319// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
2320TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
2321 traffic_queues->set_uni_id(3);
2322 traffic_queues->set_port_no(16);
2323 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2324
2325 traffic_queue_2 = traffic_queues->add_traffic_queues();
2326 traffic_queue_2->set_gemport_id(1025);
2327 traffic_queue_2->set_pbit_map("0b00001010");
2328 traffic_queue_2->set_aes_encryption(true);
2329 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2330 traffic_queue_2->set_priority(1);
2331 traffic_queue_2->set_weight(0);
2332 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2333 discard_config_2 = new tech_profile::DiscardConfig;
2334 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2335 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2336 tail_drop_discard_config_2->set_queue_size(8);
2337 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2338 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2339 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2340
2341 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2342 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2343
2344 Status status = CreateTrafficQueues_(traffic_queues);
2345 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2346}
2347
2348// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
2349TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
2350 int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
2351 int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
2352 std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
2353
2354 traffic_queue_2 = traffic_queues->add_traffic_queues();
2355 for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
2356 traffic_queues->set_uni_id(uni_ids[i]);
2357 traffic_queues->set_port_no(port_nos[i]);
2358 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2359
2360 traffic_queue_2->set_gemport_id(1025);
2361 traffic_queue_2->set_pbit_map(pbit_maps[i]);
2362 traffic_queue_2->set_aes_encryption(true);
2363 traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
2364 traffic_queue_2->set_priority(1);
2365 traffic_queue_2->set_weight(0);
2366 traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2367 discard_config_2 = new tech_profile::DiscardConfig;
2368 discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
2369 tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
2370 tail_drop_discard_config_2->set_queue_size(8);
2371 discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
2372 traffic_queue_2->set_allocated_discard_config(discard_config_2);
2373 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2374
2375 bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
2376 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2377
2378 Status status = CreateTrafficQueues_(traffic_queues);
2379 if(i==16)
2380 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2381 else
2382 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2383 }
2384}
2385
2386// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
2387TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
2388 traffic_queues->set_uni_id(0);
2389 traffic_queues->set_port_no(16);
2390 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2391
2392 bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
2393 ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
2394
2395 Status status = CreateTrafficQueues_(traffic_queues);
2396 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2397}
2398
2399////////////////////////////////////////////////////////////////////////////
2400// For testing RemoveTrafficQueues functionality
2401////////////////////////////////////////////////////////////////////////////
2402
2403class TestRemoveTrafficQueues : public Test {
2404 protected:
2405 NiceMock<BalMocker> balMock;
2406 tech_profile::TrafficQueues* traffic_queues;
2407 tech_profile::TrafficQueue* traffic_queue_1;
2408 tech_profile::TrafficQueue* traffic_queue_2;
2409
2410 virtual void SetUp() {
2411 traffic_queues = new tech_profile::TrafficQueues;
2412 traffic_queues->set_intf_id(0);
2413 traffic_queues->set_onu_id(1);
2414 traffic_queue_1 = traffic_queues->add_traffic_queues();
2415 traffic_queue_1->set_gemport_id(1024);
2416 traffic_queue_1->set_priority(0);
2417 }
2418
2419 virtual void TearDown() {
2420 }
2421};
2422
2423// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
2424TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
2425 Status status;
2426 traffic_queues->set_uni_id(0);
2427 traffic_queues->set_port_no(16);
2428 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2429
2430 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2431 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2432
2433 status = RemoveTrafficQueues_(traffic_queues);
2434 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2435
2436 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2437 status = RemoveTrafficQueues_(traffic_queues);
2438 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2439}
2440
2441// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
2442TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
2443 Status status;
2444 traffic_queues->set_uni_id(0);
2445 traffic_queues->set_port_no(16);
2446 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2447
2448 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2449 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2450
2451 status = RemoveTrafficQueues_(traffic_queues);
2452 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2453}
2454
2455// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
2456TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
2457 //Remove scheduler so that is_tm_sched_id_present api call will return false
2458 tech_profile::TrafficSchedulers* traffic_scheds;
2459 tech_profile::TrafficScheduler* traffic_sched;
2460 traffic_scheds = new tech_profile::TrafficSchedulers;
2461 traffic_scheds->set_intf_id(0);
2462 traffic_scheds->set_onu_id(1);
2463 traffic_scheds->set_uni_id(0);
2464 traffic_scheds->set_port_no(16);
2465 traffic_sched = traffic_scheds->add_traffic_scheds();
2466 traffic_sched->set_alloc_id(1024);
2467 traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
2468
2469 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2470 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2471 RemoveTrafficSchedulers_(traffic_scheds);
2472
2473 traffic_queues->set_uni_id(0);
2474 traffic_queues->set_port_no(16);
2475 traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
2476
2477 Status status = RemoveTrafficQueues_(traffic_queues);
2478 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2479}
2480
2481/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
2482as it is getting referred by some other queues case */
2483TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
2484 traffic_queues->set_uni_id(3);
2485 traffic_queues->set_port_no(16);
2486 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2487 traffic_queue_2 = traffic_queues->add_traffic_queues();
2488 traffic_queue_2->set_gemport_id(1025);
2489 traffic_queue_2->set_priority(1);
2490 traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
2491
2492 Status status = RemoveTrafficQueues_(traffic_queues);
2493 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2494}
2495
2496/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
2497is not getting referred by any other queues case */
2498TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
2499 traffic_queues->set_uni_id(1);
2500 traffic_queues->set_port_no(32);
2501 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2502 traffic_queue_2 = traffic_queues->add_traffic_queues();
2503 traffic_queue_2->set_gemport_id(1025);
2504 traffic_queue_2->set_priority(1);
2505
2506 bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
2507 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2508
2509 Status status = RemoveTrafficQueues_(traffic_queues);
2510 ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
2511}
2512
2513/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
2514having no reference to any other queues case */
2515TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
2516 traffic_queues->set_uni_id(4);
2517 traffic_queues->set_port_no(64);
2518 traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
2519 traffic_queue_2 = traffic_queues->add_traffic_queues();
2520 traffic_queue_2->set_gemport_id(1025);
2521 traffic_queue_2->set_priority(1);
2522
2523 bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
2524 ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
2525
2526 Status status = RemoveTrafficQueues_(traffic_queues);
2527 ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
2528}