khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | # |
| 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 | """ |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 18 | This facade handles kafka-formatted messages from the Core, extracts the kafka |
| 19 | formatting and forwards the request to the concrete handler. |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 20 | """ |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 21 | import structlog |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 22 | from twisted.internet.defer import inlineCallbacks |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 23 | from zope.interface import implementer |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 24 | from twisted.internet import reactor |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 25 | |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 26 | from afkak.consumer import OFFSET_LATEST, OFFSET_EARLIEST |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 27 | from python.adapters.interface import IAdapterInterface |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 28 | from python.protos.inter_container_pb2 import IntType, InterAdapterMessage, StrType, Error, ErrorCode |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 29 | from python.protos.device_pb2 import Device, ImageDownload |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 30 | from python.protos.openflow_13_pb2 import FlowChanges, FlowGroups, Flows, \ |
| 31 | FlowGroupChanges, ofp_packet_out |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 32 | from python.adapters.kafka.kafka_inter_container_library import IKafkaMessagingProxy, \ |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 33 | get_messaging_proxy, KAFKA_OFFSET_LATEST, KAFKA_OFFSET_EARLIEST, ARG_FROM_TOPIC |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 34 | |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 35 | log = structlog.get_logger() |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 36 | |
| 37 | class MacAddressError(BaseException): |
| 38 | def __init__(self, error): |
| 39 | self.error = error |
| 40 | |
| 41 | |
| 42 | class IDError(BaseException): |
| 43 | def __init__(self, error): |
| 44 | self.error = error |
| 45 | |
| 46 | |
| 47 | @implementer(IAdapterInterface) |
| 48 | class AdapterRequestFacade(object): |
| 49 | """ |
| 50 | Gate-keeper between CORE and device adapters. |
| 51 | |
| 52 | On one side it interacts with Core's internal model and update/dispatch |
| 53 | mechanisms. |
| 54 | |
| 55 | On the other side, it interacts with the adapters standard interface as |
| 56 | defined in |
| 57 | """ |
| 58 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 59 | def __init__(self, adapter, core_proxy): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 60 | self.adapter = adapter |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 61 | self.core_proxy = core_proxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 62 | |
| 63 | @inlineCallbacks |
| 64 | def start(self): |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 65 | log.debug('starting') |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 66 | |
| 67 | @inlineCallbacks |
| 68 | def stop(self): |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 69 | log.debug('stopping') |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 70 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 71 | # @inlineCallbacks |
| 72 | # def createKafkaDeviceTopic(self, deviceId): |
| 73 | # log.debug("subscribing-to-topic", device_id=deviceId) |
| 74 | # kafka_proxy = get_messaging_proxy() |
| 75 | # device_topic = kafka_proxy.get_default_topic() + "_" + deviceId |
| 76 | # # yield kafka_proxy.create_topic(topic=device_topic) |
| 77 | # yield kafka_proxy.subscribe(topic=device_topic, group_id=device_topic, target_cls=self, offset=KAFKA_OFFSET_EARLIEST) |
| 78 | # log.debug("subscribed-to-topic", topic=device_topic) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 79 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 80 | def adopt_device(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 81 | d = Device() |
| 82 | if device: |
| 83 | device.Unpack(d) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 84 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 85 | # Update the core reference for that device as it will be used |
| 86 | # by the adapter to send async messages to the Core. |
| 87 | if ARG_FROM_TOPIC in kwargs: |
| 88 | t = StrType() |
| 89 | kwargs[ARG_FROM_TOPIC].Unpack(t) |
| 90 | # Update the core reference for that device |
| 91 | self.core_proxy.update_device_core_reference(d.id, t.val) |
| 92 | |
| 93 | # # Start the creation of a device specific topic to handle all |
| 94 | # # subsequent requests from the Core. This adapter instance will |
| 95 | # # handle all requests for that device. |
| 96 | # reactor.callLater(0, self.createKafkaDeviceTopic, d.id) |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 97 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 98 | result = self.adapter.adopt_device(d) |
| 99 | # return True, self.adapter.adopt_device(d) |
| 100 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 101 | return True, result |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 102 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 103 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 104 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 105 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 106 | def get_ofp_device_info(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 107 | d = Device() |
| 108 | if device: |
| 109 | device.Unpack(d) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 110 | return True, self.adapter.get_ofp_device_info(d) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 111 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 112 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 113 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 114 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 115 | def get_ofp_port_info(self, device, port_no, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 116 | d = Device() |
| 117 | if device: |
| 118 | device.Unpack(d) |
| 119 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 120 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 121 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 122 | p = IntType() |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 123 | if port_no: |
| 124 | port_no.Unpack(p) |
| 125 | else: |
| 126 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 127 | reason="port-no-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 128 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 129 | return True, self.adapter.get_ofp_port_info(d, p.val) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 130 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 131 | def reconcile_device(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 132 | return self.adapter.reconcile_device(device) |
| 133 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 134 | def abandon_device(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 135 | return self.adapter.abandon_device(device) |
| 136 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 137 | def disable_device(self, device, **kwargs): |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 138 | d = Device() |
| 139 | if device: |
| 140 | device.Unpack(d) |
| 141 | return True, self.adapter.disable_device(d) |
| 142 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 143 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 144 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 145 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 146 | def reenable_device(self, device, **kwargs): |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 147 | d = Device() |
| 148 | if device: |
| 149 | device.Unpack(d) |
| 150 | return True, self.adapter.reenable_device(d) |
| 151 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 152 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 153 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 154 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 155 | def reboot_device(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 156 | d = Device() |
| 157 | if device: |
| 158 | device.Unpack(d) |
| 159 | return (True, self.adapter.reboot_device(d)) |
| 160 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 161 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 162 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 163 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 164 | def download_image(self, device, request, **kwargs): |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 165 | d = Device() |
| 166 | if device: |
| 167 | device.Unpack(d) |
| 168 | else: |
| 169 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 170 | reason="device-invalid") |
| 171 | img = ImageDownload() |
| 172 | if request: |
| 173 | request.Unpack(img) |
| 174 | else: |
| 175 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 176 | reason="port-no-invalid") |
| 177 | |
| 178 | return True, self.adapter.download_image(device, request) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 179 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 180 | def get_image_download_status(self, device, request, **kwargs): |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 181 | d = Device() |
| 182 | if device: |
| 183 | device.Unpack(d) |
| 184 | else: |
| 185 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 186 | reason="device-invalid") |
| 187 | img = ImageDownload() |
| 188 | if request: |
| 189 | request.Unpack(img) |
| 190 | else: |
| 191 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 192 | reason="port-no-invalid") |
| 193 | |
| 194 | return True, self.adapter.get_image_download_status(device, request) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 195 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 196 | def cancel_image_download(self, device, request, **kwargs): |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 197 | d = Device() |
| 198 | if device: |
| 199 | device.Unpack(d) |
| 200 | else: |
| 201 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 202 | reason="device-invalid") |
| 203 | img = ImageDownload() |
| 204 | if request: |
| 205 | request.Unpack(img) |
| 206 | else: |
| 207 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 208 | reason="port-no-invalid") |
| 209 | |
| 210 | return True, self.adapter.cancel_image_download(device, request) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 211 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 212 | def activate_image_update(self, device, request, **kwargs): |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 213 | d = Device() |
| 214 | if device: |
| 215 | device.Unpack(d) |
| 216 | else: |
| 217 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 218 | reason="device-invalid") |
| 219 | img = ImageDownload() |
| 220 | if request: |
| 221 | request.Unpack(img) |
| 222 | else: |
| 223 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 224 | reason="port-no-invalid") |
| 225 | |
| 226 | return True, self.adapter.activate_image_update(device, request) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 227 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 228 | def revert_image_update(self, device, request, **kwargs): |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 229 | d = Device() |
| 230 | if device: |
| 231 | device.Unpack(d) |
| 232 | else: |
| 233 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 234 | reason="device-invalid") |
| 235 | img = ImageDownload() |
| 236 | if request: |
| 237 | request.Unpack(img) |
| 238 | else: |
| 239 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 240 | reason="port-no-invalid") |
| 241 | |
| 242 | return True, self.adapter.revert_image_update(device, request) |
| 243 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 244 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 245 | def self_test(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 246 | return self.adapter.self_test_device(device) |
| 247 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 248 | def delete_device(self, device, **kwargs): |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 249 | d = Device() |
| 250 | if device: |
| 251 | device.Unpack(d) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 252 | result = self.adapter.delete_device(d) |
| 253 | # return (True, self.adapter.delete_device(d)) |
| 254 | |
| 255 | # Before we return, delete the device specific topic as we will no |
| 256 | # longer receive requests from the Core for that device |
| 257 | kafka_proxy = get_messaging_proxy() |
| 258 | device_topic = kafka_proxy.get_default_topic() + "/" + d.id |
| 259 | kafka_proxy.unsubscribe(topic=device_topic) |
| 260 | |
| 261 | return (True, result) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 262 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 263 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 264 | reason="device-invalid") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 265 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 266 | def get_device_details(self, device, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 267 | return self.adapter.get_device_details(device) |
| 268 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 269 | def update_flows_bulk(self, device, flows, groups, **kwargs): |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 270 | d = Device() |
| 271 | if device: |
| 272 | device.Unpack(d) |
| 273 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 274 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 275 | reason="device-invalid") |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 276 | f = Flows() |
| 277 | if flows: |
| 278 | flows.Unpack(f) |
| 279 | |
| 280 | g = FlowGroups() |
| 281 | if groups: |
| 282 | groups.Unpack(g) |
| 283 | |
| 284 | return (True, self.adapter.update_flows_bulk(d, f, g)) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 285 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 286 | def update_flows_incrementally(self, device, flow_changes, group_changes, **kwargs): |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 287 | d = Device() |
| 288 | if device: |
| 289 | device.Unpack(d) |
| 290 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 291 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 292 | reason="device-invalid") |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 293 | f = FlowChanges() |
| 294 | if flow_changes: |
| 295 | flow_changes.Unpack(f) |
| 296 | |
| 297 | g = FlowGroupChanges() |
| 298 | if group_changes: |
| 299 | group_changes.Unpack(g) |
| 300 | |
| 301 | return (True, self.adapter.update_flows_incrementally(d, f, g)) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 302 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 303 | def suppress_alarm(self, filter, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 304 | return self.adapter.suppress_alarm(filter) |
| 305 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 306 | def unsuppress_alarm(self, filter, **kwargs): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 307 | return self.adapter.unsuppress_alarm(filter) |
| 308 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 309 | def process_inter_adapter_message(self, msg, **kwargs): |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 310 | m = InterAdapterMessage() |
| 311 | if msg: |
| 312 | msg.Unpack(m) |
| 313 | else: |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 314 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 315 | reason="msg-invalid") |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 316 | |
| 317 | return (True, self.adapter.process_inter_adapter_message(m)) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 318 | |
| 319 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 320 | def receive_packet_out(self, deviceId, outPort, packet, **kwargs): |
khenaidoo | bcf205b | 2019-01-25 22:21:14 -0500 | [diff] [blame] | 321 | try: |
| 322 | d_id = StrType() |
| 323 | if deviceId: |
| 324 | deviceId.Unpack(d_id) |
| 325 | else: |
| 326 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 327 | reason="deviceid-invalid") |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 328 | |
khenaidoo | bcf205b | 2019-01-25 22:21:14 -0500 | [diff] [blame] | 329 | op = IntType() |
| 330 | if outPort: |
| 331 | outPort.Unpack(op) |
| 332 | else: |
| 333 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 334 | reason="outport-invalid") |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 335 | |
khenaidoo | bcf205b | 2019-01-25 22:21:14 -0500 | [diff] [blame] | 336 | p = ofp_packet_out() |
| 337 | if packet: |
| 338 | packet.Unpack(p) |
| 339 | else: |
| 340 | return False, Error(code=ErrorCode.INVALID_PARAMETERS, |
| 341 | reason="packet-invalid") |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 342 | |
khenaidoo | bcf205b | 2019-01-25 22:21:14 -0500 | [diff] [blame] | 343 | return (True, self.adapter.receive_packet_out(d_id.val, op.val, p)) |
| 344 | except Exception as e: |
| 345 | log.exception("error-processing-receive_packet_out", e=e) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 346 | |