VOL-1581: Add support for reporting registration id in onu activation alarm

Change-Id: Ib593efdd285f75f1f7b65080ad07cf7d5c6330be
diff --git a/voltha/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py b/voltha/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
index 9d1ba65..565bb30 100644
--- a/voltha/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
+++ b/voltha/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
@@ -28,6 +28,7 @@
 from twisted.internet.defer import DeferredQueue, inlineCallbacks, returnValue, TimeoutError
 
 from heartbeat import HeartBeat
+from voltha.extensions.alarms.onu.onu_active_alarm import OnuActiveAlarm
 from voltha.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics
 from voltha.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
 from voltha.extensions.alarms.adapter_alarms import AdapterAlarms
@@ -1360,6 +1361,9 @@
                     self._mib_download_done.extend(self._get_uni_ids(device))
                     self._execute_queued_tp_task()
 
+                    # raise onu activated alarm
+                    self.onu_active_alarm()
+
                 def failure(_reason):
                     self.log.warn('mib-download-failure-retrying', _reason=_reason)
                     device.reason = 'initial-mib-download-failure-retrying'
@@ -1435,3 +1439,43 @@
 
         self.adapter_agent.add_port_reference_to_parent(self.device_id,
                                                         pon_port)
+
+    def onu_active_alarm(self):
+        self.log.debug('function-entry')
+        try:
+            device = self.adapter_agent.get_device(self.device_id)
+            parent_device = self.adapter_agent.get_device(self.parent_id)
+            olt_serial_number = parent_device.serial_number
+            datapath_id = self.get_datapath_id()
+        except Exception as e:
+            self.log.exception("error-handling-onu-active-alarm", e=e)
+            return
+
+        self.log.debug("onu-indication-context-data",
+                       pon_id=self._onu_indication.intf_id,
+                       registration_id=self._onu_indication.registration_id,
+                       device_id=self.device_id,
+                       onu_serial_number=device.serial_number,
+                       olt_serial_number=olt_serial_number)
+        try:
+            OnuActiveAlarm(self.alarms, self.device_id,
+                           self._onu_indication.intf_id,
+                           device.serial_number,
+                           self._onu_indication.registration_id,
+                           olt_serial_number,onu_id=self._onu_indication.onu_id,
+                           datapath_id=datapath_id).raise_alarm()
+        except Exception as active_alarm_error:
+            self.log.exception('onu-activated-alarm-error',
+                               errmsg=active_alarm_error.message)
+
+    def get_datapath_id(self):
+        datapath_hex_id = None
+        try:
+            logical_device = self.adapter_agent.get_logical_device(
+                self.logical_device_id)
+            datapath_hex_id = format(logical_device.datapath_id, '016x')
+            self.log.debug("datapath-hex-id", datapath_hex_id=datapath_hex_id)
+        except Exception as e:
+            self.log.exception('datapath-id-error:', e=e)
+        return datapath_hex_id
+
diff --git a/voltha/adapters/openolt/openolt_data_model.py b/voltha/adapters/openolt/openolt_data_model.py
index 9bc8d3d..dda5b32 100644
--- a/voltha/adapters/openolt/openolt_data_model.py
+++ b/voltha/adapters/openolt/openolt_data_model.py
@@ -274,12 +274,10 @@
         onu_adapter_agent.update_interface(onu_device,
                                            {'oper_state': 'down'})
 
-    def onu_oper_up(self, intf_id, onu_id):
+    def onu_oper_up(self, onu_indication):
 
-        class _OnuIndication:
-            def __init__(self, intf_id, onu_id):
-                self.intf_id = intf_id
-                self.onu_id = onu_id
+        intf_id = onu_indication.intf_id
+        onu_id = onu_indication.onu_id
 
         onu_device = self.adapter_agent.get_child_device(
             self.device.id,
@@ -310,7 +308,7 @@
             return
 
         onu_adapter_agent.create_interface(onu_device,
-                                           _OnuIndication(intf_id, onu_id))
+                                           onu_indication)
 
     def onu_download_tech_profile(self, intf_id, onu_id, uni_id, tp_path):
         onu_device = self.adapter_agent.get_child_device(
diff --git a/voltha/adapters/openolt/protos/openolt.proto b/voltha/adapters/openolt/protos/openolt.proto
index 7e52f02..cdd7ab7 100644
--- a/voltha/adapters/openolt/protos/openolt.proto
+++ b/voltha/adapters/openolt/protos/openolt.proto
@@ -227,6 +227,7 @@
     string oper_state = 3;      // up, down
     string admin_state = 5;     // up, down
     SerialNumber serial_number = 4;
+    bytes registration_id = 6;
 }
 
 message IntfOperIndication {
diff --git a/voltha/extensions/alarms/onu/onu_active_alarm.py b/voltha/extensions/alarms/onu/onu_active_alarm.py
index a139875..134f6ab 100644
--- a/voltha/extensions/alarms/onu/onu_active_alarm.py
+++ b/voltha/extensions/alarms/onu/onu_active_alarm.py
@@ -18,7 +18,7 @@
 
 class OnuActiveAlarm(AlarmBase):
     def __init__(self, alarm_mgr, device_id, pon_id, onu_serial_number,
-                 reg_id, olt_serial_number, ipv4_address=None):
+                 reg_id, olt_serial_number, ipv4_address=None, onu_id=None, datapath_id=None):
         super(OnuActiveAlarm, self).__init__(alarm_mgr, object_type='ONU',
                                              alarm='ONU_ACTIVATED',
                                              alarm_category=AlarmEventCategory.PON,
@@ -26,19 +26,23 @@
                                              alarm_type=AlarmEventType.EQUIPMENT,
                                              alarm_severity=AlarmEventSeverity.CRITICAL)
         self._pon_id = pon_id
+        self._onu_id = onu_id
         self._onu_serial_number = onu_serial_number
         self._device_id = device_id
         self._olt_serial_number = olt_serial_number
         self._host = ipv4_address
         self._reg_id = reg_id
+        self._datapath_id = datapath_id
 
     def get_context_data(self):
         data = {
-            'pon-id': self._pon_id,
-            'serial-number': self._onu_serial_number,
+            'pon_id': self._pon_id,
+            'onu_id': self._onu_id,
+            'serial_number': self._onu_serial_number,
             'olt_serial_number': self._olt_serial_number,
             'device_id': self._device_id,
-            'registration_id': self._reg_id
+            'registration_id': self._reg_id,
+            'datapath_id': self._datapath_id
         }
         if self._host is not None:
             data['host'] = self._host