Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 2 | * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 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 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package pmmgr provides the utilities to manage onu metrics |
| 18 | package pmmgr |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 22 | "encoding/json" |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 23 | "fmt" |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 24 | "math" |
| 25 | "sync" |
| 26 | "time" |
| 27 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 28 | "github.com/looplab/fsm" |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 29 | omci "github.com/opencord/omci-lib-go/v2" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 30 | me "github.com/opencord/omci-lib-go/v2/generated" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 31 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 32 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 34 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 36 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 37 | ) |
| 38 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 39 | // events of L2 PM FSM |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 40 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 41 | L2PmEventInit = "L2PmEventInit" |
| 42 | L2PmEventTick = "L2PmEventTick" |
| 43 | L2PmEventSuccess = "L2PmEventSuccess" |
| 44 | L2PmEventFailure = "L2PmEventFailure" |
| 45 | L2PmEventAddMe = "L2PmEventAddMe" |
| 46 | L2PmEventDeleteMe = "L2PmEventDeleteMe" |
| 47 | L2PmEventStop = "L2PmEventStop" |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 48 | ) |
| 49 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 50 | // states of L2 PM FSM |
| 51 | const ( |
| 52 | L2PmStNull = "L2PmStNull" |
| 53 | L2PmStStarting = "L2PmStStarting" |
| 54 | L2PmStSyncTime = "L2PmStSyncTime" |
| 55 | L2PmStIdle = "L2PmStIdle" |
| 56 | L2PmStCreatePmMe = "L2PmStCreatePm" |
| 57 | L2PmStDeletePmMe = "L2PmStDeletePmMe" |
| 58 | L2PmStCollectData = "L2PmStCollectData" |
| 59 | ) |
| 60 | |
| 61 | // CL2PmFsmIdleState - TODO: add comment |
| 62 | const CL2PmFsmIdleState = L2PmStIdle |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 63 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 64 | // general constants used for overall Metric Collection management |
| 65 | const ( |
| 66 | DefaultMetricCollectionFrequency = 15 * 60 // unit in seconds. This setting can be changed from voltha NBI PmConfig configuration |
| 67 | GroupMetricEnabled = true // This is READONLY and cannot be changed from VOLTHA NBI |
| 68 | DefaultFrequencyOverrideEnabled = true // This is READONLY and cannot be changed from VOLTHA NBI |
| 69 | FrequencyGranularity = 5 // The frequency (in seconds) has to be multiple of 5. This setting cannot changed later. |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 70 | MaxTimeForPmFsmShutDown = 120 // in seconds |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 71 | ) |
| 72 | |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 73 | // constants for ethernet frame extended pm collection |
| 74 | const ( |
| 75 | ExtendedPmCreateAttempts = 3 |
| 76 | UnsupportedCounterValue32bit uint64 = 4294967294 |
| 77 | UnsupportedCounterValue64bit uint64 = 18446744073709551614 |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 78 | ) |
| 79 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 80 | // OpticalPowerGroupMetrics are supported optical pm names |
| 81 | var OpticalPowerGroupMetrics = map[string]voltha.PmConfig_PmType{ |
Girish Gowdra | e20a4f6 | 2021-03-09 16:06:23 -0800 | [diff] [blame] | 82 | "ani_g_instance_id": voltha.PmConfig_CONTEXT, |
| 83 | "transmit_power_dBm": voltha.PmConfig_GAUGE, |
| 84 | "receive_power_dBm": voltha.PmConfig_GAUGE, |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | // OpticalPowerGroupMetrics specific constants |
| 88 | const ( |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 89 | OpticalPowerGroupMetricName = "PON_Optical" |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 90 | OpticalPowerGroupMetricEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 91 | OpticalPowerMetricGroupCollectionFrequency = 5 * 60 // unit in seconds. This setting can be changed from voltha NBI PmConfig configuration |
| 92 | ) |
| 93 | |
| 94 | // UniStatusGroupMetrics are supported UNI status names |
| 95 | var UniStatusGroupMetrics = map[string]voltha.PmConfig_PmType{ |
Girish Gowdra | d343680 | 2021-06-28 13:15:40 -0700 | [diff] [blame] | 96 | "uni_port_no": voltha.PmConfig_CONTEXT, |
| 97 | "me_class_id": voltha.PmConfig_CONTEXT, |
| 98 | "entity_id": voltha.PmConfig_CONTEXT, |
| 99 | "configuration_ind": voltha.PmConfig_GAUGE, |
| 100 | "oper_status": voltha.PmConfig_GAUGE, |
| 101 | "uni_admin_state": voltha.PmConfig_GAUGE, |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // UniStatusGroupMetrics specific constants |
| 105 | const ( |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 106 | UniStatusGroupMetricName = "UNI_Status" |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 107 | UniStatusGroupMetricEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 108 | UniStatusMetricGroupCollectionFrequency = 5 * 60 // unit in seconds. This setting can be changed from voltha NBI PmConfig configuration |
| 109 | ) |
| 110 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 111 | // *** Classical L2 PM Counters begin *** |
| 112 | |
| 113 | // EthernetBridgeHistory are supported ethernet bridge history counters fetched from |
| 114 | // Ethernet Frame Performance Monitoring History Data Downstream and Ethernet Frame Performance Monitoring History Data Upstream MEs. |
| 115 | var EthernetBridgeHistory = map[string]voltha.PmConfig_PmType{ |
| 116 | "class_id": voltha.PmConfig_CONTEXT, |
| 117 | "entity_id": voltha.PmConfig_CONTEXT, |
| 118 | "interval_end_time": voltha.PmConfig_CONTEXT, |
| 119 | "parent_class_id": voltha.PmConfig_CONTEXT, |
| 120 | "parent_entity_id": voltha.PmConfig_CONTEXT, |
| 121 | "upstream": voltha.PmConfig_CONTEXT, |
| 122 | |
| 123 | "drop_events": voltha.PmConfig_COUNTER, |
| 124 | "octets": voltha.PmConfig_COUNTER, |
| 125 | "packets": voltha.PmConfig_COUNTER, |
| 126 | "broadcast_packets": voltha.PmConfig_COUNTER, |
| 127 | "multicast_packets": voltha.PmConfig_COUNTER, |
| 128 | "crc_errored_packets": voltha.PmConfig_COUNTER, |
| 129 | "undersize_packets": voltha.PmConfig_COUNTER, |
| 130 | "oversize_packets": voltha.PmConfig_COUNTER, |
| 131 | "64_octets": voltha.PmConfig_COUNTER, |
| 132 | "65_to_127_octets": voltha.PmConfig_COUNTER, |
| 133 | "128_to_255_octets": voltha.PmConfig_COUNTER, |
| 134 | "256_to_511_octets": voltha.PmConfig_COUNTER, |
| 135 | "512_to_1023_octets": voltha.PmConfig_COUNTER, |
| 136 | "1024_to_1518_octets": voltha.PmConfig_COUNTER, |
| 137 | } |
| 138 | |
| 139 | // EthernetUniHistory are supported ethernet uni history counters fetched from |
| 140 | // Ethernet Performance Monitoring History Data ME. |
| 141 | var EthernetUniHistory = map[string]voltha.PmConfig_PmType{ |
| 142 | "class_id": voltha.PmConfig_CONTEXT, |
| 143 | "entity_id": voltha.PmConfig_CONTEXT, |
| 144 | "interval_end_time": voltha.PmConfig_CONTEXT, |
| 145 | |
| 146 | "fcs_errors": voltha.PmConfig_COUNTER, |
| 147 | "excessive_collision_counter": voltha.PmConfig_COUNTER, |
| 148 | "late_collision_counter": voltha.PmConfig_COUNTER, |
| 149 | "frames_too_long": voltha.PmConfig_COUNTER, |
| 150 | "buffer_overflows_on_rx": voltha.PmConfig_COUNTER, |
| 151 | "buffer_overflows_on_tx": voltha.PmConfig_COUNTER, |
| 152 | "single_collision_frame_counter": voltha.PmConfig_COUNTER, |
| 153 | "multiple_collisions_frame_counter": voltha.PmConfig_COUNTER, |
| 154 | "sqe_counter": voltha.PmConfig_COUNTER, |
| 155 | "deferred_tx_counter": voltha.PmConfig_COUNTER, |
| 156 | "internal_mac_tx_error_counter": voltha.PmConfig_COUNTER, |
| 157 | "carrier_sense_error_counter": voltha.PmConfig_COUNTER, |
| 158 | "alignment_error_counter": voltha.PmConfig_COUNTER, |
| 159 | "internal_mac_rx_error_counter": voltha.PmConfig_COUNTER, |
| 160 | } |
| 161 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 162 | // FecHistory is supported FEC Performance Monitoring History Data related metrics |
| 163 | var FecHistory = map[string]voltha.PmConfig_PmType{ |
| 164 | "class_id": voltha.PmConfig_CONTEXT, |
| 165 | "entity_id": voltha.PmConfig_CONTEXT, |
| 166 | "interval_end_time": voltha.PmConfig_CONTEXT, |
| 167 | |
| 168 | "corrected_bytes": voltha.PmConfig_COUNTER, |
| 169 | "corrected_code_words": voltha.PmConfig_COUNTER, |
| 170 | "uncorrectable_code_words": voltha.PmConfig_COUNTER, |
| 171 | "total_code_words": voltha.PmConfig_COUNTER, |
| 172 | "fec_seconds": voltha.PmConfig_COUNTER, |
| 173 | } |
| 174 | |
| 175 | // GemPortHistory is supported GEM Port Network Ctp Performance Monitoring History Data |
| 176 | // related metrics |
| 177 | var GemPortHistory = map[string]voltha.PmConfig_PmType{ |
| 178 | "class_id": voltha.PmConfig_CONTEXT, |
| 179 | "entity_id": voltha.PmConfig_CONTEXT, |
| 180 | "interval_end_time": voltha.PmConfig_CONTEXT, |
| 181 | |
| 182 | "transmitted_gem_frames": voltha.PmConfig_COUNTER, |
| 183 | "received_gem_frames": voltha.PmConfig_COUNTER, |
| 184 | "received_payload_bytes": voltha.PmConfig_COUNTER, |
| 185 | "transmitted_payload_bytes": voltha.PmConfig_COUNTER, |
| 186 | "encryption_key_errors": voltha.PmConfig_COUNTER, |
| 187 | } |
| 188 | |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 189 | var maskToEthernetFrameExtendedPM32Bit = map[uint16][]string{ |
| 190 | 0x3F00: {"drop_events", "octets", "frames", "broadcast_frames", "multicast_frames", "crc_errored_frames"}, |
| 191 | 0x00FC: {"undersize_frames", "oversize_frames", "64_octets", "65_to_127_octets", "128_to_255_octets", "256_to_511_octets"}, |
| 192 | 0x0003: {"512_to_1023_octets", "1024_to_1518_octets"}, |
| 193 | } |
| 194 | |
| 195 | var maskToEthernetFrameExtendedPM64Bit = map[uint16][]string{ |
| 196 | 0x3800: {"drop_events", "octets", "frames"}, |
| 197 | 0x0700: {"broadcast_frames", "multicast_frames", "crc_errored_frames"}, |
| 198 | 0x00E0: {"undersize_frames", "oversize_frames", "64_octets"}, |
| 199 | 0x001C: {"65_to_127_octets", "128_to_255_octets", "256_to_511_octets"}, |
| 200 | 0x0003: {"512_to_1023_octets", "1024_to_1518_octets"}, |
| 201 | } |
| 202 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 203 | // Constants specific for L2 PM collection |
| 204 | const ( |
| 205 | L2PmCollectionInterval = 15 * 60 // Unit in seconds. Do not change this as this fixed by OMCI specification for L2 PM counters |
| 206 | SyncTimeRetryInterval = 15 // Unit seconds |
| 207 | L2PmCreateAttempts = 3 |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 208 | L2PmDeleteAttempts = 3 |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 209 | L2PmCollectAttempts = 3 |
Girish Gowdra | 453750f | 2021-02-16 16:36:46 -0800 | [diff] [blame] | 210 | // Per Table 11.2.9-1 – OMCI baseline message limitations in G.988 spec, the max GET Response |
| 211 | // payload size is 25. We define 24 (one less) to allow for dynamic insertion of IntervalEndTime |
| 212 | // attribute (1 byte) in L2 PM GET Requests. |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 213 | MaxBaselineL2PMGetPayLoadSize = 24 |
| 214 | // unused: MaxEthernetFrameExtPmPayloadSize = 25 |
| 215 | MaxExtendedL2PMGetPayLoadSize = omci.MaxExtendedLength - 17 - 1 - 4 // minus header, attribute IntervalEndTime and MIC |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 216 | ) |
| 217 | |
| 218 | // EthernetUniHistoryName specific constants |
| 219 | const ( |
| 220 | EthernetBridgeHistoryName = "Ethernet_Bridge_Port_History" |
| 221 | EthernetBridgeHistoryEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 222 | EthernetBridgeHistoryFrequency = L2PmCollectionInterval |
| 223 | ) |
| 224 | |
| 225 | // EthernetBridgeHistory specific constants |
| 226 | const ( |
| 227 | EthernetUniHistoryName = "Ethernet_UNI_History" |
| 228 | EthernetUniHistoryEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 229 | EthernetUniHistoryFrequency = L2PmCollectionInterval |
| 230 | ) |
| 231 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 232 | // FecHistory specific constants |
| 233 | const ( |
| 234 | FecHistoryName = "FEC_History" |
| 235 | FecHistoryEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 236 | FecHistoryFrequency = L2PmCollectionInterval |
| 237 | ) |
| 238 | |
| 239 | // GemPortHistory specific constants |
| 240 | const ( |
| 241 | GemPortHistoryName = "GEM_Port_History" |
| 242 | GemPortHistoryEnabled = true // This setting can be changed from voltha NBI PmConfig configuration |
| 243 | GemPortHistoryFrequency = L2PmCollectionInterval |
| 244 | ) |
| 245 | |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 246 | // CPmKvStorePrefixBase - kv store base path of ONU specific PM data |
| 247 | const CPmKvStorePrefixBase = cmn.CBasePathOnuKVStore + "/pm-data" // <some-base-path>/openonu/pm-data |
| 248 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 249 | // KV Store related constants |
| 250 | const ( |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 251 | cPmKvStorePrefix = CPmKvStorePrefixBase + "/%s" // <some-base-path>/openonu/pm-data/<onu-device-id> |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 252 | cPmAdd = "add" |
| 253 | cPmAdded = "added" |
| 254 | cPmRemove = "remove" |
| 255 | cPmRemoved = "removed" |
| 256 | cExtPmKvStorePrefix = "%s/omci_me" //<some-base-path>/omci_me/<onu_vendor>/<onu_equipment_id>/<onu_sw_version> |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 257 | ) |
| 258 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 259 | // Defines the type for generic metric population function |
| 260 | type groupMetricPopulateFunc func(context.Context, me.ClassID, uint16, me.AttributeValueMap, me.AttributeValueMap, map[string]float32, *int) error |
| 261 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 262 | // *** Classical L2 PM Counters end *** |
| 263 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 264 | type pmMEData struct { |
| 265 | InstancesActive []uint16 `json:"instances_active"` // list of active ME instance IDs for the group |
| 266 | InstancesToDelete []uint16 `json:"instances_to_delete"` // list of ME instance IDs marked for deletion for the group |
| 267 | InstancesToAdd []uint16 `json:"instances_to_add"` // list of ME instance IDs marked for addition for the group |
| 268 | } |
| 269 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 270 | type groupMetric struct { |
| 271 | groupName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 272 | Enabled bool |
| 273 | Frequency uint32 // valid only if FrequencyOverride is enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 274 | metricMap map[string]voltha.PmConfig_PmType |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 275 | NextCollectionInterval time.Time // valid only if FrequencyOverride is enabled. |
| 276 | IsL2PMCounter bool // true for only L2 PM counters |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 277 | collectAttempts uint32 // number of attempts to collect L2 PM data |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 278 | pmMEData *pmMEData |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | type standaloneMetric struct { |
| 282 | metricName string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 283 | Enabled bool |
| 284 | Frequency uint32 // valid only if FrequencyOverride is enabled. |
| 285 | NextCollectionInterval time.Time // valid only if FrequencyOverride is enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 288 | // OnuMetricsManager - TODO: add comment |
| 289 | type OnuMetricsManager struct { |
| 290 | deviceID string |
| 291 | pDeviceHandler cmn.IdeviceHandler |
| 292 | pOnuDeviceEntry cmn.IonuDeviceEntry |
| 293 | PAdaptFsm *cmn.AdapterFsm |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 294 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 295 | opticalMetricsChan chan me.AttributeValueMap |
| 296 | uniStatusMetricsChan chan me.AttributeValueMap |
| 297 | l2PmChan chan me.AttributeValueMap |
| 298 | extendedPmMeChan chan me.AttributeValueMap |
| 299 | syncTimeResponseChan chan bool // true is success, false is fail |
| 300 | l2PmCreateOrDeleteResponseChan chan bool // true is success, false is fail |
| 301 | extendedPMMeResponseChan chan me.Results // true is sucesss, false is fail |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 302 | |
| 303 | activeL2Pms []string // list of active l2 pm MEs created on the ONU. |
| 304 | l2PmToDelete []string // list of L2 PMs to delete |
| 305 | l2PmToAdd []string // list of L2 PM to add |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 306 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 307 | GroupMetricMap map[string]*groupMetric |
| 308 | StandaloneMetricMap map[string]*standaloneMetric |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 309 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 310 | StopProcessingOmciResponses chan bool |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 311 | omciProcessingActive bool |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 312 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 313 | StopTicks chan bool |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 314 | tickGenerationActive bool |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 315 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 316 | deviceDeletionInProgress bool |
| 317 | GarbageCollectionComplete chan bool |
| 318 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 319 | NextGlobalMetricCollectionTime time.Time // valid only if pmConfig.FreqOverride is set to false. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 320 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 321 | OnuMetricsManagerLock sync.RWMutex |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 322 | |
| 323 | pmKvStore *db.Backend |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 324 | |
| 325 | supportedEthernetFrameExtendedPMClass me.ClassID |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 326 | ethernetFrameExtendedPmUpStreamMEByEntityID map[uint16]*me.ManagedEntity |
| 327 | ethernetFrameExtendedPmDownStreamMEByEntityID map[uint16]*me.ManagedEntity |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 328 | extPmKvStore *db.Backend |
| 329 | onuEthernetFrameExtendedPmLock sync.RWMutex |
| 330 | isDeviceReadyToCollectExtendedPmStats bool |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 331 | isEthernetFrameExtendedPmOperationOngoing bool |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 332 | isExtendedOmci bool |
| 333 | maxL2PMGetPayLoadSize int |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 336 | // NewOnuMetricsManager returns a new instance of the NewOnuMetricsManager |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 337 | // The metrics manager module is responsible for configuration and management of individual and group metrics. |
| 338 | // Currently all the metrics are managed as a group which fall into two categories - L2 PM and "all others" |
| 339 | // The L2 PM counters have a fixed 15min interval for PM collection while all other group counters have |
| 340 | // the collection interval configurable. |
| 341 | // The global PM config is part of the voltha.Device struct and is backed up on KV store (by rw-core). |
| 342 | // This module also implements resiliency for L2 PM ME instances that are active/pending-delete/pending-add. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 343 | func NewOnuMetricsManager(ctx context.Context, dh cmn.IdeviceHandler, onuDev cmn.IonuDeviceEntry) *OnuMetricsManager { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 344 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 345 | var metricsManager OnuMetricsManager |
| 346 | metricsManager.deviceID = dh.GetDeviceID() |
| 347 | logger.Debugw(ctx, "init-OnuMetricsManager", log.Fields{"device-id": metricsManager.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 348 | metricsManager.pDeviceHandler = dh |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 349 | metricsManager.pOnuDeviceEntry = onuDev |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 350 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 351 | commMetricsChan := make(chan cmn.Message) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 352 | metricsManager.opticalMetricsChan = make(chan me.AttributeValueMap) |
| 353 | metricsManager.uniStatusMetricsChan = make(chan me.AttributeValueMap) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 354 | metricsManager.l2PmChan = make(chan me.AttributeValueMap) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 355 | metricsManager.extendedPmMeChan = make(chan me.AttributeValueMap) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 356 | |
| 357 | metricsManager.syncTimeResponseChan = make(chan bool) |
| 358 | metricsManager.l2PmCreateOrDeleteResponseChan = make(chan bool) |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 359 | metricsManager.extendedPMMeResponseChan = make(chan me.Results) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 360 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 361 | metricsManager.StopProcessingOmciResponses = make(chan bool) |
| 362 | metricsManager.StopTicks = make(chan bool) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 363 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 364 | metricsManager.GroupMetricMap = make(map[string]*groupMetric) |
| 365 | metricsManager.StandaloneMetricMap = make(map[string]*standaloneMetric) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 366 | |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 367 | metricsManager.ethernetFrameExtendedPmUpStreamMEByEntityID = make(map[uint16]*me.ManagedEntity) |
| 368 | metricsManager.ethernetFrameExtendedPmDownStreamMEByEntityID = make(map[uint16]*me.ManagedEntity) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 369 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 370 | // make this a buffered channel so that the sender is not blocked for any reason if there is no listener |
| 371 | metricsManager.GarbageCollectionComplete = make(chan bool, 1) |
| 372 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 373 | if dh.GetPmConfigs() == nil { // dh.GetPmConfigs() is NOT nil if adapter comes back from a restart. We should NOT go back to defaults in this case |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 374 | metricsManager.initializeAllGroupMetrics() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 377 | metricsManager.populateLocalGroupMetricData(ctx) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 378 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 379 | if err := metricsManager.initializeL2PmFsm(ctx, commMetricsChan); err != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 380 | return nil |
| 381 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 382 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 383 | // initialize the next metric collection intervals. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 384 | metricsManager.InitializeMetricCollectionTime(ctx) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 385 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 386 | baseKvStorePath := fmt.Sprintf(cPmKvStorePrefix, dh.GetBackendPathPrefix(), metricsManager.deviceID) |
| 387 | metricsManager.pmKvStore = dh.SetBackend(ctx, baseKvStorePath) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 388 | if metricsManager.pmKvStore == nil { |
| 389 | logger.Errorw(ctx, "Can't initialize pmKvStore - no backend connection to PM module", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 390 | log.Fields{"device-id": metricsManager.deviceID, "service": baseKvStorePath}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 391 | return nil |
| 392 | } |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 393 | // restore data from KV store |
| 394 | if err := metricsManager.restorePmData(ctx); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 395 | logger.Errorw(ctx, "error restoring pm data", log.Fields{"device-id": metricsManager.deviceID, "err": err}) |
Girish Gowdra | 50e5642 | 2021-06-01 16:46:04 -0700 | [diff] [blame] | 396 | // we continue given that it does not effect the actual services for the ONU, |
| 397 | // but there may be some negative effect on PM collection (there may be some mismatch in |
| 398 | // the actual PM config and what is present on the device). |
| 399 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 400 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 401 | baseExtPmKvStorePath := fmt.Sprintf(cExtPmKvStorePrefix, dh.GetBackendPathPrefix()) |
| 402 | metricsManager.extPmKvStore = dh.SetBackend(ctx, baseExtPmKvStorePath) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 403 | if metricsManager.extPmKvStore == nil { |
| 404 | logger.Errorw(ctx, "Can't initialize extPmKvStore - no backend connection to PM module", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 405 | log.Fields{"device-id": metricsManager.deviceID, "service": baseExtPmKvStorePath}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 406 | return nil |
| 407 | } |
| 408 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 409 | logger.Info(ctx, "init-OnuMetricsManager completed", log.Fields{"device-id": metricsManager.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 410 | return &metricsManager |
| 411 | } |
| 412 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 413 | // InitializeMetricCollectionTime - TODO: add comment |
| 414 | func (mm *OnuMetricsManager) InitializeMetricCollectionTime(ctx context.Context) { |
| 415 | if mm.pDeviceHandler.GetPmConfigs().FreqOverride { |
| 416 | // If mm.pDeviceHandler.GetPmConfigs().FreqOverride is set to true, then group/standalone metric specific interval applies |
| 417 | mm.OnuMetricsManagerLock.Lock() |
| 418 | defer mm.OnuMetricsManagerLock.Unlock() |
| 419 | for _, v := range mm.GroupMetricMap { |
| 420 | if v.Enabled && !v.IsL2PMCounter { // L2 PM counter collection is managed in a L2PmFsm |
| 421 | v.NextCollectionInterval = time.Now().Add(time.Duration(v.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 425 | for _, v := range mm.StandaloneMetricMap { |
| 426 | if v.Enabled { |
| 427 | v.NextCollectionInterval = time.Now().Add(time.Duration(v.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 431 | // If mm.pDeviceHandler.GetPmConfigs().FreqOverride is set to false, then overall metric specific interval applies |
| 432 | mm.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(mm.pDeviceHandler.GetPmConfigs().DefaultFreq) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 433 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 434 | logger.Infow(ctx, "initialized standalone group/metric collection time", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 437 | // UpdateDefaultFrequency - TODO: add comment |
| 438 | func (mm *OnuMetricsManager) UpdateDefaultFrequency(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 439 | // Verify that the configured DefaultFrequency is > 0 and is a multiple of FrequencyGranularity |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 440 | if pmConfigs.DefaultFreq == 0 || (pmConfigs.DefaultFreq > 0 && pmConfigs.DefaultFreq%FrequencyGranularity != 0) { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 441 | logger.Errorf(ctx, "frequency-%u-should-be-a-multiple-of-%u", pmConfigs.DefaultFreq, FrequencyGranularity) |
| 442 | return fmt.Errorf("frequency-%d-should-be-a-multiple-of-%d", pmConfigs.DefaultFreq, FrequencyGranularity) |
| 443 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 444 | mm.pDeviceHandler.GetPmConfigs().DefaultFreq = pmConfigs.DefaultFreq |
| 445 | // re-set the NextGlobalMetricCollectionTime based on the new DefaultFreq |
| 446 | mm.NextGlobalMetricCollectionTime = time.Now().Add(time.Duration(mm.pDeviceHandler.GetPmConfigs().DefaultFreq) * time.Second) |
| 447 | logger.Debugw(ctx, "frequency-updated--new-frequency", log.Fields{"device-id": mm.deviceID, "frequency": mm.pDeviceHandler.GetPmConfigs().DefaultFreq}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 448 | return nil |
| 449 | } |
| 450 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 451 | // UpdateGroupFreq - TODO: add comment |
| 452 | func (mm *OnuMetricsManager) UpdateGroupFreq(ctx context.Context, aGroupName string, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 453 | var newGroupFreq uint32 |
| 454 | found := false |
| 455 | groupSliceIdx := 0 |
| 456 | var group *voltha.PmGroupConfig |
| 457 | for groupSliceIdx, group = range pmConfigs.Groups { |
| 458 | if group.GroupName == aGroupName { |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 459 | // freq 0 is not allowed and it should be multiple of FrequencyGranularity |
| 460 | if group.GroupFreq == 0 || (group.GroupFreq > 0 && group.GroupFreq%FrequencyGranularity != 0) { |
| 461 | logger.Errorf(ctx, "frequency-%u-should-be-a-multiple-of-%u", group.GroupFreq, FrequencyGranularity) |
| 462 | return fmt.Errorf("frequency-%d-should-be-a-multiple-of-%d", group.GroupFreq, FrequencyGranularity) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 463 | } |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 464 | newGroupFreq = group.GroupFreq |
| 465 | found = true |
| 466 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | // if not found update group freq and next collection interval for the group |
| 470 | if !found { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 471 | logger.Errorw(ctx, "group name not found", log.Fields{"device-id": mm.deviceID, "groupName": aGroupName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 472 | return fmt.Errorf("group-name-not-found-%v", aGroupName) |
| 473 | } |
| 474 | |
| 475 | updated := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 476 | mm.OnuMetricsManagerLock.Lock() |
| 477 | defer mm.OnuMetricsManagerLock.Unlock() |
| 478 | for k, v := range mm.GroupMetricMap { |
| 479 | if k == aGroupName && !v.IsL2PMCounter { // We cannot allow the L2 PM counter frequency to be updated. It is 15min fixed by OMCI spec |
| 480 | v.Frequency = newGroupFreq |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 481 | // update internal pm config |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 482 | mm.pDeviceHandler.GetPmConfigs().Groups[groupSliceIdx].GroupFreq = newGroupFreq |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 483 | // Also updated the next group metric collection time from now |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 484 | v.NextCollectionInterval = time.Now().Add(time.Duration(newGroupFreq) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 485 | updated = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 486 | logger.Infow(ctx, "group frequency updated", log.Fields{"device-id": mm.deviceID, "newGroupFreq": newGroupFreq, "groupName": aGroupName}) |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 487 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | if !updated { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 491 | logger.Errorw(ctx, "group frequency not updated", log.Fields{"device-id": mm.deviceID, "newGroupFreq": newGroupFreq, "groupName": aGroupName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 492 | return fmt.Errorf("internal-error-during-group-freq-update--groupname-%s-freq-%d", aGroupName, newGroupFreq) |
| 493 | } |
| 494 | return nil |
| 495 | } |
| 496 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 497 | // UpdateMetricFreq - TODO: add comment |
| 498 | func (mm *OnuMetricsManager) UpdateMetricFreq(ctx context.Context, aMetricName string, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 499 | var newMetricFreq uint32 |
| 500 | found := false |
| 501 | metricSliceIdx := 0 |
| 502 | var metric *voltha.PmConfig |
| 503 | for metricSliceIdx, metric = range pmConfigs.Metrics { |
| 504 | if metric.Name == aMetricName { |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 505 | // freq 0 is not allowed and it should be multiple of FrequencyGranularity |
| 506 | if metric.SampleFreq == 0 || (metric.SampleFreq > 0 && metric.SampleFreq%FrequencyGranularity != 0) { |
| 507 | logger.Errorf(ctx, "frequency-%u-should-be-a-multiple-of-%u", metric.SampleFreq, FrequencyGranularity) |
| 508 | return fmt.Errorf("frequency-%d-should-be-a-multiple-of-%d", metric.SampleFreq, FrequencyGranularity) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 509 | } |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 510 | newMetricFreq = metric.SampleFreq |
| 511 | found = true |
| 512 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | if !found { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 516 | logger.Errorw(ctx, "metric name not found", log.Fields{"device-id": mm.deviceID, "metricName": aMetricName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 517 | return fmt.Errorf("metric-name-not-found-%v", aMetricName) |
| 518 | } |
| 519 | |
| 520 | updated := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 521 | mm.OnuMetricsManagerLock.Lock() |
| 522 | defer mm.OnuMetricsManagerLock.Unlock() |
| 523 | for k, v := range mm.GroupMetricMap { |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 524 | if k == aMetricName { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 525 | v.Frequency = newMetricFreq |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 526 | // update internal pm config |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 527 | mm.pDeviceHandler.GetPmConfigs().Metrics[metricSliceIdx].SampleFreq = newMetricFreq |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 528 | // Also updated the next standalone metric collection time from now |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 529 | v.NextCollectionInterval = time.Now().Add(time.Duration(newMetricFreq) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 530 | updated = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 531 | logger.Infow(ctx, "metric frequency updated", log.Fields{"device-id": mm.deviceID, "newMetricFreq": newMetricFreq, "aMetricName": aMetricName}) |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 532 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | if !updated { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 536 | logger.Errorw(ctx, "metric frequency not updated", log.Fields{"device-id": mm.deviceID, "newMetricFreq": newMetricFreq, "aMetricName": aMetricName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 537 | return fmt.Errorf("internal-error-during-standalone-metric-update--matricnane-%s-freq-%d", aMetricName, newMetricFreq) |
| 538 | } |
| 539 | return nil |
| 540 | } |
| 541 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 542 | // UpdateGroupSupport - TODO: add comment |
| 543 | func (mm *OnuMetricsManager) UpdateGroupSupport(ctx context.Context, aGroupName string, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 544 | groupSliceIdx := 0 |
| 545 | var group *voltha.PmGroupConfig |
| 546 | |
| 547 | for groupSliceIdx, group = range pmConfigs.Groups { |
| 548 | if group.GroupName == aGroupName { |
| 549 | break |
| 550 | } |
| 551 | } |
| 552 | if group == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 553 | logger.Errorw(ctx, "group metric not found", log.Fields{"device-id": mm.deviceID, "groupName": aGroupName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 554 | return fmt.Errorf("group-not-found--groupName-%s", aGroupName) |
| 555 | } |
| 556 | |
| 557 | updated := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 558 | mm.OnuMetricsManagerLock.Lock() |
| 559 | defer mm.OnuMetricsManagerLock.Unlock() |
| 560 | for k, v := range mm.GroupMetricMap { |
| 561 | if k == aGroupName && v.Enabled != group.Enabled { |
| 562 | mm.pDeviceHandler.GetPmConfigs().Groups[groupSliceIdx].Enabled = group.Enabled |
| 563 | v.Enabled = group.Enabled |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 564 | if group.Enabled { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 565 | if v.IsL2PMCounter { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 566 | // If it is a L2 PM counter we need to mark the PM to be added |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 567 | mm.l2PmToAdd = mm.appendIfMissingString(mm.l2PmToAdd, v.groupName) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 568 | // If the group support flag toggles too soon, we need to delete the group name from l2PmToDelete slice |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 569 | mm.l2PmToDelete = mm.removeIfFoundString(mm.l2PmToDelete, v.groupName) |
| 570 | |
| 571 | // The GemPortHistory group requires some special handling as the instance IDs are not pre-defined |
| 572 | // unlike other L2 PM counters. We need to fetch the active gemport instance IDs in the system to |
| 573 | // take further action |
| 574 | if v.groupName == GemPortHistoryName { |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 575 | mm.updateGemPortNTPInstanceToAddForPerfMonitoring(ctx) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 576 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 577 | } else if mm.pDeviceHandler.GetPmConfigs().FreqOverride { // otherwise just update the next collection interval |
| 578 | v.NextCollectionInterval = time.Now().Add(time.Duration(v.Frequency) * time.Second) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 579 | } |
| 580 | } else { // group counter is disabled |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 581 | if v.IsL2PMCounter { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 582 | // If it is a L2 PM counter we need to mark the PM to be deleted |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 583 | mm.l2PmToDelete = mm.appendIfMissingString(mm.l2PmToDelete, v.groupName) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 584 | // If the group support flag toggles too soon, we need to delete the group name from l2PmToAdd slice |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 585 | mm.l2PmToAdd = mm.removeIfFoundString(mm.l2PmToAdd, v.groupName) |
| 586 | |
| 587 | // The GemPortHistory group requires some special handling as the instance IDs are not pre-defined |
| 588 | // unlike other L2 PM counters. We need to fetch the active gemport instance IDs in the system to |
| 589 | // take further action |
| 590 | if v.groupName == GemPortHistoryName { |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 591 | mm.updateGemPortNTPInstanceToDeleteForPerfMonitoring(ctx) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 592 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 593 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 594 | } |
| 595 | updated = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 596 | if v.IsL2PMCounter { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 597 | logger.Infow(ctx, "l2 pm group metric support updated", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 598 | log.Fields{"device-id": mm.deviceID, "groupName": aGroupName, "enabled": group.Enabled, "l2PmToAdd": mm.l2PmToAdd, "l2PmToDelete": mm.l2PmToDelete}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 599 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 600 | logger.Infow(ctx, "group metric support updated", log.Fields{"device-id": mm.deviceID, "groupName": aGroupName, "enabled": group.Enabled}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 601 | } |
| 602 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | if !updated { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 607 | logger.Errorw(ctx, "group metric support not updated", log.Fields{"device-id": mm.deviceID, "groupName": aGroupName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 608 | return fmt.Errorf("internal-error-during-group-support-update--groupName-%s", aGroupName) |
| 609 | } |
| 610 | return nil |
| 611 | } |
| 612 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 613 | // UpdateMetricSupport - TODO: add comment |
| 614 | func (mm *OnuMetricsManager) UpdateMetricSupport(ctx context.Context, aMetricName string, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 615 | metricSliceIdx := 0 |
| 616 | var metric *voltha.PmConfig |
| 617 | |
| 618 | for metricSliceIdx, metric = range pmConfigs.Metrics { |
| 619 | if metric.Name == aMetricName { |
| 620 | break |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | if metric == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 625 | logger.Errorw(ctx, "standalone metric not found", log.Fields{"device-id": mm.deviceID, "metricName": aMetricName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 626 | return fmt.Errorf("metric-not-found--metricname-%s", aMetricName) |
| 627 | } |
| 628 | |
| 629 | updated := false |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 630 | mm.OnuMetricsManagerLock.Lock() |
| 631 | defer mm.OnuMetricsManagerLock.Unlock() |
| 632 | for k, v := range mm.StandaloneMetricMap { |
| 633 | if k == aMetricName && v.Enabled != metric.Enabled { |
| 634 | mm.pDeviceHandler.GetPmConfigs().Metrics[metricSliceIdx].Enabled = metric.Enabled |
| 635 | v.Enabled = metric.Enabled |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 636 | // If the standalone metric is now enabled and frequency override is enabled, set the next metric collection time |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 637 | if metric.Enabled && mm.pDeviceHandler.GetPmConfigs().FreqOverride { |
| 638 | v.NextCollectionInterval = time.Now().Add(time.Duration(v.Frequency) * time.Second) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 639 | } |
| 640 | updated = true |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 641 | logger.Infow(ctx, "standalone metric support updated", log.Fields{"device-id": mm.deviceID, "metricName": aMetricName, "enabled": metric.Enabled}) |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 642 | break |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | if !updated { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 646 | logger.Errorw(ctx, "standalone metric support not updated", log.Fields{"device-id": mm.deviceID, "metricName": aMetricName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 647 | return fmt.Errorf("internal-error-during-standalone-support-update--metricname-%s", aMetricName) |
| 648 | } |
| 649 | return nil |
| 650 | } |
| 651 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 652 | // CollectAllGroupAndStandaloneMetrics - TODO: add comment |
| 653 | func (mm *OnuMetricsManager) CollectAllGroupAndStandaloneMetrics(ctx context.Context) { |
| 654 | if mm.pDeviceHandler.GetPmConfigs().Grouped { // metrics are managed as a group. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 655 | go mm.collectAllGroupMetrics(ctx) |
| 656 | } else { |
| 657 | go mm.collectAllStandaloneMetrics(ctx) |
| 658 | } |
| 659 | } |
| 660 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 661 | func (mm *OnuMetricsManager) collectAllGroupMetrics(ctx context.Context) { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 662 | go func() { |
| 663 | logger.Debug(ctx, "startCollector before collecting optical metrics") |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 664 | metricInfo, err := mm.collectOpticalMetrics(ctx) |
| 665 | if err != nil { |
| 666 | logger.Errorw(ctx, "collectOpticalMetrics failed", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 667 | log.Fields{"device-id": mm.deviceID, "Error": err}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 668 | return |
| 669 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 670 | if metricInfo != nil { |
| 671 | mm.publishMetrics(ctx, metricInfo) |
| 672 | } |
| 673 | }() |
| 674 | |
| 675 | go func() { |
| 676 | logger.Debug(ctx, "startCollector before collecting uni metrics") |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 677 | metricInfo, err := mm.collectUniStatusMetrics(ctx) |
| 678 | if err != nil { |
| 679 | logger.Errorw(ctx, "collectOpticalMetrics failed", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 680 | log.Fields{"device-id": mm.deviceID, "Error": err}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 681 | return |
| 682 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 683 | if metricInfo != nil { |
| 684 | mm.publishMetrics(ctx, metricInfo) |
| 685 | } |
| 686 | }() |
| 687 | |
| 688 | // Add more here |
| 689 | } |
| 690 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 691 | func (mm *OnuMetricsManager) collectAllStandaloneMetrics(ctx context.Context) { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 692 | // None exists as of now, add when available here |
| 693 | } |
| 694 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 695 | // CollectGroupMetric - TODO: add comment |
| 696 | func (mm *OnuMetricsManager) CollectGroupMetric(ctx context.Context, groupName string) { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 697 | switch groupName { |
| 698 | case OpticalPowerGroupMetricName: |
| 699 | go func() { |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 700 | if mi, _ := mm.collectOpticalMetrics(ctx); mi != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 701 | mm.publishMetrics(ctx, mi) |
| 702 | } |
| 703 | }() |
| 704 | case UniStatusGroupMetricName: |
| 705 | go func() { |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 706 | if mi, _ := mm.collectUniStatusMetrics(ctx); mi != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 707 | mm.publishMetrics(ctx, mi) |
| 708 | } |
| 709 | }() |
| 710 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 711 | logger.Errorw(ctx, "unhandled group metric name", log.Fields{"device-id": mm.deviceID, "groupName": groupName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 715 | // CollectStandaloneMetric - TODO: add comment |
| 716 | func (mm *OnuMetricsManager) CollectStandaloneMetric(ctx context.Context, metricName string) { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 717 | switch metricName { |
| 718 | // None exist as of now, add when available |
| 719 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 720 | logger.Errorw(ctx, "unhandled standalone metric name", log.Fields{"device-id": mm.deviceID, "metricName": metricName}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
| 724 | // collectOpticalMetrics collects groups metrics related to optical power from ani-g ME. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 725 | func (mm *OnuMetricsManager) collectOpticalMetrics(ctx context.Context) ([]*voltha.MetricInformation, error) { |
| 726 | logger.Debugw(ctx, "collectOpticalMetrics", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 727 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 728 | mm.OnuMetricsManagerLock.RLock() |
| 729 | if !mm.GroupMetricMap[OpticalPowerGroupMetricName].Enabled { |
| 730 | mm.OnuMetricsManagerLock.RUnlock() |
| 731 | logger.Debugw(ctx, "optical power group metric is not enabled", log.Fields{"device-id": mm.deviceID}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 732 | return nil, nil |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 733 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 734 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 735 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 736 | var metricInfoSlice []*voltha.MetricInformation |
| 737 | metricsContext := make(map[string]string) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 738 | metricsContext["onuID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetProxyAddress().OnuId) |
| 739 | metricsContext["intfID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetProxyAddress().ChannelId) |
| 740 | metricsContext["devicetype"] = mm.pDeviceHandler.GetDeviceType() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 741 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 742 | raisedTs := time.Now().Unix() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 743 | mmd := voltha.MetricMetaData{ |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 744 | Title: OpticalPowerGroupMetricName, |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 745 | Ts: float64(raisedTs), |
| 746 | Context: metricsContext, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 747 | DeviceId: mm.deviceID, |
| 748 | LogicalDeviceId: mm.pDeviceHandler.GetLogicalDeviceID(), |
| 749 | SerialNo: mm.pDeviceHandler.GetDevice().SerialNumber, |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 752 | // get the ANI-G instance IDs |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 753 | anigInstKeys := mm.pOnuDeviceEntry.GetOnuDB().GetSortedInstKeys(ctx, me.AniGClassID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 754 | loop: |
| 755 | for _, anigInstID := range anigInstKeys { |
| 756 | var meAttributes me.AttributeValueMap |
| 757 | opticalMetrics := make(map[string]float32) |
| 758 | // Get the ANI-G instance optical power attributes |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 759 | requestedAttributes := me.AttributeValueMap{me.AniG_OpticalSignalLevel: 0, me.AniG_TransmitOpticalLevel: 0} |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 760 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, me.AniGClassID, anigInstID, requestedAttributes, |
| 761 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 762 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 763 | logger.Errorw(ctx, "GetMe failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 764 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 765 | return nil, err |
| 766 | } |
| 767 | |
| 768 | if meInstance != nil { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 769 | select { |
| 770 | case meAttributes = <-mm.opticalMetricsChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 771 | logger.Debugw(ctx, "received optical metrics", log.Fields{"device-id": mm.deviceID}) |
| 772 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 773 | logger.Errorw(ctx, "timeout waiting for omci-get response for optical metrics", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 774 | // The metrics will be empty in this case |
| 775 | break loop |
| 776 | } |
| 777 | // Populate metric only if it was enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 778 | for k := range OpticalPowerGroupMetrics { |
| 779 | switch k { |
| 780 | case "ani_g_instance_id": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 781 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 782 | opticalMetrics[k] = float32(val.(uint16)) |
| 783 | } |
Girish Gowdra | e20a4f6 | 2021-03-09 16:06:23 -0800 | [diff] [blame] | 784 | case "transmit_power_dBm": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 785 | if val, ok := meAttributes[me.AniG_TransmitOpticalLevel]; ok && val != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 786 | opticalMetrics[k] = float32(math.Round((float64(cmn.TwosComplementToSignedInt16(val.(uint16)))/500.0)*10) / 10) // convert to dBm rounded of to single decimal place |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 787 | } |
Girish Gowdra | e20a4f6 | 2021-03-09 16:06:23 -0800 | [diff] [blame] | 788 | case "receive_power_dBm": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 789 | if val, ok := meAttributes[me.AniG_OpticalSignalLevel]; ok && val != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 790 | opticalMetrics[k] = float32(math.Round((float64(cmn.TwosComplementToSignedInt16(val.(uint16)))/500.0)*10) / 10) // convert to dBm rounded of to single decimal place |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 791 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 792 | default: |
| 793 | // do nothing |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | // create slice of metrics given that there could be more than one ANI-G instance and |
| 798 | // optical metrics are collected per ANI-G instance |
| 799 | metricInfo := voltha.MetricInformation{Metadata: &mmd, Metrics: opticalMetrics} |
| 800 | metricInfoSlice = append(metricInfoSlice, &metricInfo) |
| 801 | } |
| 802 | |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 803 | return metricInfoSlice, nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 804 | } |
| 805 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 806 | // collectUniStatusMetrics collects UNI status group metric from various MEs (uni-g, pptp and veip). |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 807 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 808 | func (mm *OnuMetricsManager) collectUniStatusMetrics(ctx context.Context) ([]*voltha.MetricInformation, error) { |
| 809 | logger.Debugw(ctx, "collectUniStatusMetrics", log.Fields{"device-id": mm.deviceID}) |
| 810 | mm.OnuMetricsManagerLock.RLock() |
| 811 | if !mm.GroupMetricMap[UniStatusGroupMetricName].Enabled { |
| 812 | mm.OnuMetricsManagerLock.RUnlock() |
| 813 | logger.Debugw(ctx, "uni status group metric is not enabled", log.Fields{"device-id": mm.deviceID}) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 814 | return nil, nil |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 815 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 816 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 817 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 818 | var metricInfoSlice []*voltha.MetricInformation |
| 819 | metricsContext := make(map[string]string) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 820 | metricsContext["onuID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetDevice().ProxyAddress.OnuId) |
| 821 | metricsContext["intfID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetDevice().ProxyAddress.ChannelId) |
| 822 | metricsContext["devicetype"] = mm.pDeviceHandler.GetDeviceType() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 823 | |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 824 | raisedTs := time.Now().Unix() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 825 | mmd := voltha.MetricMetaData{ |
Girish Gowdra | 9b1577b | 2021-04-21 12:56:13 -0700 | [diff] [blame] | 826 | Title: UniStatusGroupMetricName, |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 827 | Ts: float64(raisedTs), |
| 828 | Context: metricsContext, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 829 | DeviceId: mm.deviceID, |
| 830 | LogicalDeviceId: mm.pDeviceHandler.GetLogicalDeviceID(), |
| 831 | SerialNo: mm.pDeviceHandler.GetDevice().SerialNumber, |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 834 | // get the UNI-G instance IDs |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 835 | unigInstKeys := mm.pOnuDeviceEntry.GetOnuDB().GetSortedInstKeys(ctx, me.UniGClassID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 836 | loop1: |
| 837 | for _, unigInstID := range unigInstKeys { |
| 838 | // TODO: Include additional information in the voltha.MetricMetaData - like portno, uni-id, instance-id |
| 839 | // to uniquely identify this ME instance and also to correlate the ME instance to physical instance |
| 840 | unigMetrics := make(map[string]float32) |
| 841 | var meAttributes me.AttributeValueMap |
| 842 | // Get the UNI-G instance optical power attributes |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 843 | requestedAttributes := me.AttributeValueMap{me.UniG_AdministrativeState: 0} |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 844 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, me.UniGClassID, unigInstID, requestedAttributes, |
| 845 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 846 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 847 | logger.Errorw(ctx, "UNI-G failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 848 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 849 | return nil, err |
| 850 | } |
| 851 | if meInstance != nil { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 852 | // Wait for metrics or timeout |
| 853 | select { |
| 854 | case meAttributes = <-mm.uniStatusMetricsChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 855 | logger.Debugw(ctx, "received uni-g metrics", log.Fields{"device-id": mm.deviceID}) |
| 856 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 857 | logger.Errorw(ctx, "timeout waiting for omci-get response for uni status", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 858 | // The metrics could be empty in this case |
| 859 | break loop1 |
| 860 | } |
| 861 | // Populate metric only if it was enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 862 | for k := range UniStatusGroupMetrics { |
| 863 | switch k { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 864 | case "uni_admin_state": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 865 | if val, ok := meAttributes[me.UniG_AdministrativeState]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 866 | unigMetrics[k] = float32(val.(byte)) |
| 867 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 868 | default: |
| 869 | // do nothing |
| 870 | } |
| 871 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 872 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 873 | entityID := val.(uint16) |
| 874 | unigMetrics["entity_id"] = float32(entityID) |
| 875 | // TODO: Rlock needed for reading uniEntityMap? May not be needed given uniEntityMap is populated setup at initial ONU bring up |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 876 | for _, uni := range *mm.pDeviceHandler.GetUniEntityMap() { |
| 877 | if uni.EntityID == entityID { |
| 878 | unigMetrics["uni_port_no"] = float32(uni.PortNo) |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 879 | break |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 880 | } |
| 881 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 882 | } |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 883 | unigMetrics["me_class_id"] = float32(me.UniGClassID) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 884 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 885 | // create slice of metrics given that there could be more than one UNI-G instance |
| 886 | metricInfo := voltha.MetricInformation{Metadata: &mmd, Metrics: unigMetrics} |
| 887 | metricInfoSlice = append(metricInfoSlice, &metricInfo) |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | // get the PPTP instance IDs |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 892 | pptpInstKeys := mm.pOnuDeviceEntry.GetOnuDB().GetSortedInstKeys(ctx, me.PhysicalPathTerminationPointEthernetUniClassID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 893 | loop2: |
| 894 | for _, pptpInstID := range pptpInstKeys { |
| 895 | // TODO: Include additional information in the voltha.MetricMetaData - like portno, uni-id, instance-id |
| 896 | // to uniquely identify this ME instance and also to correlate the ME instance to physical instance |
| 897 | var meAttributes me.AttributeValueMap |
| 898 | pptpMetrics := make(map[string]float32) |
| 899 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 900 | requestedAttributes := me.AttributeValueMap{ |
| 901 | me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd: 0, |
| 902 | me.PhysicalPathTerminationPointEthernetUni_OperationalState: 0, |
| 903 | me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: 0} |
| 904 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, me.PhysicalPathTerminationPointEthernetUniClassID, |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 905 | pptpInstID, requestedAttributes, mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 906 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 907 | logger.Errorw(ctx, "GetMe failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 908 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 909 | return nil, err |
| 910 | } |
| 911 | if meInstance != nil { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 912 | // Wait for metrics or timeout |
| 913 | select { |
| 914 | case meAttributes = <-mm.uniStatusMetricsChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 915 | logger.Debugw(ctx, "received pptp metrics", log.Fields{"device-id": mm.deviceID}) |
| 916 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 917 | logger.Errorw(ctx, "timeout waiting for omci-get response for uni status", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 918 | // The metrics could be empty in this case |
| 919 | break loop2 |
| 920 | } |
| 921 | |
| 922 | // Populate metric only if it was enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 923 | for k := range UniStatusGroupMetrics { |
| 924 | switch k { |
Girish Gowdra | d343680 | 2021-06-28 13:15:40 -0700 | [diff] [blame] | 925 | case "configuration_ind": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 926 | if val, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 927 | pptpMetrics[k] = float32(val.(byte)) |
| 928 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 929 | case "oper_status": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 930 | if val, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_OperationalState]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 931 | pptpMetrics[k] = float32(val.(byte)) |
| 932 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 933 | case "uni_admin_state": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 934 | if val, ok := meAttributes[me.PhysicalPathTerminationPointEthernetUni_AdministrativeState]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 935 | pptpMetrics[k] = float32(val.(byte)) |
| 936 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 937 | default: |
| 938 | // do nothing |
| 939 | } |
| 940 | } |
| 941 | } |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 942 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 943 | entityID := val.(uint16) |
| 944 | pptpMetrics["entity_id"] = float32(entityID) |
| 945 | // TODO: Rlock needed for reading uniEntityMap? May not be needed given uniEntityMap is populated setup at initial ONU bring up |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 946 | for _, uni := range *mm.pDeviceHandler.GetUniEntityMap() { |
| 947 | if uni.EntityID == entityID { |
| 948 | pptpMetrics["uni_port_no"] = float32(uni.PortNo) |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 949 | break |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 950 | } |
| 951 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 952 | } |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 953 | pptpMetrics["me_class_id"] = float32(me.PhysicalPathTerminationPointEthernetUniClassID) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 954 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 955 | // create slice of metrics given that there could be more than one PPTP instance and |
| 956 | metricInfo := voltha.MetricInformation{Metadata: &mmd, Metrics: pptpMetrics} |
| 957 | metricInfoSlice = append(metricInfoSlice, &metricInfo) |
| 958 | } |
| 959 | |
| 960 | // get the VEIP instance IDs |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 961 | veipInstKeys := mm.pOnuDeviceEntry.GetOnuDB().GetSortedInstKeys(ctx, me.VirtualEthernetInterfacePointClassID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 962 | loop3: |
| 963 | for _, veipInstID := range veipInstKeys { |
| 964 | // TODO: Include additional information in the voltha.MetricMetaData - like portno, uni-id, instance-id |
| 965 | // to uniquely identify this ME instance and also to correlate the ME instance to physical instance |
| 966 | var meAttributes me.AttributeValueMap |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 967 | veipMetrics := make(map[string]float32) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 968 | |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 969 | requestedAttributes := me.AttributeValueMap{me.VirtualEthernetInterfacePoint_OperationalState: 0, |
| 970 | me.VirtualEthernetInterfacePoint_AdministrativeState: 0} |
| 971 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, me.VirtualEthernetInterfacePointClassID, veipInstID, requestedAttributes, |
| 972 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 973 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 974 | logger.Errorw(ctx, "GetMe failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 975 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 976 | return nil, err |
| 977 | } |
| 978 | if meInstance != nil { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 979 | // Wait for metrics or timeout |
| 980 | select { |
| 981 | case meAttributes = <-mm.uniStatusMetricsChan: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 982 | logger.Debugw(ctx, "received veip metrics", log.Fields{"device-id": mm.deviceID}) |
| 983 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 984 | logger.Errorw(ctx, "timeout waiting for omci-get response for uni status", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 985 | // The metrics could be empty in this case |
| 986 | break loop3 |
| 987 | } |
| 988 | |
| 989 | // Populate metric only if it was enabled. |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 990 | for k := range UniStatusGroupMetrics { |
| 991 | switch k { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 992 | case "oper_status": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 993 | if val, ok := meAttributes[me.VirtualEthernetInterfacePoint_OperationalState]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 994 | veipMetrics[k] = float32(val.(byte)) |
| 995 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 996 | case "uni_admin_state": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 997 | if val, ok := meAttributes[me.VirtualEthernetInterfacePoint_AdministrativeState]; ok && val != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 998 | veipMetrics[k] = float32(val.(byte)) |
| 999 | } |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1000 | default: |
| 1001 | // do nothing |
| 1002 | } |
| 1003 | } |
| 1004 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 1005 | |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 1006 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1007 | entityID := val.(uint16) |
| 1008 | veipMetrics["entity_id"] = float32(entityID) |
| 1009 | // TODO: Rlock needed for reading uniEntityMap? May not be needed given uniEntityMap is populated setup at initial ONU bring up |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1010 | for _, uni := range *mm.pDeviceHandler.GetUniEntityMap() { |
| 1011 | if uni.EntityID == entityID { |
| 1012 | veipMetrics["uni_port_no"] = float32(uni.PortNo) |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 1013 | break |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1014 | } |
| 1015 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 1016 | } |
Girish Gowdra | da3a52f | 2021-03-17 11:24:11 -0700 | [diff] [blame] | 1017 | veipMetrics["me_class_id"] = float32(me.VirtualEthernetInterfacePointClassID) |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 1018 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1019 | // create slice of metrics given that there could be more than one VEIP instance |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 1020 | metricInfo := voltha.MetricInformation{Metadata: &mmd, Metrics: veipMetrics} |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1021 | metricInfoSlice = append(metricInfoSlice, &metricInfo) |
| 1022 | } |
| 1023 | |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1024 | return metricInfoSlice, nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | // publishMetrics publishes the metrics on kafka |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1028 | func (mm *OnuMetricsManager) publishMetrics(ctx context.Context, metricInfo []*voltha.MetricInformation) { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1029 | var ke voltha.KpiEvent2 |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 1030 | ts := time.Now().Unix() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1031 | ke.SliceData = metricInfo |
| 1032 | ke.Type = voltha.KpiEventType_slice |
| 1033 | ke.Ts = float64(ts) |
| 1034 | |
Himani Chawla | f976888 | 2021-12-01 00:18:58 +0530 | [diff] [blame] | 1035 | if err := mm.pDeviceHandler.GetEventProxy().SendKpiEvent(ctx, "STATS_PUBLISH_EVENT", &ke, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, ts); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 1036 | logger.Errorw(ctx, "failed-to-send-pon-stats", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1040 | // ProcessOmciMessages - TODO: add comment |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 1041 | func (mm *OnuMetricsManager) ProcessOmciMessages(ctx context.Context, waitForOmciProcessor *sync.WaitGroup) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1042 | logger.Infow(ctx, "Start routine to process OMCI-GET messages for device-id", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1043 | // Flush metric collection channels to be safe. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1044 | // It is possible that there is stale data on this channel if the ProcessOmciMessages routine |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1045 | // is stopped right after issuing a OMCI-GET request and started again. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1046 | // The ProcessOmciMessages routine will get stopped if startCollector routine (in device_handler.go) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1047 | // is stopped - as a result of ONU going down. |
| 1048 | mm.flushMetricCollectionChannels(ctx) |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 1049 | // when instantiating mm it was too early, but now we can check for ONU's extended OMCI support |
| 1050 | mm.isExtendedOmci = mm.pOnuDeviceEntry.GetPersIsExtOmciSupported() |
| 1051 | if mm.isExtendedOmci { |
| 1052 | mm.maxL2PMGetPayLoadSize = MaxExtendedL2PMGetPayLoadSize |
| 1053 | } else { |
| 1054 | mm.maxL2PMGetPayLoadSize = MaxBaselineL2PMGetPayLoadSize |
| 1055 | } |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 1056 | mm.updateOmciProcessingStatus(true) |
Girish Gowdra | f7d82d0 | 2022-04-26 16:18:35 -0700 | [diff] [blame] | 1057 | waitForOmciProcessor.Done() |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1058 | for { |
| 1059 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1060 | case <-mm.StopProcessingOmciResponses: // stop this routine |
| 1061 | logger.Infow(ctx, "Stop routine to process OMCI-GET messages for device-id", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 1062 | mm.updateOmciProcessingStatus(false) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1063 | return |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1064 | case message, ok := <-mm.PAdaptFsm.CommChan: |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1065 | if !ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1066 | logger.Errorw(ctx, "Message couldn't be read from channel", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1067 | continue |
| 1068 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1069 | logger.Debugw(ctx, "Received message on ONU metrics channel", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1070 | |
| 1071 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1072 | case cmn.OMCI: |
| 1073 | msg, _ := message.Data.(cmn.OmciMessage) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1074 | mm.handleOmciMessage(ctx, msg) |
| 1075 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1076 | logger.Warn(ctx, "Unknown message type received", log.Fields{"device-id": mm.deviceID, "message.Type": message.Type}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1082 | func (mm *OnuMetricsManager) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) { |
| 1083 | logger.Debugw(ctx, "omci Msg", log.Fields{"device-id": mm.deviceID, |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1084 | "msgType": msg.OmciMsg.MessageType, "msg": msg}) |
| 1085 | switch msg.OmciMsg.MessageType { |
| 1086 | case omci.GetResponseType: |
| 1087 | //TODO: error handling |
| 1088 | _ = mm.handleOmciGetResponseMessage(ctx, msg) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1089 | case omci.SynchronizeTimeResponseType: |
| 1090 | _ = mm.handleOmciSynchronizeTimeResponseMessage(ctx, msg) |
| 1091 | case omci.CreateResponseType: |
| 1092 | _ = mm.handleOmciCreateResponseMessage(ctx, msg) |
| 1093 | case omci.DeleteResponseType: |
| 1094 | _ = mm.handleOmciDeleteResponseMessage(ctx, msg) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1095 | case omci.GetCurrentDataResponseType: |
| 1096 | _ = mm.handleOmciGetCurrentDataResponseMessage(ctx, msg) |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 1097 | case omci.SetResponseType: |
| 1098 | _ = mm.handleOmciSetResponseMessage(ctx, msg) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1099 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 1100 | logger.Warnw(ctx, "Unknown Message Type", log.Fields{"device-id": mm.deviceID, "msgType": msg.OmciMsg.MessageType}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1101 | |
| 1102 | } |
| 1103 | } |
| 1104 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1105 | func (mm *OnuMetricsManager) handleOmciGetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1106 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetResponse) |
| 1107 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1108 | logger.Errorw(ctx, "omci Msg layer could not be detected for GetResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1109 | return fmt.Errorf("omci Msg layer could not be detected for GetResponse - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1110 | } |
| 1111 | msgObj, msgOk := msgLayer.(*omci.GetResponse) |
| 1112 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1113 | logger.Errorw(ctx, "omci Msg layer could not be assigned for GetResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1114 | return fmt.Errorf("omci Msg layer could not be assigned for GetResponse - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1115 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1116 | logger.Debugw(ctx, "OMCI GetResponse Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj, "result": msgObj.Result}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1117 | if msgObj.Result == me.Success { |
| 1118 | meAttributes := msgObj.Attributes |
| 1119 | switch msgObj.EntityClass { |
| 1120 | case me.AniGClassID: |
| 1121 | mm.opticalMetricsChan <- meAttributes |
| 1122 | return nil |
| 1123 | case me.UniGClassID: |
| 1124 | mm.uniStatusMetricsChan <- meAttributes |
| 1125 | return nil |
| 1126 | case me.PhysicalPathTerminationPointEthernetUniClassID: |
| 1127 | mm.uniStatusMetricsChan <- meAttributes |
| 1128 | return nil |
| 1129 | case me.VirtualEthernetInterfacePointClassID: |
| 1130 | mm.uniStatusMetricsChan <- meAttributes |
| 1131 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1132 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 1133 | me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1134 | me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 1135 | me.FecPerformanceMonitoringHistoryDataClassID, |
| 1136 | me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1137 | mm.l2PmChan <- meAttributes |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1138 | return nil |
| 1139 | case me.EthernetFrameExtendedPmClassID, |
| 1140 | me.EthernetFrameExtendedPm64BitClassID: |
| 1141 | mm.extendedPmMeChan <- meAttributes |
| 1142 | return nil |
| 1143 | default: |
| 1144 | logger.Errorw(ctx, "unhandled omci get response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1145 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1146 | } |
| 1147 | } else { |
| 1148 | meAttributes := msgObj.Attributes |
| 1149 | switch msgObj.EntityClass { |
| 1150 | case me.EthernetFrameExtendedPmClassID, |
| 1151 | me.EthernetFrameExtendedPm64BitClassID: |
| 1152 | // not all counters may be supported in which case we have seen some ONUs throwing |
| 1153 | // AttributeFailure error code, while correctly populating other counters it supports |
| 1154 | mm.extendedPmMeChan <- meAttributes |
| 1155 | return nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1156 | default: |
| 1157 | logger.Errorw(ctx, "unhandled omci get response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1158 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1159 | } |
| 1160 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1161 | return fmt.Errorf("unhandled-omci-get-response-message") |
| 1162 | } |
| 1163 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1164 | func (mm *OnuMetricsManager) handleOmciGetCurrentDataResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1165 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetCurrentDataResponse) |
| 1166 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1167 | logger.Errorw(ctx, "omci Msg layer could not be detected for GetCurrentDataResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1168 | return fmt.Errorf("omci Msg layer could not be detected for GetCurrentDataResponse - handling stopped: %s", mm.deviceID) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1169 | } |
| 1170 | msgObj, msgOk := msgLayer.(*omci.GetCurrentDataResponse) |
| 1171 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1172 | logger.Errorw(ctx, "omci Msg layer could not be assigned for GetCurrentDataResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1173 | return fmt.Errorf("omci Msg layer could not be assigned for GetCurrentDataResponse - handling stopped: %s", mm.deviceID) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1174 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1175 | logger.Debugw(ctx, "OMCI GetCurrentDataResponse Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj, "result": msgObj.Result}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1176 | if msgObj.Result == me.Success { |
| 1177 | meAttributes := msgObj.Attributes |
| 1178 | switch msgObj.EntityClass { |
| 1179 | case me.EthernetFrameExtendedPmClassID, |
| 1180 | me.EthernetFrameExtendedPm64BitClassID: |
| 1181 | mm.extendedPmMeChan <- meAttributes |
| 1182 | return nil |
| 1183 | default: |
| 1184 | logger.Errorw(ctx, "unhandled omci get current data response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1185 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1186 | } |
| 1187 | } else { |
| 1188 | meAttributes := msgObj.Attributes |
| 1189 | switch msgObj.EntityClass { |
| 1190 | case me.EthernetFrameExtendedPmClassID, |
| 1191 | me.EthernetFrameExtendedPm64BitClassID: |
| 1192 | // not all counters may be supported in which case we have seen some ONUs throwing |
| 1193 | // AttributeFailure error code, while correctly populating other counters it supports |
| 1194 | mm.extendedPmMeChan <- meAttributes |
| 1195 | return nil |
| 1196 | default: |
| 1197 | logger.Errorw(ctx, "unhandled omci get current data response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1198 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | return fmt.Errorf("unhandled-omci-get-current-data-response-message") |
| 1202 | } |
| 1203 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1204 | func (mm *OnuMetricsManager) handleOmciSynchronizeTimeResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1205 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSynchronizeTimeResponse) |
| 1206 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1207 | logger.Errorw(ctx, "omci Msg layer could not be detected for synchronize time response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1208 | return fmt.Errorf("omci Msg layer could not be detected for synchronize time response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1209 | } |
| 1210 | msgObj, msgOk := msgLayer.(*omci.SynchronizeTimeResponse) |
| 1211 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1212 | logger.Errorw(ctx, "omci Msg layer could not be assigned for synchronize time response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1213 | return fmt.Errorf("omci Msg layer could not be assigned for synchronize time response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1214 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1215 | logger.Debugw(ctx, "OMCI synchronize time response Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1216 | if msgObj.Result == me.Success { |
| 1217 | switch msgObj.EntityClass { |
| 1218 | case me.OnuGClassID: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1219 | logger.Infow(ctx, "omci synchronize time success", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1220 | mm.syncTimeResponseChan <- true |
| 1221 | return nil |
| 1222 | default: |
| 1223 | logger.Errorw(ctx, "unhandled omci message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1224 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | mm.syncTimeResponseChan <- false |
| 1228 | logger.Errorf(ctx, "unhandled-omci-synchronize-time-response-message--error-code-%v", msgObj.Result) |
| 1229 | return fmt.Errorf("unhandled-omci-synchronize-time-response-message--error-code-%v", msgObj.Result) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 1232 | func (mm *OnuMetricsManager) handleOmciSetResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
| 1233 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeSetResponse) |
| 1234 | if msgLayer == nil { |
| 1235 | logger.Errorw(ctx, "omci Msg layer could not be detected for SetResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1236 | return fmt.Errorf("omci Msg layer could not be detected for SetResponse - handling stopped: %s", mm.deviceID) |
| 1237 | } |
| 1238 | msgObj, msgOk := msgLayer.(*omci.SetResponse) |
| 1239 | if !msgOk { |
| 1240 | logger.Errorw(ctx, "omci Msg layer could not be assigned for SetResponse - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 1241 | return fmt.Errorf("omci Msg layer could not be assigned for SetResponse - handling stopped: %s", mm.deviceID) |
| 1242 | } |
| 1243 | logger.Debugw(ctx, "OMCI SetResponse Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj, "result": msgObj.Result}) |
| 1244 | switch msgObj.EntityClass { |
| 1245 | case me.EthernetFrameExtendedPmClassID, |
| 1246 | me.EthernetFrameExtendedPm64BitClassID: |
| 1247 | mm.extendedPMMeResponseChan <- msgObj.Result |
| 1248 | return nil |
| 1249 | default: |
| 1250 | logger.Errorw(ctx, "unhandled omci set response message", |
| 1251 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
| 1252 | } |
| 1253 | return fmt.Errorf("unhandled-omci-set-response-message-%v", mm.deviceID) |
| 1254 | } |
| 1255 | |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1256 | // flushMetricCollectionChannels flushes all metric collection channels for any stale OMCI responses |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1257 | func (mm *OnuMetricsManager) flushMetricCollectionChannels(ctx context.Context) { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1258 | // flush commMetricsChan |
| 1259 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1260 | case <-mm.PAdaptFsm.CommChan: |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1261 | logger.Debug(ctx, "flushed common metrics channel") |
| 1262 | default: |
| 1263 | } |
| 1264 | |
| 1265 | // flush opticalMetricsChan |
| 1266 | select { |
| 1267 | case <-mm.opticalMetricsChan: |
| 1268 | logger.Debug(ctx, "flushed optical metrics channel") |
| 1269 | default: |
| 1270 | } |
| 1271 | |
| 1272 | // flush uniStatusMetricsChan |
| 1273 | select { |
| 1274 | case <-mm.uniStatusMetricsChan: |
| 1275 | logger.Debug(ctx, "flushed uni status metrics channel") |
| 1276 | default: |
| 1277 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1278 | |
| 1279 | // flush syncTimeResponseChan |
| 1280 | select { |
| 1281 | case <-mm.syncTimeResponseChan: |
| 1282 | logger.Debug(ctx, "flushed sync time response channel") |
| 1283 | default: |
| 1284 | } |
| 1285 | |
| 1286 | // flush l2PmChan |
| 1287 | select { |
| 1288 | case <-mm.l2PmChan: |
| 1289 | logger.Debug(ctx, "flushed L2 PM collection channel") |
| 1290 | default: |
| 1291 | } |
| 1292 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1293 | // flush StopTicks |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1294 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1295 | case <-mm.StopTicks: |
| 1296 | logger.Debug(ctx, "flushed StopTicks channel") |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1297 | default: |
| 1298 | } |
| 1299 | |
| 1300 | } |
| 1301 | |
| 1302 | // ** L2 PM FSM Handlers start ** |
| 1303 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1304 | func (mm *OnuMetricsManager) l2PMFsmStarting(ctx context.Context, e *fsm.Event) { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1305 | if mm.GetdeviceDeletionInProgress() { |
| 1306 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1307 | return |
| 1308 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1309 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1310 | // Loop through all the group metrics |
| 1311 | // If it is a L2 PM Interval metric and it is enabled, then if it is not in the |
| 1312 | // list of active L2 PM list then mark it for creation |
| 1313 | // It it is a L2 PM Interval metric and it is disabled, then if it is in the |
| 1314 | // list of active L2 PM list then mark it for deletion |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1315 | mm.OnuMetricsManagerLock.Lock() |
| 1316 | for n, g := range mm.GroupMetricMap { |
| 1317 | if g.IsL2PMCounter { // it is a l2 pm counter |
| 1318 | if g.Enabled { // metric enabled. |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1319 | found := false |
| 1320 | inner1: |
| 1321 | for _, v := range mm.activeL2Pms { |
| 1322 | if v == n { |
| 1323 | found = true // metric already present in active l2 pm list |
| 1324 | break inner1 |
| 1325 | } |
| 1326 | } |
| 1327 | if !found { // metric not in active l2 pm list. Mark this to be added later |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1328 | mm.l2PmToAdd = mm.appendIfMissingString(mm.l2PmToAdd, n) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1329 | } |
| 1330 | } else { // metric not enabled. |
| 1331 | found := false |
| 1332 | inner2: |
| 1333 | for _, v := range mm.activeL2Pms { |
| 1334 | if v == n { |
| 1335 | found = true // metric is found in active l2 pm list |
| 1336 | break inner2 |
| 1337 | } |
| 1338 | } |
| 1339 | if found { // metric is found in active l2 pm list. Mark this to be deleted later |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1340 | mm.l2PmToDelete = mm.appendIfMissingString(mm.l2PmToDelete, n) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1345 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1346 | logger.Debugw(ctx, "pms to add and delete", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1347 | log.Fields{"device-id": mm.deviceID, "pms-to-add": mm.l2PmToAdd, "pms-to-delete": mm.l2PmToDelete}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1348 | go func() { |
| 1349 | // push a tick event to move to next state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1350 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventTick); err != nil { |
| 1351 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1352 | } |
| 1353 | }() |
| 1354 | } |
| 1355 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1356 | func (mm *OnuMetricsManager) l2PMFsmSyncTime(ctx context.Context, e *fsm.Event) { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1357 | if mm.GetdeviceDeletionInProgress() { |
| 1358 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1359 | return |
| 1360 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1361 | // Sync time with the ONU to establish 15min boundary for PM collection. |
| 1362 | if err := mm.syncTime(ctx); err != nil { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1363 | // device could be deleted while waiting on sync time response |
| 1364 | if mm.GetdeviceDeletionInProgress() { |
| 1365 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1366 | return |
| 1367 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1368 | go func() { |
| 1369 | time.Sleep(SyncTimeRetryInterval * time.Second) // retry to sync time after this timeout |
| 1370 | // This will result in FSM attempting to sync time again |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1371 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventFailure); err != nil { |
| 1372 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1373 | } |
| 1374 | }() |
| 1375 | } |
| 1376 | // Initiate a tick generation routine every L2PmCollectionInterval |
| 1377 | go mm.generateTicks(ctx) |
| 1378 | |
| 1379 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1380 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventSuccess); err != nil { |
| 1381 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1382 | } |
| 1383 | }() |
| 1384 | } |
| 1385 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1386 | func (mm *OnuMetricsManager) l2PMFsmNull(ctx context.Context, e *fsm.Event) { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1387 | // We need to reset the local data so that the L2 PM MEs are re-provisioned once the ONU is back up based on the latest PM CONFIG |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1388 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1389 | mm.activeL2Pms = nil |
| 1390 | mm.l2PmToAdd = nil |
| 1391 | mm.l2PmToDelete = nil |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1392 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1393 | // If the FSM was stopped, then clear PM data from KV store |
| 1394 | // The FSM is stopped when ONU goes down. It is time to clear its data from store |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1395 | if e.Event == L2PmEventStop { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1396 | _ = mm.clearPmGroupData(ctx) // ignore error |
| 1397 | } |
| 1398 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1399 | if mm.GetdeviceDeletionInProgress() { |
| 1400 | mm.pDeviceHandler = nil |
| 1401 | mm.pOnuDeviceEntry = nil |
| 1402 | mm.GarbageCollectionComplete <- true |
| 1403 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1404 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1405 | func (mm *OnuMetricsManager) l2PMFsmIdle(ctx context.Context, e *fsm.Event) { |
| 1406 | logger.Debugw(ctx, "Enter state idle", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1407 | if mm.GetdeviceDeletionInProgress() { |
| 1408 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1409 | return |
| 1410 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1411 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1412 | mm.OnuMetricsManagerLock.RLock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1413 | numOfPmToDelete := len(mm.l2PmToDelete) |
| 1414 | numOfPmToAdd := len(mm.l2PmToAdd) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1415 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1416 | |
| 1417 | if numOfPmToDelete > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1418 | logger.Debugw(ctx, "state idle - pms to delete", log.Fields{"device-id": mm.deviceID, "pms-to-delete": numOfPmToDelete}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1419 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1420 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventDeleteMe); err != nil { |
| 1421 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1422 | } |
| 1423 | }() |
| 1424 | } else if numOfPmToAdd > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1425 | logger.Debugw(ctx, "state idle - pms to add", log.Fields{"device-id": mm.deviceID, "pms-to-add": numOfPmToAdd}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1426 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1427 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventAddMe); err != nil { |
| 1428 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1429 | } |
| 1430 | }() |
| 1431 | } |
| 1432 | } |
| 1433 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1434 | func (mm *OnuMetricsManager) l2PmFsmCollectData(ctx context.Context, e *fsm.Event) { |
| 1435 | logger.Debugw(ctx, "state collect data", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1436 | if mm.GetdeviceDeletionInProgress() { |
| 1437 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1438 | return |
| 1439 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1440 | // Copy the activeL2Pms for which we want to collect the metrics since activeL2Pms can change dynamically |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1441 | mm.OnuMetricsManagerLock.RLock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1442 | copyOfActiveL2Pms := make([]string, len(mm.activeL2Pms)) |
| 1443 | _ = copy(copyOfActiveL2Pms, mm.activeL2Pms) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1444 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1445 | |
| 1446 | for _, n := range copyOfActiveL2Pms { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1447 | var metricInfoSlice []*voltha.MetricInformation |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1448 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1449 | // mm.GroupMetricMap[n].pmMEData.InstancesActive could dynamically change, so make a copy |
| 1450 | mm.OnuMetricsManagerLock.RLock() |
| 1451 | copyOfEntityIDs := make([]uint16, len(mm.GroupMetricMap[n].pmMEData.InstancesActive)) |
| 1452 | _ = copy(copyOfEntityIDs, mm.GroupMetricMap[n].pmMEData.InstancesActive) |
| 1453 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1454 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1455 | switch n { |
| 1456 | case EthernetBridgeHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1457 | logger.Debugw(ctx, "state collect data - collecting data for EthernetFramePerformanceMonitoringHistoryData ME", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1458 | for _, entityID := range copyOfEntityIDs { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1459 | if metricInfo := mm.collectEthernetFramePerformanceMonitoringHistoryData(ctx, true, entityID); metricInfo != nil { // upstream |
| 1460 | metricInfoSlice = append(metricInfoSlice, metricInfo) |
| 1461 | } |
| 1462 | if metricInfo := mm.collectEthernetFramePerformanceMonitoringHistoryData(ctx, false, entityID); metricInfo != nil { // downstream |
| 1463 | metricInfoSlice = append(metricInfoSlice, metricInfo) |
| 1464 | } |
| 1465 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1466 | case EthernetUniHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1467 | logger.Debugw(ctx, "state collect data - collecting data for EthernetPerformanceMonitoringHistoryData ME", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1468 | for _, entityID := range copyOfEntityIDs { |
| 1469 | if metricInfo := mm.collectEthernetUniHistoryData(ctx, entityID); metricInfo != nil { // upstream |
| 1470 | metricInfoSlice = append(metricInfoSlice, metricInfo) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1471 | } |
| 1472 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1473 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1474 | case FecHistoryName: |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1475 | for _, entityID := range copyOfEntityIDs { |
| 1476 | if metricInfo := mm.collectFecHistoryData(ctx, entityID); metricInfo != nil { // upstream |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1477 | metricInfoSlice = append(metricInfoSlice, metricInfo) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1478 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1479 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1480 | case GemPortHistoryName: |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1481 | for _, entityID := range copyOfEntityIDs { |
| 1482 | if metricInfo := mm.collectGemHistoryData(ctx, entityID); metricInfo != nil { // upstream |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1483 | metricInfoSlice = append(metricInfoSlice, metricInfo) |
| 1484 | } |
| 1485 | } |
| 1486 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1487 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1488 | logger.Errorw(ctx, "unsupported l2 pm", log.Fields{"device-id": mm.deviceID, "name": n}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1489 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1490 | mm.handleMetricsPublish(ctx, n, metricInfoSlice) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1491 | } |
| 1492 | // Does not matter we send success or failure here. |
| 1493 | // Those PMs that we failed to collect data will be attempted to collect again in the next PM collection cycle (assuming |
| 1494 | // we have not exceed max attempts to collect the PM data) |
| 1495 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1496 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventSuccess); err != nil { |
| 1497 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1498 | } |
| 1499 | }() |
| 1500 | } |
| 1501 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1502 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1503 | func (mm *OnuMetricsManager) l2PmFsmCreatePM(ctx context.Context, e *fsm.Event) error { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1504 | if mm.GetdeviceDeletionInProgress() { |
| 1505 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1506 | return nil |
| 1507 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1508 | // Copy the l2PmToAdd for which we want to collect the metrics since l2PmToAdd can change dynamically |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1509 | mm.OnuMetricsManagerLock.RLock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1510 | copyOfL2PmToAdd := make([]string, len(mm.l2PmToAdd)) |
| 1511 | _ = copy(copyOfL2PmToAdd, mm.l2PmToAdd) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1512 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1513 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1514 | logger.Debugw(ctx, "state create pm - start", log.Fields{"device-id": mm.deviceID, "pms-to-add": copyOfL2PmToAdd}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1515 | for _, n := range copyOfL2PmToAdd { |
| 1516 | resp := false |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1517 | atLeastOneSuccess := false // flag indicates if at least one ME instance of the PM was successfully created. |
| 1518 | cnt := 0 |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1519 | switch n { |
| 1520 | case EthernetBridgeHistoryName: |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1521 | // Create ME twice, one for each direction. Boolean true is used to indicate upstream and false for downstream. |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 1522 | for _, direction := range []bool{true, false} { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1523 | for _, uniPort := range *mm.pDeviceHandler.GetUniEntityMap() { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1524 | // Attach the EthernetFramePerformanceMonitoringHistoryData ME to MacBridgePortConfigData on the UNI port |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1525 | entityID := cmn.MacBridgePortAniBaseEID + uniPort.EntityID |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1526 | _ = mm.updatePmData(ctx, n, entityID, cPmAdd) // TODO: ignore error for now |
| 1527 | inner1: |
| 1528 | // retry L2PmCreateAttempts times to create the instance of PM |
| 1529 | for cnt = 0; cnt < L2PmCreateAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1530 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteEthernetPerformanceMonitoringHistoryME( |
| 1531 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, direction, true, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1532 | if err != nil { |
| 1533 | logger.Errorw(ctx, "EthernetPerformanceMonitoringHistoryME create or delete failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1534 | log.Fields{"device-id": mm.deviceID}) |
| 1535 | pPMFsm := mm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1536 | if pPMFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1537 | go func(p_pmFsm *cmn.AdapterFsm) { |
| 1538 | _ = p_pmFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1539 | }(pPMFsm) |
| 1540 | } |
| 1541 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteEthernetPerformanceMonitoringHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1542 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1543 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1544 | if resp = mm.waitForResponseOrTimeout(ctx, true, entityID, "EthernetFramePerformanceMonitoringHistoryData"); resp { |
| 1545 | atLeastOneSuccess = true |
| 1546 | _ = mm.updatePmData(ctx, n, entityID, cPmAdded) // TODO: ignore error for now |
| 1547 | break inner1 |
| 1548 | } |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1549 | if mm.GetdeviceDeletionInProgress() { |
| 1550 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1551 | return nil |
| 1552 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1553 | } |
| 1554 | if cnt == L2PmCreateAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1555 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | case EthernetUniHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1560 | for _, uniPort := range *mm.pDeviceHandler.GetUniEntityMap() { |
| 1561 | if uniPort.PortType == cmn.UniPPTP { // This metric is only applicable for PPTP Uni Type |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1562 | // Attach the EthernetPerformanceMonitoringHistoryData ME to PPTP port instance |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1563 | entityID := uniPort.EntityID |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1564 | _ = mm.updatePmData(ctx, n, entityID, cPmAdd) // TODO: ignore error for now |
| 1565 | inner2: |
| 1566 | // retry L2PmCreateAttempts times to create the instance of PM |
| 1567 | for cnt = 0; cnt < L2PmCreateAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1568 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteEthernetUniHistoryME( |
| 1569 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, true, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1570 | if err != nil { |
| 1571 | logger.Errorw(ctx, "CreateOrDeleteEthernetUNIHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1572 | log.Fields{"device-id": mm.deviceID}) |
| 1573 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1574 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteEthernetUniHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1575 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1576 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1577 | if resp = mm.waitForResponseOrTimeout(ctx, true, entityID, "EthernetPerformanceMonitoringHistoryData"); resp { |
| 1578 | atLeastOneSuccess = true |
| 1579 | _ = mm.updatePmData(ctx, n, entityID, cPmAdded) // TODO: ignore error for now |
| 1580 | break inner2 |
| 1581 | } |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1582 | if mm.GetdeviceDeletionInProgress() { |
| 1583 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1584 | return nil |
| 1585 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1586 | } |
| 1587 | if cnt == L2PmCreateAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1588 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1592 | case FecHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1593 | for _, anigInstID := range mm.pOnuDeviceEntry.GetOnuDB().GetSortedInstKeys(ctx, me.AniGClassID) { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1594 | // Attach the FecPerformanceMonitoringHistoryData ME to the ANI-G ME instance |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1595 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteFecHistoryME( |
| 1596 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, true, mm.PAdaptFsm.CommChan, anigInstID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1597 | if err != nil { |
| 1598 | logger.Errorw(ctx, "CreateOrDeleteFecHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1599 | log.Fields{"device-id": mm.deviceID}) |
| 1600 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1601 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteFecHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1602 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1603 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1604 | _ = mm.updatePmData(ctx, n, anigInstID, cPmAdd) // TODO: ignore error for now |
| 1605 | inner3: |
| 1606 | // retry L2PmCreateAttempts times to create the instance of PM |
| 1607 | for cnt = 0; cnt < L2PmCreateAttempts; cnt++ { |
| 1608 | if resp = mm.waitForResponseOrTimeout(ctx, true, anigInstID, "FecPerformanceMonitoringHistoryData"); resp { |
| 1609 | atLeastOneSuccess = true |
| 1610 | _ = mm.updatePmData(ctx, n, anigInstID, cPmAdded) // TODO: ignore error for now |
| 1611 | break inner3 |
| 1612 | } |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1613 | if mm.GetdeviceDeletionInProgress() { |
| 1614 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1615 | return nil |
| 1616 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1617 | } |
| 1618 | if cnt == L2PmCreateAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1619 | _ = mm.updatePmData(ctx, n, anigInstID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | case GemPortHistoryName: |
| 1623 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1624 | mm.OnuMetricsManagerLock.RLock() |
| 1625 | copyOfGemPortInstIDsToAdd := make([]uint16, len(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd)) |
| 1626 | _ = copy(copyOfGemPortInstIDsToAdd, mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd) |
| 1627 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1628 | |
| 1629 | if len(copyOfGemPortInstIDsToAdd) == 0 { |
| 1630 | // If there are no gemport history MEs to be created, just skip further processing |
| 1631 | // Otherwise down below (after 'switch' case handling) we assume the ME creation failed because resp and atLeastOneSuccess flag are false. |
| 1632 | // Normally there are no GemPortHistory MEs to create at start up. They come in only after provisioning service on the ONU. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1633 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1634 | mm.l2PmToAdd = mm.removeIfFoundString(mm.l2PmToAdd, n) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1635 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1636 | continue |
| 1637 | } |
| 1638 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1639 | for _, v := range copyOfGemPortInstIDsToAdd { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1640 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteGemPortHistoryME( |
| 1641 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, true, mm.PAdaptFsm.CommChan, v) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1642 | if err != nil { |
| 1643 | logger.Errorw(ctx, "CreateOrDeleteGemPortHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1644 | log.Fields{"device-id": mm.deviceID}) |
| 1645 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1646 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteGemPortHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1647 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1648 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1649 | _ = mm.updatePmData(ctx, n, v, cPmAdd) // TODO: ignore error for now |
| 1650 | inner4: |
| 1651 | // retry L2PmCreateAttempts times to create the instance of PM |
| 1652 | for cnt = 0; cnt < L2PmCreateAttempts; cnt++ { |
| 1653 | if resp = mm.waitForResponseOrTimeout(ctx, true, v, "GemPortNetworkCtpPerformanceMonitoringHistoryData"); resp { |
| 1654 | atLeastOneSuccess = true |
| 1655 | _ = mm.updatePmData(ctx, n, v, cPmAdded) // TODO: ignore error for now |
| 1656 | break inner4 |
| 1657 | } |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1658 | if mm.GetdeviceDeletionInProgress() { |
| 1659 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1660 | return nil |
| 1661 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1662 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1663 | if cnt == L2PmCreateAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1664 | _ = mm.updatePmData(ctx, n, v, cPmRemoved) // TODO: ignore error for now |
| 1665 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1666 | } |
| 1667 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1668 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1669 | logger.Errorw(ctx, "unsupported l2 pm", log.Fields{"device-id": mm.deviceID, "name": n}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1670 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1671 | // On success of at least one instance of the PM for a given ME, update the local list maintained for active PMs and PMs to add |
| 1672 | if atLeastOneSuccess { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1673 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1674 | mm.activeL2Pms = mm.appendIfMissingString(mm.activeL2Pms, n) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 1675 | // gem ports can be added dynamically for perf monitoring. We want to clear the GemPortHistoryName from mm.l2PmToAdd |
| 1676 | // only if no more new gem port instances created. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1677 | if n != GemPortHistoryName || (n == GemPortHistoryName && len(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd) == 0) { |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 1678 | mm.l2PmToAdd = mm.removeIfFoundString(mm.l2PmToAdd, n) |
| 1679 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1680 | logger.Debugw(ctx, "success-resp", log.Fields{"pm-name": n, "active-l2-pms": mm.activeL2Pms, "pms-to-add": mm.l2PmToAdd}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1681 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1682 | } else { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1683 | // If we are here then no instance of the PM of the given ME were created successfully, so locally disable the PM |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1684 | // and also remove it from l2PmToAdd slice so that we do not try to create the PM ME anymore |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1685 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1686 | logger.Debugw(ctx, "exceeded-max-add-retry-attempts--disabling-group", log.Fields{"groupName": n}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1687 | mm.GroupMetricMap[n].Enabled = false |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1688 | mm.l2PmToAdd = mm.removeIfFoundString(mm.l2PmToAdd, n) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1689 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1690 | logger.Warnw(ctx, "state create pm - failed to create pm", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1691 | log.Fields{"device-id": mm.deviceID, "metricName": n, |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1692 | "active-l2-pms": mm.activeL2Pms, "pms-to-add": mm.l2PmToAdd}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1693 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1694 | } |
| 1695 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1696 | mm.OnuMetricsManagerLock.RLock() |
| 1697 | logger.Debugw(ctx, "state create pm - done", log.Fields{"device-id": mm.deviceID, "active-l2-pms": mm.activeL2Pms, "pms-to-add": mm.l2PmToAdd}) |
| 1698 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1699 | // Does not matter we send success or failure here. |
| 1700 | // Those PMs that we failed to create will be attempted to create again in the next PM creation cycle (assuming |
| 1701 | // we have not exceed max attempts to create the PM ME) |
| 1702 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1703 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventSuccess); err != nil { |
| 1704 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1705 | } |
| 1706 | }() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1707 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1710 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1711 | func (mm *OnuMetricsManager) l2PmFsmDeletePM(ctx context.Context, e *fsm.Event) error { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1712 | if mm.GetdeviceDeletionInProgress() { |
| 1713 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1714 | return nil |
| 1715 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1716 | // Copy the l2PmToDelete for which we want to collect the metrics since l2PmToDelete can change dynamically |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1717 | mm.OnuMetricsManagerLock.RLock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1718 | copyOfL2PmToDelete := make([]string, len(mm.l2PmToDelete)) |
| 1719 | _ = copy(copyOfL2PmToDelete, mm.l2PmToDelete) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1720 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1721 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1722 | logger.Debugw(ctx, "state delete pm", log.Fields{"device-id": mm.deviceID, "pms-to-delete": copyOfL2PmToDelete}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1723 | for _, n := range copyOfL2PmToDelete { |
| 1724 | resp := false |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1725 | cnt := 0 |
| 1726 | atLeastOneDeleteFailure := false |
| 1727 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1728 | // mm.GroupMetricMap[n].pmMEData.InstancesActive could dynamically change, so make a copy |
| 1729 | mm.OnuMetricsManagerLock.RLock() |
| 1730 | copyOfEntityIDs := make([]uint16, len(mm.GroupMetricMap[n].pmMEData.InstancesActive)) |
| 1731 | _ = copy(copyOfEntityIDs, mm.GroupMetricMap[n].pmMEData.InstancesActive) |
| 1732 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1733 | |
| 1734 | if len(copyOfEntityIDs) == 0 { |
| 1735 | // if there are no enityIDs to remove for the PM ME just clear the PM name entry from cache and continue |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1736 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1737 | mm.activeL2Pms = mm.removeIfFoundString(mm.activeL2Pms, n) |
| 1738 | mm.l2PmToDelete = mm.removeIfFoundString(mm.l2PmToDelete, n) |
| 1739 | logger.Debugw(ctx, "success-resp", log.Fields{"pm-name": n, "active-l2-pms": mm.activeL2Pms, "pms-to-delete": mm.l2PmToDelete}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1740 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1741 | continue |
| 1742 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1743 | logger.Debugw(ctx, "entities to delete", log.Fields{"device-id": mm.deviceID, "metricName": n, "entityIDs": copyOfEntityIDs}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1744 | switch n { |
| 1745 | case EthernetBridgeHistoryName: |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1746 | // Create ME twice, one for each direction. Boolean true is used to indicate upstream and false for downstream. |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 1747 | for _, direction := range []bool{true, false} { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1748 | for _, entityID := range copyOfEntityIDs { |
| 1749 | inner1: |
| 1750 | // retry L2PmDeleteAttempts times to delete the instance of PM |
| 1751 | for cnt = 0; cnt < L2PmDeleteAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1752 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteEthernetPerformanceMonitoringHistoryME( |
| 1753 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, direction, false, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1754 | if err != nil { |
| 1755 | logger.Errorw(ctx, "CreateOrDeleteEthernetPerformanceMonitoringHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1756 | log.Fields{"device-id": mm.deviceID}) |
| 1757 | pPMFsm := mm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1758 | if pPMFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1759 | go func(p_pmFsm *cmn.AdapterFsm) { |
| 1760 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1761 | }(pPMFsm) |
| 1762 | } |
| 1763 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteEthernetPerformanceMonitoringHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1764 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1765 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1766 | _ = mm.updatePmData(ctx, n, entityID, cPmRemove) // TODO: ignore error for now |
| 1767 | if resp = mm.waitForResponseOrTimeout(ctx, false, entityID, "EthernetFramePerformanceMonitoringHistoryData"); !resp { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1768 | if mm.GetdeviceDeletionInProgress() { |
| 1769 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1770 | return nil |
| 1771 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1772 | atLeastOneDeleteFailure = true |
| 1773 | } else { |
| 1774 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
| 1775 | break inner1 |
| 1776 | } |
| 1777 | } |
| 1778 | if cnt == L2PmDeleteAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1779 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | case EthernetUniHistoryName: |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1784 | for _, entityID := range copyOfEntityIDs { |
| 1785 | inner2: |
| 1786 | // retry L2PmDeleteAttempts times to delete the instance of PM |
| 1787 | for cnt = 0; cnt < L2PmDeleteAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1788 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteEthernetUniHistoryME( |
| 1789 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, false, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1790 | if err != nil { |
| 1791 | logger.Errorw(ctx, "CreateOrDeleteEthernetUniHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1792 | log.Fields{"device-id": mm.deviceID}) |
| 1793 | pmFsm := mm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1794 | if pmFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1795 | go func(p_pmFsm *cmn.AdapterFsm) { |
| 1796 | _ = p_pmFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1797 | }(pmFsm) |
| 1798 | return err |
| 1799 | } |
| 1800 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteEthernetUniHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1801 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1802 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1803 | if resp = mm.waitForResponseOrTimeout(ctx, false, entityID, "EthernetPerformanceMonitoringHistoryData"); !resp { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1804 | if mm.GetdeviceDeletionInProgress() { |
| 1805 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1806 | return nil |
| 1807 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1808 | atLeastOneDeleteFailure = true |
| 1809 | } else { |
| 1810 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1811 | break inner2 |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1812 | } |
| 1813 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1814 | if cnt == L2PmDeleteAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1815 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
| 1816 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1817 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1818 | case FecHistoryName: |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1819 | for _, entityID := range copyOfEntityIDs { |
| 1820 | inner3: |
| 1821 | // retry L2PmDeleteAttempts times to delete the instance of PM |
| 1822 | for cnt = 0; cnt < L2PmDeleteAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1823 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteFecHistoryME( |
| 1824 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, false, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1825 | if err != nil { |
| 1826 | logger.Errorw(ctx, "CreateOrDeleteFecHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1827 | log.Fields{"device-id": mm.deviceID}) |
| 1828 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1829 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteFecHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1830 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1831 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1832 | if resp := mm.waitForResponseOrTimeout(ctx, false, entityID, "FecPerformanceMonitoringHistoryData"); !resp { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1833 | if mm.GetdeviceDeletionInProgress() { |
| 1834 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1835 | return nil |
| 1836 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1837 | atLeastOneDeleteFailure = true |
| 1838 | } else { |
| 1839 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
| 1840 | break inner3 |
| 1841 | } |
| 1842 | } |
| 1843 | if cnt == L2PmDeleteAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1844 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | case GemPortHistoryName: |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1848 | for _, entityID := range copyOfEntityIDs { |
| 1849 | inner4: |
| 1850 | // retry L2PmDeleteAttempts times to delete the instance of PM |
| 1851 | for cnt = 0; cnt < L2PmDeleteAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1852 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteGemPortHistoryME( |
| 1853 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, false, mm.PAdaptFsm.CommChan, entityID) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1854 | if err != nil { |
| 1855 | logger.Errorw(ctx, "CreateOrDeleteGemPortHistoryME failed, failure PM FSM!", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1856 | log.Fields{"device-id": mm.deviceID}) |
| 1857 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1858 | return fmt.Errorf(fmt.Sprintf("CreateOrDeleteGemPortHistoryMe-failed-%s-%s", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1859 | mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1860 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1861 | if resp = mm.waitForResponseOrTimeout(ctx, false, entityID, "GemPortNetworkCtpPerformanceMonitoringHistoryData"); !resp { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1862 | if mm.GetdeviceDeletionInProgress() { |
| 1863 | logger.Debugw(ctx, "device deleted, no more pm processing", log.Fields{"deviceID": mm.deviceID}) |
| 1864 | return nil |
| 1865 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1866 | atLeastOneDeleteFailure = true |
| 1867 | } else { |
| 1868 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
| 1869 | break inner4 |
| 1870 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1871 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1872 | if cnt == L2PmDeleteAttempts { // if we reached max attempts just give up hope on this given instance of the PM ME |
| 1873 | _ = mm.updatePmData(ctx, n, entityID, cPmRemoved) // TODO: ignore error for now |
| 1874 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1875 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1876 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1877 | logger.Errorw(ctx, "unsupported l2 pm", log.Fields{"device-id": mm.deviceID, "name": n}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1878 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1879 | // If we could not completely clean up the PM ME then just give up. |
| 1880 | if atLeastOneDeleteFailure { |
| 1881 | logger.Warnw(ctx, "state delete pm - failed to delete at least one instance of the PM ME", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1882 | log.Fields{"device-id": mm.deviceID, "metricName": n, |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1883 | "active-l2-pms": mm.activeL2Pms, "pms-to-delete": mm.l2PmToDelete}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1884 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1885 | logger.Debugw(ctx, "exceeded-max-delete-retry-attempts--disabling-group", log.Fields{"groupName": n}) |
| 1886 | mm.activeL2Pms = mm.removeIfFoundString(mm.activeL2Pms, n) |
| 1887 | mm.l2PmToDelete = mm.removeIfFoundString(mm.l2PmToDelete, n) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1888 | mm.GroupMetricMap[n].Enabled = false |
| 1889 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 1890 | } else { // success case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1891 | mm.OnuMetricsManagerLock.Lock() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1892 | mm.activeL2Pms = mm.removeIfFoundString(mm.activeL2Pms, n) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 1893 | // gem ports can be deleted dynamically from perf monitoring. We want to clear the GemPortHistoryName from mm.l2PmToDelete |
| 1894 | // only if no more new gem port instances removed. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1895 | if n != GemPortHistoryName || (n == GemPortHistoryName && len(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete) == 0) { |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 1896 | mm.l2PmToDelete = mm.removeIfFoundString(mm.l2PmToDelete, n) |
| 1897 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1898 | logger.Debugw(ctx, "success-resp", log.Fields{"pm-name": n, "active-l2-pms": mm.activeL2Pms, "pms-to-delete": mm.l2PmToDelete}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1899 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1900 | } |
| 1901 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1902 | mm.OnuMetricsManagerLock.RLock() |
| 1903 | logger.Debugw(ctx, "state delete pm - done", log.Fields{"device-id": mm.deviceID, "active-l2-pms": mm.activeL2Pms, "pms-to-delete": mm.l2PmToDelete}) |
| 1904 | mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1905 | // Does not matter we send success or failure here. |
| 1906 | // Those PMs that we failed to delete will be attempted to create again in the next PM collection cycle |
| 1907 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1908 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventSuccess); err != nil { |
| 1909 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1910 | } |
| 1911 | }() |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 1912 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | // ** L2 PM FSM Handlers end ** |
| 1916 | |
| 1917 | // syncTime synchronizes time with the ONU to establish a 15 min boundary for PM collection and reporting. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1918 | func (mm *OnuMetricsManager) syncTime(ctx context.Context) error { |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 1919 | if mm.GetdeviceDeletionInProgress() { |
| 1920 | logger.Infow(ctx, "device already deleted, return", log.Fields{"curr-state": mm.PAdaptFsm.PFsm.Current, "deviceID": mm.deviceID}) |
| 1921 | return nil |
| 1922 | } |
| 1923 | |
| 1924 | if !mm.GetOmciProcessingStatus() { |
| 1925 | logger.Errorw(ctx, "not sending sync time, because the omci resp processor is shutdown due to device down/delete", log.Fields{"device-id": mm.deviceID}) |
| 1926 | return fmt.Errorf("omci-resp-processor-not-running") |
| 1927 | } |
| 1928 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1929 | if err := mm.pOnuDeviceEntry.GetDevOmciCC().SendSyncTime(ctx, mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan); err != nil { |
| 1930 | logger.Errorw(ctx, "cannot send sync time request", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1931 | return err |
| 1932 | } |
| 1933 | |
| 1934 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1935 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 1936 | logger.Errorw(ctx, "timed out waiting for sync time response from onu", log.Fields{"device-id": mm.deviceID}) |
| 1937 | return fmt.Errorf("timed-out-waiting-for-sync-time-response-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1938 | case syncTimeRes := <-mm.syncTimeResponseChan: |
| 1939 | if !syncTimeRes { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1940 | return fmt.Errorf("failed-to-sync-time-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1941 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1942 | logger.Infow(ctx, "sync time success", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1943 | return nil |
| 1944 | } |
| 1945 | } |
| 1946 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1947 | func (mm *OnuMetricsManager) collectEthernetFramePerformanceMonitoringHistoryData(ctx context.Context, upstream bool, entityID uint16) *voltha.MetricInformation { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1948 | var mEnt *me.ManagedEntity |
| 1949 | var omciErr me.OmciErrors |
| 1950 | var classID me.ClassID |
| 1951 | var meAttributes me.AttributeValueMap |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1952 | logger.Debugw(ctx, "collecting data for EthernetFramePerformanceMonitoringHistoryData", log.Fields{"device-id": mm.deviceID, "entityID": entityID, "upstream": upstream}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1953 | meParam := me.ParamData{EntityID: entityID} |
| 1954 | if upstream { |
| 1955 | if mEnt, omciErr = me.NewEthernetFramePerformanceMonitoringHistoryDataUpstream(meParam); omciErr == nil || mEnt == nil || omciErr.GetError() != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1956 | logger.Errorw(ctx, "error creating me", log.Fields{"device-id": mm.deviceID, "entityID": entityID, "upstream": upstream}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1957 | return nil |
| 1958 | } |
| 1959 | classID = me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID |
| 1960 | } else { |
| 1961 | if mEnt, omciErr = me.NewEthernetFramePerformanceMonitoringHistoryDataDownstream(meParam); omciErr == nil || mEnt == nil || omciErr.GetError() != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1962 | logger.Errorw(ctx, "error creating me", log.Fields{"device-id": mm.deviceID, "entityID": entityID, "upstream": upstream}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1963 | return nil |
| 1964 | } |
| 1965 | classID = me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID |
| 1966 | } |
| 1967 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1968 | intervalEndTime := -1 |
| 1969 | ethPMHistData := make(map[string]float32) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1970 | if err := mm.populateGroupSpecificMetrics(ctx, mEnt, classID, entityID, meAttributes, ethPMHistData, &intervalEndTime); err != nil { |
| 1971 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | // Populate some relevant context for the EthernetFramePerformanceMonitoringHistoryData PM |
| 1975 | ethPMHistData["class_id"] = float32(classID) |
| 1976 | ethPMHistData["interval_end_time"] = float32(intervalEndTime) |
| 1977 | ethPMHistData["parent_class_id"] = float32(me.MacBridgeConfigurationDataClassID) // EthernetFramePerformanceMonitoringHistoryData is attached to MBPCD ME |
| 1978 | ethPMHistData["parent_entity_id"] = float32(entityID) |
| 1979 | if upstream { |
| 1980 | ethPMHistData["upstream"] = float32(1) |
| 1981 | } else { |
| 1982 | ethPMHistData["upstream"] = float32(0) |
| 1983 | } |
| 1984 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 1985 | metricInfo := mm.populateOnuMetricInfo(EthernetBridgeHistoryName, ethPMHistData) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1986 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1987 | logger.Debugw(ctx, "collecting data for EthernetFramePerformanceMonitoringHistoryData successful", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1988 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "upstream": upstream, "metricInfo": metricInfo}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1989 | return &metricInfo |
| 1990 | } |
| 1991 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1992 | func (mm *OnuMetricsManager) collectEthernetUniHistoryData(ctx context.Context, entityID uint16) *voltha.MetricInformation { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1993 | var mEnt *me.ManagedEntity |
| 1994 | var omciErr me.OmciErrors |
| 1995 | var classID me.ClassID |
| 1996 | var meAttributes me.AttributeValueMap |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1997 | logger.Debugw(ctx, "collecting data for EthernetFramePerformanceMonitoringHistoryData", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 1998 | meParam := me.ParamData{EntityID: entityID} |
| 1999 | if mEnt, omciErr = me.NewEthernetPerformanceMonitoringHistoryData(meParam); omciErr == nil || mEnt == nil || omciErr.GetError() != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2000 | logger.Errorw(ctx, "error creating me", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2001 | return nil |
| 2002 | } |
| 2003 | classID = me.EthernetPerformanceMonitoringHistoryDataClassID |
| 2004 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2005 | intervalEndTime := -1 |
| 2006 | ethUniHistData := make(map[string]float32) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2007 | if err := mm.populateGroupSpecificMetrics(ctx, mEnt, classID, entityID, meAttributes, ethUniHistData, &intervalEndTime); err != nil { |
| 2008 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | // Populate some relevant context for the EthernetPerformanceMonitoringHistoryData PM |
| 2012 | ethUniHistData["class_id"] = float32(classID) |
| 2013 | ethUniHistData["interval_end_time"] = float32(intervalEndTime) |
| 2014 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2015 | metricInfo := mm.populateOnuMetricInfo(EthernetUniHistoryName, ethUniHistData) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2016 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2017 | logger.Debugw(ctx, "collecting data for EthernetPerformanceMonitoringHistoryData successful", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2018 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "metricInfo": metricInfo}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2019 | return &metricInfo |
| 2020 | } |
| 2021 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2022 | func (mm *OnuMetricsManager) collectFecHistoryData(ctx context.Context, entityID uint16) *voltha.MetricInformation { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2023 | var mEnt *me.ManagedEntity |
| 2024 | var omciErr me.OmciErrors |
| 2025 | var classID me.ClassID |
| 2026 | var meAttributes me.AttributeValueMap |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2027 | logger.Debugw(ctx, "collecting data for FecPerformanceMonitoringHistoryData", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2028 | meParam := me.ParamData{EntityID: entityID} |
| 2029 | if mEnt, omciErr = me.NewFecPerformanceMonitoringHistoryData(meParam); omciErr == nil || mEnt == nil || omciErr.GetError() != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2030 | logger.Errorw(ctx, "error creating me", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2031 | return nil |
| 2032 | } |
| 2033 | classID = me.FecPerformanceMonitoringHistoryDataClassID |
| 2034 | |
| 2035 | intervalEndTime := -1 |
| 2036 | fecHistData := make(map[string]float32) |
| 2037 | if err := mm.populateGroupSpecificMetrics(ctx, mEnt, classID, entityID, meAttributes, fecHistData, &intervalEndTime); err != nil { |
| 2038 | return nil |
| 2039 | } |
| 2040 | |
| 2041 | // Populate some relevant context for the EthernetPerformanceMonitoringHistoryData PM |
| 2042 | fecHistData["class_id"] = float32(classID) |
| 2043 | fecHistData["interval_end_time"] = float32(intervalEndTime) |
| 2044 | |
| 2045 | metricInfo := mm.populateOnuMetricInfo(FecHistoryName, fecHistData) |
| 2046 | |
| 2047 | logger.Debugw(ctx, "collecting data for FecPerformanceMonitoringHistoryData successful", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2048 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "metricInfo": metricInfo}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2049 | return &metricInfo |
| 2050 | } |
| 2051 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2052 | func (mm *OnuMetricsManager) collectGemHistoryData(ctx context.Context, entityID uint16) *voltha.MetricInformation { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2053 | var mEnt *me.ManagedEntity |
| 2054 | var omciErr me.OmciErrors |
| 2055 | var classID me.ClassID |
| 2056 | var meAttributes me.AttributeValueMap |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2057 | logger.Debugw(ctx, "collecting data for GemPortNetworkCtpPerformanceMonitoringHistoryData", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2058 | meParam := me.ParamData{EntityID: entityID} |
| 2059 | if mEnt, omciErr = me.NewGemPortNetworkCtpPerformanceMonitoringHistoryData(meParam); omciErr == nil || mEnt == nil || omciErr.GetError() != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2060 | logger.Errorw(ctx, "error creating me", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2061 | return nil |
| 2062 | } |
| 2063 | classID = me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID |
| 2064 | |
| 2065 | intervalEndTime := -1 |
| 2066 | gemHistData := make(map[string]float32) |
| 2067 | if err := mm.populateGroupSpecificMetrics(ctx, mEnt, classID, entityID, meAttributes, gemHistData, &intervalEndTime); err != nil { |
| 2068 | return nil |
| 2069 | } |
| 2070 | |
| 2071 | // Populate some relevant context for the GemPortNetworkCtpPerformanceMonitoringHistoryData PM |
| 2072 | gemHistData["class_id"] = float32(classID) |
| 2073 | gemHistData["interval_end_time"] = float32(intervalEndTime) |
| 2074 | |
| 2075 | metricInfo := mm.populateOnuMetricInfo(GemPortHistoryName, gemHistData) |
| 2076 | |
| 2077 | logger.Debugw(ctx, "collecting data for GemPortNetworkCtpPerformanceMonitoringHistoryData successful", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2078 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "metricInfo": metricInfo}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2079 | return &metricInfo |
| 2080 | } |
| 2081 | |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2082 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2083 | func (mm *OnuMetricsManager) populateEthernetBridgeHistoryMetrics(ctx context.Context, classID me.ClassID, entityID uint16, |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2084 | meAttributes me.AttributeValueMap, requestedAttributes me.AttributeValueMap, ethPMHistData map[string]float32, intervalEndTime *int) error { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2085 | upstream := false |
| 2086 | if classID == me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID { |
| 2087 | upstream = true |
| 2088 | } |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2089 | // Insert "IntervalEndTime" as part of the requested attributes as we need this to compare the get responses when get request is multipart |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2090 | requestedAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_IntervalEndTime] = 0 |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 2091 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, classID, entityID, requestedAttributes, |
| 2092 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2093 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2094 | logger.Errorw(ctx, "GetME failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 2095 | pmFsm := mm.PAdaptFsm |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2096 | if pmFsm != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2097 | go func(p_pmFsm *cmn.AdapterFsm) { |
| 2098 | _ = p_pmFsm.PFsm.Event(L2PmEventFailure) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2099 | }(pmFsm) |
| 2100 | return err |
| 2101 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2102 | return fmt.Errorf(fmt.Sprintf("GetME-failed-%s-%s", mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2103 | } |
| 2104 | if meInstance != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2105 | select { |
| 2106 | case meAttributes = <-mm.l2PmChan: |
| 2107 | logger.Debugw(ctx, "received ethernet pm history data metrics", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2108 | log.Fields{"device-id": mm.deviceID, "upstream": upstream, "entityID": entityID}) |
| 2109 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2110 | logger.Errorw(ctx, "timeout waiting for omci-get response for ethernet pm history data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2111 | log.Fields{"device-id": mm.deviceID, "upstream": upstream, "entityID": entityID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2112 | // The metrics will be empty in this case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2113 | return fmt.Errorf("timeout-during-l2-pm-collection-for-ethernet-bridge-history-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2114 | } |
| 2115 | // verify that interval end time has not changed during metric collection. If it changed, we abort the procedure |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2116 | if valid := mm.updateAndValidateIntervalEndTime(ctx, entityID, meAttributes, intervalEndTime); !valid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2117 | return fmt.Errorf("interval-end-time-changed-during-metric-collection-for-ethernet-bridge-history-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | for k := range EthernetBridgeHistory { |
| 2121 | // populate ethPMHistData only if metric key not already present (or populated), since it is possible that we populate |
| 2122 | // the attributes in multiple iterations for a given L2 PM ME as there is a limit on the max OMCI GET payload size. |
| 2123 | if _, ok := ethPMHistData[k]; !ok { |
| 2124 | switch k { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2125 | case "entity_id": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2126 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2127 | ethPMHistData[k] = float32(val.(uint16)) |
| 2128 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2129 | case "drop_events": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2130 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_DropEvents]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2131 | ethPMHistData[k] = float32(val.(uint32)) |
| 2132 | } |
| 2133 | case "octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2134 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2135 | ethPMHistData[k] = float32(val.(uint32)) |
| 2136 | } |
| 2137 | case "packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2138 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2139 | ethPMHistData[k] = float32(val.(uint32)) |
| 2140 | } |
| 2141 | case "broadcast_packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2142 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_BroadcastPackets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2143 | ethPMHistData[k] = float32(val.(uint32)) |
| 2144 | } |
| 2145 | case "multicast_packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2146 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_MulticastPackets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2147 | ethPMHistData[k] = float32(val.(uint32)) |
| 2148 | } |
| 2149 | case "crc_errored_packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2150 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_CrcErroredPackets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2151 | ethPMHistData[k] = float32(val.(uint32)) |
| 2152 | } |
| 2153 | case "undersize_packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2154 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_UndersizePackets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2155 | ethPMHistData[k] = float32(val.(uint32)) |
| 2156 | } |
| 2157 | case "oversize_packets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2158 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_OversizePackets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2159 | ethPMHistData[k] = float32(val.(uint32)) |
| 2160 | } |
| 2161 | case "64_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2162 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets64Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2163 | ethPMHistData[k] = float32(val.(uint32)) |
| 2164 | } |
| 2165 | case "65_to_127_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2166 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets65To127Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2167 | ethPMHistData[k] = float32(val.(uint32)) |
| 2168 | } |
| 2169 | case "128_to_255_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2170 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets128To255Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2171 | ethPMHistData[k] = float32(val.(uint32)) |
| 2172 | } |
| 2173 | case "256_to_511_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2174 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets256To511Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2175 | ethPMHistData[k] = float32(val.(uint32)) |
| 2176 | } |
| 2177 | case "512_to_1023_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2178 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets512To1023Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2179 | ethPMHistData[k] = float32(val.(uint32)) |
| 2180 | } |
| 2181 | case "1024_to_1518_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2182 | if val, ok := meAttributes[me.EthernetFramePerformanceMonitoringHistoryDataUpstream_Packets1024To1518Octets]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2183 | ethPMHistData[k] = float32(val.(uint32)) |
| 2184 | } |
| 2185 | default: |
| 2186 | // do nothing |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | return nil |
| 2191 | } |
| 2192 | |
| 2193 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2194 | func (mm *OnuMetricsManager) populateEthernetUniHistoryMetrics(ctx context.Context, classID me.ClassID, entityID uint16, |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2195 | meAttributes me.AttributeValueMap, requestedAttributes me.AttributeValueMap, ethPMUniHistData map[string]float32, intervalEndTime *int) error { |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2196 | // Insert "IntervalEndTime" as part of the requested attributes as we need this to compare the get responses when get request is multipart |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2197 | if _, ok := requestedAttributes["IntervalEndTime"]; !ok { |
| 2198 | requestedAttributes["IntervalEndTime"] = 0 |
| 2199 | } |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 2200 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, classID, entityID, requestedAttributes, |
| 2201 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2202 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2203 | logger.Errorw(ctx, "GetMe failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 2204 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
| 2205 | return fmt.Errorf(fmt.Sprintf("GetME-failed-%s-%s", mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2206 | } |
| 2207 | if meInstance != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2208 | select { |
| 2209 | case meAttributes = <-mm.l2PmChan: |
| 2210 | logger.Debugw(ctx, "received ethernet uni history data metrics", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2211 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
| 2212 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2213 | logger.Errorw(ctx, "timeout waiting for omci-get response for ethernet uni history data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2214 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2215 | // The metrics will be empty in this case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2216 | return fmt.Errorf("timeout-during-l2-pm-collection-for-ethernet-uni-history-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2217 | } |
| 2218 | // verify that interval end time has not changed during metric collection. If it changed, we abort the procedure |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2219 | if valid := mm.updateAndValidateIntervalEndTime(ctx, entityID, meAttributes, intervalEndTime); !valid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2220 | return fmt.Errorf("interval-end-time-changed-during-metric-collection-for-ethernet-uni-history-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | for k := range EthernetUniHistory { |
| 2224 | // populate ethPMUniHistData only if metric key not already present (or populated), since it is possible that we populate |
| 2225 | // the attributes in multiple iterations for a given L2 PM ME as there is a limit on the max OMCI GET payload size. |
| 2226 | if _, ok := ethPMUniHistData[k]; !ok { |
| 2227 | switch k { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2228 | case "entity_id": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2229 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2230 | ethPMUniHistData[k] = float32(val.(uint16)) |
| 2231 | } |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2232 | case "fcs_errors": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2233 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_FcsErrors]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2234 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2235 | } |
| 2236 | case "excessive_collision_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2237 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_ExcessiveCollisionCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2238 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2239 | } |
| 2240 | case "late_collision_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2241 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_LateCollisionCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2242 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2243 | } |
| 2244 | case "frames_too_long": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2245 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_FramesTooLong]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2246 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2247 | } |
| 2248 | case "buffer_overflows_on_rx": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2249 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_BufferOverflowsOnReceive]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2250 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2251 | } |
| 2252 | case "buffer_overflows_on_tx": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2253 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_BufferOverflowsOnTransmit]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2254 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2255 | } |
| 2256 | case "single_collision_frame_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2257 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_SingleCollisionFrameCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2258 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2259 | } |
| 2260 | case "multiple_collisions_frame_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2261 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_MultipleCollisionsFrameCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2262 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2263 | } |
| 2264 | case "sqe_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2265 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_SqeCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2266 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2267 | } |
| 2268 | case "deferred_tx_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2269 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_DeferredTransmissionCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2270 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2271 | } |
| 2272 | case "internal_mac_tx_error_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2273 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_InternalMacTransmitErrorCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2274 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2275 | } |
| 2276 | case "carrier_sense_error_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2277 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_CarrierSenseErrorCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2278 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2279 | } |
| 2280 | case "alignment_error_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2281 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_AlignmentErrorCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2282 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2283 | } |
| 2284 | case "internal_mac_rx_error_counter": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2285 | if val, ok := meAttributes[me.EthernetPerformanceMonitoringHistoryData_InternalMacReceiveErrorCounter]; ok && val != nil { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2286 | ethPMUniHistData[k] = float32(val.(uint32)) |
| 2287 | } |
| 2288 | default: |
| 2289 | // do nothing |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | return nil |
| 2294 | } |
| 2295 | |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2296 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2297 | func (mm *OnuMetricsManager) populateFecHistoryMetrics(ctx context.Context, classID me.ClassID, entityID uint16, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2298 | meAttributes me.AttributeValueMap, requestedAttributes me.AttributeValueMap, fecHistData map[string]float32, intervalEndTime *int) error { |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2299 | // Insert "IntervalEndTime" as part of the requested attributes as we need this to compare the get responses when get request is multipart |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2300 | if _, ok := requestedAttributes[me.FecPerformanceMonitoringHistoryData_IntervalEndTime]; !ok { |
| 2301 | requestedAttributes[me.FecPerformanceMonitoringHistoryData_IntervalEndTime] = 0 |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2302 | } |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 2303 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, classID, entityID, requestedAttributes, |
| 2304 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2305 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2306 | logger.Errorw(ctx, "GetMe failed, failure PM FSM!", log.Fields{"device-id": mm.deviceID}) |
| 2307 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
| 2308 | return fmt.Errorf(fmt.Sprintf("GetME-failed-%s-%s", mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2309 | } |
| 2310 | if meInstance != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2311 | select { |
| 2312 | case meAttributes = <-mm.l2PmChan: |
| 2313 | logger.Debugw(ctx, "received fec history data metrics", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2314 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
| 2315 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2316 | logger.Errorw(ctx, "timeout waiting for omci-get response for fec history data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2317 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2318 | // The metrics will be empty in this case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2319 | return fmt.Errorf("timeout-during-l2-pm-collection-for-fec-history-%v", mm.deviceID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2320 | } |
| 2321 | // verify that interval end time has not changed during metric collection. If it changed, we abort the procedure |
| 2322 | if valid := mm.updateAndValidateIntervalEndTime(ctx, entityID, meAttributes, intervalEndTime); !valid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2323 | return fmt.Errorf("interval-end-time-changed-during-metric-collection-for-fec-history-%v", mm.deviceID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | for k := range FecHistory { |
| 2327 | // populate fecHistData only if metric key not already present (or populated), since it is possible that we populate |
| 2328 | // the attributes in multiple iterations for a given L2 PM ME as there is a limit on the max OMCI GET payload size. |
| 2329 | if _, ok := fecHistData[k]; !ok { |
| 2330 | switch k { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2331 | case "entity_id": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2332 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2333 | fecHistData[k] = float32(val.(uint16)) |
| 2334 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2335 | case "corrected_bytes": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2336 | if val, ok := meAttributes[me.FecPerformanceMonitoringHistoryData_CorrectedBytes]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2337 | fecHistData[k] = float32(val.(uint32)) |
| 2338 | } |
| 2339 | case "corrected_code_words": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2340 | if val, ok := meAttributes[me.FecPerformanceMonitoringHistoryData_CorrectedCodeWords]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2341 | fecHistData[k] = float32(val.(uint32)) |
| 2342 | } |
| 2343 | case "uncorrectable_code_words": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2344 | if val, ok := meAttributes[me.FecPerformanceMonitoringHistoryData_UncorrectableCodeWords]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2345 | fecHistData[k] = float32(val.(uint32)) |
| 2346 | } |
| 2347 | case "total_code_words": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2348 | if val, ok := meAttributes[me.FecPerformanceMonitoringHistoryData_TotalCodeWords]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2349 | fecHistData[k] = float32(val.(uint32)) |
| 2350 | } |
| 2351 | case "fec_seconds": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2352 | if val, ok := meAttributes[me.FecPerformanceMonitoringHistoryData_FecSeconds]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2353 | fecHistData[k] = float32(val.(uint16)) |
| 2354 | } |
| 2355 | default: |
| 2356 | // do nothing |
| 2357 | } |
| 2358 | } |
| 2359 | } |
| 2360 | return nil |
| 2361 | } |
| 2362 | |
| 2363 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2364 | func (mm *OnuMetricsManager) populateGemPortMetrics(ctx context.Context, classID me.ClassID, entityID uint16, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2365 | meAttributes me.AttributeValueMap, requestedAttributes me.AttributeValueMap, gemPortHistData map[string]float32, intervalEndTime *int) error { |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2366 | // Insert "IntervalEndTime" is part of the requested attributes as we need this to compare the get responses when get request is multipart |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2367 | if _, ok := requestedAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_IntervalEndTime]; !ok { |
| 2368 | requestedAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_IntervalEndTime] = 0 |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2369 | } |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 2370 | meInstance, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMe(ctx, classID, entityID, requestedAttributes, |
| 2371 | mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan, mm.isExtendedOmci) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2372 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2373 | logger.Errorw(ctx, "GetMe failed", log.Fields{"device-id": mm.deviceID}) |
| 2374 | _ = mm.PAdaptFsm.PFsm.Event(L2PmEventFailure) |
| 2375 | return fmt.Errorf(fmt.Sprintf("GetME-failed-%s-%s", mm.deviceID, err)) |
ozgecanetsia | b36ed57 | 2021-04-01 10:38:48 +0300 | [diff] [blame] | 2376 | } |
| 2377 | if meInstance != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2378 | select { |
| 2379 | case meAttributes = <-mm.l2PmChan: |
| 2380 | logger.Debugw(ctx, "received gem port history data metrics", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2381 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
| 2382 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2383 | logger.Errorw(ctx, "timeout waiting for omci-get response for gem port history data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2384 | log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2385 | // The metrics will be empty in this case |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2386 | return fmt.Errorf("timeout-during-l2-pm-collection-for-gemport-history-%v", mm.deviceID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2387 | } |
| 2388 | // verify that interval end time has not changed during metric collection. If it changed, we abort the procedure |
| 2389 | if valid := mm.updateAndValidateIntervalEndTime(ctx, entityID, meAttributes, intervalEndTime); !valid { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2390 | return fmt.Errorf("interval-end-time-changed-during-metric-collection-for-gemport-history-%v", mm.deviceID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | for k := range GemPortHistory { |
| 2394 | // populate gemPortHistData only if metric key not already present (or populated), since it is possible that we populate |
| 2395 | // the attributes in multiple iterations for a given L2 PM ME as there is a limit on the max OMCI GET payload size. |
| 2396 | if _, ok := gemPortHistData[k]; !ok { |
| 2397 | switch k { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2398 | case "entity_id": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2399 | if val, ok := meAttributes[me.ManagedEntityID]; ok && val != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2400 | gemPortHistData[k] = float32(val.(uint16)) |
| 2401 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2402 | case "transmitted_gem_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2403 | if val, ok := meAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_TransmittedGemFrames]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2404 | gemPortHistData[k] = float32(val.(uint32)) |
| 2405 | } |
| 2406 | case "received_gem_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2407 | if val, ok := meAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_ReceivedGemFrames]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2408 | gemPortHistData[k] = float32(val.(uint32)) |
| 2409 | } |
| 2410 | case "received_payload_bytes": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2411 | if val, ok := meAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_ReceivedPayloadBytes]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2412 | gemPortHistData[k] = float32(val.(uint64)) |
| 2413 | } |
| 2414 | case "transmitted_payload_bytes": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2415 | if val, ok := meAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_TransmittedPayloadBytes]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2416 | gemPortHistData[k] = float32(val.(uint64)) |
| 2417 | } |
| 2418 | case "encryption_key_errors": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 2419 | if val, ok := meAttributes[me.GemPortNetworkCtpPerformanceMonitoringHistoryData_EncryptionKeyErrors]; ok && val != nil { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2420 | gemPortHistData[k] = float32(val.(uint32)) |
| 2421 | } |
| 2422 | default: |
| 2423 | // do nothing |
| 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | return nil |
| 2428 | } |
| 2429 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2430 | func (mm *OnuMetricsManager) handleOmciCreateResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2431 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeCreateResponse) |
| 2432 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2433 | logger.Errorw(ctx, "omci Msg layer could not be detected for create response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 2434 | return fmt.Errorf("omci Msg layer could not be detected for create response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2435 | } |
| 2436 | msgObj, msgOk := msgLayer.(*omci.CreateResponse) |
| 2437 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2438 | logger.Errorw(ctx, "omci Msg layer could not be assigned for create response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 2439 | return fmt.Errorf("omci Msg layer could not be assigned for delete response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2440 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2441 | logger.Debugw(ctx, "OMCI create response Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2442 | switch msgObj.EntityClass { |
| 2443 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 2444 | me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2445 | me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 2446 | me.FecPerformanceMonitoringHistoryDataClassID, |
| 2447 | me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2448 | // If the result is me.InstanceExists it means the entity was already created. It is ok handled that as success |
| 2449 | if msgObj.Result == me.Success || msgObj.Result == me.InstanceExists { |
| 2450 | mm.l2PmCreateOrDeleteResponseChan <- true |
| 2451 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2452 | logger.Warnw(ctx, "failed to create me", log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2453 | mm.l2PmCreateOrDeleteResponseChan <- false |
| 2454 | } |
| 2455 | return nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 2456 | case me.EthernetFrameExtendedPmClassID, |
| 2457 | me.EthernetFrameExtendedPm64BitClassID: |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 2458 | mm.extendedPMMeResponseChan <- msgObj.Result |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 2459 | return nil |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2460 | default: |
| 2461 | logger.Errorw(ctx, "unhandled omci create response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2462 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2463 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2464 | return fmt.Errorf("unhandled-omci-create-response-message-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2465 | } |
| 2466 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2467 | func (mm *OnuMetricsManager) handleOmciDeleteResponseMessage(ctx context.Context, msg cmn.OmciMessage) error { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2468 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeDeleteResponse) |
| 2469 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2470 | logger.Errorw(ctx, "omci Msg layer could not be detected for delete response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 2471 | return fmt.Errorf("omci Msg layer could not be detected for create response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2472 | } |
| 2473 | msgObj, msgOk := msgLayer.(*omci.DeleteResponse) |
| 2474 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2475 | logger.Errorw(ctx, "omci Msg layer could not be assigned for delete response - handling stopped", log.Fields{"device-id": mm.deviceID}) |
| 2476 | return fmt.Errorf("omci Msg layer could not be assigned for delete response - handling stopped: %s", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2477 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2478 | logger.Debugw(ctx, "OMCI delete response Data", log.Fields{"device-id": mm.deviceID, "data-fields": msgObj}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2479 | switch msgObj.EntityClass { |
| 2480 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, |
| 2481 | me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2482 | me.EthernetPerformanceMonitoringHistoryDataClassID, |
| 2483 | me.FecPerformanceMonitoringHistoryDataClassID, |
| 2484 | me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2485 | // If the result is me.UnknownInstance it means the entity was already deleted. It is ok handled that as success |
| 2486 | if msgObj.Result == me.Success || msgObj.Result == me.UnknownInstance { |
| 2487 | mm.l2PmCreateOrDeleteResponseChan <- true |
| 2488 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2489 | logger.Warnw(ctx, "failed to delete me", log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2490 | mm.l2PmCreateOrDeleteResponseChan <- false |
| 2491 | } |
| 2492 | return nil |
| 2493 | default: |
| 2494 | logger.Errorw(ctx, "unhandled omci delete response message", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2495 | log.Fields{"device-id": mm.deviceID, "class-id": msgObj.EntityClass}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2496 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2497 | return fmt.Errorf("unhandled-omci-delete-response-message-%v", mm.deviceID) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2498 | } |
| 2499 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2500 | func (mm *OnuMetricsManager) generateTicks(ctx context.Context) { |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2501 | mm.updateTickGenerationStatus(true) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2502 | for { |
| 2503 | select { |
| 2504 | case <-time.After(L2PmCollectionInterval * time.Second): |
| 2505 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2506 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventTick); err != nil { |
| 2507 | logger.Errorw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2508 | } |
| 2509 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2510 | case <-mm.StopTicks: |
| 2511 | logger.Infow(ctx, "stopping ticks", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 2512 | mm.updateTickGenerationStatus(false) |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 2513 | return |
| 2514 | } |
| 2515 | } |
| 2516 | } |
| 2517 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2518 | func (mm *OnuMetricsManager) handleMetricsPublish(ctx context.Context, metricName string, metricInfoSlice []*voltha.MetricInformation) { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2519 | // Publish metrics if it is valid |
| 2520 | if metricInfoSlice != nil { |
| 2521 | mm.publishMetrics(ctx, metricInfoSlice) |
| 2522 | } else { |
| 2523 | // If collectAttempts exceeds L2PmCollectAttempts then remove it from activeL2Pms |
| 2524 | // slice so that we do not collect data from that PM ME anymore |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2525 | mm.OnuMetricsManagerLock.Lock() |
| 2526 | mm.GroupMetricMap[metricName].collectAttempts++ |
| 2527 | if mm.GroupMetricMap[metricName].collectAttempts > L2PmCollectAttempts { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2528 | mm.activeL2Pms = mm.removeIfFoundString(mm.activeL2Pms, metricName) |
| 2529 | } |
| 2530 | logger.Warnw(ctx, "state collect data - no metrics collected", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2531 | log.Fields{"device-id": mm.deviceID, "metricName": metricName, "collectAttempts": mm.GroupMetricMap[metricName].collectAttempts}) |
| 2532 | mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2533 | } |
| 2534 | } |
| 2535 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2536 | func (mm *OnuMetricsManager) populateGroupSpecificMetrics(ctx context.Context, mEnt *me.ManagedEntity, classID me.ClassID, entityID uint16, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2537 | meAttributes me.AttributeValueMap, data map[string]float32, intervalEndTime *int) error { |
| 2538 | var grpFunc groupMetricPopulateFunc |
| 2539 | switch classID { |
| 2540 | case me.EthernetFramePerformanceMonitoringHistoryDataUpstreamClassID, me.EthernetFramePerformanceMonitoringHistoryDataDownstreamClassID: |
| 2541 | grpFunc = mm.populateEthernetBridgeHistoryMetrics |
| 2542 | case me.EthernetPerformanceMonitoringHistoryDataClassID: |
| 2543 | grpFunc = mm.populateEthernetUniHistoryMetrics |
| 2544 | case me.FecPerformanceMonitoringHistoryDataClassID: |
| 2545 | grpFunc = mm.populateFecHistoryMetrics |
| 2546 | case me.GemPortNetworkCtpPerformanceMonitoringHistoryDataClassID: |
| 2547 | grpFunc = mm.populateGemPortMetrics |
| 2548 | default: |
| 2549 | return fmt.Errorf("unknown-classid-%v", classID) |
| 2550 | } |
| 2551 | |
| 2552 | size := 0 |
| 2553 | requestedAttributes := make(me.AttributeValueMap) |
| 2554 | for _, v := range mEnt.GetAttributeDefinitions() { |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2555 | if v.Name == "ManagedEntityId" || v.Name == "IntervalEndTime" || v.Name == "ThresholdData12Id" { |
| 2556 | // Exclude the ManagedEntityId , it will be inserted by omci library based on 'entityID' information |
| 2557 | // Exclude IntervalEndTime. It will be inserted by the group PM populater function. |
| 2558 | // Exclude ThresholdData12Id as that is of no particular relevance for metrics collection. |
| 2559 | continue |
| 2560 | } |
Holger Hildebrandt | d930cb2 | 2022-06-17 09:24:50 +0000 | [diff] [blame] | 2561 | if v.Size+size <= mm.maxL2PMGetPayLoadSize { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2562 | requestedAttributes[v.Name] = v.DefValue |
| 2563 | size = v.Size + size |
| 2564 | } else { // We exceeded the allow omci get size |
| 2565 | // Let's collect the attributes via get now and collect remaining in the next iteration |
| 2566 | if err := grpFunc(ctx, classID, entityID, meAttributes, requestedAttributes, data, intervalEndTime); err != nil { |
| 2567 | logger.Errorw(ctx, "error during metric collection", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2568 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "err": err}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2569 | return err |
| 2570 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2571 | requestedAttributes = make(me.AttributeValueMap) // reset map |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2572 | requestedAttributes[v.Name] = v.DefValue // populate the metric that was missed in the current iteration |
| 2573 | size = v.Size // reset size |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | // Collect the omci get attributes for the last bunch of attributes. |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2577 | if err := grpFunc(ctx, classID, entityID, meAttributes, requestedAttributes, data, intervalEndTime); err != nil { |
| 2578 | logger.Errorw(ctx, "error during metric collection", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2579 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "err": err}) |
Girish Gowdra | 6c04fbc | 2021-04-22 15:34:49 -0700 | [diff] [blame] | 2580 | return err |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2581 | } |
| 2582 | return nil |
| 2583 | } |
| 2584 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2585 | func (mm *OnuMetricsManager) populateOnuMetricInfo(title string, data map[string]float32) voltha.MetricInformation { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2586 | metricsContext := make(map[string]string) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2587 | metricsContext["onuID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetDevice().ProxyAddress.OnuId) |
| 2588 | metricsContext["intfID"] = fmt.Sprintf("%d", mm.pDeviceHandler.GetDevice().ProxyAddress.ChannelId) |
| 2589 | metricsContext["devicetype"] = mm.pDeviceHandler.GetDeviceType() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2590 | |
| 2591 | raisedTs := time.Now().Unix() |
| 2592 | mmd := voltha.MetricMetaData{ |
| 2593 | Title: title, |
| 2594 | Ts: float64(raisedTs), |
| 2595 | Context: metricsContext, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2596 | DeviceId: mm.deviceID, |
| 2597 | LogicalDeviceId: mm.pDeviceHandler.GetLogicalDeviceID(), |
| 2598 | SerialNo: mm.pDeviceHandler.GetDevice().SerialNumber, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | // create slice of metrics given that there could be more than one VEIP instance |
| 2602 | metricInfo := voltha.MetricInformation{Metadata: &mmd, Metrics: data} |
| 2603 | return metricInfo |
| 2604 | } |
| 2605 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2606 | func (mm *OnuMetricsManager) updateAndValidateIntervalEndTime(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap, intervalEndTime *int) bool { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2607 | valid := false |
| 2608 | if *intervalEndTime == -1 { // first time |
| 2609 | // Update the interval end time |
| 2610 | if val, ok := meAttributes["IntervalEndTime"]; ok && val != nil { |
| 2611 | *intervalEndTime = int(meAttributes["IntervalEndTime"].(uint8)) |
| 2612 | valid = true |
| 2613 | } |
| 2614 | } else { |
| 2615 | var currIntervalEndTime int |
| 2616 | if val, ok := meAttributes["IntervalEndTime"]; ok && val != nil { |
| 2617 | currIntervalEndTime = int(meAttributes["IntervalEndTime"].(uint8)) |
| 2618 | } |
| 2619 | if currIntervalEndTime != *intervalEndTime { // interval end time changed during metric collection |
| 2620 | logger.Errorw(ctx, "interval end time changed during metrics collection for ethernet pm history data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2621 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2622 | "currIntervalEndTime": *intervalEndTime, "newIntervalEndTime": currIntervalEndTime}) |
| 2623 | } else { |
| 2624 | valid = true |
| 2625 | } |
| 2626 | } |
| 2627 | return valid |
| 2628 | } |
| 2629 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2630 | func (mm *OnuMetricsManager) waitForResponseOrTimeout(ctx context.Context, create bool, instID uint16, meClassName string) bool { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2631 | logger.Debugw(ctx, "waitForResponseOrTimeout", log.Fields{"create": create, "instID": instID, "meClassName": meClassName}) |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 2632 | if !mm.GetOmciProcessingStatus() { |
| 2633 | logger.Errorw(ctx, "not waiting for omci resp, because the omci resp processor is shutdown due to device down/delete", log.Fields{"device-id": mm.deviceID}) |
| 2634 | return false |
| 2635 | } |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2636 | select { |
| 2637 | case resp := <-mm.l2PmCreateOrDeleteResponseChan: |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2638 | logger.Debugw(ctx, "received l2 pm me response", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2639 | log.Fields{"device-id": mm.deviceID, "resp": resp, "create": create, "meClassName": meClassName, "instID": instID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2640 | return resp |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2641 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2642 | logger.Errorw(ctx, "timeout waiting for l2 pm me response", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2643 | log.Fields{"device-id": mm.deviceID, "resp": false, "create": create, "meClassName": meClassName, "instID": instID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2644 | } |
| 2645 | return false |
| 2646 | } |
| 2647 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2648 | func (mm *OnuMetricsManager) initializeGroupMetric(grpMtrcs map[string]voltha.PmConfig_PmType, grpName string, grpEnabled bool, grpFreq uint32) { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2649 | var pmConfigSlice []*voltha.PmConfig |
| 2650 | for k, v := range grpMtrcs { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2651 | pmConfigSlice = append(pmConfigSlice, |
| 2652 | &voltha.PmConfig{ |
| 2653 | Name: k, |
| 2654 | Type: v, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2655 | Enabled: grpEnabled && mm.pDeviceHandler.GetMetricsEnabled(), |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2656 | SampleFreq: grpFreq}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2657 | } |
| 2658 | groupMetric := voltha.PmGroupConfig{ |
| 2659 | GroupName: grpName, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2660 | Enabled: grpEnabled && mm.pDeviceHandler.GetMetricsEnabled(), |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2661 | GroupFreq: grpFreq, |
| 2662 | Metrics: pmConfigSlice, |
| 2663 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2664 | mm.pDeviceHandler.GetPmConfigs().Groups = append(mm.pDeviceHandler.GetPmConfigs().Groups, &groupMetric) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2665 | |
| 2666 | } |
| 2667 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2668 | func (mm *OnuMetricsManager) initializeL2PmFsm(ctx context.Context, aCommChannel chan cmn.Message) error { |
| 2669 | mm.PAdaptFsm = cmn.NewAdapterFsm("L2PmFSM", mm.deviceID, aCommChannel) |
| 2670 | if mm.PAdaptFsm == nil { |
| 2671 | logger.Errorw(ctx, "L2PMFsm cmn.AdapterFsm could not be instantiated!!", log.Fields{ |
| 2672 | "device-id": mm.deviceID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2673 | return fmt.Errorf("nil-adapter-fsm") |
| 2674 | } |
| 2675 | // L2 PM FSM related state machine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2676 | mm.PAdaptFsm.PFsm = fsm.NewFSM( |
| 2677 | L2PmStNull, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2678 | fsm.Events{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2679 | {Name: L2PmEventInit, Src: []string{L2PmStNull}, Dst: L2PmStStarting}, |
| 2680 | {Name: L2PmEventTick, Src: []string{L2PmStStarting}, Dst: L2PmStSyncTime}, |
| 2681 | {Name: L2PmEventTick, Src: []string{L2PmStIdle, L2PmStCreatePmMe, L2PmStDeletePmMe}, Dst: L2PmStCollectData}, |
| 2682 | {Name: L2PmEventSuccess, Src: []string{L2PmStSyncTime, L2PmStCreatePmMe, L2PmStDeletePmMe, L2PmStCollectData}, Dst: L2PmStIdle}, |
| 2683 | {Name: L2PmEventFailure, Src: []string{L2PmStCreatePmMe, L2PmStDeletePmMe, L2PmStCollectData}, Dst: L2PmStIdle}, |
| 2684 | {Name: L2PmEventFailure, Src: []string{L2PmStSyncTime}, Dst: L2PmStSyncTime}, |
| 2685 | {Name: L2PmEventAddMe, Src: []string{L2PmStIdle}, Dst: L2PmStCreatePmMe}, |
| 2686 | {Name: L2PmEventDeleteMe, Src: []string{L2PmStIdle}, Dst: L2PmStDeletePmMe}, |
| 2687 | {Name: L2PmEventStop, Src: []string{L2PmStNull, L2PmStStarting, L2PmStSyncTime, L2PmStIdle, L2PmStCreatePmMe, L2PmStDeletePmMe, L2PmStCollectData}, Dst: L2PmStNull}, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2688 | }, |
| 2689 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2690 | "enter_state": func(e *fsm.Event) { mm.PAdaptFsm.LogFsmStateChange(ctx, e) }, |
| 2691 | "enter_" + L2PmStNull: func(e *fsm.Event) { mm.l2PMFsmNull(ctx, e) }, |
| 2692 | "enter_" + L2PmStIdle: func(e *fsm.Event) { mm.l2PMFsmIdle(ctx, e) }, |
| 2693 | "enter_" + L2PmStStarting: func(e *fsm.Event) { mm.l2PMFsmStarting(ctx, e) }, |
| 2694 | "enter_" + L2PmStSyncTime: func(e *fsm.Event) { mm.l2PMFsmSyncTime(ctx, e) }, |
| 2695 | "enter_" + L2PmStCollectData: func(e *fsm.Event) { mm.l2PmFsmCollectData(ctx, e) }, |
| 2696 | "enter_" + L2PmStCreatePmMe: func(e *fsm.Event) { _ = mm.l2PmFsmCreatePM(ctx, e) }, |
| 2697 | "enter_" + L2PmStDeletePmMe: func(e *fsm.Event) { _ = mm.l2PmFsmDeletePM(ctx, e) }, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2698 | }, |
| 2699 | ) |
| 2700 | return nil |
| 2701 | } |
| 2702 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2703 | func (mm *OnuMetricsManager) initializeAllGroupMetrics() { |
| 2704 | mm.pDeviceHandler.InitPmConfigs() |
| 2705 | mm.pDeviceHandler.GetPmConfigs().Id = mm.deviceID |
| 2706 | mm.pDeviceHandler.GetPmConfigs().DefaultFreq = DefaultMetricCollectionFrequency |
| 2707 | mm.pDeviceHandler.GetPmConfigs().Grouped = GroupMetricEnabled |
| 2708 | mm.pDeviceHandler.GetPmConfigs().FreqOverride = DefaultFrequencyOverrideEnabled |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2709 | |
| 2710 | // Populate group metrics. |
| 2711 | // Lets populate irrespective of GroupMetricEnabled is true or not. |
| 2712 | // The group metrics collection will decided on this flag later |
| 2713 | |
| 2714 | mm.initializeGroupMetric(OpticalPowerGroupMetrics, OpticalPowerGroupMetricName, |
| 2715 | OpticalPowerGroupMetricEnabled, OpticalPowerMetricGroupCollectionFrequency) |
| 2716 | |
| 2717 | mm.initializeGroupMetric(UniStatusGroupMetrics, UniStatusGroupMetricName, |
| 2718 | UniStatusGroupMetricEnabled, UniStatusMetricGroupCollectionFrequency) |
| 2719 | |
| 2720 | // classical l2 pm counter start |
| 2721 | |
| 2722 | mm.initializeGroupMetric(EthernetBridgeHistory, EthernetBridgeHistoryName, |
| 2723 | EthernetBridgeHistoryEnabled, EthernetBridgeHistoryFrequency) |
| 2724 | |
| 2725 | mm.initializeGroupMetric(EthernetUniHistory, EthernetUniHistoryName, |
| 2726 | EthernetUniHistoryEnabled, EthernetUniHistoryFrequency) |
| 2727 | |
| 2728 | mm.initializeGroupMetric(FecHistory, FecHistoryName, |
| 2729 | FecHistoryEnabled, FecHistoryFrequency) |
| 2730 | |
| 2731 | mm.initializeGroupMetric(GemPortHistory, GemPortHistoryName, |
| 2732 | GemPortHistoryEnabled, GemPortHistoryFrequency) |
| 2733 | |
| 2734 | // classical l2 pm counter end |
| 2735 | |
| 2736 | // Add standalone metric (if present) after this (will be added to dh.pmConfigs.Metrics) |
| 2737 | } |
| 2738 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2739 | func (mm *OnuMetricsManager) populateLocalGroupMetricData(ctx context.Context) { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2740 | // Populate local group metric structures |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2741 | for _, g := range mm.pDeviceHandler.GetPmConfigs().Groups { |
| 2742 | mm.GroupMetricMap[g.GroupName] = &groupMetric{ |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2743 | groupName: g.GroupName, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2744 | Enabled: g.Enabled, |
| 2745 | Frequency: g.GroupFreq, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2746 | } |
| 2747 | switch g.GroupName { |
| 2748 | case OpticalPowerGroupMetricName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2749 | mm.GroupMetricMap[g.GroupName].metricMap = OpticalPowerGroupMetrics |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2750 | case UniStatusGroupMetricName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2751 | mm.GroupMetricMap[g.GroupName].metricMap = UniStatusGroupMetrics |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2752 | case EthernetBridgeHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2753 | mm.GroupMetricMap[g.GroupName].metricMap = EthernetBridgeHistory |
| 2754 | mm.GroupMetricMap[g.GroupName].IsL2PMCounter = true |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2755 | case EthernetUniHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2756 | mm.GroupMetricMap[g.GroupName].metricMap = EthernetUniHistory |
| 2757 | mm.GroupMetricMap[g.GroupName].IsL2PMCounter = true |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2758 | case FecHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2759 | mm.GroupMetricMap[g.GroupName].metricMap = FecHistory |
| 2760 | mm.GroupMetricMap[g.GroupName].IsL2PMCounter = true |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2761 | case GemPortHistoryName: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2762 | mm.GroupMetricMap[g.GroupName].metricMap = GemPortHistory |
| 2763 | mm.GroupMetricMap[g.GroupName].IsL2PMCounter = true |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2764 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2765 | logger.Errorw(ctx, "unhandled-group-name", log.Fields{"device-id": mm.deviceID, "groupName": g.GroupName}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | // Populate local standalone metric structures |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2770 | for _, m := range mm.pDeviceHandler.GetPmConfigs().Metrics { |
| 2771 | mm.StandaloneMetricMap[m.Name] = &standaloneMetric{ |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2772 | metricName: m.Name, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2773 | Enabled: m.Enabled, |
| 2774 | Frequency: m.SampleFreq, |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2775 | } |
| 2776 | switch m.Name { |
| 2777 | // None exist as of now. Add when available. |
| 2778 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2779 | logger.Errorw(ctx, "unhandled-metric-name", log.Fields{"device-id": mm.deviceID, "metricName": m.Name}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2780 | } |
| 2781 | } |
| 2782 | } |
| 2783 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2784 | // AddGemPortForPerfMonitoring - TODO: add comment |
| 2785 | func (mm *OnuMetricsManager) AddGemPortForPerfMonitoring(ctx context.Context, gemPortNTPInstID uint16) { |
| 2786 | mm.OnuMetricsManagerLock.Lock() |
| 2787 | defer mm.OnuMetricsManagerLock.Unlock() |
| 2788 | logger.Debugw(ctx, "add gemport for perf monitoring - start", log.Fields{"device-id": mm.deviceID, "gemPortID": gemPortNTPInstID}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2789 | // mark the instance for addition |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2790 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd = mm.appendIfMissingUnt16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, gemPortNTPInstID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2791 | // If the instance presence toggles too soon, we need to remove it from gemPortNCTPPerfHistInstToDelete slice |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2792 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete = mm.removeIfFoundUint16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete, gemPortNTPInstID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2793 | |
| 2794 | mm.l2PmToAdd = mm.appendIfMissingString(mm.l2PmToAdd, GemPortHistoryName) |
| 2795 | // We do not need to remove from l2PmToDelete slice as we could have Add and Delete of |
| 2796 | // GemPortPerfHistory ME simultaneously for different instances of the ME. |
| 2797 | // The creation or deletion of an instance is decided based on its presence in gemPortNCTPPerfHistInstToDelete or |
| 2798 | // gemPortNCTPPerfHistInstToAdd slice |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2799 | |
| 2800 | logger.Debugw(ctx, "add gemport for perf monitoring - end", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2801 | log.Fields{"device-id": mm.deviceID, "pms-to-add": mm.l2PmToAdd, |
| 2802 | "instances-to-add": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd}) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2803 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2804 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventAddMe); err != nil { |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2805 | // log at warn level as the gem port for monitoring is going to be added eventually |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2806 | logger.Warnw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2807 | } |
| 2808 | }() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2809 | } |
| 2810 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2811 | // RemoveGemPortForPerfMonitoring - TODO: add comment |
| 2812 | func (mm *OnuMetricsManager) RemoveGemPortForPerfMonitoring(ctx context.Context, gemPortNTPInstID uint16) { |
| 2813 | mm.OnuMetricsManagerLock.Lock() |
| 2814 | defer mm.OnuMetricsManagerLock.Unlock() |
| 2815 | logger.Debugw(ctx, "remove gemport for perf monitoring - start", log.Fields{"device-id": mm.deviceID, "gemPortID": gemPortNTPInstID}) |
| 2816 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete = mm.appendIfMissingUnt16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete, gemPortNTPInstID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2817 | // If the instance presence toggles too soon, we need to remove it from gemPortNCTPPerfHistInstToAdd slice |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2818 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd = mm.removeIfFoundUint16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, gemPortNTPInstID) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2819 | |
| 2820 | mm.l2PmToDelete = mm.appendIfMissingString(mm.l2PmToDelete, GemPortHistoryName) |
| 2821 | // We do not need to remove from l2PmToAdd slice as we could have Add and Delete of |
| 2822 | // GemPortPerfHistory ME simultaneously for different instances of the ME. |
| 2823 | // The creation or deletion of an instance is decided based on its presence in gemPortNCTPPerfHistInstToDelete or |
| 2824 | // gemPortNCTPPerfHistInstToAdd slice |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2825 | |
| 2826 | logger.Debugw(ctx, "remove gemport from perf monitoring - end", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2827 | log.Fields{"device-id": mm.deviceID, "pms-to-delete": mm.l2PmToDelete, |
| 2828 | "instances-to-delete": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete}) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2829 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2830 | if err := mm.PAdaptFsm.PFsm.Event(L2PmEventDeleteMe); err != nil { |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2831 | // log at warn level as the gem port for monitoring is going to be removed eventually |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2832 | logger.Warnw(ctx, "error calling event", log.Fields{"device-id": mm.deviceID, "err": err}) |
Girish Gowdra | 69570d9 | 2021-04-22 18:26:20 -0700 | [diff] [blame] | 2833 | } |
| 2834 | }() |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2837 | func (mm *OnuMetricsManager) updateGemPortNTPInstanceToAddForPerfMonitoring(ctx context.Context) { |
| 2838 | if mm.pDeviceHandler.GetOnuTP() != nil { |
| 2839 | gemPortInstIDs := mm.pDeviceHandler.GetOnuTP().GetAllBidirectionalGemPortIDsForOnu() |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2840 | // NOTE: It is expected that caller of this function has acquired the required mutex for synchronization purposes |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2841 | for _, v := range gemPortInstIDs { |
| 2842 | // mark the instance for addition |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2843 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd = mm.appendIfMissingUnt16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, v) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2844 | // If the instance presence toggles too soon, we need to remove it from gemPortNCTPPerfHistInstToDelete slice |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2845 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete = mm.removeIfFoundUint16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete, v) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2846 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2847 | logger.Debugw(ctx, "updateGemPortNTPInstanceToAddForPerfMonitoring", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2848 | log.Fields{"deviceID": mm.deviceID, "gemToAdd": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, "gemToDel": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete}) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2849 | } |
| 2850 | } |
| 2851 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2852 | func (mm *OnuMetricsManager) updateGemPortNTPInstanceToDeleteForPerfMonitoring(ctx context.Context) { |
| 2853 | if mm.pDeviceHandler.GetOnuTP() != nil { |
| 2854 | gemPortInstIDs := mm.pDeviceHandler.GetOnuTP().GetAllBidirectionalGemPortIDsForOnu() |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2855 | // NOTE: It is expected that caller of this function has acquired the required mutex for synchronization purposes |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2856 | for _, v := range gemPortInstIDs { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2857 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete = mm.appendIfMissingUnt16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete, v) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2858 | // If the instance presence toggles too soon, we need to remove it from gemPortNCTPPerfHistInstToAdd slice |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2859 | mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd = mm.removeIfFoundUint16(mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, v) |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 2860 | } |
| 2861 | } |
Girish Gowdra | 36ccf7d | 2021-02-25 20:42:51 -0800 | [diff] [blame] | 2862 | logger.Debugw(ctx, "updateGemPortNTPInstanceToDeleteForPerfMonitoring", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2863 | log.Fields{"deviceID": mm.deviceID, "gemToAdd": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToAdd, "gemToDel": mm.GroupMetricMap[GemPortHistoryName].pmMEData.InstancesToDelete}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | // restorePmData restores any PM data available on the KV store to local cache |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2867 | func (mm *OnuMetricsManager) restorePmData(ctx context.Context) error { |
| 2868 | logger.Debugw(ctx, "restorePmData - start", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2869 | if mm.pmKvStore == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2870 | logger.Errorw(ctx, "pmKvStore not set - abort", log.Fields{"device-id": mm.deviceID}) |
| 2871 | return fmt.Errorf(fmt.Sprintf("pmKvStore-not-set-abort-%s", mm.deviceID)) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2872 | } |
| 2873 | var errorsList []error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2874 | for groupName, group := range mm.GroupMetricMap { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2875 | group.pmMEData = &pmMEData{} |
| 2876 | Value, err := mm.pmKvStore.Get(ctx, groupName) |
| 2877 | if err == nil { |
| 2878 | if Value != nil { |
| 2879 | logger.Debugw(ctx, "PM data read", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2880 | log.Fields{"Key": Value.Key, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2881 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 2882 | |
| 2883 | if err = json.Unmarshal(tmpBytes, &group.pmMEData); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2884 | logger.Errorw(ctx, "unable to unmarshal PM data", log.Fields{"error": err, "device-id": mm.deviceID}) |
| 2885 | errorsList = append(errorsList, fmt.Errorf(fmt.Sprintf("unable-to-unmarshal-PM-data-%s-for-group-%s", mm.deviceID, groupName))) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2886 | continue |
| 2887 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2888 | logger.Debugw(ctx, "restorePmData - success", log.Fields{"pmData": group.pmMEData, "groupName": groupName, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2889 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2890 | logger.Debugw(ctx, "no PM data found", log.Fields{"groupName": groupName, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2891 | continue |
| 2892 | } |
| 2893 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2894 | logger.Errorw(ctx, "restorePmData - fail", log.Fields{"device-id": mm.deviceID, "groupName": groupName, "err": err}) |
| 2895 | errorsList = append(errorsList, fmt.Errorf(fmt.Sprintf("unable-to-read-from-KVstore-%s-for-group-%s", mm.deviceID, groupName))) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2896 | continue |
| 2897 | } |
| 2898 | } |
| 2899 | if len(errorsList) > 0 { |
| 2900 | return fmt.Errorf("errors-restoring-pm-data-for-one-or-more-groups--errors:%v", errorsList) |
| 2901 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2902 | logger.Debugw(ctx, "restorePmData - complete success", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2903 | return nil |
| 2904 | } |
| 2905 | |
| 2906 | // getPmData gets pmMEData from cache. Since we have write through cache implementation for pmMEData, |
| 2907 | // the data must be available in cache. |
| 2908 | // Note, it is expected that caller of this function manages the required synchronization (like using locks etc.). |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2909 | func (mm *OnuMetricsManager) getPmData(ctx context.Context, groupName string) (*pmMEData, error) { |
| 2910 | if grp, ok := mm.GroupMetricMap[groupName]; ok { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2911 | return grp.pmMEData, nil |
| 2912 | } |
| 2913 | // Data not in cache, try to fetch from kv store. |
| 2914 | data := &pmMEData{} |
| 2915 | if mm.pmKvStore == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2916 | logger.Errorw(ctx, "pmKvStore not set - abort", log.Fields{"device-id": mm.deviceID}) |
| 2917 | return data, fmt.Errorf("pmKvStore not set. device-id - %s", mm.deviceID) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2918 | } |
| 2919 | Value, err := mm.pmKvStore.Get(ctx, groupName) |
| 2920 | if err == nil { |
| 2921 | if Value != nil { |
| 2922 | logger.Debugw(ctx, "PM data read", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2923 | log.Fields{"Key": Value.Key, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2924 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 2925 | |
| 2926 | if err = json.Unmarshal(tmpBytes, data); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2927 | logger.Errorw(ctx, "unable to unmarshal PM data", log.Fields{"error": err, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2928 | return data, err |
| 2929 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2930 | logger.Debugw(ctx, "PM data", log.Fields{"pmData": data, "groupName": groupName, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2931 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2932 | logger.Debugw(ctx, "no PM data found", log.Fields{"groupName": groupName, "device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2933 | return data, err |
| 2934 | } |
| 2935 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2936 | logger.Errorw(ctx, "unable to read from KVstore", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2937 | return data, err |
| 2938 | } |
| 2939 | |
| 2940 | return data, nil |
| 2941 | } |
| 2942 | |
| 2943 | // updatePmData update pmMEData to store. It is write through cache, i.e., write to cache first and then update store |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2944 | func (mm *OnuMetricsManager) updatePmData(ctx context.Context, groupName string, meInstanceID uint16, pmAction string) error { |
| 2945 | logger.Debugw(ctx, "updatePmData - start", log.Fields{"device-id": mm.deviceID, "groupName": groupName, "entityID": meInstanceID, "pmAction": pmAction}) |
| 2946 | mm.OnuMetricsManagerLock.Lock() |
| 2947 | defer mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2948 | |
| 2949 | if mm.pmKvStore == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2950 | logger.Errorw(ctx, "pmKvStore not set - abort", log.Fields{"device-id": mm.deviceID}) |
| 2951 | return fmt.Errorf(fmt.Sprintf("pmKvStore-not-set-abort-%s", mm.deviceID)) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | pmMEData, err := mm.getPmData(ctx, groupName) |
| 2955 | if err != nil || pmMEData == nil { |
| 2956 | // error already logged in called function. |
| 2957 | return err |
| 2958 | } |
| 2959 | switch pmAction { |
| 2960 | case cPmAdd: |
| 2961 | pmMEData.InstancesToAdd = mm.appendIfMissingUnt16(pmMEData.InstancesToAdd, meInstanceID) |
| 2962 | pmMEData.InstancesToDelete = mm.removeIfFoundUint16(pmMEData.InstancesToDelete, meInstanceID) |
| 2963 | pmMEData.InstancesActive = mm.removeIfFoundUint16(pmMEData.InstancesActive, meInstanceID) |
| 2964 | case cPmAdded: |
| 2965 | pmMEData.InstancesActive = mm.appendIfMissingUnt16(pmMEData.InstancesActive, meInstanceID) |
| 2966 | pmMEData.InstancesToAdd = mm.removeIfFoundUint16(pmMEData.InstancesToAdd, meInstanceID) |
| 2967 | pmMEData.InstancesToDelete = mm.removeIfFoundUint16(pmMEData.InstancesToDelete, meInstanceID) |
| 2968 | case cPmRemove: |
| 2969 | pmMEData.InstancesToDelete = mm.appendIfMissingUnt16(pmMEData.InstancesToDelete, meInstanceID) |
| 2970 | pmMEData.InstancesToAdd = mm.removeIfFoundUint16(pmMEData.InstancesToAdd, meInstanceID) |
| 2971 | pmMEData.InstancesActive = mm.removeIfFoundUint16(pmMEData.InstancesActive, meInstanceID) |
| 2972 | case cPmRemoved: |
| 2973 | pmMEData.InstancesToDelete = mm.removeIfFoundUint16(pmMEData.InstancesToDelete, meInstanceID) |
| 2974 | pmMEData.InstancesToAdd = mm.removeIfFoundUint16(pmMEData.InstancesToAdd, meInstanceID) |
| 2975 | pmMEData.InstancesActive = mm.removeIfFoundUint16(pmMEData.InstancesActive, meInstanceID) |
| 2976 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2977 | logger.Errorw(ctx, "unknown pm action", log.Fields{"device-id": mm.deviceID, "pmAction": pmAction, "groupName": groupName}) |
| 2978 | return fmt.Errorf(fmt.Sprintf("unknown-pm-action-deviceid-%s-groupName-%s-pmaction-%s", mm.deviceID, groupName, pmAction)) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2979 | } |
| 2980 | // write through cache |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 2981 | mm.GroupMetricMap[groupName].pmMEData = pmMEData |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2982 | |
| 2983 | Value, err := json.Marshal(*pmMEData) |
| 2984 | if err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2985 | logger.Errorw(ctx, "unable to marshal PM data", log.Fields{"device-id": mm.deviceID, |
| 2986 | "groupName": groupName, "pmAction": pmAction, "pmData": *pmMEData, "err": err}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2987 | return err |
| 2988 | } |
| 2989 | // Update back to kv store |
| 2990 | if err = mm.pmKvStore.Put(ctx, groupName, Value); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2991 | logger.Errorw(ctx, "unable to put PM data to kv store", log.Fields{"device-id": mm.deviceID, |
| 2992 | "groupName": groupName, "pmData": *pmMEData, "pmAction": pmAction, "err": err}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2993 | return err |
| 2994 | } |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 2995 | logger.Debugw(ctx, "updatePmData - success", log.Fields{"device-id": mm.deviceID, |
| 2996 | "groupName": groupName, "pmData": *pmMEData, "pmAction": pmAction}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 2997 | |
| 2998 | return nil |
| 2999 | } |
| 3000 | |
| 3001 | // clearPmGroupData cleans PM Group data from store |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3002 | func (mm *OnuMetricsManager) clearPmGroupData(ctx context.Context) error { |
| 3003 | mm.OnuMetricsManagerLock.Lock() |
| 3004 | defer mm.OnuMetricsManagerLock.Unlock() |
| 3005 | logger.Debugw(ctx, "clearPmGroupData - start", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3006 | if mm.pmKvStore == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3007 | logger.Errorw(ctx, "pmKvStore not set - abort", log.Fields{"device-id": mm.deviceID}) |
| 3008 | return fmt.Errorf(fmt.Sprintf("pmKvStore-not-set-abort-%s", mm.deviceID)) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3009 | } |
| 3010 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3011 | for n := range mm.GroupMetricMap { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3012 | if err := mm.pmKvStore.Delete(ctx, n); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3013 | logger.Errorw(ctx, "clearPmGroupData - fail", log.Fields{"deviceID": mm.deviceID, "groupName": n, "err": err}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3014 | // do not abort this procedure. continue to delete next group. |
| 3015 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3016 | logger.Debugw(ctx, "clearPmGroupData - success", log.Fields{"device-id": mm.deviceID, "groupName": n}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | return nil |
| 3021 | } |
| 3022 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3023 | // ClearAllPmData clears all PM data associated with the device from KV store |
| 3024 | func (mm *OnuMetricsManager) ClearAllPmData(ctx context.Context) error { |
| 3025 | mm.OnuMetricsManagerLock.Lock() |
| 3026 | defer mm.OnuMetricsManagerLock.Unlock() |
| 3027 | logger.Debugw(ctx, "ClearAllPmData - start", log.Fields{"device-id": mm.deviceID}) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3028 | if mm.pmKvStore == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3029 | logger.Errorw(ctx, "pmKvStore not set - abort", log.Fields{"device-id": mm.deviceID}) |
| 3030 | return fmt.Errorf(fmt.Sprintf("pmKvStore-not-set-abort-%s", mm.deviceID)) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3031 | } |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3032 | var value error |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3033 | for n := range mm.GroupMetricMap { |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3034 | if err := mm.pmKvStore.Delete(ctx, n); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3035 | logger.Errorw(ctx, "clearPmGroupData - fail", log.Fields{"deviceID": mm.deviceID, "groupName": n, "err": err}) |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3036 | value = err |
| 3037 | // do not abort this procedure - continue to delete next group. |
| 3038 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3039 | logger.Debugw(ctx, "clearPmGroupData - success", log.Fields{"device-id": mm.deviceID, "groupName": n}) |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3040 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 3041 | } |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3042 | if value == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3043 | logger.Debugw(ctx, "ClearAllPmData - success", log.Fields{"device-id": mm.deviceID}) |
Holger Hildebrandt | 44a0d4f | 2021-03-18 14:00:54 +0000 | [diff] [blame] | 3044 | } |
| 3045 | return value |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 3046 | } |
| 3047 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3048 | func (mm *OnuMetricsManager) updateOmciProcessingStatus(status bool) { |
| 3049 | mm.OnuMetricsManagerLock.Lock() |
| 3050 | defer mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3051 | mm.omciProcessingActive = status |
| 3052 | } |
| 3053 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3054 | // updateTickGenerationStatus - TODO: add comment |
| 3055 | func (mm *OnuMetricsManager) updateTickGenerationStatus(status bool) { |
| 3056 | mm.OnuMetricsManagerLock.Lock() |
| 3057 | defer mm.OnuMetricsManagerLock.Unlock() |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3058 | mm.tickGenerationActive = status |
| 3059 | } |
| 3060 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3061 | // GetOmciProcessingStatus - TODO: add comment |
| 3062 | func (mm *OnuMetricsManager) GetOmciProcessingStatus() bool { |
| 3063 | mm.OnuMetricsManagerLock.RLock() |
| 3064 | defer mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3065 | return mm.omciProcessingActive |
| 3066 | } |
| 3067 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3068 | // GetTickGenerationStatus - TODO: add comment |
| 3069 | func (mm *OnuMetricsManager) GetTickGenerationStatus() bool { |
| 3070 | mm.OnuMetricsManagerLock.RLock() |
| 3071 | defer mm.OnuMetricsManagerLock.RUnlock() |
Girish Gowdra | 7b0ee5c | 2021-03-19 21:48:15 -0700 | [diff] [blame] | 3072 | return mm.tickGenerationActive |
| 3073 | } |
| 3074 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3075 | func (mm *OnuMetricsManager) appendIfMissingString(slice []string, n string) []string { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3076 | for _, ele := range slice { |
| 3077 | if ele == n { |
| 3078 | return slice |
| 3079 | } |
| 3080 | } |
| 3081 | return append(slice, n) |
| 3082 | } |
| 3083 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3084 | func (mm *OnuMetricsManager) removeIfFoundString(slice []string, n string) []string { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 3085 | for i, ele := range slice { |
| 3086 | if ele == n { |
| 3087 | return append(slice[:i], slice[i+1:]...) |
| 3088 | } |
| 3089 | } |
| 3090 | return slice |
| 3091 | } |
| 3092 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3093 | func (mm *OnuMetricsManager) appendIfMissingUnt16(slice []uint16, n uint16) []uint16 { |
Girish Gowdra | 5c5aaf4 | 2021-02-17 19:40:50 -0800 | [diff] [blame] | 3094 | for _, ele := range slice { |
| 3095 | if ele == n { |
| 3096 | return slice |
| 3097 | } |
| 3098 | } |
| 3099 | return append(slice, n) |
| 3100 | } |
| 3101 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3102 | func (mm *OnuMetricsManager) removeIfFoundUint16(slice []uint16, n uint16) []uint16 { |
Girish Gowdra | e0140f0 | 2021-02-02 16:55:09 -0800 | [diff] [blame] | 3103 | for i, ele := range slice { |
| 3104 | if ele == n { |
| 3105 | return append(slice[:i], slice[i+1:]...) |
| 3106 | } |
| 3107 | } |
| 3108 | return slice |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 3109 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3110 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3111 | func (mm *OnuMetricsManager) getEthernetFrameExtendedMETypeFromKvStore(ctx context.Context) (bool, error) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3112 | // Check if the data is already available in KV store, if yes, do not send the request for get me. |
| 3113 | var data me.ClassID |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3114 | key := fmt.Sprintf("%s/%s/%s", mm.pOnuDeviceEntry.GetPersVendorID(), |
Holger Hildebrandt | 6a001d0 | 2022-06-15 08:32:48 +0000 | [diff] [blame] | 3115 | mm.pOnuDeviceEntry.GetPersVersion(), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3116 | mm.pOnuDeviceEntry.GetPersActiveSwVersion()) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3117 | Value, err := mm.extPmKvStore.Get(ctx, key) |
| 3118 | if err == nil { |
| 3119 | if Value != nil { |
| 3120 | logger.Debugw(ctx, "me-type-read", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3121 | log.Fields{"key": Value.Key, "device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3122 | tmpBytes, _ := kvstore.ToByte(Value.Value) |
| 3123 | |
| 3124 | if err = json.Unmarshal(tmpBytes, &data); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3125 | logger.Errorw(ctx, "unable-to-unmarshal-data", log.Fields{"error": err, "device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3126 | return false, err |
| 3127 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3128 | logger.Debugw(ctx, "me-ext-pm-class-data", log.Fields{"class-id": data, "device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3129 | // We have found the data from db, no need to get through omci get message. |
| 3130 | mm.supportedEthernetFrameExtendedPMClass = data |
| 3131 | return true, nil |
| 3132 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3133 | logger.Debugw(ctx, "no-me-ext-pm-class-data-found", log.Fields{"device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3134 | return false, nil |
| 3135 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3136 | logger.Errorw(ctx, "unable-to-read-from-kv-store", log.Fields{"device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3137 | return false, err |
| 3138 | } |
| 3139 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3140 | func (mm *OnuMetricsManager) waitForEthernetFrameCreateOrDeleteResponseOrTimeout(ctx context.Context, create bool, instID uint16, meClassID me.ClassID, upstream bool) (bool, error) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3141 | logger.Debugw(ctx, "wait-for-ethernet-frame-create-or-delete-response-or-timeout", log.Fields{"create": create, "instID": instID, "meClassID": meClassID}) |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 3142 | if !mm.GetOmciProcessingStatus() || mm.GetdeviceDeletionInProgress() { |
| 3143 | logger.Errorw(ctx, "not waiting for omci resp, because the omci resp processor is shutdown due to device down/delete", log.Fields{"device-id": mm.deviceID}) |
| 3144 | return false, fmt.Errorf("omci-processor-shutdown") |
| 3145 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3146 | select { |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3147 | case resp := <-mm.extendedPMMeResponseChan: |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3148 | logger.Debugw(ctx, "received-extended-pm-me-response", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3149 | log.Fields{"device-id": mm.deviceID, "resp": resp, "create": create, "meClassID": meClassID, "instID": instID, "upstream": upstream}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3150 | // If the result is me.InstanceExists it means the entity was already created. It is ok handled that as success |
| 3151 | if resp == me.Success || resp == me.InstanceExists { |
| 3152 | return true, nil |
| 3153 | } else if resp == me.UnknownEntity || resp == me.ParameterError || |
| 3154 | resp == me.ProcessingError || resp == me.NotSupported || resp == me.AttributeFailure { |
| 3155 | return false, fmt.Errorf("not-supported-me--resp-code-%v", resp) |
| 3156 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3157 | logger.Warnw(ctx, "failed to create me", log.Fields{"device-id": mm.deviceID, "resp": resp, "class-id": meClassID, "instID": instID, "upstream": upstream}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3158 | return true, fmt.Errorf("error-while-creating-me--resp-code-%v", resp) |
| 3159 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3160 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3161 | logger.Errorw(ctx, "timeout-waiting-for-ext-pm-me-response", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3162 | log.Fields{"device-id": mm.deviceID, "resp": false, "create": create, "meClassID": meClassID, "instID": instID, "upstream": upstream}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3163 | } |
| 3164 | return false, fmt.Errorf("timeout-while-waiting-for-response") |
| 3165 | } |
| 3166 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3167 | func (mm *OnuMetricsManager) tryCreateExtPmMe(ctx context.Context, meType me.ClassID) (bool, error) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3168 | cnt := 0 |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3169 | // Create ME twice, one for each direction. Boolean true is used to indicate upstream and false for downstream. |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 3170 | for _, direction := range []bool{true, false} { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3171 | for _, uniPort := range *mm.pDeviceHandler.GetUniEntityMap() { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3172 | var entityID uint16 |
| 3173 | if direction { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3174 | entityID = uniPort.EntityID + 0x100 |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3175 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3176 | entityID = uniPort.EntityID |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3177 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3178 | logger.Debugw(ctx, "try-creating-extended-pm-me", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3179 | // parent entity id will be same for both direction |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3180 | controlBlock := mm.getControlBlockForExtendedPMDirection(ctx, direction, uniPort.EntityID, false) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3181 | |
| 3182 | inner1: |
| 3183 | // retry ExtendedPmCreateAttempts times to create the instance of PM |
| 3184 | for cnt = 0; cnt < ExtendedPmCreateAttempts; cnt++ { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3185 | meEnt, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendCreateOrDeleteEthernetFrameExtendedPMME( |
| 3186 | ctx, mm.pDeviceHandler.GetOmciTimeout(), true, direction, true, |
| 3187 | mm.PAdaptFsm.CommChan, entityID, meType, controlBlock) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3188 | if err != nil { |
| 3189 | logger.Errorw(ctx, "EthernetFrameExtendedPMME-create-or-delete-failed", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3190 | log.Fields{"device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3191 | return false, err |
| 3192 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3193 | if supported, err := mm.waitForEthernetFrameCreateOrDeleteResponseOrTimeout(ctx, true, entityID, |
| 3194 | meType, direction); err == nil && supported { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3195 | if direction { |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 3196 | mm.ethernetFrameExtendedPmUpStreamMEByEntityID[entityID] = meEnt |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3197 | } else { |
Himani Chawla | c77d537 | 2021-07-12 15:42:26 +0530 | [diff] [blame] | 3198 | mm.ethernetFrameExtendedPmDownStreamMEByEntityID[entityID] = meEnt |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3199 | } |
| 3200 | break inner1 |
| 3201 | } else if err != nil { |
| 3202 | if !supported { |
| 3203 | // Need to return immediately |
| 3204 | return false, err |
| 3205 | } |
| 3206 | //In case of failure, go for a retry |
| 3207 | } |
| 3208 | } |
| 3209 | if cnt == ExtendedPmCreateAttempts { |
| 3210 | logger.Error(ctx, "exceeded-attempts-while-creating-me-for-ethernet-frame-extended-pm") |
| 3211 | return true, fmt.Errorf("unable-to-create-me") |
| 3212 | } |
| 3213 | } |
| 3214 | } |
| 3215 | return true, nil |
| 3216 | } |
| 3217 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3218 | func (mm *OnuMetricsManager) putExtPmMeKvStore(ctx context.Context) { |
| 3219 | key := fmt.Sprintf("%s/%s/%s", mm.pOnuDeviceEntry.GetPersVendorID(), |
Holger Hildebrandt | 6a001d0 | 2022-06-15 08:32:48 +0000 | [diff] [blame] | 3220 | mm.pOnuDeviceEntry.GetPersVersion(), |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3221 | mm.pOnuDeviceEntry.GetPersActiveSwVersion()) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3222 | // check if we get the supported type me for ethernet frame extended pm class id |
| 3223 | if mm.supportedEthernetFrameExtendedPMClass == 0 { |
| 3224 | logger.Error(ctx, "unable-to-get-any-supported-extended-pm-me-class") |
| 3225 | } |
| 3226 | classSupported, err := json.Marshal(mm.supportedEthernetFrameExtendedPMClass) |
| 3227 | if err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 3228 | logger.Errorw(ctx, "unable-to-marshal-data", log.Fields{"device-id": mm.deviceID, "err": err}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3229 | } |
| 3230 | if err := mm.extPmKvStore.Put(ctx, key, classSupported); err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 3231 | logger.Errorw(ctx, "unable-to-add-data-in-db", log.Fields{"device-id": mm.deviceID, "err": err}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3235 | func (mm *OnuMetricsManager) setAllExtPmMeCreatedFlag() { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3236 | mm.onuEthernetFrameExtendedPmLock.Lock() |
| 3237 | mm.isDeviceReadyToCollectExtendedPmStats = true |
| 3238 | mm.onuEthernetFrameExtendedPmLock.Unlock() |
| 3239 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3240 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3241 | // CreateEthernetFrameExtendedPMME - This method tries to create the possible me type for extended pms |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3242 | func (mm *OnuMetricsManager) CreateEthernetFrameExtendedPMME(ctx context.Context) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3243 | //get the type of extended frame pm me supported by onu first |
| 3244 | exist, err := mm.getEthernetFrameExtendedMETypeFromKvStore(ctx) |
| 3245 | if err != nil { |
| 3246 | logger.Error(ctx, "unable-to-get-supported-me-for-ethernet-frame-extended-pm") |
| 3247 | return |
| 3248 | } |
| 3249 | if exist { |
| 3250 | // we have the me type, go ahead with the me type supported. |
| 3251 | if _, err := mm.tryCreateExtPmMe(ctx, mm.supportedEthernetFrameExtendedPMClass); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3252 | logger.Errorw(ctx, "unable-to-create-me-type", log.Fields{"device-id": mm.deviceID, |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3253 | "meClassID": mm.supportedEthernetFrameExtendedPMClass}) |
| 3254 | return |
| 3255 | } |
| 3256 | mm.setAllExtPmMeCreatedFlag() |
| 3257 | return |
| 3258 | } |
| 3259 | // First try with 64 bit me |
| 3260 | // we have the me type, go ahead with the me type supported. |
| 3261 | supported64Bit, err := mm.tryCreateExtPmMe(ctx, me.EthernetFrameExtendedPm64BitClassID) |
| 3262 | if err != nil && !supported64Bit { |
| 3263 | logger.Errorw(ctx, "unable-to-create-me-type-as-it-is-not-supported", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3264 | log.Fields{"device-id": mm.deviceID, "meClassID": me.EthernetFrameExtendedPm64BitClassID, |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3265 | "supported": supported64Bit}) |
| 3266 | // Then Try with 32 bit type |
| 3267 | if supported32Bit, err := mm.tryCreateExtPmMe(ctx, me.EthernetFrameExtendedPmClassID); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3268 | logger.Errorw(ctx, "unable-to-create-me-type", log.Fields{"device-id": mm.deviceID, |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3269 | "meClassID": me.EthernetFrameExtendedPmClassID, "supported": supported32Bit}) |
| 3270 | } else if supported32Bit { |
| 3271 | mm.supportedEthernetFrameExtendedPMClass = me.EthernetFrameExtendedPmClassID |
| 3272 | mm.putExtPmMeKvStore(ctx) |
| 3273 | mm.setAllExtPmMeCreatedFlag() |
| 3274 | } |
| 3275 | } else if err == nil && supported64Bit { |
| 3276 | mm.supportedEthernetFrameExtendedPMClass = me.EthernetFrameExtendedPm64BitClassID |
| 3277 | mm.putExtPmMeKvStore(ctx) |
| 3278 | mm.setAllExtPmMeCreatedFlag() |
| 3279 | } |
| 3280 | } |
| 3281 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3282 | func (mm *OnuMetricsManager) setControlBlockResetFlagForEthernetExtendedPMME(ctx context.Context, upstream bool, |
| 3283 | entityID uint16, meName string, reset bool) (extension.GetValueResponse_ErrorReason, error) { |
| 3284 | uniPortEntityID := entityID |
| 3285 | if upstream { |
| 3286 | uniPortEntityID = entityID - 0x100 |
| 3287 | } |
| 3288 | controlBlock := mm.getControlBlockForExtendedPMDirection(ctx, upstream, uniPortEntityID, reset) |
| 3289 | _, err := mm.pOnuDeviceEntry.GetDevOmciCC().SendSetEthernetFrameExtendedPMME(ctx, |
| 3290 | mm.pDeviceHandler.GetOmciTimeout(), true, |
| 3291 | mm.PAdaptFsm.CommChan, entityID, mm.supportedEthernetFrameExtendedPMClass, controlBlock) |
| 3292 | if err != nil { |
| 3293 | logger.Errorw(ctx, "EthernetFrameExtendedPMME-set-reset-bit-failed", |
| 3294 | log.Fields{"device-id": mm.deviceID}) |
| 3295 | return extension.GetValueResponse_INTERNAL_ERROR, err |
| 3296 | } |
| 3297 | |
| 3298 | if resp := mm.waitForResetResponseOrTimeout(ctx, entityID, meName); resp { |
| 3299 | return extension.GetValueResponse_REASON_UNDEFINED, nil |
| 3300 | } |
| 3301 | return extension.GetValueResponse_INTERNAL_ERROR, fmt.Errorf("unable-to-reset-pm-counters") |
| 3302 | } |
| 3303 | |
| 3304 | func (mm *OnuMetricsManager) waitForResetResponseOrTimeout(ctx context.Context, instID uint16, meClassName string) bool { |
| 3305 | logger.Debugw(ctx, "wait-for-ethernet-frame-reset-counters-response-or-timeout", log.Fields{"instID": instID, "meClassName": meClassName}) |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 3306 | if !mm.GetOmciProcessingStatus() { |
| 3307 | logger.Errorw(ctx, "not waiting for omci resp, because the omci resp processor is shutdown due to device down/delete", log.Fields{"device-id": mm.deviceID}) |
| 3308 | return false |
| 3309 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3310 | select { |
| 3311 | case resp := <-mm.extendedPMMeResponseChan: |
| 3312 | logger.Debugw(ctx, "received-extended-pm-me-reset-response", |
| 3313 | log.Fields{"device-id": mm.deviceID, "resp": resp, "meClassName": meClassName, "instID": instID}) |
| 3314 | if resp == me.Success { |
| 3315 | return true |
| 3316 | } |
| 3317 | return false |
| 3318 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
| 3319 | logger.Errorw(ctx, "timeout-waiting-for-ext-pm-me-reset-response", |
| 3320 | log.Fields{"device-id": mm.deviceID, "resp": false, "meClassName": meClassName, "instID": instID}) |
| 3321 | } |
| 3322 | return false |
| 3323 | } |
| 3324 | |
| 3325 | func (mm *OnuMetricsManager) resetEthernetFrameExtendedPMCounters(ctx context.Context, |
| 3326 | upstreamEntityMap map[uint16]*me.ManagedEntity, downstreamEntityMap map[uint16]*me.ManagedEntity) (extension.GetValueResponse_ErrorReason, error) { |
| 3327 | className := "EthernetFrameExtendedPm64Bit" |
| 3328 | if mm.supportedEthernetFrameExtendedPMClass == me.EthernetFrameExtendedPmClassID { |
| 3329 | className = "EthernetFrameExtendedPm" |
| 3330 | } |
| 3331 | // Reset the counters if option is specified |
| 3332 | for entityID := range upstreamEntityMap { |
| 3333 | errReason, err := mm.setControlBlockResetFlagForEthernetExtendedPMME(ctx, true, entityID, className, |
| 3334 | true) |
| 3335 | if err != nil { |
| 3336 | return errReason, err |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | for entityID := range downstreamEntityMap { |
| 3341 | errReason, err := mm.setControlBlockResetFlagForEthernetExtendedPMME(ctx, false, entityID, className, |
| 3342 | true) |
| 3343 | if err != nil { |
| 3344 | return errReason, err |
| 3345 | } |
| 3346 | } |
| 3347 | // This is currently done as a workaround for sercomm glasfaser onu as the reset bit is not getting cleared by the |
| 3348 | // device itself. |
| 3349 | // Unset the reset bit if option is specified |
| 3350 | for entityID := range upstreamEntityMap { |
| 3351 | errReason, err := mm.setControlBlockResetFlagForEthernetExtendedPMME(ctx, true, entityID, className, |
| 3352 | false) |
| 3353 | if err != nil { |
| 3354 | return errReason, err |
| 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | for entityID := range downstreamEntityMap { |
| 3359 | errReason, err := mm.setControlBlockResetFlagForEthernetExtendedPMME(ctx, false, entityID, className, |
| 3360 | false) |
| 3361 | if err != nil { |
| 3362 | return errReason, err |
| 3363 | } |
| 3364 | } |
| 3365 | return extension.GetValueResponse_REASON_UNDEFINED, nil |
| 3366 | } |
| 3367 | |
| 3368 | func (mm *OnuMetricsManager) setEthernetFrameExtendedPmCounterOperationFlag(val bool) { |
| 3369 | mm.onuEthernetFrameExtendedPmLock.Lock() |
| 3370 | defer mm.onuEthernetFrameExtendedPmLock.Unlock() |
| 3371 | mm.isEthernetFrameExtendedPmOperationOngoing = val |
| 3372 | } |
| 3373 | |
| 3374 | func (mm *OnuMetricsManager) getEthernetFrameExtendedPmCounterOperationFlag() bool { |
| 3375 | mm.onuEthernetFrameExtendedPmLock.Lock() |
| 3376 | defer mm.onuEthernetFrameExtendedPmLock.Unlock() |
| 3377 | return mm.isEthernetFrameExtendedPmOperationOngoing |
| 3378 | } |
| 3379 | |
| 3380 | // CollectEthernetFrameExtendedPMCounters - This method collects the ethernet frame extended pm counters from the device |
| 3381 | func (mm *OnuMetricsManager) CollectEthernetFrameExtendedPMCounters(ctx context.Context, |
| 3382 | onuInfo *extension.GetOmciEthernetFrameExtendedPmRequest) *extension.SingleGetValueResponse { |
| 3383 | errFunc := func(reason extension.GetValueResponse_ErrorReason, err string) *extension.SingleGetValueResponse { |
| 3384 | logger.Error(ctx, err) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3385 | return &extension.SingleGetValueResponse{ |
| 3386 | Response: &extension.GetValueResponse{ |
| 3387 | Status: extension.GetValueResponse_ERROR, |
| 3388 | ErrReason: reason, |
| 3389 | }, |
| 3390 | } |
| 3391 | } |
| 3392 | mm.onuEthernetFrameExtendedPmLock.RLock() |
| 3393 | if !mm.isDeviceReadyToCollectExtendedPmStats { |
| 3394 | mm.onuEthernetFrameExtendedPmLock.RUnlock() |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3395 | return errFunc(extension.GetValueResponse_INTERNAL_ERROR, fmt.Sprintf("onu-%v-not-ready-to-collect-stats", mm.deviceID)) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3396 | } |
| 3397 | mm.onuEthernetFrameExtendedPmLock.RUnlock() |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3398 | |
| 3399 | if mm.getEthernetFrameExtendedPmCounterOperationFlag() { |
| 3400 | return errFunc(extension.GetValueResponse_INTERNAL_ERROR, |
| 3401 | fmt.Sprintf("extended-pm-reset-or-get-operation-is-still-going-on-for-onu-%v", mm.deviceID)) |
| 3402 | } |
| 3403 | mm.setEthernetFrameExtendedPmCounterOperationFlag(true) |
| 3404 | defer mm.setEthernetFrameExtendedPmCounterOperationFlag(false) |
| 3405 | |
| 3406 | upstreamEntityMap := make(map[uint16]*me.ManagedEntity) |
| 3407 | downstreamEntityMap := make(map[uint16]*me.ManagedEntity) |
| 3408 | if onuInfo.IsUniIndex != nil { |
| 3409 | for _, uniPort := range *mm.pDeviceHandler.GetUniEntityMap() { |
| 3410 | if uniPort.UniID == uint8(onuInfo.GetUniIndex()) { |
| 3411 | logger.Debugw(ctx, "mapped-uni-index-to-uni-port", log.Fields{"device-id": mm.deviceID, "uni-index": onuInfo.GetUniIndex()}) |
| 3412 | upstreamEntityMap[uniPort.EntityID+0x100] = mm.ethernetFrameExtendedPmUpStreamMEByEntityID[uniPort.EntityID+0x100] |
| 3413 | downstreamEntityMap[uniPort.EntityID] = mm.ethernetFrameExtendedPmDownStreamMEByEntityID[uniPort.EntityID] |
| 3414 | break |
| 3415 | } |
| 3416 | } |
| 3417 | if len(downstreamEntityMap) == 0 { |
| 3418 | logger.Errorw(ctx, "invalid-uni-index-provided-while-fetching-the-extended-pm", |
| 3419 | log.Fields{"device-id": mm.deviceID, "uni-index": onuInfo.GetUniIndex()}) |
| 3420 | return errFunc(extension.GetValueResponse_INVALID_REQ_TYPE, |
| 3421 | fmt.Sprintf("onu-%s-invalid-uni-%v", mm.deviceID, onuInfo.GetUniIndex())) |
| 3422 | } |
| 3423 | } else { |
| 3424 | // make a copy of all downstream and upstream maps in the local ones |
| 3425 | for entityID, meEnt := range mm.ethernetFrameExtendedPmUpStreamMEByEntityID { |
| 3426 | upstreamEntityMap[entityID] = meEnt |
| 3427 | } |
| 3428 | for entityID, meEnt := range mm.ethernetFrameExtendedPmDownStreamMEByEntityID { |
| 3429 | downstreamEntityMap[entityID] = meEnt |
| 3430 | } |
| 3431 | } |
| 3432 | logger.Debugw(ctx, "extended-pm-collection-me-count", log.Fields{"device-id": mm.deviceID, |
| 3433 | "count": len(upstreamEntityMap) + len(downstreamEntityMap)}) |
| 3434 | // Reset the metrics first for all required me's |
| 3435 | if onuInfo.Reset_ { |
| 3436 | errReason, err := mm.resetEthernetFrameExtendedPMCounters(ctx, upstreamEntityMap, downstreamEntityMap) |
| 3437 | if err != nil { |
| 3438 | logger.Errorw(ctx, "unable-to-reset-ethernet-frame-extended-pm-counters", |
| 3439 | log.Fields{"device-id": mm.deviceID}) |
| 3440 | return errFunc(errReason, fmt.Sprintf("%v", err.Error())) |
| 3441 | } |
| 3442 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3443 | // Collect metrics for upstream for all the PM Mes per uni port and aggregate |
| 3444 | var pmUpstream extension.OmciEthernetFrameExtendedPm |
| 3445 | var pmDownstream extension.OmciEthernetFrameExtendedPm |
Himani Chawla | 89ea9e6 | 2021-08-25 17:01:03 +0530 | [diff] [blame] | 3446 | counterFormat := extension.GetOmciEthernetFrameExtendedPmResponse_SIXTY_FOUR_BIT |
| 3447 | if mm.supportedEthernetFrameExtendedPMClass == me.EthernetFrameExtendedPmClassID { |
| 3448 | counterFormat = extension.GetOmciEthernetFrameExtendedPmResponse_THIRTY_TWO_BIT |
| 3449 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3450 | if !onuInfo.Reset_ { |
| 3451 | for entityID, meEnt := range upstreamEntityMap { |
| 3452 | logger.Debugw(ctx, "collect-upstream-pm-counters-for-entity-id", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
| 3453 | var receivedMask uint16 |
| 3454 | if metricInfo, errResp, err := mm.collectEthernetFrameExtendedPMData(ctx, meEnt, entityID, true, &receivedMask); metricInfo != nil { // upstream |
| 3455 | if receivedMask == 0 { |
| 3456 | pmUpstream = mm.aggregateEthernetFrameExtendedPM(metricInfo, pmUpstream, false) |
Himani Chawla | e18b10f | 2021-10-27 11:51:47 +0530 | [diff] [blame] | 3457 | logger.Error(ctx, "all-the-attributes-of-ethernet-frame-extended-pm-counters-for-upstream-are-unsupported") |
| 3458 | // It might be possible that still some downstream pms are supported and hence we need to continue |
| 3459 | // further to collect the downstream stats but stop collecting upstream stats for other ME's. |
| 3460 | break |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3461 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3462 | // Aggregate the result for upstream |
| 3463 | pmUpstream = mm.aggregateEthernetFrameExtendedPM(metricInfo, pmUpstream, true) |
| 3464 | } else { |
| 3465 | return errFunc(errResp, fmt.Sprintf("%v", err.Error())) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3466 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3467 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3468 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3469 | for entityID, meEnt := range downstreamEntityMap { |
| 3470 | logger.Debugw(ctx, "collect-downstream-pm-counters-for-entity-id", log.Fields{"device-id": mm.deviceID, "entityID": entityID}) |
| 3471 | var receivedMask uint16 |
| 3472 | if metricInfo, errResp, err := mm.collectEthernetFrameExtendedPMData(ctx, meEnt, entityID, false, &receivedMask); metricInfo != nil { // downstream |
Himani Chawla | e18b10f | 2021-10-27 11:51:47 +0530 | [diff] [blame] | 3473 | if receivedMask == 0 { |
| 3474 | pmDownstream = mm.aggregateEthernetFrameExtendedPM(metricInfo, pmDownstream, false) |
| 3475 | logger.Error(ctx, "all-the-attributes-of-ethernet-frame-extended-pm-counters-for-downstream-are-unsupported") |
| 3476 | // Stop collecting downstream counters for other ME's. |
| 3477 | break |
| 3478 | } |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3479 | // Aggregate the result for downstream |
| 3480 | pmDownstream = mm.aggregateEthernetFrameExtendedPM(metricInfo, pmDownstream, true) |
| 3481 | } else { |
| 3482 | return errFunc(errResp, fmt.Sprintf("%v", err.Error())) |
| 3483 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | singleValResp := extension.SingleGetValueResponse{ |
| 3487 | Response: &extension.GetValueResponse{ |
| 3488 | Status: extension.GetValueResponse_OK, |
| 3489 | Response: &extension.GetValueResponse_OnuCounters{ |
| 3490 | OnuCounters: &extension.GetOmciEthernetFrameExtendedPmResponse{ |
Himani Chawla | 89ea9e6 | 2021-08-25 17:01:03 +0530 | [diff] [blame] | 3491 | Upstream: &pmUpstream, |
| 3492 | Downstream: &pmDownstream, |
| 3493 | OmciEthernetFrameExtendedPmFormat: counterFormat, |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3494 | }, |
| 3495 | }, |
| 3496 | }, |
| 3497 | } |
| 3498 | return &singleValResp |
| 3499 | } |
| 3500 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3501 | func (mm *OnuMetricsManager) collectEthernetFrameExtendedPMData(ctx context.Context, meEnt *me.ManagedEntity, entityID uint16, upstream bool, receivedMask *uint16) (map[string]uint64, extension.GetValueResponse_ErrorReason, error) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3502 | var classID me.ClassID |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3503 | logger.Debugw(ctx, "collecting-data-for-ethernet-frame-extended-pm", log.Fields{"device-id": mm.deviceID, "entityID": entityID, "upstream": upstream}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3504 | |
| 3505 | classID = mm.supportedEthernetFrameExtendedPMClass |
| 3506 | attributeMaskList := maskToEthernetFrameExtendedPM64Bit |
| 3507 | if classID == me.EthernetFrameExtendedPmClassID { |
| 3508 | attributeMaskList = maskToEthernetFrameExtendedPM32Bit |
| 3509 | } |
| 3510 | ethPMData := make(map[string]uint64) |
| 3511 | var sumReceivedMask uint16 |
| 3512 | for mask := range attributeMaskList { |
| 3513 | if errResp, err := mm.populateEthernetFrameExtendedPMMetrics(ctx, classID, entityID, mask, ethPMData, upstream, &sumReceivedMask); err != nil { |
| 3514 | logger.Errorw(ctx, "error-during-metric-collection", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3515 | log.Fields{"device-id": mm.deviceID, "entityID": entityID, "err": err}) |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3516 | return nil, errResp, err |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3517 | } |
| 3518 | if (mask == 0x3F00 || mask == 0x3800) && sumReceivedMask == 0 { |
| 3519 | //It means the first attributes fetch was a failure, hence instead of sending multiple failure get requests |
| 3520 | //populate all counters as failure and return |
| 3521 | mm.fillAllErrorCountersEthernetFrameExtendedPM(ethPMData) |
| 3522 | break |
| 3523 | } |
| 3524 | } |
| 3525 | *receivedMask = sumReceivedMask |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3526 | return ethPMData, extension.GetValueResponse_REASON_UNDEFINED, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3530 | func (mm *OnuMetricsManager) populateEthernetFrameExtendedPMMetrics(ctx context.Context, classID me.ClassID, entityID uint16, |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3531 | requestedAttributesMask uint16, ethFrameExtPMData map[string]uint64, upstream bool, sumReceivedMask *uint16) (extension.GetValueResponse_ErrorReason, error) { |
| 3532 | var meAttributes me.AttributeValueMap |
| 3533 | logger.Debugw(ctx, "requesting-attributes", log.Fields{"attributes-mask": requestedAttributesMask, "entityID": entityID, "classID": classID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3534 | err := mm.pOnuDeviceEntry.GetDevOmciCC().SendGetMeWithAttributeMask(ctx, classID, entityID, requestedAttributesMask, mm.pDeviceHandler.GetOmciTimeout(), true, mm.PAdaptFsm.CommChan) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3535 | if err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3536 | logger.Errorw(ctx, "get-me-failed", log.Fields{"device-id": mm.deviceID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3537 | return extension.GetValueResponse_INTERNAL_ERROR, err |
| 3538 | } |
| 3539 | select { |
| 3540 | case meAttributes = <-mm.extendedPmMeChan: |
| 3541 | logger.Debugw(ctx, "received-extended-pm-data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3542 | log.Fields{"device-id": mm.deviceID, "upstream": upstream, "entityID": entityID}) |
| 3543 | case <-time.After(mm.pOnuDeviceEntry.GetDevOmciCC().GetMaxOmciTimeoutWithRetries() * time.Second): |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3544 | logger.Errorw(ctx, "timeout-waiting-for-omci-get-response-for-received-extended-pm-data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3545 | log.Fields{"device-id": mm.deviceID, "upstream": upstream, "entityID": entityID}) |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3546 | return extension.GetValueResponse_TIMEOUT, fmt.Errorf("timeout-waiting-for-omci-get-response-for-received-extended-pm-data") |
| 3547 | } |
| 3548 | if mm.supportedEthernetFrameExtendedPMClass == me.EthernetFrameExtendedPmClassID { |
| 3549 | mask := mm.getEthFrameExtPMDataFromResponse(ctx, ethFrameExtPMData, meAttributes, requestedAttributesMask) |
| 3550 | *sumReceivedMask += mask |
| 3551 | logger.Debugw(ctx, "data-received-for-ethernet-frame-ext-pm", log.Fields{"data": ethFrameExtPMData, "entityID": entityID}) |
| 3552 | } else { |
| 3553 | mask := mm.getEthFrameExtPM64BitDataFromResponse(ctx, ethFrameExtPMData, meAttributes, requestedAttributesMask) |
| 3554 | *sumReceivedMask += mask |
| 3555 | logger.Debugw(ctx, "data-received-for-ethernet-frame-ext-pm", log.Fields{"data": ethFrameExtPMData, "entityID": entityID}) |
| 3556 | } |
| 3557 | |
| 3558 | return extension.GetValueResponse_REASON_UNDEFINED, nil |
| 3559 | } |
| 3560 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3561 | func (mm *OnuMetricsManager) fillAllErrorCountersEthernetFrameExtendedPM(ethFrameExtPMData map[string]uint64) { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3562 | sourceMap := maskToEthernetFrameExtendedPM64Bit |
| 3563 | errorCounterValue := UnsupportedCounterValue64bit |
| 3564 | if mm.supportedEthernetFrameExtendedPMClass == me.EthernetFrameExtendedPmClassID { |
| 3565 | sourceMap = maskToEthernetFrameExtendedPM32Bit |
| 3566 | errorCounterValue = UnsupportedCounterValue32bit |
| 3567 | } |
| 3568 | for _, value := range sourceMap { |
| 3569 | for _, k := range value { |
| 3570 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3571 | ethFrameExtPMData[k] = errorCounterValue |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3578 | func (mm *OnuMetricsManager) getEthFrameExtPMDataFromResponse(ctx context.Context, ethFrameExtPMData map[string]uint64, meAttributes me.AttributeValueMap, requestedAttributesMask uint16) uint16 { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3579 | receivedMask := uint16(0) |
| 3580 | switch requestedAttributesMask { |
| 3581 | case 0x3F00: |
| 3582 | for _, k := range maskToEthernetFrameExtendedPM32Bit[requestedAttributesMask] { |
| 3583 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3584 | switch k { |
| 3585 | case "drop_events": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3586 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_DropEvents]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3587 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3588 | receivedMask |= 0x2000 |
| 3589 | } else if !ok { |
| 3590 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3591 | } |
| 3592 | case "octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3593 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3594 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3595 | receivedMask |= 0x1000 |
| 3596 | } else if !ok { |
| 3597 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3598 | } |
| 3599 | case "frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3600 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3601 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3602 | receivedMask |= 0x800 |
| 3603 | } else if !ok { |
| 3604 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3605 | } |
| 3606 | case "broadcast_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3607 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_BroadcastFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3608 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3609 | receivedMask |= 0x400 |
| 3610 | } else if !ok { |
| 3611 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3612 | } |
| 3613 | case "multicast_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3614 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_MulticastFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3615 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3616 | receivedMask |= 0x200 |
| 3617 | } else if !ok { |
| 3618 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3619 | } |
| 3620 | case "crc_errored_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3621 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_CrcErroredFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3622 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3623 | receivedMask |= 0x100 |
| 3624 | } else if !ok { |
| 3625 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3626 | } |
| 3627 | default: |
| 3628 | //do nothing |
| 3629 | } |
| 3630 | } |
| 3631 | } |
| 3632 | case 0x00FC: |
| 3633 | for _, k := range maskToEthernetFrameExtendedPM32Bit[requestedAttributesMask] { |
| 3634 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3635 | switch k { |
| 3636 | case "undersize_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3637 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_UndersizeFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3638 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3639 | receivedMask |= 0x80 |
| 3640 | } else if !ok { |
| 3641 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3642 | } |
| 3643 | case "oversize_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3644 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_OversizeFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3645 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3646 | receivedMask |= 0x40 |
| 3647 | } else if !ok { |
| 3648 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3649 | } |
| 3650 | case "64_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3651 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames64Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3652 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3653 | receivedMask |= 0x20 |
| 3654 | } else if !ok { |
| 3655 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3656 | } |
| 3657 | case "65_to_127_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3658 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames65To127Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3659 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3660 | receivedMask |= 0x10 |
| 3661 | } else if !ok { |
| 3662 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3663 | } |
| 3664 | case "128_to_255_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3665 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames128To255Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3666 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3667 | receivedMask |= 0x8 |
| 3668 | } else if !ok { |
| 3669 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3670 | } |
| 3671 | case "256_to_511_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3672 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames256To511Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3673 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3674 | receivedMask |= 0x4 |
| 3675 | } else if !ok { |
| 3676 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3677 | } |
| 3678 | default: |
| 3679 | //do nothing |
| 3680 | } |
| 3681 | } |
| 3682 | } |
| 3683 | case 0x0003: |
| 3684 | for _, k := range maskToEthernetFrameExtendedPM32Bit[requestedAttributesMask] { |
| 3685 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3686 | switch k { |
| 3687 | case "512_to_1023_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3688 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames512To1023Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3689 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3690 | receivedMask |= 0x2 |
| 3691 | } else if !ok { |
| 3692 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3693 | } |
| 3694 | case "1024_to_1518_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3695 | if val, ok := meAttributes[me.EthernetFrameExtendedPm_Frames1024To1518Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3696 | ethFrameExtPMData[k] = uint64(val.(uint32)) |
| 3697 | receivedMask |= 0x1 |
| 3698 | } else if !ok { |
| 3699 | ethFrameExtPMData[k] = UnsupportedCounterValue32bit |
| 3700 | } |
| 3701 | default: |
| 3702 | //do nothing |
| 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | default: |
| 3707 | //do nothing |
| 3708 | } |
| 3709 | return receivedMask |
| 3710 | } |
| 3711 | |
| 3712 | // nolint: gocyclo |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 3713 | func (mm *OnuMetricsManager) getEthFrameExtPM64BitDataFromResponse(ctx context.Context, ethFrameExtPMData map[string]uint64, meAttributes me.AttributeValueMap, requestedAttributesMask uint16) uint16 { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3714 | receivedMask := uint16(0) |
| 3715 | switch requestedAttributesMask { |
| 3716 | case 0x3800: |
| 3717 | for _, k := range maskToEthernetFrameExtendedPM64Bit[requestedAttributesMask] { |
| 3718 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3719 | switch k { |
| 3720 | case "drop_events": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3721 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_DropEvents]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3722 | ethFrameExtPMData[k] = val.(uint64) |
| 3723 | receivedMask |= 0x2000 |
| 3724 | } else if !ok { |
| 3725 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3726 | } |
| 3727 | case "octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3728 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3729 | ethFrameExtPMData[k] = val.(uint64) |
| 3730 | receivedMask |= 0x1000 |
| 3731 | } else if !ok { |
| 3732 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3733 | } |
| 3734 | case "frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3735 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3736 | ethFrameExtPMData[k] = val.(uint64) |
| 3737 | receivedMask |= 0x800 |
| 3738 | } else if !ok { |
| 3739 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3740 | } |
| 3741 | } |
| 3742 | } |
| 3743 | } |
| 3744 | case 0x0700: |
| 3745 | for _, k := range maskToEthernetFrameExtendedPM64Bit[requestedAttributesMask] { |
| 3746 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3747 | switch k { |
| 3748 | case "broadcast_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3749 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_BroadcastFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3750 | ethFrameExtPMData[k] = val.(uint64) |
| 3751 | receivedMask |= 0x400 |
| 3752 | } else if !ok { |
| 3753 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3754 | } |
| 3755 | case "multicast_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3756 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_MulticastFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3757 | ethFrameExtPMData[k] = val.(uint64) |
| 3758 | receivedMask |= 0x200 |
| 3759 | } else if !ok { |
| 3760 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3761 | } |
| 3762 | case "crc_errored_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3763 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_CrcErroredFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3764 | ethFrameExtPMData[k] = val.(uint64) |
| 3765 | receivedMask |= 0x100 |
| 3766 | } else if !ok { |
| 3767 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3768 | } |
| 3769 | } |
| 3770 | } |
| 3771 | } |
| 3772 | case 0x00E0: |
| 3773 | for _, k := range maskToEthernetFrameExtendedPM64Bit[requestedAttributesMask] { |
| 3774 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3775 | switch k { |
| 3776 | case "undersize_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3777 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_UndersizeFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3778 | ethFrameExtPMData[k] = val.(uint64) |
| 3779 | receivedMask |= 0x80 |
| 3780 | } else if !ok { |
| 3781 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3782 | } |
| 3783 | case "oversize_frames": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3784 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_OversizeFrames]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3785 | ethFrameExtPMData[k] = val.(uint64) |
| 3786 | receivedMask |= 0x40 |
| 3787 | } else if !ok { |
| 3788 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3789 | } |
| 3790 | case "64_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3791 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames64Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3792 | ethFrameExtPMData[k] = val.(uint64) |
| 3793 | receivedMask |= 0x20 |
| 3794 | } else if !ok { |
| 3795 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3796 | } |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | case 0x001C: |
| 3801 | for _, k := range maskToEthernetFrameExtendedPM64Bit[requestedAttributesMask] { |
| 3802 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3803 | switch k { |
| 3804 | case "65_to_127_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3805 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames65To127Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3806 | ethFrameExtPMData[k] = val.(uint64) |
| 3807 | receivedMask |= 0x10 |
| 3808 | } else if !ok { |
| 3809 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3810 | } |
| 3811 | case "128_to_255_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3812 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames128To255Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3813 | ethFrameExtPMData[k] = val.(uint64) |
| 3814 | receivedMask |= 0x8 |
| 3815 | } else if !ok { |
| 3816 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3817 | } |
| 3818 | case "256_to_511_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3819 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames256To511Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3820 | ethFrameExtPMData[k] = val.(uint64) |
| 3821 | receivedMask |= 0x4 |
| 3822 | } else if !ok { |
| 3823 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3824 | } |
| 3825 | default: |
| 3826 | //do nothing |
| 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | case 0x0003: |
| 3831 | for _, k := range maskToEthernetFrameExtendedPM64Bit[requestedAttributesMask] { |
| 3832 | if _, ok := ethFrameExtPMData[k]; !ok { |
| 3833 | switch k { |
| 3834 | case "512_to_1023_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3835 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames512To1023Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3836 | ethFrameExtPMData[k] = val.(uint64) |
| 3837 | receivedMask |= 0x2 |
| 3838 | } else if !ok { |
| 3839 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3840 | } |
| 3841 | case "1024_to_1518_octets": |
Holger Hildebrandt | 3ac49bd | 2022-02-07 17:46:43 +0000 | [diff] [blame] | 3842 | if val, ok := meAttributes[me.EthernetFrameExtendedPm64Bit_Frames1024To1518Octets]; ok && val != nil { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3843 | ethFrameExtPMData[k] = val.(uint64) |
| 3844 | receivedMask |= 0x1 |
| 3845 | } else if !ok { |
| 3846 | ethFrameExtPMData[k] = UnsupportedCounterValue64bit |
| 3847 | } |
| 3848 | default: |
| 3849 | //do nothing |
| 3850 | } |
| 3851 | } |
| 3852 | } |
| 3853 | } |
| 3854 | return receivedMask |
| 3855 | } |
| 3856 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3857 | func (mm *OnuMetricsManager) aggregateEthernetFrameExtendedPM(pmDataIn map[string]uint64, |
| 3858 | pmData extension.OmciEthernetFrameExtendedPm, aggregate bool) extension.OmciEthernetFrameExtendedPm { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3859 | errorCounterValue := UnsupportedCounterValue64bit |
| 3860 | if mm.supportedEthernetFrameExtendedPMClass == me.EthernetFrameExtendedPmClassID { |
| 3861 | errorCounterValue = UnsupportedCounterValue32bit |
| 3862 | } |
| 3863 | var pmDataOut extension.OmciEthernetFrameExtendedPm |
| 3864 | if aggregate { |
| 3865 | if pmData.DropEvents != errorCounterValue { |
| 3866 | pmDataOut.DropEvents = pmData.DropEvents + pmDataIn["drop_events"] |
| 3867 | } else { |
| 3868 | pmDataOut.DropEvents = pmData.DropEvents |
| 3869 | } |
| 3870 | if pmData.Octets != errorCounterValue { |
| 3871 | pmDataOut.Octets = pmData.Octets + pmDataIn["octets"] |
| 3872 | } else { |
| 3873 | pmDataOut.Octets = pmData.Octets |
| 3874 | } |
| 3875 | if pmData.Frames != errorCounterValue { |
| 3876 | pmDataOut.Frames = pmData.Frames + pmDataIn["frames"] |
| 3877 | } else { |
| 3878 | pmDataOut.Frames = pmData.Frames |
| 3879 | } |
| 3880 | if pmData.BroadcastFrames != errorCounterValue { |
| 3881 | pmDataOut.BroadcastFrames = pmData.BroadcastFrames + pmDataIn["broadcast_frames"] |
| 3882 | } else { |
| 3883 | pmDataOut.BroadcastFrames = pmData.BroadcastFrames |
| 3884 | } |
| 3885 | if pmData.MulticastFrames != errorCounterValue { |
| 3886 | pmDataOut.MulticastFrames = pmData.MulticastFrames + pmDataIn["multicast_frames"] |
| 3887 | } else { |
| 3888 | pmDataOut.MulticastFrames = pmData.MulticastFrames |
| 3889 | } |
| 3890 | if pmData.CrcErroredFrames != errorCounterValue { |
| 3891 | pmDataOut.CrcErroredFrames = pmData.CrcErroredFrames + pmDataIn["crc_errored_frames"] |
| 3892 | } else { |
| 3893 | pmDataOut.CrcErroredFrames = pmData.CrcErroredFrames |
| 3894 | } |
| 3895 | if pmData.UndersizeFrames != errorCounterValue { |
| 3896 | pmDataOut.UndersizeFrames = pmData.UndersizeFrames + pmDataIn["undersize_frames"] |
| 3897 | } else { |
| 3898 | pmDataOut.UndersizeFrames = pmData.UndersizeFrames |
| 3899 | } |
| 3900 | if pmData.OversizeFrames != errorCounterValue { |
| 3901 | pmDataOut.OversizeFrames = pmData.OversizeFrames + pmDataIn["oversize_frames"] |
| 3902 | } else { |
| 3903 | pmDataOut.OversizeFrames = pmData.OversizeFrames |
| 3904 | } |
| 3905 | if pmData.Frames_64Octets != errorCounterValue { |
| 3906 | pmDataOut.Frames_64Octets = pmData.Frames_64Octets + pmDataIn["64_octets"] |
| 3907 | } else { |
| 3908 | pmDataOut.Frames_64Octets = pmData.Frames_64Octets |
| 3909 | } |
| 3910 | if pmData.Frames_65To_127Octets != errorCounterValue { |
| 3911 | pmDataOut.Frames_65To_127Octets = pmData.Frames_65To_127Octets + pmDataIn["65_to_127_octets"] |
| 3912 | } else { |
| 3913 | pmDataOut.Frames_65To_127Octets = pmData.Frames_65To_127Octets |
| 3914 | } |
| 3915 | if pmData.Frames_128To_255Octets != errorCounterValue { |
| 3916 | pmDataOut.Frames_128To_255Octets = pmData.Frames_128To_255Octets + pmDataIn["128_to_255_octets"] |
| 3917 | } else { |
| 3918 | pmDataOut.Frames_128To_255Octets = pmData.Frames_128To_255Octets |
| 3919 | } |
| 3920 | if pmData.Frames_256To_511Octets != errorCounterValue { |
| 3921 | pmDataOut.Frames_256To_511Octets = pmData.Frames_256To_511Octets + pmDataIn["256_to_511_octets"] |
| 3922 | } else { |
| 3923 | pmDataOut.Frames_256To_511Octets = pmData.Frames_256To_511Octets |
| 3924 | } |
| 3925 | if pmData.Frames_512To_1023Octets != errorCounterValue { |
| 3926 | pmDataOut.Frames_512To_1023Octets = pmData.Frames_512To_1023Octets + pmDataIn["512_to_1023_octets"] |
| 3927 | } else { |
| 3928 | pmDataOut.Frames_512To_1023Octets = pmData.Frames_512To_1023Octets |
| 3929 | } |
| 3930 | if pmData.Frames_1024To_1518Octets != errorCounterValue { |
| 3931 | pmDataOut.Frames_1024To_1518Octets = pmData.Frames_1024To_1518Octets + pmDataIn["1024_to_1518_octets"] |
| 3932 | } else { |
| 3933 | pmDataOut.Frames_1024To_1518Octets = pmData.Frames_1024To_1518Octets |
| 3934 | } |
| 3935 | } else { |
| 3936 | pmDataOut.DropEvents = pmDataIn["drop_events"] |
| 3937 | pmDataOut.Octets = pmDataIn["octets"] |
| 3938 | pmDataOut.Frames = pmDataIn["frames"] |
| 3939 | pmDataOut.BroadcastFrames = pmDataIn["broadcast_frames"] |
| 3940 | pmDataOut.MulticastFrames = pmDataIn["multicast_frames"] |
| 3941 | pmDataOut.CrcErroredFrames = pmDataIn["crc_errored_frames"] |
| 3942 | pmDataOut.UndersizeFrames = pmDataIn["undersize_frames"] |
| 3943 | pmDataOut.OversizeFrames = pmDataIn["oversize_frames"] |
| 3944 | pmDataOut.Frames_64Octets = pmDataIn["64_octets"] |
| 3945 | pmDataOut.Frames_65To_127Octets = pmDataIn["65_to_127_octets"] |
| 3946 | pmDataOut.Frames_128To_255Octets = pmDataIn["128_to_255_octets"] |
| 3947 | pmDataOut.Frames_256To_511Octets = pmDataIn["256_to_511_octets"] |
| 3948 | pmDataOut.Frames_512To_1023Octets = pmDataIn["512_to_1023_octets"] |
| 3949 | pmDataOut.Frames_1024To_1518Octets = pmDataIn["1024_to_1518_octets"] |
| 3950 | } |
| 3951 | return pmDataOut |
| 3952 | } |
| 3953 | |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3954 | func (mm *OnuMetricsManager) getControlBlockForExtendedPMDirection(ctx context.Context, upstream bool, entityID uint16, reset bool) []uint16 { |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3955 | controlBlock := make([]uint16, 8) |
| 3956 | // Control Block First two bytes are for threshold data 1/2 id - does not matter here |
| 3957 | controlBlock[0] = 0 |
| 3958 | // Next two bytes are for the parent class ID |
| 3959 | controlBlock[1] = (uint16)(me.PhysicalPathTerminationPointEthernetUniClassID) |
| 3960 | // Next two bytes are for the parent me instance id |
| 3961 | controlBlock[2] = entityID |
| 3962 | // Next two bytes are for accumulation disable |
Himani Chawla | ee10b54 | 2021-09-20 16:46:40 +0530 | [diff] [blame] | 3963 | if reset { |
| 3964 | controlBlock[3] = 1 << 15 //Set the 16th bit of AD to reset the counters. |
| 3965 | } else { |
| 3966 | controlBlock[3] = 0 |
| 3967 | } |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 3968 | // Next two bytes are for tca disable |
| 3969 | controlBlock[4] = 0x4000 //tca global disable |
| 3970 | // Next two bytes are for control fields - bit 1(lsb) as 1 for continuous accumulation and bit 2(0 for upstream) |
| 3971 | if upstream { |
| 3972 | controlBlock[5] = 1 << 0 |
| 3973 | } else { |
| 3974 | controlBlock[5] = (1 << 0) | (1 << 1) |
| 3975 | } |
| 3976 | // Next two bytes are for tci - does not matter here |
| 3977 | controlBlock[6] = 0 |
| 3978 | // Next two bytes are for reserved bits - does not matter here |
| 3979 | controlBlock[7] = 0 |
| 3980 | return controlBlock |
| 3981 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 3982 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 3983 | // GetdeviceDeletionInProgress gets the deviceDeletionInProgress flag |
| 3984 | func (mm *OnuMetricsManager) GetdeviceDeletionInProgress() bool { |
| 3985 | mm.OnuMetricsManagerLock.RLock() |
| 3986 | defer mm.OnuMetricsManagerLock.RUnlock() |
| 3987 | return mm.deviceDeletionInProgress |
| 3988 | } |
| 3989 | |
| 3990 | // SetdeviceDeletionInProgress sets the deviceDeletionInProgress flag |
| 3991 | func (mm *OnuMetricsManager) SetdeviceDeletionInProgress(deleted bool) { |
| 3992 | mm.OnuMetricsManagerLock.Lock() |
| 3993 | defer mm.OnuMetricsManagerLock.Unlock() |
| 3994 | mm.deviceDeletionInProgress = true |
| 3995 | } |
| 3996 | |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 3997 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 3998 | func (mm *OnuMetricsManager) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
Girish Gowdra | 8feabf8 | 2022-05-11 16:39:16 -0700 | [diff] [blame] | 3999 | currState := L2PmStNull |
| 4000 | if mm.PAdaptFsm != nil && mm.PAdaptFsm.PFsm != nil { |
| 4001 | currState = mm.PAdaptFsm.PFsm.Current() |
| 4002 | } |
| 4003 | if currState == L2PmStNull { |
| 4004 | logger.Infow(ctx, "pm fsm already stopped, safe to garbage collect", log.Fields{"device-id": mm.deviceID}) |
| 4005 | mm.pDeviceHandler = nil |
| 4006 | mm.pOnuDeviceEntry = nil |
| 4007 | mm.GarbageCollectionComplete <- true |
| 4008 | return |
| 4009 | } |
| 4010 | logger.Debugw(ctx, "prepare for garbage collection - no action, garbage collection done when PM FSM is stopped", |
| 4011 | log.Fields{"device-id": aDeviceID, "curr-fsm-state": currState}) |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 4012 | } |