Initial commit moving openolt adapter from voltha-go to the new repo.
This version works with ponsim rather than openolt, this is temporary.
It is currently being fixed to work with openolt.

Change-Id: I34a800c98f050140b367e2d474b7aa8b79f34b9a
Signed-off-by: William Kurkian <wkurkian@cisco.com>
diff --git a/python/adapters/extensions/alarms/README.md b/python/adapters/extensions/alarms/README.md
new file mode 100644
index 0000000..2ac971a
--- /dev/null
+++ b/python/adapters/extensions/alarms/README.md
@@ -0,0 +1,62 @@
+# VOLTHA Alarm Library
+
+This directory provides a common library for the creation of Alarms by adapters within VOLTHA
+and should be used to insure that published alarms from different adapters use the same format
+
+## Alarm Manager Creation
+
+Each device handler should create an instance of the **AdapterAlarms** alarm manager shortly after
+initial activation. This alarm manager is responsible for the formatting and sending of alarms
+by the adapters.
+
+## Raising and Clearing Alarms
+
+To create a specific alarm, create an instance of the specific alarm you wish to publish
+(such as **OnuDiscoveryAlarms** for newly discovered ONUs) and pass in alarm specific information
+to the initialize.
+
+Once constructed, you can call the alarm's **_raise_alarm()_** method to format and send an active
+alarm, or the **_clear_alarm()_** to clear it.
+
+# Basic Alarm Format
+
+Here is an JSON example of a current alarm published on the kafka bus under the 
+_voltha.alarms_ topic:
+
+```json
+{
+  "id": "voltha.adtran_olt.000198f9c4d2ae80.Discovery",
+  "description": "adtran_olt.000198f9c4d2ae80 - ONU DISCOVERY Alarm - DISCOVERY - Raised",
+  "logical_device_id": "0001112233445566",
+  "state": "RAISED",
+  "category": "PON",
+  "severity": "CRITICAL",
+  "resource_id": "0",
+  "type": "EQUIPMENT",
+  "reported_ts": 1532031872.0,
+  "raised_ts": 1532031872.0,
+  "changed_ts": 0.0,
+  "context": {
+    "serial-number": "ADTN17230031",
+    "pon-id": "0"
+  }
+}
+```
+
+# Remaining Work Items
+This initial code is only a prelimenary sample. The following tasks need to be
+added to the VOLTHA JIRA or performed in the SEBA group.
+
+- Get a list from SEBA/VOLTHA on required alarms 
+
+- Provide example JSON output and verify that it meets SEBA's requirements
+
+- Get feedback from other OLT/ONU developers on any needed changes
+
+- For the logical_device_id, this is reported in the format that the device adapter has which
+  includes the vcore number (often 0001) in the first four nibble.  Should this be normalized to
+  all zeros?
+
+- Support alarm_suppression capability (via IAdapter call). Needs investigation
+
+- TODO: Probably a few more.  Look through code for more 'TODO' Notes
diff --git a/python/adapters/extensions/alarms/__init__.py b/python/adapters/extensions/alarms/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/python/adapters/extensions/alarms/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017-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.
diff --git a/python/adapters/extensions/alarms/adapter_alarms.py b/python/adapters/extensions/alarms/adapter_alarms.py
new file mode 100644
index 0000000..b24113f
--- /dev/null
+++ b/python/adapters/extensions/alarms/adapter_alarms.py
@@ -0,0 +1,205 @@
+#
+# Copyright 2017 the original author or authors.
+#
+# 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.
+
+import structlog
+import arrow
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity,\
+    AlarmEventState, AlarmEventCategory
+log = structlog.get_logger()
+
+
+# TODO: In the device adapter, the following alarms are still TBD
+#       (Taken from openolt_alarms)
+# onu_alarm_ind
+# onu_startup_failure_indication
+# onu_signal_degrade_indication
+# onu_drift_of_window_ind
+# onu_loss_omci_ind
+# onu_signals_fail_ind
+# onu_tiwi_ind
+# onu_activation_fail_ind
+# onu_processing_error_ind
+
+
+class AdapterAlarms:
+    """
+    Class for managing Alarms within a given Device Handler instance
+    """
+    def __init__(self, adapter_agent, device_id, logical_device_id):
+        """
+        Adapter alarm manager initializer
+
+        :param adapter_agent: (AdapterAgent) Adapter agent reference
+        :param device_id: (str) Device handler's unique device id
+        :param logical_device_id: (str) Logical Device that the device is a member of
+        """
+        self.log = structlog.get_logger(device_id=device_id)
+        self.adapter_agent = adapter_agent
+        self.device_id = device_id
+        self.logical_device_id = logical_device_id
+        self.adapter_name = adapter_agent.adapter_name
+        self.lc = None
+
+    def format_id(self, alarm):
+        """
+        Format the Unique Alarm ID for this alarm.  This is provided in the alarms
+        'id' field
+
+        :param alarm: (str) The name of the alarm such as 'Discover' or 'LOS'
+
+        :return: (str) Alarm ID
+        """
+        return 'voltha.{}.{}.{}'.format(self.adapter_name,
+                                        self.device_id,
+                                        alarm)
+
+    def format_description(self, _object, alarm, status):
+        """
+        Format the textual description field of this alarm
+
+        :param _object: ()
+        :param alarm: (str) The name of the alarm such as 'Discover' or 'LOS'
+        :param status: (bool) If True, the alarm is active (it is being raised)
+
+        :return: (str) Alarm description
+        """
+        return '{} Alarm - {} - {}'.format(_object.upper(),
+                                           alarm.upper(),
+                                           'Raised' if status else 'Cleared')
+
+    def send_alarm(self, context_data, alarm_data):
+        """
+        Send the alarm to the event bus
+
+        :param context_data: (dict) Alarm specific context data
+        :param alarm_data: (dict) Common Alarm information dictionary
+        """
+        try:
+            current_context = {}
+            if isinstance(context_data, dict):
+                for key, value in context_data.iteritems():
+                    current_context[key] = str(value)
+            ser_num = None
+            device = self.adapter_agent.get_device(device_id=self.device_id)
+            ser_num = device.serial_number
+
+
+            """
+            Only put in the onu serial numbers since the OLT does not currently have a serial number and the
+            value is the ip:port address.
+            """
+            if isinstance(context_data, dict) and '_onu' in device.type.lower():
+                current_context["onu_serial_number"] = ser_num
+            alarm_event = self.adapter_agent.create_alarm(
+                id=alarm_data.get('id', 'voltha.{}.{}.olt'.format(self.adapter_name,
+                                                                  self.device_id)),
+                resource_id=str(alarm_data.get('resource_id', self.device_id)),
+                description="{}.{} - {}".format(self.adapter_name, self.device_id,
+                                                alarm_data.get('description')),
+                type=alarm_data.get('type'),
+                category=alarm_data.get('category'),
+                severity=alarm_data.get('severity'),
+                state=alarm_data.get('state'),
+                raised_ts=alarm_data.get('ts', 0),
+                context=current_context,
+                logical_device_id=self.logical_device_id,
+                alarm_type_name=alarm_data.get('alarm_type_name')
+            )
+            self.adapter_agent.submit_alarm(self.device_id, alarm_event)
+
+        except Exception as e:
+            self.log.exception('failed-to-send-alarm', e=e)
+            raise
+
+
+class AlarmBase(object):
+    """Base class for alarms"""
+    def __init__(self, alarm_mgr, object_type, alarm,
+                 alarm_category,
+                 resource_id=None,
+                 alarm_type=AlarmEventType.EQUIPMENT,
+                 alarm_severity=AlarmEventSeverity.CRITICAL):
+        """
+        Initializer for the Alarm base class
+
+        :param alarm_mgr: (AdapterAlarms) Reference to the device handler's Adapter
+                                          Alarm manager
+        :param object_type: (str) Type of device generating the alarm such as 'olt' or 'onu'
+        :param alarm: (str) A textual name for the alarm such as 'HeartBeat' or 'Discovery'
+        :param alarm_category: (AlarmEventCategory) Refers to functional category of
+                                                    the alarm
+        :param resource_id: (str) Identifier of the originating resource of the alarm
+        :param alarm_type: (AlarmEventType) Refers to the area of the system impacted
+                                            by the alarm
+        :param alarm_severity: (AlarmEventSeverity) Overall impact of the alarm on the
+                                                    system
+        """
+        self._alarm_mgr = alarm_mgr
+        self._object_type = object_type
+        self._alarm = alarm
+        self._alarm_category = alarm_category
+        self._alarm_type = alarm_type
+        self._alarm_severity = alarm_severity
+        self._resource_id = resource_id
+
+    def get_alarm_data(self, status):
+        """
+        Get the alarm specific data and format it into a dictionary.  When the alarm
+        is being sent to the event bus, this dictionary provides a majority of the
+        fields for the alarms.
+
+        :param status: (bool) True if the alarm is active/raised
+        :return: (dict) Alarm data
+        """
+        data = {
+            'ts': arrow.utcnow().timestamp,
+            'description': self._alarm_mgr.format_description(self._object_type,
+                                                              self._alarm,
+                                                              status),
+            'id': self._alarm_mgr.format_id(self._alarm),
+            'type': self._alarm_type,
+            'category': self._alarm_category,
+            'severity': self._alarm_severity,
+            'state': AlarmEventState.RAISED if status else AlarmEventState.CLEARED,
+            'alarm_type_name': self._alarm
+        }
+        if self._resource_id is not None:
+            data['resource_id'] = self._resource_id
+        return data
+
+    def get_context_data(self):
+        """
+        Get alarm specific context data. If an alarm has specific data to specify, it is
+        included in the context field in the published event
+
+        :return: (dict) Dictionary with alarm specific context data
+        """
+        return {}   # NOTE: You should override this if needed
+
+    def raise_alarm(self):
+        """
+        Called to set the state of an alarm to active and to send it to the event bus
+        """
+        alarm_data = self.get_alarm_data(True)
+        context_data = self.get_context_data()
+        self._alarm_mgr.send_alarm(context_data, alarm_data)
+
+    def clear_alarm(self):
+        """
+        Called to set the state of an alarm to inactive and to send it to the event bus
+        """
+        alarm_data = self.get_alarm_data(False)
+        context_data = self.get_context_data()
+        self._alarm_mgr.send_alarm(context_data, alarm_data)
diff --git a/python/adapters/extensions/alarms/heartbeat_alarm.py b/python/adapters/extensions/alarms/heartbeat_alarm.py
new file mode 100644
index 0000000..4f5f4f4
--- /dev/null
+++ b/python/adapters/extensions/alarms/heartbeat_alarm.py
@@ -0,0 +1,28 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from adapter_alarms import AlarmBase
+
+
+class HeartbeatAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, object_type='olt', heartbeat_misses=0):
+        super(HeartbeatAlarm, self).__init__(alarm_mgr, object_type,
+                                             alarm='Heartbeat',
+                                             alarm_category=AlarmEventCategory.PON,
+                                             alarm_type=AlarmEventType.EQUIPMENT,
+                                             alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._misses = heartbeat_misses
+
+    def get_context_data(self):
+        return {'heartbeats-missed': self._misses}
diff --git a/python/adapters/extensions/alarms/olt/__init__.py b/python/adapters/extensions/alarms/olt/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/python/adapters/extensions/alarms/olt/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017-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.
diff --git a/python/adapters/extensions/alarms/olt/olt_los_alarm.py b/python/adapters/extensions/alarms/olt/olt_los_alarm.py
new file mode 100644
index 0000000..c8666a3
--- /dev/null
+++ b/python/adapters/extensions/alarms/olt/olt_los_alarm.py
@@ -0,0 +1,32 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OltLosAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, intf_id, port_type_name):
+        super(OltLosAlarm, self).__init__(alarm_mgr, object_type='olt LOS',
+                                          alarm='OLT_LOS',
+                                          alarm_category=AlarmEventCategory.OLT,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        # Added port type to indicate if alarm was on NNI or PON
+        self._intf_id = intf_id
+        self._port_type_name = port_type_name
+
+    def get_context_data(self):
+        return {'olt-intf-id:': self._intf_id,
+                'olt-port-type-name': self._port_type_name}
diff --git a/python/adapters/extensions/alarms/onu/__init__.py b/python/adapters/extensions/alarms/onu/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017-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.
diff --git a/python/adapters/extensions/alarms/onu/onu_activation_fail_alarm.py b/python/adapters/extensions/alarms/onu/onu_activation_fail_alarm.py
new file mode 100644
index 0000000..2bf054e
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_activation_fail_alarm.py
@@ -0,0 +1,30 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuActivationFailAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuActivationFailAlarm, self).__init__(alarm_mgr, object_type='onu ACTIVATION FAIL',
+                                          alarm='ONU_ACTIVATION_FAIL',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_active_alarm.py b/python/adapters/extensions/alarms/onu/onu_active_alarm.py
new file mode 100644
index 0000000..a139875
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_active_alarm.py
@@ -0,0 +1,50 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+
+
+class OnuActiveAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, device_id, pon_id, onu_serial_number,
+                 reg_id, olt_serial_number, ipv4_address=None):
+        super(OnuActiveAlarm, self).__init__(alarm_mgr, object_type='ONU',
+                                             alarm='ONU_ACTIVATED',
+                                             alarm_category=AlarmEventCategory.PON,
+                                             resource_id=pon_id,
+                                             alarm_type=AlarmEventType.EQUIPMENT,
+                                             alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._pon_id = pon_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
+
+    def get_context_data(self):
+        data = {
+            'pon-id': self._pon_id,
+            'serial-number': self._onu_serial_number,
+            'olt_serial_number': self._olt_serial_number,
+            'device_id': self._device_id,
+            'registration_id': self._reg_id
+        }
+        if self._host is not None:
+            data['host'] = self._host
+
+        return data
+
+    def clear_alarm(self):
+        raise NotImplementedError('ONU Active Alarms are auto-clear')
+
diff --git a/python/adapters/extensions/alarms/onu/onu_discovery_alarm.py b/python/adapters/extensions/alarms/onu/onu_discovery_alarm.py
new file mode 100644
index 0000000..c7da2bc
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_discovery_alarm.py
@@ -0,0 +1,36 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuDiscoveryAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, pon_id, serial_number):
+        super(OnuDiscoveryAlarm, self).__init__(alarm_mgr, object_type='ONU Discovery',
+                                                alarm='ONU_DISCOVERY',
+                                                alarm_category=AlarmEventCategory.PON,
+                                                resource_id=pon_id,
+                                                alarm_type=AlarmEventType.EQUIPMENT,
+                                                alarm_severity=AlarmEventSeverity.MAJOR)
+        self._pon_id = pon_id
+        self._serial_number = serial_number
+
+    def get_context_data(self):
+        return {
+            'pon-id': self._pon_id,
+            'serial-number': self._serial_number
+        }
+
+    def clear_alarm(self):
+        raise NotImplementedError('ONU Discovery Alarms are auto-clear')
diff --git a/python/adapters/extensions/alarms/onu/onu_dying_gasp_alarm.py b/python/adapters/extensions/alarms/onu/onu_dying_gasp_alarm.py
new file mode 100644
index 0000000..52b6850
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_dying_gasp_alarm.py
@@ -0,0 +1,33 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuDyingGaspAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuDyingGaspAlarm, self).__init__(alarm_mgr, object_type='onu DYING_GASP',
+                                                alarm='ONU_DYING_GASP',
+                                                alarm_category=AlarmEventCategory.ONU,
+                                                alarm_type=AlarmEventType.COMMUNICATION,
+                                                alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {
+            'onu-id': self._onu_id,
+            'onu-intf-id': self._intf_id
+        }
diff --git a/python/adapters/extensions/alarms/onu/onu_equipment_alarm.py b/python/adapters/extensions/alarms/onu/onu_equipment_alarm.py
new file mode 100644
index 0000000..e7e3a7a
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_equipment_alarm.py
@@ -0,0 +1,45 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuEquipmentAlarm(AlarmBase):
+    """
+    The ONU Equipment Alarm is reported by both the CircuitPack (ME #6) and
+    the ONT-G (ME # 256) to indicate failure on an internal interface or
+    failed self-test.
+
+    For CircuitPack equipment alarms, the intf_id reported is that of the
+    UNI's logical port number
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+
+    Note: Some ONUs may use this alarm to report a self-test failure or may
+          may report it with a different alarm number specifically for a
+          self-test failure.
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuEquipmentAlarm, self).__init__(alarm_mgr, object_type='onu equipment',
+                                                alarm='ONU_EQUIPMENT',
+                                                alarm_category=AlarmEventCategory.ONU,
+                                                alarm_type=AlarmEventType.EQUIPTMENT,
+                                                alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_high_rx_optical_power_alarm.py b/python/adapters/extensions/alarms/onu/onu_high_rx_optical_power_alarm.py
new file mode 100644
index 0000000..7b59d55
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_high_rx_optical_power_alarm.py
@@ -0,0 +1,37 @@
+# Copyright 2018 the original author or authors.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuHighRxOpticalAlarm(AlarmBase):
+    """
+    The ONU High Tx Optical Power Alarm is reported by the ANI-G (ME # 263) to
+    indicate that the received downstream optical power above threshold..
+
+    For ANI-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuHighRxOpticalAlarm, self).__init__(alarm_mgr, object_type='onu high rx optical power',
+                                                    alarm='ONU_HIGH_RX_OPTICAL',
+                                                    alarm_category=AlarmEventCategory.ONU,
+                                                    alarm_type=AlarmEventType.COMMUNICATION,
+                                                    alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_high_tx_optical_power_alarm.py b/python/adapters/extensions/alarms/onu/onu_high_tx_optical_power_alarm.py
new file mode 100644
index 0000000..64caefe
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_high_tx_optical_power_alarm.py
@@ -0,0 +1,37 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuHighTxOpticalAlarm(AlarmBase):
+    """
+    The ONU High Tx Optical Power Alarm is reported by the ANI-G (ME # 263) to
+    indicate that the received downstream optical power above upper threshold.
+
+    For ANI-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuHighTxOpticalAlarm, self).__init__(alarm_mgr, object_type='onu high tx optical power',
+                                                    alarm='ONU_HIGH_TX_OPTICAL',
+                                                    alarm_category=AlarmEventCategory.ONU,
+                                                    alarm_type=AlarmEventType.COMMUNICATION,
+                                                    alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
\ No newline at end of file
diff --git a/python/adapters/extensions/alarms/onu/onu_laser_bias_current_alarm.py b/python/adapters/extensions/alarms/onu/onu_laser_bias_current_alarm.py
new file mode 100644
index 0000000..8daf5a6
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_laser_bias_current_alarm.py
@@ -0,0 +1,38 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLaserBiasAlarm(AlarmBase):
+    """
+    The ONU Laser Bias Current Alarm is reported by the ANI-G (ME # 263) to
+    indicate that the laser bias current above threshold determined by
+    vendor and that laser end of life is pending
+
+    For ANI-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLaserBiasAlarm, self).__init__(alarm_mgr, object_type='onu laser bias current',
+                                                alarm='ONU_LASER_BIAS_CURRENT',
+                                                alarm_category=AlarmEventCategory.ONU,
+                                                alarm_type=AlarmEventType.EQUIPTMENT,
+                                                alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_laser_eol_alarm.py b/python/adapters/extensions/alarms/onu/onu_laser_eol_alarm.py
new file mode 100644
index 0000000..fa5039c
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_laser_eol_alarm.py
@@ -0,0 +1,36 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLaserEolAlarm(AlarmBase):
+    """
+    The ONU Laser End-of-Lifer Alarm is reported by both the CircuitPack (ME #6)
+    to indicate that failure of transmit laser imminent
+
+    The intf_id reported is that of the UNI's logical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLaserEolAlarm, self).__init__(alarm_mgr, object_type='onu laser EOL',
+                                               alarm='ONU_LASER_EOL',
+                                               alarm_category=AlarmEventCategory.ONU,
+                                               alarm_type=AlarmEventType.EQUIPTMENT,
+                                               alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_lob_alarm.py b/python/adapters/extensions/alarms/onu/onu_lob_alarm.py
new file mode 100644
index 0000000..e595211
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_lob_alarm.py
@@ -0,0 +1,30 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLobAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLobAlarm, self).__init__(alarm_mgr, object_type='onu LOB',
+                                          alarm='ONU_LOB',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_lopc_mic_error_alarm.py b/python/adapters/extensions/alarms/onu/onu_lopc_mic_error_alarm.py
new file mode 100644
index 0000000..cc05cb0
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_lopc_mic_error_alarm.py
@@ -0,0 +1,33 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLopcMicErrorAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLopcMicErrorAlarm, self).__init__(alarm_mgr,  object_type='onu LOPC_MIC_ERROR',
+                                                   alarm='ONU_LOPC_MIC_ERROR',
+                                                   alarm_category=AlarmEventCategory.ONU,
+                                                   alarm_type=AlarmEventType.COMMUNICATION,
+                                                   alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {
+            'onu-id': self._onu_id,
+            'onu-intf-id': self._intf_id
+        }
diff --git a/python/adapters/extensions/alarms/onu/onu_lopc_miss_alarm.py b/python/adapters/extensions/alarms/onu/onu_lopc_miss_alarm.py
new file mode 100644
index 0000000..af695ca
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_lopc_miss_alarm.py
@@ -0,0 +1,33 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLopcMissAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLopcMissAlarm, self).__init__(alarm_mgr, object_type='onu LOPC_MISS',
+                                               alarm='ONU_LOPC_MISS',
+                                               alarm_category=AlarmEventCategory.ONU,
+                                               alarm_type=AlarmEventType.COMMUNICATION,
+                                               alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {
+            'onu-id': self._onu_id,
+            'onu-intf-id': self._intf_id
+        }
diff --git a/python/adapters/extensions/alarms/onu/onu_los_alarm.py b/python/adapters/extensions/alarms/onu/onu_los_alarm.py
new file mode 100644
index 0000000..d2ebb7f
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_los_alarm.py
@@ -0,0 +1,30 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLosAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLosAlarm, self).__init__(alarm_mgr, object_type='onu LOS',
+                                          alarm='ONU_LOS',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_low_rx_optical_power_alarm.py b/python/adapters/extensions/alarms/onu/onu_low_rx_optical_power_alarm.py
new file mode 100644
index 0000000..ee6f4d2
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_low_rx_optical_power_alarm.py
@@ -0,0 +1,37 @@
+# Copyright 2018 the original author or authors.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLowRxOpticalAlarm(AlarmBase):
+    """
+    The ONU Low Rx Optical Power Alarm is reported by the ANI-G (ME # 263) to
+    indicate that the received downstream optical power below threshold.
+
+    For ANI-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLowRxOpticalAlarm, self).__init__(alarm_mgr, object_type='onu low rx optical power',
+                                                   alarm='ONU_LOW_RX_OPTICAL',
+                                                   alarm_category=AlarmEventCategory.ONU,
+                                                   alarm_type=AlarmEventType.COMMUNICATION,
+                                                   alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_low_tx_optical_power_alarm.py b/python/adapters/extensions/alarms/onu/onu_low_tx_optical_power_alarm.py
new file mode 100644
index 0000000..e28a556
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_low_tx_optical_power_alarm.py
@@ -0,0 +1,37 @@
+# Copyright 2018 the original author or authors.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuLowTxOpticalAlarm(AlarmBase):
+    """
+    The ONU Low Tx Optical Power Alarm is reported by the ANI-G (ME # 263) to
+    indicate that the transmit optical power below lower threshold
+
+    For ANI-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuLowTxOpticalAlarm, self).__init__(alarm_mgr, object_type='onu low tx optical power',
+                                                   alarm='ONU_LOW_TX_OPTICAL',
+                                                   alarm_category=AlarmEventCategory.ONU,
+                                                   alarm_type=AlarmEventType.COMMUNICATION,
+                                                   alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_selftest_failure_alarm.py b/python/adapters/extensions/alarms/onu/onu_selftest_failure_alarm.py
new file mode 100644
index 0000000..c742762
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_selftest_failure_alarm.py
@@ -0,0 +1,44 @@
+# Copyright 2018 the original author or authors.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuSelfTestFailureAlarm(AlarmBase):
+    """
+    The ONU Self Test Failure Alarm is reported by both the CircuitPack (ME #6)
+    and the ONT-G (ME # 256) to indicate failure a failed autonomous self-test.
+
+    For CircuitPack equipment alarms, the intf_id reported is that of the
+    UNI's logical port number
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+
+    Note: Some ONUs may use this alarm to report a self-test failure or may
+          may report it with the ONU Equipment Alarm which can also cover a
+          self-test failure.
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuSelfTestFailureAlarm, self).__init__(alarm_mgr, object_type='onu self-test failure',
+                                                      alarm='ONU_SELF_TEST_FAIL',
+                                                      alarm_category=AlarmEventCategory.ONU,
+                                                      alarm_type=AlarmEventType.EQUIPTMENT,
+                                                      alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_signal_degrade_alarm.py b/python/adapters/extensions/alarms/onu/onu_signal_degrade_alarm.py
new file mode 100644
index 0000000..4861f75
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_signal_degrade_alarm.py
@@ -0,0 +1,33 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuSignalDegradeAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id,
+                 inverse_bit_error_rate):
+        super(OnuSignalDegradeAlarm, self).__init__(alarm_mgr, object_type='onu SIGNAL DEGRADE',
+                                          alarm='ONU_SIGNAL_DEGRADE',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+        self._inverse_bit_error_rate=inverse_bit_error_rate
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id,
+                'inverse-bit-error-rate': self._inverse_bit_error_rate}
diff --git a/python/adapters/extensions/alarms/onu/onu_signal_fail_alarm.py b/python/adapters/extensions/alarms/onu/onu_signal_fail_alarm.py
new file mode 100644
index 0000000..bcc629a
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_signal_fail_alarm.py
@@ -0,0 +1,39 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+"""
+    OnuSignalsFailureIndication {
+                fixed32 intf_id = 1;
+                fixed32 onu_id = 2;
+                string status = 3;
+                fixed32 inverse_bit_error_rate = 4;
+"""
+
+class OnuSignalFailAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, onu_id, intf_id, inverse_bit_error_rate):
+        super(OnuSignalFailAlarm, self).__init__(alarm_mgr, object_type='onu SIGNAL FAIL',
+                                          alarm='ONU_SIGNAL_FAIL',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+        self._inverse_bit_error_rate = inverse_bit_error_rate
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id,
+                'inverse-bit-error-rate': self._inverse_bit_error_rate}
diff --git a/python/adapters/extensions/alarms/onu/onu_startup_alarm.py b/python/adapters/extensions/alarms/onu/onu_startup_alarm.py
new file mode 100644
index 0000000..9960f03
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_startup_alarm.py
@@ -0,0 +1,39 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+"""
+    message OnuStartupFailureIndication {
+    fixed32 intf_id = 1;
+    fixed32 onu_id = 2;
+    string status = 3;
+}
+
+"""
+
+class OnuStartupAlarm(AlarmBase):
+
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuStartupAlarm, self).__init__(alarm_mgr, object_type='onu STARTUP FAIL',
+                                          alarm='ONU_STARTUP_FAIL',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_temp_red_alarm.py b/python/adapters/extensions/alarms/onu/onu_temp_red_alarm.py
new file mode 100644
index 0000000..bfa1623
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_temp_red_alarm.py
@@ -0,0 +1,42 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuTempRedAlarm(AlarmBase):
+    """
+    The ONU Temperature Yellow Alarm is reported by both the CircuitPack
+    (ME #6) and the ONT-G (ME # 256) to indicate no service has been shut
+    down to avoid equipment damage. The operational state of the affected
+    PPTPs indicates the affected services.
+
+    For CircuitPack equipment alarms, the intf_id reported is that of the
+    UNI's logical port number
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuTempRedAlarm, self).__init__(alarm_mgr, object_type='onu temperature red',
+                                              alarm='ONU_TEMP_RED',
+                                              alarm_category=AlarmEventCategory.ONU,
+                                              alarm_type=AlarmEventType.ENVIRONMENT,
+                                              alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_temp_yellow_alarm.py b/python/adapters/extensions/alarms/onu/onu_temp_yellow_alarm.py
new file mode 100644
index 0000000..7a28f81
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_temp_yellow_alarm.py
@@ -0,0 +1,41 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuTempYellowAlarm(AlarmBase):
+    """
+    The ONU Temperature Yellow Alarm is reported by both the CircuitPack
+    (ME #6) and the ONT-G (ME # 256) to indicate no service shutdown at
+    present, but the circuit pack is operating beyond its recommended range.
+
+    For CircuitPack equipment alarms, the intf_id reported is that of the
+    UNI's logical port number
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuTempYellowAlarm, self).__init__(alarm_mgr, object_type='onu temperature yellow',
+                                                 alarm='ONU_TEMP_YELLOW',
+                                                 alarm_category=AlarmEventCategory.ONU,
+                                                 alarm_type=AlarmEventType.ENVIRONMENT,
+                                                 alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_voltage_red_alarm.py b/python/adapters/extensions/alarms/onu/onu_voltage_red_alarm.py
new file mode 100644
index 0000000..506351c
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_voltage_red_alarm.py
@@ -0,0 +1,39 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuVoltageRedAlarm(AlarmBase):
+    """
+    The ONU Voltage Red Alarm is reported by the ONT-G (ME # 256) to
+    indicate some services have been shut down to avoid power collapse.
+    The operational state of the affected PPTPs indicates the affected
+    services.
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuVoltageRedAlarm, self).__init__(alarm_mgr, object_type='onu voltage red',
+                                                 alarm='ONU_VOLTAGE_RED',
+                                                 alarm_category=AlarmEventCategory.ONU,
+                                                 alarm_type=AlarmEventType.COMMUNICATION,
+                                                 alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_voltage_yellow_alarm.py b/python/adapters/extensions/alarms/onu/onu_voltage_yellow_alarm.py
new file mode 100644
index 0000000..1bb3ef6
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_voltage_yellow_alarm.py
@@ -0,0 +1,39 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuVoltageYellowAlarm(AlarmBase):
+    """
+    The ONU Voltage Red Alarm is reported by the ONT-G (ME # 256) to
+    indicate some services have been shut down to avoid power collapse.
+    The operational state of the affected PPTPs indicates the affected
+    services.
+
+    For ONT-G equipment alarms, the intf_id reported is that of the PON/ANI
+    physical port number
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id):
+        super(OnuVoltageYellowAlarm, self).__init__(alarm_mgr, object_type='onu voltage yellow',
+                                                    alarm='ONU_VOLTAGE_YELLOW',
+                                                    alarm_category=AlarmEventCategory.ONU,
+                                                    alarm_type=AlarmEventType.COMMUNICATION,
+                                                    alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id}
diff --git a/python/adapters/extensions/alarms/onu/onu_window_drift_alarm.py b/python/adapters/extensions/alarms/onu/onu_window_drift_alarm.py
new file mode 100644
index 0000000..32d677d
--- /dev/null
+++ b/python/adapters/extensions/alarms/onu/onu_window_drift_alarm.py
@@ -0,0 +1,43 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OnuWindowDriftAlarm(AlarmBase):
+    """
+    OnuDriftOfWindowIndication {
+            fixed32 intf_id = 1;
+            fixed32 onu_id = 2;
+            string status = 3;
+            fixed32 drift = 4;
+            fixed32 new_eqd = 5;
+        }
+    """
+    def __init__(self, alarm_mgr, onu_id, intf_id, drift, new_eqd):
+        super(OnuWindowDriftAlarm, self).__init__(alarm_mgr, object_type='onu WINDOW DRIFT',
+                                          alarm='ONU_WINDOW_DRIFT',
+                                          alarm_category=AlarmEventCategory.ONU,
+                                          alarm_type=AlarmEventType.COMMUNICATION,
+                                          alarm_severity=AlarmEventSeverity.MAJOR)
+        self._onu_id = onu_id
+        self._intf_id = intf_id
+        self._drift = drift
+        self._new_eqd = new_eqd
+
+    def get_context_data(self):
+        return {'onu-id': self._onu_id,
+                'onu-intf-id': self._intf_id,
+                'drift': self._drift,
+                'new-eqd': self._new_eqd}
diff --git a/python/adapters/extensions/alarms/simulator/README.md b/python/adapters/extensions/alarms/simulator/README.md
new file mode 100644
index 0000000..1333ed7
--- /dev/null
+++ b/python/adapters/extensions/alarms/simulator/README.md
@@ -0,0 +1 @@
+TODO
diff --git a/python/adapters/extensions/alarms/simulator/__init__.py b/python/adapters/extensions/alarms/simulator/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/python/adapters/extensions/alarms/simulator/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017-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.
diff --git a/python/adapters/extensions/alarms/simulator/simulate_alarms.py b/python/adapters/extensions/alarms/simulator/simulate_alarms.py
new file mode 100644
index 0000000..4dfee37
--- /dev/null
+++ b/python/adapters/extensions/alarms/simulator/simulate_alarms.py
@@ -0,0 +1,77 @@
+#
+# Copyright 2017 the original author or authors.
+#
+# 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.
+
+from voltha.extensions.alarms.olt.olt_los_alarm import OltLosAlarm
+from voltha.extensions.alarms.onu.onu_dying_gasp_alarm import OnuDyingGaspAlarm
+from voltha.extensions.alarms.onu.onu_los_alarm import OnuLosAlarm
+from voltha.extensions.alarms.onu.onu_lopc_miss_alarm import OnuLopcMissAlarm
+from voltha.extensions.alarms.onu.onu_lopc_mic_error_alarm import OnuLopcMicErrorAlarm
+from voltha.extensions.alarms.onu.onu_lob_alarm import OnuLobAlarm
+
+from voltha.extensions.alarms.onu.onu_startup_alarm import OnuStartupAlarm
+from voltha.extensions.alarms.onu.onu_signal_degrade_alarm import OnuSignalDegradeAlarm
+from voltha.extensions.alarms.onu.onu_signal_fail_alarm import OnuSignalFailAlarm
+from voltha.extensions.alarms.onu.onu_window_drift_alarm import OnuWindowDriftAlarm
+from voltha.extensions.alarms.onu.onu_activation_fail_alarm import OnuActivationFailAlarm
+
+from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm
+
+class AdapterAlarmSimulator(object):
+    def __init__(self, adapter_alarms):
+        self.adapter_alarms = adapter_alarms
+
+    def simulate_alarm(self, alarm):
+        if alarm.indicator == "los":
+            alarm_obj = OltLosAlarm(self.adapter_alarms, intf_id=alarm.intf_id, port_type_name=alarm.port_type_name)
+        elif alarm.indicator == "dying_gasp":
+            alarm_obj = OnuDyingGaspAlarm(self.adapter_alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
+        elif alarm.indicator == "onu_los":
+            alarm_obj = OnuLosAlarm(self.adapter_alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
+        elif alarm.indicator == "onu_lopc_miss":
+            alarm_obj = OnuLopcMissAlarm(self.adapter_alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
+        elif alarm.indicator == "onu_lopc_mic":
+            alarm_obj = OnuLopcMicErrorAlarm(self.adapter_alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
+        elif alarm.indicator == "onu_lob":
+            alarm_obj = OnuLobAlarm(self.adapter_alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
+        elif alarm.indicator == "onu_startup":
+            alarm_obj = OnuStartupAlarm(self.adapter_alarms, intf_id=alarm.intf_id, onu_id=alarm.onu_device_id)
+        elif alarm.indicator == "onu_signal_degrade":
+            alarm_obj = OnuSignalDegradeAlarm(self.adapter_alarms, intf_id=alarm.intf_id, onu_id=alarm.onu_device_id,
+                                  inverse_bit_error_rate=alarm.inverse_bit_error_rate)
+        elif alarm.indicator == "onu_drift_of_window":
+            alarm_obj = OnuWindowDriftAlarm(self.adapter_alarms, intf_id=alarm.intf_id,
+                                onu_id=alarm.onu_device_id,
+                                drift=alarm.drift,
+                                new_eqd=alarm.new_eqd)
+        elif alarm.indicator == "onu_signal_fail":
+            alarm_obj = OnuSignalFailAlarm(self.adapter_alarms, intf_id=alarm.intf_id,
+                               onu_id=alarm.onu_device_id,
+                               inverse_bit_error_rate=alarm.inverse_bit_error_rate)
+        elif alarm.indicator == "onu_activation":
+            alarm_obj = OnuActivationFailAlarm(self.adapter_alarms, intf_id=alarm.intf_id,
+                                   onu_id=alarm.onu_device_id)
+        elif alarm.indicator == "onu_discovery":
+            alarm_obj = OnuDiscoveryAlarm(self.adapter_alarms, pon_id=alarm.intf_id,
+                                   serial_number=alarm.onu_serial_number)
+        else:
+            raise Exception("Unknown alarm indicator %s" % alarm.indicator)
+
+        if alarm.operation == alarm.RAISE:
+            alarm_obj.raise_alarm()
+        elif alarm.operation == alarm.CLEAR:
+            alarm_obj.clear_alarm()
+        else:
+            # This shouldn't happen
+            raise Exception("Unknown alarm operation")