blob: 4da58d87449c943250e8ead1dfd7621ca76845e6 [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
876 if type is not None and _vlan_vid is None:
877 self.log.warn('ignoring-flow-with-ethType', ethType=_type)
878 elif _set_vlan_vid is None or _set_vlan_vid == 0:
879 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
880 else:
881 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)
882 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
883 _set_vlan_vid=_set_vlan_vid,
884 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
885 tp_id=tp_id)
886
887 except Exception as e:
888 self.log.exception('failed-to-install-flow', e=e, flow=flow)
889
890
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500891 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
892 # flow decomposition that ultimately comes from onos
893 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700894 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500895
896 #
897 # We need to proxy through the OLT to get to the ONU
898 # Configuration from here should be using OMCI
899 #
900 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
901
902 # no point in pushing omci flows if the device isnt reachable
903 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530904 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500905 self.log.warn("device-disabled-or-offline-skipping-flow-update",
906 admin=device.admin_state, connect=device.connect_status)
907 return
908
909 def is_downstream(port):
910 return port == self._pon_port_number
911
912 def is_upstream(port):
913 return not is_downstream(port)
914
915 for flow in flows:
916 _type = None
917 _port = None
918 _vlan_vid = None
919 _udp_dst = None
920 _udp_src = None
921 _ipv4_dst = None
922 _ipv4_src = None
923 _metadata = None
924 _output = None
925 _push_tpid = None
926 _field = None
927 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800928 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400929 _tunnel_id = None
930
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500931 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530932 write_metadata = fd.get_write_metadata(flow)
933 if write_metadata is None:
934 self.log.error("do-not-process-flow-without-write-metadata")
935 return
936
937 # extract tp id from flow
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800938 tp_id= self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500939 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530940
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500941 _in_port = fd.get_in_port(flow)
942 assert _in_port is not None
943
944 _out_port = fd.get_out_port(flow) # may be None
945
946 if is_downstream(_in_port):
947 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
948 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530949 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500950 elif is_upstream(_in_port):
951 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
952 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400953 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500954 else:
955 raise Exception('port should be 1 or 2 by our convention')
956
957 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
958
959 for field in fd.get_ofb_fields(flow):
960 if field.type == fd.ETH_TYPE:
961 _type = field.eth_type
962 self.log.debug('field-type-eth-type',
963 eth_type=_type)
964
965 elif field.type == fd.IP_PROTO:
966 _proto = field.ip_proto
967 self.log.debug('field-type-ip-proto',
968 ip_proto=_proto)
969
970 elif field.type == fd.IN_PORT:
971 _port = field.port
972 self.log.debug('field-type-in-port',
973 in_port=_port)
974
975 elif field.type == fd.VLAN_VID:
976 _vlan_vid = field.vlan_vid & 0xfff
977 self.log.debug('field-type-vlan-vid',
978 vlan=_vlan_vid)
979
980 elif field.type == fd.VLAN_PCP:
981 _vlan_pcp = field.vlan_pcp
982 self.log.debug('field-type-vlan-pcp',
983 pcp=_vlan_pcp)
984
985 elif field.type == fd.UDP_DST:
986 _udp_dst = field.udp_dst
987 self.log.debug('field-type-udp-dst',
988 udp_dst=_udp_dst)
989
990 elif field.type == fd.UDP_SRC:
991 _udp_src = field.udp_src
992 self.log.debug('field-type-udp-src',
993 udp_src=_udp_src)
994
995 elif field.type == fd.IPV4_DST:
996 _ipv4_dst = field.ipv4_dst
997 self.log.debug('field-type-ipv4-dst',
998 ipv4_dst=_ipv4_dst)
999
1000 elif field.type == fd.IPV4_SRC:
1001 _ipv4_src = field.ipv4_src
1002 self.log.debug('field-type-ipv4-src',
1003 ipv4_dst=_ipv4_src)
1004
1005 elif field.type == fd.METADATA:
1006 _metadata = field.table_metadata
1007 self.log.debug('field-type-metadata',
1008 metadata=_metadata)
1009
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001010 elif field.type == fd.TUNNEL_ID:
1011 _tunnel_id = field.tunnel_id
1012 self.log.debug('field-type-tunnel-id',
1013 tunnel_id=_tunnel_id)
1014
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001015 else:
1016 raise NotImplementedError('field.type={}'.format(
1017 field.type))
1018
1019 for action in fd.get_actions(flow):
1020
1021 if action.type == fd.OUTPUT:
1022 _output = action.output.port
1023 self.log.debug('action-type-output',
1024 output=_output, in_port=_in_port)
1025
1026 elif action.type == fd.POP_VLAN:
1027 self.log.debug('action-type-pop-vlan',
1028 in_port=_in_port)
1029
1030 elif action.type == fd.PUSH_VLAN:
1031 _push_tpid = action.push.ethertype
1032 self.log.debug('action-type-push-vlan',
1033 push_tpid=_push_tpid, in_port=_in_port)
1034 if action.push.ethertype != 0x8100:
1035 self.log.error('unhandled-tpid',
1036 ethertype=action.push.ethertype)
1037
1038 elif action.type == fd.SET_FIELD:
1039 _field = action.set_field.field.ofb_field
1040 assert (action.set_field.field.oxm_class ==
1041 OFPXMC_OPENFLOW_BASIC)
1042 self.log.debug('action-type-set-field',
1043 field=_field, in_port=_in_port)
1044 if _field.type == fd.VLAN_VID:
1045 _set_vlan_vid = _field.vlan_vid & 0xfff
1046 self.log.debug('set-field-type-vlan-vid',
1047 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001048 elif _field.type == fd.VLAN_PCP:
1049 _set_vlan_pcp = _field.vlan_pcp
1050 self.log.debug('set-field-type-vlan-pcp',
1051 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001052 else:
1053 self.log.error('unsupported-action-set-field-type',
1054 field_type=_field.type)
1055 else:
1056 self.log.error('unsupported-action-type',
1057 action_type=action.type, in_port=_in_port)
1058
Matt Jeanneret810148b2019-09-29 12:44:01 -04001059 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1060 # supported match and action criteria cannot be handled by omci and must be ignored.
1061 if _set_vlan_vid is None or _set_vlan_vid == 0:
1062 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001063 else:
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001064 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)
1065 self._add_vlan_filter_task(device, uni_id,
1066 uni_port=uni_port, match_vlan=_vlan_vid,
1067 _set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001068 except Exception as e:
1069 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1070
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001071 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1072 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1073 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 -05001074 assert uni_port is not None
Mahir Gunyele9110a32020-02-20 14:56:50 -08001075 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 -04001076 @inlineCallbacks
1077 def success(_results):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001078 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 -05001079 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001080
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001081 @inlineCallbacks
1082 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301083 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 -05001084 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001085 reactor.callLater(retry,
1086 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1087 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1088 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001089 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001090
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001091 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)
1092 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1093 match_vlan, _set_vlan_pcp, add_tag=True,
1094 tp_id=tp_id)
1095 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001096 self._deferred.addCallbacks(success, failure)
1097 else:
1098 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001099 uni_id=uni_id, tp_id=tp_id)
1100 if uni_id not in self._queued_vlan_filter_task:
1101 self._queued_vlan_filter_task[uni_id] = dict()
1102 self._queued_vlan_filter_task[uni_id][tp_id] = {"device": device,
1103 "uni_id": uni_id,
1104 "uni_port": uni_port,
1105 "match_vlan": match_vlan,
1106 "set_vlan_vid": _set_vlan_vid,
1107 "set_vlan_pcp": _set_vlan_pcp,
1108 "tp_id": tp_id}
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001109
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001110 def get_tp_id_in_flow(self, flow):
1111 flow_metadata = fd.get_metadata_from_write_metadata ( flow )
1112 tp_id = fd.get_tp_id_from_metadata ( flow_metadata )
1113 return tp_id
1114
1115 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1116 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1117 assert uni_port is not None
1118 @inlineCallbacks
1119 def success(_results):
1120 self.log.info('vlan-untagging-success', _results=_results)
1121 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1122
1123 @inlineCallbacks
1124 def failure(_reason):
1125 self.log.warn('vlan-untagging-failure', _reason=_reason)
1126 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
1127 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1128 reactor.callLater(retry,
1129 self._remove_vlan_filter_task, device, uni_id,
1130 add_tag=False, uni_port=uni_port)
1131
1132 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1133 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1134 match_vlan, _set_vlan_pcp, add_tag=False,
1135 tp_id=tp_id)
1136 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1137 self._deferred.addCallbacks(success, failure)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001138 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001139 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1140 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001141 try:
1142 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1143 omci_msg = InterAdapterOmciMessage()
1144 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001145 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001146
Matt Jeannereta32441c2019-03-07 05:16:37 -05001147 self.receive_message(omci_msg.message)
1148
1149 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1150 onu_indication = OnuIndication()
1151 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001152 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1153 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1154 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001155
1156 if onu_indication.oper_state == "up":
1157 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301158 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001159 self.update_interface(onu_indication)
1160 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001161 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1162 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001163
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001164 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1165 tech_msg = InterAdapterTechProfileDownloadMessage()
1166 request.body.Unpack(tech_msg)
1167 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1168
1169 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1170
Girish Gowdrae933cd32019-11-21 21:04:41 +05301171 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1172 del_gem_msg = InterAdapterDeleteGemPortMessage()
1173 request.body.Unpack(del_gem_msg)
1174 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1175
1176 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1177 gem_port_id=del_gem_msg.gem_port_id,
1178 tp_path=del_gem_msg.tp_path)
1179
1180 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1181 del_tcont_msg = InterAdapterDeleteTcontMessage()
1182 request.body.Unpack(del_tcont_msg)
1183 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1184
1185 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1186 alloc_id=del_tcont_msg.alloc_id,
1187 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001188 else:
1189 self.log.error("inter-adapter-unhandled-type", request=request)
1190
1191 except Exception as e:
1192 self.log.exception("error-processing-inter-adapter-message", e=e)
1193
1194 # Called each time there is an onu "up" indication from the olt handler
1195 @inlineCallbacks
1196 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001197 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001198 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001199
1200 # Ignore if onu_indication is received for an already running ONU
1201 if self._onu_omci_device is not None and self._onu_omci_device.active:
1202 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1203 return
1204
Matt Jeannereta32441c2019-03-07 05:16:37 -05001205 self._onu_indication = onu_indication
1206
Matt Jeanneretc083f462019-03-11 15:02:01 -04001207 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1208 connect_status=ConnectStatus.REACHABLE)
1209
Matt Jeannereta32441c2019-03-07 05:16:37 -05001210 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001211
1212 self.log.debug('starting-openomci-statemachine')
1213 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001214 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301215 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001216 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001217 self._heartbeat.enabled = True
1218
Matt Jeanneret42dad792020-02-01 09:28:27 -05001219 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001220 @inlineCallbacks
1221 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001222 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001223 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001224
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001225 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001226 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001227 reactor.callLater(0, self._onu_omci_device.stop)
1228
1229 # Let TP download happen again
1230 for uni_id in self._tp_service_specific_task:
1231 self._tp_service_specific_task[uni_id].clear()
1232 for uni_id in self._tech_profile_download_done:
1233 self._tech_profile_download_done[uni_id].clear()
1234
Matt Jeanneretf4113222019-08-14 19:44:34 -04001235 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001236 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1237 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1238 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001239 else:
1240 self.log.debug('not-changing-openomci-statemachine')
1241
Matt Jeanneretf4113222019-08-14 19:44:34 -04001242 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001243 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001244 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001245 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001246 yield self.disable_ports(lock_ports=True)
1247 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1248 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001249
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001250 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001251 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001252
William Kurkian3a206332019-04-29 11:05:47 -04001253 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001254 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001255 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001256 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001257 yield self.core_proxy.device_state_update(device.id,
1258 oper_status=OperStatus.ACTIVE,
1259 connect_status=ConnectStatus.REACHABLE)
1260 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1261 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001262 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001263 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001264
William Kurkian3a206332019-04-29 11:05:47 -04001265 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001266 def reboot(self):
1267 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001268 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001269 if device.connect_status != ConnectStatus.REACHABLE:
1270 self.log.error("device-unreachable")
1271 return
1272
William Kurkian3a206332019-04-29 11:05:47 -04001273 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001274 def success(_results):
1275 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001276 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001277
1278 def failure(_reason):
1279 self.log.info('reboot-failure', _reason=_reason)
1280
1281 self._deferred = self._onu_omci_device.reboot()
1282 self._deferred.addCallbacks(success, failure)
1283
William Kurkian3a206332019-04-29 11:05:47 -04001284 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001285 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001286 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001287
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001288 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1289 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001290 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001291 if port.mac_bridge_port_num == 1:
1292 port.operstatus = OperStatus.UNKNOWN
1293 self.log.info('disable-port', device_id=self.device_id, port=port)
1294 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 -04001295
1296 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001297 self.lock_ports(lock=True)
1298
William Kurkian3a206332019-04-29 11:05:47 -04001299 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001300 def enable_ports(self):
1301 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001302
Matt Jeanneretf4113222019-08-14 19:44:34 -04001303 self.lock_ports(lock=False)
1304
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001305 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1306 # load on the core
1307 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001308 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001309 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001310 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001311 self.log.info('enable-port', device_id=self.device_id, port=port)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001312 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1313
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001314
1315 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1316 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1317 #
1318 # Basically the link state sequence:
1319 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1320 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1321 # 3) a link state up alarm is received for the uni plugged in.
1322 #
1323 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1324 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1325 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1326 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001327 @inlineCallbacks
1328 def port_state_handler(self, _topic, msg):
1329 self.log.info("port-state-change", _topic=_topic, msg=msg)
1330
1331 onu_id = msg['onu_id']
1332 port_no = msg['port_number']
1333 serial_number = msg['serial_number']
1334 port_status = msg['port_status']
1335 uni_port = self.uni_port(int(port_no))
1336
1337 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1338 port_status=port_status)
1339
1340 if port_status is True:
1341 uni_port.operstatus = OperStatus.ACTIVE
1342 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1343 else:
1344 uni_port.operstatus = OperStatus.UNKNOWN
1345 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1346
1347 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 -05001348 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001349
1350 # Called just before openomci state machine is started. These listen for events from selected state machines,
1351 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1352 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001353 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001354
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001355 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001356
1357 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001358 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1359 OnuDeviceEvents.MibDatabaseSyncEvent)
1360 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1361
1362 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001363 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1364 OnuDeviceEvents.OmciCapabilitiesEvent)
1365 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1366
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001367 # TODO: these alarms seem to be unreliable depending on the environment
1368 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
1369 #topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1370 # OnuDeviceEvents.PortEvent)
1371 #self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
1372
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001373 # Called when the mib is in sync
1374 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001375 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001376 if self._in_sync_subscription is not None:
1377 try:
1378 in_sync = msg[IN_SYNC_KEY]
1379
1380 if in_sync:
1381 # Only call this once
1382 bus = self._onu_omci_device.event_bus
1383 bus.unsubscribe(self._in_sync_subscription)
1384 self._in_sync_subscription = None
1385
1386 # Start up device_info load
1387 self.log.debug('running-mib-sync')
1388 reactor.callLater(0, self._mib_in_sync)
1389
1390 except Exception as e:
1391 self.log.exception('in-sync', e=e)
1392
1393 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001394 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001395 if self._capabilities_subscription is not None:
1396 self.log.debug('capabilities-handler-done')
1397
1398 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1399 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1400 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001401 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001402 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001403 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001404
1405 omci = self._onu_omci_device
1406 in_sync = omci.mib_db_in_sync
1407
Matt Jeanneretc083f462019-03-11 15:02:01 -04001408 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001409 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001410
1411 if not self._dev_info_loaded:
1412 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1413
1414 omci_dev = self._onu_omci_device
1415 config = omci_dev.configuration
1416
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001417 try:
1418
1419 # sort the lists so we get consistent port ordering.
1420 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1421 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1422 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1423 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1424
1425 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001426 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001427 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001428 raise Exception("onu-missing-required-elements")
1429
1430 # Currently logging the ani, pptp, veip, and uni for information purposes.
1431 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1432 # And in some ONU the UNI-G list is incomplete or incorrect...
1433 for entity_id in ani_list:
1434 ani_value = config.ani_g_entities[entity_id]
1435 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1436 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1437 self._total_tcont_count = ani_value.get('total-tcont-count')
1438 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1439
1440 for entity_id in uni_list:
1441 uni_value = config.uni_g_entities[entity_id]
1442 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1443
1444 uni_entities = OrderedDict()
1445 for entity_id in pptp_list:
1446 pptp_value = config.pptp_entities[entity_id]
1447 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1448 uni_entities[entity_id] = UniType.PPTP
1449
1450 for entity_id in veip_list:
1451 veip_value = config.veip_entities[entity_id]
1452 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1453 uni_entities[entity_id] = UniType.VEIP
1454
1455 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001456 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001457 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001458 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001459 uni_id += 1
1460 except AssertionError as e:
1461 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1462
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001463 self._qos_flexibility = config.qos_configuration_flexibility or 0
1464 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1465
1466 if self._unis:
1467 self._dev_info_loaded = True
1468 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001469 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001470 self.log.warn("no-usable-unis")
1471 raise Exception("no-usable-unis")
1472
1473 except Exception as e:
1474 self.log.exception('device-info-load', e=e)
1475 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1476
1477 else:
1478 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1479
1480 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001481 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001482
1483 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001484 def success(_results):
1485 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001486 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301487 oper_status=OperStatus.ACTIVE,
1488 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001489 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001490 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001491 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001492 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001493
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001494 # Start collecting stats from the device after a brief pause
1495 if not self._pm_metrics_started:
1496 self._pm_metrics_started = True
1497 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1498 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1499
1500 # Start test requests after a brief pause
1501 if not self._test_request_started:
1502 self._test_request_started = True
1503 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1504 reactor.callLater(tststart, self._test_request.start_collector)
1505
Matt Jeanneretc083f462019-03-11 15:02:01 -04001506 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001507 def failure(_reason):
1508 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001509 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1510 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001511 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001512
Matt Jeanneretf4113222019-08-14 19:44:34 -04001513 # start by locking all the unis till mib sync and initial mib is downloaded
1514 # this way we can capture the port down/up events when we are ready
1515 self.lock_ports(lock=True)
1516
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001517 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1518 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1519 self.log.info('downloading-initial-mib-configuration')
1520 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1521 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1522 self._deferred.addCallbacks(success, failure)
1523 else:
1524 self.log.info('admin-down-disabling')
1525 self.disable(device)
1526 else:
1527 self.log.info('device-info-not-loaded-skipping-mib-download')
1528
Matt Jeanneretc083f462019-03-11 15:02:01 -04001529 @inlineCallbacks
1530 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001531 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001532
Matt Jeanneretc083f462019-03-11 15:02:01 -04001533 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 -05001534
1535 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1536 uni_name = "uni-{}".format(uni_no)
1537
Girish Gowdrae933cd32019-11-21 21:04:41 +05301538 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001539
1540 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 -04001541 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001542
1543 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1544 uni_port.entity_id = entity_id
1545 uni_port.enabled = True
1546 uni_port.mac_bridge_port_num = mac_bridge_port_num
1547
1548 self.log.debug("created-uni-port", uni=uni_port)
1549
Matt Jeanneretc083f462019-03-11 15:02:01 -04001550 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001551
1552 self._unis[uni_port.port_number] = uni_port
1553
1554 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301555 uni_ports=self.uni_ports,
1556 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001557
Matt Jeanneretc083f462019-03-11 15:02:01 -04001558 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1559 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001560 MAX_PONS_PER_OLT = 256
1561 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001562 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001563
Matt Jeanneretc083f462019-03-11 15:02:01 -04001564 assert intf_id < MAX_PONS_PER_OLT
1565 assert onu_id < MAX_ONUS_PER_PON
1566 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001567 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001568
1569 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001570 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001571 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001572 try:
1573 device = yield self.core_proxy.get_device(self.device_id)
1574 parent_device = yield self.core_proxy.get_device(self.parent_id)
1575 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001576 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001577
1578 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301579 pon_id=self._onu_indication.intf_id,
1580 onu_id=self._onu_indication.onu_id,
1581 registration_id=self.device_id,
1582 device_id=self.device_id,
1583 onu_serial_number=device.serial_number,
1584 olt_serial_number=olt_serial_number,
1585 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001586
Devmalya Paulffc89df2019-07-31 17:43:13 -04001587 self.log.debug("Trying-to-raise-onu-active-event")
1588 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001589 self._onu_indication.intf_id,
1590 device.serial_number,
1591 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301592 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001593 onu_id=self._onu_indication.onu_id).send(True)
1594 except Exception as active_event_error:
1595 self.log.exception('onu-activated-event-error',
1596 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001597
1598 def lock_ports(self, lock=True):
1599
1600 def success(response):
1601 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1602
1603 def failure(response):
1604 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1605
1606 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1607 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1608 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001609
1610 def extract_tp_id_from_path(self, tp_path):
1611 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
1612 tp_id = int ( tp_path.split ( _PATH_SEPERATOR)[1] )
1613 return tp_id