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