Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 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
|