[VOL-2152][BAL3.0 Brigade] OpenOLT driver registers ONU Remote Defect
Indicator alarm
- Provide missing BAL API definitions required for unit test compilation

Change-Id: Ifb38a55b24413beb9f5caf864403c4513cd7be68
diff --git a/Makefile b/Makefile
index fb7f456..c95af8d 100644
--- a/Makefile
+++ b/Makefile
@@ -23,9 +23,11 @@
 # set default shell options
 SHELL = bash -e -o pipefail
 
+export OPENOLT_ROOT_DIR=$(shell pwd)
+
 ## Variables
 OPENOLTDEVICE     ?= asfvolt16
-OPENOLT_PROTO_VER ?= v3.3.5
+OPENOLT_PROTO_VER ?= v3.3.6
 GTEST_VER         ?= release-1.8.0
 CMOCK_VER         ?= 0207b30
 GMOCK_GLOBAL_VER  ?= 1.0.2
diff --git a/README.md b/README.md
index f9f88a6..69492e2 100644
--- a/README.md
+++ b/README.md
@@ -272,7 +272,7 @@
 make OPENOLTDEVICE=asfvolt16 OPENOLT_PROTO_VER=master
 ```
 
-By default, the `OPENOLT_PROTO_VER` defaults to git tag *v3.3.5* of the
+By default, the `OPENOLT_PROTO_VER` defaults to git tag *v3.3.6* of the
 [voltha-protos](https://gerrit.opencord.org/gitweb?p=voltha-protos.git;a=summary)
 repo.
 
diff --git a/VERSION b/VERSION
index 59aa62c..7bf4b6a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.4.5
+2.4.6
diff --git a/agent/Makefile.in b/agent/Makefile.in
index 62f3ba3..9de5071 100644
--- a/agent/Makefile.in
+++ b/agent/Makefile.in
@@ -42,7 +42,7 @@
 # This specifies the GIT tag in https://github.com/opencord/voltha-protos
 # repo that we need to refer to, to pick the right version of
 # openolt.proto and tech_profile.proto
-OPENOLT_PROTO_VER ?= v3.3.5
+OPENOLT_PROTO_VER ?= v3.3.6
 
 # Variables used for Inband build
 INBAND = "n"
diff --git a/agent/common/core.h b/agent/common/core.h
index 33a9066..f4a440e 100644
--- a/agent/common/core.h
+++ b/agent/common/core.h
@@ -229,6 +229,7 @@
 Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues);
 Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues);
 Status PerformGroupOperation_(const openolt::Group *group_cfg);
+Status OnuItuPonAlarmSet_(const openolt::OnuItuPonAlarm* request);
 uint32_t GetPortNum_(uint32_t flow_id);
 int get_status_bcm_cli_quit(void);
 uint16_t get_dev_id(void);
diff --git a/agent/common/server.cc b/agent/common/server.cc
index 53b6317..17b804e 100644
--- a/agent/common/server.cc
+++ b/agent/common/server.cc
@@ -308,6 +308,13 @@
             openolt::Empty* response) override {
         return PerformGroupOperation_(request);
     };
+
+    Status OnuItuPonAlarmSet(
+            ServerContext* context,
+            const openolt::OnuItuPonAlarm* request,
+            openolt::Empty* response) override {
+        return OnuItuPonAlarmSet_(request);
+    };
 };
 
 void RunServer(int argc, char** argv) {
diff --git a/agent/src/core_api_handler.cc b/agent/src/core_api_handler.cc
index 6319faa..54f7e0d 100644
--- a/agent/src/core_api_handler.cc
+++ b/agent/src/core_api_handler.cc
@@ -90,6 +90,117 @@
     return s_actions_ptr;
 }
 
+bcmolt_stat_alarm_config set_stat_alarm_config(const openolt::OnuItuPonAlarm* request) {
+    bcmolt_stat_alarm_config alarm_cfg = {};
+    bcmolt_stat_alarm_trigger_config trigger_obj = {};
+    bcmolt_stat_alarm_soak_config soak_obj = {};
+
+    switch (request->alarm_reporting_condition()) {
+        case openolt::OnuItuPonAlarm::RATE_THRESHOLD:
+            trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
+            BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold,
+                    rising, request->rate_threshold_config().rate_threshold_rising());
+            BCMOLT_FIELD_SET(&trigger_obj.u.rate_threshold, stat_alarm_trigger_config_rate_threshold,
+                    falling, request->rate_threshold_config().rate_threshold_falling());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
+                    request->rate_threshold_config().soak_time().active_soak_time());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
+                    request->rate_threshold_config().soak_time().clear_soak_time());
+            break;
+        case openolt::OnuItuPonAlarm::RATE_RANGE:
+            trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
+            BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, upper,
+                    request->rate_range_config().rate_range_upper());
+            BCMOLT_FIELD_SET(&trigger_obj.u.rate_range, stat_alarm_trigger_config_rate_range, lower,
+                    request->rate_range_config().rate_range_lower());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
+                    request->rate_range_config().soak_time().active_soak_time());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
+                    request->rate_range_config().soak_time().clear_soak_time());
+            break;
+        case openolt::OnuItuPonAlarm::VALUE_THRESHOLD:
+            trigger_obj.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
+            BCMOLT_FIELD_SET(&trigger_obj.u.value_threshold, stat_alarm_trigger_config_value_threshold,
+                    limit, request->value_threshold_config().threshold_limit());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, active_soak_time,
+                    request->value_threshold_config().soak_time().active_soak_time());
+            BCMOLT_FIELD_SET(&soak_obj, stat_alarm_soak_config, clear_soak_time,
+                    request->value_threshold_config().soak_time().clear_soak_time());
+            break;
+        default:
+            OPENOLT_LOG(ERROR, openolt_log_id, "unsupported alarm reporting condition = %u\n", request->alarm_reporting_condition());
+            // For now just log the error and not return error. We can handle this scenario in the future.
+            break;
+    }
+
+    BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, trigger, trigger_obj);
+    BCMOLT_FIELD_SET(&alarm_cfg, stat_alarm_config, soak, soak_obj);
+
+    return alarm_cfg;
+}
+
+Status OnuItuPonAlarmSet_(const openolt::OnuItuPonAlarm* request) {
+    bcmos_errno err;
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg; /* declare main API struct */
+    bcmolt_onu_key key = {}; /* declare key */
+    bcmolt_stat_alarm_config errors_cfg = {};
+
+    key.pon_ni = request->pon_ni();
+    key.onu_id = request->onu_id();
+
+    /* Initialize the API struct. */
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+
+    /*
+       1. BCMOLT_STAT_CONDITION_TYPE_NONE = 0, The alarm is disabled.
+       2. BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD = 1, The alarm is triggered if the stats delta value between samples
+                                                   crosses the configured threshold boundary.
+           rising: The alarm is raised if the stats delta value per second becomes greater than this threshold level.
+           falling: The alarm is cleared if the stats delta value per second becomes less than this threshold level.
+       3. BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE = 2, The alarm is triggered if the stats delta value between samples
+                                               deviates from the configured range.
+           upper: The alarm is raised if the stats delta value per second becomes greater than this upper level.
+           lower: The alarm is raised if the stats delta value per second becomes less than this lower level.
+       4. BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD = 3, The alarm is raised if the stats sample value becomes greater
+                                                    than this level.  The alarm is cleared when the host read the stats.
+           limit: The alarm is raised if the stats sample value becomes greater than this level.
+                  The alarm is cleared when the host clears the stats.
+
+       active_soak_time: If the alarm condition is raised and stays in the raised state for at least this amount
+                         of time (unit=seconds), the alarm indication is sent to the host.
+                         The OLT delays the alarm indication no less than this delay period.
+                         It can be delayed more than this period because of the statistics sampling interval.
+       clear_soak_time: After the alarm is raised, if it is cleared and stays in the cleared state for at least
+                        this amount of time (unit=seconds), the alarm indication is sent to the host.
+                        The OLT delays the alarm indication no less than this delay period. It can be delayed more
+                        than this period because of the statistics sampling interval.
+    */
+
+    errors_cfg = set_stat_alarm_config(request);
+
+    switch (request->alarm_id()) {
+        case openolt::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS:
+            //set the rdi_errors alarm
+            BCMOLT_FIELD_SET(&stat_cfg.data, onu_itu_pon_stats_cfg_data, rdi_errors, errors_cfg);
+            break;
+        default:
+            OPENOLT_LOG(ERROR, openolt_log_id, "could not find the alarm id %d\n", request->alarm_id());
+            return bcm_to_grpc_err(BCM_ERR_PARM, "the alarm id is wrong");
+    }
+
+    err = bcmolt_stat_cfg_set(dev_id, &stat_cfg.hdr);
+    if (err != BCM_ERR_OK) {
+        OPENOLT_LOG(ERROR, openolt_log_id, "Failed to set onu itu pon stats, alarm id %d, pon_ni %d, onu_id %d, err = %s\n",
+                request->alarm_id(), key.pon_ni, key.onu_id, bcmos_strerror(err));
+        return bcm_to_grpc_err(err, "set Onu ITU PON stats alarm faild");
+    } else {
+        OPENOLT_LOG(INFO, openolt_log_id, "set onu itu pon stats alarm %d successfully, pon_ni %d, onu_id %d\n",
+                request->alarm_id(), key.pon_ni, key.onu_id);
+    }
+
+    return Status::OK;
+}
+
 Status GetDeviceInfo_(openolt::DeviceInfo* device_info) {
     device_info->set_vendor(VENDOR_ID);
     device_info->set_model(MODEL_ID);
diff --git a/agent/src/indications.cc b/agent/src/indications.cc
index 7c1c90d..759f419 100644
--- a/agent/src/indications.cc
+++ b/agent/src/indications.cc
@@ -38,7 +38,6 @@
 extern std::map<alloc_cfg_compltd_key,  Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
 extern bcmos_fastlock alloc_cfg_wait_lock;
 
-
 bool subscribed = false;
 uint32_t nni_intf_id = 0;
 #define current_device 0
@@ -93,6 +92,43 @@
     return "unknown";
 }
 
+inline uint64_t get_pon_stats_alarms_data(bcmolt_interface pon_ni, bcmolt_onu_id onu_id, bcmolt_onu_itu_pon_stats_data_id stat) {
+    bcmos_errno err;
+    bcmolt_onu_itu_pon_stats itu_pon_stat; /* declare main API struct */
+    bcmolt_onu_key key = {}; /* declare key */
+    bcmolt_stat_flags clear_on_read = BCMOLT_STAT_FLAGS_NONE; /* declare 'clear on read' flag */
+
+    key.pon_ni = pon_ni;
+    key.onu_id = onu_id;
+
+    /* Initialize the API struct. */
+    BCMOLT_STAT_INIT(&itu_pon_stat, onu, itu_pon_stats, key);
+    switch (stat) {
+        case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_RDI_ERRORS:
+            BCMOLT_FIELD_SET_PRESENT(&itu_pon_stat.data, onu_itu_pon_stats_data, rdi_errors);
+            err = bcmolt_stat_get(dev_id, &itu_pon_stat.hdr, clear_on_read ? BCMOLT_STAT_FLAGS_CLEAR_ON_READ : BCMOLT_STAT_FLAGS_NONE);
+            if (err) {
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get rdi_errors, err = %s\n", bcmos_strerror(err));
+                return err;
+            }
+            return itu_pon_stat.data.rdi_errors;
+        /* It is a further requirement
+        case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_BIP_ERRORS:
+            BCMOLT_FIELD_SET_PRESENT(&itu_pon_stat.data, onu_itu_pon_stats_data, bip_errors);
+            err = bcmolt_stat_get(dev_id, &itu_pon_stat.hdr, clear_on_read ? BCMOLT_STAT_FLAGS_CLEAR_ON_READ : BCMOLT_STAT_FLAGS_NONE);
+            if (err) {
+                OPENOLT_LOG(ERROR, openolt_log_id, "Failed to get bip_errors, err = %s\n", bcmos_strerror(err));
+                return err;
+            }
+            return itu_pon_stat.data.bip_errors;
+        */
+        default:
+            return BCM_ERR_INTERNAL;
+    }
+
+    return err;
+}
+
 /*std::string getOnuRegistrationId(uint32_t intf_id, uint32_t onu_id){
     bcmbal_subscriber_terminal_key key;
     bcmbal_subscriber_terminal_cfg sub_term_obj = {};
@@ -828,7 +864,7 @@
     bcmolt_msg_free(msg);
 }
 
-static void OnuItuPonStatsIndication(bcmolt_devid olt, bcmolt_msg *msg) {
+static void OnuItuPonStatsAlarmRaisedIndication(bcmolt_devid olt, bcmolt_msg *msg) {
     openolt::Indication ind;
     openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
     openolt::OnuItuPonStatsIndication* onu_itu_pon_stats_ind = new openolt::OnuItuPonStatsIndication;
@@ -836,20 +872,41 @@
     switch (msg->obj_type) {
         case BCMOLT_OBJ_ID_ONU:
             switch (msg->subgroup) {
-                case BCMOLT_ONU_STAT_SUBGROUP_ITU_PON_STATS:
+                case BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_RAISED:
                 {
-                    bcmolt_onu_key *key = &((bcmolt_onu_itu_pon_stats*)msg)->key;
-                    bcmolt_onu_itu_pon_stats_data *data = &((bcmolt_onu_itu_pon_stats*)msg)->data;
+                    bcmolt_onu_key *onu_key = &((bcmolt_onu_itu_pon_stats_alarm_raised*)msg)->key;
+                    bcmolt_onu_itu_pon_stats_alarm_raised_data *data = &((bcmolt_onu_itu_pon_stats_alarm_raised*)msg)->data;
 
-                    OPENOLT_LOG(INFO, openolt_log_id, "Got onu rdi erros, intf_id %d, onu_id %d, rdi_errors %"PRIu64"\n",
-                        key->pon_ni, key->onu_id, data->rdi_errors);
-
-                    onu_itu_pon_stats_ind->set_intf_id(key->pon_ni);
-                    onu_itu_pon_stats_ind->set_onu_id(key->onu_id);
-                    onu_itu_pon_stats_ind->set_rdi_errors(data->rdi_errors);
-                    alarm_ind->set_allocated_onu_itu_pon_stats_ind(onu_itu_pon_stats_ind);
-
-                    ind.set_allocated_alarm_ind(alarm_ind);
+                    if (_BCMOLT_FIELD_MASK_BIT_IS_SET(data->presence_mask, BCMOLT_ONU_ITU_PON_STATS_ALARM_RAISED_DATA_ID_STAT)) {
+                        switch (data->stat)
+                        {
+                            case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_RDI_ERRORS:
+                                uint64_t rdi_errors;
+                                openolt::RdiErrorIndication* rdi_err_ind = new openolt::RdiErrorIndication;
+                                rdi_errors = get_pon_stats_alarms_data(onu_key->pon_ni, onu_key->onu_id, data->stat);
+                                onu_itu_pon_stats_ind->set_intf_id(onu_key->pon_ni);
+                                onu_itu_pon_stats_ind->set_onu_id(onu_key->onu_id);
+                                rdi_err_ind->set_rdi_error_count(rdi_errors);
+                                rdi_err_ind->set_status("on");
+                                onu_itu_pon_stats_ind->set_allocated_rdi_error_ind(rdi_err_ind);
+                                OPENOLT_LOG(INFO, openolt_log_id, "Got onu raised alarm indication, intf_id %d, onu_id %d, \
+                                        rdi_errors %"PRIu64"\n", onu_key->pon_ni, onu_key->onu_id, rdi_errors);
+                                alarm_ind->set_allocated_onu_itu_pon_stats_ind(onu_itu_pon_stats_ind);
+                                break;
+                            /* It is a further requirement
+                            case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_BIP_ERRORS:
+                                uint64_t bip_errors;
+                                bip_errors = get_pon_stats_alarms_data(onu_key->pon_ni, onu_key->onu_id, data->stat);
+                                onu_itu_pon_stats_ind->set_intf_id(onu_key->pon_ni);
+                                onu_itu_pon_stats_ind->set_onu_id(onu_key->onu_id);
+                                OPENOLT_LOG(INFO, openolt_log_id, "Got onu raised alarm indication, intf_id %d, onu_id %d, \
+                                        bip_errors %"PRIu64"\n", onu_key->pon_ni, onu_key->onu_id, bip_errors);
+                                alarm_ind->set_allocated_onu_itu_pon_stats_ind(onu_itu_pon_stats_ind);
+                                break;
+                            */
+                        }
+                        ind.set_allocated_alarm_ind(alarm_ind);
+                    }
                 }
             }
     }
@@ -858,7 +915,58 @@
     bcmolt_msg_free(msg);
 }
 
+static void OnuItuPonStatsAlarmClearedIndication(bcmolt_devid olt, bcmolt_msg *msg) {
+    openolt::Indication ind;
+    openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
+    openolt::OnuItuPonStatsIndication* onu_itu_pon_stats_ind = new openolt::OnuItuPonStatsIndication;
 
+    switch (msg->obj_type) {
+        case BCMOLT_OBJ_ID_ONU:
+            switch (msg->subgroup) {
+                case BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_CLEARED:
+                {
+                    bcmolt_onu_key *onu_key = &((bcmolt_onu_itu_pon_stats_alarm_cleared*)msg)->key;
+                    bcmolt_onu_itu_pon_stats_alarm_cleared_data *data = &((bcmolt_onu_itu_pon_stats_alarm_cleared*)msg)->data;
+
+                    if (_BCMOLT_FIELD_MASK_BIT_IS_SET(data->presence_mask, BCMOLT_ONU_ITU_PON_STATS_ALARM_CLEARED_DATA_ID_STAT)) {
+                        switch (data->stat)
+                        {
+                            case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_RDI_ERRORS:
+                                uint64_t rdi_errors;
+                                openolt::RdiErrorIndication* rdi_err_ind = new openolt::RdiErrorIndication;
+
+                                rdi_errors = get_pon_stats_alarms_data(onu_key->pon_ni, onu_key->onu_id, data->stat);
+                                onu_itu_pon_stats_ind->set_intf_id(onu_key->pon_ni);
+                                onu_itu_pon_stats_ind->set_onu_id(onu_key->onu_id);
+                                rdi_err_ind->set_rdi_error_count(rdi_errors);
+                                rdi_err_ind->set_status("off");
+                                onu_itu_pon_stats_ind->set_allocated_rdi_error_ind(rdi_err_ind);
+                                OPENOLT_LOG(INFO, openolt_log_id, "Got onu cleared alarm indication, intf_id %d, onu_id %d, \
+                                        rdi_errors %"PRIu64"\n", onu_key->pon_ni, onu_key->onu_id, rdi_errors);
+                                alarm_ind->set_allocated_onu_itu_pon_stats_ind(onu_itu_pon_stats_ind);
+                                break;
+                            /* It is a further requirement
+                            case BCMOLT_ONU_ITU_PON_STATS_DATA_ID_BIP_ERRORS:
+                                uint64_t bip_errors;
+                                bip_errors = get_pon_stats_alarms_data(onu_key->pon_ni, onu_key->onu_id, data->stat);
+                                onu_itu_pon_stats_ind->set_intf_id(onu_key->pon_ni);
+                                onu_itu_pon_stats_ind->set_onu_id(onu_key->onu_id);
+                                onu_itu_pon_stats_ind->set_bip_errors(bip_errors);
+                                OPENOLT_LOG(INFO, openolt_log_id, "Got onu cleared alarm indication, intf_id %d, onu_id %d, \
+                                        bip_errors %"PRIu64"\n", onu_key->pon_ni, onu_key->onu_id, bip_errors);
+                                alarm_ind->set_allocated_onu_itu_pon_stats_ind(onu_itu_pon_stats_ind);
+                                break;
+                            */
+                        }
+                        ind.set_allocated_alarm_ind(alarm_ind);
+                    }
+                }
+            }
+    }
+
+    oltIndQ.push(ind);
+    bcmolt_msg_free(msg);
+}
 
 static void OnuDeactivationCompletedIndication(bcmolt_devid olt, bcmolt_msg *msg) {
     openolt::Indication ind;
@@ -930,7 +1038,6 @@
     OPENOLT_LOG(WARNING, openolt_log_id, "onu processing error indication, intf_id %d, onu_id %d\n",
         key->intf_id, key->sub_term_id);
 
-
     onu_proc_error_ind->set_intf_id(key->intf_id);
     onu_proc_error_ind->set_onu_id(key->sub_term_id);
 
@@ -1139,14 +1246,23 @@
     if(rc != BCM_ERR_OK)
         return Status(grpc::StatusCode::INTERNAL, "onu loss of key sync indication subscribe failed");
 
-    /* ONU ITU-PON Stats Indiction */
+    /* ONU ITU-PON Raised Stats Indiction */
     rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
-    rx_cfg.rx_cb = OnuItuPonStatsIndication;
+    rx_cfg.rx_cb = OnuItuPonStatsAlarmRaisedIndication;
     rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
-    rx_cfg.subgroup = bcmolt_onu_stat_subgroup_itu_pon_stats;
+    rx_cfg.subgroup = bcmolt_onu_auto_subgroup_itu_pon_stats_alarm_raised;
     rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
     if(rc != BCM_ERR_OK)
-        return Status(grpc::StatusCode::INTERNAL, "onu itu-pon stats indication subscribe failed");
+        return Status(grpc::StatusCode::INTERNAL, "onu itu-pon raised stats indication subscribe failed");
+
+    /* ONU ITU-PON Cleared Stats Indiction */
+    rx_cfg.obj_type = BCMOLT_OBJ_ID_ONU;
+    rx_cfg.rx_cb = OnuItuPonStatsAlarmClearedIndication;
+    rx_cfg.flags = BCMOLT_AUTO_FLAGS_NONE;
+    rx_cfg.subgroup = bcmolt_onu_auto_subgroup_itu_pon_stats_alarm_cleared;
+    rc = bcmolt_ind_subscribe(current_device, &rx_cfg);
+    if(rc != BCM_ERR_OK)
+        return Status(grpc::StatusCode::INTERNAL, "onu itu-pon cleared stats indication subscribe failed");
 
     /* Packet-In by Access_Control */
     rx_cfg.obj_type = BCMOLT_OBJ_ID_ACCESS_CONTROL;
diff --git a/agent/src/stats_collection.cc b/agent/src/stats_collection.cc
index 9caa98e..4979366 100644
--- a/agent/src/stats_collection.cc
+++ b/agent/src/stats_collection.cc
@@ -34,7 +34,7 @@
 #define FLOWS_COUNT 100
 
 bcmolt_flow_key* flows_keys = new bcmolt_flow_key[FLOWS_COUNT];
-bcmolt_odid device_id = 0;    
+bcmolt_odid device_id = 0;
 
 void init_stats() {
     memset(flows_keys, 0, FLOWS_COUNT * sizeof(bcmolt_flow_key));
@@ -84,7 +84,6 @@
     bcmolt_onu_itu_pon_stats pon_stats;
     bcmolt_pon_interface_itu_pon_stats itu_pon_stats;
 
-
     switch (intf_ref.intf_type) {
         case BCMOLT_INTERFACE_TYPE_NNI:
         {
@@ -111,7 +110,7 @@
             {
                 //std::cout << "Interface statistics retrieved"
                 //          << " intf_id:" << intf_id << std::endl;
-            
+
                 port_stats->set_rx_bytes(nni_stats.data.rx_bytes);
                 port_stats->set_rx_packets(nni_stats.data.rx_packets);
                 port_stats->set_rx_ucast_packets(nni_stats.data.rx_ucast_packets);
@@ -124,7 +123,7 @@
                 port_stats->set_tx_mcast_packets(nni_stats.data.tx_mcast_packets);
                 port_stats->set_tx_bcast_packets(nni_stats.data.tx_bcast_packets);
                 port_stats->set_tx_error_packets(nni_stats.data.tx_error_packets);
-            
+
             } else {
                 OPENOLT_LOG(ERROR, openolt_log_id,  "Failed to retrieve port statistics, intf_id %d, intf_type %d, err = %s\n",
                     (int)intf_ref.intf_id, (int)intf_ref.intf_type, bcmos_strerror(err));
@@ -171,7 +170,7 @@
             }
             break;
         }
-    } 
+    }
 
     port_stats->set_intf_id(interface_key_to_port_no((bcmolt_interface_id)intf_ref.intf_id, (bcmolt_interface_type)intf_ref.intf_type));
     time_t now;
@@ -222,7 +221,6 @@
 }
 #endif
 
-
 void stats_collection() {
 
     if (!state.is_connected()) {
@@ -234,7 +232,6 @@
         return;
     }
 
-
     OPENOLT_LOG(DEBUG, openolt_log_id, "Collecting statistics\n");
 
     //Ports statistics
@@ -258,7 +255,7 @@
         intf_ref.intf_type = BCMOLT_INTERFACE_TYPE_PON;
         intf_ref.intf_id = i;
 
-        openolt::PortStatistics* port_stats = 
+        openolt::PortStatistics* port_stats =
             collectPortStatistics(intf_ref);
 
         openolt::Indication ind;
diff --git a/agent/test/Makefile b/agent/test/Makefile
index a32c160..1693af0 100644
--- a/agent/test/Makefile
+++ b/agent/test/Makefile
@@ -1,4 +1,4 @@
-# Copyright 2018-present Open Networking Foundation
+ # Copyright 2018-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
 TOP_DIR=`pwd`
 OPENOLTDEVICE ?= asfvolt16
 
-OPENOLT_PROTO_VER ?= v3.3.5
+OPENOLT_PROTO_VER ?= v3.3.6
 
 GTEST_VER ?= release-1.8.0
 gtest-target = /usr/local/lib/libgtest.a
@@ -134,6 +134,11 @@
 OPENOLT_API_LIB = lib/libopenoltapi.a
 OPENOLT_LIB = lib/libopenolt.a
 
+# Set the OPENOLT_ROOT_DIR variable to "/app" folder inside the docker container, if not already set.
+ifeq ($(OPENOLT_ROOT_DIR),)
+OPENOLT_ROOT_DIR := /app
+endif
+
 all: bcm_host_api_stubs $(OPENOLT_API_LIB) $(OPENOLT_LIB) build
 
 # test
@@ -152,20 +157,15 @@
 
 # bcm_host_api_stubs
 bcm_host_api_stubs:
+	echo $(OPENOLT_ROOT_DIR); \
 	# TODO: This is temporary hack below to introduce the definition BAL IEs that are missing in https://github.com/balapi/bal-api-<BAL-VER>
 	if [ -d $(BAL_API_DIR) ]; then \
 		echo "$(BAL_API_DIR) exists"; \
 	else \
 		git clone https://github.com/balapi/$(BAL_API_VER).git ;\
-		sed -i "\$$i #define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0" ./$(BAL_API_DIR)/include/bcmos_system.h; \
-		sed -i "\$$i struct bcmos_mutex \{ pthread_mutex_t m; };" ./$(BAL_API_DIR)/include/bcmos_system.h; \
-		sed -i "\$$i extern void* bcmos_calloc(uint32_t size);"  ./$(BAL_API_DIR)/include/bcmos_common.h; \
-		sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_1_G 3"  ./$(BAL_API_DIR)/include/bcmos_common.h; \
-		sed -i "\$$i #define BCMOLT_INTERFACE_TYPE_EPON_10_G 4"  ./$(BAL_API_DIR)/include/bcmos_common.h; \
-		sed -i "\$$i typedef struct \{ uint64_t rdi_errors;} bcmolt_onu_itu_pon_stats_data;" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
-		sed -i "\$$i typedef struct \{ bcmolt_onu_key key; bcmolt_onu_itu_pon_stats_data data;} bcmolt_onu_itu_pon_stats;" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
-		sed -i "\$$i #define bcmolt_onu_stat_subgroup_itu_pon_stats BCMOLT_ONU_STAT_SUBGROUP_ITU_PON_STATS" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
-		sed -i "\$$i #define BCMOLT_ONU_STAT_SUBGROUP_ITU_PON_STATS 0" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
+		sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_system_test.h\"" ./$(BAL_API_DIR)/include/bcmos_system.h; \
+		sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmos_common_test.h\"" ./$(BAL_API_DIR)/include/bcmos_common.h; \
+		sed -i "\$$i #include \"$(OPENOLT_ROOT_DIR)/agent/test/inc/bcmolt_api_model_api_structs_test.h\"" ./$(BAL_API_DIR)/include/object_model/bcmolt_api_model_api_structs.h; \
 	fi
 
 # openoltapi
diff --git a/agent/test/inc/bal_mocker.h b/agent/test/inc/bal_mocker.h
index f60c581..8a8a9fa 100644
--- a/agent/test/inc/bal_mocker.h
+++ b/agent/test/inc/bal_mocker.h
@@ -44,6 +44,7 @@
     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*));
+    MOCK_METHOD2(bcmolt_stat_cfg_set, bcmos_errno(bcmolt_oltid, bcmolt_stat_cfg*));
   // Add more here
 };
 
diff --git a/agent/test/inc/bcmolt_api_model_api_structs_test.h b/agent/test/inc/bcmolt_api_model_api_structs_test.h
new file mode 100644
index 0000000..3c67a1e
--- /dev/null
+++ b/agent/test/inc/bcmolt_api_model_api_structs_test.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCMOLT_API_MODEL_API_STRUCTS_TEST_H_
+#define BCMOLT_API_MODEL_API_STRUCTS_TEST_H_
+
+#include <bcmos_system.h>
+#include <bcmolt_system_types.h>
+#include "bcmolt_msg.h"
+#include "bcmolt_api_model_supporting_structs.h"
+#include "bcmolt_api_model_supporting_enums.h"
+#include "bcmolt_api_model_supporting_typedefs.h"
+
+/**
+This header file provides STUB definitions of missing BAL structs for unit test compilation
+*/
+
+
+// ITU PON Statistics
+typedef struct
+{
+    uint64_t presence_mask;
+    uint64_t rdi_errors;
+} bcmolt_onu_itu_pon_stats_data;
+
+typedef struct
+{
+    bcmolt_stat hdr;
+    bcmolt_onu_key key;
+    bcmolt_onu_itu_pon_stats_data data;
+} bcmolt_onu_itu_pon_stats;
+
+
+
+// onu_itu_pon_stats_data'
+typedef enum
+{
+    BCMOLT_ONU_ITU_PON_STATS_DATA_ID_RDI_ERRORS = 1,
+    BCMOLT_ONU_ITU_PON_STATS_CFG_DATA_ID_BIP_ERRORS = 2
+
+    #define bcmolt_onu_itu_pon_stats_data_id_rdi_errors BCMOLT_ONU_ITU_PON_STATS_DATA_ID_RDI_ERRORS
+    #define bcmolt_onu_itu_pon_stats_cfg_data_id_bip_errors BCMOLT_ONU_ITU_PON_STATS_CFG_DATA_ID_BIP_ERRORS
+
+} bcmolt_onu_itu_pon_stats_data_id;
+
+// onu_itu_pon_stats_cfg_data
+typedef enum
+{
+
+    BCMOLT_ONU_ITU_PON_STATS_CFG_DATA_ID_RDI_ERRORS = 1
+
+    #define bcmolt_onu_itu_pon_stats_cfg_data_id_rdi_errors BCMOLT_ONU_ITU_PON_STATS_CFG_DATA_ID_RDI_ERRORS
+
+} bcmolt_onu_itu_pon_stats_cfg_data_id;
+
+//onu_itu_pon_stats_alarm_raised_data
+typedef enum
+{
+    BCMOLT_ONU_ITU_PON_STATS_ALARM_RAISED_DATA_ID_STAT = 0
+    #define bcmolt_onu_itu_pon_stats_alarm_raised_data_id_stat BCMOLT_ONU_ITU_PON_STATS_ALARM_RAISED_DATA_ID_STAT
+
+} bcmolt_onu_itu_pon_stats_alarm_raised_data_id;
+
+// onu_itu_pon_stats_alarm_cleared_data
+typedef enum
+{
+    BCMOLT_ONU_ITU_PON_STATS_ALARM_CLEARED_DATA_ID_STAT = 0
+    #define bcmolt_onu_itu_pon_stats_alarm_cleared_data_id_stat BCMOLT_ONU_ITU_PON_STATS_ALARM_CLEARED_DATA_ID_STAT
+
+} bcmolt_onu_itu_pon_stats_alarm_cleared_data_id;
+
+
+/** ONU: ITU PON Statistics Alarm Raised */
+typedef struct
+{
+    bcmolt_presence_mask presence_mask;
+    bcmolt_onu_itu_pon_stats_data_id stat;
+} bcmolt_onu_itu_pon_stats_alarm_raised_data;
+
+// itu_pon_stats_alarm_raised" group of "onu" object
+typedef struct
+{
+    bcmolt_auto hdr;
+    bcmolt_onu_key key;
+    bcmolt_onu_itu_pon_stats_alarm_raised_data data;
+} bcmolt_onu_itu_pon_stats_alarm_raised;
+
+// ITU PON Statistics Alarm Cleared
+typedef struct
+{
+    uint64_t presence_mask;
+    bcmolt_onu_itu_pon_stats_data_id stat;
+} bcmolt_onu_itu_pon_stats_alarm_cleared_data;
+
+// itu_pon_stats_alarm_cleared" group of "onu" object
+typedef struct
+{
+    bcmolt_auto hdr;
+    bcmolt_onu_key key;
+    bcmolt_onu_itu_pon_stats_alarm_cleared_data data;
+} bcmolt_onu_itu_pon_stats_alarm_cleared;
+
+
+// ITU PON Statistics Configuration
+typedef struct
+{
+    uint64_t presence_mask;
+    bcmolt_stat_alarm_config rdi_errors;
+    bcmolt_stat_alarm_config bip_errors;
+
+} bcmolt_onu_itu_pon_stats_cfg_data;
+
+// itu_pon_stats_cfg" group of "onu" object
+typedef struct
+{
+    bcmolt_stat_cfg hdr;
+    bcmolt_onu_key key;
+    bcmolt_onu_itu_pon_stats_cfg_data data;
+} bcmolt_onu_itu_pon_stats_cfg;
+
+#define BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_CLEARED 1
+#define BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_RAISED 2
+#define BCMOLT_ONU_STAT_SUBGROUP_ITU_PON_STATS 3
+#define BCMOLT_ONU_STAT_CFG_SUBGROUP_ITU_PON_STATS_CFG 4
+
+#define bcmolt_onu_auto_subgroup_itu_pon_stats_alarm_cleared BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_CLEARED
+#define bcmolt_onu_auto_subgroup_itu_pon_stats_alarm_raised BCMOLT_ONU_AUTO_SUBGROUP_ITU_PON_STATS_ALARM_RAISED
+#define bcmolt_onu_stat_subgroup_itu_pon_stats BCMOLT_ONU_STAT_SUBGROUP_ITU_PON_STATS
+#define bcmolt_onu_stat_cfg_subgroup_itu_pon_stats_cfg BCMOLT_ONU_STAT_CFG_SUBGROUP_ITU_PON_STATS_CFG
+
+#endif // BCMOLT_API_MODEL_API_STRUCTS_TEST_H_
+
diff --git a/agent/test/inc/bcmos_common_test.h b/agent/test/inc/bcmos_common_test.h
new file mode 100644
index 0000000..391b444
--- /dev/null
+++ b/agent/test/inc/bcmos_common_test.h
@@ -0,0 +1,29 @@
+/*
+
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCMOS_COMMON_TEST_H_
+#define BCMOS_COMMON_TEST_H_
+
+/**
+This header file provides missing BAL API definitions required for unit test compilation.
+*/
+
+extern void* bcmos_calloc(uint32_t size);
+#define BCMOLT_INTERFACE_TYPE_EPON_1_G 3
+#define BCMOLT_INTERFACE_TYPE_EPON_10_G 4
+
+#endif // BCMOS_COMMON_TEST_H_
diff --git a/agent/test/inc/bcmos_system_test.h b/agent/test/inc/bcmos_system_test.h
new file mode 100644
index 0000000..881a232
--- /dev/null
+++ b/agent/test/inc/bcmos_system_test.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCMOS_SYSTEM_TEST_H_
+#define BCMOS_SYSTEM_TEST_H_
+
+#include <pthread.h>
+
+/**
+This header file provides missing BAL API definitions required for unit test compilation.
+*/
+
+#define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0
+struct bcmos_mutex { pthread_mutex_t m; };
+
+#endif
+
diff --git a/agent/test/src/bal_mocker.cc b/agent/test/src/bal_mocker.cc
index f59c412..72ef1d2 100644
--- a/agent/test/src/bal_mocker.cc
+++ b/agent/test/src/bal_mocker.cc
@@ -21,5 +21,6 @@
 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*));
+CMOCK_MOCK_FUNCTION2(BalMocker, bcmolt_stat_cfg_set, bcmos_errno(bcmolt_oltid, bcmolt_stat_cfg*));
 }
 
diff --git a/agent/test/src/bal_stub.cc b/agent/test/src/bal_stub.cc
index 124b9a0..2c778ce 100644
--- a/agent/test/src/bal_stub.cc
+++ b/agent/test/src/bal_stub.cc
@@ -108,13 +108,6 @@
     return BCM_ERR_OK;
 }
 
-/* Set statistics configuration */
-bcmos_errno bcmolt_stat_cfg_set(bcmolt_oltid olt, bcmolt_stat_cfg *cfg)
-{
-    printf("-- entering :stubbed %s\n", __FUNCTION__);
-    return BCM_ERR_OK;
-}
-
 /* Register Autonomous Indication Message Handler */
 bcmos_errno bcmolt_ind_subscribe(bcmolt_oltid olt, bcmolt_rx_cfg *rx_cfg)
 {
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index d5b4dc8..698b894 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -2633,3 +2633,179 @@
     Status status = RemoveTrafficQueues_(traffic_queues);
     ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
 }
+
+////////////////////////////////////////////////////////////////////////////
+// For testing OnuItuPonAlarmSet functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestOnuItuPonAlarmSet : public Test {
+    protected:
+        bcmolt_pon_ni pon_ni = 0;
+        bcmolt_onu_id onu_id = 1;
+
+        openolt::OnuItuPonAlarm *onu_itu_pon_alarm_rt;
+        openolt::OnuItuPonAlarm::RateThresholdConfig *rate_threshold_config;
+        openolt::OnuItuPonAlarm::SoakTime *soak_time_rt;
+
+        openolt::OnuItuPonAlarm *onu_itu_pon_alarm_rr;
+        openolt::OnuItuPonAlarm::RateRangeConfig *rate_range_config;
+        openolt::OnuItuPonAlarm::SoakTime *soak_time_rr;
+
+        openolt::OnuItuPonAlarm *onu_itu_pon_alarm_tc;
+        openolt::OnuItuPonAlarm::ValueThresholdConfig *value_threshold_config;
+        openolt::OnuItuPonAlarm::SoakTime *soak_time_tc;
+
+        NiceMock<BalMocker> balMock;
+
+        virtual void SetUp() {
+            onu_itu_pon_alarm_rt = new openolt::OnuItuPonAlarm;
+            rate_threshold_config = new openolt::OnuItuPonAlarm::RateThresholdConfig;
+            soak_time_rt = new openolt::OnuItuPonAlarm::SoakTime;
+            onu_itu_pon_alarm_rt->set_pon_ni(0);
+            onu_itu_pon_alarm_rt->set_onu_id(1);
+            onu_itu_pon_alarm_rt->set_alarm_id(openolt::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
+            onu_itu_pon_alarm_rt->set_alarm_reporting_condition(openolt::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_THRESHOLD);
+            rate_threshold_config->set_rate_threshold_rising(1);
+            rate_threshold_config->set_rate_threshold_falling(4);
+            soak_time_rt->set_active_soak_time(2);
+            soak_time_rt->set_clear_soak_time(2);
+            rate_threshold_config->set_allocated_soak_time(soak_time_rt);
+            onu_itu_pon_alarm_rt->set_allocated_rate_threshold_config(rate_threshold_config);
+
+            onu_itu_pon_alarm_rr = new openolt::OnuItuPonAlarm;
+            rate_range_config = new openolt::OnuItuPonAlarm::RateRangeConfig;
+            soak_time_rr = new openolt::OnuItuPonAlarm::SoakTime;
+            onu_itu_pon_alarm_rr->set_pon_ni(0);
+            onu_itu_pon_alarm_rr->set_onu_id(1);
+            onu_itu_pon_alarm_rr->set_alarm_id(openolt::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
+            onu_itu_pon_alarm_rr->set_alarm_reporting_condition(openolt::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_RATE_RANGE);
+            rate_range_config->set_rate_range_lower(1);
+            rate_range_config->set_rate_range_upper(4);
+            soak_time_rr->set_active_soak_time(2);
+            soak_time_rr->set_clear_soak_time(2);
+            rate_range_config->set_allocated_soak_time(soak_time_rr);
+            onu_itu_pon_alarm_rr->set_allocated_rate_range_config(rate_range_config);
+
+            onu_itu_pon_alarm_tc = new openolt::OnuItuPonAlarm;
+            value_threshold_config = new openolt::OnuItuPonAlarm::ValueThresholdConfig;
+            soak_time_tc = new openolt::OnuItuPonAlarm::SoakTime;
+            onu_itu_pon_alarm_tc->set_pon_ni(0);
+            onu_itu_pon_alarm_tc->set_onu_id(1);
+            onu_itu_pon_alarm_tc->set_alarm_id(openolt::OnuItuPonAlarm_AlarmID::OnuItuPonAlarm_AlarmID_RDI_ERRORS);
+            onu_itu_pon_alarm_tc->set_alarm_reporting_condition(openolt::OnuItuPonAlarm_AlarmReportingCondition::OnuItuPonAlarm_AlarmReportingCondition_VALUE_THRESHOLD);
+            value_threshold_config->set_threshold_limit(6);
+            soak_time_tc->set_active_soak_time(2);
+            soak_time_tc->set_clear_soak_time(2);
+            value_threshold_config->set_allocated_soak_time(soak_time_tc);
+            onu_itu_pon_alarm_tc->set_allocated_value_threshold_config(value_threshold_config);
+        }
+
+        virtual void TearDown() {
+        }
+};
+
+// Test 1 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type success case
+// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
+//                 the configured threshold boundary.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeSuccess) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
+    stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
+    stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
+    ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - OnuItuPonAlarmSet-Set RDI_errors to rate threshold type failure case
+// rate_threshold: The alarm is triggered if the stats delta value between samples crosses
+//                 the configured threshold boundary.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateThresholdTypeFailure) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_THRESHOLD;
+    stat_cfg.data.rdi_errors.trigger.u.rate_threshold.rising = 50;
+    stat_cfg.data.rdi_errors.trigger.u.rate_threshold.falling = 100;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rt);
+    ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 3 - OnuItuPonAlarmSet-Set RDI_errors to rate range type success case
+// rate_range: The alarm is triggered if the stats delta value between samples deviates
+//             from the configured range.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeSuccess) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
+    stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 100;
+    stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 50;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
+    ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 4 - OnuItuPonAlarmSet-Set RDI_errors to rate range type failure case
+// rate_range: The alarm is triggered if the stats delta value between samples deviates
+//             from the configured range.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsRateRangeTypeFailure) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_RATE_RANGE;
+    stat_cfg.data.rdi_errors.trigger.u.rate_range.upper = 50;
+    stat_cfg.data.rdi_errors.trigger.u.rate_range.lower = 100;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_rr);
+    ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
+
+// Test 5 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type success case
+// value_threshold: The alarm is raised if the stats sample value becomes greater than this
+//                  level.  The alarm is cleared when the host read the stats.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeSuccess) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
+    stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = 100;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_OK;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
+    ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 6 - OnuItuPonAlarmSet-Set RDI_errors to value threshold type failure case
+// value_threshold: The alarm is raised if the stats sample value becomes greater than this
+//                  level.  The alarm is cleared when the host read the stats.
+TEST_F(TestOnuItuPonAlarmSet, OnuItuPonAlarmSetRdiErrorsValueThresholdTypeFailure) {
+    bcmolt_onu_itu_pon_stats_cfg stat_cfg;
+    bcmolt_onu_key key = {};
+    BCMOLT_STAT_CFG_INIT(&stat_cfg, onu, itu_pon_stats, key);
+    stat_cfg.data.rdi_errors.trigger.type = BCMOLT_STAT_CONDITION_TYPE_VALUE_THRESHOLD;
+    stat_cfg.data.rdi_errors.trigger.u.value_threshold.limit = -1;
+    bcmos_errno olt_cfg_set_res = BCM_ERR_INTERNAL;
+
+    ON_CALL(balMock, bcmolt_stat_cfg_set(_, _)).WillByDefault(Return(olt_cfg_set_res));
+
+    Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
+    ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}
diff --git a/protos/Makefile b/protos/Makefile
index 92b99d8..376ea8c 100644
--- a/protos/Makefile
+++ b/protos/Makefile
@@ -19,7 +19,7 @@
 # This specifies the GIT tag in https://github.com/opencord/voltha-protos
 # repo that we need to refer to, to pick the right version of
 # openolt.proto and tech_profile.proto
-OPENOLT_PROTO_VER ?= v3.3.5
+OPENOLT_PROTO_VER ?= v3.3.6
 GRPC_VER ?= v1.10.x
 
 CXX ?= g++