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