blob: e72668e1d922ffc4d93cbe37a2a6cc3615953e3f [file] [log] [blame]
Devmalya Paulfb990a52019-07-09 10:01:49 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017// Package core provides APIs for the openOLT adapter
18package core
Devmalya Paulfb990a52019-07-09 10:01:49 -040019
20import (
Neha Sharma96b7bf22020-06-15 10:37:32 +000021 "context"
Devmalya Paula1efa642020-04-20 01:36:43 -040022 "errors"
Devmalya Paulfb990a52019-07-09 10:01:49 -040023 "fmt"
Naga Manjunath9546b912019-11-28 20:56:20 +053024 "strconv"
Naga Manjunatha8dc9372019-10-31 23:01:18 +053025
Girish Gowdra4c3d4602021-07-22 16:33:37 -070026 "github.com/opencord/voltha-lib-go/v6/pkg/events/eventif"
27 "github.com/opencord/voltha-lib-go/v6/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070029 "github.com/opencord/voltha-protos/v4/go/common"
30 oop "github.com/opencord/voltha-protos/v4/go/openolt"
31 "github.com/opencord/voltha-protos/v4/go/voltha"
Devmalya Paulfb990a52019-07-09 10:01:49 -040032)
33
34const (
Devmalya Paul41a762d2020-03-01 18:56:54 -050035 onuDiscoveryEvent = "ONU_DISCOVERY"
36 onuLosEvent = "ONU_LOSS_OF_SIGNAL"
37 onuLobEvent = "ONU_LOSS_OF_BURST"
38 onuLopcMissEvent = "ONU_LOPC_MISS"
39 onuLopcMicErrorEvent = "ONU_LOPC_MIC_ERROR"
40 oltLosEvent = "OLT_LOSS_OF_SIGNAL"
Gamze Abaka07868a52020-12-17 14:19:28 +000041 oltCommFailure = "OLT_COMMUNICATION_FAILURE"
Devmalya Paul41a762d2020-03-01 18:56:54 -050042 oltIndicationDown = "OLT_DOWN_INDICATION"
43 onuDyingGaspEvent = "ONU_DYING_GASP"
44 onuSignalsFailEvent = "ONU_SIGNALS_FAIL"
45 onuStartupFailEvent = "ONU_STARTUP_FAIL"
46 onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
47 onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
48 onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
Devmalya Paul41a762d2020-03-01 18:56:54 -050049 onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
50 onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
51 onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
52 onuLossOfPloamEvent = "ONU_LOSS_OF_PLOAM"
53 ponIntfDownIndiction = "OLT_PON_INTERFACE_DOWN"
54 onuDeactivationFailureEvent = "ONU_DEACTIVATION_FAILURE"
55 onuRemoteDefectIndication = "ONU_REMOTE_DEFECT"
56 onuLossOfGEMChannelDelineationEvent = "ONU_LOSS_OF_GEM_CHANNEL_DELINEATION"
57 onuPhysicalEquipmentErrorEvent = "ONU_PHYSICAL_EQUIPMENT_ERROR"
58 onuLossOfAcknowledgementEvent = "ONU_LOSS_OF_ACKNOWLEDGEMENT"
Devmalya Pauleb5294e2020-03-19 03:01:39 -040059 onuDifferentialReachExceededEvent = "ONU_DIFFERENTIAL_REACH_EXCEEDED"
Devmalya Paulfb990a52019-07-09 10:01:49 -040060)
61
62const (
Naga Manjunath9546b912019-11-28 20:56:20 +053063 // statusCheckOn represents status check On
64 statusCheckOn = "on"
65 // statusCheckOff represents status check Off
66 statusCheckOff = "off"
67 // operationStateUp represents operation state Up
68 operationStateUp = "up"
69 // operationStateDown represents operation state Down
70 operationStateDown = "down"
71 // base10 represents base 10 conversion
72 base10 = 10
73)
74
Amit Ghosh502056b2020-07-15 09:15:48 +010075const (
Gamze Abaka07868a52020-12-17 14:19:28 +000076 // ContextOltAdminState is for the admin state of the Olt in the context of the event
77 ContextOltAdminState = "admin-state"
78 // ContextOltConnectState is for the connect state of the Olt in the context of the event
79 ContextOltConnectState = "connect-state"
Amit Ghosh502056b2020-07-15 09:15:48 +010080 // ContextOltOperState is for the operational state of the Olt in the context of the event
81 ContextOltOperState = "oper-state"
Gamze Abaka07868a52020-12-17 14:19:28 +000082 // ContextOltVendor is for the Olt vendor in the context of the event
83 ContextOltVendor = "vendor"
84 // ContextOltType is for the Olt type in the context of the event
85 ContextOltType = "type"
86 // ContextOltParentID is for the Olt parent id in the context of the event
87 ContextOltParentID = "parent-id"
88 // ContextOltParentPortNo is for the Olt parent port no in the context of the event
89 ContextOltParentPortNo = "parent-port-no"
90 // ContextOltFirmwareVersion is for the Olt firmware version in the context of the event
91 ContextOltFirmwareVersion = "firmware-version"
92 // ContextOltHardwareVersion is for the Olt hardware version in the context of the event
93 ContextOltHardwareVersion = "hardware-version"
94 // ContextOltSerialNumber is for the serial number of the OLT
95 ContextOltSerialNumber = "serial-number"
96 // ContextOltMacAddress is for the OLT mac address
97 ContextOltMacAddress = "mac-address"
98 // ContextDeviceID is for the device id in the context of the event
99 ContextDeviceID = "id"
Amit Ghosh502056b2020-07-15 09:15:48 +0100100 // ContextOnuOnuID is for the Onu Id in the context of the event
101 ContextOnuOnuID = "onu-id"
102 // ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
103 ContextOnuPonIntfID = "intf-id"
104 // ContextOnuSerialNumber is for the serial number of the ONU
105 ContextOnuSerialNumber = "serial-number"
106 // ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
107 ContextOnuDeviceID = "onu-device-id"
108 // ContextOltPonIntfID is for the PON interface Id on an OLT event
109 ContextOltPonIntfID = "intf-id"
110 // ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
111 ContextOnuFailureReaseon = "fail-reason"
112 // ContextOnuDrift is for the drift of an ONU in the context of an event
113 ContextOnuDrift = "drift"
114 // ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
115 ContextOnuNewEqd = "new-eqd"
116 // ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
117 ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
118 // ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
119 ContextOltPonIntfOperState = "oper-state"
120 // ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
121 ContextOnuRemoteDefectIndicatorCount = "rdi-count"
122 // ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
123 ContextOnuDelineationErrors = "delineation-errors"
124 // ContextOnuDifferentialDistance is for the differential distance in an ONU event context
125 ContextOnuDifferentialDistance = "differential-distance"
ssiddiqui04386ee2021-08-23 21:58:25 +0530126 // ContextOltPonTechnology is to indicate the pon-technology type, ie, 'GPON' or 'XGS-PON' (TODO check for combo?)
127 ContextOltPonTechnology = "pon-technology"
128 // ContextOltPortLabel is to indicate the string label of the pon-port, example: pon-0
129 ContextOltPortLabel = "port-label"
Amit Ghosh502056b2020-07-15 09:15:48 +0100130)
131
Devmalya Paulfb990a52019-07-09 10:01:49 -0400132// OpenOltEventMgr struct contains
133type OpenOltEventMgr struct {
Himani Chawlacd407802020-12-10 12:08:59 +0530134 eventProxy eventif.EventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400135 handler *DeviceHandler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400136}
137
138// 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 +0530139func NewEventMgr(eventProxy eventif.EventProxy, handler *DeviceHandler) *OpenOltEventMgr {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400140 var em OpenOltEventMgr
141 em.eventProxy = eventProxy
Devmalya Paul90ca3012019-09-02 21:55:45 -0400142 em.handler = handler
Devmalya Paulfb990a52019-07-09 10:01:49 -0400143 return &em
144}
145
146// ProcessEvents is function to process and publish OpenOLT event
Devmalya Paul41a762d2020-03-01 18:56:54 -0500147// nolint: gocyclo
Kent Hagermane6ff1012020-07-14 15:07:53 -0400148func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
Naga Manjunath9546b912019-11-28 20:56:20 +0530149 var err error
Devmalya Paulfb990a52019-07-09 10:01:49 -0400150 switch alarmInd.Data.(type) {
151 case *oop.AlarmIndication_LosInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000152 logger.Debugw(ctx, "received-los-indication", log.Fields{"alarm-ind": alarmInd})
153 err = em.oltLosIndication(ctx, alarmInd.GetLosInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400154 case *oop.AlarmIndication_OnuAlarmInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000155 logger.Debugw(ctx, "received-onu-alarm-indication ", log.Fields{"alarm-ind": alarmInd})
156 err = em.onuAlarmIndication(ctx, alarmInd.GetOnuAlarmInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400157 case *oop.AlarmIndication_DyingGaspInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000158 logger.Debugw(ctx, "received-dying-gasp-indication", log.Fields{"alarm-ind": alarmInd})
159 err = em.onuDyingGaspIndication(ctx, alarmInd.GetDyingGaspInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400160 case *oop.AlarmIndication_OnuLossOmciInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000161 logger.Debugw(ctx, "received-onu-loss-omci-indication ", log.Fields{"alarm-ind": alarmInd})
162 err = em.onuLossOmciIndication(ctx, alarmInd.GetOnuLossOmciInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400163 case *oop.AlarmIndication_OnuDriftOfWindowInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000164 logger.Debugw(ctx, "received-onu-drift-of-window-indication ", log.Fields{"alarm-ind": alarmInd})
165 err = em.onuDriftOfWindowIndication(ctx, alarmInd.GetOnuDriftOfWindowInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400166 case *oop.AlarmIndication_OnuSignalDegradeInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000167 logger.Debugw(ctx, "received-onu-signal-degrade-indication ", log.Fields{"alarm-ind": alarmInd})
168 err = em.onuSignalDegradeIndication(ctx, alarmInd.GetOnuSignalDegradeInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400169 case *oop.AlarmIndication_OnuSignalsFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debugw(ctx, "received-onu-signal-fail-indication ", log.Fields{"alarm-ind": alarmInd})
171 err = em.onuSignalsFailIndication(ctx, alarmInd.GetOnuSignalsFailInd(), deviceID, raisedTs)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530172 case *oop.AlarmIndication_OnuStartupFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debugw(ctx, "received-onu-startup-fail-indication ", log.Fields{"alarm-ind": alarmInd})
174 err = em.onuStartupFailedIndication(ctx, alarmInd.GetOnuStartupFailInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400175 case *oop.AlarmIndication_OnuTiwiInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000176 logger.Debugw(ctx, "received-onu-transmission-warning-indication ", log.Fields{"alarm-ind": alarmInd})
177 logger.Warnw(ctx, "not-implemented-yet", log.Fields{"alarm-ind": "Onu-Transmission-indication"})
Naga Manjunath9546b912019-11-28 20:56:20 +0530178 case *oop.AlarmIndication_OnuLossOfSyncFailInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000179 logger.Debugw(ctx, "received-onu-loss-of-sync-fail-indication ", log.Fields{"alarm-ind": alarmInd})
180 err = em.onuLossOfSyncIndication(ctx, alarmInd.GetOnuLossOfSyncFailInd(), deviceID, raisedTs)
Naga Manjunath9546b912019-11-28 20:56:20 +0530181 case *oop.AlarmIndication_OnuItuPonStatsInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000182 logger.Debugw(ctx, "received-onu-itu-pon-stats-indication ", log.Fields{"alarm-ind": alarmInd})
183 err = em.onuItuPonStatsIndication(ctx, alarmInd.GetOnuItuPonStatsInd(), deviceID, raisedTs)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500184 case *oop.AlarmIndication_OnuDeactivationFailureInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000185 logger.Debugw(ctx, "received-onu-deactivation-failure-indication ", log.Fields{"alarm-ind": alarmInd})
186 err = em.onuDeactivationFailureIndication(ctx, alarmInd.GetOnuDeactivationFailureInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500187 case *oop.AlarmIndication_OnuLossGemDelineationInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000188 logger.Debugw(ctx, "received-onu-loss-of-gem-channel-delineation-indication ", log.Fields{"alarm-ind": alarmInd})
189 err = em.onuLossOfGEMChannelDelineationIndication(ctx, alarmInd.GetOnuLossGemDelineationInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500190 case *oop.AlarmIndication_OnuPhysicalEquipmentErrorInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000191 logger.Debugw(ctx, "received-onu-physical-equipment-error-indication ", log.Fields{"alarm-ind": alarmInd})
192 err = em.onuPhysicalEquipmentErrorIndication(ctx, alarmInd.GetOnuPhysicalEquipmentErrorInd(), deviceID, raisedTs)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500193 case *oop.AlarmIndication_OnuLossOfAckInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000194 logger.Debugw(ctx, "received-onu-loss-of-acknowledgement-indication ", log.Fields{"alarm-ind": alarmInd})
195 err = em.onuLossOfAcknowledgementIndication(ctx, alarmInd.GetOnuLossOfAckInd(), deviceID, raisedTs)
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400196 case *oop.AlarmIndication_OnuDiffReachExceededInd:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000197 logger.Debugw(ctx, "received-onu-differential-reach-exceeded-indication ", log.Fields{"alarm-ind": alarmInd})
198 err = em.onuDifferentialReachExceededIndication(ctx, alarmInd.GetOnuDiffReachExceededInd(), deviceID, raisedTs)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400199 default:
Thomas Lee S94109f12020-03-03 16:39:29 +0530200 err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400201 }
Naga Manjunath9546b912019-11-28 20:56:20 +0530202 if err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400203 _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
Naga Manjunath9546b912019-11-28 20:56:20 +0530204 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400205}
206
Gamze Abaka07868a52020-12-17 14:19:28 +0000207func (em *OpenOltEventMgr) oltCommunicationEvent(ctx context.Context, device *voltha.Device, raisedTs int64) {
208 if device == nil {
209 logger.Warn(ctx, "device-is-nil-can't-send-olt-communication-failure-event")
210 return
211 }
212 var de voltha.DeviceEvent
213 context := make(map[string]string)
214 context[ContextOltOperState] = device.OperStatus.String()
215 context[ContextOltAdminState] = device.AdminState.String()
216 context[ContextOltVendor] = device.Vendor
217 context[ContextOltConnectState] = device.ConnectStatus.String()
218 context[ContextOltType] = device.Type
219 context[ContextOltParentID] = device.ParentId
220 context[ContextOltParentPortNo] = fmt.Sprintf("%d", device.ParentPortNo)
221 context[ContextDeviceID] = device.Id
222 context[ContextOltFirmwareVersion] = device.FirmwareVersion
223 context[ContextOltHardwareVersion] = device.HardwareVersion
224 context[ContextOltSerialNumber] = device.SerialNumber
225 context[ContextOltMacAddress] = device.MacAddress
226 de.Context = context
227 de.ResourceId = device.Id
228
229 if device.ConnectStatus == voltha.ConnectStatus_UNREACHABLE {
230 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "RAISE_EVENT")
231 } else {
232 de.DeviceEventName = fmt.Sprintf("%s_%s", oltCommFailure, "CLEAR_EVENT")
233 }
234
235 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
236 logger.Errorw(ctx, "failed-to-send-olt-comm-failure-event", log.Fields{"err": err})
237 }
238 logger.Debugw(ctx, "olt-comm-failure-event-sent-to-kafka",
239 log.Fields{
240 "device-id": device.Id,
241 "connect-status": device.ConnectStatus,
242 })
243}
244
Daniele Rossi051466a2019-07-26 13:39:37 +0000245// oltUpDownIndication handles Up and Down state of an OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000246func (em *OpenOltEventMgr) oltUpDownIndication(ctx context.Context, oltIndication *oop.OltIndication, deviceID string, raisedTs int64) error {
Daniele Rossi051466a2019-07-26 13:39:37 +0000247 var de voltha.DeviceEvent
248 context := make(map[string]string)
249 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100250 context[ContextOltOperState] = oltIndication.OperState
Daniele Rossi051466a2019-07-26 13:39:37 +0000251 /* Populating device event body */
252 de.Context = context
253 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530254 if oltIndication.OperState == operationStateDown {
Daniele Rossi051466a2019-07-26 13:39:37 +0000255 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "RAISE_EVENT")
Naga Manjunath9546b912019-11-28 20:56:20 +0530256 } else if oltIndication.OperState == operationStateUp {
Daniele Rossi051466a2019-07-26 13:39:37 +0000257 de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
258 }
259 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400260 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000261 return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
Daniele Rossi051466a2019-07-26 13:39:37 +0000262 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000263 logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
Naga Manjunath9546b912019-11-28 20:56:20 +0530264 return nil
Daniele Rossi051466a2019-07-26 13:39:37 +0000265}
266
Devmalya Paulfb990a52019-07-09 10:01:49 -0400267// OnuDiscoveryIndication is an exported method to handle ONU discovery event
Neha Sharma96b7bf22020-06-15 10:37:32 +0000268func (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 -0400269 var de voltha.DeviceEvent
270 context := make(map[string]string)
271 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100272 context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
273 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
274 context[ContextOnuSerialNumber] = serialNumber
275 context[ContextOnuDeviceID] = onuDeviceID
ssiddiqui04386ee2021-08-23 21:58:25 +0530276 context[ContextOltPonTechnology] = em.handler.getPonTechnology(onuDisc.IntfId)
277 context[ContextOltPortLabel], _ = GetportLabel(onuDisc.GetIntfId(), voltha.Port_PON_OLT)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400278 /* Populating device event body */
279 de.Context = context
Amit Ghosh75f0e292020-05-14 11:31:54 +0100280 de.ResourceId = oltDeviceID
Devmalya Paulfb990a52019-07-09 10:01:49 -0400281 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
282 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400283 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530284 return olterrors.NewErrCommunication("send-onu-discovery-event",
285 log.Fields{
286 "serial-number": serialNumber,
287 "intf-id": onuDisc.IntfId}, err)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400288 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000289 logger.Debugw(ctx, "onu-discovery-event-sent-to-kafka",
Shrey Baid26912972020-04-16 21:02:31 +0530290 log.Fields{
291 "serial-number": serialNumber,
292 "intf-id": onuDisc.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530293 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400294}
295
Neha Sharma96b7bf22020-06-15 10:37:32 +0000296func (em *OpenOltEventMgr) oltLosIndication(ctx context.Context, oltLos *oop.LosIndication, deviceID string, raisedTs int64) error {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530297 var err error = nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400298 var de voltha.DeviceEvent
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530299 var alarmInd oop.OnuAlarmIndication
300 ponIntdID := PortNoToIntfID(oltLos.IntfId, voltha.Port_PON_OLT)
301
Devmalya Paulfb990a52019-07-09 10:01:49 -0400302 context := make(map[string]string)
303 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100304 context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400305 /* Populating device event body */
306 de.Context = context
307 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530308 if oltLos.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400309 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "RAISE_EVENT")
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530310
311 /* When PON cable disconnected from OLT, it was expected OnuAlarmIndication
312 with "los_status: on" should be raised for each Onu connected to the PON
313 but BAL does not raise this Alarm hence manually sending OnuLosRaise event
314 for all the ONU's connected to PON on receiving LoSIndication for PON */
315 em.handler.onus.Range(func(Onukey interface{}, onuInCache interface{}) bool {
316 if onuInCache.(*OnuDevice).intfID == ponIntdID {
317 alarmInd.IntfId = ponIntdID
318 alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
319 alarmInd.LosStatus = statusCheckOn
Neha Sharma96b7bf22020-06-15 10:37:32 +0000320 err = em.onuAlarmIndication(ctx, &alarmInd, deviceID, raisedTs)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530321 }
322 return true
323 })
324 if err != nil {
325 /* Return if any error encountered while processing ONU LoS Event*/
326 return err
327 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400328 } else {
329 de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
330 }
331 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100332 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530333 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400334 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000335 logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530336 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400337}
338
Amit Ghosh502056b2020-07-15 09:15:48 +0100339func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
340 var serialNumber = ""
341 var onuDeviceID = ""
342 onu := em.handler.formOnuKey(intfID, onuID)
Naga Manjunatha8dc9372019-10-31 23:01:18 +0530343 if onu, ok := em.handler.onus.Load(onu); ok {
344 serialNumber = onu.(*OnuDevice).serialNumber
Amit Ghosh502056b2020-07-15 09:15:48 +0100345 onuDeviceID = onu.(*OnuDevice).deviceID
Devmalya Paul90ca3012019-09-02 21:55:45 -0400346 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100347
ssiddiqui04386ee2021-08-23 21:58:25 +0530348 context[ContextOltPortLabel], _ = GetportLabel(intfID, voltha.Port_PON_OLT)
Amit Ghosh502056b2020-07-15 09:15:48 +0100349 context[ContextOnuSerialNumber] = serialNumber
350 context[ContextOnuDeviceID] = onuDeviceID
351}
352
353func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
354 var de voltha.DeviceEvent
355 context := make(map[string]string)
356 /* Populating event context */
357 em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
358
359 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
360 context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
361
Devmalya Paulfb990a52019-07-09 10:01:49 -0400362 /* Populating device event body */
363 de.Context = context
364 de.ResourceId = deviceID
Thomas Lee Sf68399e2020-02-11 15:41:38 +0530365 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
Devmalya Paulfb990a52019-07-09 10:01:49 -0400366 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100367 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530368 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400369 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000370 logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
Naga Manjunath9546b912019-11-28 20:56:20 +0530371 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400372}
373
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530374//wasLosRaised checks whether los raised already. If already raised returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000375func (em *OpenOltEventMgr) wasLosRaised(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530376 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
377 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000378 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530379
380 if onuAlarm.LosStatus == statusCheckOn {
381 if onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000382 logger.Warnw(ctx, "onu-los-raised-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530383 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
384 return true
385 }
386 return false
387 }
388 }
389 return true
390}
391
392//wasLosCleared checks whether los cleared already. If already cleared returns true else false
Neha Sharma96b7bf22020-06-15 10:37:32 +0000393func (em *OpenOltEventMgr) wasLosCleared(ctx context.Context, onuAlarm *oop.OnuAlarmIndication) bool {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530394 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
395 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000396 logger.Debugw(ctx, "onu-device-found-in-cache.", log.Fields{"intfID": onuAlarm.IntfId, "onuID": onuAlarm.OnuId})
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530397
398 if onuAlarm.LosStatus == statusCheckOff {
399 if !onuInCache.(*OnuDevice).losRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000400 logger.Warnw(ctx, "onu-los-cleared-already", log.Fields{"onu_id": onuAlarm.OnuId,
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530401 "intf_id": onuAlarm.IntfId, "LosStatus": onuAlarm.LosStatus})
402 return true
403 }
404 return false
405 }
406 }
407 return true
408}
409
410func (em *OpenOltEventMgr) getDeviceEventName(onuAlarm *oop.OnuAlarmIndication) string {
411 var deviceEventName string
412 if onuAlarm.LosStatus == statusCheckOn {
413 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "RAISE_EVENT")
414 } else if onuAlarm.LosStatus == statusCheckOff {
415 deviceEventName = fmt.Sprintf("%s_%s", onuLosEvent, "CLEAR_EVENT")
416 } else if onuAlarm.LobStatus == statusCheckOn {
417 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "RAISE_EVENT")
418 } else if onuAlarm.LobStatus == statusCheckOff {
419 deviceEventName = fmt.Sprintf("%s_%s", onuLobEvent, "CLEAR_EVENT")
420 } else if onuAlarm.LopcMissStatus == statusCheckOn {
421 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "RAISE_EVENT")
422 } else if onuAlarm.LopcMissStatus == statusCheckOff {
423 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMissEvent, "CLEAR_EVENT")
424 } else if onuAlarm.LopcMicErrorStatus == statusCheckOn {
425 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "RAISE_EVENT")
426 } else if onuAlarm.LopcMicErrorStatus == statusCheckOff {
427 deviceEventName = fmt.Sprintf("%s_%s", onuLopcMicErrorEvent, "CLEAR_EVENT")
428 } else if onuAlarm.LofiStatus == statusCheckOn {
429 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "RAISE_EVENT")
430 } else if onuAlarm.LofiStatus == statusCheckOff {
431 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfFrameEvent, "CLEAR_EVENT")
432 } else if onuAlarm.LoamiStatus == statusCheckOn {
433 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "RAISE_EVENT")
434 } else if onuAlarm.LoamiStatus == statusCheckOff {
435 deviceEventName = fmt.Sprintf("%s_%s", onuLossOfPloamEvent, "CLEAR_EVENT")
436 }
437 return deviceEventName
438}
439
Neha Sharma96b7bf22020-06-15 10:37:32 +0000440func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400441 var de voltha.DeviceEvent
Amit Ghosh502056b2020-07-15 09:15:48 +0100442
Devmalya Paulfb990a52019-07-09 10:01:49 -0400443 context := make(map[string]string)
444 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100445 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
446 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
447 em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530448
Devmalya Paulfb990a52019-07-09 10:01:49 -0400449 /* Populating device event body */
450 de.Context = context
451 de.ResourceId = deviceID
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530452 de.DeviceEventName = em.getDeviceEventName(onuAlarm)
453
454 switch onuAlarm.LosStatus {
455 case statusCheckOn:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000456 if em.wasLosRaised(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530457 /* No need to raise Onu Los Event as it might have already raised
458 or Onu might have deleted */
459 return nil
460 }
461 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
462 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
463 /* Update onu device with LoS raised state as true */
464 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
465 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
466 onuInCache.(*OnuDevice).proxyDeviceID, true))
467 }
468 case statusCheckOff:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000469 if em.wasLosCleared(ctx, onuAlarm) {
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530470 /* No need to clear Onu Los Event as it might have already cleared
471 or Onu might have deleted */
472 return nil
473 }
474 onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
475 if onuInCache, ok := em.handler.onus.Load(onuKey); ok {
476 /* Update onu device with LoS raised state as false */
477 em.handler.onus.Store(onuKey, NewOnuDevice(onuInCache.(*OnuDevice).deviceID, onuInCache.(*OnuDevice).deviceType,
478 onuInCache.(*OnuDevice).serialNumber, onuInCache.(*OnuDevice).onuID, onuInCache.(*OnuDevice).intfID,
479 onuInCache.(*OnuDevice).proxyDeviceID, false))
480 }
Devmalya Paulfb990a52019-07-09 10:01:49 -0400481 }
Thiyagarajan Subramani34a00282020-03-10 20:19:31 +0530482
Devmalya Paulfb990a52019-07-09 10:01:49 -0400483 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400484 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530485 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400486 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000487 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 +0530488 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400489}
490
kesavand7cf3a052020-08-28 12:49:18 +0530491func (em *OpenOltEventMgr) onuActivationIndication(ctx context.Context, eventName string, onuInd *oop.OnuIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400492 var de voltha.DeviceEvent
493 context := make(map[string]string)
494 /* Populating event context */
kesavand7cf3a052020-08-28 12:49:18 +0530495 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuInd.IntfId), base10)
496 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuInd.OnuId), base10)
497 context[ContextOnuFailureReaseon] = onuInd.FailReason.String()
Amit Ghosh502056b2020-07-15 09:15:48 +0100498
kesavand7cf3a052020-08-28 12:49:18 +0530499 em.populateContextWithSerialDeviceID(context, onuInd.IntfId, onuInd.OnuId)
Amit Ghosh502056b2020-07-15 09:15:48 +0100500
Devmalya Paulfb990a52019-07-09 10:01:49 -0400501 /* Populating device event body */
502 de.Context = context
503 de.ResourceId = deviceID
kesavand7cf3a052020-08-28 12:49:18 +0530504 de.DeviceEventName = eventName
Devmalya Paulfb990a52019-07-09 10:01:49 -0400505 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400506 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530507 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400508 }
kesavand7cf3a052020-08-28 12:49:18 +0530509 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 +0530510 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400511}
512
Neha Sharma96b7bf22020-06-15 10:37:32 +0000513func (em *OpenOltEventMgr) onuLossOmciIndication(ctx context.Context, onuLossOmci *oop.OnuLossOfOmciChannelIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400514 var de voltha.DeviceEvent
515 context := make(map[string]string)
516 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100517 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
518 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
519
520 em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
521
Devmalya Paulfb990a52019-07-09 10:01:49 -0400522 /* Populating device event body */
523 de.Context = context
524 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530525 if onuLossOmci.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400526 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "RAISE_EVENT")
527 } else {
528 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
529 }
530 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100531 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530532 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400533 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000534 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 +0530535 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400536}
537
Neha Sharma96b7bf22020-06-15 10:37:32 +0000538func (em *OpenOltEventMgr) onuDriftOfWindowIndication(ctx context.Context, onuDriftWindow *oop.OnuDriftOfWindowIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400539 var de voltha.DeviceEvent
540 context := make(map[string]string)
541 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100542 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
543 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
544 context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
545 context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
546
547 em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
548
Devmalya Paulfb990a52019-07-09 10:01:49 -0400549 /* Populating device event body */
550 de.Context = context
551 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530552 if onuDriftWindow.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400553 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "RAISE_EVENT")
554 } else {
555 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
556 }
557 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100558 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530559 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400560 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000561 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 +0530562 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400563}
564
Neha Sharma96b7bf22020-06-15 10:37:32 +0000565func (em *OpenOltEventMgr) onuSignalDegradeIndication(ctx context.Context, onuSignalDegrade *oop.OnuSignalDegradeIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400566 var de voltha.DeviceEvent
567 context := make(map[string]string)
568 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100569 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
570 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
571 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
572
573 em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
574
Devmalya Paulfb990a52019-07-09 10:01:49 -0400575 /* Populating device event body */
576 de.Context = context
577 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530578 if onuSignalDegrade.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400579 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "RAISE_EVENT")
580 } else {
581 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
582 }
583 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100584 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530585 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400586 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000587 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 +0530588 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400589}
590
Neha Sharma96b7bf22020-06-15 10:37:32 +0000591func (em *OpenOltEventMgr) onuSignalsFailIndication(ctx context.Context, onuSignalsFail *oop.OnuSignalsFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400592 var de voltha.DeviceEvent
593 context := make(map[string]string)
594 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100595 em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
596
597 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
598 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
599 context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
Devmalya Paulfb990a52019-07-09 10:01:49 -0400600 /* Populating device event body */
601 de.Context = context
602 de.ResourceId = deviceID
Naga Manjunath9546b912019-11-28 20:56:20 +0530603 if onuSignalsFail.Status == statusCheckOn {
Devmalya Paulfb990a52019-07-09 10:01:49 -0400604 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "RAISE_EVENT")
605 } else {
606 de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
607 }
608 /* Send event to KAFKA */
Andrea Campanella4dea6312021-02-23 10:06:18 +0100609 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530610 return err
Devmalya Paulfb990a52019-07-09 10:01:49 -0400611 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000612 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 +0530613 return nil
614}
615
Neha Sharma96b7bf22020-06-15 10:37:32 +0000616func (em *OpenOltEventMgr) onuStartupFailedIndication(ctx context.Context, onuStartupFail *oop.OnuStartupFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530617 var de voltha.DeviceEvent
618 context := make(map[string]string)
619 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100620 em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
621
622 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
623 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
Naga Manjunathf6f74642020-01-13 21:37:28 +0530624
625 /* Populating device event body */
626 de.Context = context
627 de.ResourceId = deviceID
628 if onuStartupFail.Status == statusCheckOn {
629 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "RAISE_EVENT")
630 } else {
631 de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
632 }
633 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400634 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
Naga Manjunathf6f74642020-01-13 21:37:28 +0530635 return err
636 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000637 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 +0530638 return nil
639}
640
Neha Sharma96b7bf22020-06-15 10:37:32 +0000641func (em *OpenOltEventMgr) onuLossOfSyncIndication(ctx context.Context, onuLOKI *oop.OnuLossOfKeySyncFailureIndication, deviceID string, raisedTs int64) error {
Naga Manjunath9546b912019-11-28 20:56:20 +0530642 var de voltha.DeviceEvent
643 context := make(map[string]string)
644 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100645 em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
646
647 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
648 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
Naga Manjunath9546b912019-11-28 20:56:20 +0530649 /* Populating device event body */
650 de.Context = context
651 de.ResourceId = deviceID
652 if onuLOKI.Status == statusCheckOn {
653 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "RAISE_EVENT")
654 } else {
655 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfKeySyncEvent, "CLEAR_EVENT")
656 }
657
658 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400659 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Naga Manjunath9546b912019-11-28 20:56:20 +0530660 return err
661 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000662 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 +0530663 return nil
Devmalya Paulfb990a52019-07-09 10:01:49 -0400664}
kesavand39e0aa32020-01-28 20:58:50 -0500665
666// oltIntfOperIndication handles Up and Down state of an OLT PON ports
Kent Hagermane6ff1012020-07-14 15:07:53 -0400667func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400668 portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
669 if port, err := em.handler.coreProxy.GetDevicePort(ctx, deviceID, portNo); err != nil {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700670 logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "err": err})
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400671 } else if port.AdminState != common.AdminState_ENABLED {
672 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 -0400673 return
kesavand39e0aa32020-01-28 20:58:50 -0500674 }
675 /* Populating event context */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400676 context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
kesavand39e0aa32020-01-28 20:58:50 -0500677 /* Populating device event body */
Kent Hagermanf1db18b2020-07-08 13:38:15 -0400678 var de voltha.DeviceEvent
kesavand39e0aa32020-01-28 20:58:50 -0500679 de.Context = context
680 de.ResourceId = deviceID
681
682 if ifindication.GetOperState() == operationStateDown {
683 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "RAISE_EVENT")
684 } else if ifindication.OperState == operationStateUp {
685 de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
686 }
687 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400688 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
689 _ = 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)
690 return
kesavand39e0aa32020-01-28 20:58:50 -0500691 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000692 logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
kesavand39e0aa32020-01-28 20:58:50 -0500693}
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500694
Neha Sharma96b7bf22020-06-15 10:37:32 +0000695func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500696 var de voltha.DeviceEvent
697 context := make(map[string]string)
698 /* Populating event context */
Amit Ghosh502056b2020-07-15 09:15:48 +0100699 em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
700
701 context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
702 context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500703 /* Populating device event body */
704 de.Context = context
705 de.ResourceId = deviceID
Devmalya Paula1efa642020-04-20 01:36:43 -0400706 if onuDFI.Status == statusCheckOn {
707 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "RAISE_EVENT")
708 } else {
709 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
710 }
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500711 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400712 if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul1abc34e2020-02-04 20:48:06 -0500713 return err
714 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000715 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 -0500716 return nil
717}
Amit Ghosh502056b2020-07-15 09:15:48 +0100718
Neha Sharma96b7bf22020-06-15 10:37:32 +0000719func (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 -0500720 /* Populating event context */
721 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100722 ContextOnuOnuID: strconv.FormatUint(uint64(onuID), base10),
723 ContextOnuPonIntfID: strconv.FormatUint(uint64(intfID), base10),
724 ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
Devmalya Paul6f063a62020-02-19 19:19:06 -0500725 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100726 em.populateContextWithSerialDeviceID(context, intfID, onuID)
727
Devmalya Paul6f063a62020-02-19 19:19:06 -0500728 /* Populating device event body */
729 de := &voltha.DeviceEvent{
Devmalya Paula1efa642020-04-20 01:36:43 -0400730 Context: context,
731 ResourceId: deviceID,
732 }
733 if status == statusCheckOn {
734 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "RAISE_EVENT")
735 } else {
736 de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
Devmalya Paul6f063a62020-02-19 19:19:06 -0500737 }
738 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400739 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul6f063a62020-02-19 19:19:06 -0500740 return err
741 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000742 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 -0400743 return nil
744}
745
Neha Sharma96b7bf22020-06-15 10:37:32 +0000746func (em *OpenOltEventMgr) onuItuPonStatsIndication(ctx context.Context, onuIPS *oop.OnuItuPonStatsIndication, deviceID string, raisedTs int64) error {
Devmalya Paula1efa642020-04-20 01:36:43 -0400747 onuDevice, found := em.handler.onus.Load(em.handler.formOnuKey(onuIPS.IntfId, onuIPS.OnuId))
748 if !found {
749 return errors.New("unknown-onu-device")
750 }
751 if onuIPS.GetRdiErrorInd().Status == statusCheckOn {
752 if !onuDevice.(*OnuDevice).rdiRaised {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000753 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOn, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400754 return err
755 }
756 onuDevice.(*OnuDevice).rdiRaised = true
757 return nil
758 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000759 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 -0400760 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000761 if err := em.onuRemoteDefectIndication(ctx, onuIPS.OnuId, onuIPS.IntfId, onuIPS.GetRdiErrorInd().RdiErrorCount, statusCheckOff, deviceID, raisedTs); err != nil {
Devmalya Paula1efa642020-04-20 01:36:43 -0400762 return err
763 }
764 onuDevice.(*OnuDevice).rdiRaised = false
765 }
Devmalya Paul41a762d2020-03-01 18:56:54 -0500766 return nil
767}
768
Neha Sharma96b7bf22020-06-15 10:37:32 +0000769func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500770 /* Populating event context */
771 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100772 ContextOnuOnuID: strconv.FormatUint(uint64(onuGCD.OnuId), base10),
773 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuGCD.IntfId), base10),
774 ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500775 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100776 em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
777
Devmalya Paul41a762d2020-03-01 18:56:54 -0500778 /* Populating device event body */
779 de := &voltha.DeviceEvent{
780 Context: context,
781 ResourceId: deviceID,
782 }
783 if onuGCD.Status == statusCheckOn {
784 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "RAISE_EVENT")
785 } else {
786 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
787 }
788 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400789 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500790 return err
791 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000792 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 -0500793 return nil
794}
795
Neha Sharma96b7bf22020-06-15 10:37:32 +0000796func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500797 /* Populating event context */
798 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100799 ContextOnuOnuID: strconv.FormatUint(uint64(onuErr.OnuId), base10),
800 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500801 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100802 em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
Devmalya Paul41a762d2020-03-01 18:56:54 -0500803 /* Populating device event body */
804 de := &voltha.DeviceEvent{
805 Context: context,
806 ResourceId: deviceID,
807 }
808 if onuErr.Status == statusCheckOn {
809 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "RAISE_EVENT")
810 } else {
811 de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
812 }
813 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400814 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500815 return err
816 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000817 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 -0500818 return nil
819}
820
Neha Sharma96b7bf22020-06-15 10:37:32 +0000821func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500822 /* Populating event context */
823 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100824 ContextOnuOnuID: strconv.FormatUint(uint64(onuLOA.OnuId), base10),
825 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
Devmalya Paul41a762d2020-03-01 18:56:54 -0500826 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100827 em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
828
Devmalya Paul41a762d2020-03-01 18:56:54 -0500829 /* Populating device event body */
830 de := &voltha.DeviceEvent{
831 Context: context,
832 ResourceId: deviceID,
833 }
834 if onuLOA.Status == statusCheckOn {
835 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "RAISE_EVENT")
836 } else {
837 de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
838 }
839 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400840 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Paul41a762d2020-03-01 18:56:54 -0500841 return err
842 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000843 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 -0500844 return nil
845}
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400846
Neha Sharma96b7bf22020-06-15 10:37:32 +0000847func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400848 /* Populating event context */
849 context := map[string]string{
Amit Ghosh502056b2020-07-15 09:15:48 +0100850 ContextOnuOnuID: strconv.FormatUint(uint64(onuDRE.OnuId), base10),
851 ContextOnuPonIntfID: strconv.FormatUint(uint64(onuDRE.IntfId), base10),
852 ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400853 }
Amit Ghosh502056b2020-07-15 09:15:48 +0100854 em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
855
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400856 /* Populating device event body */
857 de := &voltha.DeviceEvent{
858 Context: context,
859 ResourceId: deviceID,
860 }
861 if onuDRE.Status == statusCheckOn {
862 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "RAISE_EVENT")
863 } else {
864 de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
865 }
866 /* Send event to KAFKA */
Kent Hagermane6ff1012020-07-14 15:07:53 -0400867 if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
Devmalya Pauleb5294e2020-03-19 03:01:39 -0400868 return err
869 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000870 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 -0400871 return nil
872}