VOL-2291: Add unit test cases for RPC's in core.cc
Changed Openolt agent version to 2.0.1-dev
Change-Id: Id0e315db7af0cb2a5032e8c9aded86237f194f5f
diff --git a/VERSION b/VERSION
index 227cea2..1e4ec5e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.0
+2.0.1-dev
diff --git a/agent/src/core.cc b/agent/src/core.cc
index 691254b..582373e 100644
--- a/agent/src/core.cc
+++ b/agent/src/core.cc
@@ -142,6 +142,11 @@
/* 'qmp_id_to_qmp_map' maps TM Queue Mapping Profile ID to TM Queue Mapping Profile */
static std::map<int, std::vector < uint32_t > > qmp_id_to_qmp_map;
+// Flag used to watch whether mocked alloc_cfg_compltd_key is added to alloc_cfg_compltd_map
+#ifdef TEST_MODE
+bool ALLOC_CFG_FLAG = false;
+#endif
+
#define ALLOC_CFG_COMPLETE_WAIT_TIMEOUT 1000 // in milli-seconds
// Map used to track response from BAL for ITU PON Alloc Configuration.
// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
@@ -178,6 +183,10 @@
// Stubbed defntions of bcmolt_cfg_get required for unit-test
#ifdef TEST_MODE
extern bcmos_errno bcmolt_cfg_get__bal_state_stub(bcmolt_oltid olt_id, void* ptr);
+extern bcmos_errno bcmolt_cfg_get__onu_state_stub(bcmolt_oltid olt_id, void* ptr);
+extern bcmos_errno bcmolt_cfg_get__tm_sched_stub(bcmolt_oltid olt_id, void* ptr);
+extern bcmos_errno bcmolt_cfg_get__pon_intf_stub(bcmolt_oltid olt_id, void* ptr);
+extern bcmos_errno bcmolt_cfg_get__nni_intf_stub(bcmolt_oltid olt_id, void* ptr);
extern bcmos_errno bcmolt_cfg_get__olt_topology_stub(bcmolt_oltid olt_id, void* ptr);
#endif
/**
@@ -594,6 +603,9 @@
alloc_cfg_compltd_key k(intf_id, alloc_id);
alloc_cfg_compltd_map[k] = &cfg_result;
bcmos_errno err = BCM_ERR_OK;
+ #ifdef TEST_MODE
+ ALLOC_CFG_FLAG = true;
+ #endif
// Try to pop the result from BAL with a timeout of ALLOC_CFG_COMPLETE_WAIT_TIMEOUT ms
std::pair<alloc_cfg_complete_result, bool> result = cfg_result.pop(ALLOC_CFG_COMPLETE_WAIT_TIMEOUT);
@@ -605,6 +617,9 @@
alloc_cfg_compltd_map[k] = NULL;
bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
err = BCM_ERR_INTERNAL;
+ #ifdef TEST_MODE
+ ALLOC_CFG_FLAG = false;
+ #endif
}
else if (result.first.status == ALLOC_CFG_STATUS_FAIL) {
OPENOLT_LOG(ERROR, openolt_log_id, "error processing alloc cfg request intf_id %d, alloc_id %d\n",
@@ -638,6 +653,9 @@
bcmos_fastlock_lock(&alloc_cfg_wait_lock);
alloc_cfg_compltd_map.erase(k);
bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
+ #ifdef TEST_MODE
+ ALLOC_CFG_FLAG = false;
+ #endif
return err;
}
@@ -1068,7 +1086,16 @@
BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, state);
BCMOLT_FIELD_SET_PRESENT(&pon_cfg.data, pon_interface_cfg_data, itu);
+ #ifdef TEST_MODE
+ // It is impossible to mock the setting of pon_cfg.data.state because
+ // the actual bcmolt_cfg_get passes the address of pon_cfg.hdr and we cannot
+ // set the pon_cfg.data.state. So a new stub function is created and address
+ // of pon_cfg is passed. This is one-of case where we need to add test specific
+ // code in production code.
+ err = bcmolt_cfg_get__pon_intf_stub(dev_id, &pon_cfg);
+ #else
err = bcmolt_cfg_get(dev_id, &pon_cfg.hdr);
+ #endif
*state = pon_cfg.data.state;
return err;
}
@@ -1561,7 +1588,16 @@
BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
BCMOLT_FIELD_SET_PRESENT(&nni_cfg.data, nni_interface_cfg_data, state);
+ #ifdef TEST_MODE
+ // It is impossible to mock the setting of nni_cfg.data.state because
+ // the actual bcmolt_cfg_get passes the address of nni_cfg.hdr and we cannot
+ // set the nni_cfg.data.state. So a new stub function is created and address
+ // of nni_cfg is passed. This is one-of case where we need to add test specific
+ // code in production code.
+ err = bcmolt_cfg_get__nni_intf_stub(dev_id, &nni_cfg);
+ #else
err = bcmolt_cfg_get(dev_id, &nni_cfg.hdr);
+ #endif
*state = nni_cfg.data.state;
return err;
}
@@ -1653,7 +1689,16 @@
onu_key.pon_ni = intf_id;
BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
+ #ifdef TEST_MODE
+ // It is impossible to mock the setting of onu_cfg.data.onu_state because
+ // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
+ // set the onu_cfg.data.onu_state. So a new stub function is created and address
+ // of onu_cfg is passed. This is one-of case where we need to add test specific
+ // code in production code.
+ err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
+ #else
err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
+ #endif
if (err == BCM_ERR_OK) {
if ((onu_cfg.data.onu_state == BCMOLT_ONU_STATE_PROCESSING ||
onu_cfg.data.onu_state == BCMOLT_ONU_STATE_ACTIVE) ||
@@ -1700,10 +1745,20 @@
onu_key.pon_ni = intf_id;
BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
BCMOLT_FIELD_SET_PRESENT(&onu_cfg.data, onu_cfg_data, onu_state);
+ #ifdef TEST_MODE
+ // It is impossible to mock the setting of onu_cfg.data.onu_state because
+ // the actual bcmolt_cfg_get passes the address of onu_cfg.hdr and we cannot
+ // set the onu_cfg.data.onu_state. So a new stub function is created and address
+ // of onu_cfg is passed. This is one-of case where we need to add test specific
+ // code in production code.
+ err = bcmolt_cfg_get__onu_state_stub(dev_id, &onu_cfg);
+ onu_state = onu_cfg.data.onu_state;
+ #else
err = bcmolt_cfg_get(dev_id, &onu_cfg.hdr);
+ #endif
if (err == BCM_ERR_OK) {
switch (onu_state) {
- case BCMOLT_ONU_OPERATION_ACTIVE:
+ case BCMOLT_ONU_STATE_ACTIVE:
BCMOLT_OPER_INIT(&onu_oper, onu, set_onu_state, onu_key);
BCMOLT_FIELD_SET(&onu_oper.data, onu_set_onu_state_data,
onu_state, BCMOLT_ONU_OPERATION_INACTIVE);
@@ -1738,7 +1793,9 @@
bcmolt_onu_cfg cfg_obj;
bcmolt_onu_key key;
- OPENOLT_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
+ //OPENOLT_LOG(INFO, openolt_log_id, "Processing subscriber terminal cfg clear for sub_term_id %d and intf_id %d\n",
+ // onu_id, intf_id);
+ OPENOLT_LOG(INFO, openolt_log_id, "Processing onu cfg clear for onu_id %d and intf_id %d\n",
onu_id, intf_id);
key.onu_id = onu_id;
@@ -1748,7 +1805,8 @@
bcmos_errno err = bcmolt_cfg_clear(dev_id, &cfg_obj.hdr);
if (err != BCM_ERR_OK)
{
- OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
+ //OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL subscriber_terminal_id %d, Interface ID %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to clear information for BAL onu_id %d, Interface ID %d, err = %s\n", onu_id, intf_id, bcmos_strerror(err));
return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU");
}
@@ -2476,7 +2534,16 @@
//check TM scheduler has configured or not
BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
BCMOLT_MSG_FIELD_GET(&tm_sched_cfg, state);
+ #ifdef TEST_MODE
+ // It is impossible to mock the setting of tm_sched_cfg.data.state because
+ // the actual bcmolt_cfg_get passes the address of tm_sched_cfg.hdr and we cannot
+ // set the tm_sched_cfg.data.state. So a new stub function is created and address
+ // of tm_sched_cfg is passed. This is one-of case where we need to add test specific
+ // code in production code.
+ err = bcmolt_cfg_get__tm_sched_stub(dev_id, &tm_sched_cfg);
+ #else
err = bcmolt_cfg_get(dev_id, &tm_sched_cfg.hdr);
+ #endif
if (err) {
OPENOLT_LOG(ERROR, openolt_log_id, "cfg: Failed to query TM scheduler, err = %s\n",bcmos_strerror(err));
return err;
@@ -2616,6 +2683,7 @@
if (pir_bw == 0) {
OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth was set to 0, must be at least \
%d bytes/sec\n", (board_technology == "XGS-PON")?XGS_BANDWIDTH_GRANULARITY:GPON_BANDWIDTH_GRANULARITY);
+ return BCM_ERR_PARM;
} else if (pir_bw < cir_bw) {
OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \
bandwidth (%d)\n", pir_bw, cir_bw);
@@ -2659,13 +2727,13 @@
} else if (pir_bw > cir_bw) {
OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth must be equal to Guaranteed bandwidth \
for additional bandwidth eligibility of type None\n");
- OPENOLT_LOG(ERROR, openolt_log_id, "set Maximum bandwidth (%d) to Guaranteed \
+ OPENOLT_LOG(ERROR, openolt_log_id, "Setting Maximum bandwidth (%d) to Guaranteed \
bandwidth in None eligibility\n", pir_bw);
cir_bw = pir_bw;
} else if (pir_bw < cir_bw) {
OPENOLT_LOG(ERROR, openolt_log_id, "Maximum bandwidth (%d) can't be less than Guaranteed \
bandwidth (%d)\n", pir_bw, cir_bw);
- OPENOLT_LOG(ERROR, openolt_log_id, "set Maximum bandwidth (%d) to Guaranteed \
+ OPENOLT_LOG(ERROR, openolt_log_id, "Setting Maximum bandwidth (%d) to Guaranteed \
bandwidth in None eligibility\n", pir_bw);
cir_bw = pir_bw;
}
@@ -2844,7 +2912,8 @@
int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tmq_map_profile);
if (tm_qmp_id == -1) {
- OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile. Max allowed profile count is 16.\n");
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile. Max allowed tm queue mapping profile count is 16.\n");
+ return BCM_ERR_RANGE;
}
tm_qmp_key.id = tm_qmp_id;
@@ -3005,7 +3074,11 @@
int tm_qmp_id = get_tm_qmp_id(tmq_map_profile);
if (tm_qmp_id == -1) {
- CreateTrafficQueueMappingProfile(sched_id, intf_id, onu_id, uni_id, direction, tmq_map_profile);
+ err = CreateTrafficQueueMappingProfile(sched_id, intf_id, onu_id, uni_id, direction, tmq_map_profile);
+ if (err != BCM_ERR_OK) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to create tm queue mapping profile, err = %s\n", bcmos_strerror(err));
+ return bcm_to_grpc_err(err, "Failed to create tm queue mapping profile");
+ }
} else if (tm_qmp_id != -1 && get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id) == -1) {
OPENOLT_LOG(INFO, openolt_log_id, "tm queue mapping profile present already with id %d\n", tm_qmp_id);
update_sched_qmp_id_map(sched_id, intf_id, onu_id, uni_id, tm_qmp_id);
@@ -3107,7 +3180,11 @@
int tm_qmp_id = get_tm_qmp_id(sched_id, intf_id, onu_id, uni_id);
if (free_tm_qmp_id(sched_id, intf_id, onu_id, uni_id, tm_qmp_id)) {
- RemoveTrafficQueueMappingProfile(tm_qmp_id);
+ err = RemoveTrafficQueueMappingProfile(tm_qmp_id);
+ if (err != BCM_ERR_OK) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to remove tm queue mapping profile, err = %s\n", bcmos_strerror(err));
+ return bcm_to_grpc_err(err, "Failed to remove tm queue mapping profile");
+ }
}
}
clear_qos_type(intf_id, onu_id, uni_id);
diff --git a/agent/test/inc/bal_mocker.h b/agent/test/inc/bal_mocker.h
index 6ad612d..f60c581 100644
--- a/agent/test/inc/bal_mocker.h
+++ b/agent/test/inc/bal_mocker.h
@@ -43,6 +43,7 @@
MOCK_METHOD2(bcmolt_cfg_get, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
MOCK_METHOD2(bcmolt_oper_submit, bcmos_errno(bcmolt_oltid, bcmolt_oper*));
MOCK_METHOD2(bcmolt_cfg_set, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
+ MOCK_METHOD2(bcmolt_cfg_clear, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
// Add more here
};
diff --git a/agent/test/src/bal_mocker.cc b/agent/test/src/bal_mocker.cc
index 8c8ec44..f59c412 100644
--- a/agent/test/src/bal_mocker.cc
+++ b/agent/test/src/bal_mocker.cc
@@ -20,5 +20,6 @@
CMOCK_MOCK_FUNCTION2(BalMocker, bcmolt_cfg_get, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
CMOCK_MOCK_FUNCTION2(BalMocker, bcmolt_oper_submit, bcmos_errno(bcmolt_oltid, bcmolt_oper*));
CMOCK_MOCK_FUNCTION2(BalMocker, bcmolt_cfg_set, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
+CMOCK_MOCK_FUNCTION2(BalMocker, bcmolt_cfg_clear, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
}
diff --git a/agent/test/src/bal_stub.cc b/agent/test/src/bal_stub.cc
index 1094cf6..1a82dff 100644
--- a/agent/test/src/bal_stub.cc
+++ b/agent/test/src/bal_stub.cc
@@ -71,11 +71,13 @@
*/
/* Clear configuration */
+/*
bcmos_errno bcmolt_cfg_clear(bcmolt_oltid olt, bcmolt_cfg *cfg)
{
printf("-- entering :stubbed %s\n", __FUNCTION__);
return BCM_ERR_OK;
}
+*/
/* Get statistics */
bcmos_errno bcmolt_stat_get(bcmolt_oltid olt, bcmolt_stat *stat, bcmolt_stat_flags flags)
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index 12fd0ee..54d65a2 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -14,11 +14,18 @@
* limitations under the License.
*/
#include "gtest/gtest.h"
+#include "Queue.h"
#include "bal_mocker.h"
#include "core.h"
+#include <future>
using namespace testing;
using namespace std;
+extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
+extern dev_log_id openolt_log_id;
+extern bcmos_fastlock alloc_cfg_wait_lock;
+extern bool ALLOC_CFG_FLAG;
+
class TestOltEnable : public Test {
protected:
virtual void SetUp() {
@@ -34,9 +41,28 @@
// bcmolt_cfg_get__bal_state_stub.
ACTION_P(SetArg1ToBcmOltCfg, value) { *static_cast<bcmolt_olt_cfg*>(arg1) = value; };
+// This is used to set custom bcmolt_onu_cfg value to bcmolt_onu_cfg pointer coming in
+// bcmolt_cfg_get__onu_state_stub.
+ACTION_P(SetArg1ToBcmOltOnuCfg, value) { *static_cast<bcmolt_onu_cfg*>(arg1) = value; };
+
+// This is used to set custom bcmolt_tm_sched_cfg value to bcmolt_tm_sched_cfg pointer coming in
+// bcmolt_cfg_get__tm_sched_stub.
+ACTION_P(SetArg1ToBcmOltTmSchedCfg, value) { *static_cast<bcmolt_tm_sched_cfg*>(arg1) = value; };
+
+// This is used to set custom bcmolt_pon_interface_cfg value to bcmolt_pon_interface_cfg pointer coming in
+// bcmolt_cfg_get__pon_intf_stub.
+ACTION_P(SetArg1ToBcmOltPonCfg, value) { *static_cast<bcmolt_pon_interface_cfg*>(arg1) = value; };
+
+// This is used to set custom bcmolt_nni_interface_cfg value to bcmolt_nni_interface_cfg pointer coming in
+// bcmolt_cfg_get__nni_intf_stub.
+ACTION_P(SetArg1ToBcmOltNniCfg, value) { *static_cast<bcmolt_nni_interface_cfg*>(arg1) = value; };
// Create a mock function for bcmolt_cfg_get__bal_state_stub C++ function
MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__bal_state_stub, bcmos_errno(bcmolt_oltid, void*));
+MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__onu_state_stub, bcmos_errno(bcmolt_oltid, void*));
+MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__tm_sched_stub, bcmos_errno(bcmolt_oltid, void*));
+MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__pon_intf_stub, bcmos_errno(bcmolt_oltid, void*));
+MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__nni_intf_stub, bcmos_errno(bcmolt_oltid, void*));
// Test Fixture for OltEnable
@@ -266,35 +292,58 @@
// NiceMock is used to suppress 'WillByDefault' return errors.
// This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
NiceMock<BalMocker> balMock;
- bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
-
+ uint32_t pon_id = 0;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
Status olt_reenable_res;
- EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
- .Times(num_of_pon_ports*2)
- .WillRepeatedly(Return(bal_cfg_get_res));
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .Times(num_of_pon_ports)
+ .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
+
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .Times(num_of_pon_ports)
+ .WillRepeatedly(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
olt_reenable_res = Reenable_();
ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
}
-// Test 2: OltReenableAllPonFailed case
+// Test 2: OltReenableAllPonFailed case
TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
// NiceMock is used to suppress 'WillByDefault' return errors.
// This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
NiceMock<BalMocker> balMock;
- bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
+ uint32_t pon_id = 0;
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
-
Status olt_reenable_res;
- EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
- .Times(num_of_pon_ports)
- .WillRepeatedly(Return(bal_cfg_get_res));
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .Times(num_of_pon_ports)
+ .WillRepeatedly(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
.Times(num_of_pon_ports)
.WillRepeatedly(Return(olt_oper_res));
+
olt_reenable_res = Reenable_();
ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
}
@@ -379,6 +428,339 @@
}
////////////////////////////////////////////////////////////////////////////
+// For testing EnablePonIf functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestEnablePonIf : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - EnablePonIf, Downstream DefaultSched & DefaultQueues creation success case
+TEST_F(TestEnablePonIf, EnablePonIfDefaultSchedQueuesSuccess) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - EnablePonIf success but Downstream DefaultSched Query failure case
+TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueryFailure) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_INTERNAL;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 3 - EnablePonIf success but Downstream DefaultSched already in Configured state
+TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedAlreadyConfigured) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+ ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 4 - EnablePonIf success but Downstream DefaultSched & DefaultQueues creation failed
+TEST_F(TestEnablePonIf, EnablePonIfSuccessDefaultSchedQueuesFailed) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_err = BCM_ERR_INTERNAL;
+ bcmos_errno olt_cfg_get_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ EXPECT_CALL(balMock, bcmolt_cfg_set(_, _))
+ .WillOnce(Return(olt_cfg_set_res))
+ .WillRepeatedly(Return(olt_cfg_set_err));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+ ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(olt_cfg_get_res));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 5 - EnablePonIf already enabled success
+TEST_F(TestEnablePonIf, EnablePonIfAlreadyEnabled) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 6 - EnablePonIf - enable onu discovery failure case
+TEST_F(TestEnablePonIf, EnablePonIfEnableOnuDiscFailed) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 7 - EnablePonIf failure case
+TEST_F(TestEnablePonIf, EnablePonIfFailed) {
+ bcmos_errno olt_cfg_get_pon_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
+
+ bcmolt_pon_interface_key pon_key;
+ bcmolt_pon_interface_cfg pon_cfg;
+ pon_key.pon_ni = pon_id;
+ BCMOLT_CFG_INIT(&pon_cfg, pon_interface, pon_key);
+ pon_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__pon_intf_stub, bcmolt_cfg_get__pon_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltPonCfg(pon_cfg), Return(olt_cfg_get_pon_stub_res)));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ Status status = EnablePonIf_(pon_id);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing SetStateUplinkIf functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestSetStateUplinkIf : public Test {
+ protected:
+ uint32_t intf_id = 0;
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - SetStateUplinkIf NNI intf already enabled, Upstream DefaultSched & DefaultQueues creation success case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyEnabledDefaultSchedQueuesSuccess) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = SetStateUplinkIf_(intf_id, true);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - SetStateUplinkIf, NNI interface already disabled case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfAlreadyDisabled) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE_INACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+
+ Status status = SetStateUplinkIf_(intf_id, false);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 3 - SetStateUplinkIf Enable success, Upstream DefaultSched & DefaultQueues creation success case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDefaultSchedQueuesSuccess) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_get_tmstub_res = BCM_ERR_OK;
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+
+ bcmolt_tm_sched_cfg tm_sched_cfg;
+ bcmolt_tm_sched_key tm_sched_key = {.id = 1004};
+ BCMOLT_CFG_INIT(&tm_sched_cfg, tm_sched, tm_sched_key);
+ tm_sched_cfg.data.state = BCMOLT_CONFIG_STATE_NOT_CONFIGURED;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__tm_sched_stub, bcmolt_cfg_get__tm_sched_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltTmSchedCfg(tm_sched_cfg), Return(olt_cfg_get_tmstub_res)));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ Status status = SetStateUplinkIf_(intf_id, true);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 4 - SetStateUplinkIf Enable failure case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfEnableFailure) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE__BEGIN;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ Status status = SetStateUplinkIf_(intf_id, true);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 5 - SetStateUplinkIf Disable success case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableSuccess) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ Status status = SetStateUplinkIf_(intf_id, false);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 6 - SetStateUplinkIf Disable failure case
+TEST_F(TestSetStateUplinkIf, SetStateUplinkIfDisableFailure) {
+ bcmos_errno olt_cfg_get_nni_stub_res = BCM_ERR_OK;
+ bcmos_errno olt_oper_sub_res = BCM_ERR_INTERNAL;
+
+ bcmolt_nni_interface_key nni_key;
+ bcmolt_nni_interface_cfg nni_cfg;
+ nni_key.id = intf_id;
+ BCMOLT_CFG_INIT(&nni_cfg, nni_interface, nni_key);
+ nni_cfg.data.state = BCMOLT_INTERFACE_STATE_ACTIVE_WORKING;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__nni_intf_stub, bcmolt_cfg_get__nni_intf_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltNniCfg(nni_cfg), Return(olt_cfg_get_nni_stub_res)));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_sub_res));
+
+ Status status = SetStateUplinkIf_(intf_id, false);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
// For testing DisablePonIf functionality
////////////////////////////////////////////////////////////////////////////
@@ -431,3 +813,1102 @@
ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
}
+////////////////////////////////////////////////////////////////////////////
+// For testing ActivateOnu functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestActivateOnu : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ uint32_t onu_id = 1;
+ std::string vendor_id = "TWSH";
+ std::string vendor_specific = "80808080";
+ uint32_t pir = 1000000;
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - ActivateOnu success case
+TEST_F(TestActivateOnu, ActivateOnuSuccess) {
+ bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
+ bcmos_errno onu_cfg_set_res = BCM_ERR_OK;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
+
+ Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - ActivateOnu failure case
+TEST_F(TestActivateOnu, ActivateOnuFailure) {
+ bcmos_errno onu_cfg_get_res = BCM_ERR_INTERNAL;
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_INTERNAL;
+ bcmos_errno onu_cfg_set_res = BCM_ERR_INTERNAL;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(onu_cfg_set_res));
+
+ Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
+ ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 3 - ActivateOnu - Onu already under processing case
+TEST_F(TestActivateOnu, ActivateOnuProcessing) {
+ bcmos_errno onu_cfg_get_res = BCM_ERR_OK;
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+ ON_CALL(balMock, bcmolt_cfg_get(_, _)).WillByDefault(Return(onu_cfg_get_res));
+
+ Status status = ActivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str(), pir);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing DeactivateOnu functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestDeactivateOnu : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ uint32_t onu_id = 1;
+ std::string vendor_id = "TWSH";
+ std::string vendor_specific = "80808080";
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - DeactivateOnu success case
+TEST_F(TestDeactivateOnu, DeactivateOnuSuccess) {
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
+ bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+
+ Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - DeactivateOnu failure case
+TEST_F(TestDeactivateOnu, DeactivateOnuFailure) {
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
+ bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+
+ Status status = DeactivateOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
+ ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing DeleteOnu functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestDeleteOnu : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ uint32_t onu_id = 1;
+ std::string vendor_id = "TWSH";
+ std::string vendor_specific = "80808080";
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - DeleteOnu success case
+TEST_F(TestDeleteOnu, DeleteOnuSuccess) {
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
+ bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
+ bcmos_errno onu_cfg_clear_res = BCM_ERR_OK;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
+
+ Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - DeleteOnu failure case
+TEST_F(TestDeleteOnu, DeleteOnuFailure) {
+ bcmos_errno onu_cfg_get_stub_res = BCM_ERR_OK;
+ bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
+ bcmos_errno onu_cfg_clear_res = BCM_ERR_INTERNAL;
+
+ bcmolt_onu_cfg onu_cfg;
+ bcmolt_onu_key onu_key;
+ BCMOLT_CFG_INIT(&onu_cfg, onu, onu_key);
+ onu_cfg.data.onu_state = BCMOLT_ONU_STATE_ACTIVE;
+ EXPECT_GLOBAL_CALL(bcmolt_cfg_get__onu_state_stub, bcmolt_cfg_get__onu_state_stub(_, _))
+ .WillOnce(DoAll(SetArg1ToBcmOltOnuCfg(onu_cfg), Return(onu_cfg_get_stub_res)));
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(onu_cfg_clear_res));
+
+ Status status = DeleteOnu_(pon_id, onu_id, vendor_id.c_str(), vendor_specific.c_str());
+ ASSERT_FALSE( status.error_message() == Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing OmciMsgOut functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestOmciMsgOut : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ uint32_t onu_id = 1;
+ std::string pkt = "omci-pkt";
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - OmciMsgOut success case
+TEST_F(TestOmciMsgOut, OmciMsgOutSuccess) {
+ bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+
+ Status status = OmciMsgOut_(pon_id, onu_id, pkt);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 1 - OmciMsgOut failure case
+TEST_F(TestOmciMsgOut, OmciMsgOutFailure) {
+ bcmos_errno onu_oper_sub_res = BCM_ERR_INTERNAL;
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+
+ Status status = OmciMsgOut_(pon_id, onu_id, pkt);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing OnuPacketOut functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestOnuPacketOut : public Test {
+ protected:
+ uint32_t pon_id = 0;
+ uint32_t onu_id = 1;
+ std::string pkt = "omci-pkt";
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - OnuPacketOut success case
+TEST_F(TestOnuPacketOut, OnuPacketOutSuccess) {
+ uint32_t port_no = 16;
+ uint32_t gemport_id = 1024;
+ bcmos_errno onu_oper_sub_res = BCM_ERR_OK;
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(onu_oper_sub_res));
+
+ Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - OnuPacketOut Port number as 0 case
+TEST_F(TestOnuPacketOut, OnuPacketOutPortNo0) {
+ uint32_t port_no = 0;
+ uint32_t gemport_id = 1024;
+
+ Status status = OnuPacketOut_(pon_id, onu_id, port_no, gemport_id, pkt);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing CreateTrafficSchedulers functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestCreateTrafficSchedulers : public Test {
+ protected:
+ NiceMock<BalMocker> balMock;
+ tech_profile::TrafficSchedulers* traffic_scheds;
+ tech_profile::TrafficScheduler* traffic_sched;
+ tech_profile::SchedulerConfig* scheduler;
+ tech_profile::TrafficShapingInfo* traffic_shaping_info;
+
+ virtual void SetUp() {
+ traffic_scheds = new tech_profile::TrafficSchedulers;
+ traffic_scheds->set_intf_id(0);
+ traffic_scheds->set_onu_id(1);
+ traffic_scheds->set_uni_id(0);
+ traffic_scheds->set_port_no(16);
+ traffic_sched = traffic_scheds->add_traffic_scheds();
+ traffic_sched->set_alloc_id(1024);
+ scheduler = new tech_profile::SchedulerConfig;
+ scheduler->set_priority(0);
+ scheduler->set_weight(0);
+ scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_shaping_info = new tech_profile::TrafficShapingInfo;
+ traffic_shaping_info->set_cbs(60536);
+ traffic_shaping_info->set_pbs(65536);
+ traffic_shaping_info->set_gir(10000);
+ }
+
+ virtual void TearDown() {
+ }
+
+ public:
+ static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
+ if(ALLOC_CFG_FLAG) {
+ alloc_cfg_compltd_key k(0, 1024);
+ alloc_cfg_complete_result res;
+ res.pon_intf_id = 0;
+ res.alloc_id = 1024;
+ res.state = state;
+ res.status = status;
+
+ bcmos_fastlock_lock(&alloc_cfg_wait_lock);
+ std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
+ if (it == alloc_cfg_compltd_map.end()) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1024, 0);
+ } else {
+ it->second->push(res);
+ OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
+ }
+ bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
+ } else {
+ PushAllocCfgResult(state, status);
+ }
+ }
+};
+
+// Test 1 - CreateTrafficSchedulers-Upstream success case
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamSuccess) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - CreateTrafficSchedulers-Upstream failure case(timeout waiting for alloc cfg indication)
+TEST_F(TestCreateTrafficSchedulers, UpstreamAllocCfgTimeout) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 3 - CreateTrafficSchedulers-Upstream failure case(error processing alloc cfg request)
+TEST_F(TestCreateTrafficSchedulers, UpstreamErrorProcessingAllocCfg) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_FAIL);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 4 - CreateTrafficSchedulers-Upstream failure case(alloc object not in active state)
+TEST_F(TestCreateTrafficSchedulers, UpstreamAllocObjNotinActiveState) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 5 - CreateTrafficSchedulers-Upstream Failure case
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersUpstreamFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 6 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW set to 0) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWZeroFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(0);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 7 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW < Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWLtGuaranteedBwFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(32000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 8 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_BestEffort-Max BW = Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_BestEffortMaxBWEqGuaranteedBwFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(64000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 9 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW set to 0) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWZeroFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(0);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 10 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Guaranteed BW set to 0) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAGuaranteedBwZeroFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(0);
+ traffic_shaping_info->set_pir(32000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 11 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW < Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWLtGuaranteedBwFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(32000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 12 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_NA-Max BW = Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NAMaxBWEqGuaranteedBwFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_NA);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(64000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 13 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Max BW set to 0) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWZeroFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(0);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 14 - CreateTrafficSchedulers-Upstream Failure (AdditionalBW_None-Guaranteed BW set to 0) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneGuaranteedBwZeroFailure) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(0);
+ traffic_shaping_info->set_pir(32000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 15 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW > Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWGtGuaranteedBwSuccess) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 16 - CreateTrafficSchedulers-Upstream Success (AdditionalBW_None-Max BW < Guaranteed BW) case
+TEST_F(TestCreateTrafficSchedulers, AdditionalBW_NoneMaxBWLtGuaranteedBwSuccess) {
+ scheduler->set_direction(tech_profile::Direction::UPSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_None);
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(32000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ future<Status> future_res = async(launch::async, CreateTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestCreateTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_ACTIVE, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 17 - CreateTrafficSchedulers-Downstream success case
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamSuccess) {
+ scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 18 - CreateTrafficSchedulers-Downstream Failure case
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersDownstreamFailure) {
+ scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 19 - CreateTrafficSchedulers-Invalid direction Failure case
+TEST_F(TestCreateTrafficSchedulers, CreateTrafficSchedulersInvalidDirectionFailure) {
+ scheduler->set_direction(tech_profile::Direction::BIDIRECTIONAL);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_sched->set_direction(tech_profile::Direction::BIDIRECTIONAL);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+
+ Status status = CreateTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing RemoveTrafficSchedulers functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestRemoveTrafficSchedulers : public Test {
+ protected:
+ NiceMock<BalMocker> balMock;
+ tech_profile::TrafficSchedulers* traffic_scheds;
+ tech_profile::TrafficScheduler* traffic_sched;
+ tech_profile::SchedulerConfig* scheduler;
+ tech_profile::TrafficShapingInfo* traffic_shaping_info;
+ alloc_cfg_complete_result res;
+
+ virtual void SetUp() {
+ traffic_scheds = new tech_profile::TrafficSchedulers;
+ traffic_scheds->set_intf_id(0);
+ traffic_scheds->set_onu_id(1);
+ traffic_scheds->set_uni_id(0);
+ traffic_scheds->set_port_no(16);
+ traffic_sched = traffic_scheds->add_traffic_scheds();
+ traffic_sched->set_alloc_id(1025);
+ scheduler = new tech_profile::SchedulerConfig;
+ scheduler->set_priority(0);
+ scheduler->set_weight(0);
+ scheduler->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ scheduler->set_additional_bw(tech_profile::AdditionalBW::AdditionalBW_BestEffort);
+ traffic_shaping_info = new tech_profile::TrafficShapingInfo;
+ traffic_shaping_info->set_cir(64000);
+ traffic_shaping_info->set_pir(128000);
+ traffic_shaping_info->set_cbs(60536);
+ traffic_shaping_info->set_pbs(65536);
+ traffic_shaping_info->set_gir(10000);
+ traffic_sched->set_allocated_traffic_shaping_info(traffic_shaping_info);
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+ }
+
+ virtual void TearDown() {
+ }
+
+ public:
+ static void PushAllocCfgResult(AllocObjectState state, AllocCfgStatus status) {
+ if(ALLOC_CFG_FLAG) {
+ alloc_cfg_compltd_key k(0, 1025);
+ alloc_cfg_complete_result res;
+ res.pon_intf_id = 0;
+ res.alloc_id = 1025;
+ res.state = state;
+ res.status = status;
+
+ bcmos_fastlock_lock(&alloc_cfg_wait_lock);
+ std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *>::iterator it = alloc_cfg_compltd_map.find(k);
+ if (it == alloc_cfg_compltd_map.end()) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "alloc config key not found for alloc_id = %u, pon_intf = %u\n", 1025, 0);
+ } else {
+ it->second->push(res);
+ OPENOLT_LOG(INFO, openolt_log_id, "Pushed mocked alloc cfg result\n");
+ }
+ bcmos_fastlock_unlock(&alloc_cfg_wait_lock, 0);
+ } else {
+ PushAllocCfgResult(state, status);
+ }
+ }
+};
+
+// Test 1 - RemoveTrafficSchedulers-Upstream success case
+TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamSuccess) {
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_NOT_CONFIGURED, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - RemoveTrafficSchedulers-Upstream success case(alloc object is not reset)
+TEST_F(TestRemoveTrafficSchedulers, UpstreamAllocObjNotReset) {
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ future<Status> future_res = async(launch::async, RemoveTrafficSchedulers_, traffic_scheds);
+ async(launch::async, TestRemoveTrafficSchedulers::PushAllocCfgResult, ALLOC_OBJECT_STATE_INACTIVE, ALLOC_CFG_STATUS_SUCCESS);
+
+ Status status = future_res.get();
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 3 - RemoveTrafficSchedulers-Upstream Failure case
+TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersUpstreamFailure) {
+ traffic_sched->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ Status status = RemoveTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 4 - RemoveTrafficSchedulers-Downstream Failure case
+TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamFailure) {
+ //Create Scheduler
+ scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ CreateTrafficSchedulers_(traffic_scheds);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ Status status = RemoveTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 5 - RemoveTrafficSchedulers-Downstream success case
+TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSuccess) {
+ //Create Scheduler
+ scheduler->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+ traffic_sched->set_allocated_scheduler(scheduler);
+ CreateTrafficSchedulers_(traffic_scheds);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ Status status = RemoveTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 6 - RemoveTrafficSchedulers-Downstream Scheduler not present case
+TEST_F(TestRemoveTrafficSchedulers, RemoveTrafficSchedulersDownstreamSchedNotpresent) {
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+
+ Status status = RemoveTrafficSchedulers_(traffic_scheds);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing CreateTrafficQueues functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestCreateTrafficQueues : public Test {
+ protected:
+ NiceMock<BalMocker> balMock;
+ tech_profile::TrafficQueues* traffic_queues;
+ tech_profile::TrafficQueue* traffic_queue_1;
+ tech_profile::TrafficQueue* traffic_queue_2;
+ tech_profile::DiscardConfig* discard_config_1;
+ tech_profile::DiscardConfig* discard_config_2;
+ tech_profile::TailDropDiscardConfig* tail_drop_discard_config_1;
+ tech_profile::TailDropDiscardConfig* tail_drop_discard_config_2;
+
+ virtual void SetUp() {
+ traffic_queues = new tech_profile::TrafficQueues;
+ traffic_queues->set_intf_id(0);
+ traffic_queues->set_onu_id(1);
+ traffic_queue_1 = traffic_queues->add_traffic_queues();
+ traffic_queue_1->set_gemport_id(1024);
+ traffic_queue_1->set_pbit_map("0b00000101");
+ traffic_queue_1->set_aes_encryption(true);
+ traffic_queue_1->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_queue_1->set_priority(0);
+ traffic_queue_1->set_weight(0);
+ traffic_queue_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ discard_config_1 = new tech_profile::DiscardConfig;
+ discard_config_1->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ tail_drop_discard_config_1 = new tech_profile::TailDropDiscardConfig;
+ tail_drop_discard_config_1->set_queue_size(8);
+ discard_config_1->set_allocated_tail_drop_discard_config(tail_drop_discard_config_1);
+ traffic_queue_1->set_allocated_discard_config(discard_config_1);
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - CreateTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamDownstreamFixedQueueSuccess) {
+ Status status;
+ traffic_queues->set_uni_id(0);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+
+ traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
+ status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE success case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueSuccess) {
+ traffic_queues->set_uni_id(1);
+ traffic_queues->set_port_no(32);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_pbit_map("0b00001010");
+ traffic_queue_2->set_aes_encryption(true);
+ traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_queue_2->set_priority(1);
+ traffic_queue_2->set_weight(0);
+ traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ discard_config_2 = new tech_profile::DiscardConfig;
+ discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
+ tail_drop_discard_config_2->set_queue_size(8);
+ discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
+ traffic_queue_2->set_allocated_discard_config(discard_config_2);
+ traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 3 - CreateTrafficQueues-Upstream create tm queue mapping profile failure case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPCreationFailure) {
+ traffic_queues->set_uni_id(2);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_pbit_map("0b10001010");
+ traffic_queue_2->set_aes_encryption(true);
+ traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_queue_2->set_priority(1);
+ traffic_queue_2->set_weight(0);
+ traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ discard_config_2 = new tech_profile::DiscardConfig;
+ discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
+ tail_drop_discard_config_2->set_queue_size(8);
+ discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
+ traffic_queue_2->set_allocated_discard_config(discard_config_2);
+ traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 4 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP already present case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueTMQMPAlreadyPresent) {
+ traffic_queues->set_uni_id(3);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_pbit_map("0b00001010");
+ traffic_queue_2->set_aes_encryption(true);
+ traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_queue_2->set_priority(1);
+ traffic_queue_2->set_weight(0);
+ traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ discard_config_2 = new tech_profile::DiscardConfig;
+ discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
+ tail_drop_discard_config_2->set_queue_size(8);
+ discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
+ traffic_queue_2->set_allocated_discard_config(discard_config_2);
+ traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 5 - CreateTrafficQueues-Upstream PRIORITY_TO_QUEUE TM QMP Max count reached case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamPriorityQueueReachedMaxTMQMPCount) {
+ int uni_ids[17] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
+ int port_nos[17] = {16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272};
+ std::string pbit_maps[17] = {"0b00001010", "0b10001010", "0b00000001", "0b00000010", "0b00000100", "0b00001000", "0b00010000", "0b00100000", "0b01000000", "0b10000000", "0b10000001", "0b10000010", "0b10000100", "0b10001000", "0b10010000", "0b10100000", "0b11000000"};
+
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ for(int i=0; i<sizeof(uni_ids)/sizeof(uni_ids[0]); i++) {
+ traffic_queues->set_uni_id(uni_ids[i]);
+ traffic_queues->set_port_no(port_nos[i]);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_pbit_map(pbit_maps[i]);
+ traffic_queue_2->set_aes_encryption(true);
+ traffic_queue_2->set_sched_policy(tech_profile::SchedulingPolicy::StrictPriority);
+ traffic_queue_2->set_priority(1);
+ traffic_queue_2->set_weight(0);
+ traffic_queue_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ discard_config_2 = new tech_profile::DiscardConfig;
+ discard_config_2->set_discard_policy(tech_profile::DiscardPolicy::TailDrop);
+ tail_drop_discard_config_2 = new tech_profile::TailDropDiscardConfig;
+ tail_drop_discard_config_2->set_queue_size(8);
+ discard_config_2->set_allocated_tail_drop_discard_config(tail_drop_discard_config_2);
+ traffic_queue_2->set_allocated_discard_config(discard_config_2);
+ traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficQueues_(traffic_queues);
+ if(i==16)
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+ else
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+ }
+}
+
+// Test 6 - CreateTrafficQueues-Upstream FIXED_QUEUE failure case
+TEST_F(TestCreateTrafficQueues, CreateUpstreamFixedQueueFailure) {
+ traffic_queues->set_uni_id(0);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+ Status status = CreateTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing RemoveTrafficQueues functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestRemoveTrafficQueues : public Test {
+ protected:
+ NiceMock<BalMocker> balMock;
+ tech_profile::TrafficQueues* traffic_queues;
+ tech_profile::TrafficQueue* traffic_queue_1;
+ tech_profile::TrafficQueue* traffic_queue_2;
+
+ virtual void SetUp() {
+ traffic_queues = new tech_profile::TrafficQueues;
+ traffic_queues->set_intf_id(0);
+ traffic_queues->set_onu_id(1);
+ traffic_queue_1 = traffic_queues->add_traffic_queues();
+ traffic_queue_1->set_gemport_id(1024);
+ traffic_queue_1->set_priority(0);
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - RemoveTrafficQueues-Upstream/Downstream FIXED_QUEUE success case
+TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueSuccess) {
+ Status status;
+ traffic_queues->set_uni_id(0);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+
+ traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
+ status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - RemoveTrafficQueues-Downstream FIXED_QUEUE failure case
+TEST_F(TestRemoveTrafficQueues, RemoveUpstreamDownstreamFixedQueueFailure) {
+ Status status;
+ traffic_queues->set_uni_id(0);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 3 - RemoveTrafficQueues-Downstream_QUEUE not present case
+TEST_F(TestRemoveTrafficQueues, RemoveDownstreamFixedQueueNotPresent) {
+ //Remove scheduler so that is_tm_sched_id_present api call will return false
+ tech_profile::TrafficSchedulers* traffic_scheds;
+ tech_profile::TrafficScheduler* traffic_sched;
+ traffic_scheds = new tech_profile::TrafficSchedulers;
+ traffic_scheds->set_intf_id(0);
+ traffic_scheds->set_onu_id(1);
+ traffic_scheds->set_uni_id(0);
+ traffic_scheds->set_port_no(16);
+ traffic_sched = traffic_scheds->add_traffic_scheds();
+ traffic_sched->set_alloc_id(1024);
+ traffic_sched->set_direction(tech_profile::Direction::DOWNSTREAM);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+ RemoveTrafficSchedulers_(traffic_scheds);
+
+ traffic_queues->set_uni_id(0);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::DOWNSTREAM);
+
+ Status status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+/* Test 4 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, not removing TM QMP
+as it is getting referred by some other queues case */
+TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueNotRemovingTMQMP) {
+ traffic_queues->set_uni_id(3);
+ traffic_queues->set_port_no(16);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_priority(1);
+ traffic_queue_2->set_direction(tech_profile::Direction::UPSTREAM);
+
+ Status status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+/* Test 5 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, removing TM QMP as it
+is not getting referred by any other queues case */
+TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueRemovingTMQMP) {
+ traffic_queues->set_uni_id(1);
+ traffic_queues->set_port_no(32);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_priority(1);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_OK;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ Status status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+/* Test 6 - RemoveTrafficQueues-Upstream PRIORITY_TO_QUEUE, error while removing TM QMP
+having no reference to any other queues case */
+TEST_F(TestRemoveTrafficQueues, RemoveUpstreamPriorityQueueErrorRemovingTMQMP) {
+ traffic_queues->set_uni_id(4);
+ traffic_queues->set_port_no(64);
+ traffic_queue_1->set_direction(tech_profile::Direction::UPSTREAM);
+ traffic_queue_2 = traffic_queues->add_traffic_queues();
+ traffic_queue_2->set_gemport_id(1025);
+ traffic_queue_2->set_priority(1);
+
+ bcmos_errno olt_cfg_clear_res = BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_clear(_, _)).WillByDefault(Return(olt_cfg_clear_res));
+
+ Status status = RemoveTrafficQueues_(traffic_queues);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}