VOL-1042, VOL-773 No 0 SN, LOS and DG indications

Change-Id: I0f32093df95dc572659e5bb6298d69c8589e91bf
diff --git a/protos/openolt.proto b/protos/openolt.proto
index 3e72181..d5a83f2 100644
--- a/protos/openolt.proto
+++ b/protos/openolt.proto
@@ -75,6 +75,14 @@
         PacketIndication pkt_ind = 7;
         PortStatistics port_stats = 8;
         FlowStatistics flow_stats = 9;
+        AlarmIndication alarm_ind= 10;
+    }
+}
+
+message AlarmIndication {
+    oneof data {
+        LosIndication los_ind = 1;
+        DyingGaspIndication dying_gasp_ind = 2;
     }
 }
 
@@ -224,4 +232,15 @@
     fixed32 timestamp = 16;
 }
 
+message LosIndication {
+    fixed32 intf_id = 1;
+    string status = 2;
+}
+
+message DyingGaspIndication {
+    fixed32 intf_id = 1;
+    fixed32 onu_id = 2;
+    string status = 3;
+}
+
 message Empty {}
diff --git a/src/indications.cc b/src/indications.cc
index 3f49fcb..cbde803 100644
--- a/src/indications.cc
+++ b/src/indications.cc
@@ -18,6 +18,8 @@
 #include "core.h"
 #include "utils.h"
 #include "stats_collection.h"
+#include "translation.h"
+#include <string>
 extern "C"
 {
 #include <bcmos_system.h>
@@ -79,7 +81,22 @@
 
 bcmos_errno LosIndication(bcmbal_obj *obj) {
     openolt::Indication ind;
-    std::cout << "LOS indication " << std::endl;
+    openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
+    openolt::LosIndication* los_ind = new openolt::LosIndication;
+
+    bcmbal_interface_los* bcm_los_ind = (bcmbal_interface_los *) obj;
+    int intf_id = interface_key_to_port_no(bcm_los_ind->key);
+    std::string status = alarm_status_to_string(bcm_los_ind->data.status);
+
+    std::cout << "LOS indication : " << intf_id << "  " << status << std::endl;
+
+    los_ind->set_intf_id(intf_id);
+    los_ind->set_status(status);
+
+    alarm_ind->set_allocated_los_ind(los_ind);
+    ind.set_allocated_alarm_ind(alarm_ind);
+
+    oltIndQ.push(ind);
     return BCM_ERR_OK;
 }
 
@@ -143,8 +160,8 @@
 
 bcmos_errno OnuDyingGaspIndication(bcmbal_obj *obj) {
     openolt::Indication ind;
-    openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
-    openolt::SerialNumber* serial_number = new openolt::SerialNumber;
+    openolt::AlarmIndication* alarm_ind = new openolt::AlarmIndication;
+    openolt::DyingGaspIndication* dg_ind = new openolt::DyingGaspIndication;
 
     bcmbal_subscriber_terminal_key *key =
         &(((bcmbal_subscriber_terminal_dgi*)obj)->key);
@@ -160,21 +177,12 @@
          << ", alarm: "
          << data->dgi_status << std::endl;
 
-    onu_ind->set_intf_id(key->intf_id);
-    onu_ind->set_onu_id(key->sub_term_id);
-    const char* zeros4 = "0000";
-    const char* zeros8 = "00000000";
-    serial_number->set_vendor_id(zeros4);
-    serial_number->set_vendor_specific(zeros8);
-    onu_ind->set_allocated_serial_number(serial_number);
-    //ONU is dying, set operating state to down
-    onu_ind->set_oper_state("down");
-    //TODO: set admin state to unknow ? For now assume that it is up otherwise
-    //we would not have received the alarm
-    onu_ind->set_admin_state("up");
+    dg_ind->set_intf_id(key->intf_id);
+    dg_ind->set_onu_id(key->sub_term_id);
+    dg_ind->set_status(alarm_status_to_string(data->dgi_status));
 
-
-    ind.set_allocated_onu_ind(onu_ind);
+    alarm_ind->set_allocated_dying_gasp_ind(dg_ind);
+    ind.set_allocated_alarm_ind(alarm_ind);
 
     oltIndQ.push(ind);
     return BCM_ERR_OK;
@@ -247,7 +255,6 @@
 bcmos_errno OnuOperIndication(bcmbal_obj *obj) {
     openolt::Indication ind;
     openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
-    openolt::SerialNumber* serial_number = new openolt::SerialNumber;
 
     bcmbal_subscriber_terminal_key *key =
         &(((bcmbal_subscriber_terminal_oper_status_change*)obj)->key);
@@ -267,11 +274,6 @@
 
     onu_ind->set_intf_id(key->intf_id);
     onu_ind->set_onu_id(key->sub_term_id);
-    const char* zeros4 = "0000";
-    const char* zeros8 = "00000000";
-    serial_number->set_vendor_id(zeros4);
-    serial_number->set_vendor_specific(zeros8);
-    onu_ind->set_allocated_serial_number(serial_number);
     if (data->new_oper_status == BCMBAL_STATE_UP) {
         onu_ind->set_oper_state("up");
     } else {
diff --git a/src/translation.cc b/src/translation.cc
new file mode 100644
index 0000000..55daa4c
--- /dev/null
+++ b/src/translation.cc
@@ -0,0 +1,23 @@
+#include "translation.h"
+
+int interface_key_to_port_no(bcmbal_interface_key key) {
+    if (key.intf_type == BCMBAL_INTF_TYPE_NNI) {
+        return 128 + key.intf_id;
+    }
+    if (key.intf_type == BCMBAL_INTF_TYPE_PON) {
+        return (0x2 << 28) + 1;
+    }
+    return key.intf_id;
+}
+
+std::string alarm_status_to_string(bcmbal_alarm_status status) {
+    switch (status) {
+        case BCMBAL_ALARM_STATUS_OFF:
+            return "off";
+        case BCMBAL_ALARM_STATUS_ON:
+            return "on";
+        case BCMBAL_ALARM_STATUS_NO__CHANGE:
+            return "no_change";
+    }
+    return "unknown";
+}
diff --git a/src/translation.h b/src/translation.h
new file mode 100644
index 0000000..ffd476d
--- /dev/null
+++ b/src/translation.h
@@ -0,0 +1,15 @@
+#ifndef OPENOLT_TRANSLATION_H_
+#define OPENOLT_TRANSLATION_H_
+
+#include <string>
+extern "C"
+{
+#include <bal_model_types.h>
+}
+
+int interface_key_to_port_no(bcmbal_interface_key key);
+std::string alarm_status_to_string(bcmbal_alarm_status status);
+
+
+
+#endif