[VOL-2261]: changes to facilitate DisablePonIf
Change-Id: Ie8f85b9fdb8d880e051cc2007bab1ebef8785b10
diff --git a/agent/src/core.cc b/agent/src/core.cc
index 5053cd3..148ae08 100644
--- a/agent/src/core.cc
+++ b/agent/src/core.cc
@@ -1549,18 +1549,31 @@
}
Status DisablePonIf_(uint32_t intf_id) {
+ bcmos_errno err;
bcmolt_pon_interface_cfg interface_obj;
- bcmolt_pon_interface_key interface_key;
+ bcmolt_pon_interface_key intf_key = {.pon_ni = (bcmolt_interface)intf_id};
+ bcmolt_pon_interface_set_pon_interface_state pon_interface_set_state;
- interface_key.pon_ni = intf_id;
- BCMOLT_CFG_INIT(&interface_obj, pon_interface, interface_key);
- BCMOLT_MSG_FIELD_GET(&interface_obj, state);
- bcmos_errno err = bcmolt_cfg_get(dev_id, &interface_obj.hdr);
- if (err) {
- OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d, err = %s\n", intf_id, bcmos_strerror(err));
+ BCMOLT_CFG_INIT(&interface_obj, pon_interface, intf_key);
+ BCMOLT_OPER_INIT(&pon_interface_set_state, pon_interface, set_pon_interface_state, intf_key);
+ BCMOLT_MSG_FIELD_SET(&interface_obj, discovery.control, BCMOLT_CONTROL_STATE_DISABLE);
+
+ err = bcmolt_cfg_set(dev_id, &interface_obj.hdr);
+ if (err != BCM_ERR_OK) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable discovery of onu, PON interface %d, err %d\n", intf_id, err);
+ return bcm_to_grpc_err(err, "Failed to disable discovery of onu");
+ }
+
+ BCMOLT_FIELD_SET(&pon_interface_set_state.data, pon_interface_set_pon_interface_state_data,
+ operation, BCMOLT_INTERFACE_OPERATION_INACTIVE);
+
+ err = bcmolt_oper_submit(dev_id, &pon_interface_set_state.hdr);
+ if (err != BCM_ERR_OK) {
+ OPENOLT_LOG(ERROR, openolt_log_id, "Failed to disable PON interface: %d\n , err %d\n", intf_id, err);
return bcm_to_grpc_err(err, "Failed to disable PON interface");
}
+ OPENOLT_LOG(INFO, openolt_log_id, "Successfully disabled PON interface: %d\n", intf_id);
return Status::OK;
}
diff --git a/agent/test/inc/bal_mocker.h b/agent/test/inc/bal_mocker.h
index d36d0c7..6ad612d 100644
--- a/agent/test/inc/bal_mocker.h
+++ b/agent/test/inc/bal_mocker.h
@@ -42,6 +42,7 @@
MOCK_METHOD1(bcmolt_host_init, bcmos_errno(bcmolt_host_init_parms*));
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*));
// Add more here
};
diff --git a/agent/test/src/bal_mocker.cc b/agent/test/src/bal_mocker.cc
index 1bab8a2..8c8ec44 100644
--- a/agent/test/src/bal_mocker.cc
+++ b/agent/test/src/bal_mocker.cc
@@ -19,5 +19,6 @@
CMOCK_MOCK_FUNCTION1(BalMocker, bcmolt_host_init, bcmos_errno(bcmolt_host_init_parms*));
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*));
}
diff --git a/agent/test/src/bal_stub.cc b/agent/test/src/bal_stub.cc
index f3f27b4..1094cf6 100644
--- a/agent/test/src/bal_stub.cc
+++ b/agent/test/src/bal_stub.cc
@@ -55,11 +55,11 @@
}
/* Set configuration */
-bcmos_errno bcmolt_cfg_set(bcmolt_oltid olt, bcmolt_cfg *cfg)
+/*bcmos_errno bcmolt_cfg_set(bcmolt_oltid olt, bcmolt_cfg *cfg)
{
printf("-- entering :stubbed %s\n", __FUNCTION__);
return BCM_ERR_OK;
-}
+}*/
/* Get configuration */
/*
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index 3588f95..12fd0ee 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -234,14 +234,11 @@
// 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;
+ bcmos_errno olt_oper_res = BCM_ERR_OK;
Status olt_disable_res;
-
- EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
- .Times(num_of_pon_ports)
- .WillRepeatedly(Return(bal_cfg_get_res));
-
+ state.deactivate();
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
olt_disable_res = Disable_();
ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
@@ -252,14 +249,11 @@
// 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_INTERNAL;
+ bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
Status olt_disable_res;
-
- EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
- .Times(num_of_pon_ports)
- .WillRepeatedly(Return(bal_cfg_get_res));
-
+ state.deactivate();
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
olt_disable_res = Disable_();
ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
}
@@ -384,3 +378,56 @@
ASSERT_TRUE( query_status.error_message() == Status::OK.error_message() );
}
+////////////////////////////////////////////////////////////////////////////
+// For testing DisablePonIf functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestDisablePonIf : public Test {
+ protected:
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - DisablePonIf success case
+TEST_F(TestDisablePonIf, DisablePonIfSuccess) {
+ bcmos_errno olt_oper_res = BCM_ERR_OK;
+ bcmos_errno bal_cfg_set_res = BCM_ERR_OK;
+ NiceMock<BalMocker> balMock;
+ uint32_t pon_id=1;
+
+ //ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
+ state.deactivate();
+ Status status = DisablePonIf_(pon_id);
+
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - DisablePonIf Failure case
+TEST_F(TestDisablePonIf, DisablePonIfFailed) {
+ bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
+ NiceMock<BalMocker> balMock;
+ uint32_t pon_id=1;
+
+ ON_CALL(balMock, bcmolt_oper_submit(_, _)).WillByDefault(Return(olt_oper_res));
+ state.deactivate();
+ Status status = DisablePonIf_(pon_id);
+
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 3 - DisablePonIf ONU discovery failure case
+TEST_F(TestDisablePonIf, DisablePonIfOnuDiscoveryFail) {
+ NiceMock<BalMocker> balMock;
+ uint32_t pon_id=1;
+ bcmos_errno bal_cfg_set_res= BCM_ERR_INTERNAL;
+ ON_CALL(balMock, bcmolt_cfg_set(_, _)).WillByDefault(Return(bal_cfg_set_res));
+ state.deactivate();
+ Status status = DisablePonIf_(pon_id);
+
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+