VOL-3049 Final review comments addressed for alarm notifications
Change-Id: Id3fedd89c3b347e14719e597c6f7b93938567eee
diff --git a/internal/pkg/onuadaptercore/alarm_manager.go b/internal/pkg/onuadaptercore/alarm_manager.go
index dcf3a18..1efc819 100644
--- a/internal/pkg/onuadaptercore/alarm_manager.go
+++ b/internal/pkg/onuadaptercore/alarm_manager.go
@@ -54,6 +54,7 @@
onuAlarmManagerLock sync.RWMutex
processMessage bool
activeAlarms alarms
+ onuEventsList map[onuDevice]onuDeviceEvent
}
type onuDevice struct {
@@ -76,12 +77,7 @@
alarmManager.stopProcessingOmciMessages = make(chan bool)
alarmManager.processMessage = false
alarmManager.activeAlarms = make(map[alarmInfo]struct{})
- return &alarmManager
-}
-
-// getDeviceEventData returns the event data for a device
-func (am *onuAlarmManager) getDeviceEventData(ctx context.Context, classID me.ClassID, alarmNo uint8) (onuDeviceEvent, error) {
- onuEventsList := map[onuDevice]onuDeviceEvent{
+ alarmManager.onuEventsList = map[onuDevice]onuDeviceEvent{
{classID: circuitPackClassID, alarmno: 0}: {EventName: "ONU_EQUIPMENT",
EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu equipment"},
{classID: circuitPackClassID, alarmno: 2}: {EventName: "ONU_SELF_TEST_FAIL",
@@ -119,20 +115,28 @@
{classID: aniGClassID, alarmno: 6}: {EventName: "ONU_LASER_BIAS_CURRENT",
EventCategory: voltha.EventCategory_EQUIPMENT, EventSubCategory: voltha.EventSubCategory_ONU, EventDescription: "onu laser bias current"},
}
- if onuEventDetails, ok := onuEventsList[onuDevice{classID: classID, alarmno: alarmNo}]; ok {
+ return &alarmManager
+}
+
+// getDeviceEventData returns the event data for a device
+func (am *onuAlarmManager) getDeviceEventData(ctx context.Context, classID me.ClassID, alarmNo uint8) (onuDeviceEvent, error) {
+ if onuEventDetails, ok := am.onuEventsList[onuDevice{classID: classID, alarmno: alarmNo}]; ok {
return onuEventDetails, nil
}
return onuDeviceEvent{}, errors.New("onu Event Detail not found")
-
}
func (am *onuAlarmManager) startOMCIAlarmMessageProcessing(ctx context.Context) {
am.onuAlarmManagerLock.Lock()
am.processMessage = true
+ if am.activeAlarms == nil {
+ am.activeAlarms = make(map[alarmInfo]struct{})
+ }
am.onuAlarmManagerLock.Unlock()
if stop := <-am.stopProcessingOmciMessages; stop {
am.onuAlarmManagerLock.Lock()
am.processMessage = false
+ am.activeAlarms = nil
am.onuAlarmManagerLock.Unlock()
}
}
@@ -176,6 +180,10 @@
alarmBitmap := msg.AlarmBitmap
logger.Debugw(ctx, "processing-alarm-data", log.Fields{"class-id": classID, "instance-id": meInstance,
"alarmBitMap": alarmBitmap, "sequence-no": sequenceNo})
+ if _, present := am.pDeviceHandler.pOnuOmciDevice.pOnuDB.meDb[classID][meInstance]; !present {
+ logger.Errorw(ctx, "me-class-instance-not-present", log.Fields{"class-id": classID, "instance-id": meInstance})
+ return fmt.Errorf("me-class-%d-instance-%d-not-present", classID, meInstance)
+ }
/*
if sequenceNo > 0 {
// TODO Need Auditing if sequence no does not matches, after incrementing the last sequence no by 1
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index 91f9a8d..c452fe5 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -198,6 +198,8 @@
collectorIsRunning bool
mutexCollectorFlag sync.RWMutex
stopCollector chan bool
+ alarmManagerIsRunning bool
+ mutextAlarmManagerFlag sync.RWMutex
stopAlarmManager chan bool
stopHeartbeatCheck chan bool
uniEntityMap map[uint32]*onuUniPort
@@ -226,6 +228,7 @@
dh.deviceEntrySet = make(chan bool, 1)
dh.collectorIsRunning = false
dh.stopCollector = make(chan bool, 2)
+ dh.alarmManagerIsRunning = false
dh.stopAlarmManager = make(chan bool, 2)
dh.stopHeartbeatCheck = make(chan bool, 2)
//dh.metrics = pmmetrics.NewPmMetrics(cloned.Id, pmmetrics.Frequency(150), pmmetrics.FrequencyOverride(false), pmmetrics.Grouped(false), pmmetrics.Metrics(pmNames))
@@ -1465,7 +1468,9 @@
// Start PM collector routine
go dh.startCollector(ctx)
}
- go dh.startAlarmManager(ctx)
+ if !dh.getAlarmManagerIsRunning() {
+ go dh.startAlarmManager(ctx)
+ }
return nil
}
@@ -1591,7 +1596,10 @@
// Stop collector routine
dh.stopCollector <- true
}
- dh.stopAlarmManager <- true
+ if dh.getAlarmManagerIsRunning() {
+ dh.stopAlarmManager <- true
+ }
+
return nil
}
@@ -2857,6 +2865,9 @@
// Start PM collector routine
go dh.startCollector(ctx)
}
+ if !dh.getAlarmManagerIsRunning() {
+ go dh.startAlarmManager(ctx)
+ }
dh.uniEntityMap = make(map[uint32]*onuUniPort)
dh.startReconciling(ctx)
}
@@ -2874,14 +2885,30 @@
return flagValue
}
+func (dh *deviceHandler) setAlarmManagerIsRunning(flagValue bool) {
+ dh.mutextAlarmManagerFlag.Lock()
+ dh.alarmManagerIsRunning = flagValue
+ dh.mutextAlarmManagerFlag.Unlock()
+}
+
+func (dh *deviceHandler) getAlarmManagerIsRunning() bool {
+ dh.mutextAlarmManagerFlag.RLock()
+ flagValue := dh.alarmManagerIsRunning
+ dh.mutextAlarmManagerFlag.RUnlock()
+ return flagValue
+}
+
func (dh *deviceHandler) startAlarmManager(ctx context.Context) {
logger.Debugf(ctx, "startingAlarmManager")
// Start routine to process OMCI GET Responses
go dh.pAlarmMgr.startOMCIAlarmMessageProcessing(ctx)
+ dh.setAlarmManagerIsRunning(true)
if stop := <-dh.stopAlarmManager; stop {
logger.Debugw(ctx, "stopping-collector-for-onu", log.Fields{"device-id": dh.device.Id})
dh.pAlarmMgr.stopProcessingOmciMessages <- true // Stop the OMCI routines if any
+ dh.setAlarmManagerIsRunning(false)
+
}
}
func (dh *deviceHandler) startReconciling(ctx context.Context) {