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