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