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