blob: 570a5c7ce3ea70cf6c4e5432b435aea204202584 [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
31from twisted.internet.defer import DeferredQueue, inlineCallbacks
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
35from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_metrics import OnuPmMetrics
36from pyvoltha.adapters.extensions.events.kpi.onu.onu_omci_pm import OnuOmciPmMetrics
37from pyvoltha.adapters.extensions.events.adapter_events import AdapterEvents
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050038
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050039import pyvoltha.common.openflow.utils as fd
40from pyvoltha.common.utils.registry import registry
Matteo Scandolod8d73172019-11-26 12:15:15 -070041from pyvoltha.adapters.common.frameio.frameio import hexify
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050042from pyvoltha.common.utils.nethelpers import mac_str_to_tuple
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050043from pyvoltha.common.config.config_backend import ConsulStore
44from pyvoltha.common.config.config_backend import EtcdStore
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
48from voltha_protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, ofp_port, OFPPS_LIVE,OFPPS_LINK_DOWN,\
49 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_configuration import OMCCVersion
55from pyvoltha.adapters.extensions.omci.onu_device_entry import OnuDeviceEvents, \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050056 OnuDeviceEntry, IN_SYNC_KEY
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050057from omci.brcm_mib_download_task import BrcmMibDownloadTask
Girish Gowdrae933cd32019-11-21 21:04:41 +053058from omci.brcm_tp_setup_task import BrcmTpSetupTask
59from omci.brcm_tp_delete_task import BrcmTpDeleteTask
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050060from omci.brcm_uni_lock_task import BrcmUniLockTask
61from omci.brcm_vlan_filter_task import BrcmVlanFilterTask
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050062from onu_gem_port import OnuGemPort
63from onu_tcont import OnuTCont
64from pon_port import PonPort
65from 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
69from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050070from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050071
72OP = EntityOperations
73RC = ReasonCodes
74
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050075_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080076_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050077
78
79class BrcmOpenomciOnuHandler(object):
80
81 def __init__(self, adapter, device_id):
82 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050083 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050084 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050085 self.core_proxy = adapter.core_proxy
86 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 self.parent_id = None
88 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050089 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050090 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040091 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050092 self._pm_metrics = None
93 self._pm_metrics_started = False
94 self._test_request = None
95 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050096 self._omcc_version = OMCCVersion.Unknown
97 self._total_tcont_count = 0 # From ANI-G ME
98 self._qos_flexibility = 0 # From ONT2_G ME
99
100 self._onu_indication = None
101 self._unis = dict() # Port # -> UniPort
102
103 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500104 self._pon_port_number = 100
105 self.logical_device_id = None
106
107 self._heartbeat = HeartBeat.create(self, device_id)
108
109 # Set up OpenOMCI environment
110 self._onu_omci_device = None
111 self._dev_info_loaded = False
112 self._deferred = None
113
114 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400115 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500116 self._connectivity_subscription = None
117 self._capabilities_subscription = None
118
119 self.mac_bridge_service_profile_entity_id = 0x201
120 self.gal_enet_profile_entity_id = 0x1
121
122 self._tp_service_specific_task = dict()
123 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400124 # Stores information related to queued vlan filter tasks
125 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
126
127 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500128
129 # Initialize KV store client
130 self.args = registry('main').get_args()
131 if self.args.backend == 'etcd':
132 host, port = self.args.etcd.split(':', 1)
133 self.kv_client = EtcdStore(host, port,
134 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
135 elif self.args.backend == 'consul':
136 host, port = self.args.consul.split(':', 1)
137 self.kv_client = ConsulStore(host, port,
138 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
139 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500140 self.log.error('invalid-backend')
141 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500142
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500143 @property
144 def enabled(self):
145 return self._enabled
146
147 @enabled.setter
148 def enabled(self, value):
149 if self._enabled != value:
150 self._enabled = value
151
152 @property
153 def omci_agent(self):
154 return self.adapter.omci_agent
155
156 @property
157 def omci_cc(self):
158 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
159
160 @property
161 def heartbeat(self):
162 return self._heartbeat
163
164 @property
165 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500166 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500167
168 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500169 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500170 return next((uni for uni in self.uni_ports
171 if uni.name == port_no_or_name), None)
172
173 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
174 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530175 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500176
177 @property
178 def pon_port(self):
179 return self._pon
180
Girish Gowdraa73ee452019-12-20 18:52:17 +0530181 @property
182 def onu_omci_device(self):
183 return self._onu_omci_device
184
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500185 def receive_message(self, msg):
186 if self.omci_cc is not None:
187 self.omci_cc.receive_message(msg)
188
Matt Jeanneretc083f462019-03-11 15:02:01 -0400189 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500190 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400191 cap = OFPPF_1GB_FD | OFPPF_FIBER
192
Girish Gowdrae933cd32019-11-21 21:04:41 +0530193 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
194 ((device.parent_port_no >> 8 & 0xff),
195 device.parent_port_no & 0xff,
196 (port_no >> 16) & 0xff,
197 (port_no >> 8) & 0xff,
198 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400199
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400200 uni_port = self.uni_port(int(port_no))
201 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500202 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400203
204 ofstate = OFPPS_LINK_DOWN
205 if uni_port.operstatus is OperStatus.ACTIVE:
206 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400207
Matt Jeanneretc083f462019-03-11 15:02:01 -0400208 return PortCapability(
209 port=LogicalPort(
210 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400211 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400212 hw_addr=hw_addr,
213 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400214 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400215 curr=cap,
216 advertised=cap,
217 peer=cap,
218 curr_speed=OFPPF_1GB_FD,
219 max_speed=OFPPF_1GB_FD
220 ),
221 device_id=device.id,
222 device_port_no=port_no
223 )
224 )
225
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500226 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500227 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500228 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700229 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500230
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500231 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500232 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500233 assert device.proxy_address.device_id
234
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500236 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500237 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500238 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700239 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500240 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500241 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500242 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500243 device.reason = 'activating-onu'
244
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500245 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400246 # pm_metrics requires a logical device id. For now set to just device_id
247 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500248
Matt Jeannereta32441c2019-03-07 05:16:37 -0500249 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500250 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500251
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700252 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500253
Matteo Scandolod8d73172019-11-26 12:15:15 -0700254 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500255 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400256 # Setup Alarm handler
257 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
258 device.serial_number)
259 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500260 # Setup PM configuration for this device
261 # Pass in ONU specific options
262 kwargs = {
263 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
264 'heartbeat': self.heartbeat,
265 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
266 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500267 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500268 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400269 self.logical_device_id, device.serial_number,
270 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500271 pm_config = self._pm_metrics.make_proto()
272 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530273 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500274 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500275
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500276 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400277 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500278 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500279
onkarkundargiaae99712019-09-23 15:02:52 +0530280 # Code to Run OMCI Test Action
281 kwargs_omci_test_action = {
282 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
283 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
284 }
285 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500286 self._test_request = OmciTestRequest(self.core_proxy,
onkarkundargiaae99712019-09-23 15:02:52 +0530287 self.omci_agent, self.device_id,
288 AniG, serial_number,
289 self.logical_device_id,
290 exclusive=False,
291 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500292
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500293 self.enabled = True
294 else:
295 self.log.info('onu-already-activated')
296
297 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400298 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500299 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700300 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500301
302 # first we verify that we got parent reference and proxy info
303 assert device.parent_id
304 assert device.proxy_address.device_id
305
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700306 self.proxy_address = device.proxy_address
307 self.parent_id = device.parent_id
308 self._pon_port_number = device.parent_port_no
309
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500310 if self.enabled is not True:
311 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700312 self.logical_device_id = self.device_id
313 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500314
315 # need to restart state machines on vcore restart. there is no indication to do it for us.
316 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700317 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500318
319 # TODO: this is probably a bit heavy handed
320 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
321 # This may not be necessary when mib resync actually works
322 reactor.callLater(1, self.reboot)
323
324 self.enabled = True
325 else:
326 self.log.info('onu-already-activated')
327
328 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700329 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500330 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 -0500331
332 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500333 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700334 self.log.debug('adding-pon-port-to-agent',
335 type=self._pon.get_port().type,
336 admin_state=self._pon.get_port().admin_state,
337 oper_status=self._pon.get_port().oper_status,
338 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500339
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700340 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500341
Matteo Scandolod8d73172019-11-26 12:15:15 -0700342 self.log.debug('added-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 Jeanneretf1e9c5d2019-02-08 07:41:29 -0500347
348 # Create and start the OpenOMCI ONU Device Entry for this ONU
349 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500350 self.core_proxy,
351 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500352 support_classes=self.adapter.broadcom_omci,
353 custom_me_map=self.adapter.custom_me_entities())
354 # Port startup
355 if self._pon is not None:
356 self._pon.enabled = True
357
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500358 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700359 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500360
361 self._deferred.cancel()
362 self._test_request.stop_collector()
363 self._pm_metrics.stop_collector()
364 self.log.debug('removing-openomci-statemachine')
365 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500366
367 def _create_tconts(self, uni_id, us_scheduler):
368 alloc_id = us_scheduler['alloc_id']
369 q_sched_policy = us_scheduler['q_sched_policy']
370 self.log.debug('create-tcont', us_scheduler=us_scheduler)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800371 #TODO: revisit for multi tconts support
372 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500373 tcontdict = dict()
374 tcontdict['alloc-id'] = alloc_id
375 tcontdict['q_sched_policy'] = q_sched_policy
376 tcontdict['uni_id'] = uni_id
377
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500378 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500379
380 self._pon.add_tcont(tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800381 new_tconts.append(tcont)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500382 self.log.debug('pon-add-tcont', tcont=tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800383 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500384
385 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
386 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
387 self.log.debug('create-gemport',
388 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530389 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500390 for gem_port in gem_ports:
391 gemdict = dict()
392 gemdict['gemport_id'] = gem_port['gemport_id']
393 gemdict['direction'] = direction
394 gemdict['alloc_id_ref'] = alloc_id_ref
395 gemdict['encryption'] = gem_port['aes_encryption']
396 gemdict['discard_config'] = dict()
397 gemdict['discard_config']['max_probability'] = \
398 gem_port['discard_config']['max_probability']
399 gemdict['discard_config']['max_threshold'] = \
400 gem_port['discard_config']['max_threshold']
401 gemdict['discard_config']['min_threshold'] = \
402 gem_port['discard_config']['min_threshold']
403 gemdict['discard_policy'] = gem_port['discard_policy']
404 gemdict['max_q_size'] = gem_port['max_q_size']
405 gemdict['pbit_map'] = gem_port['pbit_map']
406 gemdict['priority_q'] = gem_port['priority_q']
407 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
408 gemdict['weight'] = gem_port['weight']
409 gemdict['uni_id'] = uni_id
410
411 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530412 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500413
Mahir Gunyel9c3c0932020-02-28 00:29:38 -0800414 self._pon.add_gem_port(gem_port,True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500415
416 self.log.debug('pon-add-gemport', gem_port=gem_port)
417
Girish Gowdrae933cd32019-11-21 21:04:41 +0530418 return new_gem_ports
419
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800420 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400421 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
422 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
423 # or initial-mib-download is not done. Once the tp_task is completed, we execute
424 # such queued vlan-filter tasks
425 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800426 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 -0400427 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800428 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800429 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
430 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800431 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
432 match_vlan = filter_info.get("match_vlan"),
433 _set_vlan_vid= filter_info.get("set_vlan_vid"),
434 _set_vlan_pcp = filter_info.get("set_vlan_pcp"),
435 tp_id = filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400436 # Now remove the entry from the dictionary
Mahir Gunyela982ec32020-02-25 12:30:37 -0800437 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400438 self.log.debug("executed-queued-vlan-filter-task",
Mahir Gunyela982ec32020-02-25 12:30:37 -0800439 uni_id=uni_id, tp_id=tp_id)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400440 except Exception as e:
441 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
442
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500443 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500444 us_scheduler = tp['us_scheduler']
445 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800446 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500447 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800448 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500449 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800450 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
451
452 new_gems = []
453 new_gems.extend(new_upstream_gems)
454 new_gems.extend(new_downstream_gems)
455
456 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500457
458 def load_and_configure_tech_profile(self, uni_id, tp_path):
459 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800460 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500461 if uni_id not in self._tp_service_specific_task:
462 self._tp_service_specific_task[uni_id] = dict()
463
464 if uni_id not in self._tech_profile_download_done:
465 self._tech_profile_download_done[uni_id] = dict()
466
Mahir Gunyele9110a32020-02-20 14:56:50 -0800467 if tp_id not in self._tech_profile_download_done[uni_id]:
468 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500469
Mahir Gunyele9110a32020-02-20 14:56:50 -0800470 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500471 try:
472 if tp_path in self._tp_service_specific_task[uni_id]:
473 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530474 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500475 return
476
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500477 tpstored = self.kv_client[tp_path]
478 tpstring = tpstored.decode('ascii')
479 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530480
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500481 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800482 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700483
William Kurkian3a206332019-04-29 11:05:47 -0400484 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500485 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800486 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500487 if tp_path in self._tp_service_specific_task[uni_id]:
488 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800489 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400490 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800491 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500492 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530493
William Kurkian3a206332019-04-29 11:05:47 -0400494 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500495 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800496 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530497 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500498 if tp_path in self._tp_service_specific_task[uni_id]:
499 del self._tp_service_specific_task[uni_id][tp_path]
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500500 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
501 reactor.callLater(retry, self.load_and_configure_tech_profile,
502 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500503 yield self.core_proxy.device_reason_update(self.device_id,
504 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500505
Mahir Gunyela982ec32020-02-25 12:30:37 -0800506 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530507 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
508
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500509 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800510 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500511 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530512 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500513 self._deferred.addCallbacks(success, failure)
514
515 except Exception as e:
516 self.log.exception("error-loading-tech-profile", e=e)
517 else:
518 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530519 # Could be a case where TP exists but new gem-ports are getting added dynamically
520 tpstored = self.kv_client[tp_path]
521 tpstring = tpstored.decode('ascii')
522 tp = json.loads(tpstring)
523 upstream_gems = []
524 downstream_gems = []
525 # Find out the new Gem ports that are getting added afresh.
526 for gp in tp['upstream_gem_port_attribute_list']:
527 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
528 # gem port already exists
529 continue
530 upstream_gems.append(gp)
531 for gp in tp['downstream_gem_port_attribute_list']:
532 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
533 # gem port already exists
534 continue
535 downstream_gems.append(gp)
536
537 us_scheduler = tp['us_scheduler']
538 alloc_id = us_scheduler['alloc_id']
539
540 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
541 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
542 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
543 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
544 new_gems = []
545 new_gems.extend(new_upstream_gems)
546 new_gems.extend(new_downstream_gems)
547
548 def success(_results):
549 self.log.info("new-gem-ports-successfully-installed", result=_results)
550
551 def failure(_reason):
552 self.log.warn('new-gem-port-install-failed--retrying',
553 _reason=_reason)
554 # Remove gem ports from cache. We will re-add them during the retry
555 for gp in new_gems:
556 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
557
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500558 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
559 reactor.callLater(retry, self.load_and_configure_tech_profile,
560 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530561
562 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800563 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530564 self._deferred = \
565 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
566 self._deferred.addCallbacks(success, failure)
567
568 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
569 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800570 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530571 if not uni_id in self._tech_profile_download_done:
572 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
573 return
574
Mahir Gunyele9110a32020-02-20 14:56:50 -0800575 if not tp_table_id in self._tech_profile_download_done[uni_id]:
576 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530577 return
578
Mahir Gunyele9110a32020-02-20 14:56:50 -0800579 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
580 self.log.error("tp-download-is-not-done-in-order-to-process-tp-delete", uni_id=uni_id, tp_id=tp_table_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530581 return
582
583 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800584 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 +0530585 return
586
587 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
588 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
589 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
590 # this initializer
591 tcont = None
592 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
593 for tc in list(self.pon_port.tconts.values()):
594 if tc.alloc_id == alloc_id:
595 tcont = tc
596 self.pon_port.remove_tcont(tc.alloc_id, False)
597
598 gem_port = None
599 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
600 for gp in list(self.pon_port.gem_ports.values()):
601 if gp.gem_id == gem_port_id:
602 gem_port = gp
603 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
604
Girish Gowdrae933cd32019-11-21 21:04:41 +0530605 @inlineCallbacks
606 def success(_results):
607 if gem_port_id:
608 self.log.info("gem-port-delete-done-successfully")
609 if alloc_id:
610 self.log.info("tcont-delete-done-successfully")
611 # The deletion of TCONT marks the complete deletion of tech-profile
612 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800613 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530614 del self._tp_service_specific_task[uni_id][tp_path]
615 except Exception as ex:
616 self.log.error("del-tp-state-info", e=ex)
617
618 # TODO: There could be multiple TP on the UNI, and also the ONU.
619 # TODO: But the below reason updates for the whole device.
620 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
621
622 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530623 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530624 self.log.warn('tech-profile-delete-failure-retrying',
625 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500626 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
627 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500628 yield self.core_proxy.device_reason_update(self.device_id,
629 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530630
631 self.log.info('deleting-tech-profile-configuration')
632
Girish Gowdraa73ee452019-12-20 18:52:17 +0530633 if tcont is None and gem_port is None:
634 if alloc_id is not None:
635 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
636 if gem_port_id is not None:
637 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
638 return
639
Girish Gowdrae933cd32019-11-21 21:04:41 +0530640 self._tp_service_specific_task[uni_id][tp_path] = \
641 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
642 tcont=tcont, gem_port=gem_port)
643 self._deferred = \
644 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
645 self._deferred.addCallbacks(success, failure)
646 except Exception as e:
647 self.log.exception("failed-to-delete-tp",
648 e=e, uni_id=uni_id, tp_path=tp_path,
649 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500650
651 def update_pm_config(self, device, pm_config):
652 # TODO: This has not been tested
653 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500654 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500655
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800656 def remove_onu_flows(self, device, flows):
657 self.log.debug('remove_onu_flows', device_id=device.id)
658
659
660 # no point in removing omci flows if the device isnt reachable
661 if device.connect_status != ConnectStatus.REACHABLE or \
662 device.admin_state != AdminState.ENABLED:
663 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
664 admin=device.admin_state, connect=device.connect_status)
665 return
666
667 for flow in flows:
668 # if incoming flow contains cookie, then remove from ONU
669 if flow.cookie:
670 self.log.debug("remove-flow", device_id=device.id, flow=flow)
671
672 def is_downstream(port):
673 return port == self._pon_port_number
674
675 def is_upstream(port):
676 return not is_downstream(port)
677
678 try:
679 _in_port = fd.get_in_port(flow)
680 assert _in_port is not None
681
682 _out_port = fd.get_out_port(flow) # may be None
683 _vlan_vid = fd.get_default_vlan(flow)
684
685 if is_downstream(_in_port):
686 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
687 device_id=device.id)
688 # extended vlan tagging operation will handle it
689 continue
690 elif is_upstream(_in_port):
691 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
692 if fd.is_dhcp_flow(flow):
693 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
694 return
695
696 uni_port = self.uni_port(_in_port)
697 uni_id = _in_port & 0xF
698 else:
699 raise Exception('port should be 1 or 2 by our convention')
700
701 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
702
703 tp_id = self.get_tp_id_in_flow(flow)
704 # Deleting flow from ONU.
705 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
706 match_vlan=_vlan_vid, tp_id=tp_id)
707 #TODO:Delete TD task.
708 except Exception as e:
709 self.log.exception('failed-to-remove-flow', e=e)
710
711 def add_onu_flows(self, device, flows):
712 self.log.debug('function-entry', flows=flows)
713
714 #
715 # We need to proxy through the OLT to get to the ONU
716 # Configuration from here should be using OMCI
717 #
718 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
719
720 # no point in pushing omci flows if the device isnt reachable
721 if device.connect_status != ConnectStatus.REACHABLE or \
722 device.admin_state != AdminState.ENABLED:
723 self.log.warn("device-disabled-or-offline-skipping-flow-update",
724 admin=device.admin_state, connect=device.connect_status)
725 return
726 def is_downstream(port):
727 return port == self._pon_port_number
728
729 def is_upstream(port):
730 return not is_downstream(port)
731
732 for flow in flows:
733 # if incoming flow contains cookie, then add to ONU
734 if flow.cookie:
735 _type = None
736 _port = None
737 _vlan_vid = None
738 _udp_dst = None
739 _udp_src = None
740 _ipv4_dst = None
741 _ipv4_src = None
742 _metadata = None
743 _output = None
744 _push_tpid = None
745 _field = None
746 _set_vlan_vid = None
747 _set_vlan_pcp = 0
748 _tunnel_id = None
749 self.log.debug("add-flow", device_id=device.id, flow=flow)
750
751 try:
752 _in_port = fd.get_in_port(flow)
753 assert _in_port is not None
754
755 _out_port = fd.get_out_port(flow) # may be None
756 tp_id = self.get_tp_id_in_flow(flow)
757 if is_downstream(_in_port):
758 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
759 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
760 # uni_port = self.uni_port(_out_port)
761 # uni_id = _out_port & 0xF
762 continue
763 elif is_upstream(_in_port):
764 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
765 uni_port = self.uni_port(_in_port)
766 uni_id = _in_port & 0xF
767 else:
768 raise Exception('port should be 1 or 2 by our convention')
769
770 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
771
772 for field in fd.get_ofb_fields(flow):
773 if field.type == fd.ETH_TYPE:
774 _type = field.eth_type
775 self.log.debug('field-type-eth-type',
776 eth_type=_type)
777
778 elif field.type == fd.IP_PROTO:
779 _proto = field.ip_proto
780 self.log.debug('field-type-ip-proto',
781 ip_proto=_proto)
782
783 elif field.type == fd.IN_PORT:
784 _port = field.port
785 self.log.debug('field-type-in-port',
786 in_port=_port)
787 elif field.type == fd.TUNNEL_ID:
788 self.log.debug('field-type-tunnel-id')
789
790 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100791 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
792 _vlan_vid = RESERVED_TRANSPARENT_VLAN
793 else:
794 _vlan_vid = field.vlan_vid & 0xfff
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800795 self.log.debug('field-type-vlan-vid',
796 vlan=_vlan_vid)
797
798 elif field.type == fd.VLAN_PCP:
799 _vlan_pcp = field.vlan_pcp
800 self.log.debug('field-type-vlan-pcp',
801 pcp=_vlan_pcp)
802
803 elif field.type == fd.UDP_DST:
804 _udp_dst = field.udp_dst
805 self.log.debug('field-type-udp-dst',
806 udp_dst=_udp_dst)
807
808 elif field.type == fd.UDP_SRC:
809 _udp_src = field.udp_src
810 self.log.debug('field-type-udp-src',
811 udp_src=_udp_src)
812
813 elif field.type == fd.IPV4_DST:
814 _ipv4_dst = field.ipv4_dst
815 self.log.debug('field-type-ipv4-dst',
816 ipv4_dst=_ipv4_dst)
817
818 elif field.type == fd.IPV4_SRC:
819 _ipv4_src = field.ipv4_src
820 self.log.debug('field-type-ipv4-src',
821 ipv4_dst=_ipv4_src)
822
823 elif field.type == fd.METADATA:
824 _metadata = field.table_metadata
825 self.log.debug('field-type-metadata',
826 metadata=_metadata)
827
828 else:
829 raise NotImplementedError('field.type={}'.format(
830 field.type))
831
832 for action in fd.get_actions(flow):
833
834 if action.type == fd.OUTPUT:
835 _output = action.output.port
836 self.log.debug('action-type-output',
837 output=_output, in_port=_in_port)
838
839 elif action.type == fd.POP_VLAN:
840 self.log.debug('action-type-pop-vlan',
841 in_port=_in_port)
842
843 elif action.type == fd.PUSH_VLAN:
844 _push_tpid = action.push.ethertype
845 self.log.debug('action-type-push-vlan',
846 push_tpid=_push_tpid, in_port=_in_port)
847 if action.push.ethertype != 0x8100:
848 self.log.error('unhandled-tpid',
849 ethertype=action.push.ethertype)
850
851 elif action.type == fd.SET_FIELD:
852 _field = action.set_field.field.ofb_field
853 assert (action.set_field.field.oxm_class ==
854 OFPXMC_OPENFLOW_BASIC)
855 self.log.debug('action-type-set-field',
856 field=_field, in_port=_in_port)
857 if _field.type == fd.VLAN_VID:
858 _set_vlan_vid = _field.vlan_vid & 0xfff
859 self.log.debug('set-field-type-vlan-vid',
860 vlan_vid=_set_vlan_vid)
861 elif _field.type == fd.VLAN_PCP:
862 _set_vlan_pcp = _field.vlan_pcp
863 self.log.debug('set-field-type-vlan-pcp',
864 vlan_pcp=_set_vlan_pcp)
865 else:
866 self.log.error('unsupported-action-set-field-type',
867 field_type=_field.type)
868 else:
869 self.log.error('unsupported-action-type',
870 action_type=action.type, in_port=_in_port)
871
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100872 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
873 # supported match and action criteria cannot be handled by omci and must be ignored.
874 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
875 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
876 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
877 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
878 _set_vlan_vid=_vlan_vid,
879 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
880 tp_id=tp_id)
881 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
882 _set_vlan_vid=_vlan_vid,
883 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
884 tp_id=tp_id)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800885 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100886 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
887 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800888 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
889 _set_vlan_vid=_set_vlan_vid,
890 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
891 tp_id=tp_id)
892
893 except Exception as e:
894 self.log.exception('failed-to-install-flow', e=e, flow=flow)
895
896
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500897 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
898 # flow decomposition that ultimately comes from onos
899 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700900 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500901
902 #
903 # We need to proxy through the OLT to get to the ONU
904 # Configuration from here should be using OMCI
905 #
906 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
907
908 # no point in pushing omci flows if the device isnt reachable
909 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530910 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500911 self.log.warn("device-disabled-or-offline-skipping-flow-update",
912 admin=device.admin_state, connect=device.connect_status)
913 return
914
915 def is_downstream(port):
916 return port == self._pon_port_number
917
918 def is_upstream(port):
919 return not is_downstream(port)
920
921 for flow in flows:
922 _type = None
923 _port = None
924 _vlan_vid = None
925 _udp_dst = None
926 _udp_src = None
927 _ipv4_dst = None
928 _ipv4_src = None
929 _metadata = None
930 _output = None
931 _push_tpid = None
932 _field = None
933 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800934 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400935 _tunnel_id = None
936
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500937 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530938 write_metadata = fd.get_write_metadata(flow)
939 if write_metadata is None:
940 self.log.error("do-not-process-flow-without-write-metadata")
941 return
942
943 # extract tp id from flow
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800944 tp_id= self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500945 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530946
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500947 _in_port = fd.get_in_port(flow)
948 assert _in_port is not None
949
950 _out_port = fd.get_out_port(flow) # may be None
951
952 if is_downstream(_in_port):
953 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
954 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530955 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500956 elif is_upstream(_in_port):
957 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
958 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400959 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500960 else:
961 raise Exception('port should be 1 or 2 by our convention')
962
963 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
964
965 for field in fd.get_ofb_fields(flow):
966 if field.type == fd.ETH_TYPE:
967 _type = field.eth_type
968 self.log.debug('field-type-eth-type',
969 eth_type=_type)
970
971 elif field.type == fd.IP_PROTO:
972 _proto = field.ip_proto
973 self.log.debug('field-type-ip-proto',
974 ip_proto=_proto)
975
976 elif field.type == fd.IN_PORT:
977 _port = field.port
978 self.log.debug('field-type-in-port',
979 in_port=_port)
980
981 elif field.type == fd.VLAN_VID:
Andrea Campanellacf916ea2020-02-14 10:03:58 +0100982 if field.vlan_vid == RESERVED_TRANSPARENT_VLAN and field.vlan_vid_mask == RESERVED_TRANSPARENT_VLAN:
983 _vlan_vid = RESERVED_TRANSPARENT_VLAN
984 else:
985 _vlan_vid = field.vlan_vid & 0xfff
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500986 self.log.debug('field-type-vlan-vid',
987 vlan=_vlan_vid)
988
989 elif field.type == fd.VLAN_PCP:
990 _vlan_pcp = field.vlan_pcp
991 self.log.debug('field-type-vlan-pcp',
992 pcp=_vlan_pcp)
993
994 elif field.type == fd.UDP_DST:
995 _udp_dst = field.udp_dst
996 self.log.debug('field-type-udp-dst',
997 udp_dst=_udp_dst)
998
999 elif field.type == fd.UDP_SRC:
1000 _udp_src = field.udp_src
1001 self.log.debug('field-type-udp-src',
1002 udp_src=_udp_src)
1003
1004 elif field.type == fd.IPV4_DST:
1005 _ipv4_dst = field.ipv4_dst
1006 self.log.debug('field-type-ipv4-dst',
1007 ipv4_dst=_ipv4_dst)
1008
1009 elif field.type == fd.IPV4_SRC:
1010 _ipv4_src = field.ipv4_src
1011 self.log.debug('field-type-ipv4-src',
1012 ipv4_dst=_ipv4_src)
1013
1014 elif field.type == fd.METADATA:
1015 _metadata = field.table_metadata
1016 self.log.debug('field-type-metadata',
1017 metadata=_metadata)
1018
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001019 elif field.type == fd.TUNNEL_ID:
1020 _tunnel_id = field.tunnel_id
1021 self.log.debug('field-type-tunnel-id',
1022 tunnel_id=_tunnel_id)
1023
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001024
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001025 else:
1026 raise NotImplementedError('field.type={}'.format(
1027 field.type))
1028
1029 for action in fd.get_actions(flow):
1030
1031 if action.type == fd.OUTPUT:
1032 _output = action.output.port
1033 self.log.debug('action-type-output',
1034 output=_output, in_port=_in_port)
1035
1036 elif action.type == fd.POP_VLAN:
1037 self.log.debug('action-type-pop-vlan',
1038 in_port=_in_port)
1039
1040 elif action.type == fd.PUSH_VLAN:
1041 _push_tpid = action.push.ethertype
1042 self.log.debug('action-type-push-vlan',
1043 push_tpid=_push_tpid, in_port=_in_port)
1044 if action.push.ethertype != 0x8100:
1045 self.log.error('unhandled-tpid',
1046 ethertype=action.push.ethertype)
1047
1048 elif action.type == fd.SET_FIELD:
1049 _field = action.set_field.field.ofb_field
1050 assert (action.set_field.field.oxm_class ==
1051 OFPXMC_OPENFLOW_BASIC)
1052 self.log.debug('action-type-set-field',
1053 field=_field, in_port=_in_port)
1054 if _field.type == fd.VLAN_VID:
1055 _set_vlan_vid = _field.vlan_vid & 0xfff
1056 self.log.debug('set-field-type-vlan-vid',
1057 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001058 elif _field.type == fd.VLAN_PCP:
1059 _set_vlan_pcp = _field.vlan_pcp
1060 self.log.debug('set-field-type-vlan-pcp',
1061 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001062 else:
1063 self.log.error('unsupported-action-set-field-type',
1064 field_type=_field.type)
1065 else:
1066 self.log.error('unsupported-action-type',
1067 action_type=action.type, in_port=_in_port)
1068
Matt Jeanneret810148b2019-09-29 12:44:01 -04001069 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1070 # supported match and action criteria cannot be handled by omci and must be ignored.
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001071 if (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid != RESERVED_TRANSPARENT_VLAN:
1072 self.log.warn('ignoring-flow-that-does-not-set-vlanid', set_vlan_vid=_set_vlan_vid)
1073 elif (_set_vlan_vid is None or _set_vlan_vid == 0) and _vlan_vid == RESERVED_TRANSPARENT_VLAN:
1074 self.log.info('set-vlanid-any', uni_id=uni_id, uni_port=uni_port,
1075 _set_vlan_vid=_vlan_vid,
1076 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1077 tp_id=tp_id)
1078 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1079 _set_vlan_vid=_vlan_vid,
1080 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1081 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001082 else:
Andrea Campanellacf916ea2020-02-14 10:03:58 +01001083 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid,
1084 set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1085 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
1086 _set_vlan_vid=_set_vlan_vid,
1087 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
1088 tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001089 except Exception as e:
1090 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1091
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001092 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1093 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1094 self.log.info('_adding_vlan_filter_task', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001095 assert uni_port is not None
Mahir Gunyele9110a32020-02-20 14:56:50 -08001096 if uni_id in self._tech_profile_download_done and tp_id in self._tech_profile_download_done[uni_id] and self._tech_profile_download_done[uni_id][tp_id] is True:
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001097 @inlineCallbacks
1098 def success(_results):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001099 self.log.info('vlan-tagging-success', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id, set_vlan_pcp=_set_vlan_pcp)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001100 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001101
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001102 @inlineCallbacks
1103 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301104 self.log.warn('vlan-tagging-failure', uni_port=uni_port, vlan=_set_vlan_vid, tp_id=tp_id)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001105 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001106 reactor.callLater(retry,
1107 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1108 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1109 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001110 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001111
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001112 self.log.info('setting-vlan-tag', uni_port=uni_port, uni_id=uni_id, tp_id=tp_id, match_vlan=match_vlan, vlan=_set_vlan_vid, vlan_pcp=_set_vlan_pcp)
1113 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1114 match_vlan, _set_vlan_pcp, add_tag=True,
1115 tp_id=tp_id)
1116 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001117 self._deferred.addCallbacks(success, failure)
1118 else:
1119 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001120 uni_id=uni_id, tp_id=tp_id)
1121 if uni_id not in self._queued_vlan_filter_task:
1122 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001123 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1124 self._queued_vlan_filter_task[uni_id][tp_id] = []
1125 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001126 "uni_id": uni_id,
1127 "uni_port": uni_port,
1128 "match_vlan": match_vlan,
1129 "set_vlan_vid": _set_vlan_vid,
1130 "set_vlan_pcp": _set_vlan_pcp,
Mahir Gunyela982ec32020-02-25 12:30:37 -08001131 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001132
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001133 def get_tp_id_in_flow(self, flow):
1134 flow_metadata = fd.get_metadata_from_write_metadata ( flow )
1135 tp_id = fd.get_tp_id_from_metadata ( flow_metadata )
1136 return tp_id
1137
1138 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1139 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1140 assert uni_port is not None
1141 @inlineCallbacks
1142 def success(_results):
1143 self.log.info('vlan-untagging-success', _results=_results)
1144 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1145
1146 @inlineCallbacks
1147 def failure(_reason):
1148 self.log.warn('vlan-untagging-failure', _reason=_reason)
1149 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
1150 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1151 reactor.callLater(retry,
1152 self._remove_vlan_filter_task, device, uni_id,
1153 add_tag=False, uni_port=uni_port)
1154
1155 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1156 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1157 match_vlan, _set_vlan_pcp, add_tag=False,
1158 tp_id=tp_id)
1159 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1160 self._deferred.addCallbacks(success, failure)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001161 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001162 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1163 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001164 try:
1165 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1166 omci_msg = InterAdapterOmciMessage()
1167 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001168 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001169
Matt Jeannereta32441c2019-03-07 05:16:37 -05001170 self.receive_message(omci_msg.message)
1171
1172 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1173 onu_indication = OnuIndication()
1174 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001175 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1176 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1177 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001178
1179 if onu_indication.oper_state == "up":
1180 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301181 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001182 self.update_interface(onu_indication)
1183 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001184 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1185 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001186
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001187 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1188 tech_msg = InterAdapterTechProfileDownloadMessage()
1189 request.body.Unpack(tech_msg)
1190 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1191
1192 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1193
Girish Gowdrae933cd32019-11-21 21:04:41 +05301194 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1195 del_gem_msg = InterAdapterDeleteGemPortMessage()
1196 request.body.Unpack(del_gem_msg)
1197 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1198
1199 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1200 gem_port_id=del_gem_msg.gem_port_id,
1201 tp_path=del_gem_msg.tp_path)
1202
1203 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1204 del_tcont_msg = InterAdapterDeleteTcontMessage()
1205 request.body.Unpack(del_tcont_msg)
1206 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1207
1208 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1209 alloc_id=del_tcont_msg.alloc_id,
1210 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001211 else:
1212 self.log.error("inter-adapter-unhandled-type", request=request)
1213
1214 except Exception as e:
1215 self.log.exception("error-processing-inter-adapter-message", e=e)
1216
1217 # Called each time there is an onu "up" indication from the olt handler
1218 @inlineCallbacks
1219 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001220 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001221 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001222
1223 # Ignore if onu_indication is received for an already running ONU
1224 if self._onu_omci_device is not None and self._onu_omci_device.active:
1225 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1226 return
1227
Matt Jeannereta32441c2019-03-07 05:16:37 -05001228 self._onu_indication = onu_indication
1229
Matt Jeanneretc083f462019-03-11 15:02:01 -04001230 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1231 connect_status=ConnectStatus.REACHABLE)
1232
Matt Jeannereta32441c2019-03-07 05:16:37 -05001233 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001234
1235 self.log.debug('starting-openomci-statemachine')
1236 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001237 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301238 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001239 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001240 self._heartbeat.enabled = True
1241
Matt Jeanneret42dad792020-02-01 09:28:27 -05001242 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001243 @inlineCallbacks
1244 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001245 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001246 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001247
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001248 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001249 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001250 reactor.callLater(0, self._onu_omci_device.stop)
1251
1252 # Let TP download happen again
1253 for uni_id in self._tp_service_specific_task:
1254 self._tp_service_specific_task[uni_id].clear()
1255 for uni_id in self._tech_profile_download_done:
1256 self._tech_profile_download_done[uni_id].clear()
1257
Matt Jeanneretf4113222019-08-14 19:44:34 -04001258 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001259 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1260 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1261 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001262 else:
1263 self.log.debug('not-changing-openomci-statemachine')
1264
Matt Jeanneretf4113222019-08-14 19:44:34 -04001265 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001266 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001267 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001268 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001269 yield self.disable_ports(lock_ports=True)
1270 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1271 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001272
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001273 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001274 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
William Kurkian3a206332019-04-29 11:05:47 -04001276 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001277 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001278 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001279 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001280 yield self.core_proxy.device_state_update(device.id,
1281 oper_status=OperStatus.ACTIVE,
1282 connect_status=ConnectStatus.REACHABLE)
1283 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1284 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001285 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001286 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001287
William Kurkian3a206332019-04-29 11:05:47 -04001288 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001289 def reboot(self):
1290 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001291 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001292 if device.connect_status != ConnectStatus.REACHABLE:
1293 self.log.error("device-unreachable")
1294 return
1295
William Kurkian3a206332019-04-29 11:05:47 -04001296 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001297 def success(_results):
1298 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001299 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001300
1301 def failure(_reason):
1302 self.log.info('reboot-failure', _reason=_reason)
1303
1304 self._deferred = self._onu_omci_device.reboot()
1305 self._deferred.addCallbacks(success, failure)
1306
William Kurkian3a206332019-04-29 11:05:47 -04001307 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001308 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001309 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001310
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001311 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1312 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001313 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001314 if port.mac_bridge_port_num == 1:
1315 port.operstatus = OperStatus.UNKNOWN
1316 self.log.info('disable-port', device_id=self.device_id, port=port)
1317 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001318
1319 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001320 self.lock_ports(lock=True)
1321
William Kurkian3a206332019-04-29 11:05:47 -04001322 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001323 def enable_ports(self):
1324 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001325
Matt Jeanneretf4113222019-08-14 19:44:34 -04001326 self.lock_ports(lock=False)
1327
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001328 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1329 # load on the core
1330 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001331 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001332 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001333 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001334 self.log.info('enable-port', device_id=self.device_id, port=port)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001335 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1336
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001337
1338 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1339 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1340 #
1341 # Basically the link state sequence:
1342 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1343 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1344 # 3) a link state up alarm is received for the uni plugged in.
1345 #
1346 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1347 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1348 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1349 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001350 @inlineCallbacks
1351 def port_state_handler(self, _topic, msg):
1352 self.log.info("port-state-change", _topic=_topic, msg=msg)
1353
1354 onu_id = msg['onu_id']
1355 port_no = msg['port_number']
1356 serial_number = msg['serial_number']
1357 port_status = msg['port_status']
1358 uni_port = self.uni_port(int(port_no))
1359
1360 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1361 port_status=port_status)
1362
1363 if port_status is True:
1364 uni_port.operstatus = OperStatus.ACTIVE
1365 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1366 else:
1367 uni_port.operstatus = OperStatus.UNKNOWN
1368 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1369
1370 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 -05001371 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001372
1373 # Called just before openomci state machine is started. These listen for events from selected state machines,
1374 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1375 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001376 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001377
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001378 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001379
1380 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001381 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1382 OnuDeviceEvents.MibDatabaseSyncEvent)
1383 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1384
1385 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001386 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1387 OnuDeviceEvents.OmciCapabilitiesEvent)
1388 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1389
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001390 # TODO: these alarms seem to be unreliable depending on the environment
1391 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
1392 #topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1393 # OnuDeviceEvents.PortEvent)
1394 #self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
1395
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001396 # Called when the mib is in sync
1397 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001398 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001399 if self._in_sync_subscription is not None:
1400 try:
1401 in_sync = msg[IN_SYNC_KEY]
1402
1403 if in_sync:
1404 # Only call this once
1405 bus = self._onu_omci_device.event_bus
1406 bus.unsubscribe(self._in_sync_subscription)
1407 self._in_sync_subscription = None
1408
1409 # Start up device_info load
1410 self.log.debug('running-mib-sync')
1411 reactor.callLater(0, self._mib_in_sync)
1412
1413 except Exception as e:
1414 self.log.exception('in-sync', e=e)
1415
1416 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001417 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001418 if self._capabilities_subscription is not None:
1419 self.log.debug('capabilities-handler-done')
1420
1421 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1422 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1423 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001424 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001425 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001426 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001427
1428 omci = self._onu_omci_device
1429 in_sync = omci.mib_db_in_sync
1430
Matt Jeanneretc083f462019-03-11 15:02:01 -04001431 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001432 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001433
1434 if not self._dev_info_loaded:
1435 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1436
1437 omci_dev = self._onu_omci_device
1438 config = omci_dev.configuration
1439
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001440 try:
1441
1442 # sort the lists so we get consistent port ordering.
1443 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1444 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1445 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1446 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1447
1448 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001449 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001450 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001451 raise Exception("onu-missing-required-elements")
1452
1453 # Currently logging the ani, pptp, veip, and uni for information purposes.
1454 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1455 # And in some ONU the UNI-G list is incomplete or incorrect...
1456 for entity_id in ani_list:
1457 ani_value = config.ani_g_entities[entity_id]
1458 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1459 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1460 self._total_tcont_count = ani_value.get('total-tcont-count')
1461 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1462
1463 for entity_id in uni_list:
1464 uni_value = config.uni_g_entities[entity_id]
1465 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1466
1467 uni_entities = OrderedDict()
1468 for entity_id in pptp_list:
1469 pptp_value = config.pptp_entities[entity_id]
1470 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1471 uni_entities[entity_id] = UniType.PPTP
1472
1473 for entity_id in veip_list:
1474 veip_value = config.veip_entities[entity_id]
1475 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1476 uni_entities[entity_id] = UniType.VEIP
1477
1478 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001479 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001480 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001481 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001482 uni_id += 1
1483 except AssertionError as e:
1484 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1485
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001486 self._qos_flexibility = config.qos_configuration_flexibility or 0
1487 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1488
1489 if self._unis:
1490 self._dev_info_loaded = True
1491 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001492 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001493 self.log.warn("no-usable-unis")
1494 raise Exception("no-usable-unis")
1495
1496 except Exception as e:
1497 self.log.exception('device-info-load', e=e)
1498 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1499
1500 else:
1501 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1502
1503 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001504 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001505
1506 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001507 def success(_results):
1508 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001509 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301510 oper_status=OperStatus.ACTIVE,
1511 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001512 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001513 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001514 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001515 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001516
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001517 # Start collecting stats from the device after a brief pause
1518 if not self._pm_metrics_started:
1519 self._pm_metrics_started = True
1520 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1521 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1522
1523 # Start test requests after a brief pause
1524 if not self._test_request_started:
1525 self._test_request_started = True
1526 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1527 reactor.callLater(tststart, self._test_request.start_collector)
1528
Matt Jeanneretc083f462019-03-11 15:02:01 -04001529 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001530 def failure(_reason):
1531 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001532 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1533 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001534 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001535
Matt Jeanneretf4113222019-08-14 19:44:34 -04001536 # start by locking all the unis till mib sync and initial mib is downloaded
1537 # this way we can capture the port down/up events when we are ready
1538 self.lock_ports(lock=True)
1539
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001540 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1541 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1542 self.log.info('downloading-initial-mib-configuration')
1543 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1544 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1545 self._deferred.addCallbacks(success, failure)
1546 else:
1547 self.log.info('admin-down-disabling')
1548 self.disable(device)
1549 else:
1550 self.log.info('device-info-not-loaded-skipping-mib-download')
1551
Matt Jeanneretc083f462019-03-11 15:02:01 -04001552 @inlineCallbacks
1553 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001554 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001555
Matt Jeanneretc083f462019-03-11 15:02:01 -04001556 uni_no = self.mk_uni_port_num(self._onu_indication.intf_id, self._onu_indication.onu_id, uni_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001557
1558 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1559 uni_name = "uni-{}".format(uni_no)
1560
Girish Gowdrae933cd32019-11-21 21:04:41 +05301561 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001562
1563 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 -04001564 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001565
1566 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1567 uni_port.entity_id = entity_id
1568 uni_port.enabled = True
1569 uni_port.mac_bridge_port_num = mac_bridge_port_num
1570
1571 self.log.debug("created-uni-port", uni=uni_port)
1572
Matt Jeanneretc083f462019-03-11 15:02:01 -04001573 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001574
1575 self._unis[uni_port.port_number] = uni_port
1576
1577 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301578 uni_ports=self.uni_ports,
1579 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001580
Matt Jeanneretc083f462019-03-11 15:02:01 -04001581 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1582 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001583 MAX_PONS_PER_OLT = 256
1584 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001585 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001586
Matt Jeanneretc083f462019-03-11 15:02:01 -04001587 assert intf_id < MAX_PONS_PER_OLT
1588 assert onu_id < MAX_ONUS_PER_PON
1589 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001590 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001591
1592 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001593 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001594 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001595 try:
1596 device = yield self.core_proxy.get_device(self.device_id)
1597 parent_device = yield self.core_proxy.get_device(self.parent_id)
1598 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001599 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001600
1601 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301602 pon_id=self._onu_indication.intf_id,
1603 onu_id=self._onu_indication.onu_id,
1604 registration_id=self.device_id,
1605 device_id=self.device_id,
1606 onu_serial_number=device.serial_number,
1607 olt_serial_number=olt_serial_number,
1608 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001609
Devmalya Paulffc89df2019-07-31 17:43:13 -04001610 self.log.debug("Trying-to-raise-onu-active-event")
1611 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001612 self._onu_indication.intf_id,
1613 device.serial_number,
1614 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301615 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001616 onu_id=self._onu_indication.onu_id).send(True)
1617 except Exception as active_event_error:
1618 self.log.exception('onu-activated-event-error',
1619 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001620
1621 def lock_ports(self, lock=True):
1622
1623 def success(response):
1624 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1625
1626 def failure(response):
1627 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1628
1629 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1630 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1631 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001632
1633 def extract_tp_id_from_path(self, tp_path):
1634 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
1635 tp_id = int ( tp_path.split ( _PATH_SEPERATOR)[1] )
1636 return tp_id