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