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