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 | |
| 17 | import structlog |
| 18 | import threading |
| 19 | import grpc |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 20 | import time |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 21 | |
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 |
| 24 | import binascii |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 25 | from transitions import Machine |
Shad Ansari | 15928d1 | 2018-04-17 02:42:13 +0000 | [diff] [blame] | 26 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 27 | from voltha.protos.device_pb2 import Port, Device |
| 28 | from voltha.protos.common_pb2 import OperStatus, AdminState, ConnectStatus |
| 29 | from voltha.protos.logical_device_pb2 import LogicalDevice |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 30 | from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ |
| 31 | OFPPS_LINK_DOWN, OFPPF_1GB_FD, OFPC_GROUP_STATS, OFPC_PORT_STATS, \ |
| 32 | OFPC_TABLE_STATS, OFPC_FLOW_STATS, ofp_switch_features, ofp_port |
| 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 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 42 | import openolt_platform as platform |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 43 | from openolt_flow_mgr import OpenOltFlowMgr |
Shad Ansari | 801f737 | 2018-04-27 02:15:41 +0000 | [diff] [blame] | 44 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 45 | MAX_HEARTBEAT_MISS = 3 |
| 46 | HEARTBEAT_PERIOD = 1 |
| 47 | GRPC_TIMEOUT = 5 |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 48 | |
| 49 | """ |
| 50 | OpenoltDevice represents an OLT. |
| 51 | """ |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 52 | |
| 53 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 54 | class OpenoltDevice(object): |
| 55 | |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 56 | states = ['up', 'down'] |
| 57 | transitions = [ |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 58 | {'trigger': 'olt_up', 'source': 'down', 'dest': 'up', |
| 59 | 'before': 'olt_indication_up'}, |
| 60 | {'trigger': 'olt_down', 'source': 'up', 'dest': 'down', |
| 61 | 'before': 'olt_indication_down'} |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 62 | ] |
| 63 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 64 | def __init__(self, **kwargs): |
| 65 | super(OpenoltDevice, self).__init__() |
| 66 | |
| 67 | self.adapter_agent = kwargs['adapter_agent'] |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 68 | self.device_num = kwargs['device_num'] |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 69 | device = kwargs['device'] |
Nicolas Palpacuer | 253461f | 2018-06-01 12:01:45 -0400 | [diff] [blame] | 70 | is_reconciliation = kwargs.get('reconciliation', False) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 71 | self.device_id = device.id |
| 72 | self.host_and_port = device.host_and_port |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 73 | self.log = structlog.get_logger(id=self.device_id, |
| 74 | ip=self.host_and_port) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 75 | self.proxy = registry('core').get_proxy('/') |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 76 | |
Nicolas Palpacuer | 253461f | 2018-06-01 12:01:45 -0400 | [diff] [blame] | 77 | # Device already set in the event of reconciliation |
| 78 | if not is_reconciliation: |
| 79 | # It is a new device |
| 80 | # Update device |
| 81 | device.root = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 82 | device.serial_number = self.host_and_port # FIXME |
Nicolas Palpacuer | 253461f | 2018-06-01 12:01:45 -0400 | [diff] [blame] | 83 | device.connect_status = ConnectStatus.REACHABLE |
| 84 | device.oper_status = OperStatus.ACTIVATING |
| 85 | self.adapter_agent.update_device(device) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 86 | |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 87 | # Initialize the OLT state machine |
| 88 | self.machine = Machine(model=self, states=OpenoltDevice.states, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 89 | transitions=OpenoltDevice.transitions, |
| 90 | send_event=True, initial='down', |
| 91 | ignore_invalid_triggers=True) |
| 92 | self.machine.add_transition(trigger='olt_ind_up', source='down', |
| 93 | dest='up') |
| 94 | self.machine.add_transition(trigger='olt_ind_loss', source='up', |
| 95 | dest='down') |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 96 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 97 | # Initialize gRPC |
| 98 | self.channel = grpc.insecure_channel(self.host_and_port) |
Shad Ansari | 8f1b253 | 2018-04-21 07:51:39 +0000 | [diff] [blame] | 99 | self.channel_ready_future = grpc.channel_ready_future(self.channel) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 100 | self.stub = openolt_pb2_grpc.OpenoltStub(self.channel) |
| 101 | |
| 102 | self.flow_mgr = OpenOltFlowMgr(self.log, self.stub) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 103 | |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 104 | # Indications thread plcaholder (started by heartbeat thread) |
| 105 | self.indications_thread = None |
| 106 | self.indications_thread_active = False |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 107 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 108 | # Start heartbeat thread |
| 109 | self.heartbeat_thread = threading.Thread(target=self.heartbeat) |
| 110 | self.heartbeat_thread.setDaemon(True) |
| 111 | self.heartbeat_thread_active = True |
| 112 | self.heartbeat_miss = 0 |
| 113 | self.heartbeat_signature = None |
| 114 | self.heartbeat_thread.start() |
| 115 | |
Nicolas Palpacuer | 253461f | 2018-06-01 12:01:45 -0400 | [diff] [blame] | 116 | self.log.debug('openolt-device-created', device_id=self.device_id) |
| 117 | |
Shad Ansari | 8f1b253 | 2018-04-21 07:51:39 +0000 | [diff] [blame] | 118 | def process_indications(self): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 119 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 120 | self.log.debug('starting-indications-thread') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 121 | |
Shad Ansari | 15928d1 | 2018-04-17 02:42:13 +0000 | [diff] [blame] | 122 | self.indications = self.stub.EnableIndication(openolt_pb2.Empty()) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 123 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 124 | while self.indications_thread_active: |
| 125 | try: |
| 126 | # get the next indication from olt |
| 127 | ind = next(self.indications) |
| 128 | except Exception as e: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 129 | self.log.warn('GRPC-connection-lost-stoping-indication-thread', |
| 130 | error=e) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 131 | self.indications_thread_active = False |
| 132 | else: |
| 133 | self.log.debug("rx indication", indication=ind) |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 134 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 135 | # indication handlers run in the main event loop |
| 136 | if ind.HasField('olt_ind'): |
| 137 | reactor.callFromThread(self.olt_indication, ind.olt_ind) |
| 138 | elif ind.HasField('intf_ind'): |
| 139 | reactor.callFromThread(self.intf_indication, ind.intf_ind) |
| 140 | elif ind.HasField('intf_oper_ind'): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 141 | reactor.callFromThread(self.intf_oper_indication, |
| 142 | ind.intf_oper_ind) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 143 | elif ind.HasField('onu_disc_ind'): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 144 | reactor.callFromThread(self.onu_discovery_indication, |
| 145 | ind.onu_disc_ind) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 146 | elif ind.HasField('onu_ind'): |
| 147 | reactor.callFromThread(self.onu_indication, ind.onu_ind) |
| 148 | elif ind.HasField('omci_ind'): |
| 149 | reactor.callFromThread(self.omci_indication, ind.omci_ind) |
| 150 | elif ind.HasField('pkt_ind'): |
| 151 | reactor.callFromThread(self.packet_indication, ind.pkt_ind) |
Nicolas Palpacuer | 33f1a82 | 2018-06-13 12:36:36 -0400 | [diff] [blame^] | 152 | elif ind.HasField('port_stats'): |
| 153 | reactor.callFromThread(self.port_statistics_indication, |
| 154 | ind.port_stats) |
| 155 | elif ind.HasField('flow_stats'): |
| 156 | reactor.callFromThread(self.flow_statistics_indication, |
| 157 | ind.flow_stats) |
| 158 | else: |
| 159 | self.log.warn('unknown indication type') |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 160 | |
| 161 | self.log.debug('stopping-indications-thread', device_id=self.device_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 162 | |
| 163 | def olt_indication(self, olt_indication): |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 164 | if olt_indication.oper_state == "up": |
| 165 | self.olt_up(ind=olt_indication) |
| 166 | elif olt_indication.oper_state == "down": |
| 167 | self.olt_down(ind=olt_indication) |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 168 | |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 169 | def olt_indication_up(self, event): |
| 170 | olt_indication = event.kwargs.get('ind', None) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 171 | self.log.debug("olt indication", olt_ind=olt_indication) |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 172 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 173 | device = self.adapter_agent.get_device(self.device_id) |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 174 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 175 | # If logical device does not exist create it |
| 176 | if len(device.parent_id) == 0: |
| 177 | |
| 178 | dpid = '00:00:' + self.ip_hex(self.host_and_port.split(":")[0]) |
| 179 | |
| 180 | # Create logical OF device |
| 181 | ld = LogicalDevice( |
| 182 | root_device_id=self.device_id, |
| 183 | switch_features=ofp_switch_features( |
| 184 | n_buffers=256, # TODO fake for now |
| 185 | n_tables=2, # TODO ditto |
| 186 | capabilities=( # TODO and ditto |
| 187 | OFPC_FLOW_STATS |
| 188 | | OFPC_TABLE_STATS |
| 189 | | OFPC_PORT_STATS |
| 190 | | OFPC_GROUP_STATS |
| 191 | ) |
Jonathan Hart | 7687e0a | 2018-05-16 10:54:47 -0700 | [diff] [blame] | 192 | ) |
| 193 | ) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 194 | ld_init = self.adapter_agent.create_logical_device(ld, |
| 195 | dpid=dpid) |
| 196 | self.logical_device_id = ld_init.id |
Nicolas Palpacuer | cf735ac | 2018-06-06 11:12:53 -0400 | [diff] [blame] | 197 | else: |
| 198 | # logical device already exists |
| 199 | self.logical_device_id = device.parent_id |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 200 | |
| 201 | # Update phys OF device |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 202 | device.parent_id = self.logical_device_id |
| 203 | device.oper_status = OperStatus.ACTIVE |
| 204 | self.adapter_agent.update_device(device) |
| 205 | |
Shad Ansari | 22efe83 | 2018-05-19 05:37:03 +0000 | [diff] [blame] | 206 | def olt_indication_down(self, event): |
| 207 | olt_indication = event.kwargs.get('ind', None) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 208 | new_admin_state = event.kwargs.get('admin_state', None) |
| 209 | new_oper_state = event.kwargs.get('oper_state', None) |
| 210 | new_connect_state = event.kwargs.get('connect_state', None) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 211 | self.log.debug("olt indication", olt_ind=olt_indication, |
| 212 | admin_state=new_admin_state, oper_state=new_oper_state, |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 213 | connect_state=new_connect_state) |
| 214 | |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 215 | # Propagating to the children |
| 216 | |
| 217 | # Children ports |
| 218 | child_devices = self.adapter_agent.get_child_devices(self.device_id) |
| 219 | for onu_device in child_devices: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 220 | uni_no = platform.mk_uni_port_num( |
| 221 | onu_device.proxy_address.channel_id, |
| 222 | onu_device.proxy_address.onu_id) |
| 223 | uni_name = self.port_name(uni_no, Port.ETHERNET_UNI, |
| 224 | serial_number=onu_device.serial_number) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 225 | |
| 226 | self.onu_ports_down(onu_device, uni_no, uni_name, new_oper_state) |
| 227 | # Children devices |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 228 | self.adapter_agent.update_child_devices_state( |
| 229 | self.device_id, oper_status=new_oper_state, |
| 230 | connect_status=ConnectStatus.UNREACHABLE, |
| 231 | admin_state=new_admin_state) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 232 | # Device Ports |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 233 | device_ports = self.adapter_agent.get_ports(self.device_id, |
| 234 | Port.ETHERNET_NNI) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 235 | logical_ports_ids = [port.label for port in device_ports] |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 236 | device_ports += self.adapter_agent.get_ports(self.device_id, |
| 237 | Port.PON_OLT) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 238 | |
| 239 | for port in device_ports: |
| 240 | if new_admin_state is not None: |
| 241 | port.admin_state = new_admin_state |
| 242 | if new_oper_state is not None: |
| 243 | port.oper_status = new_oper_state |
| 244 | self.adapter_agent.add_port(self.device_id, port) |
| 245 | |
| 246 | # Device logical port |
| 247 | for logical_port_id in logical_ports_ids: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 248 | logical_port = self.adapter_agent.get_logical_port( |
| 249 | self.logical_device_id, logical_port_id) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 250 | logical_port.ofp_port.state = OFPPS_LINK_DOWN |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 251 | self.adapter_agent.update_logical_port(self.logical_device_id, |
| 252 | logical_port) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 253 | |
| 254 | # Device |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 255 | device = self.adapter_agent.get_device(self.device_id) |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 256 | if new_admin_state is not None: |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 257 | device.admin_state = new_admin_state |
| 258 | if new_oper_state is not None: |
| 259 | device.oper_status = new_oper_state |
| 260 | if new_connect_state is not None: |
| 261 | device.connect_status = new_connect_state |
| 262 | |
| 263 | self.adapter_agent.update_device(device) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 264 | |
| 265 | def intf_indication(self, intf_indication): |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 266 | self.log.debug("intf indication", intf_id=intf_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 267 | oper_state=intf_indication.oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 268 | |
| 269 | if intf_indication.oper_state == "up": |
| 270 | oper_status = OperStatus.ACTIVE |
| 271 | else: |
| 272 | oper_status = OperStatus.DISCOVERED |
| 273 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 274 | # add_port update the port if it exists |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 275 | self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status) |
| 276 | |
| 277 | def intf_oper_indication(self, intf_oper_indication): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 278 | self.log.debug("Received interface oper state change indication", |
| 279 | intf_id=intf_oper_indication.intf_id, |
| 280 | type=intf_oper_indication.type, |
| 281 | oper_state=intf_oper_indication.oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 282 | |
| 283 | if intf_oper_indication.oper_state == "up": |
| 284 | oper_state = OperStatus.ACTIVE |
| 285 | else: |
| 286 | oper_state = OperStatus.DISCOVERED |
| 287 | |
| 288 | if intf_oper_indication.type == "nni": |
| 289 | |
Shad Ansari | 0346f0d | 2018-04-26 06:54:09 +0000 | [diff] [blame] | 290 | # FIXME - creating logical port for 2nd interface throws exception! |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 291 | if intf_oper_indication.intf_id != 0: |
| 292 | return |
| 293 | |
Nicolas Palpacuer | cf735ac | 2018-06-06 11:12:53 -0400 | [diff] [blame] | 294 | # add_(logical_)port update the port if it exists |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 295 | port_no, label = self.add_port(intf_oper_indication.intf_id, |
| 296 | Port.ETHERNET_NNI, oper_state) |
Nicolas Palpacuer | cf735ac | 2018-06-06 11:12:53 -0400 | [diff] [blame] | 297 | self.log.debug("int_oper_indication", port_no=port_no, label=label) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 298 | self.add_logical_port(port_no, intf_oper_indication.intf_id, |
| 299 | oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 300 | |
| 301 | elif intf_oper_indication.type == "pon": |
| 302 | # FIXME - handle PON oper state change |
| 303 | pass |
| 304 | |
| 305 | def onu_discovery_indication(self, onu_disc_indication): |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 306 | intf_id = onu_disc_indication.intf_id |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 307 | serial_number = onu_disc_indication.serial_number |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 308 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 309 | serial_number_str = self.stringify_serial_number(serial_number) |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 310 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 311 | self.log.debug("onu discovery indication", intf_id=intf_id, |
| 312 | serial_number=serial_number_str) |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 313 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 314 | onu_device = self.adapter_agent.get_child_device( |
| 315 | self.device_id, |
| 316 | serial_number=serial_number_str) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 317 | |
| 318 | if onu_device is None: |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 319 | onu_id = self.new_onu_id(intf_id) |
Shad Ansari | 15928d1 | 2018-04-17 02:42:13 +0000 | [diff] [blame] | 320 | try: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 321 | self.add_onu_device( |
| 322 | intf_id, |
| 323 | platform.intf_id_to_port_no(intf_id, Port.PON_OLT), |
| 324 | onu_id, serial_number) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 325 | 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] | 326 | serial_number=serial_number_str) |
| 327 | onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id, |
| 328 | serial_number=serial_number) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 329 | self.stub.ActivateOnu(onu) |
| 330 | except Exception as e: |
| 331 | self.log.exception('onu-activation-failed', e=e) |
| 332 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 333 | else: |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 334 | if onu_device.connect_status != ConnectStatus.REACHABLE: |
| 335 | onu_device.connect_status = ConnectStatus.REACHABLE |
| 336 | self.adapter_agent.update_device(onu_device) |
| 337 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 338 | onu_id = onu_device.proxy_address.onu_id |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 339 | if onu_device.oper_status == OperStatus.DISCOVERED \ |
| 340 | or onu_device.oper_status == OperStatus.ACTIVATING: |
| 341 | self.log.debug("ignore onu discovery indication, \ |
| 342 | the onu has been discovered and should be \ |
| 343 | activating shorlty", intf_id=intf_id, |
| 344 | onu_id=onu_id, state=onu_device.oper_status) |
| 345 | elif onu_device.oper_status == OperStatus.ACTIVE: |
| 346 | self.log.warn("onu discovery indication whereas onu is \ |
| 347 | supposed to be active", |
| 348 | intf_id=intf_id, onu_id=onu_id, |
| 349 | state=onu_device.oper_status) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 350 | elif onu_device.oper_status == OperStatus.UNKNOWN: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 351 | self.log.info("onu in unknown state, recovering from olt \ |
| 352 | reboot, activate onu", intf_id=intf_id, |
| 353 | onu_id=onu_id, serial_number=serial_number_str) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 354 | |
| 355 | onu_device.oper_status = OperStatus.DISCOVERED |
| 356 | self.adapter_agent.update_device(onu_device) |
| 357 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 358 | onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id, |
| 359 | serial_number=serial_number) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 360 | self.stub.ActivateOnu(onu) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 361 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 362 | self.log.warn('unexpected state', onu_id=onu_id, |
| 363 | onu_device_oper_state=onu_device.oper_status) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 364 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 365 | def onu_indication(self, onu_indication): |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 366 | self.log.debug("onu indication", intf_id=onu_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 367 | onu_id=onu_indication.onu_id, |
| 368 | serial_number=onu_indication.serial_number, |
| 369 | oper_state=onu_indication.oper_state, |
| 370 | admin_state=onu_indication.admin_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 371 | |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 372 | if onu_indication.serial_number: |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 373 | onu_device = self.adapter_agent.get_child_device( |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 374 | self.device_id, |
| 375 | serial_number=self.stringify_serial_number( |
| 376 | onu_indication.serial_number)) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 377 | else: |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 378 | onu_device = self.adapter_agent.get_child_device( |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 379 | self.device_id, |
| 380 | parent_port_no=platform.intf_id_to_port_no( |
| 381 | onu_indication.intf_id, Port.PON_OLT), |
| 382 | onu_id=onu_indication.onu_id) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 383 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 384 | if onu_device is None: |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 385 | self.log.error('onu not found', intf_id=onu_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 386 | onu_id=onu_indication.onu_id) |
Shad Ansari | 803900a | 2018-05-02 06:26:00 +0000 | [diff] [blame] | 387 | return |
| 388 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 389 | if onu_device.connect_status != ConnectStatus.REACHABLE: |
| 390 | onu_device.connect_status = ConnectStatus.REACHABLE |
| 391 | self.adapter_agent.update_device(onu_device) |
| 392 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 393 | if platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \ |
| 394 | != onu_indication.intf_id: |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 395 | self.log.warn('ONU-is-on-a-different-intf-id-now', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 396 | previous_intf_id=platform.intf_id_from_pon_port_no( |
| 397 | onu_device.parent_port_no), |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 398 | current_intf_id=onu_indication.intf_id) |
| 399 | # FIXME - handle intf_id mismatch (ONU move?) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 400 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 401 | if onu_device.proxy_address.onu_id != onu_indication.onu_id: |
| 402 | # FIXME - handle onu id mismatch |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 403 | self.log.warn('ONU-id-mismatch', |
| 404 | expected_onu_id=onu_device.proxy_address.onu_id, |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 405 | received_onu_id=onu_indication.onu_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 406 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 407 | uni_no = platform.mk_uni_port_num(onu_indication.intf_id, |
| 408 | onu_indication.onu_id) |
| 409 | uni_name = self.port_name(uni_no, Port.ETHERNET_UNI, |
| 410 | serial_number=onu_device.serial_number) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 411 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 412 | 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] | 413 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 414 | # Admin state |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 415 | if onu_indication.admin_state == 'down': |
| 416 | if onu_indication.oper_state != 'down': |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 417 | self.log.error('ONU-admin-state-down-and-oper-status-not-down', |
| 418 | oper_state=onu_indication.oper_state) |
| 419 | # Forcing the oper state change code to execute |
| 420 | onu_indication.oper_state = 'down' |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 421 | |
| 422 | if onu_device.admin_state != AdminState.DISABLED: |
| 423 | onu_device.admin_state = AdminState.DISABLED |
| 424 | self.adapter_agent.update(onu_device) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 425 | self.log.debug('putting-onu-in-disabled-state', |
| 426 | onu_serial_number=onu_device.serial_number) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 427 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 428 | # 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] | 429 | |
| 430 | elif onu_indication.admin_state == 'up': |
| 431 | if onu_device.admin_state != AdminState.ENABLED: |
| 432 | onu_device.admin_state = AdminState.ENABLED |
| 433 | self.adapter_agent.update(onu_device) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 434 | self.log.debug('putting-onu-in-enabled-state', |
| 435 | onu_serial_number=onu_device.serial_number) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 436 | |
| 437 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 438 | self.log.warn('Invalid-or-not-implemented-admin-state', |
| 439 | received_admin_state=onu_indication.admin_state) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 440 | |
| 441 | self.log.debug('admin-state-dealt-with') |
| 442 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 443 | # Operating state |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 444 | if onu_indication.oper_state == 'down': |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 445 | # Move to discovered state |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 446 | self.log.debug('onu-oper-state-is-down') |
| 447 | |
| 448 | if onu_device.oper_status != OperStatus.DISCOVERED: |
| 449 | onu_device.oper_status = OperStatus.DISCOVERED |
| 450 | self.adapter_agent.update_device(onu_device) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 451 | # Set port oper state to Discovered |
| 452 | self.onu_ports_down(onu_device, uni_no, uni_name, |
| 453 | OperStatus.DISCOVERED) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 454 | |
| 455 | elif onu_indication.oper_state == 'up': |
| 456 | |
| 457 | if onu_device.oper_status != OperStatus.DISCOVERED: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 458 | self.log.debug("ignore onu indication", |
| 459 | intf_id=onu_indication.intf_id, |
| 460 | onu_id=onu_indication.onu_id, |
| 461 | state=onu_device.oper_status, |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 462 | msg_oper_state=onu_indication.oper_state) |
| 463 | return |
| 464 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 465 | # Device was in Discovered state, setting it to active |
| 466 | onu_adapter_agent = \ |
| 467 | registry('adapter_loader').get_agent(onu_device.adapter) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 468 | if onu_adapter_agent is None: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 469 | self.log.error('onu_adapter_agent-could-not-be-retrieved', |
| 470 | onu_device=onu_device) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 471 | return |
| 472 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 473 | # Prepare onu configuration |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 474 | |
| 475 | # onu initialization, base configuration (bridge setup ...) |
| 476 | def onu_initialization(): |
| 477 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 478 | # FIXME: that's definitely cheating |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 479 | if onu_device.adapter == 'broadcom_onu': |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 480 | onu_adapter_agent.adapter.devices_handlers[onu_device.id] \ |
| 481 | .message_exchange() |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 482 | self.log.debug('broadcom-message-exchange-started') |
| 483 | |
| 484 | # tcont creation (onu) |
| 485 | tcont = TcontsConfigData() |
| 486 | tcont.alloc_id = platform.mk_alloc_id(onu_indication.onu_id) |
| 487 | |
| 488 | # gem port creation |
| 489 | gem_port = GemportsConfigData() |
| 490 | gem_port.gemport_id = platform.mk_gemport_id(onu_indication.onu_id) |
| 491 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 492 | # ports creation/update |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 493 | def port_config(): |
| 494 | |
| 495 | # "v_enet" creation (olt) |
| 496 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 497 | # add_port update port when it exists |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 498 | self.adapter_agent.add_port( |
| 499 | self.device_id, |
| 500 | Port( |
| 501 | port_no=uni_no, |
| 502 | label=uni_name, |
| 503 | type=Port.ETHERNET_UNI, |
| 504 | admin_state=AdminState.ENABLED, |
| 505 | oper_status=OperStatus.ACTIVE)) |
| 506 | |
| 507 | # v_enet creation (onu) |
| 508 | |
| 509 | venet = VEnetConfig(name=uni_name) |
| 510 | venet.interface.name = uni_name |
| 511 | onu_adapter_agent.create_interface(onu_device, venet) |
| 512 | |
| 513 | # ONU device status update in the datastore |
| 514 | def onu_update_oper_status(): |
| 515 | onu_device.oper_status = OperStatus.ACTIVE |
| 516 | onu_device.connect_status = ConnectStatus.REACHABLE |
| 517 | self.adapter_agent.update_device(onu_device) |
| 518 | |
| 519 | # FIXME : the asynchronicity has to be taken care of properly |
| 520 | onu_initialization() |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 521 | reactor.callLater(10, onu_adapter_agent.create_tcont, |
| 522 | device=onu_device, tcont_data=tcont, |
| 523 | traffic_descriptor_data=None) |
| 524 | reactor.callLater(11, onu_adapter_agent.create_gemport, onu_device, |
| 525 | gem_port) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 526 | reactor.callLater(12, port_config) |
| 527 | reactor.callLater(12, onu_update_oper_status) |
| 528 | |
| 529 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 530 | self.log.warn('Not-implemented-or-invalid-value-of-oper-state', |
| 531 | oper_state=onu_indication.oper_state) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 532 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 533 | def onu_ports_down(self, onu_device, uni_no, uni_name, oper_state): |
| 534 | # Set port oper state to Discovered |
| 535 | # add port will update port if it exists |
| 536 | self.adapter_agent.add_port( |
| 537 | self.device_id, |
| 538 | Port( |
| 539 | port_no=uni_no, |
| 540 | label=uni_name, |
| 541 | type=Port.ETHERNET_UNI, |
| 542 | admin_state=onu_device.admin_state, |
| 543 | oper_status=oper_state)) |
| 544 | |
| 545 | # Disable logical port |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 546 | onu_ports = self.proxy.get('devices/{}/ports'.format(onu_device.id)) |
| 547 | onu_port_id = None |
| 548 | for onu_port in onu_ports: |
| 549 | if onu_port.port_no == uni_no: |
| 550 | onu_port_id = onu_port.label |
| 551 | if onu_port_id is None: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 552 | self.log.error('matching-onu-port-label-not-found', |
| 553 | onu_id=onu_device.id, olt_id=self.device_id, |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 554 | onu_ports=onu_ports) |
| 555 | return |
| 556 | try: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 557 | onu_logical_port = self.adapter_agent.get_logical_port( |
| 558 | logical_device_id=self.logical_device_id, port_id=onu_port_id) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 559 | onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 560 | self.adapter_agent.update_logical_port( |
| 561 | logical_device_id=self.logical_device_id, |
| 562 | port=onu_logical_port) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 563 | self.log.debug('cascading-oper-state-to-port-and-logical-port') |
| 564 | except KeyError as e: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 565 | self.log.error('matching-onu-port-label-invalid', |
| 566 | onu_id=onu_device.id, olt_id=self.device_id, |
| 567 | onu_ports=onu_ports, onu_port_id=onu_port_id, |
| 568 | error=e) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 569 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 570 | def omci_indication(self, omci_indication): |
| 571 | |
| 572 | self.log.debug("omci indication", intf_id=omci_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 573 | onu_id=omci_indication.onu_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 574 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 575 | onu_device = self.adapter_agent.get_child_device( |
| 576 | self.device_id, onu_id=omci_indication.onu_id) |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 577 | |
| 578 | self.adapter_agent.receive_proxied_message(onu_device.proxy_address, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 579 | omci_indication.pkt) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 580 | |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 581 | def packet_indication(self, pkt_indication): |
| 582 | |
| 583 | self.log.debug("packet indication", intf_id=pkt_indication.intf_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 584 | gemport_id=pkt_indication.gemport_id, |
| 585 | flow_id=pkt_indication.flow_id) |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 586 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 587 | onu_id = platform.onu_id_from_gemport_id(pkt_indication.gemport_id) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 588 | logical_port_num = platform.mk_uni_port_num(pkt_indication.intf_id, |
| 589 | onu_id) |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 590 | |
| 591 | pkt = Ether(pkt_indication.pkt) |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 592 | kw = dict(logical_device_id=self.logical_device_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 593 | logical_port_no=logical_port_num) |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 594 | self.adapter_agent.send_packet_in(packet=str(pkt), **kw) |
| 595 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 596 | def olt_reachable(self): |
| 597 | device = self.adapter_agent.get_device(self.device_id) |
| 598 | device.connect_status = ConnectStatus.REACHABLE |
| 599 | self.adapter_agent.update_device(device) |
| 600 | # Not changing its child devices state, we cannot guaranty that |
| 601 | |
| 602 | def heartbeat(self): |
| 603 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 604 | # block till gRPC connection is complete |
| 605 | self.channel_ready_future.result() |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 606 | |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 607 | while self.heartbeat_thread_active: |
| 608 | |
| 609 | try: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 610 | heartbeat = self.stub.HeartbeatCheck(openolt_pb2.Empty(), |
| 611 | timeout=GRPC_TIMEOUT) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 612 | except Exception as e: |
| 613 | self.heartbeat_miss += 1 |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 614 | self.log.warn('heartbeat-miss', |
| 615 | missed_heartbeat=self.heartbeat_miss, error=e) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 616 | if self.heartbeat_miss == MAX_HEARTBEAT_MISS: |
| 617 | self.log.error('lost-connectivity-to-olt') |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 618 | # TODO : send alarm/notify monitoring system |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 619 | # Using reactor to synchronize update |
| 620 | # flagging it as unreachable and in unknow state |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 621 | reactor.callFromThread( |
| 622 | self.olt_down, |
| 623 | oper_state=OperStatus.UNKNOWN, |
| 624 | connect_state=ConnectStatus.UNREACHABLE) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 625 | |
| 626 | else: |
| 627 | # heartbeat received |
| 628 | if self.heartbeat_signature is None: |
| 629 | # Initialize heartbeat signature |
| 630 | self.heartbeat_signature = heartbeat.heartbeat_signature |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 631 | self.log.debug( |
| 632 | 'heartbeat-signature', |
| 633 | device_id=self.device_id, |
| 634 | heartbeat_signature=self.heartbeat_signature) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 635 | # Check if signature is different |
| 636 | if self.heartbeat_signature != heartbeat.heartbeat_signature: |
| 637 | # OLT has rebooted |
| 638 | self.log.warn('OLT-was-rebooted', device_id=self.device_id) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 639 | # TODO: notify monitoring system |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 640 | self.heartbeat_signature = heartbeat.heartbeat_signature |
| 641 | |
| 642 | else: |
| 643 | self.log.debug('valid-heartbeat-received') |
| 644 | |
| 645 | if self.heartbeat_miss > MAX_HEARTBEAT_MISS: |
| 646 | self.log.info('OLT-connection-restored') |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 647 | # TODO : suppress alarm/notify monitoring system |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 648 | # flagging it as reachable again |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 649 | reactor.callFromThread(self.olt_reachable) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 650 | |
| 651 | if not self.indications_thread_active: |
nick | 369a506 | 2018-05-29 17:11:06 -0400 | [diff] [blame] | 652 | self.log.info('(re)starting-indications-thread') |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 653 | # reset indications thread |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 654 | self.indications_thread = threading.Thread( |
| 655 | target=self.process_indications) |
nick | 47b7437 | 2018-05-25 18:22:49 -0400 | [diff] [blame] | 656 | self.indications_thread.setDaemon(True) |
| 657 | self.indications_thread_active = True |
| 658 | self.indications_thread.start() |
| 659 | |
| 660 | self.heartbeat_miss = 0 |
| 661 | |
| 662 | time.sleep(HEARTBEAT_PERIOD) |
| 663 | |
| 664 | self.log.debug('stopping-heartbeat-thread', device_id=self.device_id) |
| 665 | |
Nicolas Palpacuer | 33f1a82 | 2018-06-13 12:36:36 -0400 | [diff] [blame^] | 666 | def port_statistics_indication(self, port_stats): |
| 667 | # TODO: send to kafka |
| 668 | # TODO : update ONOS counters |
| 669 | self.log.info('port-stats-collected', stats=port_stats) |
| 670 | |
| 671 | def flow_statistics_indication(self, flow_stats): |
| 672 | # TODO: send to kafka |
| 673 | # TODO : update ONOS counters |
| 674 | self.log.info('flow-stats-collected', stats=flow_stats) |
| 675 | |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 676 | def packet_out(self, egress_port, msg): |
Shad Ansari | 0346f0d | 2018-04-26 06:54:09 +0000 | [diff] [blame] | 677 | pkt = Ether(msg) |
| 678 | self.log.info('packet out', egress_port=egress_port, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 679 | packet=str(pkt).encode("HEX")) |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 680 | |
| 681 | # Find port type |
| 682 | egress_port_type = self.port_type(egress_port) |
| 683 | |
| 684 | if egress_port_type == Port.ETHERNET_UNI: |
| 685 | |
| 686 | if pkt.haslayer(Dot1Q): |
| 687 | outer_shim = pkt.getlayer(Dot1Q) |
| 688 | if isinstance(outer_shim.payload, Dot1Q): |
| 689 | # If double tag, remove the outer tag |
| 690 | payload = ( |
| 691 | Ether(src=pkt.src, dst=pkt.dst, type=outer_shim.type) / |
| 692 | outer_shim.payload |
| 693 | ) |
| 694 | else: |
| 695 | payload = pkt |
Shad Ansari | 0346f0d | 2018-04-26 06:54:09 +0000 | [diff] [blame] | 696 | else: |
| 697 | payload = pkt |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 698 | |
| 699 | send_pkt = binascii.unhexlify(str(payload).encode("HEX")) |
| 700 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 701 | self.log.info( |
| 702 | 'sending-packet-to-ONU', egress_port=egress_port, |
| 703 | intf_id=platform.intf_id_from_pon_port_no(egress_port), |
| 704 | onu_id=platform.onu_id_from_port_num(egress_port), |
| 705 | packet=str(payload).encode("HEX")) |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 706 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 707 | onu_pkt = openolt_pb2.OnuPacket( |
| 708 | intf_id=platform.intf_id_from_pon_port_no(egress_port), |
| 709 | onu_id=platform.onu_id_from_port_num(egress_port), |
| 710 | pkt=send_pkt) |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 711 | |
| 712 | self.stub.OnuPacketOut(onu_pkt) |
| 713 | |
| 714 | elif egress_port_type == Port.ETHERNET_NNI: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 715 | self.log.info('sending-packet-to-uplink', egress_port=egress_port, |
| 716 | packet=str(pkt).encode("HEX")) |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 717 | |
| 718 | send_pkt = binascii.unhexlify(str(pkt).encode("HEX")) |
| 719 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 720 | uplink_pkt = openolt_pb2.UplinkPacket( |
| 721 | intf_id=platform.intf_id_from_nni_port_num(egress_port), |
| 722 | pkt=send_pkt) |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 723 | |
| 724 | self.stub.UplinkPacketOut(uplink_pkt) |
| 725 | |
Shad Ansari | 0346f0d | 2018-04-26 06:54:09 +0000 | [diff] [blame] | 726 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 727 | self.log.warn('Packet-out-to-this-interface-type-not-implemented', |
| 728 | egress_port=egress_port, |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 729 | port_type=egress_port_type) |
Shad Ansari | 42db734 | 2018-04-25 21:39:46 +0000 | [diff] [blame] | 730 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 731 | def send_proxied_message(self, proxy_address, msg): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 732 | omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id, |
| 733 | onu_id=proxy_address.onu_id, pkt=str(msg)) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 734 | self.stub.OmciMsgOut(omci) |
| 735 | |
| 736 | 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] | 737 | 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] | 738 | serial_number=serial_number) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 739 | |
| 740 | # NOTE - channel_id of onu is set to intf_id |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 741 | proxy_address = Device.ProxyAddress(device_id=self.device_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 742 | channel_id=intf_id, onu_id=onu_id, |
| 743 | onu_session_id=onu_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 744 | |
| 745 | self.log.info("Adding ONU", proxy_address=proxy_address) |
| 746 | |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 747 | serial_number_str = self.stringify_serial_number(serial_number) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 748 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 749 | self.adapter_agent.add_onu_device( |
| 750 | parent_device_id=self.device_id, parent_port_no=port_no, |
| 751 | vendor_id=serial_number.vendor_id, proxy_address=proxy_address, |
| 752 | root=True, serial_number=serial_number_str, |
| 753 | admin_state=AdminState.ENABLED) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 754 | |
Shad Ansari | 1fd9eb2 | 2018-05-15 05:13:49 +0000 | [diff] [blame] | 755 | 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] | 756 | if port_type is Port.ETHERNET_NNI: |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 757 | return "nni-" + str(port_no) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 758 | elif port_type is Port.PON_OLT: |
Shad Ansari | 4a232ca | 2018-05-05 05:24:17 +0000 | [diff] [blame] | 759 | return "pon" + str(intf_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 760 | elif port_type is Port.ETHERNET_UNI: |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 761 | if serial_number is not None: |
| 762 | return serial_number |
| 763 | else: |
| 764 | return "uni-{}".format(port_no) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 765 | |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 766 | def port_type(self, port_no): |
| 767 | ports = self.adapter_agent.get_ports(self.device_id) |
| 768 | for port in ports: |
| 769 | if port.port_no == port_no: |
| 770 | return port.type |
| 771 | return None |
| 772 | |
Nicolas Palpacuer | cf735ac | 2018-06-06 11:12:53 -0400 | [diff] [blame] | 773 | def add_logical_port(self, port_no, intf_id, oper_state): |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 774 | self.log.info('adding-logical-port', port_no=port_no) |
| 775 | |
| 776 | label = self.port_name(port_no, Port.ETHERNET_NNI) |
| 777 | |
| 778 | cap = OFPPF_1GB_FD | OFPPF_FIBER |
| 779 | curr_speed = OFPPF_1GB_FD |
| 780 | max_speed = OFPPF_1GB_FD |
| 781 | |
Nicolas Palpacuer | cf735ac | 2018-06-06 11:12:53 -0400 | [diff] [blame] | 782 | if oper_state == OperStatus.ACTIVE: |
| 783 | of_oper_state = OFPPS_LIVE |
| 784 | else: |
| 785 | of_oper_state = OFPPS_LINK_DOWN |
| 786 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 787 | ofp = ofp_port( |
| 788 | port_no=port_no, |
| 789 | hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % port_no), |
| 790 | name=label, config=0, state=of_oper_state, curr=cap, |
| 791 | advertised=cap, peer=cap, curr_speed=curr_speed, |
| 792 | max_speed=max_speed) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 793 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 794 | logical_port = LogicalPort( |
| 795 | id=label, ofp_port=ofp, device_id=self.device_id, |
| 796 | device_port_no=port_no, root_port=True) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 797 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 798 | self.adapter_agent.add_logical_port(self.logical_device_id, |
| 799 | logical_port) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 800 | |
| 801 | def add_port(self, intf_id, port_type, oper_status): |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 802 | port_no = platform.intf_id_to_port_no(intf_id, port_type) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 803 | |
Shad Ansari | 4a232ca | 2018-05-05 05:24:17 +0000 | [diff] [blame] | 804 | label = self.port_name(port_no, port_type, intf_id) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 805 | |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 806 | self.log.info('adding-port', port_no=port_no, label=label, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 807 | port_type=port_type) |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 808 | |
| 809 | port = Port(port_no=port_no, label=label, type=port_type, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 810 | admin_state=AdminState.ENABLED, oper_status=oper_status) |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 811 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 812 | self.adapter_agent.add_port(self.device_id, port) |
Shad Ansari | 0efa651 | 2018-04-28 06:42:54 +0000 | [diff] [blame] | 813 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 814 | return port_no, label |
| 815 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 816 | def new_onu_id(self, intf_id): |
| 817 | onu_id = None |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 818 | onu_devices = self.adapter_agent.get_child_devices(self.device_id) |
Shad Ansari | 5dbc9c8 | 2018-05-10 03:29:31 +0000 | [diff] [blame] | 819 | for i in range(1, 512): |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 820 | id_not_taken = True |
| 821 | for child_device in onu_devices: |
| 822 | if child_device.proxy_address.onu_id == i: |
| 823 | id_not_taken = False |
| 824 | break |
| 825 | if id_not_taken: |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 826 | onu_id = i |
| 827 | break |
| 828 | return onu_id |
| 829 | |
| 830 | def stringify_vendor_specific(self, vendor_specific): |
| 831 | return ''.join(str(i) for i in [ |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 832 | hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:], |
Shad Ansari | 1fd9eb2 | 2018-05-15 05:13:49 +0000 | [diff] [blame] | 833 | hex(ord(vendor_specific[0]) & 0x0f)[2:], |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 834 | hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:], |
Shad Ansari | 1fd9eb2 | 2018-05-15 05:13:49 +0000 | [diff] [blame] | 835 | hex(ord(vendor_specific[1]) & 0x0f)[2:], |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 836 | hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:], |
Shad Ansari | 1fd9eb2 | 2018-05-15 05:13:49 +0000 | [diff] [blame] | 837 | hex(ord(vendor_specific[2]) & 0x0f)[2:], |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 838 | hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:], |
Shad Ansari | 1fd9eb2 | 2018-05-15 05:13:49 +0000 | [diff] [blame] | 839 | hex(ord(vendor_specific[3]) & 0x0f)[2:]]) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 840 | |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 841 | def update_flow_table(self, flows): |
| 842 | device = self.adapter_agent.get_device(self.device_id) |
Shad Ansari | cd2e8ff | 2018-05-11 20:26:22 +0000 | [diff] [blame] | 843 | self.log.debug('update flow table') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 844 | in_port = None |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 845 | |
| 846 | for flow in flows: |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 847 | is_down_stream = None |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 848 | in_port = fd.get_in_port(flow) |
| 849 | assert in_port is not None |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 850 | # Right now there is only one NNI port. Get the NNI PORT and |
| 851 | # compare with IN_PUT port number. Need to find better way. |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 852 | ports = self.adapter_agent.get_ports(device.id, Port.ETHERNET_NNI) |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 853 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 854 | for port in ports: |
| 855 | if (port.port_no == in_port): |
| 856 | self.log.info('downstream-flow') |
| 857 | is_down_stream = True |
| 858 | break |
| 859 | if is_down_stream is None: |
| 860 | is_down_stream = False |
| 861 | self.log.info('upstream-flow') |
Shad Ansari | 2825d01 | 2018-02-22 23:57:46 +0000 | [diff] [blame] | 862 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 863 | for flow in flows: |
| 864 | try: |
| 865 | self.flow_mgr.add_flow(flow, is_down_stream) |
| 866 | except Exception as e: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 867 | self.log.exception('failed-to-install-flow', e=e, |
| 868 | flow=flow) |
Shad Ansari | 89b09d5 | 2018-05-21 07:28:14 +0000 | [diff] [blame] | 869 | |
| 870 | # There has to be a better way to do this |
| 871 | def ip_hex(self, ip): |
| 872 | octets = ip.split(".") |
| 873 | hex_ip = [] |
| 874 | for octet in octets: |
| 875 | octet_hex = hex(int(octet)) |
| 876 | octet_hex = octet_hex.split('0x')[1] |
| 877 | octet_hex = octet_hex.rjust(2, '0') |
| 878 | hex_ip.append(octet_hex) |
| 879 | return ":".join(hex_ip) |
Nicolas Palpacuer | 65de6a4 | 2018-05-22 17:28:29 -0400 | [diff] [blame] | 880 | |
| 881 | def stringify_serial_number(self, serial_number): |
| 882 | return ''.join([serial_number.vendor_id, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 883 | self.stringify_vendor_specific( |
| 884 | serial_number.vendor_specific)]) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 885 | |
| 886 | def disable(self): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 887 | self.log.info('sending-deactivate-olt-message', |
| 888 | device_id=self.device_id) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 889 | |
| 890 | # Send grpc call |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 891 | # self.stub.DeactivateOlt(openolt_pb2.Empty()) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 892 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 893 | # Soft deactivate. Turning down hardware should remove flows, |
| 894 | # but we are not doing that presently |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 895 | |
| 896 | # Bring OLT down |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 897 | self.olt_down(oper_state=OperStatus.UNKNOWN, |
| 898 | admin_state=AdminState.DISABLED, |
| 899 | connect_state=ConnectStatus.UNREACHABLE) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 900 | |
| 901 | def delete(self): |
| 902 | self.log.info('delete-olt', device_id=self.device_id) |
| 903 | |
| 904 | # Stop the grpc communication threads |
| 905 | self.log.info('stopping-grpc-threads', device_id=self.device_id) |
| 906 | self.indications_thread_active = False |
| 907 | self.heartbeat_thread_active = False |
| 908 | |
| 909 | # Close the grpc channel |
| 910 | # self.log.info('unsubscribing-grpc-channel', device_id=self.device_id) |
| 911 | # self.channel.unsubscribe() |
| 912 | |
| 913 | self.log.info('successfully-deleted-olt', device_id=self.device_id) |
| 914 | |
| 915 | def reenable(self): |
| 916 | self.log.info('reenable-olt', device_id=self.device_id) |
| 917 | |
| 918 | # Bring up OLT |
| 919 | self.olt_up() |
| 920 | |
| 921 | # Enable all child devices |
| 922 | self.log.info('enabling-child-devices', device_id=self.device_id) |
| 923 | self.log.info('enabling-child-devices', olt_device_id=self.device_id) |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 924 | self.adapter_agent.update_child_devices_state( |
| 925 | parent_device_id=self.device_id, |
| 926 | admin_state=AdminState.ENABLED) |
Jonathan Davis | 0f917a2 | 2018-05-30 14:39:45 -0400 | [diff] [blame] | 927 | |
| 928 | # Set all ports to enabled |
| 929 | self.log.info('enabling-all-ports', device_id=self.device_id) |
Shad Ansari | a0b3789 | 2018-06-12 21:34:30 +0000 | [diff] [blame] | 930 | self.adapter_agent.enable_all_ports(self.device_id) |