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