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