Nicolas Palpacuer | e761c90 | 2018-07-05 16:30:52 -0400 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 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 | from voltha.protos.events_pb2 import KpiEvent, MetricValuePairs |
| 17 | from voltha.protos.events_pb2 import KpiEventType |
| 18 | import voltha.adapters.openolt.openolt_platform as platform |
| 19 | |
| 20 | class OpenOltStatisticsMgr(object): |
| 21 | def __init__(self, openolt_device, log): |
| 22 | self.device = openolt_device |
| 23 | self.log = log |
| 24 | |
| 25 | def port_statistics_indication(self, port_stats): |
| 26 | self.log.info('port-stats-collected', stats=port_stats) |
| 27 | self.ports_statistics_kpis(port_stats) |
| 28 | #FIXME: etcd problem, do not update objects for now |
| 29 | |
| 30 | # |
| 31 | # |
| 32 | # #FIXME : only the first uplink is a logical port |
| 33 | # if port_stats.intf_id == 128: |
| 34 | # # ONOS update |
| 35 | # self.update_logical_port_stats(port_stats) |
| 36 | # # FIXME: Discard other uplinks, they do not exist as an object |
| 37 | # if port_stats.intf_id in [129, 130, 131]: |
| 38 | # self.log.debug('those uplinks are not created') |
| 39 | # return |
| 40 | # # update port object stats |
| 41 | # port = self.device.adapter_agent.get_port(self.device.device_id, |
| 42 | # port_no=port_stats.intf_id) |
| 43 | # |
| 44 | # if port is None: |
| 45 | # self.log.warn('port associated with this stats does not exist') |
| 46 | # return |
| 47 | # |
| 48 | # port.rx_packets = port_stats.rx_packets |
| 49 | # port.rx_bytes = port_stats.rx_bytes |
| 50 | # port.rx_errors = port_stats.rx_error_packets |
| 51 | # port.tx_packets = port_stats.tx_packets |
| 52 | # port.tx_bytes = port_stats.tx_bytes |
| 53 | # port.tx_errors = port_stats.tx_error_packets |
| 54 | # |
| 55 | # # Add port does an update if port exists |
| 56 | # self.device.adapter_agent.add_port(self.device.device_id, port) |
| 57 | |
| 58 | def flow_statistics_indication(self, flow_stats): |
| 59 | self.log.info('flow-stats-collected', stats=flow_stats) |
| 60 | # TODO: send to kafka ? |
| 61 | # FIXME: etcd problem, do not update objects for now |
| 62 | # # UNTESTED : the openolt driver does not yet provide flow stats |
Nicolas Palpacuer | 324dcae | 2018-08-02 11:12:22 -0400 | [diff] [blame] | 63 | # self.device.adapter_agent.update_flow_stats( |
| 64 | # self.device.logical_device_id, |
| 65 | # flow_id=flow_stats.flow_id, packet_count=flow_stats.tx_packets, |
| 66 | # byte_count=flow_stats.tx_bytes) |
Nicolas Palpacuer | e761c90 | 2018-07-05 16:30:52 -0400 | [diff] [blame] | 67 | |
| 68 | def ports_statistics_kpis(self, port_stats): |
| 69 | pm_data = {} |
| 70 | pm_data["rx_bytes"] = port_stats.rx_bytes |
| 71 | pm_data["rx_packets"] = port_stats.rx_packets |
| 72 | pm_data["rx_ucast_packets"] = port_stats.rx_ucast_packets |
| 73 | pm_data["rx_mcast_packets"] = port_stats.rx_mcast_packets |
| 74 | pm_data["rx_bcast_packets"] = port_stats.rx_bcast_packets |
| 75 | pm_data["rx_error_packets"] = port_stats.rx_error_packets |
| 76 | pm_data["tx_bytes"] = port_stats.tx_bytes |
| 77 | pm_data["tx_packets"] = port_stats.tx_packets |
| 78 | pm_data["tx_ucast_packets"] = port_stats.tx_ucast_packets |
| 79 | pm_data["tx_mcast_packets"] = port_stats.tx_mcast_packets |
| 80 | pm_data["tx_bcast_packets"] = port_stats.tx_bcast_packets |
| 81 | pm_data["tx_error_packets"] = port_stats.tx_error_packets |
| 82 | pm_data["rx_crc_errors"] = port_stats.rx_crc_errors |
| 83 | pm_data["bip_errors"] = port_stats.bip_errors |
| 84 | |
| 85 | |
| 86 | prefix = 'voltha.openolt.{}'.format(self.device.device_id) |
| 87 | # FIXME |
| 88 | if port_stats.intf_id < 132: |
| 89 | prefixes = { |
| 90 | prefix + 'nni.{}'.format(port_stats.intf_id): MetricValuePairs( |
| 91 | metrics=pm_data) |
| 92 | } |
| 93 | else: |
| 94 | prefixes = { |
| 95 | prefix + '.pon.{}'.format(platform.intf_id_from_pon_port_no( |
| 96 | port_stats.intf_id)): MetricValuePairs( |
| 97 | metrics=pm_data) |
| 98 | } |
| 99 | |
| 100 | kpi_event = KpiEvent( |
| 101 | type=KpiEventType.slice, |
| 102 | ts=port_stats.timestamp, |
| 103 | prefixes=prefixes) |
| 104 | self.device.adapter_agent.submit_kpis(kpi_event) |
| 105 | |
| 106 | def update_logical_port_stats(self, port_stats): |
| 107 | # FIXME |
| 108 | label = 'nni-{}'.format(port_stats.intf_id) |
| 109 | try: |
| 110 | logical_port = self.device.adapter_agent.get_logical_port( |
| 111 | self.device.logical_device_id, label) |
| 112 | except KeyError as e: |
| 113 | self.log.warn('logical port was not found, it may not have been ' |
| 114 | 'created yet', exception=e) |
| 115 | return |
| 116 | |
| 117 | if logical_port is None: |
| 118 | self.log.error('logical-port-is-None', |
| 119 | logical_device_id=self.device.logical_device_id, label=label, |
| 120 | port_stats=port_stats) |
| 121 | return |
| 122 | |
| 123 | |
| 124 | logical_port.ofp_port_stats.rx_packets = port_stats.rx_packets |
| 125 | logical_port.ofp_port_stats.rx_bytes = port_stats.rx_bytes |
| 126 | logical_port.ofp_port_stats.tx_packets = port_stats.tx_packets |
| 127 | logical_port.ofp_port_stats.tx_bytes = port_stats.tx_bytes |
| 128 | logical_port.ofp_port_stats.rx_errors = port_stats.rx_error_packets |
| 129 | logical_port.ofp_port_stats.tx_errors = port_stats.tx_error_packets |
| 130 | logical_port.ofp_port_stats.rx_crc_err = port_stats.rx_crc_errors |
| 131 | |
| 132 | self.log.debug('after-stats-update', port=logical_port) |
| 133 | |
| 134 | self.device.adapter_agent.update_logical_port( |
| 135 | self.device.logical_device_id, logical_port) |