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