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