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