blob: bf6767e07945e34d26dbf4239ed27489bafcbe97 [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
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050066from pyvoltha.common.tech_profile.tech_profile import TechProfile
onkarkundargiaae99712019-09-23 15:02:52 +053067from pyvoltha.adapters.extensions.omci.tasks.omci_test_request import OmciTestRequest
68from pyvoltha.adapters.extensions.omci.omci_entities import AniG
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -050069from pyvoltha.adapters.extensions.omci.omci_defs import EntityOperations, ReasonCodes
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050070
71OP = EntityOperations
72RC = ReasonCodes
73
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050074_STARTUP_RETRY_WAIT = 10
Mahir Gunyele9110a32020-02-20 14:56:50 -080075_PATH_SEPERATOR = "/"
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050076
77
78class BrcmOpenomciOnuHandler(object):
79
80 def __init__(self, adapter, device_id):
81 self.log = structlog.get_logger(device_id=device_id)
Matt Jeanneret08a8e862019-12-20 14:02:32 -050082 self.log.debug('starting-handler')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050083 self.adapter = adapter
Matt Jeannereta32441c2019-03-07 05:16:37 -050084 self.core_proxy = adapter.core_proxy
85 self.adapter_proxy = adapter.adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050086 self.parent_id = None
87 self.device_id = device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050088 self.proxy_address = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050089 self._enabled = False
Devmalya Paulffc89df2019-07-31 17:43:13 -040090 self.events = None
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -050091 self._pm_metrics = None
92 self._pm_metrics_started = False
93 self._test_request = None
94 self._test_request_started = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050095 self._omcc_version = OMCCVersion.Unknown
96 self._total_tcont_count = 0 # From ANI-G ME
97 self._qos_flexibility = 0 # From ONT2_G ME
98
99 self._onu_indication = None
100 self._unis = dict() # Port # -> UniPort
101
102 self._pon = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500103 self._pon_port_number = 100
104 self.logical_device_id = None
105
106 self._heartbeat = HeartBeat.create(self, device_id)
107
108 # Set up OpenOMCI environment
109 self._onu_omci_device = None
110 self._dev_info_loaded = False
111 self._deferred = None
112
113 self._in_sync_subscription = None
Matt Jeanneretf4113222019-08-14 19:44:34 -0400114 self._port_state_subscription = None
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500115 self._connectivity_subscription = None
116 self._capabilities_subscription = None
117
118 self.mac_bridge_service_profile_entity_id = 0x201
119 self.gal_enet_profile_entity_id = 0x1
120
121 self._tp_service_specific_task = dict()
122 self._tech_profile_download_done = dict()
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400123 # Stores information related to queued vlan filter tasks
124 # Dictionary with key being uni_id and value being device,uni port ,uni id and vlan id
125
126 self._queued_vlan_filter_task = dict()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500127
128 # Initialize KV store client
129 self.args = registry('main').get_args()
130 if self.args.backend == 'etcd':
131 host, port = self.args.etcd.split(':', 1)
132 self.kv_client = EtcdStore(host, port,
133 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
134 elif self.args.backend == 'consul':
135 host, port = self.args.consul.split(':', 1)
136 self.kv_client = ConsulStore(host, port,
137 TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX)
138 else:
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500139 self.log.error('invalid-backend')
140 raise Exception("invalid-backend-for-kv-store")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500141
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500142 @property
143 def enabled(self):
144 return self._enabled
145
146 @enabled.setter
147 def enabled(self, value):
148 if self._enabled != value:
149 self._enabled = value
150
151 @property
152 def omci_agent(self):
153 return self.adapter.omci_agent
154
155 @property
156 def omci_cc(self):
157 return self._onu_omci_device.omci_cc if self._onu_omci_device is not None else None
158
159 @property
160 def heartbeat(self):
161 return self._heartbeat
162
163 @property
164 def uni_ports(self):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500165 return list(self._unis.values())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500166
167 def uni_port(self, port_no_or_name):
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500168 if isinstance(port_no_or_name, six.string_types):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500169 return next((uni for uni in self.uni_ports
170 if uni.name == port_no_or_name), None)
171
172 assert isinstance(port_no_or_name, int), 'Invalid parameter type'
173 return next((uni for uni in self.uni_ports
Girish Gowdrae933cd32019-11-21 21:04:41 +0530174 if uni.port_number == port_no_or_name), None)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500175
176 @property
177 def pon_port(self):
178 return self._pon
179
Girish Gowdraa73ee452019-12-20 18:52:17 +0530180 @property
181 def onu_omci_device(self):
182 return self._onu_omci_device
183
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500184 def receive_message(self, msg):
185 if self.omci_cc is not None:
186 self.omci_cc.receive_message(msg)
187
Matt Jeanneretc083f462019-03-11 15:02:01 -0400188 def get_ofp_port_info(self, device, port_no):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500189 self.log.debug('get-ofp-port-info', port_no=port_no, device_id=device.id)
Matt Jeanneretc083f462019-03-11 15:02:01 -0400190 cap = OFPPF_1GB_FD | OFPPF_FIBER
191
Girish Gowdrae933cd32019-11-21 21:04:41 +0530192 hw_addr = mac_str_to_tuple('08:%02x:%02x:%02x:%02x:%02x' %
193 ((device.parent_port_no >> 8 & 0xff),
194 device.parent_port_no & 0xff,
195 (port_no >> 16) & 0xff,
196 (port_no >> 8) & 0xff,
197 port_no & 0xff))
Matt Jeanneretc083f462019-03-11 15:02:01 -0400198
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400199 uni_port = self.uni_port(int(port_no))
200 name = device.serial_number + '-' + str(uni_port.mac_bridge_port_num)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500201 self.log.debug('ofp-port-name', port_no=port_no, name=name, uni_port=uni_port)
Matt Jeanneretf4113222019-08-14 19:44:34 -0400202
203 ofstate = OFPPS_LINK_DOWN
204 if uni_port.operstatus is OperStatus.ACTIVE:
205 ofstate = OFPPS_LIVE
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400206
Matt Jeanneretc083f462019-03-11 15:02:01 -0400207 return PortCapability(
208 port=LogicalPort(
209 ofp_port=ofp_port(
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400210 name=name,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400211 hw_addr=hw_addr,
212 config=0,
Matt Jeanneretf4113222019-08-14 19:44:34 -0400213 state=ofstate,
Matt Jeanneretc083f462019-03-11 15:02:01 -0400214 curr=cap,
215 advertised=cap,
216 peer=cap,
217 curr_speed=OFPPF_1GB_FD,
218 max_speed=OFPPF_1GB_FD
219 ),
220 device_id=device.id,
221 device_port_no=port_no
222 )
223 )
224
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500225 # Called once when the adapter creates the device/onu instance
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500226 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500227 def activate(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700228 self.log.debug('activate-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500229
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500230 assert device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500231 assert device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500232 assert device.proxy_address.device_id
233
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500234 self.proxy_address = device.proxy_address
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235 self.parent_id = device.parent_id
Matt Jeanneret0c287892019-02-28 11:48:00 -0500236 self._pon_port_number = device.parent_port_no
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500237 if self.enabled is not True:
Matteo Scandolod8d73172019-11-26 12:15:15 -0700238 self.log.info('activating-new-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500239 # populate what we know. rest comes later after mib sync
Matt Jeanneret0c287892019-02-28 11:48:00 -0500240 device.root = False
Matt Jeannereta32441c2019-03-07 05:16:37 -0500241 device.vendor = 'OpenONU'
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242 device.reason = 'activating-onu'
243
Matt Jeanneret84e56f62019-02-26 10:48:09 -0500244 # TODO NEW CORE: Need to either get logical device id from core or use regular device id
Matt Jeanneret3b7db442019-04-22 16:29:48 -0400245 # pm_metrics requires a logical device id. For now set to just device_id
246 self.logical_device_id = self.device_id
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500247
Matt Jeannereta32441c2019-03-07 05:16:37 -0500248 yield self.core_proxy.device_update(device)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500249 self.log.debug('device-updated', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500250
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700251 yield self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500252
Matteo Scandolod8d73172019-11-26 12:15:15 -0700253 self.log.debug('pon state initialized', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500254 ############################################################################
Devmalya Paulffc89df2019-07-31 17:43:13 -0400255 # Setup Alarm handler
256 self.events = AdapterEvents(self.core_proxy, device.id, self.logical_device_id,
257 device.serial_number)
258 ############################################################################
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500259 # Setup PM configuration for this device
260 # Pass in ONU specific options
261 kwargs = {
262 OnuPmMetrics.DEFAULT_FREQUENCY_KEY: OnuPmMetrics.DEFAULT_ONU_COLLECTION_FREQUENCY,
263 'heartbeat': self.heartbeat,
264 OnuOmciPmMetrics.OMCI_DEV_KEY: self._onu_omci_device
265 }
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500266 self.log.debug('create-pm-metrics', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500267 self._pm_metrics = OnuPmMetrics(self.events, self.core_proxy, self.device_id,
Yongjie Zhang8f891ad2019-07-03 15:32:38 -0400268 self.logical_device_id, device.serial_number,
269 grouped=True, freq_override=False, **kwargs)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500270 pm_config = self._pm_metrics.make_proto()
271 self._onu_omci_device.set_pm_config(self._pm_metrics.omci_pm.openomci_interval_pm)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530272 self.log.info("initial-pm-config", device_id=device.id, serial_number=device.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -0500273 yield self.core_proxy.device_pm_config_update(pm_config, init=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500274
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500275 # Note, ONU ID and UNI intf set in add_uni_port method
Devmalya Paulffc89df2019-07-31 17:43:13 -0400276 self._onu_omci_device.alarm_synchronizer.set_alarm_params(mgr=self.events,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500277 ani_ports=[self._pon])
aishwaryarana01a98d9fe2019-05-08 12:09:06 -0500278
onkarkundargiaae99712019-09-23 15:02:52 +0530279 # Code to Run OMCI Test Action
280 kwargs_omci_test_action = {
281 OmciTestRequest.DEFAULT_FREQUENCY_KEY:
282 OmciTestRequest.DEFAULT_COLLECTION_FREQUENCY
283 }
284 serial_number = device.serial_number
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500285 self._test_request = OmciTestRequest(self.core_proxy,
onkarkundargiaae99712019-09-23 15:02:52 +0530286 self.omci_agent, self.device_id,
287 AniG, serial_number,
288 self.logical_device_id,
289 exclusive=False,
290 **kwargs_omci_test_action)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500291
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500292 self.enabled = True
293 else:
294 self.log.info('onu-already-activated')
295
296 # Called once when the adapter needs to re-create device. usually on vcore restart
William Kurkian3a206332019-04-29 11:05:47 -0400297 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500298 def reconcile(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700299 self.log.debug('reconcile-device', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500300
301 # first we verify that we got parent reference and proxy info
302 assert device.parent_id
303 assert device.proxy_address.device_id
304
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700305 self.proxy_address = device.proxy_address
306 self.parent_id = device.parent_id
307 self._pon_port_number = device.parent_port_no
308
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500309 if self.enabled is not True:
310 self.log.info('reconciling-broadcom-onu-device')
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700311 self.logical_device_id = self.device_id
312 self._init_pon_state()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500313
314 # need to restart state machines on vcore restart. there is no indication to do it for us.
315 self._onu_omci_device.start()
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700316 yield self.core_proxy.device_reason_update(self.device_id, "restarting-openomci")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500317
318 # TODO: this is probably a bit heavy handed
319 # Force a reboot for now. We need indications to reflow to reassign tconts and gems given vcore went away
320 # This may not be necessary when mib resync actually works
321 reactor.callLater(1, self.reboot)
322
323 self.enabled = True
324 else:
325 self.log.info('onu-already-activated')
326
327 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700328 def _init_pon_state(self):
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500329 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 -0500330
331 self._pon = PonPort.create(self, self._pon_port_number)
Matt Jeanneret0c287892019-02-28 11:48:00 -0500332 self._pon.add_peer(self.parent_id, self._pon_port_number)
Matteo Scandolod8d73172019-11-26 12:15:15 -0700333 self.log.debug('adding-pon-port-to-agent',
334 type=self._pon.get_port().type,
335 admin_state=self._pon.get_port().admin_state,
336 oper_status=self._pon.get_port().oper_status,
337 )
Matt Jeanneret0c287892019-02-28 11:48:00 -0500338
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700339 yield self.core_proxy.port_created(self.device_id, self._pon.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500340
Matteo Scandolod8d73172019-11-26 12:15:15 -0700341 self.log.debug('added-pon-port-to-agent',
342 type=self._pon.get_port().type,
343 admin_state=self._pon.get_port().admin_state,
344 oper_status=self._pon.get_port().oper_status,
345 )
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500346
347 # Create and start the OpenOMCI ONU Device Entry for this ONU
348 self._onu_omci_device = self.omci_agent.add_device(self.device_id,
Matt Jeannereta32441c2019-03-07 05:16:37 -0500349 self.core_proxy,
350 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500351 support_classes=self.adapter.broadcom_omci,
352 custom_me_map=self.adapter.custom_me_entities())
353 # Port startup
354 if self._pon is not None:
355 self._pon.enabled = True
356
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500357 def delete(self, device):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700358 self.log.info('delete-onu', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneret42dad792020-02-01 09:28:27 -0500359
360 self._deferred.cancel()
361 self._test_request.stop_collector()
362 self._pm_metrics.stop_collector()
363 self.log.debug('removing-openomci-statemachine')
364 self.omci_agent.remove_device(device.id, cleanup=True)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500365
366 def _create_tconts(self, uni_id, us_scheduler):
367 alloc_id = us_scheduler['alloc_id']
368 q_sched_policy = us_scheduler['q_sched_policy']
369 self.log.debug('create-tcont', us_scheduler=us_scheduler)
370
371 tcontdict = dict()
372 tcontdict['alloc-id'] = alloc_id
373 tcontdict['q_sched_policy'] = q_sched_policy
374 tcontdict['uni_id'] = uni_id
375
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500376 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500377
378 self._pon.add_tcont(tcont)
379
380 self.log.debug('pon-add-tcont', tcont=tcont)
381
382 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
383 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
384 self.log.debug('create-gemport',
385 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530386 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500387 for gem_port in gem_ports:
388 gemdict = dict()
389 gemdict['gemport_id'] = gem_port['gemport_id']
390 gemdict['direction'] = direction
391 gemdict['alloc_id_ref'] = alloc_id_ref
392 gemdict['encryption'] = gem_port['aes_encryption']
393 gemdict['discard_config'] = dict()
394 gemdict['discard_config']['max_probability'] = \
395 gem_port['discard_config']['max_probability']
396 gemdict['discard_config']['max_threshold'] = \
397 gem_port['discard_config']['max_threshold']
398 gemdict['discard_config']['min_threshold'] = \
399 gem_port['discard_config']['min_threshold']
400 gemdict['discard_policy'] = gem_port['discard_policy']
401 gemdict['max_q_size'] = gem_port['max_q_size']
402 gemdict['pbit_map'] = gem_port['pbit_map']
403 gemdict['priority_q'] = gem_port['priority_q']
404 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
405 gemdict['weight'] = gem_port['weight']
406 gemdict['uni_id'] = uni_id
407
408 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530409 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500410
411 self._pon.add_gem_port(gem_port)
412
413 self.log.debug('pon-add-gemport', gem_port=gem_port)
414
Girish Gowdrae933cd32019-11-21 21:04:41 +0530415 return new_gem_ports
416
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800417 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400418 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
419 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
420 # or initial-mib-download is not done. Once the tp_task is completed, we execute
421 # such queued vlan-filter tasks
422 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800423 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 -0400424 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800425 uni_id=uni_id, tp_id=tp_id)
426 filter_info = self._queued_vlan_filter_task[uni_id][tp_id]
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400427 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800428 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
429 match_vlan = filter_info.get("match_vlan"),
430 _set_vlan_vid= filter_info.get("set_vlan_vid"),
431 _set_vlan_pcp = filter_info.get("set_vlan_pcp"),
432 tp_id = filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400433 # Now remove the entry from the dictionary
434 self._queued_vlan_filter_task[uni_id].clear()
435 self.log.debug("executed-queued-vlan-filter-task",
436 uni_id=uni_id)
437 except Exception as e:
438 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
439
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500440 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500441 us_scheduler = tp['us_scheduler']
442 alloc_id = us_scheduler['alloc_id']
443 self._create_tconts(uni_id, us_scheduler)
444 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
445 self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
446 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
447 self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
448
449 def load_and_configure_tech_profile(self, uni_id, tp_path):
450 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800451 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500452 if uni_id not in self._tp_service_specific_task:
453 self._tp_service_specific_task[uni_id] = dict()
454
455 if uni_id not in self._tech_profile_download_done:
456 self._tech_profile_download_done[uni_id] = dict()
457
Mahir Gunyele9110a32020-02-20 14:56:50 -0800458 if tp_id not in self._tech_profile_download_done[uni_id]:
459 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500460
Mahir Gunyele9110a32020-02-20 14:56:50 -0800461 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500462 try:
463 if tp_path in self._tp_service_specific_task[uni_id]:
464 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530465 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500466 return
467
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500468 tpstored = self.kv_client[tp_path]
469 tpstring = tpstored.decode('ascii')
470 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530471
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500472 self.log.debug("tp-instance", tp=tp)
473 self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700474
William Kurkian3a206332019-04-29 11:05:47 -0400475 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500476 def success(_results):
477 self.log.info("tech-profile-config-done-successfully")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500478 if tp_path in self._tp_service_specific_task[uni_id]:
479 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800480 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400481 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800482 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500483 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530484
William Kurkian3a206332019-04-29 11:05:47 -0400485 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500486 def failure(_reason):
487 self.log.warn('tech-profile-config-failure-retrying',
Girish Gowdrae933cd32019-11-21 21:04:41 +0530488 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500489 if tp_path in self._tp_service_specific_task[uni_id]:
490 del self._tp_service_specific_task[uni_id][tp_path]
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500491 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
492 reactor.callLater(retry, self.load_and_configure_tech_profile,
493 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500494 yield self.core_proxy.device_reason_update(self.device_id,
495 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500496
497 self.log.info('downloading-tech-profile-configuration')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530498 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
499 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
500 # due to additional tasks on different UNIs. So, it we cannot use the pon_port after
501 # this initializer
502 tconts = []
503 for tcont in list(self.pon_port.tconts.values()):
504 if tcont.uni_id is not None and tcont.uni_id != uni_id:
505 continue
506 tconts.append(tcont)
507
508 gem_ports = []
509 for gem_port in list(self.pon_port.gem_ports.values()):
510 if gem_port.uni_id is not None and gem_port.uni_id != uni_id:
511 continue
512 gem_ports.append(gem_port)
513
514 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
515
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500516 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800517 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500518 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530519 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500520 self._deferred.addCallbacks(success, failure)
521
522 except Exception as e:
523 self.log.exception("error-loading-tech-profile", e=e)
524 else:
525 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530526 # Could be a case where TP exists but new gem-ports are getting added dynamically
527 tpstored = self.kv_client[tp_path]
528 tpstring = tpstored.decode('ascii')
529 tp = json.loads(tpstring)
530 upstream_gems = []
531 downstream_gems = []
532 # Find out the new Gem ports that are getting added afresh.
533 for gp in tp['upstream_gem_port_attribute_list']:
534 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
535 # gem port already exists
536 continue
537 upstream_gems.append(gp)
538 for gp in tp['downstream_gem_port_attribute_list']:
539 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
540 # gem port already exists
541 continue
542 downstream_gems.append(gp)
543
544 us_scheduler = tp['us_scheduler']
545 alloc_id = us_scheduler['alloc_id']
546
547 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
548 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
549 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
550 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
551 new_gems = []
552 new_gems.extend(new_upstream_gems)
553 new_gems.extend(new_downstream_gems)
554
555 def success(_results):
556 self.log.info("new-gem-ports-successfully-installed", result=_results)
557
558 def failure(_reason):
559 self.log.warn('new-gem-port-install-failed--retrying',
560 _reason=_reason)
561 # Remove gem ports from cache. We will re-add them during the retry
562 for gp in new_gems:
563 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
564
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500565 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
566 reactor.callLater(retry, self.load_and_configure_tech_profile,
567 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530568
569 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800570 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530571 self._deferred = \
572 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
573 self._deferred.addCallbacks(success, failure)
574
575 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
576 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800577 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530578 if not uni_id in self._tech_profile_download_done:
579 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
580 return
581
Mahir Gunyele9110a32020-02-20 14:56:50 -0800582 if not tp_table_id in self._tech_profile_download_done[uni_id]:
583 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530584 return
585
Mahir Gunyele9110a32020-02-20 14:56:50 -0800586 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
587 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 +0530588 return
589
590 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800591 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 +0530592 return
593
594 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
595 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
596 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
597 # this initializer
598 tcont = None
599 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
600 for tc in list(self.pon_port.tconts.values()):
601 if tc.alloc_id == alloc_id:
602 tcont = tc
603 self.pon_port.remove_tcont(tc.alloc_id, False)
604
605 gem_port = None
606 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
607 for gp in list(self.pon_port.gem_ports.values()):
608 if gp.gem_id == gem_port_id:
609 gem_port = gp
610 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
611
Girish Gowdrae933cd32019-11-21 21:04:41 +0530612 @inlineCallbacks
613 def success(_results):
614 if gem_port_id:
615 self.log.info("gem-port-delete-done-successfully")
616 if alloc_id:
617 self.log.info("tcont-delete-done-successfully")
618 # The deletion of TCONT marks the complete deletion of tech-profile
619 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800620 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530621 del self._tp_service_specific_task[uni_id][tp_path]
622 except Exception as ex:
623 self.log.error("del-tp-state-info", e=ex)
624
625 # TODO: There could be multiple TP on the UNI, and also the ONU.
626 # TODO: But the below reason updates for the whole device.
627 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
628
629 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530630 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530631 self.log.warn('tech-profile-delete-failure-retrying',
632 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500633 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
634 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500635 yield self.core_proxy.device_reason_update(self.device_id,
636 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530637
638 self.log.info('deleting-tech-profile-configuration')
639
Girish Gowdraa73ee452019-12-20 18:52:17 +0530640 if tcont is None and gem_port is None:
641 if alloc_id is not None:
642 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
643 if gem_port_id is not None:
644 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
645 return
646
Girish Gowdrae933cd32019-11-21 21:04:41 +0530647 self._tp_service_specific_task[uni_id][tp_path] = \
648 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
649 tcont=tcont, gem_port=gem_port)
650 self._deferred = \
651 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
652 self._deferred.addCallbacks(success, failure)
653 except Exception as e:
654 self.log.exception("failed-to-delete-tp",
655 e=e, uni_id=uni_id, tp_path=tp_path,
656 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500657
658 def update_pm_config(self, device, pm_config):
659 # TODO: This has not been tested
660 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500661 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500662
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800663 def remove_onu_flows(self, device, flows):
664 self.log.debug('remove_onu_flows', device_id=device.id)
665
666
667 # no point in removing omci flows if the device isnt reachable
668 if device.connect_status != ConnectStatus.REACHABLE or \
669 device.admin_state != AdminState.ENABLED:
670 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
671 admin=device.admin_state, connect=device.connect_status)
672 return
673
674 for flow in flows:
675 # if incoming flow contains cookie, then remove from ONU
676 if flow.cookie:
677 self.log.debug("remove-flow", device_id=device.id, flow=flow)
678
679 def is_downstream(port):
680 return port == self._pon_port_number
681
682 def is_upstream(port):
683 return not is_downstream(port)
684
685 try:
686 _in_port = fd.get_in_port(flow)
687 assert _in_port is not None
688
689 _out_port = fd.get_out_port(flow) # may be None
690 _vlan_vid = fd.get_default_vlan(flow)
691
692 if is_downstream(_in_port):
693 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
694 device_id=device.id)
695 # extended vlan tagging operation will handle it
696 continue
697 elif is_upstream(_in_port):
698 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
699 if fd.is_dhcp_flow(flow):
700 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
701 return
702
703 uni_port = self.uni_port(_in_port)
704 uni_id = _in_port & 0xF
705 else:
706 raise Exception('port should be 1 or 2 by our convention')
707
708 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
709
710 tp_id = self.get_tp_id_in_flow(flow)
711 # Deleting flow from ONU.
712 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
713 match_vlan=_vlan_vid, tp_id=tp_id)
714 #TODO:Delete TD task.
715 except Exception as e:
716 self.log.exception('failed-to-remove-flow', e=e)
717
718 def add_onu_flows(self, device, flows):
719 self.log.debug('function-entry', flows=flows)
720
721 #
722 # We need to proxy through the OLT to get to the ONU
723 # Configuration from here should be using OMCI
724 #
725 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
726
727 # no point in pushing omci flows if the device isnt reachable
728 if device.connect_status != ConnectStatus.REACHABLE or \
729 device.admin_state != AdminState.ENABLED:
730 self.log.warn("device-disabled-or-offline-skipping-flow-update",
731 admin=device.admin_state, connect=device.connect_status)
732 return
733 def is_downstream(port):
734 return port == self._pon_port_number
735
736 def is_upstream(port):
737 return not is_downstream(port)
738
739 for flow in flows:
740 # if incoming flow contains cookie, then add to ONU
741 if flow.cookie:
742 _type = None
743 _port = None
744 _vlan_vid = None
745 _udp_dst = None
746 _udp_src = None
747 _ipv4_dst = None
748 _ipv4_src = None
749 _metadata = None
750 _output = None
751 _push_tpid = None
752 _field = None
753 _set_vlan_vid = None
754 _set_vlan_pcp = 0
755 _tunnel_id = None
756 self.log.debug("add-flow", device_id=device.id, flow=flow)
757
758 try:
759 _in_port = fd.get_in_port(flow)
760 assert _in_port is not None
761
762 _out_port = fd.get_out_port(flow) # may be None
763 tp_id = self.get_tp_id_in_flow(flow)
764 if is_downstream(_in_port):
765 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
766 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
767 # uni_port = self.uni_port(_out_port)
768 # uni_id = _out_port & 0xF
769 continue
770 elif is_upstream(_in_port):
771 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
772 uni_port = self.uni_port(_in_port)
773 uni_id = _in_port & 0xF
774 else:
775 raise Exception('port should be 1 or 2 by our convention')
776
777 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
778
779 for field in fd.get_ofb_fields(flow):
780 if field.type == fd.ETH_TYPE:
781 _type = field.eth_type
782 self.log.debug('field-type-eth-type',
783 eth_type=_type)
784
785 elif field.type == fd.IP_PROTO:
786 _proto = field.ip_proto
787 self.log.debug('field-type-ip-proto',
788 ip_proto=_proto)
789
790 elif field.type == fd.IN_PORT:
791 _port = field.port
792 self.log.debug('field-type-in-port',
793 in_port=_port)
794 elif field.type == fd.TUNNEL_ID:
795 self.log.debug('field-type-tunnel-id')
796
797 elif field.type == fd.VLAN_VID:
798 _vlan_vid = field.vlan_vid & 0xfff
799 self.log.debug('field-type-vlan-vid',
800 vlan=_vlan_vid)
801
802 elif field.type == fd.VLAN_PCP:
803 _vlan_pcp = field.vlan_pcp
804 self.log.debug('field-type-vlan-pcp',
805 pcp=_vlan_pcp)
806
807 elif field.type == fd.UDP_DST:
808 _udp_dst = field.udp_dst
809 self.log.debug('field-type-udp-dst',
810 udp_dst=_udp_dst)
811
812 elif field.type == fd.UDP_SRC:
813 _udp_src = field.udp_src
814 self.log.debug('field-type-udp-src',
815 udp_src=_udp_src)
816
817 elif field.type == fd.IPV4_DST:
818 _ipv4_dst = field.ipv4_dst
819 self.log.debug('field-type-ipv4-dst',
820 ipv4_dst=_ipv4_dst)
821
822 elif field.type == fd.IPV4_SRC:
823 _ipv4_src = field.ipv4_src
824 self.log.debug('field-type-ipv4-src',
825 ipv4_dst=_ipv4_src)
826
827 elif field.type == fd.METADATA:
828 _metadata = field.table_metadata
829 self.log.debug('field-type-metadata',
830 metadata=_metadata)
831
832 else:
833 raise NotImplementedError('field.type={}'.format(
834 field.type))
835
836 for action in fd.get_actions(flow):
837
838 if action.type == fd.OUTPUT:
839 _output = action.output.port
840 self.log.debug('action-type-output',
841 output=_output, in_port=_in_port)
842
843 elif action.type == fd.POP_VLAN:
844 self.log.debug('action-type-pop-vlan',
845 in_port=_in_port)
846
847 elif action.type == fd.PUSH_VLAN:
848 _push_tpid = action.push.ethertype
849 self.log.debug('action-type-push-vlan',
850 push_tpid=_push_tpid, in_port=_in_port)
851 if action.push.ethertype != 0x8100:
852 self.log.error('unhandled-tpid',
853 ethertype=action.push.ethertype)
854
855 elif action.type == fd.SET_FIELD:
856 _field = action.set_field.field.ofb_field
857 assert (action.set_field.field.oxm_class ==
858 OFPXMC_OPENFLOW_BASIC)
859 self.log.debug('action-type-set-field',
860 field=_field, in_port=_in_port)
861 if _field.type == fd.VLAN_VID:
862 _set_vlan_vid = _field.vlan_vid & 0xfff
863 self.log.debug('set-field-type-vlan-vid',
864 vlan_vid=_set_vlan_vid)
865 elif _field.type == fd.VLAN_PCP:
866 _set_vlan_pcp = _field.vlan_pcp
867 self.log.debug('set-field-type-vlan-pcp',
868 vlan_pcp=_set_vlan_pcp)
869 else:
870 self.log.error('unsupported-action-set-field-type',
871 field_type=_field.type)
872 else:
873 self.log.error('unsupported-action-type',
874 action_type=action.type, in_port=_in_port)
875
Mahir Gunyel9dfab822020-02-20 15:52:15 -0800876 if _set_vlan_vid is None or _set_vlan_vid == 0:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800877 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
878 else:
879 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, set_vlan_vid=_set_vlan_vid, vlan_vid=_vlan_vid,tp_id=tp_id)
880 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
881 _set_vlan_vid=_set_vlan_vid,
882 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
883 tp_id=tp_id)
884
885 except Exception as e:
886 self.log.exception('failed-to-install-flow', e=e, flow=flow)
887
888
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500889 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
890 # flow decomposition that ultimately comes from onos
891 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700892 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500893
894 #
895 # We need to proxy through the OLT to get to the ONU
896 # Configuration from here should be using OMCI
897 #
898 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
899
900 # no point in pushing omci flows if the device isnt reachable
901 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530902 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500903 self.log.warn("device-disabled-or-offline-skipping-flow-update",
904 admin=device.admin_state, connect=device.connect_status)
905 return
906
907 def is_downstream(port):
908 return port == self._pon_port_number
909
910 def is_upstream(port):
911 return not is_downstream(port)
912
913 for flow in flows:
914 _type = None
915 _port = None
916 _vlan_vid = None
917 _udp_dst = None
918 _udp_src = None
919 _ipv4_dst = None
920 _ipv4_src = None
921 _metadata = None
922 _output = None
923 _push_tpid = None
924 _field = None
925 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800926 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400927 _tunnel_id = None
928
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500929 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530930 write_metadata = fd.get_write_metadata(flow)
931 if write_metadata is None:
932 self.log.error("do-not-process-flow-without-write-metadata")
933 return
934
935 # extract tp id from flow
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800936 tp_id= self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500937 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530938
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500939 _in_port = fd.get_in_port(flow)
940 assert _in_port is not None
941
942 _out_port = fd.get_out_port(flow) # may be None
943
944 if is_downstream(_in_port):
945 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
946 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530947 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500948 elif is_upstream(_in_port):
949 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
950 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400951 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500952 else:
953 raise Exception('port should be 1 or 2 by our convention')
954
955 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
956
957 for field in fd.get_ofb_fields(flow):
958 if field.type == fd.ETH_TYPE:
959 _type = field.eth_type
960 self.log.debug('field-type-eth-type',
961 eth_type=_type)
962
963 elif field.type == fd.IP_PROTO:
964 _proto = field.ip_proto
965 self.log.debug('field-type-ip-proto',
966 ip_proto=_proto)
967
968 elif field.type == fd.IN_PORT:
969 _port = field.port
970 self.log.debug('field-type-in-port',
971 in_port=_port)
972
973 elif field.type == fd.VLAN_VID:
974 _vlan_vid = field.vlan_vid & 0xfff
975 self.log.debug('field-type-vlan-vid',
976 vlan=_vlan_vid)
977
978 elif field.type == fd.VLAN_PCP:
979 _vlan_pcp = field.vlan_pcp
980 self.log.debug('field-type-vlan-pcp',
981 pcp=_vlan_pcp)
982
983 elif field.type == fd.UDP_DST:
984 _udp_dst = field.udp_dst
985 self.log.debug('field-type-udp-dst',
986 udp_dst=_udp_dst)
987
988 elif field.type == fd.UDP_SRC:
989 _udp_src = field.udp_src
990 self.log.debug('field-type-udp-src',
991 udp_src=_udp_src)
992
993 elif field.type == fd.IPV4_DST:
994 _ipv4_dst = field.ipv4_dst
995 self.log.debug('field-type-ipv4-dst',
996 ipv4_dst=_ipv4_dst)
997
998 elif field.type == fd.IPV4_SRC:
999 _ipv4_src = field.ipv4_src
1000 self.log.debug('field-type-ipv4-src',
1001 ipv4_dst=_ipv4_src)
1002
1003 elif field.type == fd.METADATA:
1004 _metadata = field.table_metadata
1005 self.log.debug('field-type-metadata',
1006 metadata=_metadata)
1007
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001008 elif field.type == fd.TUNNEL_ID:
1009 _tunnel_id = field.tunnel_id
1010 self.log.debug('field-type-tunnel-id',
1011 tunnel_id=_tunnel_id)
1012
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001013 else:
1014 raise NotImplementedError('field.type={}'.format(
1015 field.type))
1016
1017 for action in fd.get_actions(flow):
1018
1019 if action.type == fd.OUTPUT:
1020 _output = action.output.port
1021 self.log.debug('action-type-output',
1022 output=_output, in_port=_in_port)
1023
1024 elif action.type == fd.POP_VLAN:
1025 self.log.debug('action-type-pop-vlan',
1026 in_port=_in_port)
1027
1028 elif action.type == fd.PUSH_VLAN:
1029 _push_tpid = action.push.ethertype
1030 self.log.debug('action-type-push-vlan',
1031 push_tpid=_push_tpid, in_port=_in_port)
1032 if action.push.ethertype != 0x8100:
1033 self.log.error('unhandled-tpid',
1034 ethertype=action.push.ethertype)
1035
1036 elif action.type == fd.SET_FIELD:
1037 _field = action.set_field.field.ofb_field
1038 assert (action.set_field.field.oxm_class ==
1039 OFPXMC_OPENFLOW_BASIC)
1040 self.log.debug('action-type-set-field',
1041 field=_field, in_port=_in_port)
1042 if _field.type == fd.VLAN_VID:
1043 _set_vlan_vid = _field.vlan_vid & 0xfff
1044 self.log.debug('set-field-type-vlan-vid',
1045 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001046 elif _field.type == fd.VLAN_PCP:
1047 _set_vlan_pcp = _field.vlan_pcp
1048 self.log.debug('set-field-type-vlan-pcp',
1049 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001050 else:
1051 self.log.error('unsupported-action-set-field-type',
1052 field_type=_field.type)
1053 else:
1054 self.log.error('unsupported-action-type',
1055 action_type=action.type, in_port=_in_port)
1056
Matt Jeanneret810148b2019-09-29 12:44:01 -04001057 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1058 # supported match and action criteria cannot be handled by omci and must be ignored.
1059 if _set_vlan_vid is None or _set_vlan_vid == 0:
1060 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001061 else:
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001062 self.log.info('set-vlanid', uni_id=uni_id, uni_port=uni_port, match_vlan=_vlan_vid, set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, ethType=_type)
1063 self._add_vlan_filter_task(device, uni_id,
1064 uni_port=uni_port, match_vlan=_vlan_vid,
1065 _set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001066 except Exception as e:
1067 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1068
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001069 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1070 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1071 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 -05001072 assert uni_port is not None
Mahir Gunyele9110a32020-02-20 14:56:50 -08001073 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 -04001074 @inlineCallbacks
1075 def success(_results):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001076 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 -05001077 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001078
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001079 @inlineCallbacks
1080 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301081 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 -05001082 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001083 reactor.callLater(retry,
1084 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1085 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1086 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001087 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001088
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001089 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)
1090 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1091 match_vlan, _set_vlan_pcp, add_tag=True,
1092 tp_id=tp_id)
1093 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001094 self._deferred.addCallbacks(success, failure)
1095 else:
1096 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001097 uni_id=uni_id, tp_id=tp_id)
1098 if uni_id not in self._queued_vlan_filter_task:
1099 self._queued_vlan_filter_task[uni_id] = dict()
1100 self._queued_vlan_filter_task[uni_id][tp_id] = {"device": device,
1101 "uni_id": uni_id,
1102 "uni_port": uni_port,
1103 "match_vlan": match_vlan,
1104 "set_vlan_vid": _set_vlan_vid,
1105 "set_vlan_pcp": _set_vlan_pcp,
1106 "tp_id": tp_id}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001107
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001108 def get_tp_id_in_flow(self, flow):
1109 flow_metadata = fd.get_metadata_from_write_metadata ( flow )
1110 tp_id = fd.get_tp_id_from_metadata ( flow_metadata )
1111 return tp_id
1112
1113 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1114 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1115 assert uni_port is not None
1116 @inlineCallbacks
1117 def success(_results):
1118 self.log.info('vlan-untagging-success', _results=_results)
1119 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1120
1121 @inlineCallbacks
1122 def failure(_reason):
1123 self.log.warn('vlan-untagging-failure', _reason=_reason)
1124 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
1125 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1126 reactor.callLater(retry,
1127 self._remove_vlan_filter_task, device, uni_id,
1128 add_tag=False, uni_port=uni_port)
1129
1130 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1131 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1132 match_vlan, _set_vlan_pcp, add_tag=False,
1133 tp_id=tp_id)
1134 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1135 self._deferred.addCallbacks(success, failure)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001136 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001137 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1138 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001139 try:
1140 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1141 omci_msg = InterAdapterOmciMessage()
1142 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001143 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001144
Matt Jeannereta32441c2019-03-07 05:16:37 -05001145 self.receive_message(omci_msg.message)
1146
1147 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1148 onu_indication = OnuIndication()
1149 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001150 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1151 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1152 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001153
1154 if onu_indication.oper_state == "up":
1155 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301156 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001157 self.update_interface(onu_indication)
1158 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001159 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1160 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001161
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001162 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1163 tech_msg = InterAdapterTechProfileDownloadMessage()
1164 request.body.Unpack(tech_msg)
1165 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1166
1167 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1168
Girish Gowdrae933cd32019-11-21 21:04:41 +05301169 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1170 del_gem_msg = InterAdapterDeleteGemPortMessage()
1171 request.body.Unpack(del_gem_msg)
1172 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1173
1174 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1175 gem_port_id=del_gem_msg.gem_port_id,
1176 tp_path=del_gem_msg.tp_path)
1177
1178 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1179 del_tcont_msg = InterAdapterDeleteTcontMessage()
1180 request.body.Unpack(del_tcont_msg)
1181 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1182
1183 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1184 alloc_id=del_tcont_msg.alloc_id,
1185 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001186 else:
1187 self.log.error("inter-adapter-unhandled-type", request=request)
1188
1189 except Exception as e:
1190 self.log.exception("error-processing-inter-adapter-message", e=e)
1191
1192 # Called each time there is an onu "up" indication from the olt handler
1193 @inlineCallbacks
1194 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001195 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001196 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001197
1198 # Ignore if onu_indication is received for an already running ONU
1199 if self._onu_omci_device is not None and self._onu_omci_device.active:
1200 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1201 return
1202
Matt Jeannereta32441c2019-03-07 05:16:37 -05001203 self._onu_indication = onu_indication
1204
Matt Jeanneretc083f462019-03-11 15:02:01 -04001205 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1206 connect_status=ConnectStatus.REACHABLE)
1207
Matt Jeannereta32441c2019-03-07 05:16:37 -05001208 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001209
1210 self.log.debug('starting-openomci-statemachine')
1211 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001212 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301213 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001214 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001215 self._heartbeat.enabled = True
1216
Matt Jeanneret42dad792020-02-01 09:28:27 -05001217 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001218 @inlineCallbacks
1219 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001220 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001221 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001222
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001223 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001224 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001225 reactor.callLater(0, self._onu_omci_device.stop)
1226
1227 # Let TP download happen again
1228 for uni_id in self._tp_service_specific_task:
1229 self._tp_service_specific_task[uni_id].clear()
1230 for uni_id in self._tech_profile_download_done:
1231 self._tech_profile_download_done[uni_id].clear()
1232
Matt Jeanneretf4113222019-08-14 19:44:34 -04001233 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001234 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1235 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1236 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001237 else:
1238 self.log.debug('not-changing-openomci-statemachine')
1239
Matt Jeanneretf4113222019-08-14 19:44:34 -04001240 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001241 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001242 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001243 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001244 yield self.disable_ports(lock_ports=True)
1245 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1246 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001247
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001248 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001249 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001250
William Kurkian3a206332019-04-29 11:05:47 -04001251 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001252 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001253 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001254 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001255 yield self.core_proxy.device_state_update(device.id,
1256 oper_status=OperStatus.ACTIVE,
1257 connect_status=ConnectStatus.REACHABLE)
1258 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1259 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001260 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001261 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001262
William Kurkian3a206332019-04-29 11:05:47 -04001263 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001264 def reboot(self):
1265 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001266 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001267 if device.connect_status != ConnectStatus.REACHABLE:
1268 self.log.error("device-unreachable")
1269 return
1270
William Kurkian3a206332019-04-29 11:05:47 -04001271 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001272 def success(_results):
1273 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001274 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001275
1276 def failure(_reason):
1277 self.log.info('reboot-failure', _reason=_reason)
1278
1279 self._deferred = self._onu_omci_device.reboot()
1280 self._deferred.addCallbacks(success, failure)
1281
William Kurkian3a206332019-04-29 11:05:47 -04001282 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001283 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001284 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001285
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001286 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1287 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001288 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001289 if port.mac_bridge_port_num == 1:
1290 port.operstatus = OperStatus.UNKNOWN
1291 self.log.info('disable-port', device_id=self.device_id, port=port)
1292 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 -04001293
1294 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001295 self.lock_ports(lock=True)
1296
William Kurkian3a206332019-04-29 11:05:47 -04001297 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001298 def enable_ports(self):
1299 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001300
Matt Jeanneretf4113222019-08-14 19:44:34 -04001301 self.lock_ports(lock=False)
1302
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001303 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1304 # load on the core
1305 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001306 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001307 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001308 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001309 self.log.info('enable-port', device_id=self.device_id, port=port)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001310 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1311
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001312
1313 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1314 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1315 #
1316 # Basically the link state sequence:
1317 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1318 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1319 # 3) a link state up alarm is received for the uni plugged in.
1320 #
1321 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1322 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1323 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1324 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001325 @inlineCallbacks
1326 def port_state_handler(self, _topic, msg):
1327 self.log.info("port-state-change", _topic=_topic, msg=msg)
1328
1329 onu_id = msg['onu_id']
1330 port_no = msg['port_number']
1331 serial_number = msg['serial_number']
1332 port_status = msg['port_status']
1333 uni_port = self.uni_port(int(port_no))
1334
1335 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1336 port_status=port_status)
1337
1338 if port_status is True:
1339 uni_port.operstatus = OperStatus.ACTIVE
1340 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1341 else:
1342 uni_port.operstatus = OperStatus.UNKNOWN
1343 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1344
1345 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 -05001346 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001347
1348 # Called just before openomci state machine is started. These listen for events from selected state machines,
1349 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1350 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001351 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001352
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001353 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001354
1355 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001356 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1357 OnuDeviceEvents.MibDatabaseSyncEvent)
1358 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1359
1360 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001361 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1362 OnuDeviceEvents.OmciCapabilitiesEvent)
1363 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1364
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001365 # TODO: these alarms seem to be unreliable depending on the environment
1366 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
1367 #topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1368 # OnuDeviceEvents.PortEvent)
1369 #self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
1370
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001371 # Called when the mib is in sync
1372 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001373 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001374 if self._in_sync_subscription is not None:
1375 try:
1376 in_sync = msg[IN_SYNC_KEY]
1377
1378 if in_sync:
1379 # Only call this once
1380 bus = self._onu_omci_device.event_bus
1381 bus.unsubscribe(self._in_sync_subscription)
1382 self._in_sync_subscription = None
1383
1384 # Start up device_info load
1385 self.log.debug('running-mib-sync')
1386 reactor.callLater(0, self._mib_in_sync)
1387
1388 except Exception as e:
1389 self.log.exception('in-sync', e=e)
1390
1391 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001392 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001393 if self._capabilities_subscription is not None:
1394 self.log.debug('capabilities-handler-done')
1395
1396 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1397 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1398 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001399 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001400 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001401 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001402
1403 omci = self._onu_omci_device
1404 in_sync = omci.mib_db_in_sync
1405
Matt Jeanneretc083f462019-03-11 15:02:01 -04001406 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001407 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001408
1409 if not self._dev_info_loaded:
1410 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1411
1412 omci_dev = self._onu_omci_device
1413 config = omci_dev.configuration
1414
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001415 try:
1416
1417 # sort the lists so we get consistent port ordering.
1418 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1419 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1420 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1421 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1422
1423 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001424 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001425 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001426 raise Exception("onu-missing-required-elements")
1427
1428 # Currently logging the ani, pptp, veip, and uni for information purposes.
1429 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1430 # And in some ONU the UNI-G list is incomplete or incorrect...
1431 for entity_id in ani_list:
1432 ani_value = config.ani_g_entities[entity_id]
1433 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1434 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1435 self._total_tcont_count = ani_value.get('total-tcont-count')
1436 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1437
1438 for entity_id in uni_list:
1439 uni_value = config.uni_g_entities[entity_id]
1440 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1441
1442 uni_entities = OrderedDict()
1443 for entity_id in pptp_list:
1444 pptp_value = config.pptp_entities[entity_id]
1445 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1446 uni_entities[entity_id] = UniType.PPTP
1447
1448 for entity_id in veip_list:
1449 veip_value = config.veip_entities[entity_id]
1450 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1451 uni_entities[entity_id] = UniType.VEIP
1452
1453 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001454 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001455 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001456 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001457 uni_id += 1
1458 except AssertionError as e:
1459 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1460
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001461 self._qos_flexibility = config.qos_configuration_flexibility or 0
1462 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1463
1464 if self._unis:
1465 self._dev_info_loaded = True
1466 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001467 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001468 self.log.warn("no-usable-unis")
1469 raise Exception("no-usable-unis")
1470
1471 except Exception as e:
1472 self.log.exception('device-info-load', e=e)
1473 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1474
1475 else:
1476 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1477
1478 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001479 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001480
1481 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001482 def success(_results):
1483 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001484 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301485 oper_status=OperStatus.ACTIVE,
1486 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001487 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001488 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001489 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001490 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001491
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001492 # Start collecting stats from the device after a brief pause
1493 if not self._pm_metrics_started:
1494 self._pm_metrics_started = True
1495 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1496 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1497
1498 # Start test requests after a brief pause
1499 if not self._test_request_started:
1500 self._test_request_started = True
1501 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1502 reactor.callLater(tststart, self._test_request.start_collector)
1503
Matt Jeanneretc083f462019-03-11 15:02:01 -04001504 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001505 def failure(_reason):
1506 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001507 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1508 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001509 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001510
Matt Jeanneretf4113222019-08-14 19:44:34 -04001511 # start by locking all the unis till mib sync and initial mib is downloaded
1512 # this way we can capture the port down/up events when we are ready
1513 self.lock_ports(lock=True)
1514
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001515 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1516 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1517 self.log.info('downloading-initial-mib-configuration')
1518 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1519 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1520 self._deferred.addCallbacks(success, failure)
1521 else:
1522 self.log.info('admin-down-disabling')
1523 self.disable(device)
1524 else:
1525 self.log.info('device-info-not-loaded-skipping-mib-download')
1526
Matt Jeanneretc083f462019-03-11 15:02:01 -04001527 @inlineCallbacks
1528 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001529 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001530
Matt Jeanneretc083f462019-03-11 15:02:01 -04001531 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 -05001532
1533 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1534 uni_name = "uni-{}".format(uni_no)
1535
Girish Gowdrae933cd32019-11-21 21:04:41 +05301536 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001537
1538 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 -04001539 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001540
1541 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1542 uni_port.entity_id = entity_id
1543 uni_port.enabled = True
1544 uni_port.mac_bridge_port_num = mac_bridge_port_num
1545
1546 self.log.debug("created-uni-port", uni=uni_port)
1547
Matt Jeanneretc083f462019-03-11 15:02:01 -04001548 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001549
1550 self._unis[uni_port.port_number] = uni_port
1551
1552 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301553 uni_ports=self.uni_ports,
1554 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001555
Matt Jeanneretc083f462019-03-11 15:02:01 -04001556 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1557 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001558 MAX_PONS_PER_OLT = 256
1559 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001560 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001561
Matt Jeanneretc083f462019-03-11 15:02:01 -04001562 assert intf_id < MAX_PONS_PER_OLT
1563 assert onu_id < MAX_ONUS_PER_PON
1564 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001565 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001566
1567 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001568 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001569 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001570 try:
1571 device = yield self.core_proxy.get_device(self.device_id)
1572 parent_device = yield self.core_proxy.get_device(self.parent_id)
1573 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001574 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001575
1576 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301577 pon_id=self._onu_indication.intf_id,
1578 onu_id=self._onu_indication.onu_id,
1579 registration_id=self.device_id,
1580 device_id=self.device_id,
1581 onu_serial_number=device.serial_number,
1582 olt_serial_number=olt_serial_number,
1583 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001584
Devmalya Paulffc89df2019-07-31 17:43:13 -04001585 self.log.debug("Trying-to-raise-onu-active-event")
1586 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001587 self._onu_indication.intf_id,
1588 device.serial_number,
1589 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301590 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001591 onu_id=self._onu_indication.onu_id).send(True)
1592 except Exception as active_event_error:
1593 self.log.exception('onu-activated-event-error',
1594 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001595
1596 def lock_ports(self, lock=True):
1597
1598 def success(response):
1599 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1600
1601 def failure(response):
1602 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1603
1604 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1605 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1606 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001607
1608 def extract_tp_id_from_path(self, tp_path):
1609 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
1610 tp_id = int ( tp_path.split ( _PATH_SEPERATOR)[1] )
1611 return tp_id