blob: c052b7802a7b5918e05e3ee0b336a1fb76b85e25 [file] [log] [blame]
Chip Bolingf5af85d2019-02-12 15:36:17 -06001#
2# Copyright 2019-present ADTRAN, Inc.
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"""
17ADTRAN OLT Adapter.
18"""
19import structlog
20from twisted.internet import reactor, defer
21
22from pyvoltha.adapters.iadapter import OltAdapter
23from pyvoltha.protos import third_party
24from pyvoltha.protos.common_pb2 import AdminState
25
26from adtran_olt_handler import AdtranOltHandler
27
28
29_ = third_party
30log = structlog.get_logger()
31
32
33class AdtranOltAdapter(OltAdapter):
34 name = 'adtran_olt'
35
36 def __init__(self, core_proxy, adapter_proxy, config):
37 super(AdtranOltAdapter, self).__init__(core_proxy=core_proxy,
38 adapter_proxy=adapter_proxy,
39 config=config,
40 device_handler_class=AdtranOltHandler,
41 name=AdtranOltAdapter.name,
42 vendor='ADTRAN, Inc.',
43 version='2.0.0',
44 device_type=AdtranOltAdapter.name,
45 accepts_bulk_flow_update=True,
46 accepts_add_remove_flow_updates=False) # TODO: Implement me
47
48 log.debug('adtran_olt.__init__')
49
50 def health(self):
51 """
52 Return a 3-state health status using the voltha.HealthStatus message.
53
54 :return: Deferred or direct return with voltha.HealthStatus message
55 """
56 # TODO: Currently this is always healthy for every adapter.
57 # If we decide not to modify this, delete this method and use base class method
58 from pyvoltha.protos.health_pb2 import HealthStatus
59 return HealthStatus(state=HealthStatus.HEALTHY)
60
61 def abandon_device(self, device):
62 """
63 Make sure the adapter no longer looks after device. This is called
64 if device ownership is taken over by another Voltha instance.
65
66 :param device: A Voltha.Device object
67 :return: (Deferred) Shall be fired to acknowledge abandonment.
68 """
69 log.info('abandon-device', device=device)
70 raise NotImplementedError()
71
72 def adopt_device(self, device):
73 """
74 Make sure the adapter looks after given device. Called when a device
75 is provisioned top-down and needs to be activated by the adapter.
76
77 :param device: A voltha.Device object, with possible device-type
78 specific extensions. Such extensions shall be described as part of
79 the device type specification returned by device_types().
80 :return: (Deferred) Shall be fired to acknowledge device ownership.
81 """
82 log.info('adopt-device', device=device)
83 kwargs = {
84 'adapter': self,
85 'device-id': device.id
86 }
87 self.devices_handlers[device.id] = self.device_handler_class(**kwargs)
88 d = defer.Deferred()
89 reactor.callLater(0, self.devices_handlers[device.id].activate, d, False)
90 return d
91
92 def reconcile_device(self, device):
93 try:
94 self.devices_handlers[device.id] = self.device_handler_class(self,
95 device.id)
96 # Work only required for devices that are in ENABLED state
97 if device.admin_state == AdminState.ENABLED:
98
99 kwargs = {
100 'adapter': self,
101 'device-id': device.id
102 }
103 self.devices_handlers[device.id] =self.device_handler_class(**kwargs)
104 d = defer.Deferred()
105 reactor.callLater(0, self.devices_handlers[device.id].activate, d, True)
106
107 else:
108 # Invoke the children reconciliation which would setup the
109 # basic children data structures
110 self.core_proxy.reconcile_child_devices(device.id)
111 return device
112
113 except Exception, e:
114 log.exception('Exception', e=e)
115
116 def self_test_device(self, device):
117 """
118 This is called to Self a device based on a NBI call.
119 :param device: A Voltha.Device object.
120 :return: Will return result of self test
121 """
122 log.info('self-test-device', device=device.id)
123 # TODO: Support self test?
124 from pyvoltha.protos.voltha_pb2 import SelfTestResponse
125 return SelfTestResponse(result=SelfTestResponse.NOT_SUPPORTED)
126
127 def delete_device(self, device):
128 """
129 This is called to delete a device from the PON based on a NBI call.
130 If the device is an OLT then the whole PON will be deleted.
131
132 :param device: A Voltha.Device object.
133 :return: (Deferred) Shall be fired to acknowledge the deletion.
134 """
135 log.info('delete-device', device=device)
136 handler = self.devices_handlers.get(device.id)
137 if handler is not None:
138 reactor.callLater(0, handler.delete)
139 del self.device_handlers[device.id]
140 del self.logical_device_id_to_root_device_id[device.parent_id]
141
142 return device
143
144 def download_image(self, device, request):
145 """
146 This is called to request downloading a specified image into the standby partition
147 of a device based on a NBI call.
148
149 :param device: A Voltha.Device object.
150 :param request: A Voltha.ImageDownload object.
151 :return: (Deferred) Shall be fired to acknowledge the download.
152 """
153 log.info('image_download', device=device, request=request)
154 handler = self.devices_handlers.get(device.id)
155 if handler is not None:
156 return handler.start_download(device, request, defer.Deferred())
157
158 def get_image_download_status(self, device, request):
159 """
160 This is called to inquire about a requested image download status based
161 on a NBI call. The adapter is expected to update the DownloadImage DB object
162 with the query result
163
164 :param device: A Voltha.Device object.
165 :param request: A Voltha.ImageDownload object.
166 :return: (Deferred) Shall be fired to acknowledge
167 """
168 log.info('get_image_download', device=device, request=request)
169 handler = self.devices_handlers.get(device.id)
170 if handler is not None:
171 return handler.download_status(device, request, defer.Deferred())
172
173 def cancel_image_download(self, device, request):
174 """
175 This is called to cancel a requested image download
176 based on a NBI call. The admin state of the device will not
177 change after the download.
178 :param device: A Voltha.Device object.
179 :param request: A Voltha.ImageDownload object.
180 :return: (Deferred) Shall be fired to acknowledge
181 """
182 log.info('cancel_image_download', device=device)
183 handler = self.devices_handlers.get(device.id)
184 if handler is not None:
185 return handler.cancel_download(device, request, defer.Deferred())
186
187 def activate_image_update(self, device, request):
188 """
189 This is called to activate a downloaded image from
190 a standby partition into active partition.
191 Depending on the device implementation, this call
192 may or may not cause device reboot.
193 If no reboot, then a reboot is required to make the
194 activated image running on device
195 This call is expected to be non-blocking.
196 :param device: A Voltha.Device object.
197 :param request: A Voltha.ImageDownload object.
198 :return: (Deferred) OperationResponse object.
199 """
200 log.info('activate_image_update', device=device, request=request)
201 handler = self.devices_handlers.get(device.id)
202 if handler is not None:
203 return handler.activate_image(device, request, defer.Deferred())
204
205 def revert_image_update(self, device, request):
206 """
207 This is called to deactivate the specified image at
208 active partition, and revert to previous image at
209 standby partition.
210 Depending on the device implementation, this call
211 may or may not cause device reboot.
212 If no reboot, then a reboot is required to make the
213 previous image running on device
214 This call is expected to be non-blocking.
215 :param device: A Voltha.Device object.
216 :param request: A Voltha.ImageDownload object.
217 :return: (Deferred) OperationResponse object.
218 """
219 log.info('revert_image_update', device=device, request=request)
220 handler = self.devices_handlers.get(device.id)
221 if handler is not None:
222 return handler.revert_image(device, request, defer.Deferred())