VOL-1398: Adtran-ONU - Initial containerization commit
Change-Id: I7afcc1ad65b9ef80da994b0b0ddf74860911bb46
diff --git a/adapters/adtran_onu/README.md b/adapters/adtran_onu/README.md
new file mode 100644
index 0000000..d64a251
--- /dev/null
+++ b/adapters/adtran_onu/README.md
@@ -0,0 +1,2 @@
+# adtran_onu
+VOLTHA ONU Device Adapter for Adtran ONU/ONTs
diff --git a/adapters/adtran_onu/VERSION b/adapters/adtran_onu/VERSION
new file mode 100644
index 0000000..1e4ec5e
--- /dev/null
+++ b/adapters/adtran_onu/VERSION
@@ -0,0 +1 @@
+2.0.1-dev
diff --git a/adapters/adtran_onu/__init__.py b/adapters/adtran_onu/__init__.py
new file mode 100644
index 0000000..d67fcf2
--- /dev/null
+++ b/adapters/adtran_onu/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2019-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.
diff --git a/adapters/adtran_onu/adtran_onu.py b/adapters/adtran_onu/adtran_onu.py
new file mode 100755
index 0000000..c0801d1
--- /dev/null
+++ b/adapters/adtran_onu/adtran_onu.py
@@ -0,0 +1,122 @@
+#
+# 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.
+#
+
+"""
+Adtran ONU adapter.
+"""
+import structlog
+import binascii
+from pyvoltha.adapters.iadapter import OnuAdapter
+from pyvoltha.protos import third_party
+from adtran_onu_handler import AdtranOnuHandler
+from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
+from omci.adtn_capabilities_task import AdtnCapabilitiesTask
+from omci.adtn_get_mds_task import AdtnGetMdsTask
+from omci.adtn_mib_sync import AdtnMibSynchronizer
+from omci.adtn_mib_resync_task import AdtnMibResyncTask
+from omci.adtn_mib_reconcile_task import AdtnMibReconcileTask
+from copy import deepcopy
+
+_ = third_party
+
+
+class AdtranOnuAdapter(OnuAdapter):
+ def __init__(self, core_proxy, adapter_proxy, config):
+ self.log = structlog.get_logger()
+ super(AdtranOnuAdapter, self).__init__(core_proxy=core_proxy,
+ adapter_proxy=adapter_proxy,
+ config=config,
+ device_handler_class=AdtranOnuHandler,
+ name='adtran_onu',
+ vendor='ADTRAN, Inc.',
+ version='2.0',
+ device_type='adtran_onu',
+ vendor_id='ADTN',
+ accepts_bulk_flow_update=True,
+ accepts_add_remove_flow_updates=False) # TODO: Support flow-mods
+ # Customize OpenOMCI for Adtran ONUs
+ self.adtran_omci = deepcopy(OpenOmciAgentDefaults)
+
+ from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict
+ self.adtran_omci['mib-synchronizer']['database'] = MibDbVolatileDict
+
+ self.adtran_omci['mib-synchronizer']['state-machine'] = AdtnMibSynchronizer
+ self.adtran_omci['mib-synchronizer']['tasks']['get-mds'] = AdtnGetMdsTask
+ self.adtran_omci['mib-synchronizer']['tasks']['mib-audit'] = AdtnGetMdsTask
+ self.adtran_omci['mib-synchronizer']['tasks']['mib-resync'] = AdtnMibResyncTask
+ self.adtran_omci['mib-synchronizer']['tasks']['mib-reconcile'] = AdtnMibReconcileTask
+ self.adtran_omci['omci-capabilities']['tasks']['get-capabilities'] = AdtnCapabilitiesTask
+ # TODO: Continue to customize adtran_omci here as needed
+
+ self._omci_agent = OpenOMCIAgent(self.adapter_agent.core,
+ support_classes=self.adtran_omci)
+
+ @property
+ def omci_agent(self):
+ return self._omci_agent
+
+ def start(self):
+ super(AdtranOnuAdapter, self).start()
+ self._omci_agent.start()
+
+ def stop(self):
+ omci, self._omci_agent = self._omci_agent, None
+ if omci is not None:
+ omci.stop()
+
+ super(AdtranOnuAdapter, self).stop()
+
+ def download_image(self, device, request):
+ raise NotImplementedError()
+
+ def activate_image_update(self, device, request):
+ raise NotImplementedError()
+
+ def cancel_image_download(self, device, request):
+ raise NotImplementedError()
+
+ def revert_image_update(self, device, request):
+ raise NotImplementedError()
+
+ def get_image_download_status(self, device, request):
+ raise NotImplementedError()
+
+ def process_inter_adapter_message(self, msg):
+ # Currently the only OLT Device adapter that uses this is the EdgeCore
+
+ self.log.info('receive_inter_adapter_message', msg=msg)
+ proxy_address = msg['proxy_address']
+ assert proxy_address is not None
+ # Device_id from the proxy_address is the olt device id. We need to
+ # get the onu device id using the port number in the proxy_address
+ device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
+ if device is not None:
+ handler = self.devices_handlers[device.id]
+ handler.event_messages.put(msg)
+ else:
+ self.log.error("device-not-found")
+
+ def receive_proxied_message(self, proxy_address, msg):
+ self.log.debug('receive-proxied-message', proxy_address=proxy_address,
+ device_id=proxy_address.device_id, msg=binascii.hexlify(msg))
+ # Device_id from the proxy_address is the olt device id. We need to
+ # get the onu device id using the port number in the proxy_address
+ device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
+
+ if device is not None:
+ handler = self.devices_handlers[device.id]
+ if handler is not None:
+ handler.receive_message(msg)
diff --git a/adapters/adtran_onu/adtran_onu.yml b/adapters/adtran_onu/adtran_onu.yml
new file mode 100644
index 0000000..91881a0
--- /dev/null
+++ b/adapters/adtran_onu/adtran_onu.yml
@@ -0,0 +1,69 @@
+---
+# Copyright 2019-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.
+
+logging:
+ version: 1
+
+ formatters:
+ brief:
+ format: '%(message)s'
+ default:
+ format: '%(asctime)s.%(msecs)03d %(levelname)-8s %(threadName)s %(module)s.%(funcName)s %(message)s'
+ datefmt: '%Y%m%dT%H%M%S'
+
+ handlers:
+ console:
+ class : logging.StreamHandler
+ level: DEBUG
+ formatter: default
+ stream: ext://sys.stdout
+ localRotatingFile:
+ class: logging.handlers.RotatingFileHandler
+ filename: adtran_onu.log
+ formatter: default
+ maxBytes: 2097152
+ backupCount: 10
+ level: DEBUG
+ null:
+ class: logging.NullHandler
+
+ loggers:
+ amqp:
+ handlers: [null]
+ propagate: False
+ conf:
+ propagate: False
+ '': # root logger
+ handlers: [console, localRotatingFile]
+ level: DEBUG # this can be bumped up/down by -q and -v command line
+ # options
+ propagate: False
+
+
+kafka-cluster-proxy:
+ event_bus_publisher:
+ topic_mappings:
+ 'model-change-events':
+ kafka_topic: 'voltha.events'
+ filters: [null]
+ 'alarms':
+ kafka_topic: 'voltha.alarms'
+ filters: [null]
+ 'kpis':
+ kafka_topic: 'voltha.kpis'
+ filters: [null]
+ 'openomci-events':
+ kafka_topic: 'voltha.events'
+ filters: [null]
diff --git a/adapters/adtran_onu/adtran_onu_handler.py b/adapters/adtran_onu/adtran_onu_handler.py
new file mode 100644
index 0000000..61fdc2c
--- /dev/null
+++ b/adapters/adtran_onu/adtran_onu_handler.py
@@ -0,0 +1,874 @@
+#
+# 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 ast
+from pon_port import PonPort
+from uni_port import UniPort
+from heartbeat import HeartBeat
+from omci.omci import OMCI
+from onu_traffic_descriptor import OnuTrafficDescriptor
+from onu_tcont import OnuTCont
+from onu_gem_port import OnuGemPort
+
+from pyvoltha.adapters.extensions.alarms.adapter_alarms import AdapterAlarms
+from pyvoltha.adapters.extensions.kpi.onu.onu_pm_metrics import OnuPmMetrics
+from pyvoltha.adapters.extensions.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
+
+from twisted.internet import reactor
+from twisted.internet.defer import DeferredQueue, inlineCallbacks
+from twisted.internet.defer import returnValue
+
+from pyvoltha.common.utils.registry import registry
+from pyvoltha.protos import third_party
+from pyvoltha.protos.common_pb2 import OperStatus, ConnectStatus
+from pyvoltha.common.tech_profile.tech_profile import TechProfile
+from pyvoltha.adapters.common.kvstore.consul_client import Consul
+from pyvoltha.adapters.common.kvstore.etcd_client import EtcdClient
+
+import adtran_olt.resources.adtranolt_platform as platform
+from adapters.adtran_common.flow.flow_entry import FlowEntry
+from omci.adtn_install_flow import AdtnInstallFlowTask
+from omci.adtn_remove_flow import AdtnRemoveFlowTask
+from omci.adtn_tp_service_specific_task import AdtnTpServiceSpecificTask
+from pyvoltha.common.tech_profile.tech_profile import DEFAULT_TECH_PROFILE_TABLE_ID
+
+_ = third_party
+_MAXIMUM_PORT = 17 # Only one PON and UNI port at this time
+_ONU_REBOOT_MIN = 90 # IBONT 602 takes about 3 minutes
+_ONU_REBOOT_RETRY = 10
+_STARTUP_RETRY_WAIT = 20
+
+
+class AdtranOnuHandler(object):
+ def __init__(self, adapter, device_id):
+ self.adapter = adapter
+ self.adapter_agent = adapter.adapter_agent
+ self.device_id = device_id
+ self.log = structlog.get_logger(device_id=device_id)
+ self.logical_device_id = None
+ self.proxy_address = None
+ self._enabled = False
+ self.pm_metrics = None
+ self.alarms = None
+
+ self._openomci = OMCI(self, adapter.omci_agent)
+ self._in_sync_subscription = None
+
+ self._pon_port_number = 1
+
+ self._unis = dict() # Port # -> UniPort
+ self._pon = PonPort.create(self, self._pon_port_number)
+ self._heartbeat = HeartBeat.create(self, device_id)
+ self._deferred = None
+
+ # Flow entries
+ self._flows = dict()
+
+ # OMCI resources # TODO: Some of these could be dynamically chosen
+ self.vlan_tcis_1 = 0x900
+ self.mac_bridge_service_profile_entity_id = self.vlan_tcis_1
+ self.gal_enet_profile_entity_id = 0
+
+ # Technology profile related values
+ self.incoming_messages = DeferredQueue()
+ self.event_messages = DeferredQueue()
+ self._tp_service_specific_task = dict()
+ self._tech_profile_download_done = dict()
+
+ # Initialize KV store client
+ self.args = registry('main').get_args()
+ if self.args.backend == 'etcd':
+ host, port = self.args.etcd.split(':', 1)
+ self.kv_client = EtcdClient(host, port,
+ TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
+ elif self.args.backend == 'consul':
+ host, port = self.args.consul.split(':', 1)
+ self.kv_client = Consul(host, port,
+ TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
+ else:
+ self.log.error('Invalid-backend')
+ raise Exception("Invalid-backend-for-kv-store")
+
+ # Handle received ONU event messages
+ reactor.callLater(0, self.handle_onu_events)
+
+ def __str__(self):
+ return "AdtranOnuHandler: {}".format(self.device_id)
+
+ def _cancel_deferred(self):
+ d, self._deferred = self._deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ @property
+ def enabled(self):
+ return self._enabled
+
+ @enabled.setter
+ def enabled(self, value):
+ assert isinstance(value, bool), 'enabled is a boolean'
+ if self._enabled != value:
+ self._enabled = value
+ if self._enabled:
+ self.start()
+ else:
+ self.stop()
+
+ @property
+ def openomci(self):
+ return self._openomci
+
+ @property
+ def heartbeat(self):
+ return self._heartbeat
+
+ @property
+ def uni_ports(self):
+ return self._unis.values()
+
+ def uni_port(self, port_no_or_name):
+ if isinstance(port_no_or_name, (str, unicode)):
+ return next((uni for uni in self.uni_ports
+ if uni.name == port_no_or_name), None)
+
+ assert isinstance(port_no_or_name, int), 'Invalid parameter type'
+ return self._unis.get(port_no_or_name)
+
+ def pon_port(self, port_no=None):
+ return self._pon if port_no is None or port_no == self._pon.port_number else None
+
+ @property
+ def pon_ports(self):
+ return [self._pon]
+
+ def start(self):
+ assert self._enabled, 'Start should only be called if enabled'
+ self._cancel_deferred()
+
+ # Register for adapter messages
+ self.adapter_agent.register_for_inter_adapter_messages()
+
+ # OpenOMCI Startup
+ self._subscribe_to_events()
+ self._openomci.enabled = True
+
+ # Port startup
+ if self._pon is not None:
+ self._pon.enabled = True
+
+ for port in self.uni_ports:
+ port.enabled = True
+
+ # Heartbeat
+ self._heartbeat.enabled = True
+
+ def stop(self):
+ assert not self._enabled, 'Stop should only be called if disabled'
+ self._cancel_deferred()
+
+ # Drop registration for adapter messages
+ self.adapter_agent.unregister_for_inter_adapter_messages()
+
+ # Heartbeat
+ self._heartbeat.enabled = False
+
+ # OMCI Communications
+ self._unsubscribe_to_events()
+
+ # Port shutdown
+ for port in self.uni_ports:
+ port.enabled = False
+
+ if self._pon is not None:
+ self._pon.enabled = False
+ self._openomci.enabled = False
+
+ def receive_message(self, msg):
+ if self.enabled:
+ # TODO: Have OpenOMCI actually receive the messages
+ self.openomci.receive_message(msg)
+
+ def activate(self, device):
+ self.log.info('activating')
+
+ try:
+ # first we verify that we got parent reference and proxy info
+ assert device.parent_id, 'Invalid Parent ID'
+ assert device.proxy_address.device_id, 'Invalid Device ID'
+
+ # register for proxied messages right away
+ self.proxy_address = device.proxy_address
+ self.adapter_agent.register_for_proxied_messages(device.proxy_address)
+
+ # initialize device info
+ device.root = False
+ device.vendor = 'Adtran Inc.'
+ device.model = 'n/a'
+ device.hardware_version = 'n/a'
+ device.firmware_version = 'n/a'
+ device.reason = ''
+ device.connect_status = ConnectStatus.UNKNOWN
+
+ # Register physical ports. Should have at least one of each
+ self.adapter_agent.add_port(device.id, self._pon.get_port())
+
+ def xpon_not_found():
+ self.enabled = True
+
+ # Schedule xPON 'not found' startup for 10 seconds from now. We will
+ # easily get a vONT-ANI create within that time if xPON is being used
+ # as this is how we are initially launched and activated in the first
+ # place if xPON is in use.
+ reactor.callLater(10, xpon_not_found) # TODO: Clean up old xPON delay
+
+ # reference of uni_port is required when re-enabling the device if
+ # it was disabled previously
+ # Need to query ONU for number of supported uni ports
+ # For now, temporarily set number of ports to 1 - port #2
+ parent_device = self.adapter_agent.get_device(device.parent_id)
+
+ self.logical_device_id = parent_device.parent_id
+ self.adapter_agent.update_device(device)
+
+ ############################################################################
+ # Setup PM configuration for this device
+ # Pass in ONU specific options
+ kwargs = {
+ OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
+ 'heartbeat': self.heartbeat,
+ OnuOmciPmMetrics.OMCI_DEV_KEY: self.openomci.onu_omci_device
+ }
+ self.pm_metrics = OnuPmMetrics(self.adapter_agent, self.device_id,
+ self.logical_device_id, grouped=True,
+ freq_override=False, **kwargs)
+ pm_config = self.pm_metrics.make_proto()
+ self.openomci.set_pm_config(self.pm_metrics.omci_pm.openomci_interval_pm)
+ self.log.info("initial-pm-config", pm_config=pm_config)
+ self.adapter_agent.update_device_pm_config(pm_config, init=True)
+
+ ############################################################################
+ # Setup Alarm handler
+ self.alarms = AdapterAlarms(self.adapter_agent, device.id, self.logical_device_id)
+ self.openomci.onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.alarms,
+ ani_ports=[self._pon])
+ ############################################################################
+ # Start collecting stats from the device after a brief pause
+ reactor.callLater(30, self.pm_metrics.start_collector)
+
+ except Exception as e:
+ self.log.exception('activate-failure', e=e)
+ device.reason = 'Failed to activate: {}'.format(e.message)
+ device.connect_status = ConnectStatus.UNREACHABLE
+ device.oper_status = OperStatus.FAILED
+ self.adapter_agent.update_device(device)
+
+ def reconcile(self, device):
+ self.log.info('reconciling-ONU-device-starts')
+
+ # first we verify that we got parent reference and proxy info
+ assert device.parent_id
+ assert device.proxy_address.device_id
+ # assert device.proxy_address.channel_id
+ self._cancel_deferred()
+
+ # register for proxied messages right away
+ self.proxy_address = device.proxy_address
+ self.adapter_agent.register_for_proxied_messages(device.proxy_address)
+
+ # Register for adapter messages
+ self.adapter_agent.register_for_inter_adapter_messages()
+
+ # Set the connection status to REACHABLE
+ device.connect_status = ConnectStatus.REACHABLE
+ self.adapter_agent.update_device(device)
+ self.enabled = True
+
+ # TODO: Verify that the uni, pon and logical ports exists
+
+ # Mark the device as REACHABLE and ACTIVE
+ device = self.adapter_agent.get_device(device.id)
+ device.connect_status = ConnectStatus.REACHABLE
+ device.oper_status = OperStatus.ACTIVE
+ device.reason = ''
+ self.adapter_agent.update_device(device)
+
+ self.log.info('reconciling-ONU-device-ends')
+
+ @inlineCallbacks
+ def handle_onu_events(self):
+ # TODO: Add 'shutdown' message to exit loop
+ event_msg = yield self.event_messages.get()
+ try:
+ if event_msg['event'] == 'download_tech_profile':
+ tp_path = event_msg['event_data']
+ uni_id = event_msg['uni_id']
+ self.load_and_configure_tech_profile(uni_id, tp_path)
+
+ except Exception as e:
+ self.log.error("exception-handling-onu-event", e=e)
+
+ # Handle next event
+ reactor.callLater(0, self.handle_onu_events)
+
+ def _tp_path_to_tp_id(self, tp_path):
+ parts = tp_path.split('/')
+ if len(parts) > 2:
+ try:
+ return int(tp_path[1])
+ except ValueError:
+ return DEFAULT_TECH_PROFILE_TABLE_ID
+
+ def _create_tcont(self, uni_id, us_scheduler, tech_profile_id):
+ """
+ Decode Upstream Scheduler and create appropriate TCONT structures
+
+ :param uni_id: (int) UNI ID on the PON
+ :param us_scheduler: (Scheduler) Upstream Scheduler with TCONT information
+ :param tech_profile_id: (int) Tech Profile ID
+
+ :return (OnuTCont) Created TCONT
+ """
+ self.log.debug('create-tcont', us_scheduler=us_scheduler, profile_id=tech_profile_id)
+
+ q_sched_policy = {
+ 'strictpriority': 1, # Per TCONT (ME #262) values
+ 'wrr': 2
+ }.get(us_scheduler.get('q_sched_policy', 'none').lower(), 0)
+
+ tcont_data = {
+ 'tech-profile-id': tech_profile_id,
+ 'uni-id': uni_id,
+ 'alloc-id': us_scheduler['alloc_id'],
+ 'q-sched-policy': q_sched_policy
+ }
+ # TODO: Support TD if shaping on ONU is to be performed
+ td = OnuTrafficDescriptor(0, 0, 0)
+ tcont = OnuTCont.create(self, tcont_data, td)
+ self._pon.add_tcont(tcont)
+ return tcont
+
+ # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
+ def _create_gemports(self, upstream_ports, downstream_ports, tcont, uni_id, tech_profile_id):
+ """
+ Create GEM Ports for a specifc tech profile
+
+ The routine will attempt to combine upstream and downstream GEM Ports into bidirectional
+ ports where possible
+
+ :param upstream_ports: (list of IGemPortAttribute) Upstream GEM Port attributes
+ :param downstream_ports: (list of IGemPortAttribute) Downstream GEM Port attributes
+ :param tcont: (OnuTCont) Associated TCONT
+ :param uni_id: (int) UNI Instance ID
+ :param tech_profile_id: (int) Tech Profile ID
+ """
+ self.log.debug('create-gemports', upstream=upstream_ports,
+ downstream_ports=downstream_ports,
+ tcont=tcont, tech_id=tech_profile_id)
+ # Convert GEM Port lists to dicts with GEM ID as they key
+ upstream = {gem['gemport_id']: gem for gem in upstream_ports}
+ downstream = {gem['gemport_id']: gem for gem in downstream_ports}
+
+ upstream_ids = set(upstream.keys())
+ downstream_ids = set(downstream.keys())
+ bidirectional_ids = upstream_ids & downstream_ids
+
+ gem_port_types = { # Keys are the 'direction' attribute value, value is list of GEM attributes
+ OnuGemPort.UPSTREAM: [upstream[gid] for gid in upstream_ids - bidirectional_ids],
+ OnuGemPort.DOWNSTREAM: [downstream[gid] for gid in downstream_ids - bidirectional_ids],
+ OnuGemPort.BIDIRECTIONAL: [upstream[gid] for gid in bidirectional_ids]
+ }
+ for direction, gem_list in gem_port_types.items():
+ for gem in gem_list:
+ gem_data = {
+ 'gemport-id': gem['gemport_id'],
+ 'direction': direction,
+ 'encryption': gem['aes_encryption'].lower() == 'true',
+ 'discard-policy': gem['discard_policy'],
+ 'max-q-size': gem['max_q_size'],
+ 'pbit-map': gem['pbit_map'],
+ 'priority-q': gem['priority_q'],
+ 'scheduling-policy': gem['scheduling_policy'],
+ 'weight': gem['weight'],
+ 'uni-id': uni_id,
+ 'discard-config': {
+ 'max-probability': gem['discard_config']['max_probability'],
+ 'max-threshold': gem['discard_config']['max_threshold'],
+ 'min-threshold': gem['discard_config']['min_threshold'],
+ },
+ }
+ gem_port = OnuGemPort.create(self, gem_data, tcont.alloc_id,
+ tech_profile_id, uni_id,
+ self._pon.next_gem_entity_id)
+ self._pon.add_gem_port(gem_port)
+
+ def _do_tech_profile_configuration(self, uni_id, tp, tech_profile_id):
+ us_scheduler = tp['us_scheduler']
+ tcont = self._create_tcont(uni_id, us_scheduler, tech_profile_id)
+
+ upstream = tp['upstream_gem_port_attribute_list']
+ downstream = tp['downstream_gem_port_attribute_list']
+ self._create_gemports(upstream, downstream, tcont, uni_id, tech_profile_id)
+
+ def load_and_configure_tech_profile(self, uni_id, tp_path):
+ self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
+
+ if uni_id not in self._tp_service_specific_task:
+ self._tp_service_specific_task[uni_id] = dict()
+
+ if uni_id not in self._tech_profile_download_done:
+ self._tech_profile_download_done[uni_id] = dict()
+
+ if tp_path not in self._tech_profile_download_done[uni_id]:
+ self._tech_profile_download_done[uni_id][tp_path] = False
+
+ if not self._tech_profile_download_done[uni_id][tp_path]:
+ try:
+ if tp_path in self._tp_service_specific_task[uni_id]:
+ self.log.info("tech-profile-config-already-in-progress",
+ tp_path=tp_path)
+ return
+
+ tp = self.kv_client[tp_path]
+ tp = ast.literal_eval(tp)
+ self.log.debug("tp-instance", tp=tp)
+
+ tech_profile_id = self._tp_path_to_tp_id(tp_path)
+ self._do_tech_profile_configuration(uni_id, tp, tech_profile_id)
+
+ def success(_results):
+ self.log.info("tech-profile-config-done-successfully")
+ device = self.adapter_agent.get_device(self.device_id)
+ device.reason = ''
+ self.adapter_agent.update_device(device)
+
+ if tp_path in self._tp_service_specific_task[uni_id]:
+ del self._tp_service_specific_task[uni_id][tp_path]
+
+ self._tech_profile_download_done[uni_id][tp_path] = True
+
+ def failure(_reason):
+ self.log.warn('tech-profile-config-failure-retrying', reason=_reason)
+ device = self.adapter_agent.get_device(self.device_id)
+ device.reason = 'Tech Profile config failed-retrying'
+ self.adapter_agent.update_device(device)
+
+ if tp_path in self._tp_service_specific_task[uni_id]:
+ del self._tp_service_specific_task[uni_id][tp_path]
+
+ self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT,
+ self.load_and_configure_tech_profile,
+ uni_id, tp_path)
+
+ self.log.info('downloading-tech-profile-configuration')
+ tp_task = AdtnTpServiceSpecificTask(self.openomci.omci_agent, self, uni_id)
+
+ self._tp_service_specific_task[uni_id][tp_path] = tp_task
+ self._deferred = self.openomci.onu_omci_device.task_runner.queue_task(tp_task)
+ self._deferred.addCallbacks(success, failure)
+
+ except Exception as e:
+ self.log.exception("error-loading-tech-profile", e=e)
+ else:
+ self.log.info("tech-profile-config-already-done")
+
+ def update_pm_config(self, _device, pm_config):
+ # TODO: This has not been tested
+ self.log.info('update_pm_config', pm_config=pm_config)
+ self.pm_metrics.update(pm_config)
+
+ @inlineCallbacks
+ def update_flow_table(self, flows):
+ if len(flows) == 0:
+ returnValue('nop') # TODO: Do we need to delete all flows if empty?
+
+ self.log.debug('bulk-flow-update', flows=flows)
+ valid_flows = set()
+
+ for flow in flows:
+ # Decode it
+ flow_entry = FlowEntry.create(flow, self)
+
+ # Already handled?
+ if flow_entry.flow_id in self._flows:
+ valid_flows.add(flow_entry.flow_id)
+
+ if flow_entry is None or flow_entry.flow_direction not in \
+ FlowEntry.upstream_flow_types | FlowEntry.downstream_flow_types:
+ continue
+
+ is_upstream = flow_entry.flow_direction in FlowEntry.upstream_flow_types
+
+ # Ignore untagged upstream etherType flows. These are trapped at the
+ # OLT and the default flows during initial OMCI service download will
+ # send them to the Default VLAN (4091) port for us
+ if is_upstream and flow_entry.vlan_vid is None and flow_entry.etype is not None:
+ continue
+
+ # Also ignore upstream untagged/priority tag that sets priority tag
+ # since that is already installed and any user-data flows for upstream
+ # priority tag data will be at a higher level. Also should ignore the
+ # corresponding priority-tagged to priority-tagged flow as well.
+ if (flow_entry.vlan_vid == 0 and flow_entry.set_vlan_vid == 0) or \
+ (flow_entry.vlan_vid is None and flow_entry.set_vlan_vid == 0
+ and not is_upstream):
+ continue
+
+ # Add it to hardware
+ try:
+ def failed(_reason, fid):
+ del self._flows[fid]
+
+ task = AdtnInstallFlowTask(self.openomci.omci_agent, self, flow_entry)
+ d = self.openomci.onu_omci_device.task_runner.queue_task(task)
+ d.addErrback(failed, flow_entry.flow_id)
+
+ valid_flows.add(flow_entry.flow_id)
+ self._flows[flow_entry.flow_id] = flow_entry
+
+ except Exception as e:
+ self.log.exception('flow-add', e=e, flow=flow_entry)
+
+ # Now check for flows that were missing in the bulk update
+ deleted_flows = set(self._flows.keys()) - valid_flows
+
+ for flow_id in deleted_flows:
+ try:
+ del_flow = self._flows[flow_id]
+
+ task = AdtnRemoveFlowTask(self.openomci.omci_agent, self, del_flow)
+ self.openomci.onu_omci_device.task_runner.queue_task(task)
+ # TODO: Change to success/failure callback checks later
+ # d.addCallback(success, flow_entry.flow_id)
+ del self._flows[flow_id]
+
+ except Exception as e:
+ self.log.exception('flow-remove', e=e, flow=self._flows[flow_id])
+
+
+ def remove_from_flow_table(self, _flows):
+ """
+ Remove flows from the device
+
+ :param _flows: (list) Flows
+ """
+ raise NotImplementedError
+
+ def add_to_flow_table(self, _flows):
+ """
+ Remove flows from the device
+
+ :param _flows: (list) Flows
+ """
+ raise NotImplementedError
+
+ @inlineCallbacks
+ def reboot(self):
+ self.log.info('rebooting', device_id=self.device_id)
+ self._cancel_deferred()
+
+ reregister = False
+ try:
+ # Drop registration for adapter messages
+ reregister = True
+ self.adapter_agent.unregister_for_inter_adapter_messages()
+
+ except KeyError:
+ reregister = False
+
+ # Update the operational status to ACTIVATING and connect status to
+ # UNREACHABLE
+ device = self.adapter_agent.get_device(self.device_id)
+
+ previous_oper_status = device.oper_status
+ previous_conn_status = device.connect_status
+
+ device.oper_status = OperStatus.ACTIVATING
+ device.connect_status = ConnectStatus.UNREACHABLE
+ device.reason = 'Attempting reboot'
+ self.adapter_agent.update_device(device)
+
+ # TODO: send alert and clear alert after the reboot
+ try:
+ ######################################################
+ # MIB Reset
+ yield self.openomci.onu_omci_device.reboot(timeout=1)
+
+ except Exception as e:
+ self.log.exception('send-reboot', e=e)
+ raise
+
+ # Reboot in progress. A reboot may take up to 3 min 30 seconds
+ # Go ahead and pause less than that and start to look
+ # for it being alive
+ device.reason = 'reboot in progress'
+ self.adapter_agent.update_device(device)
+
+ # Disable OpenOMCI
+ self.omci.enabled = False
+ self._deferred = reactor.callLater(_ONU_REBOOT_MIN,
+ self._finish_reboot,
+ previous_oper_status,
+ previous_conn_status,
+ reregister)
+
+ @inlineCallbacks
+ def _finish_reboot(self, previous_oper_status, previous_conn_status,
+ reregister):
+ # Restart OpenOMCI
+ self.omci.enabled = True
+
+ device = self.adapter_agent.get_device(self.device_id)
+ device.oper_status = previous_oper_status
+ device.connect_status = previous_conn_status
+ device.reason = ''
+ self.adapter_agent.update_device(device)
+
+ if reregister:
+ self.adapter_agent.register_for_inter_adapter_messages()
+
+ self.log.info('reboot-complete', device_id=self.device_id)
+
+ def self_test_device(self, device):
+ """
+ This is called to Self a device based on a NBI call.
+ :param device: A Voltha.Device object.
+ :return: Will return result of self test
+ """
+ from pyvoltha.protos.voltha_pb2 import SelfTestResponse
+ self.log.info('self-test-device', device=device.id)
+ # TODO: Support self test?
+ return SelfTestResponse(result=SelfTestResponse.NOT_SUPPORTED)
+
+ def disable(self):
+ self.log.info('disabling', device_id=self.device_id)
+ try:
+ # Get the latest device reference
+ device = self.adapter_agent.get_device(self.device_id)
+
+ # Disable all ports on that device
+ self.adapter_agent.disable_all_ports(self.device_id)
+
+ # Update the device operational status to UNKNOWN
+ device.oper_status = OperStatus.UNKNOWN
+ device.connect_status = ConnectStatus.UNREACHABLE
+ device.reason = 'Disabled'
+ self.adapter_agent.update_device(device)
+
+ # Remove the uni logical port from the OLT, if still present
+ parent_device = self.adapter_agent.get_device(device.parent_id)
+ assert parent_device
+
+ for uni in self.uni_ports:
+ # port_id = 'uni-{}'.format(uni.port_number)
+ port_id = uni.port_id_name()
+ try:
+ logical_device_id = parent_device.parent_id
+ assert logical_device_id
+ port = self.adapter_agent.get_logical_port(logical_device_id,port_id)
+ self.adapter_agent.delete_logical_port(logical_device_id, port)
+ except KeyError:
+ self.log.info('logical-port-not-found', device_id=self.device_id,
+ portid=port_id)
+
+ # Remove pon port from parent and disable
+ if self._pon is not None:
+ self.adapter_agent.delete_port_reference_from_parent(self.device_id,
+ self._pon.get_port())
+ self._pon.enabled = False
+
+ # Unregister for proxied message
+ self.adapter_agent.unregister_for_proxied_messages(device.proxy_address)
+
+ except Exception as _e:
+ pass # This is expected if OLT has deleted the ONU device handler
+
+ # And disable OMCI as well
+ self.enabled = False
+ self.log.info('disabled')
+
+ def reenable(self):
+ self.log.info('re-enabling', device_id=self.device_id)
+ try:
+ # Get the latest device reference
+ device = self.adapter_agent.get_device(self.device_id)
+ self._cancel_deferred()
+
+ # First we verify that we got parent reference and proxy info
+ assert device.parent_id
+ assert device.proxy_address.device_id
+ # assert device.proxy_address.channel_id
+
+ # Re-register for proxied messages right away
+ self.proxy_address = device.proxy_address
+ self.adapter_agent.register_for_proxied_messages(
+ device.proxy_address)
+
+ # Re-enable the ports on that device
+ self.adapter_agent.enable_all_ports(self.device_id)
+
+ # Add the pon port reference to the parent
+ if self._pon is not None:
+ self._pon.enabled = True
+ self.adapter_agent.add_port_reference_to_parent(device.id,
+ self._pon.get_port())
+ # Update the connect status to REACHABLE
+ device.connect_status = ConnectStatus.REACHABLE
+ self.adapter_agent.update_device(device)
+
+ # re-add uni port to logical device
+ parent_device = self.adapter_agent.get_device(device.parent_id)
+ self.logical_device_id = parent_device.parent_id
+ assert self.logical_device_id, 'Invalid logical device ID'
+
+ # reestablish logical ports for each UNI
+ multi_uni = len(self.uni_ports) > 1
+ for uni in self.uni_ports:
+ self.adapter_agent.add_port(device.id, uni.get_port())
+ uni.add_logical_port(uni.logical_port_number, multi_uni)
+
+ device = self.adapter_agent.get_device(device.id)
+ device.oper_status = OperStatus.ACTIVE
+ device.connect_status = ConnectStatus.REACHABLE
+ device.reason = ''
+
+ self.enabled = True
+ self.adapter_agent.update_device(device)
+
+ self.log.info('re-enabled')
+
+ except Exception, e:
+ self.log.exception('error-re-enabling', e=e)
+
+ def delete(self):
+ self.log.info('deleting', device_id=self.device_id)
+
+ try:
+ for uni in self._unis.values():
+ uni.stop()
+ uni.delete()
+
+ self._pon.stop()
+ self._pon.delete()
+
+ except Exception as _e:
+ pass # Expected if the OLT deleted us from the device handler
+
+ # OpenOMCI cleanup
+ omci, self._openomci = self._openomci, None
+ omci.delete()
+
+ def add_uni_ports(self):
+ """ Called after in-sync achieved and not in xPON mode"""
+ # TODO: We have to methods adding UNI ports. Go to one
+ # TODO: Should this be moved to the omci.py module for this ONU?
+
+ # This is only for working WITHOUT xPON
+ pptp_entities = self.openomci.onu_omci_device.configuration.pptp_entities
+ device = self.adapter_agent.get_device(self.device_id)
+
+ multi_uni = len(pptp_entities) > 1
+ uni_id = 0
+
+ for entity_id, pptp in pptp_entities.items():
+ intf_id = self.proxy_address.channel_id
+ onu_id = self.proxy_address.onu_id
+ uni_no = platform.mk_uni_port_num(intf_id, onu_id, uni_id=uni_id)
+ uni_name = "uni-{}".format(uni_no)
+ mac_bridge_port_num = uni_id + 1
+
+ uni_port = UniPort.create(self, uni_name, uni_no, uni_name)
+ uni_port.entity_id = entity_id
+ uni_port.enabled = True
+ uni_port.mac_bridge_port_num = mac_bridge_port_num
+ uni_port.add_logical_port(uni_port.port_number, multi_uni)
+ self.log.debug("created-uni-port", uni=uni_port)
+
+ self.adapter_agent.add_port(device.id, uni_port.get_port())
+ parent_device = self.adapter_agent.get_device(device.parent_id)
+
+ parent_adapter_agent = registry('adapter_loader').get_agent(parent_device.adapter)
+ if parent_adapter_agent is None:
+ self.log.error('olt-adapter-agent-could-not-be-retrieved')
+
+ parent_adapter_agent.add_port(device.parent_id, uni_port.get_port())
+
+ self._unis[uni_port.port_number] = uni_port
+ self.openomci.onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self.proxy_address.onu_id,
+ uni_ports=self._unis.values())
+ # TODO: this should be in the PonPort class
+ pon_port = self._pon.get_port()
+ self.adapter_agent.delete_port_reference_from_parent(self.device_id,
+ pon_port)
+ # Find index where this ONU peer is (should almost always be zero)
+ d = [i for i, e in enumerate(pon_port.peers) if
+ e.port_no == intf_id and e.device_id == device.parent_id]
+
+ if len(d) > 0:
+ pon_port.peers[d[0]].port_no = uni_port.port_number
+ self.adapter_agent.add_port_reference_to_parent(self.device_id,
+ pon_port)
+ self.adapter_agent.update_device(device)
+ uni_port.enabled = True
+ uni_id += 1
+
+ def rx_inter_adapter_message(self, msg):
+ raise NotImplemented('Not currently supported')
+
+ def _subscribe_to_events(self):
+ from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
+ OnuDeviceEntry
+
+ # OMCI MIB Database sync status
+ bus = self.openomci.onu_omci_device.event_bus
+ topic = OnuDeviceEntry.event_bus_topic(self.device_id,
+ OnuDeviceEvents.MibDatabaseSyncEvent)
+ self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
+
+ def _unsubscribe_to_events(self):
+ insync, self._in_sync_subscription = self._in_sync_subscription, None
+
+ if insync is not None:
+ bus = self.openomci.onu_omci_device.event_bus
+ bus.unsubscribe(insync)
+
+ def in_sync_handler(self, _topic, msg):
+ # Create UNI Ports on first In-Sync event
+ if self._in_sync_subscription is not None:
+ try:
+ from pyvoltha.adapters.extensions.omci.onu_device_entry import IN_SYNC_KEY
+
+ if msg[IN_SYNC_KEY]:
+ # Do not proceed if we have not got our vENET information yet.
+
+ if len(self.uni_ports) == 0:
+ # Drop subscription....
+ insync, self._in_sync_subscription = self._in_sync_subscription, None
+
+ if insync is not None:
+ bus = self.openomci.onu_omci_device.event_bus
+ bus.unsubscribe(insync)
+
+ # Set up UNI Ports. The UNI ports are currently created when the xPON
+ # vENET information is created. Once xPON is removed, we need to create
+ # them from the information provided from the MIB upload UNI-G and other
+ # UNI related MEs.
+ self.add_uni_ports()
+
+ except Exception as e:
+ self.log.exception('in-sync', e=e)
diff --git a/adapters/adtran_onu/flow/__init__.py b/adapters/adtran_onu/flow/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/adapters/adtran_onu/flow/__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/adapters/adtran_onu/flow/flow_entry.py b/adapters/adtran_onu/flow/flow_entry.py
new file mode 100644
index 0000000..d3ec17d
--- /dev/null
+++ b/adapters/adtran_onu/flow/flow_entry.py
@@ -0,0 +1,272 @@
+# 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 enum import IntEnum
+from pyvoltha.common.openflow.utils import *
+from pyvoltha.protos.openflow_13_pb2 import OFPP_MAX
+
+log = structlog.get_logger()
+
+# IP Protocol numbers
+_supported_ip_protocols = [
+ 1, # ICMP
+ 2, # IGMP
+ 6, # TCP
+ 17, # UDP
+]
+
+
+class FlowEntry(object):
+ """
+ Provide a class that wraps the flow rule and also provides state/status for a FlowEntry.
+
+ When a new flow is sent, it is first decoded to check for any potential errors. If None are
+ found, the entry is created and it is analyzed to see if it can be combined to with any other flows
+ to create or modify an existing EVC.
+
+ Note: Since only E-LINE is supported, modification of an existing EVC is not performed.
+ """
+ class FlowDirection(IntEnum):
+ UPSTREAM = 0 # UNI port to ANI Port
+ DOWNSTREAM = 1 # ANI port to UNI Port
+ ANI = 2 # ANI port to ANI Port
+ UNI = 3 # UNI port to UNI Port
+ OTHER = 4 # Unable to determine
+
+ _flow_dir_map = {
+ (FlowDirection.UNI, FlowDirection.ANI): FlowDirection.UPSTREAM,
+ (FlowDirection.ANI, FlowDirection.UNI): FlowDirection.DOWNSTREAM
+ }
+
+ upstream_flow_types = {FlowDirection.UPSTREAM}
+ downstream_flow_types = {FlowDirection.DOWNSTREAM}
+
+ # Well known EtherTypes
+ class EtherType(IntEnum):
+ EAPOL = 0x888E
+ IPv4 = 0x0800
+ IPv6 = 0x86DD
+ ARP = 0x0806
+ LLDP = 0x88CC
+
+ # Well known IP Protocols
+ class IpProtocol(IntEnum):
+ IGMP = 2
+ UDP = 17
+
+ def __init__(self, flow, handler):
+ self._handler = handler
+ self.flow_id = flow.id
+ self._flow_direction = FlowEntry.FlowDirection.OTHER
+ self._is_multicast = False
+ self.tech_profile_id = None
+
+ # Selection properties
+ self.in_port = None
+ self.vlan_vid = None
+ self.vlan_pcp = None
+ self.etype = None
+ self.proto = None
+ self.ipv4_dst = None
+ self.udp_dst = None # UDP Port #
+ self.udp_src = None # UDP Port #
+ self.inner_vid = None
+
+ # Actions
+ self.out_port = None
+ self.pop_vlan = False
+ self.push_vlan_tpid = None
+ self.set_vlan_vid = None
+ self._name = self.create_flow_name()
+
+ def __str__(self):
+ return 'flow_entry: {}, in: {}, out: {}, vid: {}, inner:{}, eth: {}, IP: {}'.format(
+ self.name, self.in_port, self.out_port, self.vlan_vid, self.inner_vid,
+ self.etype, self.proto)
+
+ def __repr__(self):
+ return str(self)
+
+ @property
+ def name(self):
+ return self._name # TODO: Is a name really needed in production?
+
+ def create_flow_name(self):
+ return 'flow-{}-{}'.format(self.device_id, self.flow_id)
+
+ @property
+ def handler(self):
+ return self._handler
+
+ @property
+ def device_id(self):
+ return self.handler.device_id
+
+ @property
+ def flow_direction(self):
+ return self._flow_direction
+
+ @property
+ def is_multicast_flow(self):
+ return self._is_multicast
+
+ @staticmethod
+ def create(flow, handler):
+ """
+ Create the appropriate FlowEntry wrapper for the flow. This method returns a two
+ results.
+
+ The first result is the flow entry that was created. This could be a match to an
+ existing flow since it is a bulk update. None is returned only if no match to
+ an existing entry is found and decode failed (unsupported field)
+
+ :param flow: (Flow) Flow entry passed to VOLTHA adapter
+ :param handler: (DeviceHandler) handler for the device
+ :return: (FlowEntry) Created flow entry, None on decode failure
+ """
+ # Exit early if it already exists
+ try:
+ flow_entry = FlowEntry(flow, handler)
+
+ if not flow_entry.decode(flow):
+ return None
+
+ # TODO: Do we want to do the OMCI here ?
+
+ return flow_entry
+
+ except Exception as e:
+ log.exception('flow-entry-processing', e=e)
+ return None
+
+ def decode(self, flow):
+ """
+ Examine flow rules and extract appropriate settings
+ """
+ log.debug('start-decode')
+ status = self._decode_traffic_selector(flow) and self._decode_traffic_treatment(flow)
+
+ if status:
+ ani_ports = [pon.port_number for pon in self._handler.pon_ports]
+ uni_ports = [uni.port_number for uni in self._handler.uni_ports]
+
+ # Determine direction of the flow
+ def port_type(port_number):
+ if port_number in ani_ports:
+ return FlowEntry.FlowDirection.ANI
+
+ elif port_number in uni_ports:
+ return FlowEntry.FlowDirection.UNI
+
+ return FlowEntry.FlowDirection.OTHER
+
+ self._flow_direction = FlowEntry._flow_dir_map.get((port_type(self.in_port),
+ port_type(self.out_port)),
+ FlowEntry.FlowDirection.OTHER)
+ return status
+
+ def _decode_traffic_selector(self, flow):
+ """
+ Extract traffic selection settings
+ """
+ self.in_port = get_in_port(flow)
+
+ if self.in_port > OFPP_MAX:
+ log.warn('logical-input-ports-not-supported')
+ return False
+
+ for field in get_ofb_fields(flow):
+ if field.type == IN_PORT:
+ assert self.in_port == field.port, 'Multiple Input Ports found in flow rule'
+
+ elif field.type == VLAN_VID:
+ self.vlan_vid = field.vlan_vid & 0xfff
+ log.debug('*** field.type == VLAN_VID', value=field.vlan_vid, vlan_id=self.vlan_vid)
+ self._is_multicast = False # TODO: self.vlan_id in self._handler.multicast_vlans
+
+ elif field.type == VLAN_PCP:
+ log.debug('*** field.type == VLAN_PCP', value=field.vlan_pcp)
+ self.vlan_pcp = field.vlan_pcp
+
+ elif field.type == ETH_TYPE:
+ log.debug('*** field.type == ETH_TYPE', value=field.eth_type)
+ self.etype = field.eth_type
+
+ elif field.type == IP_PROTO:
+ log.debug('*** field.type == IP_PROTO', value=field.ip_proto)
+ self.proto = field.ip_proto
+
+ if self.proto not in _supported_ip_protocols:
+ log.error('Unsupported IP Protocol', ip_proto=self.proto)
+ return False
+
+ elif field.type == IPV4_DST:
+ log.debug('*** field.type == IPV4_DST', value=field.ipv4_dst)
+ self.ipv4_dst = field.ipv4_dst
+
+ elif field.type == UDP_DST:
+ log.debug('*** field.type == UDP_DST', value=field.udp_dst)
+ self.udp_dst = field.udp_dst
+
+ elif field.type == UDP_SRC:
+ log.debug('*** field.type == UDP_SRC', value=field.udp_src)
+ self.udp_src = field.udp_src
+
+ elif field.type == METADATA:
+ log.debug('*** field.type == METADATA', value=field.table_metadata)
+ self.inner_vid = field.table_metadata
+ log.debug('*** field.type == METADATA', value=field.table_metadata,
+ inner_vid=self.inner_vid)
+ else:
+ log.warn('unsupported-selection-field', type=field.type)
+ self._status_message = 'Unsupported field.type={}'.format(field.type)
+ return False
+
+ return True
+
+ def _decode_traffic_treatment(self, flow):
+ self.out_port = get_out_port(flow)
+
+ if self.out_port > OFPP_MAX:
+ log.warn('logical-output-ports-not-supported')
+ return False
+
+ for act in get_actions(flow):
+ if act.type == OUTPUT:
+ assert self.out_port == act.output.port, 'Multiple Output Ports found in flow rule'
+ pass # Handled earlier
+
+ elif act.type == POP_VLAN:
+ log.debug('*** action.type == POP_VLAN')
+ self.pop_vlan = True
+
+ elif act.type == PUSH_VLAN:
+ log.debug('*** action.type == PUSH_VLAN', value=act.push)
+ tpid = act.push.ethertype
+ self.push_tpid = tpid
+ assert tpid == 0x8100, 'Only TPID 0x8100 is currently supported'
+
+ elif act.type == SET_FIELD:
+ log.debug('*** action.type == SET_FIELD', value=act.set_field.field)
+ assert (act.set_field.field.oxm_class == ofp.OFPXMC_OPENFLOW_BASIC)
+ field = act.set_field.field.ofb_field
+ if field.type == VLAN_VID:
+ self.set_vlan_vid = field.vlan_vid & 0xfff
+
+ else:
+ log.warn('unsupported-action', action=act)
+ self._status_message = 'Unsupported action.type={}'.format(act.type)
+ return False
+
+ return True
diff --git a/adapters/adtran_onu/heartbeat.py b/adapters/adtran_onu/heartbeat.py
new file mode 100644
index 0000000..a29e8ac
--- /dev/null
+++ b/adapters/adtran_onu/heartbeat.py
@@ -0,0 +1,179 @@
+# 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.
+
+import structlog
+from twisted.internet import reactor
+from pyvoltha.protos.common_pb2 import OperStatus, ConnectStatus
+from pyvoltha.adapters.extensions.omci.omci_me import OntGFrame
+
+
+class HeartBeat(object):
+ """Wraps health-check support for ONU"""
+ INITIAL_DELAY = 60 # Delay after start until first check
+ TICK_DELAY = 2 # Heartbeat interval
+
+ def __init__(self, handler, device_id):
+ self.log = structlog.get_logger(device_id=device_id)
+ self._enabled = False
+ self._handler = handler
+ self._device_id = device_id
+ self._defer = None
+ self._alarm_active = False
+ self._heartbeat_count = 0
+ self._heartbeat_miss = 0
+ self._alarms_raised_count = 0
+ self.heartbeat_failed_limit = 5
+ self.heartbeat_last_reason = ''
+ self.heartbeat_interval = self.TICK_DELAY
+
+ def __str__(self):
+ return "HeartBeat: count:{}, miss: {}".format(self._heartbeat_count,
+ self._heartbeat_miss)
+
+ @staticmethod
+ def create(handler, device_id):
+ return HeartBeat(handler, device_id)
+
+ def _start(self, delay=INITIAL_DELAY):
+ self._defer = reactor.callLater(delay, self.check_pulse)
+
+ def _stop(self):
+ d, self._defeered = self._defeered, None
+ if d is not None and not d.called():
+ d.cancel()
+
+ @property
+ def enabled(self):
+ return self._enabled
+
+ @enabled.setter
+ def enabled(self, value):
+ if self._enabled != value:
+ self._enabled = value
+
+ # if value:
+ # self._start()
+ # else:
+ # self._stop()
+
+ @property
+ def check_item(self):
+ return 'vendor_id'
+
+ @property
+ def check_value(self):
+ # device = self._handler.adapter_agent.get_device(self._device_id)
+ # return device.serial_number
+ return 'ADTN'
+
+ @property
+ def alarm_active(self):
+ return self._alarm_active
+
+ @property
+ def heartbeat_count(self):
+ return self._heartbeat_count
+
+ @property
+ def heartbeat_miss(self):
+ return self._heartbeat_miss
+
+ @property
+ def alarms_raised_count(self):
+ return self._alarms_raised_count
+
+ def check_pulse(self):
+ if self.enabled:
+ try:
+ self._defer = self._handler.openomci.omci_cc.send(OntGFrame(self.check_item).get())
+ self._defer.addCallbacks(self._heartbeat_success, self._heartbeat_fail)
+
+ except Exception as e:
+ self._defer = reactor.callLater(5, self._heartbeat_fail, e)
+
+ def _heartbeat_success(self, results):
+ self.log.debug('heartbeat-success')
+
+ try:
+ omci_response = results.getfieldval("omci_message")
+ data = omci_response.getfieldval("data")
+ value = data[self.check_item]
+
+ if value != self.check_value:
+ self._heartbeat_miss = self.heartbeat_failed_limit
+ self.heartbeat_last_reason = "Invalid {}, got '{}' but expected '{}'".\
+ format(self.check_item, value, self.check_value)
+ else:
+ self._heartbeat_miss = 0
+ self.heartbeat_last_reason = ''
+
+ except Exception as e:
+ self._heartbeat_miss = self.heartbeat_failed_limit
+ self.heartbeat_last_reason = e.message
+
+ self.heartbeat_check_status(results)
+
+ def _heartbeat_fail(self, failure):
+ self._heartbeat_miss += 1
+ self.log.info('heartbeat-miss', failure=failure,
+ count=self._heartbeat_count,
+ miss=self._heartbeat_miss)
+ self.heartbeat_last_reason = 'OMCI connectivity error'
+ self.heartbeat_check_status(None)
+
+ def on_heartbeat_alarm(self, active):
+ # TODO: Do something here ?
+ #
+ # TODO: If failed (active = true) due to bad serial-number shut off the UNI port?
+ pass
+
+ def heartbeat_check_status(self, results):
+ """
+ Check the number of heartbeat failures against the limit and emit an alarm if needed
+ """
+ device = self._handler.adapter_agent.get_device(self._device_id)
+
+ try:
+ from voltha.extensions.alarms.heartbeat_alarm import HeartbeatAlarm
+
+ if self._heartbeat_miss >= self.heartbeat_failed_limit:
+ if device.connect_status == ConnectStatus.REACHABLE:
+ self.log.warning('heartbeat-failed', count=self._heartbeat_miss)
+ device.connect_status = ConnectStatus.UNREACHABLE
+ device.oper_status = OperStatus.FAILED
+ device.reason = self.heartbeat_last_reason
+ self._handler.adapter_agent.update_device(device)
+ HeartbeatAlarm(self._handler.alarms, 'onu', self._heartbeat_miss).raise_alarm()
+ self._alarm_active = True
+ self.on_heartbeat_alarm(True)
+ else:
+ # Update device states
+ if device.connect_status != ConnectStatus.REACHABLE and self._alarm_active:
+ device.connect_status = ConnectStatus.REACHABLE
+ device.oper_status = OperStatus.ACTIVE
+ device.reason = ''
+ self._handler.adapter_agent.update_device(device)
+ HeartbeatAlarm(self._handler.alarms, 'onu').clear_alarm()
+
+ self._alarm_active = False
+ self._alarms_raised_count += 1
+ self.on_heartbeat_alarm(False)
+
+ except Exception as e:
+ self.log.exception('heartbeat-check', e=e)
+
+ # Reschedule next heartbeat
+ if self.enabled:
+ self._heartbeat_count += 1
+ self._defer = reactor.callLater(self.heartbeat_interval, self.check_pulse)
diff --git a/adapters/adtran_onu/main.py b/adapters/adtran_onu/main.py
new file mode 100755
index 0000000..e19f320
--- /dev/null
+++ b/adapters/adtran_onu/main.py
@@ -0,0 +1,558 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+"""Adtran ONU Adapter main entry point"""
+
+import argparse
+import os
+import time
+
+import arrow
+import yaml
+from packaging.version import Version
+from simplejson import dumps
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.task import LoopingCall
+from zope.interface import implementer
+
+from pyvoltha.common.structlog_setup import setup_logging, update_logging
+from pyvoltha.common.utils.asleep import asleep
+from pyvoltha.common.utils.deferred_utils import TimeOutError
+from pyvoltha.common.utils.dockerhelpers import get_my_containers_name
+from pyvoltha.common.utils.nethelpers import get_my_primary_local_ipv4, \
+ get_my_primary_interface
+from pyvoltha.common.utils.registry import registry, IComponent
+from pyvoltha.adapters.kafka.adapter_proxy import AdapterProxy
+from pyvoltha.adapters.kafka.adapter_request_facade import AdapterRequestFacade
+from pyvoltha.adapters.kafka.core_proxy import CoreProxy
+from pyvoltha.adapters.kafka.kafka_inter_container_library import IKafkaMessagingProxy, \
+ get_messaging_proxy
+from pyvoltha.adapters.kafka.kafka_proxy import KafkaProxy, get_kafka_proxy
+from adtran_onu import AdtranOnuAdapter
+from pyvoltha.protos import third_party
+from pyvoltha.protos.adapter_pb2 import AdapterConfig
+
+_ = third_party
+
+
+defs = dict(
+ version_file='./VERSION',
+ config=os.environ.get('CONFIG', './adapters-adtran_onu.yml'),
+ container_name_regex=os.environ.get('CONTAINER_NUMBER_EXTRACTOR', '^.*\.(['
+ '0-9]+)\..*$'),
+ consul=os.environ.get('CONSUL', 'localhost:8500'),
+ name=os.environ.get('NAME', 'adtran_onu'),
+ vendor=os.environ.get('VENDOR', 'Voltha Project'),
+ device_type=os.environ.get('DEVICE_TYPE', 'adtran_onu'),
+ accept_bulk_flow=os.environ.get('ACCEPT_BULK_FLOW', True),
+ accept_atomic_flow=os.environ.get('ACCEPT_ATOMIC_FLOW', True),
+ etcd=os.environ.get('ETCD', 'localhost:2379'),
+ core_topic=os.environ.get('CORE_TOPIC', 'rwcore'),
+ interface=os.environ.get('INTERFACE', get_my_primary_interface()),
+ instance_id=os.environ.get('INSTANCE_ID', os.environ.get('HOSTNAME', '1')),
+ kafka_adapter=os.environ.get('KAFKA_ADAPTER', '172.20.10.3:9092'),
+ kafka_cluster=os.environ.get('KAFKA_CLUSTER', '172.20.10.3:9092'),
+ backend=os.environ.get('BACKEND', 'none'),
+ retry_interval=os.environ.get('RETRY_INTERVAL', 2),
+ heartbeat_topic=os.environ.get('HEARTBEAT_TOPIC', "adapters.heartbeat"),
+
+ # Following are for debugging
+ debug_enabled=True,
+ debug_host='work.bcsw.net',
+ # debug_host='10.0.2.15',
+ debug_port=5678,
+)
+
+
+def parse_args():
+ parser = argparse.ArgumentParser()
+
+ _help = ('Path to adapters-adtran_onu.yml config file (default: %s). '
+ 'If relative, it is relative to main.py of Adtran ONU adapter.'
+ % defs['config'])
+ parser.add_argument('-c', '--config',
+ dest='config',
+ action='store',
+ default=defs['config'],
+ help=_help)
+
+ _help = 'Regular expression for extracting container number from ' \
+ 'container name (default: %s)' % defs['container_name_regex']
+ parser.add_argument('-X', '--container-number-extractor',
+ dest='container_name_regex',
+ action='store',
+ default=defs['container_name_regex'],
+ help=_help)
+
+ _help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
+ parser.add_argument('-C', '--consul',
+ dest='consul',
+ action='store',
+ default=defs['consul'],
+ help=_help)
+
+ _help = 'name of this adapter (default: %s)' % defs['name']
+ parser.add_argument('-na', '--name',
+ dest='name',
+ action='store',
+ default=defs['name'],
+ help=_help)
+
+ _help = 'vendor of this adapter (default: %s)' % defs['vendor']
+ parser.add_argument('-ven', '--vendor',
+ dest='vendor',
+ action='store',
+ default=defs['vendor'],
+ help=_help)
+
+ _help = 'supported device type of this adapter (default: %s)' % defs[
+ 'device_type']
+ parser.add_argument('-dt', '--device_type',
+ dest='device_type',
+ action='store',
+ default=defs['device_type'],
+ help=_help)
+
+ _help = 'specifies whether the device type accepts bulk flow updates ' \
+ 'adapter (default: %s)' % defs['accept_bulk_flow']
+ parser.add_argument('-abf', '--accept_bulk_flow',
+ dest='accept_bulk_flow',
+ action='store',
+ default=defs['accept_bulk_flow'],
+ help=_help)
+
+ _help = 'specifies whether the device type accepts add/remove flow ' \
+ '(default: %s)' % defs['accept_atomic_flow']
+ parser.add_argument('-aaf', '--accept_atomic_flow',
+ dest='accept_atomic_flow',
+ action='store',
+ default=defs['accept_atomic_flow'],
+ help=_help)
+
+ _help = '<hostname>:<port> to etcd server (default: %s)' % defs['etcd']
+ parser.add_argument('-e', '--etcd',
+ dest='etcd',
+ action='store',
+ default=defs['etcd'],
+ help=_help)
+
+ _help = ('unique string id of this container instance (default: %s)'
+ % defs['instance_id'])
+ parser.add_argument('-i', '--instance-id',
+ dest='instance_id',
+ action='store',
+ default=defs['instance_id'],
+ help=_help)
+
+ _help = 'ETH interface to recieve (default: %s)' % defs['interface']
+ parser.add_argument('-I', '--interface',
+ dest='interface',
+ action='store',
+ default=defs['interface'],
+ help=_help)
+
+ _help = 'omit startup banner log lines'
+ parser.add_argument('-n', '--no-banner',
+ dest='no_banner',
+ action='store_true',
+ default=False,
+ help=_help)
+
+ _help = 'do not emit periodic heartbeat log messages'
+ parser.add_argument('-N', '--no-heartbeat',
+ dest='no_heartbeat',
+ action='store_true',
+ default=False,
+ help=_help)
+
+ _help = "suppress debug and info logs"
+ parser.add_argument('-q', '--quiet',
+ dest='quiet',
+ action='count',
+ help=_help)
+
+ _help = 'enable verbose logging'
+ parser.add_argument('-v', '--verbose',
+ dest='verbose',
+ action='count',
+ help=_help)
+
+ _help = ('use docker container name as container instance id'
+ ' (overrides -i/--instance-id option)')
+ parser.add_argument('--instance-id-is-container-name',
+ dest='instance_id_is_container_name',
+ action='store_true',
+ default=False,
+ help=_help)
+
+ _help = ('<hostname>:<port> of the kafka adapter broker (default: %s). ('
+ 'If not '
+ 'specified (None), the address from the config file is used'
+ % defs['kafka_adapter'])
+ parser.add_argument('-KA', '--kafka_adapter',
+ dest='kafka_adapter',
+ action='store',
+ default=defs['kafka_adapter'],
+ help=_help)
+
+ _help = ('<hostname>:<port> of the kafka cluster broker (default: %s). ('
+ 'If not '
+ 'specified (None), the address from the config file is used'
+ % defs['kafka_cluster'])
+ parser.add_argument('-KC', '--kafka_cluster',
+ dest='kafka_cluster',
+ action='store',
+ default=defs['kafka_cluster'],
+ help=_help)
+
+ _help = 'backend to use for config persistence'
+ parser.add_argument('-b', '--backend',
+ default=defs['backend'],
+ choices=['none', 'consul', 'etcd'],
+ help=_help)
+
+ _help = 'topic of core on the kafka bus'
+ parser.add_argument('-ct', '--core_topic',
+ dest='core_topic',
+ action='store',
+ default=defs['core_topic'],
+ help=_help)
+
+ _help = 'Enable remote python debug'
+ parser.add_argument('-de', '--debug_enabled',
+ dest='debug_enabled',
+ action='store_true',
+ default=defs['debug_enabled'],
+ help=_help)
+
+ _help = 'remote debug hostname or IP address'
+ parser.add_argument('-dh', '--debug_host',
+ dest='debug_host',
+ action='store',
+ default=defs['debug_host'],
+ help=_help)
+
+ _help = 'remote debug port number'
+ parser.add_argument('-dp', '--debug_port',
+ dest='debug_port',
+ action='store',
+ default=defs['debug_port'],
+ help=_help)
+
+ args = parser.parse_args()
+
+ # post-processing
+
+ if args.instance_id_is_container_name:
+ args.instance_id = get_my_containers_name()
+
+ return args
+
+
+def setup_remote_debug(host, port, logger):
+ try:
+ import sys
+ sys.path.append('/voltha/pydevd/pycharm-debug.egg')
+ import pydevd
+ # Initial breakpoint
+
+ pydevd.settrace(host, port=port, stdoutToServer=True, stderrToServer=True, suspend=False)
+
+ except ImportError:
+ logger.error('Error importing pydevd package')
+ logger.error('REMOTE DEBUGGING will not be supported in this run...')
+ # Continue on, you do not want to completely kill VOLTHA, you just need to fix it.
+
+ except AttributeError:
+ logger.error('Attribute error. Perhaps try to explicitly set PYTHONPATH to'
+ 'pydevd directory and rlogger.errorun again?')
+ logger.error('REMOTE DEBUGGING will not be supported in this run...')
+ # Continue on, you do not want to completely kill VOLTHA, you just need to fix it.
+
+ except:
+ import sys
+ logger.error("pydevd startup exception: %s" % sys.exc_info()[0])
+ print('REMOTE DEBUGGING will not be supported in this run...')
+
+
+def load_config(args):
+ path = args.config
+ if path.startswith('.'):
+ dir = os.path.dirname(os.path.abspath(__file__))
+ path = os.path.join(dir, path)
+ path = os.path.abspath(path)
+ with open(path) as fd:
+ config = yaml.load(fd)
+ return config
+
+
+def print_banner(log):
+ log.info(" _____ _______ _____ _ _ ____ _ _______ ")
+ log.info(" /\ | __ \__ __| __ \ /\ | \ | | / __ \| \ | | | | |")
+ log.info(" / \ | | | | | | | |__) | / \ | \| | | | | | \| | | | |")
+ log.info(" / /\ \ | | | | | | | _ / / /\ \ | . ` | | | | | . ` | | | |")
+ log.info(" / ____ \| |__| | | | | | \ \ / ____ \| |\ | | |__| | |\ | |__| |")
+ log.info(" /_/ \_\_____/ |_| |_| _\_\/_/ \_\_| \_| \____/|_| \_|\____/ ")
+ log.info(" /\ | | | | ")
+ log.info(" / \ __| | __ _ _ __ | |_ ___ _ __ ")
+ log.info(" / /\ \ / _` |/ _` | '_ \| __/ _ \ '__| ")
+ log.info(" / ____ \ (_| | (_| | |_) | || __/ | ")
+ log.info(" /_/ \_\__,_|\__,_| .__/ \__\___|_| ")
+ log.info(" | | ")
+ log.info(" |_| ")
+ log.info("")
+ log.info('(to stop: press Ctrl-C)')
+
+
+@implementer(IComponent)
+class Main(object):
+
+ def __init__(self):
+
+ self.args = args = parse_args()
+ self.config = load_config(args)
+
+ verbosity_adjust = (args.verbose or 0) - (args.quiet or 0)
+ self.log = setup_logging(self.config.get('logging', {}),
+ args.instance_id,
+ verbosity_adjust=verbosity_adjust)
+ self.log.info('container-number-extractor',
+ regex=args.container_name_regex)
+
+ if args.debug_enabled:
+ setup_remote_debug(args.debug_host, args.debug_port, self.log)
+
+ self.adtran_onu_adapter_version = self.get_version()
+ self.log.info('ADTRAN-ONU-Adapter-Version', version=self.adtran_onu_adapter_version)
+
+ if not args.no_banner:
+ print_banner(self.log)
+
+ self.adapter = None
+ self.core_proxy = None
+ self.adapter_proxy = None
+
+ # Create a unique instance id using the passed-in instance id and
+ # UTC timestamp
+ current_time = arrow.utcnow().timestamp
+ self.instance_id = self.args.instance_id + '_' + str(current_time)
+
+ self.core_topic = args.core_topic
+ self.listening_topic = args.name
+ self.startup_components()
+
+ if not args.no_heartbeat:
+ self.start_heartbeat()
+ self.start_kafka_cluster_heartbeat(self.instance_id)
+
+ def get_version(self):
+ path = defs['version_file']
+ if not path.startswith('/'):
+ dir = os.path.dirname(os.path.abspath(__file__))
+ path = os.path.join(dir, path)
+
+ path = os.path.abspath(path)
+ version_file = open(path, 'r')
+ v = version_file.read()
+
+ # Use Version to validate the version string - exception will be raised
+ # if the version is invalid
+ Version(v)
+
+ version_file.close()
+ return v
+
+ def start(self):
+ self.start_reactor() # will not return except Keyboard interrupt
+
+ def stop(self):
+ pass
+
+ def get_args(self):
+ """Allow access to command line args"""
+ return self.args
+
+ def get_config(self):
+ """Allow access to content of config file"""
+ return self.config
+
+ def _get_adapter_config(self):
+ cfg = AdapterConfig()
+ return cfg
+
+ @inlineCallbacks
+ def startup_components(self):
+ try:
+ self.log.info('starting-internal-components',
+ consul=self.args.consul,
+ etcd=self.args.etcd)
+
+ registry.register('main', self)
+
+ # Update the logger to output the vcore id.
+ self.log = update_logging(instance_id=self.instance_id,
+ vcore_id=None)
+
+ yield registry.register(
+ 'kafka_cluster_proxy',
+ KafkaProxy(
+ self.args.consul,
+ self.args.kafka_cluster,
+ config=self.config.get('kafka-cluster-proxy', {})
+ )
+ ).start()
+
+ config = self._get_adapter_config()
+
+ self.core_proxy = CoreProxy(
+ kafka_proxy=None,
+ core_topic=self.core_topic,
+ my_listening_topic=self.listening_topic)
+
+ self.adapter_proxy = AdapterProxy(
+ kafka_proxy=None,
+ core_topic=self.core_topic,
+ my_listening_topic=self.listening_topic)
+
+ self.adapter = AdtranOnuAdapter(core_proxy=self.core_proxy,
+ adapter_proxy=self.adapter_proxy,
+ config=config)
+
+ adtran_request_handler = AdapterRequestFacade(adapter=self.adapter)
+
+ yield registry.register(
+ 'kafka_adapter_proxy',
+ IKafkaMessagingProxy(
+ kafka_host_port=self.args.kafka_adapter,
+ # TODO: Add KV Store object reference
+ kv_store=self.args.backend,
+ default_topic=self.args.name,
+ group_id_prefix=self.args.instance_id,
+ target_cls=adtran_request_handler
+ )
+ ).start()
+
+ self.core_proxy.kafka_proxy = get_messaging_proxy()
+ self.adapter_proxy.kafka_proxy = get_messaging_proxy()
+
+ # retry for ever
+ res = yield self._register_with_core(-1)
+
+ self.log.info('started-internal-services')
+
+ except Exception as e:
+ self.log.exception('Failure-to-start-all-components', e=e)
+
+ @inlineCallbacks
+ def shutdown_components(self):
+ """Execute before the reactor is shut down"""
+ self.log.info('exiting-on-keyboard-interrupt')
+ for component in reversed(registry.iterate()):
+ yield component.stop()
+
+ import threading
+ self.log.info('THREADS:')
+ main_thread = threading.current_thread()
+ for t in threading.enumerate():
+ if t is main_thread:
+ continue
+ if not t.isDaemon():
+ continue
+ self.log.info('joining thread {} {}'.format(
+ t.getName(), "daemon" if t.isDaemon() else "not-daemon"))
+ t.join()
+
+ def start_reactor(self):
+ from twisted.internet import reactor
+ reactor.callWhenRunning(
+ lambda: self.log.info('twisted-reactor-started'))
+ reactor.addSystemEventTrigger('before', 'shutdown',
+ self.shutdown_components)
+ reactor.run()
+
+ @inlineCallbacks
+ def _register_with_core(self, retries):
+ while 1:
+ try:
+ resp = yield self.core_proxy.register(
+ self.adapter.adapter_descriptor(),
+ self.adapter.device_types())
+ if resp:
+ self.log.info('registered-with-core',
+ coreId=resp.instance_id)
+ returnValue(resp)
+ except TimeOutError as e:
+ self.log.warn("timeout-when-registering-with-core", e=e)
+ if retries == 0:
+ self.log.exception("no-more-retries", e=e)
+ raise
+ else:
+ retries = retries if retries < 0 else retries - 1
+ yield asleep(defs['retry_interval'])
+ except Exception as e:
+ self.log.exception("failed-registration", e=e)
+ raise
+
+ def start_heartbeat(self):
+
+ t0 = time.time()
+ t0s = time.ctime(t0)
+
+ def heartbeat():
+ self.log.debug(status='up', since=t0s, uptime=time.time() - t0)
+
+ lc = LoopingCall(heartbeat)
+ lc.start(10)
+
+ # Temporary function to send a heartbeat message to the external kafka
+ # broker
+ def start_kafka_cluster_heartbeat(self, instance_id):
+ # For heartbeat we will send a message to a specific "voltha-heartbeat"
+ # topic. The message is a protocol buf
+ # message
+ message = dict(
+ type='heartbeat',
+ adapter=self.args.name,
+ instance=instance_id,
+ ip=get_my_primary_local_ipv4()
+ )
+ topic = defs['heartbeat_topic']
+
+ def send_msg(start_time):
+ try:
+ kafka_cluster_proxy = get_kafka_proxy()
+ if kafka_cluster_proxy and not kafka_cluster_proxy.is_faulty():
+ # self.log.debug('kafka-proxy-available')
+ message['ts'] = arrow.utcnow().timestamp
+ message['uptime'] = time.time() - start_time
+ # self.log.debug('start-kafka-heartbeat')
+ kafka_cluster_proxy.send_message(topic, dumps(message))
+ else:
+ self.log.error('kafka-proxy-unavailable')
+ except Exception, err:
+ self.log.exception('failed-sending-message-heartbeat', e=err)
+
+ try:
+ t0 = time.time()
+ lc = LoopingCall(send_msg, t0)
+ lc.start(10)
+ except Exception, e:
+ self.log.exception('failed-kafka-heartbeat', e=e)
+
+
+if __name__ == '__main__':
+ Main().start()
diff --git a/adapters/adtran_onu/omci/README.md b/adapters/adtran_onu/omci/README.md
new file mode 100644
index 0000000..babd884
--- /dev/null
+++ b/adapters/adtran_onu/omci/README.md
@@ -0,0 +1,97 @@
+#OMCI Support
+
+This directory contains classes to assist in the creation, transmission,
+and reception of OMCI frames on this ONU Adapter. A number of these files (but
+not all) could be moved into the common *.../voltha/extensions/omci* subdirectory.
+
+##Files
+### omci_cc.py
+
+The *omci_cc.py* file contains the OMCI communications channel for sending and receiving
+OMCI messages. For transmits, it will send the OMCI message to the proper proxy channel,
+but for received, OMCI frames, your device adapter will need to call the
+*receive_message()* method.
+
+The communications channel will return a deferred on a Tx request which will fire when
+a corresponding response is received or if a timeout or other error occurs. When a
+successful response is received, the *OMCI_CC* will also look at *Get, Set, Create*, and
+*Delete* messages prior to calling any additional callbacks so that the MIB Database can be
+checked or updated as needed. Note that the MIB Database is not yet implemented.
+
+ONU Autonomous messages are also handled (Test Results messages are TBD) and these are
+placed
+
+A collection of statistics are available in case the ONU wishes to publish a
+PM group containing these statistics. The Adtran ONU does so in the *onu_pm_metrics.py*
+file.
+
+Finally, a list of vendor-specific ME's can be passed to the class initializer so that
+they are registered in the class_id map. This allows for successful decode of custom MEs.
+See the Adtran ONU's instantiation of the *OMCI_CC* class as an example of how to
+add vendor-specific MEs.
+
+### me_frame.py
+
+This file contains the base class implementation that helps to transform defined
+Managed EntityClasses into OMCI Frames with specific actions (*get, set, create,
+delete, ...*). Prior this class, frames to do each action were hand created methods.
+
+Besides providing methods for creating OMCI frames, the ME attributes names, access
+attributes, and allowed operations are checked to verify that the action is valid
+for both the ME as well as the specific attribute.
+
+What is currently missing is other OMCI actions have not been coded:
+ - GetNext
+ - GetCurrentData
+ - GetAllAlarms
+ - GetAllAlarmsNext
+ - MibUpload
+ - MibUploadNext
+ - MibReset
+ - Test
+ - StartSoftwareDownload
+ - DownloadSection
+ - EndSoftwareDownload
+ - ActivateSoftware
+ - CommitSoftware
+ - SynchronizeTime
+ - Reboot
+
+For many of these actions, such as MibReset, these are only performed on a specific
+ME and it may be best to provide these as explicit static methods.
+
+### omci_me.py
+
+This file is a collection of ME classes derived from the MEFrame base class. For many
+of the currently defined ME's in *omci_entities.py*
+
+### omci_defs.py
+
+This file contains an additional status code enumeration which could be merged with
+the main OMCI extensions directory.
+
+### omci_entities.py
+
+This is an Adtran ONU specific file to add custom OMCI **OMCI_CC** entities and a function
+that can be called by the **OMCI_CC** class to install them into the appropriate locations
+such that OMCI frame decode works as expected during MIB uploads.
+
+Eventually I envision the **OMCI_CC** to be mostly hidden from an ONU device adapter, so
+a method to register these custom ME's needs to be provided.
+
+### deprecated.py
+
+This file contains some of the original _old-style_ OMCI frame creation and send
+commands for the Adtran ONU. These were originally copied over from the BroadCom
+ONU Device Adapter and modified for use in the Adtran ONU. After the **OMCI_CC** class
+was created to handle OMCI Tx/Rx, a reference to the **OMCI_CC** was passed in so that
+these methods could use the *OMCI_CC.send()* method
+
+If you look at the current Adtran ONU **pon_port.py** file, it still contains the original
+calls to these are still in place (commented out) next to how to do the same calls with
+the new **ME_Frame** and **OMCI_CC** classes.
+
+##Unit Tests
+
+After some peer review and any needed refactoring of code, the plan is to create unit tests
+to cover the **OMCI_CC** and **ME_Frame** classes with a target of _90%+_ line coverage.
\ No newline at end of file
diff --git a/adapters/adtran_onu/omci/__init__.py b/adapters/adtran_onu/omci/__init__.py
new file mode 100644
index 0000000..b0fb0b2
--- /dev/null
+++ b/adapters/adtran_onu/omci/__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/adapters/adtran_onu/omci/adtn_capabilities_task.py b/adapters/adtran_onu/omci/adtn_capabilities_task.py
new file mode 100644
index 0000000..6dbed03
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_capabilities_task.py
@@ -0,0 +1,147 @@
+#
+# 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.extensions.omci.tasks.onu_capabilities_task import OnuCapabilitiesTask
+from twisted.internet.defer import failure
+
+
+class AdtnCapabilitiesTask(OnuCapabilitiesTask):
+ """
+ OpenOMCI MIB Capabilities Task - ADTRAN ONUs
+
+ This task requests information on supported MEs via the OMCI (ME#287)
+ Managed entity.
+
+ This task should be ran after MIB Synchronization and before any MIB
+ Downloads to the ONU.
+
+ Upon completion, the Task deferred callback is invoked with dictionary
+ containing the supported managed entities and message types.
+
+ results = {
+ 'supported-managed-entities': {set of supported managed entities},
+ 'supported-message-types': {set of supported message types}
+ }
+ """
+ name = "Adtran ONU Capabilities Task"
+
+ def __init__(self, omci_agent, device_id):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param device_id: (str) ONU Device ID
+ """
+ super(AdtnCapabilitiesTask, self).__init__(omci_agent, device_id)
+
+ self.name = AdtnCapabilitiesTask.name
+ self._omci_managed = False # TODO: Look up capabilities/model number
+
+ @property
+ def supported_managed_entities(self):
+ """
+ Return a set of the Managed Entity class IDs supported on this ONU
+
+ None is returned if not MEs have been discovered
+
+ :return: (set of ints)
+ """
+ if self._omci_managed:
+ return super(AdtnCapabilitiesTask, self).supported_managed_entities
+
+ me_1287800f1 = [
+ 2, 5, 6, 7, 11, 24, 45, 46, 47, 48, 49, 50, 51, 52, 79, 84, 89, 130,
+ 131, 133, 134, 135, 136, 137, 148, 157, 158, 159, 171, 256, 257, 262,
+ 263, 264, 266, 268, 272, 273, 274, 277, 278, 279, 280, 281, 297, 298,
+ 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312,
+ 329, 330, 332, 334, 336, 340, 341, 342, 343, 348, 425, 426, 65300,
+ 65400, 65401, 65402, 65403, 65404, 65406, 65407, 65408, 65409, 65410,
+ 65411, 65412, 65413, 65414, 65420, 65421, 65422, 65423, 65424
+ ]
+ return frozenset(list(me_1287800f1))
+
+ @property
+ def supported_message_types(self):
+ """
+ Return a set of the Message Types supported on this ONU
+
+ None is returned if no message types have been discovered
+
+ :return: (set of EntityOperations)
+ """
+ if self._omci_managed:
+ return super(AdtnCapabilitiesTask, self).supported_message_types
+
+ from voltha.extensions.omci.omci_entities import EntityOperations
+ op_11287800f1 = [
+ EntityOperations.Create,
+ EntityOperations.CreateComplete,
+ EntityOperations.Delete,
+ EntityOperations.Set,
+ EntityOperations.Get,
+ EntityOperations.GetComplete,
+ EntityOperations.GetAllAlarms,
+ EntityOperations.GetAllAlarmsNext,
+ EntityOperations.MibUpload,
+ EntityOperations.MibUploadNext,
+ EntityOperations.MibReset,
+ EntityOperations.AlarmNotification,
+ EntityOperations.AttributeValueChange,
+ EntityOperations.Test,
+ EntityOperations.StartSoftwareDownload,
+ EntityOperations.DownloadSection,
+ EntityOperations.EndSoftwareDownload,
+ EntityOperations.ActivateSoftware,
+ EntityOperations.CommitSoftware,
+ EntityOperations.SynchronizeTime,
+ EntityOperations.Reboot,
+ EntityOperations.GetNext,
+ ]
+ return frozenset(op_11287800f1)
+
+ def perform_get_capabilities(self):
+ """
+ Perform the MIB Capabilities sequence.
+
+ The sequence is to perform a Get request with the attribute mask equal
+ to 'me_type_table'. The response to this request will carry the size
+ of (number of get-next sequences).
+
+ Then a loop is entered and get-next commands are sent for each sequence
+ requested.
+ """
+ self.log.info('perform-get')
+
+ if self._omci_managed:
+ # Return generator deferred/results
+ return super(AdtnCapabilitiesTask, self).perform_get_capabilities()
+
+ # Fixed values, no need to query
+ try:
+ self._supported_entities = self.supported_managed_entities
+ self._supported_msg_types = self.supported_message_types
+
+ self.log.debug('get-success',
+ supported_entities=self.supported_managed_entities,
+ supported_msg_types=self.supported_message_types)
+ results = {
+ 'supported-managed-entities': self.supported_managed_entities,
+ 'supported-message-types': self.supported_message_types
+ }
+ self.deferred.callback(results)
+
+ except Exception as e:
+ self.log.exception('get-failed', e=e)
+ self.deferred.errback(failure.Failure(e))
diff --git a/adapters/adtran_onu/omci/adtn_get_mds_task.py b/adapters/adtran_onu/omci/adtn_get_mds_task.py
new file mode 100644
index 0000000..0de236f
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_get_mds_task.py
@@ -0,0 +1,56 @@
+#
+# 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.extensions.omci.tasks.get_mds_task import GetMdsTask
+
+
+class AdtnGetMdsTask(GetMdsTask):
+ """
+ OpenOMCI Get MIB Data Sync value task - Adtran ONU
+
+ On successful completion, this task will call the 'callback' method of the
+ deferred returned by the start method and return the value of the MIB
+ Data Sync attribute of the ONT Data ME
+ """
+ name = "ADTN: Get MDS Task"
+
+ def __init__(self, omci_agent, device_id):
+ """
+ Class initialization
+
+ :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
+ :param device_id: (str) ONU Device ID
+ """
+ super(AdtnGetMdsTask, self).__init__(omci_agent, device_id)
+
+ self.name = AdtnGetMdsTask.name
+ self._device = omci_agent.get_device(device_id)
+ self._omci_managed = False # TODO: Look up capabilities/model number/check handler
+
+ def perform_get_mds(self):
+ """
+ Get the 'mib_data_sync' attribute of the ONU
+ """
+ self.log.info('perform-get-mds')
+
+ if self._omci_managed:
+ return super(AdtnGetMdsTask, self).perform_get_mds()
+
+ # Non-OMCI managed ADTN ONUs always return 0 for MDS, use the MIB
+ # sync value and depend on an accelerated mib resync to do the
+ # proper comparison
+
+ self.deferred.callback(self._device.mib_synchronizer.mib_data_sync)
+
diff --git a/adapters/adtran_onu/omci/adtn_install_flow.py b/adapters/adtran_onu/omci/adtn_install_flow.py
new file mode 100644
index 0000000..5d5a2f6
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_install_flow.py
@@ -0,0 +1,321 @@
+#
+# 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 twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, failure, returnValue
+from voltha.extensions.omci.omci_me import *
+from voltha.extensions.omci.tasks.task import Task
+from voltha.extensions.omci.omci_defs import *
+from voltha.adapters.adtran_onu.flow.flow_entry import FlowEntry
+
+OP = EntityOperations
+RC = ReasonCodes
+
+
+class ServiceInstallFailure(Exception):
+ """
+ This error is raised by default when the flow-install fails
+ """
+
+
+class AdtnInstallFlowTask(Task):
+ """
+ OpenOMCI MIB Flow Install Task
+
+ Currently, the only service tech profiles expected by v2.0 will be for AT&T
+ residential data service and DT residential data service.
+ """
+ task_priority = Task.DEFAULT_PRIORITY + 10
+ name = "ADTRAN MIB Install Flow Task"
+
+ def __init__(self, omci_agent, handler, flow_entry):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param handler: (AdtranOnuHandler) ONU Handler
+ :param flow_entry: (FlowEntry) Flow to install
+ """
+ super(AdtnInstallFlowTask, self).__init__(AdtnInstallFlowTask.name,
+ omci_agent,
+ handler.device_id,
+ priority=AdtnInstallFlowTask.task_priority,
+ exclusive=False)
+ self._handler = handler
+ self._onu_device = omci_agent.get_device(handler.device_id)
+ self._local_deferred = None
+ self._flow_entry = flow_entry
+ self._install_by_delete = True
+
+ # TODO: Cleanup below that is not needed
+ is_upstream = flow_entry.flow_direction in FlowEntry.upstream_flow_types
+ uni_port = flow_entry.in_port if is_upstream else flow_entry.out_port
+ pon_port = flow_entry.out_port if is_upstream else flow_entry.in_port
+
+ self._uni = handler.uni_port(uni_port)
+ self._pon = handler.pon_port(pon_port)
+
+ # Entity IDs. IDs with values can probably be most anything for most ONUs,
+ # IDs set to None are discovered/set
+ #
+ # TODO: Probably need to store many of these in the appropriate object (UNI, PON,...)
+ #
+ self._ethernet_uni_entity_id = self._handler.uni_ports[0].entity_id
+ self._ieee_mapper_service_profile_entity_id = self._pon.ieee_mapper_service_profile_entity_id
+
+ # Next to are specific
+ self._mac_bridge_service_profile_entity_id = handler.mac_bridge_service_profile_entity_id
+
+ def cancel_deferred(self):
+ super(AdtnInstallFlowTask, self).cancel_deferred()
+
+ d, self._local_deferred = self._local_deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def start(self):
+ """
+ Start the flow installation
+ """
+ super(AdtnInstallFlowTask, self).start()
+ self._local_deferred = reactor.callLater(0, self.perform_flow_install)
+
+ def stop(self):
+ """
+ Shutdown flow install task
+ """
+ self.log.debug('stopping')
+
+ self.cancel_deferred()
+ super(AdtnInstallFlowTask, self).stop()
+
+ def check_status_and_state(self, results, operation=''):
+ """
+ Check the results of an OMCI response. An exception is thrown
+ if the task was cancelled or an error was detected.
+
+ :param results: (OmciFrame) OMCI Response frame
+ :param operation: (str) what operation was being performed
+ :return: True if successful, False if the entity existed (already created)
+ """
+ omci_msg = results.fields['omci_message'].fields
+ status = omci_msg['success_code']
+ error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
+ failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
+ unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
+
+ self.log.debug(operation, status=status, error_mask=error_mask,
+ failed_mask=failed_mask, unsupported_mask=unsupported_mask)
+
+ if status == RC.Success:
+ self.strobe_watchdog()
+ return True
+
+ elif status == RC.InstanceExists:
+ return False
+
+ elif status == RC.UnknownInstance and operation == 'delete':
+ return True
+
+ raise ServiceInstallFailure('{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
+ .format(operation, status, error_mask, failed_mask, unsupported_mask))
+
+ @inlineCallbacks
+ def perform_flow_install(self):
+ """
+ Send the commands to configure the flow.
+
+ Currently this task uses the pre-installed default TCONT and GEM Port. This will
+ change when Technology Profiles are supported.
+ """
+ self.log.info('perform-flow-install', vlan_vid=self._flow_entry.vlan_vid)
+
+ if self._flow_entry.vlan_vid == 0:
+ return
+
+ def resources_available():
+ # TODO: Rework for non-xpon mode
+ return (len(self._handler.uni_ports) > 0 and
+ len(self._pon.tconts) and
+ len(self._pon.gem_ports))
+
+ if self._handler.enabled and resources_available():
+
+ omci = self._onu_device.omci_cc
+ brg_id = self._mac_bridge_service_profile_entity_id
+ vlan_vid = self._flow_entry.vlan_vid
+
+ if self._install_by_delete:
+ # Delete any existing flow before adding this new one
+
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(brg_id, attributes=None)
+ frame = msg.delete()
+
+ try:
+ results = yield omci.send(frame)
+ self.check_status_and_state(results, operation='delete')
+
+ attributes = dict(
+ association_type=2, # Assoc Type, PPTP Ethernet UNI
+ associated_me_pointer=self._ethernet_uni_entity_id # Assoc ME, PPTP Entity Id
+ )
+
+ frame = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id + self._uni.mac_bridge_port_num,
+ attributes=attributes
+ ).create()
+ results = yield omci.send(frame)
+ self.check_status_and_state(results, 'flow-recreate-before-set')
+
+ # TODO: Any of the following needed as well
+
+ # # Delete bridge ani side vlan filter
+ # msg = VlanTaggingFilterDataFrame(self._mac_bridge_port_ani_entity_id)
+ # frame = msg.delete()
+ #
+ # results = yield omci.send(frame)
+ # self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
+ #
+ # # Re-Create bridge ani side vlan filter
+ # msg = VlanTaggingFilterDataFrame(
+ # self._mac_bridge_port_ani_entity_id, # Entity ID
+ # vlan_tcis=[vlan_vid], # VLAN IDs
+ # forward_operation=0x10
+ # )
+ # frame = msg.create()
+ #
+ # results = yield omci.send(frame)
+ # self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
+
+ except Exception as e:
+ self.log.exception('flow-delete-before-install-failure', e=e)
+ self.deferred.errback(failure.Failure(e))
+ returnValue(None)
+
+ try:
+ # Now set the VLAN Tagging Operation up as we want it
+ # Update uni side extended vlan filter
+ # filter for untagged
+ # probably for eapol
+ # TODO: lots of magic
+ # attributes = dict(
+ # # This table filters and tags upstream frames
+ # received_frame_vlan_tagging_operation_table=
+ # VlanTaggingOperation(
+ # filter_outer_priority=15, # This entry is not a double-tag rule (ignore out tag rules)
+ # filter_outer_vid=4096, # Do not filter on the outer VID value
+ # filter_outer_tpid_de=0, # Do not filter on the outer TPID field
+ #
+ # filter_inner_priority=15, # This is a no-tag rule, ignore all other VLAN tag filter fields
+ # filter_inner_vid=4096, # Do not filter on the inner VID
+ # filter_inner_tpid_de=0, # Do not filter on inner TPID field
+ # filter_ether_type=0, # Do not filter on EtherType
+ #
+ # treatment_tags_to_remove=0, # Remove 0 tags
+ #
+ # treatment_outer_priority=15, # Do not add an outer tag
+ # treatment_outer_vid=0, # n/a
+ # treatment_outer_tpid_de=0, # n/a
+ #
+ # treatment_inner_priority=0, # Add an inner tag and insert this value as the priority
+ # treatment_inner_vid=vlan_vid, # Push this tag onto the frame
+ # treatment_inner_tpid_de=4 # set TPID
+ # )
+ # )
+ # msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ # self._mac_bridge_service_profile_entity_id + self._uni.mac_bridge_port_num, # Bridge Entity ID
+ # attributes=attributes # See above
+ # )
+ # frame = msg.set()
+ #
+ # results = yield omci.send(frame)
+ # self.check_status_and_state(results,
+ # 'flow-set-ext-vlan-tagging-op-config-data-untagged')
+
+ # Update uni side extended vlan filter
+ # filter for vlan 0
+ # TODO: lots of magic
+
+ ################################################################################
+ # Update Extended VLAN Tagging Operation Config Data
+ #
+ # Specifies the TPIDs in use and that operations in the downstream direction are
+ # inverse to the operations in the upstream direction
+ # TODO: Downstream mode may need to be modified once we work more on the flow rules
+
+ attributes = dict(
+ input_tpid=0x8100, # input TPID
+ output_tpid=0x8100, # output TPID
+ downstream_mode=0, # inverse of upstream
+ )
+
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id +
+ self._uni.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes # See above
+ )
+ frame = msg.set()
+
+ results = yield omci.send(frame)
+ self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
+
+ attributes = dict(
+ received_frame_vlan_tagging_operation_table=
+ VlanTaggingOperation(
+ filter_outer_priority=15, # This entry is not a double-tag rule
+ filter_outer_vid=4096, # Do not filter on the outer VID value
+ filter_outer_tpid_de=0, # Do not filter on the outer TPID field
+
+ filter_inner_priority=15, # This is a no-tag rule, ignore all other VLAN tag filter fields
+ filter_inner_vid=0x1000, # Do not filter on the inner VID
+ filter_inner_tpid_de=0, # Do not filter on inner TPID field
+
+ filter_ether_type=0, # Do not filter on EtherType
+ treatment_tags_to_remove=0, # Remove 0 tags
+
+ treatment_outer_priority=15, # Do not add an outer tag
+ treatment_outer_vid=0, # n/a
+ treatment_outer_tpid_de=0, # n/a
+
+ treatment_inner_priority=0, # Add an inner tag and insert this value as the priority
+ treatment_inner_vid=vlan_vid, # use this value as the VID in the inner VLAN tag
+ treatment_inner_tpid_de=4, # set TPID
+ )
+ )
+
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id +
+ self._uni.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes # See above
+ )
+ frame = msg.set()
+
+ results = yield omci.send(frame)
+ self.check_status_and_state(results,
+ 'flow-set-ext-vlan-tagging-op-config-data-untagged')
+ self.deferred.callback('flow-install-success')
+
+ except Exception as e:
+ # TODO: Better context info for this exception output...
+ self.log.exception('failed-to-install-flow', e=e)
+ self.deferred.errback(failure.Failure(e))
+
+ else:
+ # TODO: Provide better error reason, what was missing...
+ e = ServiceInstallFailure('Required resources are not available')
+ self.deferred.errback(failure.Failure(e))
diff --git a/adapters/adtran_onu/omci/adtn_mib_download_task.py b/adapters/adtran_onu/omci/adtn_mib_download_task.py
new file mode 100644
index 0000000..36289bf
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_mib_download_task.py
@@ -0,0 +1,370 @@
+#
+# 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 twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue, TimeoutError, failure
+from voltha.extensions.omci.omci_me import *
+from voltha.extensions.omci.tasks.task import Task
+from voltha.extensions.omci.omci_defs import *
+
+OP = EntityOperations
+RC = ReasonCodes
+
+
+class MibDownloadFailure(Exception):
+ """
+ This error is raised by default when the download fails
+ """
+
+
+class MibResourcesFailure(Exception):
+ """
+ This error is raised by when one or more resources required is not available
+ """
+
+
+class AdtnMibDownloadTask(Task):
+ """
+ OpenOMCI MIB Download Example
+
+ This task takes the legacy OMCI 'script' for provisioning the Adtran ONU
+ and converts it to run as a Task on the OpenOMCI Task runner. This is
+ in order to begin to decompose service instantiation in preparation for
+ Technology Profile work.
+
+ Once technology profiles are ready, some of this task may hang around or
+ be moved into OpenOMCI if there are any very common settings/configs to do
+ for any profile that may be provided in the v2.0 release
+
+ Currently, the only service tech profiles expected by v2.0 will be for AT&T
+ residential data service and DT residential data service.
+ """
+ task_priority = Task.DEFAULT_PRIORITY + 10
+ default_tpid = 0x8100
+ default_gem_payload = 1518
+
+ name = "ADTRAN MIB Download Task"
+
+ def __init__(self, omci_agent, handler):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param handler: (OnuHandler) ONU Device Handler
+ """
+ super(AdtnMibDownloadTask, self).__init__(AdtnMibDownloadTask.name,
+ omci_agent,
+ handler.device_id,
+ priority=AdtnMibDownloadTask.task_priority,
+ exclusive=False)
+ self._handler = handler
+ self._onu_device = omci_agent.get_device(handler.device_id)
+ self._local_deferred = None
+
+ # Frame size
+ self._max_gem_payload = AdtnMibDownloadTask.default_gem_payload
+
+ # Port numbers
+ self._pon_port_num = 0
+ self._uni_port_num = 0 # TODO Both port numbers are the same, is this correct? See MacBridgePortConfigurationDataFrame
+
+ self._pon = handler.pon_port()
+ self._vlan_tcis_1 = self._handler.vlan_tcis_1
+
+ # Entity IDs. IDs with values can probably be most anything for most ONUs,
+ # IDs set to None are discovered/set
+ #
+ # TODO: Probably need to store many of these in the appropriate object (UNI, PON,...)
+ #
+ self._ieee_mapper_service_profile_entity_id = self._pon.ieee_mapper_service_profile_entity_id
+ self._mac_bridge_port_ani_entity_id = self._pon.mac_bridge_port_ani_entity_id
+ self._gal_enet_profile_entity_id = self._handler.gal_enet_profile_entity_id
+
+ # Next to are specific TODO: UNI lookups here or uni specific install !!!
+ self._ethernet_uni_entity_id = self._handler.uni_ports[0].entity_id
+ self._mac_bridge_service_profile_entity_id = \
+ self._handler.mac_bridge_service_profile_entity_id
+
+ def cancel_deferred(self):
+ super(AdtnMibDownloadTask, self).cancel_deferred()
+
+ d, self._local_deferred = self._local_deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def start(self):
+ """
+ Start the MIB Download
+ """
+ super(AdtnMibDownloadTask, self).start()
+ self._local_deferred = reactor.callLater(0, self.perform_mib_download)
+
+ def stop(self):
+ """
+ Shutdown MIB Synchronization tasks
+ """
+ self.log.debug('stopping')
+
+ self.cancel_deferred()
+ super(AdtnMibDownloadTask, self).stop()
+
+ def check_status_and_state(self, results, operation=''):
+ """
+ Check the results of an OMCI response. An exception is thrown
+ if the task was cancelled or an error was detected.
+
+ :param results: (OmciFrame) OMCI Response frame
+ :param operation: (str) what operation was being performed
+ :return: True if successful, False if the entity existed (already created)
+ """
+ omci_msg = results.fields['omci_message'].fields
+ status = omci_msg['success_code']
+ error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
+ failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
+ unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
+
+ self.log.debug(operation, status=status, error_mask=error_mask,
+ failed_mask=failed_mask, unsupported_mask=unsupported_mask)
+
+ if status == RC.Success:
+ self.strobe_watchdog()
+ return True
+
+ elif status == RC.InstanceExists:
+ return False
+
+ raise MibDownloadFailure('{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
+ .format(operation, status, error_mask, failed_mask, unsupported_mask))
+
+ @inlineCallbacks
+ def perform_mib_download(self):
+ """
+ Send the commands to minimally configure the PON, Bridge, and
+ UNI ports for this device. The application of any service flows
+ and other characteristics are done once resources (gem-ports, tconts, ...)
+ have been defined.
+ """
+ self.log.info('perform-initial-download')
+
+ device = self._handler.adapter_agent.get_device(self.device_id)
+
+ def resources_available():
+ return len(self._handler.uni_ports) > 0
+
+ if self._handler.enabled and resources_available():
+ device.reason = 'Performing Initial OMCI Download'
+ self._handler.adapter_agent.update_device(device)
+
+ try:
+ # Lock the UNI ports to prevent any alarms during initial configuration
+ # of the ONU
+ for uni_port in self._handler.uni_ports:
+ self.strobe_watchdog()
+
+ yield self.enable_uni(uni_port, True)
+
+ # Provision the initial bridge configuration
+ yield self.perform_initial_bridge_setup(uni_port)
+
+ # And re-enable the UNIs if needed
+ yield self.enable_uni(uni_port, False)
+
+ # If here, we are done with the generic MIB download
+ device = self._handler.adapter_agent.get_device(self.device_id)
+
+ device.reason = 'Initial OMCI Download Complete'
+ self._handler.adapter_agent.update_device(device)
+ self.deferred.callback('MIB Download - success')
+
+ except TimeoutError as e:
+ self.deferred.errback(failure.Failure(e))
+
+ else:
+ # TODO: Provide better error reason, what was missing...
+ e = MibResourcesFailure('ONU is not enabled')
+ self.deferred.errback(failure.Failure(e))
+
+ @inlineCallbacks
+ def perform_initial_bridge_setup(self, uni_port):
+ omci_cc = self._onu_device.omci_cc
+ frame = None
+
+ try:
+ ################################################################################
+ # Common - PON and/or UNI #
+ ################################################################################
+ # MAC Bridge Service Profile
+ #
+ # EntityID will be referenced by:
+ # - MAC Bridge Port Configuration Data (PON & UNI)
+ # References:
+ # - Nothing
+ attributes = {
+ 'spanning_tree_ind': False,
+ 'learning_ind': True
+ }
+ frame = MacBridgeServiceProfileFrame(
+ self._mac_bridge_service_profile_entity_id,
+ attributes
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-mac-bridge-service-profile')
+
+ ################################################################################
+ # PON Specific #
+ ################################################################################
+ # IEEE 802.1 Mapper Service config - Once per PON
+ #
+ # EntityID will be referenced by:
+ # - MAC Bridge Port Configuration Data for the PON port
+ # References:
+ # - Nothing at this point. When a GEM port is created, this entity will
+ # be updated to reference the GEM Interworking TP
+
+ frame = Ieee8021pMapperServiceProfileFrame(self._ieee_mapper_service_profile_entity_id +
+ uni_port.mac_bridge_port_num).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-8021p-mapper-service-profile')
+
+ ################################################################################
+ # Create MAC Bridge Port Configuration Data for the PON port via IEEE 802.1
+ # mapper service. Upon receipt by the ONU, the ONU will create an instance
+ # of the following before returning the response.
+ #
+ # - MAC bridge port designation data
+ # - MAC bridge port filter table data
+ # - MAC bridge port bridge table data
+ #
+ # EntityID will be referenced by:
+ # - Implicitly by the VLAN tagging filter data
+ # References:
+ # - MAC Bridge Service Profile (the bridge)
+ # - IEEE 802.1p mapper service profile for PON port
+
+ frame = MacBridgePortConfigurationDataFrame(
+ self._mac_bridge_port_ani_entity_id, # Entity ID
+ bridge_id_pointer=self._mac_bridge_service_profile_entity_id, # Bridge Entity ID
+ # TODO: The PORT number for this port and the UNI port are the same. Correct?
+ port_num=self._pon_port_num, # Port ID
+ tp_type=3, # TP Type (IEEE 802.1p mapper service)
+ tp_pointer=self._ieee_mapper_service_profile_entity_id +
+ uni_port.mac_bridge_port_num # TP ID, 8021p mapper ID
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-mac-bridge-port-config-data-part-1')
+
+ #############################################################
+ # VLAN Tagging Filter config
+ #
+ # EntityID will be referenced by:
+ # - Nothing
+ # References:
+ # - MacBridgePortConfigurationData for the ANI/PON side
+ #
+ # Set anything, this request will not be used when using Extended Vlan
+
+ frame = VlanTaggingFilterDataFrame(
+ self._mac_bridge_port_ani_entity_id, # Entity ID
+ vlan_tcis=[self._vlan_tcis_1], # VLAN IDs
+ forward_operation=0x00
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-vlan-tagging-filter-data')
+
+ #############################################################
+ # Create GalEthernetProfile - Once per ONU/PON interface
+ #
+ # EntityID will be referenced by:
+ # - GemInterworkingTp
+ # References:
+ # - Nothing
+
+ frame = GalEthernetProfileFrame(
+ self._gal_enet_profile_entity_id,
+ max_gem_payload_size=self._max_gem_payload
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-gal-ethernet-profile')
+
+ ##################################################
+ # UNI Specific #
+ ##################################################
+ # MAC Bridge Port config
+ # This configuration is for Ethernet UNI
+ #
+ # EntityID will be referenced by:
+ # - Nothing
+ # References:
+ # - MAC Bridge Service Profile (the bridge)
+ # - PPTP Ethernet UNI
+
+ frame = MacBridgePortConfigurationDataFrame(
+ 0x000, # Entity ID - This is read-only/set-by-create !!!
+ bridge_id_pointer=self._mac_bridge_service_profile_entity_id, # Bridge Entity ID
+ port_num=self._uni_port_num, # Port ID
+ tp_type=1, # PPTP Ethernet UNI
+ tp_pointer=self._ethernet_uni_entity_id # TP ID, 8021p mapper Id
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-mac-bridge-port-config-data-part-2')
+
+ except TimeoutError as _e:
+ self.log.warn('rx-timeout-download', frame=hexlify(frame))
+ raise
+
+ except Exception as e:
+ self.log.exception('omci-setup-1', e=e)
+ raise
+
+ returnValue(None)
+
+ @inlineCallbacks
+ def enable_uni(self, uni, force_lock):
+ """
+ Lock or unlock one or more UNI ports
+
+ :param unis: (list) of UNI objects
+ :param force_lock: (boolean) If True, force lock regardless of enabled state
+ """
+ omci_cc = self._onu_device.omci_cc
+
+ ##################################################################
+ # Lock/Unlock UNI - 0 to Unlock, 1 to lock
+ #
+ # EntityID is referenced by:
+ # - MAC bridge port configuration data for the UNI side
+ # References:
+ # - Nothing
+ try:
+ state = 1 if force_lock or not uni.enabled else 0
+
+ frame = PptpEthernetUniFrame(uni.entity_id,
+ attributes=dict(administrative_state=state)).set()
+
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-pptp-ethernet-uni-lock-restore')
+
+ except TimeoutError:
+ self.log.warn('rx-timeout-uni-enable', uni_port=uni)
+ raise
+
+ except Exception as e:
+ self.log.exception('omci-failure', e=e)
+ raise
+
+ returnValue(None)
diff --git a/adapters/adtran_onu/omci/adtn_mib_reconcile_task.py b/adapters/adtran_onu/omci/adtn_mib_reconcile_task.py
new file mode 100644
index 0000000..b0892ad
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_mib_reconcile_task.py
@@ -0,0 +1,184 @@
+#
+# 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 twisted.internet.defer import returnValue
+from pyvoltha.adapters.extensions.omci.omci_defs import *
+from voltha.extensions.omci.omci_entities import Ieee8021pMapperServiceProfile
+from voltha.extensions.omci.tasks.mib_reconcile_task import MibReconcileTask
+from voltha.extensions.omci.database.mib_db_api import ATTRIBUTES_KEY
+from twisted.internet.defer import inlineCallbacks
+from voltha.extensions.omci.omci_defs import ReasonCodes, EntityOperations
+from voltha.extensions.omci.omci_me import MEFrame
+
+OP = EntityOperations
+RC = ReasonCodes
+AA = AttributeAccess
+
+
+class AdtnMibReconcileTask(MibReconcileTask):
+ """
+ Adtran ONU OpenOMCI MIB Reconcile Task
+
+ For some crazy reason, the ADTRAN ONU does not report the IEEE802.1p Mapper ME
+ in the ONU upload even though it does exists. This results in an 'instance
+ exists' error when trying to create it on the ONU
+ """
+ name = "Adtran MIB Reconcile Task"
+
+ def __init__(self, omci_agent, device_id, diffs):
+ super(AdtnMibReconcileTask, self).__init__(omci_agent, device_id, diffs)
+
+ self.name = AdtnMibReconcileTask.name
+ self._me_130_okay = False # Set true once bug is fixed (auto detect)
+ self._omci_managed = False # Set once ONU Data tracking of MIB-Data-Sync supported
+
+ @inlineCallbacks
+ def fix_olt_only(self, olt, onu_db, olt_db):
+ """
+ Fix ME's that were only found on the OLT. For OLT only MEs there are
+ the following things that will be checked.
+
+ o ME's that do not have an OpenOMCI class decoder. These are stored
+ as binary blobs in the MIB database. Since the OLT will never
+ create these (all are learned from ONU), it is assumed the ONU
+ has removed them for some purpose. So delete them from the OLT
+ database.
+
+ o For ME's that are created by the ONU (no create/delete access), the
+ MEs 'may' not be on the ONU because of a reboot or an OLT created
+ ME was deleted and the ONU gratuitously removes it. So delete them
+ from the OLT database.
+
+ o For ME's that are created by the OLT/OpenOMCI, delete them from the
+ ONU
+
+ :param olt: (list(int,int)) List of tuples where (class_id, inst_id)
+ :param onu_db: (dict) ONU Database snapshot at time of audit
+ :param olt_db: (dict) OLT Database snapshot at time of audit
+
+ :return: (int, int) successes, failures
+ """
+ # Has IEEE 802.1p reporting Bug fixed?
+
+ if self._me_130_okay or Ieee8021pMapperServiceProfile.class_id in onu_db:
+ self._me_130_okay = True
+ returnValue(super(AdtnMibReconcileTask, self).fix_olt_only(olt, onu_db, olt_db))
+
+ ############################
+ # Base class handles all but ME 130
+ local_mes = {Ieee8021pMapperServiceProfile.class_id}
+ not_manual = [(cid, eid) for cid, eid in olt if cid not in local_mes]
+
+ results = yield super(AdtnMibReconcileTask, self).fix_olt_only(not_manual,
+ onu_db,
+ olt_db)
+ successes = results[0]
+ failures = results[1]
+
+ # If IEEE 802.1p mapper needs to be checked, do it manually as the IBONT 602
+ # manipulates it during MEF EVC/EVC-Map creation
+ for cid in local_mes:
+ class_entry = olt_db.get(cid, None)
+
+ if class_entry is not None:
+ entries = {k: v for k, v in class_entry.items() if isinstance(k, int)}
+ for eid, instance in entries.items():
+ try:
+ self.strobe_watchdog()
+ results = yield self.manual_verification(cid, eid, instance[ATTRIBUTES_KEY])
+ successes += results[0]
+ failures += results[1]
+
+ except Exception as _e:
+ failures += 1
+
+ returnValue((successes, failures))
+
+ @inlineCallbacks
+ def update_mib_data_sync(self):
+ """ IBONT version does not support MDS"""
+ if self._omci_managed:
+ results = yield super(AdtnMibReconcileTask, self).update_mib_data_sync()
+ returnValue(results)
+
+ returnValue((1, 0))
+
+ @inlineCallbacks
+ def manual_verification(self, cid, eid, attributes):
+ # Trim off read-only attributes from ones passed in
+
+ me_map = self._device.me_map
+ ro_set = {AA.R}
+ ro_attrs = {attr.field.name for attr in me_map[cid].attributes
+ if attr.access == ro_set}
+ attributes = {k: v for k, v in attributes.items() if k not in ro_attrs}
+ attributes_to_fix = dict()
+
+ try:
+ while len(attributes):
+ frame = MEFrame(me_map[cid], eid, attributes).get()
+ self.strobe_watchdog()
+ results = yield self._device.omci_cc.send(frame)
+ omci_message = results.fields['omci_message'].fields
+ status = omci_message['success_code']
+
+ if status == RC.UnknownEntity.value:
+ self.strobe_watchdog()
+ results = yield self.create_instance(me_map[cid], eid, attributes)
+ returnValue((results[0], results[1]))
+
+ if status != RC.Success.value:
+ self.log.error('manual-check-get-failed', cid=cid, eid=eid,
+ attributes=attributes, status=status)
+ returnValue((1, 0))
+
+ onu_attr = {k: v for k, v in omci_message['data'].items()}
+ attributes_to_fix.update({k: v for k, v in onu_attr.items()
+ if k in attributes and v != attributes[k]})
+ attributes = {k: v for k, v in attributes if k not in onu_attr.keys()}
+
+ if len(attributes_to_fix) > 0:
+ try:
+ frame = MEFrame(me_map[cid], eid, attributes_to_fix).set()
+ self.strobe_watchdog()
+ yield self._device.omci_cc.send(frame)
+ returnValue((1, 0))
+
+ except Exception as _e:
+ returnValue((0, 1))
+
+ except Exception as e:
+ self.log.exception('manual-check-failed', e=e, cid=cid, eid=eid)
+ raise
+
+ @inlineCallbacks
+ def create_instance(self, cid, eid, attributes):
+ try:
+ me_map = self._device.me_map
+ frame = MEFrame(me_map[cid], eid, attributes).create()
+
+ self.strobe_watchdog()
+ results = yield self._device.omci_cc.send(frame)
+ status = results.fields['omci_message'].fields['success_code']
+ if status == RC.Success.value or status == RC.InstanceExists.value:
+ returnValue((1, 0))
+
+ self.log.error('manual-check-create-failed', cid=cid, eid=eid,
+ attributes=attributes, status=status)
+ returnValue((0, 1))
+
+ except Exception as e:
+ self.log.exception('manual-check-failed', e=e, cid=cid, eid=eid)
+ raise
diff --git a/adapters/adtran_onu/omci/adtn_mib_resync_task.py b/adapters/adtran_onu/omci/adtn_mib_resync_task.py
new file mode 100644
index 0000000..500ee02
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_mib_resync_task.py
@@ -0,0 +1,67 @@
+#
+# 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.omci.tasks.mib_resync_task import MibResyncTask
+from voltha.extensions.omci.omci_entities import GalEthernetProfile, GemPortNetworkCtp, \
+ Ieee8021pMapperServiceProfile
+
+
+class AdtnMibResyncTask(MibResyncTask):
+ """
+ ADTRAN MIB resynchronization Task
+
+ The ADTRAN IBONT 602 does not report the current value of the GAL Ethernet
+ Payload size, it is always 0.
+
+ Also, the MEF EVC/EVC-MAP code monitors GEM Port CTP ME
+ """
+ def __init__(self, omci_agent, device_id):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param device_id: (str) ONU Device ID
+ """
+ super(AdtnMibResyncTask, self).__init__(omci_agent, device_id)
+ self.omci_fixed = False
+
+ def compare_mibs(self, db_copy, db_active):
+ """
+ Compare the our db_copy with the ONU's active copy
+
+ :param db_copy: (dict) OpenOMCI's copy of the database
+ :param db_active: (dict) ONU's database snapshot
+ :return: (dict), (dict), (list) Differences
+ """
+ on_olt_only, on_onu_only, attr_diffs = super(AdtnMibResyncTask, self).\
+ compare_mibs(db_copy, db_active)
+
+ if not self.omci_fixed:
+ # Exclude 'max_gem_payload_size' in GAL Ethernet Profile
+ attr_diffs = [attr for attr in attr_diffs
+ if attr[0] != GalEthernetProfile.class_id
+ or attr[2] != 'max_gem_payload_size']
+
+ # Exclude any changes to GEM Port Network CTP
+ attr_diffs = [attr for attr in attr_diffs
+ if attr[0] != GemPortNetworkCtp.class_id]
+
+ if on_olt_only is not None:
+ # Exclude IEEE 8021.p Mapper Service Profile from OLT Only as not
+ # reported in current IBONT 602 software
+ on_olt_only = [(cid, eid) for cid, eid in on_olt_only
+ if cid != Ieee8021pMapperServiceProfile.class_id]
+
+ return on_olt_only, on_onu_only, attr_diffs
diff --git a/adapters/adtran_onu/omci/adtn_mib_sync.py b/adapters/adtran_onu/omci/adtn_mib_sync.py
new file mode 100644
index 0000000..e0d6b82
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_mib_sync.py
@@ -0,0 +1,85 @@
+#
+# 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.extensions.omci.state_machines.mib_sync import MibSynchronizer
+
+
+class AdtnMibSynchronizer(MibSynchronizer):
+ """
+ OpenOMCI MIB Synchronizer state machine for Adtran ONUs
+ """
+ ADTN_RESYNC_DELAY = 120 # Periodically force a resync (lower for debugging)
+ ADTN_AUDIT_DELAY = 60
+
+ def __init__(self, agent, device_id, mib_sync_tasks, db, advertise_events=False):
+ """
+ Class initialization
+
+ :param agent: (OpenOmciAgent) Agent
+ :param device_id: (str) ONU Device ID
+ :param db: (MibDbVolatileDict) MIB Database
+ :param mib_sync_tasks: (dict) Tasks to run
+ :param advertise_events: (bool) Advertise events on OpenOMCI Event Bus
+ """
+ super(AdtnMibSynchronizer, self).__init__(agent, device_id, mib_sync_tasks, db,
+ advertise_events=advertise_events,
+ audit_delay=AdtnMibSynchronizer.ADTN_AUDIT_DELAY,
+ resync_delay=AdtnMibSynchronizer.ADTN_RESYNC_DELAY)
+ self._first_in_sync = True
+ self._omci_managed = False # TODO: Look up model number/check handler
+
+ def increment_mib_data_sync(self):
+ if self._omci_managed:
+ super(AdtnMibSynchronizer, self).increment_mib_data_sync()
+
+ # IBONT 602 does not support MDS
+ self._mib_data_sync = 0
+
+ def on_enter_in_sync(self):
+ """ Early first sync """
+ if not self._omci_managed:
+ # IBONT 602 does not support MDS, accelerate first forced resync
+ # after a MIB reset occurs or on first startup
+ if self._first_in_sync:
+ self._first_in_sync = False
+ # self._audit_delay = 10 # Re-enable after BBWF
+ # self._resync_delay = 10
+ else:
+ self._audit_delay = MibSynchronizer.DEFAULT_AUDIT_DELAY
+ self._resync_delay = AdtnMibSynchronizer.ADTN_RESYNC_DELAY
+
+ super(AdtnMibSynchronizer, self).on_enter_in_sync()
+
+ def on_enter_auditing(self):
+ """
+ Perform a MIB Audit. If our last MIB resync was too long in the
+ past, perform a resynchronization anyway
+ """
+ # Is this a model that supports full OMCI management. If so, use standard
+ # forced resync delay
+
+ if not self._omci_managed and self._check_if_mib_data_sync_supported():
+ self._omci_managed = True
+ # Revert to standard timeouts
+ self._resync_delay = MibSynchronizer.DEFAULT_RESYNC_DELAY
+
+ super(AdtnMibSynchronizer, self).on_enter_auditing()
+
+ def _check_if_mib_data_sync_supported(self):
+ return False # TODO: Look up to see if we are/check handler
+
+ def on_mib_reset_response(self, topic, msg):
+ self._first_in_sync = True
+ super(AdtnMibSynchronizer, self).on_mib_reset_response(topic, msg)
diff --git a/adapters/adtran_onu/omci/adtn_remove_flow.py b/adapters/adtran_onu/omci/adtn_remove_flow.py
new file mode 100644
index 0000000..f0fbf77
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_remove_flow.py
@@ -0,0 +1,225 @@
+#
+# 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 twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, failure
+from voltha.extensions.omci.omci_me import *
+from voltha.extensions.omci.tasks.task import Task
+from voltha.extensions.omci.omci_defs import *
+from voltha.adapters.adtran_onu.flow.flow_entry import FlowEntry
+from voltha.adapters.adtran_onu.omci.omci import OMCI
+
+OP = EntityOperations
+RC = ReasonCodes
+
+
+class ServiceRemovalFailure(Exception):
+ """
+ This error is raised by default when the flow-install fails
+ """
+
+
+class AdtnRemoveFlowTask(Task):
+ """
+ OpenOMCI MIB Flow Remove Task
+
+ Currently, the only service tech profiles expected by v2.0 will be for AT&T
+ residential data service and DT residential data service.
+ """
+ task_priority = Task.DEFAULT_PRIORITY + 10
+ default_tpid = 0x8100 # TODO: Locate to a better location
+
+ name = "ADTRAN MIB Install Flow Task"
+
+ def __init__(self, omci_agent, handler, flow_entry):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param handler: (AdtranOnuHandler) ONU Handler
+ :param flow_entry: (FlowEntry) Flow to install
+ """
+ super(AdtnRemoveFlowTask, self).__init__(AdtnRemoveFlowTask.name,
+ omci_agent,
+ handler.device_id,
+ priority=AdtnRemoveFlowTask.task_priority,
+ exclusive=False)
+ self._handler = handler
+ self._onu_device = omci_agent.get_device(handler.device_id)
+ self._local_deferred = None
+ self._flow_entry = flow_entry
+
+ # TODO: Cleanup below that is not needed
+ # self._vlan_tcis_1 = 0x900
+ # self._input_tpid = AdtnRemoveFlowTask.default_tpid
+ # self._output_tpid = AdtnRemoveFlowTask.default_tpid
+
+ is_upstream = flow_entry.flow_direction in FlowEntry.upstream_flow_types
+ uni_port = flow_entry.in_port if is_upstream else flow_entry.out_port
+ pon_port = flow_entry.out_port if is_upstream else flow_entry.in_port
+
+ self._uni = handler.uni_port(uni_port)
+ self._pon = handler.pon_port(pon_port)
+
+ self._vid = OMCI.DEFAULT_UNTAGGED_VLAN
+
+ # Entity IDs. IDs with values can probably be most anything for most ONUs,
+ # IDs set to None are discovered/set
+ #
+ # TODO: Probably need to store many of these in the appropriate object (UNI, PON,...)
+ #
+ self._ieee_mapper_service_profile_entity_id = self._pon.ieee_mapper_service_profile_entity_id
+ self._mac_bridge_port_ani_entity_id = self._pon.mac_bridge_port_ani_entity_id
+
+ # Next to are specific
+ self._mac_bridge_service_profile_entity_id = handler.mac_bridge_service_profile_entity_id
+
+ def cancel_deferred(self):
+ super(AdtnRemoveFlowTask, self).cancel_deferred()
+
+ d, self._local_deferred = self._local_deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def start(self):
+ """
+ Start the flow installation
+ """
+ super(AdtnRemoveFlowTask, self).start()
+ self._local_deferred = reactor.callLater(0, self.perform_flow_removal)
+
+ def stop(self):
+ """
+ Shutdown flow install task
+ """
+ self.log.debug('stopping')
+
+ self.cancel_deferred()
+ super(AdtnRemoveFlowTask, self).stop()
+
+ def check_status_and_state(self, results, operation=''):
+ """
+ Check the results of an OMCI response. An exception is thrown
+ if the task was cancelled or an error was detected.
+
+ :param results: (OmciFrame) OMCI Response frame
+ :param operation: (str) what operation was being performed
+ :return: True if successful, False if the entity existed (already created)
+ """
+ omci_msg = results.fields['omci_message'].fields
+ status = omci_msg['success_code']
+ error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
+ failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
+ unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
+
+ self.log.debug(operation, status=status, error_mask=error_mask,
+ failed_mask=failed_mask, unsupported_mask=unsupported_mask)
+
+ if status == RC.Success:
+ self.strobe_watchdog()
+ return True
+
+ elif status == RC.InstanceExists:
+ return False
+
+ raise ServiceRemovalFailure(
+ '{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
+ .format(operation, status, error_mask, failed_mask, unsupported_mask))
+
+ @inlineCallbacks
+ def perform_flow_removal(self):
+ """
+ Send the commands to configure the flow
+ """
+ self.log.info('perform-flow-removal')
+
+ # TODO: This has not been fully implemented
+
+ def resources_available():
+ return (len(self._handler.uni_ports) > 0 and
+ len(self._pon.tconts) and
+ len(self._pon.gem_ports))
+
+ if self._handler.enabled and resources_available():
+ omci = self._onu_device.omci_cc
+ try:
+ # TODO: make this a member of the onu gem port or the uni port
+ set_vlan_vid = self._flow_entry.set_vlan_vid
+
+ # # Delete bridge ani side vlan filter
+ # msg = VlanTaggingFilterDataFrame(self._mac_bridge_port_ani_entity_id)
+ # frame = msg.delete()
+ #
+ # results = yield omci.send(frame)
+ # self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
+ #
+ # # Re-Create bridge ani side vlan filter
+ # msg = VlanTaggingFilterDataFrame(
+ # self._mac_bridge_port_ani_entity_id, # Entity ID
+ # vlan_tcis=[self._vlan_tcis_1], # VLAN IDs
+ # forward_operation=0x10
+ # )
+ # frame = msg.create()
+ # results = yield omci.send(frame)
+ # self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
+
+ # Update uni side extended vlan filter
+ attributes = dict(
+ received_frame_vlan_tagging_operation_table=
+ VlanTaggingOperation(
+ filter_outer_priority=15, # This entry is not a double-tag rule
+ filter_outer_vid=4096, # Do not filter on the outer VID value
+ filter_outer_tpid_de=0, # Do not filter on the outer TPID field
+
+ filter_inner_priority=15, # This is a no-tag rule, ignore all other VLAN tag filter fields
+ filter_inner_vid=0x1000, # Do not filter on the inner VID
+ filter_inner_tpid_de=0, # Do not filter on inner TPID field
+
+ filter_ether_type=0, # Do not filter on EtherType
+ treatment_tags_to_remove=0, # Remove 0 tags
+
+ treatment_outer_priority=15, # Do not add an outer tag
+ treatment_outer_vid=0, # n/a
+ treatment_outer_tpid_de=0, # n/a
+
+ treatment_inner_priority=0, # Add an inner tag and insert this value as the priority
+ treatment_inner_vid=self._vid, # use this value as the VID in the inner VLAN tag
+ treatment_inner_tpid_de=4, # set TPID
+ )
+ )
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id +
+ self._uni.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes # See above
+ )
+ frame = msg.set()
+ results = yield omci.send(frame)
+ self.check_status_and_state(results,
+ 'flow-set-ext-vlan-tagging-op-config-data-untagged')
+
+ self.deferred.callback('flow-remove-success')
+
+ except Exception as e:
+ # TODO: Better context info for this exception output...
+ self.log.exception('failed-to-remove-flow', e=e)
+ self.deferred.errback(failure.Failure(e))
+
+ else:
+ # TODO: Provide better error reason, what was missing...
+ e = ServiceRemovalFailure('Required resources are not available')
+ self.deferred.errback(failure.Failure(e))
diff --git a/adapters/adtran_onu/omci/adtn_tp_service_specific_task.py b/adapters/adtran_onu/omci/adtn_tp_service_specific_task.py
new file mode 100644
index 0000000..66a86b4
--- /dev/null
+++ b/adapters/adtran_onu/omci/adtn_tp_service_specific_task.py
@@ -0,0 +1,484 @@
+#
+# 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 twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, TimeoutError, failure, returnValue
+from voltha.extensions.omci.omci_me import *
+from voltha.extensions.omci.tasks.task import Task
+from voltha.extensions.omci.omci_defs import *
+from voltha.adapters.adtran_onu.omci.omci import OMCI
+from voltha.adapters.adtran_onu.uni_port import *
+from voltha.adapters.adtran_onu.onu_tcont import OnuTCont
+from voltha.adapters.adtran_onu.onu_gem_port import OnuGemPort
+
+OP = EntityOperations
+RC = ReasonCodes
+
+
+class TechProfileDownloadFailure(Exception):
+ """
+ This error is raised by default when the download fails
+ """
+
+
+class TechProfileResourcesFailure(Exception):
+ """
+ This error is raised by when one or more resources required is not available
+ """
+
+
+class AdtnTpServiceSpecificTask(Task):
+ """
+ Adtran OpenOMCI Tech-Profile Download Task
+ """
+ name = "Adtran Tech-Profile Download Task"
+ task_priority = Task.DEFAULT_PRIORITY + 10
+ default_tpid = 0x8100 # TODO: Move to a better location
+ default_gem_payload = 48
+
+ def __init__(self, omci_agent, handler, uni_id):
+ """
+ Class initialization
+
+ :param omci_agent: (OmciAdapterAgent) OMCI Adapter agent
+ :param device_id: (str) ONU Device ID
+ """
+ self.log = structlog.get_logger(device_id=handler.device_id, uni_id=uni_id)
+
+ super(AdtnTpServiceSpecificTask, self).__init__(AdtnTpServiceSpecificTask.name,
+ omci_agent,
+ handler.device_id,
+ priority=AdtnTpServiceSpecificTask.task_priority,
+ exclusive=False)
+
+ self._onu_device = omci_agent.get_device(handler.device_id)
+ self._local_deferred = None
+
+ pon_port = handler.pon_port()
+ self._uni_port = handler.uni_ports[uni_id]
+ assert self._uni_port.uni_id == uni_id
+
+ self._input_tpid = AdtnTpServiceSpecificTask.default_tpid
+ self._output_tpid = AdtnTpServiceSpecificTask.default_tpid
+
+ self._vlan_tcis_1 = OMCI.DEFAULT_UNTAGGED_VLAN
+ self._cvid = OMCI.DEFAULT_UNTAGGED_VLAN
+ self._vlan_config_entity_id = self._vlan_tcis_1
+ self._max_gem_payload = AdtnTpServiceSpecificTask.default_gem_payload
+
+ # Entity IDs. IDs with values can probably be most anything for most ONUs,
+ # IDs set to None are discovered/set
+
+ self._mac_bridge_service_profile_entity_id = handler.mac_bridge_service_profile_entity_id
+ self._ieee_mapper_service_profile_entity_id = pon_port.ieee_mapper_service_profile_entity_id
+ self._mac_bridge_port_ani_entity_id = pon_port.mac_bridge_port_ani_entity_id
+ self._gal_enet_profile_entity_id = handler.gal_enet_profile_entity_id
+
+ # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
+ # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
+ # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
+ # this initializer
+ self._tconts = [tcont for tcont in pon_port.tconts.itervalues()
+ if tcont.uni_id == self._uni_port.uni_id]
+
+ self._gem_ports = [gem_port for gem_port in pon_port.gem_ports.itervalues()
+ if gem_port.uni_id == self._uni_port.uni_id]
+
+ self.tcont_me_to_queue_map = dict()
+ self.uni_port_to_queue_map = dict()
+
+ def cancel_deferred(self):
+ self.log.debug('function-entry')
+ super(AdtnTpServiceSpecificTask, self).cancel_deferred()
+
+ d, self._local_deferred = self._local_deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def start(self):
+ """
+ Start the Tech-Profile Download
+ """
+ self.log.debug('function-entry')
+ super(AdtnTpServiceSpecificTask, self).start()
+ self._local_deferred = reactor.callLater(0, self.perform_service_specific_steps)
+
+ def stop(self):
+ """
+ Shutdown Tech-Profile download tasks
+ """
+ self.log.debug('function-entry')
+ self.log.debug('stopping')
+
+ self.cancel_deferred()
+ super(AdtnTpServiceSpecificTask, self).stop()
+
+ def check_status_and_state(self, results, operation=''):
+ """
+ Check the results of an OMCI response. An exception is thrown
+ if the task was cancelled or an error was detected.
+
+ :param results: (OmciFrame) OMCI Response frame
+ :param operation: (str) what operation was being performed
+ :return: True if successful, False if the entity existed (already created)
+ """
+ self.log.debug('function-entry')
+
+ omci_msg = results.fields['omci_message'].fields
+ status = omci_msg['success_code']
+ error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
+ failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
+ unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
+
+ self.log.debug("OMCI Result: %s", operation, omci_msg=omci_msg, status=status, error_mask=error_mask,
+ failed_mask=failed_mask, unsupported_mask=unsupported_mask)
+
+ if status == RC.Success:
+ self.strobe_watchdog()
+ return True
+
+ elif status == RC.InstanceExists:
+ return False # For Creates issued during task retries
+
+ raise TechProfileDownloadFailure(
+ '{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
+ .format(operation, status, error_mask, failed_mask, unsupported_mask))
+
+ @inlineCallbacks
+ def perform_service_specific_steps(self):
+ """
+ Install the Technology Profile specific ME instances into the ONU. The
+ initial bridge setup was performed after the capabilities were discovered.
+
+ This task is called near the end of the ONU Tech profile setup when the
+ ONU receives technology profile info from the OLT over the inter-adapter channel
+ """
+ self.log.debug('setting-up-tech-profile-me-instances')
+
+ if len(self._tconts) == 0:
+ self.deferred.errback(failure.Failure(TechProfileResourcesFailure('No TCONTs assigned')))
+ returnValue('no-resources')
+
+ if len(self._gem_ports) == 0:
+ self.deferred.errback(failure.Failure(TechProfileResourcesFailure('No GEM Ports assigned')))
+ returnValue('no-resources')
+
+ omci_cc = self._onu_device.omci_cc
+ self.strobe_watchdog()
+
+ try:
+ ################################################################################
+ # TCONTS
+ #
+ # EntityID will be referenced by:
+ # - GemPortNetworkCtp
+ # References:
+ # - ONU created TCONT (created on ONU tech profile startup)
+
+ tcont_idents = self._onu_device.query_mib(Tcont.class_id)
+ self.log.debug('tcont-idents', tcont_idents=tcont_idents)
+
+ for tcont in self._tconts:
+ if tcont.entity_id is not None:
+ continue # Already installed
+
+ free_alloc_ids = {OnuTCont.FREE_TCONT_ALLOC_ID,
+ OnuTCont.FREE_GPON_TCONT_ALLOC_ID}
+
+ free_entity_id = next((k for k, v in tcont_idents.items()
+ if isinstance(k, int) and
+ v.get('attributes', {}).get('alloc_id', 0) in
+ free_alloc_ids), None)
+
+ if free_entity_id is None:
+ self.log.error('no-available-tconts')
+ raise TechProfileResourcesFailure('No Available TConts')
+
+ try:
+ prev_alloc_id = tcont_idents[free_entity_id].get('attributes').get('alloc_id')
+ results = yield tcont.add_to_hardware(omci_cc, free_entity_id, prev_alloc_id=prev_alloc_id)
+ self.check_status_and_state(results, 'create-tcont')
+
+ except Exception as e:
+ self.log.exception('tcont-set', e=e, eid=free_entity_id)
+ raise
+
+ ################################################################################
+ # GEMS (GemPortNetworkCtp and GemInterworkingTp)
+ #
+ # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the
+ # GemInterworkingTp ME could be different since it has an attribute to specify
+ # the GemPortNetworkCtp entity id.
+ #
+ # for the GemPortNetworkCtp ME
+ #
+ # GemPortNetworkCtp
+ # EntityID will be referenced by:
+ # - GemInterworkingTp
+ # References:
+ # - TCONT
+ # - Hardcoded upstream TM Entity ID
+ # - (Possibly in Future) Upstream Traffic descriptor profile pointer
+ #
+ # GemInterworkingTp
+ # EntityID will be referenced by:
+ # - Ieee8021pMapperServiceProfile
+ # References:
+ # - GemPortNetworkCtp
+ # - Ieee8021pMapperServiceProfile
+ # - GalEthernetProfile
+ #
+ #onu_g = self._onu_device.query_mib(OntG.class_id)
+
+ # If the traffic management option attribute in the ONU-G ME is 0
+ # (priority controlled) or 2 (priority and rate controlled), this
+ # pointer specifies the priority queue ME serving this GEM port
+ # network CTP. If the traffic management option attribute is 1
+ # (rate controlled), this attribute redundantly points to the
+ # T-CONT serving this GEM port network CTP.
+
+ # traffic_mgmt_opt = onu_g.get('attributes', {}).get('traffic_management_options', 0)
+ traffic_mgmt_opt = self._onu_device.configuration.traffic_management_option
+ self.log.debug("traffic-mgmt-option", traffic_mgmt_opt=traffic_mgmt_opt)
+
+ prior_q = self._onu_device.query_mib(PriorityQueueG.class_id)
+
+ for k, v in prior_q.items():
+ self.log.debug("prior-q", k=k, v=v)
+ self.strobe_watchdog()
+
+ try:
+ _ = iter(v)
+ except TypeError:
+ continue
+
+ if 'instance_id' in v:
+ related_port = v['attributes']['related_port']
+ if v['instance_id'] & 0b1000000000000000:
+ tcont_me = (related_port & 0xffff0000) >> 16
+
+ if tcont_me not in self.tcont_me_to_queue_map:
+ self.log.debug("prior-q-related-port-and-tcont-me",
+ related_port=related_port,
+ tcont_me=tcont_me)
+ self.tcont_me_to_queue_map[tcont_me] = list()
+
+ self.tcont_me_to_queue_map[tcont_me].append(k)
+ else:
+ uni_port = (related_port & 0xffff0000) >> 16
+
+ if uni_port == self._uni_port.entity_id:
+ if uni_port not in self.uni_port_to_queue_map:
+ self.log.debug("prior-q-related-port-and-uni-port-me",
+ related_port=related_port,
+ uni_port_me=uni_port)
+ self.uni_port_to_queue_map[uni_port] = list()
+
+ self.uni_port_to_queue_map[uni_port].append(k)
+
+ self.log.debug("ul-prior-q", ul_prior_q=self.tcont_me_to_queue_map)
+ self.log.debug("dl-prior-q", dl_prior_q=self.uni_port_to_queue_map)
+
+ for gem_port in self._gem_ports:
+ self.strobe_watchdog()
+ if gem_port.entity_id is not None:
+ continue # Already installed
+
+ # TODO: Traffic descriptor will be available after meter bands are available
+ tcont = gem_port.tcont
+ if tcont is None:
+ self.log.error('unknown-tcont-reference', gem_id=gem_port.gem_id)
+ continue
+
+ ul_prior_q_entity_id = None
+ dl_prior_q_entity_id = None
+
+ if gem_port.direction in {OnuGemPort.UPSTREAM, OnuGemPort.BIDIRECTIONAL}:
+
+ # Sort the priority queue list in order of priority.
+ # 0 is highest priority and 0x0fff is lowest.
+ self.tcont_me_to_queue_map[tcont.entity_id].sort()
+ self.uni_port_to_queue_map[self._uni_port.entity_id].sort()
+
+ # Get the priority queue associated with p-bit that is
+ # mapped to the gem port.
+ # p-bit-7 is highest priority and p-bit-0 is lowest
+ # Gem port associated with p-bit-7 should be mapped to
+ # highest priority queue and gem port associated with p-bit-0
+ # should be mapped to lowest priority queue.
+ # The self.tcont_me_to_queue_map and self.uni_port_to_queue_map
+ # have priority queue entities ordered in descending order
+ # of priority
+ for i, p in enumerate(gem_port.pbit_map):
+ if p == '1':
+ ul_prior_q_entity_id = self.tcont_me_to_queue_map[tcont.entity_id][i]
+ dl_prior_q_entity_id = self.uni_port_to_queue_map[self._uni_port.entity_id][i]
+ break
+
+ assert ul_prior_q_entity_id is not None and dl_prior_q_entity_id is not None
+
+ # TODO: Need to restore on failure. Need to check status/results
+ results = yield gem_port.add_to_hardware(omci_cc,
+ tcont.entity_id,
+ self._ieee_mapper_service_profile_entity_id +
+ self._uni_port.mac_bridge_port_num,
+ self._gal_enet_profile_entity_id,
+ ul_prior_q_entity_id, dl_prior_q_entity_id)
+ self.check_status_and_state(results, 'create-gem-port')
+
+ elif gem_port.direction == OnuGemPort.DOWNSTREAM:
+ # Downstream is inverse of upstream
+ # TODO: could also be a case of multicast. Not supported for now
+ pass
+
+ ################################################################################
+ # Update the IEEE 802.1p Mapper Service Profile config
+ #
+ # EntityID was created prior to this call. This is a set
+ #
+ # References:
+ # - Gem Interwork TPs are set here
+ #
+ gem_entity_ids = [OmciNullPointer] * 8
+
+ for gem_port in self._gem_ports:
+ self.strobe_watchdog()
+ self.log.debug("tp-gem-port", entity_id=gem_port.entity_id, uni_id=gem_port.uni_id)
+
+ if gem_port.direction in {OnuGemPort.UPSTREAM, OnuGemPort.BIDIRECTIONAL}:
+ for i, p in enumerate(gem_port.pbit_map):
+ if p == '1':
+ gem_entity_ids[i] = gem_port.entity_id
+
+ elif gem_port.direction == OnuGemPort.DOWNSTREAM:
+ # Downstream gem port p-bit mapper is inverse of upstream
+ # TODO: Could also be a case of multicast. Not supported for now
+ pass
+
+ msg = Ieee8021pMapperServiceProfileFrame(
+ self._ieee_mapper_service_profile_entity_id +
+ self._uni_port.mac_bridge_port_num, # 802.1p mapper Service Mapper Profile ID
+ interwork_tp_pointers=gem_entity_ids # Interworking TP IDs
+ )
+ frame = msg.set()
+ self.log.debug('openomci-msg', omci_msg=msg)
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-8021p-mapper-service-profile-ul')
+
+ ################################################################################
+ # Create Extended VLAN Tagging Operation config (PON-side)
+ #
+ # EntityID relates to the VLAN TCIS
+ # References:
+ # - VLAN TCIS from previously created VLAN Tagging filter data
+ # - PPTP Ethernet or VEIP UNI
+ #
+ # TODO: do this for all uni/ports...
+ # TODO: magic. static variable for assoc_type
+ # default to PPTP
+ # if self._uni_port.type is UniType.VEIP:
+ # association_type = 10
+ # elif self._uni_port.type is UniType.PPTP:
+ # association_type = 2
+ # else:
+ association_type = 2
+
+ attributes = dict(
+ association_type=association_type, # Assoc Type, PPTP/VEIP Ethernet UNI
+ associated_me_pointer=self._uni_port.entity_id, # Assoc ME, PPTP/VEIP Entity Id
+
+ # See VOL-1311 - Need to set table during create to avoid exception
+ # trying to read back table during post-create-read-missing-attributes
+ # But, because this is a R/W attribute. Some ONU may not accept the
+ # value during create. It is repeated again in a set below.
+ input_tpid=self._input_tpid, # input TPID
+ output_tpid=self._output_tpid, # output TPID
+ )
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes
+ )
+ frame = msg.create()
+ self.log.debug('openomci-msg', omci_msg=msg)
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-extended-vlan-tagging-operation-configuration-data')
+
+ attributes = dict(
+ # Specifies the TPIDs in use and that operations in the downstream direction are
+ # inverse to the operations in the upstream direction
+ input_tpid=self._input_tpid, # input TPID
+ output_tpid=self._output_tpid, # output TPID
+ downstream_mode=0, # inverse of upstream
+ )
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes
+ )
+ frame = msg.set()
+ self.log.debug('openomci-msg', omci_msg=msg)
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
+
+ attributes = dict(
+ # parameters: Entity Id ( 0x900), Filter Inner Vlan Id(0x1000-4096,do not filter on Inner vid,
+ # Treatment Inner Vlan Id : 2
+
+ # Update uni side extended vlan filter
+ # filter for untagged
+ # probably for eapol
+ # TODO: lots of magic
+ received_frame_vlan_tagging_operation_table=
+ VlanTaggingOperation(
+ filter_outer_priority=15, # This entry is not a double-tag rule
+ filter_outer_vid=4096, # Do not filter on the outer VID value
+ filter_outer_tpid_de=0, # Do not filter on the outer TPID field
+
+ filter_inner_priority=15, # This is a no-tag rule, ignore all other VLAN tag filter fields
+ filter_inner_vid=0x1000, # Do not filter on the inner VID
+ filter_inner_tpid_de=0, # Do not filter on inner TPID field
+
+ filter_ether_type=0, # Do not filter on EtherType
+ treatment_tags_to_remove=0, # Remove 0 tags
+
+ treatment_outer_priority=15, # Do not add an outer tag
+ treatment_outer_vid=0, # n/a
+ treatment_outer_tpid_de=0, # n/a
+
+ treatment_inner_priority=0, # Add an inner tag and insert this value as the priority
+ treatment_inner_vid=self._cvid, # use this value as the VID in the inner VLAN tag
+ treatment_inner_tpid_de=4, # set TPID
+ )
+ )
+ msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id + self._uni_port.mac_bridge_port_num, # Bridge Entity ID
+ attributes=attributes
+ )
+ frame = msg.set()
+ self.log.debug('openomci-msg', omci_msg=msg)
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data-table')
+
+ self.deferred.callback("tech-profile-download-success")
+
+ except TimeoutError as e:
+ self.log.warn('rx-timeout-2', e=e)
+ self.deferred.errback(failure.Failure(e))
+
+ except Exception as e:
+ self.log.exception('omci-setup-2', e=e)
+ self.deferred.errback(failure.Failure(e))
diff --git a/adapters/adtran_onu/omci/deprecated/adtn_service_download_task.py b/adapters/adtran_onu/omci/deprecated/adtn_service_download_task.py
new file mode 100644
index 0000000..a272e3d
--- /dev/null
+++ b/adapters/adtran_onu/omci/deprecated/adtn_service_download_task.py
@@ -0,0 +1,464 @@
+#
+# 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 twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks, returnValue, TimeoutError, failure
+from voltha.extensions.omci.omci_me import *
+from voltha.extensions.omci.tasks.task import Task
+from voltha.extensions.omci.omci_defs import *
+from voltha.adapters.adtran_onu.omci.omci import OMCI
+
+OP = EntityOperations
+RC = ReasonCodes
+
+
+class ServiceDownloadFailure(Exception):
+ """
+ This error is raised by default when the download fails
+ """
+
+
+class ServiceResourcesFailure(Exception):
+ """
+ This error is raised by when one or more resources required is not available
+ """
+
+
+class AdtnServiceDownloadTask(Task):
+ """
+ OpenOMCI MIB Download Example - Service specific
+
+ This task takes the legacy OMCI 'script' for provisioning the Adtran ONU
+ and converts it to run as a Task on the OpenOMCI Task runner. This is
+ in order to begin to decompose service instantiation in preparation for
+ Technology Profile work.
+
+ Once technology profiles are ready, some of this task may hang around or
+ be moved into OpenOMCI if there are any very common settings/configs to do
+ for any profile that may be provided in the v2.0 release
+
+ Currently, the only service tech profiles expected by v2.0 will be for AT&T
+ residential data service and DT residential data service.
+ """
+ task_priority = Task.DEFAULT_PRIORITY + 10
+ default_tpid = 0x8100 # TODO: Move to a better location
+ name = "ADTRAN Service Download Task"
+ free_tcont_alloc_id = 0xFFFF
+ free_gpon_tcont_alloc_id = 0xFF
+
+ def __init__(self, omci_agent, handler):
+ """
+ Class initialization
+
+ :param omci_agent: (OpenOMCIAgent) OMCI Adapter agent
+ :param device_id: (str) ONU Device ID
+ """
+ super(AdtnServiceDownloadTask, self).__init__(AdtnServiceDownloadTask.name,
+ omci_agent,
+ handler.device_id,
+ priority=AdtnServiceDownloadTask.task_priority,
+ exclusive=False)
+ self._handler = handler
+ self._onu_device = omci_agent.get_device(handler.device_id)
+ self._local_deferred = None
+ self._pon = handler.pon_port()
+ self._extended_vlan_me_created = False
+
+ self._input_tpid = AdtnServiceDownloadTask.default_tpid
+ self._output_tpid = AdtnServiceDownloadTask.default_tpid
+
+ # TODO: TCIS below is just a test, may need 0x900...as in the xPON mode
+ # self._vlan_tcis_1 = OMCI.DEFAULT_UNTAGGED_VLAN
+ self._vid = OMCI.DEFAULT_UNTAGGED_VLAN
+
+ # Entity IDs. IDs with values can probably be most anything for most ONUs,
+ # IDs set to None are discovered/set
+ #
+ # TODO: Probably need to store many of these in the appropriate object (UNI, PON,...)
+ #
+ self._ieee_mapper_service_profile_entity_id = self._pon.ieee_mapper_service_profile_entity_id
+ self._gal_enet_profile_entity_id = self._handler.gal_enet_profile_entity_id
+
+ # Next to are specific
+ self._ethernet_uni_entity_id = self._handler.uni_ports[0].entity_id
+ self._mac_bridge_service_profile_entity_id = self._handler.mac_bridge_service_profile_entity_id
+
+ def cancel_deferred(self):
+ super(AdtnServiceDownloadTask, self).cancel_deferred()
+
+ d, self._local_deferred = self._local_deferred, None
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def start(self):
+ """
+ Start the MIB Service Download
+ """
+ super(AdtnServiceDownloadTask, self).start()
+ self._local_deferred = reactor.callLater(0, self.perform_service_download)
+
+ def stop(self):
+ """
+ Shutdown MIB Service download
+ """
+ self.log.debug('stopping')
+
+ self.cancel_deferred()
+ super(AdtnServiceDownloadTask, self).stop()
+
+ def check_status_and_state(self, results, operation=''):
+ """
+ Check the results of an OMCI response. An exception is thrown
+ if the task was cancelled or an error was detected.
+
+ :param results: (OmciFrame) OMCI Response frame
+ :param operation: (str) what operation was being performed
+ :return: True if successful, False if the entity existed (already created)
+ """
+ omci_msg = results.fields['omci_message'].fields
+ status = omci_msg['success_code']
+ error_mask = omci_msg.get('parameter_error_attributes_mask', 'n/a')
+ failed_mask = omci_msg.get('failed_attributes_mask', 'n/a')
+ unsupported_mask = omci_msg.get('unsupported_attributes_mask', 'n/a')
+
+ self.log.debug(operation, status=status, error_mask=error_mask,
+ failed_mask=failed_mask, unsupported_mask=unsupported_mask)
+
+ if status == RC.Success:
+ self.strobe_watchdog()
+ return True
+
+ elif status == RC.InstanceExists:
+ return False
+
+ raise ServiceDownloadFailure('{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
+ .format(operation, status, error_mask, failed_mask, unsupported_mask))
+
+ @inlineCallbacks
+ def perform_service_download(self):
+ """
+ Send the commands to minimally configure the PON, Bridge, and
+ UNI ports for this device. The application of any service flows
+ and other characteristics are done once resources (gem-ports, tconts, ...)
+ have been defined.
+ """
+ self.log.debug('perform-service-download')
+ device = self._handler.adapter_agent.get_device(self.device_id)
+
+ def resources_available():
+ return (len(self._handler.uni_ports) > 0 and
+ len(self._pon.tconts) and
+ len(self._pon.gem_ports))
+
+ if self._handler.enabled and resources_available():
+ device.reason = 'Performing Service OMCI Download'
+ self._handler.adapter_agent.update_device(device)
+
+ try:
+ # Lock the UNI ports to prevent any alarms during initial configuration
+ # of the ONU
+ self.strobe_watchdog()
+ # Provision the initial bridge configuration
+ yield self.perform_service_specific_steps()
+
+ # And re-enable the UNIs if needed
+ yield self.enable_unis(self._handler.uni_ports, False)
+
+ # If here, we are done
+ device = self._handler.adapter_agent.get_device(self.device_id)
+ device.reason = ''
+ self._handler.adapter_agent.update_device(device)
+ self.deferred.callback('service-download-success')
+
+ except TimeoutError as e:
+ self.deferred.errback(failure.Failure(e))
+
+ except Exception as e:
+ self.deferred.errback(failure.Failure(e))
+ else:
+ # TODO: Provide better error reason, what was missing...
+ e = ServiceResourcesFailure('Required resources are not available')
+ self.deferred.errback(failure.Failure(e))
+
+ @inlineCallbacks
+ def perform_service_specific_steps(self):
+ omci_cc = self._onu_device.omci_cc
+ frame = None
+
+ try:
+ ################################################################################
+ # TCONTS
+ #
+ # EntityID will be referenced by:
+ # - GemPortNetworkCtp
+ # References:
+ # - ONU created TCONT (created on ONU startup)
+
+ tcont_idents = self._onu_device.query_mib(Tcont.class_id)
+ self.log.debug('tcont-idents', tcont_idents=tcont_idents)
+
+ for tcont in self._pon.tconts.itervalues():
+ if tcont.entity_id is None:
+ free_ids = {AdtnServiceDownloadTask.free_tcont_alloc_id,
+ AdtnServiceDownloadTask.free_gpon_tcont_alloc_id}
+
+ free_entity_id = next((k for k, v in tcont_idents.items()
+ if isinstance(k, int) and
+ v.get('attributes', {}).get('alloc_id', 0) in
+ free_ids), None)
+
+ if free_entity_id is None:
+ self.log.error('no-available-tconts')
+ raise ServiceResourcesFailure('No Available TConts')
+
+ try:
+ prev_alloc_id = tcont_idents[free_entity_id].get('attributes').get('alloc_id')
+ yield tcont.add_to_hardware(omci_cc, free_entity_id, prev_alloc_id=prev_alloc_id)
+
+ except Exception as e:
+ self.log.exception('tcont-set', e=e, eid=free_entity_id)
+ raise
+
+ ################################################################################
+ # GEMS (GemPortNetworkCtp and GemInterworkingTp)
+ #
+ # For both of these MEs, the entity_id is the GEM Port ID. The entity id of the
+ # GemInterworkingTp ME could be different since it has an attribute to specify
+ # the GemPortNetworkCtp entity id.
+ #
+ # TODO: In the GEM Port routine to add, it has a hardcoded upstream TM ID of 0x8000
+ # for the GemPortNetworkCtp ME
+ #
+ # GemPortNetworkCtp
+ # EntityID will be referenced by:
+ # - GemInterworkingTp
+ # References:
+ # - TCONT
+ # - Hardcoded upstream TM Entity ID
+ # - (Possibly in Future) Upstream Traffic descriptor profile pointer
+ #
+ # GemInterworkingTp
+ # EntityID will be referenced by:
+ # - Ieee8021pMapperServiceProfile
+ # References:
+ # - GemPortNetworkCtp
+ # - Ieee8021pMapperServiceProfile
+ # - GalEthernetProfile
+ #
+ for gem_port in self._pon.gem_ports.itervalues():
+ if not gem_port.in_hardware:
+ tcont = gem_port.tcont
+ if tcont is None:
+ raise Exception('unknown-tcont-reference', gem_id=gem_port.gem_id)
+
+ try:
+ yield gem_port.add_to_hardware(omci_cc,
+ tcont.entity_id,
+ self._ieee_mapper_service_profile_entity_id,
+ self._gal_enet_profile_entity_id)
+ except Exception as e:
+ self.log.exception('gem-add-failed', e=e, gem=gem_port)
+ raise
+
+ ################################################################################
+ # Update the IEEE 802.1p Mapper Service Profile config
+ #
+ # EntityID was created prior to this call. This is a set
+ #
+ # References:
+ # - Gem Interworking TPs are set here
+ #
+ # TODO: All p-bits currently go to the one and only GEMPORT ID for now
+ gem_ports = self._pon.gem_ports
+
+ if len(gem_ports):
+ gem_entity_ids = [gem_port.entity_id for _, gem_port in gem_ports.items()]
+ else:
+ gem_entity_ids = [OmciNullPointer]
+
+ frame = Ieee8021pMapperServiceProfileFrame(
+ self._ieee_mapper_service_profile_entity_id, # 802.1p mapper Service Mapper Profile ID
+ interwork_tp_pointers=gem_entity_ids # Interworking TP IDs
+ ).set()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-8021p-mapper-service-profile')
+
+ ################################################################################
+ # Create Extended VLAN Tagging Operation config (PON-side)
+ #
+ # EntityID relates to the VLAN TCIS
+ # References:
+ # - VLAN TCIS from previously created VLAN Tagging filter data
+ # - PPTP Ethernet UNI
+ #
+ # TODO: add entry here for additional UNI interfaces
+
+ attributes = dict(
+ association_type=2, # Assoc Type, PPTP Ethernet UNI
+ associated_me_pointer=self._ethernet_uni_entity_id # Assoc ME, PPTP Entity Id
+ )
+
+ frame = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id,
+ attributes=attributes
+ ).create()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'create-extended-vlan-tagging-operation-configuration-data')
+ self._extended_vlan_me_created = True
+
+ ################################################################################
+ # Update Extended VLAN Tagging Operation Config Data
+ #
+ # Specifies the TPIDs in use and that operations in the downstream direction are
+ # inverse to the operations in the upstream direction
+ # TODO: Downstream mode may need to be modified once we work more on the flow rules
+
+ attributes = dict(
+ input_tpid=self._input_tpid, # input TPID
+ output_tpid=self._output_tpid, # output TPID
+ downstream_mode=0, # inverse of upstream
+ )
+ frame = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id,
+ attributes=attributes
+ ).set()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
+
+ ################################################################################
+ # Update Extended VLAN Tagging Operation Config Data
+ #
+ # parameters: Entity Id ( 0x900), Filter Inner Vlan Id(0x1000-4096,do not filter on Inner vid,
+ # Treatment Inner Vlan Id : 2
+
+ attributes = dict(
+ received_frame_vlan_tagging_operation_table=
+ VlanTaggingOperation(
+ filter_outer_priority=15, # This entry is not a double-tag rule
+ filter_outer_vid=4096, # Do not filter on the outer VID value
+ filter_outer_tpid_de=0, # Do not filter on the outer TPID field
+
+ filter_inner_priority=15, # This is a no-tag rule, ignore all other VLAN tag filter fields
+ filter_inner_vid=0x1000, # Do not filter on the inner VID
+ filter_inner_tpid_de=0, # Do not filter on inner TPID field
+
+ filter_ether_type=0, # Do not filter on EtherType
+ treatment_tags_to_remove=0, # Remove 0 tags
+
+ treatment_outer_priority=15, # Do not add an outer tag
+ treatment_outer_vid=0, # n/a
+ treatment_outer_tpid_de=0, # n/a
+
+ treatment_inner_priority=0, # Add an inner tag and insert this value as the priority
+ treatment_inner_vid=self._vid, # use this value as the VID in the inner VLAN tag
+ treatment_inner_tpid_de=4, # set TPID
+ )
+ )
+ frame = ExtendedVlanTaggingOperationConfigurationDataFrame(
+ self._mac_bridge_service_profile_entity_id, # Entity ID
+ attributes=attributes # See above
+ ).set()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data-untagged')
+
+ ###############################################################################
+
+ except TimeoutError as e:
+ self.log.warn('rx-timeout-download', frame=hexlify(frame))
+ self.cleanup_on_error()
+ raise
+
+ except Exception as e:
+ self.log.exception('omci-setup-2', e=e)
+ self.cleanup_on_error()
+ raise
+
+ returnValue(None)
+
+ @inlineCallbacks
+ def enable_unis(self, unis, force_lock):
+ """
+ Lock or unlock one or more UNI ports
+
+ :param unis: (list) of UNI objects
+ :param force_lock: (boolean) If True, force lock regardless of enabled state
+ """
+ omci_cc = self._onu_device.omci_cc
+ frame = None
+
+ for uni in unis:
+ ################################################################################
+ # Lock/Unlock UNI - 0 to Unlock, 1 to lock
+ #
+ # EntityID is referenced by:
+ # - MAC bridge port configuration data for the UNI side
+ # References:
+ # - Nothing
+ try:
+ state = 1 if force_lock or not uni.enabled else 0
+ frame = PptpEthernetUniFrame(uni.entity_id,
+ attributes=dict(administrative_state=state)).set()
+ results = yield omci_cc.send(frame)
+ self.check_status_and_state(results, 'set-pptp-ethernet-uni-lock-restore')
+
+ except TimeoutError:
+ self.log.warn('rx-timeout-unis', frame=hexlify(frame))
+ raise
+
+ except Exception as e:
+ self.log.exception('omci-failure', e=e)
+ raise
+
+ returnValue(None)
+
+ @inlineCallbacks
+ def cleanup_on_error(self):
+
+ omci_cc = self._onu_device.omci_cc
+
+ if self._extended_vlan_me_created:
+ try:
+ eid = self._mac_bridge_service_profile_entity_id
+ frame = ExtendedVlanTaggingOperationConfigurationDataFrame(eid).delete()
+ results = yield omci_cc.send(frame)
+ status = results.fields['omci_message'].fields['success_code']
+ self.log.debug('delete-extended-vlan-me', status=status)
+
+ except Exception as e:
+ self.log.exception('extended-vlan-cleanup', e=e)
+ # Continue processing
+
+ for gem_port in self._pon.gem_ports.itervalues():
+ if gem_port.in_hardware:
+ try:
+ yield gem_port.remove_from_hardware(omci_cc)
+
+ except Exception as e:
+ self.log.exception('gem-port-cleanup', e=e)
+ # Continue processing
+
+ for tcont in self._pon.tconts.itervalues():
+ if tcont.entity_id != AdtnServiceDownloadTask.free_tcont_alloc_id:
+ try:
+ yield tcont.remove_from_hardware(omci_cc)
+
+ except Exception as e:
+ self.log.exception('tcont-cleanup', e=e)
+ # Continue processing
+
+ returnValue('Cleanup Complete')
diff --git a/adapters/adtran_onu/omci/omci.py b/adapters/adtran_onu/omci/omci.py
new file mode 100644
index 0000000..8469a3f
--- /dev/null
+++ b/adapters/adtran_onu/omci/omci.py
@@ -0,0 +1,367 @@
+# Copyright 2018-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.
+import structlog
+from twisted.internet.defer import inlineCallbacks, returnValue, TimeoutError
+from twisted.internet import reactor
+
+from voltha.protos.device_pb2 import Image
+
+from voltha.protos.common_pb2 import OperStatus, ConnectStatus
+from voltha.extensions.omci.onu_configuration import OMCCVersion
+
+from omci_entities import onu_custom_me_entities
+from voltha.extensions.omci.omci_me import *
+
+_STARTUP_RETRY_WAIT = 5
+# abbreviations
+OP = EntityOperations
+
+
+class OMCI(object):
+ """
+ OpenOMCI Support
+ """
+ DEFAULT_UNTAGGED_VLAN = 4091 # To be equivalent to BroadCom Defaults
+
+ def __init__(self, handler, omci_agent):
+ self.log = structlog.get_logger(device_id=handler.device_id)
+ self._handler = handler
+ self._openomci_agent = omci_agent
+ self._enabled = False
+ self._connected = False
+ self._deferred = None
+ self._bridge_initialized = False
+ self._in_sync_reached = False
+ self._omcc_version = OMCCVersion.Unknown
+ self._total_tcont_count = 0 # From ANI-G ME
+ self._qos_flexibility = 0 # From ONT2_G ME
+
+ self._in_sync_subscription = None
+ self._connectivity_subscription = None
+ self._capabilities_subscription = None
+
+ # self._service_downloaded = False
+ self._mib_downloaded = False
+ self._mib_download_task = None
+ self._mib_download_deferred = None
+
+ self._onu_omci_device = omci_agent.add_device(handler.device_id,
+ handler.adapter_agent,
+ custom_me_map=onu_custom_me_entities(),
+ support_classes=handler.adapter.adtran_omci)
+
+ def __str__(self):
+ return "OMCI"
+
+ @property
+ def omci_agent(self):
+ return self._openomci_agent
+
+ @property
+ def omci_cc(self):
+ # TODO: Decrement access to Communications channel at this point? What about current PM stuff?
+ return self.onu_omci_device.omci_cc if self._onu_omci_device is not None else None
+
+ def receive_message(self, msg):
+ if self.enabled:
+ # TODO: Have OpenOMCI actually receive the messages
+ self.omci_cc.receive_message(msg)
+
+ def _start(self):
+ self._cancel_deferred()
+
+ # Subscriber to events of interest in OpenOMCI
+ self._subscribe_to_events()
+ self._onu_omci_device.start()
+
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+ device.reason = 'Performing MIB Upload'
+ self._handler.adapter_agent.update_device(device)
+
+ if self._onu_omci_device.mib_db_in_sync:
+ self._deferred = reactor.callLater(0, self._mib_in_sync)
+
+ def _stop(self):
+ self._cancel_deferred()
+
+ # Unsubscribe to OpenOMCI Events
+ self._unsubscribe_to_events()
+ self._onu_omci_device.stop() # Will also cancel any running tasks/state-machines
+
+ self._mib_downloaded = False
+ self._mib_download_task = None
+ self._bridge_initialized = False
+ self._in_sync_reached = False
+
+ def _cancel_deferred(self):
+ d1, self._deferred = self._deferred, None
+ d2, self._mib_download_deferred = self._mib_download_deferred, None
+
+ for d in [d1, d2]:
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def delete(self):
+ self.enabled = False
+
+ agent, self._openomci_agent = self._openomci_agent, None
+ device_id = self._handler.device_id
+ self._onu_omci_device = None
+ self._handler = None
+
+ if agent is not None:
+ agent.remove_device(device_id, cleanup=True)
+
+ @property
+ def enabled(self):
+ return self._enabled
+
+ @enabled.setter
+ def enabled(self, value):
+ if self._enabled != value:
+ self._enabled = value
+
+ if value:
+ self._start()
+ else:
+ self._stop()
+
+ @property
+ def connected(self):
+ return self._connected
+
+ @property
+ def onu_omci_device(self):
+ return self._onu_omci_device
+
+ def set_pm_config(self, pm_config):
+ """
+ Set PM interval configuration
+
+ :param pm_config: (OnuPmIntervalMetrics) PM Interval configuration
+ :return:
+ """
+ self.onu_omci_device.set_pm_config(pm_config)
+
+ def _mib_in_sync(self):
+ """
+ This method is ran whenever the ONU MIB database is in-sync. This is often after
+ the initial MIB Upload during ONU startup, or after it has gone out-of-sync and
+ then back in. This second case could be due a reboot of the ONU and a new version
+ of firmware is running on the ONU hardware.
+ """
+ self.log.info('mib-in-sync')
+
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+ device.oper_status = OperStatus.ACTIVE
+ device.connect_status = ConnectStatus.REACHABLE
+ device.reason = ''
+ self._handler.adapter_agent.update_device(device)
+
+ omci_dev = self._onu_omci_device
+ config = omci_dev.configuration
+
+ # In Sync, we can register logical ports now. Ideally this could occur on
+ # the first time we received a successful (no timeout) OMCI Rx response.
+ try:
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+
+ ani_g = config.ani_g_entities
+ uni_g = config.uni_g_entities
+ pon_ports = len(ani_g) if ani_g is not None else 0
+ uni_ports = len(uni_g) if uni_g is not None else 0
+
+ # For the UNI ports below, they are created after the MIB Sync event occurs
+ # and the onu handler adds the ONU
+ assert pon_ports == 1, 'Expected one PON/ANI port, got {}'.format(pon_ports)
+ assert uni_ports == len(self._handler.uni_ports), \
+ 'Expected {} UNI port(s), got {}'.format(len(self._handler.uni_ports), uni_ports)
+
+ # serial_number = omci_dev.configuration.serial_number
+ # self.log.info('serial-number', serial_number=serial_number)
+
+ # Save entity_id of PON ports
+ self._handler.pon_ports[0].entity_id = ani_g.keys()[0]
+
+ self._total_tcont_count = ani_g.get('total-tcont-count')
+ self._qos_flexibility = config.qos_configuration_flexibility or 0
+ self._omcc_version = config.omcc_version or OMCCVersion.Unknown
+
+ # vendorProductCode = str(config.vendor_product_code or 'unknown').rstrip('\0')
+
+ host_info = omci_dev.query_mib(IpHostConfigData.class_id)
+ mgmt_mac_address = next((host_info[inst].get('attributes').get('mac_address')
+ for inst in host_info
+ if isinstance(inst, int)), 'unknown')
+ device.mac_address = str(mgmt_mac_address)
+ device.model = str(config.version or 'unknown').rstrip('\0')
+
+ equipment_id = config.equipment_id or " unknown unknown "
+ eqpt_boot_version = str(equipment_id).rstrip('\0')
+ # eqptId = eqpt_boot_version[:10] # ie) BVMDZ10DRA
+ boot_version = eqpt_boot_version[12:] # ie) CML.D55~
+
+ images = [Image(name='boot-code',
+ version=boot_version.rstrip('\0'),
+ is_active=False,
+ is_committed=True,
+ is_valid=True,
+ install_datetime='Not Available',
+ hash='Not Available')] + \
+ config.software_images
+
+ del (device.images.image[:]) # Clear previous entries
+ device.images.image.extend(images)
+
+ # Save our device information
+ self._handler.adapter_agent.update_device(device)
+
+ # Start MIB download TODO: This will be replaced with a MIB Download task soon
+ self._in_sync_reached = True
+
+ except Exception as e:
+ self.log.exception('device-info-load', e=e)
+ self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
+
+ def _subscribe_to_events(self):
+ from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \
+ OnuDeviceEntry
+ from voltha.extensions.omci.omci_cc import OMCI_CC, OmciCCRxEvents
+
+ # OMCI MIB Database sync status
+ bus = self._onu_omci_device.event_bus
+ topic = OnuDeviceEntry.event_bus_topic(self._handler.device_id,
+ OnuDeviceEvents.MibDatabaseSyncEvent)
+ self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
+
+ # OMCI Capabilities (MEs and Message Types
+ bus = self._onu_omci_device.event_bus
+ topic = OnuDeviceEntry.event_bus_topic(self._handler.device_id,
+ OnuDeviceEvents.OmciCapabilitiesEvent)
+ self._capabilities_subscription = bus.subscribe(topic, self.capabilities_handler)
+
+ # OMCI-CC Connectivity Events (for reachability/heartbeat)
+ bus = self._onu_omci_device.omci_cc.event_bus
+ topic = OMCI_CC.event_bus_topic(self._handler.device_id,
+ OmciCCRxEvents.Connectivity)
+ self._connectivity_subscription = bus.subscribe(topic, self.onu_is_reachable)
+
+ # TODO: Watch for any MIB RESET events or detection of an ONU reboot.
+ # If it occurs, set _service_downloaded and _mib_download to false
+ # and make sure that we get 'new' capabilities
+
+ def _unsubscribe_to_events(self):
+ insync, self._in_sync_subscription = self._in_sync_subscription, None
+ connect, self._connectivity_subscription = self._connectivity_subscription, None
+ caps, self._capabilities_subscription = self._capabilities_subscription, None
+
+ if insync is not None:
+ bus = self._onu_omci_device.event_bus
+ bus.unsubscribe(insync)
+
+ if connect is not None:
+ bus = self._onu_omci_device.omci_cc.event_bus
+ bus.unsubscribe(connect)
+
+ if caps is not None:
+ bus = self._onu_omci_device.event_bus
+ bus.unsubscribe(caps)
+
+ def in_sync_handler(self, _topic, msg):
+ if self._in_sync_subscription is not None:
+ try:
+ from voltha.extensions.omci.onu_device_entry import IN_SYNC_KEY
+
+ if msg[IN_SYNC_KEY]:
+ # Start up device_info load from MIB DB
+ reactor.callLater(0, self._mib_in_sync)
+ else:
+ # Cancel any running/scheduled MIB download task
+ try:
+ d, self._mib_download_deferred = self._mib_download_deferred, None
+ d.cancel()
+ except:
+ pass
+
+ except Exception as e:
+ self.log.exception('in-sync', e=e)
+
+ def capabilities_handler(self, _topic, _msg):
+ """
+ This event occurs after an ONU reaches the In-Sync state and the OMCI ME has
+ been queried for supported ME and message types.
+
+ At this point, we can act upon any download device and/or service Technology
+ profiles (when they exist). For now, just run our somewhat fixed script
+ """
+ if self._capabilities_subscription is not None:
+ from adtn_mib_download_task import AdtnMibDownloadTask
+ self._mib_download_task = None
+
+ def success(_results):
+ dev = self._handler.adapter_agent.get_device(self._handler.device_id)
+ dev.reason = ''
+ self._handler.adapter_agent.update_device(dev)
+ self._mib_downloaded = True
+ self._mib_download_task = None
+
+ def failure(reason):
+ self.log.error('mib-download-failure', reason=reason)
+ self._mib_download_task = None
+ dev = self._handler.adapter_agent.get_device(self._handler.device_id)
+ self._handler.adapter_agent.update_device(dev)
+ self._mib_download_deferred = reactor.callLater(_STARTUP_RETRY_WAIT,
+ self.capabilities_handler,
+ None, None)
+ if not self._mib_downloaded:
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+ device.reason = 'Initial MIB Download'
+ self._handler.adapter_agent.update_device(device)
+ self._mib_download_task = AdtnMibDownloadTask(self.omci_agent,
+ self._handler)
+ if self._mib_download_task is not None:
+ self._mib_download_deferred = \
+ self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
+ self._mib_download_deferred.addCallbacks(success, failure)
+
+ def onu_is_reachable(self, _topic, msg):
+ """
+ Reach-ability change event
+ :param _topic: (str) subscription topic, not used
+ :param msg: (dict) 'connected' key holds True if reachable
+ """
+ from voltha.extensions.omci.omci_cc import CONNECTED_KEY
+ if self._connectivity_subscription is not None:
+ try:
+ connected = msg[CONNECTED_KEY]
+
+ # TODO: For now, only care about the first connect occurrence.
+ # Later we could use this for a heartbeat, but may want some hysteresis
+ # Cancel any 'reachable' subscriptions
+ if connected:
+ evt_bus = self._onu_omci_device.omci_cc.event_bus
+ evt_bus.unsubscribe(self._connectivity_subscription)
+ self._connectivity_subscription = None
+ self._connected = True
+
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+ device.oper_status = OperStatus.ACTIVE
+ device.connect_status = ConnectStatus.REACHABLE
+ self._handler.adapter_agent.update_device(device)
+
+ except Exception as e:
+ self.log.exception('onu-reachable', e=e)
diff --git a/adapters/adtran_onu/omci/omci_entities.py b/adapters/adtran_onu/omci/omci_entities.py
new file mode 100644
index 0000000..654078d
--- /dev/null
+++ b/adapters/adtran_onu/omci/omci_entities.py
@@ -0,0 +1,265 @@
+# 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.
+#
+""" Adtran vendor-specific OMCI Entities"""
+
+import inspect
+import sys
+import json
+from binascii import hexlify
+from bitstring import BitArray
+from scapy.fields import ByteField, ShortField, BitField
+from scapy.fields import IntField, StrFixedLenField, FieldListField, PacketLenField
+from scapy.packet import Packet
+from voltha.extensions.omci.omci_entities import EntityClassAttribute, \
+ AttributeAccess, EntityOperations, EntityClass
+
+# abbreviations
+ECA = EntityClassAttribute
+AA = AttributeAccess
+OP = EntityOperations
+
+
+class OntSystem(EntityClass):
+ class_id = 65300
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(StrFixedLenField("time_of_day", None, 8), {AA.R, AA.W}),
+ ]
+ mandatory_operations = {OP.Get}
+
+
+class VerizonOpenOMCI(EntityClass):
+ class_id = 65400
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(IntField("supported_specification_version", None), {AA.R}),
+ ECA(ShortField("pon_device_type", None), {AA.R}),
+ ECA(IntField("specification_in_use", None), {AA.R, AA.W})
+ ]
+ mandatory_operations = {OP.Get, OP.Set}
+
+
+class TwdmSystemProfile(EntityClass):
+ class_id = 65401
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(ByteField("total_twdm_channel_number", None), {AA.R}),
+ ECA(ByteField("channel_partition_index", None), {AA.R, AA.W}),
+ ECA(IntField("channel_partion_waiver_timer", None), {AA.R, AA.W}),
+ ECA(IntField("lods_re_initialization_timer", None), {AA.R, AA.W}),
+ ECA(IntField("lods_protection_timer", None), {AA.R, AA.W}),
+ ECA(IntField("downstream_tuning_timer", None), {AA.R, AA.W}),
+ ECA(IntField("upstream_tuning_timer", None), {AA.R, AA.W}),
+ ECA(StrFixedLenField("location_label_1", None, 24), {AA.R, AA.W}),
+ ECA(StrFixedLenField("location_label_2", None, 24), {AA.R, AA.W}),
+ ]
+ mandatory_operations = {OP.Get, OP.Set}
+
+
+class TwdmChannel(EntityClass):
+ class_id = 65402
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(ByteField("active_channel_indication", None), {AA.R}),
+ ECA(ByteField("operational_channel_indication", None), {AA.R}),
+ ECA(ByteField("downstream_wavelength_channel", None), {AA.R}),
+ ECA(ByteField("upstream_wavelength_channel", None), {AA.R}),
+ ]
+ mandatory_operations = {OP.Get}
+
+
+class WatchdogConfigData(EntityClass):
+ class_id = 65403
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(IntField("upstream_transmission_timing_drift_self_monitoring_capability", None), {AA.R}),
+ ECA(IntField("upstream_transmission_wavelength_drift_self_monitoring_capability", None), {AA.R}),
+ ECA(IntField("upstream_transmission_optical_power_self_monitoring_capability", None), {AA.R}),
+ ECA(IntField("mean_out_of_channel_optical_power_spectral_density_self_monitoring_capability", None), {AA.R}),
+ ECA(IntField("mean_optical_power_spectral_density_self_monitoring_capability", None), {AA.R}),
+ ]
+ mandatory_operations = {OP.Get}
+
+
+class FlexibleConfigurationStatusPortal(EntityClass):
+ class_id = 65420
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(IntField("service_instance", None), {AA.R, AA.W}),
+ ECA(ShortField("configuration_method", None), {AA.R, AA.W}),
+ ECA(ShortField("network_address", None), {AA.R, AA.W}),
+ ECA(ByteField("administrative_state", None), {AA.R, AA}),
+ ECA(ByteField("operational_state", None), {AA.R}, avc=True),
+ ECA(ShortField("cause_for_last_abnormal_halt", None), {AA.R}),
+ ECA(ShortField("configuration_portal_update_available", None), {AA.R, AA.W}),
+ ECA(StrFixedLenField("configuration_portal_table", None, 25), {AA.R, AA.W}),
+ ECA(ByteField("configuration_portal_result", None), {AA.R, AA.W}, avc=True),
+ ECA(ShortField("status_message_available", None), {AA.R, AA.W}, avc=True),
+ ECA(ByteField("status_message", None), {AA.R, AA.W}),
+ ECA(ByteField("status_message_result", None), {AA.R, AA.W}),
+ ECA(ShortField("associated_me_class", None), {AA.R}),
+ ECA(ShortField("associated_me_class_instance", None), {AA.R}),
+ ]
+ mandatory_operations = {OP.Get, OP.Set, OP.Create, OP.Delete, OP.GetNext, OP.SetTable}
+
+
+class Onu3G(EntityClass):
+ class_id = 65422
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(ByteField("flash_memory_performance_value", None), {AA.R}),
+ ECA(ByteField("latest_restart_reason", None), {AA.R}),
+ ECA(ShortField("total_number_of_status_snapshots", None), {AA.R}),
+ ECA(ShortField("number_of_valid_status_snapshots", None), {AA.R}),
+ ECA(ShortField("next_status_snapshot_index", None), {AA.R}),
+ ECA(ByteField("status_snapshot_record_table", None), {AA.R}), # TODO: MxN field
+ ECA(ByteField("snap_action", None), {AA.W}),
+ ECA(ByteField("most_recent_status_snapshot", None), {AA.R}), # TODO: N field
+ ECA(ByteField("reset_action", None), {AA.W}),
+ ]
+ mandatory_operations = {OP.Get, OP.Set, OP.GetNext}
+
+
+class AdtnVlanTaggingOperation(Packet):
+ name = "VlanTaggingOperation"
+ fields_desc = [
+ BitField("filter_outer_priority", 0, 4),
+ BitField("filter_outer_vid", 0, 13),
+ BitField("filter_outer_tpid_de", 0, 3),
+ BitField("pad1", 0, 12),
+
+ BitField("filter_inner_priority", 0, 4),
+ BitField("filter_inner_vid", 0, 13),
+ BitField("filter_inner_tpid_de", 0, 3),
+ BitField("pad2", 0, 8),
+ BitField("filter_ether_type", 0, 4),
+
+ BitField("treatment_tags_to_remove", 0, 2),
+ BitField("pad3", 0, 10),
+ BitField("treatment_outer_priority", 0, 4),
+ BitField("treatment_outer_vid", 0, 13),
+ BitField("treatment_outer_tpid_de", 0, 3),
+
+ BitField("pad4", 0, 12),
+ BitField("treatment_inner_priority", 0, 4),
+ BitField("treatment_inner_vid", 0, 13),
+ BitField("treatment_inner_tpid_de", 0, 3),
+ ]
+
+ def to_json(self):
+ return json.dumps(self.fields, separators=(',', ':'))
+
+ @staticmethod
+ def json_from_value(value):
+ bits = BitArray(hex=hexlify(value))
+ temp = AdtnVlanTaggingOperation(
+ filter_outer_priority=bits[0:4].uint, # 4 <-size
+ filter_outer_vid=bits[4:17].uint, # 13
+ filter_outer_tpid_de=bits[17:20].uint, # 3
+ # pad 12
+ filter_inner_priority=bits[32:36].uint, # 4
+ filter_inner_vid=bits[36:49].uint, # 13
+ filter_inner_tpid_de=bits[49:52].uint, # 3
+ # pad 8
+ filter_ether_type=bits[60:64].uint, # 4
+ treatment_tags_to_remove=bits[64:66].uint, # 2
+ # pad 10
+ treatment_outer_priority=bits[76:80].uint, # 4
+ treatment_outer_vid=bits[80:93].uint, # 13
+ treatment_outer_tpid_de=bits[93:96].uint, # 3
+ # pad 12
+ treatment_inner_priority=bits[108:112].uint, # 4
+ treatment_inner_vid=bits[112:125].uint, # 13
+ treatment_inner_tpid_de=bits[125:128].uint, # 3
+ )
+ return json.dumps(temp.fields, separators=(',', ':'))
+
+ def index(self):
+ return '{:02}'.format(self.fields.get('filter_outer_priority',0)) + \
+ '{:03}'.format(self.fields.get('filter_outer_vid',0)) + \
+ '{:01}'.format(self.fields.get('filter_outer_tpid_de',0)) + \
+ '{:03}'.format(self.fields.get('filter_inner_priority',0)) + \
+ '{:04}'.format(self.fields.get('filter_inner_vid',0)) + \
+ '{:01}'.format(self.fields.get('filter_inner_tpid_de',0)) + \
+ '{:02}'.format(self.fields.get('filter_ether_type',0))
+
+ def is_delete(self):
+ return self.fields.get('treatment_tags_to_remove',0) == 0x3 and \
+ self.fields.get('pad3',0) == 0x3ff and \
+ self.fields.get('treatment_outer_priority',0) == 0xf and \
+ self.fields.get('treatment_outer_vid',0) == 0x1fff and \
+ self.fields.get('treatment_outer_tpid_de',0) == 0x7 and \
+ self.fields.get('pad4',0) == 0xfff and \
+ self.fields.get('treatment_inner_priority',0) == 0xf and \
+ self.fields.get('treatment_inner_vid',0) == 0x1fff and \
+ self.fields.get('treatment_inner_tpid_de',0) == 0x7
+
+ def delete(self):
+ self.fields['treatment_tags_to_remove'] = 0x3
+ self.fields['pad3'] = 0x3ff
+ self.fields['treatment_outer_priority'] = 0xf
+ self.fields['treatment_outer_vid'] = 0x1fff
+ self.fields['treatment_outer_tpid_de'] = 0x7
+ self.fields['pad4'] = 0xfff
+ self.fields['treatment_inner_priority'] = 0xf
+ self.fields['treatment_inner_vid'] = 0x1fff
+ self.fields['treatment_inner_tpid_de'] = 0x7
+ return self
+
+
+class AdtnExtendedVlanTaggingOperationConfigurationData(EntityClass):
+ class_id = 171
+ attributes = [
+ ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
+ ECA(ByteField("association_type", None), {AA.R, AA.W, AA.SBC},
+ range_check=lambda x: 0 <= x <= 11),
+ ECA(ShortField("received_vlan_tagging_operation_table_max_size", None),
+ {AA.R}),
+ ECA(ShortField("input_tpid", None), {AA.R, AA.W}),
+ ECA(ShortField("output_tpid", None), {AA.R, AA.W}),
+ ECA(ByteField("downstream_mode", None), {AA.R, AA.W},
+ range_check=lambda x: 0 <= x <= 8),
+ ECA(StrFixedLenField("received_frame_vlan_tagging_operation_table",
+ AdtnVlanTaggingOperation, 16), {AA.R, AA.W}),
+ ECA(ShortField("associated_me_pointer", None), {AA.R, AA.W, AA.SBC}),
+ ECA(FieldListField("dscp_to_p_bit_mapping", None,
+ BitField('', 0, size=3), count_from=lambda _: 64),
+ {AA.R, AA.W}),
+ ]
+ mandatory_operations = {OP.Create, OP.Delete, OP.Set, OP.Get, OP.GetNext}
+ optional_operations = {OP.SetTable}
+
+
+
+
+#################################################################################
+# entity class lookup table from entity_class values
+_onu_entity_classes_name_map = dict(
+ inspect.getmembers(sys.modules[__name__], lambda o:
+ inspect.isclass(o) and issubclass(o, EntityClass) and o is not EntityClass)
+)
+_onu_custom_entity_classes = [c for c in _onu_entity_classes_name_map.itervalues()]
+_onu_custom_entity_id_to_class_map = dict()
+
+
+def onu_custom_me_entities():
+ if len(_onu_custom_entity_id_to_class_map) == 0:
+ for entity_class in _onu_custom_entity_classes:
+ assert entity_class.class_id not in _onu_custom_entity_id_to_class_map, \
+ "Class ID '{}' already exists in the class map".format(entity_class.class_id)
+ _onu_custom_entity_id_to_class_map[entity_class.class_id] = entity_class
+
+ return _onu_custom_entity_id_to_class_map
+
diff --git a/adapters/adtran_onu/onu_gem_port.py b/adapters/adtran_onu/onu_gem_port.py
new file mode 100644
index 0000000..de8ba04
--- /dev/null
+++ b/adapters/adtran_onu/onu_gem_port.py
@@ -0,0 +1,276 @@
+#
+# 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.
+
+import structlog
+from adapters.adtran_common.xpon.gem_port import GemPort
+from twisted.internet.defer import inlineCallbacks, returnValue
+from pyvoltha.adapters.extensions.omci.omci_me import GemPortNetworkCtpFrame, GemInterworkingTpFrame
+from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes
+
+
+class OnuGemPort(GemPort):
+ """
+ Adtran ONU specific implementation
+ """
+ UPSTREAM = 1
+ DOWNSTREAM = 2
+ BIDIRECTIONAL = 3
+
+ def __init__(self, handler, gem_data, alloc_id, tech_profile_id,
+ uni_id, entity_id,
+ multicast=False, traffic_class=None, is_mock=False):
+ gem_id = gem_data['gemport-id']
+ self.log = structlog.get_logger(device_id=handler.device_id, gem_id=gem_id)
+ encryption = gem_data['encryption']
+
+ super(OnuGemPort, self).__init__(gem_id, alloc_id, uni_id,
+ tech_profile_id,
+ encryption=encryption,
+ multicast=multicast,
+ traffic_class=traffic_class,
+ handler=handler,
+ is_mock=is_mock)
+ try:
+ self._gem_data = gem_data
+ self._entity_id = entity_id
+ self._tcont_entity_id = None
+ self._interworking = False
+ self.uni_id = gem_data['uni-id']
+ self.direction = gem_data.get('direction', OnuGemPort.BIDIRECTIONAL)
+
+ # IEEE 802.1p Mapper ME (#130) related parameters
+ self._pbit_map = None
+ self.pbit_map = gem_data.get('pbit-map', '0b00000011')
+
+ # Upstream priority queue ME (#277) related parameters
+ self.priority_q = gem_data.get('priority-q', 3)
+
+ self._max_q_size = None
+ self.max_q_size = gem_data.get('max-q-size', 'auto')
+
+ self.weight = gem_data.get('weight', 8)
+
+ self._discard_config = None
+ self.discard_config = gem_data.get('discard-config', None)
+
+ self._discard_policy = None
+ self.discard_policy = gem_data.get('discard-policy', 'TailDrop')
+
+ # Traffic scheduler ME (#278) related parameters
+ self._scheduling_policy = None
+ self.scheduling_policy = gem_data.get('scheduling-policy', 'WRR')
+
+ except Exception as _e:
+ raise
+
+ @property
+ def entity_id(self):
+ return self._entity_id
+
+ @property
+ def discard_config(self):
+ return self._discard_config
+
+ @discard_config.setter
+ def discard_config(self, discard_config):
+ assert isinstance(discard_config, dict), "discard-config not dict"
+ assert 'max-probability' in discard_config, "max-probability missing"
+ assert 'max-threshold' in discard_config, "max-hreshold missing"
+ assert 'min-threshold' in discard_config, "min-threshold missing"
+ self._discard_config = discard_config
+
+ @property
+ def discard_policy(self):
+ self.log.debug('function-entry')
+ return self._discard_policy
+
+ @discard_policy.setter
+ def discard_policy(self, discard_policy):
+ dp = ("TailDrop", "WTailDrop", "RED", "WRED")
+ assert (isinstance(discard_policy, str))
+ assert (discard_policy in dp)
+ self._discard_policy = discard_policy
+
+ @property
+ def max_q_size(self):
+ return self._max_q_size
+
+ @max_q_size.setter
+ def max_q_size(self, max_q_size):
+ if isinstance(max_q_size, str):
+ assert (max_q_size == "auto")
+ else:
+ assert (isinstance(max_q_size, int))
+
+ self._max_q_size = max_q_size
+
+ @property
+ def pbit_map(self):
+ return self._pbit_map
+
+ @pbit_map.setter
+ def pbit_map(self, pbit_map):
+ assert (isinstance(pbit_map, str))
+ assert (len(pbit_map[2:]) == 8) # Example format of pbit_map: "0b00000101"
+ try:
+ _ = int(pbit_map[2], 2)
+ except ValueError:
+ raise Exception("pbit_map-not-binary-string-{}".format(pbit_map))
+
+ # remove '0b'
+ self._pbit_map = pbit_map[2:]
+
+ @property
+ def scheduling_policy(self):
+ return self._scheduling_policy
+
+ @scheduling_policy.setter
+ def scheduling_policy(self, scheduling_policy):
+ sp = ("WRR", "StrictPriority")
+ assert (isinstance(scheduling_policy, str))
+ assert (scheduling_policy in sp)
+ self._scheduling_policy = scheduling_policy
+
+ @property
+ def in_hardware(self):
+ return self._tcont_entity_id is not None and self._interworking
+
+ @staticmethod
+ def create(handler, gem_data, alloc_id, tech_profile_id, uni_id, entity_id):
+ return OnuGemPort(handler, gem_data, alloc_id,
+ tech_profile_id, uni_id, entity_id)
+
+ @property
+ def tcont(self):
+ """ Get the associated TCONT object """
+ return self._handler.pon_port.tconts.get(self.alloc_id)
+
+ @inlineCallbacks
+ def add_to_hardware(self, omci,
+ tcont_entity_id,
+ ieee_mapper_service_profile_entity_id,
+ gal_enet_profile_entity_id):
+ if self._is_mock:
+ returnValue('mock')
+
+ self.log.debug('add-to-hardware', gem_id=self.gem_id,
+ gem_entity_id=self.entity_id,
+ tcont_entity_id=tcont_entity_id,
+ ieee_mapper_service_profile_entity_id=ieee_mapper_service_profile_entity_id,
+ gal_enet_profile_entity_id=gal_enet_profile_entity_id)
+
+ if self._tcont_entity_id is not None and self._tcont_entity_id != tcont_entity_id:
+ raise KeyError('GEM Port already assigned to TCONT: {}'.format(self._tcont_entity_id))
+
+ results = None
+ if self._tcont_entity_id is None:
+ try:
+ direction = "downstream" if self.multicast else "bi-directional"
+ assert not self.multicast, 'MCAST is not supported yet'
+
+ frame = GemPortNetworkCtpFrame(
+ self.entity_id, # same entity id as GEM port
+ port_id=self.gem_id,
+ tcont_id=tcont_entity_id,
+ direction=direction,
+ upstream_tm=0x8000 # TM ID, 32768 unique ID set in TD set TODO: Parameterize
+ # This is Priority Queue ME with this entity ID
+ # and the ME's related port value is 0x01.00.0007
+ # which is slot=0x01, tcont# = 0x00, priority= 0x0007
+ ).create()
+ results = yield omci.send(frame)
+
+ status = results.fields['omci_message'].fields['success_code']
+ error_mask = results.fields['omci_message'].fields['parameter_error_attributes_mask']
+ self.log.debug('create-gem-port-network-ctp', status=status, error_mask=error_mask)
+
+ if status == ReasonCodes.Success or status == ReasonCodes.InstanceExists:
+ self._tcont_entity_id = tcont_entity_id
+ else:
+ raise Exception('GEM Port create failed with status: {}'.format(status))
+
+ except Exception as e:
+ self.log.exception('gemport-create', e=e)
+ raise
+
+ if not self._interworking:
+ try:
+ extra = {'gal_loopback_configuration': 0} # No loopback
+
+ frame = GemInterworkingTpFrame(
+ self.entity_id, # same entity id as GEM port
+ gem_port_network_ctp_pointer=self.entity_id,
+ interworking_option=5, # IEEE 802.1
+ service_profile_pointer=ieee_mapper_service_profile_entity_id,
+ interworking_tp_pointer=0x0,
+ pptp_counter=1,
+ gal_profile_pointer=gal_enet_profile_entity_id,
+ attributes=extra
+ ).create()
+ results = yield omci.send(frame)
+
+ status = results.fields['omci_message'].fields['success_code']
+ error_mask = results.fields['omci_message'].fields['parameter_error_attributes_mask']
+ self.log.debug('create-gem-interworking-tp', status=status, error_mask=error_mask)
+
+ if status == ReasonCodes.Success or status == ReasonCodes.InstanceExists:
+ self._interworking = True
+ else:
+ raise Exception('GEM Interworking create failed with status: {}'.format(status))
+
+ except Exception as e:
+ self.log.exception('interworking-create', e=e)
+ raise
+
+ returnValue(results)
+
+ @inlineCallbacks
+ def remove_from_hardware(self, omci):
+ if self._is_mock:
+ returnValue('mock')
+
+ self.log.debug('remove-from-hardware', gem_id=self.gem_id)
+
+ results = None
+ if self._interworking:
+ try:
+ frame = GemInterworkingTpFrame(self.entity_id).delete()
+ results = yield omci.send(frame)
+ status = results.fields['omci_message'].fields['success_code']
+ self.log.debug('delete-gem-interworking-tp', status=status)
+
+ if status == ReasonCodes.Success:
+ self._interworking = False
+
+ except Exception as e:
+ self.log.exception('interworking-delete', e=e)
+ raise
+
+ if self._tcont_entity_id is not None:
+ try:
+ frame = GemPortNetworkCtpFrame(self.entity_id).delete()
+ results = yield omci.send(frame)
+
+ status = results.fields['omci_message'].fields['success_code']
+ self.log.debug('delete-gem-port-network-ctp', status=status)
+
+ if status == ReasonCodes.Success:
+ self._tcont_entity_id = None
+
+ except Exception as e:
+ self.log.exception('gemport-delete', e=e)
+ raise
+
+ returnValue(results)
diff --git a/adapters/adtran_onu/onu_tcont.py b/adapters/adtran_onu/onu_tcont.py
new file mode 100644
index 0000000..c314dc4
--- /dev/null
+++ b/adapters/adtran_onu/onu_tcont.py
@@ -0,0 +1,111 @@
+# 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.
+
+import structlog
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+from adapters.adtran_common.xpon.tcont import TCont
+from adapters.adtran_common.xpon.traffic_descriptor import TrafficDescriptor
+from pyvoltha.adapters.extensions.omci.omci_me import TcontFrame
+from pyvoltha.adapters.extensions.omci.omci_defs import ReasonCodes
+
+
+class OnuTCont(TCont):
+ """
+ Adtran ONU specific implementation
+ """
+ FREE_TCONT_ALLOC_ID = 0xFFFF
+ FREE_GPON_TCONT_ALLOC_ID = 0xFF # SFU may use this to indicate a free TCONT
+
+ def __init__(self, handler, alloc_id, sched_policy, tech_profile_id, uni_id, traffic_descriptor, is_mock=False):
+ super(OnuTCont, self).__init__(alloc_id, tech_profile_id, traffic_descriptor, uni_id, is_mock=is_mock)
+ self.log = structlog.get_logger(device_id=handler.device_id, alloc_id=alloc_id)
+
+ self._handler = handler
+ self.sched_policy = sched_policy
+ self._entity_id = None
+ self._free_alloc_id = OnuTCont.FREE_TCONT_ALLOC_ID
+
+ @property
+ def entity_id(self):
+ return self._entity_id
+
+ @staticmethod
+ def create(handler, tcont, td):
+ assert isinstance(tcont, dict), 'TCONT should be a dictionary'
+ assert isinstance(td, TrafficDescriptor), 'Invalid Traffic Descriptor data type'
+ return OnuTCont(handler,
+ tcont['alloc-id'],
+ tcont['q-sched-policy'],
+ tcont['tech-profile-id'],
+ tcont['uni-id'],
+ td)
+
+ @inlineCallbacks
+ def add_to_hardware(self, omci, tcont_entity_id, prev_alloc_id=FREE_TCONT_ALLOC_ID):
+ self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id)
+ if self._is_mock:
+ returnValue('mock')
+
+ if self._entity_id == tcont_entity_id:
+ returnValue('Already set')
+
+ elif self.entity_id is not None:
+ raise KeyError('TCONT already assigned: {}'.format(self.entity_id))
+
+ try:
+ # TODO: Look up ONU2-G QoS flexibility attribute and only set this
+ # if q-sched-policy can be supported
+
+ self._free_alloc_id = prev_alloc_id
+ frame = TcontFrame(tcont_entity_id, self.alloc_id).set()
+ results = yield omci.send(frame)
+
+ status = results.fields['omci_message'].fields['success_code']
+ if status == ReasonCodes.Success:
+ self._entity_id = tcont_entity_id
+
+ failed_attributes_mask = results.fields['omci_message'].fields['failed_attributes_mask']
+ unsupported_attributes_mask = results.fields['omci_message'].fields['unsupported_attributes_mask']
+
+ self.log.debug('set-tcont', status=status,
+ failed_attributes_mask=failed_attributes_mask,
+ unsupported_attributes_mask=unsupported_attributes_mask)
+
+ except Exception as e:
+ self.log.exception('tcont-set', e=e)
+ raise
+
+ returnValue(results)
+
+ @inlineCallbacks
+ def remove_from_hardware(self, omci):
+ self.log.debug('remove-from-hardware', tcont_entity_id=self.entity_id)
+ if self._is_mock:
+ returnValue('mock')
+ try:
+ frame = TcontFrame(self.entity_id, self._free_alloc_id).set()
+ results = yield omci.send(frame)
+
+ status = results.fields['omci_message'].fields['success_code']
+ self.log.debug('delete-tcont', status=status)
+
+ if status == ReasonCodes.Success:
+ self._entity_id = None
+
+ except Exception as e:
+ self.log.exception('tcont-delete', e=e)
+ raise
+
+ returnValue(results)
diff --git a/adapters/adtran_onu/onu_traffic_descriptor.py b/adapters/adtran_onu/onu_traffic_descriptor.py
new file mode 100644
index 0000000..5f5b59b
--- /dev/null
+++ b/adapters/adtran_onu/onu_traffic_descriptor.py
@@ -0,0 +1,78 @@
+# 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 adapters.adtran_common.xpon.traffic_descriptor import TrafficDescriptor
+from adapters.adtran_common.xpon.best_effort import BestEffort
+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
+
+
+class OnuTrafficDescriptor(TrafficDescriptor):
+ """
+ Adtran ONU specific implementation
+ """
+ def __init__(self, fixed, assured, maximum,
+ additional=TrafficDescriptor.AdditionalBwEligibility.DEFAULT,
+ best_effort=None):
+ super(OnuTrafficDescriptor, self).__init__(fixed, assured, maximum,
+ additional=additional,
+ best_effort=best_effort)
+
+ @staticmethod
+ def create(traffic_disc):
+ assert isinstance(traffic_disc, dict), 'Traffic Descriptor should be a dictionary'
+
+ additional = TrafficDescriptor.AdditionalBwEligibility.from_value(
+ traffic_disc['additional-bw-eligibility-indicator'])
+
+ if additional == TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING:
+ best_effort = BestEffort(traffic_disc['maximum-bandwidth'],
+ traffic_disc['priority'],
+ traffic_disc['weight'])
+ else:
+ best_effort = None
+
+ return OnuTrafficDescriptor(traffic_disc['fixed-bandwidth'],
+ traffic_disc['assured-bandwidth'],
+ traffic_disc['maximum-bandwidth'],
+ best_effort=best_effort,
+ additional=additional)
+
+ @inlineCallbacks
+ def add_to_hardware(self, omci):
+
+ results = succeed('TODO: Implement me')
+ # from ..adtran_olt_handler import AdtranOltHandler
+ #
+ # uri = AdtranOltHandler.GPON_TCONT_CONFIG_URI.format(pon_id, onu_id, alloc_id)
+ # data = json.dumps({'traffic-descriptor': self.to_dict()})
+ # name = 'tcont-td-{}-{}: {}'.format(pon_id, onu_id, alloc_id)
+ # try:
+ # results = yield session.request('PATCH', uri, data=data, name=name)
+ #
+ # except Exception as e:
+ # log.exception('traffic-descriptor', td=self, e=e)
+ # raise
+ #
+ # if self.additional_bandwidth_eligibility == \
+ # TrafficDescriptor.AdditionalBwEligibility.BEST_EFFORT_SHARING:
+ # if self.best_effort is None:
+ # raise ValueError('TCONT is best-effort but does not define best effort sharing')
+ #
+ # try:
+ # results = yield self.best_effort.add_to_hardware(session, pon_id, onu_id, alloc_id)
+ #
+ # except Exception as e:
+ # log.exception('best-effort', best_effort=self.best_effort, e=e)
+ # raise
+ returnValue(results)
diff --git a/adapters/adtran_onu/pon_port.py b/adapters/adtran_onu/pon_port.py
new file mode 100644
index 0000000..fd0d0c1
--- /dev/null
+++ b/adapters/adtran_onu/pon_port.py
@@ -0,0 +1,248 @@
+# 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.
+
+import structlog
+from twisted.internet.defer import inlineCallbacks, returnValue
+from pyvoltha.protos.common_pb2 import AdminState, OperStatus
+from pyvoltha.protos.device_pb2 import Port
+
+
+class PonPort(object):
+ """Wraps northbound-port/ANI support for ONU"""
+ MIN_GEM_ENTITY_ID = 0x4900
+ MAX_GEM_ENTITY_ID = 0x4AFF
+
+ def __init__(self, handler, port_no):
+ self.log = structlog.get_logger(device_id=handler.device_id, port_no=port_no)
+
+ self._enabled = False
+ self._valid = True
+ self._handler = handler
+ self._deferred = None
+ self._port = None
+ self._port_number = port_no
+ self._entity_id = None # ANI entity ID
+ self._next_entity_id = PonPort.MIN_GEM_ENTITY_ID
+
+ self._admin_state = AdminState.ENABLED
+ self._oper_status = OperStatus.ACTIVE
+
+ self._gem_ports = {} # gem-id -> GemPort
+ self._tconts = {} # alloc-id -> TCont
+
+ # OMCI resources
+ # TODO: These could be dynamically chosen (can be most any value)
+ self.ieee_mapper_service_profile_entity_id = 0x100
+ self.mac_bridge_port_ani_entity_id = 0x100
+
+ def __str__(self):
+ return "PonPort" # TODO: Encode current state
+
+ @staticmethod
+ def create(handler, port_no):
+ port = PonPort(handler, port_no)
+ return port
+
+ def _start(self):
+ self._cancel_deferred()
+
+ self._admin_state = AdminState.ENABLED
+ self._oper_status = OperStatus.ACTIVE
+ self._update_adapter_agent()
+
+ def _stop(self):
+ self._cancel_deferred()
+
+ self._admin_state = AdminState.DISABLED
+ self._oper_status = OperStatus.UNKNOWN
+ self._update_adapter_agent()
+
+ # TODO: stop h/w sync
+
+ def _cancel_deferred(self):
+ d1, self._deferred = self._deferred, None
+
+ for d in [d1]:
+ try:
+ if d is not None and not d.called:
+ d.cancel()
+ except:
+ pass
+
+ def delete(self):
+ self.enabled = False
+ self._valid = False
+ self._handler = None
+
+ @property
+ def enabled(self):
+ return self._enabled
+
+ @enabled.setter
+ def enabled(self, value):
+ if self._enabled != value:
+ self._enabled = value
+
+ if value:
+ self._start()
+ else:
+ self._stop()
+
+ @property
+ def port_number(self):
+ return self._port_number
+
+ @property
+ def entity_id(self):
+ """
+ OMCI ANI_G entity ID for port
+ """
+ return self._entity_id
+
+ @entity_id.setter
+ def entity_id(self, value):
+ assert self._entity_id is None or self._entity_id == value, 'Cannot reset the Entity ID'
+ self._entity_id = value
+
+ @property
+ def next_gem_entity_id(self):
+ entity_id = self._next_entity_id
+
+ self._next_entity_id = self._next_entity_id + 1
+ if self._next_entity_id > PonPort.MAX_GEM_ENTITY_ID:
+ self._next_entity_id = PonPort.MIN_GEM_ENTITY_ID
+
+ return entity_id
+
+ @property
+ def tconts(self):
+ return self._tconts
+
+ @property
+ def gem_ports(self):
+ return self._gem_ports
+
+ def get_port(self):
+ """
+ Get the VOLTHA PORT object for this port
+ :return: VOLTHA Port object
+ """
+ if self._port is None:
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+
+ self._port = Port(port_no=self.port_number,
+ label='PON port',
+ type=Port.PON_ONU,
+ admin_state=self._admin_state,
+ oper_status=self._oper_status,
+ peers=[Port.PeerPort(device_id=device.parent_id,
+ port_no=device.parent_port_no)])
+ return self._port
+
+ def _update_adapter_agent(self):
+ """
+ Update the port status and state in the core
+ """
+ self.log.debug('update-adapter-agent', admin_state=self._admin_state,
+ oper_status=self._oper_status)
+
+ if self._port is not None:
+ self._port.admin_state = self._admin_state
+ self._port.oper_status = self._oper_status
+
+ # adapter_agent add_port also does an update of port status
+ try:
+ self._handler.adapter_agent.add_port(self._handler.device_id, self.get_port())
+ except Exception as e:
+ self.log.exception('update-port', e=e)
+
+ def add_tcont(self, tcont, reflow=False):
+ """
+ Creates/ a T-CONT with the given alloc-id
+
+ :param tcont: (TCont) Object that maintains the TCONT properties
+ :param reflow: (boolean) If true, force add (used during h/w resync)
+ :return: (deferred)
+ """
+ if not self._valid:
+ return # Deleting
+
+ if not reflow and tcont.alloc_id in self._tconts:
+ return # already created
+
+ self.log.info('add', tcont=tcont, reflow=reflow)
+ self._tconts[tcont.alloc_id] = tcont
+
+ @inlineCallbacks
+ def remove_tcont(self, alloc_id):
+ tcont = self._tconts.get(alloc_id)
+
+ if tcont is None:
+ returnValue('nop')
+
+ try:
+ del self._tconts[alloc_id]
+ results = yield tcont.remove_from_hardware(self._handler.openomci.omci_cc)
+ returnValue(results)
+
+ except Exception as e:
+ self.log.exception('delete', e=e)
+ raise
+
+ def gem_port(self, gem_id):
+ return self._gem_ports.get(gem_id)
+
+ @property
+ def gem_ids(self):
+ """Get all GEM Port IDs used by this ONU"""
+ return sorted([gem_id for gem_id, gem in self._gem_ports.items()])
+
+ def add_gem_port(self, gem_port, reflow=False):
+ """
+ Add a GEM Port to this ONU
+
+ :param gem_port: (GemPort) GEM Port to add
+ :param reflow: (boolean) If true, force add (used during h/w resync)
+ :return: (deferred)
+ """
+ if not self._valid:
+ return # Deleting
+
+ if not reflow and gem_port.gem_id in self._gem_ports:
+ return # nop
+
+ self.log.info('add', gem_port=gem_port, reflow=reflow)
+ self._gem_ports[gem_port.gem_id] = gem_port
+
+ @inlineCallbacks
+ def remove_gem_id(self, gem_id):
+ """
+ Remove a GEM Port from this ONU
+
+ :param gem_port: (GemPort) GEM Port to remove
+ :return: deferred
+ """
+ gem_port = self._gem_ports.get(gem_id)
+
+ if gem_port is None:
+ returnValue('nop')
+
+ try:
+ del self._gem_ports[gem_id]
+ results = yield gem_port.remove_from_hardware(self._handler.openomci.omci_cc)
+ returnValue(results)
+
+ except Exception as ex:
+ self.log.exception('gem-port-delete', e=ex)
+ raise
diff --git a/adapters/adtran_onu/uni_port.py b/adapters/adtran_onu/uni_port.py
new file mode 100644
index 0000000..96cd353
--- /dev/null
+++ b/adapters/adtran_onu/uni_port.py
@@ -0,0 +1,227 @@
+# 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.
+
+import structlog
+from pyvoltha.protos.common_pb2 import OperStatus, AdminState
+from pyvoltha.protos.device_pb2 import Port
+from pyvoltha.protos.openflow_13_pb2 import OFPPF_10GB_FD
+from pyvoltha.protos.logical_device_pb2 import LogicalPort
+from pyvoltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER
+from pyvoltha.protos.openflow_13_pb2 import ofp_port
+import adtran_olt.resources.adtranolt_platform as platform
+
+
+class UniPort(object):
+ """Wraps southbound-port(s) support for ONU"""
+ def __init__(self, handler, name, port_no, ofp_port_no):
+ self.log = structlog.get_logger(device_id=handler.device_id, port_no=port_no)
+ self._enabled = False
+ self._handler = handler
+ self._name = name
+ self.uni_id = platform.uni_id_from_uni_port(port_no)
+ self._port = None
+ self._port_number = port_no
+ self._ofp_port_no = ofp_port_no # Set at by creator (vENET create)
+ self._logical_port_number = None # Set at time of logical port creation
+ self._entity_id = None # TODO: Use port number from UNI-G entity ID
+ self._mac_bridge_port_num = 0
+
+ self._admin_state = AdminState.ENABLED
+ self._oper_status = OperStatus.ACTIVE
+ # TODO Add state, stats, alarm reference, ...
+ pass
+
+ def __str__(self):
+ return "UniPort: {}:{}".format(self.name, self.port_number)
+
+ @staticmethod
+ def create(handler, name, port_no, ofp_port_no):
+ port = UniPort(handler, name, port_no, ofp_port_no)
+ return port
+
+ def _start(self):
+ self._cancel_deferred()
+
+ self._admin_state = AdminState.ENABLED
+ self._oper_status = OperStatus.ACTIVE
+ self._update_adapter_agent()
+ # TODO: start h/w sync
+ # TODO: Enable the actual physical port?
+ pass
+
+ def _stop(self):
+ self._cancel_deferred()
+
+ self._admin_state = AdminState.DISABLED
+ self._oper_status = OperStatus.UNKNOWN
+ self._update_adapter_agent()
+ # TODO: Disable/power-down the actual physical port?
+ pass
+
+ def delete(self):
+ self.enabled = False
+ self._handler = None
+
+ def _cancel_deferred(self):
+ pass
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def enabled(self):
+ return self._enabled
+
+ @enabled.setter
+ def enabled(self, value):
+ if self._enabled != value:
+ self._enabled = value
+
+ if value:
+ self._start()
+ else:
+ self._stop()
+
+ @property
+ def port_number(self):
+ """
+ Physical device port number
+ :return: (int) port number
+ """
+ return self._port_number
+
+ @property
+ def mac_bridge_port_num(self):
+ """
+ Port number used when creating MacBridgePortConfigurationDataFrame port number
+ :return: (int) port number
+ """
+ self.log.debug('function-entry')
+ return self._mac_bridge_port_num
+
+ @mac_bridge_port_num.setter
+ def mac_bridge_port_num(self, value):
+ self.log.debug('function-entry')
+ self._mac_bridge_port_num = value
+
+ @property
+ def entity_id(self):
+ """
+ OMCI UNI_G entity ID for port
+ """
+ return self._entity_id
+
+ @entity_id.setter
+ def entity_id(self, value):
+ assert self._entity_id is None, 'Cannot reset the Entity ID'
+ self._entity_id = value
+
+ @property
+ def logical_port_number(self):
+ """
+ Logical device port number (used as OpenFlow port for UNI)
+ :return: (int) port number
+ """
+ return self._logical_port_number
+
+ def _update_adapter_agent(self):
+ """
+ Update the port status and state in the core
+ """
+ self.log.debug('update-adapter-agent', admin_state=self._admin_state,
+ oper_status=self._oper_status)
+
+ if self._port is not None:
+ self._port.admin_state = self._admin_state
+ self._port.oper_status = self._oper_status
+
+ try:
+ # adapter_agent add_port also does an update of existing port
+ self._handler.adapter_agent.add_port(self._handler.device_id,
+ self.get_port())
+ except KeyError: # Expected exception during ONU disabling
+ pass
+ except Exception as e: # Expected exception during ONU disabling
+ self.log.exception('update-port', e=e)
+
+ def get_port(self):
+ """
+ Get the VOLTHA PORT object for this port
+ :return: VOLTHA Port object
+ """
+ if self._port is None:
+ self._port = Port(port_no=self.port_number,
+ label=self.port_id_name(),
+ type=Port.ETHERNET_UNI,
+ admin_state=self._admin_state,
+ oper_status=self._oper_status)
+ return self._port
+
+ def port_id_name(self):
+ return 'uni-{}'.format(self._port_number)
+
+ def add_logical_port(self, openflow_port_no, multi_uni_naming,
+ capabilities=OFPPF_10GB_FD | OFPPF_FIBER,
+ speed=OFPPF_10GB_FD):
+
+ if self._logical_port_number is not None:
+ # delete old logical port if it exists
+ try:
+ port = self._handler.adapter_agent.get_logical_port(self._handler.logical_device_id,
+ self.port_id_name())
+ self._handler.adapter_agent.delete_logical_port(self._handler.logical_device_id, port)
+
+ except Exception as e:
+ # assume this exception was because logical port does not already exist
+ pass
+
+ self._logical_port_number = None
+
+ # Use vENET provisioned values if none supplied
+ port_no = openflow_port_no or self._ofp_port_no
+
+ if self._logical_port_number is None and port_no is not None:
+ self._logical_port_number = port_no
+ device = self._handler.adapter_agent.get_device(self._handler.device_id)
+
+ def mac_str_to_tuple(mac):
+ """
+ Convert 'xx:xx:xx:xx:xx:xx' MAC address string to a tuple of integers.
+ Example: mac_str_to_tuple('00:01:02:03:04:05') == (0, 1, 2, 3, 4, 5)
+ """
+ return tuple(int(d, 16) for d in mac.split(':'))
+
+ openflow_port = ofp_port(
+ port_no=port_no,
+ hw_addr=mac_str_to_tuple('08:00:%02x:%02x:%02x:%02x' %
+ ((device.parent_port_no >> 8 & 0xff),
+ device.parent_port_no & 0xff,
+ (port_no >> 8) & 0xff,
+ port_no & 0xff)),
+ name=device.serial_number + ['', '-' + str(self._mac_bridge_port_num)][multi_uni_naming],
+ config=0,
+ state=OFPPS_LIVE,
+ curr=capabilities,
+ advertised=capabilities,
+ peer=capabilities,
+ curr_speed=speed,
+ max_speed=speed
+ )
+ self._handler.adapter_agent.add_logical_port(self._handler.logical_device_id,
+ LogicalPort(
+ id=self.port_id_name(),
+ ofp_port=openflow_port,
+ device_id=device.id,
+ device_port_no=self._port_number))