blob: 8a583039ad9bf8ccd811d2443e4184e89760da64 [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
2 * Copyright 2018-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
Scott Bakerdbd960e2020-02-28 08:57:51 -080017// Package core provides APIs for the openOLT adapter
18package core
Devmalya Paulfb990a52019-07-09 10:01:49 -040019
20import (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Devmalya Paula1efa642020-04-20 01:36:43 -040022 "errors"
Devmalya Paulfb990a52019-07-09 10:01:49 -040023 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053024 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053025
Esin Karamanccb714b2019-11-29 15:02:06 +000026 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
27 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
kesavand39e0aa32020-01-28 20:58:50 -050029 "github.com/opencord/voltha-protos/v3/go/common"
Esin Karamanccb714b2019-11-29 15:02:06 +000030 oop "github.com/opencord/voltha-protos/v3/go/openolt"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040032)
33
34const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050035 onuDiscoveryEvent = "ONU_DISCOVERY"
36 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
37 onuLobEvent = "ONU_LOSS_OF_BURST"
38 onuLopcMissEvent = "ONU_LOPC_MISS"
39 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
40 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
41 oltIndicationDown = "OLT_DOWN_INDICATION"
42 onuDyingGaspEvent = "ONU_DYING_GASP"
43 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
44 onuStartupFailEvent = "ONU_STARTUP_FAIL"
45 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
46 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
47 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050048 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
49 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
50 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
51 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
52 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
53 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
54 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
55 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
56 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
57 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040058 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040059)
60
61const (
Naga Manjunath9546b912019-11-28 20:56:20 +053062 // statusCheckOn represents status check On
63 statusCheckOn = "on"
64 // statusCheckOff represents status check Off
65 statusCheckOff = "off"
66 // operationStateUp represents operation state Up
67 operationStateUp = "up"
68 // operationStateDown represents operation state Down
69 operationStateDown = "down"
70 // base10 represents base 10 conversion
71 base10 = 10
72)
73
Amit Ghosh502056b2020-07-15 09:15:48 +010074const (
75 // ContextOltOperState is for the operational state of the Olt in the context of the event
76 ContextOltOperState = "oper-state"
77 // ContextOnuOnuID is for the Onu Id in the context of the event
78 ContextOnuOnuID = "onu-id"
79 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
80 ContextOnuPonIntfID = "intf-id"
81 // ContextOnuSerialNumber is for the serial number of the ONU
82 ContextOnuSerialNumber = "serial-number"
83 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
84 ContextOnuDeviceID = "onu-device-id"
85 // ContextOltPonIntfID is for the PON interface Id on an OLT event
86 ContextOltPonIntfID = "intf-id"
87 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
88 ContextOnuFailureReaseon = "fail-reason"
89 // ContextOnuDrift is for the drift of an ONU in the context of an event
90 ContextOnuDrift = "drift"
91 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
92 ContextOnuNewEqd = "new-eqd"
93 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
94 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
95 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
96 ContextOltPonIntfOperState = "oper-state"
97 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
98 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
99 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
100 ContextOnuDelineationErrors = "delineation-errors"
101 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
102 ContextOnuDifferentialDistance = "differential-distance"
103)
104
Devmalya Paulfb990a52019-07-09 10:01:49 -0400105// OpenOltEventMgr struct contains
106type OpenOltEventMgr struct {
kdarapu381c6902019-07-31 18:23:16 +0530107 eventProxy adapterif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400108 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400109}
110
111// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
Devmalya Paul90ca3012019-09-02 21:55:45 -0400112func NewEventMgr(eventProxy adapterif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400113 var em OpenOltEventMgr
114 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400115 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400116 return &em
117}
118
119// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500120// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400121func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530122 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400123 switch alarmInd.Data.(type) {
124 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000125 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
126 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400127 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000128 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
129 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400130 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000131 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
132 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400133 case *oop.AlarmIndication_OnuActivationFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000134 logger.Debugw(ctx, "received-onu-activation-fail-indication ", log.Fields{"alarm-ind": alarmInd})
135 err = em.onuActivationFailIndication(ctx, alarmInd.GetOnuActivationFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400136 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000137 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
138 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400139 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000140 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
141 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400142 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000143 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
144 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400145 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000146 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
147 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530148 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000149 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
150 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400151 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000152 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
153 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530154 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000155 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
156 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530157 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
159 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500160 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500163 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500166 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500169 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400172 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
174 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400175 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530176 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400177 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530178 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400179 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530180 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400181}
182
Daniele Rossi051466a2019-07-26 13:39:37 +0000183// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000184func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000185 var de voltha.DeviceEvent
186 context := make(map[string]string)
187 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100188 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000189 /* Populating device event body */
190 de.Context = context
191 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530192 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000193 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530194 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000195 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
196 }
197 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400198 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000199 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000200 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000201 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530202 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000203}
204
Devmalya Paulfb990a52019-07-09 10:01:49 -0400205// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000206func (em *OpenOltEventMgr) OnuDiscoveryIndication(ctx context.Context, onuDisc *oop.OnuDiscIndication, oltDeviceID string, onuDeviceID string, OnuID uint32, serialNumber string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400207 var de voltha.DeviceEvent
208 context := make(map[string]string)
209 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100210 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
211 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
212 context[ContextOnuSerialNumber] = serialNumber
213 context[ContextOnuDeviceID] = onuDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400214 /* Populating device event body */
215 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100216 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400217 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
218 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400219 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530220 return olterrors.NewErrCommunication("send-onu-discovery-event",
221 log.Fields{
222 "serial-number": serialNumber,
223 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400224 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000225 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530226 log.Fields{
227 "serial-number": serialNumber,
228 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530229 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400230}
231
Neha Sharma96b7bf22020-06-15 10:37:32 +0000232func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530233 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400234 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530235 var alarmInd oop.OnuAlarmIndication
236 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
237
Devmalya Paulfb990a52019-07-09 10:01:49 -0400238 context := make(map[string]string)
239 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100240 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400241 /* Populating device event body */
242 de.Context = context
243 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530244 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400245 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530246
247 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
248 with "los_status: on" should be raised for each Onu connected to the PON
249 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
250 for all the ONU's connected to PON on receiving LoSIndication for PON */
251 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
252 if onuInCache.(*OnuDevice).intfID == ponIntdID {
253 alarmInd.IntfId = ponIntdID
254 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
255 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000256 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530257 }
258 return true
259 })
260 if err != nil {
261 /* Return if any error encountered while processing ONU LoS Event*/
262 return err
263 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400264 } else {
265 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
266 }
267 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400268 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530269 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400270 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000271 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530272 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400273}
274
Amit Ghosh502056b2020-07-15 09:15:48 +0100275func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
276 var serialNumber = ""
277 var onuDeviceID = ""
278 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530279 if onu, ok := em.handler.onus.Load(onu); ok {
280 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100281 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400282 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100283
284 context[ContextOnuSerialNumber] = serialNumber
285 context[ContextOnuDeviceID] = onuDeviceID
286}
287
288func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
289 var de voltha.DeviceEvent
290 context := make(map[string]string)
291 /* Populating event context */
292 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
293
294 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
295 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
296
Devmalya Paulfb990a52019-07-09 10:01:49 -0400297 /* Populating device event body */
298 de.Context = context
299 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530300 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400301 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400302 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530303 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400304 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000305 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530306 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400307}
308
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530309//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000310func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530311 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
312 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000313 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530314
315 if onuAlarm.LosStatus == statusCheckOn {
316 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000317 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530318 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
319 return true
320 }
321 return false
322 }
323 }
324 return true
325}
326
327//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000328func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530329 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
330 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000331 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530332
333 if onuAlarm.LosStatus == statusCheckOff {
334 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000335 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530336 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
337 return true
338 }
339 return false
340 }
341 }
342 return true
343}
344
345func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
346 var deviceEventName string
347 if onuAlarm.LosStatus == statusCheckOn {
348 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
349 } else if onuAlarm.LosStatus == statusCheckOff {
350 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
351 } else if onuAlarm.LobStatus == statusCheckOn {
352 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
353 } else if onuAlarm.LobStatus == statusCheckOff {
354 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
355 } else if onuAlarm.LopcMissStatus == statusCheckOn {
356 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
357 } else if onuAlarm.LopcMissStatus == statusCheckOff {
358 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
359 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
360 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
361 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
362 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
363 } else if onuAlarm.LofiStatus == statusCheckOn {
364 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
365 } else if onuAlarm.LofiStatus == statusCheckOff {
366 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
367 } else if onuAlarm.LoamiStatus == statusCheckOn {
368 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
369 } else if onuAlarm.LoamiStatus == statusCheckOff {
370 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
371 }
372 return deviceEventName
373}
374
Neha Sharma96b7bf22020-06-15 10:37:32 +0000375func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400376 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100377
Devmalya Paulfb990a52019-07-09 10:01:49 -0400378 context := make(map[string]string)
379 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100380 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
381 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
382 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530383
Devmalya Paulfb990a52019-07-09 10:01:49 -0400384 /* Populating device event body */
385 de.Context = context
386 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530387 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
388
389 switch onuAlarm.LosStatus {
390 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000391 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530392 /* No need to raise Onu Los Event as it might have already raised
393 or Onu might have deleted */
394 return nil
395 }
396 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
397 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
398 /* Update onu device with LoS raised state as true */
399 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
400 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
401 onuInCache.(*OnuDevice).proxyDeviceID, true))
402 }
403 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000404 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530405 /* No need to clear Onu Los Event as it might have already cleared
406 or Onu might have deleted */
407 return nil
408 }
409 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
410 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
411 /* Update onu device with LoS raised state as false */
412 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
413 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
414 onuInCache.(*OnuDevice).proxyDeviceID, false))
415 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400416 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530417
Devmalya Paulfb990a52019-07-09 10:01:49 -0400418 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400419 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530420 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400421 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000422 logger.Debugw(ctx, "onu-los-event-sent-to-kafka", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530423 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400424}
425
Neha Sharma96b7bf22020-06-15 10:37:32 +0000426func (em *OpenOltEventMgr) onuActivationFailIndication(ctx context.Context, oaf *oop.OnuActivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400427 var de voltha.DeviceEvent
428 context := make(map[string]string)
429 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100430 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(oaf.IntfId), base10)
431 context[ContextOnuOnuID] = strconv.FormatUint(uint64(oaf.OnuId), base10)
432 context[ContextOnuFailureReaseon] = strconv.FormatUint(uint64(oaf.FailReason), base10)
433
434 em.populateContextWithSerialDeviceID(context, oaf.IntfId, oaf.OnuId)
435
Devmalya Paulfb990a52019-07-09 10:01:49 -0400436 /* Populating device event body */
437 de.Context = context
438 de.ResourceId = deviceID
439 de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
440 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400441 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530442 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400443 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000444 logger.Debugw(ctx, "onu-activation-failure-event-sent-to-kafka", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530445 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400446}
447
Neha Sharma96b7bf22020-06-15 10:37:32 +0000448func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400449 var de voltha.DeviceEvent
450 context := make(map[string]string)
451 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100452 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
453 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
454
455 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
456
Devmalya Paulfb990a52019-07-09 10:01:49 -0400457 /* Populating device event body */
458 de.Context = context
459 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530460 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400461 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
462 } else {
463 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
464 }
465 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400466 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530467 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400468 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000469 logger.Debugw(ctx, "onu-loss-of-omci-channel-event-sent-to-kafka", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530470 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400471}
472
Neha Sharma96b7bf22020-06-15 10:37:32 +0000473func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400474 var de voltha.DeviceEvent
475 context := make(map[string]string)
476 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100477 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
478 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
479 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
480 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
481
482 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
483
Devmalya Paulfb990a52019-07-09 10:01:49 -0400484 /* Populating device event body */
485 de.Context = context
486 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530487 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400488 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
489 } else {
490 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
491 }
492 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400493 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530494 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400495 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000496 logger.Debugw(ctx, "onu-drift-of-window-event-sent-to-kafka", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530497 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400498}
499
Neha Sharma96b7bf22020-06-15 10:37:32 +0000500func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400501 var de voltha.DeviceEvent
502 context := make(map[string]string)
503 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100504 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
505 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
506 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
507
508 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
509
Devmalya Paulfb990a52019-07-09 10:01:49 -0400510 /* Populating device event body */
511 de.Context = context
512 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530513 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400514 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
515 } else {
516 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
517 }
518 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400519 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530520 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400521 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000522 logger.Debugw(ctx, "onu-signal-degrade-event-sent-to-kafka", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530523 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400524}
525
Neha Sharma96b7bf22020-06-15 10:37:32 +0000526func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400527 var de voltha.DeviceEvent
528 context := make(map[string]string)
529 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100530 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
531
532 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
533 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
534 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400535 /* Populating device event body */
536 de.Context = context
537 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530538 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400539 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
540 } else {
541 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
542 }
543 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400544 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530545 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400546 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000547 logger.Debugw(ctx, "onu-signals-fail-event-sent-to-kafka", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530548 return nil
549}
550
Neha Sharma96b7bf22020-06-15 10:37:32 +0000551func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530552 var de voltha.DeviceEvent
553 context := make(map[string]string)
554 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100555 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
556
557 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
558 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530559
560 /* Populating device event body */
561 de.Context = context
562 de.ResourceId = deviceID
563 if onuStartupFail.Status == statusCheckOn {
564 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
565 } else {
566 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
567 }
568 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400569 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530570 return err
571 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000572 logger.Debugw(ctx, "onu-startup-fail-event-sent-to-kafka", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
Naga Manjunathf6f74642020-01-13 21:37:28 +0530573 return nil
574}
575
Neha Sharma96b7bf22020-06-15 10:37:32 +0000576func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530577 var de voltha.DeviceEvent
578 context := make(map[string]string)
579 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100580 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
581
582 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
583 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530584 /* Populating device event body */
585 de.Context = context
586 de.ResourceId = deviceID
587 if onuLOKI.Status == statusCheckOn {
588 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
589 } else {
590 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
591 }
592
593 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400594 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530595 return err
596 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000597 logger.Debugw(ctx, "onu-loss-of-key-sync-event-sent-to-kafka", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530598 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400599}
kesavand39e0aa32020-01-28 20:58:50 -0500600
601// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400602func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400603 portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
604 if port, err := em.handler.coreProxy.GetDevicePort(ctx, deviceID, portNo); err != nil {
605 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "error": err})
606 } else if port.AdminState != common.AdminState_ENABLED {
607 logger.Debugw(ctx, "port-disable/enable-event-not-generated--the-port-is-not-enabled-by-operator", log.Fields{"device-id": deviceID, "port": port})
Kent Hagermane6ff1012020-07-14 15:07:53 -0400608 return
kesavand39e0aa32020-01-28 20:58:50 -0500609 }
610 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400611 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500612 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400613 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500614 de.Context = context
615 de.ResourceId = deviceID
616
617 if ifindication.GetOperState() == operationStateDown {
618 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
619 } else if ifindication.OperState == operationStateUp {
620 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
621 }
622 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400623 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
624 _ = olterrors.NewErrCommunication("send-olt-intf-oper-status-event", log.Fields{"device-id": deviceID, "intf-id": ifindication.IntfId, "oper-state": ifindication.OperState}, err).LogAt(log.WarnLevel)
625 return
kesavand39e0aa32020-01-28 20:58:50 -0500626 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000627 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500628}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500629
Neha Sharma96b7bf22020-06-15 10:37:32 +0000630func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500631 var de voltha.DeviceEvent
632 context := make(map[string]string)
633 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100634 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
635
636 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
637 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500638 /* Populating device event body */
639 de.Context = context
640 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400641 if onuDFI.Status == statusCheckOn {
642 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
643 } else {
644 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
645 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500646 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400647 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500648 return err
649 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000650 logger.Debugw(ctx, "onu-deactivation-failure-event-sent-to-kafka", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId})
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500651 return nil
652}
Amit Ghosh502056b2020-07-15 09:15:48 +0100653
Neha Sharma96b7bf22020-06-15 10:37:32 +0000654func (em *OpenOltEventMgr) onuRemoteDefectIndication(ctx context.Context, onuID uint32, intfID uint32, rdiCount uint64, status string, deviceID string, raisedTs int64) error {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500655 /* Populating event context */
656 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100657 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
658 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
659 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500660 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100661 em.populateContextWithSerialDeviceID(context, intfID, onuID)
662
Devmalya Paul6f063a62020-02-19 19:19:06 -0500663 /* Populating device event body */
664 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400665 Context: context,
666 ResourceId: deviceID,
667 }
668 if status == statusCheckOn {
669 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
670 } else {
671 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500672 }
673 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400674 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500675 return err
676 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000677 logger.Debugw(ctx, "onu-remote-defect-event-sent-to-kafka", log.Fields{"onu-id": onuID, "intf-id": intfID})
Devmalya Paula1efa642020-04-20 01:36:43 -0400678 return nil
679}
680
Neha Sharma96b7bf22020-06-15 10:37:32 +0000681func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400682 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
683 if !found {
684 return errors.New("unknown-onu-device")
685 }
686 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
687 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000688 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400689 return err
690 }
691 onuDevice.(*OnuDevice).rdiRaised = true
692 return nil
693 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000694 logger.Debugw(ctx, "onu-remote-defect-already-raised", log.Fields{"onu-id": onuIPS.OnuId, "intf-id": onuIPS.IntfId})
Devmalya Paula1efa642020-04-20 01:36:43 -0400695 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000696 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400697 return err
698 }
699 onuDevice.(*OnuDevice).rdiRaised = false
700 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500701 return nil
702}
703
Neha Sharma96b7bf22020-06-15 10:37:32 +0000704func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500705 /* Populating event context */
706 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100707 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
708 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
709 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500710 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100711 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
712
Devmalya Paul41a762d2020-03-01 18:56:54 -0500713 /* Populating device event body */
714 de := &voltha.DeviceEvent{
715 Context: context,
716 ResourceId: deviceID,
717 }
718 if onuGCD.Status == statusCheckOn {
719 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
720 } else {
721 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
722 }
723 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400724 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500725 return err
726 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000727 logger.Debugw(ctx, "onu-loss-of-gem-channel-delineation-event-sent-to-kafka", log.Fields{"onu-id": onuGCD.OnuId, "intf-id": onuGCD.IntfId})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500728 return nil
729}
730
Neha Sharma96b7bf22020-06-15 10:37:32 +0000731func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500732 /* Populating event context */
733 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100734 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
735 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500736 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100737 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500738 /* Populating device event body */
739 de := &voltha.DeviceEvent{
740 Context: context,
741 ResourceId: deviceID,
742 }
743 if onuErr.Status == statusCheckOn {
744 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
745 } else {
746 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
747 }
748 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400749 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500750 return err
751 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000752 logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuErr.OnuId, "intf-id": onuErr.IntfId})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500753 return nil
754}
755
Neha Sharma96b7bf22020-06-15 10:37:32 +0000756func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500757 /* Populating event context */
758 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100759 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
760 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500761 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100762 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
763
Devmalya Paul41a762d2020-03-01 18:56:54 -0500764 /* Populating device event body */
765 de := &voltha.DeviceEvent{
766 Context: context,
767 ResourceId: deviceID,
768 }
769 if onuLOA.Status == statusCheckOn {
770 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
771 } else {
772 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
773 }
774 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400775 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500776 return err
777 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000778 logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuLOA.OnuId, "intf-id": onuLOA.IntfId})
Devmalya Paul6f063a62020-02-19 19:19:06 -0500779 return nil
780}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400781
Neha Sharma96b7bf22020-06-15 10:37:32 +0000782func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400783 /* Populating event context */
784 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100785 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
786 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
787 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400788 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100789 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
790
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400791 /* Populating device event body */
792 de := &voltha.DeviceEvent{
793 Context: context,
794 ResourceId: deviceID,
795 }
796 if onuDRE.Status == statusCheckOn {
797 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
798 } else {
799 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
800 }
801 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400802 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400803 return err
804 }
Shrey Baid26912972020-04-16 21:02:31 +0530805 log.Debugw("onu-differential-reach-exceeded–event-sent-to-kafka", log.Fields{"onu-id": onuDRE.OnuId, "intf-id": onuDRE.IntfId})
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400806 return nil
807}