Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 2 | * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 17 | // Package almgr provides the utilities for managing alarm notifications |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package almgr |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 24 | "reflect" |
| 25 | "sync" |
| 26 | "time" |
| 27 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [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/events/eventif" |
| 32 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 33 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 34 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | const ( |
| 39 | circuitPackClassID = me.CircuitPackClassID |
| 40 | physicalPathTerminationPointEthernetUniClassID = me.PhysicalPathTerminationPointEthernetUniClassID |
| 41 | onuGClassID = me.OnuGClassID |
| 42 | aniGClassID = me.AniGClassID |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 43 | defaultTimeoutDelay = 10 |
| 44 | alarmBitMapSizeBytes = 28 |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 45 | ) |
| 46 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 47 | // events of alarm sync FSM |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 48 | const ( |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 49 | AsEvStart = "AsEvStart" |
| 50 | AsEvStop = "AsEvStop" |
| 51 | AsEvAudit = "AsEvAudit" |
| 52 | AsEvSync = "AsEvSync" |
| 53 | AsEvSuccess = "AsEvSuccess" |
| 54 | AsEvFailure = "AsEvFailure" |
| 55 | AsEvResync = "AsEvResync" |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 56 | ) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 57 | |
| 58 | // states of alarm sync FSM |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 59 | const ( |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 60 | asStStarting = "asStStarting" |
| 61 | asStDisabled = "asStDisabled" |
| 62 | asStInSync = "asStInSync" |
| 63 | asStAuditing = "asStAuditing" |
| 64 | asStResynchronizing = "asStResynchronizing" |
| 65 | asStIdle = "asStIdle" |
| 66 | ) |
| 67 | |
| 68 | //const cAsFsmIdleState = asStIdle not using idle state currently |
| 69 | |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 70 | type alarmInfo struct { |
| 71 | classID me.ClassID |
| 72 | instanceID uint16 |
| 73 | alarmNo uint8 |
| 74 | } |
| 75 | |
| 76 | type alarms map[alarmInfo]struct{} |
| 77 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 78 | type meAlarmKey struct { |
| 79 | classID me.ClassID |
| 80 | instanceID uint16 |
| 81 | } |
| 82 | |
| 83 | type alarmBitMapDB map[meAlarmKey][alarmBitMapSizeBytes]byte |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 84 | |
| 85 | type onuDevice struct { |
| 86 | classID me.ClassID |
| 87 | alarmno uint8 |
| 88 | } |
| 89 | type onuDeviceEvent struct { |
| 90 | EventName string |
| 91 | EventCategory eventif.EventCategory |
| 92 | EventSubCategory eventif.EventSubCategory |
| 93 | EventDescription string |
| 94 | } |
| 95 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 96 | // OnuAlarmManager holds alarm manager related data |
| 97 | type OnuAlarmManager struct { |
| 98 | deviceID string |
| 99 | pDeviceHandler cmn.IdeviceHandler |
| 100 | pOnuDeviceEntry cmn.IonuDeviceEntry |
| 101 | eventProxy eventif.EventProxy |
| 102 | StopProcessingOmciMessages chan bool |
| 103 | eventChannel chan cmn.Message |
| 104 | onuAlarmManagerLock sync.RWMutex |
| 105 | processMessage bool |
| 106 | activeAlarms alarms |
| 107 | alarmBitMapDB alarmBitMapDB |
| 108 | onuEventsList map[onuDevice]onuDeviceEvent |
| 109 | lastAlarmSequence uint8 |
| 110 | AlarmSyncFsm *cmn.AdapterFsm |
| 111 | oltDbCopy alarmBitMapDB |
| 112 | onuDBCopy alarmBitMapDB |
| 113 | bufferedNotifications []*omci.AlarmNotificationMsg |
| 114 | alarmUploadSeqNo uint16 |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 115 | alarmUploadNoOfCmdsOrMEs uint16 |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 116 | StopAlarmAuditTimer chan struct{} |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 117 | isExtendedOmci bool |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 118 | AsyncAlarmsCommChan chan struct{} |
| 119 | isAsyncAlarmRequest bool |
| 120 | onuAlarmRequestLock sync.RWMutex |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // NewAlarmManager - TODO: add comment |
| 124 | func NewAlarmManager(ctx context.Context, dh cmn.IdeviceHandler, onuDev cmn.IonuDeviceEntry) *OnuAlarmManager { |
| 125 | var alarmManager OnuAlarmManager |
| 126 | alarmManager.deviceID = dh.GetDeviceID() |
| 127 | logger.Debugw(ctx, "init-alarm-manager", log.Fields{"device-id": alarmManager.deviceID}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 128 | alarmManager.pDeviceHandler = dh |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 129 | alarmManager.pOnuDeviceEntry = onuDev |
| 130 | alarmManager.eventProxy = dh.GetEventProxy() // Or event proxy should be on cluster address ?? |
| 131 | alarmManager.eventChannel = make(chan cmn.Message) |
| 132 | alarmManager.StopProcessingOmciMessages = make(chan bool) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 133 | alarmManager.processMessage = false |
| 134 | alarmManager.activeAlarms = make(map[alarmInfo]struct{}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 135 | alarmManager.alarmBitMapDB = make(map[meAlarmKey][alarmBitMapSizeBytes]byte) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 136 | alarmManager.StopAlarmAuditTimer = make(chan struct{}) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 137 | alarmManager.AsyncAlarmsCommChan = make(chan struct{}) |
| 138 | alarmManager.isAsyncAlarmRequest = false |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 139 | alarmManager.onuEventsList = map[onuDevice]onuDeviceEvent{ |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 140 | {classID: circuitPackClassID, alarmno: 0}: {EventName: "ONU_EQUIPMENT", |
| 141 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu equipment"}, |
| 142 | {classID: circuitPackClassID, alarmno: 2}: {EventName: "ONU_SELF_TEST_FAIL", |
| 143 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu self-test failure"}, |
| 144 | {classID: circuitPackClassID, alarmno: 3}: {EventName: "ONU_LASER_EOL", |
| 145 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu laser EOL"}, |
| 146 | {classID: circuitPackClassID, alarmno: 4}: {EventName: "ONU_TEMP_YELLOW", |
| 147 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu temperature yellow"}, |
| 148 | {classID: circuitPackClassID, alarmno: 5}: {EventName: "ONU_TEMP_RED", |
| 149 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu temperature red"}, |
| 150 | {classID: physicalPathTerminationPointEthernetUniClassID, alarmno: 0}: {EventName: "ONU_Ethernet_UNI", EventCategory: voltha.EventCategory_EQUIPMENT, |
| 151 | EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "LAN Loss Of Signal"}, |
| 152 | {classID: onuGClassID, alarmno: 0}: {EventName: "ONU_EQUIPMENT", |
| 153 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu equipment"}, |
| 154 | {classID: onuGClassID, alarmno: 6}: {EventName: "ONU_SELF_TEST_FAIL", |
| 155 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu self-test failure"}, |
| 156 | {classID: onuGClassID, alarmno: 7}: {EventName: "ONU_DYING_GASP", |
| 157 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu DYING_GASP"}, |
| 158 | {classID: onuGClassID, alarmno: 8}: {EventName: "ONU_TEMP_YELLOW", |
| 159 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu temperature yellow"}, |
| 160 | {classID: onuGClassID, alarmno: 9}: {EventName: "ONU_TEMP_RED", |
| 161 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu temperature red"}, |
| 162 | {classID: onuGClassID, alarmno: 10}: {EventName: "ONU_VOLTAGE_YELLOW", |
| 163 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu voltage yellow"}, |
| 164 | {classID: onuGClassID, alarmno: 11}: {EventName: "ONU_VOLTAGE_RED", |
| 165 | EventCategory: voltha.EventCategory_ENVIRONMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu voltage red"}, |
| 166 | {classID: aniGClassID, alarmno: 0}: {EventName: "ONU_LOW_RX_OPTICAL", |
| 167 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu low rx optical power"}, |
| 168 | {classID: aniGClassID, alarmno: 1}: {EventName: "ONU_HIGH_RX_OPTICAL", |
| 169 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu high rx optical power"}, |
Marcos Aurelio Carrero (Furukawa) | 935e5f6 | 2023-11-13 14:18:35 -0300 | [diff] [blame] | 170 | {classID: aniGClassID, alarmno: 2}: {EventName: "ONU_BIT_ERROR_BASED_SIGNAL_FAIL", |
| 171 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu bit error based signal fail"}, |
| 172 | {classID: aniGClassID, alarmno: 3}: {EventName: "ONU_BIT_ERROR_BASED_SIGNAL_DEGRADE", |
| 173 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu bit error based signal degrade"}, |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 174 | {classID: aniGClassID, alarmno: 4}: {EventName: "ONU_LOW_TX_OPTICAL", |
| 175 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu low tx optical power"}, |
| 176 | {classID: aniGClassID, alarmno: 5}: {EventName: "ONU_HIGH_TX_OPTICAL", |
| 177 | EventCategory: voltha.EventCategory_COMMUNICATION, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu high tx optical power"}, |
| 178 | {classID: aniGClassID, alarmno: 6}: {EventName: "ONU_LASER_BIAS_CURRENT", |
| 179 | EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu laser bias current"}, |
| 180 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 181 | alarmManager.AlarmSyncFsm = cmn.NewAdapterFsm("AlarmSync", alarmManager.deviceID, alarmManager.eventChannel) |
| 182 | alarmManager.AlarmSyncFsm.PFsm = fsm.NewFSM( |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 183 | asStDisabled, |
| 184 | fsm.Events{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 185 | {Name: AsEvStart, Src: []string{asStDisabled}, Dst: asStStarting}, |
| 186 | {Name: AsEvAudit, Src: []string{asStStarting, asStInSync}, Dst: asStAuditing}, |
| 187 | {Name: AsEvSync, Src: []string{asStStarting}, Dst: asStInSync}, |
| 188 | {Name: AsEvSuccess, Src: []string{asStAuditing, asStResynchronizing}, Dst: asStInSync}, |
| 189 | {Name: AsEvFailure, Src: []string{asStAuditing, asStResynchronizing}, Dst: asStAuditing}, |
| 190 | {Name: AsEvResync, Src: []string{asStAuditing}, Dst: asStResynchronizing}, |
| 191 | {Name: AsEvStop, Src: []string{asStDisabled, asStStarting, asStAuditing, asStInSync, asStIdle, asStResynchronizing}, Dst: asStDisabled}, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 192 | }, |
| 193 | fsm.Callbacks{ |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 194 | "enter_state": func(e *fsm.Event) { alarmManager.AlarmSyncFsm.LogFsmStateChange(ctx, e) }, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 195 | "enter_" + asStStarting: func(e *fsm.Event) { alarmManager.asFsmStarting(ctx, e) }, |
| 196 | "enter_" + asStAuditing: func(e *fsm.Event) { alarmManager.asFsmAuditing(ctx, e) }, |
| 197 | "enter_" + asStInSync: func(e *fsm.Event) { alarmManager.asFsmInSync(ctx, e) }, |
| 198 | "enter_" + asStResynchronizing: func(e *fsm.Event) { alarmManager.asFsmResynchronizing(ctx, e) }, |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 199 | "leave_" + asStAuditing: func(e *fsm.Event) { alarmManager.asFsmLeaveAuditing(ctx, e) }, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 200 | }, |
| 201 | ) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 202 | return &alarmManager |
| 203 | } |
| 204 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 205 | func (am *OnuAlarmManager) asFsmStarting(ctx context.Context, e *fsm.Event) { |
| 206 | logger.Debugw(ctx, "alarm-sync-fsm-start-processing-msgs-in-state", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 207 | go am.processAlarmSyncMessages(ctx) |
| 208 | // Start the first audit, if audit interval configured, else reach the sync state |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 209 | if am.pDeviceHandler.GetAlarmAuditInterval() > 0 { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 210 | select { |
| 211 | //Transition into auditing state, using a very shorter timeout delay here, hence it is the first audit |
| 212 | case <-time.After(defaultTimeoutDelay * time.Second): |
| 213 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 214 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvAudit); err != nil { |
| 215 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-auditing", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 216 | } |
| 217 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 218 | case <-am.StopAlarmAuditTimer: |
| 219 | logger.Infow(ctx, "stopping-alarm-timer", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 220 | return |
| 221 | } |
| 222 | } else { |
| 223 | // Transition into sync state directly. |
| 224 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 225 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvSync); err != nil { |
| 226 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-sync", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 227 | } |
| 228 | }() |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 229 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 230 | } |
| 231 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 232 | func (am *OnuAlarmManager) asFsmAuditing(ctx context.Context, e *fsm.Event) { |
| 233 | logger.Debugw(ctx, "alarm-sync-fsm-start-auditing", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 234 | // Always reset the buffered notifications and db copies before starting the audit |
| 235 | am.onuAlarmManagerLock.Lock() |
| 236 | am.bufferedNotifications = make([]*omci.AlarmNotificationMsg, 0) |
| 237 | am.oltDbCopy = make(map[meAlarmKey][alarmBitMapSizeBytes]byte) |
| 238 | am.onuDBCopy = make(map[meAlarmKey][alarmBitMapSizeBytes]byte) |
| 239 | am.onuAlarmManagerLock.Unlock() |
| 240 | failureTransition := func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 241 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvFailure); err != nil { |
| 242 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-failure", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 243 | } |
| 244 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 245 | if err := am.pOnuDeviceEntry.GetDevOmciCC().SendGetAllAlarm(log.WithSpanFromContext(context.TODO(), ctx), 0, |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 246 | am.pDeviceHandler.GetOmciTimeout(), true, am.isExtendedOmci); err != nil { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 247 | // Transition to failure so that alarm sync can be restarted again |
| 248 | go failureTransition() |
| 249 | } |
| 250 | } |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 251 | func (am *OnuAlarmManager) asFsmLeaveAuditing(ctx context.Context, e *fsm.Event) { |
| 252 | logger.Debugw(ctx, "alarm-sync-fsm-leave-auditing state", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
| 253 | if am.isAsyncAlarmRequest { |
| 254 | logger.Errorw(ctx, "alarm-sync-fsm-leave-auditing state process the updated ONU alarms ", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
| 255 | am.AsyncAlarmsCommChan <- struct{}{} |
| 256 | am.isAsyncAlarmRequest = false |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 257 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 258 | } |
| 259 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 260 | func (am *OnuAlarmManager) asFsmResynchronizing(ctx context.Context, e *fsm.Event) { |
| 261 | logger.Debugw(ctx, "alarm-sync-fsm", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 262 | failureTransition := func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 263 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvFailure); err != nil { |
| 264 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-failure", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | // See if there is any onu only diff, meaning the class and entity is only in onu DB |
| 268 | for alarm := range am.onuDBCopy { |
| 269 | if _, exists := am.oltDbCopy[meAlarmKey{ |
| 270 | classID: alarm.classID, |
| 271 | instanceID: alarm.instanceID, |
| 272 | }]; !exists { |
| 273 | // We need to raise all such alarms as OLT wont have received notification for these alarms |
| 274 | omciAlarmMessage := &omci.AlarmNotificationMsg{ |
| 275 | MeBasePacket: omci.MeBasePacket{ |
| 276 | EntityClass: alarm.classID, |
| 277 | EntityInstance: alarm.instanceID, |
| 278 | }, |
| 279 | AlarmBitmap: am.onuDBCopy[alarm], |
| 280 | } |
| 281 | if err := am.processAlarmData(ctx, omciAlarmMessage); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 282 | logger.Errorw(ctx, "unable-to-process-alarm-notification", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 283 | // Transition to failure. |
| 284 | go failureTransition() |
| 285 | return |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | // See if there is any olt only diff, meaning the class and entity is only in olt DB |
| 290 | for alarm := range am.oltDbCopy { |
| 291 | if _, exists := am.onuDBCopy[meAlarmKey{ |
| 292 | classID: alarm.classID, |
| 293 | instanceID: alarm.instanceID, |
| 294 | }]; !exists { |
| 295 | // We need to clear all such alarms as OLT might have stale data and the alarms are already cleared. |
| 296 | omciAlarmMessage := &omci.AlarmNotificationMsg{ |
| 297 | MeBasePacket: omci.MeBasePacket{ |
| 298 | EntityClass: alarm.classID, |
| 299 | EntityInstance: alarm.instanceID, |
| 300 | }, |
| 301 | AlarmBitmap: am.oltDbCopy[alarm], |
| 302 | } |
| 303 | if err := am.processAlarmData(ctx, omciAlarmMessage); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 304 | logger.Errorw(ctx, "unable-to-process-alarm-notification", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 305 | // Transition to failure |
| 306 | go failureTransition() |
| 307 | return |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | // See if there is any attribute difference |
| 312 | for alarm := range am.onuDBCopy { |
| 313 | if _, exists := am.oltDbCopy[alarm]; exists { |
| 314 | if am.onuDBCopy[alarm] != am.oltDbCopy[alarm] { |
| 315 | omciAlarmMessage := &omci.AlarmNotificationMsg{ |
| 316 | MeBasePacket: omci.MeBasePacket{ |
| 317 | EntityClass: alarm.classID, |
| 318 | EntityInstance: alarm.instanceID, |
| 319 | }, |
| 320 | AlarmBitmap: am.onuDBCopy[alarm], |
| 321 | } |
| 322 | // We will assume that onudb is correct always in this case and process the changed bitmap. |
| 323 | if err := am.processAlarmData(ctx, omciAlarmMessage); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 324 | logger.Errorw(ctx, "unable-to-process-alarm-notification", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 325 | // Transition to failure |
| 326 | go failureTransition() |
| 327 | return |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | // Send the buffered notifications if no failure. |
| 333 | for _, notif := range am.bufferedNotifications { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 334 | logger.Debugw(ctx, "processing-buffered-alarm-notification", log.Fields{"device-id": am.deviceID, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 335 | "notification": notif}) |
| 336 | if err := am.processAlarmData(ctx, notif); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 337 | logger.Errorw(ctx, "unable-to-process-alarm-notification", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 338 | go failureTransition() |
| 339 | } |
| 340 | } |
| 341 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 342 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvSuccess); err != nil { |
| 343 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-sync", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 344 | } |
| 345 | }() |
| 346 | } |
| 347 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 348 | func (am *OnuAlarmManager) asFsmInSync(ctx context.Context, e *fsm.Event) { |
| 349 | logger.Debugw(ctx, "alarm-sync-fsm", log.Fields{"state": e.FSM.Current(), "device-id": am.deviceID}) |
| 350 | if am.pDeviceHandler.GetAlarmAuditInterval() > 0 { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 351 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 352 | case <-time.After(am.pDeviceHandler.GetAlarmAuditInterval()): |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 353 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 354 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvAudit); err != nil { |
| 355 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-auditing", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 356 | } |
| 357 | }() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 358 | case <-am.StopAlarmAuditTimer: |
| 359 | logger.Infow(ctx, "stopping-alarm-timer", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 360 | return |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 361 | |
| 362 | case <-am.AsyncAlarmsCommChan: |
| 363 | go func() { |
| 364 | logger.Debugw(ctx, "On demand Auditing the ONU for Alarms ", log.Fields{"device-id": am.deviceID}) |
| 365 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvAudit); err != nil { |
| 366 | logger.Errorw(ctx, "alarm-sync-fsm-cannot-go-to-state-auditing, use current snapshot of alarms", log.Fields{"device-id": am.deviceID, "err": err}) |
| 367 | am.isAsyncAlarmRequest = false |
| 368 | am.AsyncAlarmsCommChan <- struct{}{} |
| 369 | } |
| 370 | }() |
| 371 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 376 | func (am *OnuAlarmManager) processAlarmSyncMessages(ctx context.Context) { |
| 377 | logger.Debugw(ctx, "start-routine-to-process-omci-messages-for-alarm-sync", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 378 | for { |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 379 | select { |
| 380 | case message, ok := <-am.eventChannel: |
| 381 | if !ok { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 382 | logger.Info(ctx, "alarm-sync-omci-message-could-not-be-read-from-channel", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 383 | continue |
| 384 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 385 | logger.Debugw(ctx, "alarm-sync-omci-message-received", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 386 | |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 387 | switch message.Type { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 388 | case cmn.OMCI: |
| 389 | msg, _ := message.Data.(cmn.OmciMessage) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 390 | am.handleOmciMessage(ctx, msg) |
| 391 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 392 | logger.Warn(ctx, "alarm-sync-unknown-message-type-received", log.Fields{"device-id": am.deviceID, "message.Type": message.Type}) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 393 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 394 | case <-am.StopProcessingOmciMessages: |
| 395 | logger.Infow(ctx, "alarm-manager-stop-omci-alarm-message-processing-routines", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 396 | am.onuAlarmManagerLock.Lock() |
| 397 | am.processMessage = false |
| 398 | am.activeAlarms = nil |
| 399 | am.alarmBitMapDB = nil |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 400 | am.alarmUploadNoOfCmdsOrMEs = 0 |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 401 | am.alarmUploadSeqNo = 0 |
| 402 | am.onuAlarmManagerLock.Unlock() |
| 403 | return |
| 404 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 405 | } |
| 406 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 407 | } |
| 408 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 409 | func (am *OnuAlarmManager) handleOmciMessage(ctx context.Context, msg cmn.OmciMessage) { |
| 410 | logger.Debugw(ctx, "alarm-sync-omci-message-received", log.Fields{"device-id": am.deviceID, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 411 | "msg-type": msg.OmciMsg.MessageType, "msg": msg}) |
| 412 | switch msg.OmciMsg.MessageType { |
| 413 | case omci.GetAllAlarmsResponseType: |
| 414 | am.handleOmciGetAllAlarmsResponseMessage(ctx, msg) |
| 415 | case omci.GetAllAlarmsNextResponseType: |
| 416 | am.handleOmciGetAllAlarmNextResponseMessage(ctx, msg) |
| 417 | default: |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 418 | logger.Warnw(ctx, "unknown-message-type", log.Fields{"device-id": am.deviceID, "msg-type": msg.OmciMsg.MessageType}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 419 | |
| 420 | } |
| 421 | } |
| 422 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 423 | func (am *OnuAlarmManager) handleOmciGetAllAlarmsResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 424 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetAllAlarmsResponse) |
| 425 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 426 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-detected", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 427 | return |
| 428 | } |
| 429 | msgObj, msgOk := msgLayer.(*omci.GetAllAlarmsResponse) |
| 430 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 431 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-assigned", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 432 | return |
| 433 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 434 | logger.Debugw(ctx, "get-all-alarm-response-data", log.Fields{"device-id": am.deviceID, "data-fields": msgObj}) |
| 435 | if am.AlarmSyncFsm.PFsm.Is(asStDisabled) { |
| 436 | logger.Debugw(ctx, "alarm-sync-fsm-is-disabled-ignoring-response-message", log.Fields{"device-id": am.deviceID, "data-fields": msgObj}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 437 | return |
| 438 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 439 | am.onuAlarmManagerLock.Lock() |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 440 | am.alarmUploadNoOfCmdsOrMEs = msgObj.NumberOfCommands |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 441 | am.onuAlarmManagerLock.Unlock() |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 442 | failureTransition := func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 443 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvFailure); err != nil { |
| 444 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-failure", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 445 | } |
| 446 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 447 | am.onuAlarmManagerLock.Lock() |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 448 | if am.alarmUploadSeqNo < am.alarmUploadNoOfCmdsOrMEs { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 449 | // Reset Onu Alarm Sequence |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 450 | am.resetAlarmSequence() |
| 451 | // Get a copy of the alarm bit map db. |
| 452 | for alarms, bitmap := range am.alarmBitMapDB { |
| 453 | am.oltDbCopy[alarms] = bitmap |
| 454 | } |
| 455 | am.onuAlarmManagerLock.Unlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 456 | if err := am.pOnuDeviceEntry.GetDevOmciCC().SendGetAllAlarmNext( |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 457 | log.WithSpanFromContext(context.TODO(), ctx), am.pDeviceHandler.GetOmciTimeout(), true, am.isExtendedOmci); err != nil { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 458 | // Transition to failure |
| 459 | go failureTransition() |
| 460 | } |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 461 | } else if am.alarmUploadNoOfCmdsOrMEs == 0 { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 462 | // Reset Onu Alarm Sequence |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 463 | am.resetAlarmSequence() |
| 464 | // Get a copy of the alarm bit map db. |
| 465 | for alarms, bitmap := range am.alarmBitMapDB { |
| 466 | am.oltDbCopy[alarms] = bitmap |
| 467 | } |
| 468 | am.onuAlarmManagerLock.Unlock() |
| 469 | if am.isAlarmDBDiffPresent(ctx) { |
| 470 | // transition to resync state |
| 471 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 472 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvResync); err != nil { |
| 473 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-resynchronizing", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 474 | } |
| 475 | }() |
| 476 | } else { |
| 477 | // Transition to sync state |
| 478 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 479 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvSuccess); err != nil { |
| 480 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-sync", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 481 | } |
| 482 | }() |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 483 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 484 | } |
| 485 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 486 | logger.Errorw(ctx, "invalid-number-of-commands-received", log.Fields{"device-id": am.deviceID, |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 487 | "upload-no-of-cmds": am.alarmUploadNoOfCmdsOrMEs, "upload-seq-no": am.alarmUploadSeqNo}) |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 488 | am.onuAlarmManagerLock.Unlock() |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 489 | go failureTransition() |
| 490 | } |
| 491 | } |
| 492 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 493 | func (am *OnuAlarmManager) handleOmciGetAllAlarmNextResponseMessage(ctx context.Context, msg cmn.OmciMessage) { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 494 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeGetAllAlarmsNextResponse) |
| 495 | |
| 496 | if msgLayer == nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 497 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-detected", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 498 | return |
| 499 | } |
| 500 | msgObj, msgOk := msgLayer.(*omci.GetAllAlarmsNextResponse) |
| 501 | if !msgOk { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 502 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-assigned", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 503 | return |
| 504 | } |
| 505 | logger.Debugw(ctx, "get-all-alarms-next-response-data", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 506 | log.Fields{"device-id": am.deviceID, "data-fields": msgObj}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 507 | meClassID := msgObj.AlarmEntityClass |
| 508 | meEntityID := msgObj.AlarmEntityInstance |
| 509 | meAlarmBitMap := msgObj.AlarmBitMap |
| 510 | |
| 511 | am.onuAlarmManagerLock.Lock() |
| 512 | am.onuDBCopy[meAlarmKey{ |
| 513 | classID: meClassID, |
| 514 | instanceID: meEntityID, |
| 515 | }] = meAlarmBitMap |
| 516 | am.onuAlarmManagerLock.Unlock() |
| 517 | failureTransition := func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 518 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvFailure); err != nil { |
| 519 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-failure", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 520 | } |
| 521 | } |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 522 | if msg.OmciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 523 | logger.Debugw(ctx, "get-all-alarms-next-response-additional-data", |
| 524 | log.Fields{"device-id": am.deviceID, "additional-data": msgObj.AdditionalAlarms}) |
| 525 | |
| 526 | for _, additionalAlarmReport := range msgObj.AdditionalAlarms { |
| 527 | meClassID := additionalAlarmReport.AlarmEntityClass |
| 528 | meEntityID := additionalAlarmReport.AlarmEntityInstance |
| 529 | meAlarmBitMap := additionalAlarmReport.AlarmBitMap |
| 530 | |
| 531 | am.onuAlarmManagerLock.Lock() |
| 532 | am.onuDBCopy[meAlarmKey{ |
| 533 | classID: meClassID, |
| 534 | instanceID: meEntityID, |
| 535 | }] = meAlarmBitMap |
| 536 | am.onuAlarmManagerLock.Unlock() |
| 537 | |
| 538 | am.IncrementAlarmUploadSeqNo() |
| 539 | } |
| 540 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 541 | am.onuAlarmManagerLock.RLock() |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 542 | if am.alarmUploadSeqNo < am.alarmUploadNoOfCmdsOrMEs { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 543 | am.onuAlarmManagerLock.RUnlock() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 544 | if err := am.pOnuDeviceEntry.GetDevOmciCC().SendGetAllAlarmNext( |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 545 | log.WithSpanFromContext(context.TODO(), ctx), am.pDeviceHandler.GetOmciTimeout(), true, am.isExtendedOmci); err != nil { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 546 | // Transition to failure |
| 547 | go failureTransition() |
| 548 | } //TODO: needs to handle timeouts |
| 549 | } else { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 550 | am.onuAlarmManagerLock.RUnlock() |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 551 | if am.isAlarmDBDiffPresent(ctx) { |
| 552 | // transition to resync state |
| 553 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 554 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvResync); err != nil { |
| 555 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-resynchronizing", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 556 | } |
| 557 | }() |
| 558 | } else { |
| 559 | // Transition to sync state |
| 560 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 561 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvSuccess); err != nil { |
| 562 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-sync", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 563 | } |
| 564 | }() |
| 565 | } |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 566 | |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 567 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 568 | } |
| 569 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 570 | // StartOMCIAlarmMessageProcessing - TODO: add comment: add comment |
| 571 | func (am *OnuAlarmManager) StartOMCIAlarmMessageProcessing(ctx context.Context) { |
| 572 | logger.Infow(ctx, "alarm-manager-start-omci-alarm-message-processing-routines", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 573 | am.onuAlarmManagerLock.Lock() |
| 574 | am.processMessage = true |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 575 | if am.activeAlarms == nil { |
| 576 | am.activeAlarms = make(map[alarmInfo]struct{}) |
| 577 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 578 | am.alarmBitMapDB = make(map[meAlarmKey][alarmBitMapSizeBytes]byte) |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 579 | // when instantiating alarm manager it was too early, but now we can check for ONU's extended OMCI support |
| 580 | am.isExtendedOmci = am.pOnuDeviceEntry.GetPersIsExtOmciSupported() |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 581 | am.onuAlarmManagerLock.Unlock() |
Himani Chawla | 1472c68 | 2021-03-17 17:11:14 +0530 | [diff] [blame] | 582 | am.flushAlarmSyncChannels(ctx) // Need to do this first as there might be stale data on the channels and the start state waits on same channels |
| 583 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 584 | if am.AlarmSyncFsm.PFsm.Is(asStDisabled) { |
| 585 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvStart); err != nil { |
| 586 | logger.Errorw(ctx, "alarm-sync-fsm-can-not-go-to-state-starting", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 587 | return |
| 588 | } |
| 589 | } else { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 590 | logger.Errorw(ctx, "wrong-state-of-alarm-sync-fsm-want-disabled", log.Fields{"state": string(am.AlarmSyncFsm.PFsm.Current()), |
| 591 | "device-id": am.deviceID}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 592 | return |
| 593 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 594 | logger.Debugw(ctx, "alarm-sync-fsm-started", log.Fields{"state": string(am.AlarmSyncFsm.PFsm.Current())}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 595 | } |
| 596 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 597 | // HandleOmciAlarmNotificationMessage - TODO: add comment |
| 598 | func (am *OnuAlarmManager) HandleOmciAlarmNotificationMessage(ctx context.Context, msg cmn.OmciMessage) { |
| 599 | logger.Debugw(ctx, "omci-alarm-notification-msg", log.Fields{"device-id": am.deviceID, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 600 | "msg-type": msg.OmciMsg.MessageType}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 601 | |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 602 | msgLayer := (*msg.OmciPacket).Layer(omci.LayerTypeAlarmNotification) |
| 603 | if msgLayer == nil { |
| 604 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-detected-for-alarm-notification", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 605 | log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 606 | return |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 607 | } |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 608 | msgObj, msgOk := msgLayer.(*omci.AlarmNotificationMsg) |
| 609 | if !msgOk { |
| 610 | logger.Errorw(ctx, "omci-msg-layer-could-not-be-assigned-for-alarm-notification", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 611 | log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 612 | return |
| 613 | } |
| 614 | //Alarm Notification decoding at omci lib validates that the me class ID supports the |
| 615 | // alarm notifications. |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 616 | logger.Debugw(ctx, "alarm-notification-data-received", log.Fields{"device-id": am.deviceID, "data-fields": msgObj}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 617 | if err := am.processAlarmData(ctx, msgObj); err != nil { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 618 | logger.Errorw(ctx, "unable-to-process-alarm-notification", log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 619 | } |
| 620 | |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 621 | } |
| 622 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 623 | func (am *OnuAlarmManager) processAlarmData(ctx context.Context, msg *omci.AlarmNotificationMsg) error { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 624 | classID := msg.EntityClass |
| 625 | sequenceNo := msg.AlarmSequenceNumber |
| 626 | meInstance := msg.EntityInstance |
| 627 | alarmBitmap := msg.AlarmBitmap |
| 628 | logger.Debugw(ctx, "processing-alarm-data", log.Fields{"class-id": classID, "instance-id": meInstance, |
| 629 | "alarmBitMap": alarmBitmap, "sequence-no": sequenceNo}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 630 | am.onuAlarmManagerLock.Lock() |
| 631 | defer am.onuAlarmManagerLock.Unlock() |
| 632 | if !am.processMessage { |
| 633 | logger.Warnw(ctx, "ignoring-alarm-notification-received-for-me-as-channel-for-processing-is-closed", |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 634 | log.Fields{"device-id": am.deviceID}) |
Himani Chawla | 7998aa9 | 2021-04-07 14:16:52 +0530 | [diff] [blame] | 635 | return fmt.Errorf("alarm-manager-is-in-stopped-state") |
| 636 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 637 | if _, present := am.pOnuDeviceEntry.GetOnuDB().MeDb[classID][meInstance]; !present { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 638 | logger.Errorw(ctx, "me-class-instance-not-present", |
| 639 | log.Fields{"class-id": classID, "instance-id": meInstance, "device-id": am.deviceID}) |
Himani Chawla | 4c1d4c7 | 2021-02-18 12:14:31 +0530 | [diff] [blame] | 640 | return fmt.Errorf("me-class-%d-instance-%d-not-present", classID, meInstance) |
| 641 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 642 | if sequenceNo > 0 { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 643 | if am.AlarmSyncFsm.PFsm.Is(asStAuditing) || am.AlarmSyncFsm.PFsm.Is(asStResynchronizing) { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 644 | am.bufferedNotifications = append(am.bufferedNotifications, msg) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 645 | logger.Debugw(ctx, "adding-notification-to-buffered-notification-list", log.Fields{"device-id": am.deviceID, |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 646 | "notification": msg}) |
| 647 | return nil |
Andrea Campanella | ce91529 | 2021-03-12 17:59:35 +0000 | [diff] [blame] | 648 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 649 | am.incrementAlarmSequence() |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 650 | if sequenceNo != am.lastAlarmSequence && am.pDeviceHandler.GetAlarmAuditInterval() > 0 { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 651 | // signal early audit, if no match(if we are reaching here it means that audit is not going on currently) |
| 652 | go func() { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 653 | if err := am.AlarmSyncFsm.PFsm.Event(AsEvAudit); err != nil { |
| 654 | logger.Debugw(ctx, "alarm-sync-fsm-cannot-go-to-state-auditing", log.Fields{"device-id": am.deviceID, "err": err}) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 655 | } |
| 656 | }() |
| 657 | } |
| 658 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 659 | entity, omciErr := me.LoadManagedEntityDefinition(classID, |
| 660 | me.ParamData{EntityID: meInstance}) |
| 661 | if omciErr.StatusCode() != me.Success { |
| 662 | //log error and return |
| 663 | logger.Error(ctx, "unable-to-get-managed-entity", log.Fields{"class-id": classID, "instance-id": meInstance}) |
| 664 | return fmt.Errorf("unable-to-get-managed-entity-class-%d-instance-%d", classID, meInstance) |
| 665 | } |
| 666 | meAlarmMap := entity.GetAlarmMap() |
| 667 | if meAlarmMap == nil { |
| 668 | logger.Error(ctx, "unable-to-get-managed-entity-alarm-map", log.Fields{"class-id": classID, "instance-id": meInstance}) |
| 669 | return fmt.Errorf("unable-to-get-managed-entity-alarm-map-%d-instance-%d", classID, meInstance) |
| 670 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 671 | |
| 672 | am.alarmBitMapDB[meAlarmKey{ |
| 673 | classID: classID, |
| 674 | instanceID: meInstance, |
| 675 | }] = alarmBitmap |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 676 | // Loop over the supported alarm list for this me |
| 677 | for alarmNo := range meAlarmMap { |
| 678 | // Check if alarmNo was previously active in the alarms, if yes clear it and remove it from active alarms |
| 679 | _, exists := am.activeAlarms[alarmInfo{ |
| 680 | classID: classID, |
| 681 | instanceID: meInstance, |
| 682 | alarmNo: alarmNo, |
| 683 | }] |
| 684 | if exists { |
| 685 | // Clear this alarm if It is cleared now, in that case IsAlarmClear would return true |
| 686 | cleared, err := msg.IsAlarmClear(alarmNo) |
| 687 | if err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 688 | logger.Warnw(ctx, "unable-to-find-out-alarm-is-cleared", log.Fields{"device-id": am.deviceID, |
| 689 | "class-id": classID, "instance-id": meInstance, "alarm-no": alarmNo}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 690 | return err |
| 691 | } |
| 692 | if cleared { |
| 693 | // Clear this alarm. |
| 694 | am.clearAlarm(ctx, classID, meInstance, alarmNo) |
| 695 | } |
| 696 | } else { |
| 697 | // If alarm entry was not present in the list of active alarms, we need to see if this alarm is now active |
| 698 | // or not, if yes then raise it. |
| 699 | raised, err := msg.IsAlarmActive(alarmNo) |
| 700 | if err != nil { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 701 | logger.Warnw(ctx, "unable-to-find-out-alarm-is-raised", log.Fields{"device-id": am.deviceID, |
| 702 | "class-id": classID, "instance-id": meInstance, "alarm-no": alarmNo}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 703 | return err |
| 704 | } |
| 705 | if raised { |
| 706 | am.raiseAlarm(ctx, classID, meInstance, alarmNo) |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | return nil |
| 711 | } |
| 712 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 713 | func (am *OnuAlarmManager) raiseAlarm(ctx context.Context, classID me.ClassID, instanceID uint16, alarm uint8) { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 714 | am.activeAlarms[alarmInfo{ |
| 715 | classID: classID, |
| 716 | instanceID: instanceID, |
| 717 | alarmNo: alarm, |
| 718 | }] = struct{}{} |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 719 | |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 720 | go am.sendAlarm(ctx, classID, instanceID, alarm, true) |
| 721 | } |
| 722 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 723 | func (am *OnuAlarmManager) clearAlarm(ctx context.Context, classID me.ClassID, instanceID uint16, alarm uint8) { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 724 | go am.sendAlarm(ctx, classID, instanceID, alarm, false) |
| 725 | delete(am.activeAlarms, alarmInfo{ |
| 726 | classID: classID, |
| 727 | instanceID: instanceID, |
| 728 | alarmNo: alarm, |
| 729 | }) |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 730 | key := meAlarmKey{ |
| 731 | classID: classID, |
| 732 | instanceID: instanceID, |
| 733 | } |
| 734 | if am.alarmBitMapDB[key] == [alarmBitMapSizeBytes]byte{0} { |
| 735 | delete(am.alarmBitMapDB, key) |
| 736 | } |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 737 | } |
| 738 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 739 | func (am *OnuAlarmManager) getIntfIDAlarm(ctx context.Context, classID me.ClassID, instanceID uint16) *uint32 { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 740 | var intfID *uint32 |
| 741 | if classID == circuitPackClassID || classID == physicalPathTerminationPointEthernetUniClassID { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 742 | for _, uniPort := range *am.pDeviceHandler.GetUniEntityMap() { |
| 743 | if uniPort.EntityID == instanceID { |
| 744 | intfID = &uniPort.PortNo |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 745 | return intfID |
| 746 | } |
| 747 | } |
| 748 | } else if classID == aniGClassID || classID == onuGClassID { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 749 | intfID = am.pDeviceHandler.GetPonPortNumber() |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 750 | return intfID |
| 751 | } else { |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 752 | logger.Warnw(ctx, "me-not-supported", log.Fields{"device-id": am.deviceID, "class-id": classID, "instance-id": instanceID}) |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 753 | } |
| 754 | return nil |
| 755 | } |
| 756 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 757 | func (am *OnuAlarmManager) sendAlarm(ctx context.Context, classID me.ClassID, instanceID uint16, alarm uint8, raised bool) { |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 758 | context := make(map[string]string) |
| 759 | intfID := am.getIntfIDAlarm(ctx, classID, instanceID) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 760 | onuID := am.deviceID |
| 761 | serialNo := am.pOnuDeviceEntry.GetPersSerialNumber() |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 762 | if intfID == nil { |
| 763 | logger.Warn(ctx, "intf-id-for-alarm-not-found", log.Fields{"alarm-no": alarm, "class-id": classID}) |
| 764 | return |
| 765 | } |
| 766 | context["onu-intf-id"] = fmt.Sprintf("%d", *intfID) |
| 767 | context["onu-id"] = onuID |
| 768 | context["onu-serial-number"] = serialNo |
| 769 | |
ozgecanetsia | 2f05ed3 | 2021-05-31 17:13:48 +0300 | [diff] [blame] | 770 | raisedTimestamp := time.Now().Unix() |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 771 | eventDetails, err := am.getDeviceEventData(ctx, classID, alarm) |
| 772 | if err != nil { |
| 773 | logger.Warn(ctx, "event-details-for-alarm-not-found", log.Fields{"alarm-no": alarm, "class-id": classID}) |
| 774 | return |
| 775 | } |
| 776 | suffixDesc := "Raised" |
Marcos Aurelio Carrero (Furukawa) | 935e5f6 | 2023-11-13 14:18:35 -0300 | [diff] [blame] | 777 | clearOrRaiseEvent := "RAISE_EVENT" |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 778 | if !raised { |
| 779 | suffixDesc = "Cleared" |
Marcos Aurelio Carrero (Furukawa) | 935e5f6 | 2023-11-13 14:18:35 -0300 | [diff] [blame] | 780 | clearOrRaiseEvent = "CLEAR_EVENT" |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 781 | } |
| 782 | deviceEvent := &voltha.DeviceEvent{ |
| 783 | ResourceId: onuID, |
Marcos Aurelio Carrero (Furukawa) | 935e5f6 | 2023-11-13 14:18:35 -0300 | [diff] [blame] | 784 | DeviceEventName: fmt.Sprintf("%s_%s", eventDetails.EventName, clearOrRaiseEvent), |
Himani Chawla | ac1f5ad | 2021-02-04 21:21:54 +0530 | [diff] [blame] | 785 | Description: fmt.Sprintf("%s Event - %s - %s", eventDetails.EventDescription, eventDetails.EventName, |
| 786 | suffixDesc), |
| 787 | Context: context, |
| 788 | } |
| 789 | _ = am.eventProxy.SendDeviceEvent(ctx, deviceEvent, eventDetails.EventCategory, eventDetails.EventSubCategory, |
| 790 | raisedTimestamp) |
| 791 | } |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 792 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 793 | func (am *OnuAlarmManager) isAlarmDBDiffPresent(ctx context.Context) bool { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 794 | return !reflect.DeepEqual(am.onuDBCopy, am.oltDbCopy) |
| 795 | } |
| 796 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 797 | func (am *OnuAlarmManager) incrementAlarmSequence() { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 798 | //alarm sequence number wraps from 255 to 1. |
| 799 | if am.lastAlarmSequence == 255 { |
| 800 | am.lastAlarmSequence = 1 |
| 801 | } else { |
| 802 | am.lastAlarmSequence++ |
| 803 | } |
| 804 | } |
| 805 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 806 | func (am *OnuAlarmManager) resetAlarmSequence() { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 807 | am.lastAlarmSequence = 0 |
| 808 | } |
| 809 | |
| 810 | // flushAlarmSyncChannels flushes all alarm sync channels to discard any previous response |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 811 | func (am *OnuAlarmManager) flushAlarmSyncChannels(ctx context.Context) { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 812 | // flush alarm sync channel |
| 813 | select { |
| 814 | case <-am.eventChannel: |
| 815 | logger.Debug(ctx, "flushed-alarm-sync-channel") |
| 816 | default: |
| 817 | } |
| 818 | select { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 819 | case <-am.StopAlarmAuditTimer: |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 820 | logger.Debug(ctx, "flushed-alarm-audit-timer-channel") |
| 821 | default: |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // getDeviceEventData returns the event data for a device |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 826 | func (am *OnuAlarmManager) getDeviceEventData(ctx context.Context, classID me.ClassID, alarmNo uint8) (onuDeviceEvent, error) { |
Himani Chawla | d3dac42 | 2021-03-13 02:31:31 +0530 | [diff] [blame] | 827 | if onuEventDetails, ok := am.onuEventsList[onuDevice{classID: classID, alarmno: alarmNo}]; ok { |
| 828 | return onuEventDetails, nil |
| 829 | } |
| 830 | return onuDeviceEvent{}, errors.New("onu Event Detail not found") |
| 831 | } |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 832 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 833 | // ResetAlarmUploadCounters resets alarm upload sequence number and number of commands |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 834 | func (am *OnuAlarmManager) ResetAlarmUploadCounters() { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 835 | am.onuAlarmManagerLock.Lock() |
| 836 | am.alarmUploadSeqNo = 0 |
Holger Hildebrandt | 3b29a8a | 2022-07-11 05:55:13 +0000 | [diff] [blame] | 837 | am.alarmUploadNoOfCmdsOrMEs = 0 |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 838 | am.onuAlarmManagerLock.Unlock() |
| 839 | } |
| 840 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 841 | // IncrementAlarmUploadSeqNo increments alarm upload sequence number |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 842 | func (am *OnuAlarmManager) IncrementAlarmUploadSeqNo() { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 843 | am.onuAlarmManagerLock.Lock() |
| 844 | am.alarmUploadSeqNo++ |
| 845 | am.onuAlarmManagerLock.Unlock() |
| 846 | } |
| 847 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 848 | // GetAlarmUploadSeqNo gets alarm upload sequence number |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 849 | func (am *OnuAlarmManager) GetAlarmUploadSeqNo() uint16 { |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 850 | am.onuAlarmManagerLock.RLock() |
| 851 | value := am.alarmUploadSeqNo |
| 852 | am.onuAlarmManagerLock.RUnlock() |
| 853 | return value |
| 854 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 855 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 856 | // GetAlarmMgrEventChannel gets alarm manager event channel |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 857 | func (am *OnuAlarmManager) GetAlarmMgrEventChannel() chan cmn.Message { |
| 858 | return am.eventChannel |
| 859 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 860 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 861 | // GetOnuActiveAlarms - Fetch the Active Alarms on demand |
| 862 | func (am *OnuAlarmManager) GetOnuActiveAlarms(ctx context.Context) *extension.SingleGetValueResponse { |
| 863 | |
| 864 | am.onuAlarmRequestLock.Lock() |
| 865 | defer am.onuAlarmRequestLock.Unlock() |
| 866 | |
| 867 | resp := extension.SingleGetValueResponse{ |
| 868 | Response: &extension.GetValueResponse{ |
| 869 | Status: extension.GetValueResponse_OK, |
| 870 | Response: &extension.GetValueResponse_OnuActiveAlarms{ |
| 871 | OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsResponse{}, |
| 872 | }, |
| 873 | }, |
| 874 | } |
| 875 | |
| 876 | logger.Debugw(ctx, "Requesting to start audit on demand ", log.Fields{"device-id": am.deviceID}) |
| 877 | am.isAsyncAlarmRequest = true |
| 878 | |
| 879 | am.AsyncAlarmsCommChan <- struct{}{} |
| 880 | |
| 881 | select { |
| 882 | case <-time.After(10 * time.Second): //the time to wait needs further discussion. |
| 883 | logger.Errorw(ctx, "Couldn't get the Alarms with in 10 seconds stipulated time frame ", log.Fields{"device-id": am.deviceID}) |
| 884 | am.isAsyncAlarmRequest = false |
| 885 | |
| 886 | case <-am.AsyncAlarmsCommChan: |
| 887 | logger.Debugw(ctx, "Received response for the alarm audit ", log.Fields{"device-id": am.deviceID}) |
| 888 | |
| 889 | } |
| 890 | |
| 891 | for activeAlarm := range am.activeAlarms { |
| 892 | |
| 893 | onuEventDetails := am.onuEventsList[onuDevice{classID: activeAlarm.classID, alarmno: activeAlarm.alarmNo}] |
| 894 | activeAlarmData := extension.AlarmData{} |
| 895 | activeAlarmData.ClassId = uint32(activeAlarm.classID) |
| 896 | activeAlarmData.InstanceId = uint32(activeAlarm.instanceID) |
| 897 | activeAlarmData.Name = onuEventDetails.EventName |
| 898 | activeAlarmData.Description = onuEventDetails.EventDescription |
| 899 | |
| 900 | resp.Response.GetOnuActiveAlarms().ActiveAlarms = append(resp.Response.GetOnuActiveAlarms().ActiveAlarms, &activeAlarmData) |
| 901 | |
| 902 | } |
| 903 | |
| 904 | return &resp |
| 905 | } |
| 906 | |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 907 | // PrepareForGarbageCollection - remove references to prepare for garbage collection |
| 908 | func (am *OnuAlarmManager) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) { |
| 909 | logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID}) |
| 910 | am.pDeviceHandler = nil |
| 911 | am.pOnuDeviceEntry = nil |
| 912 | } |