blob: dde4334c52531308f0e375a7a28ff0769658f9a8 [file] [log] [blame]
Balaji Purushothaman17795c52017-08-28 14:21:48 -05001#
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"""
Chip Bolinge84aca92018-03-27 11:45:56 -070020import structlog
Chip Bolingfd1fd372017-12-20 13:34:12 -060021import binascii
Chip Bolingef0e2fa2017-10-06 14:33:01 -050022from voltha.adapters.iadapter import OnuAdapter
Balaji Purushothaman17795c52017-08-28 14:21:48 -050023from voltha.protos import third_party
Chip Bolingfd1fd372017-12-20 13:34:12 -060024from adtran_onu_handler import AdtranOnuHandler
Chip Boling3971d242018-06-06 10:26:34 -050025from voltha.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
Chip Bolingfd1fd372017-12-20 13:34:12 -060026from twisted.internet import reactor
Chip Bolinge9313592018-06-08 13:36:18 -050027from omci.adtn_capabilities_task import AdtnCapabilitiesTask
28from omci.adtn_get_mds_task import AdtnGetMdsTask
29from omci.adtn_mib_sync import AdtnMibSynchronizer
Chip Bolingdaebae32018-10-26 09:39:21 -050030from omci.adtn_mib_resync_task import AdtnMibResyncTask
31from omci.adtn_mib_reconcile_task import AdtnMibReconcileTask
Chip Boling3971d242018-06-06 10:26:34 -050032from copy import deepcopy
Balaji Purushothaman17795c52017-08-28 14:21:48 -050033
34_ = third_party
Chip Bolingef0e2fa2017-10-06 14:33:01 -050035
Balaji Purushothaman17795c52017-08-28 14:21:48 -050036
Chip Bolingef0e2fa2017-10-06 14:33:01 -050037class AdtranOnuAdapter(OnuAdapter):
Balaji Purushothaman17795c52017-08-28 14:21:48 -050038 def __init__(self, adapter_agent, config):
Chip Bolingff3087f2017-10-12 09:26:29 -050039 self.log = structlog.get_logger()
Chip Bolingef0e2fa2017-10-06 14:33:01 -050040 super(AdtranOnuAdapter, self).__init__(adapter_agent=adapter_agent,
41 config=config,
42 device_handler_class=AdtranOnuHandler,
43 name='adtran_onu',
Chip Boling363d5ec2018-11-09 16:28:04 -060044 vendor='ADTRAN, Inc.',
Chip Boling495389b2018-12-20 14:42:58 -060045 version='1.25',
Chip Bolingef0e2fa2017-10-06 14:33:01 -050046 device_type='adtran_onu',
Chip Boling639eb6f2018-08-07 14:54:53 -050047 vendor_id='ADTN',
48 accepts_add_remove_flow_updates=False), # TODO: Support flow-mods
Chip Boling3971d242018-06-06 10:26:34 -050049 # Customize OpenOMCI for Adtran ONUs
50 self.adtran_omci = deepcopy(OpenOmciAgentDefaults)
51
Chip Boling9fef0fd2018-12-11 09:43:59 -060052 from voltha.extensions.omci.database.mib_db_dict import MibDbVolatileDict
53 self.adtran_omci['mib-synchronizer']['database'] = MibDbVolatileDict
54
Chip Bolinge9313592018-06-08 13:36:18 -050055 self.adtran_omci['mib-synchronizer']['state-machine'] = AdtnMibSynchronizer
56 self.adtran_omci['mib-synchronizer']['tasks']['get-mds'] = AdtnGetMdsTask
57 self.adtran_omci['mib-synchronizer']['tasks']['mib-audit'] = AdtnGetMdsTask
Chip Bolingdaebae32018-10-26 09:39:21 -050058 self.adtran_omci['mib-synchronizer']['tasks']['mib-resync'] = AdtnMibResyncTask
59 self.adtran_omci['mib-synchronizer']['tasks']['mib-reconcile'] = AdtnMibReconcileTask
Chip Bolinge9313592018-06-08 13:36:18 -050060 self.adtran_omci['omci-capabilities']['tasks']['get-capabilities'] = AdtnCapabilitiesTask
Chip Boling3971d242018-06-06 10:26:34 -050061 # TODO: Continue to customize adtran_omci here as needed
62
63 self._omci_agent = OpenOMCIAgent(self.adapter_agent.core,
64 support_classes=self.adtran_omci)
65
66 @property
67 def omci_agent(self):
68 return self._omci_agent
69
70 def start(self):
71 super(AdtranOnuAdapter, self).start()
72 self._omci_agent.start()
73
74 def stop(self):
75 omci, self._omci_agent = self._omci_agent, None
76 if omci is not None:
77 omci.stop()
78
79 super(AdtranOnuAdapter, self).stop()
Balaji Purushothaman17795c52017-08-28 14:21:48 -050080
Chip Bolingfd1fd372017-12-20 13:34:12 -060081 def suppress_alarm(self, filter):
82 raise NotImplementedError()
83
84 def unsuppress_alarm(self, filter):
85 raise NotImplementedError()
86
87 def download_image(self, device, request):
88 raise NotImplementedError()
89
90 def activate_image_update(self, device, request):
91 raise NotImplementedError()
92
93 def cancel_image_download(self, device, request):
94 raise NotImplementedError()
95
96 def revert_image_update(self, device, request):
97 raise NotImplementedError()
98
99 def get_image_download_status(self, device, request):
100 raise NotImplementedError()
101
102 def update_flows_incrementally(self, device, flow_changes, group_changes):
103 raise NotImplementedError()
104
105 def send_proxied_message(self, proxy_address, msg):
106 raise NotImplementedError('Not an ONU method')
107
108 def get_device_details(self, device):
109 raise NotImplementedError('TODO: Not currently supported')
110
111 def change_master_state(self, master):
112 raise NotImplementedError('Not currently supported or required')
113
114 def receive_inter_adapter_message(self, msg):
115 # Currently the only OLT Device adapter that uses this is the EdgeCore
116
Chip Bolinge84aca92018-03-27 11:45:56 -0700117 self.log.info('receive_inter_adapter_message', msg=msg)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600118 proxy_address = msg['proxy_address']
119 assert proxy_address is not None
Chip Bolingfd1fd372017-12-20 13:34:12 -0600120 # Device_id from the proxy_address is the olt device id. We need to
121 # get the onu device id using the port number in the proxy_address
Chip Bolingfd1fd372017-12-20 13:34:12 -0600122 device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600123 if device is not None:
Chip Boling521735d2018-12-20 09:58:01 -0600124 handler = self.devices_handlers[device.id]
125 handler.event_messages.put(msg)
126 else:
127 self.log.error("device-not-found")
Chip Bolingfd1fd372017-12-20 13:34:12 -0600128
129 def abandon_device(self, device):
130 raise NotImplementedError('TODO: Not currently supported')
131
132 def receive_onu_detect_state(self, proxy_address, state):
133 raise NotImplementedError('TODO: Not currently supported')
134
135 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
136 raise NotImplementedError('Not an ONU method')
137
138 def receive_proxied_message(self, proxy_address, msg):
Chip Bolinge84aca92018-03-27 11:45:56 -0700139 self.log.debug('receive-proxied-message', proxy_address=proxy_address,
Chip Bolingdaebae32018-10-26 09:39:21 -0500140 device_id=proxy_address.device_id, msg=binascii.hexlify(msg))
Chip Bolingfd1fd372017-12-20 13:34:12 -0600141 # Device_id from the proxy_address is the olt device id. We need to
142 # get the onu device id using the port number in the proxy_address
143 device = self.adapter_agent.get_child_device_with_proxy_address(proxy_address)
144
145 if device is not None:
146 handler = self.devices_handlers[device.id]
147 if handler is not None:
148 handler.receive_message(msg)
149
150 ######################################################################
Chip Bolingb4868192018-11-01 16:38:44 -0500151 # PON Mgnt APIs (Eventually will be deprecated)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600152
153 def create_interface(self, device, data):
154 """
155 API to create various interfaces (only some PON interfaces as of now)
156 in the devices
157 """
Chip Bolingfd1fd372017-12-20 13:34:12 -0600158 self.log.debug('create-interface', data=data)
159
160 handler = self.devices_handlers.get(device.id)
161 if handler is not None:
162 reactor.callLater(0, handler.xpon_create, data)
163
164 def update_interface(self, device, data):
165 """
166 API to update various interfaces (only some PON interfaces as of now)
167 in the devices
168 """
169 self.log.debug('update-interface', data=data)
170 handler = self.devices_handlers.get(device.id)
171 if handler is not None:
172 handler.xpon_update(data)
173
174 def remove_interface(self, device, data):
175 """
176 API to delete various interfaces (only some PON interfaces as of now)
177 in the devices
178 """
179 self.log.debug('remove-interface', data=data)
180 handler = self.devices_handlers.get(device.id)
181 if handler is not None:
182 handler.xpon_remove(data)
183
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500184 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
185 """
186 API to create tcont object in the devices
187 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600188 :param tcont_data: tcont data object
189 :param traffic_descriptor_data: traffic descriptor data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500190 :return: None
191 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500192 self.log.info('create-tcont', tcont_data=tcont_data,
193 traffic_descriptor_data=traffic_descriptor_data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600194 handler = self.devices_handlers.get(device.id)
195 if handler is not None:
196 handler.create_tcont(tcont_data, traffic_descriptor_data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500197
198 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
199 """
200 API to update tcont object in the devices
201 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600202 :param tcont_data: tcont data object
203 :param traffic_descriptor_data: traffic descriptor data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500204 :return: None
205 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500206 self.log.info('update-tcont', tcont_data=tcont_data,
207 traffic_descriptor_data=traffic_descriptor_data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600208 handler = self.devices_handlers.get(device.id)
209 if handler is not None:
210 handler.update_tcont(tcont_data, traffic_descriptor_data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500211
212 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
213 """
214 API to delete tcont object in the devices
215 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600216 :param tcont_data: tcont data object
217 :param traffic_descriptor_data: traffic descriptor data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500218 :return: None
219 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500220 self.log.info('remove-tcont', tcont_data=tcont_data,
221 traffic_descriptor_data=traffic_descriptor_data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600222 handler = self.devices_handlers.get(device.id)
223 if handler is not None:
224 handler.remove_tcont(tcont_data, traffic_descriptor_data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500225
226 def create_gemport(self, device, data):
227 """
228 API to create gemport object in the devices
229 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600230 :param data: gemport data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500231 :return: None
232 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500233 self.log.info('create-gemport', data=data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600234 handler = self.devices_handlers.get(device.id)
235 if handler is not None:
236 handler.xpon_create(data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500237
238 def update_gemport(self, device, data):
239 """
240 API to update gemport object in the devices
241 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600242 :param data: gemport data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500243 :return: None
244 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500245 self.log.info('update-gemport', data=data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600246 handler = self.devices_handlers.get(device.id)
247 if handler is not None:
248 handler.xpon_update(data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500249
250 def remove_gemport(self, device, data):
251 """
252 API to delete gemport object in the devices
253 :param device: device id
Chip Bolingfd1fd372017-12-20 13:34:12 -0600254 :param data: gemport data object
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500255 :return: None
256 """
Chip Bolingef0e2fa2017-10-06 14:33:01 -0500257 self.log.info('remove-gemport', data=data)
Chip Bolingfd1fd372017-12-20 13:34:12 -0600258 handler = self.devices_handlers.get(device.id)
259 if handler is not None:
260 handler.xpon_remove(data)
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500261
262 def create_multicast_gemport(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500263 raise NotImplemented('xPON has been deprecated')
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500264
265 def update_multicast_gemport(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500266 raise NotImplemented('xPON has been deprecated')
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500267
268 def remove_multicast_gemport(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500269 raise NotImplemented('xPON has been deprecated')
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500270
271 def create_multicast_distribution_set(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500272 raise NotImplemented('xPON has been deprecated')
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500273
274 def update_multicast_distribution_set(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500275 raise NotImplemented('xPON has been deprecated')
Balaji Purushothaman17795c52017-08-28 14:21:48 -0500276
277 def remove_multicast_distribution_set(self, device, data):
Chip Bolingb4868192018-11-01 16:38:44 -0500278 raise NotImplemented('xPON has been deprecated')