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