Chip Boling | 2727599 | 2017-09-22 15:17:04 -0500 | [diff] [blame] | 1 | # Copyright 2017-present Adtran, Inc. |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 14 | |
| 15 | """ |
| 16 | Adtran 1-U OLT adapter. |
| 17 | """ |
| 18 | import structlog |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 19 | from twisted.internet import reactor, defer |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 20 | from zope.interface import implementer |
| 21 | |
| 22 | from adtran_olt_handler import AdtranOltHandler |
| 23 | from voltha.adapters.interface import IAdapterInterface |
| 24 | from voltha.protos import third_party |
| 25 | from voltha.protos.adapter_pb2 import Adapter |
| 26 | from voltha.protos.adapter_pb2 import AdapterConfig |
| 27 | from voltha.protos.common_pb2 import LogLevel |
| 28 | from voltha.protos.device_pb2 import DeviceType, DeviceTypes |
| 29 | from voltha.protos.health_pb2 import HealthStatus |
| 30 | from voltha.registry import registry |
| 31 | |
| 32 | _ = third_party |
| 33 | log = structlog.get_logger() |
| 34 | |
| 35 | |
| 36 | @implementer(IAdapterInterface) |
| 37 | class AdtranOltAdapter(object): |
| 38 | name = 'adtran_olt' |
| 39 | |
| 40 | supported_device_types = [ |
| 41 | DeviceType( |
| 42 | id=name, |
| 43 | adapter=name, |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 44 | accepts_bulk_flow_update=True, |
| 45 | accepts_add_remove_flow_updates=False # TODO: Support flow-mods |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 46 | ) |
| 47 | ] |
| 48 | |
| 49 | def __init__(self, adapter_agent, config): |
| 50 | self.adapter_agent = adapter_agent |
| 51 | self.config = config |
| 52 | self.descriptor = Adapter( |
| 53 | id=self.name, |
Chip Boling | bffef5e | 2018-08-07 14:53:12 -0500 | [diff] [blame] | 54 | vendor='Adtran Inc.', |
Chip Boling | 3810e13 | 2018-10-12 13:03:47 -0500 | [diff] [blame^] | 55 | version='1.24', |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 56 | config=AdapterConfig(log_level=LogLevel.INFO) |
| 57 | ) |
| 58 | log.debug('adtran_olt.__init__', adapter_agent=adapter_agent) |
| 59 | self.devices_handlers = dict() # device_id -> AdtranOltHandler() |
| 60 | self.interface = registry('main').get_args().interface |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 61 | self.logical_device_id_to_root_device_id = dict() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 62 | |
| 63 | def start(self): |
| 64 | """ |
| 65 | Called once after adapter instance is loaded. Can be used to async |
| 66 | initialization. |
| 67 | |
| 68 | :return: (None or Deferred) |
| 69 | """ |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 70 | log.info('started', interface=self.interface) |
| 71 | |
| 72 | def stop(self): |
| 73 | """ |
| 74 | Called once before adapter is unloaded. It can be used to perform |
| 75 | any cleanup after the adapter. |
| 76 | |
| 77 | :return: (None or Deferred) |
| 78 | """ |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 79 | log.info('stopped', interface=self.interface) |
| 80 | |
| 81 | def adapter_descriptor(self): |
| 82 | """ |
| 83 | Return the adapter descriptor object for this adapter. |
| 84 | |
| 85 | :return: voltha.Adapter grpc object (see voltha/protos/adapter.proto), |
| 86 | with adapter-specific information and config extensions. |
| 87 | """ |
| 88 | log.debug('get descriptor', interface=self.interface) |
| 89 | return self.descriptor |
| 90 | |
| 91 | def device_types(self): |
| 92 | """ |
| 93 | Return list of device types supported by the adapter. |
| 94 | |
| 95 | :return: voltha.DeviceTypes protobuf object, with optional type |
| 96 | specific extensions. |
| 97 | """ |
| 98 | log.debug('get device_types', interface=self.interface, items=self.supported_device_types) |
| 99 | return DeviceTypes(items=self.supported_device_types) |
| 100 | |
| 101 | def health(self): |
| 102 | """ |
| 103 | Return a 3-state health status using the voltha.HealthStatus message. |
| 104 | |
| 105 | :return: Deferred or direct return with voltha.HealthStatus message |
| 106 | """ |
| 107 | log.debug('get health', interface=self.interface) |
| 108 | return HealthStatus(state=HealthStatus.HealthState.HEALTHY) |
| 109 | |
| 110 | def change_master_state(self, master): |
| 111 | """ |
| 112 | Called to indicate if plugin shall assume or lose master role. The |
| 113 | master role can be used to perform functions that must be performed |
| 114 | from a single point in the cluster. In single-node deployments of |
| 115 | Voltha, the plugins are always in master role. |
| 116 | |
| 117 | :param master: (bool) True to indicate the mastership needs to be |
| 118 | assumed; False to indicate that mastership needs to be abandoned. |
| 119 | :return: (Deferred) which is fired by the adapter when mastership is |
| 120 | assumed/dropped, respectively. |
| 121 | """ |
| 122 | log.debug('change_master_state', interface=self.interface, master=master) |
| 123 | raise NotImplementedError() |
| 124 | |
| 125 | def adopt_device(self, device): |
| 126 | """ |
| 127 | Make sure the adapter looks after given device. Called when a device |
| 128 | is provisioned top-down and needs to be activated by the adapter. |
| 129 | |
| 130 | :param device: A voltha.Device object, with possible device-type |
| 131 | specific extensions. Such extensions shall be described as part of |
| 132 | the device type specification returned by device_types(). |
| 133 | :return: (Deferred) Shall be fired to acknowledge device ownership. |
| 134 | """ |
| 135 | log.info('adopt-device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 136 | kwargs = { |
| 137 | 'adapter': self, |
| 138 | 'device-id': device.id |
| 139 | } |
| 140 | self.devices_handlers[device.id] = AdtranOltHandler(**kwargs) |
| 141 | d = defer.Deferred() |
Chip Boling | ce5bfc0 | 2018-08-09 13:57:49 -0500 | [diff] [blame] | 142 | reactor.callLater(0, self.devices_handlers[device.id].activate, d, False) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 143 | return d |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 144 | |
khenaidoo | ce68104 | 2017-06-12 11:25:34 -0400 | [diff] [blame] | 145 | def reconcile_device(self, device): |
| 146 | """ |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 147 | Make sure the adapter looks after given device. Called when this device has |
| 148 | changed ownership from another Voltha instance to this one (typically, this |
| 149 | occurs when the previous voltha instance went down). |
khenaidoo | ce68104 | 2017-06-12 11:25:34 -0400 | [diff] [blame] | 150 | |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 151 | :param device: A voltha.Device object, with possible device-type specific |
| 152 | extensions. Such extensions shall be described as part of |
| 153 | the device type specification returned by device_types(). |
| 154 | :return: (Deferred) Shall be fired to acknowledge device ownership. |
| 155 | """ |
| 156 | log.info('reconcile-device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 157 | kwargs = { |
| 158 | 'adapter': self, |
| 159 | 'device-id': device.id |
| 160 | } |
| 161 | self.devices_handlers[device.id] = AdtranOltHandler(**kwargs) |
| 162 | d = defer.Deferred() |
Chip Boling | ce5bfc0 | 2018-08-09 13:57:49 -0500 | [diff] [blame] | 163 | reactor.callLater(0, self.devices_handlers[device.id].activate, d, True) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 164 | return d |
khenaidoo | ce68104 | 2017-06-12 11:25:34 -0400 | [diff] [blame] | 165 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 166 | def abandon_device(self, device): |
| 167 | """ |
| 168 | Make sure the adapter no longer looks after device. This is called |
| 169 | if device ownership is taken over by another Voltha instance. |
| 170 | |
| 171 | :param device: A Voltha.Device object. |
| 172 | :return: (Deferred) Shall be fired to acknowledge abandonment. |
| 173 | """ |
| 174 | log.info('abandon-device', device=device) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 175 | raise NotImplementedError() |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 176 | |
| 177 | def disable_device(self, device): |
| 178 | """ |
| 179 | This is called when a previously enabled device needs to be disabled |
| 180 | based on a NBI call. |
| 181 | |
| 182 | :param device: A Voltha.Device object. |
| 183 | :return: (Deferred) Shall be fired to acknowledge disabling the device. |
| 184 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 185 | log.info('disable-device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 186 | handler = self.devices_handlers.get(device.id) |
| 187 | if handler is not None: |
| 188 | reactor.callLater(0, handler.disable) |
| 189 | return device |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 190 | |
| 191 | def reenable_device(self, device): |
| 192 | """ |
| 193 | This is called when a previously disabled device needs to be enabled |
| 194 | based on a NBI call. |
| 195 | |
| 196 | :param device: A Voltha.Device object. |
| 197 | :return: (Deferred) Shall be fired to acknowledge re-enabling the device. |
| 198 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 199 | log.info('reenable-device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 200 | handler = self.devices_handlers.get(device.id) |
| 201 | if handler is not None: |
| 202 | d = defer.Deferred() |
| 203 | reactor.callLater(0, handler.reenable, done_deferred=d) |
| 204 | return d |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 205 | |
| 206 | def reboot_device(self, device): |
| 207 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 208 | This is called to reboot a device based on a NBI call. The admin state of the device |
| 209 | will not change after the reboot |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 210 | |
| 211 | :param device: A Voltha.Device object. |
| 212 | :return: (Deferred) Shall be fired to acknowledge the reboot. |
| 213 | """ |
| 214 | log.info('reboot_device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 215 | handler = self.devices_handlers.get(device.id) |
| 216 | if handler is not None: |
| 217 | reactor.callLater(0, handler.reboot) |
| 218 | return device |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 219 | |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 220 | def download_image(self, device, request): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 221 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 222 | This is called to request downloading a specified image into the standby partition |
| 223 | of a device based on a NBI call. |
| 224 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 225 | :param device: A Voltha.Device object. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 226 | :param request: A Voltha.ImageDownload object. |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 227 | :return: (Deferred) Shall be fired to acknowledge the download. |
| 228 | """ |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 229 | log.info('image_download', device=device, request=request) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 230 | handler = self.devices_handlers.get(device.id) |
| 231 | if handler is not None: |
| 232 | return handler.start_download(device, request, defer.Deferred()) |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 233 | |
| 234 | def get_image_download_status(self, device, request): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 235 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 236 | This is called to inquire about a requested image download status based |
| 237 | on a NBI call. The adapter is expected to update the DownloadImage DB object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 238 | with the query result |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 239 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 240 | :param device: A Voltha.Device object. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 241 | :param request: A Voltha.ImageDownload object. |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 242 | :return: (Deferred) Shall be fired to acknowledge |
| 243 | """ |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 244 | log.info('get_image_download', device=device, request=request) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 245 | handler = self.devices_handlers.get(device.id) |
| 246 | if handler is not None: |
| 247 | return handler.download_status(device, request, defer.Deferred()) |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 248 | |
| 249 | def cancel_image_download(self, device, request): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 250 | """ |
| 251 | This is called to cancel a requested image download |
| 252 | based on a NBI call. The admin state of the device will not |
| 253 | change after the download. |
| 254 | :param device: A Voltha.Device object. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 255 | :param request: A Voltha.ImageDownload object. |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 256 | :return: (Deferred) Shall be fired to acknowledge |
| 257 | """ |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 258 | log.info('cancel_image_download', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 259 | handler = self.devices_handlers.get(device.id) |
| 260 | if handler is not None: |
| 261 | return handler.cancel_download(device, request, defer.Deferred()) |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 262 | |
| 263 | def activate_image_update(self, device, request): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 264 | """ |
| 265 | This is called to activate a downloaded image from |
| 266 | a standby partition into active partition. |
| 267 | Depending on the device implementation, this call |
| 268 | may or may not cause device reboot. |
| 269 | If no reboot, then a reboot is required to make the |
| 270 | activated image running on device |
| 271 | This call is expected to be non-blocking. |
| 272 | :param device: A Voltha.Device object. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 273 | :param request: A Voltha.ImageDownload object. |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 274 | :return: (Deferred) OperationResponse object. |
| 275 | """ |
| 276 | log.info('activate_image_update', device=device, request=request) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 277 | handler = self.devices_handlers.get(device.id) |
| 278 | if handler is not None: |
| 279 | return handler.activate_image(device, request, defer.Deferred()) |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 280 | |
| 281 | def revert_image_update(self, device, request): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 282 | """ |
| 283 | This is called to deactivate the specified image at |
| 284 | active partition, and revert to previous image at |
| 285 | standby partition. |
| 286 | Depending on the device implementation, this call |
| 287 | may or may not cause device reboot. |
| 288 | If no reboot, then a reboot is required to make the |
| 289 | previous image running on device |
| 290 | This call is expected to be non-blocking. |
| 291 | :param device: A Voltha.Device object. |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 292 | :param request: A Voltha.ImageDownload object. |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 293 | :return: (Deferred) OperationResponse object. |
| 294 | """ |
| 295 | log.info('revert_image_update', device=device, request=request) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 296 | handler = self.devices_handlers.get(device.id) |
| 297 | if handler is not None: |
| 298 | return handler.revert_image(device, request, defer.Deferred()) |
Lydia Fang | 01f2e85 | 2017-06-28 17:24:58 -0700 | [diff] [blame] | 299 | |
sathishg | 5ae8622 | 2017-06-28 15:16:29 +0530 | [diff] [blame] | 300 | def self_test_device(self, device): |
| 301 | """ |
| 302 | This is called to Self a device based on a NBI call. |
| 303 | :param device: A Voltha.Device object. |
| 304 | :return: Will return result of self test |
| 305 | """ |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 306 | from voltha.protos.voltha_pb2 import SelfTestResponse |
sathishg | 5ae8622 | 2017-06-28 15:16:29 +0530 | [diff] [blame] | 307 | log.info('self-test-device', device=device.id) |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 308 | # TODO: Support self test? |
| 309 | return SelfTestResponse(result=SelfTestResponse.NOT_SUPPORTED) |
sathishg | 5ae8622 | 2017-06-28 15:16:29 +0530 | [diff] [blame] | 310 | |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 311 | def delete_device(self, device): |
| 312 | """ |
| 313 | This is called to delete a device from the PON based on a NBI call. |
| 314 | If the device is an OLT then the whole PON will be deleted. |
| 315 | |
| 316 | :param device: A Voltha.Device object. |
| 317 | :return: (Deferred) Shall be fired to acknowledge the deletion. |
| 318 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 319 | log.info('delete-device', device=device) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 320 | handler = self.devices_handlers.get(device.id) |
| 321 | if handler is not None: |
| 322 | reactor.callLater(0, handler.delete) |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 323 | return device |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 324 | |
| 325 | def get_device_details(self, device): |
| 326 | """ |
| 327 | This is called to get additional device details based on a NBI call. |
| 328 | |
| 329 | :param device: A Voltha.Device object. |
| 330 | :return: (Deferred) Shall be fired to acknowledge the retrieval of |
| 331 | additional details. |
| 332 | """ |
| 333 | log.debug('get_device_details', device=device) |
| 334 | raise NotImplementedError() |
| 335 | |
| 336 | def update_flows_bulk(self, device, flows, groups): |
| 337 | """ |
| 338 | Called after any flow table change, but only if the device supports |
| 339 | bulk mode, which is expressed by the 'accepts_bulk_flow_update' |
| 340 | capability attribute of the device type. |
| 341 | |
| 342 | :param device: A Voltha.Device object. |
| 343 | :param flows: An openflow_v13.Flows object |
| 344 | :param groups: An openflow_v13.Flows object |
| 345 | :return: (Deferred or None) |
| 346 | """ |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 347 | log.debug('bulk-flow-update', device_id=device.id, flows=flows, |
| 348 | groups=groups, num_flows=len(flows.items)) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 349 | assert len(groups.items) == 0, "Cannot yet deal with groups" |
Chip Boling | 7294b25 | 2017-06-15 16:16:55 -0500 | [diff] [blame] | 350 | |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 351 | handler = self.devices_handlers.get(device.id) |
| 352 | if handler is not None: |
| 353 | return handler.update_flow_table(flows.items, device) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 354 | |
| 355 | def update_flows_incrementally(self, device, flow_changes, group_changes): |
| 356 | """ |
| 357 | [This mode is not supported yet.] |
| 358 | |
| 359 | :param device: A Voltha.Device object. |
| 360 | :param flow_changes: |
| 361 | :param group_changes: |
| 362 | :return: |
| 363 | """ |
| 364 | log.debug('update_flows_incrementally', device=device, flow_changes=flow_changes, |
| 365 | group_changes=group_changes) |
| 366 | raise NotImplementedError() |
| 367 | |
| 368 | def update_pm_config(self, device, pm_configs): |
| 369 | """ |
| 370 | Called every time a request is made to change pm collection behavior |
| 371 | :param device: A Voltha.Device object |
| 372 | :param pm_configs: A Pms |
| 373 | """ |
| 374 | log.debug('update_pm_config', device=device, pm_configs=pm_configs) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 375 | handler = self.devices_handlers.get(device.id) |
| 376 | if handler is not None: |
| 377 | handler.update_pm_config(device, pm_configs) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 378 | |
| 379 | def send_proxied_message(self, proxy_address, msg): |
| 380 | """ |
| 381 | Forward a msg to a child device of device, addressed by the given |
| 382 | proxy_address=Device.ProxyAddress(). |
| 383 | |
| 384 | :param proxy_address: Address info for the parent device |
| 385 | to route the message to the child device. This was given to the |
| 386 | child device by the parent device at the creation of the child |
| 387 | device. |
| 388 | :param msg: (str) The actual message to send. |
| 389 | :return: (Deferred(None) or None) The return of this method should |
| 390 | indicate that the message was successfully *sent*. |
| 391 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 392 | log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 393 | handler = self.devices_handlers.get(proxy_address.device_id) |
| 394 | if handler is not None: |
| 395 | handler.send_proxied_message(proxy_address, msg) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 396 | |
| 397 | def receive_proxied_message(self, proxy_address, msg): |
| 398 | """ |
| 399 | Pass an async message (arrived via a proxy) to this device. |
| 400 | |
| 401 | :param proxy_address: Address info for the parent device |
| 402 | to route the message to the child device. This was given to the |
| 403 | child device by the parent device at the creation of the child |
| 404 | device. Note this is the proxy_address with which the adapter |
| 405 | had to register prior to receiving proxied messages. |
| 406 | :param msg: (str) The actual message received. |
| 407 | :return: None |
| 408 | """ |
| 409 | log.debug('receive_proxied_message', proxy_address=proxy_address, msg=msg) |
| 410 | raise NotImplementedError() |
| 411 | |
| 412 | def receive_packet_out(self, logical_device_id, egress_port_no, msg): |
| 413 | """ |
| 414 | Pass a packet_out message content to adapter so that it can forward it |
| 415 | out to the device. This is only called on root devices. |
| 416 | |
| 417 | :param logical_device_id: |
| 418 | :param egress_port_no: egress logical port number |
| 419 | :param msg: actual message |
| 420 | :return: None |
| 421 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 422 | log.debug('packet-out', logical_device_id=logical_device_id, |
| 423 | egress_port_no=egress_port_no, msg_len=len(msg)) |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 424 | |
| 425 | def ldi_to_di(ldi): |
| 426 | di = self.logical_device_id_to_root_device_id.get(ldi) |
| 427 | if di is None: |
| 428 | logical_device = self.adapter_agent.get_logical_device(ldi) |
| 429 | di = logical_device.root_device_id |
| 430 | self.logical_device_id_to_root_device_id[ldi] = di |
| 431 | return di |
| 432 | |
| 433 | device_id = ldi_to_di(logical_device_id) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 434 | handler = self.devices_handlers.get(device_id) |
| 435 | if handler is not None: |
| 436 | handler.packet_out(egress_port_no, msg) |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 437 | |
| 438 | def receive_inter_adapter_message(self, msg): |
| 439 | """ |
Chip Boling | 252c777 | 2017-08-16 10:13:17 -0500 | [diff] [blame] | 440 | Called when the adapter receives a message that was sent to it directly |
Chip Boling | 3e3b1a9 | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 441 | from another adapter. An adapter may register for these messages by calling |
| 442 | the register_for_inter_adapter_messages() method in the adapter agent. |
| 443 | Note that it is the responsibility of the sending and receiving |
| 444 | adapters to properly encode and decode the message. |
| 445 | :param msg: The message contents. |
| 446 | :return: None |
| 447 | """ |
| 448 | log.info('rx_inter_adapter_msg') |
| 449 | raise NotImplementedError() |
Chip Boling | 9900488 | 2017-05-19 15:36:19 -0500 | [diff] [blame] | 450 | |
| 451 | def suppress_alarm(self, filter): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 452 | """ |
| 453 | Inform an adapter that all incoming alarms should be suppressed |
| 454 | :param filter: A Voltha.AlarmFilter object. |
| 455 | :return: (Deferred) Shall be fired to acknowledge the suppression. |
| 456 | """ |
Chip Boling | 9900488 | 2017-05-19 15:36:19 -0500 | [diff] [blame] | 457 | log.info('suppress_alarm', filter=filter) |
| 458 | raise NotImplementedError() |
| 459 | |
| 460 | def unsuppress_alarm(self, filter): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 461 | """ |
| 462 | Inform an adapter that all incoming alarms should resume |
| 463 | :param filter: A Voltha.AlarmFilter object. |
| 464 | :return: (Deferred) Shall be fired to acknowledge the unsuppression. |
| 465 | """ |
Chip Boling | 9900488 | 2017-05-19 15:36:19 -0500 | [diff] [blame] | 466 | log.info('unsuppress_alarm', filter=filter) |
| 467 | raise NotImplementedError() |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 468 | |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 469 | # PON Mgnt APIs # |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 470 | def create_interface(self, device, data): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 471 | """ |
| 472 | API to create various interfaces (only some PON interfaces as of now) |
| 473 | in the devices |
| 474 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 475 | log.debug('create-interface', data=data) |
| 476 | handler = self.devices_handlers.get(device.id) |
| 477 | if handler is not None: |
| 478 | handler.xpon_create(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 479 | |
| 480 | def update_interface(self, device, data): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 481 | """ |
| 482 | API to update various interfaces (only some PON interfaces as of now) |
| 483 | in the devices |
| 484 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 485 | log.debug('update-interface', data=data) |
| 486 | handler = self.devices_handlers.get(device.id) |
| 487 | if handler is not None: |
| 488 | handler.xpon_update(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 489 | |
| 490 | def remove_interface(self, device, data): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 491 | """ |
| 492 | API to delete various interfaces (only some PON interfaces as of now) |
| 493 | in the devices |
| 494 | """ |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 495 | log.debug('remove-interface', data=data) |
| 496 | handler = self.devices_handlers.get(device.id) |
| 497 | if handler is not None: |
| 498 | handler.xpon_remove(data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 499 | |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 500 | def receive_onu_detect_state(self, proxy_address, state): |
Chip Boling | 5561d55 | 2017-07-07 15:11:26 -0500 | [diff] [blame] | 501 | """ |
| 502 | Receive onu detect state in ONU adapter |
| 503 | :param proxy_address: ONU device address |
| 504 | :param state: ONU detect state (bool) |
| 505 | :return: None |
| 506 | """ |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 507 | raise NotImplementedError() |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 508 | |
| 509 | def create_tcont(self, device, tcont_data, traffic_descriptor_data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 510 | """ |
| 511 | API to create tcont object in the devices |
| 512 | :param device: device id |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 513 | :param tcont_data: tcont data object |
| 514 | :param traffic_descriptor_data: traffic descriptor data object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 515 | :return: None |
| 516 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 517 | log.info('create-tcont', tcont_data=tcont_data, |
| 518 | traffic_descriptor_data=traffic_descriptor_data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 519 | handler = self.devices_handlers.get(device.id) |
| 520 | if handler is not None: |
| 521 | handler.create_tcont(tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 522 | |
| 523 | def update_tcont(self, device, tcont_data, traffic_descriptor_data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 524 | """ |
| 525 | API to update tcont object in the devices |
| 526 | :param device: device id |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 527 | :param tcont_data: tcont data object |
| 528 | :param traffic_descriptor_data: traffic descriptor data object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 529 | :return: None |
| 530 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 531 | log.info('update-tcont', tcont_data=tcont_data, |
| 532 | traffic_descriptor_data=traffic_descriptor_data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 533 | handler = self.devices_handlers.get(device.id) |
| 534 | if handler is not None: |
| 535 | handler.update_tcont(tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 536 | |
| 537 | def remove_tcont(self, device, tcont_data, traffic_descriptor_data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 538 | """ |
| 539 | API to delete tcont object in the devices |
| 540 | :param device: device id |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 541 | :param tcont_data: tcont data object |
| 542 | :param traffic_descriptor_data: traffic descriptor data object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 543 | :return: None |
| 544 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 545 | log.info('remove-tcont', tcont_data=tcont_data, |
| 546 | traffic_descriptor_data=traffic_descriptor_data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 547 | handler = self.devices_handlers.get(device.id) |
| 548 | if handler is not None: |
| 549 | handler.remove_tcont(tcont_data, traffic_descriptor_data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 550 | |
| 551 | def create_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 552 | """ |
| 553 | API to create gemport object in the devices |
| 554 | :param device: device id |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 555 | :param data: gemport data object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 556 | :return: None |
| 557 | """ |
Chip Boling | bb15b51 | 2018-06-01 11:39:58 -0500 | [diff] [blame] | 558 | log.debug('create-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 559 | handler = self.devices_handlers.get(device.id) |
| 560 | if handler is not None: |
| 561 | handler.xpon_create(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 562 | |
| 563 | def update_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 564 | """ |
| 565 | API to update gemport object in the devices |
| 566 | :param device: device id |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 567 | :param data: gemport data object |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 568 | :return: None |
| 569 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 570 | log.info('update-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 571 | handler = self.devices_handlers.get(device.id) |
| 572 | if handler is not None: |
| 573 | handler.xpon_update(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 574 | |
| 575 | def remove_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 576 | """ |
| 577 | API to delete gemport object in the devices |
| 578 | :param device: device id |
| 579 | :data: gemport data object |
| 580 | :return: None |
| 581 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 582 | log.info('remove-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 583 | handler = self.devices_handlers.get(device.id) |
| 584 | if handler is not None: |
| 585 | handler.xpon_remove(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 586 | |
| 587 | def create_multicast_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 588 | """ |
| 589 | API to create multicast gemport object in the devices |
| 590 | :param device: device id |
| 591 | :data: multicast gemport data object |
| 592 | :return: None |
| 593 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 594 | log.info('create-mcast-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 595 | handler = self.devices_handlers.get(device.id) |
| 596 | if handler is not None: |
| 597 | handler.xpon_create(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 598 | |
| 599 | def update_multicast_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 600 | """ |
| 601 | API to update multicast gemport object in the devices |
| 602 | :param device: device id |
| 603 | :data: multicast gemport data object |
| 604 | :return: None |
| 605 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 606 | log.info('update-mcast-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 607 | handler = self.devices_handlers.get(device.id) |
| 608 | if handler is not None: |
| 609 | handler.xpon_update(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 610 | |
| 611 | def remove_multicast_gemport(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 612 | """ |
| 613 | API to delete multicast gemport object in the devices |
| 614 | :param device: device id |
| 615 | :data: multicast gemport data object |
| 616 | :return: None |
| 617 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 618 | log.info('remove-mcast-gemport', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 619 | handler = self.devices_handlers.get(device.id) |
| 620 | if handler is not None: |
| 621 | handler.xpon_remove(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 622 | |
| 623 | def create_multicast_distribution_set(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 624 | """ |
| 625 | API to create multicast distribution rule to specify |
| 626 | the multicast VLANs that ride on the multicast gemport |
| 627 | :param device: device id |
| 628 | :data: multicast distribution data object |
| 629 | :return: None |
| 630 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 631 | log.info('create-mcast-distribution-set', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 632 | handler = self.devices_handlers.get(device.id) |
| 633 | if handler is not None: |
| 634 | handler.xpon_create(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 635 | |
| 636 | def update_multicast_distribution_set(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 637 | """ |
| 638 | API to update multicast distribution rule to specify |
| 639 | the multicast VLANs that ride on the multicast gemport |
| 640 | :param device: device id |
| 641 | :data: multicast distribution data object |
| 642 | :return: None |
| 643 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 644 | log.info('update-mcast-distribution-set', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 645 | handler = self.devices_handlers.get(device.id) |
| 646 | if handler is not None: |
| 647 | handler.xpon_update(data) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 648 | |
| 649 | def remove_multicast_distribution_set(self, device, data): |
Chip Boling | ae29801 | 2017-08-28 08:55:17 -0500 | [diff] [blame] | 650 | """ |
| 651 | API to delete multicast distribution rule to specify |
| 652 | the multicast VLANs that ride on the multicast gemport |
| 653 | :param device: device id |
| 654 | :data: multicast distribution data object |
| 655 | :return: None |
| 656 | """ |
Chip Boling | 69fba86 | 2017-08-18 15:11:32 -0500 | [diff] [blame] | 657 | log.info('remove-mcast-distribution-set', data=data) |
Chip Boling | fd1fd37 | 2017-12-20 13:34:12 -0600 | [diff] [blame] | 658 | handler = self.devices_handlers.get(device.id) |
| 659 | if handler is not None: |
| 660 | handler.xpon_remove(data) |