blob: c2c5b5e922ee1339a9565230954bb6bb80c88235 [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"
57 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
58 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
59 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
60 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
61 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
62 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040063 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040064)
65
66const (
Naga Manjunath9546b912019-11-28 20:56:20 +053067 // statusCheckOn represents status check On
68 statusCheckOn = "on"
69 // statusCheckOff represents status check Off
70 statusCheckOff = "off"
71 // operationStateUp represents operation state Up
72 operationStateUp = "up"
73 // operationStateDown represents operation state Down
74 operationStateDown = "down"
75 // base10 represents base 10 conversion
76 base10 = 10
77)
78
Amit Ghosh502056b2020-07-15 09:15:48 +010079const (
Gamze Abaka07868a52020-12-17 14:19:28 +000080 // ContextOltAdminState is for the admin state of the Olt in the context of the event
81 ContextOltAdminState = "admin-state"
82 // ContextOltConnectState is for the connect state of the Olt in the context of the event
83 ContextOltConnectState = "connect-state"
Gustavo Silva41af9122022-10-11 11:05:13 -030084 // ContextOltFailureReason is to report the reason of an operation failure in the Olt
85 ContextOltFailureReason = "failure-reason"
Amit Ghosh502056b2020-07-15 09:15:48 +010086 // ContextOltOperState is for the operational state of the Olt in the context of the event
87 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000088 // ContextOltVendor is for the Olt vendor in the context of the event
89 ContextOltVendor = "vendor"
90 // ContextOltType is for the Olt type in the context of the event
91 ContextOltType = "type"
92 // ContextOltParentID is for the Olt parent id in the context of the event
93 ContextOltParentID = "parent-id"
94 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
95 ContextOltParentPortNo = "parent-port-no"
96 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
97 ContextOltFirmwareVersion = "firmware-version"
98 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
99 ContextOltHardwareVersion = "hardware-version"
100 // ContextOltSerialNumber is for the serial number of the OLT
101 ContextOltSerialNumber = "serial-number"
102 // ContextOltMacAddress is for the OLT mac address
103 ContextOltMacAddress = "mac-address"
104 // ContextDeviceID is for the device id in the context of the event
105 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100106 // ContextOnuOnuID is for the Onu Id in the context of the event
107 ContextOnuOnuID = "onu-id"
108 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
109 ContextOnuPonIntfID = "intf-id"
110 // ContextOnuSerialNumber is for the serial number of the ONU
111 ContextOnuSerialNumber = "serial-number"
112 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
113 ContextOnuDeviceID = "onu-device-id"
114 // ContextOltPonIntfID is for the PON interface Id on an OLT event
115 ContextOltPonIntfID = "intf-id"
116 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
117 ContextOnuFailureReaseon = "fail-reason"
118 // ContextOnuDrift is for the drift of an ONU in the context of an event
119 ContextOnuDrift = "drift"
120 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
121 ContextOnuNewEqd = "new-eqd"
122 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
123 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
124 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
125 ContextOltPonIntfOperState = "oper-state"
126 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
127 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
128 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
129 ContextOnuDelineationErrors = "delineation-errors"
130 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
131 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530132 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
133 ContextOltPonTechnology = "pon-technology"
134 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
135 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100136)
137
Devmalya Paulfb990a52019-07-09 10:01:49 -0400138// OpenOltEventMgr struct contains
139type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530140 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400141 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400142}
143
144// 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 +0530145func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400146 var em OpenOltEventMgr
147 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400148 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400149 return &em
150}
151
152// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500153// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400154func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530155 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400156 switch alarmInd.Data.(type) {
157 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
159 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400163 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400166 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400169 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
174 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400175 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000176 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
177 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530178 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000179 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
180 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400181 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000182 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
183 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530184 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000185 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
186 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530187 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000188 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
189 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500190 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000191 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
192 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500193 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000194 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
195 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500196 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000197 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
198 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500199 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000200 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
201 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400202 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000203 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
204 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400205 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530206 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400207 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530208 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400209 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530210 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400211}
212
Gamze Abaka07868a52020-12-17 14:19:28 +0000213func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
214 if device == nil {
215 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
216 return
217 }
218 var de voltha.DeviceEvent
219 context := make(map[string]string)
220 context[ContextOltOperState] = device.OperStatus.String()
221 context[ContextOltAdminState] = device.AdminState.String()
222 context[ContextOltVendor] = device.Vendor
223 context[ContextOltConnectState] = device.ConnectStatus.String()
224 context[ContextOltType] = device.Type
225 context[ContextOltParentID] = device.ParentId
226 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
227 context[ContextDeviceID] = device.Id
228 context[ContextOltFirmwareVersion] = device.FirmwareVersion
229 context[ContextOltHardwareVersion] = device.HardwareVersion
230 context[ContextOltSerialNumber] = device.SerialNumber
231 context[ContextOltMacAddress] = device.MacAddress
232 de.Context = context
233 de.ResourceId = device.Id
234
235 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
236 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
237 } else {
238 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
239 }
240
241 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
242 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
243 }
244 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
245 log.Fields{
246 "device-id": device.Id,
247 "connect-status": device.ConnectStatus,
248 })
249}
250
Daniele Rossi051466a2019-07-26 13:39:37 +0000251// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000252func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000253 var de voltha.DeviceEvent
254 context := make(map[string]string)
255 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100256 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000257 /* Populating device event body */
258 de.Context = context
259 de.ResourceId = deviceID
mgouda86543582025-10-29 20:58:16 +0530260 switch oltIndication.OperState {
261 case operationStateDown:
Daniele Rossi051466a2019-07-26 13:39:37 +0000262 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
mgouda86543582025-10-29 20:58:16 +0530263 case operationStateUp:
Daniele Rossi051466a2019-07-26 13:39:37 +0000264 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
265 }
266 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400267 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000268 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000269 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000270 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530271 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000272}
273
Devmalya Paulfb990a52019-07-09 10:01:49 -0400274// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000275func (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 -0400276 var de voltha.DeviceEvent
277 context := make(map[string]string)
278 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100279 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
280 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
281 context[ContextOnuSerialNumber] = serialNumber
282 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530283 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
284 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400285 /* Populating device event body */
286 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100287 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400288 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
289 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530290 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530291 return olterrors.NewErrCommunication("send-onu-discovery-event",
292 log.Fields{
293 "serial-number": serialNumber,
294 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400295 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000296 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530297 log.Fields{
298 "serial-number": serialNumber,
299 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530300 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400301}
302
Neha Sharma96b7bf22020-06-15 10:37:32 +0000303func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530304 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530306 var alarmInd oop.OnuAlarmIndication
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700307 ponIntdID := plt.PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530308
Devmalya Paulfb990a52019-07-09 10:01:49 -0400309 context := make(map[string]string)
310 /* Populating event context */
yasin sapli0b242942021-10-11 08:51:16 +0000311 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(ponIntdID), base10)
Abhilash Laxmeshwar42b58242021-11-24 19:27:25 +0530312 context[ContextOltPortLabel], _ = GetportLabel(oltLos.IntfId, voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400313 /* Populating device event body */
314 de.Context = context
315 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530316 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400317 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530318
319 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
320 with "los_status: on" should be raised for each Onu connected to the PON
321 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
322 for all the ONU's connected to PON on receiving LoSIndication for PON */
323 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
324 if onuInCache.(*OnuDevice).intfID == ponIntdID {
325 alarmInd.IntfId = ponIntdID
326 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
327 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000328 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530329 }
330 return true
331 })
332 if err != nil {
333 /* Return if any error encountered while processing ONU LoS Event*/
334 return err
335 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400336 } else {
337 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
338 }
339 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100340 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530341 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400342 }
yasin sapli0b242942021-10-11 08:51:16 +0000343 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": ponIntdID})
Naga Manjunath9546b912019-11-28 20:56:20 +0530344 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400345}
Akash Kankanala041a2122024-10-16 15:49:22 +0530346
Gustavo Silva41af9122022-10-11 11:05:13 -0300347func (em *OpenOltEventMgr) oltRebootFailedEvent(ctx context.Context, deviceID string, reason string, raisedTs int64) error {
348 de := voltha.DeviceEvent{
349 Context: map[string]string{ContextOltFailureReason: "olt-reboot-failed"},
350 ResourceId: deviceID,
351 DeviceEventName: fmt.Sprintf("%s_%s", oltRebootFailedEvent, "RAISE_EVENT")}
352 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT,
353 raisedTs); err != nil {
354 return olterrors.NewErrCommunication("send-olt-reboot-failed-event", log.Fields{
Akash Kankanala041a2122024-10-16 15:49:22 +0530355 "device-id": deviceID, "raised-ts": raisedTs, "reason": reason}, err)
Gustavo Silva41af9122022-10-11 11:05:13 -0300356 }
357 logger.Debugw(ctx, "olt-reboot-failed-event-sent-to-kafka", log.Fields{
Akash Kankanala041a2122024-10-16 15:49:22 +0530358 "device-id": deviceID, "raised-ts": raisedTs, "reason": reason})
Gustavo Silva41af9122022-10-11 11:05:13 -0300359 return nil
360}
Devmalya Paulfb990a52019-07-09 10:01:49 -0400361
kesavand0ef592c2022-03-16 12:34:24 +0530362func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) string {
Amit Ghosh502056b2020-07-15 09:15:48 +0100363 var serialNumber = ""
364 var onuDeviceID = ""
365 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530366 if onu, ok := em.handler.onus.Load(onu); ok {
367 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100368 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400369 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100370
ssiddiqui04386ee2021-08-23 21:58:25 +0530371 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100372 context[ContextOnuSerialNumber] = serialNumber
373 context[ContextOnuDeviceID] = onuDeviceID
kesavand0ef592c2022-03-16 12:34:24 +0530374 return onuDeviceID
Amit Ghosh502056b2020-07-15 09:15:48 +0100375}
376
377func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
378 var de voltha.DeviceEvent
379 context := make(map[string]string)
380 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530381 onuDeviceID := em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100382
383 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
384 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
385
Devmalya Paulfb990a52019-07-09 10:01:49 -0400386 /* Populating device event body */
387 de.Context = context
388 de.ResourceId = deviceID
Marcos Aurelio Carrero (Furukawa)1992f992023-11-14 14:31:40 -0300389
390 if dgi.Status == statusCheckOn {
391 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "RAISE_EVENT")
392 } else {
393 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "CLEAR_EVENT")
394 }
395
Devmalya Paulfb990a52019-07-09 10:01:49 -0400396 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530397 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530398 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400399 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000400 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530401 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400402}
403
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400404// wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000405func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530406 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
407 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000408 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530409
410 if onuAlarm.LosStatus == statusCheckOn {
411 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000412 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530413 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
414 return true
415 }
416 return false
417 }
418 }
419 return true
420}
421
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400422// wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000423func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530424 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
425 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000426 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530427
428 if onuAlarm.LosStatus == statusCheckOff {
429 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000430 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530431 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
432 return true
433 }
434 return false
435 }
436 }
437 return true
438}
439
440func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
441 var deviceEventName string
442 if onuAlarm.LosStatus == statusCheckOn {
443 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
444 } else if onuAlarm.LosStatus == statusCheckOff {
445 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
446 } else if onuAlarm.LobStatus == statusCheckOn {
447 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
448 } else if onuAlarm.LobStatus == statusCheckOff {
449 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
450 } else if onuAlarm.LopcMissStatus == statusCheckOn {
451 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
452 } else if onuAlarm.LopcMissStatus == statusCheckOff {
453 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
454 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
455 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
456 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
457 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
458 } else if onuAlarm.LofiStatus == statusCheckOn {
459 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
460 } else if onuAlarm.LofiStatus == statusCheckOff {
461 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
462 } else if onuAlarm.LoamiStatus == statusCheckOn {
463 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
464 } else if onuAlarm.LoamiStatus == statusCheckOff {
465 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
466 }
467 return deviceEventName
468}
469
Neha Sharma96b7bf22020-06-15 10:37:32 +0000470func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400471 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100472
Devmalya Paulfb990a52019-07-09 10:01:49 -0400473 context := make(map[string]string)
474 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100475 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
476 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
kesavand0ef592c2022-03-16 12:34:24 +0530477 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530478
Devmalya Paulfb990a52019-07-09 10:01:49 -0400479 /* Populating device event body */
480 de.Context = context
481 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530482 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
483
484 switch onuAlarm.LosStatus {
485 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000486 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530487 /* No need to raise Onu Los Event as it might have already raised
488 or Onu might have deleted */
489 return nil
490 }
491 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
492 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
493 /* Update onu device with LoS raised state as true */
494 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
495 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400496 onuInCache.(*OnuDevice).proxyDeviceID, true, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530497 }
498 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000499 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530500 /* No need to clear Onu Los Event as it might have already cleared
501 or Onu might have deleted */
502 return nil
503 }
504 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
505 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
506 /* Update onu device with LoS raised state as false */
507 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
508 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400509 onuInCache.(*OnuDevice).proxyDeviceID, false, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530510 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400511 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530512
Devmalya Paulfb990a52019-07-09 10:01:49 -0400513 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530514 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530515 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400516 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000517 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 +0530518 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400519}
520
kesavand7cf3a052020-08-28 12:49:18 +0530521func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400522 var de voltha.DeviceEvent
523 context := make(map[string]string)
524 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530525 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
526 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
527 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100528
kesavand0ef592c2022-03-16 12:34:24 +0530529 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100530
Devmalya Paulfb990a52019-07-09 10:01:49 -0400531 /* Populating device event body */
532 de.Context = context
533 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530534 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400535 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530536 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530537 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400538 }
kesavand7cf3a052020-08-28 12:49:18 +0530539 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 +0530540 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400541}
542
Neha Sharma96b7bf22020-06-15 10:37:32 +0000543func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400544 var de voltha.DeviceEvent
545 context := make(map[string]string)
546 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100547 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
548 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
549
kesavand0ef592c2022-03-16 12:34:24 +0530550 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100551
Devmalya Paulfb990a52019-07-09 10:01:49 -0400552 /* Populating device event body */
553 de.Context = context
554 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530555 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400556 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
557 } else {
558 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
559 }
560 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530561 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530562 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400563 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000564 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 +0530565 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400566}
567
Neha Sharma96b7bf22020-06-15 10:37:32 +0000568func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400569 var de voltha.DeviceEvent
570 context := make(map[string]string)
571 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100572 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
573 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
574 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
575 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
576
kesavand0ef592c2022-03-16 12:34:24 +0530577 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100578
Devmalya Paulfb990a52019-07-09 10:01:49 -0400579 /* Populating device event body */
580 de.Context = context
581 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530582 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400583 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
584 } else {
585 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
586 }
587 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530588 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530589 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400590 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000591 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 +0530592 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400593}
594
Neha Sharma96b7bf22020-06-15 10:37:32 +0000595func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400596 var de voltha.DeviceEvent
597 context := make(map[string]string)
598 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100599 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
600 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
601 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
602
kesavand0ef592c2022-03-16 12:34:24 +0530603 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100604
Devmalya Paulfb990a52019-07-09 10:01:49 -0400605 /* Populating device event body */
606 de.Context = context
607 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530608 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400609 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
610 } else {
611 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
612 }
613 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530614 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530615 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400616 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000617 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 +0530618 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400619}
620
Neha Sharma96b7bf22020-06-15 10:37:32 +0000621func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400622 var de voltha.DeviceEvent
623 context := make(map[string]string)
624 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530625 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100626
627 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
628 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
629 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400630 /* Populating device event body */
631 de.Context = context
632 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530633 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400634 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
635 } else {
636 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
637 }
638 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530639 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530640 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400641 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000642 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 +0530643 return nil
644}
645
Neha Sharma96b7bf22020-06-15 10:37:32 +0000646func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530647 var de voltha.DeviceEvent
648 context := make(map[string]string)
649 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530650 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100651
652 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
653 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530654
655 /* Populating device event body */
656 de.Context = context
657 de.ResourceId = deviceID
658 if onuStartupFail.Status == statusCheckOn {
659 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
660 } else {
661 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
662 }
663 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530664 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530665 return err
666 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000667 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 +0530668 return nil
669}
670
Neha Sharma96b7bf22020-06-15 10:37:32 +0000671func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530672 var de voltha.DeviceEvent
673 context := make(map[string]string)
674 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530675 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100676
677 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
678 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530679 /* Populating device event body */
680 de.Context = context
681 de.ResourceId = deviceID
682 if onuLOKI.Status == statusCheckOn {
683 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
684 } else {
685 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
686 }
687
688 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530689 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530690 return err
691 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000692 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 +0530693 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400694}
kesavand39e0aa32020-01-28 20:58:50 -0500695
696// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400697func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700698 portNo := plt.IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
khenaidoodc2116e2021-10-19 17:33:19 -0400699 if port, err := em.handler.getPortFromCore(ctx, &ca.PortFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400700 DeviceId: deviceID,
701 Port: portNo,
702 }); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700703 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400704 } else if port.AdminState != common.AdminState_ENABLED {
705 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 -0400706 return
kesavand39e0aa32020-01-28 20:58:50 -0500707 }
708 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400709 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500710 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400711 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500712 de.Context = context
713 de.ResourceId = deviceID
714
715 if ifindication.GetOperState() == operationStateDown {
716 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
717 } else if ifindication.OperState == operationStateUp {
718 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "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_OLT, raisedTs); err != nil {
722 _ = 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)
723 return
kesavand39e0aa32020-01-28 20:58:50 -0500724 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000725 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500726}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500727
Neha Sharma96b7bf22020-06-15 10:37:32 +0000728func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500729 var de voltha.DeviceEvent
730 context := make(map[string]string)
731 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530732 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100733
734 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
735 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500736 /* Populating device event body */
737 de.Context = context
738 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400739 if onuDFI.Status == statusCheckOn {
740 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
741 } else {
742 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
743 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500744 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530745 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500746 return err
747 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000748 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 -0500749 return nil
750}
Amit Ghosh502056b2020-07-15 09:15:48 +0100751
Neha Sharma96b7bf22020-06-15 10:37:32 +0000752func (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 -0500753 /* Populating event context */
754 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100755 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
756 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
757 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500758 }
kesavand0ef592c2022-03-16 12:34:24 +0530759 onuDeviceID := em.populateContextWithSerialDeviceID(context, intfID, onuID)
Amit Ghosh502056b2020-07-15 09:15:48 +0100760
Devmalya Paul6f063a62020-02-19 19:19:06 -0500761 /* Populating device event body */
762 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400763 Context: context,
764 ResourceId: deviceID,
765 }
766 if status == statusCheckOn {
767 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
768 } else {
769 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500770 }
771 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530772 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500773 return err
774 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000775 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 -0400776 return nil
777}
778
Neha Sharma96b7bf22020-06-15 10:37:32 +0000779func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400780 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
781 if !found {
782 return errors.New("unknown-onu-device")
783 }
784 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
785 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000786 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400787 return err
788 }
789 onuDevice.(*OnuDevice).rdiRaised = true
790 return nil
791 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000792 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 -0400793 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000794 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400795 return err
796 }
797 onuDevice.(*OnuDevice).rdiRaised = false
798 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500799 return nil
800}
801
Neha Sharma96b7bf22020-06-15 10:37:32 +0000802func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500803 /* Populating event context */
804 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100805 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
806 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
807 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500808 }
kesavand0ef592c2022-03-16 12:34:24 +0530809 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100810
Devmalya Paul41a762d2020-03-01 18:56:54 -0500811 /* Populating device event body */
812 de := &voltha.DeviceEvent{
813 Context: context,
814 ResourceId: deviceID,
815 }
816 if onuGCD.Status == statusCheckOn {
817 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
818 } else {
819 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
820 }
821 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530822 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500823 return err
824 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000825 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 -0500826 return nil
827}
828
Neha Sharma96b7bf22020-06-15 10:37:32 +0000829func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500830 /* Populating event context */
831 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100832 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
833 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500834 }
kesavand0ef592c2022-03-16 12:34:24 +0530835 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500836 /* Populating device event body */
837 de := &voltha.DeviceEvent{
838 Context: context,
839 ResourceId: deviceID,
840 }
841 if onuErr.Status == statusCheckOn {
842 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
843 } else {
844 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
845 }
846 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530847 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500848 return err
849 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000850 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 -0500851 return nil
852}
853
Neha Sharma96b7bf22020-06-15 10:37:32 +0000854func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500855 /* Populating event context */
856 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100857 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
858 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500859 }
kesavand0ef592c2022-03-16 12:34:24 +0530860 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100861
Devmalya Paul41a762d2020-03-01 18:56:54 -0500862 /* Populating device event body */
863 de := &voltha.DeviceEvent{
864 Context: context,
865 ResourceId: deviceID,
866 }
867 if onuLOA.Status == statusCheckOn {
868 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
869 } else {
870 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
871 }
872 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530873 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500874 return err
875 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000876 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 -0500877 return nil
878}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400879
Neha Sharma96b7bf22020-06-15 10:37:32 +0000880func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400881 /* Populating event context */
882 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100883 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
884 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
885 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400886 }
kesavand0ef592c2022-03-16 12:34:24 +0530887 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100888
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400889 /* Populating device event body */
890 de := &voltha.DeviceEvent{
891 Context: context,
892 ResourceId: deviceID,
893 }
894 if onuDRE.Status == statusCheckOn {
895 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
896 } else {
897 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
898 }
899 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530900 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400901 return err
902 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000903 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 -0400904 return nil
905}