Openolt data model changes (4th batch)
- remove unused openolt_bw.py
- add device_alarms.py that defines DeviceAlarms which
is a replacement for AdapterAlarms (minus adapter_agent).
AdapterAlarms is used by brcm_openomci_onu adapter
so cannot be removed/changed.
- pep8 fixes to openolt_alarms.py
- remove adapter_agent from openolt_alarms.py
- add new interfaces to data_model
Change-Id: Id84eb71965df5c775f8095a385b136cc26e5b5b5
diff --git a/voltha/adapters/openolt/openolt.py b/voltha/adapters/openolt/openolt.py
index 196fb97..51462ad 100644
--- a/voltha/adapters/openolt/openolt.py
+++ b/voltha/adapters/openolt/openolt.py
@@ -32,7 +32,6 @@
from voltha.adapters.openolt.openolt_flow_mgr import OpenOltFlowMgr
from voltha.adapters.openolt.openolt_alarms import OpenOltAlarmMgr
from voltha.adapters.openolt.openolt_statistics import OpenOltStatisticsMgr
-from voltha.adapters.openolt.openolt_bw import OpenOltBW
from voltha.adapters.openolt.openolt_platform import OpenOltPlatform
from voltha.adapters.openolt.openolt_resource_manager import OpenOltResourceMgr
from voltha.adapters.openolt.openolt_data_model import OpenOltDataModel
@@ -49,7 +48,6 @@
'flow_mgr': OpenOltFlowMgr,
'alarm_mgr': OpenOltAlarmMgr,
'stats_mgr': OpenOltStatisticsMgr,
- 'bw_mgr': OpenOltBW
}
}
diff --git a/voltha/adapters/openolt/openolt_alarms.py b/voltha/adapters/openolt/openolt_alarms.py
index 764a013..e55d003 100644
--- a/voltha/adapters/openolt/openolt_alarms.py
+++ b/voltha/adapters/openolt/openolt_alarms.py
@@ -14,59 +14,54 @@
# limitations under the License.
#
-import arrow
-from voltha.extensions.alarms.adapter_alarms import AdapterAlarms
-from voltha.extensions.alarms.simulator.simulate_alarms import AdapterAlarmSimulator
+from voltha.extensions.alarms.device_alarms import DeviceAlarms
+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
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_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
-
-import protos.openolt_pb2 as openolt_pb2
-import voltha.protos.device_pb2 as device_pb2
+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
class OpenOltAlarmMgr(object):
- def __init__(self, log, adapter_agent, device_id, logical_device_id,
- platform):
- """
- 20180711 - Addition of adapter_agent and device_id
- to facilitate alarm processing and kafka posting
- :param log:
- :param adapter_agent:
- :param device_id:
- """
+ def __init__(self, log, platform, data_model):
self.log = log
- self.adapter_agent = adapter_agent
- self.device_id = device_id
- self.logical_device_id = logical_device_id
self.platform = platform
+ self.data_model = data_model
"""
- The following is added to reduce the continual posting of OLT LOS alarming
- to Kafka. Set enable_alarm_suppress = true to enable otherwise the
- current openolt bal will send continuous olt los alarm cleared messages
- ONU disc raised counter is place holder for a future addition
+ The following is added to reduce the continual posting of OLT LOS
+ alarming to Kafka. Set enable_alarm_suppress = true to enable
+ otherwise the current openolt bal will send continuous olt los alarm
+ cleared messages ONU disc raised counter is place holder for a future
+ addition
"""
self.enable_alarm_suppress = True
- self.alarm_suppress = {"olt_los_clear": 0, "onu_disc_raised": []} # Keep count of alarms to limit.
+ # Keep count of alarms to limit.
+ self.alarm_suppress = {"olt_los_clear": 0, "onu_disc_raised": []}
try:
- self.alarms = AdapterAlarms(self.adapter_agent, self.device_id, self.logical_device_id)
+ self.alarms = DeviceAlarms(self.data_model)
self.simulator = AdapterAlarmSimulator(self.alarms)
except Exception as initerr:
- self.log.exception("alarmhandler-init-error", errmsg=initerr.message)
+ self.log.exception("alarmhandler-init-error",
+ errmsg=initerr.message)
raise Exception(initerr)
def process_alarms(self, alarm_ind):
try:
- self.log.debug('alarm-indication', alarm=alarm_ind, device_id=self.device_id)
+ self.log.debug('alarm-indication', alarm=alarm_ind)
if alarm_ind.HasField('los_ind'):
self.los_indication(alarm_ind.los_ind)
elif alarm_ind.HasField('dying_gasp_ind'):
@@ -112,17 +107,23 @@
self.log.debug('los indication received', los_ind=los_ind,
int_id=los_ind.intf_id, status=los_ind.status)
try:
- port_type_name = self.platform.intf_id_to_port_type_name(los_ind.intf_id)
+ port_type_name \
+ = self.platform.intf_id_to_port_type_name(los_ind.intf_id)
if los_ind.status == 1 or los_ind.status == "on":
# Zero out the suppression counter on OLT_LOS raise
self.alarm_suppress['olt_los_clear'] = 0
- OltLosAlarm(self.alarms, intf_id=los_ind.intf_id, port_type_name=port_type_name).raise_alarm()
+ OltLosAlarm(self.alarms, intf_id=los_ind.intf_id,
+ port_type_name=port_type_name).raise_alarm()
else:
"""
- Check if there has been more that one los clear following a previous los
+ Check if there has been more that one los clear
+ following a previous los
"""
- if self.alarm_suppress['olt_los_clear'] == 0 and self.enable_alarm_suppress:
- OltLosAlarm(self.alarms, intf_id=los_ind.intf_id, port_type_name=port_type_name).clear_alarm()
+ if (self.alarm_suppress['olt_los_clear'] == 0
+ and self.enable_alarm_suppress):
+ OltLosAlarm(
+ self.alarms, intf_id=los_ind.intf_id,
+ port_type_name=port_type_name).clear_alarm()
self.alarm_suppress['olt_los_clear'] += 1
except Exception as alarm_err:
@@ -134,28 +135,25 @@
try:
alarm_dgi = dying_gasp_ind
onu_id = alarm_dgi.onu_id
- self.log.debug('openolt-alarmindication-dispatch-dying-gasp', int_id=alarm_dgi.intf_id,
- onu_id=alarm_dgi.onu_id, status=alarm_dgi.status)
+ self.log.debug('openolt-alarmindication-dispatch-dying-gasp',
+ int_id=alarm_dgi.intf_id,
+ onu_id=onu_id, status=alarm_dgi.status)
try:
"""
- Get the specific onu device information for the onu generating the alarm.
- Extract the id. In the future extract the serial number as well
+ Get the specific onu device information for the onu generating
+ the alarm. Extract the id. In the future extract the serial
+ number as well
"""
- onu_device_id = "unresolved"
- onu_serial_number = "unresolved"
- onu_device = self.resolve_onu_id(onu_id, port_intf_id=alarm_dgi.intf_id)
- if onu_device != None:
- onu_device_id = onu_device.id
- onu_serial_number = onu_device.serial_number
-
+ # FIXME - Include ONU serial number in alarm
if dying_gasp_ind.status == 1 or dying_gasp_ind.status == "on":
OnuDyingGaspAlarm(self.alarms, dying_gasp_ind.intf_id,
- onu_device_id).raise_alarm()
+ onu_id).raise_alarm()
else:
OnuDyingGaspAlarm(self.alarms, dying_gasp_ind.intf_id,
- onu_device_id).clear_alarm()
+ onu_id).clear_alarm()
except Exception as alarm_err:
- self.log.exception('dying-gasp-indication', errmsg=alarm_err.message)
+ self.log.exception('dying-gasp-indication',
+ errmsg=alarm_err.message)
except Exception as e:
self.log.error('dying_gasp_indication', error=e)
@@ -176,55 +174,74 @@
self.log.info('onu-alarm-indication')
try:
- self.log.debug('onu alarm indication received', los_status=onu_alarm_ind.los_status,
- onu_intf_id=onu_alarm_ind.onu_id,
- lob_status=onu_alarm_ind.lob_status,
- lopc_miss_status=onu_alarm_ind.lopc_miss_status,
- lopc_mic_error_status=onu_alarm_ind.lopc_mic_error_status,
- intf_id=onu_alarm_ind.intf_id
- )
+ self.log.debug(
+ 'onu alarm indication received',
+ los_status=onu_alarm_ind.los_status,
+ onu_intf_id=onu_alarm_ind.onu_id,
+ lob_status=onu_alarm_ind.lob_status,
+ lopc_miss_status=onu_alarm_ind.lopc_miss_status,
+ lopc_mic_error_status=onu_alarm_ind.lopc_mic_error_status,
+ intf_id=onu_alarm_ind.intf_id)
try:
"""
- Get the specific onu device information for the onu generating the alarm.
- Extract the id. In the future extract the serial number as well
+ Get the specific onu device information for the onu
+ generating the alarm. Extract the id. In the future
+ extract the serial number as well
"""
- onu_device_id = "unresolved"
- serial_number = "unresolved"
- onu_device = self.resolve_onu_id(onu_alarm_ind.onu_id, port_intf_id=onu_alarm_ind.intf_id)
- if onu_device != None:
- onu_device_id = onu_device.id
- serial_number = onu_device.serial_number
-
- if onu_alarm_ind.los_status == 1 or onu_alarm_ind.los_status == "on":
- OnuLosAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).raise_alarm()
- elif onu_alarm_ind.los_status == 0 or onu_alarm_ind.los_status == "off":
- OnuLosAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).clear_alarm()
+ # FIXME - Include ONU serial number in alarm
+ if (onu_alarm_ind.los_status == 1
+ or onu_alarm_ind.los_status == "on"):
+ OnuLosAlarm(self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).raise_alarm()
+ elif (onu_alarm_ind.los_status == 0
+ or onu_alarm_ind.los_status == "off"):
+ OnuLosAlarm(self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).clear_alarm()
else: # No Change
pass
- if onu_alarm_ind.lopc_miss_status == 1 or onu_alarm_ind.lopc_miss_status == "on":
- OnuLopcMissAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).raise_alarm()
- elif (onu_alarm_ind.lopc_miss_status == 0 or onu_alarm_ind.lopc_miss_status == "off"):
- OnuLopcMissAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).clear_alarm()
+ if (onu_alarm_ind.lopc_miss_status == 1
+ or onu_alarm_ind.lopc_miss_status == "on"):
+ OnuLopcMissAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).raise_alarm()
+ elif (onu_alarm_ind.lopc_miss_status == 0
+ or onu_alarm_ind.lopc_miss_status == "off"):
+ OnuLopcMissAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).clear_alarm()
else: # No Change
pass
- if onu_alarm_ind.lopc_mic_error_status == 1 or onu_alarm_ind.lopc_mic_error_status == "on":
- OnuLopcMicErrorAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).raise_alarm()
- elif onu_alarm_ind.lopc_mic_error_status == 0 or onu_alarm_ind.lopc_mic_error_status == "off":
- OnuLopcMicErrorAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).clear_alarm()
+ if (onu_alarm_ind.lopc_mic_error_status == 1
+ or onu_alarm_ind.lopc_mic_error_status == "on"):
+ OnuLopcMicErrorAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).raise_alarm()
+ elif (onu_alarm_ind.lopc_mic_error_status == 0
+ or onu_alarm_ind.lopc_mic_error_status == "off"):
+ OnuLopcMicErrorAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).clear_alarm()
else: # No Change
pass
- if onu_alarm_ind.lob_status == 1 or onu_alarm_ind.lob_status == "on":
- OnuLobAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).raise_alarm()
- elif onu_alarm_ind.lob_status == 0 or onu_alarm_ind.lob_status == "off":
- OnuLobAlarm(self.alarms, onu_id=onu_device_id, intf_id=onu_alarm_ind.intf_id).clear_alarm()
+ if (onu_alarm_ind.lob_status == 1
+ or onu_alarm_ind.lob_status == "on"):
+ OnuLobAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).raise_alarm()
+ elif (onu_alarm_ind.lob_status == 0
+ or onu_alarm_ind.lob_status == "off"):
+ OnuLobAlarm(
+ self.alarms, onu_id=onu_alarm_ind.onu_id,
+ intf_id=onu_alarm_ind.intf_id).clear_alarm()
else: # No Change
pass
except Exception as alarm_err:
- self.log.exception('onu-alarm-indication', errmsg=alarm_err.message)
+ self.log.exception('onu-alarm-indication',
+ errmsg=alarm_err.message)
except Exception as e:
self.log.exception('onu-alarm-indication', errmsg=e.message)
@@ -244,12 +261,16 @@
try:
ind = onu_startup_fail_ind
label = "onu-startup-failure-indication"
- self.log.debug(label + " received", onu_startup_fail_ind=ind, int_id=ind.intf_id, onu_id=ind.onu_id, status=ind.status)
+ self.log.debug(label + " received", onu_startup_fail_ind=ind,
+ int_id=ind.intf_id, onu_id=ind.onu_id,
+ status=ind.status)
try:
if ind.status == 1 or ind.status == "on":
- OnuStartupAlarm(self.alarms, intf_id=ind.intf_id,onu_id=ind.onu_id).raise_alarm()
+ OnuStartupAlarm(self.alarms, intf_id=ind.intf_id,
+ onu_id=ind.onu_id).raise_alarm()
else:
- OnuStartupAlarm(self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id).clear_alarm()
+ OnuStartupAlarm(self.alarms, intf_id=ind.intf_id,
+ onu_id=ind.onu_id).clear_alarm()
except Exception as alarm_err:
self.log.exception(label, errmsg=alarm_err.message)
@@ -279,11 +300,15 @@
status=ind.status)
try:
if ind.status == 1 or ind.status == "on":
- OnuSignalDegradeAlarm(self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id,
- inverse_bit_error_rate=ind.inverse_bit_error_rate).raise_alarm()
+ OnuSignalDegradeAlarm(
+ self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id,
+ inverse_bit_error_rate=ind.inverse_bit_error_rate) \
+ .raise_alarm()
else:
- OnuSignalDegradeAlarm(self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id,
- inverse_bit_error_rate=ind.inverse_bit_error_rate).clear_alarm()
+ OnuSignalDegradeAlarm(
+ self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id,
+ inverse_bit_error_rate=ind.inverse_bit_error_rate) \
+ .clear_alarm()
except Exception as alarm_err:
self.log.exception(label, errmsg=alarm_err.message)
@@ -308,28 +333,24 @@
ind = onu_drift_of_window_ind
label = "onu-window-drift-indication"
- onu_device_id, onu_serial_number = self.resolve_onudev_id_onudev_serialnum(
- self.resolve_onu_id(ind.onu_id, port_intf_id=ind.intf_id))
-
self.log.debug(label + ' received',
onu_drift_of_window_ind=ind,
int_id=ind.intf_id,
onu_id=ind.onu_id,
- onu_device_id=onu_device_id,
drift=ind.drift,
new_eqd=ind.new_eqd,
status=ind.status)
try:
if ind.status == 1 or ind.status == "on":
OnuWindowDriftAlarm(self.alarms, intf_id=ind.intf_id,
- onu_id=onu_device_id,
- drift=ind.drift,
- new_eqd=ind.new_eqd).raise_alarm()
+ onu_id=ind.onu_id,
+ drift=ind.drift,
+ new_eqd=ind.new_eqd).raise_alarm()
else:
OnuWindowDriftAlarm(self.alarms, intf_id=ind.intf_id,
- onu_id=onu_device_id,
- drift=ind.drift,
- new_eqd=ind.new_eqd).clear_alarm()
+ onu_id=ind.onu_id,
+ drift=ind.drift,
+ new_eqd=ind.new_eqd).clear_alarm()
except Exception as alarm_err:
self.log.exception(label, errmsg=alarm_err.message)
@@ -356,40 +377,38 @@
ind = onu_signals_fail_ind
label = "onu-signal-failure-indication"
- onu_device_id, onu_serial_number = self.resolve_onudev_id_onudev_serialnum(
- self.resolve_onu_id(ind.onu_id, port_intf_id=ind.intf_id))
-
self.log.debug(label + ' received',
onu_startup_fail_ind=ind,
int_id=ind.intf_id,
onu_id=ind.onu_id,
- onu_device_id=onu_device_id,
- onu_serial_number=onu_serial_number,
inverse_bit_error_rate=ind.inverse_bit_error_rate,
status=ind.status)
try:
if ind.status == 1 or ind.status == "on":
- OnuSignalFailAlarm(self.alarms, intf_id=ind.intf_id,
- onu_id=onu_device_id,
- inverse_bit_error_rate=ind.inverse_bit_error_rate).raise_alarm()
+ OnuSignalFailAlarm(
+ self.alarms, intf_id=ind.intf_id,
+ onu_id=ind.onu_id,
+ inverse_bit_error_rate=ind.inverse_bit_error_rate) \
+ .raise_alarm()
else:
- OnuSignalFailAlarm(self.alarms, intf_id=ind.intf_id,
- onu_id=onu_device_id,
- inverse_bit_error_rate=ind.inverse_bit_error_rate).clear_alarm()
+ OnuSignalFailAlarm(
+ self.alarms, intf_id=ind.intf_id, onu_id=ind.onu_id,
+ inverse_bit_error_rate=ind.inverse_bit_error_rate) \
+ .clear_alarm()
except Exception as alarm_err:
self.log.exception(label, errmsg=alarm_err.message)
except Exception as e:
self.log.exception(label, errmsg=e.message)
-
def onu_transmission_interference_warning(self, onu_tiwi_ind):
self.log.info('not implemented yet')
def onu_activation_failure_indication(self, onu_activation_fail_ind):
"""
- No status is currently passed with this alarm. Consequently it will always just raise
+ No status is currently passed with this alarm. Consequently it will
+ always just raise
:param onu_activation_fail_ind:
:return:
"""
@@ -397,19 +416,19 @@
ind = onu_activation_fail_ind
label = "onu-activation-failure-indication"
- onu_device_id, onu_serial_number = self.resolve_onudev_id_onudev_serialnum(
- self.resolve_onu_id(ind.onu_id, port_intf_id=ind.intf_id))
+ onu_device_id, onu_serial_number \
+ = self.resolve_onudev_id_onudev_serialnum(
+ self.resolve_onu_id(ind.onu_id, port_intf_id=ind.intf_id))
self.log.debug(label + ' received',
onu_startup_fail_ind=ind,
int_id=ind.intf_id,
onu_id=ind.onu_id,
- onu_device_id=onu_device_id,
onu_serial_number=onu_serial_number)
try:
OnuActivationFailAlarm(self.alarms, intf_id=ind.intf_id,
- onu_id=onu_device_id).raise_alarm()
+ onu_id=ind.onu_id).raise_alarm()
except Exception as alarm_err:
self.log.exception(label, errmsg=alarm_err.message)
@@ -418,49 +437,3 @@
def onu_processing_error_indication(self, onu_processing_error_ind):
self.log.info('not implemented yet')
-
- """
- Helper Methods
- """
-
- def resolve_onudev_id_onudev_serialnum(self,onu_device):
- """
- Convenience wrapper to resolve device_id and serial number
- :param onu_device:
- :return: tuple: onu_device_id, onu_serial_number
- """
- try:
- onu_device_id = "unresolved"
- onu_serial_number = "unresolved"
- if onu_device != None:
- onu_device_id = onu_device.id
- onu_serial_number = onu_device.serial_number
- except Exception as err:
- self.log.exception("openolt-alarms-resolve-onudev-id ", errmsg=err.message)
- raise Exception(err)
- return onu_device_id, onu_serial_number
-
- def resolve_onu_id(self, onu_id, port_intf_id):
- """
- Resolve the onu_device from the intf_id value and port. Uses the adapter agent to
- resolve this..
-
- Returns None if not found. Caller will have to test for None and act accordingly.
- :param onu_id:
- :param port_intf_id:
- :return:
- """
-
- try:
- onu_device = None
- onu_device = self.adapter_agent.get_child_device(
- self.device_id,
- parent_port_no=self.platform.intf_id_to_port_no(
- port_intf_id, device_pb2.Port.PON_OLT),
- onu_id=onu_id)
- onu_device_id = onu_device.id
- except Exception as inner:
- self.log.exception('resolve-onu-id', errmsg=inner.message)
-
- return onu_device
-
diff --git a/voltha/adapters/openolt/openolt_bw.py b/voltha/adapters/openolt/openolt_bw.py
deleted file mode 100644
index 7c70b78..0000000
--- a/voltha/adapters/openolt/openolt_bw.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# 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.
-#
-
-DEFAULT_ONU_BW_PROFILE = "default"
-DEFAULT_ONU_PIR = 1000000 # 1Gbps
-
-
-class OpenOltBW(object):
-
- def __init__(self, log, proxy):
- self.log = log
- self.proxy = proxy
-
- def pir(self, serial_number):
- bw = 0
- try:
- bw = self.proxy.get(
- '/traffic_descriptor_profiles/{}'.format(serial_number))
- except KeyError:
- self.log.debug('bandwidth not configured',
- serial_number=serial_number)
- try:
- bw = self.proxy.get('/traffic_descriptor_profiles/{}' \
- .format(DEFAULT_ONU_BW_PROFILE))
- except KeyError:
- return DEFAULT_ONU_PIR
-
- return bw.maximum_bandwidth
diff --git a/voltha/adapters/openolt/openolt_data_model.py b/voltha/adapters/openolt/openolt_data_model.py
index dca219d..6dd111b 100644
--- a/voltha/adapters/openolt/openolt_data_model.py
+++ b/voltha/adapters/openolt/openolt_data_model.py
@@ -15,6 +15,7 @@
#
import structlog
import socket
+from scapy.layers.l2 import Ether
import voltha.core.flow_decomposer as fd
from voltha.adapters.openolt.openolt_utils import OpenoltUtils
from voltha.protos.device_pb2 import Port, Device
@@ -51,6 +52,8 @@
assert self.logical_device_id is not None
self.adapter_agent.reconcile_logical_device(
self.logical_device_id)
+ # Update device cache
+ self.device = self.get_device(self.device.id)
def olt_create(self, device_info):
if self.logical_device_id is not None:
@@ -245,7 +248,7 @@
onu_device.oper_status = OperStatus.DISCOVERED
self.adapter_agent.update_device(onu_device)
# Set port oper state to Discovered
- self.data_model.__onu_ports_down(onu_device)
+ self.__onu_ports_down(onu_device)
onu_adapter_agent.update_interface(onu_device,
{'oper_state': 'down'})
@@ -302,6 +305,32 @@
self.adapter_agent.publish_inter_adapter_message(
onu_device.id, msg)
+ def onu_omci_rx(self, intf_id, onu_id, pkt):
+ onu_device = self.adapter_agent.get_child_device(
+ self.device.id,
+ parent_port_no=self.platform.intf_id_to_port_no(intf_id,
+ Port.PON_OLT),
+ onu_id=onu_id)
+ self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
+ pkt)
+
+ def onu_send_packet_in(self, intf_type, intf_id, port_no, pkt):
+ if intf_type == "pon":
+ if not port_no:
+ raise ValueError("invalid port_no")
+ logical_port_num = port_no
+ elif intf_type == "nni":
+ logical_port_num = self.platform.intf_id_to_port_no(
+ intf_id,
+ Port.ETHERNET_NNI)
+
+ ether_pkt = Ether(pkt)
+
+ self.adapter_agent.send_packet_in(
+ logical_device_id=self.logical_device_id,
+ logical_port_no=logical_port_num,
+ packet=str(ether_pkt))
+
# #######################################################################
# Flow decomposer utility functions
#
@@ -364,6 +393,35 @@
return ofp_port_name
# #######################################################################
+ # Methods used by Alarm and Statistics Manager (TODO - re-visit)
+ # #######################################################################
+
+ def _adapter_name(self):
+ return self.adapter_agent.adapter_name
+
+ def _device_id(self):
+ return self.device.id
+
+ def _resolve_onu_id(self, onu_id, port_intf_id):
+ try:
+ onu_device = None
+ onu_device = self.adapter_agent.get_child_device(
+ self.device_id,
+ parent_port_no=self.platform.intf_id_to_port_no(
+ port_intf_id, Port.PON_OLT),
+ onu_id=onu_id)
+ except Exception as inner:
+ self.log.exception('resolve-onu-id', errmsg=inner.message)
+
+ return onu_device
+
+ def create_alarm(self, **kwargs):
+ self.adapter_agent.create_alarm(kwargs)
+
+ def submit_alarm(self, alarm_event):
+ self.adapter_agent.submit_alarm(self.device.id, alarm_event)
+
+ # #######################################################################
# Private functions
#
# These functions are prefixed with __ to denote that they are private
@@ -442,7 +500,7 @@
def __delete_logical_port(self, child_device):
logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
- self.data_model.logical_device_id))
+ self.logical_device_id))
for logical_port in logical_ports:
if logical_port.device_id == child_device.id:
self.log.debug('delete-logical-port',
@@ -451,7 +509,7 @@
self.flow_mgr.clear_flows_and_scheduler_for_logical_port(
child_device, logical_port)
self.adapter_agent.delete_logical_port(
- self.data_model.logical_device_id, logical_port)
+ self.logical_device_id, logical_port)
return
def __onu_ports_down(self, onu_device):
@@ -461,11 +519,11 @@
onu_port_id = onu_port.label
try:
onu_logical_port = self.adapter_agent.get_logical_port(
- logical_device_id=self.data_model.logical_device_id,
+ logical_device_id=self.logical_device_id,
port_id=onu_port_id)
onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
self.adapter_agent.update_logical_port(
- logical_device_id=self.data_model.logical_device_id,
+ logical_device_id=self.logical_device_id,
port=onu_logical_port)
self.log.debug('cascading-oper-state-to-port-and-logical-port')
except KeyError as e:
@@ -491,7 +549,7 @@
def __get_uni_ofp_port_name(self, child_device):
logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
- self.data_model.logical_device_id))
+ self.logical_device_id))
for logical_port in logical_ports:
if logical_port.device_id == child_device.id:
return logical_port.ofp_port.name
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index da08170..82c8009 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -23,7 +23,6 @@
from transitions import Machine
from voltha.protos.device_pb2 import Port
-from voltha.protos.common_pb2 import ConnectStatus
from voltha.registry import registry
from voltha.adapters.openolt.protos import openolt_pb2_grpc, openolt_pb2
from voltha.adapters.openolt.openolt_utils import OpenoltUtils
@@ -75,7 +74,7 @@
self.admin_state = "up"
- self.adapter_agent = kwargs['adapter_agent']
+ adapter_agent = kwargs['adapter_agent']
self.device_num = kwargs['device_num']
device = kwargs['device']
@@ -86,27 +85,21 @@
self.flow_mgr_class = kwargs['support_classes']['flow_mgr']
self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr']
self.stats_mgr_class = kwargs['support_classes']['stats_mgr']
- self.bw_mgr_class = kwargs['support_classes']['bw_mgr']
is_reconciliation = kwargs.get('reconciliation', False)
self.device_id = device.id
self.host_and_port = device.host_and_port
self.extra_args = device.extra_args
- self.log = structlog.get_logger(id=self.device_id,
- ip=self.host_and_port)
+ self.log = structlog.get_logger(ip=self.host_and_port)
self.proxy = registry('core').get_proxy('/')
self.log.info('openolt-device-init')
- if not is_reconciliation:
- self.log.info('create data model')
- self.data_model = self.data_model_class(device,
- self.adapter_agent,
- self.platform)
- else:
+ self.data_model = self.data_model_class(device, adapter_agent,
+ self.platform)
+ if is_reconciliation:
self.log.info('reconcile data model')
assert device.parent_id is not None
- assert self.data_model is not None
self.data_model.reconcile()
# Initialize the OLT state machine
@@ -123,7 +116,7 @@
self.channel = grpc.insecure_channel(self.host_and_port)
self.channel_ready_future = grpc.channel_ready_future(self.channel)
- self.log.info('openolt-device-created', device_id=self.device_id)
+ self.log.info('openolt-device-created')
def post_init(self, event):
self.log.debug('post_init')
@@ -164,11 +157,10 @@
self.platform, self.resource_mgr,
self.data_model)
- self.alarm_mgr = self.alarm_mgr_class(
- self.log, self.adapter_agent, self.device_id,
- self.data_model.logical_device_id, self.platform)
- self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
- self.bw_mgr = self.bw_mgr_class(self.log, self.proxy)
+ self.alarm_mgr = self.alarm_mgr_class(self.log, self.platform,
+ self.data_model)
+ self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform,
+ self.data_model)
def do_state_up(self, event):
self.log.debug("do_state_up")
@@ -184,7 +176,7 @@
def indications_thread(self):
self.log.debug('starting-indications-thread')
- self.log.debug('connecting to olt', device_id=self.device_id)
+ self.log.debug('connecting to olt')
self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
@@ -354,16 +346,11 @@
self.log.debug("omci indication", intf_id=omci_indication.intf_id,
onu_id=omci_indication.onu_id)
- onu_device = self.adapter_agent.get_child_device(
- self.device_id, onu_id=omci_indication.onu_id,
- parent_port_no=self.platform.intf_id_to_port_no(
- omci_indication.intf_id, Port.PON_OLT), )
-
- self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
- omci_indication.pkt)
+ self.data_model.onu_omci_rx(omci_indication.intf_id,
+ omci_indication.onu_id,
+ omci_indication.pkt)
def packet_indication(self, pkt_indication):
-
self.log.debug("packet indication",
intf_type=pkt_indication.intf_type,
intf_id=pkt_indication.intf_id,
@@ -371,53 +358,14 @@
cookie=pkt_indication.cookie,
gemport_id=pkt_indication.gemport_id,
flow_id=pkt_indication.flow_id)
-
- if pkt_indication.intf_type == "pon":
- if pkt_indication.port_no:
- logical_port_num = pkt_indication.port_no
- else:
- # TODO Remove this else block after openolt device has been
- # fully rolled out with cookie protobuf change
- try:
- onu_id_uni_id = self.resource_mgr. \
- get_onu_uni_from_ponport_gemport(
- pkt_indication.intf_id, pkt_indication.gemport_id)
- onu_id = int(onu_id_uni_id[0])
- uni_id = int(onu_id_uni_id[1])
- self.log.debug("packet indication-kv", onu_id=onu_id,
- uni_id=uni_id)
- if onu_id is None:
- raise Exception("onu-id-none")
- if uni_id is None:
- raise Exception("uni-id-none")
- logical_port_num = self.platform.mk_uni_port_num(
- pkt_indication.intf_id, onu_id, uni_id)
- except Exception as e:
- self.log.error("no-onu-reference-for-gem",
- gemport_id=pkt_indication.gemport_id, e=e)
- return
-
- elif pkt_indication.intf_type == "nni":
- logical_port_num = self.platform.intf_id_to_port_no(
- pkt_indication.intf_id,
- Port.ETHERNET_NNI)
-
- pkt = Ether(pkt_indication.pkt)
-
- self.log.debug("packet indication",
- logical_device_id=self.data_model.logical_device_id,
- logical_port_no=logical_port_num)
-
- self.adapter_agent.send_packet_in(
- logical_device_id=self.data_model.logical_device_id,
- logical_port_no=logical_port_num,
- packet=str(pkt))
+ self.data_model.onu_send_packet_in(pkt_indication.intf_type,
+ pkt_indication.intf_id,
+ pkt_indication.port_no,
+ pkt_indication.pkt)
def packet_out(self, egress_port, msg):
pkt = Ether(msg)
self.log.debug('packet out', egress_port=egress_port,
- device_id=self.device_id,
- logical_device_id=self.data_model.logical_device_id,
packet=str(pkt).encode("HEX"))
# Find port type
@@ -474,17 +422,6 @@
port_type=egress_port_type)
def send_proxied_message(self, proxy_address, msg):
- onu_device = self.adapter_agent.get_child_device(
- self.device_id, onu_id=proxy_address.onu_id,
- parent_port_no=self.platform.intf_id_to_port_no(
- proxy_address.channel_id, Port.PON_OLT)
- )
- if onu_device.connect_status != ConnectStatus.REACHABLE:
- self.log.debug('ONU is not reachable, cannot send OMCI',
- serial_number=onu_device.serial_number,
- intf_id=onu_device.proxy_address.channel_id,
- onu_id=onu_device.proxy_address.onu_id)
- return
omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id,
onu_id=proxy_address.onu_id, pkt=str(msg))
self.stub.OmciMsgOut(omci)
@@ -526,8 +463,7 @@
self.flow_mgr.repush_all_different_flows()
def disable(self):
- self.log.debug('sending-deactivate-olt-message',
- device_id=self.device_id)
+ self.log.debug('sending-deactivate-olt-message')
try:
# Send grpc call
@@ -538,8 +474,7 @@
self.log.error('Failure to disable openolt device', error=e)
def delete(self):
- self.log.info('deleting-olt', device_id=self.device_id,
- logical_device_id=self.data_model.logical_device_id)
+ self.log.info('deleting-olt')
# Clears up the data from the resource manager KV store
# for the device
@@ -553,10 +488,10 @@
self.log.error('Failure to delete openolt device', error=e)
raise e
else:
- self.log.info('successfully-deleted-olt', device_id=self.device_id)
+ self.log.info('successfully-deleted-olt')
def reenable(self):
- self.log.debug('reenabling-olt', device_id=self.device_id)
+ self.log.debug('reenabling-olt')
try:
self.stub.ReenableOlt(openolt_pb2.Empty())
@@ -568,12 +503,11 @@
def activate_onu(self, intf_id, onu_id, serial_number,
serial_number_str):
- pir = self.bw_mgr.pir(serial_number_str)
self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id,
serial_number_str=serial_number_str,
- serial_number=serial_number, pir=pir)
+ serial_number=serial_number)
onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
- serial_number=serial_number, pir=pir)
+ serial_number=serial_number)
try:
self.stub.ActivateOnu(onu)
except grpc.RpcError as grpc_e:
@@ -592,7 +526,6 @@
# needs to change to use serial_number.
def delete_child_device(self, child_device):
self.log.debug('sending-deactivate-onu',
- olt_device_id=self.device_id,
onu_device=child_device,
onu_serial_number=child_device.serial_number)
@@ -630,7 +563,7 @@
self.log.exception("error-deleting-the-onu-on-olt-device", error=e)
def reboot(self):
- self.log.debug('rebooting openolt device', device_id=self.device_id)
+ self.log.debug('rebooting openolt device')
try:
self.stub.Reboot(openolt_pb2.Empty())
except Exception as e:
diff --git a/voltha/adapters/openolt/openolt_statistics.py b/voltha/adapters/openolt/openolt_statistics.py
index 7f3aad5..fa60fd0 100644
--- a/voltha/adapters/openolt/openolt_statistics.py
+++ b/voltha/adapters/openolt/openolt_statistics.py
@@ -26,7 +26,7 @@
class OpenOltStatisticsMgr(object):
- def __init__(self, openolt_device, log, platform, **kargs):
+ def __init__(self, openolt_device, log, platform, data_model, **kargs):
"""
kargs are used to pass debugging flags at this time.
@@ -37,6 +37,7 @@
self.device = openolt_device
self.log = log
self.platform = platform
+ self.data_model = data_model
# Northbound and Southbound ports
# added to initialize the pm_metrics
self.northbound_ports = self.init_ports(type="nni")
@@ -60,7 +61,8 @@
'pon-ports': self.southbound_ports.values()
}
self.pm_metrics = OltPmMetrics(
- self.device.adapter_agent, self.device.device_id,
+ self.device.data_model.adapter_agent,
+ self.data_model._device_id(),
self.device.data_model.logical_device_id,
grouped=True, freq_override=False, **kwargs)
"""
@@ -82,8 +84,8 @@
for (m, t) in self.pm_metrics.pon_pm_names}
pm_config = self.pm_metrics.make_proto()
self.log.info("initial-pm-config", pm_config=pm_config)
- self.device.adapter_agent.update_device_pm_config(pm_config,
- init=True)
+ self.device.data_model.adapter_agent.update_device_pm_config(
+ pm_config, init=True)
# Start collecting stats from the device after a brief pause
reactor.callLater(10, self.pm_metrics.start_collector)
except Exception as e:
@@ -102,7 +104,7 @@
# # ONOS update
# self.update_logical_port_stats(port_stats)
# # update port object stats
- # port = self.device.adapter_agent.get_port(self.device.device_id,
+ # port = self.device.adapter_agent.get_port(self.device_id,
# port_no=port_stats.intf_id)
#
# if port is None:
@@ -117,7 +119,7 @@
# port.tx_errors = port_stats.tx_error_packets
#
# # Add port does an update if port exists
- # self.device.adapter_agent.add_port(self.device.device_id, port)
+ # self.device.adapter_agent.add_port(self.device_id, port)
def flow_statistics_indication(self, flow_stats):
self.log.info('flow-stats-collected', stats=flow_stats)
@@ -125,7 +127,7 @@
# FIXME: etcd problem, do not update objects for now
# # UNTESTED : the openolt driver does not yet provide flow stats
# self.device.adapter_agent.update_flow_stats(
- # self.device.data_model.logical_device_id,
+ # self.device.logical_device_id,
# flow_id=flow_stats.flow_id, packet_count=flow_stats.tx_packets,
# byte_count=flow_stats.tx_bytes)
@@ -200,8 +202,9 @@
def update_logical_port_stats(self, port_stats):
try:
label = 'nni-{}'.format(port_stats.intf_id)
- logical_port = self.device.adapter_agent.get_logical_port(
- self.device.data_model.logical_device_id, label)
+ logical_port \
+ = self.device.data_model.adapter_agent.get_logical_port(
+ self.device.data_model.logical_device_id, label)
except KeyError as e:
self.log.warn('logical port was not found, it may not have been '
'created yet', exception=e)
@@ -224,7 +227,7 @@
self.log.debug('after-stats-update', port=logical_port)
- self.device.adapter_agent.update_logical_port(
+ self.device.data_model.adapter_agent.update_logical_port(
self.device.data_model.logical_device_id, logical_port)
"""
@@ -415,7 +418,7 @@
'port_no': port_num,
'intf_id': self.platform.intf_id_to_port_no(
port_num, Port.ETHERNET_NNI),
- "device_id": self.device.device_id
+ "device_id": self.data_model._device_id()
}
nni_port = NniPort
port = nni_port(**kwargs)
@@ -429,7 +432,7 @@
Port.PON_OLT),
'pon-id': self.platform.intf_id_to_port_no(port_num,
Port.PON_OLT),
- "device_id": self.device.device_id
+ "device_id": self.data_model._device_id()
}
pon_port = PonPort
port = pon_port(**kwargs)
@@ -494,7 +497,6 @@
assert 'pon-id' in kwargs, 'PON ID not found'
self._pon_id = kwargs['pon-id']
- self._device_id = kwargs['device_id']
self._intf_id = kwargs['intf_id']
self._port_no = kwargs['port_no']
self._port_id = 0
diff --git a/voltha/extensions/alarms/device_alarms.py b/voltha/extensions/alarms/device_alarms.py
new file mode 100644
index 0000000..56f9f40
--- /dev/null
+++ b/voltha/extensions/alarms/device_alarms.py
@@ -0,0 +1,96 @@
+#
+# Copyright 2019 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
+log = structlog.get_logger()
+
+
+class DeviceAlarms:
+ """
+ Class for managing device alarms
+ """
+ def __init__(self, data_model):
+ """
+ Adapter alarm manager initializer
+
+ :param data_model: data_model
+ """
+ self.log = structlog.get_logger()
+ self.data_model = data_model
+ 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.data_model._adapter_name(),
+ self.data_model._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)
+ # FIXME - The entity that is raising the alarm needs to
+ # provide the onu and olt serial numbers.
+ alarm_event = self.data_model.create_alarm(
+ id=alarm_data.get('id', 'voltha.{}.{}.olt'.format(
+ self.data_model._adapter_name(),
+ self.data_model._device_id())),
+ resource_id=str(alarm_data.get('resource_id',
+ self.data_model.device.id)),
+ description="{}.{} - {}".format(self.data_model._adapter_name(),
+ self.data_model._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,
+ alarm_type_name=alarm_data.get('alarm_type_name')
+ )
+ self.data_model.submit_alarm(alarm_event)
+
+ except Exception as e:
+ self.log.exception('failed-to-send-alarm', e=e)
+ raise