SEBA-242 generalize simulate_alarm to other adapters
Change-Id: I6addd28b0217b8a033c4c24df6a255967f8f3489
diff --git a/voltha/adapters/openolt/openolt_alarms.py b/voltha/adapters/openolt/openolt_alarms.py
index 6eb0702..efb9c1f 100644
--- a/voltha/adapters/openolt/openolt_alarms.py
+++ b/voltha/adapters/openolt/openolt_alarms.py
@@ -18,6 +18,7 @@
import voltha.adapters.openolt.openolt_platform as platform
# from voltha.protos.device_pb2 import Port
from voltha.extensions.alarms.adapter_alarms import AdapterAlarms
+from voltha.extensions.alarms.simulator.simulate_alarms import AdapterAlarmSimulator
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
@@ -31,8 +32,6 @@
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
-
import protos.openolt_pb2 as openolt_pb2
import voltha.protos.device_pb2 as device_pb2
@@ -60,6 +59,7 @@
self.alarm_suppress = {"olt_los_clear": 0, "onu_disc_raised": []} # Keep count of alarms to limit.
try:
self.alarms = AdapterAlarms(self.adapter_agent, self.device_id, self.logical_device_id)
+ self.simulator = AdapterAlarmSimulator(self.alarms)
except Exception as initerr:
self.log.exception("alarmhandler-init-error", errmsg=initerr.message)
raise Exception(initerr)
@@ -104,48 +104,7 @@
alarm=alarm_ind)
def simulate_alarm(self, alarm):
- if alarm.indicator == "los":
- alarm_obj = OltLosAlarm(self.alarms, intf_id=alarm.intf_id, port_type_name=alarm.port_type_name)
- elif alarm.indicator == "dying_gasp":
- alarm_obj = OnuDyingGaspAlarm(self.alarms, alarm.intf_id, alarm.onu_device_id)
- elif alarm.indicator == "onu_los":
- alarm_obj = OnuLosAlarm(self.alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
- elif alarm.indicator == "onu_lopc_miss":
- alarm_obj = OnuLopcMissAlarm(self.alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
- elif alarm.indicator == "onu_lopc_mic":
- alarm_obj = OnuLopcMicErrorAlarm(self.alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
- elif alarm.indicator == "onu_lob":
- alarm_obj = OnuLobAlarm(self.alarms, onu_id=alarm.onu_device_id, intf_id=alarm.intf_id)
- elif alarm.indicator == "onu_startup":
- alarm_obj = OnuStartupAlarm(self.alarms, intf_id=alarm.intf_id, onu_id=alarm.onu_device_id)
- elif alarm.indicator == "onu_signal_degrade":
- alarm_obj = OnuSignalDegradeAlarm(self.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.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.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.alarms, intf_id=alarm.intf_id,
- onu_id=alarm.onu_device_id)
- elif alarm.indicator == "onu_discovery":
- alarm_obj = OnuDiscoveryAlarm(self.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")
+ self.simulator.simulate_alarm(alarm)
def los_indication(self, los_ind):
diff --git a/voltha/extensions/alarms/simulator/README.md b/voltha/extensions/alarms/simulator/README.md
new file mode 100644
index 0000000..1333ed7
--- /dev/null
+++ b/voltha/extensions/alarms/simulator/README.md
@@ -0,0 +1 @@
+TODO
diff --git a/voltha/extensions/alarms/simulator/__init__.py b/voltha/extensions/alarms/simulator/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/voltha/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/voltha/extensions/alarms/simulator/simulate_alarms.py b/voltha/extensions/alarms/simulator/simulate_alarms.py
new file mode 100644
index 0000000..73e7b2e
--- /dev/null
+++ b/voltha/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, alarm.intf_id, alarm.onu_device_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")