William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 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 | import threading |
| 17 | import binascii |
| 18 | import grpc |
| 19 | import socket |
| 20 | import re |
| 21 | import structlog |
William Kurkian | fefd464 | 2019-02-07 15:30:03 -0500 | [diff] [blame] | 22 | import time |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 23 | from twisted.internet import reactor |
William Kurkian | 92bd712 | 2019-02-14 15:26:59 -0500 | [diff] [blame] | 24 | from twisted.internet.defer import inlineCallbacks, returnValue |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 25 | from scapy.layers.l2 import Ether, Dot1Q |
| 26 | from transitions import Machine |
| 27 | |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 28 | from voltha_protos import openolt_pb2_grpc, openolt_pb2 |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 29 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 30 | from pyvoltha.adapters.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 31 | |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 32 | from pyvoltha.common.utils.nethelpers import mac_str_to_tuple |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 33 | from voltha_protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 34 | OFPPS_LINK_DOWN, OFPPF_1GB_FD, \ |
| 35 | OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \ |
| 36 | ofp_switch_features, ofp_port, ofp_port_stats, ofp_desc |
William Kurkian | 44cd7bb | 2019-02-11 16:39:12 -0500 | [diff] [blame] | 37 | from pyvoltha.common.utils.registry import registry |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 38 | from voltha_protos.common_pb2 import AdminState, OperStatus, ConnectStatus |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 39 | from voltha_protos.device_pb2 import Port, Device |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 40 | from voltha_protos.inter_container_pb2 import SwitchCapability, PortCapability, \ |
| 41 | InterAdapterMessageType, InterAdapterOmciMessage |
William Kurkian | 8b1690c | 2019-03-04 16:53:22 -0500 | [diff] [blame] | 42 | from voltha_protos.logical_device_pb2 import LogicalDevice, LogicalPort |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 43 | |
Matt Jeanneret | 9fd36df | 2019-02-14 19:14:36 -0500 | [diff] [blame] | 44 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 45 | class OpenoltDevice(object): |
| 46 | """ |
| 47 | OpenoltDevice state machine: |
| 48 | |
| 49 | null ----> init ------> connected -----> up -----> down |
| 50 | ^ ^ | ^ | | |
| 51 | | | | | | | |
| 52 | | +-------------+ +---------+ | |
| 53 | | | |
| 54 | +-----------------------------------------+ |
| 55 | """ |
| 56 | # pylint: disable=too-many-instance-attributes |
| 57 | # pylint: disable=R0904 |
| 58 | states = [ |
| 59 | 'state_null', |
| 60 | 'state_init', |
| 61 | 'state_connected', |
| 62 | 'state_up', |
| 63 | 'state_down'] |
| 64 | |
| 65 | transitions = [ |
| 66 | {'trigger': 'go_state_init', |
| 67 | 'source': ['state_null', 'state_connected', 'state_down'], |
| 68 | 'dest': 'state_init', |
| 69 | 'before': 'do_state_init', |
| 70 | 'after': 'post_init'}, |
| 71 | {'trigger': 'go_state_connected', |
| 72 | 'source': 'state_init', |
| 73 | 'dest': 'state_connected', |
| 74 | 'before': 'do_state_connected'}, |
| 75 | {'trigger': 'go_state_up', |
| 76 | 'source': ['state_connected', 'state_down'], |
| 77 | 'dest': 'state_up', |
| 78 | 'before': 'do_state_up'}, |
| 79 | {'trigger': 'go_state_down', |
| 80 | 'source': ['state_up'], |
| 81 | 'dest': 'state_down', |
| 82 | 'before': 'do_state_down', |
| 83 | 'after': 'post_down'}] |
| 84 | |
| 85 | def __init__(self, **kwargs): |
| 86 | super(OpenoltDevice, self).__init__() |
| 87 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 88 | self.core_proxy = kwargs['core_proxy'] |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 89 | self.adapter_proxy = kwargs['adapter_proxy'] |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 90 | self.device_num = kwargs['device_num'] |
| 91 | device = kwargs['device'] |
| 92 | |
| 93 | self.platform_class = kwargs['support_classes']['platform'] |
| 94 | self.resource_mgr_class = kwargs['support_classes']['resource_mgr'] |
| 95 | self.flow_mgr_class = kwargs['support_classes']['flow_mgr'] |
| 96 | self.alarm_mgr_class = kwargs['support_classes']['alarm_mgr'] |
| 97 | self.stats_mgr_class = kwargs['support_classes']['stats_mgr'] |
| 98 | self.bw_mgr_class = kwargs['support_classes']['bw_mgr'] |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 99 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 100 | self.seen_discovery_indications = [] |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 101 | self.stub = None |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 102 | self.connected = False |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 103 | is_reconciliation = kwargs.get('reconciliation', False) |
| 104 | self.device_id = device.id |
| 105 | self.host_and_port = device.host_and_port |
| 106 | self.extra_args = device.extra_args |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 107 | self.device_info = None |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 108 | self.log = structlog.get_logger(id=self.device_id, |
| 109 | ip=self.host_and_port) |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 110 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 111 | self.log.info('openolt-device-init') |
| 112 | |
| 113 | # default device id and device serial number. If device_info provides better results, they will be updated |
| 114 | self.dpid = kwargs.get('dp_id') |
| 115 | self.serial_number = self.host_and_port # FIXME |
| 116 | |
| 117 | # Device already set in the event of reconciliation |
| 118 | if not is_reconciliation: |
| 119 | self.log.info('updating-device') |
| 120 | # It is a new device |
| 121 | # Update device |
| 122 | device.root = True |
| 123 | device.connect_status = ConnectStatus.UNREACHABLE |
| 124 | device.oper_status = OperStatus.ACTIVATING |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 125 | # TODO NEW CORE. need to move this, cant have a constructor be a generator (yield) |
| 126 | #self.adapter_agent.device_update(device) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 127 | |
| 128 | # If logical device does exist use it, else create one after connecting to device |
| 129 | if device.parent_id: |
| 130 | # logical device already exists |
| 131 | self.logical_device_id = device.parent_id |
| 132 | if is_reconciliation: |
| 133 | self.adapter_agent.reconcile_logical_device( |
| 134 | self.logical_device_id) |
| 135 | |
| 136 | # Initialize the OLT state machine |
| 137 | self.machine = Machine(model=self, states=OpenoltDevice.states, |
| 138 | transitions=OpenoltDevice.transitions, |
| 139 | send_event=True, initial='state_null') |
| 140 | self.go_state_init() |
| 141 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 142 | @inlineCallbacks |
Matt Jeanneret | 9fd36df | 2019-02-14 19:14:36 -0500 | [diff] [blame] | 143 | def create_logical_device(self, device_info): |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 144 | dpid = device_info.device_id |
| 145 | serial_number = device_info.device_serial_number |
| 146 | |
| 147 | if dpid is None: dpid = self.dpid |
| 148 | if serial_number is None: serial_number = self.serial_number |
| 149 | |
| 150 | if dpid == None or dpid == '': |
| 151 | uri = self.host_and_port.split(":")[0] |
| 152 | try: |
| 153 | socket.inet_pton(socket.AF_INET, uri) |
| 154 | dpid = '00:00:' + self.ip_hex(uri) |
| 155 | except socket.error: |
| 156 | # this is not an IP |
| 157 | dpid = self.stringToMacAddr(uri) |
| 158 | |
| 159 | if serial_number == None or serial_number == '': |
| 160 | serial_number = self.host_and_port |
| 161 | |
| 162 | self.log.info('creating-openolt-logical-device', dp_id=dpid, serial_number=serial_number) |
| 163 | |
| 164 | mfr_desc = device_info.vendor |
| 165 | sw_desc = device_info.firmware_version |
| 166 | hw_desc = device_info.model |
| 167 | if device_info.hardware_version: hw_desc += '-' + device_info.hardware_version |
William Kurkian | 92bd712 | 2019-02-14 15:26:59 -0500 | [diff] [blame] | 168 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 169 | # Create logical OF device |
| 170 | ld = LogicalDevice( |
| 171 | root_device_id=self.device_id, |
| 172 | switch_features=ofp_switch_features( |
| 173 | n_buffers=256, # TODO fake for now |
| 174 | n_tables=2, # TODO ditto |
| 175 | capabilities=( # TODO and ditto |
| 176 | OFPC_FLOW_STATS |
| 177 | | OFPC_TABLE_STATS |
| 178 | | OFPC_PORT_STATS |
| 179 | | OFPC_GROUP_STATS |
| 180 | ) |
| 181 | ), |
| 182 | desc=ofp_desc( |
| 183 | serial_num=serial_number |
| 184 | ) |
| 185 | ) |
| 186 | ld_init = self.adapter_agent.create_logical_device(ld, |
William Kurkian | 92bd712 | 2019-02-14 15:26:59 -0500 | [diff] [blame] | 187 | dpid=dpid) |
| 188 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 189 | self.logical_device_id = ld_init.id |
| 190 | |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 191 | ##Moved setting serial number outside of the logical_device function |
| 192 | #device = yield self.adapter_agent.get_device(self.device_id) |
| 193 | #device.serial_number = serial_number |
| 194 | #yield self.adapter_agent.update_device(device) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 195 | |
| 196 | self.dpid = dpid |
| 197 | self.serial_number = serial_number |
| 198 | |
| 199 | self.log.info('created-openolt-logical-device', logical_device_id=ld_init.id) |
| 200 | |
| 201 | def stringToMacAddr(self, uri): |
| 202 | regex = re.compile('[^a-zA-Z]') |
| 203 | uri = regex.sub('', uri) |
| 204 | |
| 205 | l = len(uri) |
| 206 | if l > 6: |
| 207 | uri = uri[0:6] |
| 208 | else: |
| 209 | uri = uri + uri[0:6 - l] |
| 210 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 211 | return ":".join([hex(ord(x))[-2:] for x in uri]) |
| 212 | |
| 213 | def do_state_init(self, event): |
| 214 | # Initialize gRPC |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 215 | self.log.debug("grpc-host-port", self.host_and_port) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 216 | self.channel = grpc.insecure_channel(self.host_and_port) |
| 217 | self.channel_ready_future = grpc.channel_ready_future(self.channel) |
| 218 | |
| 219 | self.log.info('openolt-device-created', device_id=self.device_id) |
| 220 | |
| 221 | def post_init(self, event): |
| 222 | self.log.debug('post_init') |
| 223 | |
| 224 | # We have reached init state, starting the indications thread |
| 225 | |
| 226 | # Catch RuntimeError exception |
| 227 | try: |
| 228 | # Start indications thread |
| 229 | self.indications_thread_handle = threading.Thread( |
| 230 | target=self.indications_thread) |
| 231 | # Old getter/setter API for daemon; use it directly as a |
| 232 | # property instead. The Jinkins error will happon on the reason of |
| 233 | # Exception in thread Thread-1 (most likely raised # during |
| 234 | # interpreter shutdown) |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 235 | self.log.debug('starting indications thread') |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 236 | self.indications_thread_handle.setDaemon(True) |
| 237 | self.indications_thread_handle.start() |
| 238 | except Exception as e: |
| 239 | self.log.exception('post_init failed', e=e) |
| 240 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 241 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 242 | def do_state_connected(self, event): |
| 243 | self.log.debug("do_state_connected") |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 244 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 245 | device = yield self.core_proxy.get_device(self.device_id) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 246 | |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 247 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 248 | self.stub = openolt_pb2_grpc.OpenoltStub(self.channel) |
| 249 | |
William Kurkian | fefd464 | 2019-02-07 15:30:03 -0500 | [diff] [blame] | 250 | delay = 1 |
| 251 | while True: |
| 252 | try: |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 253 | self.device_info = self.stub.GetDeviceInfo(openolt_pb2.Empty()) |
William Kurkian | fefd464 | 2019-02-07 15:30:03 -0500 | [diff] [blame] | 254 | break |
| 255 | except Exception as e: |
| 256 | reraise = True |
| 257 | if delay > 120: |
| 258 | self.log.error("gRPC failure too many times") |
| 259 | else: |
| 260 | self.log.warn("gRPC failure, retry in %ds: %s" |
| 261 | % (delay, repr(e))) |
| 262 | time.sleep(delay) |
| 263 | delay += delay |
| 264 | reraise = False |
| 265 | |
| 266 | if reraise: |
| 267 | raise |
| 268 | |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 269 | self.log.info('Device connected', device_info=self.device_info) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 270 | |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 271 | # self.create_logical_device(device_info) |
| 272 | self.logical_device_id = 0 |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 273 | |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 274 | serial_number = self.device_info.device_serial_number |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 275 | if serial_number is None: |
| 276 | serial_number = self.serial_number |
| 277 | device.serial_number = serial_number |
| 278 | |
| 279 | self.serial_number = serial_number |
| 280 | |
Matt Jeanneret | 5ba87e3 | 2019-02-28 11:35:49 -0500 | [diff] [blame] | 281 | device.root = True |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 282 | device.vendor = self.device_info.vendor |
| 283 | device.model = self.device_info.model |
| 284 | device.hardware_version = self.device_info.hardware_version |
| 285 | device.firmware_version = self.device_info.firmware_version |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 286 | |
| 287 | # TODO: check for uptime and reboot if too long (VOL-1192) |
| 288 | |
| 289 | device.connect_status = ConnectStatus.REACHABLE |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 290 | # TODO NEW CORE: Gather this from DeviceInfo proto from openolt agent |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 291 | device.mac_address = "AA:BB:CC:DD:EE:FF" |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 292 | yield self.core_proxy.device_update(device) |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 293 | |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 294 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 295 | self.resource_mgr = self.resource_mgr_class(self.device_id, |
| 296 | self.host_and_port, |
| 297 | self.extra_args, |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 298 | self.device_info) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 299 | self.platform = self.platform_class(self.log, self.resource_mgr) |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 300 | self.flow_mgr = self.flow_mgr_class(self.core_proxy, self.log, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 301 | self.stub, self.device_id, |
| 302 | self.logical_device_id, |
| 303 | self.platform, self.resource_mgr) |
| 304 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 305 | self.alarm_mgr = self.alarm_mgr_class(self.log, self.core_proxy, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 306 | self.device_id, |
| 307 | self.logical_device_id, |
| 308 | self.platform) |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 309 | self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform) |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 310 | self.bw_mgr = self.bw_mgr_class(self.log, self.core_proxy) |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 311 | |
| 312 | self.connected = True |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 313 | |
| 314 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 315 | def do_state_up(self, event): |
| 316 | self.log.debug("do_state_up") |
| 317 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 318 | yield self.core_proxy.device_state_update(self.device_id, |
Matt Jeanneret | 9fd36df | 2019-02-14 19:14:36 -0500 | [diff] [blame] | 319 | connect_status=ConnectStatus.REACHABLE, |
| 320 | oper_status=OperStatus.ACTIVE) |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 321 | self.log.debug("done_state_up") |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 322 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 323 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 324 | def do_state_down(self, event): |
| 325 | self.log.debug("do_state_down") |
| 326 | oper_state = OperStatus.UNKNOWN |
| 327 | connect_state = ConnectStatus.UNREACHABLE |
| 328 | |
| 329 | # Propagating to the children |
| 330 | |
| 331 | # Children ports |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 332 | child_devices = yield self.adapter_agent.get_child_devices(self.device_id) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 333 | for onu_device in child_devices: |
| 334 | onu_adapter_agent = \ |
| 335 | registry('adapter_loader').get_agent(onu_device.adapter) |
| 336 | onu_adapter_agent.update_interface(onu_device, |
| 337 | {'oper_state': 'down'}) |
| 338 | self.onu_ports_down(onu_device, oper_state) |
| 339 | |
| 340 | # Children devices |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 341 | yield self.adapter_agent.update_child_devices_state( |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 342 | self.device_id, oper_status=oper_state, |
| 343 | connect_status=connect_state) |
| 344 | # Device Ports |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 345 | device_ports = yield self.adapter_agent.get_ports(self.device_id, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 346 | Port.ETHERNET_NNI) |
| 347 | logical_ports_ids = [port.label for port in device_ports] |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 348 | device_ports += yield self.adapter_agent.get_ports(self.device_id, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 349 | Port.PON_OLT) |
| 350 | |
| 351 | for port in device_ports: |
| 352 | port.oper_status = oper_state |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 353 | yield self.adapter_agent.add_port(self.device_id, port) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 354 | |
| 355 | # Device logical port |
| 356 | for logical_port_id in logical_ports_ids: |
| 357 | logical_port = self.adapter_agent.get_logical_port( |
| 358 | self.logical_device_id, logical_port_id) |
| 359 | logical_port.ofp_port.state = OFPPS_LINK_DOWN |
| 360 | self.adapter_agent.update_logical_port(self.logical_device_id, |
| 361 | logical_port) |
| 362 | |
| 363 | # Device |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 364 | device = yield self.adapter_agent.get_device(self.device_id) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 365 | device.oper_status = oper_state |
| 366 | device.connect_status = connect_state |
| 367 | |
William Kurkian | fefd464 | 2019-02-07 15:30:03 -0500 | [diff] [blame] | 368 | reactor.callLater(2, self.adapter_agent.device_update, device) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 369 | |
| 370 | # def post_up(self, event): |
| 371 | # self.log.debug('post-up') |
| 372 | # self.flow_mgr.reseed_flows() |
| 373 | |
| 374 | def post_down(self, event): |
| 375 | self.log.debug('post_down') |
| 376 | self.flow_mgr.reset_flows() |
| 377 | |
| 378 | def indications_thread(self): |
| 379 | self.log.debug('starting-indications-thread') |
| 380 | self.log.debug('connecting to olt', device_id=self.device_id) |
| 381 | self.channel_ready_future.result() # blocking call |
| 382 | self.log.info('connected to olt', device_id=self.device_id) |
| 383 | self.go_state_connected() |
| 384 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 385 | # TODO: thread timing issue. stub isnt ready yet from above go_state_connected (which doesnt block) |
William Kurkian | 2752258 | 2019-02-25 14:24:32 -0500 | [diff] [blame] | 386 | # Don't continue until connected is done |
| 387 | while (not self.connected): |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 388 | time.sleep(0.5) |
| 389 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 390 | self.indications = self.stub.EnableIndication(openolt_pb2.Empty()) |
| 391 | |
| 392 | while True: |
| 393 | try: |
| 394 | # get the next indication from olt |
| 395 | ind = next(self.indications) |
| 396 | except Exception as e: |
| 397 | self.log.warn('gRPC connection lost', error=e) |
| 398 | reactor.callFromThread(self.go_state_down) |
| 399 | reactor.callFromThread(self.go_state_init) |
| 400 | break |
| 401 | else: |
| 402 | self.log.debug("rx indication", indication=ind) |
| 403 | |
| 404 | # indication handlers run in the main event loop |
| 405 | if ind.HasField('olt_ind'): |
| 406 | reactor.callFromThread(self.olt_indication, ind.olt_ind) |
| 407 | elif ind.HasField('intf_ind'): |
| 408 | reactor.callFromThread(self.intf_indication, ind.intf_ind) |
| 409 | elif ind.HasField('intf_oper_ind'): |
| 410 | reactor.callFromThread(self.intf_oper_indication, |
| 411 | ind.intf_oper_ind) |
| 412 | elif ind.HasField('onu_disc_ind'): |
| 413 | reactor.callFromThread(self.onu_discovery_indication, |
| 414 | ind.onu_disc_ind) |
| 415 | elif ind.HasField('onu_ind'): |
| 416 | reactor.callFromThread(self.onu_indication, ind.onu_ind) |
| 417 | elif ind.HasField('omci_ind'): |
| 418 | reactor.callFromThread(self.omci_indication, ind.omci_ind) |
| 419 | elif ind.HasField('pkt_ind'): |
| 420 | reactor.callFromThread(self.packet_indication, ind.pkt_ind) |
| 421 | elif ind.HasField('port_stats'): |
| 422 | reactor.callFromThread( |
| 423 | self.stats_mgr.port_statistics_indication, |
| 424 | ind.port_stats) |
| 425 | elif ind.HasField('flow_stats'): |
| 426 | reactor.callFromThread( |
| 427 | self.stats_mgr.flow_statistics_indication, |
| 428 | ind.flow_stats) |
| 429 | elif ind.HasField('alarm_ind'): |
| 430 | reactor.callFromThread(self.alarm_mgr.process_alarms, |
| 431 | ind.alarm_ind) |
| 432 | else: |
| 433 | self.log.warn('unknown indication type') |
| 434 | |
| 435 | def olt_indication(self, olt_indication): |
| 436 | if olt_indication.oper_state == "up": |
| 437 | self.go_state_up() |
| 438 | elif olt_indication.oper_state == "down": |
| 439 | self.go_state_down() |
| 440 | |
| 441 | def intf_indication(self, intf_indication): |
| 442 | self.log.debug("intf indication", intf_id=intf_indication.intf_id, |
| 443 | oper_state=intf_indication.oper_state) |
| 444 | |
| 445 | if intf_indication.oper_state == "up": |
| 446 | oper_status = OperStatus.ACTIVE |
| 447 | else: |
| 448 | oper_status = OperStatus.DISCOVERED |
| 449 | |
| 450 | # add_port update the port if it exists |
| 451 | self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status) |
| 452 | |
| 453 | def intf_oper_indication(self, intf_oper_indication): |
| 454 | self.log.debug("Received interface oper state change indication", |
| 455 | intf_id=intf_oper_indication.intf_id, |
| 456 | type=intf_oper_indication.type, |
| 457 | oper_state=intf_oper_indication.oper_state) |
| 458 | |
| 459 | if intf_oper_indication.oper_state == "up": |
| 460 | oper_state = OperStatus.ACTIVE |
| 461 | else: |
| 462 | oper_state = OperStatus.DISCOVERED |
| 463 | |
| 464 | if intf_oper_indication.type == "nni": |
| 465 | |
| 466 | # add_(logical_)port update the port if it exists |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 467 | self.add_port(intf_oper_indication.intf_id, |
| 468 | Port.ETHERNET_NNI, oper_state) |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 469 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 470 | elif intf_oper_indication.type == "pon": |
| 471 | # FIXME - handle PON oper state change |
| 472 | pass |
| 473 | |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 474 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 475 | def onu_discovery_indication(self, onu_disc_indication): |
| 476 | intf_id = onu_disc_indication.intf_id |
| 477 | serial_number = onu_disc_indication.serial_number |
| 478 | |
| 479 | serial_number_str = self.stringify_serial_number(serial_number) |
| 480 | |
| 481 | self.log.debug("onu discovery indication", intf_id=intf_id, |
| 482 | serial_number=serial_number_str) |
| 483 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 484 | if serial_number_str in self.seen_discovery_indications: |
| 485 | self.log.debug("skipping-seen-onu-discovery-indication", intf_id=intf_id, |
| 486 | serial_number=serial_number_str) |
| 487 | return |
| 488 | else: |
| 489 | self.seen_discovery_indications.append(serial_number_str) |
| 490 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 491 | # Post ONU Discover alarm 20180809_0805 |
| 492 | try: |
| 493 | OnuDiscoveryAlarm(self.alarm_mgr.alarms, pon_id=intf_id, |
| 494 | serial_number=serial_number_str).raise_alarm() |
| 495 | except Exception as disc_alarm_error: |
| 496 | self.log.exception("onu-discovery-alarm-error", |
| 497 | errmsg=disc_alarm_error.message) |
| 498 | # continue for now. |
| 499 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 500 | onu_device = yield self.core_proxy.get_child_device( |
Matt Jeanneret | 5ba87e3 | 2019-02-28 11:35:49 -0500 | [diff] [blame] | 501 | self.device_id, |
| 502 | serial_number=serial_number_str) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 503 | |
| 504 | if onu_device is None: |
| 505 | try: |
| 506 | onu_id = self.resource_mgr.get_onu_id(intf_id) |
| 507 | if onu_id is None: |
| 508 | raise Exception("onu-id-unavailable") |
| 509 | |
| 510 | self.add_onu_device( |
| 511 | intf_id, |
| 512 | self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT), |
| 513 | onu_id, serial_number) |
| 514 | self.activate_onu(intf_id, onu_id, serial_number, |
| 515 | serial_number_str) |
| 516 | except Exception as e: |
| 517 | self.log.exception('onu-activation-failed', e=e) |
| 518 | |
| 519 | else: |
| 520 | if onu_device.connect_status != ConnectStatus.REACHABLE: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 521 | yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.REACHABLE) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 522 | |
| 523 | onu_id = onu_device.proxy_address.onu_id |
| 524 | if onu_device.oper_status == OperStatus.DISCOVERED \ |
| 525 | or onu_device.oper_status == OperStatus.ACTIVATING: |
| 526 | self.log.debug("ignore onu discovery indication, \ |
| 527 | the onu has been discovered and should be \ |
| 528 | activating shorlty", intf_id=intf_id, |
| 529 | onu_id=onu_id, state=onu_device.oper_status) |
| 530 | elif onu_device.oper_status == OperStatus.ACTIVE: |
| 531 | self.log.warn("onu discovery indication whereas onu is \ |
| 532 | supposed to be active", |
| 533 | intf_id=intf_id, onu_id=onu_id, |
| 534 | state=onu_device.oper_status) |
| 535 | elif onu_device.oper_status == OperStatus.UNKNOWN: |
| 536 | self.log.info("onu in unknown state, recovering from olt \ |
| 537 | reboot probably, activate onu", intf_id=intf_id, |
| 538 | onu_id=onu_id, serial_number=serial_number_str) |
| 539 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 540 | yield self.core_proxy.device_state_update(onu_device.id, oper_status=OperStatus.DISCOVERED) |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 541 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 542 | try: |
| 543 | self.activate_onu(intf_id, onu_id, serial_number, |
| 544 | serial_number_str) |
| 545 | except Exception as e: |
| 546 | self.log.error('onu-activation-error', |
| 547 | serial_number=serial_number_str, error=e) |
| 548 | else: |
| 549 | self.log.warn('unexpected state', onu_id=onu_id, |
| 550 | onu_device_oper_state=onu_device.oper_status) |
| 551 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 552 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 553 | def onu_indication(self, onu_indication): |
| 554 | self.log.debug("onu indication", intf_id=onu_indication.intf_id, |
| 555 | onu_id=onu_indication.onu_id, |
| 556 | serial_number=onu_indication.serial_number, |
| 557 | oper_state=onu_indication.oper_state, |
| 558 | admin_state=onu_indication.admin_state) |
| 559 | try: |
| 560 | serial_number_str = self.stringify_serial_number( |
| 561 | onu_indication.serial_number) |
| 562 | except Exception as e: |
| 563 | serial_number_str = None |
| 564 | |
| 565 | if serial_number_str is not None: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 566 | onu_device = yield self.core_proxy.get_child_device( |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 567 | self.device_id, |
| 568 | serial_number=serial_number_str) |
| 569 | else: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 570 | onu_device = yield self.core_proxy.get_child_device( |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 571 | self.device_id, |
| 572 | parent_port_no=self.platform.intf_id_to_port_no( |
| 573 | onu_indication.intf_id, Port.PON_OLT), |
| 574 | onu_id=onu_indication.onu_id) |
| 575 | |
| 576 | if onu_device is None: |
| 577 | self.log.error('onu not found', intf_id=onu_indication.intf_id, |
| 578 | onu_id=onu_indication.onu_id) |
| 579 | return |
| 580 | |
| 581 | if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \ |
| 582 | != onu_indication.intf_id: |
| 583 | self.log.warn('ONU-is-on-a-different-intf-id-now', |
| 584 | previous_intf_id=self.platform.intf_id_from_pon_port_no( |
| 585 | onu_device.parent_port_no), |
| 586 | current_intf_id=onu_indication.intf_id) |
| 587 | # FIXME - handle intf_id mismatch (ONU move?) |
| 588 | |
| 589 | if onu_device.proxy_address.onu_id != onu_indication.onu_id: |
| 590 | # FIXME - handle onu id mismatch |
| 591 | self.log.warn('ONU-id-mismatch, can happen if both voltha and ' |
| 592 | 'the olt rebooted', |
| 593 | expected_onu_id=onu_device.proxy_address.onu_id, |
| 594 | received_onu_id=onu_indication.onu_id) |
| 595 | |
| 596 | # Admin state |
| 597 | if onu_indication.admin_state == 'down': |
| 598 | if onu_indication.oper_state != 'down': |
| 599 | self.log.error('ONU-admin-state-down-and-oper-status-not-down', |
| 600 | oper_state=onu_indication.oper_state) |
| 601 | # Forcing the oper state change code to execute |
| 602 | onu_indication.oper_state = 'down' |
| 603 | |
| 604 | # Port and logical port update is taken care of by oper state block |
| 605 | |
| 606 | elif onu_indication.admin_state == 'up': |
| 607 | pass |
| 608 | |
| 609 | else: |
| 610 | self.log.warn('Invalid-or-not-implemented-admin-state', |
| 611 | received_admin_state=onu_indication.admin_state) |
| 612 | |
| 613 | self.log.debug('admin-state-dealt-with') |
| 614 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 615 | # Operating state |
| 616 | if onu_indication.oper_state == 'down': |
| 617 | |
| 618 | if onu_device.connect_status != ConnectStatus.UNREACHABLE: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 619 | yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.UNREACHABLE) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 620 | |
| 621 | # Move to discovered state |
| 622 | self.log.debug('onu-oper-state-is-down') |
| 623 | |
| 624 | if onu_device.oper_status != OperStatus.DISCOVERED: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 625 | yield self.core_proxy.device_state_update(onu_device.id, oper_status=OperStatus.DISCOVERED) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 626 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 627 | self.log.debug('inter-adapter-send-onu-ind', onu_indication=onu_indication) |
| 628 | |
| 629 | # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
| 630 | yield self.adapter_proxy.send_inter_adapter_message( |
| 631 | msg=onu_indication, |
| 632 | type=InterAdapterMessageType.ONU_IND_REQUEST, |
| 633 | from_adapter="openolt", |
| 634 | to_adapter=onu_device.type, |
| 635 | to_device_id=onu_device.id |
| 636 | ) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 637 | |
| 638 | elif onu_indication.oper_state == 'up': |
| 639 | |
| 640 | if onu_device.connect_status != ConnectStatus.REACHABLE: |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 641 | yield self.core_proxy.device_state_update(onu_device.id, connect_status=ConnectStatus.REACHABLE) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 642 | |
| 643 | if onu_device.oper_status != OperStatus.DISCOVERED: |
| 644 | self.log.debug("ignore onu indication", |
| 645 | intf_id=onu_indication.intf_id, |
| 646 | onu_id=onu_indication.onu_id, |
| 647 | state=onu_device.oper_status, |
| 648 | msg_oper_state=onu_indication.oper_state) |
| 649 | return |
| 650 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 651 | self.log.debug('inter-adapter-send-onu-ind', onu_indication=onu_indication) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 652 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 653 | # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
| 654 | yield self.adapter_proxy.send_inter_adapter_message( |
| 655 | msg=onu_indication, |
| 656 | type=InterAdapterMessageType.ONU_IND_REQUEST, |
| 657 | from_adapter="openolt", |
| 658 | to_adapter=onu_device.type, |
| 659 | to_device_id=onu_device.id |
| 660 | ) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 661 | |
| 662 | else: |
| 663 | self.log.warn('Not-implemented-or-invalid-value-of-oper-state', |
| 664 | oper_state=onu_indication.oper_state) |
| 665 | |
| 666 | def onu_ports_down(self, onu_device, oper_state): |
| 667 | # Set port oper state to Discovered |
| 668 | # add port will update port if it exists |
| 669 | # self.adapter_agent.add_port( |
| 670 | # self.device_id, |
| 671 | # Port( |
| 672 | # port_no=uni_no, |
| 673 | # label=uni_name, |
| 674 | # type=Port.ETHERNET_UNI, |
| 675 | # admin_state=onu_device.admin_state, |
| 676 | # oper_status=oper_state)) |
| 677 | # TODO this should be downning ports in onu adatper |
| 678 | |
| 679 | # Disable logical port |
| 680 | onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id)) |
| 681 | for onu_port in onu_ports: |
| 682 | self.log.debug('onu-ports-down', onu_port=onu_port) |
| 683 | onu_port_id = onu_port.label |
| 684 | try: |
| 685 | onu_logical_port = self.adapter_agent.get_logical_port( |
| 686 | logical_device_id=self.logical_device_id, port_id=onu_port_id) |
| 687 | onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN |
| 688 | self.adapter_agent.update_logical_port( |
| 689 | logical_device_id=self.logical_device_id, |
| 690 | port=onu_logical_port) |
| 691 | self.log.debug('cascading-oper-state-to-port-and-logical-port') |
| 692 | except KeyError as e: |
| 693 | self.log.error('matching-onu-port-label-invalid', |
| 694 | onu_id=onu_device.id, olt_id=self.device_id, |
| 695 | onu_ports=onu_ports, onu_port_id=onu_port_id, |
| 696 | error=e) |
| 697 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 698 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 699 | def omci_indication(self, omci_indication): |
| 700 | |
| 701 | self.log.debug("omci indication", intf_id=omci_indication.intf_id, |
| 702 | onu_id=omci_indication.onu_id) |
| 703 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 704 | onu_device = yield self.core_proxy.get_child_device( |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 705 | self.device_id, onu_id=omci_indication.onu_id, |
| 706 | parent_port_no=self.platform.intf_id_to_port_no( |
| 707 | omci_indication.intf_id, Port.PON_OLT), ) |
| 708 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 709 | omci_msg = InterAdapterOmciMessage(message=omci_indication.pkt) |
| 710 | |
| 711 | self.log.debug('inter-adapter-send-omci', omci_msg=omci_msg) |
| 712 | |
| 713 | # TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference |
| 714 | yield self.adapter_proxy.send_inter_adapter_message( |
| 715 | msg=omci_msg, |
| 716 | type=InterAdapterMessageType.OMCI_REQUEST, |
| 717 | from_adapter="openolt", |
| 718 | to_adapter=onu_device.type, |
| 719 | to_device_id=onu_device.id |
| 720 | ) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 721 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 722 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 723 | def packet_indication(self, pkt_indication): |
| 724 | |
| 725 | self.log.debug("packet indication", |
| 726 | intf_type=pkt_indication.intf_type, |
| 727 | intf_id=pkt_indication.intf_id, |
| 728 | port_no=pkt_indication.port_no, |
| 729 | cookie=pkt_indication.cookie, |
| 730 | gemport_id=pkt_indication.gemport_id, |
| 731 | flow_id=pkt_indication.flow_id) |
| 732 | |
| 733 | if pkt_indication.intf_type == "pon": |
| 734 | if pkt_indication.port_no: |
| 735 | logical_port_num = pkt_indication.port_no |
| 736 | else: # TODO Remove this else block after openolt device has been fully rolled out with cookie protobuf change |
| 737 | try: |
| 738 | onu_id_uni_id = self.resource_mgr.get_onu_uni_from_ponport_gemport(pkt_indication.intf_id, |
| 739 | pkt_indication.gemport_id) |
| 740 | onu_id = int(onu_id_uni_id[0]) |
| 741 | uni_id = int(onu_id_uni_id[1]) |
| 742 | self.log.debug("packet indication-kv", onu_id=onu_id, uni_id=uni_id) |
| 743 | if onu_id is None: |
| 744 | raise Exception("onu-id-none") |
| 745 | if uni_id is None: |
| 746 | raise Exception("uni-id-none") |
| 747 | logical_port_num = self.platform.mk_uni_port_num(pkt_indication.intf_id, onu_id, uni_id) |
| 748 | except Exception as e: |
| 749 | self.log.error("no-onu-reference-for-gem", |
| 750 | gemport_id=pkt_indication.gemport_id, e=e) |
| 751 | return |
| 752 | |
| 753 | |
| 754 | elif pkt_indication.intf_type == "nni": |
| 755 | logical_port_num = self.platform.intf_id_to_port_no( |
| 756 | pkt_indication.intf_id, |
| 757 | Port.ETHERNET_NNI) |
| 758 | |
| 759 | pkt = Ether(pkt_indication.pkt) |
| 760 | |
| 761 | self.log.debug("packet indication", |
| 762 | logical_device_id=self.logical_device_id, |
| 763 | logical_port_no=logical_port_num) |
| 764 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 765 | yield self.adapter_agent.send_packet_in( |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 766 | logical_device_id=self.logical_device_id, |
| 767 | logical_port_no=logical_port_num, |
| 768 | packet=str(pkt)) |
| 769 | |
| 770 | def packet_out(self, egress_port, msg): |
| 771 | pkt = Ether(msg) |
| 772 | self.log.debug('packet out', egress_port=egress_port, |
| 773 | device_id=self.device_id, |
| 774 | logical_device_id=self.logical_device_id, |
| 775 | packet=str(pkt).encode("HEX")) |
| 776 | |
| 777 | # Find port type |
| 778 | egress_port_type = self.platform.intf_id_to_port_type_name(egress_port) |
| 779 | if egress_port_type == Port.ETHERNET_UNI: |
| 780 | |
| 781 | if pkt.haslayer(Dot1Q): |
| 782 | outer_shim = pkt.getlayer(Dot1Q) |
| 783 | if isinstance(outer_shim.payload, Dot1Q): |
| 784 | # If double tag, remove the outer tag |
| 785 | payload = ( |
| 786 | Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) / |
| 787 | outer_shim.payload |
| 788 | ) |
| 789 | else: |
| 790 | payload = pkt |
| 791 | else: |
| 792 | payload = pkt |
| 793 | |
| 794 | send_pkt = binascii.unhexlify(str(payload).encode("HEX")) |
| 795 | |
| 796 | self.log.debug( |
| 797 | 'sending-packet-to-ONU', egress_port=egress_port, |
| 798 | intf_id=self.platform.intf_id_from_uni_port_num(egress_port), |
| 799 | onu_id=self.platform.onu_id_from_port_num(egress_port), |
| 800 | uni_id=self.platform.uni_id_from_port_num(egress_port), |
| 801 | port_no=egress_port, |
| 802 | packet=str(payload).encode("HEX")) |
| 803 | |
| 804 | onu_pkt = openolt_pb2.OnuPacket( |
| 805 | intf_id=self.platform.intf_id_from_uni_port_num(egress_port), |
| 806 | onu_id=self.platform.onu_id_from_port_num(egress_port), |
| 807 | port_no=egress_port, |
| 808 | pkt=send_pkt) |
| 809 | |
| 810 | self.stub.OnuPacketOut(onu_pkt) |
| 811 | |
| 812 | elif egress_port_type == Port.ETHERNET_NNI: |
| 813 | self.log.debug('sending-packet-to-uplink', egress_port=egress_port, |
| 814 | packet=str(pkt).encode("HEX")) |
| 815 | |
| 816 | send_pkt = binascii.unhexlify(str(pkt).encode("HEX")) |
| 817 | |
| 818 | uplink_pkt = openolt_pb2.UplinkPacket( |
| 819 | intf_id=self.platform.intf_id_from_nni_port_num(egress_port), |
| 820 | pkt=send_pkt) |
| 821 | |
| 822 | self.stub.UplinkPacketOut(uplink_pkt) |
| 823 | |
| 824 | else: |
| 825 | self.log.warn('Packet-out-to-this-interface-type-not-implemented', |
| 826 | egress_port=egress_port, |
| 827 | port_type=egress_port_type) |
| 828 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 829 | @inlineCallbacks |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 830 | def process_inter_adapter_message(self, request): |
| 831 | self.log.debug('process-inter-adapter-message', msg=request) |
| 832 | try: |
| 833 | if request.header.type == InterAdapterMessageType.OMCI_REQUEST: |
| 834 | omci_msg = InterAdapterOmciMessage() |
| 835 | request.body.Unpack(omci_msg) |
| 836 | self.log.debug('inter-adapter-recv-omci', omci_msg=omci_msg) |
| 837 | |
| 838 | onu_device_id = request.header.to_device_id |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 839 | onu_device = yield self.core_proxy.get_device(onu_device_id) |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 840 | self.send_proxied_message(onu_device, omci_msg.message) |
| 841 | |
| 842 | else: |
| 843 | self.log.error("inter-adapter-unhandled-type", request=request) |
| 844 | |
| 845 | except Exception as e: |
| 846 | self.log.exception("error-processing-inter-adapter-message", e=e) |
| 847 | |
| 848 | def send_proxied_message(self, onu_device, msg): |
| 849 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 850 | if onu_device.connect_status != ConnectStatus.REACHABLE: |
| 851 | self.log.debug('ONU is not reachable, cannot send OMCI', |
| 852 | serial_number=onu_device.serial_number, |
| 853 | intf_id=onu_device.proxy_address.channel_id, |
| 854 | onu_id=onu_device.proxy_address.onu_id) |
| 855 | return |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 856 | |
| 857 | omci = openolt_pb2.OmciMsg(intf_id=onu_device.proxy_address.channel_id, |
| 858 | onu_id=onu_device.proxy_address.onu_id, pkt=str(msg)) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 859 | self.stub.OmciMsgOut(omci) |
| 860 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 861 | self.log.debug("omci-message-sent", intf_id=onu_device.proxy_address.channel_id, |
| 862 | onu_id=onu_device.proxy_address.onu_id, pkt=str(msg)) |
| 863 | |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 864 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 865 | def add_onu_device(self, intf_id, port_no, onu_id, serial_number): |
Matt Jeanneret | 5ba87e3 | 2019-02-28 11:35:49 -0500 | [diff] [blame] | 866 | self.log.info("adding-onu", port_no=port_no, onu_id=onu_id, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 867 | serial_number=serial_number) |
| 868 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 869 | serial_number_str = self.stringify_serial_number(serial_number) |
| 870 | |
Matt Jeanneret | b428b95 | 2019-03-07 05:14:17 -0500 | [diff] [blame] | 871 | # TODO NEW CORE dont hardcode child device type. find some way of determining by vendor in serial number |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 872 | yield self.core_proxy.child_device_detected( |
Matt Jeanneret | 6e31509 | 2019-02-20 10:42:57 -0500 | [diff] [blame] | 873 | parent_device_id=self.device_id, |
| 874 | parent_port_no=port_no, |
| 875 | child_device_type='brcm_openomci_onu', |
Matt Jeanneret | 5ba87e3 | 2019-02-28 11:35:49 -0500 | [diff] [blame] | 876 | channel_id=intf_id, |
| 877 | vendor_id=serial_number.vendor_id, |
| 878 | serial_number=serial_number_str, |
| 879 | onu_id=onu_id |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 880 | ) |
| 881 | |
Matt Jeanneret | 5ba87e3 | 2019-02-28 11:35:49 -0500 | [diff] [blame] | 882 | self.log.debug("onu-added", onu_id=onu_id, port_no=port_no, serial_number=serial_number_str) |
| 883 | |
Matt Jeanneret | e33a709 | 2019-03-12 21:54:14 -0400 | [diff] [blame^] | 884 | def get_ofp_device_info(self, device): |
| 885 | self.log.info('get_ofp_device_info', device_id=device.id) |
| 886 | |
| 887 | mfr_desc = self.device_info.vendor |
| 888 | sw_desc = self.device_info.firmware_version |
| 889 | hw_desc = self.device_info.model |
| 890 | if self.device_info.hardware_version: hw_desc += '-' + self.device_info.hardware_version |
| 891 | |
| 892 | return SwitchCapability( |
| 893 | desc=ofp_desc( |
| 894 | hw_desc=hw_desc, |
| 895 | sw_desc=sw_desc, |
| 896 | serial_num=device.serial_number |
| 897 | ), |
| 898 | switch_features=ofp_switch_features( |
| 899 | n_buffers=256, # Max packets buffered at once # TODO fake for now |
| 900 | n_tables=2, # Number of tables supported by datapath # TODO fake for now |
| 901 | capabilities=( #Bitmap of support "ofp_capabilities" # TODO fake for now |
| 902 | OFPC_FLOW_STATS |
| 903 | | OFPC_TABLE_STATS |
| 904 | | OFPC_PORT_STATS |
| 905 | | OFPC_GROUP_STATS |
| 906 | ) |
| 907 | ) |
| 908 | ) |
| 909 | |
| 910 | def get_ofp_port_info(self, device, port_no): |
| 911 | self.log.info('get_ofp_port_info', port_no=port_no, device_id=device.id) |
| 912 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 913 | return PortCapability( |
| 914 | port=LogicalPort( |
| 915 | ofp_port=ofp_port( |
| 916 | hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)), |
| 917 | config=0, |
| 918 | state=OFPPS_LIVE, |
| 919 | curr=cap, |
| 920 | advertised=cap, |
| 921 | peer=cap, |
| 922 | curr_speed=OFPPF_1GB_FD, |
| 923 | max_speed=OFPPF_1GB_FD |
| 924 | ), |
| 925 | device_id=device.id, |
| 926 | device_port_no=port_no |
| 927 | ) |
| 928 | ) |
| 929 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 930 | def port_name(self, port_no, port_type, intf_id=None, serial_number=None): |
| 931 | if port_type is Port.ETHERNET_NNI: |
| 932 | return "nni-" + str(port_no) |
| 933 | elif port_type is Port.PON_OLT: |
| 934 | return "pon" + str(intf_id) |
| 935 | elif port_type is Port.ETHERNET_UNI: |
| 936 | assert False, 'local UNI management not supported' |
| 937 | |
| 938 | def add_logical_port(self, port_no, intf_id, oper_state): |
| 939 | self.log.info('adding-logical-port', port_no=port_no) |
| 940 | |
| 941 | label = self.port_name(port_no, Port.ETHERNET_NNI) |
| 942 | |
| 943 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 944 | curr_speed = OFPPF_1GB_FD |
| 945 | max_speed = OFPPF_1GB_FD |
| 946 | |
| 947 | if oper_state == OperStatus.ACTIVE: |
| 948 | of_oper_state = OFPPS_LIVE |
| 949 | else: |
| 950 | of_oper_state = OFPPS_LINK_DOWN |
| 951 | |
| 952 | ofp = ofp_port( |
| 953 | port_no=port_no, |
| 954 | hw_addr=mac_str_to_tuple(self._get_mac_form_port_no(port_no)), |
| 955 | name=label, config=0, state=of_oper_state, curr=cap, |
| 956 | advertised=cap, peer=cap, curr_speed=curr_speed, |
| 957 | max_speed=max_speed) |
| 958 | |
| 959 | ofp_stats = ofp_port_stats(port_no=port_no) |
| 960 | |
| 961 | logical_port = LogicalPort( |
| 962 | id=label, ofp_port=ofp, device_id=self.device_id, |
| 963 | device_port_no=port_no, root_port=True, |
| 964 | ofp_port_stats=ofp_stats) |
| 965 | |
| 966 | self.adapter_agent.add_logical_port(self.logical_device_id, |
| 967 | logical_port) |
| 968 | |
| 969 | def _get_mac_form_port_no(self, port_no): |
| 970 | mac = '' |
| 971 | for i in range(4): |
| 972 | mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac |
| 973 | return '00:00' + mac |
| 974 | |
William Kurkian | 92bd712 | 2019-02-14 15:26:59 -0500 | [diff] [blame] | 975 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 976 | def add_port(self, intf_id, port_type, oper_status): |
| 977 | port_no = self.platform.intf_id_to_port_no(intf_id, port_type) |
| 978 | |
| 979 | label = self.port_name(port_no, port_type, intf_id) |
| 980 | |
| 981 | self.log.debug('adding-port', port_no=port_no, label=label, |
| 982 | port_type=port_type) |
| 983 | |
| 984 | port = Port(port_no=port_no, label=label, type=port_type, |
| 985 | admin_state=AdminState.ENABLED, oper_status=oper_status) |
| 986 | |
Matt Jeanneret | bad3d98 | 2019-03-11 16:06:10 -0400 | [diff] [blame] | 987 | yield self.core_proxy.port_created(self.device_id, port) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 988 | |
| 989 | def delete_logical_port(self, child_device): |
| 990 | logical_ports = self.proxy.get('/logical_devices/{}/ports'.format( |
| 991 | self.logical_device_id)) |
| 992 | for logical_port in logical_ports: |
| 993 | if logical_port.device_id == child_device.id: |
| 994 | self.log.debug('delete-logical-port', |
| 995 | onu_device_id=child_device.id, |
| 996 | logical_port=logical_port) |
| 997 | self.flow_mgr.clear_flows_and_scheduler_for_logical_port( |
| 998 | child_device, logical_port) |
| 999 | self.adapter_agent.delete_logical_port( |
| 1000 | self.logical_device_id, logical_port) |
| 1001 | return |
| 1002 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 1003 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1004 | def delete_port(self, child_serial_number): |
| 1005 | ports = self.proxy.get('/devices/{}/ports'.format( |
| 1006 | self.device_id)) |
| 1007 | for port in ports: |
| 1008 | if port.label == child_serial_number: |
| 1009 | self.log.debug('delete-port', |
| 1010 | onu_serial_number=child_serial_number, |
| 1011 | port=port) |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 1012 | yield self.adapter_agent.delete_port(self.device_id, port) |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1013 | return |
| 1014 | |
| 1015 | def update_flow_table(self, flows): |
| 1016 | self.log.debug('No updates here now, all is done in logical flows ' |
| 1017 | 'update') |
| 1018 | |
| 1019 | def update_logical_flows(self, flows_to_add, flows_to_remove, |
| 1020 | device_rules_map): |
| 1021 | if not self.is_state_up(): |
| 1022 | self.log.info('The OLT is not up, we cannot update flows', |
| 1023 | flows_to_add=[f.id for f in flows_to_add], |
| 1024 | flows_to_remove=[f.id for f in flows_to_remove]) |
| 1025 | return |
| 1026 | |
| 1027 | try: |
| 1028 | self.flow_mgr.update_children_flows(device_rules_map) |
| 1029 | except Exception as e: |
| 1030 | self.log.error('Error updating children flows', error=e) |
| 1031 | |
| 1032 | self.log.debug('logical flows update', flows_to_add=flows_to_add, |
| 1033 | flows_to_remove=flows_to_remove) |
| 1034 | |
| 1035 | for flow in flows_to_add: |
| 1036 | |
| 1037 | try: |
| 1038 | self.flow_mgr.add_flow(flow) |
| 1039 | except Exception as e: |
| 1040 | self.log.error('failed to add flow', flow=flow, e=e) |
| 1041 | |
| 1042 | for flow in flows_to_remove: |
| 1043 | |
| 1044 | try: |
| 1045 | self.flow_mgr.remove_flow(flow) |
| 1046 | except Exception as e: |
| 1047 | self.log.error('failed to remove flow', flow=flow, e=e) |
| 1048 | |
| 1049 | self.flow_mgr.repush_all_different_flows() |
| 1050 | |
| 1051 | # There has to be a better way to do this |
| 1052 | def ip_hex(self, ip): |
| 1053 | octets = ip.split(".") |
| 1054 | hex_ip = [] |
| 1055 | for octet in octets: |
| 1056 | octet_hex = hex(int(octet)) |
| 1057 | octet_hex = octet_hex.split('0x')[1] |
| 1058 | octet_hex = octet_hex.rjust(2, '0') |
| 1059 | hex_ip.append(octet_hex) |
| 1060 | return ":".join(hex_ip) |
| 1061 | |
| 1062 | def stringify_vendor_specific(self, vendor_specific): |
| 1063 | return ''.join(str(i) for i in [ |
| 1064 | hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:], |
| 1065 | hex(ord(vendor_specific[0]) & 0x0f)[2:], |
| 1066 | hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:], |
| 1067 | hex(ord(vendor_specific[1]) & 0x0f)[2:], |
| 1068 | hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:], |
| 1069 | hex(ord(vendor_specific[2]) & 0x0f)[2:], |
| 1070 | hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:], |
| 1071 | hex(ord(vendor_specific[3]) & 0x0f)[2:]]) |
| 1072 | |
| 1073 | def stringify_serial_number(self, serial_number): |
| 1074 | return ''.join([serial_number.vendor_id, |
| 1075 | self.stringify_vendor_specific( |
| 1076 | serial_number.vendor_specific)]) |
| 1077 | |
| 1078 | def destringify_serial_number(self, serial_number_str): |
| 1079 | serial_number = openolt_pb2.SerialNumber( |
| 1080 | vendor_id=serial_number_str[:4].encode('utf-8'), |
| 1081 | vendor_specific=binascii.unhexlify(serial_number_str[4:])) |
| 1082 | return serial_number |
| 1083 | |
| 1084 | def disable(self): |
| 1085 | self.log.debug('sending-deactivate-olt-message', |
| 1086 | device_id=self.device_id) |
| 1087 | |
| 1088 | try: |
| 1089 | # Send grpc call |
| 1090 | self.stub.DisableOlt(openolt_pb2.Empty()) |
| 1091 | # The resulting indication will bring the OLT down |
| 1092 | # self.go_state_down() |
| 1093 | self.log.info('openolt device disabled') |
| 1094 | except Exception as e: |
| 1095 | self.log.error('Failure to disable openolt device', error=e) |
| 1096 | |
| 1097 | def delete(self): |
| 1098 | self.log.info('deleting-olt', device_id=self.device_id, |
| 1099 | logical_device_id=self.logical_device_id) |
| 1100 | |
| 1101 | # Clears up the data from the resource manager KV store |
| 1102 | # for the device |
| 1103 | del self.resource_mgr |
| 1104 | |
| 1105 | try: |
| 1106 | # Rebooting to reset the state |
| 1107 | self.reboot() |
| 1108 | # Removing logical device |
| 1109 | ld = self.adapter_agent.get_logical_device(self.logical_device_id) |
| 1110 | self.adapter_agent.delete_logical_device(ld) |
| 1111 | except Exception as e: |
| 1112 | self.log.error('Failure to delete openolt device', error=e) |
| 1113 | raise e |
| 1114 | else: |
| 1115 | self.log.info('successfully-deleted-olt', device_id=self.device_id) |
| 1116 | |
| 1117 | def reenable(self): |
| 1118 | self.log.debug('reenabling-olt', device_id=self.device_id) |
| 1119 | |
| 1120 | try: |
| 1121 | self.stub.ReenableOlt(openolt_pb2.Empty()) |
| 1122 | |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1123 | except Exception as e: |
| 1124 | self.log.error('Failure to reenable openolt device', error=e) |
| 1125 | else: |
| 1126 | self.log.info('openolt device reenabled') |
| 1127 | |
| 1128 | def activate_onu(self, intf_id, onu_id, serial_number, |
| 1129 | serial_number_str): |
| 1130 | pir = self.bw_mgr.pir(serial_number_str) |
| 1131 | self.log.debug("activating-onu", intf_id=intf_id, onu_id=onu_id, |
| 1132 | serial_number_str=serial_number_str, |
| 1133 | serial_number=serial_number, pir=pir) |
| 1134 | onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id, |
| 1135 | serial_number=serial_number, pir=pir) |
| 1136 | self.stub.ActivateOnu(onu) |
| 1137 | self.log.info('onu-activated', serial_number=serial_number_str) |
| 1138 | |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 1139 | @inlineCallbacks |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1140 | def delete_child_device(self, child_device): |
| 1141 | self.log.debug('sending-deactivate-onu', |
| 1142 | olt_device_id=self.device_id, |
| 1143 | onu_device=child_device, |
| 1144 | onu_serial_number=child_device.serial_number) |
| 1145 | try: |
Matt Jeanneret | d2f155b | 2019-02-22 13:49:09 -0500 | [diff] [blame] | 1146 | yield self.adapter_agent.delete_child_device(self.device_id, |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1147 | child_device.id, |
| 1148 | child_device) |
| 1149 | except Exception as e: |
| 1150 | self.log.error('adapter_agent error', error=e) |
| 1151 | try: |
| 1152 | self.delete_logical_port(child_device) |
| 1153 | except Exception as e: |
| 1154 | self.log.error('logical_port delete error', error=e) |
| 1155 | try: |
| 1156 | self.delete_port(child_device.serial_number) |
| 1157 | except Exception as e: |
| 1158 | self.log.error('port delete error', error=e) |
| 1159 | serial_number = self.destringify_serial_number( |
| 1160 | child_device.serial_number) |
| 1161 | # TODO FIXME - For each uni. |
| 1162 | # TODO FIXME - Flows are not deleted |
| 1163 | uni_id = 0 # FIXME |
| 1164 | self.flow_mgr.delete_tech_profile_instance( |
Matt Jeanneret | 7906d23 | 2019-02-14 14:57:38 -0500 | [diff] [blame] | 1165 | child_device.proxy_address.channel_id, |
| 1166 | child_device.proxy_address.onu_id, |
| 1167 | uni_id |
William Kurkian | 6f436d0 | 2019-02-06 16:25:01 -0500 | [diff] [blame] | 1168 | ) |
| 1169 | pon_intf_id_onu_id = (child_device.proxy_address.channel_id, |
| 1170 | child_device.proxy_address.onu_id, |
| 1171 | uni_id) |
| 1172 | # Free any PON resources that were reserved for the ONU |
| 1173 | self.resource_mgr.free_pon_resources_for_onu(pon_intf_id_onu_id) |
| 1174 | |
| 1175 | onu = openolt_pb2.Onu(intf_id=child_device.proxy_address.channel_id, |
| 1176 | onu_id=child_device.proxy_address.onu_id, |
| 1177 | serial_number=serial_number) |
| 1178 | self.stub.DeleteOnu(onu) |
| 1179 | |
| 1180 | def reboot(self): |
| 1181 | self.log.debug('rebooting openolt device', device_id=self.device_id) |
| 1182 | try: |
| 1183 | self.stub.Reboot(openolt_pb2.Empty()) |
| 1184 | except Exception as e: |
| 1185 | self.log.error('something went wrong with the reboot', error=e) |
| 1186 | else: |
| 1187 | self.log.info('device rebooted') |
| 1188 | |
| 1189 | def trigger_statistics_collection(self): |
| 1190 | try: |
| 1191 | self.stub.CollectStatistics(openolt_pb2.Empty()) |
| 1192 | except Exception as e: |
| 1193 | self.log.error('Error while triggering statistics collection', |
| 1194 | error=e) |
| 1195 | else: |
| 1196 | self.log.info('statistics requested') |
| 1197 | |
| 1198 | def simulate_alarm(self, alarm): |
| 1199 | self.alarm_mgr.simulate_alarm(alarm) |