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