blob: b3f951006867c6577a9aeb6549c220ed9e8fea3a [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)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800370 #TODO: revisit for multi tconts support
371 new_tconts = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500372 tcontdict = dict()
373 tcontdict['alloc-id'] = alloc_id
374 tcontdict['q_sched_policy'] = q_sched_policy
375 tcontdict['uni_id'] = uni_id
376
Matt Jeanneret3789d0d2020-01-19 09:03:42 -0500377 tcont = OnuTCont.create(self, tcont=tcontdict)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500378
379 self._pon.add_tcont(tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800380 new_tconts.append(tcont)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500381 self.log.debug('pon-add-tcont', tcont=tcont)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800382 return new_tconts
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500383
384 # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
385 def _create_gemports(self, uni_id, gem_ports, alloc_id_ref, direction):
386 self.log.debug('create-gemport',
387 gem_ports=gem_ports, direction=direction)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530388 new_gem_ports = []
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500389 for gem_port in gem_ports:
390 gemdict = dict()
391 gemdict['gemport_id'] = gem_port['gemport_id']
392 gemdict['direction'] = direction
393 gemdict['alloc_id_ref'] = alloc_id_ref
394 gemdict['encryption'] = gem_port['aes_encryption']
395 gemdict['discard_config'] = dict()
396 gemdict['discard_config']['max_probability'] = \
397 gem_port['discard_config']['max_probability']
398 gemdict['discard_config']['max_threshold'] = \
399 gem_port['discard_config']['max_threshold']
400 gemdict['discard_config']['min_threshold'] = \
401 gem_port['discard_config']['min_threshold']
402 gemdict['discard_policy'] = gem_port['discard_policy']
403 gemdict['max_q_size'] = gem_port['max_q_size']
404 gemdict['pbit_map'] = gem_port['pbit_map']
405 gemdict['priority_q'] = gem_port['priority_q']
406 gemdict['scheduling_policy'] = gem_port['scheduling_policy']
407 gemdict['weight'] = gem_port['weight']
408 gemdict['uni_id'] = uni_id
409
410 gem_port = OnuGemPort.create(self, gem_port=gemdict)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530411 new_gem_ports.append(gem_port)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500412
413 self._pon.add_gem_port(gem_port)
414
415 self.log.debug('pon-add-gemport', gem_port=gem_port)
416
Girish Gowdrae933cd32019-11-21 21:04:41 +0530417 return new_gem_ports
418
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800419 def _execute_queued_vlan_filter_tasks(self, uni_id, tp_id):
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400420 # During OLT Reboots, ONU Reboots, ONU Disable/Enable, it is seen that vlan_filter
421 # task is scheduled even before tp task. So we queue vlan-filter task if tp_task
422 # or initial-mib-download is not done. Once the tp_task is completed, we execute
423 # such queued vlan-filter tasks
424 try:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800425 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 -0400426 self.log.info("executing-queued-vlan-filter-task",
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800427 uni_id=uni_id, tp_id=tp_id)
Mahir Gunyela982ec32020-02-25 12:30:37 -0800428 for filter_info in self._queued_vlan_filter_task[uni_id][tp_id]:
429 reactor.callLater(0, self._add_vlan_filter_task, filter_info.get("device"),
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800430 uni_id=uni_id, uni_port=filter_info.get("uni_port"),
431 match_vlan = filter_info.get("match_vlan"),
432 _set_vlan_vid= filter_info.get("set_vlan_vid"),
433 _set_vlan_pcp = filter_info.get("set_vlan_pcp"),
434 tp_id = filter_info.get("tp_id"))
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400435 # Now remove the entry from the dictionary
Mahir Gunyela982ec32020-02-25 12:30:37 -0800436 self._queued_vlan_filter_task[uni_id][tp_id].remove(filter_info)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400437 self.log.debug("executed-queued-vlan-filter-task",
Mahir Gunyela982ec32020-02-25 12:30:37 -0800438 uni_id=uni_id, tp_id=tp_id)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400439 except Exception as e:
440 self.log.error("vlan-filter-configuration-failed", uni_id=uni_id, error=e)
441
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500442 def _do_tech_profile_configuration(self, uni_id, tp):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500443 us_scheduler = tp['us_scheduler']
444 alloc_id = us_scheduler['alloc_id']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800445 new_tconts = self._create_tconts(uni_id, us_scheduler)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500446 upstream_gem_port_attribute_list = tp['upstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800447 new_upstream_gems = self._create_gemports(uni_id, upstream_gem_port_attribute_list, alloc_id, "UPSTREAM")
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500448 downstream_gem_port_attribute_list = tp['downstream_gem_port_attribute_list']
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800449 new_downstream_gems = self._create_gemports(uni_id, downstream_gem_port_attribute_list, alloc_id, "DOWNSTREAM")
450
451 new_gems = []
452 new_gems.extend(new_upstream_gems)
453 new_gems.extend(new_downstream_gems)
454
455 return new_tconts, new_gems
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500456
457 def load_and_configure_tech_profile(self, uni_id, tp_path):
458 self.log.debug("loading-tech-profile-configuration", uni_id=uni_id, tp_path=tp_path)
Mahir Gunyele9110a32020-02-20 14:56:50 -0800459 tp_id = self.extract_tp_id_from_path(tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500460 if uni_id not in self._tp_service_specific_task:
461 self._tp_service_specific_task[uni_id] = dict()
462
463 if uni_id not in self._tech_profile_download_done:
464 self._tech_profile_download_done[uni_id] = dict()
465
Mahir Gunyele9110a32020-02-20 14:56:50 -0800466 if tp_id not in self._tech_profile_download_done[uni_id]:
467 self._tech_profile_download_done[uni_id][tp_id] = False
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500468
Mahir Gunyele9110a32020-02-20 14:56:50 -0800469 if not self._tech_profile_download_done[uni_id][tp_id]:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500470 try:
471 if tp_path in self._tp_service_specific_task[uni_id]:
472 self.log.info("tech-profile-config-already-in-progress",
Girish Gowdrae933cd32019-11-21 21:04:41 +0530473 tp_path=tp_path)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500474 return
475
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -0500476 tpstored = self.kv_client[tp_path]
477 tpstring = tpstored.decode('ascii')
478 tp = json.loads(tpstring)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530479
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500480 self.log.debug("tp-instance", tp=tp)
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800481 tconts, gem_ports = self._do_tech_profile_configuration(uni_id, tp)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -0700482
William Kurkian3a206332019-04-29 11:05:47 -0400483 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500484 def success(_results):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800485 self.log.info("tech-profile-config-done-successfully", uni_id=uni_id, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500486 if tp_path in self._tp_service_specific_task[uni_id]:
487 del self._tp_service_specific_task[uni_id][tp_path]
Mahir Gunyele9110a32020-02-20 14:56:50 -0800488 self._tech_profile_download_done[uni_id][tp_id] = True
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400489 # Now execute any vlan filter tasks that were queued for later
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800490 reactor.callInThread(self._execute_queued_vlan_filter_tasks, uni_id, tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500491 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-download-success')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530492
William Kurkian3a206332019-04-29 11:05:47 -0400493 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500494 def failure(_reason):
Mahir Gunyel5afa9542020-02-23 22:54:04 -0800495 self.log.warn('tech-profile-config-failure-retrying', uni_id=uni_id, tp_id=tp_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +0530496 _reason=_reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500497 if tp_path in self._tp_service_specific_task[uni_id]:
498 del self._tp_service_specific_task[uni_id][tp_path]
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500499 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
500 reactor.callLater(retry, self.load_and_configure_tech_profile,
501 uni_id, tp_path)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500502 yield self.core_proxy.device_reason_update(self.device_id,
503 'tech-profile-config-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500504
Mahir Gunyela982ec32020-02-25 12:30:37 -0800505 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530506 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
507
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500508 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800509 BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500510 self._deferred = \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530511 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500512 self._deferred.addCallbacks(success, failure)
513
514 except Exception as e:
515 self.log.exception("error-loading-tech-profile", e=e)
516 else:
517 self.log.info("tech-profile-config-already-done")
Girish Gowdrae933cd32019-11-21 21:04:41 +0530518 # Could be a case where TP exists but new gem-ports are getting added dynamically
519 tpstored = self.kv_client[tp_path]
520 tpstring = tpstored.decode('ascii')
521 tp = json.loads(tpstring)
522 upstream_gems = []
523 downstream_gems = []
524 # Find out the new Gem ports that are getting added afresh.
525 for gp in tp['upstream_gem_port_attribute_list']:
526 if self.pon_port.gem_port(gp['gemport_id'], "upstream"):
527 # gem port already exists
528 continue
529 upstream_gems.append(gp)
530 for gp in tp['downstream_gem_port_attribute_list']:
531 if self.pon_port.gem_port(gp['gemport_id'], "downstream"):
532 # gem port already exists
533 continue
534 downstream_gems.append(gp)
535
536 us_scheduler = tp['us_scheduler']
537 alloc_id = us_scheduler['alloc_id']
538
539 if len(upstream_gems) > 0 or len(downstream_gems) > 0:
540 self.log.info("installing-new-gem-ports", upstream_gems=upstream_gems, downstream_gems=downstream_gems)
541 new_upstream_gems = self._create_gemports(uni_id, upstream_gems, alloc_id, "UPSTREAM")
542 new_downstream_gems = self._create_gemports(uni_id, downstream_gems, alloc_id, "DOWNSTREAM")
543 new_gems = []
544 new_gems.extend(new_upstream_gems)
545 new_gems.extend(new_downstream_gems)
546
547 def success(_results):
548 self.log.info("new-gem-ports-successfully-installed", result=_results)
549
550 def failure(_reason):
551 self.log.warn('new-gem-port-install-failed--retrying',
552 _reason=_reason)
553 # Remove gem ports from cache. We will re-add them during the retry
554 for gp in new_gems:
555 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
556
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500557 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
558 reactor.callLater(retry, self.load_and_configure_tech_profile,
559 uni_id, tp_path)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530560
561 self._tp_service_specific_task[uni_id][tp_path] = \
Mahir Gunyele9110a32020-02-20 14:56:50 -0800562 BrcmTpSetupTask(self.omci_agent, self, uni_id, [], new_gems, tp_id)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530563 self._deferred = \
564 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
565 self._deferred.addCallbacks(success, failure)
566
567 def delete_tech_profile(self, uni_id, tp_path, alloc_id=None, gem_port_id=None):
568 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800569 tp_table_id = self.extract_tp_id_from_path(tp_path)
Naga Manjunathe433c712020-01-02 17:27:20 +0530570 if not uni_id in self._tech_profile_download_done:
571 self.log.warn("tp-key-is-not-present", uni_id=uni_id)
572 return
573
Mahir Gunyele9110a32020-02-20 14:56:50 -0800574 if not tp_table_id in self._tech_profile_download_done[uni_id]:
575 self.log.warn("tp-id-is-not-present", uni_id=uni_id, tp_id=tp_table_id)
Naga Manjunathe433c712020-01-02 17:27:20 +0530576 return
577
Mahir Gunyele9110a32020-02-20 14:56:50 -0800578 if self._tech_profile_download_done[uni_id][tp_table_id] is not True:
579 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 +0530580 return
581
582 if alloc_id is None and gem_port_id is None:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800583 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 +0530584 return
585
586 # Extract the current set of TCONT and GEM Ports from the Handler's pon_port that are
587 # relevant to this task's UNI. It won't change. But, the underlying pon_port may change
588 # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
589 # this initializer
590 tcont = None
591 self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
592 for tc in list(self.pon_port.tconts.values()):
593 if tc.alloc_id == alloc_id:
594 tcont = tc
595 self.pon_port.remove_tcont(tc.alloc_id, False)
596
597 gem_port = None
598 self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
599 for gp in list(self.pon_port.gem_ports.values()):
600 if gp.gem_id == gem_port_id:
601 gem_port = gp
602 self.pon_port.remove_gem_id(gp.gem_id, gp.direction, False)
603
Girish Gowdrae933cd32019-11-21 21:04:41 +0530604 @inlineCallbacks
605 def success(_results):
606 if gem_port_id:
607 self.log.info("gem-port-delete-done-successfully")
608 if alloc_id:
609 self.log.info("tcont-delete-done-successfully")
610 # The deletion of TCONT marks the complete deletion of tech-profile
611 try:
Mahir Gunyele9110a32020-02-20 14:56:50 -0800612 del self._tech_profile_download_done[uni_id][tp_table_id]
Girish Gowdrae933cd32019-11-21 21:04:41 +0530613 del self._tp_service_specific_task[uni_id][tp_path]
614 except Exception as ex:
615 self.log.error("del-tp-state-info", e=ex)
616
617 # TODO: There could be multiple TP on the UNI, and also the ONU.
618 # TODO: But the below reason updates for the whole device.
619 yield self.core_proxy.device_reason_update(self.device_id, 'tech-profile-config-delete-success')
620
621 @inlineCallbacks
Girish Gowdraa73ee452019-12-20 18:52:17 +0530622 def failure(_reason):
Girish Gowdrae933cd32019-11-21 21:04:41 +0530623 self.log.warn('tech-profile-delete-failure-retrying',
624 _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500625 retry = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
626 reactor.callLater(retry, self.delete_tech_profile, uni_id, tp_path, alloc_id, gem_port_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -0500627 yield self.core_proxy.device_reason_update(self.device_id,
628 'tech-profile-config-delete-failure-retrying')
Girish Gowdrae933cd32019-11-21 21:04:41 +0530629
630 self.log.info('deleting-tech-profile-configuration')
631
Girish Gowdraa73ee452019-12-20 18:52:17 +0530632 if tcont is None and gem_port is None:
633 if alloc_id is not None:
634 self.log.error("tcont-info-corresponding-to-alloc-id-not-found", alloc_id=alloc_id)
635 if gem_port_id is not None:
636 self.log.error("gem-port-info-corresponding-to-gem-port-id-not-found", gem_port_id=gem_port_id)
637 return
638
Girish Gowdrae933cd32019-11-21 21:04:41 +0530639 self._tp_service_specific_task[uni_id][tp_path] = \
640 BrcmTpDeleteTask(self.omci_agent, self, uni_id, tp_table_id,
641 tcont=tcont, gem_port=gem_port)
642 self._deferred = \
643 self._onu_omci_device.task_runner.queue_task(self._tp_service_specific_task[uni_id][tp_path])
644 self._deferred.addCallbacks(success, failure)
645 except Exception as e:
646 self.log.exception("failed-to-delete-tp",
647 e=e, uni_id=uni_id, tp_path=tp_path,
648 alloc_id=alloc_id, gem_port_id=gem_port_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500649
650 def update_pm_config(self, device, pm_config):
651 # TODO: This has not been tested
652 self.log.info('update_pm_config', pm_config=pm_config)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -0500653 self._pm_metrics.update(pm_config)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500654
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800655 def remove_onu_flows(self, device, flows):
656 self.log.debug('remove_onu_flows', device_id=device.id)
657
658
659 # no point in removing omci flows if the device isnt reachable
660 if device.connect_status != ConnectStatus.REACHABLE or \
661 device.admin_state != AdminState.ENABLED:
662 self.log.warn("device-disabled-or-offline-skipping-remove-flow",
663 admin=device.admin_state, connect=device.connect_status)
664 return
665
666 for flow in flows:
667 # if incoming flow contains cookie, then remove from ONU
668 if flow.cookie:
669 self.log.debug("remove-flow", device_id=device.id, flow=flow)
670
671 def is_downstream(port):
672 return port == self._pon_port_number
673
674 def is_upstream(port):
675 return not is_downstream(port)
676
677 try:
678 _in_port = fd.get_in_port(flow)
679 assert _in_port is not None
680
681 _out_port = fd.get_out_port(flow) # may be None
682 _vlan_vid = fd.get_default_vlan(flow)
683
684 if is_downstream(_in_port):
685 self.log.debug('downstream-flow-no-need-to-remove', in_port=_in_port, out_port=_out_port,
686 device_id=device.id)
687 # extended vlan tagging operation will handle it
688 continue
689 elif is_upstream(_in_port):
690 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
691 if fd.is_dhcp_flow(flow):
692 self.log.debug('The dhcp trap-to-host flow will be discarded', device_id=device.id)
693 return
694
695 uni_port = self.uni_port(_in_port)
696 uni_id = _in_port & 0xF
697 else:
698 raise Exception('port should be 1 or 2 by our convention')
699
700 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
701
702 tp_id = self.get_tp_id_in_flow(flow)
703 # Deleting flow from ONU.
704 self._remove_vlan_filter_task(device, uni_id, uni_port=uni_port, _set_vlan_vid=_vlan_vid,
705 match_vlan=_vlan_vid, tp_id=tp_id)
706 #TODO:Delete TD task.
707 except Exception as e:
708 self.log.exception('failed-to-remove-flow', e=e)
709
710 def add_onu_flows(self, device, flows):
711 self.log.debug('function-entry', flows=flows)
712
713 #
714 # We need to proxy through the OLT to get to the ONU
715 # Configuration from here should be using OMCI
716 #
717 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
718
719 # no point in pushing omci flows if the device isnt reachable
720 if device.connect_status != ConnectStatus.REACHABLE or \
721 device.admin_state != AdminState.ENABLED:
722 self.log.warn("device-disabled-or-offline-skipping-flow-update",
723 admin=device.admin_state, connect=device.connect_status)
724 return
725 def is_downstream(port):
726 return port == self._pon_port_number
727
728 def is_upstream(port):
729 return not is_downstream(port)
730
731 for flow in flows:
732 # if incoming flow contains cookie, then add to ONU
733 if flow.cookie:
734 _type = None
735 _port = None
736 _vlan_vid = None
737 _udp_dst = None
738 _udp_src = None
739 _ipv4_dst = None
740 _ipv4_src = None
741 _metadata = None
742 _output = None
743 _push_tpid = None
744 _field = None
745 _set_vlan_vid = None
746 _set_vlan_pcp = 0
747 _tunnel_id = None
748 self.log.debug("add-flow", device_id=device.id, flow=flow)
749
750 try:
751 _in_port = fd.get_in_port(flow)
752 assert _in_port is not None
753
754 _out_port = fd.get_out_port(flow) # may be None
755 tp_id = self.get_tp_id_in_flow(flow)
756 if is_downstream(_in_port):
757 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
758 # NOTE: We don't care downstream flow because we will copy vlan_id to upstream flow
759 # uni_port = self.uni_port(_out_port)
760 # uni_id = _out_port & 0xF
761 continue
762 elif is_upstream(_in_port):
763 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
764 uni_port = self.uni_port(_in_port)
765 uni_id = _in_port & 0xF
766 else:
767 raise Exception('port should be 1 or 2 by our convention')
768
769 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
770
771 for field in fd.get_ofb_fields(flow):
772 if field.type == fd.ETH_TYPE:
773 _type = field.eth_type
774 self.log.debug('field-type-eth-type',
775 eth_type=_type)
776
777 elif field.type == fd.IP_PROTO:
778 _proto = field.ip_proto
779 self.log.debug('field-type-ip-proto',
780 ip_proto=_proto)
781
782 elif field.type == fd.IN_PORT:
783 _port = field.port
784 self.log.debug('field-type-in-port',
785 in_port=_port)
786 elif field.type == fd.TUNNEL_ID:
787 self.log.debug('field-type-tunnel-id')
788
789 elif field.type == fd.VLAN_VID:
790 _vlan_vid = field.vlan_vid & 0xfff
791 self.log.debug('field-type-vlan-vid',
792 vlan=_vlan_vid)
793
794 elif field.type == fd.VLAN_PCP:
795 _vlan_pcp = field.vlan_pcp
796 self.log.debug('field-type-vlan-pcp',
797 pcp=_vlan_pcp)
798
799 elif field.type == fd.UDP_DST:
800 _udp_dst = field.udp_dst
801 self.log.debug('field-type-udp-dst',
802 udp_dst=_udp_dst)
803
804 elif field.type == fd.UDP_SRC:
805 _udp_src = field.udp_src
806 self.log.debug('field-type-udp-src',
807 udp_src=_udp_src)
808
809 elif field.type == fd.IPV4_DST:
810 _ipv4_dst = field.ipv4_dst
811 self.log.debug('field-type-ipv4-dst',
812 ipv4_dst=_ipv4_dst)
813
814 elif field.type == fd.IPV4_SRC:
815 _ipv4_src = field.ipv4_src
816 self.log.debug('field-type-ipv4-src',
817 ipv4_dst=_ipv4_src)
818
819 elif field.type == fd.METADATA:
820 _metadata = field.table_metadata
821 self.log.debug('field-type-metadata',
822 metadata=_metadata)
823
824 else:
825 raise NotImplementedError('field.type={}'.format(
826 field.type))
827
828 for action in fd.get_actions(flow):
829
830 if action.type == fd.OUTPUT:
831 _output = action.output.port
832 self.log.debug('action-type-output',
833 output=_output, in_port=_in_port)
834
835 elif action.type == fd.POP_VLAN:
836 self.log.debug('action-type-pop-vlan',
837 in_port=_in_port)
838
839 elif action.type == fd.PUSH_VLAN:
840 _push_tpid = action.push.ethertype
841 self.log.debug('action-type-push-vlan',
842 push_tpid=_push_tpid, in_port=_in_port)
843 if action.push.ethertype != 0x8100:
844 self.log.error('unhandled-tpid',
845 ethertype=action.push.ethertype)
846
847 elif action.type == fd.SET_FIELD:
848 _field = action.set_field.field.ofb_field
849 assert (action.set_field.field.oxm_class ==
850 OFPXMC_OPENFLOW_BASIC)
851 self.log.debug('action-type-set-field',
852 field=_field, in_port=_in_port)
853 if _field.type == fd.VLAN_VID:
854 _set_vlan_vid = _field.vlan_vid & 0xfff
855 self.log.debug('set-field-type-vlan-vid',
856 vlan_vid=_set_vlan_vid)
857 elif _field.type == fd.VLAN_PCP:
858 _set_vlan_pcp = _field.vlan_pcp
859 self.log.debug('set-field-type-vlan-pcp',
860 vlan_pcp=_set_vlan_pcp)
861 else:
862 self.log.error('unsupported-action-set-field-type',
863 field_type=_field.type)
864 else:
865 self.log.error('unsupported-action-type',
866 action_type=action.type, in_port=_in_port)
867
Mahir Gunyel9dfab822020-02-20 15:52:15 -0800868 if _set_vlan_vid is None or _set_vlan_vid == 0:
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800869 self.log.warn('ignorning-flow-that-does-not-set-vlanid')
870 else:
871 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)
872 self._add_vlan_filter_task(device, uni_id=uni_id, uni_port=uni_port,
873 _set_vlan_vid=_set_vlan_vid,
874 _set_vlan_pcp=_set_vlan_pcp, match_vlan=_vlan_vid,
875 tp_id=tp_id)
876
877 except Exception as e:
878 self.log.exception('failed-to-install-flow', e=e, flow=flow)
879
880
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500881 # Calling this assumes the onu is active/ready and had at least an initial mib downloaded. This gets called from
882 # flow decomposition that ultimately comes from onos
883 def update_flow_table(self, device, flows):
Matteo Scandolod8d73172019-11-26 12:15:15 -0700884 self.log.debug('update-flow-table', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500885
886 #
887 # We need to proxy through the OLT to get to the ONU
888 # Configuration from here should be using OMCI
889 #
890 # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
891
892 # no point in pushing omci flows if the device isnt reachable
893 if device.connect_status != ConnectStatus.REACHABLE or \
Girish Gowdrae933cd32019-11-21 21:04:41 +0530894 device.admin_state != AdminState.ENABLED:
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500895 self.log.warn("device-disabled-or-offline-skipping-flow-update",
896 admin=device.admin_state, connect=device.connect_status)
897 return
898
899 def is_downstream(port):
900 return port == self._pon_port_number
901
902 def is_upstream(port):
903 return not is_downstream(port)
904
905 for flow in flows:
906 _type = None
907 _port = None
908 _vlan_vid = None
909 _udp_dst = None
910 _udp_src = None
911 _ipv4_dst = None
912 _ipv4_src = None
913 _metadata = None
914 _output = None
915 _push_tpid = None
916 _field = None
917 _set_vlan_vid = None
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800918 _set_vlan_pcp = None
Matt Jeanneretef06d0d2019-04-27 17:36:53 -0400919 _tunnel_id = None
920
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500921 try:
Girish Gowdraa73ee452019-12-20 18:52:17 +0530922 write_metadata = fd.get_write_metadata(flow)
923 if write_metadata is None:
924 self.log.error("do-not-process-flow-without-write-metadata")
925 return
926
927 # extract tp id from flow
Mahir Gunyeld680cb62020-02-18 10:28:12 -0800928 tp_id= self.get_tp_id_in_flow(flow)
Matt Jeanneret08a8e862019-12-20 14:02:32 -0500929 self.log.debug("tp-id-in-flow", tp_id=tp_id)
Girish Gowdraa73ee452019-12-20 18:52:17 +0530930
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500931 _in_port = fd.get_in_port(flow)
932 assert _in_port is not None
933
934 _out_port = fd.get_out_port(flow) # may be None
935
936 if is_downstream(_in_port):
937 self.log.debug('downstream-flow', in_port=_in_port, out_port=_out_port)
938 uni_port = self.uni_port(_out_port)
Girish Gowdrae933cd32019-11-21 21:04:41 +0530939 uni_id = _out_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500940 elif is_upstream(_in_port):
941 self.log.debug('upstream-flow', in_port=_in_port, out_port=_out_port)
942 uni_port = self.uni_port(_in_port)
Chaitrashree G S8fb96782019-08-19 00:10:49 -0400943 uni_id = _in_port & 0xF
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500944 else:
945 raise Exception('port should be 1 or 2 by our convention')
946
947 self.log.debug('flow-ports', in_port=_in_port, out_port=_out_port, uni_port=str(uni_port))
948
949 for field in fd.get_ofb_fields(flow):
950 if field.type == fd.ETH_TYPE:
951 _type = field.eth_type
952 self.log.debug('field-type-eth-type',
953 eth_type=_type)
954
955 elif field.type == fd.IP_PROTO:
956 _proto = field.ip_proto
957 self.log.debug('field-type-ip-proto',
958 ip_proto=_proto)
959
960 elif field.type == fd.IN_PORT:
961 _port = field.port
962 self.log.debug('field-type-in-port',
963 in_port=_port)
964
965 elif field.type == fd.VLAN_VID:
966 _vlan_vid = field.vlan_vid & 0xfff
967 self.log.debug('field-type-vlan-vid',
968 vlan=_vlan_vid)
969
970 elif field.type == fd.VLAN_PCP:
971 _vlan_pcp = field.vlan_pcp
972 self.log.debug('field-type-vlan-pcp',
973 pcp=_vlan_pcp)
974
975 elif field.type == fd.UDP_DST:
976 _udp_dst = field.udp_dst
977 self.log.debug('field-type-udp-dst',
978 udp_dst=_udp_dst)
979
980 elif field.type == fd.UDP_SRC:
981 _udp_src = field.udp_src
982 self.log.debug('field-type-udp-src',
983 udp_src=_udp_src)
984
985 elif field.type == fd.IPV4_DST:
986 _ipv4_dst = field.ipv4_dst
987 self.log.debug('field-type-ipv4-dst',
988 ipv4_dst=_ipv4_dst)
989
990 elif field.type == fd.IPV4_SRC:
991 _ipv4_src = field.ipv4_src
992 self.log.debug('field-type-ipv4-src',
993 ipv4_dst=_ipv4_src)
994
995 elif field.type == fd.METADATA:
996 _metadata = field.table_metadata
997 self.log.debug('field-type-metadata',
998 metadata=_metadata)
999
Matt Jeanneretef06d0d2019-04-27 17:36:53 -04001000 elif field.type == fd.TUNNEL_ID:
1001 _tunnel_id = field.tunnel_id
1002 self.log.debug('field-type-tunnel-id',
1003 tunnel_id=_tunnel_id)
1004
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001005 else:
1006 raise NotImplementedError('field.type={}'.format(
1007 field.type))
1008
1009 for action in fd.get_actions(flow):
1010
1011 if action.type == fd.OUTPUT:
1012 _output = action.output.port
1013 self.log.debug('action-type-output',
1014 output=_output, in_port=_in_port)
1015
1016 elif action.type == fd.POP_VLAN:
1017 self.log.debug('action-type-pop-vlan',
1018 in_port=_in_port)
1019
1020 elif action.type == fd.PUSH_VLAN:
1021 _push_tpid = action.push.ethertype
1022 self.log.debug('action-type-push-vlan',
1023 push_tpid=_push_tpid, in_port=_in_port)
1024 if action.push.ethertype != 0x8100:
1025 self.log.error('unhandled-tpid',
1026 ethertype=action.push.ethertype)
1027
1028 elif action.type == fd.SET_FIELD:
1029 _field = action.set_field.field.ofb_field
1030 assert (action.set_field.field.oxm_class ==
1031 OFPXMC_OPENFLOW_BASIC)
1032 self.log.debug('action-type-set-field',
1033 field=_field, in_port=_in_port)
1034 if _field.type == fd.VLAN_VID:
1035 _set_vlan_vid = _field.vlan_vid & 0xfff
1036 self.log.debug('set-field-type-vlan-vid',
1037 vlan_vid=_set_vlan_vid)
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001038 elif _field.type == fd.VLAN_PCP:
1039 _set_vlan_pcp = _field.vlan_pcp
1040 self.log.debug('set-field-type-vlan-pcp',
1041 vlan_pcp=_set_vlan_pcp)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001042 else:
1043 self.log.error('unsupported-action-set-field-type',
1044 field_type=_field.type)
1045 else:
1046 self.log.error('unsupported-action-type',
1047 action_type=action.type, in_port=_in_port)
1048
Matt Jeanneret810148b2019-09-29 12:44:01 -04001049 # OMCI set vlan task can only filter and set on vlan header attributes. Any other openflow
1050 # supported match and action criteria cannot be handled by omci and must be ignored.
1051 if _set_vlan_vid is None or _set_vlan_vid == 0:
1052 self.log.warn('ignoring-flow-that-does-not-set-vlanid')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001053 else:
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001054 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)
1055 self._add_vlan_filter_task(device, uni_id,
1056 uni_port=uni_port, match_vlan=_vlan_vid,
1057 _set_vlan_vid=_set_vlan_vid, _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001058 except Exception as e:
1059 self.log.exception('failed-to-install-flow', e=e, flow=flow)
1060
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001061 def _add_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1062 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1063 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 -05001064 assert uni_port is not None
Mahir Gunyele9110a32020-02-20 14:56:50 -08001065 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 -04001066 @inlineCallbacks
1067 def success(_results):
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001068 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 -05001069 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-pushed')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001070
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001071 @inlineCallbacks
1072 def failure(_reason):
Girish Gowdraa73ee452019-12-20 18:52:17 +05301073 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 -05001074 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001075 reactor.callLater(retry,
1076 self._add_vlan_filter_task, device, uni_id, uni_port=uni_port,
1077 match_vlan=match_vlan, _set_vlan_vid=_set_vlan_vid,
1078 _set_vlan_pcp=_set_vlan_pcp, tp_id=tp_id)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001079 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-failed-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001080
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001081 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)
1082 vlan_filter_add_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1083 match_vlan, _set_vlan_pcp, add_tag=True,
1084 tp_id=tp_id)
1085 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_filter_add_task)
Chaitrashree G S8fb96782019-08-19 00:10:49 -04001086 self._deferred.addCallbacks(success, failure)
1087 else:
1088 self.log.info('tp-service-specific-task-not-done-adding-request-to-local-cache',
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001089 uni_id=uni_id, tp_id=tp_id)
1090 if uni_id not in self._queued_vlan_filter_task:
1091 self._queued_vlan_filter_task[uni_id] = dict()
Mahir Gunyela982ec32020-02-25 12:30:37 -08001092 if tp_id not in self._queued_vlan_filter_task[uni_id]:
1093 self._queued_vlan_filter_task[uni_id][tp_id] = []
1094 self._queued_vlan_filter_task[uni_id][tp_id].append({"device": device,
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001095 "uni_id": uni_id,
1096 "uni_port": uni_port,
1097 "match_vlan": match_vlan,
1098 "set_vlan_vid": _set_vlan_vid,
1099 "set_vlan_pcp": _set_vlan_pcp,
Mahir Gunyela982ec32020-02-25 12:30:37 -08001100 "tp_id": tp_id})
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001101
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001102 def get_tp_id_in_flow(self, flow):
1103 flow_metadata = fd.get_metadata_from_write_metadata ( flow )
1104 tp_id = fd.get_tp_id_from_metadata ( flow_metadata )
1105 return tp_id
1106
1107 def _remove_vlan_filter_task(self, device, uni_id, uni_port=None, match_vlan=0,
1108 _set_vlan_vid=None, _set_vlan_pcp=8, tp_id=0):
1109 assert uni_port is not None
1110 @inlineCallbacks
1111 def success(_results):
1112 self.log.info('vlan-untagging-success', _results=_results)
1113 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deleted')
1114
1115 @inlineCallbacks
1116 def failure(_reason):
1117 self.log.warn('vlan-untagging-failure', _reason=_reason)
1118 yield self.core_proxy.device_reason_update(self.device_id, 'omci-flows-deletion-failed-retrying')
1119 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1120 reactor.callLater(retry,
1121 self._remove_vlan_filter_task, device, uni_id,
1122 add_tag=False, uni_port=uni_port)
1123
1124 self.log.info("remove_vlan_filter_task", tp_id=tp_id)
1125 vlan_remove_task = BrcmVlanFilterTask(self.omci_agent, self, uni_port, _set_vlan_vid,
1126 match_vlan, _set_vlan_pcp, add_tag=False,
1127 tp_id=tp_id)
1128 self._deferred = self._onu_omci_device.task_runner.queue_task(vlan_remove_task)
1129 self._deferred.addCallbacks(success, failure)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001130 def process_inter_adapter_message(self, request):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001131 self.log.debug('process-inter-adapter-message', type=request.header.type, from_topic=request.header.from_topic,
1132 to_topic=request.header.to_topic, to_device_id=request.header.to_device_id)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001133 try:
1134 if request.header.type == InterAdapterMessageType.OMCI_REQUEST:
1135 omci_msg = InterAdapterOmciMessage()
1136 request.body.Unpack(omci_msg)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001137 self.log.debug('inter-adapter-recv-omci', omci_msg=hexify(omci_msg.message))
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001138
Matt Jeannereta32441c2019-03-07 05:16:37 -05001139 self.receive_message(omci_msg.message)
1140
1141 elif request.header.type == InterAdapterMessageType.ONU_IND_REQUEST:
1142 onu_indication = OnuIndication()
1143 request.body.Unpack(onu_indication)
Matteo Scandolod8d73172019-11-26 12:15:15 -07001144 self.log.debug('inter-adapter-recv-onu-ind', onu_id=onu_indication.onu_id,
1145 oper_state=onu_indication.oper_state, admin_state=onu_indication.admin_state,
1146 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001147
1148 if onu_indication.oper_state == "up":
1149 self.create_interface(onu_indication)
Girish Gowdrae933cd32019-11-21 21:04:41 +05301150 elif onu_indication.oper_state == "down" or onu_indication.oper_state == "unreachable":
Matt Jeannereta32441c2019-03-07 05:16:37 -05001151 self.update_interface(onu_indication)
1152 else:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001153 self.log.error("unknown-onu-indication", onu_id=onu_indication.onu_id,
1154 serial_number=onu_indication.serial_number)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001155
Matt Jeanneret3bfebff2019-04-12 18:25:03 -04001156 elif request.header.type == InterAdapterMessageType.TECH_PROFILE_DOWNLOAD_REQUEST:
1157 tech_msg = InterAdapterTechProfileDownloadMessage()
1158 request.body.Unpack(tech_msg)
1159 self.log.debug('inter-adapter-recv-tech-profile', tech_msg=tech_msg)
1160
1161 self.load_and_configure_tech_profile(tech_msg.uni_id, tech_msg.path)
1162
Girish Gowdrae933cd32019-11-21 21:04:41 +05301163 elif request.header.type == InterAdapterMessageType.DELETE_GEM_PORT_REQUEST:
1164 del_gem_msg = InterAdapterDeleteGemPortMessage()
1165 request.body.Unpack(del_gem_msg)
1166 self.log.debug('inter-adapter-recv-del-gem', gem_del_msg=del_gem_msg)
1167
1168 self.delete_tech_profile(uni_id=del_gem_msg.uni_id,
1169 gem_port_id=del_gem_msg.gem_port_id,
1170 tp_path=del_gem_msg.tp_path)
1171
1172 elif request.header.type == InterAdapterMessageType.DELETE_TCONT_REQUEST:
1173 del_tcont_msg = InterAdapterDeleteTcontMessage()
1174 request.body.Unpack(del_tcont_msg)
1175 self.log.debug('inter-adapter-recv-del-tcont', del_tcont_msg=del_tcont_msg)
1176
1177 self.delete_tech_profile(uni_id=del_tcont_msg.uni_id,
1178 alloc_id=del_tcont_msg.alloc_id,
1179 tp_path=del_tcont_msg.tp_path)
Matt Jeannereta32441c2019-03-07 05:16:37 -05001180 else:
1181 self.log.error("inter-adapter-unhandled-type", request=request)
1182
1183 except Exception as e:
1184 self.log.exception("error-processing-inter-adapter-message", e=e)
1185
1186 # Called each time there is an onu "up" indication from the olt handler
1187 @inlineCallbacks
1188 def create_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001189 self.log.info('create-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001190 serial_number=onu_indication.serial_number)
Amit Ghosh028eb202020-02-17 13:34:00 +00001191
1192 # Ignore if onu_indication is received for an already running ONU
1193 if self._onu_omci_device is not None and self._onu_omci_device.active:
1194 self.log.warn('received-onu-indication-for-active-onu', onu_indication=onu_indication)
1195 return
1196
Matt Jeannereta32441c2019-03-07 05:16:37 -05001197 self._onu_indication = onu_indication
1198
Matt Jeanneretc083f462019-03-11 15:02:01 -04001199 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.ACTIVATING,
1200 connect_status=ConnectStatus.REACHABLE)
1201
Matt Jeannereta32441c2019-03-07 05:16:37 -05001202 onu_device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001203
1204 self.log.debug('starting-openomci-statemachine')
1205 self._subscribe_to_events()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001206 onu_device.reason = "starting-openomci"
Girish Gowdrae933cd32019-11-21 21:04:41 +05301207 reactor.callLater(1, self._onu_omci_device.start, onu_device)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001208 yield self.core_proxy.device_reason_update(self.device_id, onu_device.reason)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001209 self._heartbeat.enabled = True
1210
Matt Jeanneret42dad792020-02-01 09:28:27 -05001211 # Called each time there is an onu "down" indication from the olt handler
Matt Jeannereta32441c2019-03-07 05:16:37 -05001212 @inlineCallbacks
1213 def update_interface(self, onu_indication):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001214 self.log.info('update-interface', onu_id=onu_indication.onu_id,
Matteo Scandolod8d73172019-11-26 12:15:15 -07001215 serial_number=onu_indication.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001216
Chaitrashree G Sd73fb9b2019-09-09 20:27:30 -04001217 if onu_indication.oper_state == 'down' or onu_indication.oper_state == "unreachable":
Mahir Gunyeld680cb62020-02-18 10:28:12 -08001218 self.log.debug('stopping-openomci-statemachine', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001219 reactor.callLater(0, self._onu_omci_device.stop)
1220
1221 # Let TP download happen again
1222 for uni_id in self._tp_service_specific_task:
1223 self._tp_service_specific_task[uni_id].clear()
1224 for uni_id in self._tech_profile_download_done:
1225 self._tech_profile_download_done[uni_id].clear()
1226
Matt Jeanneretf4113222019-08-14 19:44:34 -04001227 yield self.disable_ports(lock_ports=False)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001228 yield self.core_proxy.device_reason_update(self.device_id, "stopping-openomci")
1229 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.DISCOVERED,
1230 connect_status=ConnectStatus.UNREACHABLE)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001231 else:
1232 self.log.debug('not-changing-openomci-statemachine')
1233
Matt Jeanneretf4113222019-08-14 19:44:34 -04001234 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001235 def disable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001236 self.log.info('disable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001237 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001238 yield self.disable_ports(lock_ports=True)
1239 yield self.core_proxy.device_reason_update(self.device_id, "omci-admin-lock")
1240 yield self.core_proxy.device_state_update(self.device_id, oper_status=OperStatus.UNKNOWN)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001241
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001242 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001243 self.log.exception('exception-in-onu-disable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001244
William Kurkian3a206332019-04-29 11:05:47 -04001245 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001246 def reenable(self, device):
Matt Jeanneret08a8e862019-12-20 14:02:32 -05001247 self.log.info('reenable', device_id=device.id, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001248 try:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001249 yield self.core_proxy.device_state_update(device.id,
1250 oper_status=OperStatus.ACTIVE,
1251 connect_status=ConnectStatus.REACHABLE)
1252 yield self.core_proxy.device_reason_update(self.device_id, 'onu-reenabled')
1253 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001254 except Exception as e:
Matteo Scandolod8d73172019-11-26 12:15:15 -07001255 self.log.exception('exception-in-onu-reenable', exception=e)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001256
William Kurkian3a206332019-04-29 11:05:47 -04001257 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001258 def reboot(self):
1259 self.log.info('reboot-device')
William Kurkian3a206332019-04-29 11:05:47 -04001260 device = yield self.core_proxy.get_device(self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001261 if device.connect_status != ConnectStatus.REACHABLE:
1262 self.log.error("device-unreachable")
1263 return
1264
William Kurkian3a206332019-04-29 11:05:47 -04001265 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001266 def success(_results):
1267 self.log.info('reboot-success', _results=_results)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001268 yield self.core_proxy.device_reason_update(self.device_id, 'rebooting')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001269
1270 def failure(_reason):
1271 self.log.info('reboot-failure', _reason=_reason)
1272
1273 self._deferred = self._onu_omci_device.reboot()
1274 self._deferred.addCallbacks(success, failure)
1275
William Kurkian3a206332019-04-29 11:05:47 -04001276 @inlineCallbacks
Matt Jeanneretf4113222019-08-14 19:44:34 -04001277 def disable_ports(self, lock_ports=True):
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001278 self.log.info('disable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001279
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001280 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1281 # load on the core
Matt Jeanneretf4113222019-08-14 19:44:34 -04001282 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001283 if port.mac_bridge_port_num == 1:
1284 port.operstatus = OperStatus.UNKNOWN
1285 self.log.info('disable-port', device_id=self.device_id, port=port)
1286 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 -04001287
1288 if lock_ports is True:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001289 self.lock_ports(lock=True)
1290
William Kurkian3a206332019-04-29 11:05:47 -04001291 @inlineCallbacks
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001292 def enable_ports(self):
1293 self.log.info('enable-ports', device_id=self.device_id)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001294
Matt Jeanneretf4113222019-08-14 19:44:34 -04001295 self.lock_ports(lock=False)
1296
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001297 # TODO: for now only support the first UNI given no requirement for multiple uni yet. Also needed to reduce flow
1298 # load on the core
1299 # Given by default all unis are initially active according to omci alarming, we must mimic this.
Matt Jeanneretf4113222019-08-14 19:44:34 -04001300 for port in self.uni_ports:
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001301 if port.mac_bridge_port_num == 1:
Matt Jeanneretf4113222019-08-14 19:44:34 -04001302 port.operstatus = OperStatus.ACTIVE
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001303 self.log.info('enable-port', device_id=self.device_id, port=port)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001304 yield self.core_proxy.port_state_update(self.device_id, Port.ETHERNET_UNI, port.port_number, port.operstatus)
1305
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001306
1307 # TODO: Normally we would want any uni ethernet link down or uni ethernet link up alarms to register in the core,
1308 # but practically olt provisioning cannot handle the churn of links up, down, then up again typical on startup.
1309 #
1310 # Basically the link state sequence:
1311 # 1) per omci default alarm state, all unis are initially up (no link down alarms received yet)
1312 # 2) a link state down alarm is received for all uni, given the lock command, and also because most unis have nothing plugged in
1313 # 3) a link state up alarm is received for the uni plugged in.
1314 #
1315 # Given the olt (BAL) has to provision all uni, de-provision all uni, and re-provision one uni in quick succession
1316 # and cannot (bug?), we have to skip this and leave uni ports as assumed active. Also all the link state activity
1317 # would have a ripple effect through the core to the controller as well. And is it really worth it?
1318 '''
Matt Jeanneretf4113222019-08-14 19:44:34 -04001319 @inlineCallbacks
1320 def port_state_handler(self, _topic, msg):
1321 self.log.info("port-state-change", _topic=_topic, msg=msg)
1322
1323 onu_id = msg['onu_id']
1324 port_no = msg['port_number']
1325 serial_number = msg['serial_number']
1326 port_status = msg['port_status']
1327 uni_port = self.uni_port(int(port_no))
1328
1329 self.log.debug("port-state-parsed-message", onu_id=onu_id, port_no=port_no, serial_number=serial_number,
1330 port_status=port_status)
1331
1332 if port_status is True:
1333 uni_port.operstatus = OperStatus.ACTIVE
1334 self.log.info('link-up', device_id=self.device_id, port=uni_port)
1335 else:
1336 uni_port.operstatus = OperStatus.UNKNOWN
1337 self.log.info('link-down', device_id=self.device_id, port=uni_port)
1338
1339 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 -05001340 '''
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001341
1342 # Called just before openomci state machine is started. These listen for events from selected state machines,
1343 # most importantly, mib in sync. Which ultimately leads to downloading the mib
1344 def _subscribe_to_events(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001345 self.log.debug('subscribe-to-events')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001346
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001347 bus = self._onu_omci_device.event_bus
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001348
1349 # OMCI MIB Database sync status
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001350 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1351 OnuDeviceEvents.MibDatabaseSyncEvent)
1352 self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
1353
1354 # OMCI Capabilities
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001355 topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1356 OnuDeviceEvents.OmciCapabilitiesEvent)
1357 self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
1358
Matt Jeanneretfc6cdef2020-02-14 10:14:36 -05001359 # TODO: these alarms seem to be unreliable depending on the environment
1360 # Listen for UNI link state alarms and set the oper_state based on that rather than assuming all UNI are up
1361 #topic = OnuDeviceEntry.event_bus_topic(self.device_id,
1362 # OnuDeviceEvents.PortEvent)
1363 #self._port_state_subscription = bus.subscribe(topic, self.port_state_handler)
1364
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001365 # Called when the mib is in sync
1366 def in_sync_handler(self, _topic, msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001367 self.log.debug('in-sync-handler', _topic=_topic, msg=msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001368 if self._in_sync_subscription is not None:
1369 try:
1370 in_sync = msg[IN_SYNC_KEY]
1371
1372 if in_sync:
1373 # Only call this once
1374 bus = self._onu_omci_device.event_bus
1375 bus.unsubscribe(self._in_sync_subscription)
1376 self._in_sync_subscription = None
1377
1378 # Start up device_info load
1379 self.log.debug('running-mib-sync')
1380 reactor.callLater(0, self._mib_in_sync)
1381
1382 except Exception as e:
1383 self.log.exception('in-sync', e=e)
1384
1385 def capabilties_handler(self, _topic, _msg):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001386 self.log.debug('capabilities-handler', _topic=_topic, msg=_msg)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001387 if self._capabilities_subscription is not None:
1388 self.log.debug('capabilities-handler-done')
1389
1390 # Mib is in sync, we can now query what we learned and actually start pushing ME (download) to the ONU.
1391 # Currently uses a basic mib download task that create a bridge with a single gem port and uni, only allowing EAP
1392 # Implement your own MibDownloadTask if you wish to setup something different by default
Matt Jeanneretc083f462019-03-11 15:02:01 -04001393 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001394 def _mib_in_sync(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001395 self.log.debug('mib-in-sync')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001396
1397 omci = self._onu_omci_device
1398 in_sync = omci.mib_db_in_sync
1399
Matt Jeanneretc083f462019-03-11 15:02:01 -04001400 device = yield self.core_proxy.get_device(self.device_id)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001401 yield self.core_proxy.device_reason_update(self.device_id, 'discovery-mibsync-complete')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001402
1403 if not self._dev_info_loaded:
1404 self.log.info('loading-device-data-from-mib', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1405
1406 omci_dev = self._onu_omci_device
1407 config = omci_dev.configuration
1408
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001409 try:
1410
1411 # sort the lists so we get consistent port ordering.
1412 ani_list = sorted(config.ani_g_entities) if config.ani_g_entities else []
1413 uni_list = sorted(config.uni_g_entities) if config.uni_g_entities else []
1414 pptp_list = sorted(config.pptp_entities) if config.pptp_entities else []
1415 veip_list = sorted(config.veip_entities) if config.veip_entities else []
1416
1417 if ani_list is None or (pptp_list is None and veip_list is None):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001418 self.log.warn("no-ani-or-unis")
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001419 yield self.core_proxy.device_reason_update(self.device_id, 'onu-missing-required-elements')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001420 raise Exception("onu-missing-required-elements")
1421
1422 # Currently logging the ani, pptp, veip, and uni for information purposes.
1423 # Actually act on the veip/pptp as its ME is the most correct one to use in later tasks.
1424 # And in some ONU the UNI-G list is incomplete or incorrect...
1425 for entity_id in ani_list:
1426 ani_value = config.ani_g_entities[entity_id]
1427 self.log.debug("discovered-ani", entity_id=entity_id, value=ani_value)
1428 # TODO: currently only one OLT PON port/ANI, so this works out. With NGPON there will be 2..?
1429 self._total_tcont_count = ani_value.get('total-tcont-count')
1430 self.log.debug("set-total-tcont-count", tcont_count=self._total_tcont_count)
1431
1432 for entity_id in uni_list:
1433 uni_value = config.uni_g_entities[entity_id]
1434 self.log.debug("discovered-uni", entity_id=entity_id, value=uni_value)
1435
1436 uni_entities = OrderedDict()
1437 for entity_id in pptp_list:
1438 pptp_value = config.pptp_entities[entity_id]
1439 self.log.debug("discovered-pptp", entity_id=entity_id, value=pptp_value)
1440 uni_entities[entity_id] = UniType.PPTP
1441
1442 for entity_id in veip_list:
1443 veip_value = config.veip_entities[entity_id]
1444 self.log.debug("discovered-veip", entity_id=entity_id, value=veip_value)
1445 uni_entities[entity_id] = UniType.VEIP
1446
1447 uni_id = 0
Matt Jeanneret2e3cb8d2019-11-16 09:22:41 -05001448 for entity_id, uni_type in uni_entities.items():
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001449 try:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001450 yield self._add_uni_port(device, entity_id, uni_id, uni_type)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001451 uni_id += 1
1452 except AssertionError as e:
1453 self.log.warn("could not add UNI", entity_id=entity_id, uni_type=uni_type, e=e)
1454
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001455 self._qos_flexibility = config.qos_configuration_flexibility or 0
1456 self._omcc_version = config.omcc_version or OMCCVersion.Unknown
1457
1458 if self._unis:
1459 self._dev_info_loaded = True
1460 else:
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001461 yield self.core_proxy.device_reason_update(self.device_id, 'no-usable-unis')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001462 self.log.warn("no-usable-unis")
1463 raise Exception("no-usable-unis")
1464
1465 except Exception as e:
1466 self.log.exception('device-info-load', e=e)
1467 self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self._mib_in_sync)
1468
1469 else:
1470 self.log.info('device-info-already-loaded', in_sync=in_sync, already_loaded=self._dev_info_loaded)
1471
1472 if self._dev_info_loaded:
Matt Jeanneretad9a0f12019-05-09 14:05:49 -04001473 if device.admin_state == AdminState.PREPROVISIONED or device.admin_state == AdminState.ENABLED:
Matt Jeanneretc083f462019-03-11 15:02:01 -04001474
1475 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001476 def success(_results):
1477 self.log.info('mib-download-success', _results=_results)
Matt Jeanneretc083f462019-03-11 15:02:01 -04001478 yield self.core_proxy.device_state_update(device.id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301479 oper_status=OperStatus.ACTIVE,
1480 connect_status=ConnectStatus.REACHABLE)
Mahir Gunyel0e6882a2019-10-16 17:02:39 -07001481 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-downloaded')
Matt Jeanneretf4113222019-08-14 19:44:34 -04001482 yield self.enable_ports()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001483 self._mib_download_task = None
Devmalya Paulffc89df2019-07-31 17:43:13 -04001484 yield self.onu_active_event()
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001485
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001486 # Start collecting stats from the device after a brief pause
1487 if not self._pm_metrics_started:
1488 self._pm_metrics_started = True
1489 pmstart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1490 reactor.callLater(pmstart, self._pm_metrics.start_collector)
1491
1492 # Start test requests after a brief pause
1493 if not self._test_request_started:
1494 self._test_request_started = True
1495 tststart = _STARTUP_RETRY_WAIT * (random.randint(1, 5))
1496 reactor.callLater(tststart, self._test_request.start_collector)
1497
Matt Jeanneretc083f462019-03-11 15:02:01 -04001498 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001499 def failure(_reason):
1500 self.log.warn('mib-download-failure-retrying', _reason=_reason)
Matt Jeanneret04ebe8f2020-01-26 01:05:23 -05001501 retry = _STARTUP_RETRY_WAIT * (random.randint(1,5))
1502 reactor.callLater(retry, self._mib_in_sync)
Matt Jeanneretd84c9072020-01-31 06:33:27 -05001503 yield self.core_proxy.device_reason_update(self.device_id, 'initial-mib-download-failure-retrying')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001504
Matt Jeanneretf4113222019-08-14 19:44:34 -04001505 # start by locking all the unis till mib sync and initial mib is downloaded
1506 # this way we can capture the port down/up events when we are ready
1507 self.lock_ports(lock=True)
1508
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001509 # Download an initial mib that creates simple bridge that can pass EAP. On success (above) finally set
1510 # the device to active/reachable. This then opens up the handler to openflow pushes from outside
1511 self.log.info('downloading-initial-mib-configuration')
1512 self._mib_download_task = BrcmMibDownloadTask(self.omci_agent, self)
1513 self._deferred = self._onu_omci_device.task_runner.queue_task(self._mib_download_task)
1514 self._deferred.addCallbacks(success, failure)
1515 else:
1516 self.log.info('admin-down-disabling')
1517 self.disable(device)
1518 else:
1519 self.log.info('device-info-not-loaded-skipping-mib-download')
1520
Matt Jeanneretc083f462019-03-11 15:02:01 -04001521 @inlineCallbacks
1522 def _add_uni_port(self, device, entity_id, uni_id, uni_type=UniType.PPTP):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001523 self.log.debug('add-uni-port')
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001524
Matt Jeanneretc083f462019-03-11 15:02:01 -04001525 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 -05001526
1527 # TODO: Some or parts of this likely need to move to UniPort. especially the format stuff
1528 uni_name = "uni-{}".format(uni_no)
1529
Girish Gowdrae933cd32019-11-21 21:04:41 +05301530 mac_bridge_port_num = uni_id + 1 # TODO +1 is only to test non-zero index
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001531
1532 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 -04001533 entity_id=entity_id, mac_bridge_port_num=mac_bridge_port_num, serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001534
1535 uni_port = UniPort.create(self, uni_name, uni_id, uni_no, uni_name, uni_type)
1536 uni_port.entity_id = entity_id
1537 uni_port.enabled = True
1538 uni_port.mac_bridge_port_num = mac_bridge_port_num
1539
1540 self.log.debug("created-uni-port", uni=uni_port)
1541
Matt Jeanneretc083f462019-03-11 15:02:01 -04001542 yield self.core_proxy.port_created(device.id, uni_port.get_port())
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001543
1544 self._unis[uni_port.port_number] = uni_port
1545
1546 self._onu_omci_device.alarm_synchronizer.set_alarm_params(onu_id=self._onu_indication.onu_id,
Girish Gowdrae933cd32019-11-21 21:04:41 +05301547 uni_ports=self.uni_ports,
1548 serial_number=device.serial_number)
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001549
Matt Jeanneretc083f462019-03-11 15:02:01 -04001550 # TODO NEW CORE: Figure out how to gain this knowledge from the olt. for now cheat terribly.
1551 def mk_uni_port_num(self, intf_id, onu_id, uni_id):
Amit Ghosh65400f12019-11-21 12:04:12 +00001552 MAX_PONS_PER_OLT = 256
1553 MAX_ONUS_PER_PON = 256
Matt Jeanneretc083f462019-03-11 15:02:01 -04001554 MAX_UNIS_PER_ONU = 16
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001555
Matt Jeanneretc083f462019-03-11 15:02:01 -04001556 assert intf_id < MAX_PONS_PER_OLT
1557 assert onu_id < MAX_ONUS_PER_PON
1558 assert uni_id < MAX_UNIS_PER_ONU
Amit Ghosh65400f12019-11-21 12:04:12 +00001559 return intf_id << 12 | onu_id << 4 | uni_id
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001560
1561 @inlineCallbacks
Devmalya Paulffc89df2019-07-31 17:43:13 -04001562 def onu_active_event(self):
Matteo Scandolod8d73172019-11-26 12:15:15 -07001563 self.log.debug('onu-active-event')
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001564 try:
1565 device = yield self.core_proxy.get_device(self.device_id)
1566 parent_device = yield self.core_proxy.get_device(self.parent_id)
1567 olt_serial_number = parent_device.serial_number
Devmalya Paulffc89df2019-07-31 17:43:13 -04001568 raised_ts = arrow.utcnow().timestamp
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001569
1570 self.log.debug("onu-indication-context-data",
Girish Gowdrae933cd32019-11-21 21:04:41 +05301571 pon_id=self._onu_indication.intf_id,
1572 onu_id=self._onu_indication.onu_id,
1573 registration_id=self.device_id,
1574 device_id=self.device_id,
1575 onu_serial_number=device.serial_number,
1576 olt_serial_number=olt_serial_number,
1577 raised_ts=raised_ts)
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001578
Devmalya Paulffc89df2019-07-31 17:43:13 -04001579 self.log.debug("Trying-to-raise-onu-active-event")
1580 OnuActiveEvent(self.events, self.device_id,
Devmalya Paul7e0be4a2019-05-08 05:18:04 -04001581 self._onu_indication.intf_id,
1582 device.serial_number,
1583 str(self.device_id),
Girish Gowdrae933cd32019-11-21 21:04:41 +05301584 olt_serial_number, raised_ts,
Devmalya Paulffc89df2019-07-31 17:43:13 -04001585 onu_id=self._onu_indication.onu_id).send(True)
1586 except Exception as active_event_error:
1587 self.log.exception('onu-activated-event-error',
1588 errmsg=active_event_error.message)
Matt Jeanneretf4113222019-08-14 19:44:34 -04001589
1590 def lock_ports(self, lock=True):
1591
1592 def success(response):
1593 self.log.debug('set-onu-ports-state', lock=lock, response=response)
1594
1595 def failure(response):
1596 self.log.error('cannot-set-onu-ports-state', lock=lock, response=response)
1597
1598 task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=lock)
1599 self._deferred = self._onu_omci_device.task_runner.queue_task(task)
1600 self._deferred.addCallbacks(success, failure)
Mahir Gunyele9110a32020-02-20 14:56:50 -08001601
1602 def extract_tp_id_from_path(self, tp_path):
1603 # tp_path is of the format <technology>/<table_id>/<uni_port_name>
1604 tp_id = int ( tp_path.split ( _PATH_SEPERATOR)[1] )
1605 return tp_id