blob: 0e2af4f8f188e23a5e0be089c8587e31cfd53049 [file] [log] [blame]
Chip Boling67b674a2019-02-08 11:42:18 -06001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import arrow
William Kurkianede82e92019-03-05 13:02:57 -050016from voltha_protos.device_pb2 import PmConfig, PmGroupConfig
17from voltha_protos.events_pb2 import MetricInformation, MetricMetaData
Devmalya Paul0d3abf02019-07-31 18:34:27 -040018from pyvoltha.adapters.extensions.events.kpi.adapter_pm_metrics import AdapterPmMetrics
19from pyvoltha.adapters.extensions.events.kpi.onu.onu_pm_interval_metrics import OnuPmIntervalMetrics
Chip Boling67b674a2019-02-08 11:42:18 -060020from pyvoltha.adapters.extensions.omci.omci_entities import UniG
21from pyvoltha.adapters.extensions.omci.omci_entities import PptpEthernetUni
22
23
24class OnuOmciPmMetrics(AdapterPmMetrics):
25 """ ONU OMCI related metrics """
26
27 # Metric default settings
28 #
29 # Frequency values are in 1/10ths of a second
30 #
31 OMCI_DEV_KEY = 'omci-onu-dev'
32 OMCI_CC_GROUP_NAME = 'OMCI_CC'
33 DEFAULT_OMCI_CC_ENABLED = False
34 DEFAULT_OMCI_CC_FREQUENCY = (2 * 60) * 10
35
36 OPTICAL_GROUP_NAME = 'PON_Optical'
37 DEFAULT_OPTICAL_ENABLED = True
38 DEFAULT_OPTICAL_FREQUENCY = (15 * 60 * 10)
39
40 UNI_STATUS_GROUP_NAME = 'UNI_Status'
41 DEFAULT_UNI_STATUS_ENABLED = True
42 DEFAULT_UNI_STATUS_FREQUENCY = (15 * 60 * 10)
43
Devmalya Paul0d3abf02019-07-31 18:34:27 -040044 def __init__(self, event_mgr, core_proxy, device_id, logical_device_id, serial_number,
Chip Boling67b674a2019-02-08 11:42:18 -060045 grouped=False, freq_override=False, **kwargs):
46 """
47 Initializer for shared ONU Device Adapter OMCI CC PM metrics
48
William Kurkian6eda8182019-05-03 15:51:54 -040049 :param core_proxy: (CoreProxy) Core proxy for the device
Chip Boling67b674a2019-02-08 11:42:18 -060050 :param device_id: (str) Device ID
51 :param logical_device_id: (str) VOLTHA Logical Device ID
52 :param grouped: (bool) Flag indicating if statistics are managed as a group
53 :param freq_override: (bool) Flag indicating if frequency collection can be specified
54 on a per group basis
55 :param kwargs: (dict) Device Adapter specific values. For an ONU Device adapter, the
56 expected key-value pairs are listed below. If not provided, the
57 associated PM statistics are not gathered:
58
59 'omci-onu-dev': Reference to the OMCI OnuDeviceEtnry object for
60 retrieval of OpenOMCI Communications channel statistics
61 and retrieval of polled statistics.
62 """
Devmalya Paul0d3abf02019-07-31 18:34:27 -040063 super(OnuOmciPmMetrics, self).__init__(event_mgr, core_proxy, device_id, logical_device_id, serial_number,
Chip Boling67b674a2019-02-08 11:42:18 -060064 grouped=grouped, freq_override=freq_override,
65 **kwargs)
66
67 self._omci_onu_device = kwargs.pop(OnuOmciPmMetrics.OMCI_DEV_KEY, None)
68 self._omci_cc = self._omci_onu_device.omci_cc if self._omci_onu_device is not None else None
69
70 self.omci_cc_pm_names = {
71 ('tx_frames', PmConfig.COUNTER),
72 ('tx_errors', PmConfig.COUNTER),
73 ('rx_frames', PmConfig.COUNTER),
74 ('rx_unknown_tid', PmConfig.COUNTER),
75 ('rx_onu_frames', PmConfig.COUNTER), # Rx ONU autonomous messages
76 ('rx_unknown_me', PmConfig.COUNTER), # Managed Entities without a decode definition
77 ('rx_timeouts', PmConfig.COUNTER),
78 ('rx_late', PmConfig.COUNTER),
79 ('consecutive_errors', PmConfig.COUNTER),
80 ('reply_min', PmConfig.GAUGE), # Milliseconds
81 ('reply_max', PmConfig.GAUGE), # Milliseconds
82 ('reply_average', PmConfig.GAUGE), # Milliseconds
83 ('hp_tx_queue_len', PmConfig.GAUGE),
84 ('lp_tx_queue_len', PmConfig.GAUGE),
85 ('max_hp_tx_queue', PmConfig.GAUGE),
86 ('max_lp_tx_queue', PmConfig.GAUGE),
87 }
88 self.omci_cc_metrics_config = {m: PmConfig(name=m, type=t, enabled=True)
89 for (m, t) in self.omci_cc_pm_names}
90
91 self.omci_optical_pm_names = {
92 ('intf_id', PmConfig.CONTEXT),
93
94 ('transmit_power', PmConfig.GAUGE),
95 ('receive_power', PmConfig.GAUGE),
96 }
97 self.omci_optical_metrics_config = {m: PmConfig(name=m, type=t, enabled=True)
98 for (m, t) in self.omci_optical_pm_names}
99
100 self.omci_uni_pm_names = {
101 ('intf_id', PmConfig.CONTEXT),
102
103 ('ethernet_type', PmConfig.GAUGE), # PPTP Ethernet ME
104 ('oper_status', PmConfig.GAUGE), # PPTP Ethernet ME
105 ('pptp_admin_state', PmConfig.GAUGE), # PPTP Ethernet ME
106 ('uni_admin_state', PmConfig.GAUGE), # UNI-G ME
107 }
108 self.omci_uni_metrics_config = {m: PmConfig(name=m, type=t, enabled=True)
109 for (m, t) in self.omci_uni_pm_names}
110
Devmalya Paul0d3abf02019-07-31 18:34:27 -0400111 self.openomci_interval_pm = OnuPmIntervalMetrics(event_mgr, core_proxy, device_id, logical_device_id,
Yongjie Zhang415a2962019-07-03 15:46:50 -0400112 serial_number)
Chip Boling67b674a2019-02-08 11:42:18 -0600113
114 def update(self, pm_config):
115 # TODO: Test frequency override capability for a particular group
116 if self.default_freq != pm_config.default_freq:
117 # Update the callback to the new frequency.
118 self.default_freq = pm_config.default_freq
119 self.lc.stop()
120 self.lc.start(interval=self.default_freq / 10)
121
122 if pm_config.grouped:
123 for group in pm_config.groups:
124 group_config = self.pm_group_metrics.get(group.group_name)
125 if group_config is not None:
126 group_config.enabled = group.enabled
127 else:
128 msg = 'There are on independent OMCI metrics, only group metrics at this time'
129 raise NotImplemented(msg)
130
131 self.openomci_interval_pm.update(pm_config)
132
133 def make_proto(self, pm_config=None):
134 assert pm_config is not None
135
136 # OMCI only supports grouped metrics
137 if self._omci_onu_device is None or not self.grouped:
138 return pm_config
139
140 pm_omci_cc_stats = PmGroupConfig(group_name=OnuOmciPmMetrics.OMCI_CC_GROUP_NAME,
141 group_freq=OnuOmciPmMetrics.DEFAULT_OMCI_CC_FREQUENCY,
142 enabled=OnuOmciPmMetrics.DEFAULT_OMCI_CC_ENABLED)
143 self.pm_group_metrics[pm_omci_cc_stats.group_name] = pm_omci_cc_stats
144
145 pm_omci_optical_stats = PmGroupConfig(group_name=OnuOmciPmMetrics.OPTICAL_GROUP_NAME,
146 group_freq=OnuOmciPmMetrics.DEFAULT_OPTICAL_FREQUENCY,
147 enabled=OnuOmciPmMetrics.DEFAULT_OPTICAL_ENABLED)
148 self.pm_group_metrics[pm_omci_optical_stats.group_name] = pm_omci_optical_stats
149
150 pm_omci_uni_stats = PmGroupConfig(group_name=OnuOmciPmMetrics.UNI_STATUS_GROUP_NAME,
151 group_freq=OnuOmciPmMetrics.DEFAULT_UNI_STATUS_FREQUENCY,
152 enabled=OnuOmciPmMetrics.DEFAULT_UNI_STATUS_ENABLED)
153 self.pm_group_metrics[pm_omci_uni_stats.group_name] = pm_omci_uni_stats
154
155 stats_and_config = [(pm_omci_cc_stats, self.omci_cc_metrics_config),
156 (pm_omci_optical_stats, self.omci_optical_metrics_config),
157 (pm_omci_uni_stats, self.omci_cc_metrics_config)]
158
159 for stats, config in stats_and_config:
160 for m in sorted(config):
161 pm = config[m]
162 stats.metrics.extend([PmConfig(name=pm.name,
163 type=pm.type,
164 enabled=pm.enabled)])
165 pm_config.groups.extend([stats])
166
167 # Also create OMCI Interval PM configs
168 return self.openomci_interval_pm.make_proto(pm_config)
169
170 def collect_metrics(self, data=None):
171 """
172 Collect metrics for this adapter.
173
174 The data collected (or passed in) is a list of pairs/tuples. Each
175 pair is composed of a MetricMetaData metadata-portion and list of MetricValuePairs
176 that contains a single individual metric or list of metrics if this is a
177 group metric.
178
179 This method is called for each adapter at a fixed frequency.
180 TODO: Currently all group metrics are collected on a single timer tick.
181 This needs to be fixed as independent group or instance collection is
182 desirable.
183
184 :param data: (list) Existing list of collected metrics (MetricInformation).
185 This is provided to allow derived classes to call into
186 further encapsulated classes.
187
188 :return: (list) metadata and metrics pairs - see description above
189 """
190 if data is None:
191 data = list()
192
193 # Note: Interval PM is collection done autonomously, not through this method
194
195 if self._omci_cc is not None:
196 group_name = OnuOmciPmMetrics.OMCI_CC_GROUP_NAME
197 if self.pm_group_metrics[group_name].enabled:
198 group_data = self.collect_group_metrics(group_name,
199 self._omci_cc,
200 self.omci_cc_pm_names,
201 self.omci_cc_metrics_config)
202 if group_data is not None:
203 data.append(group_data)
204
205 # Optical and UNI data is collected on a per-port basis
206 data.extend(self.collect_optical_metrics())
207 data.extend(self.collect_uni_status_metrics())
208
209 return data
210
211 def collect_optical_metrics(self):
212 """
213 Collect the metrics for optical information from all ANI/PONs
214
215 :return: (list) collected metrics (MetricInformation)
216 """
217 now = self._omci_onu_device.timestamp
218
219 group_name = OnuOmciPmMetrics.OPTICAL_GROUP_NAME
220 if now is None or not self.pm_group_metrics[group_name].enabled:
221 return []
222
223 # Scan all ANI-G ports
224 ani_g_entities = self._omci_onu_device.configuration.ani_g_entities
225 ani_g_entities_ids = ani_g_entities.keys() if ani_g_entities is not None else None
226 metrics_info = []
227
228 if ani_g_entities_ids is not None and len(ani_g_entities_ids):
229 from pyvoltha.adapters.extensions.omci.omci_entities import AniG
230 ani_g_items = ['optical_signal_level', 'transmit_optical_level']
231
232 for entity_id in ani_g_entities_ids:
233 metrics = dict()
234 data = self._omci_onu_device.query_mib(class_id=AniG.class_id,
235 instance_id=entity_id,
236 attributes=ani_g_items)
237 if len(data):
238 if 'optical_signal_level' in data:
239 metrics['receive_power'] = data['optical_signal_level']
240
241 if 'transmit_optical_level' in data:
242 metrics['transmit_power'] = data['transmit_optical_level']
243
244 if len(metrics):
245 metric_data = MetricInformation(metadata=MetricMetaData(title=group_name,
246 ts=now,
247 logical_device_id=self.logical_device_id,
248 serial_no=self.serial_number,
249 device_id=self.device_id,
250 context={
251 'intf_id': str(entity_id)
252 }),
253 metrics=metrics)
254 metrics_info.append(metric_data)
255
256 return metrics_info
257
258 def collect_uni_status_metrics(self):
259 """
260 Collect the metrics for optical information from all ANI/PONs
261
262 :return: (list) collected metrics (MetricInformation)
263 """
264 now = self._omci_onu_device.timestamp
265
266 group_name = OnuOmciPmMetrics.UNI_STATUS_GROUP_NAME
267 if now is None or not self.pm_group_metrics[group_name].enabled:
268 return []
269
270 # Scan all UNI-G and PPTP ports
271 uni_g_entities = self._omci_onu_device.configuration.uni_g_entities
272 uni_g_entities_ids = uni_g_entities.keys() if uni_g_entities is not None else None
273 pptp_entities = self._omci_onu_device.configuration.pptp_entities
274 pptp_entities_ids = pptp_entities.keys() if pptp_entities is not None else None
275
276 metrics_info = []
277
278 if uni_g_entities_ids and pptp_entities_ids and len(uni_g_entities_ids) and \
279 len(uni_g_entities_ids) <= len(pptp_entities_ids):
280
281 uni_g_items = ['administrative_state']
282 pptp_items = ['administrative_state', 'operational_state', 'sensed_type']
283
284 for entity_id in pptp_entities_ids:
285 metrics = dict()
286 data = self._omci_onu_device.query_mib(class_id=UniG.class_id,
287 instance_id=entity_id,
288 attributes=uni_g_items)
289 if len(data):
290 if 'administrative_state' in data:
291 metrics['uni_admin_state'] = data['administrative_state']
292
293 data = self._omci_onu_device.query_mib(class_id=PptpEthernetUni.class_id,
294 instance_id=entity_id,
295 attributes=pptp_items)
296 if len(data):
297 if 'administrative_state' in data:
298 metrics['pptp_admin_state'] = data['administrative_state']
299
300 if 'operational_state' in data:
301 metrics['oper_status'] = data['operational_state']
302
303 if 'sensed_type' in data:
304 metrics['ethernet_type'] = data['sensed_type']
305
306 if len(metrics):
307 metric_data = MetricInformation(metadata=MetricMetaData(title=group_name,
308 ts=now,
309 logical_device_id=self.logical_device_id,
310 serial_no=self.serial_number,
311 device_id=self.device_id,
312 context={
313 'intf_id': str(entity_id & 0xFF)
314 }),
315 metrics=metrics)
316 metrics_info.append(metric_data)
317
318 return metrics_info