blob: 65b76e60778c45dea2d825101b3ea9e429528b9a [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
Girish Gowdraa09aeab2020-09-14 16:30:52 -070026 "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif"
27 "github.com/opencord/voltha-lib-go/v4/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070029 "github.com/opencord/voltha-protos/v4/go/common"
30 oop "github.com/opencord/voltha-protos/v4/go/openolt"
31 "github.com/opencord/voltha-protos/v4/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_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000134 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
135 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400136 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000137 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
138 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400139 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000140 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
141 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400142 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000143 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
144 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530145 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000146 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
147 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400148 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000149 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
150 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530151 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000152 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
153 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530154 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000155 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
156 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500157 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
159 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500160 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500163 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500166 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400169 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530173 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400174 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530175 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400176 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530177 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400178}
179
Daniele Rossi051466a2019-07-26 13:39:37 +0000180// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000181func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000182 var de voltha.DeviceEvent
183 context := make(map[string]string)
184 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100185 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000186 /* Populating device event body */
187 de.Context = context
188 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530189 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000190 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530191 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000192 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
193 }
194 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400195 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000196 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000197 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000198 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530199 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000200}
201
Devmalya Paulfb990a52019-07-09 10:01:49 -0400202// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000203func (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 -0400204 var de voltha.DeviceEvent
205 context := make(map[string]string)
206 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100207 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
208 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
209 context[ContextOnuSerialNumber] = serialNumber
210 context[ContextOnuDeviceID] = onuDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400211 /* Populating device event body */
212 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100213 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400214 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
215 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400216 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530217 return olterrors.NewErrCommunication("send-onu-discovery-event",
218 log.Fields{
219 "serial-number": serialNumber,
220 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400221 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000222 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530223 log.Fields{
224 "serial-number": serialNumber,
225 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530226 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400227}
228
Neha Sharma96b7bf22020-06-15 10:37:32 +0000229func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530230 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400231 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530232 var alarmInd oop.OnuAlarmIndication
233 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
234
Devmalya Paulfb990a52019-07-09 10:01:49 -0400235 context := make(map[string]string)
236 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100237 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400238 /* Populating device event body */
239 de.Context = context
240 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530241 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400242 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530243
244 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
245 with "los_status: on" should be raised for each Onu connected to the PON
246 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
247 for all the ONU's connected to PON on receiving LoSIndication for PON */
248 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
249 if onuInCache.(*OnuDevice).intfID == ponIntdID {
250 alarmInd.IntfId = ponIntdID
251 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
252 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000253 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530254 }
255 return true
256 })
257 if err != nil {
258 /* Return if any error encountered while processing ONU LoS Event*/
259 return err
260 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400261 } else {
262 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
263 }
264 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400265 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530266 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400267 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000268 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530269 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400270}
271
Amit Ghosh502056b2020-07-15 09:15:48 +0100272func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
273 var serialNumber = ""
274 var onuDeviceID = ""
275 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530276 if onu, ok := em.handler.onus.Load(onu); ok {
277 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100278 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400279 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100280
281 context[ContextOnuSerialNumber] = serialNumber
282 context[ContextOnuDeviceID] = onuDeviceID
283}
284
285func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
286 var de voltha.DeviceEvent
287 context := make(map[string]string)
288 /* Populating event context */
289 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
290
291 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
292 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
293
Devmalya Paulfb990a52019-07-09 10:01:49 -0400294 /* Populating device event body */
295 de.Context = context
296 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530297 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400298 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400299 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530300 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400301 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000302 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530303 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400304}
305
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530306//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000307func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530308 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
309 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000310 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530311
312 if onuAlarm.LosStatus == statusCheckOn {
313 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000314 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530315 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
316 return true
317 }
318 return false
319 }
320 }
321 return true
322}
323
324//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000325func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530326 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
327 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000328 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530329
330 if onuAlarm.LosStatus == statusCheckOff {
331 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000332 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530333 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
334 return true
335 }
336 return false
337 }
338 }
339 return true
340}
341
342func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
343 var deviceEventName string
344 if onuAlarm.LosStatus == statusCheckOn {
345 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
346 } else if onuAlarm.LosStatus == statusCheckOff {
347 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
348 } else if onuAlarm.LobStatus == statusCheckOn {
349 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
350 } else if onuAlarm.LobStatus == statusCheckOff {
351 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
352 } else if onuAlarm.LopcMissStatus == statusCheckOn {
353 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
354 } else if onuAlarm.LopcMissStatus == statusCheckOff {
355 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
356 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
357 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
358 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
359 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
360 } else if onuAlarm.LofiStatus == statusCheckOn {
361 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
362 } else if onuAlarm.LofiStatus == statusCheckOff {
363 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
364 } else if onuAlarm.LoamiStatus == statusCheckOn {
365 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
366 } else if onuAlarm.LoamiStatus == statusCheckOff {
367 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
368 }
369 return deviceEventName
370}
371
Neha Sharma96b7bf22020-06-15 10:37:32 +0000372func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400373 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100374
Devmalya Paulfb990a52019-07-09 10:01:49 -0400375 context := make(map[string]string)
376 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100377 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
378 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
379 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530380
Devmalya Paulfb990a52019-07-09 10:01:49 -0400381 /* Populating device event body */
382 de.Context = context
383 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530384 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
385
386 switch onuAlarm.LosStatus {
387 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000388 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530389 /* No need to raise Onu Los Event as it might have already raised
390 or Onu might have deleted */
391 return nil
392 }
393 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
394 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
395 /* Update onu device with LoS raised state as true */
396 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
397 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
398 onuInCache.(*OnuDevice).proxyDeviceID, true))
399 }
400 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000401 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530402 /* No need to clear Onu Los Event as it might have already cleared
403 or Onu might have deleted */
404 return nil
405 }
406 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
407 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
408 /* Update onu device with LoS raised state as false */
409 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
410 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
411 onuInCache.(*OnuDevice).proxyDeviceID, false))
412 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400413 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530414
Devmalya Paulfb990a52019-07-09 10:01:49 -0400415 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400416 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530417 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400418 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000419 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 +0530420 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400421}
422
kesavand7cf3a052020-08-28 12:49:18 +0530423func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400424 var de voltha.DeviceEvent
425 context := make(map[string]string)
426 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530427 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
428 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
429 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100430
kesavand7cf3a052020-08-28 12:49:18 +0530431 em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100432
Devmalya Paulfb990a52019-07-09 10:01:49 -0400433 /* Populating device event body */
434 de.Context = context
435 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530436 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400437 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400438 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530439 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400440 }
kesavand7cf3a052020-08-28 12:49:18 +0530441 logger.Debugw(ctx, "onu-activation-failure-event-sent-to-kafka", log.Fields{"onu-id": onuInd.OnuId, "intf-id": onuInd.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530442 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400443}
444
Neha Sharma96b7bf22020-06-15 10:37:32 +0000445func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400446 var de voltha.DeviceEvent
447 context := make(map[string]string)
448 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100449 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
450 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
451
452 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
453
Devmalya Paulfb990a52019-07-09 10:01:49 -0400454 /* Populating device event body */
455 de.Context = context
456 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530457 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400458 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
459 } else {
460 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
461 }
462 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400463 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530464 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400465 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000466 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 +0530467 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400468}
469
Neha Sharma96b7bf22020-06-15 10:37:32 +0000470func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400471 var de voltha.DeviceEvent
472 context := make(map[string]string)
473 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100474 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
475 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
476 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
477 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
478
479 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
480
Devmalya Paulfb990a52019-07-09 10:01:49 -0400481 /* Populating device event body */
482 de.Context = context
483 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530484 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400485 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
486 } else {
487 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
488 }
489 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400490 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530491 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400492 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000493 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 +0530494 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400495}
496
Neha Sharma96b7bf22020-06-15 10:37:32 +0000497func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400498 var de voltha.DeviceEvent
499 context := make(map[string]string)
500 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100501 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
502 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
503 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
504
505 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
506
Devmalya Paulfb990a52019-07-09 10:01:49 -0400507 /* Populating device event body */
508 de.Context = context
509 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530510 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400511 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
512 } else {
513 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
514 }
515 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400516 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530517 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400518 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000519 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 +0530520 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400521}
522
Neha Sharma96b7bf22020-06-15 10:37:32 +0000523func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400524 var de voltha.DeviceEvent
525 context := make(map[string]string)
526 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100527 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
528
529 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
530 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
531 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400532 /* Populating device event body */
533 de.Context = context
534 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530535 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400536 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
537 } else {
538 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
539 }
540 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400541 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530542 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400543 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000544 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 +0530545 return nil
546}
547
Neha Sharma96b7bf22020-06-15 10:37:32 +0000548func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530549 var de voltha.DeviceEvent
550 context := make(map[string]string)
551 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100552 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
553
554 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
555 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530556
557 /* Populating device event body */
558 de.Context = context
559 de.ResourceId = deviceID
560 if onuStartupFail.Status == statusCheckOn {
561 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
562 } else {
563 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
564 }
565 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400566 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530567 return err
568 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000569 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 +0530570 return nil
571}
572
Neha Sharma96b7bf22020-06-15 10:37:32 +0000573func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530574 var de voltha.DeviceEvent
575 context := make(map[string]string)
576 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100577 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
578
579 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
580 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530581 /* Populating device event body */
582 de.Context = context
583 de.ResourceId = deviceID
584 if onuLOKI.Status == statusCheckOn {
585 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
586 } else {
587 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
588 }
589
590 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400591 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530592 return err
593 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000594 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 +0530595 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400596}
kesavand39e0aa32020-01-28 20:58:50 -0500597
598// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400599func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400600 portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
601 if port, err := em.handler.coreProxy.GetDevicePort(ctx, deviceID, portNo); err != nil {
602 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "error": err})
603 } else if port.AdminState != common.AdminState_ENABLED {
604 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 -0400605 return
kesavand39e0aa32020-01-28 20:58:50 -0500606 }
607 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400608 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500609 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400610 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500611 de.Context = context
612 de.ResourceId = deviceID
613
614 if ifindication.GetOperState() == operationStateDown {
615 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
616 } else if ifindication.OperState == operationStateUp {
617 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
618 }
619 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400620 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
621 _ = 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)
622 return
kesavand39e0aa32020-01-28 20:58:50 -0500623 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000624 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500625}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500626
Neha Sharma96b7bf22020-06-15 10:37:32 +0000627func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500628 var de voltha.DeviceEvent
629 context := make(map[string]string)
630 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100631 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
632
633 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
634 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500635 /* Populating device event body */
636 de.Context = context
637 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400638 if onuDFI.Status == statusCheckOn {
639 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
640 } else {
641 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
642 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500643 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400644 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500645 return err
646 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000647 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 -0500648 return nil
649}
Amit Ghosh502056b2020-07-15 09:15:48 +0100650
Neha Sharma96b7bf22020-06-15 10:37:32 +0000651func (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 -0500652 /* Populating event context */
653 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100654 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
655 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
656 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500657 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100658 em.populateContextWithSerialDeviceID(context, intfID, onuID)
659
Devmalya Paul6f063a62020-02-19 19:19:06 -0500660 /* Populating device event body */
661 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400662 Context: context,
663 ResourceId: deviceID,
664 }
665 if status == statusCheckOn {
666 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
667 } else {
668 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500669 }
670 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400671 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500672 return err
673 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000674 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 -0400675 return nil
676}
677
Neha Sharma96b7bf22020-06-15 10:37:32 +0000678func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400679 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
680 if !found {
681 return errors.New("unknown-onu-device")
682 }
683 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
684 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000685 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400686 return err
687 }
688 onuDevice.(*OnuDevice).rdiRaised = true
689 return nil
690 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000691 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 -0400692 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000693 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400694 return err
695 }
696 onuDevice.(*OnuDevice).rdiRaised = false
697 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500698 return nil
699}
700
Neha Sharma96b7bf22020-06-15 10:37:32 +0000701func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500702 /* Populating event context */
703 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100704 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
705 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
706 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500707 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100708 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
709
Devmalya Paul41a762d2020-03-01 18:56:54 -0500710 /* Populating device event body */
711 de := &voltha.DeviceEvent{
712 Context: context,
713 ResourceId: deviceID,
714 }
715 if onuGCD.Status == statusCheckOn {
716 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
717 } else {
718 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
719 }
720 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400721 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500722 return err
723 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000724 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 -0500725 return nil
726}
727
Neha Sharma96b7bf22020-06-15 10:37:32 +0000728func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500729 /* Populating event context */
730 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100731 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
732 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500733 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100734 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500735 /* Populating device event body */
736 de := &voltha.DeviceEvent{
737 Context: context,
738 ResourceId: deviceID,
739 }
740 if onuErr.Status == statusCheckOn {
741 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
742 } else {
743 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
744 }
745 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400746 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500747 return err
748 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000749 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 -0500750 return nil
751}
752
Neha Sharma96b7bf22020-06-15 10:37:32 +0000753func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500754 /* Populating event context */
755 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100756 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
757 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500758 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100759 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
760
Devmalya Paul41a762d2020-03-01 18:56:54 -0500761 /* Populating device event body */
762 de := &voltha.DeviceEvent{
763 Context: context,
764 ResourceId: deviceID,
765 }
766 if onuLOA.Status == statusCheckOn {
767 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
768 } else {
769 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
770 }
771 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400772 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500773 return err
774 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000775 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 -0500776 return nil
777}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400778
Neha Sharma96b7bf22020-06-15 10:37:32 +0000779func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400780 /* Populating event context */
781 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100782 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
783 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
784 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400785 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100786 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
787
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400788 /* Populating device event body */
789 de := &voltha.DeviceEvent{
790 Context: context,
791 ResourceId: deviceID,
792 }
793 if onuDRE.Status == statusCheckOn {
794 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
795 } else {
796 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
797 }
798 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400799 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400800 return err
801 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000802 logger.Debugw(ctx, "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 -0400803 return nil
804}