blob: 888957f2aacf95c428097690433fbcaa1218ae4c [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Devmalya Paulfb990a52019-07-09 10:01:49 -04003
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
khenaidoodc2116e2021-10-19 17:33:19 -040026 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidoo106c61a2021-08-11 18:05:46 -040027
28 "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
29 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Mahir Gunyel85f61c12021-10-06 11:53:45 -070030 plt "github.com/opencord/voltha-lib-go/v7/pkg/platform"
Thomas Lee S94109f12020-03-03 16:39:29 +053031 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
khenaidoo106c61a2021-08-11 18:05:46 -040032 "github.com/opencord/voltha-protos/v5/go/common"
33 oop "github.com/opencord/voltha-protos/v5/go/openolt"
34 "github.com/opencord/voltha-protos/v5/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040035)
36
37const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050038 onuDiscoveryEvent = "ONU_DISCOVERY"
39 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
40 onuLobEvent = "ONU_LOSS_OF_BURST"
41 onuLopcMissEvent = "ONU_LOPC_MISS"
42 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
43 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Gustavo Silva41af9122022-10-11 11:05:13 -030044 oltRebootFailedEvent = "OLT_REBOOT_FAILED"
Gamze Abaka07868a52020-12-17 14:19:28 +000045 oltCommFailure = "OLT_COMMUNICATION_FAILURE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050046 oltIndicationDown = "OLT_DOWN_INDICATION"
47 onuDyingGaspEvent = "ONU_DYING_GASP"
48 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
49 onuStartupFailEvent = "ONU_STARTUP_FAIL"
50 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
51 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
52 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050053 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
54 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
55 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
56 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
balaji.nagarajan68f56e82025-07-04 15:16:01 +053057 onuDisableEvent = "ONU_DISABLE"
58 onuEnableEvent = "ONU_ENABLE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050059 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
60 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
61 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
62 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
63 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
64 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040065 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040066)
67
68const (
Naga Manjunath9546b912019-11-28 20:56:20 +053069 // statusCheckOn represents status check On
70 statusCheckOn = "on"
71 // statusCheckOff represents status check Off
72 statusCheckOff = "off"
73 // operationStateUp represents operation state Up
74 operationStateUp = "up"
75 // operationStateDown represents operation state Down
76 operationStateDown = "down"
77 // base10 represents base 10 conversion
78 base10 = 10
79)
80
Amit Ghosh502056b2020-07-15 09:15:48 +010081const (
Gamze Abaka07868a52020-12-17 14:19:28 +000082 // ContextOltAdminState is for the admin state of the Olt in the context of the event
83 ContextOltAdminState = "admin-state"
84 // ContextOltConnectState is for the connect state of the Olt in the context of the event
85 ContextOltConnectState = "connect-state"
Gustavo Silva41af9122022-10-11 11:05:13 -030086 // ContextOltFailureReason is to report the reason of an operation failure in the Olt
87 ContextOltFailureReason = "failure-reason"
Amit Ghosh502056b2020-07-15 09:15:48 +010088 // ContextOltOperState is for the operational state of the Olt in the context of the event
89 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000090 // ContextOltVendor is for the Olt vendor in the context of the event
91 ContextOltVendor = "vendor"
92 // ContextOltType is for the Olt type in the context of the event
93 ContextOltType = "type"
94 // ContextOltParentID is for the Olt parent id in the context of the event
95 ContextOltParentID = "parent-id"
96 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
97 ContextOltParentPortNo = "parent-port-no"
98 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
99 ContextOltFirmwareVersion = "firmware-version"
100 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
101 ContextOltHardwareVersion = "hardware-version"
102 // ContextOltSerialNumber is for the serial number of the OLT
103 ContextOltSerialNumber = "serial-number"
104 // ContextOltMacAddress is for the OLT mac address
105 ContextOltMacAddress = "mac-address"
106 // ContextDeviceID is for the device id in the context of the event
107 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100108 // ContextOnuOnuID is for the Onu Id in the context of the event
109 ContextOnuOnuID = "onu-id"
110 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
111 ContextOnuPonIntfID = "intf-id"
112 // ContextOnuSerialNumber is for the serial number of the ONU
113 ContextOnuSerialNumber = "serial-number"
114 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
115 ContextOnuDeviceID = "onu-device-id"
116 // ContextOltPonIntfID is for the PON interface Id on an OLT event
117 ContextOltPonIntfID = "intf-id"
118 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
119 ContextOnuFailureReaseon = "fail-reason"
120 // ContextOnuDrift is for the drift of an ONU in the context of an event
121 ContextOnuDrift = "drift"
122 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
123 ContextOnuNewEqd = "new-eqd"
124 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
125 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
126 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
127 ContextOltPonIntfOperState = "oper-state"
128 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
129 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
130 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
131 ContextOnuDelineationErrors = "delineation-errors"
132 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
133 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530134 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
135 ContextOltPonTechnology = "pon-technology"
136 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
137 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100138)
139
Devmalya Paulfb990a52019-07-09 10:01:49 -0400140// OpenOltEventMgr struct contains
141type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530142 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400143 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400144}
145
146// NewEventMgr is a Function to get a new event manager struct for the OpenOLT to process and publish OpenOLT event
Himani Chawlacd407802020-12-10 12:08:59 +0530147func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400148 var em OpenOltEventMgr
149 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400150 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400151 return &em
152}
153
154// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500155// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400156func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530157 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400158 switch alarmInd.Data.(type) {
159 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000160 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
161 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400162 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000163 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
164 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400165 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000166 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
167 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400168 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000169 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
170 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400171 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000172 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
173 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400174 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000175 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
176 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400177 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000178 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
179 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530180 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000181 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
182 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400183 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000184 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
185 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530186 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000187 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
188 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530189 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000190 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
191 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500192 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000193 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
194 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500195 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000196 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
197 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500198 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000199 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
200 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500201 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000202 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
203 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400204 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000205 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
206 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400207 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530208 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400209 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530210 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400211 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530212 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400213}
214
Gamze Abaka07868a52020-12-17 14:19:28 +0000215func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
216 if device == nil {
217 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
218 return
219 }
220 var de voltha.DeviceEvent
221 context := make(map[string]string)
222 context[ContextOltOperState] = device.OperStatus.String()
223 context[ContextOltAdminState] = device.AdminState.String()
224 context[ContextOltVendor] = device.Vendor
225 context[ContextOltConnectState] = device.ConnectStatus.String()
226 context[ContextOltType] = device.Type
227 context[ContextOltParentID] = device.ParentId
228 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
229 context[ContextDeviceID] = device.Id
230 context[ContextOltFirmwareVersion] = device.FirmwareVersion
231 context[ContextOltHardwareVersion] = device.HardwareVersion
232 context[ContextOltSerialNumber] = device.SerialNumber
233 context[ContextOltMacAddress] = device.MacAddress
234 de.Context = context
235 de.ResourceId = device.Id
236
237 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
238 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
239 } else {
240 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
241 }
242
243 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
244 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
245 }
246 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
247 log.Fields{
248 "device-id": device.Id,
249 "connect-status": device.ConnectStatus,
250 })
251}
252
Daniele Rossi051466a2019-07-26 13:39:37 +0000253// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000254func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000255 var de voltha.DeviceEvent
256 context := make(map[string]string)
257 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100258 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000259 /* Populating device event body */
260 de.Context = context
261 de.ResourceId = deviceID
mgouda86543582025-10-29 20:58:16 +0530262 switch oltIndication.OperState {
263 case operationStateDown:
Daniele Rossi051466a2019-07-26 13:39:37 +0000264 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
mgouda86543582025-10-29 20:58:16 +0530265 case operationStateUp:
Daniele Rossi051466a2019-07-26 13:39:37 +0000266 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
267 }
268 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400269 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000270 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000271 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000272 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530273 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000274}
275
Devmalya Paulfb990a52019-07-09 10:01:49 -0400276// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000277func (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 -0400278 var de voltha.DeviceEvent
279 context := make(map[string]string)
280 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100281 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
282 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
283 context[ContextOnuSerialNumber] = serialNumber
284 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530285 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
286 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400287 /* Populating device event body */
288 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100289 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400290 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
291 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530292 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530293 return olterrors.NewErrCommunication("send-onu-discovery-event",
294 log.Fields{
295 "serial-number": serialNumber,
296 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400297 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000298 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530299 log.Fields{
300 "serial-number": serialNumber,
301 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530302 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400303}
304
Neha Sharma96b7bf22020-06-15 10:37:32 +0000305func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530306 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400307 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530308 var alarmInd oop.OnuAlarmIndication
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700309 ponIntdID := plt.PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530310
Devmalya Paulfb990a52019-07-09 10:01:49 -0400311 context := make(map[string]string)
312 /* Populating event context */
yasin sapli0b242942021-10-11 08:51:16 +0000313 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(ponIntdID), base10)
Abhilash Laxmeshwar42b58242021-11-24 19:27:25 +0530314 context[ContextOltPortLabel], _ = GetportLabel(oltLos.IntfId, voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400315 /* Populating device event body */
316 de.Context = context
317 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530318 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400319 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530320
321 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
322 with "los_status: on" should be raised for each Onu connected to the PON
323 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
324 for all the ONU's connected to PON on receiving LoSIndication for PON */
325 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
326 if onuInCache.(*OnuDevice).intfID == ponIntdID {
327 alarmInd.IntfId = ponIntdID
328 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
329 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000330 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530331 }
332 return true
333 })
334 if err != nil {
335 /* Return if any error encountered while processing ONU LoS Event*/
336 return err
337 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400338 } else {
339 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
340 }
341 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100342 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530343 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400344 }
yasin sapli0b242942021-10-11 08:51:16 +0000345 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": ponIntdID})
Naga Manjunath9546b912019-11-28 20:56:20 +0530346 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400347}
Akash Kankanala041a2122024-10-16 15:49:22 +0530348
Gustavo Silva41af9122022-10-11 11:05:13 -0300349func (em *OpenOltEventMgr) oltRebootFailedEvent(ctx context.Context, deviceID string, reason string, raisedTs int64) error {
350 de := voltha.DeviceEvent{
351 Context: map[string]string{ContextOltFailureReason: "olt-reboot-failed"},
352 ResourceId: deviceID,
353 DeviceEventName: fmt.Sprintf("%s_%s", oltRebootFailedEvent, "RAISE_EVENT")}
354 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT,
355 raisedTs); err != nil {
356 return olterrors.NewErrCommunication("send-olt-reboot-failed-event", log.Fields{
Akash Kankanala041a2122024-10-16 15:49:22 +0530357 "device-id": deviceID, "raised-ts": raisedTs, "reason": reason}, err)
Gustavo Silva41af9122022-10-11 11:05:13 -0300358 }
359 logger.Debugw(ctx, "olt-reboot-failed-event-sent-to-kafka", log.Fields{
Akash Kankanala041a2122024-10-16 15:49:22 +0530360 "device-id": deviceID, "raised-ts": raisedTs, "reason": reason})
Gustavo Silva41af9122022-10-11 11:05:13 -0300361 return nil
362}
Devmalya Paulfb990a52019-07-09 10:01:49 -0400363
kesavand0ef592c2022-03-16 12:34:24 +0530364func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) string {
Amit Ghosh502056b2020-07-15 09:15:48 +0100365 var serialNumber = ""
366 var onuDeviceID = ""
367 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530368 if onu, ok := em.handler.onus.Load(onu); ok {
369 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100370 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400371 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100372
ssiddiqui04386ee2021-08-23 21:58:25 +0530373 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100374 context[ContextOnuSerialNumber] = serialNumber
375 context[ContextOnuDeviceID] = onuDeviceID
kesavand0ef592c2022-03-16 12:34:24 +0530376 return onuDeviceID
Amit Ghosh502056b2020-07-15 09:15:48 +0100377}
378
balaji.nagarajan68f56e82025-07-04 15:16:01 +0530379func (em *OpenOltEventMgr) onuDisableIndication(ctx context.Context, onui *oop.OnuDisabledIndication, parentDeviceID string, onuDev *OnuDevice, raisedTs int64) error {
380 var de voltha.DeviceEvent
381 context := make(map[string]string)
382 /* Populating event context */
383 onuDeviceID := em.populateContextWithSerialDeviceID(context, onui.IntfId, onui.OnuId)
384
385 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onui.IntfId), base10)
386 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onui.OnuId), base10)
387 context[ContextDeviceID] = onuDev.deviceID
388 context[ContextOnuSerialNumber] = onuDev.serialNumber
389 /* Populating device event body */
390 de.Context = context
391 de.ResourceId = parentDeviceID
392 de.DeviceEventName = onuDisableEvent
393 /* Send event to KAFKA */
394 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
395 return err
396 }
397 logger.Debugw(ctx, "onu-disabled-event-sent-to-kafka", log.Fields{"intf-id": onui.IntfId, "onu_id": onui.OnuId})
398 return nil
399}
400
401func (em *OpenOltEventMgr) onuEnableIndication(ctx context.Context, onui *oop.OnuEnabledIndication, deviceID string, onuDev *OnuDevice, raisedTs int64) error {
402 var de voltha.DeviceEvent
403 context := make(map[string]string)
404 /* Populating event context */
405 onuDeviceID := em.populateContextWithSerialDeviceID(context, onui.IntfId, onui.OnuId)
406
407 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onui.IntfId), base10)
408 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onui.OnuId), base10)
409 context[ContextDeviceID] = onuDev.deviceID
410 context[ContextOnuSerialNumber] = onuDev.serialNumber
411 /* Populating device event body */
412 de.Context = context
413 de.ResourceId = deviceID
414 de.DeviceEventName = onuEnableEvent
415 /* Send event to KAFKA */
416 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
417 return err
418 }
419 logger.Debugw(ctx, "onu-enabled-event-sent-to-kafka", log.Fields{"intf-id": onui.IntfId, "onu_id": onui.OnuId})
420 return nil
421}
422
Amit Ghosh502056b2020-07-15 09:15:48 +0100423func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
424 var de voltha.DeviceEvent
425 context := make(map[string]string)
426 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530427 onuDeviceID := em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100428
429 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
430 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
431
Devmalya Paulfb990a52019-07-09 10:01:49 -0400432 /* Populating device event body */
433 de.Context = context
434 de.ResourceId = deviceID
Marcos Aurelio Carrero (Furukawa)1992f992023-11-14 14:31:40 -0300435
436 if dgi.Status == statusCheckOn {
437 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT")
438 } else {
439 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT")
440 }
441
Devmalya Paulfb990a52019-07-09 10:01:49 -0400442 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530443 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530444 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400445 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000446 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530447 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400448}
449
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400450// wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000451func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530452 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
453 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000454 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530455
456 if onuAlarm.LosStatus == statusCheckOn {
457 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000458 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530459 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
460 return true
461 }
462 return false
463 }
464 }
465 return true
466}
467
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400468// wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000469func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530470 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
471 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000472 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530473
474 if onuAlarm.LosStatus == statusCheckOff {
475 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000476 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530477 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
478 return true
479 }
480 return false
481 }
482 }
483 return true
484}
485
486func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
487 var deviceEventName string
488 if onuAlarm.LosStatus == statusCheckOn {
489 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
490 } else if onuAlarm.LosStatus == statusCheckOff {
491 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
492 } else if onuAlarm.LobStatus == statusCheckOn {
493 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
494 } else if onuAlarm.LobStatus == statusCheckOff {
495 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
496 } else if onuAlarm.LopcMissStatus == statusCheckOn {
497 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
498 } else if onuAlarm.LopcMissStatus == statusCheckOff {
499 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
500 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
501 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
502 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
503 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
504 } else if onuAlarm.LofiStatus == statusCheckOn {
505 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
506 } else if onuAlarm.LofiStatus == statusCheckOff {
507 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
508 } else if onuAlarm.LoamiStatus == statusCheckOn {
509 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
510 } else if onuAlarm.LoamiStatus == statusCheckOff {
511 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
512 }
513 return deviceEventName
514}
515
Neha Sharma96b7bf22020-06-15 10:37:32 +0000516func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400517 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100518
Devmalya Paulfb990a52019-07-09 10:01:49 -0400519 context := make(map[string]string)
520 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100521 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
522 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
kesavand0ef592c2022-03-16 12:34:24 +0530523 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530524
Devmalya Paulfb990a52019-07-09 10:01:49 -0400525 /* Populating device event body */
526 de.Context = context
527 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530528 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
529
530 switch onuAlarm.LosStatus {
531 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000532 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530533 /* No need to raise Onu Los Event as it might have already raised
534 or Onu might have deleted */
535 return nil
536 }
537 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
538 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
539 /* Update onu device with LoS raised state as true */
540 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
541 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400542 onuInCache.(*OnuDevice).proxyDeviceID, true, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530543 }
544 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000545 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530546 /* No need to clear Onu Los Event as it might have already cleared
547 or Onu might have deleted */
548 return nil
549 }
550 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
551 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
552 /* Update onu device with LoS raised state as false */
553 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
554 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400555 onuInCache.(*OnuDevice).proxyDeviceID, false, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530556 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400557 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530558
Devmalya Paulfb990a52019-07-09 10:01:49 -0400559 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530560 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530561 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400562 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000563 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 +0530564 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400565}
566
kesavand7cf3a052020-08-28 12:49:18 +0530567func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400568 var de voltha.DeviceEvent
569 context := make(map[string]string)
570 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530571 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
572 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
573 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100574
kesavand0ef592c2022-03-16 12:34:24 +0530575 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100576
Devmalya Paulfb990a52019-07-09 10:01:49 -0400577 /* Populating device event body */
578 de.Context = context
579 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530580 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400581 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530582 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530583 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400584 }
kesavand7cf3a052020-08-28 12:49:18 +0530585 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 +0530586 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400587}
588
Neha Sharma96b7bf22020-06-15 10:37:32 +0000589func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400590 var de voltha.DeviceEvent
591 context := make(map[string]string)
592 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100593 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
594 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
595
kesavand0ef592c2022-03-16 12:34:24 +0530596 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100597
Devmalya Paulfb990a52019-07-09 10:01:49 -0400598 /* Populating device event body */
599 de.Context = context
600 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530601 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400602 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
603 } else {
604 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
605 }
606 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530607 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530608 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400609 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000610 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 +0530611 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400612}
613
Neha Sharma96b7bf22020-06-15 10:37:32 +0000614func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400615 var de voltha.DeviceEvent
616 context := make(map[string]string)
617 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100618 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
619 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
620 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
621 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
622
kesavand0ef592c2022-03-16 12:34:24 +0530623 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100624
Devmalya Paulfb990a52019-07-09 10:01:49 -0400625 /* Populating device event body */
626 de.Context = context
627 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530628 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400629 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
630 } else {
631 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
632 }
633 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530634 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530635 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400636 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000637 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 +0530638 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400639}
640
Neha Sharma96b7bf22020-06-15 10:37:32 +0000641func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400642 var de voltha.DeviceEvent
643 context := make(map[string]string)
644 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100645 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
646 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
647 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
648
kesavand0ef592c2022-03-16 12:34:24 +0530649 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100650
Devmalya Paulfb990a52019-07-09 10:01:49 -0400651 /* Populating device event body */
652 de.Context = context
653 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530654 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400655 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
656 } else {
657 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
658 }
659 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530660 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530661 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400662 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000663 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 +0530664 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400665}
666
Neha Sharma96b7bf22020-06-15 10:37:32 +0000667func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400668 var de voltha.DeviceEvent
669 context := make(map[string]string)
670 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530671 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100672
673 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
674 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
675 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400676 /* Populating device event body */
677 de.Context = context
678 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530679 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400680 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
681 } else {
682 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
683 }
684 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530685 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530686 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400687 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000688 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 +0530689 return nil
690}
691
Neha Sharma96b7bf22020-06-15 10:37:32 +0000692func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530693 var de voltha.DeviceEvent
694 context := make(map[string]string)
695 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530696 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100697
698 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
699 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530700
701 /* Populating device event body */
702 de.Context = context
703 de.ResourceId = deviceID
704 if onuStartupFail.Status == statusCheckOn {
705 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
706 } else {
707 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
708 }
709 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530710 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530711 return err
712 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000713 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 +0530714 return nil
715}
716
Neha Sharma96b7bf22020-06-15 10:37:32 +0000717func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530718 var de voltha.DeviceEvent
719 context := make(map[string]string)
720 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530721 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100722
723 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
724 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530725 /* Populating device event body */
726 de.Context = context
727 de.ResourceId = deviceID
728 if onuLOKI.Status == statusCheckOn {
729 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
730 } else {
731 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
732 }
733
734 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530735 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530736 return err
737 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000738 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 +0530739 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400740}
kesavand39e0aa32020-01-28 20:58:50 -0500741
742// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400743func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700744 portNo := plt.IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
khenaidoodc2116e2021-10-19 17:33:19 -0400745 if port, err := em.handler.getPortFromCore(ctx, &ca.PortFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400746 DeviceId: deviceID,
747 Port: portNo,
748 }); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700749 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400750 } else if port.AdminState != common.AdminState_ENABLED {
751 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 -0400752 return
kesavand39e0aa32020-01-28 20:58:50 -0500753 }
754 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400755 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500756 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400757 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500758 de.Context = context
759 de.ResourceId = deviceID
760
761 if ifindication.GetOperState() == operationStateDown {
762 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
763 } else if ifindication.OperState == operationStateUp {
764 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
765 }
766 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400767 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
768 _ = 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)
769 return
kesavand39e0aa32020-01-28 20:58:50 -0500770 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000771 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500772}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500773
Neha Sharma96b7bf22020-06-15 10:37:32 +0000774func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500775 var de voltha.DeviceEvent
776 context := make(map[string]string)
777 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530778 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100779
780 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
781 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500782 /* Populating device event body */
783 de.Context = context
784 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400785 if onuDFI.Status == statusCheckOn {
786 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
787 } else {
788 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
789 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500790 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530791 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500792 return err
793 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000794 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 -0500795 return nil
796}
Amit Ghosh502056b2020-07-15 09:15:48 +0100797
Neha Sharma96b7bf22020-06-15 10:37:32 +0000798func (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 -0500799 /* Populating event context */
800 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100801 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
802 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
803 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500804 }
kesavand0ef592c2022-03-16 12:34:24 +0530805 onuDeviceID := em.populateContextWithSerialDeviceID(context, intfID, onuID)
Amit Ghosh502056b2020-07-15 09:15:48 +0100806
Devmalya Paul6f063a62020-02-19 19:19:06 -0500807 /* Populating device event body */
808 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400809 Context: context,
810 ResourceId: deviceID,
811 }
812 if status == statusCheckOn {
813 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
814 } else {
815 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500816 }
817 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530818 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500819 return err
820 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000821 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 -0400822 return nil
823}
824
Neha Sharma96b7bf22020-06-15 10:37:32 +0000825func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400826 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
827 if !found {
828 return errors.New("unknown-onu-device")
829 }
830 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
831 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000832 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400833 return err
834 }
835 onuDevice.(*OnuDevice).rdiRaised = true
836 return nil
837 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000838 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 -0400839 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000840 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400841 return err
842 }
843 onuDevice.(*OnuDevice).rdiRaised = false
844 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500845 return nil
846}
847
Neha Sharma96b7bf22020-06-15 10:37:32 +0000848func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500849 /* Populating event context */
850 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100851 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
852 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
853 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500854 }
kesavand0ef592c2022-03-16 12:34:24 +0530855 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100856
Devmalya Paul41a762d2020-03-01 18:56:54 -0500857 /* Populating device event body */
858 de := &voltha.DeviceEvent{
859 Context: context,
860 ResourceId: deviceID,
861 }
862 if onuGCD.Status == statusCheckOn {
863 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
864 } else {
865 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
866 }
867 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530868 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500869 return err
870 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000871 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 -0500872 return nil
873}
874
Neha Sharma96b7bf22020-06-15 10:37:32 +0000875func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500876 /* Populating event context */
877 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100878 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
879 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500880 }
kesavand0ef592c2022-03-16 12:34:24 +0530881 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500882 /* Populating device event body */
883 de := &voltha.DeviceEvent{
884 Context: context,
885 ResourceId: deviceID,
886 }
887 if onuErr.Status == statusCheckOn {
888 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
889 } else {
890 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
891 }
892 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530893 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500894 return err
895 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000896 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 -0500897 return nil
898}
899
Neha Sharma96b7bf22020-06-15 10:37:32 +0000900func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500901 /* Populating event context */
902 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100903 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
904 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500905 }
kesavand0ef592c2022-03-16 12:34:24 +0530906 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100907
Devmalya Paul41a762d2020-03-01 18:56:54 -0500908 /* Populating device event body */
909 de := &voltha.DeviceEvent{
910 Context: context,
911 ResourceId: deviceID,
912 }
913 if onuLOA.Status == statusCheckOn {
914 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
915 } else {
916 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
917 }
918 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530919 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500920 return err
921 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000922 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 -0500923 return nil
924}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400925
Neha Sharma96b7bf22020-06-15 10:37:32 +0000926func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400927 /* Populating event context */
928 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100929 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
930 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
931 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400932 }
kesavand0ef592c2022-03-16 12:34:24 +0530933 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100934
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400935 /* Populating device event body */
936 de := &voltha.DeviceEvent{
937 Context: context,
938 ResourceId: deviceID,
939 }
940 if onuDRE.Status == statusCheckOn {
941 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
942 } else {
943 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
944 }
945 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530946 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400947 return err
948 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000949 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 -0400950 return nil
951}