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