Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 1 | # |
Zsolt Haraszti | 3eb27a5 | 2017-01-03 21:56:48 -0800 | [diff] [blame] | 2 | # Copyright 2017 the original author or authors. |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -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 | # |
alshabib | 06b449c | 2017-01-15 17:33:16 -0600 | [diff] [blame] | 16 | import os |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 17 | |
| 18 | import sys |
| 19 | |
| 20 | from twisted.internet import reactor |
| 21 | from twisted.internet.defer import Deferred, inlineCallbacks, returnValue |
| 22 | |
| 23 | from common.utils.asleep import asleep |
| 24 | from common.utils.consulhelpers import get_endpoint_from_consul |
| 25 | from structlog import get_logger |
| 26 | import grpc |
Rouzbahan Rashidi-Tabrizi | 34b7dd7 | 2017-03-13 17:45:20 -0400 | [diff] [blame] | 27 | from grpc import StatusCode |
| 28 | from grpc._channel import _Rendezvous |
Zsolt Haraszti | 1edb828 | 2016-11-08 10:57:19 -0800 | [diff] [blame] | 29 | from ofagent.protos import third_party |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 30 | from protos import voltha_pb2 |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 31 | from protos.voltha_pb2 import OfAgentSubscriber |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 32 | from grpc_client import GrpcClient |
| 33 | |
| 34 | from agent import Agent |
Zsolt Haraszti | 7eeb2b3 | 2016-11-06 14:04:55 -0800 | [diff] [blame] | 35 | from google.protobuf.empty_pb2 import Empty |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 36 | from common.utils.dockerhelpers import get_my_containers_name |
Zsolt Haraszti | 7eeb2b3 | 2016-11-06 14:04:55 -0800 | [diff] [blame] | 37 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 38 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 39 | log = get_logger() |
Zsolt Haraszti | 7eeb2b3 | 2016-11-06 14:04:55 -0800 | [diff] [blame] | 40 | # _ = third_party |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 41 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 42 | class ConnectionManager(object): |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 43 | def __init__(self, consul_endpoint, vcore_endpoint, controller_endpoints, |
| 44 | vcore_retry_interval=0.5, devices_refresh_interval=5, |
| 45 | subscription_refresh_interval=5): |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 46 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 47 | log.info('init-connection-manager') |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 48 | log.info('list-of-controllers', controller_endpoints=controller_endpoints) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 49 | self.controller_endpoints = controller_endpoints |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 50 | self.consul_endpoint = consul_endpoint |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 51 | self.vcore_endpoint = vcore_endpoint |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 52 | |
| 53 | self.channel = None |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 54 | self.grpc_client = None # single, shared gRPC client to vcore |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 55 | |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 56 | self.agent_map = {} # (datapath_id, controller_endpoint) -> Agent() |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 57 | self.device_id_to_datapath_id_map = {} |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 58 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 59 | self.vcore_retry_interval = vcore_retry_interval |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 60 | self.devices_refresh_interval = devices_refresh_interval |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 61 | self.subscription_refresh_interval = subscription_refresh_interval |
| 62 | self.subscription = None |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 63 | |
| 64 | self.running = False |
| 65 | |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 66 | def start(self): |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 67 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 68 | if self.running: |
| 69 | return |
| 70 | |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 71 | log.debug('starting') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 72 | |
| 73 | self.running = True |
| 74 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 75 | # Start monitoring the vcore grpc channel |
| 76 | reactor.callInThread(self.monitor_vcore_grpc_channel) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 77 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 78 | # Start monitoring logical devices and manage agents accordingly |
| 79 | reactor.callLater(0, self.monitor_logical_devices) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 80 | |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 81 | log.info('started') |
| 82 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 83 | return self |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 84 | |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 85 | def stop(self): |
| 86 | log.debug('stopping') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 87 | # clean up all controller connections |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 88 | for agent in self.agent_map.itervalues(): |
| 89 | agent.stop() |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 90 | self.running = False |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 91 | |
| 92 | self._reset_grpc_attributes() |
| 93 | |
Zsolt Haraszti | 2bdb6b3 | 2016-11-03 16:56:17 -0700 | [diff] [blame] | 94 | log.info('stopped') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 95 | |
| 96 | def resolve_endpoint(self, endpoint): |
| 97 | ip_port_endpoint = endpoint |
| 98 | if endpoint.startswith('@'): |
| 99 | try: |
| 100 | ip_port_endpoint = get_endpoint_from_consul( |
| 101 | self.consul_endpoint, endpoint[1:]) |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 102 | log.info( |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 103 | '{}-service-endpoint-found'.format(endpoint), address=ip_port_endpoint) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 104 | except Exception as e: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 105 | log.error('{}-service-endpoint-not-found'.format(endpoint), exception=repr(e)) |
| 106 | log.error('committing-suicide') |
alshabib | 06b449c | 2017-01-15 17:33:16 -0600 | [diff] [blame] | 107 | # Committing suicide in order to let docker restart ofagent |
| 108 | os.system("kill -15 {}".format(os.getpid())) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 109 | if ip_port_endpoint: |
| 110 | host, port = ip_port_endpoint.split(':', 2) |
| 111 | return host, int(port) |
| 112 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 113 | def _reset_grpc_attributes(self): |
| 114 | log.debug('start-reset-grpc-attributes') |
| 115 | |
| 116 | if self.grpc_client is not None: |
| 117 | self.grpc_client.stop() |
| 118 | |
| 119 | if self.channel is not None: |
| 120 | del self.channel |
| 121 | |
| 122 | self.is_alive = False |
| 123 | self.channel = None |
| 124 | self.subscription = None |
| 125 | self.grpc_client = None |
| 126 | |
| 127 | log.debug('stop-reset-grpc-attributes') |
| 128 | |
| 129 | def _assign_grpc_attributes(self): |
| 130 | log.debug('start-assign-grpc-attributes') |
| 131 | |
| 132 | host, port = self.resolve_endpoint(self.vcore_endpoint) |
| 133 | log.info('revolved-vcore-endpoint', endpoint=self.vcore_endpoint, host=host, port=port) |
| 134 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 135 | assert host is not None |
| 136 | assert port is not None |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 137 | |
| 138 | # Establish a connection to the vcore GRPC server |
| 139 | self.channel = grpc.insecure_channel('{}:{}'.format(host, port)) |
| 140 | self.is_alive = True |
| 141 | |
| 142 | log.debug('stop-assign-grpc-attributes') |
| 143 | |
| 144 | @inlineCallbacks |
| 145 | def monitor_vcore_grpc_channel(self): |
| 146 | log.debug('start-monitor-vcore-grpc-channel') |
| 147 | |
| 148 | while self.running: |
| 149 | try: |
| 150 | # If a subscription is not yet assigned then establish new GRPC connection |
| 151 | # ... otherwise keep using existing connection details |
| 152 | if self.subscription is None: |
| 153 | self._assign_grpc_attributes() |
| 154 | |
| 155 | # Send subscription request to register the current ofagent instance |
| 156 | container_name = get_my_containers_name() |
| 157 | stub = voltha_pb2.VolthaLocalServiceStub(self.channel) |
| 158 | subscription = stub.Subscribe(OfAgentSubscriber(ofagent_id=container_name)) |
| 159 | |
| 160 | # If the subscriber id matches the current instance |
| 161 | # ... then the subscription has succeeded |
| 162 | if subscription is not None and subscription.ofagent_id == container_name: |
| 163 | if self.subscription is None: |
| 164 | # Keep details on the current GRPC session and subscription |
| 165 | log.debug('subscription-with-vcore-successful', subscription=subscription) |
| 166 | self.subscription = subscription |
| 167 | self.grpc_client = GrpcClient(self, self.channel).start() |
| 168 | |
| 169 | # Sleep a bit in between each subscribe |
| 170 | yield asleep(self.subscription_refresh_interval) |
| 171 | |
| 172 | # Move on to next subscribe request |
| 173 | continue |
| 174 | |
| 175 | # The subscription did not succeed, reset and move on |
| 176 | else: |
| 177 | log.info('subscription-with-vcore-unavailable', subscription=subscription) |
| 178 | |
| 179 | except _Rendezvous, e: |
| 180 | log.error('subscription-with-vcore-terminated',exception=e, status=e.code()) |
| 181 | |
| 182 | except Exception as e: |
| 183 | log.exception('unexpected-subscription-termination-with-vcore', e=e) |
| 184 | |
| 185 | # Reset grpc details |
| 186 | # The vcore instance is either not available for subscription |
| 187 | # or a failure occurred with the existing communication. |
| 188 | self._reset_grpc_attributes() |
| 189 | |
| 190 | # Sleep for a short period and retry |
| 191 | yield asleep(self.vcore_retry_interval) |
| 192 | |
| 193 | log.debug('stop-monitor-vcore-grpc-channel') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 194 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 195 | @inlineCallbacks |
| 196 | def get_list_of_logical_devices_from_voltha(self): |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 197 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 198 | while self.running: |
| 199 | log.info('retrieve-logical-device-list') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 200 | try: |
Zsolt Haraszti | 6686203 | 2016-11-28 14:28:39 -0800 | [diff] [blame] | 201 | stub = voltha_pb2.VolthaLocalServiceStub(self.channel) |
Zsolt Haraszti | 7eeb2b3 | 2016-11-06 14:04:55 -0800 | [diff] [blame] | 202 | devices = stub.ListLogicalDevices(Empty()).items |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 203 | for device in devices: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 204 | log.info("logical-device-entry", id=device.id, datapath_id=device.datapath_id) |
| 205 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 206 | returnValue(devices) |
| 207 | |
Rouzbahan Rashidi-Tabrizi | 34b7dd7 | 2017-03-13 17:45:20 -0400 | [diff] [blame] | 208 | except _Rendezvous, e: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 209 | log.error('vcore-communication-failure', exception=e, status=e.code()) |
Rouzbahan Rashidi-Tabrizi | 34b7dd7 | 2017-03-13 17:45:20 -0400 | [diff] [blame] | 210 | if e.code() == StatusCode.UNAVAILABLE: |
| 211 | os.system("kill -15 {}".format(os.getpid())) |
| 212 | |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 213 | except Exception as e: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 214 | log.exception('logical-devices-retrieval-failure', exception=e) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 215 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 216 | log.info('reconnect', after_delay=self.vcore_retry_interval) |
| 217 | yield asleep(self.vcore_retry_interval) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 218 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 219 | def refresh_agent_connections(self, devices): |
| 220 | """ |
| 221 | Based on the new device list, update the following state in the class: |
| 222 | * agent_map |
| 223 | * datapath_map |
| 224 | * device_id_map |
| 225 | :param devices: full device list freshly received from Voltha |
| 226 | :return: None |
| 227 | """ |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 228 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 229 | # Use datapath ids for deciding what's new and what's obsolete |
| 230 | desired_datapath_ids = set(d.datapath_id for d in devices) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 231 | current_datapath_ids = set(datapath_ids[0] for datapath_ids in self.agent_map.iterkeys()) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 232 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 233 | # if identical, nothing to do |
| 234 | if desired_datapath_ids == current_datapath_ids: |
| 235 | return |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 236 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 237 | # ... otherwise calculate differences |
| 238 | to_add = desired_datapath_ids.difference(current_datapath_ids) |
| 239 | to_del = current_datapath_ids.difference(desired_datapath_ids) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 240 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 241 | # remove what we don't need |
| 242 | for datapath_id in to_del: |
| 243 | self.delete_agent(datapath_id) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 244 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 245 | # start new agents as needed |
| 246 | for device in devices: |
| 247 | if device.datapath_id in to_add: |
| 248 | self.create_agent(device) |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 249 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 250 | log.debug('updated-agent-list', count=len(self.agent_map)) |
| 251 | log.debug('updated-device-id-to-datapath-id-map', |
| 252 | map=str(self.device_id_to_datapath_id_map)) |
| 253 | |
| 254 | def create_agent(self, device): |
| 255 | datapath_id = device.datapath_id |
| 256 | device_id = device.id |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 257 | for controller_endpoint in self.controller_endpoints: |
| 258 | agent = Agent(controller_endpoint, datapath_id, |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 259 | device_id, self.grpc_client) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 260 | agent.start() |
| 261 | self.agent_map[(datapath_id,controller_endpoint)] = agent |
| 262 | self.device_id_to_datapath_id_map[device_id] = datapath_id |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 263 | |
| 264 | def delete_agent(self, datapath_id): |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 265 | for controller_endpoint in self.controller_endpoints: |
| 266 | agent = self.agent_map[(datapath_id,controller_endpoint)] |
| 267 | device_id = agent.get_device_id() |
| 268 | agent.stop() |
| 269 | del self.agent_map[(datapath_id,controller_endpoint)] |
| 270 | del self.device_id_to_datapath_id_map[device_id] |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 271 | |
| 272 | @inlineCallbacks |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 273 | def monitor_logical_devices(self): |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 274 | log.debug('start-monitor-logical-devices') |
| 275 | |
| 276 | while self.running: |
| 277 | log.info('monitoring-logical-devices') |
| 278 | |
alshabib | c3fb494 | 2017-01-26 15:34:24 -0800 | [diff] [blame] | 279 | # should change to a gRPC streaming call |
| 280 | # see https://jira.opencord.org/browse/CORD-821 |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 281 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 282 | try: |
| 283 | if self.channel is not None and self.grpc_client is not None: |
| 284 | # get current list from Voltha |
| 285 | devices = yield self.get_list_of_logical_devices_from_voltha() |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 286 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 287 | # update agent list and mapping tables as needed |
| 288 | self.refresh_agent_connections(devices) |
| 289 | else: |
| 290 | log.info('vcore-communication-unavailable') |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 291 | |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 292 | # wait before next poll |
| 293 | yield asleep(self.devices_refresh_interval) |
| 294 | |
| 295 | except _Rendezvous, e: |
| 296 | log.error('vcore-communication-failure', exception=repr(e), status=e.code()) |
| 297 | |
| 298 | except Exception as e: |
| 299 | log.exception('unexpected-vcore-communication-failure', exception=repr(e)) |
| 300 | |
| 301 | log.debug('stop-monitor-logical-devices') |
Khen Nursimulu | 68b9be3 | 2016-10-25 11:57:04 -0400 | [diff] [blame] | 302 | |
Zsolt Haraszti | cd22adc | 2016-10-25 00:13:06 -0700 | [diff] [blame] | 303 | def forward_packet_in(self, device_id, ofp_packet_in): |
| 304 | datapath_id = self.device_id_to_datapath_id_map.get(device_id, None) |
| 305 | if datapath_id: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 306 | for controller_endpoint in self.controller_endpoints: |
| 307 | agent = self.agent_map[(datapath_id, controller_endpoint)] |
| 308 | agent.forward_packet_in(ofp_packet_in) |
Zsolt Haraszti | 217a12e | 2016-12-19 16:37:55 -0800 | [diff] [blame] | 309 | |
| 310 | def forward_change_event(self, device_id, event): |
| 311 | datapath_id = self.device_id_to_datapath_id_map.get(device_id, None) |
| 312 | if datapath_id: |
Stephane Barbarie | 2940dac | 2017-08-18 14:15:17 -0400 | [diff] [blame] | 313 | for controller_endpoint in self.controller_endpoints: |
| 314 | agent = self.agent_map[(datapath_id, controller_endpoint)] |
| 315 | agent.forward_change_event(event) |