blob: 700a0eed86c90a93411290c627e96108bcf6f9e0 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 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"""
18Broadcom OpenOMCI OLT/ONU adapter handler.
19"""
20
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050021from __future__ import absolute_import
22import six
Devmalya Paulffc89df2019-07-31 17:43:13 -040023import arrow
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050024import structlog
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050025import json
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050026import random
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050027
28from collections import OrderedDict
29
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050030from twisted.internet import reactor
Matt Jeanneret5e331892019-12-07 21:31:45 -050031from twisted.internet.defer import inlineCallbacks, returnValue
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050032
33from heartbeat import HeartBeat
Devmalya Paulffc89df2019-07-31 17:43:13 -040034from pyvoltha.adapters.extensions.events.device_events.onu.onu_active_event import OnuActiveEvent
Devmalya Paule2e5f2b2020-03-08 18:50:33 -040035from pyvoltha.adapters.extensions.events.device_events.onu.onu_disabled_event import OnuDisabledEvent
Devmalya Paulffc89df2019-07-31 17:43:13 -040036from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
37from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
38from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050039
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050040import pyvoltha.common.openflow.utils as fd
41from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070042from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050043from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret5e331892019-12-07 21:31:45 -050044from pyvoltha.adapters.common.kvstore.twisted_etcd_store import TwistedEtcdStore
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050045from voltha_protos.logical_device_pb2 import LogicalPort
William Kurkian8235c1e2019-03-05 12:58:28 -050046from voltha_protos.common_pb2 import OperStatus, ConnectStatus, AdminState
Matt Jeanneretf4113222019-08-14 19:44:34 -040047from voltha_protos.device_pb2 import Port
Girish Gowdra4c11ddb2020-03-03 11:33:24 -080048from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE, OFPPS_LINK_DOWN, \
Matt Jeanneretf4113222019-08-14 19:44:34 -040049 OFPPF_FIBER, OFPPF_1GB_FD
Matt Jeanneret3bfebff2019-04-12 18:25:03 -040050from voltha_protos.inter_container_pb2 import InterAdapterMessageType, \
Girish Gowdrae933cd32019-11-21 21:04:41 +053051 InterAdapterOmciMessage, PortCapability, InterAdapterTechProfileDownloadMessage, InterAdapterDeleteGemPortMessage, \
52 InterAdapterDeleteTcontMessage
Matt Jeannereta32441c2019-03-07 05:16:37 -050053from voltha_protos.openolt_pb2 import OnuIndication
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050054from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050055 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050056from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053057from omci.brcm_tp_setup_task import BrcmTpSetupTask
58from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050059from omci.brcm_uni_lock_task import BrcmUniLockTask
60from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050061from onu_gem_port import OnuGemPort
62from onu_tcont import OnuTCont
63from pon_port import PonPort
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080064from omci.brcm_mcast_task import BrcmMcastTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050065from uni_port import UniPort, UniType
Andrea Campanellacf916ea2020-02-14 10:03:58 +010066from uni_port import RESERVED_TRANSPARENT_VLAN
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050067from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053068from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
Matt Jeanneret5e331892019-12-07 21:31:45 -050069from pyvoltha.adapters.extensions.omci.omci_entities import AniG, Tcont, MacBridgeServiceProfile
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050070from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
onkarkundargia1e2af22020-01-27 11:51:43 +053071from voltha_protos.voltha_pb2 import TestResponse
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072
73OP = EntityOperations
74RC = ReasonCodes
75
Girish Gowdradc98d812020-03-20 13:04:58 -070076IS_MULTICAST = 'is_multicast'
Mahir Gunyel5de33fe2020-03-03 22:38:44 -080077GEM_PORT_ID = 'gemport_id'
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050078_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080079_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050080
81
82class BrcmOpenomciOnuHandler(object):
83
84 def __init__(self, adapter, device_id):
85 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050086 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050088 self.core_proxy = adapter.core_proxy
89 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050090 self.parent_id = None
91 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050092 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050093 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040094 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050095 self._pm_metrics = None
96 self._pm_metrics_started = False
97 self._test_request = None
98 self._test_request_started = False
Girish Gowdradc98d812020-03-20 13:04:58 -070099 self._tp = dict() # tp_id -> technology profile definition in KV Store.
Matt Jeanneret5e331892019-12-07 21:31:45 -0500100 self._reconciling = False
101
102 # Persisted onu configuration needed in case of reconciliation.
103 self._onu_persisted_state = {
104 'onu_id': None,
105 'intf_id': None,
106 'serial_number': None,
107 'admin_state': None,
108 'oper_state': None,
109 'uni_config': list()
110 }
111
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500112 self._unis = dict() # Port # -> UniPort
113
114 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500115 self._pon_port_number = 100
116 self.logical_device_id = None
117
118 self._heartbeat = HeartBeat.create(self, device_id)
119
120 # Set up OpenOMCI environment
121 self._onu_omci_device = None
122 self._dev_info_loaded = False
123 self._deferred = None
124
125 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400126 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500127 self._connectivity_subscription = None
128 self._capabilities_subscription = None
129
130 self.mac_bridge_service_profile_entity_id = 0x201
131 self.gal_enet_profile_entity_id = 0x1
132
133 self._tp_service_specific_task = dict()
134 self._tech_profile_download_done = dict()
Girish Gowdradc98d812020-03-20 13:04:58 -0700135
136 # When the vlan filter is being removed for a given TP ID on a given UNI,
137 # mark that we are expecting a tp delete to happen for this UNI.
138 # Unless the TP delete is complete to not allow new vlan add tasks to this TP ID
139 self._pending_delete_tp = dict()
140
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400141 # Stores information related to queued vlan filter tasks
142 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400143 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500144
Girish Gowdradc98d812020-03-20 13:04:58 -0700145 self._set_vlan = dict() # uni_id, tp_id -> set_vlan_id
Matt Jeanneret5e331892019-12-07 21:31:45 -0500146
147 # Paths from kv store
148 ONU_PATH = 'service/voltha/openonu'
149
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500150 # Initialize KV store client
151 self.args = registry('main').get_args()
Matt Jeanneret5e331892019-12-07 21:31:45 -0500152 host, port = self.args.etcd.split(':', 1)
153 self.tp_kv_client = TwistedEtcdStore(host, port, TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
154 self.onu_kv_client = TwistedEtcdStore(host, port, ONU_PATH)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500155
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500156 @property
157 def enabled(self):
158 return self._enabled
159
160 @enabled.setter
161 def enabled(self, value):
162 if self._enabled != value:
163 self._enabled = value
164
165 @property
166 def omci_agent(self):
167 return self.adapter.omci_agent
168
169 @property
170 def omci_cc(self):
171 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
172
173 @property
174 def heartbeat(self):
175 return self._heartbeat
176
177 @property
178 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500179 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500180
181 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500182 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500183 return next((uni for uni in self.uni_ports
184 if uni.name == port_no_or_name), None)
185
186 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
187 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530188 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500189
190 @property
191 def pon_port(self):
192 return self._pon
193
Girish Gowdraa73ee452019-12-20 18:52:17 +0530194 @property
195 def onu_omci_device(self):
196 return self._onu_omci_device
197
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500198 def receive_message(self, msg):
199 if self.omci_cc is not None:
200 self.omci_cc.receive_message(msg)
201
Matt Jeanneretc083f462019-03-11 15:02:01 -0400202 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500203 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400204 cap = OFPPF_1GB_FD | OFPPF_FIBER
205
Girish Gowdrae933cd32019-11-21 21:04:41 +0530206 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
207 ((device.parent_port_no >> 8 & 0xff),
208 device.parent_port_no & 0xff,
209 (port_no >> 16) & 0xff,
210 (port_no >> 8) & 0xff,
211 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400212
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400213 uni_port = self.uni_port(int(port_no))
214 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500215 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400216
217 ofstate = OFPPS_LINK_DOWN
218 if uni_port.operstatus is OperStatus.ACTIVE:
219 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400220
Matt Jeanneretc083f462019-03-11 15:02:01 -0400221 return PortCapability(
222 port=LogicalPort(
223 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400224 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400225 hw_addr=hw_addr,
226 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400227 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400228 curr=cap,
229 advertised=cap,
230 peer=cap,
231 curr_speed=OFPPF_1GB_FD,
232 max_speed=OFPPF_1GB_FD
233 ),
234 device_id=device.id,
235 device_port_no=port_no
236 )
237 )
238
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500239 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500240 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500241 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700242 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500244 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500245 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500246 assert device.proxy_address.device_id
247
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500249 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500250 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500251 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700252 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500254 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500255 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500256 device.reason = 'activating-onu'
257
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500258 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400259 # pm_metrics requires a logical device id. For now set to just device_id
260 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500261
Matt Jeanneret5e331892019-12-07 21:31:45 -0500262 self._onu_persisted_state['serial_number'] = device.serial_number
263 try:
264 self.log.debug('updating-onu-state', device_id=self.device_id,
265 onu_persisted_state=self._onu_persisted_state)
266 yield self.onu_kv_client.set(self.device_id, json.dumps(self._onu_persisted_state))
267 except Exception as e:
268 self.log.error('could-not-store-onu-state', device_id=self.device_id,
269 onu_persisted_state=self._onu_persisted_state, e=e)
270 # if we cannot write to storage we can proceed, for now.
271 # later onu indications from the olt will have another chance
272
Matt Jeannereta32441c2019-03-07 05:16:37 -0500273 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500274 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500275
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700276 yield self._init_pon_state()
Matteo Scandolod8d73172019-11-26 12:15:15 -0700277 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500278
Matt Jeanneret5e331892019-12-07 21:31:45 -0500279 yield self._init_metrics()
280 self.log.debug('metrics initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500281
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500282 self.enabled = True
283 else:
284 self.log.info('onu-already-activated')
285
286 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400287 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500288 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700289 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500290
Matt Jeanneret5e331892019-12-07 21:31:45 -0500291 if self._reconciling:
292 self.log.debug('already-running-reconcile-device', device_id=device.id, serial_number=device.serial_number)
293 return
294
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500295 # first we verify that we got parent reference and proxy info
296 assert device.parent_id
297 assert device.proxy_address.device_id
298
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700299 self.proxy_address = device.proxy_address
300 self.parent_id = device.parent_id
301 self._pon_port_number = device.parent_port_no
302
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500303 if self.enabled is not True:
Matt Jeanneret5e331892019-12-07 21:31:45 -0500304 self._reconciling = True
305 self.log.info('reconciling-openonu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700306 self.logical_device_id = self.device_id
Matt Jeanneret5e331892019-12-07 21:31:45 -0500307
308 try:
309 query_data = yield self.onu_kv_client.get(device.id)
310 self._onu_persisted_state = json.loads(query_data)
311 self.log.debug('restored-onu-state', device_id=self.device_id,
312 onu_persisted_state=self._onu_persisted_state)
313 except Exception as e:
314 self.log.error('no-stored-onu-state', device_id=device.id, e=e)
315 # there is nothing we can do without data. flag the device as UNKNOWN and cannot reconcile
316 # likely it will take manual steps to delete/re-add this onu
317 yield self.core_proxy.device_reason_update(self.device_id, "cannot-reconcile")
318 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
319 return
320
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700321 self._init_pon_state()
Matt Jeanneret5e331892019-12-07 21:31:45 -0500322 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500323
Matt Jeanneret5e331892019-12-07 21:31:45 -0500324 self._init_metrics()
325 self.log.debug('metrics initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500326
Matt Jeanneret5e331892019-12-07 21:31:45 -0500327 self._subscribe_to_events()
328 # need to restart omci start machines and reload mib database. once db is loaded we can finish reconcile
329 self._onu_omci_device.start(device)
330 self._heartbeat.enabled = True
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500331
332 self.enabled = True
333 else:
334 self.log.info('onu-already-activated')
335
336 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700337 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500338 self.log.debug('init-pon-state', device_id=self.device_id, device_logical_id=self.logical_device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500339
340 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500341 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700342 self.log.debug('adding-pon-port-to-agent',
343 type=self._pon.get_port().type,
344 admin_state=self._pon.get_port().admin_state,
345 oper_status=self._pon.get_port().oper_status,
346 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500347
Matt Jeanneret5e331892019-12-07 21:31:45 -0500348 if not self._reconciling:
349 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500350
Matteo Scandolod8d73172019-11-26 12:15:15 -0700351 self.log.debug('added-pon-port-to-agent',
352 type=self._pon.get_port().type,
353 admin_state=self._pon.get_port().admin_state,
354 oper_status=self._pon.get_port().oper_status,
355 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500356
357 # Create and start the OpenOMCI ONU Device Entry for this ONU
358 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500359 self.core_proxy,
360 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500361 support_classes=self.adapter.broadcom_omci,
362 custom_me_map=self.adapter.custom_me_entities())
363 # Port startup
364 if self._pon is not None:
365 self._pon.enabled = True
366
Matt Jeanneret5e331892019-12-07 21:31:45 -0500367 @inlineCallbacks
368 def _init_metrics(self):
369 self.log.debug('init-metrics', device_id=self.device_id, device_logical_id=self.logical_device_id)
370
371 serial_number = self._onu_persisted_state.get('serial_number')
372
373 ############################################################################
374 # Setup Alarm handler
375 self.events = AdapterEvents(self.core_proxy, self.device_id, self.logical_device_id,
376 serial_number)
377 ############################################################################
378 # Setup PM configuration for this device
379 # Pass in ONU specific options
380 kwargs = {
381 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
382 'heartbeat': self.heartbeat,
383 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
384 }
385 self.log.debug('create-pm-metrics', device_id=self.device_id, serial_number=serial_number)
386 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
387 self.logical_device_id, serial_number,
388 grouped=True, freq_override=False, **kwargs)
389 pm_config = self._pm_metrics.make_proto()
390 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
391 self.log.debug("initial-pm-config", device_id=self.device_id, serial_number=serial_number)
392
393 if not self._reconciling:
394 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
395
396 # Note, ONU ID and UNI intf set in add_uni_port method
397 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
398 ani_ports=[self._pon])
399
400 # Code to Run OMCI Test Action
401 kwargs_omci_test_action = {
402 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
403 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
404 }
405 self._test_request = OmciTestRequest(self.core_proxy,
406 self.omci_agent, self.device_id,
407 AniG, serial_number,
408 self.logical_device_id,
409 exclusive=False,
410 **kwargs_omci_test_action)
411
412 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500413 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700414 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500415
Matt Jeanneret5e331892019-12-07 21:31:45 -0500416 try:
417 yield self.onu_kv_client.delete(device.id)
418 except Exception as e:
419 self.log.error('could-not-delete-onu-state', device_id=device.id, e=e)
420
Matt Jeanneret42dad792020-02-01 09:28:27 -0500421 self._deferred.cancel()
422 self._test_request.stop_collector()
423 self._pm_metrics.stop_collector()
424 self.log.debug('removing-openomci-statemachine')
425 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500426
427 def _create_tconts(self, uni_id, us_scheduler):
428 alloc_id = us_scheduler['alloc_id']
429 q_sched_policy = us_scheduler['q_sched_policy']
430 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800431 # TODO: revisit for multi tconts support
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800432 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500433 tcontdict = dict()
434 tcontdict['alloc-id'] = alloc_id
435 tcontdict['q_sched_policy'] = q_sched_policy
436 tcontdict['uni_id'] = uni_id
437
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500438 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500439
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500440 success = self._pon.add_tcont(tcont)
441 if success:
442 new_tconts.append(tcont)
443 self.log.debug('pon-add-tcont', tcont=tcont)
444
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800445 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500446
447 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
448 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
449 self.log.debug('create-gemport',
450 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530451 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500452 for gem_port in gem_ports:
453 gemdict = dict()
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800454 if gem_port[IS_MULTICAST] == 'True':
455 gemdict[GEM_PORT_ID] = gem_port['multicast_gem_id']
456 gemdict[IS_MULTICAST] = True
457 else:
458 gemdict[GEM_PORT_ID] = gem_port[GEM_PORT_ID]
459 gemdict[IS_MULTICAST] = False
460
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 gemdict['direction'] = direction
462 gemdict['alloc_id_ref'] = alloc_id_ref
463 gemdict['encryption'] = gem_port['aes_encryption']
464 gemdict['discard_config'] = dict()
465 gemdict['discard_config']['max_probability'] = \
466 gem_port['discard_config']['max_probability']
467 gemdict['discard_config']['max_threshold'] = \
468 gem_port['discard_config']['max_threshold']
469 gemdict['discard_config']['min_threshold'] = \
470 gem_port['discard_config']['min_threshold']
471 gemdict['discard_policy'] = gem_port['discard_policy']
472 gemdict['max_q_size'] = gem_port['max_q_size']
473 gemdict['pbit_map'] = gem_port['pbit_map']
474 gemdict['priority_q'] = gem_port['priority_q']
475 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
476 gemdict['weight'] = gem_port['weight']
477 gemdict['uni_id'] = uni_id
478
479 gem_port = OnuGemPort.create(self, gem_port=gemdict)
480
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500481 success = self._pon.add_gem_port(gem_port, True)
482 if success:
483 new_gem_ports.append(gem_port)
484 self.log.debug('pon-add-gemport', gem_port=gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485
Girish Gowdrae933cd32019-11-21 21:04:41 +0530486 return new_gem_ports
487
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800488 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400489 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
490 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
491 # or initial-mib-download is not done. Once the tp_task is completed, we execute
492 # such queued vlan-filter tasks
493 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800494 if uni_id in self._queued_vlan_filter_task and tp_id in self._queued_vlan_filter_task[uni_id]:
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400495 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800496 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800497 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
498 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800499 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
500 match_vlan=filter_info.get("match_vlan"),
501 _set_vlan_vid=filter_info.get("set_vlan_vid"),
502 _set_vlan_pcp=filter_info.get("set_vlan_pcp"),
503 tp_id=filter_info.get("tp_id"))
Girish Gowdraaf98a082020-03-05 16:40:51 -0800504 # Now remove the entry from the dictionary
505 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
506 self.log.debug("executed-queued-vlan-filter-task",
507 uni_id=uni_id, tp_id=tp_id)
508 # Now delete the key entries once we have handled the queued vlan filter tasks.
509 del self._queued_vlan_filter_task[uni_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400510 except Exception as e:
511 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
512
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500513 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500514 us_scheduler = tp['us_scheduler']
515 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800516 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500517 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800518 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500519 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800520 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
521
522 new_gems = []
523 new_gems.extend(new_upstream_gems)
524 new_gems.extend(new_downstream_gems)
525
526 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500527
Matt Jeanneret5e331892019-12-07 21:31:45 -0500528 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500529 def load_and_configure_tech_profile(self, uni_id, tp_path):
530 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800531 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500532 if uni_id not in self._tp_service_specific_task:
533 self._tp_service_specific_task[uni_id] = dict()
534
535 if uni_id not in self._tech_profile_download_done:
536 self._tech_profile_download_done[uni_id] = dict()
537
Mahir Gunyele9110a32020-02-20 14:56:50 -0800538 if tp_id not in self._tech_profile_download_done[uni_id]:
539 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500540
Mahir Gunyele9110a32020-02-20 14:56:50 -0800541 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500542 try:
543 if tp_path in self._tp_service_specific_task[uni_id]:
544 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530545 tp_path=tp_path)
Matt Jeanneret5e331892019-12-07 21:31:45 -0500546 returnValue(None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500547
Matt Jeanneret5e331892019-12-07 21:31:45 -0500548 tpstored = yield self.tp_kv_client.get(tp_path)
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500549 tpstring = tpstored.decode('ascii')
550 tp = json.loads(tpstring)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800551 self._tp[tp_id] = tp
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500552 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800553 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700554
William Kurkian3a206332019-04-29 11:05:47 -0400555 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500556 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800557 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500558 if tp_path in self._tp_service_specific_task[uni_id]:
559 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800560 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400561 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800562 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500563 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530564
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800565 # Execute mcast task
566 for gem in gem_ports:
Girish Gowdradc98d812020-03-20 13:04:58 -0700567 self.log.debug("checking-multicast-service-for-gem ", gem=gem)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800568 if gem.mcast is True:
Girish Gowdradc98d812020-03-20 13:04:58 -0700569 self.log.info("found-multicast-service-for-gem ", gem=gem, uni_id=uni_id, tp_id=tp_id)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800570 reactor.callInThread(self.start_multicast_service, uni_id, tp_path)
571 self.log.debug("started_multicast_service-successfully", tconts=tconts, gems=gem_ports)
572 break
573
William Kurkian3a206332019-04-29 11:05:47 -0400574 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500575 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800576 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530577 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500578 if tp_path in self._tp_service_specific_task[uni_id]:
579 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800580 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500581 reactor.callLater(retry, self.load_and_configure_tech_profile,
582 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500583 yield self.core_proxy.device_reason_update(self.device_id,
584 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500585
Mahir Gunyela982ec32020-02-25 12:30:37 -0800586 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530587 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
588
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500589 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
590 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
591
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500592 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800593 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500594 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530595 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500596 self._deferred.addCallbacks(success, failure)
597
598 except Exception as e:
599 self.log.exception("error-loading-tech-profile", e=e)
600 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700601 # There is an active tech-profile task ongoing on this UNI port. So, reschedule this task
602 # after a short interval
603 if uni_id in self._tp_service_specific_task and len(self._tp_service_specific_task[uni_id]):
604 self.log.debug("active-tp-tasks-in-progress-for-uni--scheduling-this-task-for-later",
605 uni_id=uni_id, tp_path=tp_path)
606 reactor.callLater(0.2, self.load_and_configure_tech_profile,
607 uni_id, tp_path)
608 return
609
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500610 self.log.info("tech-profile-config-already-done")
Girish Gowdradc98d812020-03-20 13:04:58 -0700611
Girish Gowdrae933cd32019-11-21 21:04:41 +0530612 # Could be a case where TP exists but new gem-ports are getting added dynamically
Matt Jeanneret5e331892019-12-07 21:31:45 -0500613 tpstored = yield self.tp_kv_client.get(tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530614 tpstring = tpstored.decode('ascii')
615 tp = json.loads(tpstring)
616 upstream_gems = []
617 downstream_gems = []
618 # Find out the new Gem ports that are getting added afresh.
619 for gp in tp['upstream_gem_port_attribute_list']:
620 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
621 # gem port already exists
622 continue
623 upstream_gems.append(gp)
624 for gp in tp['downstream_gem_port_attribute_list']:
625 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
626 # gem port already exists
627 continue
628 downstream_gems.append(gp)
629
630 us_scheduler = tp['us_scheduler']
631 alloc_id = us_scheduler['alloc_id']
632
633 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
634 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
635 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
636 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
637 new_gems = []
638 new_gems.extend(new_upstream_gems)
639 new_gems.extend(new_downstream_gems)
640
641 def success(_results):
642 self.log.info("new-gem-ports-successfully-installed", result=_results)
643
644 def failure(_reason):
645 self.log.warn('new-gem-port-install-failed--retrying',
646 _reason=_reason)
647 # Remove gem ports from cache. We will re-add them during the retry
648 for gp in new_gems:
649 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
650
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800651 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500652 reactor.callLater(retry, self.load_and_configure_tech_profile,
653 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530654
655 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800656 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530657 self._deferred = \
658 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
659 self._deferred.addCallbacks(success, failure)
Girish Gowdradc98d812020-03-20 13:04:58 -0700660
Matt Jeanneret5e331892019-12-07 21:31:45 -0500661 @inlineCallbacks
Girish Gowdradc98d812020-03-20 13:04:58 -0700662 def start_multicast_service(self, uni_id, tp_path, retry_count=0):
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800663 self.log.debug("starting-multicast-service", uni_id=uni_id, tp_path=tp_path)
664 tp_id = self.extract_tp_id_from_path(tp_path)
665 if uni_id in self._set_vlan and tp_id in self._set_vlan[uni_id]:
666 try:
667 tp = self._tp[tp_id]
668 if tp is None:
Matt Jeanneret5e331892019-12-07 21:31:45 -0500669 tpstored = yield self.tp_kv_client.get(tp_path)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800670 tpstring = tpstored.decode('ascii')
671 tp = json.loads(tpstring)
672 if tp is None:
673 self.log.error("cannot-find-tp-to-start-multicast-service", uni_id=uni_id, tp_path=tp_path)
674 return
675 else:
676 self._tp[tp_id] = tp
677
678 self.log.debug("mcast-vlan-learned-before", self._set_vlan[uni_id][tp_id], uni_id=uni_id, tp_id=tp_id)
Girish Gowdradc98d812020-03-20 13:04:58 -0700679
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800680 def success(_results):
681 self.log.debug('multicast-success', uni_id=uni_id)
682 self._multicast_task = None
683
684 def failure(_reason):
685 self.log.warn('multicast-failure', _reason=_reason)
Girish Gowdradc98d812020-03-20 13:04:58 -0700686 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800687 reactor.callLater(retry, self.start_multicast_service,
Girish Gowdradc98d812020-03-20 13:04:58 -0700688 uni_id, tp_path)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800689
690 self.log.debug('starting-multicast-task', mcast_vlan_id=self._set_vlan[uni_id][tp_id])
691 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
692 for i in range(len(downstream_gem_port_attribute_list)):
693 if IS_MULTICAST in downstream_gem_port_attribute_list[i] and \
694 downstream_gem_port_attribute_list[i][IS_MULTICAST] == 'True':
Girish Gowdradc98d812020-03-20 13:04:58 -0700695 dynamic_access_control_list_table = downstream_gem_port_attribute_list[i][
696 'dynamic_access_control_list'].split("-")
697 static_access_control_list_table = downstream_gem_port_attribute_list[i][
698 'static_access_control_list'].split("-")
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800699 multicast_gem_id = downstream_gem_port_attribute_list[i]['multicast_gem_id']
700 break
701
702 self._multicast_task = BrcmMcastTask(self.omci_agent, self, self.device_id, uni_id, tp_id,
Girish Gowdradc98d812020-03-20 13:04:58 -0700703 self._set_vlan[uni_id][tp_id], dynamic_access_control_list_table,
704 static_access_control_list_table, multicast_gem_id)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800705 self._deferred = self._onu_omci_device.task_runner.queue_task(self._multicast_task)
706 self._deferred.addCallbacks(success, failure)
707 except Exception as e:
708 self.log.exception("error-loading-multicast", e=e)
709 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700710 if retry_count < 30:
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800711 retry_count = +1
Girish Gowdradc98d812020-03-20 13:04:58 -0700712 self.log.debug("going-to-wait-for-flow-to-learn-mcast-vlan", uni_id=uni_id, tp_id=tp_id,
713 retry=retry_count)
Mahir Gunyel5de33fe2020-03-03 22:38:44 -0800714 reactor.callLater(0.5, self.start_multicast_service, uni_id, tp_path, retry_count)
715 else:
Girish Gowdradc98d812020-03-20 13:04:58 -0700716 self.log.error("mcast-vlan-not-configured-yet-failing-mcast-service-conf", uni_id=uni_id, tp_id=tp_id,
717 retry=retry_count)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530718
719 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
720 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800721 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530722 if not uni_id in self._tech_profile_download_done:
723 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
724 return
725
Mahir Gunyele9110a32020-02-20 14:56:50 -0800726 if not tp_table_id in self._tech_profile_download_done[uni_id]:
727 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530728 return
729
Mahir Gunyele9110a32020-02-20 14:56:50 -0800730 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800731 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id,
732 tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530733 return
734
735 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800736 self.log.error("alloc-id-and-gem-port-id-are-none", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530737 return
738
739 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
740 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
741 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
742 # this initializer
743 tcont = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500744 self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530745 for tc in list(self.pon_port.tconts.values()):
746 if tc.alloc_id == alloc_id:
747 tcont = tc
748 self.pon_port.remove_tcont(tc.alloc_id, False)
749
750 gem_port = None
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500751 self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
Girish Gowdrae933cd32019-11-21 21:04:41 +0530752 for gp in list(self.pon_port.gem_ports.values()):
753 if gp.gem_id == gem_port_id:
754 gem_port = gp
755 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
756
Girish Gowdrae933cd32019-11-21 21:04:41 +0530757 @inlineCallbacks
758 def success(_results):
759 if gem_port_id:
760 self.log.info("gem-port-delete-done-successfully")
761 if alloc_id:
762 self.log.info("tcont-delete-done-successfully")
763 # The deletion of TCONT marks the complete deletion of tech-profile
764 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800765 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdradc98d812020-03-20 13:04:58 -0700766 self.log.debug("tp-profile-download-flag-cleared", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530767 del self._tp_service_specific_task[uni_id][tp_path]
Girish Gowdradc98d812020-03-20 13:04:58 -0700768 self.log.debug("tp-service-specific-task-cleared", uni_id=uni_id, tp_id=tp_table_id)
769 del self._pending_delete_tp[uni_id][tp_table_id]
770 self.log.debug("pending-delete-tp-task-flag-cleared", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530771 except Exception as ex:
772 self.log.error("del-tp-state-info", e=ex)
773
774 # TODO: There could be multiple TP on the UNI, and also the ONU.
775 # TODO: But the below reason updates for the whole device.
776 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
777
778 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530779 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530780 self.log.warn('tech-profile-delete-failure-retrying',
781 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500782 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
783 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500784 yield self.core_proxy.device_reason_update(self.device_id,
785 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530786
787 self.log.info('deleting-tech-profile-configuration')
788
Girish Gowdraa73ee452019-12-20 18:52:17 +0530789 if tcont is None and gem_port is None:
790 if alloc_id is not None:
791 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
792 if gem_port_id is not None:
793 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
794 return
795
Girish Gowdrae933cd32019-11-21 21:04:41 +0530796 self._tp_service_specific_task[uni_id][tp_path] = \
797 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
798 tcont=tcont, gem_port=gem_port)
799 self._deferred = \
800 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
801 self._deferred.addCallbacks(success, failure)
802 except Exception as e:
803 self.log.exception("failed-to-delete-tp",
804 e=e, uni_id=uni_id, tp_path=tp_path,
805 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500806
807 def update_pm_config(self, device, pm_config):
808 # TODO: This has not been tested
809 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500810 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500811
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800812 def remove_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500813 self.log.debug('remove-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800814
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800815 # no point in removing omci flows if the device isnt reachable
816 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800817 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800818 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
819 admin=device.admin_state, connect=device.connect_status)
820 return
821
822 for flow in flows:
823 # if incoming flow contains cookie, then remove from ONU
824 if flow.cookie:
825 self.log.debug("remove-flow", device_id=device.id, flow=flow)
826
827 def is_downstream(port):
828 return port == self._pon_port_number
829
830 def is_upstream(port):
831 return not is_downstream(port)
832
833 try:
834 _in_port = fd.get_in_port(flow)
835 assert _in_port is not None
836
837 _out_port = fd.get_out_port(flow) # may be None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800838
839 if is_downstream(_in_port):
840 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
841 device_id=device.id)
842 # extended vlan tagging operation will handle it
843 continue
844 elif is_upstream(_in_port):
845 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
846 if fd.is_dhcp_flow(flow):
847 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
848 return
849
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800850 _vlan_vid = 0
851 # Retrieve the VLAN_VID that needs to be removed from the EVTO rule on the ONU.
852 for action in fd.get_actions(flow):
853 if action.type == fd.SET_FIELD:
854 _field = action.set_field.field.ofb_field
855 assert (action.set_field.field.oxm_class ==
856 OFPXMC_OPENFLOW_BASIC)
857 if _field.type == fd.VLAN_VID:
858 _vlan_vid = _field.vlan_vid & 0xfff
859 self.log.debug('vlan-vid-to-remove',
860 _vlan_vid=_vlan_vid, in_port=_in_port)
861
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800862 uni_port = self.uni_port(_in_port)
863 uni_id = _in_port & 0xF
864 else:
865 raise Exception('port should be 1 or 2 by our convention')
866
867 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
868
869 tp_id = self.get_tp_id_in_flow(flow)
Girish Gowdradc98d812020-03-20 13:04:58 -0700870 # The vlan filter remove should be followed by a TP deleted for that TP ID.
871 # Use this information to re-schedule any vlan filter add tasks for the same TP ID again.
872 # First check if the TP download was done, before we access that TP delete is necessary
873 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
874 self._tech_profile_download_done[uni_id][tp_id] is True:
875 if uni_id not in self._pending_delete_tp:
876 self._pending_delete_tp[uni_id] = dict()
877 self._pending_delete_tp[uni_id][tp_id] = True
878 else:
879 self._pending_delete_tp[uni_id][tp_id] = True
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800880 # Deleting flow from ONU.
881 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800882 match_vlan=_vlan_vid, tp_id=tp_id)
Girish Gowdradc98d812020-03-20 13:04:58 -0700883
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800884 # TODO:Delete TD task.
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800885 except Exception as e:
886 self.log.exception('failed-to-remove-flow', e=e)
887
888 def add_onu_flows(self, device, flows):
Matt Jeanneret2ca384f2020-03-06 13:49:31 -0500889 self.log.debug('add-onu-flows')
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800890
891 # no point in pushing omci flows if the device isnt reachable
892 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800893 device.admin_state != AdminState.ENABLED:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800894 self.log.warn("device-disabled-or-offline-skipping-flow-update",
895 admin=device.admin_state, connect=device.connect_status)
896 return
Girish Gowdra4c11ddb2020-03-03 11:33:24 -0800897
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800898 def is_downstream(port):
899 return port == self._pon_port_number
900
901 def is_upstream(port):
902 return not is_downstream(port)
903
904 for flow in flows:
905 # if incoming flow contains cookie, then add to ONU
906 if flow.cookie:
907 _type = None
908 _port = None
909 _vlan_vid = None
910 _udp_dst = None
911 _udp_src = None
912 _ipv4_dst = None
913 _ipv4_src = None
914 _metadata = None
915 _output = None
916 _push_tpid = None
917 _field = None
918 _set_vlan_vid = None
919 _set_vlan_pcp = 0
920 _tunnel_id = None
921 self.log.debug("add-flow", device_id=device.id, flow=flow)
922
923 try:
924 _in_port = fd.get_in_port(flow)
925 assert _in_port is not None
926
927 _out_port = fd.get_out_port(flow) # may be None
928 tp_id = self.get_tp_id_in_flow(flow)
929 if is_downstream(_in_port):
930 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
931 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
932 # uni_port = self.uni_port(_out_port)
933 # uni_id = _out_port & 0xF
934 continue
935 elif is_upstream(_in_port):
936 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
937 uni_port = self.uni_port(_in_port)
938 uni_id = _in_port & 0xF
939 else:
940 raise Exception('port should be 1 or 2 by our convention')
941
942 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
943
944 for field in fd.get_ofb_fields(flow):
945 if field.type == fd.ETH_TYPE:
946 _type = field.eth_type
947 self.log.debug('field-type-eth-type',
948 eth_type=_type)
949
950 elif field.type == fd.IP_PROTO:
951 _proto = field.ip_proto
952 self.log.debug('field-type-ip-proto',
953 ip_proto=_proto)
954
955 elif field.type == fd.IN_PORT:
956 _port = field.port
957 self.log.debug('field-type-in-port',
958 in_port=_port)
959 elif field.type == fd.TUNNEL_ID:
960 self.log.debug('field-type-tunnel-id')
961
962 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100963 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
964 _vlan_vid = RESERVED_TRANSPARENT_VLAN
965 else:
966 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800967 self.log.debug('field-type-vlan-vid',
968 vlan=_vlan_vid)
969
970 elif field.type == fd.VLAN_PCP:
971 _vlan_pcp = field.vlan_pcp
972 self.log.debug('field-type-vlan-pcp',
973 pcp=_vlan_pcp)
974
975 elif field.type == fd.UDP_DST:
976 _udp_dst = field.udp_dst
977 self.log.debug('field-type-udp-dst',
978 udp_dst=_udp_dst)
979
980 elif field.type == fd.UDP_SRC:
981 _udp_src = field.udp_src
982 self.log.debug('field-type-udp-src',
983 udp_src=_udp_src)
984
985 elif field.type == fd.IPV4_DST:
986 _ipv4_dst = field.ipv4_dst
987 self.log.debug('field-type-ipv4-dst',
988 ipv4_dst=_ipv4_dst)
989
990 elif field.type == fd.IPV4_SRC:
991 _ipv4_src = field.ipv4_src
992 self.log.debug('field-type-ipv4-src',
993 ipv4_dst=_ipv4_src)
994
995 elif field.type == fd.METADATA:
996 _metadata = field.table_metadata
997 self.log.debug('field-type-metadata',
998 metadata=_metadata)
999
1000 else:
1001 raise NotImplementedError('field.type={}'.format(
1002 field.type))
1003
1004 for action in fd.get_actions(flow):
1005
1006 if action.type == fd.OUTPUT:
1007 _output = action.output.port
1008 self.log.debug('action-type-output',
1009 output=_output, in_port=_in_port)
1010
1011 elif action.type == fd.POP_VLAN:
1012 self.log.debug('action-type-pop-vlan',
1013 in_port=_in_port)
1014
1015 elif action.type == fd.PUSH_VLAN:
1016 _push_tpid = action.push.ethertype
1017 self.log.debug('action-type-push-vlan',
1018 push_tpid=_push_tpid, in_port=_in_port)
1019 if action.push.ethertype != 0x8100:
1020 self.log.error('unhandled-tpid',
1021 ethertype=action.push.ethertype)
1022
1023 elif action.type == fd.SET_FIELD:
1024 _field = action.set_field.field.ofb_field
1025 assert (action.set_field.field.oxm_class ==
1026 OFPXMC_OPENFLOW_BASIC)
1027 self.log.debug('action-type-set-field',
1028 field=_field, in_port=_in_port)
1029 if _field.type == fd.VLAN_VID:
1030 _set_vlan_vid = _field.vlan_vid & 0xfff
1031 self.log.debug('set-field-type-vlan-vid',
1032 vlan_vid=_set_vlan_vid)
1033 elif _field.type == fd.VLAN_PCP:
1034 _set_vlan_pcp = _field.vlan_pcp
1035 self.log.debug('set-field-type-vlan-pcp',
1036 vlan_pcp=_set_vlan_pcp)
1037 else:
1038 self.log.error('unsupported-action-set-field-type',
1039 field_type=_field.type)
1040 else:
1041 self.log.error('unsupported-action-type',
1042 action_type=action.type, in_port=_in_port)
1043
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001044 if self._set_vlan is not None:
1045 if uni_id not in self._set_vlan:
1046 self._set_vlan[uni_id] = dict()
1047 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1048 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
1049
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001050 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1051 # supported match and action criteria cannot be handled by omci and must be ignored.
1052 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1053 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1054 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1055 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001056 _set_vlan_vid=_vlan_vid,
1057 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1058 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001059 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1060 _set_vlan_vid=_vlan_vid,
1061 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1062 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001063 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001064 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1065 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001066 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1067 _set_vlan_vid=_set_vlan_vid,
1068 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1069 tp_id=tp_id)
1070
1071 except Exception as e:
1072 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1073
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001074 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
1075 # flow decomposition that ultimately comes from onos
1076 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001077 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001078
1079 #
1080 # We need to proxy through the OLT to get to the ONU
1081 # Configuration from here should be using OMCI
1082 #
1083 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
1084
1085 # no point in pushing omci flows if the device isnt reachable
1086 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +05301087 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001088 self.log.warn("device-disabled-or-offline-skipping-flow-update",
1089 admin=device.admin_state, connect=device.connect_status)
1090 return
1091
1092 def is_downstream(port):
1093 return port == self._pon_port_number
1094
1095 def is_upstream(port):
1096 return not is_downstream(port)
1097
1098 for flow in flows:
1099 _type = None
1100 _port = None
1101 _vlan_vid = None
1102 _udp_dst = None
1103 _udp_src = None
1104 _ipv4_dst = None
1105 _ipv4_src = None
1106 _metadata = None
1107 _output = None
1108 _push_tpid = None
1109 _field = None
1110 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001111 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001112 _tunnel_id = None
1113
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001114 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +05301115 write_metadata = fd.get_write_metadata(flow)
1116 if write_metadata is None:
1117 self.log.error("do-not-process-flow-without-write-metadata")
1118 return
1119
1120 # extract tp id from flow
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001121 tp_id = self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001122 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +05301123
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001124 _in_port = fd.get_in_port(flow)
1125 assert _in_port is not None
1126
1127 _out_port = fd.get_out_port(flow) # may be None
1128
1129 if is_downstream(_in_port):
1130 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
1131 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301132 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001133 elif is_upstream(_in_port):
1134 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
1135 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001136 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001137 else:
1138 raise Exception('port should be 1 or 2 by our convention')
1139
1140 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
1141
1142 for field in fd.get_ofb_fields(flow):
1143 if field.type == fd.ETH_TYPE:
1144 _type = field.eth_type
1145 self.log.debug('field-type-eth-type',
1146 eth_type=_type)
1147
1148 elif field.type == fd.IP_PROTO:
1149 _proto = field.ip_proto
1150 self.log.debug('field-type-ip-proto',
1151 ip_proto=_proto)
1152
1153 elif field.type == fd.IN_PORT:
1154 _port = field.port
1155 self.log.debug('field-type-in-port',
1156 in_port=_port)
1157
1158 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001159 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
1160 _vlan_vid = RESERVED_TRANSPARENT_VLAN
1161 else:
1162 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001163 self.log.debug('field-type-vlan-vid',
1164 vlan=_vlan_vid)
1165
1166 elif field.type == fd.VLAN_PCP:
1167 _vlan_pcp = field.vlan_pcp
1168 self.log.debug('field-type-vlan-pcp',
1169 pcp=_vlan_pcp)
1170
1171 elif field.type == fd.UDP_DST:
1172 _udp_dst = field.udp_dst
1173 self.log.debug('field-type-udp-dst',
1174 udp_dst=_udp_dst)
1175
1176 elif field.type == fd.UDP_SRC:
1177 _udp_src = field.udp_src
1178 self.log.debug('field-type-udp-src',
1179 udp_src=_udp_src)
1180
1181 elif field.type == fd.IPV4_DST:
1182 _ipv4_dst = field.ipv4_dst
1183 self.log.debug('field-type-ipv4-dst',
1184 ipv4_dst=_ipv4_dst)
1185
1186 elif field.type == fd.IPV4_SRC:
1187 _ipv4_src = field.ipv4_src
1188 self.log.debug('field-type-ipv4-src',
1189 ipv4_dst=_ipv4_src)
1190
1191 elif field.type == fd.METADATA:
1192 _metadata = field.table_metadata
1193 self.log.debug('field-type-metadata',
1194 metadata=_metadata)
1195
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001196 elif field.type == fd.TUNNEL_ID:
1197 _tunnel_id = field.tunnel_id
1198 self.log.debug('field-type-tunnel-id',
1199 tunnel_id=_tunnel_id)
1200
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001201
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001202 else:
1203 raise NotImplementedError('field.type={}'.format(
1204 field.type))
1205
1206 for action in fd.get_actions(flow):
1207
1208 if action.type == fd.OUTPUT:
1209 _output = action.output.port
1210 self.log.debug('action-type-output',
1211 output=_output, in_port=_in_port)
1212
1213 elif action.type == fd.POP_VLAN:
1214 self.log.debug('action-type-pop-vlan',
1215 in_port=_in_port)
1216
1217 elif action.type == fd.PUSH_VLAN:
1218 _push_tpid = action.push.ethertype
1219 self.log.debug('action-type-push-vlan',
1220 push_tpid=_push_tpid, in_port=_in_port)
1221 if action.push.ethertype != 0x8100:
1222 self.log.error('unhandled-tpid',
1223 ethertype=action.push.ethertype)
1224
1225 elif action.type == fd.SET_FIELD:
1226 _field = action.set_field.field.ofb_field
1227 assert (action.set_field.field.oxm_class ==
1228 OFPXMC_OPENFLOW_BASIC)
1229 self.log.debug('action-type-set-field',
1230 field=_field, in_port=_in_port)
1231 if _field.type == fd.VLAN_VID:
1232 _set_vlan_vid = _field.vlan_vid & 0xfff
1233 self.log.debug('set-field-type-vlan-vid',
1234 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001235 elif _field.type == fd.VLAN_PCP:
1236 _set_vlan_pcp = _field.vlan_pcp
1237 self.log.debug('set-field-type-vlan-pcp',
1238 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001239 else:
1240 self.log.error('unsupported-action-set-field-type',
1241 field_type=_field.type)
1242 else:
1243 self.log.error('unsupported-action-type',
1244 action_type=action.type, in_port=_in_port)
1245
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001246 if self._set_vlan is not None:
1247 if uni_id not in self._set_vlan:
1248 self._set_vlan[uni_id] = dict()
1249 self._set_vlan[uni_id][tp_id] = _set_vlan_vid
1250 self.log.debug("set_vlan_id-for-tp", _set_vlan_vid=_set_vlan_vid, tp_id=tp_id)
Matt Jeanneret810148b2019-09-29 12:44:01 -04001251 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1252 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001253 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1254 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1255 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1256 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001257 _set_vlan_vid=_vlan_vid,
1258 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1259 tp_id=tp_id)
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001260 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1261 _set_vlan_vid=_vlan_vid,
1262 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1263 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001264 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001265 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1266 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1267 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1268 _set_vlan_vid=_set_vlan_vid,
1269 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1270 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001271 except Exception as e:
1272 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1273
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001274 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001275 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Girish Gowdradc98d812020-03-20 13:04:58 -07001276 if uni_id in self._pending_delete_tp and tp_id in self._pending_delete_tp[uni_id] and \
1277 self._pending_delete_tp[uni_id][tp_id] is True:
1278 self.log.debug("pending-del-tp--scheduling-add-vlan-filter-task-for-later")
1279 reactor.callLater(0.2, self._add_vlan_filter_task, device, uni_id, uni_port, match_vlan,
1280 _set_vlan_vid, _set_vlan_pcp, tp_id)
1281 return
1282
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001283 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1284 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001285 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001286 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and \
1287 self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001288 @inlineCallbacks
1289 def success(_results):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001290 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id,
1291 set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001292 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001293
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001294 @inlineCallbacks
1295 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301296 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001297 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1298 reactor.callLater(retry,
1299 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1300 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1301 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001302 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001303
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001304 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan,
1305 vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001306 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001307 match_vlan, _set_vlan_pcp, add_tag=True,
1308 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001309 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001310 self._deferred.addCallbacks(success, failure)
1311 else:
1312 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001313 uni_id=uni_id, tp_id=tp_id)
1314 if uni_id not in self._queued_vlan_filter_task:
1315 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001316 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1317 self._queued_vlan_filter_task[uni_id][tp_id] = []
1318 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001319 "uni_id": uni_id,
1320 "uni_port": uni_port,
1321 "match_vlan": match_vlan,
1322 "set_vlan_vid": _set_vlan_vid,
1323 "set_vlan_pcp": _set_vlan_pcp,
1324 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001325
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001326 def get_tp_id_in_flow(self, flow):
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001327 flow_metadata = fd.get_metadata_from_write_metadata(flow)
1328 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001329 return tp_id
1330
1331 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001332 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001333 assert uni_port is not None
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001334
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001335 @inlineCallbacks
1336 def success(_results):
1337 self.log.info('vlan-untagging-success', _results=_results)
1338 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1339
1340 @inlineCallbacks
1341 def failure(_reason):
1342 self.log.warn('vlan-untagging-failure', _reason=_reason)
1343 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001344 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001345 reactor.callLater(retry,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001346 self._remove_vlan_filter_task, device, uni_id,
1347 add_tag=False, uni_port=uni_port)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001348
1349 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1350 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001351 match_vlan, _set_vlan_pcp, add_tag=False,
1352 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001353 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1354 self._deferred.addCallbacks(success, failure)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001355
Matt Jeanneret5e331892019-12-07 21:31:45 -05001356 @inlineCallbacks
Matt Jeannereta32441c2019-03-07 05:16:37 -05001357 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001358 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1359 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeanneret2101f3d2020-03-12 10:13:06 -04001360
1361 if not self.enabled:
1362 self.log.warn('device-not-activated')
1363 reactor.callLater(0.5, self.process_inter_adapter_message, request)
1364 return
1365
Matt Jeannereta32441c2019-03-07 05:16:37 -05001366 try:
Matt Jeanneret5e331892019-12-07 21:31:45 -05001367
1368 update_onu_state = False
1369
Matt Jeannereta32441c2019-03-07 05:16:37 -05001370 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1371 omci_msg = InterAdapterOmciMessage()
1372 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001373 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001374
Matt Jeannereta32441c2019-03-07 05:16:37 -05001375 self.receive_message(omci_msg.message)
1376
1377 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1378 onu_indication = OnuIndication()
1379 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001380 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1381 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1382 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001383
Matt Jeanneret5e331892019-12-07 21:31:45 -05001384 update_onu_state = True
1385 self._onu_persisted_state['onu_id'] = onu_indication.onu_id
1386 self._onu_persisted_state['intf_id'] = onu_indication.intf_id
1387 self._onu_persisted_state['admin_state'] = onu_indication.admin_state
1388 self._onu_persisted_state['oper_state'] = onu_indication.oper_state
1389
Matt Jeannereta32441c2019-03-07 05:16:37 -05001390 if onu_indication.oper_state == "up":
Matt Jeanneret5e331892019-12-07 21:31:45 -05001391 yield self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301392 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeanneret5e331892019-12-07 21:31:45 -05001393 yield self.update_interface(onu_indication)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001394 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001395 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1396 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001397
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001398 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1399 tech_msg = InterAdapterTechProfileDownloadMessage()
1400 request.body.Unpack(tech_msg)
1401 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1402
Matt Jeanneret5e331892019-12-07 21:31:45 -05001403 update_onu_state = self._update_onu_persisted_state(tech_msg.uni_id, tp_path=tech_msg.path)
1404 yield self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001405
Girish Gowdrae933cd32019-11-21 21:04:41 +05301406 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1407 del_gem_msg = InterAdapterDeleteGemPortMessage()
1408 request.body.Unpack(del_gem_msg)
1409 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1410
1411 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1412 gem_port_id=del_gem_msg.gem_port_id,
1413 tp_path=del_gem_msg.tp_path)
1414
1415 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1416 del_tcont_msg = InterAdapterDeleteTcontMessage()
1417 request.body.Unpack(del_tcont_msg)
1418 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1419
Matt Jeanneret5e331892019-12-07 21:31:45 -05001420 # Removal of the tcont/alloc id mapping represents the removal of the tech profile
1421 update_onu_state = self._update_onu_persisted_state(del_tcont_msg.uni_id, tp_path=None)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301422 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1423 alloc_id=del_tcont_msg.alloc_id,
1424 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001425 else:
1426 self.log.error("inter-adapter-unhandled-type", request=request)
1427
Matt Jeanneret5e331892019-12-07 21:31:45 -05001428 if update_onu_state:
1429 try:
1430 self.log.debug('updating-onu-state', device_id=self.device_id,
1431 onu_persisted_state=self._onu_persisted_state)
1432 yield self.onu_kv_client.set(self.device_id, json.dumps(self._onu_persisted_state))
1433 except Exception as e:
1434 self.log.error('could-not-store-onu-state', device_id=self.device_id,
1435 onu_persisted_state=self._onu_persisted_state, e=e)
1436 # at this point omci is started and/or indications being processed
1437 # later indications may have a chance to write this state out again
1438
Matt Jeannereta32441c2019-03-07 05:16:37 -05001439 except Exception as e:
1440 self.log.exception("error-processing-inter-adapter-message", e=e)
1441
Matt Jeanneret5e331892019-12-07 21:31:45 -05001442 def _update_onu_persisted_state(self, uni_id, tp_path):
1443 # persist the uni and tech profile path for later reconciliation. update only if changed
1444 update_onu_state = False
1445 found = False
1446 for entry in self._onu_persisted_state.get('uni_config', list()):
1447 if entry.get('uni_id') == uni_id:
1448 found = True
1449 if entry.get('tp_path') != tp_path:
1450 update_onu_state = True
1451 entry['tp_path'] = tp_path
1452
1453 if not found:
1454 update_onu_state = True
1455 uni_tp = {
1456 'uni_id': uni_id,
1457 'tp_path': tp_path
1458 }
1459 self._onu_persisted_state['uni_config'].append(uni_tp)
1460
1461 return update_onu_state
1462
Matt Jeannereta32441c2019-03-07 05:16:37 -05001463 # Called each time there is an onu "up" indication from the olt handler
1464 @inlineCallbacks
1465 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001466 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001467 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001468
1469 # Ignore if onu_indication is received for an already running ONU
1470 if self._onu_omci_device is not None and self._onu_omci_device.active:
1471 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1472 return
1473
Matt Jeannereta32441c2019-03-07 05:16:37 -05001474
Matt Jeanneretc083f462019-03-11 15:02:01 -04001475 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1476 connect_status=ConnectStatus.REACHABLE)
1477
Matt Jeannereta32441c2019-03-07 05:16:37 -05001478 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001479
1480 self.log.debug('starting-openomci-statemachine')
1481 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001482 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301483 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001484 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001485 self._heartbeat.enabled = True
1486
Matt Jeanneret42dad792020-02-01 09:28:27 -05001487 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001488 @inlineCallbacks
1489 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001490 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001491 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001492
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001493 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001494 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001495 reactor.callLater(0, self._onu_omci_device.stop)
1496
Mahir Gunyel5de33fe2020-03-03 22:38:44 -08001497 self._tp = dict()
1498
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001499 # Let TP download happen again
1500 for uni_id in self._tp_service_specific_task:
1501 self._tp_service_specific_task[uni_id].clear()
1502 for uni_id in self._tech_profile_download_done:
1503 self._tech_profile_download_done[uni_id].clear()
1504
Matt Jeanneretf4113222019-08-14 19:44:34 -04001505 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001506 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1507 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1508 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001509 else:
1510 self.log.debug('not-changing-openomci-statemachine')
1511
Matt Jeanneretf4113222019-08-14 19:44:34 -04001512 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001513 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001514 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001515 try:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001516 yield self.disable_ports(lock_ports=True, device_disabled=True)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001517 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1518 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001519 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001520 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001521
William Kurkian3a206332019-04-29 11:05:47 -04001522 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001523 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001524 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001525 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001526 yield self.core_proxy.device_state_update(device.id,
1527 oper_status=OperStatus.ACTIVE,
1528 connect_status=ConnectStatus.REACHABLE)
1529 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1530 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001531 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001532 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001533
William Kurkian3a206332019-04-29 11:05:47 -04001534 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001535 def reboot(self):
1536 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001537 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001538 if device.connect_status != ConnectStatus.REACHABLE:
1539 self.log.error("device-unreachable")
1540 return
1541
William Kurkian3a206332019-04-29 11:05:47 -04001542 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001543 def success(_results):
1544 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001545 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001546
1547 def failure(_reason):
1548 self.log.info('reboot-failure', _reason=_reason)
1549
1550 self._deferred = self._onu_omci_device.reboot()
1551 self._deferred.addCallbacks(success, failure)
1552
William Kurkian3a206332019-04-29 11:05:47 -04001553 @inlineCallbacks
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001554 def disable_ports(self, lock_ports=True, device_disabled=False):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001555 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001556
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001557 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1558 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001559 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001560 if port.mac_bridge_port_num == 1:
1561 port.operstatus = OperStatus.UNKNOWN
1562 self.log.info('disable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001563 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1564 port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001565
1566 if lock_ports is True:
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001567 self.lock_ports(lock=True, device_disabled=device_disabled)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001568
William Kurkian3a206332019-04-29 11:05:47 -04001569 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001570 def enable_ports(self):
1571 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001572
Matt Jeanneretf4113222019-08-14 19:44:34 -04001573 self.lock_ports(lock=False)
1574
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001575 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1576 # load on the core
1577 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001578 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001579 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001580 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001581 self.log.info('enable-port', device_id=self.device_id, port=port)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001582 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number,
1583 port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001584
1585 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1586 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1587 #
1588 # Basically the link state sequence:
1589 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1590 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1591 # 3) a link state up alarm is received for the uni plugged in.
1592 #
1593 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1594 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1595 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1596 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001597 @inlineCallbacks
1598 def port_state_handler(self, _topic, msg):
1599 self.log.info("port-state-change", _topic=_topic, msg=msg)
1600
1601 onu_id = msg['onu_id']
1602 port_no = msg['port_number']
1603 serial_number = msg['serial_number']
1604 port_status = msg['port_status']
1605 uni_port = self.uni_port(int(port_no))
1606
1607 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1608 port_status=port_status)
1609
1610 if port_status is True:
1611 uni_port.operstatus = OperStatus.ACTIVE
1612 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1613 else:
1614 uni_port.operstatus = OperStatus.UNKNOWN
1615 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1616
1617 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, uni_port.port_number, uni_port.operstatus)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001618 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001619
1620 # Called just before openomci state machine is started. These listen for events from selected state machines,
1621 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1622 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001623 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001624
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001625 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001626
1627 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001628 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1629 OnuDeviceEvents.MibDatabaseSyncEvent)
1630 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1631
1632 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001633 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1634 OnuDeviceEvents.OmciCapabilitiesEvent)
1635 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1636
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001637 # TODO: these alarms seem to be unreliable depending on the environment
1638 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001639 # topic = OnuDeviceEntry.event_bus_topic(self.device_id,
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001640 # OnuDeviceEvents.PortEvent)
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001641 # self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001642
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001643 # Called when the mib is in sync
1644 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001645 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001646 if self._in_sync_subscription is not None:
1647 try:
1648 in_sync = msg[IN_SYNC_KEY]
1649
1650 if in_sync:
1651 # Only call this once
1652 bus = self._onu_omci_device.event_bus
1653 bus.unsubscribe(self._in_sync_subscription)
1654 self._in_sync_subscription = None
1655
1656 # Start up device_info load
1657 self.log.debug('running-mib-sync')
1658 reactor.callLater(0, self._mib_in_sync)
1659
1660 except Exception as e:
1661 self.log.exception('in-sync', e=e)
1662
1663 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001664 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001665 if self._capabilities_subscription is not None:
1666 self.log.debug('capabilities-handler-done')
1667
1668 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
Matt Jeanneretc083f462019-03-11 15:02:01 -04001669 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001670 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001671 self.log.debug('mib-in-sync')
Matt Jeanneretc083f462019-03-11 15:02:01 -04001672 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001673
Matt Jeanneret5e331892019-12-07 21:31:45 -05001674 # only notify core if this is a new device. otherwise do not have reconcile generating
1675 # a lot of needless message churn
1676 if not self._reconciling:
1677 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001678
1679 if self._dev_info_loaded:
Matt Jeanneret5e331892019-12-07 21:31:45 -05001680 self.log.debug('device-info-already-loaded')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001681 else:
Matt Jeanneret5e331892019-12-07 21:31:45 -05001682 # new onu or adapter was restarted. fill up our local data
1683 yield self._load_device_data(device)
1684
1685 if self._check_mib_downloaded():
1686 self.log.debug('mib-already-downloaded')
1687 if not self._reconciling:
1688 yield self.core_proxy.device_state_update(device.id,
1689 oper_status=OperStatus.ACTIVE,
1690 connect_status=ConnectStatus.REACHABLE)
1691 yield self.enable_ports()
1692 else:
1693 self._download_mib(device)
1694
1695 if self._reconciling:
1696 yield self._restore_tech_profile()
1697 self._start_monitoring()
1698 self._reconciling = False
1699 self.log.debug('reconcile-finished')
1700
1701 def _download_mib(self, device):
1702 self.log.debug('downloading-initial-mib-configuration')
1703
1704 @inlineCallbacks
1705 def success(_results):
1706 self.log.debug('mib-download-success', _results=_results)
1707 yield self.core_proxy.device_state_update(device.id,
1708 oper_status=OperStatus.ACTIVE,
1709 connect_status=ConnectStatus.REACHABLE)
1710 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
1711 self._mib_download_task = None
1712 yield self.enable_ports()
1713 yield self.onu_active_event()
1714 self._start_monitoring()
1715
1716 @inlineCallbacks
1717 def failure(_reason):
1718 self.log.warn('mib-download-failure-retrying', _reason=_reason)
1719 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1720 reactor.callLater(retry, self._mib_in_sync)
1721 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
1722
1723 # start by locking all the unis till mib sync and initial mib is downloaded
1724 # this way we can capture the port down/up events when we are ready
1725 self.lock_ports(lock=True)
1726
1727 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1728 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1729 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1730 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1731 self._deferred.addCallbacks(success, failure)
1732
1733 def _start_monitoring(self):
1734 self.log.debug('starting-monitoring')
1735
1736 # Start collecting stats from the device after a brief pause
1737 if not self._pm_metrics_started:
1738 self._pm_metrics_started = True
1739 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1740 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1741
1742 # Start test requests after a brief pause
1743 if not self._test_request_started:
1744 self._test_request_started = True
1745 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1746 reactor.callLater(tststart, self._test_request.start_collector)
1747
1748 def _check_mib_downloaded(self):
1749 self.log.debug('checking-mib-downloaded')
1750 results = False
1751
1752 mac_bridges = self.onu_omci_device.query_mib(MacBridgeServiceProfile.class_id)
1753 self.log.debug('mac-bridges', mac_bridges=mac_bridges)
1754
1755 for k, v in mac_bridges.items():
1756 if not isinstance(v, dict):
1757 continue
1758 # found at least one mac bridge, good enough to say its done, break out
1759 self.log.debug('found-mac-bridge-mib-download-has-been-done', omci_key=k, omci_value=v)
1760 results = True
1761 break
1762
1763 return results
1764
1765 @inlineCallbacks
1766 def _load_device_data(self, device):
1767 self.log.debug('loading-device-data-from-mib', device_id=device.id)
1768
1769 omci_dev = self._onu_omci_device
1770 config = omci_dev.configuration
1771
1772 try:
1773 # sort the lists so we get consistent port ordering.
1774 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1775 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1776 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1777 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1778
1779 if ani_list is None or (pptp_list is None and veip_list is None):
1780 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
1781 raise Exception("onu-missing-required-elements")
1782
1783 # Currently logging the ani, pptp, veip, and uni for information purposes.
1784 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1785 # And in some ONU the UNI-G list is incomplete or incorrect...
1786 for entity_id in ani_list:
1787 ani_value = config.ani_g_entities[entity_id]
1788 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1789
1790 for entity_id in uni_list:
1791 uni_value = config.uni_g_entities[entity_id]
1792 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1793
1794 uni_entities = OrderedDict()
1795 for entity_id in pptp_list:
1796 pptp_value = config.pptp_entities[entity_id]
1797 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1798 uni_entities[entity_id] = UniType.PPTP
1799
1800 for entity_id in veip_list:
1801 veip_value = config.veip_entities[entity_id]
1802 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1803 uni_entities[entity_id] = UniType.VEIP
1804
1805 uni_id = 0
1806 for entity_id, uni_type in uni_entities.items():
1807 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
1808 uni_id += 1
1809
1810 if self._unis:
1811 self._dev_info_loaded = True
1812 else:
1813 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
1814 raise Exception("no-usable-unis")
1815
1816 except Exception as e:
1817 self.log.exception('device-info-load', e=e)
1818 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001819
Matt Jeanneretc083f462019-03-11 15:02:01 -04001820 @inlineCallbacks
1821 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matt Jeanneret5e331892019-12-07 21:31:45 -05001822 self.log.debug('add-uni-port', entity_id=entity_id, uni_id=uni_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001823
Matt Jeanneret5e331892019-12-07 21:31:45 -05001824 intf_id = self._onu_persisted_state.get('intf_id')
1825 onu_id = self._onu_persisted_state.get('onu_id')
1826 uni_no = self.mk_uni_port_num(intf_id, onu_id, uni_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001827
1828 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1829 uni_name = "uni-{}".format(uni_no)
1830
Girish Gowdrae933cd32019-11-21 21:04:41 +05301831 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001832
1833 self.log.debug('uni-port-inputs', uni_no=uni_no, uni_id=uni_id, uni_name=uni_name, uni_type=uni_type,
Yongjie Zhang286099c2019-08-06 13:39:07 -04001834 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001835
1836 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1837 uni_port.entity_id = entity_id
1838 uni_port.enabled = True
1839 uni_port.mac_bridge_port_num = mac_bridge_port_num
1840
1841 self.log.debug("created-uni-port", uni=uni_port)
1842
Matt Jeanneret5e331892019-12-07 21:31:45 -05001843 if not self._reconciling:
1844 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001845
1846 self._unis[uni_port.port_number] = uni_port
1847
Matt Jeanneret5e331892019-12-07 21:31:45 -05001848 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301849 uni_ports=self.uni_ports,
1850 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001851
Matt Jeanneret5e331892019-12-07 21:31:45 -05001852 @inlineCallbacks
1853 def _restore_tech_profile(self):
1854 self.log.debug("reconcile-restoring-tech-profile-tcont-gem-config")
1855
1856 # for every uni that has tech profile config reload all its tcont/alloc_id and gem from the tp path
1857 for entry in self._onu_persisted_state.get('uni_config', list()):
1858 uni_id = entry.get('uni_id')
1859 tp_path = entry.get('tp_path')
1860 if tp_path:
1861 tpstored = yield self.tp_kv_client.get(tp_path)
1862 tpstring = tpstored.decode('ascii')
1863 tp = json.loads(tpstring)
1864
1865 self.log.debug("restoring-tp-instance", tp=tp)
1866
1867 # re-run tech profile config that stores gem and tconts in the self._pon object
1868 # this does not actually re-run the omci, just rebuilds our local data store
1869 self._do_tech_profile_configuration(uni_id, tp)
1870
1871 tp_id = self.extract_tp_id_from_path(tp_path)
1872
1873 # rebuild cache dicts so tp updates and deletes dont get KeyErrors
1874 if uni_id not in self._tp_service_specific_task:
1875 self._tp_service_specific_task[uni_id] = dict()
1876
1877 if uni_id not in self._tech_profile_download_done:
1878 self._tech_profile_download_done[uni_id] = dict()
1879
1880 if tp_id not in self._tech_profile_download_done[uni_id]:
1881 self._tech_profile_download_done[uni_id][tp_id] = True
1882 else:
1883 self.log.debug("no-assigned-tp-instance", uni_id=uni_id)
1884
1885 # for every loaded tcont from tp check the mib database for its entity_id
1886 # needed for later tp deletes/adds
1887 tcont_idents = self.onu_omci_device.query_mib(Tcont.class_id)
1888 self.log.debug('tcont-idents', tcont_idents=tcont_idents)
1889
1890 for k, v in tcont_idents.items():
1891 if not isinstance(v, dict):
1892 continue
1893 alloc_check = v.get('attributes', {}).get('alloc_id', 0)
1894 tcont = self._pon.tconts.get(alloc_check)
1895 if tcont:
1896 tcont.entity_id = k
1897 self.log.debug('reassigning-tcont-entity-id', entity_id=tcont.entity_id,
1898 alloc_id=tcont.alloc_id)
1899
Matt Jeanneretc083f462019-03-11 15:02:01 -04001900 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1901 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001902 MAX_PONS_PER_OLT = 256
1903 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001904 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001905
Matt Jeanneretc083f462019-03-11 15:02:01 -04001906 assert intf_id < MAX_PONS_PER_OLT
1907 assert onu_id < MAX_ONUS_PER_PON
1908 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001909 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001910
1911 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001912 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001913 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001914 try:
Matt Jeanneret5e331892019-12-07 21:31:45 -05001915 # TODO: this is expensive for just getting the olt serial number. replace with direct api call
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001916 parent_device = yield self.core_proxy.get_device(self.parent_id)
1917 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001918 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001919
Matt Jeanneret5e331892019-12-07 21:31:45 -05001920 intf_id = self._onu_persisted_state.get('intf_id')
1921 onu_id = self._onu_persisted_state.get('onu_id')
1922 onu_serial = self._onu_persisted_state.get('serial_number')
1923
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001924 self.log.debug("onu-indication-context-data",
Matt Jeanneret5e331892019-12-07 21:31:45 -05001925 pon_id=intf_id,
1926 onu_id=onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301927 registration_id=self.device_id,
1928 device_id=self.device_id,
Matt Jeanneret5e331892019-12-07 21:31:45 -05001929 onu_serial_number=onu_serial,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301930 olt_serial_number=olt_serial_number,
1931 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001932
Devmalya Paulffc89df2019-07-31 17:43:13 -04001933 self.log.debug("Trying-to-raise-onu-active-event")
1934 OnuActiveEvent(self.events, self.device_id,
Matt Jeanneret5e331892019-12-07 21:31:45 -05001935 intf_id,
1936 onu_serial,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001937 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301938 olt_serial_number, raised_ts,
Matt Jeanneret5e331892019-12-07 21:31:45 -05001939 onu_id=onu_id).send(True)
Devmalya Paulffc89df2019-07-31 17:43:13 -04001940 except Exception as active_event_error:
1941 self.log.exception('onu-activated-event-error',
1942 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001943
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001944 @inlineCallbacks
1945 def onu_disabled_event(self):
1946 self.log.debug('onu-disabled-event')
1947 try:
1948 device = yield self.core_proxy.get_device(self.device_id)
1949 parent_device = yield self.core_proxy.get_device(self.parent_id)
1950 olt_serial_number = parent_device.serial_number
1951 raised_ts = arrow.utcnow().timestamp
1952
1953 self.log.debug("onu-indication-context-data",
1954 pon_id=self._onu_indication.intf_id,
1955 onu_id=self._onu_indication.onu_id,
1956 registration_id=self.device_id,
1957 device_id=self.device_id,
1958 onu_serial_number=device.serial_number,
1959 olt_serial_number=olt_serial_number,
1960 raised_ts=raised_ts)
1961
1962 self.log.debug("Trying-to-raise-onu-disabled-event")
1963 OnuDisabledEvent(self.events, self.device_id,
Girish Gowdradc98d812020-03-20 13:04:58 -07001964 self._onu_indication.intf_id,
1965 device.serial_number,
1966 str(self.device_id),
1967 olt_serial_number, raised_ts,
1968 onu_id=self._onu_indication.onu_id).send(True)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001969 except Exception as active_event_error:
1970 self.log.exception('onu-disabled-event-error',
1971 errmsg=active_event_error.message)
1972
1973 def lock_ports(self, lock=True, device_disabled=False):
Matt Jeanneretf4113222019-08-14 19:44:34 -04001974
1975 def success(response):
1976 self.log.debug('set-onu-ports-state', lock=lock, response=response)
Devmalya Paule2e5f2b2020-03-08 18:50:33 -04001977 if device_disabled:
1978 self.onu_disabled_event()
Matt Jeanneretf4113222019-08-14 19:44:34 -04001979
1980 def failure(response):
1981 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1982
1983 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1984 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1985 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001986
1987 def extract_tp_id_from_path(self, tp_path):
1988 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
Girish Gowdra4c11ddb2020-03-03 11:33:24 -08001989 tp_id = int(tp_path.split(_PATH_SEPERATOR)[1])
1990 return tp_id
onkarkundargia1e2af22020-01-27 11:51:43 +05301991
1992 def start_omci_test_action(self, device, uuid):
1993 """
1994
1995 :param device:
1996 :return:
1997 """
1998 # Code to Run OMCI Test Action
1999 self.log.info('Omci-test-action-request-On', request=device.id)
2000 kwargs_omci_test_action = {
2001 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
2002 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
2003 }
2004 serial_number = device.serial_number
2005 if device.connect_status != ConnectStatus.REACHABLE or device.admin_state != AdminState.ENABLED:
2006 return (TestResponse(result=TestResponse.FAILURE))
2007 test_request = OmciTestRequest(self.core_proxy,
2008 self.omci_agent, self.device_id, AniG,
2009 serial_number,
2010 self.logical_device_id, exclusive=False,
2011 uuid=uuid,
2012 **kwargs_omci_test_action)
2013 test_request.perform_test_omci()
2014 return (TestResponse(result=TestResponse.SUCCESS))