blob: 7a88ed0ee4d71906a36e14e5ed626b1d0ccfa289 [file] [log] [blame]
Chip Boling8e042f62019-02-12 16:14:34 -06001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Adtran ONU adapter.
19"""
20import structlog
21import binascii
22from pyvoltha.adapters.iadapter import OnuAdapter
23from pyvoltha.protos import third_party
24from adtran_onu_handler import AdtranOnuHandler
25from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
26from omci.adtn_capabilities_task import AdtnCapabilitiesTask
27from omci.adtn_get_mds_task import AdtnGetMdsTask
28from omci.adtn_mib_sync import AdtnMibSynchronizer
29from omci.adtn_mib_resync_task import AdtnMibResyncTask
30from omci.adtn_mib_reconcile_task import AdtnMibReconcileTask
31from copy import deepcopy
32
33_ = third_party
34
35
36class AdtranOnuAdapter(OnuAdapter):
37 def __init__(self, core_proxy, adapter_proxy, config):
38 self.log = structlog.get_logger()
39 super(AdtranOnuAdapter, self).__init__(core_proxy=core_proxy,
40 adapter_proxy=adapter_proxy,
41 config=config,
42 device_handler_class=AdtranOnuHandler,
43 name='adtran_onu',
44 vendor='ADTRAN, Inc.',
45 version='2.0',
46 device_type='adtran_onu',
47 vendor_id='ADTN',
48 accepts_bulk_flow_update=True,
49 accepts_add_remove_flow_updates=False) # TODO: Support flow-mods
50 # Customize OpenOMCI for Adtran ONUs
51 self.adtran_omci = deepcopy(OpenOmciAgentDefaults)
52
53 from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict
54 self.adtran_omci['mib-synchronizer']['database'] = MibDbVolatileDict
55
56 self.adtran_omci['mib-synchronizer']['state-machine'] = AdtnMibSynchronizer
57 self.adtran_omci['mib-synchronizer']['tasks']['get-mds'] = AdtnGetMdsTask
58 self.adtran_omci['mib-synchronizer']['tasks']['mib-audit'] = AdtnGetMdsTask
59 self.adtran_omci['mib-synchronizer']['tasks']['mib-resync'] = AdtnMibResyncTask
60 self.adtran_omci['mib-synchronizer']['tasks']['mib-reconcile'] = AdtnMibReconcileTask
61 self.adtran_omci['omci-capabilities']['tasks']['get-capabilities'] = AdtnCapabilitiesTask
62 # TODO: Continue to customize adtran_omci here as needed
63
Chip Bolingd2d7a4d2019-03-14 14:34:56 -050064 self._omci_agent = OpenOMCIAgent(self.adapter_agent,
Chip Boling8e042f62019-02-12 16:14:34 -060065 support_classes=self.adtran_omci)
66
67 @property
68 def omci_agent(self):
69 return self._omci_agent
70
71 def start(self):
72 super(AdtranOnuAdapter, self).start()
73 self._omci_agent.start()
74
75 def stop(self):
76 omci, self._omci_agent = self._omci_agent, None
77 if omci is not None:
78 omci.stop()
79
80 super(AdtranOnuAdapter, self).stop()
81
82 def download_image(self, device, request):
83 raise NotImplementedError()
84
85 def activate_image_update(self, device, request):
86 raise NotImplementedError()
87
88 def cancel_image_download(self, device, request):
89 raise NotImplementedError()
90
91 def revert_image_update(self, device, request):
92 raise NotImplementedError()
93
94 def get_image_download_status(self, device, request):
95 raise NotImplementedError()
96
97 def process_inter_adapter_message(self, msg):
98 # Currently the only OLT Device adapter that uses this is the EdgeCore
99
100 self.log.info('receive_inter_adapter_message', msg=msg)
101 proxy_address = msg['proxy_address']
102 assert proxy_address is not None
103 # Device_id from the proxy_address is the olt device id. We need to
104 # get the onu device id using the port number in the proxy_address
105 device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
106 if device is not None:
107 handler = self.devices_handlers[device.id]
108 handler.event_messages.put(msg)
109 else:
110 self.log.error("device-not-found")
111
112 def receive_proxied_message(self, proxy_address, msg):
113 self.log.debug('receive-proxied-message', proxy_address=proxy_address,
114 device_id=proxy_address.device_id, msg=binascii.hexlify(msg))
115 # Device_id from the proxy_address is the olt device id. We need to
116 # get the onu device id using the port number in the proxy_address
117 device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
118
119 if device is not None:
120 handler = self.devices_handlers[device.id]
121 if handler is not None:
122 handler.receive_message(msg)