khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | # |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 2 | # Copyright 2018 the original author or authors. |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 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 | Agent to play gateway between CORE and an adapter. |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 19 | """ |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 20 | import structlog |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 21 | from google.protobuf.message import Message |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 22 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 23 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 24 | from container_proxy import ContainerProxy |
| 25 | from python.protos.common_pb2 import ID, ConnectStatus, OperStatus |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 26 | from python.protos.inter_container_pb2 import StrType, BoolType, IntType, Packet |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 27 | from python.protos.device_pb2 import Device, Ports |
| 28 | from python.protos.voltha_pb2 import CoreInstance |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 29 | |
| 30 | log = structlog.get_logger() |
| 31 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 32 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 33 | def createSubTopic(*args): |
| 34 | return '_'.join(args) |
| 35 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 36 | class CoreProxy(ContainerProxy): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 37 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 38 | def __init__(self, kafka_proxy, default_core_topic, my_listening_topic): |
| 39 | super(CoreProxy, self).__init__(kafka_proxy, default_core_topic, |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 40 | my_listening_topic) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 41 | self.core_default_topic = default_core_topic |
| 42 | self.deviceId_to_core_map = dict() |
| 43 | |
| 44 | def update_device_core_reference(self, device_id, core_topic): |
| 45 | log.debug("update_device_core_reference") |
| 46 | self.deviceId_to_core_map[device_id] = core_topic |
| 47 | |
| 48 | def delete_device_core_reference(self, device_id, core_topic): |
| 49 | log.debug("delete_device_core_reference") |
| 50 | del self.deviceId_to_core_map[device_id] |
| 51 | |
| 52 | def get_adapter_topic(self, **kwargs): |
| 53 | return self.listening_topic |
| 54 | |
| 55 | def get_core_topic(self, device_id): |
| 56 | if device_id in self.deviceId_to_core_map: |
| 57 | return self.deviceId_to_core_map[device_id] |
| 58 | return self.core_default_topic |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 59 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 60 | @ContainerProxy.wrap_request(CoreInstance) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 61 | @inlineCallbacks |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 62 | def register(self, adapter, deviceTypes): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 63 | log.debug("register") |
| 64 | try: |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 65 | res = yield self.invoke(rpc="Register", |
| 66 | adapter=adapter, |
| 67 | deviceTypes=deviceTypes) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 68 | log.info("registration-returned", res=res) |
| 69 | returnValue(res) |
| 70 | except Exception as e: |
| 71 | log.exception("registration-exception", e=e) |
| 72 | raise |
| 73 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 74 | @ContainerProxy.wrap_request(Device) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 75 | @inlineCallbacks |
| 76 | def get_device(self, device_id): |
| 77 | log.debug("get-device") |
| 78 | id = ID() |
| 79 | id.id = device_id |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 80 | # Once we have a device being managed, all communications between the |
| 81 | # the adapter and the core occurs over a topic associated with that |
| 82 | # device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 83 | to_topic = self.get_core_topic(device_id) |
| 84 | reply_topic = self.get_adapter_topic() |
| 85 | |
| 86 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 87 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 88 | res = yield self.invoke(rpc="GetDevice", |
| 89 | to_topic=to_topic, |
| 90 | reply_topic=reply_topic, |
| 91 | device_id=id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 92 | returnValue(res) |
| 93 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 94 | @ContainerProxy.wrap_request(Device) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 95 | @inlineCallbacks |
| 96 | def get_child_device(self, parent_device_id, **kwargs): |
| 97 | raise NotImplementedError() |
| 98 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 99 | @ContainerProxy.wrap_request(Ports) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 100 | @inlineCallbacks |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 101 | def get_ports(self, device_id, port_type): |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 102 | id = ID() |
| 103 | id.id = device_id |
| 104 | p_type = IntType() |
| 105 | p_type.val = port_type |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 106 | to_topic = self.get_core_topic(device_id) |
| 107 | reply_topic = self.get_adapter_topic() |
| 108 | |
| 109 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 110 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 111 | res = yield self.invoke(rpc="GetPorts", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 112 | to_topic=to_topic, |
| 113 | reply_topic=reply_topic, |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 114 | device_id=id, |
| 115 | port_type=p_type) |
| 116 | returnValue(res) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 117 | |
| 118 | def get_child_devices(self, parent_device_id): |
| 119 | raise NotImplementedError() |
| 120 | |
| 121 | def get_child_device_with_proxy_address(self, proxy_address): |
| 122 | raise NotImplementedError() |
| 123 | |
| 124 | def _to_proto(self, **kwargs): |
| 125 | encoded = {} |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 126 | for k, v in kwargs.iteritems(): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 127 | if isinstance(v, Message): |
| 128 | encoded[k] = v |
| 129 | elif type(v) == int: |
| 130 | i_proto = IntType() |
| 131 | i_proto.val = v |
| 132 | encoded[k] = i_proto |
| 133 | elif type(v) == str: |
| 134 | s_proto = StrType() |
| 135 | s_proto.val = v |
| 136 | encoded[k] = s_proto |
| 137 | elif type(v) == bool: |
| 138 | b_proto = BoolType() |
| 139 | b_proto.val = v |
| 140 | encoded[k] = b_proto |
| 141 | return encoded |
| 142 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 143 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 144 | @inlineCallbacks |
| 145 | def child_device_detected(self, |
| 146 | parent_device_id, |
| 147 | parent_port_no, |
| 148 | child_device_type, |
| 149 | channel_id, |
| 150 | **kw): |
| 151 | id = ID() |
| 152 | id.id = parent_device_id |
| 153 | ppn = IntType() |
| 154 | ppn.val = parent_port_no |
| 155 | cdt = StrType() |
| 156 | cdt.val = child_device_type |
| 157 | channel = IntType() |
| 158 | channel.val = channel_id |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 159 | to_topic = self.get_core_topic(parent_device_id) |
| 160 | reply_topic = self.get_adapter_topic() |
| 161 | |
| 162 | # to_topic = createSubTopic(self.core_topic, parent_device_id) |
| 163 | # reply_topic = createSubTopic(self.listening_topic, parent_device_id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 164 | args = self._to_proto(**kw) |
| 165 | res = yield self.invoke(rpc="ChildDeviceDetected", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 166 | to_topic=to_topic, |
| 167 | reply_topic=reply_topic, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 168 | parent_device_id=id, |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 169 | parent_port_no=ppn, |
| 170 | child_device_type=cdt, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 171 | channel_id=channel, |
| 172 | **args) |
| 173 | returnValue(res) |
| 174 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 175 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 176 | @inlineCallbacks |
| 177 | def device_update(self, device): |
| 178 | log.debug("device_update") |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 179 | to_topic = self.get_core_topic(device.id) |
| 180 | reply_topic = self.get_adapter_topic() |
| 181 | |
| 182 | # to_topic = createSubTopic(self.core_topic, device.id) |
| 183 | # reply_topic = createSubTopic(self.listening_topic, device.id) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 184 | res = yield self.invoke(rpc="DeviceUpdate", |
| 185 | to_topic=to_topic, |
| 186 | reply_topic=reply_topic, |
| 187 | device=device) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 188 | returnValue(res) |
| 189 | |
| 190 | def child_device_removed(parent_device_id, child_device_id): |
| 191 | raise NotImplementedError() |
| 192 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 193 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 194 | @inlineCallbacks |
| 195 | def device_state_update(self, device_id, |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 196 | oper_status=None, |
| 197 | connect_status=None): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 198 | id = ID() |
| 199 | id.id = device_id |
| 200 | o_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 201 | if oper_status or oper_status == OperStatus.UNKNOWN: |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 202 | o_status.val = oper_status |
| 203 | else: |
| 204 | o_status.val = -1 |
| 205 | c_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 206 | if connect_status or connect_status == ConnectStatus.UNKNOWN: |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 207 | c_status.val = connect_status |
| 208 | else: |
| 209 | c_status.val = -1 |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 210 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 211 | to_topic = self.get_core_topic(device_id) |
| 212 | reply_topic = self.get_adapter_topic() |
| 213 | |
| 214 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 215 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 216 | res = yield self.invoke(rpc="DeviceStateUpdate", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 217 | to_topic=to_topic, |
| 218 | reply_topic=reply_topic, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 219 | device_id=id, |
| 220 | oper_status=o_status, |
| 221 | connect_status=c_status) |
| 222 | returnValue(res) |
| 223 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 224 | @ContainerProxy.wrap_request(None) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 225 | @inlineCallbacks |
| 226 | def children_state_update(self, device_id, |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 227 | oper_status=None, |
| 228 | connect_status=None): |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 229 | id = ID() |
| 230 | id.id = device_id |
| 231 | o_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 232 | if oper_status or oper_status == OperStatus.UNKNOWN: |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 233 | o_status.val = oper_status |
| 234 | else: |
| 235 | o_status.val = -1 |
| 236 | c_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 237 | if connect_status or connect_status == ConnectStatus.UNKNOWN: |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 238 | c_status.val = connect_status |
| 239 | else: |
| 240 | c_status.val = -1 |
| 241 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 242 | to_topic = self.get_core_topic(device_id) |
| 243 | reply_topic = self.get_adapter_topic() |
| 244 | |
| 245 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 246 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 247 | res = yield self.invoke(rpc="ChildrenStateUpdate", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 248 | to_topic=to_topic, |
| 249 | reply_topic=reply_topic, |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 250 | device_id=id, |
| 251 | oper_status=o_status, |
| 252 | connect_status=c_status) |
| 253 | returnValue(res) |
| 254 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 255 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 256 | @inlineCallbacks |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 257 | def port_state_update(self, |
| 258 | device_id, |
| 259 | port_type, |
| 260 | port_no, |
| 261 | oper_status): |
| 262 | id = ID() |
| 263 | id.id = device_id |
| 264 | pt = IntType() |
| 265 | pt.val = port_type |
| 266 | pNo = IntType() |
| 267 | pNo.val = port_no |
| 268 | o_status = IntType() |
| 269 | o_status.val = oper_status |
| 270 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 271 | to_topic = self.get_core_topic(device_id) |
| 272 | reply_topic = self.get_adapter_topic() |
| 273 | |
| 274 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 275 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 276 | res = yield self.invoke(rpc="PortStateUpdate", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 277 | to_topic=to_topic, |
| 278 | reply_topic=reply_topic, |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 279 | device_id=id, |
| 280 | port_type=pt, |
| 281 | port_no=pNo, |
| 282 | oper_status=o_status) |
| 283 | returnValue(res) |
| 284 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 285 | @ContainerProxy.wrap_request(None) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 286 | @inlineCallbacks |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 287 | def child_devices_state_update(self, parent_device_id, |
| 288 | oper_status=None, |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 289 | connect_status=None): |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 290 | |
| 291 | id = ID() |
| 292 | id.id = parent_device_id |
| 293 | o_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 294 | if oper_status or oper_status == OperStatus.UNKNOWN: |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 295 | o_status.val = oper_status |
| 296 | else: |
| 297 | o_status.val = -1 |
| 298 | c_status = IntType() |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 299 | if connect_status or connect_status == ConnectStatus.UNKNOWN: |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 300 | c_status.val = connect_status |
| 301 | else: |
| 302 | c_status.val = -1 |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 303 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 304 | to_topic = self.get_core_topic(parent_device_id) |
| 305 | reply_topic = self.get_adapter_topic() |
| 306 | |
| 307 | # to_topic = createSubTopic(self.core_topic, parent_device_id) |
| 308 | # reply_topic = createSubTopic(self.listening_topic, parent_device_id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 309 | res = yield self.invoke(rpc="child_devices_state_update", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 310 | to_topic=to_topic, |
| 311 | reply_topic=reply_topic, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 312 | parent_device_id=id, |
| 313 | oper_status=o_status, |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 314 | connect_status=c_status) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 315 | returnValue(res) |
| 316 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 317 | def child_devices_removed(parent_device_id): |
| 318 | raise NotImplementedError() |
| 319 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 320 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 321 | @inlineCallbacks |
| 322 | def device_pm_config_update(self, device_pm_config, init=False): |
| 323 | log.debug("device_pm_config_update") |
| 324 | b = BoolType() |
| 325 | b.val = init |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 326 | to_topic = self.get_core_topic(device_pm_config.id) |
| 327 | reply_topic = self.get_adapter_topic() |
| 328 | |
| 329 | # to_topic = createSubTopic(self.core_topic, device_pm_config.id) |
| 330 | # reply_topic = createSubTopic(self.listening_topic, device_pm_config.id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 331 | res = yield self.invoke(rpc="DevicePMConfigUpdate", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 332 | to_topic=to_topic, |
| 333 | reply_topic=reply_topic, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 334 | device_pm_config=device_pm_config, |
| 335 | init=b) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 336 | returnValue(res) |
| 337 | |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 338 | @ContainerProxy.wrap_request(None) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 339 | @inlineCallbacks |
| 340 | def port_created(self, device_id, port): |
| 341 | log.debug("port_created") |
| 342 | proto_id = ID() |
| 343 | proto_id.id = device_id |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 344 | to_topic = self.get_core_topic(device_id) |
| 345 | reply_topic = self.get_adapter_topic() |
| 346 | |
| 347 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 348 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 349 | res = yield self.invoke(rpc="PortCreated", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 350 | to_topic=to_topic, |
| 351 | reply_topic=reply_topic, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 352 | device_id=proto_id, |
khenaidoo | 6fdf0ba | 2018-11-02 14:38:33 -0400 | [diff] [blame] | 353 | port=port) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 354 | returnValue(res) |
| 355 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 356 | def port_removed(device_id, port): |
| 357 | raise NotImplementedError() |
| 358 | |
| 359 | def ports_enabled(device_id): |
| 360 | raise NotImplementedError() |
| 361 | |
| 362 | def ports_disabled(device_id): |
| 363 | raise NotImplementedError() |
| 364 | |
| 365 | def ports_oper_status_update(device_id, oper_status): |
| 366 | raise NotImplementedError() |
| 367 | |
| 368 | def image_download_update(img_dnld): |
| 369 | raise NotImplementedError() |
| 370 | |
| 371 | def image_download_deleted(img_dnld): |
| 372 | raise NotImplementedError() |
| 373 | |
khenaidoo | 7f9bb1a | 2018-11-29 17:15:01 -0500 | [diff] [blame] | 374 | @ContainerProxy.wrap_request(None) |
| 375 | @inlineCallbacks |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 376 | def send_packet_in(self, device_id, port, packet): |
khenaidoo | 7f9bb1a | 2018-11-29 17:15:01 -0500 | [diff] [blame] | 377 | log.debug("send_packet_in", device_id=device_id) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 378 | proto_id = ID() |
| 379 | proto_id.id = device_id |
| 380 | p = IntType() |
| 381 | p.val = port |
| 382 | pac = Packet() |
| 383 | pac.payload = packet |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame^] | 384 | to_topic = self.get_core_topic(device_id) |
| 385 | reply_topic = self.get_adapter_topic() |
| 386 | # to_topic = createSubTopic(self.core_topic, device_id) |
| 387 | # reply_topic = createSubTopic(self.listening_topic, device_id) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 388 | res = yield self.invoke(rpc="PacketIn", |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 389 | to_topic=to_topic, |
| 390 | reply_topic=reply_topic, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 391 | device_id=proto_id, |
| 392 | port=p, |
| 393 | packet=pac) |
| 394 | returnValue(res) |