blob: 07d2bd0237b2daa068e2cfa4d9944552e1ba0fbf [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017// Package core provides APIs for the openOLT adapter
18package core
Devmalya Paulfb990a52019-07-09 10:01:49 -040019
20import (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Devmalya Paula1efa642020-04-20 01:36:43 -040022 "errors"
Devmalya Paulfb990a52019-07-09 10:01:49 -040023 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053024 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053025
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"
Gamze Abaka07868a52020-12-17 14:19:28 +000044 oltCommFailure = "OLT_COMMUNICATION_FAILURE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050045 oltIndicationDown = "OLT_DOWN_INDICATION"
46 onuDyingGaspEvent = "ONU_DYING_GASP"
47 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
48 onuStartupFailEvent = "ONU_STARTUP_FAIL"
49 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
50 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
51 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050052 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
53 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
54 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
55 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
56 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
57 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
58 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
59 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
60 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
61 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040062 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040063)
64
65const (
Naga Manjunath9546b912019-11-28 20:56:20 +053066 // statusCheckOn represents status check On
67 statusCheckOn = "on"
68 // statusCheckOff represents status check Off
69 statusCheckOff = "off"
70 // operationStateUp represents operation state Up
71 operationStateUp = "up"
72 // operationStateDown represents operation state Down
73 operationStateDown = "down"
74 // base10 represents base 10 conversion
75 base10 = 10
76)
77
Amit Ghosh502056b2020-07-15 09:15:48 +010078const (
Gamze Abaka07868a52020-12-17 14:19:28 +000079 // ContextOltAdminState is for the admin state of the Olt in the context of the event
80 ContextOltAdminState = "admin-state"
81 // ContextOltConnectState is for the connect state of the Olt in the context of the event
82 ContextOltConnectState = "connect-state"
Amit Ghosh502056b2020-07-15 09:15:48 +010083 // ContextOltOperState is for the operational state of the Olt in the context of the event
84 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000085 // ContextOltVendor is for the Olt vendor in the context of the event
86 ContextOltVendor = "vendor"
87 // ContextOltType is for the Olt type in the context of the event
88 ContextOltType = "type"
89 // ContextOltParentID is for the Olt parent id in the context of the event
90 ContextOltParentID = "parent-id"
91 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
92 ContextOltParentPortNo = "parent-port-no"
93 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
94 ContextOltFirmwareVersion = "firmware-version"
95 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
96 ContextOltHardwareVersion = "hardware-version"
97 // ContextOltSerialNumber is for the serial number of the OLT
98 ContextOltSerialNumber = "serial-number"
99 // ContextOltMacAddress is for the OLT mac address
100 ContextOltMacAddress = "mac-address"
101 // ContextDeviceID is for the device id in the context of the event
102 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100103 // ContextOnuOnuID is for the Onu Id in the context of the event
104 ContextOnuOnuID = "onu-id"
105 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
106 ContextOnuPonIntfID = "intf-id"
107 // ContextOnuSerialNumber is for the serial number of the ONU
108 ContextOnuSerialNumber = "serial-number"
109 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
110 ContextOnuDeviceID = "onu-device-id"
111 // ContextOltPonIntfID is for the PON interface Id on an OLT event
112 ContextOltPonIntfID = "intf-id"
113 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
114 ContextOnuFailureReaseon = "fail-reason"
115 // ContextOnuDrift is for the drift of an ONU in the context of an event
116 ContextOnuDrift = "drift"
117 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
118 ContextOnuNewEqd = "new-eqd"
119 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
120 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
121 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
122 ContextOltPonIntfOperState = "oper-state"
123 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
124 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
125 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
126 ContextOnuDelineationErrors = "delineation-errors"
127 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
128 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530129 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
130 ContextOltPonTechnology = "pon-technology"
131 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
132 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100133)
134
Devmalya Paulfb990a52019-07-09 10:01:49 -0400135// OpenOltEventMgr struct contains
136type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530137 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400138 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400139}
140
141// 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 +0530142func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400143 var em OpenOltEventMgr
144 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400145 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400146 return &em
147}
148
149// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500150// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400151func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530152 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400153 switch alarmInd.Data.(type) {
154 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000155 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
156 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400157 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
159 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400163 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400166 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400169 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400172 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
174 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530175 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000176 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
177 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400178 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000179 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
180 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530181 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000182 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
183 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530184 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000185 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
186 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500187 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000188 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
189 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500190 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000191 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
192 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500193 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000194 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
195 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500196 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000197 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
198 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400199 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000200 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
201 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400202 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530203 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400204 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530205 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400206 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530207 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400208}
209
Gamze Abaka07868a52020-12-17 14:19:28 +0000210func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
211 if device == nil {
212 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
213 return
214 }
215 var de voltha.DeviceEvent
216 context := make(map[string]string)
217 context[ContextOltOperState] = device.OperStatus.String()
218 context[ContextOltAdminState] = device.AdminState.String()
219 context[ContextOltVendor] = device.Vendor
220 context[ContextOltConnectState] = device.ConnectStatus.String()
221 context[ContextOltType] = device.Type
222 context[ContextOltParentID] = device.ParentId
223 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
224 context[ContextDeviceID] = device.Id
225 context[ContextOltFirmwareVersion] = device.FirmwareVersion
226 context[ContextOltHardwareVersion] = device.HardwareVersion
227 context[ContextOltSerialNumber] = device.SerialNumber
228 context[ContextOltMacAddress] = device.MacAddress
229 de.Context = context
230 de.ResourceId = device.Id
231
232 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
233 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
234 } else {
235 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
236 }
237
238 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
239 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
240 }
241 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
242 log.Fields{
243 "device-id": device.Id,
244 "connect-status": device.ConnectStatus,
245 })
246}
247
Daniele Rossi051466a2019-07-26 13:39:37 +0000248// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000249func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000250 var de voltha.DeviceEvent
251 context := make(map[string]string)
252 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100253 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000254 /* Populating device event body */
255 de.Context = context
256 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530257 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000258 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530259 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000260 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
261 }
262 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400263 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000264 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000265 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000266 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530267 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000268}
269
Devmalya Paulfb990a52019-07-09 10:01:49 -0400270// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000271func (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 -0400272 var de voltha.DeviceEvent
273 context := make(map[string]string)
274 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100275 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
276 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
277 context[ContextOnuSerialNumber] = serialNumber
278 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530279 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
280 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400281 /* Populating device event body */
282 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100283 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400284 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
285 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530286 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530287 return olterrors.NewErrCommunication("send-onu-discovery-event",
288 log.Fields{
289 "serial-number": serialNumber,
290 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400291 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000292 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530293 log.Fields{
294 "serial-number": serialNumber,
295 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530296 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400297}
298
Neha Sharma96b7bf22020-06-15 10:37:32 +0000299func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530300 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400301 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530302 var alarmInd oop.OnuAlarmIndication
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700303 ponIntdID := plt.PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530304
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305 context := make(map[string]string)
306 /* Populating event context */
yasin sapli0b242942021-10-11 08:51:16 +0000307 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(ponIntdID), base10)
Abhilash Laxmeshwar42b58242021-11-24 19:27:25 +0530308 context[ContextOltPortLabel], _ = GetportLabel(oltLos.IntfId, voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400309 /* Populating device event body */
310 de.Context = context
311 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530312 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400313 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530314
315 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
316 with "los_status: on" should be raised for each Onu connected to the PON
317 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
318 for all the ONU's connected to PON on receiving LoSIndication for PON */
319 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
320 if onuInCache.(*OnuDevice).intfID == ponIntdID {
321 alarmInd.IntfId = ponIntdID
322 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
323 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000324 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530325 }
326 return true
327 })
328 if err != nil {
329 /* Return if any error encountered while processing ONU LoS Event*/
330 return err
331 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400332 } else {
333 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
334 }
335 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100336 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530337 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400338 }
yasin sapli0b242942021-10-11 08:51:16 +0000339 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": ponIntdID})
Naga Manjunath9546b912019-11-28 20:56:20 +0530340 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400341}
342
kesavand0ef592c2022-03-16 12:34:24 +0530343func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) string {
Amit Ghosh502056b2020-07-15 09:15:48 +0100344 var serialNumber = ""
345 var onuDeviceID = ""
346 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530347 if onu, ok := em.handler.onus.Load(onu); ok {
348 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100349 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400350 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100351
ssiddiqui04386ee2021-08-23 21:58:25 +0530352 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100353 context[ContextOnuSerialNumber] = serialNumber
354 context[ContextOnuDeviceID] = onuDeviceID
kesavand0ef592c2022-03-16 12:34:24 +0530355 return onuDeviceID
Amit Ghosh502056b2020-07-15 09:15:48 +0100356}
357
358func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
359 var de voltha.DeviceEvent
360 context := make(map[string]string)
361 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530362 onuDeviceID := em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100363
364 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
365 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
366
Devmalya Paulfb990a52019-07-09 10:01:49 -0400367 /* Populating device event body */
368 de.Context = context
369 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530370 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400371 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530372 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530373 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400374 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000375 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530376 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400377}
378
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530379//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000380func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530381 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
382 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000383 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530384
385 if onuAlarm.LosStatus == statusCheckOn {
386 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000387 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530388 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
389 return true
390 }
391 return false
392 }
393 }
394 return true
395}
396
397//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000398func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530399 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
400 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000401 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530402
403 if onuAlarm.LosStatus == statusCheckOff {
404 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000405 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530406 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
407 return true
408 }
409 return false
410 }
411 }
412 return true
413}
414
415func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
416 var deviceEventName string
417 if onuAlarm.LosStatus == statusCheckOn {
418 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
419 } else if onuAlarm.LosStatus == statusCheckOff {
420 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
421 } else if onuAlarm.LobStatus == statusCheckOn {
422 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
423 } else if onuAlarm.LobStatus == statusCheckOff {
424 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
425 } else if onuAlarm.LopcMissStatus == statusCheckOn {
426 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
427 } else if onuAlarm.LopcMissStatus == statusCheckOff {
428 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
429 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
430 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
431 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
432 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
433 } else if onuAlarm.LofiStatus == statusCheckOn {
434 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
435 } else if onuAlarm.LofiStatus == statusCheckOff {
436 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
437 } else if onuAlarm.LoamiStatus == statusCheckOn {
438 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
439 } else if onuAlarm.LoamiStatus == statusCheckOff {
440 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
441 }
442 return deviceEventName
443}
444
Neha Sharma96b7bf22020-06-15 10:37:32 +0000445func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400446 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100447
Devmalya Paulfb990a52019-07-09 10:01:49 -0400448 context := make(map[string]string)
449 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100450 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
451 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
kesavand0ef592c2022-03-16 12:34:24 +0530452 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530453
Devmalya Paulfb990a52019-07-09 10:01:49 -0400454 /* Populating device event body */
455 de.Context = context
456 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530457 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
458
459 switch onuAlarm.LosStatus {
460 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000461 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530462 /* No need to raise Onu Los Event as it might have already raised
463 or Onu might have deleted */
464 return nil
465 }
466 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
467 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
468 /* Update onu device with LoS raised state as true */
469 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
470 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400471 onuInCache.(*OnuDevice).proxyDeviceID, true, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530472 }
473 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000474 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530475 /* No need to clear Onu Los Event as it might have already cleared
476 or Onu might have deleted */
477 return nil
478 }
479 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
480 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
481 /* Update onu device with LoS raised state as false */
482 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
483 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
khenaidoo106c61a2021-08-11 18:05:46 -0400484 onuInCache.(*OnuDevice).proxyDeviceID, false, onuInCache.(*OnuDevice).adapterEndpoint))
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530485 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400486 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530487
Devmalya Paulfb990a52019-07-09 10:01:49 -0400488 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530489 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530490 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400491 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000492 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 +0530493 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400494}
495
kesavand7cf3a052020-08-28 12:49:18 +0530496func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400497 var de voltha.DeviceEvent
498 context := make(map[string]string)
499 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530500 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
501 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
502 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100503
kesavand0ef592c2022-03-16 12:34:24 +0530504 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100505
Devmalya Paulfb990a52019-07-09 10:01:49 -0400506 /* Populating device event body */
507 de.Context = context
508 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530509 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400510 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530511 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530512 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400513 }
kesavand7cf3a052020-08-28 12:49:18 +0530514 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 +0530515 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400516}
517
Neha Sharma96b7bf22020-06-15 10:37:32 +0000518func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400519 var de voltha.DeviceEvent
520 context := make(map[string]string)
521 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100522 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
523 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
524
kesavand0ef592c2022-03-16 12:34:24 +0530525 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100526
Devmalya Paulfb990a52019-07-09 10:01:49 -0400527 /* Populating device event body */
528 de.Context = context
529 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530530 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400531 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
532 } else {
533 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
534 }
535 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530536 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530537 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400538 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000539 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 +0530540 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400541}
542
Neha Sharma96b7bf22020-06-15 10:37:32 +0000543func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, 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(onuDriftWindow.IntfId), base10)
548 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
549 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
550 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
551
kesavand0ef592c2022-03-16 12:34:24 +0530552 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100553
Devmalya Paulfb990a52019-07-09 10:01:49 -0400554 /* Populating device event body */
555 de.Context = context
556 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530557 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400558 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
559 } else {
560 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
561 }
562 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530563 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530564 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400565 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000566 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 +0530567 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400568}
569
Neha Sharma96b7bf22020-06-15 10:37:32 +0000570func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400571 var de voltha.DeviceEvent
572 context := make(map[string]string)
573 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100574 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
575 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
576 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
577
kesavand0ef592c2022-03-16 12:34:24 +0530578 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100579
Devmalya Paulfb990a52019-07-09 10:01:49 -0400580 /* Populating device event body */
581 de.Context = context
582 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530583 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400584 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
585 } else {
586 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
587 }
588 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530589 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530590 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400591 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000592 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 +0530593 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400594}
595
Neha Sharma96b7bf22020-06-15 10:37:32 +0000596func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400597 var de voltha.DeviceEvent
598 context := make(map[string]string)
599 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530600 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100601
602 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
603 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
604 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
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 onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400609 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
610 } else {
611 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "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-signals-fail-event-sent-to-kafka", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530618 return nil
619}
620
Neha Sharma96b7bf22020-06-15 10:37:32 +0000621func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530622 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, onuStartupFail.IntfId, onuStartupFail.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100626
627 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
628 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530629
630 /* Populating device event body */
631 de.Context = context
632 de.ResourceId = deviceID
633 if onuStartupFail.Status == statusCheckOn {
634 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
635 } else {
636 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "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_PON, raisedTs, onuDeviceID); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530640 return err
641 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000642 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 +0530643 return nil
644}
645
Neha Sharma96b7bf22020-06-15 10:37:32 +0000646func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +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, onuLOKI.IntfId, onuLOKI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100651
652 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
653 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530654 /* Populating device event body */
655 de.Context = context
656 de.ResourceId = deviceID
657 if onuLOKI.Status == statusCheckOn {
658 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
659 } else {
660 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
661 }
662
663 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530664 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530665 return err
666 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000667 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 +0530668 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400669}
kesavand39e0aa32020-01-28 20:58:50 -0500670
671// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400672func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700673 portNo := plt.IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
khenaidoodc2116e2021-10-19 17:33:19 -0400674 if port, err := em.handler.getPortFromCore(ctx, &ca.PortFilter{
khenaidoo106c61a2021-08-11 18:05:46 -0400675 DeviceId: deviceID,
676 Port: portNo,
677 }); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700678 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400679 } else if port.AdminState != common.AdminState_ENABLED {
680 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 -0400681 return
kesavand39e0aa32020-01-28 20:58:50 -0500682 }
683 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400684 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500685 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400686 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500687 de.Context = context
688 de.ResourceId = deviceID
689
690 if ifindication.GetOperState() == operationStateDown {
691 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
692 } else if ifindication.OperState == operationStateUp {
693 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
694 }
695 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400696 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
697 _ = 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)
698 return
kesavand39e0aa32020-01-28 20:58:50 -0500699 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000700 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500701}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500702
Neha Sharma96b7bf22020-06-15 10:37:32 +0000703func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500704 var de voltha.DeviceEvent
705 context := make(map[string]string)
706 /* Populating event context */
kesavand0ef592c2022-03-16 12:34:24 +0530707 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100708
709 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
710 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500711 /* Populating device event body */
712 de.Context = context
713 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400714 if onuDFI.Status == statusCheckOn {
715 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
716 } else {
717 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
718 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500719 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530720 if err := em.eventProxy.SendDeviceEventWithKey(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500721 return err
722 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000723 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 -0500724 return nil
725}
Amit Ghosh502056b2020-07-15 09:15:48 +0100726
Neha Sharma96b7bf22020-06-15 10:37:32 +0000727func (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 -0500728 /* Populating event context */
729 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100730 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
731 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
732 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500733 }
kesavand0ef592c2022-03-16 12:34:24 +0530734 onuDeviceID := em.populateContextWithSerialDeviceID(context, intfID, onuID)
Amit Ghosh502056b2020-07-15 09:15:48 +0100735
Devmalya Paul6f063a62020-02-19 19:19:06 -0500736 /* Populating device event body */
737 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400738 Context: context,
739 ResourceId: deviceID,
740 }
741 if status == statusCheckOn {
742 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
743 } else {
744 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500745 }
746 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530747 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500748 return err
749 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000750 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 -0400751 return nil
752}
753
Neha Sharma96b7bf22020-06-15 10:37:32 +0000754func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400755 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
756 if !found {
757 return errors.New("unknown-onu-device")
758 }
759 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
760 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000761 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400762 return err
763 }
764 onuDevice.(*OnuDevice).rdiRaised = true
765 return nil
766 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000767 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 -0400768 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000769 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400770 return err
771 }
772 onuDevice.(*OnuDevice).rdiRaised = false
773 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500774 return nil
775}
776
Neha Sharma96b7bf22020-06-15 10:37:32 +0000777func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500778 /* Populating event context */
779 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100780 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
781 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
782 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500783 }
kesavand0ef592c2022-03-16 12:34:24 +0530784 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100785
Devmalya Paul41a762d2020-03-01 18:56:54 -0500786 /* Populating device event body */
787 de := &voltha.DeviceEvent{
788 Context: context,
789 ResourceId: deviceID,
790 }
791 if onuGCD.Status == statusCheckOn {
792 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
793 } else {
794 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
795 }
796 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530797 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500798 return err
799 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000800 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 -0500801 return nil
802}
803
Neha Sharma96b7bf22020-06-15 10:37:32 +0000804func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500805 /* Populating event context */
806 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100807 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
808 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500809 }
kesavand0ef592c2022-03-16 12:34:24 +0530810 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
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 onuErr.Status == statusCheckOn {
817 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
818 } else {
819 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
820 }
821 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530822 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, 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-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuErr.OnuId, "intf-id": onuErr.IntfId})
Devmalya Paul41a762d2020-03-01 18:56:54 -0500826 return nil
827}
828
Neha Sharma96b7bf22020-06-15 10:37:32 +0000829func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, 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(onuLOA.OnuId), base10),
833 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500834 }
kesavand0ef592c2022-03-16 12:34:24 +0530835 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100836
Devmalya Paul41a762d2020-03-01 18:56:54 -0500837 /* Populating device event body */
838 de := &voltha.DeviceEvent{
839 Context: context,
840 ResourceId: deviceID,
841 }
842 if onuLOA.Status == statusCheckOn {
843 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
844 } else {
845 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
846 }
847 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530848 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500849 return err
850 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000851 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 -0500852 return nil
853}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400854
Neha Sharma96b7bf22020-06-15 10:37:32 +0000855func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400856 /* Populating event context */
857 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100858 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
859 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
860 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400861 }
kesavand0ef592c2022-03-16 12:34:24 +0530862 onuDeviceID := em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100863
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400864 /* Populating device event body */
865 de := &voltha.DeviceEvent{
866 Context: context,
867 ResourceId: deviceID,
868 }
869 if onuDRE.Status == statusCheckOn {
870 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
871 } else {
872 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
873 }
874 /* Send event to KAFKA */
kesavand0ef592c2022-03-16 12:34:24 +0530875 if err := em.eventProxy.SendDeviceEventWithKey(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs, onuDeviceID); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400876 return err
877 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000878 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 -0400879 return nil
880}